@twilio/conversations 2.0.0-rc.1 → 2.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +3 -3
- package/dist/browser.js +2338 -2672
- package/dist/browser.js.map +1 -1
- package/dist/docs/assets/js/search.js +1 -1
- package/dist/docs/classes/AggregatedDeliveryReceipt.html +22 -6
- package/dist/docs/classes/Client.html +78 -33
- package/dist/docs/classes/Conversation.html +33 -17
- package/dist/docs/classes/DetailedDeliveryReceipt.html +22 -6
- package/dist/docs/classes/Media.html +23 -7
- package/dist/docs/classes/Message.html +23 -7
- package/dist/docs/classes/MessageBuilder.html +3280 -0
- package/dist/docs/classes/Participant.html +23 -7
- package/dist/docs/classes/PushNotification.html +24 -8
- package/dist/docs/classes/RestPaginator.html +28 -9
- package/dist/docs/classes/UnsentMessage.html +3144 -0
- package/dist/docs/classes/User.html +25 -9
- package/dist/docs/index.html +67 -26
- package/dist/docs/interfaces/ClientOptions.html +22 -6
- package/dist/docs/interfaces/ConversationState.html +22 -6
- package/dist/docs/interfaces/CreateConversationOptions.html +22 -6
- package/dist/docs/interfaces/LastMessage.html +22 -6
- package/dist/docs/interfaces/Paginator.html +3243 -0
- package/dist/docs/interfaces/PushNotificationData.html +3168 -0
- package/dist/docs/interfaces/SendEmailOptions.html +22 -6
- package/dist/docs/interfaces/SendMediaOptions.html +22 -6
- package/dist/docs/modules.html +66 -25
- package/dist/lib.d.ts +232 -57
- package/dist/lib.js +2263 -2126
- package/dist/lib.js.map +1 -1
- package/dist/react-native.js +487 -868
- package/dist/react-native.js.map +1 -1
- package/dist/twilio-conversations.js +23616 -23207
- package/dist/twilio-conversations.min.js +14 -2
- package/package.json +5 -4
@@ -126,7 +126,19 @@ This software includes platform.js under the following license.
|
|
126
126
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
127
127
|
|
128
128
|
*/
|
129
|
-
this.Twilio=this.Twilio||{},this.Twilio.Conversations=function(e){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})})),t}var r=function(e){return e&&e.Math==Math&&e},i=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof t&&t)||function(){return this}()||Function("return this")(),a={},s=function(e){try{return!!e()}catch(e){return!0}},o=!s((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),u={},c={}.propertyIsEnumerable,l=Object.getOwnPropertyDescriptor,f=l&&!c.call({1:2},1);u.f=f?function(e){var t=l(this,e);return!!t&&t.enumerable}:c;var d,p,h=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},v={}.toString,y=function(e){return v.call(e).slice(8,-1)},m=y,g="".split,b=s((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==m(e)?g.call(e,""):Object(e)}:Object,k=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},w=b,x=k,_=function(e){return w(x(e))},S=function(e){return"object"==typeof e?null!==e:"function"==typeof e},E=i,T=function(e){return"function"==typeof e?e:void 0},R=function(e,t){return arguments.length<2?T(E[e]):E[e]&&E[e][t]},I=R("navigator","userAgent")||"",O=i,C=I,P=O.process,A=O.Deno,j=P&&P.versions||A&&A.version,M=j&&j.v8;M?p=(d=M.split("."))[0]<4?1:d[0]+d[1]:C&&(!(d=C.match(/Edge\/(\d+)/))||d[1]>=74)&&(d=C.match(/Chrome\/(\d+)/))&&(p=d[1]);var L=p&&+p,N=L,U=s,D=!!Object.getOwnPropertySymbols&&!U((function(){var e=Symbol();return!String(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&N&&N<41})),F=D&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,B=R,q=F?function(e){return"symbol"==typeof e}:function(e){var t=B("Symbol");return"function"==typeof t&&Object(e)instanceof t},W=S,z={exports:{}},G=i,J=function(e,t){try{Object.defineProperty(G,e,{value:t,configurable:!0,writable:!0})}catch(n){G[e]=t}return t},V=J,$="__core-js_shared__",K=i[$]||V($,{}),H=K;(z.exports=function(e,t){return H[e]||(H[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.17.3",mode:"global",copyright:"© 2021 Denis Pushkarev (zloirock.ru)"});var Y=k,Q=function(e){return Object(Y(e))},X=Q,Z={}.hasOwnProperty,ee=Object.hasOwn||function(e,t){return Z.call(X(e),t)},te=0,ne=Math.random(),re=function(e){return"Symbol("+String(void 0===e?"":e)+")_"+(++te+ne).toString(36)},ie=i,ae=z.exports,se=ee,oe=re,ue=D,ce=F,le=ae("wks"),fe=ie.Symbol,de=ce?fe:fe&&fe.withoutSetter||oe,pe=function(e){return se(le,e)&&(ue||"string"==typeof le[e])||(ue&&se(fe,e)?le[e]=fe[e]:le[e]=de("Symbol."+e)),le[e]},he=S,ve=q,ye=function(e,t){var n,r;if("string"===t&&"function"==typeof(n=e.toString)&&!W(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!W(r=n.call(e)))return r;if("string"!==t&&"function"==typeof(n=e.toString)&&!W(r=n.call(e)))return r;throw TypeError("Can't convert object to primitive value")},me=pe("toPrimitive"),ge=function(e,t){if(!he(e)||ve(e))return e;var n,r=e[me];if(void 0!==r){if(void 0===t&&(t="default"),n=r.call(e,t),!he(n)||ve(n))return n;throw TypeError("Can't convert object to primitive value")}return void 0===t&&(t="number"),ye(e,t)},be=ge,ke=q,we=function(e){var t=be(e,"string");return ke(t)?t:String(t)},xe=S,_e=i.document,Se=xe(_e)&&xe(_e.createElement),Ee=function(e){return Se?_e.createElement(e):{}},Te=Ee,Re=!o&&!s((function(){return 7!=Object.defineProperty(Te("div"),"a",{get:function(){return 7}}).a})),Ie=o,Oe=u,Ce=h,Pe=_,Ae=we,je=ee,Me=Re,Le=Object.getOwnPropertyDescriptor;a.f=Ie?Le:function(e,t){if(e=Pe(e),t=Ae(t),Me)try{return Le(e,t)}catch(e){}if(je(e,t))return Ce(!Oe.f.call(e,t),e[t])};var Ne={},Ue=S,De=function(e){if(!Ue(e))throw TypeError(String(e)+" is not an object");return e},Fe=o,Be=Re,qe=De,We=we,ze=Object.defineProperty;Ne.f=Fe?ze:function(e,t,n){if(qe(e),t=We(t),qe(n),Be)try{return ze(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(e[t]=n.value),e};var Ge=Ne,Je=h,Ve=o?function(e,t,n){return Ge.f(e,t,Je(1,n))}:function(e,t,n){return e[t]=n,e},$e={exports:{}},Ke=K,He=Function.toString;"function"!=typeof Ke.inspectSource&&(Ke.inspectSource=function(e){return He.call(e)});var Ye,Qe,Xe,Ze=Ke.inspectSource,et=Ze,tt=i.WeakMap,nt="function"==typeof tt&&/native code/.test(et(tt)),rt=z.exports,it=re,at=rt("keys"),st=function(e){return at[e]||(at[e]=it(e))},ot={},ut=nt,ct=S,lt=Ve,ft=ee,dt=K,pt=st,ht=ot,vt="Object already initialized",yt=i.WeakMap;if(ut||dt.state){var mt=dt.state||(dt.state=new yt),gt=mt.get,bt=mt.has,kt=mt.set;Ye=function(e,t){if(bt.call(mt,e))throw new TypeError(vt);return t.facade=e,kt.call(mt,e,t),t},Qe=function(e){return gt.call(mt,e)||{}},Xe=function(e){return bt.call(mt,e)}}else{var wt=pt("state");ht[wt]=!0,Ye=function(e,t){if(ft(e,wt))throw new TypeError(vt);return t.facade=e,lt(e,wt,t),t},Qe=function(e){return ft(e,wt)?e[wt]:{}},Xe=function(e){return ft(e,wt)}}var xt={set:Ye,get:Qe,has:Xe,enforce:function(e){return Xe(e)?Qe(e):Ye(e,{})},getterFor:function(e){return function(t){var n;if(!ct(t)||(n=Qe(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return n}}},_t=i,St=Ve,Et=ee,Tt=J,Rt=Ze,It=xt.get,Ot=xt.enforce,Ct=String(String).split("String");($e.exports=function(e,t,n,r){var i,a=!!r&&!!r.unsafe,s=!!r&&!!r.enumerable,o=!!r&&!!r.noTargetGet;"function"==typeof n&&("string"!=typeof t||Et(n,"name")||St(n,"name",t),(i=Ot(n)).source||(i.source=Ct.join("string"==typeof t?t:""))),e!==_t?(a?!o&&e[t]&&(s=!0):delete e[t],s?e[t]=n:St(e,t,n)):s?e[t]=n:Tt(t,n)})(Function.prototype,"toString",(function(){return"function"==typeof this&&It(this).source||Rt(this)}));var Pt={},At=Math.ceil,jt=Math.floor,Mt=function(e){return isNaN(e=+e)?0:(e>0?jt:At)(e)},Lt=Mt,Nt=Math.min,Ut=function(e){return e>0?Nt(Lt(e),9007199254740991):0},Dt=Mt,Ft=Math.max,Bt=Math.min,qt=function(e,t){var n=Dt(e);return n<0?Ft(n+t,0):Bt(n,t)},Wt=_,zt=Ut,Gt=qt,Jt=function(e){return function(t,n,r){var i,a=Wt(t),s=zt(a.length),o=Gt(r,s);if(e&&n!=n){for(;s>o;)if((i=a[o++])!=i)return!0}else for(;s>o;o++)if((e||o in a)&&a[o]===n)return e||o||0;return!e&&-1}},Vt={includes:Jt(!0),indexOf:Jt(!1)},$t=ee,Kt=_,Ht=Vt.indexOf,Yt=ot,Qt=function(e,t){var n,r=Kt(e),i=0,a=[];for(n in r)!$t(Yt,n)&&$t(r,n)&&a.push(n);for(;t.length>i;)$t(r,n=t[i++])&&(~Ht(a,n)||a.push(n));return a},Xt=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],Zt=Qt,en=Xt.concat("length","prototype");Pt.f=Object.getOwnPropertyNames||function(e){return Zt(e,en)};var tn={};tn.f=Object.getOwnPropertySymbols;var nn,rn=Pt,an=tn,sn=De,on=R("Reflect","ownKeys")||function(e){var t=rn.f(sn(e)),n=an.f;return n?t.concat(n(e)):t},un=ee,cn=on,ln=a,fn=Ne,dn=function(e,t){for(var n=cn(t),r=fn.f,i=ln.f,a=0;a<n.length;a++){var s=n[a];un(e,s)||r(e,s,i(t,s))}},pn=s,hn=/#|\.prototype\./,vn=function(e,t){var n=mn[yn(e)];return n==bn||n!=gn&&("function"==typeof t?pn(t):!!t)},yn=vn.normalize=function(e){return String(e).replace(hn,".").toLowerCase()},mn=vn.data={},gn=vn.NATIVE="N",bn=vn.POLYFILL="P",kn=vn,wn=i,xn=a.f,_n=Ve,Sn=$e.exports,En=J,Tn=dn,Rn=kn,In=function(e,t){var n,r,i,a,s,o=e.target,u=e.global,c=e.stat;if(n=u?wn:c?wn[o]||En(o,{}):(wn[o]||{}).prototype)for(r in t){if(a=t[r],i=e.noTargetGet?(s=xn(n,r))&&s.value:n[r],!Rn(u?r:o+(c?".":"#")+r,e.forced)&&void 0!==i){if(typeof a==typeof i)continue;Tn(a,i)}(e.sham||i&&i.sham)&&_n(a,"sham",!0),Sn(n,r,a,e)}},On=function(e){if("function"!=typeof e)throw TypeError(String(e)+" is not a function");return e},Cn=Qt,Pn=Xt,An=Object.keys||function(e){return Cn(e,Pn)},jn=Ne,Mn=De,Ln=An,Nn=o?Object.defineProperties:function(e,t){Mn(e);for(var n,r=Ln(t),i=r.length,a=0;i>a;)jn.f(e,n=r[a++],t[n]);return e},Un=R("document","documentElement"),Dn=De,Fn=Nn,Bn=Xt,qn=ot,Wn=Un,zn=Ee,Gn=st("IE_PROTO"),Jn=function(){},Vn=function(e){return"<script>"+e+"</"+"script>"},$n=function(e){e.write(Vn("")),e.close();var t=e.parentWindow.Object;return e=null,t},Kn=function(){try{nn=new ActiveXObject("htmlfile")}catch(e){}var e,t;Kn="undefined"!=typeof document?document.domain&&nn?$n(nn):((t=zn("iframe")).style.display="none",Wn.appendChild(t),t.src=String("javascript:"),(e=t.contentWindow.document).open(),e.write(Vn("document.F=Object")),e.close(),e.F):$n(nn);for(var n=Bn.length;n--;)delete Kn.prototype[Bn[n]];return Kn()};qn[Gn]=!0;var Hn=Object.create||function(e,t){var n;return null!==e?(Jn.prototype=Dn(e),n=new Jn,Jn.prototype=null,n[Gn]=e):n=Kn(),void 0===t?n:Fn(n,t)},Yn=On,Qn=S,Xn=[].slice,Zn={},er=function(e,t,n){if(!(t in Zn)){for(var r=[],i=0;i<t;i++)r[i]="a["+i+"]";Zn[t]=Function("C,a","return new C("+r.join(",")+")")}return Zn[t](e,n)},tr=Function.bind||function(e){var t=Yn(this),n=Xn.call(arguments,1),r=function(){var i=n.concat(Xn.call(arguments));return this instanceof r?er(t,i.length,i):t.apply(e,i)};return Qn(t.prototype)&&(r.prototype=t.prototype),r},nr=In,rr=On,ir=De,ar=S,sr=Hn,or=tr,ur=s,cr=R("Reflect","construct"),lr=ur((function(){function e(){}return!(cr((function(){}),[],e)instanceof e)})),fr=!ur((function(){cr((function(){}))})),dr=lr||fr;nr({target:"Reflect",stat:!0,forced:dr,sham:dr},{construct:function(e,t){rr(e),ir(t);var n=arguments.length<3?e:rr(arguments[2]);if(fr&&!lr)return cr(e,t,n);if(e==n){switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3])}var r=[null];return r.push.apply(r,t),new(or.apply(e,r))}var i=n.prototype,a=sr(ar(i)?i:Object.prototype),s=Function.apply.call(e,a,t);return ar(s)?s:a}});var pr=Q,hr=An;In({target:"Object",stat:!0,forced:s((function(){hr(1)}))},{keys:function(e){return hr(pr(e))}});var vr=y,yr=Array.isArray||function(e){return"Array"==vr(e)},mr=q,gr=function(e){if(mr(e))throw TypeError("Cannot convert a Symbol value to a string");return String(e)},br={},kr=_,wr=Pt.f,xr={}.toString,_r="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];br.f=function(e){return _r&&"[object Window]"==xr.call(e)?function(e){try{return wr(e)}catch(e){return _r.slice()}}(e):wr(kr(e))};var Sr={},Er=pe;Sr.f=Er;var Tr=i,Rr=ee,Ir=Sr,Or=Ne.f,Cr=function(e){var t=Tr.Symbol||(Tr.Symbol={});Rr(t,e)||Or(t,e,{value:Ir.f(e)})},Pr=Ne.f,Ar=ee,jr=pe("toStringTag"),Mr=function(e,t,n){e&&!Ar(e=n?e:e.prototype,jr)&&Pr(e,jr,{configurable:!0,value:t})},Lr=On,Nr=function(e,t,n){if(Lr(e),void 0===t)return e;switch(n){case 0:return function(){return e.call(t)};case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}},Ur=S,Dr=yr,Fr=pe("species"),Br=function(e){var t;return Dr(e)&&("function"!=typeof(t=e.constructor)||t!==Array&&!Dr(t.prototype)?Ur(t)&&null===(t=t[Fr])&&(t=void 0):t=void 0),void 0===t?Array:t},qr=function(e,t){return new(Br(e))(0===t?0:t)},Wr=Nr,zr=b,Gr=Q,Jr=Ut,Vr=qr,$r=[].push,Kr=function(e){var t=1==e,n=2==e,r=3==e,i=4==e,a=6==e,s=7==e,o=5==e||a;return function(u,c,l,f){for(var d,p,h=Gr(u),v=zr(h),y=Wr(c,l,3),m=Jr(v.length),g=0,b=f||Vr,k=t?b(u,m):n||s?b(u,0):void 0;m>g;g++)if((o||g in v)&&(p=y(d=v[g],g,h),e))if(t)k[g]=p;else if(p)switch(e){case 3:return!0;case 5:return d;case 6:return g;case 2:$r.call(k,d)}else switch(e){case 4:return!1;case 7:$r.call(k,d)}return a?-1:r||i?i:k}},Hr={forEach:Kr(0),map:Kr(1),filter:Kr(2),some:Kr(3),every:Kr(4),find:Kr(5),findIndex:Kr(6),filterReject:Kr(7)},Yr=In,Qr=i,Xr=R,Zr=o,ei=D,ti=s,ni=ee,ri=yr,ii=S,ai=q,si=De,oi=Q,ui=_,ci=we,li=gr,fi=h,di=Hn,pi=An,hi=Pt,vi=br,yi=tn,mi=a,gi=Ne,bi=u,ki=Ve,wi=$e.exports,xi=z.exports,_i=ot,Si=re,Ei=pe,Ti=Sr,Ri=Cr,Ii=Mr,Oi=xt,Ci=Hr.forEach,Pi=st("hidden"),Ai="Symbol",ji=Ei("toPrimitive"),Mi=Oi.set,Li=Oi.getterFor(Ai),Ni=Object.prototype,Ui=Qr.Symbol,Di=Xr("JSON","stringify"),Fi=mi.f,Bi=gi.f,qi=vi.f,Wi=bi.f,zi=xi("symbols"),Gi=xi("op-symbols"),Ji=xi("string-to-symbol-registry"),Vi=xi("symbol-to-string-registry"),$i=xi("wks"),Ki=Qr.QObject,Hi=!Ki||!Ki.prototype||!Ki.prototype.findChild,Yi=Zr&&ti((function(){return 7!=di(Bi({},"a",{get:function(){return Bi(this,"a",{value:7}).a}})).a}))?function(e,t,n){var r=Fi(Ni,t);r&&delete Ni[t],Bi(e,t,n),r&&e!==Ni&&Bi(Ni,t,r)}:Bi,Qi=function(e,t){var n=zi[e]=di(Ui.prototype);return Mi(n,{type:Ai,tag:e,description:t}),Zr||(n.description=t),n},Xi=function(e,t,n){e===Ni&&Xi(Gi,t,n),si(e);var r=ci(t);return si(n),ni(zi,r)?(n.enumerable?(ni(e,Pi)&&e[Pi][r]&&(e[Pi][r]=!1),n=di(n,{enumerable:fi(0,!1)})):(ni(e,Pi)||Bi(e,Pi,fi(1,{})),e[Pi][r]=!0),Yi(e,r,n)):Bi(e,r,n)},Zi=function(e,t){si(e);var n=ui(t),r=pi(n).concat(ra(n));return Ci(r,(function(t){Zr&&!ea.call(n,t)||Xi(e,t,n[t])})),e},ea=function(e){var t=ci(e),n=Wi.call(this,t);return!(this===Ni&&ni(zi,t)&&!ni(Gi,t))&&(!(n||!ni(this,t)||!ni(zi,t)||ni(this,Pi)&&this[Pi][t])||n)},ta=function(e,t){var n=ui(e),r=ci(t);if(n!==Ni||!ni(zi,r)||ni(Gi,r)){var i=Fi(n,r);return!i||!ni(zi,r)||ni(n,Pi)&&n[Pi][r]||(i.enumerable=!0),i}},na=function(e){var t=qi(ui(e)),n=[];return Ci(t,(function(e){ni(zi,e)||ni(_i,e)||n.push(e)})),n},ra=function(e){var t=e===Ni,n=qi(t?Gi:ui(e)),r=[];return Ci(n,(function(e){!ni(zi,e)||t&&!ni(Ni,e)||r.push(zi[e])})),r};(ei||(wi((Ui=function(){if(this instanceof Ui)throw TypeError("Symbol is not a constructor");var e=arguments.length&&void 0!==arguments[0]?li(arguments[0]):void 0,t=Si(e),n=function(e){this===Ni&&n.call(Gi,e),ni(this,Pi)&&ni(this[Pi],t)&&(this[Pi][t]=!1),Yi(this,t,fi(1,e))};return Zr&&Hi&&Yi(Ni,t,{configurable:!0,set:n}),Qi(t,e)}).prototype,"toString",(function(){return Li(this).tag})),wi(Ui,"withoutSetter",(function(e){return Qi(Si(e),e)})),bi.f=ea,gi.f=Xi,mi.f=ta,hi.f=vi.f=na,yi.f=ra,Ti.f=function(e){return Qi(Ei(e),e)},Zr&&(Bi(Ui.prototype,"description",{configurable:!0,get:function(){return Li(this).description}}),wi(Ni,"propertyIsEnumerable",ea,{unsafe:!0}))),Yr({global:!0,wrap:!0,forced:!ei,sham:!ei},{Symbol:Ui}),Ci(pi($i),(function(e){Ri(e)})),Yr({target:Ai,stat:!0,forced:!ei},{for:function(e){var t=li(e);if(ni(Ji,t))return Ji[t];var n=Ui(t);return Ji[t]=n,Vi[n]=t,n},keyFor:function(e){if(!ai(e))throw TypeError(e+" is not a symbol");if(ni(Vi,e))return Vi[e]},useSetter:function(){Hi=!0},useSimple:function(){Hi=!1}}),Yr({target:"Object",stat:!0,forced:!ei,sham:!Zr},{create:function(e,t){return void 0===t?di(e):Zi(di(e),t)},defineProperty:Xi,defineProperties:Zi,getOwnPropertyDescriptor:ta}),Yr({target:"Object",stat:!0,forced:!ei},{getOwnPropertyNames:na,getOwnPropertySymbols:ra}),Yr({target:"Object",stat:!0,forced:ti((function(){yi.f(1)}))},{getOwnPropertySymbols:function(e){return yi.f(oi(e))}}),Di)&&Yr({target:"JSON",stat:!0,forced:!ei||ti((function(){var e=Ui();return"[null]"!=Di([e])||"{}"!=Di({a:e})||"{}"!=Di(Object(e))}))},{stringify:function(e,t,n){for(var r,i=[e],a=1;arguments.length>a;)i.push(arguments[a++]);if(r=t,(ii(t)||void 0!==e)&&!ai(e))return ri(t)||(t=function(e,t){if("function"==typeof r&&(t=r.call(this,e,t)),!ai(t))return t}),i[1]=t,Di.apply(null,i)}});Ui.prototype[ji]||ki(Ui.prototype,ji,Ui.prototype.valueOf),Ii(Ui,Ai),_i[Pi]=!0;var ia=s,aa=L,sa=pe("species"),oa=function(e){return aa>=51||!ia((function(){var t=[];return(t.constructor={})[sa]=function(){return{foo:1}},1!==t[e](Boolean).foo}))},ua=Hr.filter;In({target:"Array",proto:!0,forced:!oa("filter")},{filter:function(e){return ua(this,e,arguments.length>1?arguments[1]:void 0)}});var ca=In,la=s,fa=_,da=a.f,pa=o,ha=la((function(){da(1)}));ca({target:"Object",stat:!0,forced:!pa||ha,sham:!pa},{getOwnPropertyDescriptor:function(e,t){return da(fa(e),t)}});var va=we,ya=Ne,ma=h,ga=function(e,t,n){var r=va(t);r in e?ya.f(e,r,ma(0,n)):e[r]=n},ba=on,ka=_,wa=a,xa=ga;function _a(e,t,n,r,i,a,s){try{var o=e[a](s),u=o.value}catch(e){return void n(e)}o.done?t(u):Promise.resolve(u).then(r,i)}function Sa(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var a=e.apply(t,n);function s(e){_a(a,r,i,s,o,"next",e)}function o(e){_a(a,r,i,s,o,"throw",e)}s(void 0)}))}}function Ea(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Ta(e,t,n){return t&&Ea(e.prototype,t),n&&Ea(e,n),e}function Ra(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Ia(e,t){return(Ia=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Oa(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Ia(e,t)}function Ca(e){return(Ca="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Pa(e,t){return!t||"object"!==Ca(t)&&"function"!=typeof t?Ra(e):t}function Aa(e){return(Aa=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function ja(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ma(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}In({target:"Object",stat:!0,sham:!o},{getOwnPropertyDescriptors:function(e){for(var t,n,r=ka(e),i=wa.f,a=ba(r),s={},o=0;a.length>o;)void 0!==(n=i(r,t=a[o++]))&&xa(s,t,n);return s}});var La={};La[pe("toStringTag")]="z";var Na="[object z]"===String(La),Ua=Na,Da=y,Fa=pe("toStringTag"),Ba="Arguments"==Da(function(){return arguments}()),qa=Ua?Da:function(e){var t,n,r;return void 0===e?"Undefined":null===e?"Null":"string"==typeof(n=function(e,t){try{return e[t]}catch(e){}}(t=Object(e),Fa))?n:Ba?Da(t):"Object"==(r=Da(t))&&"function"==typeof t.callee?"Arguments":r},Wa=qa,za=Na?{}.toString:function(){return"[object "+Wa(this)+"]"},Ga=Na,Ja=$e.exports,Va=za;Ga||Ja(Object.prototype,"toString",Va,{unsafe:!0});var $a=i.Promise,Ka=$e.exports,Ha=function(e,t,n){for(var r in t)Ka(e,r,t[r],n);return e},Ya=S,Qa=De,Xa=function(e){if(!Ya(e)&&null!==e)throw TypeError("Can't set "+String(e)+" as a prototype");return e},Za=Object.setPrototypeOf||("__proto__"in{}?function(){var e,t=!1,n={};try{(e=Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set).call(n,[]),t=n instanceof Array}catch(e){}return function(n,r){return Qa(n),Xa(r),t?e.call(n,r):n.__proto__=r,n}}():void 0),es=R,ts=Ne,ns=o,rs=pe("species"),is=function(e){var t=es(e),n=ts.f;ns&&t&&!t[rs]&&n(t,rs,{configurable:!0,get:function(){return this}})},as=function(e,t,n){if(!(e instanceof t))throw TypeError("Incorrect "+(n?n+" ":"")+"invocation");return e},ss={},os=ss,us=pe("iterator"),cs=Array.prototype,ls=function(e){return void 0!==e&&(os.Array===e||cs[us]===e)},fs=qa,ds=ss,ps=pe("iterator"),hs=function(e){if(null!=e)return e[ps]||e["@@iterator"]||ds[fs(e)]},vs=De,ys=hs,ms=function(e,t){var n=arguments.length<2?ys(e):t;if("function"!=typeof n)throw TypeError(String(e)+" is not iterable");return vs(n.call(e))},gs=De,bs=function(e,t,n){var r,i;gs(e);try{if(void 0===(r=e.return)){if("throw"===t)throw n;return n}r=r.call(e)}catch(e){i=!0,r=e}if("throw"===t)throw n;if(i)throw r;return gs(r),n},ks=De,ws=ls,xs=Ut,_s=Nr,Ss=ms,Es=hs,Ts=bs,Rs=function(e,t){this.stopped=e,this.result=t},Is=function(e,t,n){var r,i,a,s,o,u,c,l=n&&n.that,f=!(!n||!n.AS_ENTRIES),d=!(!n||!n.IS_ITERATOR),p=!(!n||!n.INTERRUPTED),h=_s(t,l,1+f+p),v=function(e){return r&&Ts(r,"normal",e),new Rs(!0,e)},y=function(e){return f?(ks(e),p?h(e[0],e[1],v):h(e[0],e[1])):p?h(e,v):h(e)};if(d)r=e;else{if("function"!=typeof(i=Es(e)))throw TypeError("Target is not iterable");if(ws(i)){for(a=0,s=xs(e.length);s>a;a++)if((o=y(e[a]))&&o instanceof Rs)return o;return new Rs(!1)}r=Ss(e,i)}for(u=r.next;!(c=u.call(r)).done;){try{o=y(c.value)}catch(e){Ts(r,"throw",e)}if("object"==typeof o&&o&&o instanceof Rs)return o}return new Rs(!1)},Os=pe("iterator"),Cs=!1;try{var Ps=0,As={next:function(){return{done:!!Ps++}},return:function(){Cs=!0}};As[Os]=function(){return this},Array.from(As,(function(){throw 2}))}catch(e){}var js,Ms,Ls,Ns,Us=function(e,t){if(!t&&!Cs)return!1;var n=!1;try{var r={};r[Os]=function(){return{next:function(){return{done:n=!0}}}},e(r)}catch(e){}return n},Ds=De,Fs=On,Bs=pe("species"),qs=function(e,t){var n,r=Ds(e).constructor;return void 0===r||null==(n=Ds(r)[Bs])?t:Fs(n)},Ws=/(?:ipad|iphone|ipod).*applewebkit/i.test(I),zs="process"==y(i.process),Gs=i,Js=s,Vs=Nr,$s=Un,Ks=Ee,Hs=Ws,Ys=zs,Qs=Gs.setImmediate,Xs=Gs.clearImmediate,Zs=Gs.process,eo=Gs.MessageChannel,to=Gs.Dispatch,no=0,ro={},io="onreadystatechange";try{js=Gs.location}catch(e){}var ao=function(e){if(ro.hasOwnProperty(e)){var t=ro[e];delete ro[e],t()}},so=function(e){return function(){ao(e)}},oo=function(e){ao(e.data)},uo=function(e){Gs.postMessage(String(e),js.protocol+"//"+js.host)};Qs&&Xs||(Qs=function(e){for(var t=[],n=arguments.length,r=1;n>r;)t.push(arguments[r++]);return ro[++no]=function(){("function"==typeof e?e:Function(e)).apply(void 0,t)},Ms(no),no},Xs=function(e){delete ro[e]},Ys?Ms=function(e){Zs.nextTick(so(e))}:to&&to.now?Ms=function(e){to.now(so(e))}:eo&&!Hs?(Ns=(Ls=new eo).port2,Ls.port1.onmessage=oo,Ms=Vs(Ns.postMessage,Ns,1)):Gs.addEventListener&&"function"==typeof postMessage&&!Gs.importScripts&&js&&"file:"!==js.protocol&&!Js(uo)?(Ms=uo,Gs.addEventListener("message",oo,!1)):Ms=io in Ks("script")?function(e){$s.appendChild(Ks("script")).onreadystatechange=function(){$s.removeChild(this),ao(e)}}:function(e){setTimeout(so(e),0)});var co,lo,fo,po,ho,vo,yo,mo,go={set:Qs,clear:Xs},bo=i,ko=/ipad|iphone|ipod/i.test(I)&&void 0!==bo.Pebble,wo=/web0s(?!.*chrome)/i.test(I),xo=i,_o=a.f,So=go.set,Eo=Ws,To=ko,Ro=wo,Io=zs,Oo=xo.MutationObserver||xo.WebKitMutationObserver,Co=xo.document,Po=xo.process,Ao=xo.Promise,jo=_o(xo,"queueMicrotask"),Mo=jo&&jo.value;Mo||(co=function(){var e,t;for(Io&&(e=Po.domain)&&e.exit();lo;){t=lo.fn,lo=lo.next;try{t()}catch(e){throw lo?po():fo=void 0,e}}fo=void 0,e&&e.enter()},Eo||Io||Ro||!Oo||!Co?!To&&Ao&&Ao.resolve?((yo=Ao.resolve(void 0)).constructor=Ao,mo=yo.then,po=function(){mo.call(yo,co)}):po=Io?function(){Po.nextTick(co)}:function(){So.call(xo,co)}:(ho=!0,vo=Co.createTextNode(""),new Oo(co).observe(vo,{characterData:!0}),po=function(){vo.data=ho=!ho}));var Lo=Mo||function(e){var t={fn:e,next:void 0};fo&&(fo.next=t),lo||(lo=t,po()),fo=t},No={},Uo=On,Do=function(e){var t,n;this.promise=new e((function(e,r){if(void 0!==t||void 0!==n)throw TypeError("Bad Promise constructor");t=e,n=r})),this.resolve=Uo(t),this.reject=Uo(n)};No.f=function(e){return new Do(e)};var Fo,Bo,qo,Wo,zo=De,Go=S,Jo=No,Vo=i,$o="object"==typeof window,Ko=In,Ho=i,Yo=R,Qo=$a,Xo=$e.exports,Zo=Ha,eu=Za,tu=Mr,nu=is,ru=S,iu=On,au=as,su=Ze,ou=Is,uu=Us,cu=qs,lu=go.set,fu=Lo,du=function(e,t){if(zo(e),Go(t)&&t.constructor===e)return t;var n=Jo.f(e);return(0,n.resolve)(t),n.promise},pu=function(e,t){var n=Vo.console;n&&n.error&&(1===arguments.length?n.error(e):n.error(e,t))},hu=No,vu=function(e){try{return{error:!1,value:e()}}catch(e){return{error:!0,value:e}}},yu=xt,mu=kn,gu=$o,bu=zs,ku=L,wu=pe("species"),xu="Promise",_u=yu.get,Su=yu.set,Eu=yu.getterFor(xu),Tu=Qo&&Qo.prototype,Ru=Qo,Iu=Tu,Ou=Ho.TypeError,Cu=Ho.document,Pu=Ho.process,Au=hu.f,ju=Au,Mu=!!(Cu&&Cu.createEvent&&Ho.dispatchEvent),Lu="function"==typeof PromiseRejectionEvent,Nu="unhandledrejection",Uu=!1,Du=mu(xu,(function(){var e=su(Ru),t=e!==String(Ru);if(!t&&66===ku)return!0;if(ku>=51&&/native code/.test(e))return!1;var n=new Ru((function(e){e(1)})),r=function(e){e((function(){}),(function(){}))};return(n.constructor={})[wu]=r,!(Uu=n.then((function(){}))instanceof r)||!t&&gu&&!Lu})),Fu=Du||!uu((function(e){Ru.all(e).catch((function(){}))})),Bu=function(e){var t;return!(!ru(e)||"function"!=typeof(t=e.then))&&t},qu=function(e,t){if(!e.notified){e.notified=!0;var n=e.reactions;fu((function(){for(var r=e.value,i=1==e.state,a=0;n.length>a;){var s,o,u,c=n[a++],l=i?c.ok:c.fail,f=c.resolve,d=c.reject,p=c.domain;try{l?(i||(2===e.rejection&&Ju(e),e.rejection=1),!0===l?s=r:(p&&p.enter(),s=l(r),p&&(p.exit(),u=!0)),s===c.promise?d(Ou("Promise-chain cycle")):(o=Bu(s))?o.call(s,f,d):f(s)):d(r)}catch(e){p&&!u&&p.exit(),d(e)}}e.reactions=[],e.notified=!1,t&&!e.rejection&&zu(e)}))}},Wu=function(e,t,n){var r,i;Mu?((r=Cu.createEvent("Event")).promise=t,r.reason=n,r.initEvent(e,!1,!0),Ho.dispatchEvent(r)):r={promise:t,reason:n},!Lu&&(i=Ho["on"+e])?i(r):e===Nu&&pu("Unhandled promise rejection",n)},zu=function(e){lu.call(Ho,(function(){var t,n=e.facade,r=e.value;if(Gu(e)&&(t=vu((function(){bu?Pu.emit("unhandledRejection",r,n):Wu(Nu,n,r)})),e.rejection=bu||Gu(e)?2:1,t.error))throw t.value}))},Gu=function(e){return 1!==e.rejection&&!e.parent},Ju=function(e){lu.call(Ho,(function(){var t=e.facade;bu?Pu.emit("rejectionHandled",t):Wu("rejectionhandled",t,e.value)}))},Vu=function(e,t,n){return function(r){e(t,r,n)}},$u=function(e,t,n){e.done||(e.done=!0,n&&(e=n),e.value=t,e.state=2,qu(e,!0))},Ku=function(e,t,n){if(!e.done){e.done=!0,n&&(e=n);try{if(e.facade===t)throw Ou("Promise can't be resolved itself");var r=Bu(t);r?fu((function(){var n={done:!1};try{r.call(t,Vu(Ku,n,e),Vu($u,n,e))}catch(t){$u(n,t,e)}})):(e.value=t,e.state=1,qu(e,!1))}catch(t){$u({done:!1},t,e)}}};if(Du&&(Iu=(Ru=function(e){au(this,Ru,xu),iu(e),Fo.call(this);var t=_u(this);try{e(Vu(Ku,t),Vu($u,t))}catch(e){$u(t,e)}}).prototype,(Fo=function(e){Su(this,{type:xu,done:!1,notified:!1,parent:!1,reactions:[],rejection:!1,state:0,value:void 0})}).prototype=Zo(Iu,{then:function(e,t){var n=Eu(this),r=Au(cu(this,Ru));return r.ok="function"!=typeof e||e,r.fail="function"==typeof t&&t,r.domain=bu?Pu.domain:void 0,n.parent=!0,n.reactions.push(r),0!=n.state&&qu(n,!1),r.promise},catch:function(e){return this.then(void 0,e)}}),Bo=function(){var e=new Fo,t=_u(e);this.promise=e,this.resolve=Vu(Ku,t),this.reject=Vu($u,t)},hu.f=Au=function(e){return e===Ru||e===qo?new Bo(e):ju(e)},"function"==typeof Qo&&Tu!==Object.prototype)){Wo=Tu.then,Uu||(Xo(Tu,"then",(function(e,t){var n=this;return new Ru((function(e,t){Wo.call(n,e,t)})).then(e,t)}),{unsafe:!0}),Xo(Tu,"catch",Iu.catch,{unsafe:!0}));try{delete Tu.constructor}catch(e){}eu&&eu(Tu,Iu)}Ko({global:!0,wrap:!0,forced:Du},{Promise:Ru}),tu(Ru,xu,!1),nu(xu),qo=Yo(xu),Ko({target:xu,stat:!0,forced:Du},{reject:function(e){var t=Au(this);return t.reject.call(void 0,e),t.promise}}),Ko({target:xu,stat:!0,forced:Du},{resolve:function(e){return du(this,e)}}),Ko({target:xu,stat:!0,forced:Fu},{all:function(e){var t=this,n=Au(t),r=n.resolve,i=n.reject,a=vu((function(){var n=iu(t.resolve),a=[],s=0,o=1;ou(e,(function(e){var u=s++,c=!1;a.push(void 0),o++,n.call(t,e).then((function(e){c||(c=!0,a[u]=e,--o||r(a))}),i)})),--o||r(a)}));return a.error&&i(a.value),n.promise},race:function(e){var t=this,n=Au(t),r=n.reject,i=vu((function(){var i=iu(t.resolve);ou(e,(function(e){i.call(t,e).then(n.resolve,r)}))}));return i.error&&r(i.value),n.promise}});var Hu={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0},Yu=Ee("span").classList,Qu=Yu&&Yu.constructor&&Yu.constructor.prototype,Xu=Qu===Object.prototype?void 0:Qu,Zu=s,ec=function(e,t){var n=[][e];return!!n&&Zu((function(){n.call(null,t||function(){throw 1},1)}))},tc=Hr.forEach,nc=i,rc=Hu,ic=Xu,ac=ec("forEach")?[].forEach:function(e){return tc(this,e,arguments.length>1?arguments[1]:void 0)},sc=Ve,oc=function(e){if(e&&e.forEach!==ac)try{sc(e,"forEach",ac)}catch(t){e.forEach=ac}};for(var uc in rc)oc(nc[uc]&&nc[uc].prototype);oc(ic);var cc=S,lc=Za,fc=function(e,t,n){var r,i;return lc&&"function"==typeof(r=t.constructor)&&r!==n&&cc(i=r.prototype)&&i!==n.prototype&&lc(e,i),e},dc=k,pc=gr,hc="[\t\n\v\f\r \u2028\u2029\ufeff]",vc=RegExp("^"+hc+hc+"*"),yc=RegExp(hc+hc+"*$"),mc=function(e){return function(t){var n=pc(dc(t));return 1&e&&(n=n.replace(vc,"")),2&e&&(n=n.replace(yc,"")),n}},gc={start:mc(1),end:mc(2),trim:mc(3)},bc=o,kc=i,wc=kn,xc=$e.exports,_c=ee,Sc=y,Ec=fc,Tc=q,Rc=ge,Ic=s,Oc=Hn,Cc=Pt.f,Pc=a.f,Ac=Ne.f,jc=gc.trim,Mc="Number",Lc=kc.Number,Nc=Lc.prototype,Uc=Sc(Oc(Nc))==Mc,Dc=function(e){if(Tc(e))throw TypeError("Cannot convert a Symbol value to a number");var t,n,r,i,a,s,o,u,c=Rc(e,"number");if("string"==typeof c&&c.length>2)if(43===(t=(c=jc(c)).charCodeAt(0))||45===t){if(88===(n=c.charCodeAt(2))||120===n)return NaN}else if(48===t){switch(c.charCodeAt(1)){case 66:case 98:r=2,i=49;break;case 79:case 111:r=8,i=55;break;default:return+c}for(s=(a=c.slice(2)).length,o=0;o<s;o++)if((u=a.charCodeAt(o))<48||u>i)return NaN;return parseInt(a,r)}return+c};if(wc(Mc,!Lc(" 0o1")||!Lc("0b1")||Lc("+0x1"))){for(var Fc,Bc=function(e){var t=arguments.length<1?0:e,n=this;return n instanceof Bc&&(Uc?Ic((function(){Nc.valueOf.call(n)})):Sc(n)!=Mc)?Ec(new Lc(Dc(t)),n,Bc):Dc(t)},qc=bc?Cc(Lc):"MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger,fromString,range".split(","),Wc=0;qc.length>Wc;Wc++)_c(Lc,Fc=qc[Wc])&&!_c(Bc,Fc)&&Ac(Bc,Fc,Pc(Lc,Fc));Bc.prototype=Nc,Nc.constructor=Bc,xc(kc,Mc,Bc)}var zc,Gc=Object.prototype,Jc=Gc.hasOwnProperty,Vc="function"==typeof Symbol?Symbol:{},$c=Vc.iterator||"@@iterator",Kc=Vc.asyncIterator||"@@asyncIterator",Hc=Vc.toStringTag||"@@toStringTag";function Yc(e,t,n,r){var i=t&&t.prototype instanceof rl?t:rl,a=Object.create(i.prototype),s=new yl(r||[]);return a._invoke=function(e,t,n){var r=Xc;return function(i,a){if(r===el)throw new Error("Generator is already running");if(r===tl){if("throw"===i)throw a;return gl()}for(n.method=i,n.arg=a;;){var s=n.delegate;if(s){var o=pl(s,n);if(o){if(o===nl)continue;return o}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===Xc)throw r=tl,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=el;var u=Qc(e,t,n);if("normal"===u.type){if(r=n.done?tl:Zc,u.arg===nl)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=tl,n.method="throw",n.arg=u.arg)}}}(e,n,s),a}function Qc(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}var Xc="suspendedStart",Zc="suspendedYield",el="executing",tl="completed",nl={};function rl(){}function il(){}function al(){}var sl={};sl[$c]=function(){return this};var ol=Object.getPrototypeOf,ul=ol&&ol(ol(ml([])));ul&&ul!==Gc&&Jc.call(ul,$c)&&(sl=ul);var cl=al.prototype=rl.prototype=Object.create(sl);function ll(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function fl(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===il||"GeneratorFunction"===(t.displayName||t.name))}function dl(e,t){function n(r,i,a,s){var o=Qc(e[r],e,i);if("throw"!==o.type){var u=o.arg,c=u.value;return c&&"object"===Ca(c)&&Jc.call(c,"__await")?t.resolve(c.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(c).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(o.arg)}var r;this._invoke=function(e,i){function a(){return new t((function(t,r){n(e,i,t,r)}))}return r=r?r.then(a,a):a()}}function pl(e,t){var n=e.iterator[t.method];if(n===zc){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=zc,pl(e,t),"throw"===t.method))return nl;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return nl}var r=Qc(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,nl;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=zc),t.delegate=null,nl):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,nl)}function hl(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function vl(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function yl(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(hl,this),this.reset(!0)}function ml(e){if(e){var t=e[$c];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,r=function t(){for(;++n<e.length;)if(Jc.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=zc,t.done=!0,t};return r.next=r}}return{next:gl}}function gl(){return{value:zc,done:!0}}il.prototype=cl.constructor=al,al.constructor=il,al[Hc]=il.displayName="GeneratorFunction",ll(dl.prototype),dl.prototype[Kc]=function(){return this},ll(cl),cl[Hc]="Generator",cl[$c]=function(){return this},cl.toString=function(){return"[object Generator]"},yl.prototype={constructor:yl,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=zc,this.done=!1,this.delegate=null,this.method="next",this.arg=zc,this.tryEntries.forEach(vl),!e)for(var t in this)"t"===t.charAt(0)&&Jc.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=zc)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=zc),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=Jc.call(i,"catchLoc"),o=Jc.call(i,"finallyLoc");if(s&&o){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!o)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&Jc.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var i=r;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,nl):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),nl},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),vl(n),nl}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;vl(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:ml(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=zc),nl}};var bl={wrap:Yc,isGeneratorFunction:fl,AsyncIterator:dl,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,al):(e.__proto__=al,Hc in e||(e[Hc]="GeneratorFunction")),e.prototype=Object.create(cl),e},awrap:function(e){return{__await:e}},async:function(e,t,n,r,i){void 0===i&&(i=Promise);var a=new dl(Yc(e,t,n,r),i);return fl(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},keys:function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},values:ml},kl=Object.freeze({__proto__:null,default:bl});function wl(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function xl(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function _l(){}function Sl(){Sl.init.call(this)}function El(e){return void 0===e._maxListeners?Sl.defaultMaxListeners:e._maxListeners}function Tl(e,t,n){if(t)e.call(n);else for(var r=e.length,i=Ml(e,r),a=0;a<r;++a)i[a].call(n)}function Rl(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=Ml(e,i),s=0;s<i;++s)a[s].call(n,r)}function Il(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=Ml(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function Ol(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=Ml(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function Cl(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=Ml(e,i),s=0;s<i;++s)a[s].apply(n,r)}function Pl(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new _l,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=El(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function Al(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function jl(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function Ml(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}_l.prototype=Object.create(null),Sl.EventEmitter=Sl,Sl.usingDomains=!1,Sl.prototype.domain=void 0,Sl.prototype._events=void 0,Sl.prototype._maxListeners=void 0,Sl.defaultMaxListeners=10,Sl.init=function(){this.domain=null,Sl.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new _l,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Sl.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},Sl.prototype.getMaxListeners=function(){return El(this)},Sl.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:Tl(n,l,this);break;case 2:Rl(n,l,this,arguments[1]);break;case 3:Il(n,l,this,arguments[1],arguments[2]);break;case 4:Ol(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];Cl(n,l,this,i)}return!0},Sl.prototype.addListener=function(e,t){return Pl(this,e,t,!1)},Sl.prototype.on=Sl.prototype.addListener,Sl.prototype.prependListener=function(e,t){return Pl(this,e,t,!0)},Sl.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,Al(this,e,t)),this},Sl.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,Al(this,e,t)),this},Sl.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new _l:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new _l,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},Sl.prototype.off=function(e,t){return this.removeListener(e,t)},Sl.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new _l,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new _l:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new _l,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},Sl.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},Sl.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):jl.call(e,t)},Sl.prototype.listenerCount=jl,Sl.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var Ll=In,Nl=s,Ul=yr,Dl=S,Fl=Q,Bl=Ut,ql=ga,Wl=qr,zl=oa,Gl=L,Jl=pe("isConcatSpreadable"),Vl=9007199254740991,$l="Maximum allowed index exceeded",Kl=Gl>=51||!Nl((function(){var e=[];return e[Jl]=!1,e.concat()[0]!==e})),Hl=zl("concat"),Yl=function(e){if(!Dl(e))return!1;var t=e[Jl];return void 0!==t?!!t:Ul(e)};Ll({target:"Array",proto:!0,forced:!Kl||!Hl},{concat:function(e){var t,n,r,i,a,s=Fl(this),o=Wl(s,0),u=0;for(t=-1,r=arguments.length;t<r;t++)if(Yl(a=-1===t?s:arguments[t])){if(u+(i=Bl(a.length))>Vl)throw TypeError($l);for(n=0;n<i;n++,u++)n in a&&ql(o,u,a[n])}else{if(u>=Vl)throw TypeError($l);ql(o,u++,a)}return o.length=u,o}});var Ql=De,Xl=bs,Zl=Nr,ef=Q,tf=function(e,t,n,r){try{return r?t(Ql(n)[0],n[1]):t(n)}catch(t){Xl(e,"throw",t)}},nf=ls,rf=Ut,af=ga,sf=ms,of=hs,uf=function(e){var t,n,r,i,a,s,o=ef(e),u="function"==typeof this?this:Array,c=arguments.length,l=c>1?arguments[1]:void 0,f=void 0!==l,d=of(o),p=0;if(f&&(l=Zl(l,c>2?arguments[2]:void 0,2)),null==d||u==Array&&nf(d))for(n=new u(t=rf(o.length));t>p;p++)s=f?l(o[p],p):o[p],af(n,p,s);else for(a=(i=sf(o,d)).next,n=new u;!(r=a.call(i)).done;p++)s=f?tf(i,l,[r.value,p],!0):r.value,af(n,p,s);return n.length=p,n},cf=uf;In({target:"Array",stat:!0,forced:!Us((function(e){Array.from(e)}))},{from:cf});var lf,ff,df,pf=Mt,hf=gr,vf=k,yf=function(e){return function(t,n){var r,i,a=hf(vf(t)),s=pf(n),o=a.length;return s<0||s>=o?e?"":void 0:(r=a.charCodeAt(s))<55296||r>56319||s+1===o||(i=a.charCodeAt(s+1))<56320||i>57343?e?a.charAt(s):r:e?a.slice(s,s+2):i-56320+(r-55296<<10)+65536}},mf={codeAt:yf(!1),charAt:yf(!0)},gf=!s((function(){function e(){}return e.prototype.constructor=null,Object.getPrototypeOf(new e)!==e.prototype})),bf=ee,kf=Q,wf=gf,xf=st("IE_PROTO"),_f=Object.prototype,Sf=wf?Object.getPrototypeOf:function(e){return e=kf(e),bf(e,xf)?e[xf]:"function"==typeof e.constructor&&e instanceof e.constructor?e.constructor.prototype:e instanceof Object?_f:null},Ef=s,Tf=Sf,Rf=Ve,If=pe("iterator"),Of=!1;[].keys&&("next"in(df=[].keys())?(ff=Tf(Tf(df)))!==Object.prototype&&(lf=ff):Of=!0),(null==lf||Ef((function(){var e={};return lf[If].call(e)!==e})))&&(lf={}),"function"!=typeof lf[If]&&Rf(lf,If,(function(){return this}));var Cf={IteratorPrototype:lf,BUGGY_SAFARI_ITERATORS:Of},Pf=Cf.IteratorPrototype,Af=Hn,jf=h,Mf=Mr,Lf=ss,Nf=function(){return this},Uf=function(e,t,n){var r=t+" Iterator";return e.prototype=Af(Pf,{next:jf(1,n)}),Mf(e,r,!1),Lf[r]=Nf,e},Df=In,Ff=Uf,Bf=Sf,qf=Za,Wf=Mr,zf=Ve,Gf=$e.exports,Jf=ss,Vf=Cf.IteratorPrototype,$f=Cf.BUGGY_SAFARI_ITERATORS,Kf=pe("iterator"),Hf="keys",Yf="values",Qf="entries",Xf=function(){return this},Zf=function(e,t,n,r,i,a,s){Ff(n,t,r);var o,u,c,l=function(e){if(e===i&&v)return v;if(!$f&&e in p)return p[e];switch(e){case Hf:case Yf:case Qf:return function(){return new n(this,e)}}return function(){return new n(this)}},f=t+" Iterator",d=!1,p=e.prototype,h=p[Kf]||p["@@iterator"]||i&&p[i],v=!$f&&h||l(i),y="Array"==t&&p.entries||h;if(y&&(o=Bf(y.call(new e)))!==Object.prototype&&o.next&&(Bf(o)!==Vf&&(qf?qf(o,Vf):"function"!=typeof o[Kf]&&zf(o,Kf,Xf)),Wf(o,f,!0)),i==Yf&&h&&h.name!==Yf&&(d=!0,v=function(){return h.call(this)}),p[Kf]!==v&&zf(p,Kf,v),Jf[t]=v,i)if(u={values:l(Yf),keys:a?v:l(Hf),entries:l(Qf)},s)for(c in u)($f||d||!(c in p))&&Gf(p,c,u[c]);else Df({target:t,proto:!0,forced:$f||d},u);return u},ed=mf.charAt,td=gr,nd=xt,rd=Zf,id="String Iterator",ad=nd.set,sd=nd.getterFor(id);rd(String,"String",(function(e){ad(this,{type:id,string:td(e),index:0})}),(function(){var e,t=sd(this),n=t.string,r=t.index;return r>=n.length?{value:void 0,done:!0}:(e=ed(n,r),t.index+=e.length,{value:e,done:!1})}));var od,ud,cd,ld={exports:{}};function fd(e,t){return["".concat((new Date).toISOString()," Conversations ").concat(e,":")].concat(Array.from(t))}ud=t,cd=function(){var e=function(){},t="undefined",n=("undefined"==typeof window?"undefined":Ca(window))!==t&&Ca(window.navigator)!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=["trace","debug","info","warn","error"];function i(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function a(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function s(r){return"debug"===r&&(r="log"),("undefined"==typeof console?"undefined":Ca(console))!==t&&("trace"===r&&n?a:void 0!==console[r]?i(console,r):void 0!==console.log?i(console,"log"):e)}function o(t,n){for(var i=0;i<r.length;i++){var a=r[i];this[a]=i<t?e:this.methodFactory(a,t,n)}this.log=this.debug}function u(e,n,r){return function(){("undefined"==typeof console?"undefined":Ca(console))!==t&&(o.call(this,n,r),this[e].apply(this,arguments))}}function c(e,t,n){return s(e)||u.apply(this,arguments)}function l(e,n,i){var a,s=this,u="loglevel";function l(){var e;if(("undefined"==typeof window?"undefined":Ca(window))!==t&&u){try{e=window.localStorage[u]}catch(e){}if(Ca(e)===t)try{var n=window.document.cookie,r=n.indexOf(encodeURIComponent(u)+"=");-1!==r&&(e=/^([^;]+)/.exec(n.slice(r))[1])}catch(e){}return void 0===s.levels[e]&&(e=void 0),e}}"string"==typeof e?u+=":"+e:"symbol"===Ca(e)&&(u=void 0),s.name=e,s.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},s.methodFactory=i||c,s.getLevel=function(){return a},s.setLevel=function(n,i){if("string"==typeof n&&void 0!==s.levels[n.toUpperCase()]&&(n=s.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=s.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(a=n,!1!==i&&function(e){var n=(r[e]||"silent").toUpperCase();if(("undefined"==typeof window?"undefined":Ca(window))!==t&&u){try{return void(window.localStorage[u]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(u)+"="+n+";"}catch(e){}}}(n),o.call(s,n,e),("undefined"==typeof console?"undefined":Ca(console))===t&&n<s.levels.SILENT)return"No console available for logging"},s.setDefaultLevel=function(e){l()||s.setLevel(e,!1)},s.enableAll=function(e){s.setLevel(s.levels.TRACE,e)},s.disableAll=function(e){s.setLevel(s.levels.SILENT,e)};var f=l();null==f&&(f=null==n?"WARN":n),s.setLevel(f,!1)}var f=new l,d={};f.getLogger=function(e){if("symbol"!==Ca(e)&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=d[e];return t||(t=d[e]=new l(e,f.getLevel(),f.methodFactory)),t};var p=("undefined"==typeof window?"undefined":Ca(window))!==t?window.log:void 0;return f.noConflict=function(){return("undefined"==typeof window?"undefined":Ca(window))!==t&&window.log===f&&(window.log=p),f},f.getLoggers=function(){return d},f.default=f,f},(od=ld).exports?od.exports=cd():ud.log=cd();var dd,pd,hd=ld.exports.getLogger("twilio-conversations"),vd=function(){function e(t){Ma(this,e),ja(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return Ta(e,[{key:"setLevel",value:function(e){hd.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];hd.trace.apply(null,fd(this.prefix+"T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];hd.debug.apply(null,fd(this.prefix+"D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];hd.info.apply(null,fd(this.prefix+"I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];hd.warn.apply(null,fd(this.prefix+"W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];hd.error.apply(null,fd(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){hd.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];hd.trace.apply(null,fd("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];hd.debug.apply(null,fd("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];hd.info.apply(null,fd("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];hd.warn.apply(null,fd("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];hd.error.apply(null,fd("E",t))}}]),e}(),yd={};Object.defineProperty(yd,"__esModule",{value:!0});var md=["weeks","years","months","days","hours","minutes","seconds"],gd=yd.pattern=new RegExp("P(?:(\\d+(?:[\\.,]\\d+)?W)|(\\d+(?:[\\.,]\\d+)?Y)?(\\d+(?:[\\.,]\\d+)?M)?(\\d+(?:[\\.,]\\d+)?D)?(?:T(\\d+(?:[\\.,]\\d+)?H)?(\\d+(?:[\\.,]\\d+)?M)?(\\d+(?:[\\.,]\\d+)?S)?)?)"),bd=pd=yd.parse=function(e){return e.match(gd).slice(1).reduce((function(e,t,n){return e[md[n]]=parseFloat(t)||0,e}),{})},kd=yd.end=function(e,t){var n=t?t.getTime():Date.now(),r=new Date(n);return r.setFullYear(r.getFullYear()+e.years),r.setMonth(r.getMonth()+e.months),r.setDate(r.getDate()+e.days),r.setHours(r.getHours()+e.hours),r.setMinutes(r.getMinutes()+e.minutes),r.setMilliseconds(r.getMilliseconds()+1e3*e.seconds),r.setDate(r.getDate()+7*e.weeks),r},wd=dd=yd.toSeconds=function(e,t){var n=t?t.getTime():Date.now(),r=new Date(n);return(kd(e,r).getTime()-r.getTime())/1e3};function xd(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?xd(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):xd(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}yd.default={end:kd,toSeconds:wd,pattern:gd,parse:bd};var Sd="PT5S",Ed="PT5S",Td=function e(){var t,n,r,i,a,s,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},u=arguments.length>1?arguments[1]:void 0,c=arguments.length>2?arguments[2]:void 0;Ma(this,e),ja(this,"typingIndicatorTimeoutDefault",5e3);var l=o.Chat||o.IPMessaging||o||{};this.productId=l.productId,this.links={myConversations:u.links.my_conversations,conversations:u.links.conversations,users:u.links.users,currentUser:u.links.current_user,typing:u.links.typing,mediaService:u.links.media_service,mediaSetService:u.links.media_set_service,messagesReceipts:u.links.messages_receipts},this.limits={mediaAttachmentsCountLimit:u.options.media_attachments_count_limit,mediaAttachmentSizeLimitInMb:u.options.media_attachment_size_limit_in_mb,mediaAttachmentsTotalSizeLimitInMb:u.options.media_attachments_total_size_limit_in_mb,emailHistoriesAllowedMimeTypes:u.options.email_histories_allowed_mime_types,emailBodiesAllowedMimeTypes:u.options.email_bodies_allowed_mime_types},this.typingIndicatorTimeoutOverride=l.typingIndicatorTimeoutOverride,this.backoffConfiguration=_d({min:1e3,max:4e3,maxAttemptsCount:3},l.backoffConfigOverride),this.retryWhenThrottled=void 0===l.retryWhenThrottledOverride||l.retryWhenThrottledOverride,this.userInfosToSubscribe=null!==(t=null!==(n=l.userInfosToSubscribeOverride)&&void 0!==n?n:u.options.user_infos_to_subscribe)&&void 0!==t?t:100,this.reachabilityEnabled=u.options.reachability_enabled,this.userIdentity=u.identity,this.userInfo=u.sync_objects.my_user_info,this.myConversations=u.sync_objects.my_conversations;var f=null!==(r=null!==(i=l.httpCacheIntervalOverride)&&void 0!==i?i:u.options.http_cache_interval)&&void 0!==r?r:Sd;try{this.httpCacheInterval=dd(pd(f))}catch(e){c.error("Failed to parse http cache interval ".concat(f,", using default value ").concat(Sd)),this.httpCacheInterval=dd(pd(Sd))}var d=null!==(a=null!==(s=l.consumptionReportIntervalOverride)&&void 0!==s?s:u.options.consumption_report_interval)&&void 0!==a?a:Ed;try{this.consumptionReportInterval=dd(pd(d))}catch(e){c.error("Failed to parse consumption report interval ".concat(d,", using default value ").concat(Ed)),this.consumptionReportInterval=dd(pd(Ed))}},Rd=In,Id=S,Od=yr,Cd=qt,Pd=Ut,Ad=_,jd=ga,Md=pe,Ld=oa("slice"),Nd=Md("species"),Ud=[].slice,Dd=Math.max;Rd({target:"Array",proto:!0,forced:!Ld},{slice:function(e,t){var n,r,i,a=Ad(this),s=Pd(a.length),o=Cd(e,s),u=Cd(void 0===t?s:t,s);if(Od(a)&&("function"!=typeof(n=a.constructor)||n!==Array&&!Od(n.prototype)?Id(n)&&null===(n=n[Nd])&&(n=void 0):n=void 0,n===Array||void 0===n))return Ud.call(a,o,u);for(r=new(void 0===n?Array:n)(Dd(u-o,0)),i=0;o<u;o++,i++)o in a&&jd(r,i,a[o]);return r.length=i,r}});var Fd=o,Bd=Ne.f,qd=Function.prototype,Wd=qd.toString,zd=/^\s*function ([^ (]*)/,Gd="name";Fd&&!(Gd in qd)&&Bd(qd,Gd,{configurable:!0,get:function(){try{return Wd.call(this).match(zd)[1]}catch(e){return""}}});var Jd=In,Vd=o,$d=i,Kd=ee,Hd=S,Yd=Ne.f,Qd=dn,Xd=$d.Symbol;if(Vd&&"function"==typeof Xd&&(!("description"in Xd.prototype)||void 0!==Xd().description)){var Zd={},ep=function(){var e=arguments.length<1||void 0===arguments[0]?void 0:String(arguments[0]),t=this instanceof ep?new Xd(e):void 0===e?Xd():Xd(e);return""===e&&(Zd[t]=!0),t};Qd(ep,Xd);var tp=ep.prototype=Xd.prototype;tp.constructor=ep;var np=tp.toString,rp="Symbol(test)"==String(Xd("test")),ip=/^Symbol\((.*)\)[^)]+$/;Yd(tp,"description",{configurable:!0,get:function(){var e=Hd(this)?this.valueOf():this,t=np.call(e);if(Kd(Zd,e))return"";var n=rp?t.slice(7,-1):t.replace(ip,"$1");return""===n?void 0:n}}),Jd({global:!0,forced:!0},{Symbol:ep})}function ap(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function sp(e,t){if(e){if("string"==typeof e)return ap(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ap(e,t):void 0}}function op(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,a=[],s=!0,o=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){o=!0,i=e}finally{try{s||null==n.return||n.return()}finally{if(o)throw i}}return a}}(e,t)||sp(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}Cr("iterator");var up=Hn,cp=Ne,lp=pe("unscopables"),fp=Array.prototype;null==fp[lp]&&cp.f(fp,lp,{configurable:!0,value:up(null)});var dp=function(e){fp[lp][e]=!0},pp=_,hp=dp,vp=ss,yp=xt,mp=Zf,gp="Array Iterator",bp=yp.set,kp=yp.getterFor(gp),wp=mp(Array,"Array",(function(e,t){bp(this,{type:gp,target:pp(e),index:0,kind:t})}),(function(){var e=kp(this),t=e.target,n=e.kind,r=e.index++;return!t||r>=t.length?(e.target=void 0,{value:void 0,done:!0}):"keys"==n?{value:r,done:!1}:"values"==n?{value:t[r],done:!1}:{value:[r,t[r]],done:!1}}),"values");vp.Arguments=vp.Array,hp("keys"),hp("values"),hp("entries");var xp={exports:{}},_p=!s((function(){return Object.isExtensible(Object.preventExtensions({}))})),Sp=In,Ep=ot,Tp=S,Rp=ee,Ip=Ne.f,Op=Pt,Cp=br,Pp=_p,Ap=!1,jp=re("meta"),Mp=0,Lp=Object.isExtensible||function(){return!0},Np=function(e){Ip(e,jp,{value:{objectID:"O"+Mp++,weakData:{}}})},Up=xp.exports={enable:function(){Up.enable=function(){},Ap=!0;var e=Op.f,t=[].splice,n={};n[jp]=1,e(n).length&&(Op.f=function(n){for(var r=e(n),i=0,a=r.length;i<a;i++)if(r[i]===jp){t.call(r,i,1);break}return r},Sp({target:"Object",stat:!0,forced:!0},{getOwnPropertyNames:Cp.f}))},fastKey:function(e,t){if(!Tp(e))return"symbol"==typeof e?e:("string"==typeof e?"S":"P")+e;if(!Rp(e,jp)){if(!Lp(e))return"F";if(!t)return"E";Np(e)}return e[jp].objectID},getWeakData:function(e,t){if(!Rp(e,jp)){if(!Lp(e))return!0;if(!t)return!1;Np(e)}return e[jp].weakData},onFreeze:function(e){return Pp&&Ap&&Lp(e)&&!Rp(e,jp)&&Np(e),e}};Ep[jp]=!0;var Dp=In,Fp=i,Bp=kn,qp=$e.exports,Wp=xp.exports,zp=Is,Gp=as,Jp=S,Vp=s,$p=Us,Kp=Mr,Hp=fc,Yp=function(e,t,n){var r=-1!==e.indexOf("Map"),i=-1!==e.indexOf("Weak"),a=r?"set":"add",s=Fp[e],o=s&&s.prototype,u=s,c={},l=function(e){var t=o[e];qp(o,e,"add"==e?function(e){return t.call(this,0===e?0:e),this}:"delete"==e?function(e){return!(i&&!Jp(e))&&t.call(this,0===e?0:e)}:"get"==e?function(e){return i&&!Jp(e)?void 0:t.call(this,0===e?0:e)}:"has"==e?function(e){return!(i&&!Jp(e))&&t.call(this,0===e?0:e)}:function(e,n){return t.call(this,0===e?0:e,n),this})};if(Bp(e,"function"!=typeof s||!(i||o.forEach&&!Vp((function(){(new s).entries().next()})))))u=n.getConstructor(t,e,r,a),Wp.enable();else if(Bp(e,!0)){var f=new u,d=f[a](i?{}:-0,1)!=f,p=Vp((function(){f.has(1)})),h=$p((function(e){new s(e)})),v=!i&&Vp((function(){for(var e=new s,t=5;t--;)e[a](t,t);return!e.has(-0)}));h||((u=t((function(t,n){Gp(t,u,e);var i=Hp(new s,t,u);return null!=n&&zp(n,i[a],{that:i,AS_ENTRIES:r}),i}))).prototype=o,o.constructor=u),(p||v)&&(l("delete"),l("has"),r&&l("get")),(v||d)&&l(a),i&&o.clear&&delete o.clear}return c[e]=u,Dp({global:!0,forced:u!=s},c),Kp(u,e),i||n.setStrong(u,e,r),u},Qp=Ne.f,Xp=Hn,Zp=Ha,eh=Nr,th=as,nh=Is,rh=Zf,ih=is,ah=o,sh=xp.exports.fastKey,oh=xt.set,uh=xt.getterFor,ch={getConstructor:function(e,t,n,r){var i=e((function(e,a){th(e,i,t),oh(e,{type:t,index:Xp(null),first:void 0,last:void 0,size:0}),ah||(e.size=0),null!=a&&nh(a,e[r],{that:e,AS_ENTRIES:n})})),a=uh(t),s=function(e,t,n){var r,i,s=a(e),u=o(e,t);return u?u.value=n:(s.last=u={index:i=sh(t,!0),key:t,value:n,previous:r=s.last,next:void 0,removed:!1},s.first||(s.first=u),r&&(r.next=u),ah?s.size++:e.size++,"F"!==i&&(s.index[i]=u)),e},o=function(e,t){var n,r=a(e),i=sh(t);if("F"!==i)return r.index[i];for(n=r.first;n;n=n.next)if(n.key==t)return n};return Zp(i.prototype,{clear:function(){for(var e=a(this),t=e.index,n=e.first;n;)n.removed=!0,n.previous&&(n.previous=n.previous.next=void 0),delete t[n.index],n=n.next;e.first=e.last=void 0,ah?e.size=0:this.size=0},delete:function(e){var t=this,n=a(t),r=o(t,e);if(r){var i=r.next,s=r.previous;delete n.index[r.index],r.removed=!0,s&&(s.next=i),i&&(i.previous=s),n.first==r&&(n.first=i),n.last==r&&(n.last=s),ah?n.size--:t.size--}return!!r},forEach:function(e){for(var t,n=a(this),r=eh(e,arguments.length>1?arguments[1]:void 0,3);t=t?t.next:n.first;)for(r(t.value,t.key,this);t&&t.removed;)t=t.previous},has:function(e){return!!o(this,e)}}),Zp(i.prototype,n?{get:function(e){var t=o(this,e);return t&&t.value},set:function(e,t){return s(this,0===e?0:e,t)}}:{add:function(e){return s(this,e=0===e?0:e,e)}}),ah&&Qp(i.prototype,"size",{get:function(){return a(this).size}}),i},setStrong:function(e,t,n){var r=t+" Iterator",i=uh(t),a=uh(r);rh(e,t,(function(e,t){oh(this,{type:r,target:e,state:i(e),kind:t,last:void 0})}),(function(){for(var e=a(this),t=e.kind,n=e.last;n&&n.removed;)n=n.previous;return e.target&&(e.last=n=n?n.next:e.state.first)?"keys"==t?{value:n.key,done:!1}:"values"==t?{value:n.value,done:!1}:{value:[n.key,n.value],done:!1}:(e.target=void 0,{value:void 0,done:!0})}),n?"entries":"values",!n,!0),ih(t)}};Yp("Map",(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),ch);var lh=i,fh=Hu,dh=Xu,ph=wp,hh=Ve,vh=pe,yh=vh("iterator"),mh=vh("toStringTag"),gh=ph.values,bh=function(e,t){if(e){if(e[yh]!==gh)try{hh(e,yh,gh)}catch(t){e[yh]=gh}if(e[mh]||hh(e,mh,t),fh[t])for(var n in ph)if(e[n]!==ph[n])try{hh(e,n,ph[n])}catch(t){e[n]=ph[n]}}};for(var kh in fh)bh(lh[kh]&&lh[kh].prototype,kh);bh(dh,"DOMTokenList");var wh={},xh={exports:{}};!function(e){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.default=e.exports,e.exports.__esModule=!0}(xh);var _h={exports:{}};!function(e){function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}e.exports=function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e},e.exports.default=e.exports,e.exports.__esModule=!0}(_h);var Sh={exports:{}};!function(e){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e},e.exports.default=e.exports,e.exports.__esModule=!0}(Sh);var Eh={exports:{}},Th={exports:{}};!function(e){function t(n,r){return e.exports=t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},e.exports.default=e.exports,e.exports.__esModule=!0,t(n,r)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0}(Th),function(e){var t=Th.exports;e.exports=function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),n&&t(e,n)},e.exports.default=e.exports,e.exports.__esModule=!0}(Eh);var Rh={exports:{}},Ih={exports:{}};!function(e){function t(n){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(e.exports=t=function(e){return typeof e},e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=t=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.default=e.exports,e.exports.__esModule=!0),t(n)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0}(Ih),function(e){var t=Ih.exports.default,n=Sh.exports;e.exports=function(e,r){return!r||"object"!==t(r)&&"function"!=typeof r?n(e):r},e.exports.default=e.exports,e.exports.__esModule=!0}(Rh);var Oh={exports:{}};!function(e){function t(n){return e.exports=t=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},e.exports.default=e.exports,e.exports.__esModule=!0,t(n)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0}(Oh);var Ch={exports:{}};!function(e){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},e.exports.default=e.exports,e.exports.__esModule=!0}(Ch),Object.defineProperty(wh,"__esModule",{value:!0});var Ph=_h.exports,Ah=Sh.exports,jh=Eh.exports,Mh=Rh.exports,Lh=Oh.exports,Nh=Ch.exports;function Uh(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}var Dh=Uh(xh.exports),Fh=Uh(Ph),Bh=Uh(Ah),qh=Uh(jh),Wh=Uh(Mh),zh=Uh(Lh),Gh=Uh(Nh);function Jh(){}function Vh(){Vh.init.call(this)}function $h(e){return void 0===e._maxListeners?Vh.defaultMaxListeners:e._maxListeners}function Kh(e,t,n){if(t)e.call(n);else for(var r=e.length,i=nv(e,r),a=0;a<r;++a)i[a].call(n)}function Hh(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=nv(e,i),s=0;s<i;++s)a[s].call(n,r)}function Yh(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=nv(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function Qh(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=nv(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function Xh(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=nv(e,i),s=0;s<i;++s)a[s].apply(n,r)}function Zh(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new Jh,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=$h(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function ev(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function tv(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function nv(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function rv(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=zh.default(e);if(t){var i=zh.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Wh.default(this,n)}}Jh.prototype=Object.create(null),Vh.EventEmitter=Vh,Vh.usingDomains=!1,Vh.prototype.domain=void 0,Vh.prototype._events=void 0,Vh.prototype._maxListeners=void 0,Vh.defaultMaxListeners=10,Vh.init=function(){this.domain=null,Vh.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new Jh,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Vh.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},Vh.prototype.getMaxListeners=function(){return $h(this)},Vh.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:Kh(n,l,this);break;case 2:Hh(n,l,this,arguments[1]);break;case 3:Yh(n,l,this,arguments[1],arguments[2]);break;case 4:Qh(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];Xh(n,l,this,i)}return!0},Vh.prototype.addListener=function(e,t){return Zh(this,e,t,!1)},Vh.prototype.on=Vh.prototype.addListener,Vh.prototype.prependListener=function(e,t){return Zh(this,e,t,!0)},Vh.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,ev(this,e,t)),this},Vh.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,ev(this,e,t)),this},Vh.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new Jh:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new Jh,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},Vh.prototype.off=function(e,t){return this.removeListener(e,t)},Vh.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new Jh,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new Jh:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new Jh,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},Vh.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},Vh.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):tv.call(e,t)},Vh.prototype.listenerCount=tv,Vh.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var iv=function(e){qh.default(n,e);var t=rv(n);function n(e){var r;return Dh.default(this,n),r=t.call(this),Gh.default(Bh.default(r),"timeout",null),Gh.default(Bh.default(r),"startTimestamp",-1),r.minDelay=e.min,r.maxDelay=e.max,r.initialDelay=e.initial||0,r.maxAttemptsCount=e.maxAttemptsCount||0,r.maxAttemptsTime=e.maxAttemptsTime||0,r.randomness=e.randomness||0,r.inProgress=!1,r.attemptNum=0,r.prevDelay=0,r.currDelay=0,r}return Fh.default(n,[{key:"attempt",value:function(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.attemptNum++,this.emit("attempt",this)}},{key:"nextDelay",value:function(e){if("number"==typeof e)return this.prevDelay=0,this.currDelay=e,e;if(0==this.attemptNum)return this.initialDelay;if(1==this.attemptNum)return this.currDelay=this.minDelay,this.currDelay;this.prevDelay=this.currDelay;var t=this.currDelay+this.prevDelay;return this.maxDelay&&t>this.maxDelay&&(this.currDelay=this.maxDelay,t=this.maxDelay),this.currDelay=t,t}},{key:"randomize",value:function(e){var t=e*this.randomness,n=Math.round(Math.random()*t*2-t);return Math.max(0,e+n)}},{key:"scheduleAttempt",value:function(e){var t=this;if(this.maxAttemptsCount&&this.attemptNum>=this.maxAttemptsCount)return this.cleanup(),void this.emit("failed",new Error("Maximum attempt count limit reached"));var n=this.nextDelay(e);if(n=this.randomize(n),this.maxAttemptsTime&&this.startTimestamp+this.maxAttemptsTime<Date.now()+n)return this.cleanup(),void this.emit("failed",new Error("Maximum attempt time limit reached"));this.timeout=setTimeout((function(){return t.attempt()}),n)}},{key:"cleanup",value:function(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.inProgress=!1,this.attemptNum=0,this.prevDelay=0,this.currDelay=0}},{key:"start",value:function(){if(this.inProgress)throw new Error("Retrier is already in progress");this.inProgress=!0,this.startTimestamp=Date.now(),this.scheduleAttempt(this.initialDelay)}},{key:"cancel",value:function(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null,this.inProgress=!1,this.emit("cancelled"))}},{key:"succeeded",value:function(e){this.emit("succeeded",e)}},{key:"failed",value:function(e,t){if(this.timeout)throw new Error("Retrier attempt is already in progress");this.scheduleAttempt(t)}}]),n}(Vh),av=function(e){qh.default(n,e);var t=rv(n);function n(e){var r;return Dh.default(this,n),r=t.call(this),Gh.default(Bh.default(r),"resolve",(function(){})),Gh.default(Bh.default(r),"reject",(function(){})),r.retrier=new iv(e),r}return Fh.default(n,[{key:"run",value:function(e){var t=this;return this.retrier.on("attempt",(function(){e().then((function(e){return t.retrier.succeeded(e)})).catch((function(e){return t.retrier.failed(e)}))})),this.retrier.on("succeeded",(function(e){return t.resolve(e)})),this.retrier.on("cancelled",(function(){return t.reject(new Error("Cancelled"))})),this.retrier.on("failed",(function(e){return t.reject(e)})),new Promise((function(e,n){t.resolve=e,t.reject=n,t.retrier.start()}))}},{key:"cancel",value:function(){this.retrier.cancel()}}]),n}(Vh);function sv(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=zh.default(e);if(t){var i=zh.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Wh.default(this,n)}}function ov(e){return null!=e}var uv=function(e){qh.default(n,e);var t=sv(n);function n(e){var r;Dh.default(this,n),r=t.call(this),Gh.default(Bh.default(r),"backoffDelay",0),Gh.default(Bh.default(r),"nextBackoffDelay",0),Gh.default(Bh.default(r),"backoffNumber",0),Gh.default(Bh.default(r),"timeoutID",null),Gh.default(Bh.default(r),"maxNumberOfRetry",-1);var i=e=e||{},a=i.initialDelay,s=i.maxDelay,o=i.randomisationFactor,u=i.factor;if(ov(a)&&a<1)throw new Error("The initial timeout must be equal to or greater than 1.");if(ov(s)&&s<=1)throw new Error("The maximal timeout must be greater than 1.");if(ov(o)&&(o<0||o>1))throw new Error("The randomisation factor must be between 0 and 1.");if(ov(u)&&u<=1)throw new Error("Exponential factor should be greater than 1.");if(r.initialDelay=a||100,r.maxDelay=s||1e4,r.maxDelay<=r.initialDelay)throw new Error("The maximal backoff delay must be greater than the initial backoff delay.");return r.randomisationFactor=o||0,r.factor=u||2,r.reset(),r}return Fh.default(n,[{key:"backoff",value:function(e){null==this.timeoutID&&(this.backoffNumber===this.maxNumberOfRetry?(this.emit("fail",e),this.reset()):(this.backoffDelay=this.next(),this.timeoutID=setTimeout(this.onBackoff.bind(this),this.backoffDelay),this.emit("backoff",this.backoffNumber,this.backoffDelay,e)))}},{key:"reset",value:function(){this.backoffDelay=0,this.nextBackoffDelay=this.initialDelay,this.backoffNumber=0,this.timeoutID&&clearTimeout(this.timeoutID),this.timeoutID=null}},{key:"failAfter",value:function(e){if(e<=0)throw new Error("Expected a maximum number of retry greater than 0 but got ".concat(e));this.maxNumberOfRetry=e}},{key:"next",value:function(){this.backoffDelay=Math.min(this.nextBackoffDelay,this.maxDelay),this.nextBackoffDelay=this.backoffDelay*this.factor;var e=1+Math.random()*this.randomisationFactor;return Math.min(this.maxDelay,Math.round(this.backoffDelay*e))}},{key:"onBackoff",value:function(){this.timeoutID=null,this.emit("ready",this.backoffNumber,this.backoffDelay),this.backoffNumber++}}],[{key:"exponential",value:function(e){return new n(e)}}]),n}(Vh),cv=wh.AsyncRetrier=av;wh.Backoff=uv;var lv=wh.Retrier=iv;function fv(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return dv(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return dv(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function dv(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var pv=function(){function e(t,n){Ma(this,e),this.configuration=t,this.services=n,this.cache=new Map,this.cacheLifetime=100*this.configuration.httpCacheInterval,this.cleanupCache()}return Ta(e,[{key:"isExpired",value:function(e){return!this.cacheLifetime||Date.now()-e>this.cacheLifetime}},{key:"cleanupCache",value:function(){var e,t=fv(this.cache);try{for(t.s();!(e=t.n()).done;){var n=op(e.value,2),r=n[0],i=n[1];this.isExpired(i.timestamp)&&this.cache.delete(r)}}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(r,i){var a=[502,503,504];n&&a.push(429);var s=new lv(t.configuration.backoffConfiguration);s.on("attempt",(function(){e().then((function(e){return s.succeeded(e)})).catch((function(e){a.indexOf(e.status)>-1||"Twilsock disconnected"===e.message?s.failed(e):(s.removeAllListeners(),s.cancel(),i(e))}))})),s.on("succeeded",(function(e){r(e)})),s.on("cancelled",(function(e){return i(e)})),s.on("failed",(function(e){return i(e)})),s.start()}))}},{key:"get",value:function(){var e=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=this.cache.get(t))||this.isExpired(n.timestamp)){e.next=3;break}return e.abrupt("return",n.response);case 3:return r={},e.next=6,this.executeWithRetry((function(){return a.services.transport.get(t,r,a.configuration.productId)}),this.configuration.retryWhenThrottled);case 6:return i=e.sent,this.cache.set(t,{response:i,timestamp:Date.now()}),this.pokeTimer(),e.abrupt("return",i);case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()}]),e}(),hv=function e(){Ma(this,e)};ja(hv,"TYPING_INDICATOR","twilio.ipmsg.typing_indicator"),ja(hv,"NEW_MESSAGE","twilio.conversations.new_message"),ja(hv,"ADDED_TO_CONVERSATION","twilio.conversations.added_to_conversation"),ja(hv,"REMOVED_FROM_CONVERSATION","twilio.conversations.removed_from_conversation"),ja(hv,"CONSUMPTION_UPDATE","twilio.channel.consumption_update");var vv={},yv={exports:{}};!function(e){function t(e,t,n,r,i,a,s){try{var o=e[a](s),u=o.value}catch(e){return void n(e)}o.done?t(u):Promise.resolve(u).then(r,i)}e.exports=function(e){return function(){var n=this,r=arguments;return new Promise((function(i,a){var s=e.apply(n,r);function o(e){t(s,i,a,o,u,"next",e)}function u(e){t(s,i,a,o,u,"throw",e)}o(void 0)}))}},e.exports.default=e.exports,e.exports.__esModule=!0}(yv);var mv={exports:{}},gv={exports:{}};!function(e){var t=Oh.exports;e.exports=function(e,n){for(;!Object.prototype.hasOwnProperty.call(e,n)&&null!==(e=t(e)););return e},e.exports.default=e.exports,e.exports.__esModule=!0}(gv),function(e){var t=gv.exports;function n(r,i,a){return"undefined"!=typeof Reflect&&Reflect.get?(e.exports=n=Reflect.get,e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=n=function(e,n,r){var i=t(e,n);if(i){var a=Object.getOwnPropertyDescriptor(i,n);return a.get?a.get.call(r):a.value}},e.exports.default=e.exports,e.exports.__esModule=!0),n(r,i,a||r)}e.exports=n,e.exports.default=e.exports,e.exports.__esModule=!0}(mv);var bv=n(kl),kv=De,wv=function(){var e=kv(this),t="";return e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.dotAll&&(t+="s"),e.unicode&&(t+="u"),e.sticky&&(t+="y"),t},xv=$e.exports,_v=De,Sv=gr,Ev=s,Tv=wv,Rv="toString",Iv=RegExp.prototype,Ov=Iv.toString,Cv=Ev((function(){return"/a/b"!=Ov.call({source:"a",flags:"b"})})),Pv=Ov.name!=Rv;(Cv||Pv)&&xv(RegExp.prototype,Rv,(function(){var e=_v(this),t=Sv(e.source),n=e.flags;return"/"+t+"/"+Sv(void 0===n&&e instanceof RegExp&&!("flags"in Iv)?Tv.call(e):n)}),{unsafe:!0});var Av=In,jv=_,Mv=[].join,Lv=b!=Object,Nv=ec("join",",");Av({target:"Array",proto:!0,forced:Lv||!Nv},{join:function(e){return Mv.call(jv(this),void 0===e?",":e)}});var Uv=Hr.map;In({target:"Array",proto:!0,forced:!oa("map")},{map:function(e){return Uv(this,e,arguments.length>1?arguments[1]:void 0)}});var Dv={},Fv=S,Bv=Math.floor,qv=function(e){return!Fv(e)&&isFinite(e)&&Bv(e)===e};In({target:"Number",stat:!0},{isInteger:qv});var Wv={exports:{}},zv={exports:{}};!function(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.default=e.exports,e.exports.__esModule=!0}(zv);var Gv={exports:{}};!function(e){e.exports=function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,a=[],s=!0,o=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){o=!0,i=e}finally{try{s||null==n.return||n.return()}finally{if(o)throw i}}return a}},e.exports.default=e.exports,e.exports.__esModule=!0}(Gv);var Jv={exports:{}},Vv={exports:{}};!function(e){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r},e.exports.default=e.exports,e.exports.__esModule=!0}(Vv),function(e){var t=Vv.exports;e.exports=function(e,n){if(e){if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}},e.exports.default=e.exports,e.exports.__esModule=!0}(Jv);var $v={exports:{}};!function(e){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.default=e.exports,e.exports.__esModule=!0}($v),function(e){var t=zv.exports,n=Gv.exports,r=Jv.exports,i=$v.exports;e.exports=function(e,a){return t(e)||n(e,a)||r(e,a)||i()},e.exports.default=e.exports,e.exports.__esModule=!0}(Wv);var Kv=o,Hv=An,Yv=_,Qv=u.f,Xv=function(e){return function(t){for(var n,r=Yv(t),i=Hv(r),a=i.length,s=0,o=[];a>s;)n=i[s++],Kv&&!Qv.call(r,n)||o.push(e?[n,r[n]]:r[n]);return o}},Zv={entries:Xv(!0),values:Xv(!1)}.entries;In({target:"Object",stat:!0},{entries:function(e){return Zv(e)}});var ey={exports:{}},ty={exports:{}};!function(e){var t=Vv.exports;e.exports=function(e){if(Array.isArray(e))return t(e)},e.exports.default=e.exports,e.exports.__esModule=!0}(ty);var ny={exports:{}};!function(e){e.exports=function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)},e.exports.default=e.exports,e.exports.__esModule=!0}(ny);var ry={exports:{}};!function(e){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.default=e.exports,e.exports.__esModule=!0}(ry),function(e){var t=ty.exports,n=ny.exports,r=Jv.exports,i=ry.exports;e.exports=function(e){return t(e)||n(e)||r(e)||i()},e.exports.default=e.exports,e.exports.__esModule=!0}(ey);var iy=Vt.includes,ay=dp;In({target:"Array",proto:!0},{includes:function(e){return iy(this,e,arguments.length>1?arguments[1]:void 0)}}),ay("includes"),Object.defineProperty(Dv,"__esModule",{value:!0});var sy=Wv.exports,oy=ey.exports,uy=xh.exports,cy=Eh.exports,ly=Rh.exports,fy=Oh.exports;function dy(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}var py=dy(Ih.exports),hy=dy(sy),vy=dy(oy),yy=dy(uy),my=dy(cy),gy=dy(ly),by=dy(fy),ky=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return{checks:t}};function wy(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return xy(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return xy(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function xy(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var _y=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return ky((function(e){var n,r=!1,i=[],a=wy(t);try{for(a.s();!(n=a.n()).done;){var s=n.value;"string"!=typeof s?(r=r||e instanceof s,i.push("an instance of ".concat(s.name))):(r=r||py.default(e)===s,i.push("of type ".concat(s)))}}catch(e){a.e(e)}finally{a.f()}return[r,i]}))};function Sy(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Ey(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ey(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function Ey(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var Ty=ky((function(e){return["string"==typeof e&&e.length>0,"a non-empty string"]})),Ry=ky((function(e){return["number"==typeof e&&Number.isInteger(e)&&e>=0,"a non-negative integer"]})),Iy=ky((function(e){return["object"===py.default(e)&&null!==e&&!Array.isArray(e),"a pure object (non-null and non-array)"]}));function Oy(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=by.default(e);if(t){var i=by.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gy.default(this,n)}}function Cy(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Py(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Py(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function Py(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var Ay=function(e,t){if(t.length>e.length)throw new Error("Expected at most ".concat(e.length," argument(s), but got ").concat(t.length));for(;t.length<e.length;)t.push(void 0);var n,r=Cy(t.entries());try{for(r.s();!(n=r.n()).done;){var i=hy.default(n.value,2),a=i[0],s=i[1],o=Ny(e[a],s),u=hy.default(o,4),c=u[0],l=u[1],f=u[2],d=u[3];if(!c)throw new Error("Argument ".concat(a+1," is expected to be ").concat(f).concat(d," but got ").concat(l))}}catch(e){r.e(e)}finally{r.f()}},jy=function(e){var t,n,r;(["undefined","boolean","number","bigint","string"].includes(py.default(e))&&(n="string"==typeof e?'"'.concat(e,'"'):"".concat(e)),"object"===py.default(e)&&"Object"!==(null==e||null===(t=e.constructor)||void 0===t?void 0:t.name))&&(n=null===e?"null":"instance of ".concat(null==e||null===(r=e.constructor)||void 0===r?void 0:r.name));return n||(n=py.default(e)),n},My=function(e){var t,n=[],r=Cy(e);try{for(r.s();!(t=r.n()).done;){var i=t.value;n.push(Ly(i))}}catch(e){r.e(e)}finally{r.f()}return n},Ly=function(e){var t,n=[],r=Cy(Array.isArray(e)?e:[e]);try{for(r.s();!(t=r.n()).done;){var i=t.value;"string"!=typeof i&&"function"!=typeof i?n.push(i):n.push(_y(i))}}catch(e){r.e(e)}finally{r.f()}return n},Ny=function(e,t){var n,r,i=[],a=!1,s=Cy(e);try{for(s.s();!(r=s.n()).done;){var o,u=Cy(r.value.checks);try{for(u.s();!(o=u.n()).done;){var c=(0,o.value)(t),l=hy.default(c,3),f=l[0],d=l[1],p=l[2];a=a||f,!n&&p&&(n=p),d&&(i=[].concat(vy.default(i),"string"==typeof d?[d]:vy.default(d)))}}catch(e){u.e(e)}finally{u.f()}}}catch(e){s.e(e)}finally{s.f()}if(a)return[!0];var h=n||jy(t),v=i.length-1;return[!1,h,v>0?"".concat(i.slice(0,v).join(", ")," or ").concat(i[v]):i.join(", "),v>1?";":","]};function Uy(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Dy(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Dy(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function Dy(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}Dv.array=function(e,t){return ky((function(n){if(!Array.isArray(n))return[!1,"an array of ".concat(e)];var r,i=Uy(n.entries());try{for(i.s();!(r=i.n()).done;){var a=hy.default(r.value,2),s=a[0],o=a[1],u=Ny(Ly(t),o),c=hy.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"a valid array of ".concat(e," (index ").concat(s," should be ").concat(d,")"),"malformed array of ".concat(e," (index ").concat(s," is ").concat(f,")")]}}catch(e){i.e(e)}finally{i.f()}return[!0]}))};var Fy=Dv.custom=ky,By=Dv.literal=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return ky((function(e){var n,r=!1,i=[],a=Sy(t);try{for(a.s();!(n=a.n()).done;){var s=n.value;r=r||e===s,i.push("string"==typeof s?'"'.concat(s,'"'):"".concat(s))}}catch(e){a.e(e)}finally{a.f()}return[r,i]}))},qy=Dv.nonEmptyString=Ty,Wy=Dv.nonNegativeInteger=Ry,zy=Dv.objectSchema=function(e,t){return ky((function(n){if("object"!==py.default(n)||null===n||Array.isArray(n))return[!1,"valid ".concat(e," (should be a pure object)")];for(var r=0,i=Object.entries(t);r<i.length;r++){var a=hy.default(i[r],2),s=a[0],o=a[1],u=Ny(Ly(o),n[s]),c=hy.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"valid ".concat(e,' (key "').concat(s,'" should be ').concat(d,")"),"malformed ".concat(e,' (key "').concat(s,'" is ').concat(f,")")]}return[!0]}))},Gy=Dv.pureObject=Iy;Dv.runtimeTypeValidation=Ay,Dv.stringifyReceivedType=jy,Dv.type=_y;var Jy=Dv.validateConstructorTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=My(t);return function(e){return function(e){my.default(n,e);var t=Oy(n);function n(){yy.default(this,n);for(var e=arguments.length,i=new Array(e),a=0;a<e;a++)i[a]=arguments[a];return Ay(r,i),t.call.apply(t,[this].concat(i))}return n}(e)}},Vy=Dv.validateTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=My(t);return function(e,t,n){if("function"!=typeof n.value)throw new Error("The validateTypes decorator can only be applied to methods");var i=n.value;n.value=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Ay(r,t),i.apply(this,t)}}},$y=Dv.validateTypesAsync=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=My(t);return function(e,t,n){if("function"!=typeof n.value)throw new Error("The validateTypesAsync decorator can only be applied to methods");var i=n.value;n.value=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];try{Ay(r,t)}catch(e){return Promise.reject(e)}return i.apply(this,t)}}};Yp("Set",(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),ch);var Ky={exports:{}};!function(e,t){var n;n=function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=5)}([function(e,t,n){e.exports=function(e,t){var n,r,i;for(n=1;n<arguments.length;n++)for(i in r=arguments[n])r.hasOwnProperty(i)&&(e[i]=r[i]);return e}},function(e,t,n){var r=n(0);e.exports={build:function(e,t){var n,i,a,s=t.plugins;for(n=0,i=s.length;n<i;n++)(a=s[n]).methods&&r(e,a.methods),a.properties&&Object.defineProperties(e,a.properties)},hook:function(e,t,n){var r,i,a,s,o=e.config.plugins,u=[e.context];for(n&&(u=u.concat(n)),r=0,i=o.length;r<i;r++)s=o[r],(a=o[r][t])&&a.apply(s,u)}}},function(e,t,n){function r(e){if(0===e.length)return e;var t,n,r=e.split(/[_-]/);if(1===r.length&&r[0][0].toLowerCase()===r[0][0])return e;for(n=r[0].toLowerCase(),t=1;t<r.length;t++)n=n+r[t].charAt(0).toUpperCase()+r[t].substring(1).toLowerCase();return n}r.prepended=function(e,t){return e+(t=r(t))[0].toUpperCase()+t.substring(1)},e.exports=r},function(e,t,n){var r=n(0),i=n(2);function a(e,t){e=e||{},this.options=e,this.defaults=t.defaults,this.states=[],this.transitions=[],this.map={},this.lifecycle=this.configureLifecycle(),this.init=this.configureInitTransition(e.init),this.data=this.configureData(e.data),this.methods=this.configureMethods(e.methods),this.map[this.defaults.wildcard]={},this.configureTransitions(e.transitions||[]),this.plugins=this.configurePlugins(e.plugins,t.plugin)}r(a.prototype,{addState:function(e){this.map[e]||(this.states.push(e),this.addStateLifecycleNames(e),this.map[e]={})},addStateLifecycleNames:function(e){this.lifecycle.onEnter[e]=i.prepended("onEnter",e),this.lifecycle.onLeave[e]=i.prepended("onLeave",e),this.lifecycle.on[e]=i.prepended("on",e)},addTransition:function(e){this.transitions.indexOf(e)<0&&(this.transitions.push(e),this.addTransitionLifecycleNames(e))},addTransitionLifecycleNames:function(e){this.lifecycle.onBefore[e]=i.prepended("onBefore",e),this.lifecycle.onAfter[e]=i.prepended("onAfter",e),this.lifecycle.on[e]=i.prepended("on",e)},mapTransition:function(e){var t=e.name,n=e.from,r=e.to;return this.addState(n),"function"!=typeof r&&this.addState(r),this.addTransition(t),this.map[n][t]=e,e},configureLifecycle:function(){return{onBefore:{transition:"onBeforeTransition"},onAfter:{transition:"onAfterTransition"},onEnter:{state:"onEnterState"},onLeave:{state:"onLeaveState"},on:{transition:"onTransition"}}},configureInitTransition:function(e){return"string"==typeof e?this.mapTransition(r({},this.defaults.init,{to:e,active:!0})):"object"===Ca(e)?this.mapTransition(r({},this.defaults.init,e,{active:!0})):(this.addState(this.defaults.init.from),this.defaults.init)},configureData:function(e){return"function"==typeof e?e:"object"===Ca(e)?function(){return e}:function(){return{}}},configureMethods:function(e){return e||{}},configurePlugins:function(e,t){var n,r,i;for(n=0,r=(e=e||[]).length;n<r;n++)"function"==typeof(i=e[n])&&(e[n]=i=i()),i.configure&&i.configure(this);return e},configureTransitions:function(e){var t,n,r,i,a,s=this.defaults.wildcard;for(n=0;n<e.length;n++)for(r=e[n],i=Array.isArray(r.from)?r.from:[r.from||s],a=r.to||s,t=0;t<i.length;t++)this.mapTransition({name:r.name,from:i[t],to:a})},transitionFor:function(e,t){var n=this.defaults.wildcard;return this.map[e][t]||this.map[n][t]},transitionsFor:function(e){var t=this.defaults.wildcard;return Object.keys(this.map[e]).concat(Object.keys(this.map[t]))},allStates:function(){return this.states},allTransitions:function(){return this.transitions}}),e.exports=a},function(e,t,n){var r=n(0),i=n(6),a=n(1),s=[null,[]];function o(e,t){this.context=e,this.config=t,this.state=t.init.from,this.observers=[e]}r(o.prototype,{init:function(e){if(r(this.context,this.config.data.apply(this.context,e)),a.hook(this,"init"),this.config.init.active)return this.fire(this.config.init.name,[])},is:function(e){return Array.isArray(e)?e.indexOf(this.state)>=0:this.state===e},isPending:function(){return this.pending},can:function(e){return!this.isPending()&&!!this.seek(e)},cannot:function(e){return!this.can(e)},allStates:function(){return this.config.allStates()},allTransitions:function(){return this.config.allTransitions()},transitions:function(){return this.config.transitionsFor(this.state)},seek:function(e,t){var n=this.config.defaults.wildcard,r=this.config.transitionFor(this.state,e),i=r&&r.to;return"function"==typeof i?i.apply(this.context,t):i===n?this.state:i},fire:function(e,t){return this.transit(e,this.state,this.seek(e,t),t)},transit:function(e,t,n,r){var i=this.config.lifecycle,a=this.config.options.observeUnchangedState||t!==n;return n?this.isPending()?this.context.onPendingTransition(e,t,n):(this.config.addState(n),this.beginTransit(),r.unshift({transition:e,from:t,to:n,fsm:this.context}),this.observeEvents([this.observersForEvent(i.onBefore.transition),this.observersForEvent(i.onBefore[e]),a?this.observersForEvent(i.onLeave.state):s,a?this.observersForEvent(i.onLeave[t]):s,this.observersForEvent(i.on.transition),a?["doTransit",[this]]:s,a?this.observersForEvent(i.onEnter.state):s,a?this.observersForEvent(i.onEnter[n]):s,a?this.observersForEvent(i.on[n]):s,this.observersForEvent(i.onAfter.transition),this.observersForEvent(i.onAfter[e]),this.observersForEvent(i.on[e])],r)):this.context.onInvalidTransition(e,t,n)},beginTransit:function(){this.pending=!0},endTransit:function(e){return this.pending=!1,e},failTransit:function(e){throw this.pending=!1,e},doTransit:function(e){this.state=e.to},observe:function(e){if(2===e.length){var t={};t[e[0]]=e[1],this.observers.push(t)}else this.observers.push(e[0])},observersForEvent:function(e){for(var t,n=0,r=this.observers.length,i=[];n<r;n++)(t=this.observers[n])[e]&&i.push(t);return[e,i,!0]},observeEvents:function(e,t,n,r){if(0===e.length)return this.endTransit(void 0===r||r);var i=e[0][0],s=e[0][1],o=e[0][2];if(t[0].event=i,i&&o&&i!==n&&a.hook(this,"lifecycle",t),0===s.length)return e.shift(),this.observeEvents(e,t,i,r);var u=s.shift(),c=u[i].apply(u,t);return c&&"function"==typeof c.then?c.then(this.observeEvents.bind(this,e,t,i)).catch(this.failTransit.bind(this)):!1===c?this.endTransit(!1):this.observeEvents(e,t,i,c)},onInvalidTransition:function(e,t,n){throw new i("transition is invalid in current state",e,t,n,this.state)},onPendingTransition:function(e,t,n){throw new i("transition is invalid while previous transition is still in progress",e,t,n,this.state)}}),e.exports=o},function(e,t,n){var r=n(0),i=n(2),a=n(1),s=n(3),o=n(4),u={is:function(e){return this._fsm.is(e)},can:function(e){return this._fsm.can(e)},cannot:function(e){return this._fsm.cannot(e)},observe:function(){return this._fsm.observe(arguments)},transitions:function(){return this._fsm.transitions()},allTransitions:function(){return this._fsm.allTransitions()},allStates:function(){return this._fsm.allStates()},onInvalidTransition:function(e,t,n){return this._fsm.onInvalidTransition(e,t,n)},onPendingTransition:function(e,t,n){return this._fsm.onPendingTransition(e,t,n)}},c={state:{configurable:!1,enumerable:!0,get:function(){return this._fsm.state},set:function(e){throw Error("use transitions to change state")}}};function l(e){return f(this||{},e)}function f(e,t){return d(e,new s(t,l)),e._fsm(),e}function d(e,t){if("object"!==Ca(e)||Array.isArray(e))throw Error("StateMachine can only be applied to objects");a.build(e,t),Object.defineProperties(e,c),r(e,u),r(e,t.methods),t.allTransitions().forEach((function(t){e[i(t)]=function(){return this._fsm.fire(t,[].slice.call(arguments))}})),e._fsm=function(){this._fsm=new o(this,t),this._fsm.init(arguments)}}l.version="3.0.1",l.factory=function(){var e,t;"function"==typeof arguments[0]?(e=arguments[0],t=arguments[1]||{}):(e=function(){this._fsm.apply(this,arguments)},t=arguments[0]||{});var n=new s(t,l);return d(e.prototype,n),e.prototype._fsm.config=n,e},l.apply=f,l.defaults={wildcard:"*",init:{name:"init",from:"none"}},e.exports=l},function(e,t,n){e.exports=function(e,t,n,r,i){this.message=e,this.transition=t,this.from=n,this.to=r,this.current=i}}])},e.exports=n()}(Ky);var Hy={exports:{}},Yy="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(Yy){var Qy=new Uint8Array(16);Hy.exports=function(){return Yy(Qy),Qy}}else{var Xy=new Array(16);Hy.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),Xy[t]=e>>>((3&t)<<3)&255;return Xy}}for(var Zy=[],em=0;em<256;++em)Zy[em]=(em+256).toString(16).substr(1);var tm,nm,rm=function(e,t){var n=t||0,r=Zy;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")},im=Hy.exports,am=rm,sm=0,om=0;var um=function(e,t,n){var r=t&&n||0,i=t||[],a=(e=e||{}).node||tm,s=void 0!==e.clockseq?e.clockseq:nm;if(null==a||null==s){var o=im();null==a&&(a=tm=[1|o[0],o[1],o[2],o[3],o[4],o[5]]),null==s&&(s=nm=16383&(o[6]<<8|o[7]))}var u=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:om+1,l=u-sm+(c-om)/1e4;if(l<0&&void 0===e.clockseq&&(s=s+1&16383),(l<0||u>sm)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");sm=u,om=c,nm=s;var f=(1e4*(268435455&(u+=122192928e5))+c)%4294967296;i[r++]=f>>>24&255,i[r++]=f>>>16&255,i[r++]=f>>>8&255,i[r++]=255&f;var d=u/4294967296*1e4&268435455;i[r++]=d>>>8&255,i[r++]=255&d,i[r++]=d>>>24&15|16,i[r++]=d>>>16&255,i[r++]=s>>>8|128,i[r++]=255&s;for(var p=0;p<6;++p)i[r+p]=a[p];return t||am(i)},cm=Hy.exports,lm=rm;var fm=um,dm=function(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||cm)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var a=0;a<16;++a)t[r+a]=i[a];return t||lm(i)},pm=dm;pm.v1=fm,pm.v4=dm;var hm=pm,vm={},ym=s,mm=i.RegExp;vm.UNSUPPORTED_Y=ym((function(){var e=mm("a","y");return e.lastIndex=2,null!=e.exec("abcd")})),vm.BROKEN_CARET=ym((function(){var e=mm("^r","gy");return e.lastIndex=2,null!=e.exec("str")}));var gm,bm,km=s,wm=i.RegExp,xm=km((function(){var e=wm(".","s");return!(e.dotAll&&e.exec("\n")&&"s"===e.flags)})),_m=s,Sm=i.RegExp,Em=_m((function(){var e=Sm("(?<a>b)","g");return"b"!==e.exec("b").groups.a||"bc"!=="b".replace(e,"$<a>c")})),Tm=gr,Rm=wv,Im=vm,Om=z.exports,Cm=Hn,Pm=xt.get,Am=xm,jm=Em,Mm=RegExp.prototype.exec,Lm=Om("native-string-replace",String.prototype.replace),Nm=Mm,Um=(gm=/a/,bm=/b*/g,Mm.call(gm,"a"),Mm.call(bm,"a"),0!==gm.lastIndex||0!==bm.lastIndex),Dm=Im.UNSUPPORTED_Y||Im.BROKEN_CARET,Fm=void 0!==/()??/.exec("")[1];(Um||Fm||Dm||Am||jm)&&(Nm=function(e){var t,n,r,i,a,s,o,u=this,c=Pm(u),l=Tm(e),f=c.raw;if(f)return f.lastIndex=u.lastIndex,t=Nm.call(f,l),u.lastIndex=f.lastIndex,t;var d=c.groups,p=Dm&&u.sticky,h=Rm.call(u),v=u.source,y=0,m=l;if(p&&(-1===(h=h.replace("y","")).indexOf("g")&&(h+="g"),m=l.slice(u.lastIndex),u.lastIndex>0&&(!u.multiline||u.multiline&&"\n"!==l.charAt(u.lastIndex-1))&&(v="(?: "+v+")",m=" "+m,y++),n=new RegExp("^(?:"+v+")",h)),Fm&&(n=new RegExp("^"+v+"$(?!\\s)",h)),Um&&(r=u.lastIndex),i=Mm.call(p?n:u,m),p?i?(i.input=i.input.slice(y),i[0]=i[0].slice(y),i.index=u.lastIndex,u.lastIndex+=i[0].length):u.lastIndex=0:Um&&i&&(u.lastIndex=u.global?i.index+i[0].length:r),Fm&&i&&i.length>1&&Lm.call(i[0],n,(function(){for(a=1;a<arguments.length-2;a++)void 0===arguments[a]&&(i[a]=void 0)})),i&&d)for(i.groups=s=Cm(null),a=0;a<d.length;a++)s[(o=d[a])[0]]=i[o[1]];return i});var Bm=Nm;In({target:"RegExp",proto:!0,forced:/./.exec!==Bm},{exec:Bm});var qm=$e.exports,Wm=Bm,zm=s,Gm=pe,Jm=Ve,Vm=Gm("species"),$m=RegExp.prototype,Km=function(e,t,n,r){var i=Gm(e),a=!zm((function(){var t={};return t[i]=function(){return 7},7!=""[e](t)})),s=a&&!zm((function(){var t=!1,n=/a/;return"split"===e&&((n={}).constructor={},n.constructor[Vm]=function(){return n},n.flags="",n[i]=/./[i]),n.exec=function(){return t=!0,null},n[i](""),!t}));if(!a||!s||n){var o=/./[i],u=t(i,""[e],(function(e,t,n,r,i){var s=t.exec;return s===Wm||s===$m.exec?a&&!i?{done:!0,value:o.call(t,n,r)}:{done:!0,value:e.call(n,t,r)}:{done:!1}}));qm(String.prototype,e,u[0]),qm($m,i,u[1])}r&&Jm($m[i],"sham",!0)},Hm=mf.charAt,Ym=function(e,t,n){return t+(n?Hm(e,t).length:1)},Qm=Q,Xm=Math.floor,Zm="".replace,eg=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,tg=/\$([$&'`]|\d{1,2})/g,ng=y,rg=Bm,ig=function(e,t){var n=e.exec;if("function"==typeof n){var r=n.call(e,t);if("object"!=typeof r)throw TypeError("RegExp exec method returned something other than an Object or null");return r}if("RegExp"!==ng(e))throw TypeError("RegExp#exec called on incompatible receiver");return rg.call(e,t)},ag=Km,sg=s,og=De,ug=Mt,cg=Ut,lg=gr,fg=k,dg=Ym,pg=function(e,t,n,r,i,a){var s=n+e.length,o=r.length,u=tg;return void 0!==i&&(i=Qm(i),u=eg),Zm.call(a,u,(function(a,u){var c;switch(u.charAt(0)){case"$":return"$";case"&":return e;case"`":return t.slice(0,n);case"'":return t.slice(s);case"<":c=i[u.slice(1,-1)];break;default:var l=+u;if(0===l)return a;if(l>o){var f=Xm(l/10);return 0===f?a:f<=o?void 0===r[f-1]?u.charAt(1):r[f-1]+u.charAt(1):a}c=r[l-1]}return void 0===c?"":c}))},hg=ig,vg=pe("replace"),yg=Math.max,mg=Math.min,gg="$0"==="a".replace(/./,"$0"),bg=!!/./[vg]&&""===/./[vg]("a","$0");ag("replace",(function(e,t,n){var r=bg?"$":"$0";return[function(e,n){var r=fg(this),i=null==e?void 0:e[vg];return void 0!==i?i.call(e,r,n):t.call(lg(r),e,n)},function(e,i){var a=og(this),s=lg(e);if("string"==typeof i&&-1===i.indexOf(r)&&-1===i.indexOf("$<")){var o=n(t,a,s,i);if(o.done)return o.value}var u="function"==typeof i;u||(i=lg(i));var c=a.global;if(c){var l=a.unicode;a.lastIndex=0}for(var f=[];;){var d=hg(a,s);if(null===d)break;if(f.push(d),!c)break;""===lg(d[0])&&(a.lastIndex=dg(s,cg(a.lastIndex),l))}for(var p,h="",v=0,y=0;y<f.length;y++){d=f[y];for(var m=lg(d[0]),g=yg(mg(ug(d.index),s.length),0),b=[],k=1;k<d.length;k++)b.push(void 0===(p=d[k])?p:String(p));var w=d.groups;if(u){var x=[m].concat(b,g,s);void 0!==w&&x.push(w);var _=lg(i.apply(void 0,x))}else _=pg(m,s,g,b,w,i);g>=v&&(h+=s.slice(v,g)+_,v=g+m.length)}return h+s.slice(v)}]}),!!sg((function(){var e=/./;return e.exec=function(){var e=[];return e.groups={a:"7"},e},"7"!=="".replace(e,"$<a>")}))||!gg||bg);var kg,wg,xg,_g={exports:{}},Sg="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,Eg=Sg,Tg=o,Rg=i,Ig=S,Og=ee,Cg=qa,Pg=Ve,Ag=$e.exports,jg=Ne.f,Mg=Sf,Lg=Za,Ng=pe,Ug=re,Dg=Rg.Int8Array,Fg=Dg&&Dg.prototype,Bg=Rg.Uint8ClampedArray,qg=Bg&&Bg.prototype,Wg=Dg&&Mg(Dg),zg=Fg&&Mg(Fg),Gg=Object.prototype,Jg=Gg.isPrototypeOf,Vg=Ng("toStringTag"),$g=Ug("TYPED_ARRAY_TAG"),Kg=Ug("TYPED_ARRAY_CONSTRUCTOR"),Hg=Eg&&!!Lg&&"Opera"!==Cg(Rg.opera),Yg=!1,Qg={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},Xg={BigInt64Array:8,BigUint64Array:8},Zg=function(e){if(!Ig(e))return!1;var t=Cg(e);return Og(Qg,t)||Og(Xg,t)};for(kg in Qg)(xg=(wg=Rg[kg])&&wg.prototype)?Pg(xg,Kg,wg):Hg=!1;for(kg in Xg)(xg=(wg=Rg[kg])&&wg.prototype)&&Pg(xg,Kg,wg);if((!Hg||"function"!=typeof Wg||Wg===Function.prototype)&&(Wg=function(){throw TypeError("Incorrect invocation")},Hg))for(kg in Qg)Rg[kg]&&Lg(Rg[kg],Wg);if((!Hg||!zg||zg===Gg)&&(zg=Wg.prototype,Hg))for(kg in Qg)Rg[kg]&&Lg(Rg[kg].prototype,zg);if(Hg&&Mg(qg)!==zg&&Lg(qg,zg),Tg&&!Og(zg,Vg))for(kg in Yg=!0,jg(zg,Vg,{get:function(){return Ig(this)?this[$g]:void 0}}),Qg)Rg[kg]&&Pg(Rg[kg],$g,kg);var eb={NATIVE_ARRAY_BUFFER_VIEWS:Hg,TYPED_ARRAY_CONSTRUCTOR:Kg,TYPED_ARRAY_TAG:Yg&&$g,aTypedArray:function(e){if(Zg(e))return e;throw TypeError("Target is not a typed array")},aTypedArrayConstructor:function(e){if(Lg&&!Jg.call(Wg,e))throw TypeError("Target is not a typed array constructor");return e},exportTypedArrayMethod:function(e,t,n){if(Tg){if(n)for(var r in Qg){var i=Rg[r];if(i&&Og(i.prototype,e))try{delete i.prototype[e]}catch(e){}}zg[e]&&!n||Ag(zg,e,n?t:Hg&&Fg[e]||t)}},exportTypedArrayStaticMethod:function(e,t,n){var r,i;if(Tg){if(Lg){if(n)for(r in Qg)if((i=Rg[r])&&Og(i,e))try{delete i[e]}catch(e){}if(Wg[e]&&!n)return;try{return Ag(Wg,e,n?t:Hg&&Wg[e]||t)}catch(e){}}for(r in Qg)!(i=Rg[r])||i[e]&&!n||Ag(i,e,t)}},isView:function(e){if(!Ig(e))return!1;var t=Cg(e);return"DataView"===t||Og(Qg,t)||Og(Xg,t)},isTypedArray:Zg,TypedArray:Wg,TypedArrayPrototype:zg},tb=i,nb=s,rb=Us,ib=eb.NATIVE_ARRAY_BUFFER_VIEWS,ab=tb.ArrayBuffer,sb=tb.Int8Array,ob=!ib||!nb((function(){sb(1)}))||!nb((function(){new sb(-1)}))||!rb((function(e){new sb,new sb(null),new sb(1.5),new sb(e)}),!0)||nb((function(){return 1!==new sb(new ab(2),1,void 0).length})),ub=Mt,cb=Ut,lb=function(e){if(void 0===e)return 0;var t=ub(e),n=cb(t);if(t!==n)throw RangeError("Wrong length or index");return n},fb=Math.abs,db=Math.pow,pb=Math.floor,hb=Math.log,vb=Math.LN2,yb=Q,mb=qt,gb=Ut,bb=function(e){for(var t=yb(this),n=gb(t.length),r=arguments.length,i=mb(r>1?arguments[1]:void 0,n),a=r>2?arguments[2]:void 0,s=void 0===a?n:mb(a,n);s>i;)t[i++]=e;return t},kb=i,wb=o,xb=Sg,_b=Ve,Sb=Ha,Eb=s,Tb=as,Rb=Mt,Ib=Ut,Ob=lb,Cb={pack:function(e,t,n){var r,i,a,s=new Array(n),o=8*n-t-1,u=(1<<o)-1,c=u>>1,l=23===t?db(2,-24)-db(2,-77):0,f=e<0||0===e&&1/e<0?1:0,d=0;for((e=fb(e))!=e||e===1/0?(i=e!=e?1:0,r=u):(r=pb(hb(e)/vb),e*(a=db(2,-r))<1&&(r--,a*=2),(e+=r+c>=1?l/a:l*db(2,1-c))*a>=2&&(r++,a/=2),r+c>=u?(i=0,r=u):r+c>=1?(i=(e*a-1)*db(2,t),r+=c):(i=e*db(2,c-1)*db(2,t),r=0));t>=8;s[d++]=255&i,i/=256,t-=8);for(r=r<<t|i,o+=t;o>0;s[d++]=255&r,r/=256,o-=8);return s[--d]|=128*f,s},unpack:function(e,t){var n,r=e.length,i=8*r-t-1,a=(1<<i)-1,s=a>>1,o=i-7,u=r-1,c=e[u--],l=127&c;for(c>>=7;o>0;l=256*l+e[u],u--,o-=8);for(n=l&(1<<-o)-1,l>>=-o,o+=t;o>0;n=256*n+e[u],u--,o-=8);if(0===l)l=1-s;else{if(l===a)return n?NaN:c?-1/0:1/0;n+=db(2,t),l-=s}return(c?-1:1)*n*db(2,l-t)}},Pb=Sf,Ab=Za,jb=Pt.f,Mb=Ne.f,Lb=bb,Nb=Mr,Ub=xt.get,Db=xt.set,Fb="ArrayBuffer",Bb="DataView",qb="Wrong index",Wb=kb.ArrayBuffer,zb=Wb,Gb=kb.DataView,Jb=Gb&&Gb.prototype,Vb=Object.prototype,$b=kb.RangeError,Kb=Cb.pack,Hb=Cb.unpack,Yb=function(e){return[255&e]},Qb=function(e){return[255&e,e>>8&255]},Xb=function(e){return[255&e,e>>8&255,e>>16&255,e>>24&255]},Zb=function(e){return e[3]<<24|e[2]<<16|e[1]<<8|e[0]},ek=function(e){return Kb(e,23,4)},tk=function(e){return Kb(e,52,8)},nk=function(e,t){Mb(e.prototype,t,{get:function(){return Ub(this)[t]}})},rk=function(e,t,n,r){var i=Ob(n),a=Ub(e);if(i+t>a.byteLength)throw $b(qb);var s=Ub(a.buffer).bytes,o=i+a.byteOffset,u=s.slice(o,o+t);return r?u:u.reverse()},ik=function(e,t,n,r,i,a){var s=Ob(n),o=Ub(e);if(s+t>o.byteLength)throw $b(qb);for(var u=Ub(o.buffer).bytes,c=s+o.byteOffset,l=r(+i),f=0;f<t;f++)u[c+f]=l[a?f:t-f-1]};if(xb){if(!Eb((function(){Wb(1)}))||!Eb((function(){new Wb(-1)}))||Eb((function(){return new Wb,new Wb(1.5),new Wb(NaN),Wb.name!=Fb}))){for(var ak,sk=(zb=function(e){return Tb(this,zb),new Wb(Ob(e))}).prototype=Wb.prototype,ok=jb(Wb),uk=0;ok.length>uk;)(ak=ok[uk++])in zb||_b(zb,ak,Wb[ak]);sk.constructor=zb}Ab&&Pb(Jb)!==Vb&&Ab(Jb,Vb);var ck=new Gb(new zb(2)),lk=Jb.setInt8;ck.setInt8(0,2147483648),ck.setInt8(1,2147483649),!ck.getInt8(0)&&ck.getInt8(1)||Sb(Jb,{setInt8:function(e,t){lk.call(this,e,t<<24>>24)},setUint8:function(e,t){lk.call(this,e,t<<24>>24)}},{unsafe:!0})}else zb=function(e){Tb(this,zb,Fb);var t=Ob(e);Db(this,{bytes:Lb.call(new Array(t),0),byteLength:t}),wb||(this.byteLength=t)},Gb=function(e,t,n){Tb(this,Gb,Bb),Tb(e,zb,Bb);var r=Ub(e).byteLength,i=Rb(t);if(i<0||i>r)throw $b("Wrong offset");if(i+(n=void 0===n?r-i:Ib(n))>r)throw $b("Wrong length");Db(this,{buffer:e,byteLength:n,byteOffset:i}),wb||(this.buffer=e,this.byteLength=n,this.byteOffset=i)},wb&&(nk(zb,"byteLength"),nk(Gb,"buffer"),nk(Gb,"byteLength"),nk(Gb,"byteOffset")),Sb(Gb.prototype,{getInt8:function(e){return rk(this,1,e)[0]<<24>>24},getUint8:function(e){return rk(this,1,e)[0]},getInt16:function(e){var t=rk(this,2,e,arguments.length>1?arguments[1]:void 0);return(t[1]<<8|t[0])<<16>>16},getUint16:function(e){var t=rk(this,2,e,arguments.length>1?arguments[1]:void 0);return t[1]<<8|t[0]},getInt32:function(e){return Zb(rk(this,4,e,arguments.length>1?arguments[1]:void 0))},getUint32:function(e){return Zb(rk(this,4,e,arguments.length>1?arguments[1]:void 0))>>>0},getFloat32:function(e){return Hb(rk(this,4,e,arguments.length>1?arguments[1]:void 0),23)},getFloat64:function(e){return Hb(rk(this,8,e,arguments.length>1?arguments[1]:void 0),52)},setInt8:function(e,t){ik(this,1,e,Yb,t)},setUint8:function(e,t){ik(this,1,e,Yb,t)},setInt16:function(e,t){ik(this,2,e,Qb,t,arguments.length>2?arguments[2]:void 0)},setUint16:function(e,t){ik(this,2,e,Qb,t,arguments.length>2?arguments[2]:void 0)},setInt32:function(e,t){ik(this,4,e,Xb,t,arguments.length>2?arguments[2]:void 0)},setUint32:function(e,t){ik(this,4,e,Xb,t,arguments.length>2?arguments[2]:void 0)},setFloat32:function(e,t){ik(this,4,e,ek,t,arguments.length>2?arguments[2]:void 0)},setFloat64:function(e,t){ik(this,8,e,tk,t,arguments.length>2?arguments[2]:void 0)}});Nb(zb,Fb),Nb(Gb,Bb);var fk={ArrayBuffer:zb,DataView:Gb},dk=Mt,pk=function(e){var t=dk(e);if(t<0)throw RangeError("The argument can't be less than 0");return t},hk=function(e,t){var n=pk(e);if(n%t)throw RangeError("Wrong offset");return n},vk=Q,yk=Ut,mk=ms,gk=hs,bk=ls,kk=Nr,wk=eb.aTypedArrayConstructor,xk=In,_k=i,Sk=o,Ek=ob,Tk=eb,Rk=fk,Ik=as,Ok=h,Ck=Ve,Pk=qv,Ak=Ut,jk=lb,Mk=hk,Lk=we,Nk=ee,Uk=qa,Dk=S,Fk=q,Bk=Hn,qk=Za,Wk=Pt.f,zk=function(e){var t,n,r,i,a,s,o=vk(e),u=arguments.length,c=u>1?arguments[1]:void 0,l=void 0!==c,f=gk(o);if(null!=f&&!bk(f))for(s=(a=mk(o,f)).next,o=[];!(i=s.call(a)).done;)o.push(i.value);for(l&&u>2&&(c=kk(c,arguments[2],2)),n=yk(o.length),r=new(wk(this))(n),t=0;n>t;t++)r[t]=l?c(o[t],t):o[t];return r},Gk=Hr.forEach,Jk=is,Vk=Ne,$k=a,Kk=fc,Hk=xt.get,Yk=xt.set,Qk=Vk.f,Xk=$k.f,Zk=Math.round,ew=_k.RangeError,tw=Rk.ArrayBuffer,nw=Rk.DataView,rw=Tk.NATIVE_ARRAY_BUFFER_VIEWS,iw=Tk.TYPED_ARRAY_CONSTRUCTOR,aw=Tk.TYPED_ARRAY_TAG,sw=Tk.TypedArray,ow=Tk.TypedArrayPrototype,uw=Tk.aTypedArrayConstructor,cw=Tk.isTypedArray,lw="BYTES_PER_ELEMENT",fw="Wrong length",dw=function(e,t){for(var n=0,r=t.length,i=new(uw(e))(r);r>n;)i[n]=t[n++];return i},pw=function(e,t){Qk(e,t,{get:function(){return Hk(this)[t]}})},hw=function(e){var t;return e instanceof tw||"ArrayBuffer"==(t=Uk(e))||"SharedArrayBuffer"==t},vw=function(e,t){return cw(e)&&!Fk(t)&&t in e&&Pk(+t)&&t>=0},yw=function(e,t){return t=Lk(t),vw(e,t)?Ok(2,e[t]):Xk(e,t)},mw=function(e,t,n){return t=Lk(t),!(vw(e,t)&&Dk(n)&&Nk(n,"value"))||Nk(n,"get")||Nk(n,"set")||n.configurable||Nk(n,"writable")&&!n.writable||Nk(n,"enumerable")&&!n.enumerable?Qk(e,t,n):(e[t]=n.value,e)};Sk?(rw||($k.f=yw,Vk.f=mw,pw(ow,"buffer"),pw(ow,"byteOffset"),pw(ow,"byteLength"),pw(ow,"length")),xk({target:"Object",stat:!0,forced:!rw},{getOwnPropertyDescriptor:yw,defineProperty:mw}),_g.exports=function(e,t,n){var r=e.match(/\d+$/)[0]/8,i=e+(n?"Clamped":"")+"Array",a="get"+e,s="set"+e,o=_k[i],u=o,c=u&&u.prototype,l={},f=function(e,t){Qk(e,t,{get:function(){return function(e,t){var n=Hk(e);return n.view[a](t*r+n.byteOffset,!0)}(this,t)},set:function(e){return function(e,t,i){var a=Hk(e);n&&(i=(i=Zk(i))<0?0:i>255?255:255&i),a.view[s](t*r+a.byteOffset,i,!0)}(this,t,e)},enumerable:!0})};rw?Ek&&(u=t((function(e,t,n,a){return Ik(e,u,i),Kk(Dk(t)?hw(t)?void 0!==a?new o(t,Mk(n,r),a):void 0!==n?new o(t,Mk(n,r)):new o(t):cw(t)?dw(u,t):zk.call(u,t):new o(jk(t)),e,u)})),qk&&qk(u,sw),Gk(Wk(o),(function(e){e in u||Ck(u,e,o[e])})),u.prototype=c):(u=t((function(e,t,n,a){Ik(e,u,i);var s,o,c,l=0,d=0;if(Dk(t)){if(!hw(t))return cw(t)?dw(u,t):zk.call(u,t);s=t,d=Mk(n,r);var p=t.byteLength;if(void 0===a){if(p%r)throw ew(fw);if((o=p-d)<0)throw ew(fw)}else if((o=Ak(a)*r)+d>p)throw ew(fw);c=o/r}else c=jk(t),s=new tw(o=c*r);for(Yk(e,{buffer:s,byteOffset:d,byteLength:o,length:c,view:new nw(s)});l<c;)f(e,l++)})),qk&&qk(u,sw),c=u.prototype=Bk(ow)),c.constructor!==u&&Ck(c,"constructor",u),Ck(c,iw,u),aw&&Ck(c,aw,i),l[i]=u,xk({global:!0,forced:u!=o,sham:!rw},l),lw in u||Ck(u,lw,r),lw in c||Ck(c,lw,r),Jk(i)}):_g.exports=function(){},(0,_g.exports)("Uint8",(function(e){return function(t,n,r){return e(this,t,n,r)}}));var gw=Q,bw=qt,kw=Ut,ww=Math.min,xw=[].copyWithin||function(e,t){var n=gw(this),r=kw(n.length),i=bw(e,r),a=bw(t,r),s=arguments.length>2?arguments[2]:void 0,o=ww((void 0===s?r:bw(s,r))-a,r-i),u=1;for(a<i&&i<a+o&&(u=-1,a+=o-1,i+=o-1);o-- >0;)a in n?n[i]=n[a]:delete n[i],i+=u,a+=u;return n},_w=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("copyWithin",(function(e,t){return xw.call(_w(this),e,t,arguments.length>2?arguments[2]:void 0)}));var Sw=Hr.every,Ew=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("every",(function(e){return Sw(Ew(this),e,arguments.length>1?arguments[1]:void 0)}));var Tw=bb,Rw=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("fill",(function(e){return Tw.apply(Rw(this),arguments)}));var Iw=qs,Ow=eb.TYPED_ARRAY_CONSTRUCTOR,Cw=eb.aTypedArrayConstructor,Pw=function(e){return Cw(Iw(e,e[Ow]))},Aw=function(e,t){for(var n=0,r=t.length,i=new e(r);r>n;)i[n]=t[n++];return i},jw=Pw,Mw=Hr.filter,Lw=function(e,t){return Aw(jw(e),t)},Nw=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("filter",(function(e){var t=Mw(Nw(this),e,arguments.length>1?arguments[1]:void 0);return Lw(this,t)}));var Uw=Hr.find,Dw=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("find",(function(e){return Uw(Dw(this),e,arguments.length>1?arguments[1]:void 0)}));var Fw=Hr.findIndex,Bw=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("findIndex",(function(e){return Fw(Bw(this),e,arguments.length>1?arguments[1]:void 0)}));var qw=Hr.forEach,Ww=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("forEach",(function(e){qw(Ww(this),e,arguments.length>1?arguments[1]:void 0)}));var zw=Vt.includes,Gw=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("includes",(function(e){return zw(Gw(this),e,arguments.length>1?arguments[1]:void 0)}));var Jw=Vt.indexOf,Vw=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("indexOf",(function(e){return Jw(Vw(this),e,arguments.length>1?arguments[1]:void 0)}));var $w=i,Kw=eb,Hw=wp,Yw=pe("iterator"),Qw=$w.Uint8Array,Xw=Hw.values,Zw=Hw.keys,ex=Hw.entries,tx=Kw.aTypedArray,nx=Kw.exportTypedArrayMethod,rx=Qw&&Qw.prototype[Yw],ix=!!rx&&("values"==rx.name||null==rx.name),ax=function(){return Xw.call(tx(this))};nx("entries",(function(){return ex.call(tx(this))})),nx("keys",(function(){return Zw.call(tx(this))})),nx("values",ax,!ix),nx(Yw,ax,!ix);var sx=eb.aTypedArray,ox=[].join;(0,eb.exportTypedArrayMethod)("join",(function(e){return ox.apply(sx(this),arguments)}));var ux=_,cx=Mt,lx=Ut,fx=ec,dx=Math.min,px=[].lastIndexOf,hx=!!px&&1/[1].lastIndexOf(1,-0)<0,vx=fx("lastIndexOf"),yx=hx||!vx?function(e){if(hx)return px.apply(this,arguments)||0;var t=ux(this),n=lx(t.length),r=n-1;for(arguments.length>1&&(r=dx(r,cx(arguments[1]))),r<0&&(r=n+r);r>=0;r--)if(r in t&&t[r]===e)return r||0;return-1}:px,mx=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("lastIndexOf",(function(e){return yx.apply(mx(this),arguments)}));var gx=Hr.map,bx=Pw,kx=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("map",(function(e){return gx(kx(this),e,arguments.length>1?arguments[1]:void 0,(function(e,t){return new(bx(e))(t)}))}));var wx=On,xx=Q,_x=b,Sx=Ut,Ex=function(e){return function(t,n,r,i){wx(n);var a=xx(t),s=_x(a),o=Sx(a.length),u=e?o-1:0,c=e?-1:1;if(r<2)for(;;){if(u in s){i=s[u],u+=c;break}if(u+=c,e?u<0:o<=u)throw TypeError("Reduce of empty array with no initial value")}for(;e?u>=0:o>u;u+=c)u in s&&(i=n(i,s[u],u,a));return i}},Tx={left:Ex(!1),right:Ex(!0)},Rx=Tx.left,Ix=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("reduce",(function(e){return Rx(Ix(this),e,arguments.length,arguments.length>1?arguments[1]:void 0)}));var Ox=Tx.right,Cx=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("reduceRight",(function(e){return Ox(Cx(this),e,arguments.length,arguments.length>1?arguments[1]:void 0)}));var Px=eb.aTypedArray,Ax=eb.exportTypedArrayMethod,jx=Math.floor;Ax("reverse",(function(){for(var e,t=this,n=Px(t).length,r=jx(n/2),i=0;i<r;)e=t[i],t[i++]=t[--n],t[n]=e;return t}));var Mx=Ut,Lx=hk,Nx=Q,Ux=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("set",(function(e){Ux(this);var t=Lx(arguments.length>1?arguments[1]:void 0,1),n=this.length,r=Nx(e),i=Mx(r.length),a=0;if(i+t>n)throw RangeError("Wrong length");for(;a<i;)this[t+a]=r[a++]}),s((function(){new Int8Array(1).set({})})));var Dx=Pw,Fx=eb.aTypedArray,Bx=[].slice;(0,eb.exportTypedArrayMethod)("slice",(function(e,t){for(var n=Bx.call(Fx(this),e,t),r=Dx(this),i=0,a=n.length,s=new r(a);a>i;)s[i]=n[i++];return s}),s((function(){new Int8Array(1).slice()})));var qx=Hr.some,Wx=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("some",(function(e){return qx(Wx(this),e,arguments.length>1?arguments[1]:void 0)}));var zx=Math.floor,Gx=function(e,t){var n=e.length,r=zx(n/2);return n<8?Jx(e,t):Vx(Gx(e.slice(0,r),t),Gx(e.slice(r),t),t)},Jx=function(e,t){for(var n,r,i=e.length,a=1;a<i;){for(r=a,n=e[a];r&&t(e[r-1],n)>0;)e[r]=e[--r];r!==a++&&(e[r]=n)}return e},Vx=function(e,t,n){for(var r=e.length,i=t.length,a=0,s=0,o=[];a<r||s<i;)a<r&&s<i?o.push(n(e[a],t[s])<=0?e[a++]:t[s++]):o.push(a<r?e[a++]:t[s++]);return o},$x=Gx,Kx=I.match(/firefox\/(\d+)/i),Hx=!!Kx&&+Kx[1],Yx=/MSIE|Trident/.test(I),Qx=I.match(/AppleWebKit\/(\d+)\./),Xx=!!Qx&&+Qx[1],Zx=s,e_=On,t_=Ut,n_=$x,r_=Hx,i_=Yx,a_=L,s_=Xx,o_=eb.aTypedArray,u_=eb.exportTypedArrayMethod,c_=i.Uint16Array,l_=c_&&c_.prototype.sort,f_=!!l_&&!Zx((function(){var e=new c_(2);e.sort(null),e.sort({})})),d_=!!l_&&!Zx((function(){if(a_)return a_<74;if(r_)return r_<67;if(i_)return!0;if(s_)return s_<602;var e,t,n=new c_(516),r=Array(516);for(e=0;e<516;e++)t=e%4,n[e]=515-e,r[e]=e-2*t+3;for(n.sort((function(e,t){return(e/4|0)-(t/4|0)})),e=0;e<516;e++)if(n[e]!==r[e])return!0}));u_("sort",(function(e){var t=this;if(void 0!==e&&e_(e),d_)return l_.call(t,e);o_(t);var n,r=t_(t.length),i=Array(r);for(n=0;n<r;n++)i[n]=t[n];for(i=n_(t,function(e){return function(t,n){return void 0!==e?+e(t,n)||0:n!=n?-1:t!=t?1:0===t&&0===n?1/t>0&&1/n<0?1:-1:t>n}}(e)),n=0;n<r;n++)t[n]=i[n];return t}),!d_||f_);var p_=Ut,h_=qt,v_=Pw,y_=eb.aTypedArray;(0,eb.exportTypedArrayMethod)("subarray",(function(e,t){var n=y_(this),r=n.length,i=h_(e,r);return new(v_(n))(n.buffer,n.byteOffset+i*n.BYTES_PER_ELEMENT,p_((void 0===t?r:h_(t,r))-i))}));var m_=eb,g_=s,b_=i.Int8Array,k_=m_.aTypedArray,w_=m_.exportTypedArrayMethod,x_=[].toLocaleString,__=[].slice,S_=!!b_&&g_((function(){x_.call(new b_(1))}));w_("toLocaleString",(function(){return x_.apply(S_?__.call(k_(this)):k_(this),arguments)}),g_((function(){return[1,2].toLocaleString()!=new b_([1,2]).toLocaleString()}))||!g_((function(){b_.prototype.toLocaleString.call([1,2])})));var E_=eb.exportTypedArrayMethod,T_=s,R_=i.Uint8Array,I_=R_&&R_.prototype||{},O_=[].toString,C_=[].join;T_((function(){O_.call({})}))&&(O_=function(){return C_.call(this)});var P_=I_.toString!=O_;E_("toString",O_,P_);var A_=S,j_=y,M_=pe("match"),L_=function(e){var t;return A_(e)&&(void 0!==(t=e[M_])?!!t:"RegExp"==j_(e))},N_=Km,U_=L_,D_=De,F_=k,B_=qs,q_=Ym,W_=Ut,z_=gr,G_=ig,J_=Bm,V_=s,$_=vm.UNSUPPORTED_Y,K_=[].push,H_=Math.min,Y_=4294967295;N_("split",(function(e,t,n){var r;return r="c"=="abbc".split(/(b)*/)[1]||4!="test".split(/(?:)/,-1).length||2!="ab".split(/(?:ab)*/).length||4!=".".split(/(.?)(.?)/).length||".".split(/()()/).length>1||"".split(/.?/).length?function(e,n){var r=z_(F_(this)),i=void 0===n?Y_:n>>>0;if(0===i)return[];if(void 0===e)return[r];if(!U_(e))return t.call(r,e,i);for(var a,s,o,u=[],c=(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.unicode?"u":"")+(e.sticky?"y":""),l=0,f=new RegExp(e.source,c+"g");(a=J_.call(f,r))&&!((s=f.lastIndex)>l&&(u.push(r.slice(l,a.index)),a.length>1&&a.index<r.length&&K_.apply(u,a.slice(1)),o=a[0].length,l=s,u.length>=i));)f.lastIndex===a.index&&f.lastIndex++;return l===r.length?!o&&f.test("")||u.push(""):u.push(r.slice(l)),u.length>i?u.slice(0,i):u}:"0".split(void 0,0).length?function(e,n){return void 0===e&&0===n?[]:t.call(this,e,n)}:t,[function(t,n){var i=F_(this),a=null==t?void 0:t[e];return void 0!==a?a.call(t,i,n):r.call(z_(i),t,n)},function(e,i){var a=D_(this),s=z_(e),o=n(r,a,s,i,r!==t);if(o.done)return o.value;var u=B_(a,RegExp),c=a.unicode,l=(a.ignoreCase?"i":"")+(a.multiline?"m":"")+(a.unicode?"u":"")+($_?"g":"y"),f=new u($_?"^(?:"+a.source+")":a,l),d=void 0===i?Y_:i>>>0;if(0===d)return[];if(0===s.length)return null===G_(f,s)?[s]:[];for(var p=0,h=0,v=[];h<s.length;){f.lastIndex=$_?0:h;var y,m=G_(f,$_?s.slice(h):s);if(null===m||(y=H_(W_(f.lastIndex+($_?h:0)),s.length))===p)h=q_(s,h,c);else{if(v.push(s.slice(p,h)),v.length===d)return v;for(var g=1;g<=m.length-1;g++)if(v.push(m[g]),v.length===d)return v;h=p=y}}return v.push(s.slice(p)),v}]}),!!V_((function(){var e=/(?:)/,t=e.exec;e.exec=function(){return t.apply(this,arguments)};var n="ab".split(e);return 2!==n.length||"a"!==n[0]||"b"!==n[1]})),$_);var Q_={exports:{}},X_={exports:{}};!function(e){e.exports=function(e){return-1!==Function.toString.call(e).indexOf("[native code]")},e.exports.default=e.exports,e.exports.__esModule=!0}(X_);var Z_={exports:{}},eS={exports:{}};!function(e){e.exports=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}},e.exports.default=e.exports,e.exports.__esModule=!0}(eS),function(e){var t=Th.exports,n=eS.exports;function r(i,a,s){return n()?(e.exports=r=Reflect.construct,e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=r=function(e,n,r){var i=[null];i.push.apply(i,n);var a=new(Function.bind.apply(e,i));return r&&t(a,r.prototype),a},e.exports.default=e.exports,e.exports.__esModule=!0),r.apply(null,arguments)}e.exports=r,e.exports.default=e.exports,e.exports.__esModule=!0}(Z_),function(e){var t=Oh.exports,n=Th.exports,r=X_.exports,i=Z_.exports;function a(s){var o="function"==typeof Map?new Map:void 0;return e.exports=a=function(e){if(null===e||!r(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==o){if(o.has(e))return o.get(e);o.set(e,a)}function a(){return i(e,arguments,t(this).constructor)}return a.prototype=Object.create(e.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),n(a,e)},e.exports.default=e.exports,e.exports.__esModule=!0,a(s)}e.exports=a,e.exports.default=e.exports,e.exports.__esModule=!0}(Q_);var tS={exports:{}};!function(e,n){(function(){var r={function:!0,object:!0}["undefined"==typeof window?"undefined":Ca(window)]&&window||this,i=n,a=e&&!e.nodeType&&e,s=i&&a&&"object"==Ca(t)&&t;!s||s.global!==s&&s.window!==s&&s.self!==s||(r=s);var o=Math.pow(2,53)-1,u=/\bOpera/,c=Object.prototype,l=c.hasOwnProperty,f=c.toString;function d(e){return(e=String(e)).charAt(0).toUpperCase()+e.slice(1)}function p(e){return e=g(e),/^(?:webOS|i(?:OS|P))/.test(e)?e:d(e)}function h(e,t){for(var n in e)l.call(e,n)&&t(e[n],n,e)}function v(e){return null==e?d(e):f.call(e).slice(8,-1)}function y(e){return String(e).replace(/([ -])(?!$)/g,"$1?")}function m(e,t){var n=null;return function(e,t){var n=-1,r=e?e.length:0;if("number"==typeof r&&r>-1&&r<=o)for(;++n<r;)t(e[n],n,e);else h(e,t)}(e,(function(r,i){n=t(n,r,i,e)})),n}function g(e){return String(e).replace(/^ +| +$/g,"")}var b=function e(t){var n=r,i=t&&"object"==Ca(t)&&"String"!=v(t);i&&(n=t,t=null);var a=n.navigator||{},s=a.userAgent||"";t||(t=s);var o,c,l=i?!!a.likeChrome:/\bChrome\b/.test(t)&&!/internal|\n/i.test(f.toString()),d="Object",b=i?d:"ScriptBridgingProxyObject",k=i?d:"Environment",w=i&&n.java?"JavaPackage":v(n.java),x=i?d:"RuntimeObject",_=/\bJava/.test(w)&&n.java,S=_&&v(n.environment)==k,E=_?"a":"α",T=_?"b":"β",R=n.document||{},I=n.operamini||n.opera,O=u.test(O=i&&I?I["[[Class]]"]:v(I))?O:I=null,C=t,P=[],A=null,j=t==s,M=j&&I&&"function"==typeof I.version&&I.version(),L=m([{label:"EdgeHTML",pattern:"Edge"},"Trident",{label:"WebKit",pattern:"AppleWebKit"},"iCab","Presto","NetFront","Tasman","KHTML","Gecko"],(function(e,n){return e||RegExp("\\b"+(n.pattern||y(n))+"\\b","i").exec(t)&&(n.label||n)})),N=function(e){return m(e,(function(e,n){return e||RegExp("\\b"+(n.pattern||y(n))+"\\b","i").exec(t)&&(n.label||n)}))}(["Adobe AIR","Arora","Avant Browser","Breach","Camino","Electron","Epiphany","Fennec","Flock","Galeon","GreenBrowser","iCab","Iceweasel","K-Meleon","Konqueror","Lunascape","Maxthon",{label:"Microsoft Edge",pattern:"(?:Edge|Edg|EdgA|EdgiOS)"},"Midori","Nook Browser","PaleMoon","PhantomJS","Raven","Rekonq","RockMelt",{label:"Samsung Internet",pattern:"SamsungBrowser"},"SeaMonkey",{label:"Silk",pattern:"(?:Cloud9|Silk-Accelerated)"},"Sleipnir","SlimBrowser",{label:"SRWare Iron",pattern:"Iron"},"Sunrise","Swiftfox","Vivaldi","Waterfox","WebPositive",{label:"Yandex Browser",pattern:"YaBrowser"},{label:"UC Browser",pattern:"UCBrowser"},"Opera Mini",{label:"Opera Mini",pattern:"OPiOS"},"Opera",{label:"Opera",pattern:"OPR"},"Chromium","Chrome",{label:"Chrome",pattern:"(?:HeadlessChrome)"},{label:"Chrome Mobile",pattern:"(?:CriOS|CrMo)"},{label:"Firefox",pattern:"(?:Firefox|Minefield)"},{label:"Firefox for iOS",pattern:"FxiOS"},{label:"IE",pattern:"IEMobile"},{label:"IE",pattern:"MSIE"},"Safari"]),U=B([{label:"BlackBerry",pattern:"BB10"},"BlackBerry",{label:"Galaxy S",pattern:"GT-I9000"},{label:"Galaxy S2",pattern:"GT-I9100"},{label:"Galaxy S3",pattern:"GT-I9300"},{label:"Galaxy S4",pattern:"GT-I9500"},{label:"Galaxy S5",pattern:"SM-G900"},{label:"Galaxy S6",pattern:"SM-G920"},{label:"Galaxy S6 Edge",pattern:"SM-G925"},{label:"Galaxy S7",pattern:"SM-G930"},{label:"Galaxy S7 Edge",pattern:"SM-G935"},"Google TV","Lumia","iPad","iPod","iPhone","Kindle",{label:"Kindle Fire",pattern:"(?:Cloud9|Silk-Accelerated)"},"Nexus","Nook","PlayBook","PlayStation Vita","PlayStation","TouchPad","Transformer",{label:"Wii U",pattern:"WiiU"},"Wii","Xbox One",{label:"Xbox 360",pattern:"Xbox"},"Xoom"]),D=function(e){return m(e,(function(e,n,r){return e||(n[U]||n[/^[a-z]+(?: +[a-z]+\b)*/i.exec(U)]||RegExp("\\b"+y(r)+"(?:\\b|\\w*\\d)","i").exec(t))&&r}))}({Apple:{iPad:1,iPhone:1,iPod:1},Alcatel:{},Archos:{},Amazon:{Kindle:1,"Kindle Fire":1},Asus:{Transformer:1},"Barnes & Noble":{Nook:1},BlackBerry:{PlayBook:1},Google:{"Google TV":1,Nexus:1},HP:{TouchPad:1},HTC:{},Huawei:{},Lenovo:{},LG:{},Microsoft:{Xbox:1,"Xbox One":1},Motorola:{Xoom:1},Nintendo:{"Wii U":1,Wii:1},Nokia:{Lumia:1},Oppo:{},Samsung:{"Galaxy S":1,"Galaxy S2":1,"Galaxy S3":1,"Galaxy S4":1},Sony:{PlayStation:1,"PlayStation Vita":1},Xiaomi:{Mi:1,Redmi:1}}),F=function(e){return m(e,(function(e,n){var r=n.pattern||y(n);return!e&&(e=RegExp("\\b"+r+"(?:/[\\d.]+|[ \\w.]*)","i").exec(t))&&(e=function(e,t,n){var r={"10.0":"10",6.4:"10 Technical Preview",6.3:"8.1",6.2:"8",6.1:"Server 2008 R2 / 7","6.0":"Server 2008 / Vista",5.2:"Server 2003 / XP 64-bit",5.1:"XP",5.01:"2000 SP1","5.0":"2000","4.0":"NT","4.90":"ME"};return t&&n&&/^Win/i.test(e)&&!/^Windows Phone /i.test(e)&&(r=r[/[\d.]+$/.exec(e)])&&(e="Windows "+r),e=String(e),t&&n&&(e=e.replace(RegExp(t,"i"),n)),p(e.replace(/ ce$/i," CE").replace(/\bhpw/i,"web").replace(/\bMacintosh\b/,"Mac OS").replace(/_PowerPC\b/i," OS").replace(/\b(OS X) [^ \d]+/i,"$1").replace(/\bMac (OS X)\b/,"$1").replace(/\/(\d)/," $1").replace(/_/g,".").replace(/(?: BePC|[ .]*fc[ \d.]+)$/i,"").replace(/\bx86\.64\b/gi,"x86_64").replace(/\b(Windows Phone) OS\b/,"$1").replace(/\b(Chrome OS \w+) [\d.]+\b/,"$1").split(" on ")[0])}(e,r,n.label||n)),e}))}(["Windows Phone","KaiOS","Android","CentOS",{label:"Chrome OS",pattern:"CrOS"},"Debian",{label:"DragonFly BSD",pattern:"DragonFly"},"Fedora","FreeBSD","Gentoo","Haiku","Kubuntu","Linux Mint","OpenBSD","Red Hat","SuSE","Ubuntu","Xubuntu","Cygwin","Symbian OS","hpwOS","webOS ","webOS","Tablet OS","Tizen","Linux","Mac OS X","Macintosh","Mac","Windows 98;","Windows "]);function B(e){return m(e,(function(e,n){var r=n.pattern||y(n);return!e&&(e=RegExp("\\b"+r+" *\\d+[.\\w_]*","i").exec(t)||RegExp("\\b"+r+" *\\w+-[\\w]*","i").exec(t)||RegExp("\\b"+r+"(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)","i").exec(t))&&((e=String(n.label&&!RegExp(r,"i").test(n.label)?n.label:e).split("/"))[1]&&!/[\d.]+/.test(e[0])&&(e[0]+=" "+e[1]),n=n.label||n,e=p(e[0].replace(RegExp(r,"i"),n).replace(RegExp("; *(?:"+n+"[_-])?","i")," ").replace(RegExp("("+n+")[-_.]?(\\w)","i"),"$1 $2"))),e}))}function q(e){return m(e,(function(e,n){return e||(RegExp(n+"(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)","i").exec(t)||0)[1]||null}))}if(L&&(L=[L]),/\bAndroid\b/.test(F)&&!U&&(o=/\bAndroid[^;]*;(.*?)(?:Build|\) AppleWebKit)\b/i.exec(t))&&(U=g(o[1]).replace(/^[a-z]{2}-[a-z]{2};\s*/i,"")||null),D&&!U?U=B([D]):D&&U&&(U=U.replace(RegExp("^("+y(D)+")[-_.\\s]","i"),D+" ").replace(RegExp("^("+y(D)+")[-_.]?(\\w)","i"),D+" $2")),(o=/\bGoogle TV\b/.exec(U))&&(U=o[0]),/\bSimulator\b/i.test(t)&&(U=(U?U+" ":"")+"Simulator"),"Opera Mini"==N&&/\bOPiOS\b/.test(t)&&P.push("running in Turbo/Uncompressed mode"),"IE"==N&&/\blike iPhone OS\b/.test(t)?(D=(o=e(t.replace(/like iPhone OS/,""))).manufacturer,U=o.product):/^iP/.test(U)?(N||(N="Safari"),F="iOS"+((o=/ OS ([\d_]+)/i.exec(t))?" "+o[1].replace(/_/g,"."):"")):"Konqueror"==N&&/^Linux\b/i.test(F)?F="Kubuntu":D&&"Google"!=D&&(/Chrome/.test(N)&&!/\bMobile Safari\b/i.test(t)||/\bVita\b/.test(U))||/\bAndroid\b/.test(F)&&/^Chrome/.test(N)&&/\bVersion\//i.test(t)?(N="Android Browser",F=/\bAndroid\b/.test(F)?F:"Android"):"Silk"==N?(/\bMobi/i.test(t)||(F="Android",P.unshift("desktop mode")),/Accelerated *= *true/i.test(t)&&P.unshift("accelerated")):"UC Browser"==N&&/\bUCWEB\b/.test(t)?P.push("speed mode"):"PaleMoon"==N&&(o=/\bFirefox\/([\d.]+)\b/.exec(t))?P.push("identifying as Firefox "+o[1]):"Firefox"==N&&(o=/\b(Mobile|Tablet|TV)\b/i.exec(t))?(F||(F="Firefox OS"),U||(U=o[1])):!N||(o=!/\bMinefield\b/i.test(t)&&/\b(?:Firefox|Safari)\b/.exec(N))?(N&&!U&&/[\/,]|^[^(]+?\)/.test(t.slice(t.indexOf(o+"/")+8))&&(N=null),(o=U||D||F)&&(U||D||/\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(F))&&(N=/[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(F)?F:o)+" Browser")):"Electron"==N&&(o=(/\bChrome\/([\d.]+)\b/.exec(t)||0)[1])&&P.push("Chromium "+o),M||(M=q(["(?:Cloud9|CriOS|CrMo|Edge|Edg|EdgA|EdgiOS|FxiOS|HeadlessChrome|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$)|UCBrowser|YaBrowser)","Version",y(N),"(?:Firefox|Minefield|NetFront)"])),(o=("iCab"==L&&parseFloat(M)>3?"WebKit":/\bOpera\b/.test(N)&&(/\bOPR\b/.test(t)?"Blink":"Presto"))||/\b(?:Midori|Nook|Safari)\b/i.test(t)&&!/^(?:Trident|EdgeHTML)$/.test(L)&&"WebKit"||!L&&/\bMSIE\b/i.test(t)&&("Mac OS"==F?"Tasman":"Trident")||"WebKit"==L&&/\bPlayStation\b(?! Vita\b)/i.test(N)&&"NetFront")&&(L=[o]),"IE"==N&&(o=(/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(t)||0)[1])?(N+=" Mobile",F="Windows Phone "+(/\+$/.test(o)?o:o+".x"),P.unshift("desktop mode")):/\bWPDesktop\b/i.test(t)?(N="IE Mobile",F="Windows Phone 8.x",P.unshift("desktop mode"),M||(M=(/\brv:([\d.]+)/.exec(t)||0)[1])):"IE"!=N&&"Trident"==L&&(o=/\brv:([\d.]+)/.exec(t))&&(N&&P.push("identifying as "+N+(M?" "+M:"")),N="IE",M=o[1]),j){if(function(e,t){var n=null!=e?Ca(e[t]):"number";return!(/^(?:boolean|number|string|undefined)$/.test(n)||"object"==n&&!e[t])}(n,"global"))if(_&&(C=(o=_.lang.System).getProperty("os.arch"),F=F||o.getProperty("os.name")+" "+o.getProperty("os.version")),S){try{M=n.require("ringo/engine").version.join("."),N="RingoJS"}catch(e){(o=n.system)&&o.global.system==n.system&&(N="Narwhal",F||(F=o[0].os||null))}N||(N="Rhino")}else"object"==Ca(n.process)&&!n.process.browser&&(o=n.process)&&("object"==Ca(o.versions)&&("string"==typeof o.versions.electron?(P.push("Node "+o.versions.node),N="Electron",M=o.versions.electron):"string"==typeof o.versions.nw&&(P.push("Chromium "+M,"Node "+o.versions.node),N="NW.js",M=o.versions.nw)),N||(N="Node.js",C=o.arch,F=o.platform,M=(M=/[\d.]+/.exec(o.version))?M[0]:null));else v(o=n.runtime)==b?(N="Adobe AIR",F=o.flash.system.Capabilities.os):v(o=n.phantom)==x?(N="PhantomJS",M=(o=o.version||null)&&o.major+"."+o.minor+"."+o.patch):"number"==typeof R.documentMode&&(o=/\bTrident\/(\d+)/i.exec(t))?(M=[M,R.documentMode],(o=+o[1]+4)!=M[1]&&(P.push("IE "+M[1]+" mode"),L&&(L[1]=""),M[1]=o),M="IE"==N?String(M[1].toFixed(1)):M[0]):"number"==typeof R.documentMode&&/^(?:Chrome|Firefox)\b/.test(N)&&(P.push("masking as "+N+" "+M),N="IE",M="11.0",L=["Trident"],F="Windows");F=F&&p(F)}if(M&&(o=/(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(M)||/(?:alpha|beta)(?: ?\d)?/i.exec(t+";"+(j&&a.appMinorVersion))||/\bMinefield\b/i.test(t)&&"a")&&(A=/b/i.test(o)?"beta":"alpha",M=M.replace(RegExp(o+"\\+?$"),"")+("beta"==A?T:E)+(/\d+\+?/.exec(o)||"")),"Fennec"==N||"Firefox"==N&&/\b(?:Android|Firefox OS|KaiOS)\b/.test(F))N="Firefox Mobile";else if("Maxthon"==N&&M)M=M.replace(/\.[\d.]+/,".x");else if(/\bXbox\b/i.test(U))"Xbox 360"==U&&(F=null),"Xbox 360"==U&&/\bIEMobile\b/.test(t)&&P.unshift("mobile mode");else if(!/^(?:Chrome|IE|Opera)$/.test(N)&&(!N||U||/Browser|Mobi/.test(N))||"Windows CE"!=F&&!/Mobi/i.test(t))if("IE"==N&&j)try{null===n.external&&P.unshift("platform preview")}catch(e){P.unshift("embedded")}else(/\bBlackBerry\b/.test(U)||/\bBB10\b/.test(t))&&(o=(RegExp(U.replace(/ +/g," *")+"/([.\\d]+)","i").exec(t)||0)[1]||M)?(F=((o=[o,/BB10/.test(t)])[1]?(U=null,D="BlackBerry"):"Device Software")+" "+o[0],M=null):this!=h&&"Wii"!=U&&(j&&I||/Opera/.test(N)&&/\b(?:MSIE|Firefox)\b/i.test(t)||"Firefox"==N&&/\bOS X (?:\d+\.){2,}/.test(F)||"IE"==N&&(F&&!/^Win/.test(F)&&M>5.5||/\bWindows XP\b/.test(F)&&M>8||8==M&&!/\bTrident\b/.test(t)))&&!u.test(o=e.call(h,t.replace(u,"")+";"))&&o.name&&(o="ing as "+o.name+((o=o.version)?" "+o:""),u.test(N)?(/\bIE\b/.test(o)&&"Mac OS"==F&&(F=null),o="identify"+o):(o="mask"+o,N=O?p(O.replace(/([a-z])([A-Z])/g,"$1 $2")):"Opera",/\bIE\b/.test(o)&&(F=null),j||(M=null)),L=["Presto"],P.push(o));else N+=" Mobile";(o=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(t)||0)[1])&&(o=[parseFloat(o.replace(/\.(\d)$/,".0$1")),o],"Safari"==N&&"+"==o[1].slice(-1)?(N="WebKit Nightly",A="alpha",M=o[1].slice(0,-1)):M!=o[1]&&M!=(o[2]=(/\bSafari\/([\d.]+\+?)/i.exec(t)||0)[1])||(M=null),o[1]=(/\b(?:Headless)?Chrome\/([\d.]+)/i.exec(t)||0)[1],537.36==o[0]&&537.36==o[2]&&parseFloat(o[1])>=28&&"WebKit"==L&&(L=["Blink"]),j&&(l||o[1])?(L&&(L[1]="like Chrome"),o=o[1]||((o=o[0])<530?1:o<532?2:o<532.05?3:o<533?4:o<534.03?5:o<534.07?6:o<534.1?7:o<534.13?8:o<534.16?9:o<534.24?10:o<534.3?11:o<535.01?12:o<535.02?"13+":o<535.07?15:o<535.11?16:o<535.19?17:o<536.05?18:o<536.1?19:o<537.01?20:o<537.11?"21+":o<537.13?23:o<537.18?24:o<537.24?25:o<537.36?26:"Blink"!=L?"27":"28")):(L&&(L[1]="like Safari"),o=(o=o[0])<400?1:o<500?2:o<526?3:o<533?4:o<534?"4+":o<535?5:o<537?6:o<538?7:o<601?8:o<602?9:o<604?10:o<606?11:o<608?12:"12"),L&&(L[1]+=" "+(o+="number"==typeof o?".x":/[.+]/.test(o)?"":"+")),"Safari"==N&&(!M||parseInt(M)>45)?M=o:"Chrome"==N&&/\bHeadlessChrome/i.test(t)&&P.unshift("headless")),"Opera"==N&&(o=/\bzbov|zvav$/.exec(F))?(N+=" ",P.unshift("desktop mode"),"zvav"==o?(N+="Mini",M=null):N+="Mobile",F=F.replace(RegExp(" *"+o+"$"),"")):"Safari"==N&&/\bChrome\b/.exec(L&&L[1])?(P.unshift("desktop mode"),N="Chrome Mobile",M=null,/\bOS X\b/.test(F)?(D="Apple",F="iOS 4.3+"):F=null):/\bSRWare Iron\b/.test(N)&&!M&&(M=q("Chrome")),M&&0==M.indexOf(o=/[\d.]+$/.exec(F))&&t.indexOf("/"+o+"-")>-1&&(F=g(F.replace(o,""))),F&&-1!=F.indexOf(N)&&!RegExp(N+" OS").test(F)&&(F=F.replace(RegExp(" *"+y(N)+" *"),"")),L&&!/\b(?:Avant|Nook)\b/.test(N)&&(/Browser|Lunascape|Maxthon/.test(N)||"Safari"!=N&&/^iOS/.test(F)&&/\bSafari\b/.test(L[1])||/^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|SRWare Iron|Vivaldi|Web)/.test(N)&&L[1])&&(o=L[L.length-1])&&P.push(o),P.length&&(P=["("+P.join("; ")+")"]),D&&U&&U.indexOf(D)<0&&P.push("on "+D),U&&P.push((/^on /.test(P[P.length-1])?"":"on ")+U),F&&(o=/ ([\d.+]+)$/.exec(F),c=o&&"/"==F.charAt(F.length-o[0].length-1),F={architecture:32,family:o&&!c?F.replace(o[0],""):F,version:o?o[1]:null,toString:function(){var e=this.version;return this.family+(e&&!c?" "+e:"")+(64==this.architecture?" 64-bit":"")}}),(o=/\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(C))&&!/\bi686\b/i.test(C)?(F&&(F.architecture=64,F.family=F.family.replace(RegExp(" *"+o),"")),N&&(/\bWOW64\b/i.test(t)||j&&/\w(?:86|32)$/.test(a.cpuClass||a.platform)&&!/\bWin64; x64\b/i.test(t))&&P.unshift("32-bit")):F&&/^OS X/.test(F.family)&&"Chrome"==N&&parseFloat(M)>=39&&(F.architecture=64),t||(t=null);var W={};return W.description=t,W.layout=L&&L[0],W.manufacturer=D,W.name=N,W.prerelease=A,W.product=U,W.ua=t,W.version=N&&M,W.os=F||{architecture:null,family:null,version:null,toString:function(){return"null"}},W.parse=e,W.toString=function(){return this.description||""},W.version&&P.unshift(M),W.name&&P.unshift(N),F&&N&&(F!=String(F).split(" ")[0]||F!=N.split(" ")[0]&&!U)&&P.push(U?"("+F+")":"on "+F),P.length&&(W.description=P.join(" ")),W}();i&&a?h(b,(function(e,t){i[t]=e})):r.platform=b}).call(t)}(tS,tS.exports);var nS=De,rS=Ut,iS=gr,aS=k,sS=Ym,oS=ig;Km("match",(function(e,t,n){return[function(t){var n=aS(this),r=null==t?void 0:t[e];return void 0!==r?r.call(t,n):new RegExp(t)[e](iS(n))},function(e){var r=nS(this),i=iS(e),a=n(t,r,i);if(a.done)return a.value;if(!r.global)return oS(r,i);var s=r.unicode;r.lastIndex=0;for(var o,u=[],c=0;null!==(o=oS(r,i));){var l=iS(o[0]);u[c]=l,""===l&&(r.lastIndex=sS(i,rS(r.lastIndex),s)),c++}return 0===c?null:u}]}));var uS=Object.is||function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t},cS=De,lS=k,fS=uS,dS=gr,pS=ig;Km("search",(function(e,t,n){return[function(t){var n=lS(this),r=null==t?void 0:t[e];return void 0!==r?r.call(t,n):new RegExp(t)[e](dS(n))},function(e){var r=cS(this),i=dS(e),a=n(t,r,i);if(a.done)return a.value;var s=r.lastIndex;fS(s,0)||(r.lastIndex=0);var o=pS(r,i);return fS(r.lastIndex,s)||(r.lastIndex=s),null===o?-1:o.index}]}));var hS=In,vS=qt,yS=Mt,mS=Ut,gS=Q,bS=qr,kS=ga,wS=oa("splice"),xS=Math.max,_S=Math.min,SS=9007199254740991,ES="Maximum allowed length exceeded";hS({target:"Array",proto:!0,forced:!wS},{splice:function(e,t){var n,r,i,a,s,o,u=gS(this),c=mS(u.length),l=vS(e,c),f=arguments.length;if(0===f?n=r=0:1===f?(n=0,r=c-l):(n=f-2,r=_S(xS(yS(t),0),c-l)),c+n-r>SS)throw TypeError(ES);for(i=bS(u,r),a=0;a<r;a++)(s=l+a)in u&&kS(i,a,u[s]);if(i.length=r,n<r){for(a=l;a<c-r;a++)o=a+n,(s=a+r)in u?u[o]=u[s]:delete u[o];for(a=c;a>c-r+n;a--)delete u[a-1]}else if(n>r)for(a=c-r;a>l;a--)o=a+n-1,(s=a+r-1)in u?u[o]=u[s]:delete u[o];for(a=0;a<n;a++)u[a+l]=arguments[a+2];return u.length=c-r+n,i}}),function(e){var t=void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};Object.defineProperty(e,"__esModule",{value:!0});var n=yv.exports,r=_h.exports,i=Sh.exports,a=mv.exports,s=Eh.exports,o=Rh.exports,u=Oh.exports,c=xh.exports,l=Ch.exports,f=bv,d=Ih.exports,p=Dv,h=ld.exports,v=Ky.exports,y=hm,m=Q_.exports,g=wh,b=tS.exports;function k(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function w(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var x=k(n),_=k(r),S=k(i),E=k(a),T=k(s),R=k(o),I=k(u),O=k(c),C=k(l),P=k(f),A=k(d),j=w(h),M=w(v),L=k(m),N=w(b);function U(){}function D(){D.init.call(this)}function F(e){return void 0===e._maxListeners?D.defaultMaxListeners:e._maxListeners}function B(e,t,n){if(t)e.call(n);else for(var r=e.length,i=K(e,r),a=0;a<r;++a)i[a].call(n)}function q(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=K(e,i),s=0;s<i;++s)a[s].call(n,r)}function W(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=K(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function z(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=K(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function G(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=K(e,i),s=0;s<i;++s)a[s].apply(n,r)}function J(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new U,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=F(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function V(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function $(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function K(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}U.prototype=Object.create(null),D.EventEmitter=D,D.usingDomains=!1,D.prototype.domain=void 0,D.prototype._events=void 0,D.prototype._maxListeners=void 0,D.defaultMaxListeners=10,D.init=function(){this.domain=null,D.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new U,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},D.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},D.prototype.getMaxListeners=function(){return F(this)},D.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:B(n,l,this);break;case 2:q(n,l,this,arguments[1]);break;case 3:W(n,l,this,arguments[1],arguments[2]);break;case 4:z(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];G(n,l,this,i)}return!0},D.prototype.addListener=function(e,t){return J(this,e,t,!1)},D.prototype.on=D.prototype.addListener,D.prototype.prependListener=function(e,t){return J(this,e,t,!0)},D.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,V(this,e,t)),this},D.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,V(this,e,t)),this},D.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new U:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new U,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},D.prototype.off=function(e,t){return this.removeListener(e,t)},D.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new U,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new U:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new U,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},D.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},D.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):$.call(e,t)},D.prototype.listenerCount=$,D.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var H=j.getLogger("twilsock");function Y(e,t){return["".concat((new Date).toISOString()," Twilsock ").concat(e,":")].concat(Array.from(t))}var Q=new(function(){function e(t){O.default(this,e),C.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?" "+t+":":""}return _.default(e,[{key:"setLevel",value:function(e){H.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.trace.apply(null,Y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.debug.apply(null,Y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.info.apply(null,Y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.warn.apply(null,Y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.error.apply(null,Y("E",t))}}],[{key:"setLevel",value:function(e){H.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.trace.apply(null,Y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.debug.apply(null,Y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.info.apply(null,Y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.warn.apply(null,Y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.error.apply(null,Y("E",t))}}]),e}())(""),X="0.12.0-rc.1",Z=function(){function e(t,n,r){O.default(this,e),C.default(this,"confirmedCapabilities",new Set),this.activeGrant=n,this._token=t;var i=r.region||"us1",a="wss://tsock.".concat(i,".twilio.com/v3/wsconnect"),s=r.twilsock||r.Twilsock||{};this.url=s.uri||a,this._continuationToken=r.continuationToken?r.continuationToken:null,this.logLevel=r.logLevel?r.logLevel:"error",this.retryPolicy=r.retryPolicy?r.retryPolicy:{min:1e3,max:12e4,randomness:.2},this.clientMetadata=r.clientMetadata?r.clientMetadata:{},this.clientMetadata.ver=X,this.initRegistrations=r.initRegistrations?r.initRegistrations:null,this.tweaks=r.tweaks?r.tweaks:null}return _.default(e,[{key:"token",get:function(){return this._token}},{key:"continuationToken",get:function(){return this._continuationToken}},{key:"updateToken",value:function(e){this._token=e}},{key:"updateContinuationToken",value:function(e){this._continuationToken=e}}]),e}(),ee=function e(t){O.default(this,e),this.id=t||"TM".concat(y.v4())};function te(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var ne=function(e){T.default(n,e);var t=te(n);function n(e,r,i,a,s){var o;return O.default(this,n),o=t.call(this),C.default(S.default(o),"method","init"),o.token=e,o.continuation_token=r,o.metadata=i,o.registrations=a,o.tweaks=s,o.capabilities=["client_update","offline_storage","telemetry.v1"],o}return n}(ee);function re(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var ie=function(e){T.default(n,e);var t=re(n);function n(e,r,i,a,s,o,u){var c;return O.default(this,n),(c=t.call(this,e)).continuationToken=r,c.continuationTokenStatus=a,c.offlineStorage=s,c.initRegistrations=o,c.debugInfo=u,c.confirmedCapabilities=i,c}return n}(ee);function ae(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var se=function(e){T.default(n,e);var t=ae(n);function n(e){var r;return O.default(this,n),r=t.call(this),C.default(S.default(r),"method","update"),r.token=e,r}return n}(ee);function oe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Message=function(e){T.default(Message,e);var t=oe(Message);function Message(e,n,r){var i;return O.default(this,Message),i=t.call(this),C.default(S.default(i),"method","message"),i.active_grant=e,i.payload_type=n,i.http_request=r,i}return Message}(ee);function ue(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var ce=function(e){T.default(n,e);var t=ue(n);function n(e){var r;return O.default(this,n),r=t.call(this,e),C.default(S.default(r),"method","reply"),C.default(S.default(r),"payload_type","application/json"),C.default(S.default(r),"status",{code:200,status:"OK"}),r}return n}(ee);function le(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var fe=function(e){T.default(n,e);var t=le(n);function n(){var e;return O.default(this,n),e=t.call(this),C.default(S.default(e),"method","close"),e}return n}(ee);function de(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var pe=function e(t,n,r,i,a,s){O.default(this,e),this.start=t,this.end=n,this.title=r,this.details=i,this.id=a,this.type=s},he=function(e){T.default(n,e);var t=de(n);function n(e){var r;return O.default(this,n),r=t.call(this),C.default(S.default(r),"method","telemetry.v1"),r.events=e,r}return n}(ee);function ve(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})).length}function ye(e){var t=encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})),n=new Uint8Array(t.length);return Array.prototype.forEach.call(t,(function(e,t){n[t]=e.charCodeAt(0)})),n}function me(e){var t=Array.prototype.map.call(e,(function(e){return String.fromCharCode(e)})).join("").replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n}));return decodeURIComponent(t)}function ge(e){return JSON.parse(me(e))}var be=function(){function e(){O.default(this,e)}return _.default(e,null,[{key:"parse",value:function(e){var t,n,r=new Uint8Array(e),i=function(e){for(var t="",n=0;n<e.length;++n){var r=String.fromCharCode(e[n]);if(t+=r,"\r"===r){n+=2;break}}var i=t.split(" ");return{size:n,protocol:i[0],version:i[1],headerSize:Number(i[2])}}(r);if("TWILSOCK"!==i.protocol||"V3.0"!==i.version)return Q.error("unsupported protocol: ".concat(i.protocol," ver ").concat(i.version)),null;try{t=ge(r.subarray(i.size,i.size+i.headerSize))}catch(t){return Q.error("failed to parse message header",t,e),null}if(Q.debug("message received: ",t.method),Q.trace("message received: ",t),t.payload_size>0){var a=2+i.size+i.headerSize,s=t.payload_size;if(t.hasOwnProperty("payload_type")&&0!==t.payload_type.indexOf("application/json"))0===t.payload_type.indexOf("text/plain")&&(n=me(r.subarray(a,a+s)));else try{n=ge(r.subarray(a,a+s))}catch(t){return Q.error("failed to parse message body",t,e),null}}return{method:t.method,header:t,payload:n}}},{key:"createPacket",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";e.payload_size=ve(t);var n=JSON.stringify(e),r="TWILSOCK V3.0 "+ve(n);Q.debug("send request:",r+n+t);var i=ye(r+"\r\n"+n+"\r\n"+t);return i.buffer}}]),e}();function ke(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var we=function(e){T.default(n,e);var t=ke(n);function n(e){return O.default(this,n),t.call(this,e)}return n}(L.default(Error));function xe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var _e=function(e){T.default(n,e);var t=xe(n);function n(e,r){var i;return O.default(this,n),(i=t.call(this,e)).reply=r,i}return n}(we);function Se(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Ee(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Se(Object(n),!0).forEach((function(t){C.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Se(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Te(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Re=function(e){T.default(n,e);var t=Te(n);function n(e){var r;return O.default(this,n),r=t.call(this),C.default(S.default(r),"newBackoff",null),C.default(S.default(r),"usedBackoff",null),C.default(S.default(r),"retrier",null),r.options=e?Ee({},e):{},r}return _.default(n,[{key:"inProgress",get:function(){return!!this.retrier}},{key:"start",value:function(){if(this.inProgress)throw new Error("Already waiting for next attempt, call finishAttempt(success : boolean) to finish it");this.createRetrier()}},{key:"stop",value:function(){this.cleanRetrier(),this.newBackoff=null,this.usedBackoff=null}},{key:"modifyBackoff",value:function(e){this.newBackoff=e}},{key:"attemptFailed",value:function(){if(!this.inProgress)throw new Error("No attempt is in progress");var e,t;this.newBackoff?!this.usedBackoff||this.usedBackoff<this.newBackoff?this.createRetrier():null===(e=this.retrier)||void 0===e||e.failed(new Error):null===(t=this.retrier)||void 0===t||t.failed(new Error)}},{key:"cancel",value:function(){var e;null===(e=this.retrier)||void 0===e||e.cancel()}},{key:"cleanRetrier",value:function(){var e,t;null===(e=this.retrier)||void 0===e||e.removeAllListeners(),null===(t=this.retrier)||void 0===t||t.cancel(),this.retrier=null}},{key:"getRetryPolicy",value:function(){var e=Ee({},this.options);return this.newBackoff&&(e.min=this.newBackoff,e.max=this.options.max&&this.options.max>this.newBackoff?this.options.max:this.newBackoff),e.maxAttemptsCount=this.options.maxAttemptsCount?this.options.maxAttemptsCount+1:void 0,e}},{key:"createRetrier",value:function(){var e=this;this.cleanRetrier();var t=this.getRetryPolicy();this.retrier=new g.Retrier(t),this.retrier.once("attempt",(function(){var t,n;null===(t=e.retrier)||void 0===t||t.on("attempt",(function(){return e.emit("attempt")})),null===(n=e.retrier)||void 0===n||n.failed(new Error("Skipping first attempt"))})),this.retrier.on("failed",(function(t){return e.emit("failed",t)})),this.usedBackoff=this.newBackoff,this.newBackoff=null,this.retrier.start()}}]),n}(D);function Ie(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Oe=function(e){T.default(i,e);var t,n,r=Ie(i);function i(e,t,n){var a;O.default(this,i),a=r.call(this),C.default(S.default(a),"disconnectingTimer",null),C.default(S.default(a),"disconnectedPromiseResolve",null),C.default(S.default(a),"terminalStates",["disconnected","rejected"]),C.default(S.default(a),"tokenExpiredSasCode",20104),C.default(S.default(a),"terminationReason","Connection is not initialized"),a.websocket=e,a.websocket.on("connected",(function(){return a.fsm.socketConnected()})),a.websocket.on("disconnected",(function(){return a.fsm.socketClosed()})),a.websocket.on("message",(function(e){return a.onIncomingMessage(e)})),a.websocket.on("socketError",(function(e){return a.emit("connectionError",{terminal:!1,message:"Socket error: ".concat(e.message),httpStatusCode:null,errorCode:null})})),a.transport=t,a.config=n,a.retrier=new Re(n.retryPolicy),a.retrier.on("attempt",(function(){return a.retry()})),a.retrier.on("failed",(function(e){Q.warn("Retrying failed: ".concat(e.message)),a.disconnect()})),"undefined"!=typeof window&&void 0!==window.addEventListener&&(window.addEventListener("online",(function(){Q.debug("Browser reported connectivity state: online"),a.resetBackoff(),a.fsm.systemOnline()})),window.addEventListener("offline",(function(){Q.debug("Browser reported connectivity state: offline"),a.websocket.close(),a.fsm.socketClosed()})));var s=M.factory({init:"disconnected",transitions:[{name:"userConnect",from:["disconnected","rejected"],to:"connecting"},{name:"userConnect",from:["connecting","connected"]},{name:"userDisconnect",from:["connecting","initialising","connected","updating","retrying","rejected","waitSocketClosed","waitOffloadSocketClosed"],to:"disconnecting"},{name:"userRetry",from:["retrying"],to:"connecting"},{name:"socketConnected",from:["connecting"],to:"initialising"},{name:"socketClosed",from:["connecting","initialising","connected","updating","error","waitOffloadSocketClosed"],to:"retrying"},{name:"socketClosed",from:["disconnecting"],to:"disconnected"},{name:"socketClosed",from:["waitSocketClosed"],to:"disconnected"},{name:"socketClosed",from:["rejected"],to:"rejected"},{name:"initSuccess",from:["initialising"],to:"connected"},{name:"initError",from:["initialising"],to:"error"},{name:"tokenRejected",from:["initialising","updating"],to:"rejected"},{name:"protocolError",from:["initialising","connected","updating"],to:"error"},{name:"receiveClose",from:["initialising","connected","updating"],to:"waitSocketClosed"},{name:"receiveOffload",from:["initialising","connected","updating"],to:"waitOffloadSocketClosed"},{name:"unsupportedProtocol",from:["initialising","connected","updating"],to:"unsupported"},{name:"receiveFatalClose",from:["initialising","connected","updating"],to:"unsupported"},{name:"userUpdateToken",from:["disconnected","rejected","connecting","retrying"],to:"connecting"},{name:"userUpdateToken",from:["connected"],to:"updating"},{name:"updateSuccess",from:["updating"],to:"connected"},{name:"updateError",from:["updating"],to:"error"},{name:"userSend",from:["connected"],to:"connected"},{name:"systemOnline",from:["retrying"],to:"connecting"}],methods:{onConnecting:function(){a.setupSocket(),a.emit("connecting")},onEnterInitialising:function(){a.sendInit()},onLeaveInitialising:function(){a.cancelInit()},onEnterUpdating:function(){a.sendUpdate()},onLeaveUpdating:function(){a.cancelUpdate()},onEnterRetrying:function(){a.initRetry(),a.emit("connecting")},onEnterConnected:function(){a.resetBackoff(),a.onConnected()},onUserUpdateToken:function(){a.resetBackoff()},onTokenRejected:function(){a.resetBackoff(),a.closeSocket(!0),a.finalizeSocket()},onUserDisconnect:function(){a.closeSocket(!0)},onEnterDisconnecting:function(){a.startDisconnectTimer()},onLeaveDisconnecting:function(){a.cancelDisconnectTimer()},onEnterWaitSocketClosed:function(){a.startDisconnectTimer()},onLeaveWaitSocketClosed:function(){a.cancelDisconnectTimer()},onEnterWaitOffloadSocketClosed:function(){a.startDisconnectTimer()},onLeaveWaitOffloadSocketClosed:function(){a.cancelDisconnectTimer()},onDisconnected:function(){a.resetBackoff(),a.finalizeSocket()},onReceiveClose:function(){a.onCloseReceived()},onReceiveOffload:function(e,t){Q.debug("onreceiveoffload: ",t),a.modifyBackoff(t.body),a.onCloseReceived()},onUnsupported:function(){a.closeSocket(!0),a.finalizeSocket()},onError:function(e,t){a.closeSocket(t),a.finalizeSocket()},onEnterState:function(e){"none"!==e.from&&a.changeState(e)},onInvalidTransition:function(e,t,n){Q.warn("FSM: unexpected transition",t,n)}}});return a.fsm=new s,a}return _.default(i,[{key:"changeState",value:function(e){Q.debug("FSM: ".concat(e.transition,": ").concat(e.from," --\x3e ").concat(e.to)),this.lastEmittedState!==this.state&&(this.lastEmittedState=this.state,this.emit("stateChanged",this.state))}},{key:"resetBackoff",value:function(){Q.trace("resetBackoff"),this.retrier.stop()}},{key:"modifyBackoff",value:function(e){Q.trace("modifyBackoff",e);var t=e?e.backoff_policy:null;t&&"number"==typeof t.reconnect_min_ms&&this.retrier.modifyBackoff(t.reconnect_min_ms)}},{key:"startDisconnectTimer",value:function(){var e=this;Q.trace("startDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null),this.disconnectingTimer=setTimeout((function(){Q.debug("disconnecting is timed out"),e.closeSocket(!0)}),3e3)}},{key:"cancelDisconnectTimer",value:function(){Q.trace("cancelDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null)}},{key:"isConnected",get:function(){return"connected"===this.state&&this.websocket.isConnected}},{key:"state",get:function(){switch(this.fsm.state){case"connecting":case"initialising":case"retrying":case"error":return"connecting";case"updating":case"connected":return"connected";case"rejected":return"denied";case"disconnecting":case"waitSocketClosed":case"waitOffloadSocketClosed":return"disconnecting";case"disconnected":default:return"disconnected"}}},{key:"initRetry",value:function(){Q.debug("initRetry"),this.retrier.inProgress?this.retrier.attemptFailed():this.retrier.start()}},{key:"retry",value:function(){"connecting"!=this.fsm.state?(Q.trace("retry"),this.websocket.close(),this.fsm.userRetry()):Q.trace("can\t retry as already connecting")}},{key:"onConnected",value:function(){this.emit("connected")}},{key:"finalizeSocket",value:function(){Q.trace("finalizeSocket"),this.websocket.close(),this.emit("disconnected"),this.disconnectedPromiseResolve&&(this.disconnectedPromiseResolve(),this.disconnectedPromiseResolve=null)}},{key:"setupSocket",value:function(){Q.trace("setupSocket:",this.config.token),this.emit("beforeConnect"),this.websocket.connect()}},{key:"onIncomingMessage",value:function(e){var t=be.parse(e);if(t){var n=t.method,r=t.header,i=t.payload;if("reply"!==n&&this.confirmReceiving(r),"notification"===n)this.emit("message",r.message_type,i);else if("reply"===r.method)this.transport.processReply({id:r.id,status:r.status,header:r,body:i});else if("client_update"===r.method)"token_about_to_expire"===r.client_update_type&&this.emit("tokenAboutToExpire");else if("close"===r.method)if(308===r.status.code)Q.debug("Connection has been offloaded"),this.fsm.receiveOffload({status:r.status.status,body:i});else if(406===r.status.code){var a="Server closed connection because can't parse protocol: ".concat(JSON.stringify(r.status));this.emitReplyConnectionError(a,r,!0),Q.error(a),this.fsm.receiveFatalClose()}else 417===r.status.code?(Q.error("Server closed connection because can't parse client reply: ".concat(JSON.stringify(r.status))),this.fsm.receiveFatalClose(r.status.status)):410===r.status.code?(Q.warn("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status),this.emit("tokenExpired")):401===r.status.code?(Q.error("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status)):(Q.warn("unexpected message: ",r.status),this.fsm.receiveOffload({status:r.status.status,body:null}))}}},{key:"sendInit",value:(n=x.default(P.default.mark((function e(){var t,n;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("sendInit"),e.prev=1,this.emit("beforeSendInit"),e.next=5,this.transport.sendInit();case 5:t=e.sent,this.config.updateContinuationToken(t.continuationToken),this.config.confirmedCapabilities=t.confirmedCapabilities,this.fsm.initSuccess(t),this.emit("initialized",t),this.emit("tokenUpdated"),e.next=17;break;case 13:e.prev=13,e.t0=e.catch(1),e.t0 instanceof _e?(n=!1,Q.warn("Init rejected by server: ".concat(JSON.stringify(e.t0.reply.status))),this.emit("sendInitFailed"),401===e.t0.reply.status.code||403===e.t0.reply.status.code?(n=!0,this.fsm.tokenRejected(e.t0.reply.status),e.t0.reply.status.errorCode===this.tokenExpiredSasCode&&this.emit("tokenExpired")):429===e.t0.reply.status.code?(this.modifyBackoff(e.t0.reply.body),this.fsm.initError(!0)):500===e.t0.reply.status.code?this.fsm.initError(!1):this.fsm.initError(!0),this.emitReplyConnectionError(e.t0.message,e.t0.reply,n)):(this.terminationReason=e.t0.message,this.emit("connectionError",{terminal:!0,message:"Unknown error during connection initialisation: ".concat(e.t0.message,"\n").concat(JSON.stringify(e.t0,null,2)),httpStatusCode:null,errorCode:null}),this.fsm.initError(!0)),this.emit("tokenUpdated",e.t0);case 17:case"end":return e.stop()}}),e,this,[[1,13]])}))),function(){return n.apply(this,arguments)})},{key:"sendUpdate",value:(t=x.default(P.default.mark((function e(){var t,n,r;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("sendUpdate"),t=new se(this.config.token),e.prev=2,e.next=5,this.transport.sendWithReply(t);case 5:n=e.sent,this.fsm.updateSuccess(n.body),this.emit("tokenUpdated"),e.next=14;break;case 10:e.prev=10,e.t0=e.catch(2),e.t0 instanceof _e?(r=!1,Q.warn("Token update rejected by server: ".concat(JSON.stringify(e.t0.reply.status))),401===e.t0.reply.status.code||403===e.t0.reply.status.code?(r=!0,this.fsm.tokenRejected(e.t0.reply.status),e.t0.reply.status.errorCode===this.tokenExpiredSasCode&&this.emit("tokenExpired")):429===e.t0.reply.status.code?(this.modifyBackoff(e.t0.reply.body),this.fsm.updateError(e.t0.reply.status)):this.fsm.updateError(e.t0.reply.status),this.emitReplyConnectionError(e.t0.message,e.t0.reply,r)):(this.emit("error",!1,e.t0.message,null,null),this.fsm.updateError(e.t0)),this.emit("tokenUpdated",e.t0);case 14:case"end":return e.stop()}}),e,this,[[2,10]])}))),function(){return t.apply(this,arguments)})},{key:"emitReplyConnectionError",value:function(e,t,n){var r=t.status&&t.status.description?t.status.description:e,i=t.status.code,a=t.status&&t.status.errorCode?t.status.errorCode:null;n&&(this.terminationReason=r),this.emit("connectionError",{terminal:n,message:"Connection error: ".concat(r),httpStatusCode:i,errorCode:a})}},{key:"cancelInit",value:function(){Q.trace("cancelInit")}},{key:"cancelUpdate",value:function(){Q.trace("cancelUpdate")}},{key:"confirmReceiving",value:function(e){Q.trace("confirmReceiving");try{this.transport.send(new ce(e.id))}catch(e){Q.debug("failed to confirm packet receiving",e)}}},{key:"closeSocket",value:function(e){var t=this;Q.trace("closeSocket (graceful: ".concat(e,")")),e&&this.transport.isConnected&&this.transport.sendClose(),this.websocket.close(),setTimeout((function(){return t.fsm.socketClosed()}),0)}},{key:"connect",value:function(){Q.trace("connect"),this.fsm.userConnect()}},{key:"disconnect",value:function(){var e=this;return Q.trace("disconnect"),this.fsm.is("disconnected")?Promise.resolve():new Promise((function(t){e.disconnectedPromiseResolve=t,e.fsm.userDisconnect()}))}},{key:"updateToken",value:function(e){var t=this;return Q.trace("updateToken:",e),new Promise((function(e,n){t.once("tokenUpdated",(function(t){t?n(t):e()})),t.fsm.userUpdateToken()}))}},{key:"isTerminalState",get:function(){return-1!==this.terminalStates.indexOf(this.fsm.state)}},{key:"getTerminationReason",get:function(){return this.terminationReason}},{key:"onCloseReceived",value:function(){this.websocket.close()}}]),i}(D),Ce=function(){function e(){O.default(this,e)}return _.default(e,null,[{key:"getMetadata",value:function(e){var t,n,r,i,a,s,o,u,c=e&&e.clientMetadata?e.clientMetadata:{},l={env:null!==(t=N.name)&&void 0!==t?t:"unknown",envv:null!==(n=N.version)&&void 0!==n?n:"unknown",os:null!==(r=null===(i=N.os)||void 0===i?void 0:i.family)&&void 0!==r?r:"unknown",osv:null!==(a=null===(s=N.os)||void 0===s?void 0:s.version)&&void 0!==a?a:"unknown",osa:null!==(o=null===(u=N.os)||void 0===u?void 0:u.architecture)&&void 0!==o?o:"unknown",sdk:"js-default"},f={};return["ver","env","envv","os","osv","osa","type","sdk","sdkv","dev","devv","devt","app","appv"].filter((function(e){return e in c||e in l})).forEach((function(e){return f[e]=e in c?c[e]:l[e]})),f}}]),e}();var Pe=function(){function e(t,n){var r=this;O.default(this,e),this.config=n,this.activeRequests=new Map,this.channel=t,this.channel.on("reply",(function(e){return r.processReply(e)})),this.channel.on("disconnected",(function(){r.activeRequests.forEach((function(e){clearTimeout(e.timeout),e.reject(new we("disconnected"))})),r.activeRequests.clear()}))}var t;return _.default(e,[{key:"isConnected",get:function(){return this.channel.isConnected}},{key:"processReply",value:function(e){var t,n=this.activeRequests.get(e.id);n&&(clearTimeout(n.timeout),this.activeRequests.delete(e.id),(t=e.status.code)>=200&&t<300?n.resolve(e):(n.reject(new _e("Transport failure: "+e.status.status,e)),Q.trace("message rejected")))}},{key:"storeRequest",value:function(e,t,n){var r={resolve:t,reject:n,timeout:setTimeout((function(){Q.trace("request",e,"is timed out"),n(new we("Twilsock: request timeout: "+e))}),3e4)};this.activeRequests.set(e,r)}},{key:"shutdown",value:function(){this.activeRequests.forEach((function(e){clearTimeout(e.timeout),e.reject(new we("Twilsock: request cancelled by user"))})),this.activeRequests.clear()}},{key:"sendInit",value:(t=x.default(P.default.mark((function e(){var t,n,r;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("sendInit"),t=Ce.getMetadata(this.config),n=new ne(this.config.token,this.config.continuationToken,t,this.config.initRegistrations,this.config.tweaks),e.next=5,this.sendWithReply(n);case 5:return r=e.sent,e.abrupt("return",new ie(r.id,r.header.continuation_token,new Set(r.header.capabilities),r.header.continuation_token_status,r.header.offline_storage,r.header.init_registrations,r.header.debug_info));case 7:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"sendClose",value:function(){var e=new fe;this.send(e)}},{key:"sendWithReply",value:function(e,t){var n=this;return new Promise((function(r,i){var a=n.send(e,t);n.storeRequest(a,r,i)}))}},{key:"send",value:function(e,t){e.id=e.id||"TM".concat(y.v4());var n=be.createPacket(e,function(e){switch(A.default(e)){case"undefined":return"";case"object":return JSON.stringify(e);default:return e}}(t));try{return this.channel.send(n),e.id}catch(t){throw Q.debug("failed to send ",e,t),Q.trace(t.stack),t}}}]),e}();function Ae(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var je=function(e){T.default(r,e);var n=Ae(r);function r(e){var i;return O.default(this,r),i=n.call(this),C.default(S.default(i),"socket",null),i.url=e,i.url=e,i.WebSocket=t.WebSocket||t.MozWebSocket||{},i}return _.default(r,[{key:"isConnected",get:function(){return!!this.socket&&1===this.socket.readyState}},{key:"connect",value:function(){var e,t=this;Q.trace("connecting to socket");try{e=new this.WebSocket(this.url)}catch(e){return Q.debug("Socket error: ".concat(this.url)),void this.emit("socketError",e)}e.binaryType="arraybuffer",e.onopen=function(){Q.debug("socket opened ".concat(t.url)),t.emit("connected")},e.onclose=function(e){Q.debug("socket closed",e),t.emit("disconnected",e)},e.onerror=function(e){Q.debug("Socket error:",e),t.emit("socketError",e)},e.onmessage=function(e){t.emit("message",e.data)},this.socket=e}},{key:"send",value:function(e){return this.socket&&this.socket.send(e)}},{key:"close",value:function(){if(Q.trace("closing socket"),this.socket){this.socket.onopen=null,this.socket.onclose=null,this.socket.onerror=null,this.socket.onmessage=null;try{this.socket.close()}finally{}}}}]),r}(D);function Me(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Le=function(e){T.default(u,e);var t,n,r,i,a,s,o=Me(u);function u(e){var t;return O.default(this,u),(t=o.call(this)).transport=e,t.registrations=new Map,t.registrationsInProgress=new Map,t}return _.default(u,[{key:"putNotificationContext",value:(s=x.default(P.default.mark((function e(t,n){var r;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={method:"put_notification_ctx",notification_ctx_id:t},e.next=3,this.transport.sendWithReply(r,n);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return s.apply(this,arguments)})},{key:"deleteNotificationContext",value:(a=x.default(P.default.mark((function e(t){var n;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={method:"delete_notification_ctx",notification_ctx_id:t},e.next=3,this.transport.sendWithReply(n);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"updateRegistration",value:(i=x.default(P.default.mark((function e(t,n){var r,i;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.debug("update registration for context",t),(r=this.registrationsInProgress.get(t))||(r=new Set,this.registrationsInProgress.set(t,r)),i=y.v4(),r.add(i),e.prev=5,e.next=8,this.putNotificationContext(t,n);case 8:Q.debug("registration attempt succeeded for context",n),r.delete(i),0===r.size&&(this.registrationsInProgress.delete(t),this.emit("registered",t)),e.next=19;break;case 13:e.prev=13,e.t0=e.catch(5),Q.warn("registration attempt failed for context",n),Q.debug(e.t0),r.delete(i),0===r.size&&(this.registrationsInProgress.delete(t),this.emit("registrationFailed",t,e.t0));case 19:case"end":return e.stop()}}),e,this,[[5,13]])}))),function(e,t){return i.apply(this,arguments)})},{key:"updateRegistrations",value:(r=x.default(P.default.mark((function e(){var t,n=this;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("refreshing ".concat(this.registrations.size," registrations")),t=[],this.registrations.forEach((function(e,r){t.push(n.updateRegistration(r,e))})),e.next=5,Promise.all(t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"setNotificationsContext",value:(n=x.default(P.default.mark((function e(t,n){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t&&n){e.next=2;break}throw new we("Invalid arguments provided");case 2:return this.registrations.set(t,n),e.next=5,this.updateRegistration(t,n);case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeNotificationsContext",value:(t=x.default(P.default.mark((function e(t){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.registrations.has(t)){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.deleteNotificationContext(t);case 4:this.transport.isConnected&&this.registrations.delete(t);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),u}(D);function Ne(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Ue=function(e){T.default(n,e);var t=Ne(n);function n(e,r,i){var a;return O.default(this,n),(a=t.call(this,r)).status=e,a.description=r,a.body=i,a}return n}(we);function De(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Fe=function(e){T.default(n,e);var t=De(n);function n(e){return O.default(this,n),t.call(this,e)}return n}(we);function Be(e,t){var n=function(e){var t=e.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)(\/[^?#]*)(\?[^#]*|)(#.*|)$/);if(t){var n={protocol:t[1],host:t[2],hostname:t[3],port:t[4],pathname:t[5],search:t[6],hash:t[7],params:{}};if(n.search.length>0){var r=n.search.substring(1);n.params=r.split("&").map((function(e){return e.split("=")})).reduce((function(e,t){return e.hasOwnProperty(t[0])?Array.isArray(e[t[0]])?e[t[0]].push(t[1]):e[t[0]]=[e[t[0]],t[1]]:e[t[0]]=t[1],e}),{})}return n}throw new we("Incorrect URI: "+e)}(t),r={method:e,host:n.host,path:n.pathname};return n.params&&(r.params=n.params),r}function qe(e,t,n,r,i){return{to:Be(e,t),headers:n,body:r,grant:i}}var We=function(){function e(t,n,r){O.default(this,e),this.config=r,this.transport=t,this.pendingMessages=[],this.twilsock=n}var t;return _.default(e,[{key:"saveMessage",value:function(e){var t=this;return new Promise((function(n,r){var i={message:e,resolve:n,reject:r,alreadyRejected:!1,timeout:setTimeout((function(){Q.debug("request is timed out"),r(new we("request '".concat(e.to.method,"' to '").concat(e.to.host,"' timed out"))),i.alreadyRejected=!0}),2e4)};t.pendingMessages.push(i)}))}},{key:"sendPendingMessages",value:function(){for(var e=this,t=function(){var t=e.pendingMessages[0];if(!t.alreadyRejected)try{var n=t.message;e.actualSend(n).then((function(e){return t.resolve(e)})).catch((function(e){return t.reject(e)})),clearTimeout(t.timeout)}catch(e){return Q.debug("Failed to send pending message",e),"break"}e.pendingMessages.splice(0,1)};this.pendingMessages.length>0;){if("break"===t())break}}},{key:"rejectPendingMessages",value:function(){var e=this;this.pendingMessages.forEach((function(t){t.reject(new Fe("Unable to connect: "+e.twilsock.getTerminationReason)),t.alreadyRejected=!0,clearTimeout(t.timeout)})),this.pendingMessages.splice(0,this.pendingMessages.length)}},{key:"actualSend",value:(t=x.default(P.default.mark((function e(t){var n,r,i,a,s,o,u,c;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.to,i=t.headers,a=t.body,s=null!==(n=t.grant)&&void 0!==n?n:this.config.activeGrant,o={host:r.host,path:r.path,method:r.method,params:r.params,headers:i},u=new Message(s,i["Content-Type"]||"application/json",o),Q.trace("Sending upstream message",u),e.next=9,this.transport.sendWithReply(u,a);case 9:if(c=e.sent,Q.trace("Received upstream message response",c),!((f=c)&&f.header&&f.header.http_status)||(l=c.header.http_status.code)>=200&&l<300){e.next=13;break}throw new Ue(c.header.http_status.code,c.header.http_status.status,c.body);case 13:return e.abrupt("return",{status:c.header.http_status,headers:c.header.http_headers,body:c.body});case 14:case"end":return e.stop()}var l,f}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"send",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;if(this.twilsock.isTerminalState)return Promise.reject(new Fe("Unable to connect: "+this.twilsock.getTerminationReason));var a=qe(e,t,n,r,i);return this.twilsock.isConnected?this.actualSend(a):this.saveMessage(a)}}]),e}(),ze=function(){function e(){var t=this;O.default(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return _.default(e,[{key:"promise",get:function(){return this._promise}},{key:"update",value:function(e){this._resolve(e)}},{key:"set",value:function(e){this._resolve(e)}},{key:"fail",value:function(e){this._reject(e)}}]),e}(),Ge=function(){function e(t){O.default(this,e),this.id=t}return _.default(e,null,[{key:"create",value:function(t){if(t instanceof Object&&"storage_id"in t)return new e(t.storage_id);throw new we('Field "storage_id" is missing')}}]),e}(),Je=function(){function e(){return O.default(this,e),C.default(this,"initializedFlag","twilio_twilsock_token_storage"),C.default(this,"tokenStoragePrefix","twilio_continuation_token_"),e._instance||(this.initialize(),e._instance=this),e._instance}return _.default(e,[{key:"sessionStorage",value:function(){try{return t.sessionStorage}catch(e){return null}}},{key:"window",value:function(){try{return t.window}catch(e){return null}}},{key:"storeToken",value:function(e,t){this.canStore()&&this.sessionStorage.setItem(this.getKeyName(t),e)}},{key:"getStoredToken",value:function(e){return this.canStore()?this.sessionStorage.getItem(this.getKeyName(e)):null}},{key:"initialize",value:function(){var e=this;if(this.canStore()){this.sessionStorage.getItem(this.initializedFlag)&&this.clear(),this.sessionStorage.setItem(this.initializedFlag,"true");var t=this.sessionStorage.removeItem;this.window.addEventListener("unload",(function(){t(e.initializedFlag)}))}}},{key:"clear",value:function(){if(this.canStore()){for(var e=[],t=0;t<this.sessionStorage.length;t++){var n=this.sessionStorage.key(t);n&&0===n.indexOf(this.tokenStoragePrefix)&&e.push(n)}var r=this.sessionStorage.removeItem;e.forEach((function(e){return r(e)})),r(this.initializedFlag)}}},{key:"getKeyName",value:function(e){return"".concat(this.tokenStoragePrefix).concat(e)}},{key:"canStore",value:function(){return!!(this.sessionStorage&&this.sessionStorage.length&&this.window)}}]),e}();C.default(Je,"_instance",null);var Ve,$e,Ke=new Je,He=function(){function e(t,n,r,i,a,s){O.default(this,e),this.title=t,this.details=n,this.start=r,this.type=a,this.id=s,this.end=i}return _.default(e,[{key:"toTelemetryEvent",value:function(){var e=new Date,t=this.start,n=this.end?this.end:e;if(n<t){var r=n;n=t,t=r}var i=t.getTime()-e.getTime(),a=n.getTime()-e.getTime();return new pe(i,a,this.title,this.details,this.id,this.type)}}]),e}();e.TelemetryPoint=void 0,(Ve=e.TelemetryPoint||(e.TelemetryPoint={}))[Ve.Start=0]="Start",Ve[Ve.End=1]="End",e.EventSendingLimitation=void 0,($e=e.EventSendingLimitation||(e.EventSendingLimitation={}))[$e.MinEventsPortion=0]="MinEventsPortion",$e[$e.AnyEvents=1]="AnyEvents",$e[$e.AnyEventsIncludingUnfinished=2]="AnyEventsIncludingUnfinished";var Ye=function(){function t(e,n){O.default(this,t),C.default(this,"minEventsPortionToSend",50),C.default(this,"maxEventsPortionToSend",100),C.default(this,"pendingEvents",new Map),C.default(this,"readyEvents",[]),C.default(this,"hasInitializationFinished",!1),C.default(this,"_canSendTelemetry",!1),this.config=e,this.packetInterface=n}return _.default(t,[{key:"isTelemetryEnabled",get:function(){return this.config.confirmedCapabilities.has("telemetry.v1")}},{key:"canSendTelemetry",get:function(){return this._canSendTelemetry&&this.isTelemetryEnabled},set:function(t){Q.debug("TelemetryTracker.canSendTelemetry: ".concat(t," TelemetryTracker.isTelemetryEnabled: ").concat(this.isTelemetryEnabled)),this._canSendTelemetry&&!t&&(this.pendingEvents.clear(),this.readyEvents=[]),this._canSendTelemetry=t,t&&this.sendTelemetry(e.EventSendingLimitation.AnyEvents),t&&!this.hasInitializationFinished&&(this.hasInitializationFinished=!0)}},{key:"addTelemetryEvent",value:function(e){!this.canSendTelemetry&&this.hasInitializationFinished||this.readyEvents.push(e)}},{key:"addPartialEvent",value:function(t,n,r){Q.debug("Adding ".concat(r===e.TelemetryPoint.Start?"starting":"ending"," timepoint for '").concat(n,"' event"));var i=this.pendingEvents.has(n);if(r===e.TelemetryPoint.Start)i&&Q.debug("Overwriting starting point for '".concat(n,"' event")),this.pendingEvents.set(n,t);else{if(!i)return void Q.info("Could not find started event for '".concat(n,"' event"));this.addTelemetryEvent(this.merge(this.pendingEvents.get(n),t)),this.pendingEvents.delete(n)}}},{key:"getTelemetryToSend",value:function(t){return this.canSendTelemetry&&0!=this.readyEvents.length?t==e.EventSendingLimitation.MinEventsPortion&&this.readyEvents.length<this.minEventsPortionToSend?[]:this.getTelemetryPortion(t==e.EventSendingLimitation.AnyEventsIncludingUnfinished):[]}},{key:"getTelemetryPortion",value:function(e){var t=this,n=Math.min(this.readyEvents.length,this.maxEventsPortionToSend),r=this.readyEvents.splice(0,n);return e&&r.length<this.maxEventsPortionToSend&&this.pendingEvents.forEach((function(e,n){if(!(r.length>=t.maxEventsPortionToSend)){var i=t.pendingEvents.get(n);t.pendingEvents.delete(n),r.push(new He("[UNFINISHED] ".concat(i.title),i.details,i.start,null,i.type,i.id))}})),r}},{key:"merge",value:function(e,t){return new He(t.title?t.title:e.title,t.details?t.details:e.details,e.start,t.end,t.type?t.type:e.type,t.id?t.id:e.id)}},{key:"sendTelemetryIfMinimalPortionCollected",value:function(){this.sendTelemetry(e.EventSendingLimitation.MinEventsPortion)}},{key:"sendTelemetry",value:function(e){var t=this.getTelemetryToSend(e);if(0!==t.length)try{this.packetInterface.send(new he(t.map((function(e){return e.toTelemetryEvent()}))))}catch(e){Q.debug("Error while sending ".concat(t.length," telemetry events due to ").concat(e,"; they will be resubmitted")),this.readyEvents=this.readyEvents.concat(t)}}}]),t}();function Qe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Xe=function e(){O.default(this,e)};C.default(Xe,"TWILSOCK_CONNECT","twilsock.sdk.connect"),C.default(Xe,"TWILSOCK_INIT","twilsock.sdk.init"),e.TwilsockClient=function(t){T.default(f,t);var n,r,i,a,s,o,u,c,l=Qe(f);function f(t,n,r){var i;O.default(this,f),i=l.call(this),C.default(S.default(i),"version",X),C.default(S.default(i),"offlineStorageDeferred",new ze),r.continuationToken=r.continuationToken?r.continuationToken:Ke.getStoredToken(n);var a=i.config=new Z(t,n,r);Q.setLevel(a.logLevel);var s=new je(a.url),o=new Pe(s,a);return i.channel=new Oe(s,o,a),i.registrations=new Le(o),i.upstream=new We(o,i.channel,a),i.telemetryTracker=new Ye(a,o),i.channel.on("initialized",(function(){return i.telemetryTracker.canSendTelemetry=!0})),s.on("disconnected",(function(){return i.telemetryTracker.canSendTelemetry=!1})),i.registrations.on("registered",(function(e){return i.emit("registered",e)})),i.channel.on("message",(function(e,t){return setTimeout((function(){return i.emit("message",e,t)}),0)})),i.channel.on("stateChanged",(function(e){return setTimeout((function(){return i.emit("stateChanged",e)}),0)})),i.channel.on("connectionError",(function(e){return setTimeout((function(){return i.emit("connectionError",e)}),0)})),i.channel.on("tokenAboutToExpire",(function(){return setTimeout((function(){return i.emit("tokenAboutToExpire")}),0)})),i.channel.on("tokenExpired",(function(){return setTimeout((function(){return i.emit("tokenExpired")}),0)})),i.channel.on("connected",(function(){return i.registrations.updateRegistrations()})),i.channel.on("connected",(function(){return i.upstream.sendPendingMessages()})),i.channel.on("connected",(function(){return setTimeout((function(){return i.emit("connected")}),0)})),i.channel.on("beforeConnect",(function(){return i.telemetryTracker.addPartialEvent(new He("Establish WebSocket connection","",new Date),Xe.TWILSOCK_CONNECT,e.TelemetryPoint.Start)})),i.channel.on("connected",(function(){return i.telemetryTracker.addPartialEvent(new He("Establish WebSocket connection","",new Date,new Date),Xe.TWILSOCK_CONNECT,e.TelemetryPoint.End)})),i.channel.on("beforeSendInit",(function(){return i.telemetryTracker.addPartialEvent(new He("Send Twilsock init","",new Date),Xe.TWILSOCK_INIT,e.TelemetryPoint.Start)})),i.channel.on("initialized",(function(){return i.telemetryTracker.addPartialEvent(new He("Send Twilsock init","Succeeded",new Date,new Date),Xe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("sendInitFailed",(function(){return i.telemetryTracker.addPartialEvent(new He("Send Twilsock init","Failed",new Date,new Date),Xe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("initialized",(function(e){i.handleStorageId(n,e),Ke.storeToken(e.continuationToken,n),setTimeout((function(){return i.emit("initialized",e)}),0)})),i.channel.on("disconnected",(function(){return setTimeout((function(){return i.emit("disconnected")}),0)})),i.channel.on("disconnected",(function(){return i.upstream.rejectPendingMessages()})),i.channel.on("disconnected",(function(){return i.offlineStorageDeferred.fail(new we("Client disconnected"))})),i.offlineStorageDeferred.promise.catch((function(){})),i}return _.default(f,[{key:"emit",value:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return Q.debug("Emitting ".concat(e.toString(),"(").concat(r.map((function(e){return JSON.stringify(e)})).join(", "),")")),(t=E.default(I.default(f.prototype),"emit",this)).call.apply(t,[this,e].concat(r))}},{key:"handleStorageId",value:function(e,t){if(t.offlineStorage)if(t.offlineStorage.hasOwnProperty(e))try{this.offlineStorageDeferred.set(Ge.create(t.offlineStorage[e])),Q.debug("Offline storage for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage[e]),"."))}catch(n){this.offlineStorageDeferred.fail(new we("Failed to parse offline storage for ".concat(e," ").concat(JSON.stringify(t.offlineStorage[e]),". ").concat(n,".")))}else this.offlineStorageDeferred.fail(new we("No offline storage id for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage))));else this.offlineStorageDeferred.fail(new we("No offline storage id"))}},{key:"storageId",value:function(){return this.offlineStorageDeferred.promise}},{key:"isConnected",get:function(){return this.channel.isConnected}},{key:"state",get:function(){return this.channel.state}},{key:"updateToken",value:(c=x.default(P.default.mark((function e(t){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Q.trace("updating token '".concat(t,"'")),this.config.token!==t){e.next=3;break}return e.abrupt("return");case 3:return this.config.updateToken(t),e.next=6,this.channel.updateToken(t);case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"setNotificationsContext",value:(u=x.default(P.default.mark((function e(t,n){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.registrations.setNotificationsContext(t,n);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"removeNotificationsContext",value:(o=x.default(P.default.mark((function e(t){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.registrations.removeNotificationsContext(t);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"connect",value:function(){return this.channel.connect()}},{key:"disconnect",value:(s=x.default(P.default.mark((function t(){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEventsIncludingUnfinished),t.next=3,this.channel.disconnect();case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(){return s.apply(this,arguments)})},{key:"get",value:(a=x.default(P.default.mark((function t(n,r,i){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("GET",n,r,void 0,i);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n){return a.apply(this,arguments)})},{key:"post",value:(i=x.default(P.default.mark((function t(n,r,i,a){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("POST",n,r,i,a);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n,r){return i.apply(this,arguments)})},{key:"put",value:(r=x.default(P.default.mark((function t(n,r,i,a){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("PUT",n,r,i,a);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"delete",value:(n=x.default(P.default.mark((function t(n,r,i,a){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("DELETE",n,r,i,a);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,r,i){return n.apply(this,arguments)})},{key:"addTelemetryEvent",value:function(e){this.telemetryTracker.addTelemetryEvent(e),this.telemetryTracker.sendTelemetryIfMinimalPortionCollected()}},{key:"addPartialTelemetryEvent",value:function(t,n,r){this.telemetryTracker.addPartialEvent(t,n,r),r===e.TelemetryPoint.End&&this.telemetryTracker.sendTelemetryIfMinimalPortionCollected()}}]),f}(D),e.TwilsockClient=function(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":A.default(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}([p.validateConstructorTypes(p.nonEmptyString,p.nonEmptyString,[p.pureObject,"undefined",p.literal(null)]),function(e,t){if("object"===("undefined"==typeof Reflect?"undefined":A.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[String,String,Object])],e.TwilsockClient);var Ze=function(){function e(t){O.default(this,e),this.product=t,this.type="ers",this.notification_protocol_version=0,this.message_types=[]}return _.default(e,[{key:"populateInitRegistrations",value:function(e){var t=new Set(this.message_types);for(var n in e)t.add(e[n]);this.message_types=Array.from(t)}}]),e}();e.InitRegistration=Ze,e.TelemetryEventDescription=He,e.TelemetryTracker=Ye,e.TransportUnavailableError=Fe,e.Twilsock=e.TwilsockClient,e.TwilsockError=we}(vv);var TS={},RS=o,IS=s,OS=An,CS=tn,PS=u,AS=Q,jS=b,MS=Object.assign,LS=Object.defineProperty,NS=!MS||IS((function(){if(RS&&1!==MS({b:1},MS(LS({},"a",{enumerable:!0,get:function(){LS(this,"b",{value:3,enumerable:!1})}}),{b:2})).b)return!0;var e={},t={},n=Symbol(),r="abcdefghijklmnopqrst";return e[n]=7,r.split("").forEach((function(e){t[e]=e})),7!=MS({},e)[n]||OS(MS({},t)).join("")!=r}))?function(e,t){for(var n=AS(e),r=arguments.length,i=1,a=CS.f,s=PS.f;r>i;)for(var o,u=jS(arguments[i++]),c=a?OS(u).concat(a(u)):OS(u),l=c.length,f=0;l>f;)o=c[f++],RS&&!s.call(u,o)||(n[o]=u[o]);return n}:MS,US=NS;In({target:"Object",stat:!0,forced:Object.assign!==US},{assign:US}),function(e){Object.defineProperty(e,"__esModule",{value:!0});var t=yv.exports,n=xh.exports,r=_h.exports,i=Eh.exports,a=Rh.exports,s=Oh.exports,o=bv,u=Ih.exports,c=vv,l=Sh.exports,f=Ch.exports,d=wh,p=Wv.exports,h=ey.exports,v=ld.exports,y=Dv;function m(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function g(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var b=m(t),k=m(n),w=m(r),x=m(i),_=m(a),S=m(s),E=m(o),T=m(u),R=m(l),I=m(f),O=m(p),C=m(h),P=g(v);function A(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":T.default(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function j(e,t){if("object"===("undefined"==typeof Reflect?"undefined":T.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function M(){}function L(){L.init.call(this)}function N(e){return void 0===e._maxListeners?L.defaultMaxListeners:e._maxListeners}function U(e,t,n){if(t)e.call(n);else for(var r=e.length,i=J(e,r),a=0;a<r;++a)i[a].call(n)}function D(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=J(e,i),s=0;s<i;++s)a[s].call(n,r)}function F(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=J(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function B(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=J(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function q(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=J(e,i),s=0;s<i;++s)a[s].apply(n,r)}function W(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new M,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=N(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function z(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function G(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function J(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}M.prototype=Object.create(null),L.EventEmitter=L,L.usingDomains=!1,L.prototype.domain=void 0,L.prototype._events=void 0,L.prototype._maxListeners=void 0,L.defaultMaxListeners=10,L.init=function(){this.domain=null,L.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new M,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},L.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},L.prototype.getMaxListeners=function(){return N(this)},L.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:U(n,l,this);break;case 2:D(n,l,this,arguments[1]);break;case 3:F(n,l,this,arguments[1],arguments[2]);break;case 4:B(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];q(n,l,this,i)}return!0},L.prototype.addListener=function(e,t){return W(this,e,t,!1)},L.prototype.on=L.prototype.addListener,L.prototype.prependListener=function(e,t){return W(this,e,t,!0)},L.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,z(this,e,t)),this},L.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,z(this,e,t)),this},L.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new M:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new M,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},L.prototype.off=function(e,t){return this.removeListener(e,t)},L.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new M,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new M:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new M,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},L.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},L.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):G.call(e,t)},L.prototype.listenerCount=G,L.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var V=P.getLogger("twilio-notificatiions");function $(e,t){return["".concat((new Date).toISOString()," Twilio.Notifications ").concat(e,":")].concat(Array.from(t))}var K=new(function(){function e(){k.default(this,e)}return w.default(e,[{key:"setLevel",value:function(e){V.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.trace.apply(null,$("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.debug.apply(null,$("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.info.apply(null,$("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.warn.apply(null,$("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.error.apply(null,$("E",t))}}]),e}());function H(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=S.default(e);if(t){var i=S.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _.default(this,n)}}var Y=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Set;k.default(this,e),this.token=t,this.notificationId=n,this.messageTypes=r};function Q(e,t){var n=new Set;return e.notificationId!==t.notificationId&&n.add("notificationId"),e.token!==t.token&&n.add("token"),function(e,t){return[].concat(C.default(C.default(e).filter((function(e){return!t.has(e)}))),C.default(C.default(t).filter((function(t){return!e.has(t)}))))}(e.messageTypes,t.messageTypes).length>0&&n.add("messageType"),[n.size>0,n]}var X=function(e){x.default(r,e);var t,n=H(r);function r(e){var t;return k.default(this,r),t=n.call(this),I.default(R.default(t),"desiredState",new Y),I.default(R.default(t),"currentState",new Y),I.default(R.default(t),"_hasActiveAttempt",!1),t.channelType=e,t}return w.default(r,[{key:"setNotificationId",value:function(e){this.desiredState.notificationId=e}},{key:"isActive",value:function(){return""!==this.desiredState.notificationId}},{key:"subscribe",value:function(e){this.desiredState.messageTypes.has(e)?K.debug("message type '".concat(e,"' for channel ").concat(this.channelType," is already registered")):this.desiredState.messageTypes.add(e)}},{key:"unsubscribe",value:function(e){this.desiredState.messageTypes.has(e)&&this.desiredState.messageTypes.delete(e)}},{key:"updateToken",value:function(e){this.desiredState.token=e}},{key:"commitChanges",value:(t=b.default(E.default.mark((function e(){var t,n,r,i,a,s;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._hasActiveAttempt){e.next=3;break}throw K.error("One registration attempt is already in progress"),new Error("One registration attempt is already in progress");case 3:if(t=Q(this.desiredState,this.currentState),n=O.default(t,2),r=n[0],i=n[1],r){e.next=6;break}return e.abrupt("return");case 6:if(this.currentState.notificationId||i.delete("notificationId"),K.trace("Persisting ".concat(this.channelType," registration"),i,this.desiredState),e.prev=8,this._hasActiveAttempt=!0,(a=new Y).token=this.desiredState.token,a.notificationId=this.desiredState.notificationId,a.messageTypes=new Set(this.desiredState.messageTypes),!(a.messageTypes.size>0)){e.next=24;break}return e.next=17,this.updateRegistration(a,i);case 17:s=e.sent,this.currentState.token=s.token,this.currentState.notificationId=s.notificationId,this.currentState.messageTypes=new Set(s.messageTypes),this.emit("stateChanged",this.channelType,"registered",this.currentState),e.next=30;break;case 24:return e.next=26,this.removeRegistration();case 26:this.currentState.token=a.token,this.currentState.notificationId=a.notificationId,this.currentState.messageTypes.clear(),this.emit("stateChanged",this.channelType,"unregistered",this.currentState);case 30:e.next=35;break;case 32:throw e.prev=32,e.t0=e.catch(8),e.t0;case 35:return e.prev=35,this._hasActiveAttempt=!1,e.finish(35);case 38:case"end":return e.stop()}}),e,this,[[8,32,35,38]])}))),function(){return t.apply(this,arguments)})}]),r}(L);function Z(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=S.default(e);if(t){var i=S.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _.default(this,n)}}var ee={min:2e3,max:12e4,randomness:.2},te=function(e){x.default(a,e);var t,n,r,i=Z(a);function a(e,t,n,r){var s;return k.default(this,a),s=i.call(this,e),I.default(R.default(s),"registrationId",null),s.context=t,s.twilsock=n,s.registrarUrl=r,s}return w.default(a,[{key:"updateRegistration",value:(r=b.default(E.default.mark((function e(t,n){var r,i,a,s,o,u=this;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!n.has("notificationId")){e.next=3;break}return e.next=3,this.removeRegistration();case 3:if(t.notificationId&&t.notificationId.length){e.next=6;break}throw K.error("No push notification ID for registration"),new Error("No push notification ID for registration");case 6:return K.trace("Registering",this.channelType,t),r={endpoint_platform:this.context.platform,channel_type:this.channelType,version:this.context.protocolVersion.toString(),message_types:Array.from(t.messageTypes),data:{registration_id:t.notificationId}},i=this.context.productId,a="".concat(this.registrarUrl,"?productId=").concat(i),s={"Content-Type":"application/json"},K.trace("Creating registration for channel ".concat(this.channelType)),e.prev=12,e.next=15,new d.AsyncRetrier(ee).run((function(){return u.twilsock.post(a,s,r,i)}));case 15:o=e.sent,this.registrationId=o.body.id,K.debug("Registration created: ",o),e.next=24;break;case 20:throw e.prev=20,e.t0=e.catch(12),K.error("Registration failed: ",e.t0),e.t0;case 24:return e.abrupt("return",t);case 25:case"end":return e.stop()}}),e,this,[[12,20]])}))),function(e,t){return r.apply(this,arguments)})},{key:"removeRegistration",value:(n=b.default(E.default.mark((function e(){var t,n,r,i=this;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.registrationId){e.next=2;break}return e.abrupt("return");case 2:return t=this.context.productId,n="".concat(this.registrarUrl,"/").concat(this.registrationId,"?productId=").concat(t),r={"Content-Type":"application/json"},K.trace("Removing registration for ".concat(this.channelType)),e.prev=6,e.next=9,new d.AsyncRetrier(Object.assign(ee,{maxAttemptsCount:3})).run((function(){return i.twilsock.delete(n,r,{},t)}));case 9:K.debug("Registration removed for ".concat(this.channelType)),e.next=16;break;case 12:throw e.prev=12,e.t0=e.catch(6),K.error("Failed to remove registration ",this.channelType,e.t0),e.t0;case 16:case"end":return e.stop()}}),e,this,[[6,12]])}))),function(){return n.apply(this,arguments)})},{key:"sendDeviceRemoveRequest",value:(t=b.default(E.default.mark((function e(t){var n,r,i,a,s=this;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(""!==t){e.next=2;break}throw new Error("Empty registration ID");case 2:return n=this.context.productId,r="".concat(this.registrarUrl,"?productId=").concat(n),i={"Content-Type":"application/json"},a={binding_type:this.channelType,address:t},e.prev=6,K.trace("Removing old registrations for ".concat(this.channelType)),e.next=10,new d.AsyncRetrier(Object.assign(ee,{maxAttemptsCount:3})).run((function(){return s.twilsock.delete(r,i,a,n)}));case 10:K.debug("Registration removed for ".concat(this.channelType)),e.next=17;break;case 13:throw e.prev=13,e.t0=e.catch(6),K.error("Failed to remove registration ",this.channelType,e.t0),e.t0;case 17:case"end":return e.stop()}}),e,this,[[6,13]])}))),function(e){return t.apply(this,arguments)})}]),a}(X),ne={exports:{}},re="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(re){var ie=new Uint8Array(16);ne.exports=function(){return re(ie),ie}}else{var ae=new Array(16);ne.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),ae[t]=e>>>((3&t)<<3)&255;return ae}}for(var se=[],oe=0;oe<256;++oe)se[oe]=(oe+256).toString(16).substr(1);var ue,ce,le=function(e,t){var n=t||0,r=se;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")},fe=ne.exports,de=le,pe=0,he=0;var ve=function(e,t,n){var r=t&&n||0,i=t||[],a=(e=e||{}).node||ue,s=void 0!==e.clockseq?e.clockseq:ce;if(null==a||null==s){var o=fe();null==a&&(a=ue=[1|o[0],o[1],o[2],o[3],o[4],o[5]]),null==s&&(s=ce=16383&(o[6]<<8|o[7]))}var u=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:he+1,l=u-pe+(c-he)/1e4;if(l<0&&void 0===e.clockseq&&(s=s+1&16383),(l<0||u>pe)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");pe=u,he=c,ce=s;var f=(1e4*(268435455&(u+=122192928e5))+c)%4294967296;i[r++]=f>>>24&255,i[r++]=f>>>16&255,i[r++]=f>>>8&255,i[r++]=255&f;var d=u/4294967296*1e4&268435455;i[r++]=d>>>8&255,i[r++]=255&d,i[r++]=d>>>24&15|16,i[r++]=d>>>16&255,i[r++]=s>>>8|128,i[r++]=255&s;for(var p=0;p<6;++p)i[r+p]=a[p];return t||de(i)},ye=ne.exports,me=le;var ge=ve,be=function(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||ye)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var a=0;a<16;++a)t[r+a]=i[a];return t||me(i)},ke=be;ke.v1=ge,ke.v4=be;var we=ke;function xe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=S.default(e);if(t){var i=S.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _.default(this,n)}}var _e,Se=function(e){x.default(a,e);var t,n,r,i=xe(a);function a(e,t,n){var r;return k.default(this,a),r=i.call(this,"twilsock"),I.default(R.default(r),"contextId",we.v4()),r.productId=e,r.platform=t,r.twilsock=n,r}return w.default(a,[{key:"updateRegistration",value:(r=b.default(E.default.mark((function e(t,n){var r,i;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.has("messageType")){e.next=2;break}return e.abrupt("return",t);case 2:return r=Array.from(t.messageTypes),i={product_id:this.productId,notification_protocol_version:4,endpoint_platform:this.platform,message_types:r},e.prev=4,e.next=7,this.twilsock.setNotificationsContext(this.contextId,i);case 7:e.next=13;break;case 9:throw e.prev=9,e.t0=e.catch(4),K.error("Failed to update twilsock notification context: ".concat(e.t0)),e.t0;case 13:return e.abrupt("return",t);case 14:case"end":return e.stop()}}),e,this,[[4,9]])}))),function(e,t){return r.apply(this,arguments)})},{key:"removeRegistration",value:(n=b.default(E.default.mark((function e(){return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.twilsock.removeNotificationsContext(this.contextId);case 3:e.next=9;break;case 5:throw e.prev=5,e.t0=e.catch(0),K.error("Failed to remove twilsock notification context: ".concat(e.t0)),e.t0;case 9:case"end":return e.stop()}}),e,this,[[0,5]])}))),function(){return n.apply(this,arguments)})},{key:"sendDeviceRemoveRequest",value:(t=b.default(E.default.mark((function e(t){return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),a}(X);function Ee(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=S.default(e);if(t){var i=S.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _.default(this,n)}}var Te=y.literal("apn","fcm","twilsock");e.Notifications=_e=function(e){x.default(Client,e);var t,n,r,i=Ee(Client);function Client(e){var t,n,r,a,s,o,u,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};k.default(this,Client),u=i.call(this),l.logLevel=null!==(t=l.logLevel)&&void 0!==t?t:"error",K.setLevel(l.logLevel);var f=null!==(n=l.productId)&&void 0!==n?n:"notifications",d=!l.twilsockClient,p=l.twilsockClient=null!==(r=l.twilsockClient)&&void 0!==r?r:new c.TwilsockClient(e,f,l),h=null!==(a=l.notifications)&&void 0!==a?a:{},v=null!==(s=null!==(o=h.region)&&void 0!==o?o:l.region)&&void 0!==s?s:"us1",y="https://ers.".concat(v,".twilio.com/v1/registrations"),m=h.ersUrl||y;u.connectors=new Map;var g=_e._detectPlatform();return u.connectors.set("apn",new te("apn",{protocolVersion:4,productId:f,platform:g},p,m)),u.connectors.set("fcm",new te("fcm",{protocolVersion:3,productId:f,platform:g},p,m)),u.connectors.set("twilsock",new Se(f,g,p)),p.on("stateChanged",(function(e){return u.emit("transportState",e)})),u._connector("twilsock").on("stateChanged",(function(e,t,n){return u.emit("stateChanged",e,t,n)})),u._connector("apn").on("stateChanged",(function(e,t,n){return u.emit("stateChanged",e,t,n)})),u._connector("fcm").on("stateChanged",(function(e,t,n){return u.emit("stateChanged",e,t,n)})),p.on("message",(function(e,t){return u._routeMessage(e,t)})),u.updateToken(e),d&&(p.connect(),u.twilsock=p),u}return w.default(Client,[{key:"shutdown",value:(r=b.default(E.default.mark((function e(){return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectors.clear(),!this.twilsock){e.next=4;break}return e.next=4,this.twilsock.disconnect();case 4:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"setPushRegistrationId",value:function(e,t){K.debug("Set ".concat(e," push registration id '").concat(t,"'")),this._connector(e).setNotificationId(t)}},{key:"subscribe",value:function(e,t){K.debug("Add ".concat(e," subscriptions for message type ").concat(t)),this._connector(e).subscribe(t)}},{key:"unsubscribe",value:function(e,t){K.debug("Remove ".concat(e," subscriptions for message type ").concat(t)),this._connector(e).unsubscribe(t)}},{key:"updateToken",value:function(e){this.connectors.forEach((function(t){return t.updateToken(e)}))}},{key:"commitChanges",value:(n=b.default(E.default.mark((function e(){var t;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=[],this.connectors.forEach((function(e){e.isActive()&&t.push(e.commitChanges())})),e.next=4,Promise.all(t);case 4:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"removeRegistrations",value:(t=b.default(E.default.mark((function e(t,n){return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._connector(t).sendDeviceRemoveRequest(n);case 2:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})},{key:"handlePushNotification",value:function(e){return{messageType:e.twi_message_type,payload:e.payload}}},{key:"_routeMessage",value:function(e,t){K.debug("Notification message arrived: ",e,t),this.emit("message",e,t)}},{key:"_connector",value:function(e){var t=this.connectors.get(e);if(!t)throw new Error("Unknown channel type: ".concat(e));return t}}],[{key:"_detectPlatform",value:function(){var e="";return"undefined"!=typeof navigator?(e="unknown",void 0!==navigator.product&&(e=navigator.product),void 0!==navigator.userAgent&&(e=navigator.userAgent)):e="web",e.substring(0,128)}}]),Client}(L),A([y.validateTypes(Te,y.nonEmptyString),j("design:type",Function),j("design:paramtypes",[String,String]),j("design:returntype",void 0)],e.Notifications.prototype,"setPushRegistrationId",null),A([y.validateTypes(Te,y.nonEmptyString),j("design:type",Function),j("design:paramtypes",[String,String]),j("design:returntype",void 0)],e.Notifications.prototype,"subscribe",null),A([y.validateTypes(Te,y.nonEmptyString),j("design:type",Function),j("design:paramtypes",[String,String]),j("design:returntype",void 0)],e.Notifications.prototype,"unsubscribe",null),A([y.validateTypes(y.nonEmptyString),j("design:type",Function),j("design:paramtypes",[String]),j("design:returntype",void 0)],e.Notifications.prototype,"updateToken",null),A([y.validateTypesAsync(Te,y.nonEmptyString),j("design:type",Function),j("design:paramtypes",[String,String]),j("design:returntype",Promise)],e.Notifications.prototype,"removeRegistrations",null),e.Notifications=_e=A([y.validateConstructorTypes(y.nonEmptyString,[y.pureObject,"undefined",y.literal(null)]),j("design:paramtypes",[String,Object])],e.Notifications)}(TS);var DS={};Object.defineProperty(DS,"__esModule",{value:!0});var FS=yv.exports,BS=xh.exports,qS=_h.exports,WS=Sh.exports,zS=Eh.exports,GS=Rh.exports,JS=Oh.exports,VS=Ch.exports,$S=bv,KS=Ih.exports,HS=Dv,YS=vv,QS=Q_.exports,XS=ld.exports,ZS=Wv.exports,eE=wh,tE=hm,nE=mv.exports,rE=tS.exports;function iE(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function aE(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var sE=iE(FS),oE=iE(BS),uE=iE(qS),cE=iE(WS),lE=iE(zS),fE=iE(GS),dE=iE(JS),pE=iE(VS),hE=iE($S),vE=iE(KS),yE=iE(QS),mE=aE(XS),gE=iE(ZS),bE=aE(tE),kE=iE(nE),wE=aE(rE);function xE(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":vE.default(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function _E(e,t){if("object"===("undefined"==typeof Reflect?"undefined":vE.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function SE(){}function EE(){EE.init.call(this)}function TE(e){return void 0===e._maxListeners?EE.defaultMaxListeners:e._maxListeners}function RE(e,t,n){if(t)e.call(n);else for(var r=e.length,i=LE(e,r),a=0;a<r;++a)i[a].call(n)}function IE(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=LE(e,i),s=0;s<i;++s)a[s].call(n,r)}function OE(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=LE(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function CE(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=LE(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function PE(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=LE(e,i),s=0;s<i;++s)a[s].apply(n,r)}function AE(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new SE,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=TE(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function jE(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function ME(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function LE(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}SE.prototype=Object.create(null),EE.EventEmitter=EE,EE.usingDomains=!1,EE.prototype.domain=void 0,EE.prototype._events=void 0,EE.prototype._maxListeners=void 0,EE.defaultMaxListeners=10,EE.init=function(){this.domain=null,EE.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new SE,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},EE.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},EE.prototype.getMaxListeners=function(){return TE(this)},EE.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:RE(n,l,this);break;case 2:IE(n,l,this,arguments[1]);break;case 3:OE(n,l,this,arguments[1],arguments[2]);break;case 4:CE(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];PE(n,l,this,i)}return!0},EE.prototype.addListener=function(e,t){return AE(this,e,t,!1)},EE.prototype.on=EE.prototype.addListener,EE.prototype.prependListener=function(e,t){return AE(this,e,t,!0)},EE.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,jE(this,e,t)),this},EE.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,jE(this,e,t)),this},EE.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new SE:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new SE,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},EE.prototype.off=function(e,t){return this.removeListener(e,t)},EE.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new SE,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new SE:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new SE,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},EE.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},EE.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):ME.call(e,t)},EE.prototype.listenerCount=ME,EE.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var NE=function(){function e(t){oE.default(this,e),this.base=t,this.args=new Array,this.paths=new Array}return uE.default(e,[{key:"pathSegment",value:function(e){return this.paths.push(encodeURIComponent(e)),this}},{key:"queryParam",value:function(e,t){return void 0!==t&&this.args.push(encodeURIComponent(e)+"="+encodeURIComponent(t)),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}}]),e}();function UE(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=dE.default(e);if(t){var i=dE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return fE.default(this,n)}}var DE=function(e){lE.default(n,e);var t=UE(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return oE.default(this,n),(r=t.call(this)).name=r.constructor.name,r.message="".concat(e," (status: ").concat(i,", code: ").concat(a,")"),r.status=i,r.code=a,r}return n}(yE.default(Error)),FE=function(e){lE.default(n,e);var t=UE(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3?arguments[3]:void 0;return oE.default(this,n),(r=t.call(this,e,i,a)).body=s,r}return n}(DE);function BE(e){return JSON.parse(JSON.stringify(e))}function qE(e){if(!(void 0===e||WE(e)))throw new DE("Invalid pageSize parameter. Expected a positive integer, was '".concat(e,"'."),400,20007)}function WE(e){return function(e){return!isNaN(parseInt(e))&&isFinite(e)}(e)&&e>0}var zE=mE.getLogger("twilio-sync");function GE(e,t){return["".concat((new Date).toISOString()," Sync ").concat(e,":")].concat(Array.from(t))}var JE=function(e){zE.setLevel(e)},VE=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];zE.trace.apply(null,GE("T",t))},$E=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];zE.debug.apply(null,GE("D",t))},KE=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];zE.warn.apply(null,GE("W",t))},HE=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];zE.error.apply(null,GE("E",t))},YE="/v4/Subscriptions",QE="/v3/Maps",XE="/v3/Lists",ZE="/v3/Documents",eT="/v3/Streams",tT="/v3/Insights";function nT(e,t,n){return e&&void 0!==e[t]?e[t]:n}var rT=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};oE.default(this,e);var n=t.region||"us1",r="https://cds.".concat(n,".twilio.com"),i=t.cdsUri||r;this.settings={subscriptionsUri:i+YE,documentsUri:i+ZE,listsUri:i+XE,mapsUri:i+QE,streamsUri:i+eT,insightsUri:i+tT,sessionStorageEnabled:nT(t.Sync,"enableSessionStorage",!0),productId:t.productId}}return uE.default(e,[{key:"subscriptionsUri",get:function(){return this.settings.subscriptionsUri}},{key:"documentsUri",get:function(){return this.settings.documentsUri}},{key:"listsUri",get:function(){return this.settings.listsUri}},{key:"mapsUri",get:function(){return this.settings.mapsUri}},{key:"streamsUri",get:function(){return this.settings.streamsUri}},{key:"insightsUri",get:function(){return this.settings.insightsUri}},{key:"backoffConfig",get:function(){return this.settings.backoffConfig||{}}},{key:"sessionStorageEnabled",get:function(){return this.settings.sessionStorageEnabled}},{key:"productId",get:function(){return this.settings.productId}}]),e}();function iT(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return aT(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return aT(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function aT(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var sT=function(){function e(t){oE.default(this,e),this.localObject=t,this.pendingCorrelationId=null,this.pendingAction=null,this.established=!1,this.retryCount=0}return uE.default(e,[{key:"sid",get:function(){return this.localObject.sid}},{key:"type",get:function(){return this.localObject.type}},{key:"lastEventId",get:function(){return this.localObject.lastEventId}},{key:"indexName",get:function(){return this.localObject.indexName}},{key:"queryString",get:function(){return this.localObject.queryString}},{key:"isEstablished",get:function(){return this.established}},{key:"update",value:function(e,t){this.localObject._update(e,t)}},{key:"updatePending",value:function(e,t){this.pendingAction=e,this.pendingCorrelationId=t}},{key:"reset",value:function(){this.updatePending(null,null),this.retryCount=0,this.established=!1,this.setSubscriptionState("none")}},{key:"markAsFailed",value:function(e){this.rejectedWithError=e.error,this.updatePending(null,null),this.localObject.reportFailure(new DE("Failed to subscribe on service events: ".concat(e.error.message),e.error.status,e.error.code))}},{key:"complete",value:function(e){this.updatePending(null,null),this.established=!0,this.localObject._advanceLastEventId(e)}},{key:"setSubscriptionState",value:function(e){this.localObject._setSubscriptionState(e)}}]),e}(),oT=function(){function e(t){var n=this;oE.default(this,e),pE.default(this,"isConnected",!1),pE.default(this,"maxBatchSize",100),pE.default(this,"subscriptionTtlTimer",null),pE.default(this,"pendingPokeReason",null),this.services=t,this.subscriptions=new Map,this.persisted=new Map,this.latestPokeResponseArrivalTimestampByCorrelationId=new Map;this.backoff=eE.Backoff.exponential(Object.assign({randomisationFactor:.2,initialDelay:100,maxDelay:12e4},this.services.config.backoffConfig)),this.backoff.on("ready",(function(){var e=n.getSubscriptionUpdateBatch(),t=e.action,r=e.subscriptions;t?n.applyNewSubscriptionUpdateBatch(t,r):(n.backoff.reset(),$E("All subscriptions resolved."))}))}var t;return uE.default(e,[{key:"getSubscriptionUpdateBatch",value:function(){function e(e,t,n,r){var i,a=[],s=iT(e);try{for(s.s();!(i=s.n()).done;){var o=gE.default(i.value,2),u=o[0],c=o[1];if(!t.get(u)&&n!==c.pendingAction&&!c.rejectedWithError&&(a.push(c),r&&a.length>=r))break}}catch(e){s.e(e)}finally{s.f()}return a}var t=e(this.subscriptions,this.persisted,"establish",this.maxBatchSize);if(t.length>0)return{action:"establish",subscriptions:t};var n=e(this.persisted,this.subscriptions,"cancel",this.maxBatchSize);return n.length>0?{action:"cancel",subscriptions:n}:{action:null,subscriptions:null}}},{key:"persist",value:function(){this.backoff.backoff()}},{key:"applyNewSubscriptionUpdateBatch",value:(t=sE.default(hE.default.mark((function e(t,n){var r,i,a,s,o,u,c,l,f,d,p,h,v=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isConnected){e.next=4;break}return $E("Twilsock connection (required for subscription) not ready; waiting…"),this.backoff.reset(),e.abrupt("return");case 4:n=this.processLocalActions(t,n),r=(new Date).getTime(),i=iT(n);try{for(i.s();!(a=i.n()).done;)s=a.value,this.recordActionAttemptOn(s,t,r)}catch(e){i.e(e)}finally{i.f()}return o=this.pendingPokeReason,this.pendingPokeReason=null,e.prev=10,e.next=13,this.request(t,r,o,n);case 13:u=e.sent,c=u.body.max_batch_size,!isNaN(parseInt(c))&&isFinite(c)&&c>0&&(this.maxBatchSize=c),this.subscriptionTtlTimer||(l=u.body.ttl_in_s,!isNaN(parseFloat(l))&&isFinite(l)&&l>0&&(this.subscriptionTtlTimer=setTimeout((function(){return v.onSubscriptionTtlElapsed()}),1e3*l))),"establish"===t&&(f=u.body.estimated_delivery_in_ms,!isNaN(parseFloat(f))&&isFinite(f)&&f>0?setTimeout((function(){return v.verifyPokeDelivery(r,f,n)}),f):HE("Invalid timeout: ".concat(f)),n.filter((function(e){return e.pendingCorrelationId===r})).forEach((function(e){return e.setSubscriptionState("response_in_flight")}))),this.backoff.reset(),e.next=26;break;case 21:e.prev=21,e.t0=e.catch(10),d=iT(n);try{for(d.s();!(p=d.n()).done;)h=p.value,this.recordActionFailureOn(h,t)}catch(e){d.e(e)}finally{d.f()}e.t0 instanceof YS.TransportUnavailableError?($E("Twilsock connection (required for subscription) not ready (c:".concat(r,"); waiting…")),this.backoff.reset()):($E("Failed an attempt to ".concat(t," subscriptions (c:").concat(r,"); retrying"),e.t0),this.persist());case 26:case"end":return e.stop()}}),e,this,[[10,21]])}))),function(e,n){return t.apply(this,arguments)})},{key:"verifyPokeDelivery",value:function(e,t,n){var r=this,i=this.latestPokeResponseArrivalTimestampByCorrelationId.get(e),a=i?(new Date).getTime()-i:t;a>=t?(n.filter((function(t){return t.pendingCorrelationId===e})).forEach((function(e){e.updatePending(null,null),e.retryCount++,r.persisted.delete(e.sid)})),this.persist(),this.latestPokeResponseArrivalTimestampByCorrelationId.delete(e)):setTimeout((function(){return r.verifyPokeDelivery(e,t,n)}),t-a)}},{key:"processLocalActions",value:function(e,t){return"cancel"===e?t.filter((function(e){return!e.rejectedWithError})):t}},{key:"recordActionAttemptOn",value:function(e,t,n){if(e.setSubscriptionState("request_in_flight"),"establish"===t)this.persisted.set(e.sid,e),e.updatePending(t,n);else{var r=this.persisted.get(e.sid);r&&r.updatePending(t,n)}}},{key:"recordActionFailureOn",value:function(e,t){e.setSubscriptionState("none"),e.updatePending(null,null),"establish"===t&&this.persisted.delete(e.sid)}},{key:"request",value:function(e,t,n,r){var i=r.map((function(t){return{object_sid:t.sid,object_type:t.type,last_event_id:"establish"===e?t.lastEventId:void 0,index_name:"establish"===e?t.indexName:void 0,query_string:"establish"===e?t.queryString:void 0}})),a=r.filter((function(e){return e.retryCount>0})).length;$E("Attempting '".concat(e,"' request (c:").concat(t,"):"),i);var s={event_protocol_version:3,action:e,correlation_id:t,retried_requests:a,ttl_in_s:-1,requests:i};return"ttl"===n&&(s.reason=n),this.services.network.post(this.services.config.subscriptionsUri,s)}},{key:"add",value:function(e,t){$E("Establishing intent to subscribe to ".concat(e));var n=this.subscriptions.get(e);n&&t&&n.lastEventId===t.lastEventId||(this.persisted.delete(e),this.subscriptions.set(e,new sT(t)),this.persist())}},{key:"remove",value:function(e){$E("Establishing intent to unsubscribe from ".concat(e)),this.subscriptions.delete(e)&&this.persist()}},{key:"acceptMessage",value:function(e,t){var n;switch(VE("Subscriptions received",e),e.correlation_id&&this.latestPokeResponseArrivalTimestampByCorrelationId.set(e.correlation_id,(new Date).getTime()),e.event_type){case"subscription_established":this.applySubscriptionEstablishedMessage(e.event,e.correlation_id);break;case"subscription_canceled":this.applySubscriptionCancelledMessage(e.event,e.correlation_id);break;case"subscription_failed":this.applySubscriptionFailedMessage(e.event,e.correlation_id);break;case(n=e.event_type.match(/^(?:map|list|document|stream|live_query)_/)||{}).input:var r;switch(n[0]){case"map_":r=e.event.map_sid;break;case"list_":r=e.event.list_sid;break;case"document_":r=e.event.document_sid;break;case"stream_":r=e.event.stream_sid;break;case"live_query_":r=e.event.query_id,t=!1,!0===e.strictly_ordered&&(t=!0);break;default:r=void 0}this.applyEventToSubscribedEntity(r,e,t);break;default:$E("Dropping unknown message type ".concat(e.event_type))}}},{key:"applySubscriptionEstablishedMessage",value:function(e,t){var n=e.object_sid,r=this.persisted.get(e.object_sid);r&&r.pendingCorrelationId===t?"interrupted"===e.replay_status?($E("Event Replay for subscription to ".concat(n," (c:").concat(t,") interrupted; continuing eagerly.")),r.updatePending(null,null),this.persisted.delete(r.sid),this.backoff.reset()):"completed"===e.replay_status&&($E("Event Replay for subscription to ".concat(n," (c:").concat(t,") completed. Subscription is ready.")),r.complete(e.last_event_id),this.persisted.set(e.object_sid,r),r.setSubscriptionState("established"),this.backoff.reset()):$E("Late message for ".concat(e.object_sid," (c:").concat(t,") dropped.")),this.persist()}},{key:"applySubscriptionCancelledMessage",value:function(e,t){var n=this.persisted.get(e.object_sid);n&&n.pendingCorrelationId===t?(n.updatePending(null,null),n.setSubscriptionState("none"),this.persisted.delete(e.object_sid)):$E("Late message for ".concat(e.object_sid," (c:").concat(t,") dropped.")),this.persist()}},{key:"applySubscriptionFailedMessage",value:function(e,t){var n=e.object_sid,r=this.subscriptions.get(n),i=this.persisted.get(n);r&&i?i.pendingCorrelationId===t&&(HE("Failed to subscribe on ".concat(i.sid),e.error),i.markAsFailed(e),i.setSubscriptionState("none")):!r&&i&&(this.persisted.delete(n),i.setSubscriptionState("none")),this.persist()}},{key:"applyEventToSubscribedEntity",value:function(e,t,n){if(e){var r;n=n||(r=this.persisted.get(e))&&r.isEstablished;var i=this.subscriptions.get(e);i?(t.event.type=t.event_type,i.update(t.event,n)):$E("Message dropped for SID '".concat(e,"', for which there is no subscription."))}}},{key:"onConnectionStateChanged",value:function(e){this.isConnected=e,e&&this.poke("reconnect")}},{key:"onSubscriptionTtlElapsed",value:function(){this.isConnected&&this.poke("ttl")}},{key:"poke",value:function(e){$E("Triggering event replay for all subscriptions, reason=".concat(e)),this.pendingPokeReason=e,this.subscriptionTtlTimer&&(clearTimeout(this.subscriptionTtlTimer),this.subscriptionTtlTimer=null);var t,n=[],r=iT(this.persisted.values());try{for(r.s();!(t=r.n()).done;){var i=t.value;i.reset(),i.rejectedWithError&&n.push(i)}}catch(e){r.e(e)}finally{r.f()}this.persisted.clear();for(var a=0,s=n;a<s.length;a++){var o=s[a];this.persisted.set(o.sid,o)}this.persist()}},{key:"shutdown",value:function(){this.backoff.reset(),this.subscriptions.clear()}}]),e}();function uT(e){if(e.body&&e.body.message)return e.body.message;switch(e.status){case 429:return"Throttled by server";case 404:return"Not found from server";default:return"Error from server"}}function cT(e){return e.body?e.body.code:0}function lT(e){return 409===e.status?new FE(uT(e),e.status,cT(e),e.body):e.status?new DE(uT(e),e.status,cT(e)):e instanceof YS.TransportUnavailableError?e:new DE(e.message,0,0)}var fT=function(){function e(t,n,r){oE.default(this,e),this.clientInfo=t,this.config=n,this.transport=r}return uE.default(e,[{key:"createHeaders",value:function(){return{"Content-Type":"application/json","Twilio-Sync-Client-Info":JSON.stringify(this.clientInfo),"Twilio-Request-Id":"RQ"+bE.v4().replace(/-/g,"")}}},{key:"backoffConfig",value:function(){return Object.assign({min:4e3,max:6e4,maxAttemptsTime:9e4,randomness:.2},this.config.backoffConfig)}},{key:"executeWithRetry",value:function(e){var t=this,n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new Promise((function(r,i){var a=[502,503,504];n&&a.push(429);var s=new eE.Retrier(t.backoffConfig());s.on("attempt",(function(){e().then((function(e){return s.succeeded(e)})).catch((function(e){if(a.includes(e.status)){var t=parseInt(e.headers?e.headers["Retry-After"]:null);s.failed(lT(e),isNaN(t)?null:1e3*t)}else"Twilsock disconnected"===e.message?s.failed(lT(e)):(s.removeAllListeners(),s.cancel(),i(lT(e)))}))})),s.on("succeeded",(function(e){r(e)})),s.on("cancelled",(function(e){return i(lT(e))})),s.on("failed",(function(e){return i(lT(e))})),s.start()}))}},{key:"get",value:function(e){var t=this,n=this.createHeaders();return $E("GET",e,"ID:",n["Twilio-Request-Id"]),this.executeWithRetry((function(){return t.transport.get(e,n,t.config.productId)}),!0)}},{key:"post",value:function(e,t,n){var r=this,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=this.createHeaders();return null!=n&&(a["If-Match"]=n),$E("POST",e,"ID:",a["Twilio-Request-Id"]),this.executeWithRetry((function(){return r.transport.post(e,a,t,r.config.productId)}),i)}},{key:"put",value:function(e,t,n){var r=this,i=this.createHeaders();return null!=n&&(i["If-Match"]=n),$E("PUT",e,"ID:",i["Twilio-Request-Id"]),this.executeWithRetry((function(){return r.transport.put(e,i,t,r.config.productId)}),!1)}},{key:"delete",value:function(e){var t=this,n=this.createHeaders();return $E("DELETE",e,"ID:",n["Twilio-Request-Id"]),this.executeWithRetry((function(){return t.transport.delete(e,n,t.config.productId)}),!1)}}]),e}(),dT=function(){function e(t,n){oE.default(this,e),this.config=t,this.storageId=null;try{this.storage=n||sessionStorage}catch(e){}}return uE.default(e,[{key:"storageKey",value:function(e,t){return"".concat(this.storageId,"::").concat(e,"::").concat(t)}},{key:"isReady",get:function(){return this.config.sessionStorageEnabled&&!!this.storageId}},{key:"updateStorageId",value:function(e){this.storageId=e}},{key:"store",value:function(e,t,n){return this.isReady?this._store(this.storageKey(e,t),n):null}},{key:"read",value:function(e,t){return this.isReady?this._read(this.storageKey(e,t)):null}},{key:"remove",value:function(e,t,n){if(!this.isReady)return null;try{this.storage.removeItem(this.storageKey(e,t)),n&&this.storage.removeItem(this.storageKey(e,n))}catch(e){}}},{key:"update",value:function(e,t,n,r){if(!this.isReady)return null;this._apply(this.storageKey(e,t),r),n&&this._apply(this.storageKey(e,n),r)}},{key:"_store",value:function(e,t){try{this.storage.setItem(e,JSON.stringify(t))}catch(e){}}},{key:"_read",value:function(e){try{var t=this.storage.getItem(e);if(t)return JSON.parse(t)}catch(e){}return null}},{key:"_apply",value:function(e,t){var n=this._read(e);if(!n)return!1;this._store(e,Object.assign(n,t))}}]),e}();function pT(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return hT(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return hT(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function hT(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var vT=function(){function e(t,n){oE.default(this,e),this.services=t,this.removalHandler=n,this.subscriptionState="none",this._attachedListeners=new Map}return uE.default(e,[{key:"_advanceLastEventId",value:function(e,t){}},{key:"reportFailure",value:function(e){404===e.status?this.onRemoved(!1):this.broadcastEventToListeners("failure",e)}},{key:"_subscribe",value:function(){this.services.router._subscribe(this.sid,this)}},{key:"_unsubscribe",value:function(){this.services.router._unsubscribe(this.sid)}},{key:"_setSubscriptionState",value:function(e){this.subscriptionState=e,this.broadcastEventToListeners("_subscriptionStateChanged",e)}},{key:"close",value:function(){this._unsubscribe(),null!=this.removalHandler&&this.removalHandler(this.type,this.sid,this.uniqueName)}},{key:"attach",value:function(e){var t=e.listenerUuid;this._attachedListeners.get(t)||(this._attachedListeners.size||this._subscribe(),this._attachedListeners.set(t,e))}},{key:"detach",value:function(e){this._attachedListeners.delete(e),this._attachedListeners.size||this.close()}},{key:"broadcastEventToListeners",value:function(e,t){var n,r=pT(this._attachedListeners.values());try{for(r.s();!(n=r.n()).done;){n.value.emit(e,t)}}catch(e){r.e(e)}finally{r.f()}}}]),e}(),yT=function(){function e(t){oE.default(this,e),pE.default(this,"queuedRequests",[]),pE.default(this,"isRequestInFlight",!1),this.inputMergingFunction=t}return uE.default(e,[{key:"add",value:function(e,t){var n=this,r=new Promise((function(r,i){return n.queuedRequests.push({input:e,requestFunction:t,resolve:r,reject:i})}));return this.wakeupQueue(),r}},{key:"squashAndAdd",value:function(e,t){var n,r=this.queuedRequests;this.queuedRequests=[],r.length>0?(n=r.map((function(e){return e.input})).reduce(this.inputMergingFunction),n=this.inputMergingFunction(n,e)):n=e;var i=this.add(n,t);return r.forEach((function(e){return i.then(e.resolve,e.reject)})),i}},{key:"isEmpty",value:function(){return 0===this.queuedRequests.length&&!this.isRequestInFlight}},{key:"wakeupQueue",value:function(){var e=this;if(0!==this.queuedRequests.length&&!this.isRequestInFlight){var t=this.queuedRequests.shift();this.isRequestInFlight=!0,t.requestFunction(t.input).then(t.resolve,t.reject).then((function(t){e.isRequestInFlight=!1,e.wakeupQueue()}))}}}]),e}(),mT=function(){function e(t){oE.default(this,e),pE.default(this,"queueByNamespaceKey",new Map),this.inputReducer=t}var t,n;return uE.default(e,[{key:"add",value:function(){var e=sE.default(hE.default.mark((function e(t,n,r){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.invokeQueueMethod(t,(function(e){return e.add(n,r)})));case 1:case"end":return e.stop()}}),e,this)})));return function(t,n,r){return e.apply(this,arguments)}}()},{key:"squashAndAdd",value:(n=sE.default(hE.default.mark((function e(t,n,r){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.invokeQueueMethod(t,(function(e){return e.squashAndAdd(n,r)})));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"invokeQueueMethod",value:(t=sE.default(hE.default.mark((function e(t,n){var r,i;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.queueByNamespaceKey.has(t)||this.queueByNamespaceKey.set(t,new yT(this.inputReducer)),r=this.queueByNamespaceKey.get(t),i=n(r),this.queueByNamespaceKey.get(t).isEmpty()&&this.queueByNamespaceKey.delete(t),e.abrupt("return",i);case 5:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})}]),e}();function gT(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=dE.default(e);if(t){var i=dE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return fE.default(this,n)}}var bT=function(e){lE.default(n,e);var t=gT(n);function n(){var e;return oE.default(this,n),(e=t.call(this)).closed=!1,e.uuid=tE.v4(),e}return uE.default(n,[{key:"listenerUuid",get:function(){return this.uuid}},{key:"close",value:function(){this.removeAllListeners(),this.closed=!0}},{key:"ensureNotClosed",value:function(){if(this.closed)throw new Error("Invalid operation on closed object")}}]),n}(EE);function kT(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=dE.default(e);if(t){var i=dE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return fE.default(this,n)}}var wT=function(e){lE.default(f,e);var t,n,r,i,a,s,o,u,c,l=kT(f);function f(e,t,n){var r;oE.default(this,f),r=l.call(this,e,n),pE.default(cE.default(r),"isDeleted",!1);return r.updateMergingQueue=new yT((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.descriptor=t,r.descriptor.data=r.descriptor.data||{},r.descriptor.date_updated=new Date(r.descriptor.date_updated),r}return uE.default(f,[{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"document"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"data",get:function(){return this.descriptor.data}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"_update",value:function(e){switch(e.date_created=new Date(e.date_created),e.type){case"document_updated":if(e.id<=this.lastEventId){VE("Document update skipped, current:",this.lastEventId,", remote:",e.id);break}var t=void 0!==this.descriptor.data?BE(this.descriptor.data):null;this.descriptor.last_event_id=e.id,this.descriptor.revision=e.document_revision,this.descriptor.date_updated=e.date_created,this.descriptor.data=e.document_data,this.broadcastEventToListeners("updated",{data:e.document_data,isLocal:!1,previousData:t}),this.services.storage.update(this.type,this.sid,this.uniqueName,{last_event_id:e.id,revision:e.document_revision,date_updated:e.date_created,data:e.document_data});break;case"document_removed":this.onRemoved(!1)}}},{key:"set",value:(c=sE.default(hE.default.mark((function e(t,n){var r,i=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n||{},e.abrupt("return",this.updateMergingQueue.squashAndAdd(r,(function(e){return i._setUnconditionally(t,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return c.apply(this,arguments)})},{key:"mutate",value:(u=sE.default(hE.default.mark((function e(t,n){var r,i=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n||{},e.abrupt("return",this.updateMergingQueue.add(r,(function(e){return i._setWithIfMatch(t,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"update",value:(o=sE.default(hE.default.mark((function e(t,n){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mutate((function(e){return Object.assign(e,t)}),n));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"setTtl",value:(s=sE.default(hE.default.mark((function e(t){var n;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._postUpdateToServer({ttl:t});case 2:n=e.sent,this.descriptor.date_expires=n.date_expires;case 4:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"_setUnconditionally",value:(a=sE.default(hE.default.mark((function e(t,n){var r;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._postUpdateToServer({data:t,revision:void 0,ttl:n});case 2:return r=e.sent,this._handleSuccessfulUpdateResult(r),e.abrupt("return",this.descriptor.data);case 5:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"_setWithIfMatch",value:(i=sE.default(hE.default.mark((function e(t,n){var r,i,a;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=t(BE(this.descriptor.data)))){e.next=22;break}return i=this.revision,e.prev=3,e.next=6,this._postUpdateToServer({data:r,revision:i,ttl:n});case 6:return a=e.sent,this._handleSuccessfulUpdateResult(a),e.abrupt("return",this.descriptor.data);case 11:if(e.prev=11,e.t0=e.catch(3),412!==e.t0.status){e.next=19;break}return e.next=16,this._softSync();case 16:return e.abrupt("return",this._setWithIfMatch(t));case 19:throw e.t0;case 20:e.next=23;break;case 22:return e.abrupt("return",this.descriptor.data);case 23:case"end":return e.stop()}}),e,this,[[3,11]])}))),function(e,t){return i.apply(this,arguments)})},{key:"_handleSuccessfulUpdateResult",value:function(e){if(!(e.last_event_id<=this.descriptor.last_event_id)){var t=void 0!==this.descriptor.data?BE(this.descriptor.data):null;this.descriptor.revision=e.revision,this.descriptor.data=e.data,this.descriptor.last_event_id=e.last_event_id,this.descriptor.date_expires=e.date_expires,this.descriptor.date_updated=new Date(e.date_updated),this.services.storage.update(this.type,this.sid,this.uniqueName,{last_event_id:e.last_event_id,revision:e.revision,date_updated:e.date_updated,data:e.data}),this.broadcastEventToListeners("updated",{data:this.descriptor.data,isLocal:!0,previousData:t})}}},{key:"_postUpdateToServer",value:(r=sE.default(hE.default.mark((function e(t){var n,r,i;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isDeleted){e.next=17;break}return n={data:t.data},void 0!==t.ttl&&(n.ttl=t.ttl),r=t.revision,e.prev=4,e.next=7,this.services.network.post(this.uri,n,r);case 7:return i=e.sent,e.abrupt("return",{revision:i.body.revision,data:t.data,last_event_id:i.body.last_event_id,date_updated:i.body.date_updated,date_expires:i.body.date_expires});case 11:throw e.prev=11,e.t0=e.catch(4),404===e.t0.status&&this.onRemoved(!1),e.t0;case 15:e.next=18;break;case 17:return e.abrupt("return",Promise.reject(new DE("The Document has been removed",404,54100)));case 18:case"end":return e.stop()}}),e,this,[[4,11]])}))),function(e){return r.apply(this,arguments)})},{key:"_softSync",value:(n=sE.default(hE.default.mark((function e(){var t=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.services.network.get(this.uri).then((function(e){var n={type:"document_updated",id:e.body.last_event_id,document_revision:e.body.revision,document_data:e.body.data,date_created:e.body.date_updated};return t._update(n),t})).catch((function(e){404===e.status?t.onRemoved(!1):HE("Can't get updates for ".concat(t.sid,":"),e)})));case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"onRemoved",value:function(e){if(!this.isDeleted){var t=void 0!==this.descriptor.data?BE(this.descriptor.data):null;this.isDeleted=!0,this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e,previousData:t})}}},{key:"removeDocument",value:(t=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isDeleted){e.next=6;break}return e.next=3,this.services.network.delete(this.uri);case 3:this.onRemoved(!0),e.next=7;break;case 6:return e.abrupt("return",Promise.reject(new DE("The Document has been removed",404,54100)));case 7:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}],[{key:"type",get:function(){return"document"}}]),f}(vT),xT=function(e){lE.default(o,e);var t,n,r,i,a,s=kT(o);function o(e){var t;return oE.default(this,o),(t=s.call(this)).syncDocumentImpl=e,t.syncDocumentImpl.attach(cE.default(t)),t}return uE.default(o,[{key:"uri",get:function(){return this.syncDocumentImpl.uri}},{key:"revision",get:function(){return this.syncDocumentImpl.revision}},{key:"lastEventId",get:function(){return this.syncDocumentImpl.lastEventId}},{key:"dateExpires",get:function(){return this.syncDocumentImpl.dateExpires}},{key:"type",get:function(){return wT.type}},{key:"sid",get:function(){return this.syncDocumentImpl.sid}},{key:"data",get:function(){return this.syncDocumentImpl.data}},{key:"dateUpdated",get:function(){return this.syncDocumentImpl.dateUpdated}},{key:"uniqueName",get:function(){return this.syncDocumentImpl.uniqueName}},{key:"set",value:(a=sE.default(hE.default.mark((function e(t,n){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.set(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"mutate",value:(i=sE.default(hE.default.mark((function e(t,n){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.mutate(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return i.apply(this,arguments)})},{key:"update",value:(r=sE.default(hE.default.mark((function e(t,n){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.update(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"setTtl",value:(n=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.setTtl(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"removeDocument",value:(t=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.removeDocument());case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"close",value:function(){kE.default(dE.default(o.prototype),"close",this).call(this),this.syncDocumentImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return wT.type}}]),o}(bT);pE.default(xT,"removed","removed"),pE.default(xT,"updated","updated"),xE([HS.validateTypesAsync(HS.pureObject,["undefined",HS.objectSchema("document metadata",{ttl:[HS.nonNegativeInteger,"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Object,Object]),_E("design:returntype",Promise)],xT.prototype,"set",null),xE([HS.validateTypesAsync("function",["undefined",HS.objectSchema("document metadata",{ttl:[HS.nonNegativeInteger,"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Function,Object]),_E("design:returntype",Promise)],xT.prototype,"mutate",null),xE([HS.validateTypesAsync(HS.pureObject,["undefined",HS.objectSchema("document metadata",{ttl:[HS.nonNegativeInteger,"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Object,Object]),_E("design:returntype",Promise)],xT.prototype,"update",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger),_E("design:type",Function),_E("design:paramtypes",[Number]),_E("design:returntype",Promise)],xT.prototype,"setTtl",null);var _T=function(){function e(t){oE.default(this,e),this.descriptor=t}return uE.default(e,[{key:"uri",get:function(){return this.descriptor.uri}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.lastEventId}},{key:"dateUpdated",get:function(){return this.descriptor.dateUpdated}},{key:"dateExpires",get:function(){return this.descriptor.dateExpires}},{key:"index",get:function(){return this.descriptor.index}},{key:"data",get:function(){return this.descriptor.data}},{key:"update",value:function(e,t,n,r){return this.descriptor.lastEventId=e,this.descriptor.revision=t,this.descriptor.data=n,this.descriptor.dateUpdated=r,this}},{key:"updateDateExpires",value:function(e){this.descriptor.dateExpires=e}}]),e}(),Paginator=function(){function Paginator(e,t,n,r){oE.default(this,Paginator),this.prevToken=n,this.nextToken=r,this.items=e,this.source=t}var e,t;return uE.default(Paginator,[{key:"hasNextPage",get:function(){return!!this.nextToken}},{key:"hasPrevPage",get:function(){return!!this.prevToken}},{key:"nextPage",value:(t=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.hasNextPage){e.next=2;break}throw new Error("No next page");case 2:return e.abrupt("return",this.source(this.nextToken));case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"prevPage",value:(e=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.hasPrevPage){e.next=2;break}throw new Error("No previous page");case 2:return e.abrupt("return",this.source(this.prevToken));case 3:case"end":return e.stop()}}),e,this)}))),function(){return e.apply(this,arguments)})}]),Paginator}();function ST(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return ET(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ET(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function ET(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var TT=function(){function e(t,n){oE.default(this,e),this.balanceFactor=0,this.key=t,this.value=n,this.parent=null,this.left=null,this.right=null}return uE.default(e,[{key:"isRoot",get:function(){return null===this.parent}},{key:"isLeaf",get:function(){return null===this.left&&null===this.right}},{key:"isLeftChild",get:function(){return this.parent.left===this}},{key:"update",value:function(e){this.value=e}},{key:"replace",value:function(e,t){e&&(this.left===t?this.left=t:this.right===t&&(this.right=t))}}]),e}(),RT=function(){function e(t,n){oE.default(this,e),this.isLessThan=t||function(e,t){return e<t},this.isEqual=n||function(e,t){return e===t},this.root=null,this.count=null}return uE.default(e,[{key:"size",get:function(){return this.count}},{key:"clear",value:function(){this.root=null,this.count=0}},{key:"set",value:function(e,t){var n=this.getNode(e);n?n.update(t):this.insert(e,t)}},{key:"insert",value:function(e,t){var n=new TT(e,t);if(this.count++,this.root){for(var r=this.root;;)if(this.isLessThan(e,r.key)){if(!r.left){r.left=n;break}r=r.left}else{if(!r.right){r.right=n;break}r=r.right}for(n.parent=r,r=n;r.parent;){var i=r.parent,a=i.balanceFactor;if(r.isLeftChild?i.balanceFactor++:i.balanceFactor--,Math.abs(i.balanceFactor)<Math.abs(a))break;if(i.balanceFactor<-1||i.balanceFactor>1){this.rebalance(i);break}r=i}}else this.root=n}},{key:"get",value:function(e){for(var t=this.root;t;){if(this.isEqual(e,t.key))return t.value;t=this.isLessThan(e,t.key)?t.left:t.right}return null}},{key:"delete",value:function(e){var t=this.getNode(e);if(!t||t.key!==e)return null;var n=t.parent,r=t.left,i=t.right;if(!!r!=!!i){var a=r||i;n||a?n&&!a?this.root=a:(n.replace(t,null),this.rebalance(n)):this.root=null}else{for(var s=t.left;s.right;)s=s.right;if(t.left===s)t.isRoot?(this.root=s,s.parent=null):(t.isLeftChild?t.parent.left=s:t.parent.right=s,s.parent=t.parent),s.right=t.right,s.right.parent=s,s.balanceFactor=t.balanceFactor,t={parent:s,isLeftChild:!0};else{var o=s.parent,u=s.left;o.right=u,u&&(u.parent=o),t.isRoot?(this.root=s,s.parent=null):(t.isLeftChild?t.parent.left=s:t.parent.right=s,s.parent=t.parent),s.right=t.right,s.right.parent=s,s.left=t.left,s.left.parent=s,s.balanceFactor=t.balanceFactor,t={parent:o,isLeftChild:!1}}}for(this.count--;t.parent;){var c=t.parent,l=c.balanceFactor;if(t.isLeftChild?c.balanceFactor-=1:c.balanceFactor+=1,Math.abs(c.balanceFactor)>Math.abs(l)){if(!(c.balanceFactor<-1||c.balanceFactor>1))break;if(this.rebalance(c),0!==c.parent.balanceFactor)break;t=c.parent}else t=c}return null}},{key:"getNode",value:function(e){for(var t=this.root;t;){if(this.isEqual(e,t.key))return t;t=this.isLessThan(e,t.key)?t.left:t.right}return null}},{key:"rebalance",value:function(e){e.balanceFactor<0?e.right.balanceFactor>0?(this.rotateRight(e.right),this.rotateLeft(e)):this.rotateLeft(e):e.balanceFactor>0&&(e.left.balanceFactor<0?(this.rotateLeft(e.left),this.rotateRight(e)):this.rotateRight(e))}},{key:"rotateLeft",value:function(e){var t=e.right;e.right=t.left,null!==t.left&&(t.left.parent=e),t.parent=e.parent,null===t.parent?this.root=t:e.isLeftChild?t.parent.left=t:t.parent.right=t,t.left=e,e.parent=t,e.balanceFactor=e.balanceFactor+1-Math.min(t.balanceFactor,0),t.balanceFactor=t.balanceFactor+1-Math.max(e.balanceFactor,0)}},{key:"rotateRight",value:function(e){var t=e.left;e.left=t.right,null!==t.right&&(t.right.parent=e),t.parent=e.parent,null===t.parent?this.root=t:e.isLeftChild?t.parent.left=t:t.parent.right=t,t.right=e,e.parent=t,e.balanceFactor=e.balanceFactor-1-Math.min(t.balanceFactor,0),t.balanceFactor=t.balanceFactor-1-Math.max(e.balanceFactor,0)}},{key:Symbol.iterator,value:hE.default.mark((function e(){var t,n,r;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=ST(this.getIterator()),e.prev=1,t.s();case 3:if((n=t.n()).done){e.next=9;break}return r=n.value,e.next=7,r;case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case"end":return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:"getIterator",value:hE.default.mark((function e(){var t,n,r,i=arguments;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=i.length>0&&void 0!==i[0]?i[0]:null,n=this.root;case 2:if(!n){e.next=8;break}if(!this.isEqual(t,n.key)&&(null!==t||n.left)){e.next=5;break}return e.abrupt("break",8);case 5:n=this.isLessThan(t,n.key)||null===t?n.left:n.right,e.next=2;break;case 8:if(n){e.next=10;break}return e.abrupt("return",null);case 10:r=!0;case 11:if(!r){e.next=29;break}return e.next=14,[n.key,n.value];case 14:if(r=!1,!n.right){e.next=21;break}for(n=n.right;n.left;)n=n.left;r=!0,e.next=27;break;case 21:if(!n.parent){e.next=26;break}r=n.parent.left===n,n=n.parent,e.next=27;break;case 26:return e.abrupt("break",37);case 27:e.next=35;break;case 29:if(!n.parent){e.next=34;break}r=n.parent.left===n,n=n.parent,e.next=35;break;case 34:return e.abrupt("break",37);case 35:e.next=11;break;case 37:return e.abrupt("return",null);case 38:case"end":return e.stop()}}),e,this)}))},{key:"getReverseIterator",value:hE.default.mark((function e(){var t,n,r,i=arguments;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=i.length>0&&void 0!==i[0]?i[0]:null,n=this.root;case 2:if(!n){e.next=8;break}if(!this.isEqual(t,n.key)&&(null!==t||n.right)){e.next=5;break}return e.abrupt("break",8);case 5:n=this.isLessThan(t,n.key)&&null!==t?n.left:n.right,e.next=2;break;case 8:if(n){e.next=10;break}return e.abrupt("return",null);case 10:r=!0;case 11:if(!r){e.next=29;break}return e.next=14,[n.key,n.value];case 14:if(r=!1,!n.left){e.next=21;break}for(n=n.left;n.right;)n=n.right;r=!0,e.next=27;break;case 21:if(!n.parent){e.next=26;break}r=n.parent.right===n,n=n.parent,e.next=27;break;case 26:return e.abrupt("break",37);case 27:e.next=35;break;case 29:if(!n.parent){e.next=34;break}r=n.parent.right===n,n=n.parent,e.next=35;break;case 34:return e.abrupt("break",37);case 35:e.next=11;break;case 37:return e.abrupt("return",null);case 38:case"end":return e.stop()}}),e,this)}))}]),e}();function IT(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return OT(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return OT(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function OT(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var CT=function(){function e(t,n){oE.default(this,e),this.value=t,this.revision=n||0}return uE.default(e,[{key:"isValid",get:function(){return!0}}]),e}(),PT=function(){function e(t){oE.default(this,e),this.revision=t}return uE.default(e,[{key:"isValid",get:function(){return!1}}]),e}(),AT=function(){function e(){oE.default(this,e),this.items=new RT}return uE.default(e,[{key:"store",value:function(e,t,n){var r=this.items.get(e);return r&&r.revision>n?r.isValid?r.value:null:(this.items.set(e,new CT(t,n)),t)}},{key:"delete",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=this.items.get(e);(!r||r.revision<t||r&&!0===n)&&this.items.set(e,new PT(t))}},{key:"isKnown",value:function(e,t){var n=this.items.get(e);return n&&n.revision>=t}},{key:"get",value:function(e){var t=this.items.get(e);return t&&t.isValid?t.value:null}},{key:"has",value:function(e){var t=this.items.get(e);return t&&t.isValid}},{key:"forEach",value:function(e){if(this.items){var t,n=IT(this.items);try{for(n.s();!(t=n.n()).done;){var r=gE.default(t.value,2),i=r[0],a=r[1];a.isValid&&e(i,a.value)}}catch(e){n.e(e)}finally{n.f()}}}}]),e}();function jT(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=dE.default(e);if(t){var i=dE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return fE.default(this,n)}}var MT=function(e){lE.default(v,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h=jT(v);function v(e,t,n){var r;oE.default(this,v);return(r=h.call(this,e,n)).updateMergingQueue=new mT((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new AT,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),r}return uE.default(v,[{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"links",get:function(){return this.descriptor.links}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"list"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"_addOrUpdateItemOnServer",value:(p=sE.default(hE.default.mark((function e(t,n,r,i){var a,s;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a={data:n},void 0!==i&&(a.ttl=i),e.next=4,this.services.network.post(t,a,r);case 4:return(s=e.sent).body.data=n,s.body.date_updated=new Date(s.body.date_updated),e.abrupt("return",s.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n,r){return p.apply(this,arguments)})},{key:"push",value:(d=sE.default(hE.default.mark((function e(t,n){var r,i,a;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=(n||{}).ttl,e.next=3,this._addOrUpdateItemOnServer(this.links.items,t,void 0,r);case 3:return i=e.sent,a=Number(i.index),this._handleItemMutated(a,i.url,i.last_event_id,i.revision,t,i.date_updated,i.date_expires,!0,!1),e.abrupt("return",this.cache.get(a));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return d.apply(this,arguments)})},{key:"set",value:(f=sE.default(hE.default.mark((function e(t,n,r){var i,a=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r||{},e.abrupt("return",this.updateMergingQueue.squashAndAdd(t,i,(function(e){return a._updateItemUnconditionally(t,n,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"_updateItemUnconditionally",value:(l=sE.default(hE.default.mark((function e(t,n,r){var i,a;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return i=e.sent,e.next=5,this._addOrUpdateItemOnServer(i.uri,n,void 0,r);case 5:return a=e.sent,this._handleItemMutated(t,a.url,a.last_event_id,a.revision,a.data,a.date_updated,a.date_expires,!1,!1),e.abrupt("return",this.cache.get(t));case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return l.apply(this,arguments)})},{key:"_updateItemWithIfMatch",value:(c=sE.default(hE.default.mark((function e(t,n,r){var i,a,s,o;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:if(i=e.sent,!(a=n(BE(i.data)))){e.next=25;break}return s=i.revision,e.prev=6,e.next=9,this._addOrUpdateItemOnServer(i.uri,a,s,r);case 9:return o=e.sent,this._handleItemMutated(t,o.url,o.last_event_id,o.revision,o.data,o.date_updated,o.date_expires,!1,!1),e.abrupt("return",this.cache.get(t));case 14:if(e.prev=14,e.t0=e.catch(6),412!==e.t0.status){e.next=22;break}return e.next=19,this._getItemFromServer(t);case 19:return e.abrupt("return",this._updateItemWithIfMatch(t,n,r));case 22:throw e.t0;case 23:e.next=26;break;case 25:return e.abrupt("return",i);case 26:case"end":return e.stop()}}),e,this,[[6,14]])}))),function(e,t,n){return c.apply(this,arguments)})},{key:"mutate",value:(u=sE.default(hE.default.mark((function e(t,n,r){var i,a=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r||{},e.abrupt("return",this.updateMergingQueue.add(t,i,(function(e){return a._updateItemWithIfMatch(t,n,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"update",value:(o=sE.default(hE.default.mark((function e(t,n,r){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mutate(t,(function(e){return Object.assign(e,n)}),r));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return o.apply(this,arguments)})},{key:"remove",value:function(){var e=sE.default(hE.default.mark((function e(t){var n,r,i;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return n=e.sent,r=BE(n.data),e.next=6,this.services.network.delete(n.uri);case 6:i=e.sent,this._handleItemRemoved(t,i.body.last_event_id,r,new Date(i.body.date_updated),!1);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"get",value:function(){var e=sE.default(hE.default.mark((function e(t){var n;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=this.cache.get(t))){e.next=5;break}return e.abrupt("return",n);case 5:return e.abrupt("return",this._getItemFromServer(t));case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"_getItemFromServer",value:(s=sE.default(hE.default.mark((function e(t){var n;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.queryItems({index:t});case 2:if(!((n=e.sent).items.length<1)){e.next=7;break}throw new DE("No item with index ".concat(t," found"),404,54151);case 7:return e.abrupt("return",n.items[0]);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"queryItems",value:function(){var e=sE.default(hE.default.mark((function e(t){var n,r,i,a,s=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new NE(this.links.items).queryParam("From",t.from).queryParam("PageSize",t.limit).queryParam("Index",t.index).queryParam("PageToken",t.pageToken).queryParam("Order",t.order).build(),e.next=4,this.services.network.get(n);case 4:return r=e.sent,i=r.body.items.map((function(e){return e.date_updated=new Date(e.date_updated),s.cache.get(e.index)?s._handleItemMutated(e.index,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):s.cache.store(Number(e.index),new _T({index:Number(e.index),uri:e.url,revision:e.revision,lastEventId:e.last_event_id,dateUpdated:e.date_updated,dateExpires:e.date_expires,data:e.data}),e.last_event_id),s.cache.get(e.index)})),a=r.body.meta,e.abrupt("return",new Paginator(i,(function(e){return s.queryItems({pageToken:e})}),a.previous_token,a.next_token));case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"getItems",value:(a=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return qE((t=t||{}).pageSize),t.limit=t.pageSize||t.limit||50,t.order=t.order||"asc",e.abrupt("return",this.queryItems(t));case 5:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"getContext",value:(i=sE.default(hE.default.mark((function e(){var t;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.context){e.next=5;break}return e.next=3,this.services.network.get(this.links.context);case 3:t=e.sent,this._updateContextIfRequired(t.body.data,t.body.last_event_id);case 5:return e.abrupt("return",this.context);case 6:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"setTtl",value:(r=sE.default(hE.default.mark((function e(t){var n,r;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,n={ttl:t},e.next=4,this.services.network.post(this.uri,n);case 4:r=e.sent,this.descriptor.date_expires=r.body.date_expires,e.next=12;break;case 8:throw e.prev=8,e.t0=e.catch(0),404===e.t0.status&&this.onRemoved(!1),e.t0;case 12:case"end":return e.stop()}}),e,this,[[0,8]])}))),function(e){return r.apply(this,arguments)})},{key:"setItemTtl",value:(n=sE.default(hE.default.mark((function e(t,n){var r,i,a;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return r=e.sent,i={ttl:n},e.next=6,this.services.network.post(r.uri,i);case 6:a=e.sent,r.updateDateExpires(a.body.date_expires);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeList",value:(t=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}},{key:"shouldIgnoreEvent",value:function(e,t){return this.cache.isKnown(e,t)}},{key:"_update",value:function(e,t){var n=Number(e.item_index);switch(e.date_created=new Date(e.date_created),e.type){case"list_item_added":case"list_item_updated":this._handleItemMutated(n,e.item_url,e.id,e.item_revision,e.item_data,e.date_created,void 0,"list_item_added"===e.type,!0);break;case"list_item_removed":this._handleItemRemoved(n,e.id,e.item_data,e.date_created,!0);break;case"list_context_updated":this._handleContextUpdate(e.context_data,e.id,e.date_created);break;case"list_removed":this.onRemoved(!1)}t&&this._advanceLastEventId(e.id,e.list_revision)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e,t&&(this.descriptor.revision=t))}},{key:"_updateRootDateUpdated",value:function(e){(!this.descriptor.date_updated||e.getTime()>this.descriptor.date_updated.getTime())&&(this.descriptor.date_updated=e,this.services.storage.update(this.type,this.sid,this.uniqueName,{date_updated:e}))}},{key:"_handleItemMutated",value:function(e,t,n,r,i,a,s,o,u){if(this.shouldIgnoreEvent(e,n))VE("Item ".concat(e," update skipped, current: ").concat(this.lastEventId,", remote: ").concat(n));else{this._updateRootDateUpdated(a);var c=this.cache.get(e);if(!c){var l=new _T({index:e,uri:t,lastEventId:n,revision:r,data:i,dateUpdated:a,dateExpires:s});return this.cache.store(e,l,n),void this.emitItemMutationEvent(l,u,o)}var f=BE(c.data);c.update(n,r,i,a),this.cache.store(e,c,n),void 0!==s&&c.updateDateExpires(s),this.emitItemMutationEvent(c,u,!1,f)}}},{key:"emitItemMutationEvent",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=n?"itemAdded":"itemUpdated",a={item:e,isLocal:!t};n||(a.previousItemData=r),this.broadcastEventToListeners(i,a)}},{key:"_handleItemRemoved",value:function(e,t,n,r,i){this._updateRootDateUpdated(r),this.cache.delete(e,t),this.broadcastEventToListeners("itemRemoved",{index:e,isLocal:!i,previousItemData:n})}},{key:"_handleContextUpdate",value:function(e,t,n){this._updateRootDateUpdated(n),this._updateContextIfRequired(e,t)&&this.broadcastEventToListeners("contextUpdated",{context:e,isLocal:!1})}},{key:"_updateContextIfRequired",value:function(e,t){return!this.contextEventId||t>this.contextEventId?(this.context=e,this.contextEventId=t,!0):(VE("Context update skipped, current:",this.lastEventId,", remote:",t),!1)}}],[{key:"type",get:function(){return"list"}}]),v}(vT),LT=function(e){lE.default(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=jT(p);function p(e){var t;return oE.default(this,p),(t=d.call(this)).syncListImpl=e,t.syncListImpl.attach(cE.default(t)),t}return uE.default(p,[{key:"uri",get:function(){return this.syncListImpl.uri}},{key:"revision",get:function(){return this.syncListImpl.revision}},{key:"lastEventId",get:function(){return this.syncListImpl.lastEventId}},{key:"links",get:function(){return this.syncListImpl.links}},{key:"dateExpires",get:function(){return this.syncListImpl.dateExpires}},{key:"type",get:function(){return MT.type}},{key:"sid",get:function(){return this.syncListImpl.sid}},{key:"uniqueName",get:function(){return this.syncListImpl.uniqueName}},{key:"dateUpdated",get:function(){return this.syncListImpl.dateUpdated}},{key:"push",value:(f=sE.default(hE.default.mark((function e(t,n){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.push(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return f.apply(this,arguments)})},{key:"set",value:(l=sE.default(hE.default.mark((function e(t,n,r){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.set(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return l.apply(this,arguments)})},{key:"mutate",value:(c=sE.default(hE.default.mark((function e(t,n,r){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.mutate(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return c.apply(this,arguments)})},{key:"update",value:(u=sE.default(hE.default.mark((function e(t,n,r){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.update(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"remove",value:(o=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.remove(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"get",value:(s=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.get(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"getContext",value:(a=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.getContext());case 2:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"getItems",value:(i=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.getItems(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"setTtl",value:(r=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.setTtl(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"setItemTtl",value:(n=sE.default(hE.default.mark((function e(t,n){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.setItemTtl(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeList",value:(t=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.removeList());case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"close",value:function(){kE.default(dE.default(p.prototype),"close",this).call(this),this.syncListImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return MT.type}}]),p}(bT);pE.default(LT,"itemAdded","itemAdded"),pE.default(LT,"itemUpdated","itemUpdated"),pE.default(LT,"itemRemoved","itemRemoved"),pE.default(LT,"removed","removed"),xE([HS.validateTypesAsync(HS.pureObject,["undefined",HS.objectSchema("item metadata",{ttl:[HS.nonNegativeInteger,"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Object,Object]),_E("design:returntype",Promise)],LT.prototype,"push",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger,HS.pureObject,["undefined",HS.objectSchema("item metadata",{ttl:[HS.nonNegativeInteger,"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Number,Object,Object]),_E("design:returntype",Promise)],LT.prototype,"set",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger,"function",["undefined",HS.objectSchema("item metadata",{ttl:[HS.nonNegativeInteger,"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Number,Function,Object]),_E("design:returntype",Promise)],LT.prototype,"mutate",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger,HS.pureObject,["undefined",HS.objectSchema("item metadata",{ttl:[HS.nonNegativeInteger,"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Number,Object,Object]),_E("design:returntype",Promise)],LT.prototype,"update",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger),_E("design:type",Function),_E("design:paramtypes",[Number]),_E("design:returntype",Promise)],LT.prototype,"remove",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger),_E("design:type",Function),_E("design:paramtypes",[Number]),_E("design:returntype",Promise)],LT.prototype,"get",null),xE([HS.validateTypesAsync(["undefined",HS.objectSchema("query options",{from:[HS.nonNegativeInteger,"undefined"],pageSize:[HS.custom((function(e){return[WE(e),"a positive integer"]})),"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Object]),_E("design:returntype",Promise)],LT.prototype,"getItems",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger),_E("design:type",Function),_E("design:paramtypes",[Number]),_E("design:returntype",Promise)],LT.prototype,"setTtl",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger,HS.nonNegativeInteger),_E("design:type",Function),_E("design:paramtypes",[Number,Number]),_E("design:returntype",Promise)],LT.prototype,"setItemTtl",null);var NT=function(){function e(t){oE.default(this,e),this.descriptor=t}return uE.default(e,[{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"key",get:function(){return this.descriptor.key}},{key:"data",get:function(){return this.descriptor.data}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"update",value:function(e,t,n,r){return this.descriptor.last_event_id=e,this.descriptor.revision=t,this.descriptor.data=n,this.descriptor.date_updated=r,this}},{key:"updateDateExpires",value:function(e){this.descriptor.date_expires=e}}]),e}();function UT(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=dE.default(e);if(t){var i=dE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return fE.default(this,n)}}var DT=function(e){lE.default(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=UT(p);function p(e,t,n){var r;oE.default(this,p);return(r=d.call(this,e,n)).updateMergingQueue=new mT((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new AT,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),t.items&&t.items.forEach((function(e){e.date_updated=new Date(e.date_updated),r.cache.store(e.key,new NT(e),e.last_event_id)})),r}return uE.default(p,[{key:"uri",get:function(){return this.descriptor.url}},{key:"links",get:function(){return this.descriptor.links}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"map"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"set",value:(f=sE.default(hE.default.mark((function e(t,n,r){var i,a=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r||{},e.abrupt("return",this.updateMergingQueue.squashAndAdd(t,i,(function(e){return a._putItemUnconditionally(t,n,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"get",value:function(){var e=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=t){e.next=2;break}throw new DE("SyncMapItem key may not be empty",400,54209);case 2:if(!this.cache.has(t)){e.next=6;break}return e.abrupt("return",this.cache.get(t));case 6:return e.abrupt("return",this._getItemFromServer(t));case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"_getItemFromServer",value:(l=sE.default(hE.default.mark((function e(t){var n;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.queryItems({key:t});case 2:if(!((n=e.sent).items.length<1)){e.next=7;break}throw new DE("The specified Map Item does not exist",404,54201);case 7:return e.abrupt("return",n.items[0]);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"mutate",value:(c=sE.default(hE.default.mark((function e(t,n,r){var i,a=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r||{},e.abrupt("return",this.updateMergingQueue.add(t,i,(function(e){return a._putItemWithIfMatch(t,n,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return c.apply(this,arguments)})},{key:"update",value:(u=sE.default(hE.default.mark((function e(t,n,r){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mutate(t,(function(e){return Object.assign(e,n)}),r));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"_putItemUnconditionally",value:(o=sE.default(hE.default.mark((function e(t,n,r){var i,a;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._putItemToServer(t,n,void 0,r);case 2:return i=e.sent,a=i.item,this._handleItemMutated(a.key,a.url,a.last_event_id,a.revision,a.data,a.date_updated,a.date_expires,i.added,!1),e.abrupt("return",this.cache.get(a.key));case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return o.apply(this,arguments)})},{key:"_putItemWithIfMatch",value:(s=sE.default(hE.default.mark((function e(t,n,r){var i,a,s,o,u;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t).catch((function(e){if(404===e.status)return new NT({key:t,data:{},last_event_id:-1,revision:"-1",url:null,date_updated:null,date_expires:null});throw e}));case 2:if(i=e.sent,!(a=n(BE(i.data)))){e.next=26;break}return s=i.revision,e.prev=6,e.next=9,this._putItemToServer(t,a,s,r);case 9:return o=e.sent,u=o.item,this._handleItemMutated(u.key,u.url,u.last_event_id,u.revision,u.data,u.date_updated,u.date_expires,o.added,!1),e.abrupt("return",this.cache.get(u.key));case 15:if(e.prev=15,e.t0=e.catch(6),412!==e.t0.status){e.next=23;break}return e.next=20,this._getItemFromServer(t);case 20:return e.abrupt("return",this._putItemWithIfMatch(t,n,r));case 23:throw e.t0;case 24:e.next=27;break;case 26:return e.abrupt("return",i);case 27:case"end":return e.stop()}}),e,this,[[6,15]])}))),function(e,t,n){return s.apply(this,arguments)})},{key:"_putItemToServer",value:(a=sE.default(hE.default.mark((function e(t,n,r,i){var a,s,o,u,c;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=new NE(this.links.items).pathSegment(t).build(),s={data:n},void 0!==i&&(s.ttl=i),e.prev=3,e.next=6,this.services.network.put(a,s,r);case 6:return o=e.sent,(u=o.body).data=n,u.date_updated=new Date(u.date_updated),c=201===o.status.code,e.abrupt("return",{added:c,item:u});case 14:throw e.prev=14,e.t0=e.catch(3),404===e.t0.status&&this.onRemoved(!1),e.t0;case 18:case"end":return e.stop()}}),e,this,[[3,14]])}))),function(e,t,n,r){return a.apply(this,arguments)})},{key:"remove",value:function(){var e=sE.default(hE.default.mark((function e(t){var n,r,i;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return n=e.sent,r=BE(n.data),e.next=6,this.services.network.delete(n.uri);case 6:i=e.sent,this._handleItemRemoved(t,i.body.last_event_id,r,new Date(i.body.date_updated),!1);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"queryItems",value:function(){var e=sE.default(hE.default.mark((function e(t){var n,r,i,a,s=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new NE(this.links.items).queryParam("From",t.from).queryParam("PageSize",t.limit).queryParam("Key",t.key).queryParam("PageToken",t.pageToken).queryParam("Order",t.order).build(),e.next=4,this.services.network.get(n);case 4:return r=e.sent,i=r.body.items.map((function(e){return e.date_updated=new Date(e.date_updated),s.cache.get(e.key)?s._handleItemMutated(e.key,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):s.cache.store(e.key,new NT(e),e.last_event_id),s.cache.get(e.key)})),a=r.body.meta,e.abrupt("return",new Paginator(i,(function(e){return s.queryItems({pageToken:e})}),a.previous_token,a.next_token));case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"getItems",value:(i=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return qE((t=t||{}).pageSize),t.limit=t.pageSize||t.limit||50,t.order=t.order||"asc",e.abrupt("return",this.queryItems(t));case 5:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"shouldIgnoreEvent",value:function(e,t){return this.cache.isKnown(e,t)}},{key:"_update",value:function(e,t){switch(e.date_created=new Date(e.date_created),e.type){case"map_item_added":case"map_item_updated":this._handleItemMutated(e.item_key,e.item_url,e.id,e.item_revision,e.item_data,e.date_created,void 0,"map_item_added"===e.type,!0);break;case"map_item_removed":this._handleItemRemoved(e.item_key,e.id,e.item_data,e.date_created,!0);break;case"map_removed":this.onRemoved(!1)}t&&this._advanceLastEventId(e.id,e.map_revision)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e,t&&(this.descriptor.revision=t))}},{key:"_updateRootDateUpdated",value:function(e){(!this.descriptor.date_updated||e.getTime()>this.descriptor.date_updated.getTime())&&(this.descriptor.date_updated=e,this.services.storage.update(this.type,this.sid,this.uniqueName,{date_updated:e}))}},{key:"_handleItemMutated",value:function(e,t,n,r,i,a,s,o,u){if(this.shouldIgnoreEvent(e,n))VE("SyncMapItem ",e," update skipped, current:",this.lastEventId,", remote:",n);else{this._updateRootDateUpdated(a);var c=this.cache.get(e);if(!c){var l=new NT({key:e,url:t,last_event_id:n,revision:r,data:i,date_updated:a,date_expires:s});return this.cache.store(e,l,n),void this.emitItemMutationEvent(l,u,o)}var f=BE(c.data);c.update(n,r,i,a),this.cache.store(e,c,n),void 0!==s&&c.updateDateExpires(s),this.emitItemMutationEvent(c,u,!1,f)}}},{key:"emitItemMutationEvent",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=n?"itemAdded":"itemUpdated",a={item:e,isLocal:!t};n||(a.previousItemData=r),this.broadcastEventToListeners(i,a)}},{key:"_handleItemRemoved",value:function(e,t,n,r,i){this._updateRootDateUpdated(r),this.cache.delete(e,t),this.broadcastEventToListeners("itemRemoved",{key:e,isLocal:!i,previousItemData:n})}},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}},{key:"setTtl",value:(r=sE.default(hE.default.mark((function e(t){var n,r;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,n={ttl:t},e.next=4,this.services.network.post(this.uri,n);case 4:r=e.sent,this.descriptor.date_expires=r.body.date_expires,e.next=12;break;case 8:throw e.prev=8,e.t0=e.catch(0),404===e.t0.status&&this.onRemoved(!1),e.t0;case 12:case"end":return e.stop()}}),e,this,[[0,8]])}))),function(e){return r.apply(this,arguments)})},{key:"setItemTtl",value:(n=sE.default(hE.default.mark((function e(t,n){var r,i,a;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return r=e.sent,i={ttl:n},e.next=6,this.services.network.post(r.uri,i);case 6:a=e.sent,r.updateDateExpires(a.body.date_expires);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeMap",value:(t=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}],[{key:"type",get:function(){return"map"}}]),p}(vT),FT=function(e){lE.default(f,e);var t,n,r,i,a,s,o,u,c,l=UT(f);function f(e){var t;return oE.default(this,f),(t=l.call(this)).syncMapImpl=e,t.syncMapImpl.attach(cE.default(t)),t}return uE.default(f,[{key:"uri",get:function(){return this.syncMapImpl.uri}},{key:"links",get:function(){return this.syncMapImpl.links}},{key:"revision",get:function(){return this.syncMapImpl.revision}},{key:"lastEventId",get:function(){return this.syncMapImpl.lastEventId}},{key:"dateExpires",get:function(){return this.syncMapImpl.dateExpires}},{key:"type",get:function(){return DT.type}},{key:"sid",get:function(){return this.syncMapImpl.sid}},{key:"uniqueName",get:function(){return this.syncMapImpl.uniqueName}},{key:"dateUpdated",get:function(){return this.syncMapImpl.dateUpdated}},{key:"set",value:(c=sE.default(hE.default.mark((function e(t,n,r){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.set(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return c.apply(this,arguments)})},{key:"get",value:(u=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.get(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"mutate",value:(o=sE.default(hE.default.mark((function e(t,n,r){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.mutate(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return o.apply(this,arguments)})},{key:"update",value:(s=sE.default(hE.default.mark((function e(t,n,r){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.update(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return s.apply(this,arguments)})},{key:"remove",value:(a=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.remove(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"getItems",value:(i=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.getItems(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"setTtl",value:(r=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.setTtl(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"setItemTtl",value:(n=sE.default(hE.default.mark((function e(t,n){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.setItemTtl(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeMap",value:(t=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.next=3,this.syncMapImpl.removeMap();case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"close",value:function(){kE.default(dE.default(f.prototype),"close",this).call(this),this.syncMapImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return DT.type}}]),f}(bT);function BT(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=dE.default(e);if(t){var i=dE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return fE.default(this,n)}}pE.default(FT,"itemAdded","itemAdded"),pE.default(FT,"itemUpdated","itemUpdated"),pE.default(FT,"itemRemoved","itemRemoved"),pE.default(FT,"removed","removed"),xE([HS.validateTypesAsync("string",HS.pureObject,["undefined",HS.objectSchema("item metadata",{ttl:[HS.nonNegativeInteger,"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[String,Object,Object]),_E("design:returntype",Promise)],FT.prototype,"set",null),xE([HS.validateTypesAsync("string"),_E("design:type",Function),_E("design:paramtypes",[String]),_E("design:returntype",Promise)],FT.prototype,"get",null),xE([HS.validateTypesAsync("string","function",["undefined",HS.objectSchema("item metadata",{ttl:[HS.nonNegativeInteger,"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[String,Function,Object]),_E("design:returntype",Promise)],FT.prototype,"mutate",null),xE([HS.validateTypesAsync("string",HS.pureObject,["undefined",HS.objectSchema("item metadata",{ttl:[HS.nonNegativeInteger,"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[String,Object,Object]),_E("design:returntype",Promise)],FT.prototype,"update",null),xE([HS.validateTypesAsync("string"),_E("design:type",Function),_E("design:paramtypes",[String]),_E("design:returntype",Promise)],FT.prototype,"remove",null),xE([HS.validateTypesAsync(["undefined",HS.objectSchema("query options",{from:["string","undefined"],pageSize:[HS.custom((function(e){return[WE(e),"a positive integer"]})),"undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Object]),_E("design:returntype",Promise)],FT.prototype,"getItems",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger),_E("design:type",Function),_E("design:paramtypes",[Number]),_E("design:returntype",Promise)],FT.prototype,"setTtl",null),xE([HS.validateTypesAsync("string",HS.nonNegativeInteger),_E("design:type",Function),_E("design:paramtypes",[String,Number]),_E("design:returntype",Promise)],FT.prototype,"setItemTtl",null);var qT=function(e){lE.default(a,e);var t,n,r,i=BT(a);function a(e,t,n){var r;return oE.default(this,a),(r=i.call(this,e,n)).descriptor=t,r}return uE.default(a,[{key:"uri",get:function(){return this.descriptor.url}},{key:"links",get:function(){return this.descriptor.links}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"stream"}},{key:"lastEventId",get:function(){return null}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"publishMessage",value:(r=sE.default(hE.default.mark((function e(t){var n,r,i,a;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={data:t},e.next=3,this.services.network.post(this.links.messages,n);case 3:return r=e.sent,i=r.body,a=this._handleMessagePublished(i.sid,t,!1),e.abrupt("return",a);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"setTtl",value:(n=sE.default(hE.default.mark((function e(t){var n,r;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,n={ttl:t},e.next=4,this.services.network.post(this.uri,n);case 4:r=e.sent,this.descriptor.date_expires=r.body.date_expires,e.next=12;break;case 8:throw e.prev=8,e.t0=e.catch(0),404===e.t0.status&&this.onRemoved(!1),e.t0;case 12:case"end":return e.stop()}}),e,this,[[0,8]])}))),function(e){return n.apply(this,arguments)})},{key:"removeStream",value:(t=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_update",value:function(e){switch(e.type){case"stream_message_published":this._handleMessagePublished(e.message_sid,e.message_data,!0);break;case"stream_removed":this.onRemoved(!1)}}},{key:"_handleMessagePublished",value:function(e,t,n){var r={sid:e,data:t};return this.broadcastEventToListeners("messagePublished",{message:r,isLocal:!n}),r}},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}}],[{key:"type",get:function(){return"stream"}}]),a}(vT);xE([HS.validateTypesAsync(HS.pureObject),_E("design:type",Function),_E("design:paramtypes",[Object]),_E("design:returntype",Promise)],qT.prototype,"publishMessage",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger),_E("design:type",Function),_E("design:paramtypes",[Number]),_E("design:returntype",Promise)],qT.prototype,"setTtl",null);var WT=function(e){lE.default(a,e);var t,n,r,i=BT(a);function a(e){var t;return oE.default(this,a),(t=i.call(this)).syncStreamImpl=e,t.syncStreamImpl.attach(cE.default(t)),t}return uE.default(a,[{key:"uri",get:function(){return this.syncStreamImpl.uri}},{key:"links",get:function(){return this.syncStreamImpl.links}},{key:"dateExpires",get:function(){return this.syncStreamImpl.dateExpires}},{key:"type",get:function(){return qT.type}},{key:"lastEventId",get:function(){return null}},{key:"sid",get:function(){return this.syncStreamImpl.sid}},{key:"uniqueName",get:function(){return this.syncStreamImpl.uniqueName}},{key:"publishMessage",value:(r=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncStreamImpl.publishMessage(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"setTtl",value:(n=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncStreamImpl.setTtl(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"removeStream",value:(t=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncStreamImpl.removeStream());case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"close",value:function(){kE.default(dE.default(a.prototype),"close",this).call(this),this.syncStreamImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return qT.type}}]),a}(bT);pE.default(WT,"messagePublished","messagePublished"),pE.default(WT,"removed","removed"),xE([HS.validateTypesAsync(HS.pureObject),_E("design:type",Function),_E("design:paramtypes",[Object]),_E("design:returntype",Promise)],WT.prototype,"publishMessage",null),xE([HS.validateTypesAsync(HS.nonNegativeInteger),_E("design:type",Function),_E("design:paramtypes",[Number]),_E("design:returntype",Promise)],WT.prototype,"setTtl",null);var zT=function e(t){oE.default(this,e),this.sdk="js",this.sdkVer=t,this.os=wE.os.family,this.osVer=wE.os.version,this.pl=wE.name,this.plVer=wE.version},GT=function(){function e(){oE.default(this,e),this.names=new Map,this.entities=new Map}return uE.default(e,[{key:"store",value:function(e){var t=this.entities.get(e.sid);return t||(this.entities.set(e.sid,e),e.uniqueName&&this.names.set(e.type+"::"+e.uniqueName,e.sid),e)}},{key:"getResolved",value:function(e,t){var n=this.names.get(t+"::"+e);return n?this.entities.get(n):null}},{key:"get",value:function(e,t){return this.entities.get(e)||this.getResolved(e,t)||null}},{key:"remove",value:function(e){var t=this.entities.get(e);t&&(this.entities.delete(e),t.uniqueName&&this.names.delete(t.type+"::"+t.uniqueName))}}]),e}();function JT(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=dE.default(e);if(t){var i=dE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return fE.default(this,n)}}var VT=function(e){lE.default(n,e);var t=JT(n);function n(e,r,i,a){var s;return oE.default(this,n),(s=t.call(this,r,i)).descriptor=e,s.cache=new AT,a&&a.forEach((function(e){s.cache.store(e.key,{key:e.key,value:e.data},e.revision)})),s}return uE.default(n,[{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return null}},{key:"type",get:function(){return n.type}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"indexName",get:function(){return this.descriptor.indexName}},{key:"queryString",get:function(){return this.descriptor.queryExpression}},{key:"queryUri",get:function(){return this.descriptor.queryUri}},{key:"liveQueryDescriptor",get:function(){return this.descriptor}},{key:"onRemoved",value:function(){}},{key:"getItems",value:function(){var e={};return this.cache.forEach((function(t,n){e[t]=n.value})),e}},{key:"_update",value:function(e,t){switch(e.type){case"live_query_item_updated":this.handleItemMutated(e.item_key,e.item_data,e.item_revision);break;case"live_query_item_removed":this.handleItemRemoved(e.item_key,e.item_revision);break;case"live_query_updated":this.handleBatchUpdate(e.items)}t&&this._advanceLastEventId(e.last_event_id)}},{key:"handleItemMutated",value:function(e,t,n){if(this.shouldIgnoreEvent(e,n))VE("Item ".concat(e," update skipped, revision: ").concat(n));else{var r={key:e,value:t};this.cache.store(e,r,n),this.broadcastEventToListeners("itemUpdated",r)}}},{key:"handleItemRemoved",value:function(e,t){var n=null===t;this.shouldIgnoreEvent(e,t)?VE("Item ".concat(e," delete skipped, revision: ").concat(t)):(this.cache.delete(e,t,n),this.broadcastEventToListeners("itemRemoved",{key:e}))}},{key:"handleBatchUpdate",value:function(e){var t=this,n={};for(var r in null!=e&&e.forEach((function(e){n[e.key]={data:e.data,revision:e.revision}})),this.cache.forEach((function(e,r){var i=n[e];null!=i?t.handleItemMutated(e,i.data,i.revision):t.handleItemRemoved(e,null),delete n[e]})),n)this.handleItemMutated(r,n[r].data,n[r].revision)}},{key:"shouldIgnoreEvent",value:function(e,t){return null!=e&&null!=t&&this.cache.isKnown(e,t)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e)}}],[{key:"type",get:function(){return"live_query"}}]),n}(vT);function $T(e){return KT.apply(this,arguments)}function KT(){return(KT=sE.default(hE.default.mark((function e(t){var n,r,i,a,s,o;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.network,r=t.queryString,i=t.uri,a=t.type,null!=r){e.next=3;break}throw new DE("Invalid query",400,54507);case 3:return s={query_string:r},a===HT.type&&(s.type=a),e.next=7,n.post(i,s,void 0,!0);case 7:return o=e.sent,e.abrupt("return",o.body);case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var HT=function(e){lE.default(n,e);var t=JT(n);function n(e){var r;return oE.default(this,n),(r=t.call(this)).liveQueryImpl=e,r.liveQueryImpl.attach(cE.default(r)),r}return uE.default(n,[{key:"type",get:function(){return VT.type}},{key:"lastEventId",get:function(){return this.liveQueryImpl.lastEventId}},{key:"sid",get:function(){return this.liveQueryImpl.sid}},{key:"close",value:function(){kE.default(dE.default(n.prototype),"close",this).call(this),this.liveQueryImpl.detach(this.listenerUuid)}},{key:"getItems",value:function(){return this.ensureNotClosed(),this.liveQueryImpl.getItems()}}],[{key:"type",get:function(){return VT.type}}]),n}(bT);pE.default(HT,"itemUpdated","itemUpdated"),pE.default(HT,"itemRemoved","itemRemoved");var YT=function(e){lE.default(i,e);var t,n,r=JT(i);function i(e){var t;return oE.default(this,i),t=r.call(this),pE.default(cE.default(t),"queryExpression",null),pE.default(cE.default(t),"items",{}),Object.assign(cE.default(t),e),t.updateIndexName(e.indexName),t}return uE.default(i,[{key:"type",get:function(){return i.type}},{key:"search",value:(n=sE.default(hE.default.mark((function e(t){var n=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.items={},e.abrupt("return",$T({network:this.network,uri:this.queryUri,queryString:t}).then((function(e){n.queryExpression=t,e.items&&e.items.forEach((function(e){n.items[e.key]=e.data})),n.emit("searchResult",n.getItems())})).catch((function(e){throw HE("Error '".concat(e.message,"' while executing query '").concat(t,"'")),n.queryExpression=null,e})));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"subscribe",value:(t=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=this.queryExpression){e.next=2;break}return e.abrupt("return",Promise.reject(new DE("Invalid query",400,54507)));case 2:return e.abrupt("return",this.liveQueryCreator(this.indexName,this.queryExpression));case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"getItems",value:function(){return this.items}},{key:"updateIndexName",value:function(e){this.indexName=e,this.queryUri=this.generateQueryUri(this.indexName)}},{key:"generateQueryUri",value:function(e){return new NE(this.insightsUri).pathSegment(e).pathSegment("Items").build()}}],[{key:"type",get:function(){return"instant_query"}}]),i}(EE);pE.default(YT,"searchResult","searchResult"),xE([HS.validateTypesAsync("string"),_E("design:type",Function),_E("design:paramtypes",[String]),_E("design:returntype",Promise)],YT.prototype,"search",null),xE([HS.validateTypes(HS.nonEmptyString),_E("design:type",Function),_E("design:paramtypes",[String]),_E("design:returntype",void 0)],YT.prototype,"updateIndexName",null);function QT(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=dE.default(e);if(t){var i=dE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return fE.default(this,n)}}function XT(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function ZT(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?XT(Object(n),!0).forEach((function(t){pE.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):XT(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var eR="data_sync",tR="3.0.5-rc.19";function nR(e){if(e){if("string"==typeof e)return{id:e,mode:"open_or_create"};var t=e.mode||(e.id?"open_or_create":"create_new");return ZT(ZT({},e),{},{mode:t})}return{mode:"create_new"}}var rR="com.twilio.rtd.cds.document",iR="com.twilio.rtd.cds.list",aR="com.twilio.rtd.cds.map",sR="twilio.sync.event",oR=function(e){lE.default(Client,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y=QT(Client);function Client(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(oE.default(this,Client),t=y.call(this),!e)throw new Error("Sync library needs a valid Twilio token to be passed");n.hasOwnProperty("logLevel")?JE(n.logLevel):JE("silent");var r=n.productId=n.productId||eR;n.clientMetadata=n.clientMetadata||{},n.clientMetadata.hasOwnProperty("type")||(n.clientMetadata.type="sync"),n.clientMetadata.hasOwnProperty("sdk")||(n.clientMetadata.sdk="JS",n.clientMetadata.sdkv=tR);var i=!n.twilsockClient;if(!n.initRegistrations){var a=new YS.InitRegistration(r);Client.populateInitRegistrations(a),n.initRegistrations=[a]}var s=n.twilsockClient=n.twilsockClient||new YS.Twilsock(e,r,n);s.on("tokenAboutToExpire",(function(e){return t.emit("tokenAboutToExpire",e)})),s.on("tokenExpired",(function(){return t.emit("tokenExpired")})),s.on("connectionError",(function(e){return t.emit("connectionError",e)})),s.on("stateChanged",(function(e){t.emit("connectionStateChanged",e),t.services.subscriptions.onConnectionStateChanged("connected"===e)})),s.on("message",(function(e,n){return t._routeMessage(e,n)}));var o=new rT(n),u=new fT(new zT(tR),o,s),c=new dT(o);return t.services={config:o,twilsock:s,network:u,storage:c,router:cE.default(t),subscriptions:null},t.services.subscriptions=new oT(t.services),t.entities=new GT,i&&s.connect(),t}return uE.default(Client,[{key:"_routeMessage",value:function(e,t){switch(VE("Notification type:",e,"content:",t),e){case rR:case iR:case aR:this.services.subscriptions.acceptMessage(t,!1);break;case sR:this.services.subscriptions.acceptMessage(t,!0)}}},{key:"_subscribe",value:function(e,t){this.services.subscriptions.add(e,t)}},{key:"_unsubscribe",value:function(e){this.services.subscriptions.remove(e)}},{key:"connectionState",get:function(){return this.services.twilsock.state}},{key:"ensureReady",value:(v=sE.default(hE.default.mark((function e(){var t;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.services.config.sessionStorageEnabled){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,e.next=5,this.services.twilsock.storageId();case 5:t=e.sent,this.services.storage.updateStorageId(t.id),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(2),KE("Failed to initialize storage",e.t0);case 12:case"end":return e.stop()}}),e,this,[[2,9]])}))),function(){return v.apply(this,arguments)})},{key:"storeRootInSessionCache",value:function(e,t,n){if(this.services.config.sessionStorageEnabled&&t){var r=BE(n);e!==LT.type&&e!==FT.type||(r.last_event_id=null,delete r.items),this.services.storage.store(e,t,r)}}},{key:"readRootFromSessionCache",value:function(e,t){return this.services.config.sessionStorageEnabled&&t?this.services.storage.read(e,t):null}},{key:"_get",value:(h=sE.default(hE.default.mark((function e(t,n){var r,i,a,s=arguments;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=s.length>2&&void 0!==s[2]&&s[2],n){e.next=3;break}throw new DE("Cannot get entity without id",404);case 3:return i=new NE(t).pathSegment(n).queryParam("Include",r?"items":void 0).build(),e.next=6,this.services.network.get(i);case 6:return a=e.sent,e.abrupt("return",a.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return h.apply(this,arguments)})},{key:"_createDocument",value:function(e,t,n){var r={unique_name:e,data:t||{}};return void 0!==n&&(r.ttl=n),this.services.network.post(this.services.config.documentsUri,r).then((function(e){return e.body.data=r.data,e.body}))}},{key:"_getDocument",value:(p=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(xT.type,t)||this._get(this.services.config.documentsUri,t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"_createList",value:function(e,t,n,r){var i={unique_name:e,purpose:t,context:n};return void 0!==r&&(i.ttl=r),this.services.network.post(this.services.config.listsUri,i).then((function(e){return e.body}))}},{key:"_getList",value:(d=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(LT.type,t)||this._get(this.services.config.listsUri,t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"_createMap",value:function(e,t){var n={unique_name:e};return void 0!==t&&(n.ttl=t),this.services.network.post(this.services.config.mapsUri,n).then((function(e){return e.body}))}},{key:"_getMap",value:(f=sE.default(hE.default.mark((function e(t){var n,r=arguments;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.length>1&&void 0!==r[1]&&r[1],e.abrupt("return",this.readRootFromSessionCache(FT.type,t)||this._get(this.services.config.mapsUri,t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"_getStream",value:(l=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(WT.type,t)||this._get(this.services.config.streamsUri,t,!1));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"_createStream",value:(c=sE.default(hE.default.mark((function e(t,n){var r,i;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={unique_name:t},void 0!==n&&(r.ttl=n),e.next=4,this.services.network.post(this.services.config.streamsUri,r);case 4:return i=e.sent,e.abrupt("return",i.body);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return c.apply(this,arguments)})},{key:"_getLiveQuery",value:function(e){return this.readRootFromSessionCache(HT.type,e)}},{key:"getCached",value:function(e,t){return e&&this.entities.get(e,t)||null}},{key:"removeFromCacheAndSession",value:function(e,t,n){this.entities.remove(t),this.services.config.sessionStorageEnabled&&this.services.storage.remove(e,t,n)}},{key:"document",value:(u=sE.default(hE.default.mark((function e(t){var n,r,i,a,s=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=nR(t)).mode){e.next=9;break}return e.next=6,this._createDocument(n.id,n.data,n.ttl);case 6:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,xT.type))){e.next=14;break}return e.abrupt("return",new xT(i));case 14:return e.prev=14,e.next=17,this._getDocument(n.id);case 17:r=e.sent,e.next=39;break;case 20:if(e.prev=20,e.t0=e.catch(14),404===e.t0.status&&"open_existing"!==n.mode){e.next=26;break}throw e.t0;case 26:return e.prev=26,e.next=29,this._createDocument(n.id,n.data,n.ttl);case 29:r=e.sent,e.next=39;break;case 32:if(e.prev=32,e.t1=e.catch(26),409!==e.t1.status){e.next=38;break}return e.abrupt("return",this.document(t));case 38:throw e.t1;case 39:return this.storeRootInSessionCache(xT.type,n.id,r),a=new wT(this.services,r,(function(e,t,n){return s.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new xT(a));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return u.apply(this,arguments)})},{key:"map",value:(o=sE.default(hE.default.mark((function e(t){var n,r,i,a,s=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=nR(t)).mode){e.next=9;break}return e.next=6,this._createMap(n.id,n.ttl);case 6:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,FT.type))){e.next=14;break}return e.abrupt("return",new FT(i));case 14:return e.prev=14,e.next=17,this._getMap(n.id,n.includeItems);case 17:r=e.sent,e.next=39;break;case 20:if(e.prev=20,e.t0=e.catch(14),404===e.t0.status&&"open_existing"!==n.mode){e.next=26;break}throw e.t0;case 26:return e.prev=26,e.next=29,this._createMap(n.id,n.ttl);case 29:r=e.sent,e.next=39;break;case 32:if(e.prev=32,e.t1=e.catch(26),409!==e.t1.status){e.next=38;break}return e.abrupt("return",this.map(t));case 38:throw e.t1;case 39:return this.storeRootInSessionCache(FT.type,n.id,r),a=new DT(this.services,r,(function(e,t,n){return s.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new FT(a));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return o.apply(this,arguments)})},{key:"list",value:(s=sE.default(hE.default.mark((function e(t){var n,r,i,a,s=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=nR(t)).mode){e.next=9;break}return e.next=6,this._createList(n.id,n.purpose,n.context,n.ttl);case 6:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,LT.type))){e.next=14;break}return e.abrupt("return",new LT(i));case 14:return e.prev=14,e.next=17,this._getList(n.id);case 17:r=e.sent,e.next=39;break;case 20:if(e.prev=20,e.t0=e.catch(14),404===e.t0.status&&"open_existing"!==n.mode){e.next=26;break}throw e.t0;case 26:return e.prev=26,e.next=29,this._createList(n.id,n.purpose,n.context,n.ttl);case 29:r=e.sent,e.next=39;break;case 32:if(e.prev=32,e.t1=e.catch(26),409!==e.t1.status){e.next=38;break}return e.abrupt("return",this.list(t));case 38:throw e.t1;case 39:return this.storeRootInSessionCache(LT.type,n.id,r),a=new MT(this.services,r,(function(e,t,n){return s.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new LT(a));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return s.apply(this,arguments)})},{key:"stream",value:(a=sE.default(hE.default.mark((function e(t){var n,r,i,a,s,o=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=nR(t)).mode){e.next=9;break}return e.next=6,this._createStream(n.id,n.ttl);case 6:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,WT.type))){e.next=14;break}return e.abrupt("return",new WT(i));case 14:return e.prev=14,e.next=17,this._getStream(n.id);case 17:r=e.sent,e.next=39;break;case 20:if(e.prev=20,e.t0=e.catch(14),404===e.t0.status&&"open_existing"!==n.mode){e.next=26;break}throw e.t0;case 26:return e.prev=26,e.next=29,this._createStream(n.id,n.ttl);case 29:r=e.sent,e.next=39;break;case 32:if(e.prev=32,e.t1=e.catch(26),409!==e.t1.status){e.next=38;break}return e.abrupt("return",this.stream(t));case 38:throw e.t1;case 39:return this.storeRootInSessionCache(WT.type,n.id,r),a=function(e,t,n){return o.removeFromCacheAndSession(e,t,n)},s=new qT(this.services,r,a),s=this.entities.store(s),e.abrupt("return",new WT(s));case 44:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return a.apply(this,arguments)})},{key:"shutdown",value:(i=sE.default(hE.default.mark((function e(){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.subscriptions.shutdown();case 2:return e.next=4,this.services.twilsock.disconnect();case 4:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"updateToken",value:(r=sE.default(hE.default.mark((function e(t){return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.services.twilsock.updateToken(t).catch((function(e){var t,n=null==e||null===(t=e.reply)||void 0===t?void 0:t.status;if(401===(null==n?void 0:n.code)&&"UNAUTHORIZED"===(null==n?void 0:n.status))throw new DE("Updated token was rejected by server",400,51130);throw e})));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"liveQuery",value:(n=sE.default(hE.default.mark((function e(t,n){var r,i,a,s,o,u=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:return r=new NE(this.services.config.insightsUri).pathSegment(t).pathSegment("Items").build(),e.next=5,$T({network:this.services.network,uri:r,queryString:n,type:HT.type});case 5:return i=e.sent,(a=this.getCached(i.query_id,HT.type))||((s=this._getLiveQuery(i.query_id))||(s={indexName:t,queryExpression:n,sid:i.query_id,queryUri:r,last_event_id:i.last_event_id}),o=function(e,t,n){return u.removeFromCacheAndSession(e,t,n)},a=new VT(s,this.services,o,i.items)),this.storeRootInSessionCache(HT.type,i.query_id,a.liveQueryDescriptor),a=this.entities.store(a),e.abrupt("return",new HT(a));case 11:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"instantQuery",value:(t=sE.default(hE.default.mark((function e(t){var n,r=this;return hE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:return n=function(e,t){return r.liveQuery(e,t)},e.abrupt("return",new YT({indexName:t,network:this.services.network,insightsUri:this.services.config.insightsUri,liveQueryCreator:n}));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}],[{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([sR,rR,iR,aR])}},{key:"version",get:function(){return tR}}]),Client}(EE);pE.default(oR,"connectionStateChanged","connectionStateChanged"),pE.default(oR,"connectionError","connectionError"),pE.default(oR,"tokenAboutToExpire","tokenAboutToExpire"),pE.default(oR,"tokenExpired","tokenExpired"),xE([HS.validateTypesAsync(["undefined","string",HS.objectSchema("open document options",{id:["string","undefined"],mode:[HS.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[HS.nonNegativeInteger,"undefined"],data:[HS.pureObject,"undefined",HS.literal(null)]})]),_E("design:type",Function),_E("design:paramtypes",[Object]),_E("design:returntype",Promise)],oR.prototype,"document",null),xE([HS.validateTypesAsync(["undefined","string",HS.objectSchema("open map options",{id:["string","undefined"],mode:[HS.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[HS.nonNegativeInteger,"undefined"],data:[HS.pureObject,"undefined",HS.literal(null)],includeItems:["boolean","undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Object]),_E("design:returntype",Promise)],oR.prototype,"map",null),xE([HS.validateTypesAsync(["undefined","string",HS.objectSchema("open list options",{id:["string","undefined"],mode:[HS.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[HS.nonNegativeInteger,"undefined"],data:[HS.pureObject,"undefined",HS.literal(null)],purpose:["string","undefined"],context:[HS.pureObject,"undefined"],includeItems:["boolean","undefined"]})]),_E("design:type",Function),_E("design:paramtypes",[Object]),_E("design:returntype",Promise)],oR.prototype,"list",null),xE([HS.validateTypesAsync(["undefined","string",HS.objectSchema("open stream options",{id:["string","undefined"],mode:[HS.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[HS.nonNegativeInteger,"undefined"],data:[HS.pureObject,"undefined",HS.literal(null)]})]),_E("design:type",Function),_E("design:paramtypes",[Object]),_E("design:returntype",Promise)],oR.prototype,"stream",null),xE([HS.validateTypesAsync(HS.nonEmptyString),_E("design:type",Function),_E("design:paramtypes",[String]),_E("design:returntype",Promise)],oR.prototype,"updateToken",null),xE([HS.validateTypesAsync(HS.nonEmptyString,"string"),_E("design:type",Function),_E("design:paramtypes",[String,String]),_E("design:returntype",Promise)],oR.prototype,"liveQuery",null),xE([HS.validateTypesAsync(HS.nonEmptyString),_E("design:type",Function),_E("design:paramtypes",[String]),_E("design:returntype",Promise)],oR.prototype,"instantQuery",null),DS.Client=oR,DS.InsightsItem=function e(){oE.default(this,e)},DS.InstantQuery=YT,DS.LiveQuery=HT,DS.Paginator=Paginator;var uR=DS.SyncClient=oR;function cR(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function lR(e,t,n){return(lR=cR()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&Ia(i,n.prototype),i}).apply(null,arguments)}function fR(e){var t="function"==typeof Map?new Map:void 0;return(fR=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return lR(e,arguments,Aa(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),Ia(r,e)})(e)}DS.SyncDocument=xT,DS.SyncList=LT,DS.SyncListItem=_T,DS.SyncMap=FT,DS.SyncMapItem=NT,DS.SyncStream=WT,DS.default=oR;var dR,pR={},hR=L_,vR=function(e){if(hR(e))throw TypeError("The method doesn't accept regular expressions");return e},yR=pe("match"),mR=function(e){var t=/./;try{"/./"[e](t)}catch(n){try{return t[yR]=!1,"/./"[e](t)}catch(e){}}return!1},gR=In,bR=a.f,kR=Ut,wR=gr,xR=vR,_R=k,SR=mR,ER="".startsWith,TR=Math.min,RR=SR("startsWith");gR({target:"String",proto:!0,forced:!!(RR||(dR=bR(String.prototype,"startsWith"),!dR||dR.writable))&&!RR},{startsWith:function(e){var t=wR(_R(this));xR(e);var n=kR(TR(arguments.length>1?arguments[1]:void 0,t.length)),r=wR(e);return ER?ER.call(t,r,n):t.slice(n,n+r.length)===r}});var IR=Tx.left,OR=L,CR=zs;In({target:"Array",proto:!0,forced:!ec("reduce")||!CR&&OR>79&&OR<83},{reduce:function(e){return IR(this,e,arguments.length,arguments.length>1?arguments[1]:void 0)}});var PR=s,AR=pe("iterator"),jR=!PR((function(){var e=new URL("b?a=1&b=2&c=3","http://a"),t=e.searchParams,n="";return e.pathname="c%20d",t.forEach((function(e,r){t.delete("b"),n+=r+e})),!t.sort||"http://a/c%20d?a=1&c=3"!==e.href||"3"!==t.get("c")||"a=1"!==String(new URLSearchParams("?a=1"))||!t[AR]||"a"!==new URL("https://a@b").username||"b"!==new URLSearchParams(new URLSearchParams("a=b")).get("a")||"xn--e1aybc"!==new URL("http://тест").host||"#%D0%B1"!==new URL("http://a#б").hash||"a1c3"!==n||"x"!==new URL("http://x",void 0).host})),MR=2147483647,LR=/[^\0-\u007E]/,NR=/[.\u3002\uFF0E\uFF61]/g,UR="Overflow: input needs wider integers to process",DR=Math.floor,FR=String.fromCharCode,BR=function(e){return e+22+75*(e<26)},qR=function(e,t,n){var r=0;for(e=n?DR(e/700):e>>1,e+=DR(e/t);e>455;r+=36)e=DR(e/35);return DR(r+36*e/(e+38))},WR=function(e){var t,n,r=[],i=(e=function(e){for(var t=[],n=0,r=e.length;n<r;){var i=e.charCodeAt(n++);if(i>=55296&&i<=56319&&n<r){var a=e.charCodeAt(n++);56320==(64512&a)?t.push(((1023&i)<<10)+(1023&a)+65536):(t.push(i),n--)}else t.push(i)}return t}(e)).length,a=128,s=0,o=72;for(t=0;t<e.length;t++)(n=e[t])<128&&r.push(FR(n));var u=r.length,c=u;for(u&&r.push("-");c<i;){var l=MR;for(t=0;t<e.length;t++)(n=e[t])>=a&&n<l&&(l=n);var f=c+1;if(l-a>DR((MR-s)/f))throw RangeError(UR);for(s+=(l-a)*f,a=l,t=0;t<e.length;t++){if((n=e[t])<a&&++s>MR)throw RangeError(UR);if(n==a){for(var d=s,p=36;;p+=36){var h=p<=o?1:p>=o+26?26:p-o;if(d<h)break;var v=d-h,y=36-h;r.push(FR(BR(h+v%y))),d=DR(v/y)}r.push(FR(BR(d))),o=qR(s,f,c==u),s=0,++c}}++s,++a}return r.join("")},zR=In,GR=R,JR=jR,VR=$e.exports,$R=Ha,KR=Mr,HR=Uf,YR=xt,QR=as,XR=ee,ZR=Nr,eI=qa,tI=De,nI=S,rI=gr,iI=Hn,aI=h,sI=ms,oI=hs,uI=pe,cI=GR("fetch"),lI=GR("Request"),fI=lI&&lI.prototype,dI=GR("Headers"),pI=uI("iterator"),hI="URLSearchParams",vI="URLSearchParamsIterator",yI=YR.set,mI=YR.getterFor(hI),gI=YR.getterFor(vI),bI=/\+/g,kI=Array(4),wI=function(e){return kI[e-1]||(kI[e-1]=RegExp("((?:%[\\da-f]{2}){"+e+"})","gi"))},xI=function(e){try{return decodeURIComponent(e)}catch(t){return e}},_I=function(e){var t=e.replace(bI," "),n=4;try{return decodeURIComponent(t)}catch(e){for(;n;)t=t.replace(wI(n--),xI);return t}},SI=/[!'()~]|%20/g,EI={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+"},TI=function(e){return EI[e]},RI=function(e){return encodeURIComponent(e).replace(SI,TI)},II=function(e,t){if(t)for(var n,r,i=t.split("&"),a=0;a<i.length;)(n=i[a++]).length&&(r=n.split("="),e.push({key:_I(r.shift()),value:_I(r.join("="))}))},OI=function(e){this.entries.length=0,II(this.entries,e)},CI=function(e,t){if(e<t)throw TypeError("Not enough arguments")},PI=HR((function(e,t){yI(this,{type:vI,iterator:sI(mI(e).entries),kind:t})}),"Iterator",(function(){var e=gI(this),t=e.kind,n=e.iterator.next(),r=n.value;return n.done||(n.value="keys"===t?r.key:"values"===t?r.value:[r.key,r.value]),n})),AI=function(){QR(this,AI,hI);var e,t,n,r,i,a,s,o,u,c=arguments.length>0?arguments[0]:void 0,l=this,f=[];if(yI(l,{type:hI,entries:f,updateURL:function(){},updateSearchParams:OI}),void 0!==c)if(nI(c))if("function"==typeof(e=oI(c)))for(n=(t=sI(c,e)).next;!(r=n.call(t)).done;){if((s=(a=(i=sI(tI(r.value))).next).call(i)).done||(o=a.call(i)).done||!a.call(i).done)throw TypeError("Expected sequence with length 2");f.push({key:rI(s.value),value:rI(o.value)})}else for(u in c)XR(c,u)&&f.push({key:u,value:rI(c[u])});else II(f,"string"==typeof c?"?"===c.charAt(0)?c.slice(1):c:rI(c))},jI=AI.prototype;if($R(jI,{append:function(e,t){CI(arguments.length,2);var n=mI(this);n.entries.push({key:rI(e),value:rI(t)}),n.updateURL()},delete:function(e){CI(arguments.length,1);for(var t=mI(this),n=t.entries,r=rI(e),i=0;i<n.length;)n[i].key===r?n.splice(i,1):i++;t.updateURL()},get:function(e){CI(arguments.length,1);for(var t=mI(this).entries,n=rI(e),r=0;r<t.length;r++)if(t[r].key===n)return t[r].value;return null},getAll:function(e){CI(arguments.length,1);for(var t=mI(this).entries,n=rI(e),r=[],i=0;i<t.length;i++)t[i].key===n&&r.push(t[i].value);return r},has:function(e){CI(arguments.length,1);for(var t=mI(this).entries,n=rI(e),r=0;r<t.length;)if(t[r++].key===n)return!0;return!1},set:function(e,t){CI(arguments.length,1);for(var n,r=mI(this),i=r.entries,a=!1,s=rI(e),o=rI(t),u=0;u<i.length;u++)(n=i[u]).key===s&&(a?i.splice(u--,1):(a=!0,n.value=o));a||i.push({key:s,value:o}),r.updateURL()},sort:function(){var e,t,n,r=mI(this),i=r.entries,a=i.slice();for(i.length=0,n=0;n<a.length;n++){for(e=a[n],t=0;t<n;t++)if(i[t].key>e.key){i.splice(t,0,e);break}t===n&&i.push(e)}r.updateURL()},forEach:function(e){for(var t,n=mI(this).entries,r=ZR(e,arguments.length>1?arguments[1]:void 0,3),i=0;i<n.length;)r((t=n[i++]).value,t.key,this)},keys:function(){return new PI(this,"keys")},values:function(){return new PI(this,"values")},entries:function(){return new PI(this,"entries")}},{enumerable:!0}),VR(jI,pI,jI.entries),VR(jI,"toString",(function(){for(var e,t=mI(this).entries,n=[],r=0;r<t.length;)e=t[r++],n.push(RI(e.key)+"="+RI(e.value));return n.join("&")}),{enumerable:!0}),KR(AI,hI),zR({global:!0,forced:!JR},{URLSearchParams:AI}),!JR&&"function"==typeof dI){var MI=function(e){if(nI(e)){var t,n=e.body;if(eI(n)===hI)return(t=e.headers?new dI(e.headers):new dI).has("content-type")||t.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"),iI(e,{body:aI(0,String(n)),headers:aI(0,t)})}return e};if("function"==typeof cI&&zR({global:!0,enumerable:!0,forced:!0},{fetch:function(e){return cI(e,arguments.length>1?MI(arguments[1]):{})}}),"function"==typeof lI){var LI=function(e){return QR(this,LI,"Request"),new lI(e,arguments.length>1?MI(arguments[1]):{})};fI.constructor=LI,LI.prototype=fI,zR({global:!0,forced:!0},{Request:LI})}}var NI,UI={URLSearchParams:AI,getState:mI},DI=In,FI=o,BI=jR,qI=i,WI=Nn,zI=$e.exports,GI=as,JI=ee,VI=NS,$I=uf,KI=mf.codeAt,HI=function(e){var t,n,r=[],i=e.toLowerCase().replace(NR,".").split(".");for(t=0;t<i.length;t++)n=i[t],r.push(LR.test(n)?"xn--"+WR(n):n);return r.join(".")},YI=gr,QI=Mr,XI=UI,ZI=xt,eO=qI.URL,tO=XI.URLSearchParams,nO=XI.getState,rO=ZI.set,iO=ZI.getterFor("URL"),aO=Math.floor,sO=Math.pow,oO="Invalid scheme",uO="Invalid host",cO="Invalid port",lO=/[A-Za-z]/,fO=/[\d+-.A-Za-z]/,dO=/\d/,pO=/^0x/i,hO=/^[0-7]+$/,vO=/^\d+$/,yO=/^[\dA-Fa-f]+$/,mO=/[\0\t\n\r #%/:<>?@[\\\]^|]/,gO=/[\0\t\n\r #/:<>?@[\\\]^|]/,bO=/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g,kO=/[\t\n\r]/g,wO=function(e,t){var n,r,i;if("["==t.charAt(0)){if("]"!=t.charAt(t.length-1))return uO;if(!(n=_O(t.slice(1,-1))))return uO;e.host=n}else if(PO(e)){if(t=HI(t),mO.test(t))return uO;if(null===(n=xO(t)))return uO;e.host=n}else{if(gO.test(t))return uO;for(n="",r=$I(t),i=0;i<r.length;i++)n+=OO(r[i],EO);e.host=n}},xO=function(e){var t,n,r,i,a,s,o,u=e.split(".");if(u.length&&""==u[u.length-1]&&u.pop(),(t=u.length)>4)return e;for(n=[],r=0;r<t;r++){if(""==(i=u[r]))return e;if(a=10,i.length>1&&"0"==i.charAt(0)&&(a=pO.test(i)?16:8,i=i.slice(8==a?1:2)),""===i)s=0;else{if(!(10==a?vO:8==a?hO:yO).test(i))return e;s=parseInt(i,a)}n.push(s)}for(r=0;r<t;r++)if(s=n[r],r==t-1){if(s>=sO(256,5-t))return null}else if(s>255)return null;for(o=n.pop(),r=0;r<n.length;r++)o+=n[r]*sO(256,3-r);return o},_O=function(e){var t,n,r,i,a,s,o,u=[0,0,0,0,0,0,0,0],c=0,l=null,f=0,d=function(){return e.charAt(f)};if(":"==d()){if(":"!=e.charAt(1))return;f+=2,l=++c}for(;d();){if(8==c)return;if(":"!=d()){for(t=n=0;n<4&&yO.test(d());)t=16*t+parseInt(d(),16),f++,n++;if("."==d()){if(0==n)return;if(f-=n,c>6)return;for(r=0;d();){if(i=null,r>0){if(!("."==d()&&r<4))return;f++}if(!dO.test(d()))return;for(;dO.test(d());){if(a=parseInt(d(),10),null===i)i=a;else{if(0==i)return;i=10*i+a}if(i>255)return;f++}u[c]=256*u[c]+i,2!=++r&&4!=r||c++}if(4!=r)return;break}if(":"==d()){if(f++,!d())return}else if(d())return;u[c++]=t}else{if(null!==l)return;f++,l=++c}}if(null!==l)for(s=c-l,c=7;0!=c&&s>0;)o=u[c],u[c--]=u[l+s-1],u[l+--s]=o;else if(8!=c)return;return u},SO=function(e){var t,n,r,i;if("number"==typeof e){for(t=[],n=0;n<4;n++)t.unshift(e%256),e=aO(e/256);return t.join(".")}if("object"==typeof e){for(t="",r=function(e){for(var t=null,n=1,r=null,i=0,a=0;a<8;a++)0!==e[a]?(i>n&&(t=r,n=i),r=null,i=0):(null===r&&(r=a),++i);return i>n&&(t=r,n=i),t}(e),n=0;n<8;n++)i&&0===e[n]||(i&&(i=!1),r===n?(t+=n?":":"::",i=!0):(t+=e[n].toString(16),n<7&&(t+=":")));return"["+t+"]"}return e},EO={},TO=VI({},EO,{" ":1,'"':1,"<":1,">":1,"`":1}),RO=VI({},TO,{"#":1,"?":1,"{":1,"}":1}),IO=VI({},RO,{"/":1,":":1,";":1,"=":1,"@":1,"[":1,"\\":1,"]":1,"^":1,"|":1}),OO=function(e,t){var n=KI(e,0);return n>32&&n<127&&!JI(t,e)?e:encodeURIComponent(e)},CO={ftp:21,file:null,http:80,https:443,ws:80,wss:443},PO=function(e){return JI(CO,e.scheme)},AO=function(e){return""!=e.username||""!=e.password},jO=function(e){return!e.host||e.cannotBeABaseURL||"file"==e.scheme},MO=function(e,t){var n;return 2==e.length&&lO.test(e.charAt(0))&&(":"==(n=e.charAt(1))||!t&&"|"==n)},LO=function(e){var t;return e.length>1&&MO(e.slice(0,2))&&(2==e.length||"/"===(t=e.charAt(2))||"\\"===t||"?"===t||"#"===t)},NO=function(e){var t=e.path,n=t.length;!n||"file"==e.scheme&&1==n&&MO(t[0],!0)||t.pop()},UO=function(e){return"."===e||"%2e"===e.toLowerCase()},DO={},FO={},BO={},qO={},WO={},zO={},GO={},JO={},VO={},$O={},KO={},HO={},YO={},QO={},XO={},ZO={},eC={},tC={},nC={},rC={},iC={},aC=function(e,t,n,r){var i,a,s,o,u,c=n||DO,l=0,f="",d=!1,p=!1,h=!1;for(n||(e.scheme="",e.username="",e.password="",e.host=null,e.port=null,e.path=[],e.query=null,e.fragment=null,e.cannotBeABaseURL=!1,t=t.replace(bO,"")),t=t.replace(kO,""),i=$I(t);l<=i.length;){switch(a=i[l],c){case DO:if(!a||!lO.test(a)){if(n)return oO;c=BO;continue}f+=a.toLowerCase(),c=FO;break;case FO:if(a&&(fO.test(a)||"+"==a||"-"==a||"."==a))f+=a.toLowerCase();else{if(":"!=a){if(n)return oO;f="",c=BO,l=0;continue}if(n&&(PO(e)!=JI(CO,f)||"file"==f&&(AO(e)||null!==e.port)||"file"==e.scheme&&!e.host))return;if(e.scheme=f,n)return void(PO(e)&&CO[e.scheme]==e.port&&(e.port=null));f="","file"==e.scheme?c=QO:PO(e)&&r&&r.scheme==e.scheme?c=qO:PO(e)?c=JO:"/"==i[l+1]?(c=WO,l++):(e.cannotBeABaseURL=!0,e.path.push(""),c=nC)}break;case BO:if(!r||r.cannotBeABaseURL&&"#"!=a)return oO;if(r.cannotBeABaseURL&&"#"==a){e.scheme=r.scheme,e.path=r.path.slice(),e.query=r.query,e.fragment="",e.cannotBeABaseURL=!0,c=iC;break}c="file"==r.scheme?QO:zO;continue;case qO:if("/"!=a||"/"!=i[l+1]){c=zO;continue}c=VO,l++;break;case WO:if("/"==a){c=$O;break}c=tC;continue;case zO:if(e.scheme=r.scheme,a==NI)e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,e.path=r.path.slice(),e.query=r.query;else if("/"==a||"\\"==a&&PO(e))c=GO;else if("?"==a)e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,e.path=r.path.slice(),e.query="",c=rC;else{if("#"!=a){e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,e.path=r.path.slice(),e.path.pop(),c=tC;continue}e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,e.path=r.path.slice(),e.query=r.query,e.fragment="",c=iC}break;case GO:if(!PO(e)||"/"!=a&&"\\"!=a){if("/"!=a){e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,c=tC;continue}c=$O}else c=VO;break;case JO:if(c=VO,"/"!=a||"/"!=f.charAt(l+1))continue;l++;break;case VO:if("/"!=a&&"\\"!=a){c=$O;continue}break;case $O:if("@"==a){d&&(f="%40"+f),d=!0,s=$I(f);for(var v=0;v<s.length;v++){var y=s[v];if(":"!=y||h){var m=OO(y,IO);h?e.password+=m:e.username+=m}else h=!0}f=""}else if(a==NI||"/"==a||"?"==a||"#"==a||"\\"==a&&PO(e)){if(d&&""==f)return"Invalid authority";l-=$I(f).length+1,f="",c=KO}else f+=a;break;case KO:case HO:if(n&&"file"==e.scheme){c=ZO;continue}if(":"!=a||p){if(a==NI||"/"==a||"?"==a||"#"==a||"\\"==a&&PO(e)){if(PO(e)&&""==f)return uO;if(n&&""==f&&(AO(e)||null!==e.port))return;if(o=wO(e,f))return o;if(f="",c=eC,n)return;continue}"["==a?p=!0:"]"==a&&(p=!1),f+=a}else{if(""==f)return uO;if(o=wO(e,f))return o;if(f="",c=YO,n==HO)return}break;case YO:if(!dO.test(a)){if(a==NI||"/"==a||"?"==a||"#"==a||"\\"==a&&PO(e)||n){if(""!=f){var g=parseInt(f,10);if(g>65535)return cO;e.port=PO(e)&&g===CO[e.scheme]?null:g,f=""}if(n)return;c=eC;continue}return cO}f+=a;break;case QO:if(e.scheme="file","/"==a||"\\"==a)c=XO;else{if(!r||"file"!=r.scheme){c=tC;continue}if(a==NI)e.host=r.host,e.path=r.path.slice(),e.query=r.query;else if("?"==a)e.host=r.host,e.path=r.path.slice(),e.query="",c=rC;else{if("#"!=a){LO(i.slice(l).join(""))||(e.host=r.host,e.path=r.path.slice(),NO(e)),c=tC;continue}e.host=r.host,e.path=r.path.slice(),e.query=r.query,e.fragment="",c=iC}}break;case XO:if("/"==a||"\\"==a){c=ZO;break}r&&"file"==r.scheme&&!LO(i.slice(l).join(""))&&(MO(r.path[0],!0)?e.path.push(r.path[0]):e.host=r.host),c=tC;continue;case ZO:if(a==NI||"/"==a||"\\"==a||"?"==a||"#"==a){if(!n&&MO(f))c=tC;else if(""==f){if(e.host="",n)return;c=eC}else{if(o=wO(e,f))return o;if("localhost"==e.host&&(e.host=""),n)return;f="",c=eC}continue}f+=a;break;case eC:if(PO(e)){if(c=tC,"/"!=a&&"\\"!=a)continue}else if(n||"?"!=a)if(n||"#"!=a){if(a!=NI&&(c=tC,"/"!=a))continue}else e.fragment="",c=iC;else e.query="",c=rC;break;case tC:if(a==NI||"/"==a||"\\"==a&&PO(e)||!n&&("?"==a||"#"==a)){if(".."===(u=(u=f).toLowerCase())||"%2e."===u||".%2e"===u||"%2e%2e"===u?(NO(e),"/"==a||"\\"==a&&PO(e)||e.path.push("")):UO(f)?"/"==a||"\\"==a&&PO(e)||e.path.push(""):("file"==e.scheme&&!e.path.length&&MO(f)&&(e.host&&(e.host=""),f=f.charAt(0)+":"),e.path.push(f)),f="","file"==e.scheme&&(a==NI||"?"==a||"#"==a))for(;e.path.length>1&&""===e.path[0];)e.path.shift();"?"==a?(e.query="",c=rC):"#"==a&&(e.fragment="",c=iC)}else f+=OO(a,RO);break;case nC:"?"==a?(e.query="",c=rC):"#"==a?(e.fragment="",c=iC):a!=NI&&(e.path[0]+=OO(a,EO));break;case rC:n||"#"!=a?a!=NI&&("'"==a&&PO(e)?e.query+="%27":e.query+="#"==a?"%23":OO(a,EO)):(e.fragment="",c=iC);break;case iC:a!=NI&&(e.fragment+=OO(a,TO))}l++}},sC=function(e){var t,n,r=GI(this,sC,"URL"),i=arguments.length>1?arguments[1]:void 0,a=YI(e),s=rO(r,{type:"URL"});if(void 0!==i)if(i instanceof sC)t=iO(i);else if(n=aC(t={},YI(i)))throw TypeError(n);if(n=aC(s,a,null,t))throw TypeError(n);var o=s.searchParams=new tO,u=nO(o);u.updateSearchParams(s.query),u.updateURL=function(){s.query=String(o)||null},FI||(r.href=uC.call(r),r.origin=cC.call(r),r.protocol=lC.call(r),r.username=fC.call(r),r.password=dC.call(r),r.host=pC.call(r),r.hostname=hC.call(r),r.port=vC.call(r),r.pathname=yC.call(r),r.search=mC.call(r),r.searchParams=gC.call(r),r.hash=bC.call(r))},oC=sC.prototype,uC=function(){var e=iO(this),t=e.scheme,n=e.username,r=e.password,i=e.host,a=e.port,s=e.path,o=e.query,u=e.fragment,c=t+":";return null!==i?(c+="//",AO(e)&&(c+=n+(r?":"+r:"")+"@"),c+=SO(i),null!==a&&(c+=":"+a)):"file"==t&&(c+="//"),c+=e.cannotBeABaseURL?s[0]:s.length?"/"+s.join("/"):"",null!==o&&(c+="?"+o),null!==u&&(c+="#"+u),c},cC=function(){var e=iO(this),t=e.scheme,n=e.port;if("blob"==t)try{return new sC(t.path[0]).origin}catch(e){return"null"}return"file"!=t&&PO(e)?t+"://"+SO(e.host)+(null!==n?":"+n:""):"null"},lC=function(){return iO(this).scheme+":"},fC=function(){return iO(this).username},dC=function(){return iO(this).password},pC=function(){var e=iO(this),t=e.host,n=e.port;return null===t?"":null===n?SO(t):SO(t)+":"+n},hC=function(){var e=iO(this).host;return null===e?"":SO(e)},vC=function(){var e=iO(this).port;return null===e?"":String(e)},yC=function(){var e=iO(this),t=e.path;return e.cannotBeABaseURL?t[0]:t.length?"/"+t.join("/"):""},mC=function(){var e=iO(this).query;return e?"?"+e:""},gC=function(){return iO(this).searchParams},bC=function(){var e=iO(this).fragment;return e?"#"+e:""},kC=function(e,t){return{get:e,set:t,configurable:!0,enumerable:!0}};if(FI&&WI(oC,{href:kC(uC,(function(e){var t=iO(this),n=YI(e),r=aC(t,n);if(r)throw TypeError(r);nO(t.searchParams).updateSearchParams(t.query)})),origin:kC(cC),protocol:kC(lC,(function(e){var t=iO(this);aC(t,YI(e)+":",DO)})),username:kC(fC,(function(e){var t=iO(this),n=$I(YI(e));if(!jO(t)){t.username="";for(var r=0;r<n.length;r++)t.username+=OO(n[r],IO)}})),password:kC(dC,(function(e){var t=iO(this),n=$I(YI(e));if(!jO(t)){t.password="";for(var r=0;r<n.length;r++)t.password+=OO(n[r],IO)}})),host:kC(pC,(function(e){var t=iO(this);t.cannotBeABaseURL||aC(t,YI(e),KO)})),hostname:kC(hC,(function(e){var t=iO(this);t.cannotBeABaseURL||aC(t,YI(e),HO)})),port:kC(vC,(function(e){var t=iO(this);jO(t)||(""==(e=YI(e))?t.port=null:aC(t,e,YO))})),pathname:kC(yC,(function(e){var t=iO(this);t.cannotBeABaseURL||(t.path=[],aC(t,YI(e),eC))})),search:kC(mC,(function(e){var t=iO(this);""==(e=YI(e))?t.query=null:("?"==e.charAt(0)&&(e=e.slice(1)),t.query="",aC(t,e,rC)),nO(t.searchParams).updateSearchParams(t.query)})),searchParams:kC(gC),hash:kC(bC,(function(e){var t=iO(this);""!=(e=YI(e))?("#"==e.charAt(0)&&(e=e.slice(1)),t.fragment="",aC(t,e,iC)):t.fragment=null}))}),zI(oC,"toJSON",(function(){return uC.call(this)}),{enumerable:!0}),zI(oC,"toString",(function(){return uC.call(this)}),{enumerable:!0}),eO){var wC=eO.createObjectURL,xC=eO.revokeObjectURL;wC&&zI(sC,"createObjectURL",(function(e){return wC.apply(eO,arguments)})),xC&&zI(sC,"revokeObjectURL",(function(e){return xC.apply(eO,arguments)}))}function _C(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}function SC(e){return function(e){if(Array.isArray(e))return ap(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||sp(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}QI(sC,"URL"),DI({global:!0,forced:!BI,sham:!FI},{URL:sC}),function(e){var t=void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};Object.defineProperty(e,"__esModule",{value:!0});var n=yv.exports,r=Ch.exports,i=bv,a=ld.exports,s=wh,o=Dv;function u(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var l=u(n),f=u(r),d=u(i),p=c(a);
|
129
|
+
this.Twilio=this.Twilio||{},this.Twilio.Conversations=function(e){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})})),t}var r=function(e){return e&&e.Math==Math&&e},i=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof t&&t)||function(){return this}()||Function("return this")(),a={},s=function(e){try{return!!e()}catch(e){return!0}},o=!s((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),u={},c={}.propertyIsEnumerable,l=Object.getOwnPropertyDescriptor,f=l&&!c.call({1:2},1);u.f=f?function(e){var t=l(this,e);return!!t&&t.enumerable}:c;var d,p,h=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},v={}.toString,y=function(e){return v.call(e).slice(8,-1)},m=y,g="".split,b=s((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==m(e)?g.call(e,""):Object(e)}:Object,k=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},w=b,x=k,_=function(e){return w(x(e))},S=function(e){return"object"==typeof e?null!==e:"function"==typeof e},E=i,T=function(e){return"function"==typeof e?e:void 0},R=function(e,t){return arguments.length<2?T(E[e]):E[e]&&E[e][t]},I=R("navigator","userAgent")||"",O=i,C=I,P=O.process,A=O.Deno,j=P&&P.versions||A&&A.version,M=j&&j.v8;M?p=(d=M.split("."))[0]<4?1:d[0]+d[1]:C&&(!(d=C.match(/Edge\/(\d+)/))||d[1]>=74)&&(d=C.match(/Chrome\/(\d+)/))&&(p=d[1]);var L=p&&+p,N=L,U=s,D=!!Object.getOwnPropertySymbols&&!U((function(){var e=Symbol();return!String(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&N&&N<41})),F=D&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,B=R,q=F?function(e){return"symbol"==typeof e}:function(e){var t=B("Symbol");return"function"==typeof t&&Object(e)instanceof t},W=S,z={exports:{}},G=i,J=function(e,t){try{Object.defineProperty(G,e,{value:t,configurable:!0,writable:!0})}catch(n){G[e]=t}return t},V=J,$="__core-js_shared__",K=i[$]||V($,{}),H=K;(z.exports=function(e,t){return H[e]||(H[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.17.3",mode:"global",copyright:"© 2021 Denis Pushkarev (zloirock.ru)"});var Y=k,Q=function(e){return Object(Y(e))},X=Q,Z={}.hasOwnProperty,ee=Object.hasOwn||function(e,t){return Z.call(X(e),t)},te=0,ne=Math.random(),re=function(e){return"Symbol("+String(void 0===e?"":e)+")_"+(++te+ne).toString(36)},ie=i,ae=z.exports,se=ee,oe=re,ue=D,ce=F,le=ae("wks"),fe=ie.Symbol,de=ce?fe:fe&&fe.withoutSetter||oe,pe=function(e){return se(le,e)&&(ue||"string"==typeof le[e])||(ue&&se(fe,e)?le[e]=fe[e]:le[e]=de("Symbol."+e)),le[e]},he=S,ve=q,ye=function(e,t){var n,r;if("string"===t&&"function"==typeof(n=e.toString)&&!W(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!W(r=n.call(e)))return r;if("string"!==t&&"function"==typeof(n=e.toString)&&!W(r=n.call(e)))return r;throw TypeError("Can't convert object to primitive value")},me=pe("toPrimitive"),ge=function(e,t){if(!he(e)||ve(e))return e;var n,r=e[me];if(void 0!==r){if(void 0===t&&(t="default"),n=r.call(e,t),!he(n)||ve(n))return n;throw TypeError("Can't convert object to primitive value")}return void 0===t&&(t="number"),ye(e,t)},be=ge,ke=q,we=function(e){var t=be(e,"string");return ke(t)?t:String(t)},xe=S,_e=i.document,Se=xe(_e)&&xe(_e.createElement),Ee=function(e){return Se?_e.createElement(e):{}},Te=Ee,Re=!o&&!s((function(){return 7!=Object.defineProperty(Te("div"),"a",{get:function(){return 7}}).a})),Ie=o,Oe=u,Ce=h,Pe=_,Ae=we,je=ee,Me=Re,Le=Object.getOwnPropertyDescriptor;a.f=Ie?Le:function(e,t){if(e=Pe(e),t=Ae(t),Me)try{return Le(e,t)}catch(e){}if(je(e,t))return Ce(!Oe.f.call(e,t),e[t])};var Ne={},Ue=S,De=function(e){if(!Ue(e))throw TypeError(String(e)+" is not an object");return e},Fe=o,Be=Re,qe=De,We=we,ze=Object.defineProperty;Ne.f=Fe?ze:function(e,t,n){if(qe(e),t=We(t),qe(n),Be)try{return ze(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(e[t]=n.value),e};var Ge=Ne,Je=h,Ve=o?function(e,t,n){return Ge.f(e,t,Je(1,n))}:function(e,t,n){return e[t]=n,e},$e={exports:{}},Ke=K,He=Function.toString;"function"!=typeof Ke.inspectSource&&(Ke.inspectSource=function(e){return He.call(e)});var Ye,Qe,Xe,Ze=Ke.inspectSource,et=Ze,tt=i.WeakMap,nt="function"==typeof tt&&/native code/.test(et(tt)),rt=z.exports,it=re,at=rt("keys"),st=function(e){return at[e]||(at[e]=it(e))},ot={},ut=nt,ct=S,lt=Ve,ft=ee,dt=K,pt=st,ht=ot,vt="Object already initialized",yt=i.WeakMap;if(ut||dt.state){var mt=dt.state||(dt.state=new yt),gt=mt.get,bt=mt.has,kt=mt.set;Ye=function(e,t){if(bt.call(mt,e))throw new TypeError(vt);return t.facade=e,kt.call(mt,e,t),t},Qe=function(e){return gt.call(mt,e)||{}},Xe=function(e){return bt.call(mt,e)}}else{var wt=pt("state");ht[wt]=!0,Ye=function(e,t){if(ft(e,wt))throw new TypeError(vt);return t.facade=e,lt(e,wt,t),t},Qe=function(e){return ft(e,wt)?e[wt]:{}},Xe=function(e){return ft(e,wt)}}var xt={set:Ye,get:Qe,has:Xe,enforce:function(e){return Xe(e)?Qe(e):Ye(e,{})},getterFor:function(e){return function(t){var n;if(!ct(t)||(n=Qe(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return n}}},_t=i,St=Ve,Et=ee,Tt=J,Rt=Ze,It=xt.get,Ot=xt.enforce,Ct=String(String).split("String");($e.exports=function(e,t,n,r){var i,a=!!r&&!!r.unsafe,s=!!r&&!!r.enumerable,o=!!r&&!!r.noTargetGet;"function"==typeof n&&("string"!=typeof t||Et(n,"name")||St(n,"name",t),(i=Ot(n)).source||(i.source=Ct.join("string"==typeof t?t:""))),e!==_t?(a?!o&&e[t]&&(s=!0):delete e[t],s?e[t]=n:St(e,t,n)):s?e[t]=n:Tt(t,n)})(Function.prototype,"toString",(function(){return"function"==typeof this&&It(this).source||Rt(this)}));var Pt={},At=Math.ceil,jt=Math.floor,Mt=function(e){return isNaN(e=+e)?0:(e>0?jt:At)(e)},Lt=Mt,Nt=Math.min,Ut=function(e){return e>0?Nt(Lt(e),9007199254740991):0},Dt=Mt,Ft=Math.max,Bt=Math.min,qt=function(e,t){var n=Dt(e);return n<0?Ft(n+t,0):Bt(n,t)},Wt=_,zt=Ut,Gt=qt,Jt=function(e){return function(t,n,r){var i,a=Wt(t),s=zt(a.length),o=Gt(r,s);if(e&&n!=n){for(;s>o;)if((i=a[o++])!=i)return!0}else for(;s>o;o++)if((e||o in a)&&a[o]===n)return e||o||0;return!e&&-1}},Vt={includes:Jt(!0),indexOf:Jt(!1)},$t=ee,Kt=_,Ht=Vt.indexOf,Yt=ot,Qt=function(e,t){var n,r=Kt(e),i=0,a=[];for(n in r)!$t(Yt,n)&&$t(r,n)&&a.push(n);for(;t.length>i;)$t(r,n=t[i++])&&(~Ht(a,n)||a.push(n));return a},Xt=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],Zt=Qt,en=Xt.concat("length","prototype");Pt.f=Object.getOwnPropertyNames||function(e){return Zt(e,en)};var tn={};tn.f=Object.getOwnPropertySymbols;var nn,rn=Pt,an=tn,sn=De,on=R("Reflect","ownKeys")||function(e){var t=rn.f(sn(e)),n=an.f;return n?t.concat(n(e)):t},un=ee,cn=on,ln=a,fn=Ne,dn=function(e,t){for(var n=cn(t),r=fn.f,i=ln.f,a=0;a<n.length;a++){var s=n[a];un(e,s)||r(e,s,i(t,s))}},pn=s,hn=/#|\.prototype\./,vn=function(e,t){var n=mn[yn(e)];return n==bn||n!=gn&&("function"==typeof t?pn(t):!!t)},yn=vn.normalize=function(e){return String(e).replace(hn,".").toLowerCase()},mn=vn.data={},gn=vn.NATIVE="N",bn=vn.POLYFILL="P",kn=vn,wn=i,xn=a.f,_n=Ve,Sn=$e.exports,En=J,Tn=dn,Rn=kn,In=function(e,t){var n,r,i,a,s,o=e.target,u=e.global,c=e.stat;if(n=u?wn:c?wn[o]||En(o,{}):(wn[o]||{}).prototype)for(r in t){if(a=t[r],i=e.noTargetGet?(s=xn(n,r))&&s.value:n[r],!Rn(u?r:o+(c?".":"#")+r,e.forced)&&void 0!==i){if(typeof a==typeof i)continue;Tn(a,i)}(e.sham||i&&i.sham)&&_n(a,"sham",!0),Sn(n,r,a,e)}},On=function(e){if("function"!=typeof e)throw TypeError(String(e)+" is not a function");return e},Cn=Qt,Pn=Xt,An=Object.keys||function(e){return Cn(e,Pn)},jn=Ne,Mn=De,Ln=An,Nn=o?Object.defineProperties:function(e,t){Mn(e);for(var n,r=Ln(t),i=r.length,a=0;i>a;)jn.f(e,n=r[a++],t[n]);return e},Un=R("document","documentElement"),Dn=De,Fn=Nn,Bn=Xt,qn=ot,Wn=Un,zn=Ee,Gn=st("IE_PROTO"),Jn=function(){},Vn=function(e){return"<script>"+e+"</"+"script>"},$n=function(e){e.write(Vn("")),e.close();var t=e.parentWindow.Object;return e=null,t},Kn=function(){try{nn=new ActiveXObject("htmlfile")}catch(e){}var e,t;Kn="undefined"!=typeof document?document.domain&&nn?$n(nn):((t=zn("iframe")).style.display="none",Wn.appendChild(t),t.src=String("javascript:"),(e=t.contentWindow.document).open(),e.write(Vn("document.F=Object")),e.close(),e.F):$n(nn);for(var n=Bn.length;n--;)delete Kn.prototype[Bn[n]];return Kn()};qn[Gn]=!0;var Hn=Object.create||function(e,t){var n;return null!==e?(Jn.prototype=Dn(e),n=new Jn,Jn.prototype=null,n[Gn]=e):n=Kn(),void 0===t?n:Fn(n,t)},Yn=On,Qn=S,Xn=[].slice,Zn={},er=function(e,t,n){if(!(t in Zn)){for(var r=[],i=0;i<t;i++)r[i]="a["+i+"]";Zn[t]=Function("C,a","return new C("+r.join(",")+")")}return Zn[t](e,n)},tr=Function.bind||function(e){var t=Yn(this),n=Xn.call(arguments,1),r=function(){var i=n.concat(Xn.call(arguments));return this instanceof r?er(t,i.length,i):t.apply(e,i)};return Qn(t.prototype)&&(r.prototype=t.prototype),r},nr=In,rr=On,ir=De,ar=S,sr=Hn,or=tr,ur=s,cr=R("Reflect","construct"),lr=ur((function(){function e(){}return!(cr((function(){}),[],e)instanceof e)})),fr=!ur((function(){cr((function(){}))})),dr=lr||fr;nr({target:"Reflect",stat:!0,forced:dr,sham:dr},{construct:function(e,t){rr(e),ir(t);var n=arguments.length<3?e:rr(arguments[2]);if(fr&&!lr)return cr(e,t,n);if(e==n){switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3])}var r=[null];return r.push.apply(r,t),new(or.apply(e,r))}var i=n.prototype,a=sr(ar(i)?i:Object.prototype),s=Function.apply.call(e,a,t);return ar(s)?s:a}});var pr=Q,hr=An;In({target:"Object",stat:!0,forced:s((function(){hr(1)}))},{keys:function(e){return hr(pr(e))}});var vr=y,yr=Array.isArray||function(e){return"Array"==vr(e)},mr=q,gr=function(e){if(mr(e))throw TypeError("Cannot convert a Symbol value to a string");return String(e)},br={},kr=_,wr=Pt.f,xr={}.toString,_r="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];br.f=function(e){return _r&&"[object Window]"==xr.call(e)?function(e){try{return wr(e)}catch(e){return _r.slice()}}(e):wr(kr(e))};var Sr={},Er=pe;Sr.f=Er;var Tr=i,Rr=ee,Ir=Sr,Or=Ne.f,Cr=function(e){var t=Tr.Symbol||(Tr.Symbol={});Rr(t,e)||Or(t,e,{value:Ir.f(e)})},Pr=Ne.f,Ar=ee,jr=pe("toStringTag"),Mr=function(e,t,n){e&&!Ar(e=n?e:e.prototype,jr)&&Pr(e,jr,{configurable:!0,value:t})},Lr=On,Nr=function(e,t,n){if(Lr(e),void 0===t)return e;switch(n){case 0:return function(){return e.call(t)};case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}},Ur=S,Dr=yr,Fr=pe("species"),Br=function(e){var t;return Dr(e)&&("function"!=typeof(t=e.constructor)||t!==Array&&!Dr(t.prototype)?Ur(t)&&null===(t=t[Fr])&&(t=void 0):t=void 0),void 0===t?Array:t},qr=function(e,t){return new(Br(e))(0===t?0:t)},Wr=Nr,zr=b,Gr=Q,Jr=Ut,Vr=qr,$r=[].push,Kr=function(e){var t=1==e,n=2==e,r=3==e,i=4==e,a=6==e,s=7==e,o=5==e||a;return function(u,c,l,f){for(var d,p,h=Gr(u),v=zr(h),y=Wr(c,l,3),m=Jr(v.length),g=0,b=f||Vr,k=t?b(u,m):n||s?b(u,0):void 0;m>g;g++)if((o||g in v)&&(p=y(d=v[g],g,h),e))if(t)k[g]=p;else if(p)switch(e){case 3:return!0;case 5:return d;case 6:return g;case 2:$r.call(k,d)}else switch(e){case 4:return!1;case 7:$r.call(k,d)}return a?-1:r||i?i:k}},Hr={forEach:Kr(0),map:Kr(1),filter:Kr(2),some:Kr(3),every:Kr(4),find:Kr(5),findIndex:Kr(6),filterReject:Kr(7)},Yr=In,Qr=i,Xr=R,Zr=o,ei=D,ti=s,ni=ee,ri=yr,ii=S,ai=q,si=De,oi=Q,ui=_,ci=we,li=gr,fi=h,di=Hn,pi=An,hi=Pt,vi=br,yi=tn,mi=a,gi=Ne,bi=u,ki=Ve,wi=$e.exports,xi=z.exports,_i=ot,Si=re,Ei=pe,Ti=Sr,Ri=Cr,Ii=Mr,Oi=xt,Ci=Hr.forEach,Pi=st("hidden"),Ai="Symbol",ji=Ei("toPrimitive"),Mi=Oi.set,Li=Oi.getterFor(Ai),Ni=Object.prototype,Ui=Qr.Symbol,Di=Xr("JSON","stringify"),Fi=mi.f,Bi=gi.f,qi=vi.f,Wi=bi.f,zi=xi("symbols"),Gi=xi("op-symbols"),Ji=xi("string-to-symbol-registry"),Vi=xi("symbol-to-string-registry"),$i=xi("wks"),Ki=Qr.QObject,Hi=!Ki||!Ki.prototype||!Ki.prototype.findChild,Yi=Zr&&ti((function(){return 7!=di(Bi({},"a",{get:function(){return Bi(this,"a",{value:7}).a}})).a}))?function(e,t,n){var r=Fi(Ni,t);r&&delete Ni[t],Bi(e,t,n),r&&e!==Ni&&Bi(Ni,t,r)}:Bi,Qi=function(e,t){var n=zi[e]=di(Ui.prototype);return Mi(n,{type:Ai,tag:e,description:t}),Zr||(n.description=t),n},Xi=function(e,t,n){e===Ni&&Xi(Gi,t,n),si(e);var r=ci(t);return si(n),ni(zi,r)?(n.enumerable?(ni(e,Pi)&&e[Pi][r]&&(e[Pi][r]=!1),n=di(n,{enumerable:fi(0,!1)})):(ni(e,Pi)||Bi(e,Pi,fi(1,{})),e[Pi][r]=!0),Yi(e,r,n)):Bi(e,r,n)},Zi=function(e,t){si(e);var n=ui(t),r=pi(n).concat(ra(n));return Ci(r,(function(t){Zr&&!ea.call(n,t)||Xi(e,t,n[t])})),e},ea=function(e){var t=ci(e),n=Wi.call(this,t);return!(this===Ni&&ni(zi,t)&&!ni(Gi,t))&&(!(n||!ni(this,t)||!ni(zi,t)||ni(this,Pi)&&this[Pi][t])||n)},ta=function(e,t){var n=ui(e),r=ci(t);if(n!==Ni||!ni(zi,r)||ni(Gi,r)){var i=Fi(n,r);return!i||!ni(zi,r)||ni(n,Pi)&&n[Pi][r]||(i.enumerable=!0),i}},na=function(e){var t=qi(ui(e)),n=[];return Ci(t,(function(e){ni(zi,e)||ni(_i,e)||n.push(e)})),n},ra=function(e){var t=e===Ni,n=qi(t?Gi:ui(e)),r=[];return Ci(n,(function(e){!ni(zi,e)||t&&!ni(Ni,e)||r.push(zi[e])})),r};(ei||(wi((Ui=function(){if(this instanceof Ui)throw TypeError("Symbol is not a constructor");var e=arguments.length&&void 0!==arguments[0]?li(arguments[0]):void 0,t=Si(e),n=function(e){this===Ni&&n.call(Gi,e),ni(this,Pi)&&ni(this[Pi],t)&&(this[Pi][t]=!1),Yi(this,t,fi(1,e))};return Zr&&Hi&&Yi(Ni,t,{configurable:!0,set:n}),Qi(t,e)}).prototype,"toString",(function(){return Li(this).tag})),wi(Ui,"withoutSetter",(function(e){return Qi(Si(e),e)})),bi.f=ea,gi.f=Xi,mi.f=ta,hi.f=vi.f=na,yi.f=ra,Ti.f=function(e){return Qi(Ei(e),e)},Zr&&(Bi(Ui.prototype,"description",{configurable:!0,get:function(){return Li(this).description}}),wi(Ni,"propertyIsEnumerable",ea,{unsafe:!0}))),Yr({global:!0,wrap:!0,forced:!ei,sham:!ei},{Symbol:Ui}),Ci(pi($i),(function(e){Ri(e)})),Yr({target:Ai,stat:!0,forced:!ei},{for:function(e){var t=li(e);if(ni(Ji,t))return Ji[t];var n=Ui(t);return Ji[t]=n,Vi[n]=t,n},keyFor:function(e){if(!ai(e))throw TypeError(e+" is not a symbol");if(ni(Vi,e))return Vi[e]},useSetter:function(){Hi=!0},useSimple:function(){Hi=!1}}),Yr({target:"Object",stat:!0,forced:!ei,sham:!Zr},{create:function(e,t){return void 0===t?di(e):Zi(di(e),t)},defineProperty:Xi,defineProperties:Zi,getOwnPropertyDescriptor:ta}),Yr({target:"Object",stat:!0,forced:!ei},{getOwnPropertyNames:na,getOwnPropertySymbols:ra}),Yr({target:"Object",stat:!0,forced:ti((function(){yi.f(1)}))},{getOwnPropertySymbols:function(e){return yi.f(oi(e))}}),Di)&&Yr({target:"JSON",stat:!0,forced:!ei||ti((function(){var e=Ui();return"[null]"!=Di([e])||"{}"!=Di({a:e})||"{}"!=Di(Object(e))}))},{stringify:function(e,t,n){for(var r,i=[e],a=1;arguments.length>a;)i.push(arguments[a++]);if(r=t,(ii(t)||void 0!==e)&&!ai(e))return ri(t)||(t=function(e,t){if("function"==typeof r&&(t=r.call(this,e,t)),!ai(t))return t}),i[1]=t,Di.apply(null,i)}});Ui.prototype[ji]||ki(Ui.prototype,ji,Ui.prototype.valueOf),Ii(Ui,Ai),_i[Pi]=!0;var ia=s,aa=L,sa=pe("species"),oa=function(e){return aa>=51||!ia((function(){var t=[];return(t.constructor={})[sa]=function(){return{foo:1}},1!==t[e](Boolean).foo}))},ua=Hr.filter;In({target:"Array",proto:!0,forced:!oa("filter")},{filter:function(e){return ua(this,e,arguments.length>1?arguments[1]:void 0)}});var ca=In,la=s,fa=_,da=a.f,pa=o,ha=la((function(){da(1)}));ca({target:"Object",stat:!0,forced:!pa||ha,sham:!pa},{getOwnPropertyDescriptor:function(e,t){return da(fa(e),t)}});var va=we,ya=Ne,ma=h,ga=function(e,t,n){var r=va(t);r in e?ya.f(e,r,ma(0,n)):e[r]=n},ba=on,ka=_,wa=a,xa=ga;function _a(e,t,n,r,i,a,s){try{var o=e[a](s),u=o.value}catch(e){return void n(e)}o.done?t(u):Promise.resolve(u).then(r,i)}function Sa(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var a=e.apply(t,n);function s(e){_a(a,r,i,s,o,"next",e)}function o(e){_a(a,r,i,s,o,"throw",e)}s(void 0)}))}}function Ea(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Ta(e,t,n){return t&&Ea(e.prototype,t),n&&Ea(e,n),e}function Ra(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Ia(e,t){return(Ia=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Oa(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Ia(e,t)}function Ca(e){return(Ca="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Pa(e,t){return!t||"object"!==Ca(t)&&"function"!=typeof t?Ra(e):t}function Aa(e){return(Aa=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function ja(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ma(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}In({target:"Object",stat:!0,sham:!o},{getOwnPropertyDescriptors:function(e){for(var t,n,r=ka(e),i=wa.f,a=ba(r),s={},o=0;a.length>o;)void 0!==(n=i(r,t=a[o++]))&&xa(s,t,n);return s}});var La={};La[pe("toStringTag")]="z";var Na="[object z]"===String(La),Ua=Na,Da=y,Fa=pe("toStringTag"),Ba="Arguments"==Da(function(){return arguments}()),qa=Ua?Da:function(e){var t,n,r;return void 0===e?"Undefined":null===e?"Null":"string"==typeof(n=function(e,t){try{return e[t]}catch(e){}}(t=Object(e),Fa))?n:Ba?Da(t):"Object"==(r=Da(t))&&"function"==typeof t.callee?"Arguments":r},Wa=qa,za=Na?{}.toString:function(){return"[object "+Wa(this)+"]"},Ga=Na,Ja=$e.exports,Va=za;Ga||Ja(Object.prototype,"toString",Va,{unsafe:!0});var $a=i.Promise,Ka=$e.exports,Ha=function(e,t,n){for(var r in t)Ka(e,r,t[r],n);return e},Ya=S,Qa=De,Xa=function(e){if(!Ya(e)&&null!==e)throw TypeError("Can't set "+String(e)+" as a prototype");return e},Za=Object.setPrototypeOf||("__proto__"in{}?function(){var e,t=!1,n={};try{(e=Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set).call(n,[]),t=n instanceof Array}catch(e){}return function(n,r){return Qa(n),Xa(r),t?e.call(n,r):n.__proto__=r,n}}():void 0),es=R,ts=Ne,ns=o,rs=pe("species"),is=function(e){var t=es(e),n=ts.f;ns&&t&&!t[rs]&&n(t,rs,{configurable:!0,get:function(){return this}})},as=function(e,t,n){if(!(e instanceof t))throw TypeError("Incorrect "+(n?n+" ":"")+"invocation");return e},ss={},os=ss,us=pe("iterator"),cs=Array.prototype,ls=function(e){return void 0!==e&&(os.Array===e||cs[us]===e)},fs=qa,ds=ss,ps=pe("iterator"),hs=function(e){if(null!=e)return e[ps]||e["@@iterator"]||ds[fs(e)]},vs=De,ys=hs,ms=function(e,t){var n=arguments.length<2?ys(e):t;if("function"!=typeof n)throw TypeError(String(e)+" is not iterable");return vs(n.call(e))},gs=De,bs=function(e,t,n){var r,i;gs(e);try{if(void 0===(r=e.return)){if("throw"===t)throw n;return n}r=r.call(e)}catch(e){i=!0,r=e}if("throw"===t)throw n;if(i)throw r;return gs(r),n},ks=De,ws=ls,xs=Ut,_s=Nr,Ss=ms,Es=hs,Ts=bs,Rs=function(e,t){this.stopped=e,this.result=t},Is=function(e,t,n){var r,i,a,s,o,u,c,l=n&&n.that,f=!(!n||!n.AS_ENTRIES),d=!(!n||!n.IS_ITERATOR),p=!(!n||!n.INTERRUPTED),h=_s(t,l,1+f+p),v=function(e){return r&&Ts(r,"normal",e),new Rs(!0,e)},y=function(e){return f?(ks(e),p?h(e[0],e[1],v):h(e[0],e[1])):p?h(e,v):h(e)};if(d)r=e;else{if("function"!=typeof(i=Es(e)))throw TypeError("Target is not iterable");if(ws(i)){for(a=0,s=xs(e.length);s>a;a++)if((o=y(e[a]))&&o instanceof Rs)return o;return new Rs(!1)}r=Ss(e,i)}for(u=r.next;!(c=u.call(r)).done;){try{o=y(c.value)}catch(e){Ts(r,"throw",e)}if("object"==typeof o&&o&&o instanceof Rs)return o}return new Rs(!1)},Os=pe("iterator"),Cs=!1;try{var Ps=0,As={next:function(){return{done:!!Ps++}},return:function(){Cs=!0}};As[Os]=function(){return this},Array.from(As,(function(){throw 2}))}catch(e){}var js,Ms,Ls,Ns,Us=function(e,t){if(!t&&!Cs)return!1;var n=!1;try{var r={};r[Os]=function(){return{next:function(){return{done:n=!0}}}},e(r)}catch(e){}return n},Ds=De,Fs=On,Bs=pe("species"),qs=function(e,t){var n,r=Ds(e).constructor;return void 0===r||null==(n=Ds(r)[Bs])?t:Fs(n)},Ws=/(?:ipad|iphone|ipod).*applewebkit/i.test(I),zs="process"==y(i.process),Gs=i,Js=s,Vs=Nr,$s=Un,Ks=Ee,Hs=Ws,Ys=zs,Qs=Gs.setImmediate,Xs=Gs.clearImmediate,Zs=Gs.process,eo=Gs.MessageChannel,to=Gs.Dispatch,no=0,ro={},io="onreadystatechange";try{js=Gs.location}catch(e){}var ao=function(e){if(ro.hasOwnProperty(e)){var t=ro[e];delete ro[e],t()}},so=function(e){return function(){ao(e)}},oo=function(e){ao(e.data)},uo=function(e){Gs.postMessage(String(e),js.protocol+"//"+js.host)};Qs&&Xs||(Qs=function(e){for(var t=[],n=arguments.length,r=1;n>r;)t.push(arguments[r++]);return ro[++no]=function(){("function"==typeof e?e:Function(e)).apply(void 0,t)},Ms(no),no},Xs=function(e){delete ro[e]},Ys?Ms=function(e){Zs.nextTick(so(e))}:to&&to.now?Ms=function(e){to.now(so(e))}:eo&&!Hs?(Ns=(Ls=new eo).port2,Ls.port1.onmessage=oo,Ms=Vs(Ns.postMessage,Ns,1)):Gs.addEventListener&&"function"==typeof postMessage&&!Gs.importScripts&&js&&"file:"!==js.protocol&&!Js(uo)?(Ms=uo,Gs.addEventListener("message",oo,!1)):Ms=io in Ks("script")?function(e){$s.appendChild(Ks("script")).onreadystatechange=function(){$s.removeChild(this),ao(e)}}:function(e){setTimeout(so(e),0)});var co,lo,fo,po,ho,vo,yo,mo,go={set:Qs,clear:Xs},bo=i,ko=/ipad|iphone|ipod/i.test(I)&&void 0!==bo.Pebble,wo=/web0s(?!.*chrome)/i.test(I),xo=i,_o=a.f,So=go.set,Eo=Ws,To=ko,Ro=wo,Io=zs,Oo=xo.MutationObserver||xo.WebKitMutationObserver,Co=xo.document,Po=xo.process,Ao=xo.Promise,jo=_o(xo,"queueMicrotask"),Mo=jo&&jo.value;Mo||(co=function(){var e,t;for(Io&&(e=Po.domain)&&e.exit();lo;){t=lo.fn,lo=lo.next;try{t()}catch(e){throw lo?po():fo=void 0,e}}fo=void 0,e&&e.enter()},Eo||Io||Ro||!Oo||!Co?!To&&Ao&&Ao.resolve?((yo=Ao.resolve(void 0)).constructor=Ao,mo=yo.then,po=function(){mo.call(yo,co)}):po=Io?function(){Po.nextTick(co)}:function(){So.call(xo,co)}:(ho=!0,vo=Co.createTextNode(""),new Oo(co).observe(vo,{characterData:!0}),po=function(){vo.data=ho=!ho}));var Lo=Mo||function(e){var t={fn:e,next:void 0};fo&&(fo.next=t),lo||(lo=t,po()),fo=t},No={},Uo=On,Do=function(e){var t,n;this.promise=new e((function(e,r){if(void 0!==t||void 0!==n)throw TypeError("Bad Promise constructor");t=e,n=r})),this.resolve=Uo(t),this.reject=Uo(n)};No.f=function(e){return new Do(e)};var Fo,Bo,qo,Wo,zo=De,Go=S,Jo=No,Vo=i,$o="object"==typeof window,Ko=In,Ho=i,Yo=R,Qo=$a,Xo=$e.exports,Zo=Ha,eu=Za,tu=Mr,nu=is,ru=S,iu=On,au=as,su=Ze,ou=Is,uu=Us,cu=qs,lu=go.set,fu=Lo,du=function(e,t){if(zo(e),Go(t)&&t.constructor===e)return t;var n=Jo.f(e);return(0,n.resolve)(t),n.promise},pu=function(e,t){var n=Vo.console;n&&n.error&&(1===arguments.length?n.error(e):n.error(e,t))},hu=No,vu=function(e){try{return{error:!1,value:e()}}catch(e){return{error:!0,value:e}}},yu=xt,mu=kn,gu=$o,bu=zs,ku=L,wu=pe("species"),xu="Promise",_u=yu.get,Su=yu.set,Eu=yu.getterFor(xu),Tu=Qo&&Qo.prototype,Ru=Qo,Iu=Tu,Ou=Ho.TypeError,Cu=Ho.document,Pu=Ho.process,Au=hu.f,ju=Au,Mu=!!(Cu&&Cu.createEvent&&Ho.dispatchEvent),Lu="function"==typeof PromiseRejectionEvent,Nu="unhandledrejection",Uu=!1,Du=mu(xu,(function(){var e=su(Ru),t=e!==String(Ru);if(!t&&66===ku)return!0;if(ku>=51&&/native code/.test(e))return!1;var n=new Ru((function(e){e(1)})),r=function(e){e((function(){}),(function(){}))};return(n.constructor={})[wu]=r,!(Uu=n.then((function(){}))instanceof r)||!t&&gu&&!Lu})),Fu=Du||!uu((function(e){Ru.all(e).catch((function(){}))})),Bu=function(e){var t;return!(!ru(e)||"function"!=typeof(t=e.then))&&t},qu=function(e,t){if(!e.notified){e.notified=!0;var n=e.reactions;fu((function(){for(var r=e.value,i=1==e.state,a=0;n.length>a;){var s,o,u,c=n[a++],l=i?c.ok:c.fail,f=c.resolve,d=c.reject,p=c.domain;try{l?(i||(2===e.rejection&&Ju(e),e.rejection=1),!0===l?s=r:(p&&p.enter(),s=l(r),p&&(p.exit(),u=!0)),s===c.promise?d(Ou("Promise-chain cycle")):(o=Bu(s))?o.call(s,f,d):f(s)):d(r)}catch(e){p&&!u&&p.exit(),d(e)}}e.reactions=[],e.notified=!1,t&&!e.rejection&&zu(e)}))}},Wu=function(e,t,n){var r,i;Mu?((r=Cu.createEvent("Event")).promise=t,r.reason=n,r.initEvent(e,!1,!0),Ho.dispatchEvent(r)):r={promise:t,reason:n},!Lu&&(i=Ho["on"+e])?i(r):e===Nu&&pu("Unhandled promise rejection",n)},zu=function(e){lu.call(Ho,(function(){var t,n=e.facade,r=e.value;if(Gu(e)&&(t=vu((function(){bu?Pu.emit("unhandledRejection",r,n):Wu(Nu,n,r)})),e.rejection=bu||Gu(e)?2:1,t.error))throw t.value}))},Gu=function(e){return 1!==e.rejection&&!e.parent},Ju=function(e){lu.call(Ho,(function(){var t=e.facade;bu?Pu.emit("rejectionHandled",t):Wu("rejectionhandled",t,e.value)}))},Vu=function(e,t,n){return function(r){e(t,r,n)}},$u=function(e,t,n){e.done||(e.done=!0,n&&(e=n),e.value=t,e.state=2,qu(e,!0))},Ku=function(e,t,n){if(!e.done){e.done=!0,n&&(e=n);try{if(e.facade===t)throw Ou("Promise can't be resolved itself");var r=Bu(t);r?fu((function(){var n={done:!1};try{r.call(t,Vu(Ku,n,e),Vu($u,n,e))}catch(t){$u(n,t,e)}})):(e.value=t,e.state=1,qu(e,!1))}catch(t){$u({done:!1},t,e)}}};if(Du&&(Iu=(Ru=function(e){au(this,Ru,xu),iu(e),Fo.call(this);var t=_u(this);try{e(Vu(Ku,t),Vu($u,t))}catch(e){$u(t,e)}}).prototype,(Fo=function(e){Su(this,{type:xu,done:!1,notified:!1,parent:!1,reactions:[],rejection:!1,state:0,value:void 0})}).prototype=Zo(Iu,{then:function(e,t){var n=Eu(this),r=Au(cu(this,Ru));return r.ok="function"!=typeof e||e,r.fail="function"==typeof t&&t,r.domain=bu?Pu.domain:void 0,n.parent=!0,n.reactions.push(r),0!=n.state&&qu(n,!1),r.promise},catch:function(e){return this.then(void 0,e)}}),Bo=function(){var e=new Fo,t=_u(e);this.promise=e,this.resolve=Vu(Ku,t),this.reject=Vu($u,t)},hu.f=Au=function(e){return e===Ru||e===qo?new Bo(e):ju(e)},"function"==typeof Qo&&Tu!==Object.prototype)){Wo=Tu.then,Uu||(Xo(Tu,"then",(function(e,t){var n=this;return new Ru((function(e,t){Wo.call(n,e,t)})).then(e,t)}),{unsafe:!0}),Xo(Tu,"catch",Iu.catch,{unsafe:!0}));try{delete Tu.constructor}catch(e){}eu&&eu(Tu,Iu)}Ko({global:!0,wrap:!0,forced:Du},{Promise:Ru}),tu(Ru,xu,!1),nu(xu),qo=Yo(xu),Ko({target:xu,stat:!0,forced:Du},{reject:function(e){var t=Au(this);return t.reject.call(void 0,e),t.promise}}),Ko({target:xu,stat:!0,forced:Du},{resolve:function(e){return du(this,e)}}),Ko({target:xu,stat:!0,forced:Fu},{all:function(e){var t=this,n=Au(t),r=n.resolve,i=n.reject,a=vu((function(){var n=iu(t.resolve),a=[],s=0,o=1;ou(e,(function(e){var u=s++,c=!1;a.push(void 0),o++,n.call(t,e).then((function(e){c||(c=!0,a[u]=e,--o||r(a))}),i)})),--o||r(a)}));return a.error&&i(a.value),n.promise},race:function(e){var t=this,n=Au(t),r=n.reject,i=vu((function(){var i=iu(t.resolve);ou(e,(function(e){i.call(t,e).then(n.resolve,r)}))}));return i.error&&r(i.value),n.promise}});var Hu={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0},Yu=Ee("span").classList,Qu=Yu&&Yu.constructor&&Yu.constructor.prototype,Xu=Qu===Object.prototype?void 0:Qu,Zu=s,ec=function(e,t){var n=[][e];return!!n&&Zu((function(){n.call(null,t||function(){throw 1},1)}))},tc=Hr.forEach,nc=i,rc=Hu,ic=Xu,ac=ec("forEach")?[].forEach:function(e){return tc(this,e,arguments.length>1?arguments[1]:void 0)},sc=Ve,oc=function(e){if(e&&e.forEach!==ac)try{sc(e,"forEach",ac)}catch(t){e.forEach=ac}};for(var uc in rc)oc(nc[uc]&&nc[uc].prototype);oc(ic);var cc=S,lc=Za,fc=function(e,t,n){var r,i;return lc&&"function"==typeof(r=t.constructor)&&r!==n&&cc(i=r.prototype)&&i!==n.prototype&&lc(e,i),e},dc=k,pc=gr,hc="[\t\n\v\f\r \u2028\u2029\ufeff]",vc=RegExp("^"+hc+hc+"*"),yc=RegExp(hc+hc+"*$"),mc=function(e){return function(t){var n=pc(dc(t));return 1&e&&(n=n.replace(vc,"")),2&e&&(n=n.replace(yc,"")),n}},gc={start:mc(1),end:mc(2),trim:mc(3)},bc=o,kc=i,wc=kn,xc=$e.exports,_c=ee,Sc=y,Ec=fc,Tc=q,Rc=ge,Ic=s,Oc=Hn,Cc=Pt.f,Pc=a.f,Ac=Ne.f,jc=gc.trim,Mc="Number",Lc=kc.Number,Nc=Lc.prototype,Uc=Sc(Oc(Nc))==Mc,Dc=function(e){if(Tc(e))throw TypeError("Cannot convert a Symbol value to a number");var t,n,r,i,a,s,o,u,c=Rc(e,"number");if("string"==typeof c&&c.length>2)if(43===(t=(c=jc(c)).charCodeAt(0))||45===t){if(88===(n=c.charCodeAt(2))||120===n)return NaN}else if(48===t){switch(c.charCodeAt(1)){case 66:case 98:r=2,i=49;break;case 79:case 111:r=8,i=55;break;default:return+c}for(s=(a=c.slice(2)).length,o=0;o<s;o++)if((u=a.charCodeAt(o))<48||u>i)return NaN;return parseInt(a,r)}return+c};if(wc(Mc,!Lc(" 0o1")||!Lc("0b1")||Lc("+0x1"))){for(var Fc,Bc=function(e){var t=arguments.length<1?0:e,n=this;return n instanceof Bc&&(Uc?Ic((function(){Nc.valueOf.call(n)})):Sc(n)!=Mc)?Ec(new Lc(Dc(t)),n,Bc):Dc(t)},qc=bc?Cc(Lc):"MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger,fromString,range".split(","),Wc=0;qc.length>Wc;Wc++)_c(Lc,Fc=qc[Wc])&&!_c(Bc,Fc)&&Ac(Bc,Fc,Pc(Lc,Fc));Bc.prototype=Nc,Nc.constructor=Bc,xc(kc,Mc,Bc)}var zc,Gc=Object.prototype,Jc=Gc.hasOwnProperty,Vc="function"==typeof Symbol?Symbol:{},$c=Vc.iterator||"@@iterator",Kc=Vc.asyncIterator||"@@asyncIterator",Hc=Vc.toStringTag||"@@toStringTag";function Yc(e,t,n,r){var i=t&&t.prototype instanceof rl?t:rl,a=Object.create(i.prototype),s=new yl(r||[]);return a._invoke=function(e,t,n){var r=Xc;return function(i,a){if(r===el)throw new Error("Generator is already running");if(r===tl){if("throw"===i)throw a;return gl()}for(n.method=i,n.arg=a;;){var s=n.delegate;if(s){var o=pl(s,n);if(o){if(o===nl)continue;return o}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===Xc)throw r=tl,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=el;var u=Qc(e,t,n);if("normal"===u.type){if(r=n.done?tl:Zc,u.arg===nl)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=tl,n.method="throw",n.arg=u.arg)}}}(e,n,s),a}function Qc(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}var Xc="suspendedStart",Zc="suspendedYield",el="executing",tl="completed",nl={};function rl(){}function il(){}function al(){}var sl={};sl[$c]=function(){return this};var ol=Object.getPrototypeOf,ul=ol&&ol(ol(ml([])));ul&&ul!==Gc&&Jc.call(ul,$c)&&(sl=ul);var cl=al.prototype=rl.prototype=Object.create(sl);function ll(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function fl(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===il||"GeneratorFunction"===(t.displayName||t.name))}function dl(e,t){function n(r,i,a,s){var o=Qc(e[r],e,i);if("throw"!==o.type){var u=o.arg,c=u.value;return c&&"object"===Ca(c)&&Jc.call(c,"__await")?t.resolve(c.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(c).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(o.arg)}var r;this._invoke=function(e,i){function a(){return new t((function(t,r){n(e,i,t,r)}))}return r=r?r.then(a,a):a()}}function pl(e,t){var n=e.iterator[t.method];if(n===zc){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=zc,pl(e,t),"throw"===t.method))return nl;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return nl}var r=Qc(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,nl;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=zc),t.delegate=null,nl):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,nl)}function hl(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function vl(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function yl(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(hl,this),this.reset(!0)}function ml(e){if(e){var t=e[$c];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,r=function t(){for(;++n<e.length;)if(Jc.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=zc,t.done=!0,t};return r.next=r}}return{next:gl}}function gl(){return{value:zc,done:!0}}il.prototype=cl.constructor=al,al.constructor=il,al[Hc]=il.displayName="GeneratorFunction",ll(dl.prototype),dl.prototype[Kc]=function(){return this},ll(cl),cl[Hc]="Generator",cl[$c]=function(){return this},cl.toString=function(){return"[object Generator]"},yl.prototype={constructor:yl,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=zc,this.done=!1,this.delegate=null,this.method="next",this.arg=zc,this.tryEntries.forEach(vl),!e)for(var t in this)"t"===t.charAt(0)&&Jc.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=zc)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=zc),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=Jc.call(i,"catchLoc"),o=Jc.call(i,"finallyLoc");if(s&&o){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!o)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&Jc.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var i=r;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,nl):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),nl},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),vl(n),nl}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;vl(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:ml(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=zc),nl}};var bl={wrap:Yc,isGeneratorFunction:fl,AsyncIterator:dl,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,al):(e.__proto__=al,Hc in e||(e[Hc]="GeneratorFunction")),e.prototype=Object.create(cl),e},awrap:function(e){return{__await:e}},async:function(e,t,n,r,i){void 0===i&&(i=Promise);var a=new dl(Yc(e,t,n,r),i);return fl(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},keys:function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},values:ml},kl=Object.freeze({__proto__:null,default:bl});function wl(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function xl(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}var _l=In,Sl=s,El=yr,Tl=S,Rl=Q,Il=Ut,Ol=ga,Cl=qr,Pl=oa,Al=L,jl=pe("isConcatSpreadable"),Ml=9007199254740991,Ll="Maximum allowed index exceeded",Nl=Al>=51||!Sl((function(){var e=[];return e[jl]=!1,e.concat()[0]!==e})),Ul=Pl("concat"),Dl=function(e){if(!Tl(e))return!1;var t=e[jl];return void 0!==t?!!t:El(e)};_l({target:"Array",proto:!0,forced:!Nl||!Ul},{concat:function(e){var t,n,r,i,a,s=Rl(this),o=Cl(s,0),u=0;for(t=-1,r=arguments.length;t<r;t++)if(Dl(a=-1===t?s:arguments[t])){if(u+(i=Il(a.length))>Ml)throw TypeError(Ll);for(n=0;n<i;n++,u++)n in a&&Ol(o,u,a[n])}else{if(u>=Ml)throw TypeError(Ll);Ol(o,u++,a)}return o.length=u,o}});var Fl=De,Bl=bs,ql=Nr,Wl=Q,zl=function(e,t,n,r){try{return r?t(Fl(n)[0],n[1]):t(n)}catch(t){Bl(e,"throw",t)}},Gl=ls,Jl=Ut,Vl=ga,$l=ms,Kl=hs,Hl=function(e){var t,n,r,i,a,s,o=Wl(e),u="function"==typeof this?this:Array,c=arguments.length,l=c>1?arguments[1]:void 0,f=void 0!==l,d=Kl(o),p=0;if(f&&(l=ql(l,c>2?arguments[2]:void 0,2)),null==d||u==Array&&Gl(d))for(n=new u(t=Jl(o.length));t>p;p++)s=f?l(o[p],p):o[p],Vl(n,p,s);else for(a=(i=$l(o,d)).next,n=new u;!(r=a.call(i)).done;p++)s=f?zl(i,l,[r.value,p],!0):r.value,Vl(n,p,s);return n.length=p,n},Yl=Hl;In({target:"Array",stat:!0,forced:!Us((function(e){Array.from(e)}))},{from:Yl});var Ql,Xl,Zl,ef=Mt,tf=gr,nf=k,rf=function(e){return function(t,n){var r,i,a=tf(nf(t)),s=ef(n),o=a.length;return s<0||s>=o?e?"":void 0:(r=a.charCodeAt(s))<55296||r>56319||s+1===o||(i=a.charCodeAt(s+1))<56320||i>57343?e?a.charAt(s):r:e?a.slice(s,s+2):i-56320+(r-55296<<10)+65536}},af={codeAt:rf(!1),charAt:rf(!0)},sf=!s((function(){function e(){}return e.prototype.constructor=null,Object.getPrototypeOf(new e)!==e.prototype})),of=ee,uf=Q,cf=sf,lf=st("IE_PROTO"),ff=Object.prototype,df=cf?Object.getPrototypeOf:function(e){return e=uf(e),of(e,lf)?e[lf]:"function"==typeof e.constructor&&e instanceof e.constructor?e.constructor.prototype:e instanceof Object?ff:null},pf=s,hf=df,vf=Ve,yf=pe("iterator"),mf=!1;[].keys&&("next"in(Zl=[].keys())?(Xl=hf(hf(Zl)))!==Object.prototype&&(Ql=Xl):mf=!0),(null==Ql||pf((function(){var e={};return Ql[yf].call(e)!==e})))&&(Ql={}),"function"!=typeof Ql[yf]&&vf(Ql,yf,(function(){return this}));var gf={IteratorPrototype:Ql,BUGGY_SAFARI_ITERATORS:mf},bf=gf.IteratorPrototype,kf=Hn,wf=h,xf=Mr,_f=ss,Sf=function(){return this},Ef=function(e,t,n){var r=t+" Iterator";return e.prototype=kf(bf,{next:wf(1,n)}),xf(e,r,!1),_f[r]=Sf,e},Tf=In,Rf=Ef,If=df,Of=Za,Cf=Mr,Pf=Ve,Af=$e.exports,jf=ss,Mf=gf.IteratorPrototype,Lf=gf.BUGGY_SAFARI_ITERATORS,Nf=pe("iterator"),Uf="keys",Df="values",Ff="entries",Bf=function(){return this},qf=function(e,t,n,r,i,a,s){Rf(n,t,r);var o,u,c,l=function(e){if(e===i&&v)return v;if(!Lf&&e in p)return p[e];switch(e){case Uf:case Df:case Ff:return function(){return new n(this,e)}}return function(){return new n(this)}},f=t+" Iterator",d=!1,p=e.prototype,h=p[Nf]||p["@@iterator"]||i&&p[i],v=!Lf&&h||l(i),y="Array"==t&&p.entries||h;if(y&&(o=If(y.call(new e)))!==Object.prototype&&o.next&&(If(o)!==Mf&&(Of?Of(o,Mf):"function"!=typeof o[Nf]&&Pf(o,Nf,Bf)),Cf(o,f,!0)),i==Df&&h&&h.name!==Df&&(d=!0,v=function(){return h.call(this)}),p[Nf]!==v&&Pf(p,Nf,v),jf[t]=v,i)if(u={values:l(Df),keys:a?v:l(Uf),entries:l(Ff)},s)for(c in u)(Lf||d||!(c in p))&&Af(p,c,u[c]);else Tf({target:t,proto:!0,forced:Lf||d},u);return u},Wf=af.charAt,zf=gr,Gf=xt,Jf=qf,Vf="String Iterator",$f=Gf.set,Kf=Gf.getterFor(Vf);Jf(String,"String",(function(e){$f(this,{type:Vf,string:zf(e),index:0})}),(function(){var e,t=Kf(this),n=t.string,r=t.index;return r>=n.length?{value:void 0,done:!0}:(e=Wf(n,r),t.index+=e.length,{value:e,done:!1})}));var Hf,Yf,Qf,Xf={exports:{}};function Zf(e,t){return["".concat((new Date).toISOString()," Conversations ").concat(e,":")].concat(Array.from(t))}Yf=t,Qf=function(){var e=function(){},t="undefined",n=("undefined"==typeof window?"undefined":Ca(window))!==t&&Ca(window.navigator)!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=["trace","debug","info","warn","error"];function i(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function a(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function s(r){return"debug"===r&&(r="log"),("undefined"==typeof console?"undefined":Ca(console))!==t&&("trace"===r&&n?a:void 0!==console[r]?i(console,r):void 0!==console.log?i(console,"log"):e)}function o(t,n){for(var i=0;i<r.length;i++){var a=r[i];this[a]=i<t?e:this.methodFactory(a,t,n)}this.log=this.debug}function u(e,n,r){return function(){("undefined"==typeof console?"undefined":Ca(console))!==t&&(o.call(this,n,r),this[e].apply(this,arguments))}}function c(e,t,n){return s(e)||u.apply(this,arguments)}function l(e,n,i){var a,s=this,u="loglevel";function l(){var e;if(("undefined"==typeof window?"undefined":Ca(window))!==t&&u){try{e=window.localStorage[u]}catch(e){}if(Ca(e)===t)try{var n=window.document.cookie,r=n.indexOf(encodeURIComponent(u)+"=");-1!==r&&(e=/^([^;]+)/.exec(n.slice(r))[1])}catch(e){}return void 0===s.levels[e]&&(e=void 0),e}}"string"==typeof e?u+=":"+e:"symbol"===Ca(e)&&(u=void 0),s.name=e,s.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},s.methodFactory=i||c,s.getLevel=function(){return a},s.setLevel=function(n,i){if("string"==typeof n&&void 0!==s.levels[n.toUpperCase()]&&(n=s.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=s.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(a=n,!1!==i&&function(e){var n=(r[e]||"silent").toUpperCase();if(("undefined"==typeof window?"undefined":Ca(window))!==t&&u){try{return void(window.localStorage[u]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(u)+"="+n+";"}catch(e){}}}(n),o.call(s,n,e),("undefined"==typeof console?"undefined":Ca(console))===t&&n<s.levels.SILENT)return"No console available for logging"},s.setDefaultLevel=function(e){l()||s.setLevel(e,!1)},s.enableAll=function(e){s.setLevel(s.levels.TRACE,e)},s.disableAll=function(e){s.setLevel(s.levels.SILENT,e)};var f=l();null==f&&(f=null==n?"WARN":n),s.setLevel(f,!1)}var f=new l,d={};f.getLogger=function(e){if("symbol"!==Ca(e)&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=d[e];return t||(t=d[e]=new l(e,f.getLevel(),f.methodFactory)),t};var p=("undefined"==typeof window?"undefined":Ca(window))!==t?window.log:void 0;return f.noConflict=function(){return("undefined"==typeof window?"undefined":Ca(window))!==t&&window.log===f&&(window.log=p),f},f.getLoggers=function(){return d},f.default=f,f},(Hf=Xf).exports?Hf.exports=Qf():Yf.log=Qf();var ed,td,nd=Xf.exports.getLogger("twilio-conversations"),rd=function(){function e(t){Ma(this,e),ja(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return Ta(e,[{key:"setLevel",value:function(e){nd.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.trace.apply(null,Zf(this.prefix+"T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.debug.apply(null,Zf(this.prefix+"D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.info.apply(null,Zf(this.prefix+"I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.warn.apply(null,Zf(this.prefix+"W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.error.apply(null,Zf(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){nd.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.trace.apply(null,Zf("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.debug.apply(null,Zf("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.info.apply(null,Zf("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.warn.apply(null,Zf("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.error.apply(null,Zf("E",t))}}]),e}(),id={};Object.defineProperty(id,"__esModule",{value:!0});var ad=["weeks","years","months","days","hours","minutes","seconds"],sd=id.pattern=new RegExp("P(?:(\\d+(?:[\\.,]\\d+)?W)|(\\d+(?:[\\.,]\\d+)?Y)?(\\d+(?:[\\.,]\\d+)?M)?(\\d+(?:[\\.,]\\d+)?D)?(?:T(\\d+(?:[\\.,]\\d+)?H)?(\\d+(?:[\\.,]\\d+)?M)?(\\d+(?:[\\.,]\\d+)?S)?)?)"),od=td=id.parse=function(e){return e.match(sd).slice(1).reduce((function(e,t,n){return e[ad[n]]=parseFloat(t)||0,e}),{})},ud=id.end=function(e,t){var n=t?t.getTime():Date.now(),r=new Date(n);return r.setFullYear(r.getFullYear()+e.years),r.setMonth(r.getMonth()+e.months),r.setDate(r.getDate()+e.days),r.setHours(r.getHours()+e.hours),r.setMinutes(r.getMinutes()+e.minutes),r.setMilliseconds(r.getMilliseconds()+1e3*e.seconds),r.setDate(r.getDate()+7*e.weeks),r},cd=ed=id.toSeconds=function(e,t){var n=t?t.getTime():Date.now(),r=new Date(n);return(ud(e,r).getTime()-r.getTime())/1e3};function ld(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function fd(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ld(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ld(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}id.default={end:ud,toSeconds:cd,pattern:sd,parse:od};var dd="PT5S",pd="PT5S",hd=function e(){var t,n,r,i,a,s,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},u=arguments.length>1?arguments[1]:void 0,c=arguments.length>2?arguments[2]:void 0;Ma(this,e),ja(this,"typingIndicatorTimeoutDefault",5e3);var l=o.Chat||o.IPMessaging||o||{};this.productId=l.productId,this.links={myConversations:u.links.my_conversations,conversations:u.links.conversations,users:u.links.users,currentUser:u.links.current_user,typing:u.links.typing,mediaService:u.links.media_service,mediaSetService:u.links.media_set_service,messagesReceipts:u.links.messages_receipts},this.limits={mediaAttachmentsCountLimit:u.options.media_attachments_count_limit,mediaAttachmentSizeLimitInMb:u.options.media_attachment_size_limit_in_mb,mediaAttachmentsTotalSizeLimitInMb:u.options.media_attachments_total_size_limit_in_mb,emailHistoriesAllowedMimeTypes:u.options.email_histories_allowed_mime_types,emailBodiesAllowedMimeTypes:u.options.email_bodies_allowed_mime_types},this.typingIndicatorTimeoutOverride=l.typingIndicatorTimeoutOverride,this.backoffConfiguration=fd({min:1e3,max:4e3,maxAttemptsCount:3},l.backoffConfigOverride),this.retryWhenThrottled=void 0===l.retryWhenThrottledOverride||l.retryWhenThrottledOverride,this.userInfosToSubscribe=null!==(t=null!==(n=l.userInfosToSubscribeOverride)&&void 0!==n?n:u.options.user_infos_to_subscribe)&&void 0!==t?t:100,this.reachabilityEnabled=u.options.reachability_enabled,this.userIdentity=u.identity,this.userInfo=u.sync_objects.my_user_info,this.myConversations=u.sync_objects.my_conversations;var f=null!==(r=null!==(i=l.httpCacheIntervalOverride)&&void 0!==i?i:u.options.http_cache_interval)&&void 0!==r?r:dd;try{this.httpCacheInterval=ed(td(f))}catch(e){c.error("Failed to parse http cache interval ".concat(f,", using default value ").concat(dd)),this.httpCacheInterval=ed(td(dd))}var d=null!==(a=null!==(s=l.consumptionReportIntervalOverride)&&void 0!==s?s:u.options.consumption_report_interval)&&void 0!==a?a:pd;try{this.consumptionReportInterval=ed(td(d))}catch(e){c.error("Failed to parse consumption report interval ".concat(d,", using default value ").concat(pd)),this.consumptionReportInterval=ed(td(pd))}},vd=Hr.map;In({target:"Array",proto:!0,forced:!oa("map")},{map:function(e){return vd(this,e,arguments.length>1?arguments[1]:void 0)}});var yd=Hn,md=Ne,gd=pe("unscopables"),bd=Array.prototype;null==bd[gd]&&md.f(bd,gd,{configurable:!0,value:yd(null)});var kd=function(e){bd[gd][e]=!0},wd=_,xd=kd,_d=ss,Sd=xt,Ed=qf,Td="Array Iterator",Rd=Sd.set,Id=Sd.getterFor(Td),Od=Ed(Array,"Array",(function(e,t){Rd(this,{type:Td,target:wd(e),index:0,kind:t})}),(function(){var e=Id(this),t=e.target,n=e.kind,r=e.index++;return!t||r>=t.length?(e.target=void 0,{value:void 0,done:!0}):"keys"==n?{value:r,done:!1}:"values"==n?{value:t[r],done:!1}:{value:[r,t[r]],done:!1}}),"values");_d.Arguments=_d.Array,xd("keys"),xd("values"),xd("entries");var Cd=i,Pd=Hu,Ad=Xu,jd=Od,Md=Ve,Ld=pe,Nd=Ld("iterator"),Ud=Ld("toStringTag"),Dd=jd.values,Fd=function(e,t){if(e){if(e[Nd]!==Dd)try{Md(e,Nd,Dd)}catch(t){e[Nd]=Dd}if(e[Ud]||Md(e,Ud,t),Pd[t])for(var n in jd)if(e[n]!==jd[n])try{Md(e,n,jd[n])}catch(t){e[n]=jd[n]}}};for(var Bd in Pd)Fd(Cd[Bd]&&Cd[Bd].prototype,Bd);Fd(Ad,"DOMTokenList");var qd=De,Wd=function(){var e=qd(this),t="";return e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.dotAll&&(t+="s"),e.unicode&&(t+="u"),e.sticky&&(t+="y"),t},zd={},Gd=s,Jd=i.RegExp;zd.UNSUPPORTED_Y=Gd((function(){var e=Jd("a","y");return e.lastIndex=2,null!=e.exec("abcd")})),zd.BROKEN_CARET=Gd((function(){var e=Jd("^r","gy");return e.lastIndex=2,null!=e.exec("str")}));var Vd,$d,Kd=s,Hd=i.RegExp,Yd=Kd((function(){var e=Hd(".","s");return!(e.dotAll&&e.exec("\n")&&"s"===e.flags)})),Qd=s,Xd=i.RegExp,Zd=Qd((function(){var e=Xd("(?<a>b)","g");return"b"!==e.exec("b").groups.a||"bc"!=="b".replace(e,"$<a>c")})),ep=gr,tp=Wd,np=zd,rp=z.exports,ip=Hn,ap=xt.get,sp=Yd,op=Zd,up=RegExp.prototype.exec,cp=rp("native-string-replace",String.prototype.replace),lp=up,fp=(Vd=/a/,$d=/b*/g,up.call(Vd,"a"),up.call($d,"a"),0!==Vd.lastIndex||0!==$d.lastIndex),dp=np.UNSUPPORTED_Y||np.BROKEN_CARET,pp=void 0!==/()??/.exec("")[1];(fp||pp||dp||sp||op)&&(lp=function(e){var t,n,r,i,a,s,o,u=this,c=ap(u),l=ep(e),f=c.raw;if(f)return f.lastIndex=u.lastIndex,t=lp.call(f,l),u.lastIndex=f.lastIndex,t;var d=c.groups,p=dp&&u.sticky,h=tp.call(u),v=u.source,y=0,m=l;if(p&&(-1===(h=h.replace("y","")).indexOf("g")&&(h+="g"),m=l.slice(u.lastIndex),u.lastIndex>0&&(!u.multiline||u.multiline&&"\n"!==l.charAt(u.lastIndex-1))&&(v="(?: "+v+")",m=" "+m,y++),n=new RegExp("^(?:"+v+")",h)),pp&&(n=new RegExp("^"+v+"$(?!\\s)",h)),fp&&(r=u.lastIndex),i=up.call(p?n:u,m),p?i?(i.input=i.input.slice(y),i[0]=i[0].slice(y),i.index=u.lastIndex,u.lastIndex+=i[0].length):u.lastIndex=0:fp&&i&&(u.lastIndex=u.global?i.index+i[0].length:r),pp&&i&&i.length>1&&cp.call(i[0],n,(function(){for(a=1;a<arguments.length-2;a++)void 0===arguments[a]&&(i[a]=void 0)})),i&&d)for(i.groups=s=ip(null),a=0;a<d.length;a++)s[(o=d[a])[0]]=i[o[1]];return i});var hp=lp;In({target:"RegExp",proto:!0,forced:/./.exec!==hp},{exec:hp});var vp=$e.exports,yp=hp,mp=s,gp=pe,bp=Ve,kp=gp("species"),wp=RegExp.prototype,xp=function(e,t,n,r){var i=gp(e),a=!mp((function(){var t={};return t[i]=function(){return 7},7!=""[e](t)})),s=a&&!mp((function(){var t=!1,n=/a/;return"split"===e&&((n={}).constructor={},n.constructor[kp]=function(){return n},n.flags="",n[i]=/./[i]),n.exec=function(){return t=!0,null},n[i](""),!t}));if(!a||!s||n){var o=/./[i],u=t(i,""[e],(function(e,t,n,r,i){var s=t.exec;return s===yp||s===wp.exec?a&&!i?{done:!0,value:o.call(t,n,r)}:{done:!0,value:e.call(n,t,r)}:{done:!1}}));vp(String.prototype,e,u[0]),vp(wp,i,u[1])}r&&bp(wp[i],"sham",!0)},_p=af.charAt,Sp=function(e,t,n){return t+(n?_p(e,t).length:1)},Ep=Q,Tp=Math.floor,Rp="".replace,Ip=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,Op=/\$([$&'`]|\d{1,2})/g,Cp=y,Pp=hp,Ap=function(e,t){var n=e.exec;if("function"==typeof n){var r=n.call(e,t);if("object"!=typeof r)throw TypeError("RegExp exec method returned something other than an Object or null");return r}if("RegExp"!==Cp(e))throw TypeError("RegExp#exec called on incompatible receiver");return Pp.call(e,t)},jp=xp,Mp=s,Lp=De,Np=Mt,Up=Ut,Dp=gr,Fp=k,Bp=Sp,qp=function(e,t,n,r,i,a){var s=n+e.length,o=r.length,u=Op;return void 0!==i&&(i=Ep(i),u=Ip),Rp.call(a,u,(function(a,u){var c;switch(u.charAt(0)){case"$":return"$";case"&":return e;case"`":return t.slice(0,n);case"'":return t.slice(s);case"<":c=i[u.slice(1,-1)];break;default:var l=+u;if(0===l)return a;if(l>o){var f=Tp(l/10);return 0===f?a:f<=o?void 0===r[f-1]?u.charAt(1):r[f-1]+u.charAt(1):a}c=r[l-1]}return void 0===c?"":c}))},Wp=Ap,zp=pe("replace"),Gp=Math.max,Jp=Math.min,Vp="$0"==="a".replace(/./,"$0"),$p=!!/./[zp]&&""===/./[zp]("a","$0");jp("replace",(function(e,t,n){var r=$p?"$":"$0";return[function(e,n){var r=Fp(this),i=null==e?void 0:e[zp];return void 0!==i?i.call(e,r,n):t.call(Dp(r),e,n)},function(e,i){var a=Lp(this),s=Dp(e);if("string"==typeof i&&-1===i.indexOf(r)&&-1===i.indexOf("$<")){var o=n(t,a,s,i);if(o.done)return o.value}var u="function"==typeof i;u||(i=Dp(i));var c=a.global;if(c){var l=a.unicode;a.lastIndex=0}for(var f=[];;){var d=Wp(a,s);if(null===d)break;if(f.push(d),!c)break;""===Dp(d[0])&&(a.lastIndex=Bp(s,Up(a.lastIndex),l))}for(var p,h="",v=0,y=0;y<f.length;y++){d=f[y];for(var m=Dp(d[0]),g=Gp(Jp(Np(d.index),s.length),0),b=[],k=1;k<d.length;k++)b.push(void 0===(p=d[k])?p:String(p));var w=d.groups;if(u){var x=[m].concat(b,g,s);void 0!==w&&x.push(w);var _=Dp(i.apply(void 0,x))}else _=qp(m,s,g,b,w,i);g>=v&&(h+=s.slice(v,g)+_,v=g+m.length)}return h+s.slice(v)}]}),!!Mp((function(){var e=/./;return e.exec=function(){var e=[];return e.groups={a:"7"},e},"7"!=="".replace(e,"$<a>")}))||!Vp||$p);var Kp=In,Hp=_,Yp=[].join,Qp=b!=Object,Xp=ec("join",",");Kp({target:"Array",proto:!0,forced:Qp||!Xp},{join:function(e){return Yp.call(Hp(this),void 0===e?",":e)}});var Zp={},eh={};function th(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function nh(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}Object.defineProperty(eh,"__esModule",{value:!0}),eh.Pointer=void 0;var rh=function(){function e(e){void 0===e&&(e=[""]),this.tokens=e}return e.fromJSON=function(t){var n=t.split("/").map(th);if(""!==n[0])throw new Error("Invalid JSON Pointer: "+t);return new e(n)},e.prototype.toString=function(){return this.tokens.map(nh).join("/")},e.prototype.evaluate=function(e){for(var t=null,n="",r=e,i=1,a=this.tokens.length;i<a;i++)r=((t=r)||{})[n=this.tokens[i]];return{parent:t,key:n,value:r}},e.prototype.get=function(e){return this.evaluate(e).value},e.prototype.set=function(e,t){for(var n=e,r=1,i=this.tokens.length-1,a=this.tokens[r];r<i;r++)n=(n||{})[a];n&&(n[this.tokens[this.tokens.length-1]]=t)},e.prototype.push=function(e){this.tokens.push(e)},e.prototype.add=function(t){return new e(this.tokens.concat(String(t)))},e}();eh.Pointer=rh;var ih={},ah={};!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.clone=e.objectType=e.hasOwnProperty=void 0,e.hasOwnProperty=Object.prototype.hasOwnProperty,e.objectType=function(e){return void 0===e?"undefined":null===e?"null":Array.isArray(e)?"array":Ca(e)},e.clone=function t(n){if(null==n||"object"!=Ca(n))return n;if(n.constructor==Array){for(var r=n.length,i=new Array(r),a=0;a<r;a++)i[a]=t(n[a]);return i}var s={};for(var o in n)e.hasOwnProperty.call(n,o)&&(s[o]=t(n[o]));return s}}(ah);var sh={};Object.defineProperty(sh,"__esModule",{value:!0}),sh.compare=void 0;var oh=ah;function uh(e,t){if(e===t)return!0;var n=oh.objectType(e),r=oh.objectType(t);return"array"==n&&"array"==r?function(e,t){var n=e.length;if(n!==t.length)return!1;for(var r=0;r<n;r++)if(!uh(e[r],t[r]))return!1;return!0}(e,t):"object"==n&&"object"==r&&function(e,t){var n=Object.keys(e),r=Object.keys(t),i=n.length;if(i!==r.length)return!1;for(var a=0;a<i;a++){var s=n[a];if(!oh.hasOwnProperty.call(t,s)||!uh(e[s],t[s]))return!1}return!0}(e,t)}sh.compare=uh;var ch,lh=t&&t.__extends||(ch=function(e,t){return(ch=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}ch(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(ih,"__esModule",{value:!0}),ih.apply=ih.InvalidOperationError=ih.test=ih.copy=ih.move=ih.replace=ih.remove=ih.add=ih.TestError=ih.MissingError=void 0;var fh=eh,dh=ah,ph=sh,hh=function(e){function t(t){var n=e.call(this,"Value required at path: "+t)||this;return n.path=t,n.name="MissingError",n}return lh(t,e),t}(Error);ih.MissingError=hh;var vh=function(e){function t(t,n){var r=e.call(this,"Test failed: "+t+" != "+n)||this;return r.actual=t,r.expected=n,r.name="TestError",r}return lh(t,e),t}(Error);function yh(e,t,n){if(Array.isArray(e))if("-"==t)e.push(n);else{var r=parseInt(t,10);e.splice(r,0,n)}else e[t]=n}function mh(e,t){if(Array.isArray(e)){var n=parseInt(t,10);e.splice(n,1)}else delete e[t]}function gh(e,t){var n=fh.Pointer.fromJSON(t.path).evaluate(e);return void 0===n.parent?new hh(t.path):(yh(n.parent,n.key,dh.clone(t.value)),null)}function bh(e,t){var n=fh.Pointer.fromJSON(t.path).evaluate(e);return void 0===n.value?new hh(t.path):(mh(n.parent,n.key),null)}function kh(e,t){var n=fh.Pointer.fromJSON(t.path).evaluate(e);if(null===n.parent)return new hh(t.path);if(Array.isArray(n.parent)){if(parseInt(n.key,10)>=n.parent.length)return new hh(t.path)}else if(void 0===n.value)return new hh(t.path);return n.parent[n.key]=t.value,null}function wh(e,t){var n=fh.Pointer.fromJSON(t.from).evaluate(e);if(void 0===n.value)return new hh(t.from);var r=fh.Pointer.fromJSON(t.path).evaluate(e);return void 0===r.parent?new hh(t.path):(mh(n.parent,n.key),yh(r.parent,r.key,n.value),null)}function xh(e,t){var n=fh.Pointer.fromJSON(t.from).evaluate(e);if(void 0===n.value)return new hh(t.from);var r=fh.Pointer.fromJSON(t.path).evaluate(e);return void 0===r.parent?new hh(t.path):(yh(r.parent,r.key,dh.clone(n.value)),null)}function _h(e,t){var n=fh.Pointer.fromJSON(t.path).evaluate(e);return ph.compare(n.value,t.value)?null:new vh(n.value,t.value)}ih.TestError=vh,ih.add=gh,ih.remove=bh,ih.replace=kh,ih.move=wh,ih.copy=xh,ih.test=_h;var Sh=function(e){function t(t){var n=e.call(this,"Invalid operation: "+t.op)||this;return n.operation=t,n.name="InvalidOperationError",n}return lh(t,e),t}(Error);ih.InvalidOperationError=Sh,ih.apply=function(e,t){switch(t.op){case"add":return gh(e,t);case"remove":return bh(e,t);case"replace":return kh(e,t);case"move":return wh(e,t);case"copy":return xh(e,t);case"test":return _h(e,t)}return new Sh(t)};var Eh={};Object.defineProperty(Eh,"__esModule",{value:!0}),Eh.diffAny=Eh.diffObjects=Eh.diffArrays=Eh.intersection=Eh.subtract=Eh.isDestructive=void 0;var Th=sh,Rh=ah;function Ih(e,t){var n={};for(var r in e)Rh.hasOwnProperty.call(e,r)&&void 0!==e[r]&&(n[r]=1);for(var i in t)Rh.hasOwnProperty.call(t,i)&&void 0!==t[i]&&delete n[i];return Object.keys(n)}function Oh(e){for(var t=e.length,n={},r=0;r<t;r++){var i=e[r];for(var a in i)Rh.hasOwnProperty.call(i,a)&&void 0!==i[a]&&(n[a]=(n[a]||0)+1)}for(var a in n)n[a]<t&&delete n[a];return Object.keys(n)}function Ch(e,t){return{operations:e.operations.concat(t),cost:e.cost+1}}function Ph(e,t,n,r){void 0===r&&(r=jh);var i={"0,0":{operations:[],cost:0}};var a=isNaN(e.length)||e.length<=0?0:e.length,s=isNaN(t.length)||t.length<=0?0:t.length;return function n(r,a){var s=r+","+a,o=i[s];if(void 0===o){if(r>0&&a>0&&Th.compare(e[r-1],t[a-1]))o=n(r-1,a-1);else{var u=[];if(r>0){var c=n(r-1,a),l={op:"remove",index:r-1};u.push(Ch(c,l))}if(a>0){var f=n(r,a-1),d={op:"add",index:r-1,value:t[a-1]};u.push(Ch(f,d))}if(r>0&&a>0){var p=n(r-1,a-1),h={op:"replace",index:r-1,original:e[r-1],value:t[a-1]};u.push(Ch(p,h))}o=u.sort((function(e,t){return e.cost-t.cost}))[0]}i[s]=o}return o}(a,s).operations.reduce((function(e,t){var i=e[0],s=e[1];if(function(e){return"add"===e.op}(t)){var o=t.index+1+s,u=o<a+s?String(o):"-",c={op:t.op,path:n.add(u).toString(),value:t.value};return[i.concat(c),s+1]}if(function(e){return"remove"===e.op}(t)){c={op:t.op,path:n.add(String(t.index+s)).toString()};return[i.concat(c),s-1]}var l=n.add(String(t.index+s)),f=r(t.original,t.value,l);return[i.concat.apply(i,f),s]}),[[],0])[0]}function Ah(e,t,n,r){void 0===r&&(r=jh);var i=[];return Ih(e,t).forEach((function(e){i.push({op:"remove",path:n.add(e).toString()})})),Ih(t,e).forEach((function(e){i.push({op:"add",path:n.add(e).toString(),value:t[e]})})),Oh([e,t]).forEach((function(a){i.push.apply(i,r(e[a],t[a],n.add(a)))})),i}function jh(e,t,n,r){if(void 0===r&&(r=jh),e===t)return[];var i=Rh.objectType(e),a=Rh.objectType(t);return"array"==i&&"array"==a?Ph(e,t,n,r):"object"==i&&"object"==a?Ah(e,t,n,r):[{op:"replace",path:n.toString(),value:t}]}Eh.isDestructive=function(e){var t=e.op;return"remove"===t||"replace"===t||"copy"===t||"move"===t},Eh.subtract=Ih,Eh.intersection=Oh,Eh.diffArrays=Ph,Eh.diffObjects=Ah,Eh.diffAny=jh,Object.defineProperty(Zp,"__esModule",{value:!0}),Zp.createTests=Uh=Zp.createPatch=Zp.applyPatch=void 0;var Mh=eh,Lh=ih,Nh=Eh;Zp.applyPatch=function(e,t){return t.map((function(t){return Lh.apply(e,t)}))};var Uh=Zp.createPatch=function(e,t,n){var r=new Mh.Pointer;return(n?function(e){return function t(n,r,i){var a=e(n,r,i);return Array.isArray(a)?a:Nh.diffAny(n,r,i,t)}}(n):Nh.diffAny)(e,t,r)};function Dh(e,t){var n=Mh.Pointer.fromJSON(t).evaluate(e);if(void 0!==n)return{op:"test",path:t,value:n.value}}function Fh(e,t){return 0===Uh(e,t).length}function Bh(e){return JSON.parse(JSON.stringify(e))}function qh(e){return void 0===e||isNaN(Number(e))?null:Number(e)}function Wh(e){try{return new Date(e)}catch(e){return null}}function zh(e,t,n){var r={};if(e)try{r=JSON.parse(e)}catch(e){n.warn(t,e)}return r}Zp.createTests=function(e,t){var n=new Array;return t.filter(Nh.isDestructive).forEach((function(t){var r=Dh(e,t.path);if(r&&n.push(r),"from"in t){var i=Dh(e,t.from);i&&n.push(i)}})),n};var Gh=function(){function e(t){Ma(this,e),this.base=t.replace(/\/$/,""),this.args=[],this.paths=[]}return Ta(e,[{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}}]),e}(),Jh={},Vh=In,$h=S,Kh=yr,Hh=qt,Yh=Ut,Qh=_,Xh=ga,Zh=pe,ev=oa("slice"),tv=Zh("species"),nv=[].slice,rv=Math.max;Vh({target:"Array",proto:!0,forced:!ev},{slice:function(e,t){var n,r,i,a=Qh(this),s=Yh(a.length),o=Hh(e,s),u=Hh(void 0===t?s:t,s);if(Kh(a)&&("function"!=typeof(n=a.constructor)||n!==Array&&!Kh(n.prototype)?$h(n)&&null===(n=n[tv])&&(n=void 0):n=void 0,n===Array||void 0===n))return nv.call(a,o,u);for(r=new(void 0===n?Array:n)(rv(u-o,0)),i=0;o<u;o++,i++)o in a&&Xh(r,i,a[o]);return r.length=i,r}});var iv=In,av=o,sv=i,ov=ee,uv=S,cv=Ne.f,lv=dn,fv=sv.Symbol;if(av&&"function"==typeof fv&&(!("description"in fv.prototype)||void 0!==fv().description)){var dv={},pv=function(){var e=arguments.length<1||void 0===arguments[0]?void 0:String(arguments[0]),t=this instanceof pv?new fv(e):void 0===e?fv():fv(e);return""===e&&(dv[t]=!0),t};lv(pv,fv);var hv=pv.prototype=fv.prototype;hv.constructor=pv;var vv=hv.toString,yv="Symbol(test)"==String(fv("test")),mv=/^Symbol\((.*)\)[^)]+$/;cv(hv,"description",{configurable:!0,get:function(){var e=uv(this)?this.valueOf():this,t=vv.call(e);if(ov(dv,e))return"";var n=yv?t.slice(7,-1):t.replace(mv,"$1");return""===n?void 0:n}}),iv({global:!0,forced:!0},{Symbol:pv})}Cr("iterator");var gv={exports:{}};!function(e){function t(n){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(e.exports=t=function(e){return typeof e},e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=t=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.default=e.exports,e.exports.__esModule=!0),t(n)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0}(gv);var bv=o,kv=Ne.f,wv=Function.prototype,xv=wv.toString,_v=/^\s*function ([^ (]*)/,Sv="name";bv&&!(Sv in wv)&&kv(wv,Sv,{configurable:!0,get:function(){try{return xv.call(this).match(_v)[1]}catch(e){return""}}});var Ev=S,Tv=Math.floor,Rv=function(e){return!Ev(e)&&isFinite(e)&&Tv(e)===e};In({target:"Number",stat:!0},{isInteger:Rv});var Iv={exports:{}},Ov={exports:{}};!function(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.default=e.exports,e.exports.__esModule=!0}(Ov);var Cv={exports:{}};!function(e){e.exports=function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,a=[],s=!0,o=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){o=!0,i=e}finally{try{s||null==n.return||n.return()}finally{if(o)throw i}}return a}},e.exports.default=e.exports,e.exports.__esModule=!0}(Cv);var Pv={exports:{}},Av={exports:{}};!function(e){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r},e.exports.default=e.exports,e.exports.__esModule=!0}(Av),function(e){var t=Av.exports;e.exports=function(e,n){if(e){if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}},e.exports.default=e.exports,e.exports.__esModule=!0}(Pv);var jv={exports:{}};!function(e){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.default=e.exports,e.exports.__esModule=!0}(jv),function(e){var t=Ov.exports,n=Cv.exports,r=Pv.exports,i=jv.exports;e.exports=function(e,a){return t(e)||n(e,a)||r(e,a)||i()},e.exports.default=e.exports,e.exports.__esModule=!0}(Iv);var Mv=o,Lv=An,Nv=_,Uv=u.f,Dv=function(e){return function(t){for(var n,r=Nv(t),i=Lv(r),a=i.length,s=0,o=[];a>s;)n=i[s++],Mv&&!Uv.call(r,n)||o.push(e?[n,r[n]]:r[n]);return o}},Fv={entries:Dv(!0),values:Dv(!1)}.entries;In({target:"Object",stat:!0},{entries:function(e){return Fv(e)}});var Bv={exports:{}},qv={exports:{}};!function(e){var t=Av.exports;e.exports=function(e){if(Array.isArray(e))return t(e)},e.exports.default=e.exports,e.exports.__esModule=!0}(qv);var Wv={exports:{}};!function(e){e.exports=function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)},e.exports.default=e.exports,e.exports.__esModule=!0}(Wv);var zv={exports:{}};!function(e){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.default=e.exports,e.exports.__esModule=!0}(zv),function(e){var t=qv.exports,n=Wv.exports,r=Pv.exports,i=zv.exports;e.exports=function(e){return t(e)||n(e)||r(e)||i()},e.exports.default=e.exports,e.exports.__esModule=!0}(Bv);var Gv={exports:{}};!function(e){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.default=e.exports,e.exports.__esModule=!0}(Gv);var Jv={exports:{}},Vv={exports:{}};!function(e){function t(n,r){return e.exports=t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},e.exports.default=e.exports,e.exports.__esModule=!0,t(n,r)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0}(Vv),function(e){var t=Vv.exports;e.exports=function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),n&&t(e,n)},e.exports.default=e.exports,e.exports.__esModule=!0}(Jv);var $v={exports:{}},Kv={exports:{}};!function(e){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e},e.exports.default=e.exports,e.exports.__esModule=!0}(Kv),function(e){var t=gv.exports.default,n=Kv.exports;e.exports=function(e,r){return!r||"object"!==t(r)&&"function"!=typeof r?n(e):r},e.exports.default=e.exports,e.exports.__esModule=!0}($v);var Hv={exports:{}};!function(e){function t(n){return e.exports=t=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},e.exports.default=e.exports,e.exports.__esModule=!0,t(n)}e.exports=t,e.exports.default=e.exports,e.exports.__esModule=!0}(Hv);var Yv=Vt.includes,Qv=kd;In({target:"Array",proto:!0},{includes:function(e){return Yv(this,e,arguments.length>1?arguments[1]:void 0)}}),Qv("includes"),Object.defineProperty(Jh,"__esModule",{value:!0});var Xv=Iv.exports,Zv=Bv.exports,ey=Gv.exports,ty=Jv.exports,ny=$v.exports,ry=Hv.exports;function iy(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}var ay=iy(gv.exports),sy=iy(Xv),oy=iy(Zv),uy=iy(ey),cy=iy(ty),ly=iy(ny),fy=iy(ry),dy=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return{checks:t}};function py(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return hy(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return hy(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function hy(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var vy=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return dy((function(e){var n,r=!1,i=[],a=py(t);try{for(a.s();!(n=a.n()).done;){var s=n.value;"string"!=typeof s?(r=r||e instanceof s,i.push("an instance of ".concat(s.name))):(r=r||ay.default(e)===s,i.push("of type ".concat(s)))}}catch(e){a.e(e)}finally{a.f()}return[r,i]}))};function yy(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return my(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return my(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function my(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var gy=dy((function(e){return["string"==typeof e&&e.length>0,"a non-empty string"]})),by=dy((function(e){return["number"==typeof e&&Number.isInteger(e)&&e>=0,"a non-negative integer"]})),ky=dy((function(e){return["object"===ay.default(e)&&null!==e&&!Array.isArray(e),"a pure object (non-null and non-array)"]}));function wy(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=fy.default(e);if(t){var i=fy.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return ly.default(this,n)}}function xy(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return _y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _y(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function _y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var Sy=function(e,t){if(t.length>e.length)throw new Error("Expected at most ".concat(e.length," argument(s), but got ").concat(t.length));for(;t.length<e.length;)t.push(void 0);var n,r=xy(t.entries());try{for(r.s();!(n=r.n()).done;){var i=sy.default(n.value,2),a=i[0],s=i[1],o=Iy(e[a],s),u=sy.default(o,4),c=u[0],l=u[1],f=u[2],d=u[3];if(!c)throw new Error("Argument ".concat(a+1," is expected to be ").concat(f).concat(d," but got ").concat(l))}}catch(e){r.e(e)}finally{r.f()}},Ey=function(e){var t,n,r;(["undefined","boolean","number","bigint","string"].includes(ay.default(e))&&(n="string"==typeof e?'"'.concat(e,'"'):"".concat(e)),"object"===ay.default(e)&&"Object"!==(null==e||null===(t=e.constructor)||void 0===t?void 0:t.name))&&(n=null===e?"null":"instance of ".concat(null==e||null===(r=e.constructor)||void 0===r?void 0:r.name));return n||(n=ay.default(e)),n},Ty=function(e){var t,n=[],r=xy(e);try{for(r.s();!(t=r.n()).done;){var i=t.value;n.push(Ry(i))}}catch(e){r.e(e)}finally{r.f()}return n},Ry=function(e){var t,n=[],r=xy(Array.isArray(e)?e:[e]);try{for(r.s();!(t=r.n()).done;){var i=t.value;"string"!=typeof i&&"function"!=typeof i?n.push(i):n.push(vy(i))}}catch(e){r.e(e)}finally{r.f()}return n},Iy=function(e,t){var n,r,i=[],a=!1,s=xy(e);try{for(s.s();!(r=s.n()).done;){var o,u=xy(r.value.checks);try{for(u.s();!(o=u.n()).done;){var c=(0,o.value)(t),l=sy.default(c,3),f=l[0],d=l[1],p=l[2];a=a||f,!n&&p&&(n=p),d&&(i=[].concat(oy.default(i),"string"==typeof d?[d]:oy.default(d)))}}catch(e){u.e(e)}finally{u.f()}}}catch(e){s.e(e)}finally{s.f()}if(a)return[!0];var h=n||Ey(t),v=i.length-1;return[!1,h,v>0?"".concat(i.slice(0,v).join(", ")," or ").concat(i[v]):i.join(", "),v>1?";":","]};function Oy(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Cy(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Cy(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function Cy(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}Jh.array=function(e,t){return dy((function(n){if(!Array.isArray(n))return[!1,"an array of ".concat(e)];var r,i=Oy(n.entries());try{for(i.s();!(r=i.n()).done;){var a=sy.default(r.value,2),s=a[0],o=a[1],u=Iy(Ry(t),o),c=sy.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"a valid array of ".concat(e," (index ").concat(s," should be ").concat(d,")"),"malformed array of ".concat(e," (index ").concat(s," is ").concat(f,")")]}}catch(e){i.e(e)}finally{i.f()}return[!0]}))};var Py=Jh.custom=dy,Ay=Jh.literal=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return dy((function(e){var n,r=!1,i=[],a=yy(t);try{for(a.s();!(n=a.n()).done;){var s=n.value;r=r||e===s,i.push("string"==typeof s?'"'.concat(s,'"'):"".concat(s))}}catch(e){a.e(e)}finally{a.f()}return[r,i]}))},jy=Jh.nonEmptyString=gy,My=Jh.nonNegativeInteger=by,Ly=Jh.objectSchema=function(e,t){return dy((function(n){if("object"!==ay.default(n)||null===n||Array.isArray(n))return[!1,"valid ".concat(e," (should be a pure object)")];for(var r=0,i=Object.entries(t);r<i.length;r++){var a=sy.default(i[r],2),s=a[0],o=a[1],u=Iy(Ry(o),n[s]),c=sy.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"valid ".concat(e,' (key "').concat(s,'" should be ').concat(d,")"),"malformed ".concat(e,' (key "').concat(s,'" is ').concat(f,")")]}return[!0]}))},Ny=Jh.pureObject=ky;Jh.runtimeTypeValidation=Sy,Jh.stringifyReceivedType=Ey,Jh.type=vy;var Uy=Jh.validateConstructorTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Ty(t);return function(e){return function(e){cy.default(n,e);var t=wy(n);function n(){uy.default(this,n);for(var e=arguments.length,i=new Array(e),a=0;a<e;a++)i[a]=arguments[a];return Sy(r,i),t.call.apply(t,[this].concat(i))}return n}(e)}},Dy=Jh.validateTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Ty(t);return function(e,t,n){if("function"!=typeof n.value)throw new Error("The validateTypes decorator can only be applied to methods");var i=n.value;n.value=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Sy(r,t),i.apply(this,t)}}},Fy=Jh.validateTypesAsync=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Ty(t);return function(e,t,n){if("function"!=typeof n.value)throw new Error("The validateTypesAsync decorator can only be applied to methods");var i=n.value;n.value=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];try{Sy(r,t)}catch(e){return Promise.reject(e)}return i.apply(this,t)}}},By={};function qy(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function Wy(e){return function(e){if(Array.isArray(e))return qy(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return qy(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?qy(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function zy(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Gy(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Jy(e){return(Jy=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Vy(e,t,n){return(Vy="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=Jy(e)););return e}(e,t);if(r){var i=Object.getOwnPropertyDescriptor(r,t);return i.get?i.get.call(n):i.value}})(e,t,n||e)}function $y(e,t){return($y=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Ky(e){return(Ky="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Hy(e,t){return!t||"object"!==Ky(t)&&"function"!=typeof t?Gy(e):t}function Yy(){}function Qy(){Qy.init.call(this)}function Xy(e){return void 0===e._maxListeners?Qy.defaultMaxListeners:e._maxListeners}function Zy(e,t,n){if(t)e.call(n);else for(var r=e.length,i=om(e,r),a=0;a<r;++a)i[a].call(n)}function em(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=om(e,i),s=0;s<i;++s)a[s].call(n,r)}function tm(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=om(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function nm(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=om(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function rm(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=om(e,i),s=0;s<i;++s)a[s].apply(n,r)}function im(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new Yy,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=Xy(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function am(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function sm(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function om(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function um(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Jy(e);if(t){var i=Jy(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Hy(this,n)}}
|
130
|
+
/*
|
131
|
+
@license
|
132
|
+
Copyright (c) 2021 Twilio Inc.
|
133
|
+
|
134
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
135
|
+
|
136
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
137
|
+
|
138
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
139
|
+
|
140
|
+
*/
|
141
|
+
Object.defineProperty(By,"__esModule",{value:!0}),Yy.prototype=Object.create(null),Qy.EventEmitter=Qy,Qy.usingDomains=!1,Qy.prototype.domain=void 0,Qy.prototype._events=void 0,Qy.prototype._maxListeners=void 0,Qy.defaultMaxListeners=10,Qy.init=function(){this.domain=null,Qy.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new Yy,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Qy.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},Qy.prototype.getMaxListeners=function(){return Xy(this)},Qy.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:Zy(n,l,this);break;case 2:em(n,l,this,arguments[1]);break;case 3:tm(n,l,this,arguments[1],arguments[2]);break;case 4:nm(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];rm(n,l,this,i)}return!0},Qy.prototype.addListener=function(e,t){return im(this,e,t,!1)},Qy.prototype.on=Qy.prototype.addListener,Qy.prototype.prependListener=function(e,t){return im(this,e,t,!0)},Qy.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,am(this,e,t)),this},Qy.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,am(this,e,t)),this},Qy.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new Yy:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new Yy,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},Qy.prototype.off=function(e,t){return this.removeListener(e,t)},Qy.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new Yy,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new Yy:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new Yy,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},Qy.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},Qy.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):sm.call(e,t)},Qy.prototype.listenerCount=sm,Qy.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var cm=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&$y(e,t)}(n,e);var t=um(n);function n(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),function(e,t,n){t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n}(Gy(e=t.call(this)),"eventHistory",new Map),e}return function(e,t,n){t&&zy(e.prototype,t),n&&zy(e,n)}(n,[{key:"on",value:function(e,t){return Vy(Jy(n.prototype),"on",this).call(this,e,t)}},{key:"once",value:function(e,t){return Vy(Jy(n.prototype),"once",this).call(this,e,t)}},{key:"off",value:function(e,t){return Vy(Jy(n.prototype),"off",this).call(this,e,t)}},{key:"emit",value:function(e){for(var t,r=arguments.length,i=new Array(r>1?r-1:0),a=1;a<r;a++)i[a-1]=arguments[a];return this.eventHistory.set(e,i),(t=Vy(Jy(n.prototype),"emit",this)).call.apply(t,[this,e].concat(i))}},{key:"addListener",value:function(e,t){return Vy(Jy(n.prototype),"addListener",this).call(this,e,t)}},{key:"removeListener",value:function(e,t){return Vy(Jy(n.prototype),"removeListener",this).call(this,e,t)}},{key:"addListenerWithReplay",value:function(e,t){var n=this.eventHistory.get(e);return void 0!==n&&t.apply(void 0,Wy(n)),this.addListener(e,t)}},{key:"onWithReplay",value:function(e,t){return this.addListenerWithReplay(e,t)}}]),n}(Qy),lm=By.ReplayEventEmitter=cm;function fm(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var dm=rd.scope("User"),User=function(e){Oa(User,e);var t,n,r,i,a,s,o,u=fm(User);function User(e,t,n,r){var i;return Ma(this,User),ja(Ra(i=u.call(this)),"promiseToFetch",null),ja(Ra(i),"updated","updated"),ja(Ra(i),"userSubscribed","userSubscribed"),ja(Ra(i),"userUnsubscribed","userUnsubscribed"),i.services=r,i.subscribed="initializing",i.setMaxListeners(0),i.state={identity:e,entityName:t,friendlyName:null,attributes:{},online:null,notifiable:null},i._initializationPromise=new Promise((function(e){i._resolveInitializationPromise=e})),null!==n&&i._resolveInitialization(n,e,t,!1),i}return Ta(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:(o=Sa(bl.mark((function e(t,n){var r,i;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:r=[],dm.debug("User for",this.state.identity,"updated:",t,n),e.t0=t,e.next="friendlyName"===e.t0?7:"attributes"===e.t0?9:"reachability"===e.t0?12:15;break;case 7:return this.state.friendlyName!==n.value&&(r.push("friendlyName"),this.state.friendlyName=n.value),e.abrupt("break",16);case 9:return i=zh(n.value,"Retrieved malformed attributes from the server for user: ".concat(this.state.identity),dm),Fh(this.state.attributes,i)||(this.state.attributes=i,r.push("attributes")),e.abrupt("break",16);case 12:return this.state.online!==n.online&&(this.state.online=n.online,r.push("reachabilityOnline")),this.state.notifiable!==n.notifiable&&(this.state.notifiable=n.notifiable,r.push("reachabilityNotifiable")),e.abrupt("break",16);case 15:return e.abrupt("return");case 16:r.length>0&&this.emit("updated",{user:this,updateReasons:r});case 17:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"_updateReachabilityInfo",value:(s=Sa(bl.mark((function e(t,n){var r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:if(this.configuration.reachabilityEnabled){e.next=4;break}return e.abrupt("return",Promise.resolve());case 4:return e.abrupt("return",t.get("reachability").then(n).catch((function(e){dm.warn("Failed to get reachability info for ",r.state.identity,e)})));case 5:case"end":return e.stop()}}),e,this)}))),function(e,t){return s.apply(this,arguments)})},{key:"_fetch",value:(a=Sa(bl.mark((function e(){var t=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:if(this.state.entityName){e.next=4;break}return e.abrupt("return",this);case 4:return this.promiseToFetch=this.services.syncClient.map({id:this.state.entityName,mode:"open_existing",includeItems:!0}).then((function(e){return t.entity=e,e.on("itemUpdated",(function(e){return dm.debug(t.state.entityName+" ("+t.state.identity+") itemUpdated: "+e.item.key),t._update(e.item.key,e.item.data)})),Promise.all([e.get("friendlyName").then((function(e){return t._update(e.key,e.data)})),e.get("attributes").then((function(e){return t._update(e.key,e.data)})),t._updateReachabilityInfo(e,(function(e){return t._update(e.key,e.data)}))])})).then((function(){return dm.debug("Fetched for",t.identity),t.subscribed="subscribed",t.emit("userSubscribed",t),t})).catch((function(e){throw t.promiseToFetch=null,e})),e.abrupt("return",this.promiseToFetch);case 6:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"_ensureFetched",value:(i=Sa(bl.mark((function e(){return bl.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()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"updateAttributes",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:if("unsubscribed"!=this.subscribed){e.next=4;break}throw new Error("Can't modify unsubscribed object");case 4:return e.next=6,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(t)});case 6:return e.abrupt("return",this);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"updateFriendlyName",value:(n=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:if("unsubscribed"!=this.subscribed){e.next=4;break}throw new Error("Can't modify unsubscribed object");case 4:return e.next=6,this.services.commandExecutor.mutateResource("post",this.links.self,{friendly_name:t});case 6:return e.abrupt("return",this);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"unsubscribe",value:(t=Sa(bl.mark((function e(){return bl.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()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_resolveInitialization",value:function(e,t,n,r){this.configuration=e,this.identity=t,this.entityName=n,this.links={self:"".concat(this.configuration.links.users,"/").concat(this.identity)},this._resolveInitializationPromise(),r&&this.emit("updated",{user:this,updateReasons:["friendlyName","attributes","reachabilityOnline","reachabilityNotifiable"]})}}]),User}(lm);function pm(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function hm(e,t){if(e){if("string"==typeof e)return pm(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?pm(e,t):void 0}}function vm(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,a=[],s=!0,o=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){o=!0,i=e}finally{try{s||null==n.return||n.return()}finally{if(o)throw i}}return a}}(e,t)||hm(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}wl([Fy(["string","number","boolean","object",Ay(null)]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],User.prototype,"updateAttributes",null),wl([Fy(["string"]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],User.prototype,"updateFriendlyName",null);var ym={exports:{}},mm=!s((function(){return Object.isExtensible(Object.preventExtensions({}))})),gm=In,bm=ot,km=S,wm=ee,xm=Ne.f,_m=Pt,Sm=br,Em=mm,Tm=!1,Rm=re("meta"),Im=0,Om=Object.isExtensible||function(){return!0},Cm=function(e){xm(e,Rm,{value:{objectID:"O"+Im++,weakData:{}}})},Pm=ym.exports={enable:function(){Pm.enable=function(){},Tm=!0;var e=_m.f,t=[].splice,n={};n[Rm]=1,e(n).length&&(_m.f=function(n){for(var r=e(n),i=0,a=r.length;i<a;i++)if(r[i]===Rm){t.call(r,i,1);break}return r},gm({target:"Object",stat:!0,forced:!0},{getOwnPropertyNames:Sm.f}))},fastKey:function(e,t){if(!km(e))return"symbol"==typeof e?e:("string"==typeof e?"S":"P")+e;if(!wm(e,Rm)){if(!Om(e))return"F";if(!t)return"E";Cm(e)}return e[Rm].objectID},getWeakData:function(e,t){if(!wm(e,Rm)){if(!Om(e))return!0;if(!t)return!1;Cm(e)}return e[Rm].weakData},onFreeze:function(e){return Em&&Tm&&Om(e)&&!wm(e,Rm)&&Cm(e),e}};bm[Rm]=!0;var Am=In,jm=i,Mm=kn,Lm=$e.exports,Nm=ym.exports,Um=Is,Dm=as,Fm=S,Bm=s,qm=Us,Wm=Mr,zm=fc,Gm=function(e,t,n){var r=-1!==e.indexOf("Map"),i=-1!==e.indexOf("Weak"),a=r?"set":"add",s=jm[e],o=s&&s.prototype,u=s,c={},l=function(e){var t=o[e];Lm(o,e,"add"==e?function(e){return t.call(this,0===e?0:e),this}:"delete"==e?function(e){return!(i&&!Fm(e))&&t.call(this,0===e?0:e)}:"get"==e?function(e){return i&&!Fm(e)?void 0:t.call(this,0===e?0:e)}:"has"==e?function(e){return!(i&&!Fm(e))&&t.call(this,0===e?0:e)}:function(e,n){return t.call(this,0===e?0:e,n),this})};if(Mm(e,"function"!=typeof s||!(i||o.forEach&&!Bm((function(){(new s).entries().next()})))))u=n.getConstructor(t,e,r,a),Nm.enable();else if(Mm(e,!0)){var f=new u,d=f[a](i?{}:-0,1)!=f,p=Bm((function(){f.has(1)})),h=qm((function(e){new s(e)})),v=!i&&Bm((function(){for(var e=new s,t=5;t--;)e[a](t,t);return!e.has(-0)}));h||((u=t((function(t,n){Dm(t,u,e);var i=zm(new s,t,u);return null!=n&&Um(n,i[a],{that:i,AS_ENTRIES:r}),i}))).prototype=o,o.constructor=u),(p||v)&&(l("delete"),l("has"),r&&l("get")),(v||d)&&l(a),i&&o.clear&&delete o.clear}return c[e]=u,Am({global:!0,forced:u!=s},c),Wm(u,e),i||n.setStrong(u,e,r),u},Jm=Ne.f,Vm=Hn,$m=Ha,Km=Nr,Hm=as,Ym=Is,Qm=qf,Xm=is,Zm=o,eg=ym.exports.fastKey,tg=xt.set,ng=xt.getterFor,rg={getConstructor:function(e,t,n,r){var i=e((function(e,a){Hm(e,i,t),tg(e,{type:t,index:Vm(null),first:void 0,last:void 0,size:0}),Zm||(e.size=0),null!=a&&Ym(a,e[r],{that:e,AS_ENTRIES:n})})),a=ng(t),s=function(e,t,n){var r,i,s=a(e),u=o(e,t);return u?u.value=n:(s.last=u={index:i=eg(t,!0),key:t,value:n,previous:r=s.last,next:void 0,removed:!1},s.first||(s.first=u),r&&(r.next=u),Zm?s.size++:e.size++,"F"!==i&&(s.index[i]=u)),e},o=function(e,t){var n,r=a(e),i=eg(t);if("F"!==i)return r.index[i];for(n=r.first;n;n=n.next)if(n.key==t)return n};return $m(i.prototype,{clear:function(){for(var e=a(this),t=e.index,n=e.first;n;)n.removed=!0,n.previous&&(n.previous=n.previous.next=void 0),delete t[n.index],n=n.next;e.first=e.last=void 0,Zm?e.size=0:this.size=0},delete:function(e){var t=this,n=a(t),r=o(t,e);if(r){var i=r.next,s=r.previous;delete n.index[r.index],r.removed=!0,s&&(s.next=i),i&&(i.previous=s),n.first==r&&(n.first=i),n.last==r&&(n.last=s),Zm?n.size--:t.size--}return!!r},forEach:function(e){for(var t,n=a(this),r=Km(e,arguments.length>1?arguments[1]:void 0,3);t=t?t.next:n.first;)for(r(t.value,t.key,this);t&&t.removed;)t=t.previous},has:function(e){return!!o(this,e)}}),$m(i.prototype,n?{get:function(e){var t=o(this,e);return t&&t.value},set:function(e,t){return s(this,0===e?0:e,t)}}:{add:function(e){return s(this,e=0===e?0:e,e)}}),Zm&&Jm(i.prototype,"size",{get:function(){return a(this).size}}),i},setStrong:function(e,t,n){var r=t+" Iterator",i=ng(t),a=ng(r);Qm(e,t,(function(e,t){tg(this,{type:r,target:e,state:i(e),kind:t,last:void 0})}),(function(){for(var e=a(this),t=e.kind,n=e.last;n&&n.removed;)n=n.previous;return e.target&&(e.last=n=n?n.next:e.state.first)?"keys"==t?{value:n.key,done:!1}:"values"==t?{value:n.value,done:!1}:{value:[n.key,n.value],done:!1}:(e.target=void 0,{value:void 0,done:!0})}),n?"entries":"values",!n,!0),Xm(t)}};Gm("Map",(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),rg);var ig={},ag={exports:{}};!function(e){function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}e.exports=function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e},e.exports.default=e.exports,e.exports.__esModule=!0}(ag);var sg={exports:{}};!function(e){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},e.exports.default=e.exports,e.exports.__esModule=!0}(sg),Object.defineProperty(ig,"__esModule",{value:!0});var og=ag.exports,ug=Kv.exports,cg=Jv.exports,lg=$v.exports,fg=Hv.exports,dg=sg.exports;function pg(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}var hg=pg(Gv.exports),vg=pg(og),yg=pg(ug),mg=pg(cg),gg=pg(lg),bg=pg(fg),kg=pg(dg);function wg(){}function xg(){xg.init.call(this)}function _g(e){return void 0===e._maxListeners?xg.defaultMaxListeners:e._maxListeners}function Sg(e,t,n){if(t)e.call(n);else for(var r=e.length,i=Ag(e,r),a=0;a<r;++a)i[a].call(n)}function Eg(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=Ag(e,i),s=0;s<i;++s)a[s].call(n,r)}function Tg(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=Ag(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function Rg(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=Ag(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function Ig(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=Ag(e,i),s=0;s<i;++s)a[s].apply(n,r)}function Og(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new wg,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=_g(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function Cg(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function Pg(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function Ag(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function jg(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=bg.default(e);if(t){var i=bg.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gg.default(this,n)}}wg.prototype=Object.create(null),xg.EventEmitter=xg,xg.usingDomains=!1,xg.prototype.domain=void 0,xg.prototype._events=void 0,xg.prototype._maxListeners=void 0,xg.defaultMaxListeners=10,xg.init=function(){this.domain=null,xg.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new wg,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},xg.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},xg.prototype.getMaxListeners=function(){return _g(this)},xg.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:Sg(n,l,this);break;case 2:Eg(n,l,this,arguments[1]);break;case 3:Tg(n,l,this,arguments[1],arguments[2]);break;case 4:Rg(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];Ig(n,l,this,i)}return!0},xg.prototype.addListener=function(e,t){return Og(this,e,t,!1)},xg.prototype.on=xg.prototype.addListener,xg.prototype.prependListener=function(e,t){return Og(this,e,t,!0)},xg.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,Cg(this,e,t)),this},xg.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,Cg(this,e,t)),this},xg.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new wg:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new wg,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},xg.prototype.off=function(e,t){return this.removeListener(e,t)},xg.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new wg,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new wg:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new wg,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},xg.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},xg.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Pg.call(e,t)},xg.prototype.listenerCount=Pg,xg.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var Mg=function(e){mg.default(n,e);var t=jg(n);function n(e){var r;return hg.default(this,n),r=t.call(this),kg.default(yg.default(r),"timeout",null),kg.default(yg.default(r),"startTimestamp",-1),r.minDelay=e.min,r.maxDelay=e.max,r.initialDelay=e.initial||0,r.maxAttemptsCount=e.maxAttemptsCount||0,r.maxAttemptsTime=e.maxAttemptsTime||0,r.randomness=e.randomness||0,r.inProgress=!1,r.attemptNum=0,r.prevDelay=0,r.currDelay=0,r}return vg.default(n,[{key:"attempt",value:function(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.attemptNum++,this.emit("attempt",this)}},{key:"nextDelay",value:function(e){if("number"==typeof e)return this.prevDelay=0,this.currDelay=e,e;if(0==this.attemptNum)return this.initialDelay;if(1==this.attemptNum)return this.currDelay=this.minDelay,this.currDelay;this.prevDelay=this.currDelay;var t=this.currDelay+this.prevDelay;return this.maxDelay&&t>this.maxDelay&&(this.currDelay=this.maxDelay,t=this.maxDelay),this.currDelay=t,t}},{key:"randomize",value:function(e){var t=e*this.randomness,n=Math.round(Math.random()*t*2-t);return Math.max(0,e+n)}},{key:"scheduleAttempt",value:function(e){var t=this;if(this.maxAttemptsCount&&this.attemptNum>=this.maxAttemptsCount)return this.cleanup(),void this.emit("failed",new Error("Maximum attempt count limit reached"));var n=this.nextDelay(e);if(n=this.randomize(n),this.maxAttemptsTime&&this.startTimestamp+this.maxAttemptsTime<Date.now()+n)return this.cleanup(),void this.emit("failed",new Error("Maximum attempt time limit reached"));this.timeout=setTimeout((function(){return t.attempt()}),n)}},{key:"cleanup",value:function(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.inProgress=!1,this.attemptNum=0,this.prevDelay=0,this.currDelay=0}},{key:"start",value:function(){if(this.inProgress)throw new Error("Retrier is already in progress");this.inProgress=!0,this.startTimestamp=Date.now(),this.scheduleAttempt(this.initialDelay)}},{key:"cancel",value:function(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null,this.inProgress=!1,this.emit("cancelled"))}},{key:"succeeded",value:function(e){this.emit("succeeded",e)}},{key:"failed",value:function(e,t){if(this.timeout)throw new Error("Retrier attempt is already in progress");this.scheduleAttempt(t)}}]),n}(xg),Lg=function(e){mg.default(n,e);var t=jg(n);function n(e){var r;return hg.default(this,n),r=t.call(this),kg.default(yg.default(r),"resolve",(function(){})),kg.default(yg.default(r),"reject",(function(){})),r.retrier=new Mg(e),r}return vg.default(n,[{key:"run",value:function(e){var t=this;return this.retrier.on("attempt",(function(){e().then((function(e){return t.retrier.succeeded(e)})).catch((function(e){return t.retrier.failed(e)}))})),this.retrier.on("succeeded",(function(e){return t.resolve(e)})),this.retrier.on("cancelled",(function(){return t.reject(new Error("Cancelled"))})),this.retrier.on("failed",(function(e){return t.reject(e)})),new Promise((function(e,n){t.resolve=e,t.reject=n,t.retrier.start()}))}},{key:"cancel",value:function(){this.retrier.cancel()}}]),n}(xg);function Ng(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=bg.default(e);if(t){var i=bg.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gg.default(this,n)}}function Ug(e){return null!=e}var Dg=function(e){mg.default(n,e);var t=Ng(n);function n(e){var r;hg.default(this,n),r=t.call(this),kg.default(yg.default(r),"backoffDelay",0),kg.default(yg.default(r),"nextBackoffDelay",0),kg.default(yg.default(r),"backoffNumber",0),kg.default(yg.default(r),"timeoutID",null),kg.default(yg.default(r),"maxNumberOfRetry",-1);var i=e=e||{},a=i.initialDelay,s=i.maxDelay,o=i.randomisationFactor,u=i.factor;if(Ug(a)&&a<1)throw new Error("The initial timeout must be equal to or greater than 1.");if(Ug(s)&&s<=1)throw new Error("The maximal timeout must be greater than 1.");if(Ug(o)&&(o<0||o>1))throw new Error("The randomisation factor must be between 0 and 1.");if(Ug(u)&&u<=1)throw new Error("Exponential factor should be greater than 1.");if(r.initialDelay=a||100,r.maxDelay=s||1e4,r.maxDelay<=r.initialDelay)throw new Error("The maximal backoff delay must be greater than the initial backoff delay.");return r.randomisationFactor=o||0,r.factor=u||2,r.reset(),r}return vg.default(n,[{key:"backoff",value:function(e){null==this.timeoutID&&(this.backoffNumber===this.maxNumberOfRetry?(this.emit("fail",e),this.reset()):(this.backoffDelay=this.next(),this.timeoutID=setTimeout(this.onBackoff.bind(this),this.backoffDelay),this.emit("backoff",this.backoffNumber,this.backoffDelay,e)))}},{key:"reset",value:function(){this.backoffDelay=0,this.nextBackoffDelay=this.initialDelay,this.backoffNumber=0,this.timeoutID&&clearTimeout(this.timeoutID),this.timeoutID=null}},{key:"failAfter",value:function(e){if(e<=0)throw new Error("Expected a maximum number of retry greater than 0 but got ".concat(e));this.maxNumberOfRetry=e}},{key:"next",value:function(){this.backoffDelay=Math.min(this.nextBackoffDelay,this.maxDelay),this.nextBackoffDelay=this.backoffDelay*this.factor;var e=1+Math.random()*this.randomisationFactor;return Math.min(this.maxDelay,Math.round(this.backoffDelay*e))}},{key:"onBackoff",value:function(){this.timeoutID=null,this.emit("ready",this.backoffNumber,this.backoffDelay),this.backoffNumber++}}],[{key:"exponential",value:function(e){return new n(e)}}]),n}(xg),Fg=ig.AsyncRetrier=Lg;ig.Backoff=Dg;var Bg=ig.Retrier=Mg;function qg(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Wg(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Wg(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function Wg(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var zg=function(){function e(t,n){Ma(this,e),this.configuration=t,this.services=n,this.cache=new Map,this.cacheLifetime=100*this.configuration.httpCacheInterval,this.cleanupCache()}return Ta(e,[{key:"isExpired",value:function(e){return!this.cacheLifetime||Date.now()-e>this.cacheLifetime}},{key:"cleanupCache",value:function(){var e,t=qg(this.cache);try{for(t.s();!(e=t.n()).done;){var n=vm(e.value,2),r=n[0],i=n[1];this.isExpired(i.timestamp)&&this.cache.delete(r)}}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(r,i){var a=[502,503,504];n&&a.push(429);var s=new Bg(t.configuration.backoffConfiguration);s.on("attempt",(function(){e().then((function(e){return s.succeeded(e)})).catch((function(e){a.indexOf(e.status)>-1||"Twilsock disconnected"===e.message?s.failed(e):(s.removeAllListeners(),s.cancel(),i(e))}))})),s.on("succeeded",(function(e){r(e)})),s.on("cancelled",(function(e){return i(e)})),s.on("failed",(function(e){return i(e)})),s.start()}))}},{key:"get",value:function(){var e=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=this.cache.get(t))||this.isExpired(n.timestamp)){e.next=3;break}return e.abrupt("return",n.response);case 3:return r={},e.next=6,this.executeWithRetry((function(){return a.services.transport.get(t,r,a.configuration.productId)}),this.configuration.retryWhenThrottled);case 6:return i=e.sent,this.cache.set(t,{response:i,timestamp:Date.now()}),this.pokeTimer(),e.abrupt("return",i);case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()}]),e}(),Gg=function e(){Ma(this,e)};ja(Gg,"TYPING_INDICATOR","twilio.ipmsg.typing_indicator"),ja(Gg,"NEW_MESSAGE","twilio.conversations.new_message"),ja(Gg,"ADDED_TO_CONVERSATION","twilio.conversations.added_to_conversation"),ja(Gg,"REMOVED_FROM_CONVERSATION","twilio.conversations.removed_from_conversation"),ja(Gg,"CONSUMPTION_UPDATE","twilio.channel.consumption_update");var Jg={},Vg={exports:{}};!function(e){function t(e,t,n,r,i,a,s){try{var o=e[a](s),u=o.value}catch(e){return void n(e)}o.done?t(u):Promise.resolve(u).then(r,i)}e.exports=function(e){return function(){var n=this,r=arguments;return new Promise((function(i,a){var s=e.apply(n,r);function o(e){t(s,i,a,o,u,"next",e)}function u(e){t(s,i,a,o,u,"throw",e)}o(void 0)}))}},e.exports.default=e.exports,e.exports.__esModule=!0}(Vg);var $g={exports:{}},Kg={exports:{}};!function(e){var t=Hv.exports;e.exports=function(e,n){for(;!Object.prototype.hasOwnProperty.call(e,n)&&null!==(e=t(e)););return e},e.exports.default=e.exports,e.exports.__esModule=!0}(Kg),function(e){var t=Kg.exports;function n(r,i,a){return"undefined"!=typeof Reflect&&Reflect.get?(e.exports=n=Reflect.get,e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=n=function(e,n,r){var i=t(e,n);if(i){var a=Object.getOwnPropertyDescriptor(i,n);return a.get?a.get.call(r):a.value}},e.exports.default=e.exports,e.exports.__esModule=!0),n(r,i,a||r)}e.exports=n,e.exports.default=e.exports,e.exports.__esModule=!0}($g);var Hg=n(kl),Yg=$e.exports,Qg=De,Xg=gr,Zg=s,eb=Wd,tb="toString",nb=RegExp.prototype,rb=nb.toString,ib=Zg((function(){return"/a/b"!=rb.call({source:"a",flags:"b"})})),ab=rb.name!=tb;(ib||ab)&&Yg(RegExp.prototype,tb,(function(){var e=Qg(this),t=Xg(e.source),n=e.flags;return"/"+t+"/"+Xg(void 0===n&&e instanceof RegExp&&!("flags"in nb)?eb.call(e):n)}),{unsafe:!0}),Gm("Set",(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),rg);var sb={exports:{}};!function(e,t){var n;n=function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=5)}([function(e,t,n){e.exports=function(e,t){var n,r,i;for(n=1;n<arguments.length;n++)for(i in r=arguments[n])r.hasOwnProperty(i)&&(e[i]=r[i]);return e}},function(e,t,n){var r=n(0);e.exports={build:function(e,t){var n,i,a,s=t.plugins;for(n=0,i=s.length;n<i;n++)(a=s[n]).methods&&r(e,a.methods),a.properties&&Object.defineProperties(e,a.properties)},hook:function(e,t,n){var r,i,a,s,o=e.config.plugins,u=[e.context];for(n&&(u=u.concat(n)),r=0,i=o.length;r<i;r++)s=o[r],(a=o[r][t])&&a.apply(s,u)}}},function(e,t,n){function r(e){if(0===e.length)return e;var t,n,r=e.split(/[_-]/);if(1===r.length&&r[0][0].toLowerCase()===r[0][0])return e;for(n=r[0].toLowerCase(),t=1;t<r.length;t++)n=n+r[t].charAt(0).toUpperCase()+r[t].substring(1).toLowerCase();return n}r.prepended=function(e,t){return e+(t=r(t))[0].toUpperCase()+t.substring(1)},e.exports=r},function(e,t,n){var r=n(0),i=n(2);function a(e,t){e=e||{},this.options=e,this.defaults=t.defaults,this.states=[],this.transitions=[],this.map={},this.lifecycle=this.configureLifecycle(),this.init=this.configureInitTransition(e.init),this.data=this.configureData(e.data),this.methods=this.configureMethods(e.methods),this.map[this.defaults.wildcard]={},this.configureTransitions(e.transitions||[]),this.plugins=this.configurePlugins(e.plugins,t.plugin)}r(a.prototype,{addState:function(e){this.map[e]||(this.states.push(e),this.addStateLifecycleNames(e),this.map[e]={})},addStateLifecycleNames:function(e){this.lifecycle.onEnter[e]=i.prepended("onEnter",e),this.lifecycle.onLeave[e]=i.prepended("onLeave",e),this.lifecycle.on[e]=i.prepended("on",e)},addTransition:function(e){this.transitions.indexOf(e)<0&&(this.transitions.push(e),this.addTransitionLifecycleNames(e))},addTransitionLifecycleNames:function(e){this.lifecycle.onBefore[e]=i.prepended("onBefore",e),this.lifecycle.onAfter[e]=i.prepended("onAfter",e),this.lifecycle.on[e]=i.prepended("on",e)},mapTransition:function(e){var t=e.name,n=e.from,r=e.to;return this.addState(n),"function"!=typeof r&&this.addState(r),this.addTransition(t),this.map[n][t]=e,e},configureLifecycle:function(){return{onBefore:{transition:"onBeforeTransition"},onAfter:{transition:"onAfterTransition"},onEnter:{state:"onEnterState"},onLeave:{state:"onLeaveState"},on:{transition:"onTransition"}}},configureInitTransition:function(e){return"string"==typeof e?this.mapTransition(r({},this.defaults.init,{to:e,active:!0})):"object"===Ca(e)?this.mapTransition(r({},this.defaults.init,e,{active:!0})):(this.addState(this.defaults.init.from),this.defaults.init)},configureData:function(e){return"function"==typeof e?e:"object"===Ca(e)?function(){return e}:function(){return{}}},configureMethods:function(e){return e||{}},configurePlugins:function(e,t){var n,r,i;for(n=0,r=(e=e||[]).length;n<r;n++)"function"==typeof(i=e[n])&&(e[n]=i=i()),i.configure&&i.configure(this);return e},configureTransitions:function(e){var t,n,r,i,a,s=this.defaults.wildcard;for(n=0;n<e.length;n++)for(r=e[n],i=Array.isArray(r.from)?r.from:[r.from||s],a=r.to||s,t=0;t<i.length;t++)this.mapTransition({name:r.name,from:i[t],to:a})},transitionFor:function(e,t){var n=this.defaults.wildcard;return this.map[e][t]||this.map[n][t]},transitionsFor:function(e){var t=this.defaults.wildcard;return Object.keys(this.map[e]).concat(Object.keys(this.map[t]))},allStates:function(){return this.states},allTransitions:function(){return this.transitions}}),e.exports=a},function(e,t,n){var r=n(0),i=n(6),a=n(1),s=[null,[]];function o(e,t){this.context=e,this.config=t,this.state=t.init.from,this.observers=[e]}r(o.prototype,{init:function(e){if(r(this.context,this.config.data.apply(this.context,e)),a.hook(this,"init"),this.config.init.active)return this.fire(this.config.init.name,[])},is:function(e){return Array.isArray(e)?e.indexOf(this.state)>=0:this.state===e},isPending:function(){return this.pending},can:function(e){return!this.isPending()&&!!this.seek(e)},cannot:function(e){return!this.can(e)},allStates:function(){return this.config.allStates()},allTransitions:function(){return this.config.allTransitions()},transitions:function(){return this.config.transitionsFor(this.state)},seek:function(e,t){var n=this.config.defaults.wildcard,r=this.config.transitionFor(this.state,e),i=r&&r.to;return"function"==typeof i?i.apply(this.context,t):i===n?this.state:i},fire:function(e,t){return this.transit(e,this.state,this.seek(e,t),t)},transit:function(e,t,n,r){var i=this.config.lifecycle,a=this.config.options.observeUnchangedState||t!==n;return n?this.isPending()?this.context.onPendingTransition(e,t,n):(this.config.addState(n),this.beginTransit(),r.unshift({transition:e,from:t,to:n,fsm:this.context}),this.observeEvents([this.observersForEvent(i.onBefore.transition),this.observersForEvent(i.onBefore[e]),a?this.observersForEvent(i.onLeave.state):s,a?this.observersForEvent(i.onLeave[t]):s,this.observersForEvent(i.on.transition),a?["doTransit",[this]]:s,a?this.observersForEvent(i.onEnter.state):s,a?this.observersForEvent(i.onEnter[n]):s,a?this.observersForEvent(i.on[n]):s,this.observersForEvent(i.onAfter.transition),this.observersForEvent(i.onAfter[e]),this.observersForEvent(i.on[e])],r)):this.context.onInvalidTransition(e,t,n)},beginTransit:function(){this.pending=!0},endTransit:function(e){return this.pending=!1,e},failTransit:function(e){throw this.pending=!1,e},doTransit:function(e){this.state=e.to},observe:function(e){if(2===e.length){var t={};t[e[0]]=e[1],this.observers.push(t)}else this.observers.push(e[0])},observersForEvent:function(e){for(var t,n=0,r=this.observers.length,i=[];n<r;n++)(t=this.observers[n])[e]&&i.push(t);return[e,i,!0]},observeEvents:function(e,t,n,r){if(0===e.length)return this.endTransit(void 0===r||r);var i=e[0][0],s=e[0][1],o=e[0][2];if(t[0].event=i,i&&o&&i!==n&&a.hook(this,"lifecycle",t),0===s.length)return e.shift(),this.observeEvents(e,t,i,r);var u=s.shift(),c=u[i].apply(u,t);return c&&"function"==typeof c.then?c.then(this.observeEvents.bind(this,e,t,i)).catch(this.failTransit.bind(this)):!1===c?this.endTransit(!1):this.observeEvents(e,t,i,c)},onInvalidTransition:function(e,t,n){throw new i("transition is invalid in current state",e,t,n,this.state)},onPendingTransition:function(e,t,n){throw new i("transition is invalid while previous transition is still in progress",e,t,n,this.state)}}),e.exports=o},function(e,t,n){var r=n(0),i=n(2),a=n(1),s=n(3),o=n(4),u={is:function(e){return this._fsm.is(e)},can:function(e){return this._fsm.can(e)},cannot:function(e){return this._fsm.cannot(e)},observe:function(){return this._fsm.observe(arguments)},transitions:function(){return this._fsm.transitions()},allTransitions:function(){return this._fsm.allTransitions()},allStates:function(){return this._fsm.allStates()},onInvalidTransition:function(e,t,n){return this._fsm.onInvalidTransition(e,t,n)},onPendingTransition:function(e,t,n){return this._fsm.onPendingTransition(e,t,n)}},c={state:{configurable:!1,enumerable:!0,get:function(){return this._fsm.state},set:function(e){throw Error("use transitions to change state")}}};function l(e){return f(this||{},e)}function f(e,t){return d(e,new s(t,l)),e._fsm(),e}function d(e,t){if("object"!==Ca(e)||Array.isArray(e))throw Error("StateMachine can only be applied to objects");a.build(e,t),Object.defineProperties(e,c),r(e,u),r(e,t.methods),t.allTransitions().forEach((function(t){e[i(t)]=function(){return this._fsm.fire(t,[].slice.call(arguments))}})),e._fsm=function(){this._fsm=new o(this,t),this._fsm.init(arguments)}}l.version="3.0.1",l.factory=function(){var e,t;"function"==typeof arguments[0]?(e=arguments[0],t=arguments[1]||{}):(e=function(){this._fsm.apply(this,arguments)},t=arguments[0]||{});var n=new s(t,l);return d(e.prototype,n),e.prototype._fsm.config=n,e},l.apply=f,l.defaults={wildcard:"*",init:{name:"init",from:"none"}},e.exports=l},function(e,t,n){e.exports=function(e,t,n,r,i){this.message=e,this.transition=t,this.from=n,this.to=r,this.current=i}}])},e.exports=n()}(sb);var ob={exports:{}},ub="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(ub){var cb=new Uint8Array(16);ob.exports=function(){return ub(cb),cb}}else{var lb=new Array(16);ob.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),lb[t]=e>>>((3&t)<<3)&255;return lb}}for(var fb=[],db=0;db<256;++db)fb[db]=(db+256).toString(16).substr(1);var pb,hb,vb=function(e,t){var n=t||0,r=fb;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")},yb=ob.exports,mb=vb,gb=0,bb=0;var kb=function(e,t,n){var r=t&&n||0,i=t||[],a=(e=e||{}).node||pb,s=void 0!==e.clockseq?e.clockseq:hb;if(null==a||null==s){var o=yb();null==a&&(a=pb=[1|o[0],o[1],o[2],o[3],o[4],o[5]]),null==s&&(s=hb=16383&(o[6]<<8|o[7]))}var u=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:bb+1,l=u-gb+(c-bb)/1e4;if(l<0&&void 0===e.clockseq&&(s=s+1&16383),(l<0||u>gb)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");gb=u,bb=c,hb=s;var f=(1e4*(268435455&(u+=122192928e5))+c)%4294967296;i[r++]=f>>>24&255,i[r++]=f>>>16&255,i[r++]=f>>>8&255,i[r++]=255&f;var d=u/4294967296*1e4&268435455;i[r++]=d>>>8&255,i[r++]=255&d,i[r++]=d>>>24&15|16,i[r++]=d>>>16&255,i[r++]=s>>>8|128,i[r++]=255&s;for(var p=0;p<6;++p)i[r+p]=a[p];return t||mb(i)},wb=ob.exports,xb=vb;var _b=kb,Sb=function(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||wb)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var a=0;a<16;++a)t[r+a]=i[a];return t||xb(i)},Eb=Sb;Eb.v1=_b,Eb.v4=Sb;var Tb,Rb,Ib,Ob=Eb,Cb={exports:{}},Pb="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,Ab=Pb,jb=o,Mb=i,Lb=S,Nb=ee,Ub=qa,Db=Ve,Fb=$e.exports,Bb=Ne.f,qb=df,Wb=Za,zb=pe,Gb=re,Jb=Mb.Int8Array,Vb=Jb&&Jb.prototype,$b=Mb.Uint8ClampedArray,Kb=$b&&$b.prototype,Hb=Jb&&qb(Jb),Yb=Vb&&qb(Vb),Qb=Object.prototype,Xb=Qb.isPrototypeOf,Zb=zb("toStringTag"),ek=Gb("TYPED_ARRAY_TAG"),tk=Gb("TYPED_ARRAY_CONSTRUCTOR"),nk=Ab&&!!Wb&&"Opera"!==Ub(Mb.opera),rk=!1,ik={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},ak={BigInt64Array:8,BigUint64Array:8},sk=function(e){if(!Lb(e))return!1;var t=Ub(e);return Nb(ik,t)||Nb(ak,t)};for(Tb in ik)(Ib=(Rb=Mb[Tb])&&Rb.prototype)?Db(Ib,tk,Rb):nk=!1;for(Tb in ak)(Ib=(Rb=Mb[Tb])&&Rb.prototype)&&Db(Ib,tk,Rb);if((!nk||"function"!=typeof Hb||Hb===Function.prototype)&&(Hb=function(){throw TypeError("Incorrect invocation")},nk))for(Tb in ik)Mb[Tb]&&Wb(Mb[Tb],Hb);if((!nk||!Yb||Yb===Qb)&&(Yb=Hb.prototype,nk))for(Tb in ik)Mb[Tb]&&Wb(Mb[Tb].prototype,Yb);if(nk&&qb(Kb)!==Yb&&Wb(Kb,Yb),jb&&!Nb(Yb,Zb))for(Tb in rk=!0,Bb(Yb,Zb,{get:function(){return Lb(this)?this[ek]:void 0}}),ik)Mb[Tb]&&Db(Mb[Tb],ek,Tb);var ok={NATIVE_ARRAY_BUFFER_VIEWS:nk,TYPED_ARRAY_CONSTRUCTOR:tk,TYPED_ARRAY_TAG:rk&&ek,aTypedArray:function(e){if(sk(e))return e;throw TypeError("Target is not a typed array")},aTypedArrayConstructor:function(e){if(Wb&&!Xb.call(Hb,e))throw TypeError("Target is not a typed array constructor");return e},exportTypedArrayMethod:function(e,t,n){if(jb){if(n)for(var r in ik){var i=Mb[r];if(i&&Nb(i.prototype,e))try{delete i.prototype[e]}catch(e){}}Yb[e]&&!n||Fb(Yb,e,n?t:nk&&Vb[e]||t)}},exportTypedArrayStaticMethod:function(e,t,n){var r,i;if(jb){if(Wb){if(n)for(r in ik)if((i=Mb[r])&&Nb(i,e))try{delete i[e]}catch(e){}if(Hb[e]&&!n)return;try{return Fb(Hb,e,n?t:nk&&Hb[e]||t)}catch(e){}}for(r in ik)!(i=Mb[r])||i[e]&&!n||Fb(i,e,t)}},isView:function(e){if(!Lb(e))return!1;var t=Ub(e);return"DataView"===t||Nb(ik,t)||Nb(ak,t)},isTypedArray:sk,TypedArray:Hb,TypedArrayPrototype:Yb},uk=i,ck=s,lk=Us,fk=ok.NATIVE_ARRAY_BUFFER_VIEWS,dk=uk.ArrayBuffer,pk=uk.Int8Array,hk=!fk||!ck((function(){pk(1)}))||!ck((function(){new pk(-1)}))||!lk((function(e){new pk,new pk(null),new pk(1.5),new pk(e)}),!0)||ck((function(){return 1!==new pk(new dk(2),1,void 0).length})),vk=Mt,yk=Ut,mk=function(e){if(void 0===e)return 0;var t=vk(e),n=yk(t);if(t!==n)throw RangeError("Wrong length or index");return n},gk=Math.abs,bk=Math.pow,kk=Math.floor,wk=Math.log,xk=Math.LN2,_k=Q,Sk=qt,Ek=Ut,Tk=function(e){for(var t=_k(this),n=Ek(t.length),r=arguments.length,i=Sk(r>1?arguments[1]:void 0,n),a=r>2?arguments[2]:void 0,s=void 0===a?n:Sk(a,n);s>i;)t[i++]=e;return t},Rk=i,Ik=o,Ok=Pb,Ck=Ve,Pk=Ha,Ak=s,jk=as,Mk=Mt,Lk=Ut,Nk=mk,Uk={pack:function(e,t,n){var r,i,a,s=new Array(n),o=8*n-t-1,u=(1<<o)-1,c=u>>1,l=23===t?bk(2,-24)-bk(2,-77):0,f=e<0||0===e&&1/e<0?1:0,d=0;for((e=gk(e))!=e||e===1/0?(i=e!=e?1:0,r=u):(r=kk(wk(e)/xk),e*(a=bk(2,-r))<1&&(r--,a*=2),(e+=r+c>=1?l/a:l*bk(2,1-c))*a>=2&&(r++,a/=2),r+c>=u?(i=0,r=u):r+c>=1?(i=(e*a-1)*bk(2,t),r+=c):(i=e*bk(2,c-1)*bk(2,t),r=0));t>=8;s[d++]=255&i,i/=256,t-=8);for(r=r<<t|i,o+=t;o>0;s[d++]=255&r,r/=256,o-=8);return s[--d]|=128*f,s},unpack:function(e,t){var n,r=e.length,i=8*r-t-1,a=(1<<i)-1,s=a>>1,o=i-7,u=r-1,c=e[u--],l=127&c;for(c>>=7;o>0;l=256*l+e[u],u--,o-=8);for(n=l&(1<<-o)-1,l>>=-o,o+=t;o>0;n=256*n+e[u],u--,o-=8);if(0===l)l=1-s;else{if(l===a)return n?NaN:c?-1/0:1/0;n+=bk(2,t),l-=s}return(c?-1:1)*n*bk(2,l-t)}},Dk=df,Fk=Za,Bk=Pt.f,qk=Ne.f,Wk=Tk,zk=Mr,Gk=xt.get,Jk=xt.set,Vk="ArrayBuffer",$k="DataView",Kk="Wrong index",Hk=Rk.ArrayBuffer,Yk=Hk,Qk=Rk.DataView,Xk=Qk&&Qk.prototype,Zk=Object.prototype,ew=Rk.RangeError,tw=Uk.pack,nw=Uk.unpack,rw=function(e){return[255&e]},iw=function(e){return[255&e,e>>8&255]},aw=function(e){return[255&e,e>>8&255,e>>16&255,e>>24&255]},sw=function(e){return e[3]<<24|e[2]<<16|e[1]<<8|e[0]},ow=function(e){return tw(e,23,4)},uw=function(e){return tw(e,52,8)},cw=function(e,t){qk(e.prototype,t,{get:function(){return Gk(this)[t]}})},lw=function(e,t,n,r){var i=Nk(n),a=Gk(e);if(i+t>a.byteLength)throw ew(Kk);var s=Gk(a.buffer).bytes,o=i+a.byteOffset,u=s.slice(o,o+t);return r?u:u.reverse()},fw=function(e,t,n,r,i,a){var s=Nk(n),o=Gk(e);if(s+t>o.byteLength)throw ew(Kk);for(var u=Gk(o.buffer).bytes,c=s+o.byteOffset,l=r(+i),f=0;f<t;f++)u[c+f]=l[a?f:t-f-1]};if(Ok){if(!Ak((function(){Hk(1)}))||!Ak((function(){new Hk(-1)}))||Ak((function(){return new Hk,new Hk(1.5),new Hk(NaN),Hk.name!=Vk}))){for(var dw,pw=(Yk=function(e){return jk(this,Yk),new Hk(Nk(e))}).prototype=Hk.prototype,hw=Bk(Hk),vw=0;hw.length>vw;)(dw=hw[vw++])in Yk||Ck(Yk,dw,Hk[dw]);pw.constructor=Yk}Fk&&Dk(Xk)!==Zk&&Fk(Xk,Zk);var yw=new Qk(new Yk(2)),mw=Xk.setInt8;yw.setInt8(0,2147483648),yw.setInt8(1,2147483649),!yw.getInt8(0)&&yw.getInt8(1)||Pk(Xk,{setInt8:function(e,t){mw.call(this,e,t<<24>>24)},setUint8:function(e,t){mw.call(this,e,t<<24>>24)}},{unsafe:!0})}else Yk=function(e){jk(this,Yk,Vk);var t=Nk(e);Jk(this,{bytes:Wk.call(new Array(t),0),byteLength:t}),Ik||(this.byteLength=t)},Qk=function(e,t,n){jk(this,Qk,$k),jk(e,Yk,$k);var r=Gk(e).byteLength,i=Mk(t);if(i<0||i>r)throw ew("Wrong offset");if(i+(n=void 0===n?r-i:Lk(n))>r)throw ew("Wrong length");Jk(this,{buffer:e,byteLength:n,byteOffset:i}),Ik||(this.buffer=e,this.byteLength=n,this.byteOffset=i)},Ik&&(cw(Yk,"byteLength"),cw(Qk,"buffer"),cw(Qk,"byteLength"),cw(Qk,"byteOffset")),Pk(Qk.prototype,{getInt8:function(e){return lw(this,1,e)[0]<<24>>24},getUint8:function(e){return lw(this,1,e)[0]},getInt16:function(e){var t=lw(this,2,e,arguments.length>1?arguments[1]:void 0);return(t[1]<<8|t[0])<<16>>16},getUint16:function(e){var t=lw(this,2,e,arguments.length>1?arguments[1]:void 0);return t[1]<<8|t[0]},getInt32:function(e){return sw(lw(this,4,e,arguments.length>1?arguments[1]:void 0))},getUint32:function(e){return sw(lw(this,4,e,arguments.length>1?arguments[1]:void 0))>>>0},getFloat32:function(e){return nw(lw(this,4,e,arguments.length>1?arguments[1]:void 0),23)},getFloat64:function(e){return nw(lw(this,8,e,arguments.length>1?arguments[1]:void 0),52)},setInt8:function(e,t){fw(this,1,e,rw,t)},setUint8:function(e,t){fw(this,1,e,rw,t)},setInt16:function(e,t){fw(this,2,e,iw,t,arguments.length>2?arguments[2]:void 0)},setUint16:function(e,t){fw(this,2,e,iw,t,arguments.length>2?arguments[2]:void 0)},setInt32:function(e,t){fw(this,4,e,aw,t,arguments.length>2?arguments[2]:void 0)},setUint32:function(e,t){fw(this,4,e,aw,t,arguments.length>2?arguments[2]:void 0)},setFloat32:function(e,t){fw(this,4,e,ow,t,arguments.length>2?arguments[2]:void 0)},setFloat64:function(e,t){fw(this,8,e,uw,t,arguments.length>2?arguments[2]:void 0)}});zk(Yk,Vk),zk(Qk,$k);var gw={ArrayBuffer:Yk,DataView:Qk},bw=Mt,kw=function(e){var t=bw(e);if(t<0)throw RangeError("The argument can't be less than 0");return t},ww=function(e,t){var n=kw(e);if(n%t)throw RangeError("Wrong offset");return n},xw=Q,_w=Ut,Sw=ms,Ew=hs,Tw=ls,Rw=Nr,Iw=ok.aTypedArrayConstructor,Ow=In,Cw=i,Pw=o,Aw=hk,jw=ok,Mw=gw,Lw=as,Nw=h,Uw=Ve,Dw=Rv,Fw=Ut,Bw=mk,qw=ww,Ww=we,zw=ee,Gw=qa,Jw=S,Vw=q,$w=Hn,Kw=Za,Hw=Pt.f,Yw=function(e){var t,n,r,i,a,s,o=xw(e),u=arguments.length,c=u>1?arguments[1]:void 0,l=void 0!==c,f=Ew(o);if(null!=f&&!Tw(f))for(s=(a=Sw(o,f)).next,o=[];!(i=s.call(a)).done;)o.push(i.value);for(l&&u>2&&(c=Rw(c,arguments[2],2)),n=_w(o.length),r=new(Iw(this))(n),t=0;n>t;t++)r[t]=l?c(o[t],t):o[t];return r},Qw=Hr.forEach,Xw=is,Zw=Ne,ex=a,tx=fc,nx=xt.get,rx=xt.set,ix=Zw.f,ax=ex.f,sx=Math.round,ox=Cw.RangeError,ux=Mw.ArrayBuffer,cx=Mw.DataView,lx=jw.NATIVE_ARRAY_BUFFER_VIEWS,fx=jw.TYPED_ARRAY_CONSTRUCTOR,dx=jw.TYPED_ARRAY_TAG,px=jw.TypedArray,hx=jw.TypedArrayPrototype,vx=jw.aTypedArrayConstructor,yx=jw.isTypedArray,mx="BYTES_PER_ELEMENT",gx="Wrong length",bx=function(e,t){for(var n=0,r=t.length,i=new(vx(e))(r);r>n;)i[n]=t[n++];return i},kx=function(e,t){ix(e,t,{get:function(){return nx(this)[t]}})},wx=function(e){var t;return e instanceof ux||"ArrayBuffer"==(t=Gw(e))||"SharedArrayBuffer"==t},xx=function(e,t){return yx(e)&&!Vw(t)&&t in e&&Dw(+t)&&t>=0},_x=function(e,t){return t=Ww(t),xx(e,t)?Nw(2,e[t]):ax(e,t)},Sx=function(e,t,n){return t=Ww(t),!(xx(e,t)&&Jw(n)&&zw(n,"value"))||zw(n,"get")||zw(n,"set")||n.configurable||zw(n,"writable")&&!n.writable||zw(n,"enumerable")&&!n.enumerable?ix(e,t,n):(e[t]=n.value,e)};Pw?(lx||(ex.f=_x,Zw.f=Sx,kx(hx,"buffer"),kx(hx,"byteOffset"),kx(hx,"byteLength"),kx(hx,"length")),Ow({target:"Object",stat:!0,forced:!lx},{getOwnPropertyDescriptor:_x,defineProperty:Sx}),Cb.exports=function(e,t,n){var r=e.match(/\d+$/)[0]/8,i=e+(n?"Clamped":"")+"Array",a="get"+e,s="set"+e,o=Cw[i],u=o,c=u&&u.prototype,l={},f=function(e,t){ix(e,t,{get:function(){return function(e,t){var n=nx(e);return n.view[a](t*r+n.byteOffset,!0)}(this,t)},set:function(e){return function(e,t,i){var a=nx(e);n&&(i=(i=sx(i))<0?0:i>255?255:255&i),a.view[s](t*r+a.byteOffset,i,!0)}(this,t,e)},enumerable:!0})};lx?Aw&&(u=t((function(e,t,n,a){return Lw(e,u,i),tx(Jw(t)?wx(t)?void 0!==a?new o(t,qw(n,r),a):void 0!==n?new o(t,qw(n,r)):new o(t):yx(t)?bx(u,t):Yw.call(u,t):new o(Bw(t)),e,u)})),Kw&&Kw(u,px),Qw(Hw(o),(function(e){e in u||Uw(u,e,o[e])})),u.prototype=c):(u=t((function(e,t,n,a){Lw(e,u,i);var s,o,c,l=0,d=0;if(Jw(t)){if(!wx(t))return yx(t)?bx(u,t):Yw.call(u,t);s=t,d=qw(n,r);var p=t.byteLength;if(void 0===a){if(p%r)throw ox(gx);if((o=p-d)<0)throw ox(gx)}else if((o=Fw(a)*r)+d>p)throw ox(gx);c=o/r}else c=Bw(t),s=new ux(o=c*r);for(rx(e,{buffer:s,byteOffset:d,byteLength:o,length:c,view:new cx(s)});l<c;)f(e,l++)})),Kw&&Kw(u,px),c=u.prototype=$w(hx)),c.constructor!==u&&Uw(c,"constructor",u),Uw(c,fx,u),dx&&Uw(c,dx,i),l[i]=u,Ow({global:!0,forced:u!=o,sham:!lx},l),mx in u||Uw(u,mx,r),mx in c||Uw(c,mx,r),Xw(i)}):Cb.exports=function(){},(0,Cb.exports)("Uint8",(function(e){return function(t,n,r){return e(this,t,n,r)}}));var Ex=Q,Tx=qt,Rx=Ut,Ix=Math.min,Ox=[].copyWithin||function(e,t){var n=Ex(this),r=Rx(n.length),i=Tx(e,r),a=Tx(t,r),s=arguments.length>2?arguments[2]:void 0,o=Ix((void 0===s?r:Tx(s,r))-a,r-i),u=1;for(a<i&&i<a+o&&(u=-1,a+=o-1,i+=o-1);o-- >0;)a in n?n[i]=n[a]:delete n[i],i+=u,a+=u;return n},Cx=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("copyWithin",(function(e,t){return Ox.call(Cx(this),e,t,arguments.length>2?arguments[2]:void 0)}));var Px=Hr.every,Ax=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("every",(function(e){return Px(Ax(this),e,arguments.length>1?arguments[1]:void 0)}));var jx=Tk,Mx=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("fill",(function(e){return jx.apply(Mx(this),arguments)}));var Lx=qs,Nx=ok.TYPED_ARRAY_CONSTRUCTOR,Ux=ok.aTypedArrayConstructor,Dx=function(e){return Ux(Lx(e,e[Nx]))},Fx=function(e,t){for(var n=0,r=t.length,i=new e(r);r>n;)i[n]=t[n++];return i},Bx=Dx,qx=Hr.filter,Wx=function(e,t){return Fx(Bx(e),t)},zx=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("filter",(function(e){var t=qx(zx(this),e,arguments.length>1?arguments[1]:void 0);return Wx(this,t)}));var Gx=Hr.find,Jx=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("find",(function(e){return Gx(Jx(this),e,arguments.length>1?arguments[1]:void 0)}));var Vx=Hr.findIndex,$x=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("findIndex",(function(e){return Vx($x(this),e,arguments.length>1?arguments[1]:void 0)}));var Kx=Hr.forEach,Hx=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("forEach",(function(e){Kx(Hx(this),e,arguments.length>1?arguments[1]:void 0)}));var Yx=Vt.includes,Qx=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("includes",(function(e){return Yx(Qx(this),e,arguments.length>1?arguments[1]:void 0)}));var Xx=Vt.indexOf,Zx=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("indexOf",(function(e){return Xx(Zx(this),e,arguments.length>1?arguments[1]:void 0)}));var e_=i,t_=ok,n_=Od,r_=pe("iterator"),i_=e_.Uint8Array,a_=n_.values,s_=n_.keys,o_=n_.entries,u_=t_.aTypedArray,c_=t_.exportTypedArrayMethod,l_=i_&&i_.prototype[r_],f_=!!l_&&("values"==l_.name||null==l_.name),d_=function(){return a_.call(u_(this))};c_("entries",(function(){return o_.call(u_(this))})),c_("keys",(function(){return s_.call(u_(this))})),c_("values",d_,!f_),c_(r_,d_,!f_);var p_=ok.aTypedArray,h_=[].join;(0,ok.exportTypedArrayMethod)("join",(function(e){return h_.apply(p_(this),arguments)}));var v_=_,y_=Mt,m_=Ut,g_=ec,b_=Math.min,k_=[].lastIndexOf,w_=!!k_&&1/[1].lastIndexOf(1,-0)<0,x_=g_("lastIndexOf"),__=w_||!x_?function(e){if(w_)return k_.apply(this,arguments)||0;var t=v_(this),n=m_(t.length),r=n-1;for(arguments.length>1&&(r=b_(r,y_(arguments[1]))),r<0&&(r=n+r);r>=0;r--)if(r in t&&t[r]===e)return r||0;return-1}:k_,S_=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("lastIndexOf",(function(e){return __.apply(S_(this),arguments)}));var E_=Hr.map,T_=Dx,R_=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("map",(function(e){return E_(R_(this),e,arguments.length>1?arguments[1]:void 0,(function(e,t){return new(T_(e))(t)}))}));var I_=On,O_=Q,C_=b,P_=Ut,A_=function(e){return function(t,n,r,i){I_(n);var a=O_(t),s=C_(a),o=P_(a.length),u=e?o-1:0,c=e?-1:1;if(r<2)for(;;){if(u in s){i=s[u],u+=c;break}if(u+=c,e?u<0:o<=u)throw TypeError("Reduce of empty array with no initial value")}for(;e?u>=0:o>u;u+=c)u in s&&(i=n(i,s[u],u,a));return i}},j_={left:A_(!1),right:A_(!0)},M_=j_.left,L_=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("reduce",(function(e){return M_(L_(this),e,arguments.length,arguments.length>1?arguments[1]:void 0)}));var N_=j_.right,U_=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("reduceRight",(function(e){return N_(U_(this),e,arguments.length,arguments.length>1?arguments[1]:void 0)}));var D_=ok.aTypedArray,F_=ok.exportTypedArrayMethod,B_=Math.floor;F_("reverse",(function(){for(var e,t=this,n=D_(t).length,r=B_(n/2),i=0;i<r;)e=t[i],t[i++]=t[--n],t[n]=e;return t}));var q_=Ut,W_=ww,z_=Q,G_=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("set",(function(e){G_(this);var t=W_(arguments.length>1?arguments[1]:void 0,1),n=this.length,r=z_(e),i=q_(r.length),a=0;if(i+t>n)throw RangeError("Wrong length");for(;a<i;)this[t+a]=r[a++]}),s((function(){new Int8Array(1).set({})})));var J_=Dx,V_=ok.aTypedArray,$_=[].slice;(0,ok.exportTypedArrayMethod)("slice",(function(e,t){for(var n=$_.call(V_(this),e,t),r=J_(this),i=0,a=n.length,s=new r(a);a>i;)s[i]=n[i++];return s}),s((function(){new Int8Array(1).slice()})));var K_=Hr.some,H_=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("some",(function(e){return K_(H_(this),e,arguments.length>1?arguments[1]:void 0)}));var Y_=Math.floor,Q_=function(e,t){var n=e.length,r=Y_(n/2);return n<8?X_(e,t):Z_(Q_(e.slice(0,r),t),Q_(e.slice(r),t),t)},X_=function(e,t){for(var n,r,i=e.length,a=1;a<i;){for(r=a,n=e[a];r&&t(e[r-1],n)>0;)e[r]=e[--r];r!==a++&&(e[r]=n)}return e},Z_=function(e,t,n){for(var r=e.length,i=t.length,a=0,s=0,o=[];a<r||s<i;)a<r&&s<i?o.push(n(e[a],t[s])<=0?e[a++]:t[s++]):o.push(a<r?e[a++]:t[s++]);return o},eS=Q_,tS=I.match(/firefox\/(\d+)/i),nS=!!tS&&+tS[1],rS=/MSIE|Trident/.test(I),iS=I.match(/AppleWebKit\/(\d+)\./),aS=!!iS&&+iS[1],sS=s,oS=On,uS=Ut,cS=eS,lS=nS,fS=rS,dS=L,pS=aS,hS=ok.aTypedArray,vS=ok.exportTypedArrayMethod,yS=i.Uint16Array,mS=yS&&yS.prototype.sort,gS=!!mS&&!sS((function(){var e=new yS(2);e.sort(null),e.sort({})})),bS=!!mS&&!sS((function(){if(dS)return dS<74;if(lS)return lS<67;if(fS)return!0;if(pS)return pS<602;var e,t,n=new yS(516),r=Array(516);for(e=0;e<516;e++)t=e%4,n[e]=515-e,r[e]=e-2*t+3;for(n.sort((function(e,t){return(e/4|0)-(t/4|0)})),e=0;e<516;e++)if(n[e]!==r[e])return!0}));vS("sort",(function(e){var t=this;if(void 0!==e&&oS(e),bS)return mS.call(t,e);hS(t);var n,r=uS(t.length),i=Array(r);for(n=0;n<r;n++)i[n]=t[n];for(i=cS(t,function(e){return function(t,n){return void 0!==e?+e(t,n)||0:n!=n?-1:t!=t?1:0===t&&0===n?1/t>0&&1/n<0?1:-1:t>n}}(e)),n=0;n<r;n++)t[n]=i[n];return t}),!bS||gS);var kS=Ut,wS=qt,xS=Dx,_S=ok.aTypedArray;(0,ok.exportTypedArrayMethod)("subarray",(function(e,t){var n=_S(this),r=n.length,i=wS(e,r);return new(xS(n))(n.buffer,n.byteOffset+i*n.BYTES_PER_ELEMENT,kS((void 0===t?r:wS(t,r))-i))}));var SS=ok,ES=s,TS=i.Int8Array,RS=SS.aTypedArray,IS=SS.exportTypedArrayMethod,OS=[].toLocaleString,CS=[].slice,PS=!!TS&&ES((function(){OS.call(new TS(1))}));IS("toLocaleString",(function(){return OS.apply(PS?CS.call(RS(this)):RS(this),arguments)}),ES((function(){return[1,2].toLocaleString()!=new TS([1,2]).toLocaleString()}))||!ES((function(){TS.prototype.toLocaleString.call([1,2])})));var AS=ok.exportTypedArrayMethod,jS=s,MS=i.Uint8Array,LS=MS&&MS.prototype||{},NS=[].toString,US=[].join;jS((function(){NS.call({})}))&&(NS=function(){return US.call(this)});var DS=LS.toString!=NS;AS("toString",NS,DS);var FS=S,BS=y,qS=pe("match"),WS=function(e){var t;return FS(e)&&(void 0!==(t=e[qS])?!!t:"RegExp"==BS(e))},zS=xp,GS=WS,JS=De,VS=k,$S=qs,KS=Sp,HS=Ut,YS=gr,QS=Ap,XS=hp,ZS=s,eE=zd.UNSUPPORTED_Y,tE=[].push,nE=Math.min,rE=4294967295;zS("split",(function(e,t,n){var r;return r="c"=="abbc".split(/(b)*/)[1]||4!="test".split(/(?:)/,-1).length||2!="ab".split(/(?:ab)*/).length||4!=".".split(/(.?)(.?)/).length||".".split(/()()/).length>1||"".split(/.?/).length?function(e,n){var r=YS(VS(this)),i=void 0===n?rE:n>>>0;if(0===i)return[];if(void 0===e)return[r];if(!GS(e))return t.call(r,e,i);for(var a,s,o,u=[],c=(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.unicode?"u":"")+(e.sticky?"y":""),l=0,f=new RegExp(e.source,c+"g");(a=XS.call(f,r))&&!((s=f.lastIndex)>l&&(u.push(r.slice(l,a.index)),a.length>1&&a.index<r.length&&tE.apply(u,a.slice(1)),o=a[0].length,l=s,u.length>=i));)f.lastIndex===a.index&&f.lastIndex++;return l===r.length?!o&&f.test("")||u.push(""):u.push(r.slice(l)),u.length>i?u.slice(0,i):u}:"0".split(void 0,0).length?function(e,n){return void 0===e&&0===n?[]:t.call(this,e,n)}:t,[function(t,n){var i=VS(this),a=null==t?void 0:t[e];return void 0!==a?a.call(t,i,n):r.call(YS(i),t,n)},function(e,i){var a=JS(this),s=YS(e),o=n(r,a,s,i,r!==t);if(o.done)return o.value;var u=$S(a,RegExp),c=a.unicode,l=(a.ignoreCase?"i":"")+(a.multiline?"m":"")+(a.unicode?"u":"")+(eE?"g":"y"),f=new u(eE?"^(?:"+a.source+")":a,l),d=void 0===i?rE:i>>>0;if(0===d)return[];if(0===s.length)return null===QS(f,s)?[s]:[];for(var p=0,h=0,v=[];h<s.length;){f.lastIndex=eE?0:h;var y,m=QS(f,eE?s.slice(h):s);if(null===m||(y=nE(HS(f.lastIndex+(eE?h:0)),s.length))===p)h=KS(s,h,c);else{if(v.push(s.slice(p,h)),v.length===d)return v;for(var g=1;g<=m.length-1;g++)if(v.push(m[g]),v.length===d)return v;h=p=y}}return v.push(s.slice(p)),v}]}),!!ZS((function(){var e=/(?:)/,t=e.exec;e.exec=function(){return t.apply(this,arguments)};var n="ab".split(e);return 2!==n.length||"a"!==n[0]||"b"!==n[1]})),eE);var iE={exports:{}},aE={exports:{}};!function(e){e.exports=function(e){return-1!==Function.toString.call(e).indexOf("[native code]")},e.exports.default=e.exports,e.exports.__esModule=!0}(aE);var sE={exports:{}},oE={exports:{}};!function(e){e.exports=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}},e.exports.default=e.exports,e.exports.__esModule=!0}(oE),function(e){var t=Vv.exports,n=oE.exports;function r(i,a,s){return n()?(e.exports=r=Reflect.construct,e.exports.default=e.exports,e.exports.__esModule=!0):(e.exports=r=function(e,n,r){var i=[null];i.push.apply(i,n);var a=new(Function.bind.apply(e,i));return r&&t(a,r.prototype),a},e.exports.default=e.exports,e.exports.__esModule=!0),r.apply(null,arguments)}e.exports=r,e.exports.default=e.exports,e.exports.__esModule=!0}(sE),function(e){var t=Hv.exports,n=Vv.exports,r=aE.exports,i=sE.exports;function a(s){var o="function"==typeof Map?new Map:void 0;return e.exports=a=function(e){if(null===e||!r(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==o){if(o.has(e))return o.get(e);o.set(e,a)}function a(){return i(e,arguments,t(this).constructor)}return a.prototype=Object.create(e.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),n(a,e)},e.exports.default=e.exports,e.exports.__esModule=!0,a(s)}e.exports=a,e.exports.default=e.exports,e.exports.__esModule=!0}(iE);var uE={exports:{}};!function(e,n){(function(){var r={function:!0,object:!0}["undefined"==typeof window?"undefined":Ca(window)]&&window||this,i=n,a=e&&!e.nodeType&&e,s=i&&a&&"object"==Ca(t)&&t;!s||s.global!==s&&s.window!==s&&s.self!==s||(r=s);var o=Math.pow(2,53)-1,u=/\bOpera/,c=Object.prototype,l=c.hasOwnProperty,f=c.toString;function d(e){return(e=String(e)).charAt(0).toUpperCase()+e.slice(1)}function p(e){return e=g(e),/^(?:webOS|i(?:OS|P))/.test(e)?e:d(e)}function h(e,t){for(var n in e)l.call(e,n)&&t(e[n],n,e)}function v(e){return null==e?d(e):f.call(e).slice(8,-1)}function y(e){return String(e).replace(/([ -])(?!$)/g,"$1?")}function m(e,t){var n=null;return function(e,t){var n=-1,r=e?e.length:0;if("number"==typeof r&&r>-1&&r<=o)for(;++n<r;)t(e[n],n,e);else h(e,t)}(e,(function(r,i){n=t(n,r,i,e)})),n}function g(e){return String(e).replace(/^ +| +$/g,"")}var b=function e(t){var n=r,i=t&&"object"==Ca(t)&&"String"!=v(t);i&&(n=t,t=null);var a=n.navigator||{},s=a.userAgent||"";t||(t=s);var o,c,l=i?!!a.likeChrome:/\bChrome\b/.test(t)&&!/internal|\n/i.test(f.toString()),d="Object",b=i?d:"ScriptBridgingProxyObject",k=i?d:"Environment",w=i&&n.java?"JavaPackage":v(n.java),x=i?d:"RuntimeObject",_=/\bJava/.test(w)&&n.java,S=_&&v(n.environment)==k,E=_?"a":"α",T=_?"b":"β",R=n.document||{},I=n.operamini||n.opera,O=u.test(O=i&&I?I["[[Class]]"]:v(I))?O:I=null,C=t,P=[],A=null,j=t==s,M=j&&I&&"function"==typeof I.version&&I.version(),L=m([{label:"EdgeHTML",pattern:"Edge"},"Trident",{label:"WebKit",pattern:"AppleWebKit"},"iCab","Presto","NetFront","Tasman","KHTML","Gecko"],(function(e,n){return e||RegExp("\\b"+(n.pattern||y(n))+"\\b","i").exec(t)&&(n.label||n)})),N=function(e){return m(e,(function(e,n){return e||RegExp("\\b"+(n.pattern||y(n))+"\\b","i").exec(t)&&(n.label||n)}))}(["Adobe AIR","Arora","Avant Browser","Breach","Camino","Electron","Epiphany","Fennec","Flock","Galeon","GreenBrowser","iCab","Iceweasel","K-Meleon","Konqueror","Lunascape","Maxthon",{label:"Microsoft Edge",pattern:"(?:Edge|Edg|EdgA|EdgiOS)"},"Midori","Nook Browser","PaleMoon","PhantomJS","Raven","Rekonq","RockMelt",{label:"Samsung Internet",pattern:"SamsungBrowser"},"SeaMonkey",{label:"Silk",pattern:"(?:Cloud9|Silk-Accelerated)"},"Sleipnir","SlimBrowser",{label:"SRWare Iron",pattern:"Iron"},"Sunrise","Swiftfox","Vivaldi","Waterfox","WebPositive",{label:"Yandex Browser",pattern:"YaBrowser"},{label:"UC Browser",pattern:"UCBrowser"},"Opera Mini",{label:"Opera Mini",pattern:"OPiOS"},"Opera",{label:"Opera",pattern:"OPR"},"Chromium","Chrome",{label:"Chrome",pattern:"(?:HeadlessChrome)"},{label:"Chrome Mobile",pattern:"(?:CriOS|CrMo)"},{label:"Firefox",pattern:"(?:Firefox|Minefield)"},{label:"Firefox for iOS",pattern:"FxiOS"},{label:"IE",pattern:"IEMobile"},{label:"IE",pattern:"MSIE"},"Safari"]),U=B([{label:"BlackBerry",pattern:"BB10"},"BlackBerry",{label:"Galaxy S",pattern:"GT-I9000"},{label:"Galaxy S2",pattern:"GT-I9100"},{label:"Galaxy S3",pattern:"GT-I9300"},{label:"Galaxy S4",pattern:"GT-I9500"},{label:"Galaxy S5",pattern:"SM-G900"},{label:"Galaxy S6",pattern:"SM-G920"},{label:"Galaxy S6 Edge",pattern:"SM-G925"},{label:"Galaxy S7",pattern:"SM-G930"},{label:"Galaxy S7 Edge",pattern:"SM-G935"},"Google TV","Lumia","iPad","iPod","iPhone","Kindle",{label:"Kindle Fire",pattern:"(?:Cloud9|Silk-Accelerated)"},"Nexus","Nook","PlayBook","PlayStation Vita","PlayStation","TouchPad","Transformer",{label:"Wii U",pattern:"WiiU"},"Wii","Xbox One",{label:"Xbox 360",pattern:"Xbox"},"Xoom"]),D=function(e){return m(e,(function(e,n,r){return e||(n[U]||n[/^[a-z]+(?: +[a-z]+\b)*/i.exec(U)]||RegExp("\\b"+y(r)+"(?:\\b|\\w*\\d)","i").exec(t))&&r}))}({Apple:{iPad:1,iPhone:1,iPod:1},Alcatel:{},Archos:{},Amazon:{Kindle:1,"Kindle Fire":1},Asus:{Transformer:1},"Barnes & Noble":{Nook:1},BlackBerry:{PlayBook:1},Google:{"Google TV":1,Nexus:1},HP:{TouchPad:1},HTC:{},Huawei:{},Lenovo:{},LG:{},Microsoft:{Xbox:1,"Xbox One":1},Motorola:{Xoom:1},Nintendo:{"Wii U":1,Wii:1},Nokia:{Lumia:1},Oppo:{},Samsung:{"Galaxy S":1,"Galaxy S2":1,"Galaxy S3":1,"Galaxy S4":1},Sony:{PlayStation:1,"PlayStation Vita":1},Xiaomi:{Mi:1,Redmi:1}}),F=function(e){return m(e,(function(e,n){var r=n.pattern||y(n);return!e&&(e=RegExp("\\b"+r+"(?:/[\\d.]+|[ \\w.]*)","i").exec(t))&&(e=function(e,t,n){var r={"10.0":"10",6.4:"10 Technical Preview",6.3:"8.1",6.2:"8",6.1:"Server 2008 R2 / 7","6.0":"Server 2008 / Vista",5.2:"Server 2003 / XP 64-bit",5.1:"XP",5.01:"2000 SP1","5.0":"2000","4.0":"NT","4.90":"ME"};return t&&n&&/^Win/i.test(e)&&!/^Windows Phone /i.test(e)&&(r=r[/[\d.]+$/.exec(e)])&&(e="Windows "+r),e=String(e),t&&n&&(e=e.replace(RegExp(t,"i"),n)),p(e.replace(/ ce$/i," CE").replace(/\bhpw/i,"web").replace(/\bMacintosh\b/,"Mac OS").replace(/_PowerPC\b/i," OS").replace(/\b(OS X) [^ \d]+/i,"$1").replace(/\bMac (OS X)\b/,"$1").replace(/\/(\d)/," $1").replace(/_/g,".").replace(/(?: BePC|[ .]*fc[ \d.]+)$/i,"").replace(/\bx86\.64\b/gi,"x86_64").replace(/\b(Windows Phone) OS\b/,"$1").replace(/\b(Chrome OS \w+) [\d.]+\b/,"$1").split(" on ")[0])}(e,r,n.label||n)),e}))}(["Windows Phone","KaiOS","Android","CentOS",{label:"Chrome OS",pattern:"CrOS"},"Debian",{label:"DragonFly BSD",pattern:"DragonFly"},"Fedora","FreeBSD","Gentoo","Haiku","Kubuntu","Linux Mint","OpenBSD","Red Hat","SuSE","Ubuntu","Xubuntu","Cygwin","Symbian OS","hpwOS","webOS ","webOS","Tablet OS","Tizen","Linux","Mac OS X","Macintosh","Mac","Windows 98;","Windows "]);function B(e){return m(e,(function(e,n){var r=n.pattern||y(n);return!e&&(e=RegExp("\\b"+r+" *\\d+[.\\w_]*","i").exec(t)||RegExp("\\b"+r+" *\\w+-[\\w]*","i").exec(t)||RegExp("\\b"+r+"(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)","i").exec(t))&&((e=String(n.label&&!RegExp(r,"i").test(n.label)?n.label:e).split("/"))[1]&&!/[\d.]+/.test(e[0])&&(e[0]+=" "+e[1]),n=n.label||n,e=p(e[0].replace(RegExp(r,"i"),n).replace(RegExp("; *(?:"+n+"[_-])?","i")," ").replace(RegExp("("+n+")[-_.]?(\\w)","i"),"$1 $2"))),e}))}function q(e){return m(e,(function(e,n){return e||(RegExp(n+"(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)","i").exec(t)||0)[1]||null}))}if(L&&(L=[L]),/\bAndroid\b/.test(F)&&!U&&(o=/\bAndroid[^;]*;(.*?)(?:Build|\) AppleWebKit)\b/i.exec(t))&&(U=g(o[1]).replace(/^[a-z]{2}-[a-z]{2};\s*/i,"")||null),D&&!U?U=B([D]):D&&U&&(U=U.replace(RegExp("^("+y(D)+")[-_.\\s]","i"),D+" ").replace(RegExp("^("+y(D)+")[-_.]?(\\w)","i"),D+" $2")),(o=/\bGoogle TV\b/.exec(U))&&(U=o[0]),/\bSimulator\b/i.test(t)&&(U=(U?U+" ":"")+"Simulator"),"Opera Mini"==N&&/\bOPiOS\b/.test(t)&&P.push("running in Turbo/Uncompressed mode"),"IE"==N&&/\blike iPhone OS\b/.test(t)?(D=(o=e(t.replace(/like iPhone OS/,""))).manufacturer,U=o.product):/^iP/.test(U)?(N||(N="Safari"),F="iOS"+((o=/ OS ([\d_]+)/i.exec(t))?" "+o[1].replace(/_/g,"."):"")):"Konqueror"==N&&/^Linux\b/i.test(F)?F="Kubuntu":D&&"Google"!=D&&(/Chrome/.test(N)&&!/\bMobile Safari\b/i.test(t)||/\bVita\b/.test(U))||/\bAndroid\b/.test(F)&&/^Chrome/.test(N)&&/\bVersion\//i.test(t)?(N="Android Browser",F=/\bAndroid\b/.test(F)?F:"Android"):"Silk"==N?(/\bMobi/i.test(t)||(F="Android",P.unshift("desktop mode")),/Accelerated *= *true/i.test(t)&&P.unshift("accelerated")):"UC Browser"==N&&/\bUCWEB\b/.test(t)?P.push("speed mode"):"PaleMoon"==N&&(o=/\bFirefox\/([\d.]+)\b/.exec(t))?P.push("identifying as Firefox "+o[1]):"Firefox"==N&&(o=/\b(Mobile|Tablet|TV)\b/i.exec(t))?(F||(F="Firefox OS"),U||(U=o[1])):!N||(o=!/\bMinefield\b/i.test(t)&&/\b(?:Firefox|Safari)\b/.exec(N))?(N&&!U&&/[\/,]|^[^(]+?\)/.test(t.slice(t.indexOf(o+"/")+8))&&(N=null),(o=U||D||F)&&(U||D||/\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(F))&&(N=/[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(F)?F:o)+" Browser")):"Electron"==N&&(o=(/\bChrome\/([\d.]+)\b/.exec(t)||0)[1])&&P.push("Chromium "+o),M||(M=q(["(?:Cloud9|CriOS|CrMo|Edge|Edg|EdgA|EdgiOS|FxiOS|HeadlessChrome|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$)|UCBrowser|YaBrowser)","Version",y(N),"(?:Firefox|Minefield|NetFront)"])),(o=("iCab"==L&&parseFloat(M)>3?"WebKit":/\bOpera\b/.test(N)&&(/\bOPR\b/.test(t)?"Blink":"Presto"))||/\b(?:Midori|Nook|Safari)\b/i.test(t)&&!/^(?:Trident|EdgeHTML)$/.test(L)&&"WebKit"||!L&&/\bMSIE\b/i.test(t)&&("Mac OS"==F?"Tasman":"Trident")||"WebKit"==L&&/\bPlayStation\b(?! Vita\b)/i.test(N)&&"NetFront")&&(L=[o]),"IE"==N&&(o=(/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(t)||0)[1])?(N+=" Mobile",F="Windows Phone "+(/\+$/.test(o)?o:o+".x"),P.unshift("desktop mode")):/\bWPDesktop\b/i.test(t)?(N="IE Mobile",F="Windows Phone 8.x",P.unshift("desktop mode"),M||(M=(/\brv:([\d.]+)/.exec(t)||0)[1])):"IE"!=N&&"Trident"==L&&(o=/\brv:([\d.]+)/.exec(t))&&(N&&P.push("identifying as "+N+(M?" "+M:"")),N="IE",M=o[1]),j){if(function(e,t){var n=null!=e?Ca(e[t]):"number";return!(/^(?:boolean|number|string|undefined)$/.test(n)||"object"==n&&!e[t])}(n,"global"))if(_&&(C=(o=_.lang.System).getProperty("os.arch"),F=F||o.getProperty("os.name")+" "+o.getProperty("os.version")),S){try{M=n.require("ringo/engine").version.join("."),N="RingoJS"}catch(e){(o=n.system)&&o.global.system==n.system&&(N="Narwhal",F||(F=o[0].os||null))}N||(N="Rhino")}else"object"==Ca(n.process)&&!n.process.browser&&(o=n.process)&&("object"==Ca(o.versions)&&("string"==typeof o.versions.electron?(P.push("Node "+o.versions.node),N="Electron",M=o.versions.electron):"string"==typeof o.versions.nw&&(P.push("Chromium "+M,"Node "+o.versions.node),N="NW.js",M=o.versions.nw)),N||(N="Node.js",C=o.arch,F=o.platform,M=(M=/[\d.]+/.exec(o.version))?M[0]:null));else v(o=n.runtime)==b?(N="Adobe AIR",F=o.flash.system.Capabilities.os):v(o=n.phantom)==x?(N="PhantomJS",M=(o=o.version||null)&&o.major+"."+o.minor+"."+o.patch):"number"==typeof R.documentMode&&(o=/\bTrident\/(\d+)/i.exec(t))?(M=[M,R.documentMode],(o=+o[1]+4)!=M[1]&&(P.push("IE "+M[1]+" mode"),L&&(L[1]=""),M[1]=o),M="IE"==N?String(M[1].toFixed(1)):M[0]):"number"==typeof R.documentMode&&/^(?:Chrome|Firefox)\b/.test(N)&&(P.push("masking as "+N+" "+M),N="IE",M="11.0",L=["Trident"],F="Windows");F=F&&p(F)}if(M&&(o=/(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(M)||/(?:alpha|beta)(?: ?\d)?/i.exec(t+";"+(j&&a.appMinorVersion))||/\bMinefield\b/i.test(t)&&"a")&&(A=/b/i.test(o)?"beta":"alpha",M=M.replace(RegExp(o+"\\+?$"),"")+("beta"==A?T:E)+(/\d+\+?/.exec(o)||"")),"Fennec"==N||"Firefox"==N&&/\b(?:Android|Firefox OS|KaiOS)\b/.test(F))N="Firefox Mobile";else if("Maxthon"==N&&M)M=M.replace(/\.[\d.]+/,".x");else if(/\bXbox\b/i.test(U))"Xbox 360"==U&&(F=null),"Xbox 360"==U&&/\bIEMobile\b/.test(t)&&P.unshift("mobile mode");else if(!/^(?:Chrome|IE|Opera)$/.test(N)&&(!N||U||/Browser|Mobi/.test(N))||"Windows CE"!=F&&!/Mobi/i.test(t))if("IE"==N&&j)try{null===n.external&&P.unshift("platform preview")}catch(e){P.unshift("embedded")}else(/\bBlackBerry\b/.test(U)||/\bBB10\b/.test(t))&&(o=(RegExp(U.replace(/ +/g," *")+"/([.\\d]+)","i").exec(t)||0)[1]||M)?(F=((o=[o,/BB10/.test(t)])[1]?(U=null,D="BlackBerry"):"Device Software")+" "+o[0],M=null):this!=h&&"Wii"!=U&&(j&&I||/Opera/.test(N)&&/\b(?:MSIE|Firefox)\b/i.test(t)||"Firefox"==N&&/\bOS X (?:\d+\.){2,}/.test(F)||"IE"==N&&(F&&!/^Win/.test(F)&&M>5.5||/\bWindows XP\b/.test(F)&&M>8||8==M&&!/\bTrident\b/.test(t)))&&!u.test(o=e.call(h,t.replace(u,"")+";"))&&o.name&&(o="ing as "+o.name+((o=o.version)?" "+o:""),u.test(N)?(/\bIE\b/.test(o)&&"Mac OS"==F&&(F=null),o="identify"+o):(o="mask"+o,N=O?p(O.replace(/([a-z])([A-Z])/g,"$1 $2")):"Opera",/\bIE\b/.test(o)&&(F=null),j||(M=null)),L=["Presto"],P.push(o));else N+=" Mobile";(o=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(t)||0)[1])&&(o=[parseFloat(o.replace(/\.(\d)$/,".0$1")),o],"Safari"==N&&"+"==o[1].slice(-1)?(N="WebKit Nightly",A="alpha",M=o[1].slice(0,-1)):M!=o[1]&&M!=(o[2]=(/\bSafari\/([\d.]+\+?)/i.exec(t)||0)[1])||(M=null),o[1]=(/\b(?:Headless)?Chrome\/([\d.]+)/i.exec(t)||0)[1],537.36==o[0]&&537.36==o[2]&&parseFloat(o[1])>=28&&"WebKit"==L&&(L=["Blink"]),j&&(l||o[1])?(L&&(L[1]="like Chrome"),o=o[1]||((o=o[0])<530?1:o<532?2:o<532.05?3:o<533?4:o<534.03?5:o<534.07?6:o<534.1?7:o<534.13?8:o<534.16?9:o<534.24?10:o<534.3?11:o<535.01?12:o<535.02?"13+":o<535.07?15:o<535.11?16:o<535.19?17:o<536.05?18:o<536.1?19:o<537.01?20:o<537.11?"21+":o<537.13?23:o<537.18?24:o<537.24?25:o<537.36?26:"Blink"!=L?"27":"28")):(L&&(L[1]="like Safari"),o=(o=o[0])<400?1:o<500?2:o<526?3:o<533?4:o<534?"4+":o<535?5:o<537?6:o<538?7:o<601?8:o<602?9:o<604?10:o<606?11:o<608?12:"12"),L&&(L[1]+=" "+(o+="number"==typeof o?".x":/[.+]/.test(o)?"":"+")),"Safari"==N&&(!M||parseInt(M)>45)?M=o:"Chrome"==N&&/\bHeadlessChrome/i.test(t)&&P.unshift("headless")),"Opera"==N&&(o=/\bzbov|zvav$/.exec(F))?(N+=" ",P.unshift("desktop mode"),"zvav"==o?(N+="Mini",M=null):N+="Mobile",F=F.replace(RegExp(" *"+o+"$"),"")):"Safari"==N&&/\bChrome\b/.exec(L&&L[1])?(P.unshift("desktop mode"),N="Chrome Mobile",M=null,/\bOS X\b/.test(F)?(D="Apple",F="iOS 4.3+"):F=null):/\bSRWare Iron\b/.test(N)&&!M&&(M=q("Chrome")),M&&0==M.indexOf(o=/[\d.]+$/.exec(F))&&t.indexOf("/"+o+"-")>-1&&(F=g(F.replace(o,""))),F&&-1!=F.indexOf(N)&&!RegExp(N+" OS").test(F)&&(F=F.replace(RegExp(" *"+y(N)+" *"),"")),L&&!/\b(?:Avant|Nook)\b/.test(N)&&(/Browser|Lunascape|Maxthon/.test(N)||"Safari"!=N&&/^iOS/.test(F)&&/\bSafari\b/.test(L[1])||/^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|SRWare Iron|Vivaldi|Web)/.test(N)&&L[1])&&(o=L[L.length-1])&&P.push(o),P.length&&(P=["("+P.join("; ")+")"]),D&&U&&U.indexOf(D)<0&&P.push("on "+D),U&&P.push((/^on /.test(P[P.length-1])?"":"on ")+U),F&&(o=/ ([\d.+]+)$/.exec(F),c=o&&"/"==F.charAt(F.length-o[0].length-1),F={architecture:32,family:o&&!c?F.replace(o[0],""):F,version:o?o[1]:null,toString:function(){var e=this.version;return this.family+(e&&!c?" "+e:"")+(64==this.architecture?" 64-bit":"")}}),(o=/\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(C))&&!/\bi686\b/i.test(C)?(F&&(F.architecture=64,F.family=F.family.replace(RegExp(" *"+o),"")),N&&(/\bWOW64\b/i.test(t)||j&&/\w(?:86|32)$/.test(a.cpuClass||a.platform)&&!/\bWin64; x64\b/i.test(t))&&P.unshift("32-bit")):F&&/^OS X/.test(F.family)&&"Chrome"==N&&parseFloat(M)>=39&&(F.architecture=64),t||(t=null);var W={};return W.description=t,W.layout=L&&L[0],W.manufacturer=D,W.name=N,W.prerelease=A,W.product=U,W.ua=t,W.version=N&&M,W.os=F||{architecture:null,family:null,version:null,toString:function(){return"null"}},W.parse=e,W.toString=function(){return this.description||""},W.version&&P.unshift(M),W.name&&P.unshift(N),F&&N&&(F!=String(F).split(" ")[0]||F!=N.split(" ")[0]&&!U)&&P.push(U?"("+F+")":"on "+F),P.length&&(W.description=P.join(" ")),W}();i&&a?h(b,(function(e,t){i[t]=e})):r.platform=b}).call(t)}(uE,uE.exports);var cE=De,lE=Ut,fE=gr,dE=k,pE=Sp,hE=Ap;xp("match",(function(e,t,n){return[function(t){var n=dE(this),r=null==t?void 0:t[e];return void 0!==r?r.call(t,n):new RegExp(t)[e](fE(n))},function(e){var r=cE(this),i=fE(e),a=n(t,r,i);if(a.done)return a.value;if(!r.global)return hE(r,i);var s=r.unicode;r.lastIndex=0;for(var o,u=[],c=0;null!==(o=hE(r,i));){var l=fE(o[0]);u[c]=l,""===l&&(r.lastIndex=pE(i,lE(r.lastIndex),s)),c++}return 0===c?null:u}]}));var vE=Object.is||function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t},yE=De,mE=k,gE=vE,bE=gr,kE=Ap;xp("search",(function(e,t,n){return[function(t){var n=mE(this),r=null==t?void 0:t[e];return void 0!==r?r.call(t,n):new RegExp(t)[e](bE(n))},function(e){var r=yE(this),i=bE(e),a=n(t,r,i);if(a.done)return a.value;var s=r.lastIndex;gE(s,0)||(r.lastIndex=0);var o=kE(r,i);return gE(r.lastIndex,s)||(r.lastIndex=s),null===o?-1:o.index}]}));var wE=In,xE=qt,_E=Mt,SE=Ut,EE=Q,TE=qr,RE=ga,IE=oa("splice"),OE=Math.max,CE=Math.min,PE=9007199254740991,AE="Maximum allowed length exceeded";wE({target:"Array",proto:!0,forced:!IE},{splice:function(e,t){var n,r,i,a,s,o,u=EE(this),c=SE(u.length),l=xE(e,c),f=arguments.length;if(0===f?n=r=0:1===f?(n=0,r=c-l):(n=f-2,r=CE(OE(_E(t),0),c-l)),c+n-r>PE)throw TypeError(AE);for(i=TE(u,r),a=0;a<r;a++)(s=l+a)in u&&RE(i,a,u[s]);if(i.length=r,n<r){for(a=l;a<c-r;a++)o=a+n,(s=a+r)in u?u[o]=u[s]:delete u[o];for(a=c;a>c-r+n;a--)delete u[a-1]}else if(n>r)for(a=c-r;a>l;a--)o=a+n-1,(s=a+r-1)in u?u[o]=u[s]:delete u[o];for(a=0;a<n;a++)u[a+l]=arguments[a+2];return u.length=c-r+n,i}}),function(e){var t=void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};Object.defineProperty(e,"__esModule",{value:!0});var n=Vg.exports,r=ag.exports,i=Kv.exports,a=$g.exports,s=Jv.exports,o=$v.exports,u=Hv.exports,c=Gv.exports,l=sg.exports,f=Hg,d=gv.exports,p=Jh,h=Xf.exports,v=sb.exports,y=Ob,m=iE.exports,g=ig,b=uE.exports;function k(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function w(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var x=k(n),_=k(r),S=k(i),E=k(a),T=k(s),R=k(o),I=k(u),O=k(c),C=k(l),P=k(f),A=k(d),j=w(h),M=w(v),L=k(m),N=w(b);function U(){}function D(){D.init.call(this)}function F(e){return void 0===e._maxListeners?D.defaultMaxListeners:e._maxListeners}function B(e,t,n){if(t)e.call(n);else for(var r=e.length,i=K(e,r),a=0;a<r;++a)i[a].call(n)}function q(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=K(e,i),s=0;s<i;++s)a[s].call(n,r)}function W(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=K(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function z(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=K(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function G(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=K(e,i),s=0;s<i;++s)a[s].apply(n,r)}function J(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new U,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=F(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function V(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function $(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function K(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}U.prototype=Object.create(null),D.EventEmitter=D,D.usingDomains=!1,D.prototype.domain=void 0,D.prototype._events=void 0,D.prototype._maxListeners=void 0,D.defaultMaxListeners=10,D.init=function(){this.domain=null,D.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new U,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},D.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},D.prototype.getMaxListeners=function(){return F(this)},D.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:B(n,l,this);break;case 2:q(n,l,this,arguments[1]);break;case 3:W(n,l,this,arguments[1],arguments[2]);break;case 4:z(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];G(n,l,this,i)}return!0},D.prototype.addListener=function(e,t){return J(this,e,t,!1)},D.prototype.on=D.prototype.addListener,D.prototype.prependListener=function(e,t){return J(this,e,t,!0)},D.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,V(this,e,t)),this},D.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,V(this,e,t)),this},D.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new U:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new U,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},D.prototype.off=function(e,t){return this.removeListener(e,t)},D.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new U,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new U:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new U,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},D.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},D.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):$.call(e,t)},D.prototype.listenerCount=$,D.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var H=j.getLogger("twilsock");function Y(e,t){return["".concat((new Date).toISOString()," Twilsock ").concat(e,":")].concat(Array.from(t))}var Q=new(function(){function e(t){O.default(this,e),C.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?" "+t+":":""}return _.default(e,[{key:"setLevel",value:function(e){H.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.trace.apply(null,Y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.debug.apply(null,Y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.info.apply(null,Y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.warn.apply(null,Y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.error.apply(null,Y("E",t))}}],[{key:"setLevel",value:function(e){H.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.trace.apply(null,Y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.debug.apply(null,Y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.info.apply(null,Y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.warn.apply(null,Y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.error.apply(null,Y("E",t))}}]),e}())(""),X="0.12.0-rc.1",Z=function(){function e(t,n,r){O.default(this,e),C.default(this,"confirmedCapabilities",new Set),this.activeGrant=n,this._token=t;var i=r.region||"us1",a="wss://tsock.".concat(i,".twilio.com/v3/wsconnect"),s=r.twilsock||r.Twilsock||{};this.url=s.uri||a,this._continuationToken=r.continuationToken?r.continuationToken:null,this.logLevel=r.logLevel?r.logLevel:"error",this.retryPolicy=r.retryPolicy?r.retryPolicy:{min:1e3,max:12e4,randomness:.2},this.clientMetadata=r.clientMetadata?r.clientMetadata:{},this.clientMetadata.ver=X,this.initRegistrations=r.initRegistrations?r.initRegistrations:null,this.tweaks=r.tweaks?r.tweaks:null}return _.default(e,[{key:"token",get:function(){return this._token}},{key:"continuationToken",get:function(){return this._continuationToken}},{key:"updateToken",value:function(e){this._token=e}},{key:"updateContinuationToken",value:function(e){this._continuationToken=e}}]),e}(),ee=function e(t){O.default(this,e),this.id=t||"TM".concat(y.v4())};function te(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var ne=function(e){T.default(n,e);var t=te(n);function n(e,r,i,a,s){var o;return O.default(this,n),o=t.call(this),C.default(S.default(o),"method","init"),o.token=e,o.continuation_token=r,o.metadata=i,o.registrations=a,o.tweaks=s,o.capabilities=["client_update","offline_storage","telemetry.v1"],o}return n}(ee);function re(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var ie=function(e){T.default(n,e);var t=re(n);function n(e,r,i,a,s,o,u){var c;return O.default(this,n),(c=t.call(this,e)).continuationToken=r,c.continuationTokenStatus=a,c.offlineStorage=s,c.initRegistrations=o,c.debugInfo=u,c.confirmedCapabilities=i,c}return n}(ee);function ae(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var se=function(e){T.default(n,e);var t=ae(n);function n(e){var r;return O.default(this,n),r=t.call(this),C.default(S.default(r),"method","update"),r.token=e,r}return n}(ee);function oe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Message=function(e){T.default(Message,e);var t=oe(Message);function Message(e,n,r){var i;return O.default(this,Message),i=t.call(this),C.default(S.default(i),"method","message"),i.active_grant=e,i.payload_type=n,i.http_request=r,i}return Message}(ee);function ue(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var ce=function(e){T.default(n,e);var t=ue(n);function n(e){var r;return O.default(this,n),r=t.call(this,e),C.default(S.default(r),"method","reply"),C.default(S.default(r),"payload_type","application/json"),C.default(S.default(r),"status",{code:200,status:"OK"}),r}return n}(ee);function le(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var fe=function(e){T.default(n,e);var t=le(n);function n(){var e;return O.default(this,n),e=t.call(this),C.default(S.default(e),"method","close"),e}return n}(ee);function de(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var pe=function e(t,n,r,i,a,s){O.default(this,e),this.start=t,this.end=n,this.title=r,this.details=i,this.id=a,this.type=s},he=function(e){T.default(n,e);var t=de(n);function n(e){var r;return O.default(this,n),r=t.call(this),C.default(S.default(r),"method","telemetry.v1"),r.events=e,r}return n}(ee);function ve(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})).length}function ye(e){var t=encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})),n=new Uint8Array(t.length);return Array.prototype.forEach.call(t,(function(e,t){n[t]=e.charCodeAt(0)})),n}function me(e){var t=Array.prototype.map.call(e,(function(e){return String.fromCharCode(e)})).join("").replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n}));return decodeURIComponent(t)}function ge(e){return JSON.parse(me(e))}var be=function(){function e(){O.default(this,e)}return _.default(e,null,[{key:"parse",value:function(e){var t,n,r=new Uint8Array(e),i=function(e){for(var t="",n=0;n<e.length;++n){var r=String.fromCharCode(e[n]);if(t+=r,"\r"===r){n+=2;break}}var i=t.split(" ");return{size:n,protocol:i[0],version:i[1],headerSize:Number(i[2])}}(r);if("TWILSOCK"!==i.protocol||"V3.0"!==i.version)return Q.error("unsupported protocol: ".concat(i.protocol," ver ").concat(i.version)),null;try{t=ge(r.subarray(i.size,i.size+i.headerSize))}catch(t){return Q.error("failed to parse message header",t,e),null}if(Q.debug("message received: ",t.method),Q.trace("message received: ",t),t.payload_size>0){var a=2+i.size+i.headerSize,s=t.payload_size;if(t.hasOwnProperty("payload_type")&&0!==t.payload_type.indexOf("application/json"))0===t.payload_type.indexOf("text/plain")&&(n=me(r.subarray(a,a+s)));else try{n=ge(r.subarray(a,a+s))}catch(t){return Q.error("failed to parse message body",t,e),null}}return{method:t.method,header:t,payload:n}}},{key:"createPacket",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";e.payload_size=ve(t);var n=JSON.stringify(e),r="TWILSOCK V3.0 "+ve(n);Q.debug("send request:",r+n+t);var i=ye(r+"\r\n"+n+"\r\n"+t);return i.buffer}}]),e}();function ke(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var we=function(e){T.default(n,e);var t=ke(n);function n(e){return O.default(this,n),t.call(this,e)}return n}(L.default(Error));function xe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var _e=function(e){T.default(n,e);var t=xe(n);function n(e,r){var i;return O.default(this,n),(i=t.call(this,e)).reply=r,i}return n}(we);function Se(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Ee(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Se(Object(n),!0).forEach((function(t){C.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Se(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Te(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Re=function(e){T.default(n,e);var t=Te(n);function n(e){var r;return O.default(this,n),r=t.call(this),C.default(S.default(r),"newBackoff",null),C.default(S.default(r),"usedBackoff",null),C.default(S.default(r),"retrier",null),r.options=e?Ee({},e):{},r}return _.default(n,[{key:"inProgress",get:function(){return!!this.retrier}},{key:"start",value:function(){if(this.inProgress)throw new Error("Already waiting for next attempt, call finishAttempt(success : boolean) to finish it");this.createRetrier()}},{key:"stop",value:function(){this.cleanRetrier(),this.newBackoff=null,this.usedBackoff=null}},{key:"modifyBackoff",value:function(e){this.newBackoff=e}},{key:"attemptFailed",value:function(){if(!this.inProgress)throw new Error("No attempt is in progress");var e,t;this.newBackoff?!this.usedBackoff||this.usedBackoff<this.newBackoff?this.createRetrier():null===(e=this.retrier)||void 0===e||e.failed(new Error):null===(t=this.retrier)||void 0===t||t.failed(new Error)}},{key:"cancel",value:function(){var e;null===(e=this.retrier)||void 0===e||e.cancel()}},{key:"cleanRetrier",value:function(){var e,t;null===(e=this.retrier)||void 0===e||e.removeAllListeners(),null===(t=this.retrier)||void 0===t||t.cancel(),this.retrier=null}},{key:"getRetryPolicy",value:function(){var e=Ee({},this.options);return this.newBackoff&&(e.min=this.newBackoff,e.max=this.options.max&&this.options.max>this.newBackoff?this.options.max:this.newBackoff),e.maxAttemptsCount=this.options.maxAttemptsCount?this.options.maxAttemptsCount+1:void 0,e}},{key:"createRetrier",value:function(){var e=this;this.cleanRetrier();var t=this.getRetryPolicy();this.retrier=new g.Retrier(t),this.retrier.once("attempt",(function(){var t,n;null===(t=e.retrier)||void 0===t||t.on("attempt",(function(){return e.emit("attempt")})),null===(n=e.retrier)||void 0===n||n.failed(new Error("Skipping first attempt"))})),this.retrier.on("failed",(function(t){return e.emit("failed",t)})),this.usedBackoff=this.newBackoff,this.newBackoff=null,this.retrier.start()}}]),n}(D);function Ie(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Oe=function(e){T.default(i,e);var t,n,r=Ie(i);function i(e,t,n){var a;O.default(this,i),a=r.call(this),C.default(S.default(a),"disconnectingTimer",null),C.default(S.default(a),"disconnectedPromiseResolve",null),C.default(S.default(a),"terminalStates",["disconnected","rejected"]),C.default(S.default(a),"tokenExpiredSasCode",20104),C.default(S.default(a),"terminationReason","Connection is not initialized"),a.websocket=e,a.websocket.on("connected",(function(){return a.fsm.socketConnected()})),a.websocket.on("disconnected",(function(){return a.fsm.socketClosed()})),a.websocket.on("message",(function(e){return a.onIncomingMessage(e)})),a.websocket.on("socketError",(function(e){return a.emit("connectionError",{terminal:!1,message:"Socket error: ".concat(e.message),httpStatusCode:null,errorCode:null})})),a.transport=t,a.config=n,a.retrier=new Re(n.retryPolicy),a.retrier.on("attempt",(function(){return a.retry()})),a.retrier.on("failed",(function(e){Q.warn("Retrying failed: ".concat(e.message)),a.disconnect()})),"undefined"!=typeof window&&void 0!==window.addEventListener&&(window.addEventListener("online",(function(){Q.debug("Browser reported connectivity state: online"),a.resetBackoff(),a.fsm.systemOnline()})),window.addEventListener("offline",(function(){Q.debug("Browser reported connectivity state: offline"),a.websocket.close(),a.fsm.socketClosed()})));var s=M.factory({init:"disconnected",transitions:[{name:"userConnect",from:["disconnected","rejected"],to:"connecting"},{name:"userConnect",from:["connecting","connected"]},{name:"userDisconnect",from:["connecting","initialising","connected","updating","retrying","rejected","waitSocketClosed","waitOffloadSocketClosed"],to:"disconnecting"},{name:"userRetry",from:["retrying"],to:"connecting"},{name:"socketConnected",from:["connecting"],to:"initialising"},{name:"socketClosed",from:["connecting","initialising","connected","updating","error","waitOffloadSocketClosed"],to:"retrying"},{name:"socketClosed",from:["disconnecting"],to:"disconnected"},{name:"socketClosed",from:["waitSocketClosed"],to:"disconnected"},{name:"socketClosed",from:["rejected"],to:"rejected"},{name:"initSuccess",from:["initialising"],to:"connected"},{name:"initError",from:["initialising"],to:"error"},{name:"tokenRejected",from:["initialising","updating"],to:"rejected"},{name:"protocolError",from:["initialising","connected","updating"],to:"error"},{name:"receiveClose",from:["initialising","connected","updating"],to:"waitSocketClosed"},{name:"receiveOffload",from:["initialising","connected","updating"],to:"waitOffloadSocketClosed"},{name:"unsupportedProtocol",from:["initialising","connected","updating"],to:"unsupported"},{name:"receiveFatalClose",from:["initialising","connected","updating"],to:"unsupported"},{name:"userUpdateToken",from:["disconnected","rejected","connecting","retrying"],to:"connecting"},{name:"userUpdateToken",from:["connected"],to:"updating"},{name:"updateSuccess",from:["updating"],to:"connected"},{name:"updateError",from:["updating"],to:"error"},{name:"userSend",from:["connected"],to:"connected"},{name:"systemOnline",from:["retrying"],to:"connecting"}],methods:{onConnecting:function(){a.setupSocket(),a.emit("connecting")},onEnterInitialising:function(){a.sendInit()},onLeaveInitialising:function(){a.cancelInit()},onEnterUpdating:function(){a.sendUpdate()},onLeaveUpdating:function(){a.cancelUpdate()},onEnterRetrying:function(){a.initRetry(),a.emit("connecting")},onEnterConnected:function(){a.resetBackoff(),a.onConnected()},onUserUpdateToken:function(){a.resetBackoff()},onTokenRejected:function(){a.resetBackoff(),a.closeSocket(!0),a.finalizeSocket()},onUserDisconnect:function(){a.closeSocket(!0)},onEnterDisconnecting:function(){a.startDisconnectTimer()},onLeaveDisconnecting:function(){a.cancelDisconnectTimer()},onEnterWaitSocketClosed:function(){a.startDisconnectTimer()},onLeaveWaitSocketClosed:function(){a.cancelDisconnectTimer()},onEnterWaitOffloadSocketClosed:function(){a.startDisconnectTimer()},onLeaveWaitOffloadSocketClosed:function(){a.cancelDisconnectTimer()},onDisconnected:function(){a.resetBackoff(),a.finalizeSocket()},onReceiveClose:function(){a.onCloseReceived()},onReceiveOffload:function(e,t){Q.debug("onreceiveoffload: ",t),a.modifyBackoff(t.body),a.onCloseReceived()},onUnsupported:function(){a.closeSocket(!0),a.finalizeSocket()},onError:function(e,t){a.closeSocket(t),a.finalizeSocket()},onEnterState:function(e){"none"!==e.from&&a.changeState(e)},onInvalidTransition:function(e,t,n){Q.warn("FSM: unexpected transition",t,n)}}});return a.fsm=new s,a}return _.default(i,[{key:"changeState",value:function(e){Q.debug("FSM: ".concat(e.transition,": ").concat(e.from," --\x3e ").concat(e.to)),this.lastEmittedState!==this.state&&(this.lastEmittedState=this.state,this.emit("stateChanged",this.state))}},{key:"resetBackoff",value:function(){Q.trace("resetBackoff"),this.retrier.stop()}},{key:"modifyBackoff",value:function(e){Q.trace("modifyBackoff",e);var t=e?e.backoff_policy:null;t&&"number"==typeof t.reconnect_min_ms&&this.retrier.modifyBackoff(t.reconnect_min_ms)}},{key:"startDisconnectTimer",value:function(){var e=this;Q.trace("startDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null),this.disconnectingTimer=setTimeout((function(){Q.debug("disconnecting is timed out"),e.closeSocket(!0)}),3e3)}},{key:"cancelDisconnectTimer",value:function(){Q.trace("cancelDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null)}},{key:"isConnected",get:function(){return"connected"===this.state&&this.websocket.isConnected}},{key:"state",get:function(){switch(this.fsm.state){case"connecting":case"initialising":case"retrying":case"error":return"connecting";case"updating":case"connected":return"connected";case"rejected":return"denied";case"disconnecting":case"waitSocketClosed":case"waitOffloadSocketClosed":return"disconnecting";case"disconnected":default:return"disconnected"}}},{key:"initRetry",value:function(){Q.debug("initRetry"),this.retrier.inProgress?this.retrier.attemptFailed():this.retrier.start()}},{key:"retry",value:function(){"connecting"!=this.fsm.state?(Q.trace("retry"),this.websocket.close(),this.fsm.userRetry()):Q.trace("can\t retry as already connecting")}},{key:"onConnected",value:function(){this.emit("connected")}},{key:"finalizeSocket",value:function(){Q.trace("finalizeSocket"),this.websocket.close(),this.emit("disconnected"),this.disconnectedPromiseResolve&&(this.disconnectedPromiseResolve(),this.disconnectedPromiseResolve=null)}},{key:"setupSocket",value:function(){Q.trace("setupSocket:",this.config.token),this.emit("beforeConnect"),this.websocket.connect()}},{key:"onIncomingMessage",value:function(e){var t=be.parse(e);if(t){var n=t.method,r=t.header,i=t.payload;if("reply"!==n&&this.confirmReceiving(r),"notification"===n)this.emit("message",r.message_type,i);else if("reply"===r.method)this.transport.processReply({id:r.id,status:r.status,header:r,body:i});else if("client_update"===r.method)"token_about_to_expire"===r.client_update_type&&this.emit("tokenAboutToExpire");else if("close"===r.method)if(308===r.status.code)Q.debug("Connection has been offloaded"),this.fsm.receiveOffload({status:r.status.status,body:i});else if(406===r.status.code){var a="Server closed connection because can't parse protocol: ".concat(JSON.stringify(r.status));this.emitReplyConnectionError(a,r,!0),Q.error(a),this.fsm.receiveFatalClose()}else 417===r.status.code?(Q.error("Server closed connection because can't parse client reply: ".concat(JSON.stringify(r.status))),this.fsm.receiveFatalClose(r.status.status)):410===r.status.code?(Q.warn("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status),this.emit("tokenExpired")):401===r.status.code?(Q.error("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status)):(Q.warn("unexpected message: ",r.status),this.fsm.receiveOffload({status:r.status.status,body:null}))}}},{key:"sendInit",value:(n=x.default(P.default.mark((function e(){var t,n;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("sendInit"),e.prev=1,this.emit("beforeSendInit"),e.next=5,this.transport.sendInit();case 5:t=e.sent,this.config.updateContinuationToken(t.continuationToken),this.config.confirmedCapabilities=t.confirmedCapabilities,this.fsm.initSuccess(t),this.emit("initialized",t),this.emit("tokenUpdated"),e.next=17;break;case 13:e.prev=13,e.t0=e.catch(1),e.t0 instanceof _e?(n=!1,Q.warn("Init rejected by server: ".concat(JSON.stringify(e.t0.reply.status))),this.emit("sendInitFailed"),401===e.t0.reply.status.code||403===e.t0.reply.status.code?(n=!0,this.fsm.tokenRejected(e.t0.reply.status),e.t0.reply.status.errorCode===this.tokenExpiredSasCode&&this.emit("tokenExpired")):429===e.t0.reply.status.code?(this.modifyBackoff(e.t0.reply.body),this.fsm.initError(!0)):500===e.t0.reply.status.code?this.fsm.initError(!1):this.fsm.initError(!0),this.emitReplyConnectionError(e.t0.message,e.t0.reply,n)):(this.terminationReason=e.t0.message,this.emit("connectionError",{terminal:!0,message:"Unknown error during connection initialisation: ".concat(e.t0.message,"\n").concat(JSON.stringify(e.t0,null,2)),httpStatusCode:null,errorCode:null}),this.fsm.initError(!0)),this.emit("tokenUpdated",e.t0);case 17:case"end":return e.stop()}}),e,this,[[1,13]])}))),function(){return n.apply(this,arguments)})},{key:"sendUpdate",value:(t=x.default(P.default.mark((function e(){var t,n,r;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("sendUpdate"),t=new se(this.config.token),e.prev=2,e.next=5,this.transport.sendWithReply(t);case 5:n=e.sent,this.fsm.updateSuccess(n.body),this.emit("tokenUpdated"),e.next=14;break;case 10:e.prev=10,e.t0=e.catch(2),e.t0 instanceof _e?(r=!1,Q.warn("Token update rejected by server: ".concat(JSON.stringify(e.t0.reply.status))),401===e.t0.reply.status.code||403===e.t0.reply.status.code?(r=!0,this.fsm.tokenRejected(e.t0.reply.status),e.t0.reply.status.errorCode===this.tokenExpiredSasCode&&this.emit("tokenExpired")):429===e.t0.reply.status.code?(this.modifyBackoff(e.t0.reply.body),this.fsm.updateError(e.t0.reply.status)):this.fsm.updateError(e.t0.reply.status),this.emitReplyConnectionError(e.t0.message,e.t0.reply,r)):(this.emit("error",!1,e.t0.message,null,null),this.fsm.updateError(e.t0)),this.emit("tokenUpdated",e.t0);case 14:case"end":return e.stop()}}),e,this,[[2,10]])}))),function(){return t.apply(this,arguments)})},{key:"emitReplyConnectionError",value:function(e,t,n){var r=t.status&&t.status.description?t.status.description:e,i=t.status.code,a=t.status&&t.status.errorCode?t.status.errorCode:null;n&&(this.terminationReason=r),this.emit("connectionError",{terminal:n,message:"Connection error: ".concat(r),httpStatusCode:i,errorCode:a})}},{key:"cancelInit",value:function(){Q.trace("cancelInit")}},{key:"cancelUpdate",value:function(){Q.trace("cancelUpdate")}},{key:"confirmReceiving",value:function(e){Q.trace("confirmReceiving");try{this.transport.send(new ce(e.id))}catch(e){Q.debug("failed to confirm packet receiving",e)}}},{key:"closeSocket",value:function(e){var t=this;Q.trace("closeSocket (graceful: ".concat(e,")")),e&&this.transport.isConnected&&this.transport.sendClose(),this.websocket.close(),setTimeout((function(){return t.fsm.socketClosed()}),0)}},{key:"connect",value:function(){Q.trace("connect"),this.fsm.userConnect()}},{key:"disconnect",value:function(){var e=this;return Q.trace("disconnect"),this.fsm.is("disconnected")?Promise.resolve():new Promise((function(t){e.disconnectedPromiseResolve=t,e.fsm.userDisconnect()}))}},{key:"updateToken",value:function(e){var t=this;return Q.trace("updateToken:",e),new Promise((function(e,n){t.once("tokenUpdated",(function(t){t?n(t):e()})),t.fsm.userUpdateToken()}))}},{key:"isTerminalState",get:function(){return-1!==this.terminalStates.indexOf(this.fsm.state)}},{key:"getTerminationReason",get:function(){return this.terminationReason}},{key:"onCloseReceived",value:function(){this.websocket.close()}}]),i}(D),Ce=function(){function e(){O.default(this,e)}return _.default(e,null,[{key:"getMetadata",value:function(e){var t,n,r,i,a,s,o,u,c=e&&e.clientMetadata?e.clientMetadata:{},l={env:null!==(t=N.name)&&void 0!==t?t:"unknown",envv:null!==(n=N.version)&&void 0!==n?n:"unknown",os:null!==(r=null===(i=N.os)||void 0===i?void 0:i.family)&&void 0!==r?r:"unknown",osv:null!==(a=null===(s=N.os)||void 0===s?void 0:s.version)&&void 0!==a?a:"unknown",osa:null!==(o=null===(u=N.os)||void 0===u?void 0:u.architecture)&&void 0!==o?o:"unknown",sdk:"js-default"},f={};return["ver","env","envv","os","osv","osa","type","sdk","sdkv","dev","devv","devt","app","appv"].filter((function(e){return e in c||e in l})).forEach((function(e){return f[e]=e in c?c[e]:l[e]})),f}}]),e}();var Pe=function(){function e(t,n){var r=this;O.default(this,e),this.config=n,this.activeRequests=new Map,this.channel=t,this.channel.on("reply",(function(e){return r.processReply(e)})),this.channel.on("disconnected",(function(){r.activeRequests.forEach((function(e){clearTimeout(e.timeout),e.reject(new we("disconnected"))})),r.activeRequests.clear()}))}var t;return _.default(e,[{key:"isConnected",get:function(){return this.channel.isConnected}},{key:"processReply",value:function(e){var t,n=this.activeRequests.get(e.id);n&&(clearTimeout(n.timeout),this.activeRequests.delete(e.id),(t=e.status.code)>=200&&t<300?n.resolve(e):(n.reject(new _e("Transport failure: "+e.status.status,e)),Q.trace("message rejected")))}},{key:"storeRequest",value:function(e,t,n){var r={resolve:t,reject:n,timeout:setTimeout((function(){Q.trace("request",e,"is timed out"),n(new we("Twilsock: request timeout: "+e))}),3e4)};this.activeRequests.set(e,r)}},{key:"shutdown",value:function(){this.activeRequests.forEach((function(e){clearTimeout(e.timeout),e.reject(new we("Twilsock: request cancelled by user"))})),this.activeRequests.clear()}},{key:"sendInit",value:(t=x.default(P.default.mark((function e(){var t,n,r;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("sendInit"),t=Ce.getMetadata(this.config),n=new ne(this.config.token,this.config.continuationToken,t,this.config.initRegistrations,this.config.tweaks),e.next=5,this.sendWithReply(n);case 5:return r=e.sent,e.abrupt("return",new ie(r.id,r.header.continuation_token,new Set(r.header.capabilities),r.header.continuation_token_status,r.header.offline_storage,r.header.init_registrations,r.header.debug_info));case 7:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"sendClose",value:function(){var e=new fe;this.send(e)}},{key:"sendWithReply",value:function(e,t){var n=this;return new Promise((function(r,i){var a=n.send(e,t);n.storeRequest(a,r,i)}))}},{key:"send",value:function(e,t){e.id=e.id||"TM".concat(y.v4());var n=be.createPacket(e,function(e){switch(A.default(e)){case"undefined":return"";case"object":return JSON.stringify(e);default:return e}}(t));try{return this.channel.send(n),e.id}catch(t){throw Q.debug("failed to send ",e,t),Q.trace(t.stack),t}}}]),e}();function Ae(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var je=function(e){T.default(r,e);var n=Ae(r);function r(e){var i;return O.default(this,r),i=n.call(this),C.default(S.default(i),"socket",null),i.url=e,i.url=e,i.WebSocket=t.WebSocket||t.MozWebSocket||{},i}return _.default(r,[{key:"isConnected",get:function(){return!!this.socket&&1===this.socket.readyState}},{key:"connect",value:function(){var e,t=this;Q.trace("connecting to socket");try{e=new this.WebSocket(this.url)}catch(e){return Q.debug("Socket error: ".concat(this.url)),void this.emit("socketError",e)}e.binaryType="arraybuffer",e.onopen=function(){Q.debug("socket opened ".concat(t.url)),t.emit("connected")},e.onclose=function(e){Q.debug("socket closed",e),t.emit("disconnected",e)},e.onerror=function(e){Q.debug("Socket error:",e),t.emit("socketError",e)},e.onmessage=function(e){t.emit("message",e.data)},this.socket=e}},{key:"send",value:function(e){return this.socket&&this.socket.send(e)}},{key:"close",value:function(){if(Q.trace("closing socket"),this.socket){this.socket.onopen=null,this.socket.onclose=null,this.socket.onerror=null,this.socket.onmessage=null;try{this.socket.close()}finally{}}}}]),r}(D);function Me(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Le=function(e){T.default(u,e);var t,n,r,i,a,s,o=Me(u);function u(e){var t;return O.default(this,u),(t=o.call(this)).transport=e,t.registrations=new Map,t.registrationsInProgress=new Map,t}return _.default(u,[{key:"putNotificationContext",value:(s=x.default(P.default.mark((function e(t,n){var r;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={method:"put_notification_ctx",notification_ctx_id:t},e.next=3,this.transport.sendWithReply(r,n);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return s.apply(this,arguments)})},{key:"deleteNotificationContext",value:(a=x.default(P.default.mark((function e(t){var n;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={method:"delete_notification_ctx",notification_ctx_id:t},e.next=3,this.transport.sendWithReply(n);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"updateRegistration",value:(i=x.default(P.default.mark((function e(t,n){var r,i;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.debug("update registration for context",t),(r=this.registrationsInProgress.get(t))||(r=new Set,this.registrationsInProgress.set(t,r)),i=y.v4(),r.add(i),e.prev=5,e.next=8,this.putNotificationContext(t,n);case 8:Q.debug("registration attempt succeeded for context",n),r.delete(i),0===r.size&&(this.registrationsInProgress.delete(t),this.emit("registered",t)),e.next=19;break;case 13:e.prev=13,e.t0=e.catch(5),Q.warn("registration attempt failed for context",n),Q.debug(e.t0),r.delete(i),0===r.size&&(this.registrationsInProgress.delete(t),this.emit("registrationFailed",t,e.t0));case 19:case"end":return e.stop()}}),e,this,[[5,13]])}))),function(e,t){return i.apply(this,arguments)})},{key:"updateRegistrations",value:(r=x.default(P.default.mark((function e(){var t,n=this;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("refreshing ".concat(this.registrations.size," registrations")),t=[],this.registrations.forEach((function(e,r){t.push(n.updateRegistration(r,e))})),e.next=5,Promise.all(t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"setNotificationsContext",value:(n=x.default(P.default.mark((function e(t,n){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t&&n){e.next=2;break}throw new we("Invalid arguments provided");case 2:return this.registrations.set(t,n),e.next=5,this.updateRegistration(t,n);case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeNotificationsContext",value:(t=x.default(P.default.mark((function e(t){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.registrations.has(t)){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.deleteNotificationContext(t);case 4:this.transport.isConnected&&this.registrations.delete(t);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),u}(D);function Ne(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Ue=function(e){T.default(n,e);var t=Ne(n);function n(e,r,i){var a;return O.default(this,n),(a=t.call(this,r)).status=e,a.description=r,a.body=i,a}return n}(we);function De(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Fe=function(e){T.default(n,e);var t=De(n);function n(e){return O.default(this,n),t.call(this,e)}return n}(we);function Be(e,t){var n=function(e){var t=e.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)(\/[^?#]*)(\?[^#]*|)(#.*|)$/);if(t){var n={protocol:t[1],host:t[2],hostname:t[3],port:t[4],pathname:t[5],search:t[6],hash:t[7],params:{}};if(n.search.length>0){var r=n.search.substring(1);n.params=r.split("&").map((function(e){return e.split("=")})).reduce((function(e,t){return e.hasOwnProperty(t[0])?Array.isArray(e[t[0]])?e[t[0]].push(t[1]):e[t[0]]=[e[t[0]],t[1]]:e[t[0]]=t[1],e}),{})}return n}throw new we("Incorrect URI: "+e)}(t),r={method:e,host:n.host,path:n.pathname};return n.params&&(r.params=n.params),r}function qe(e,t,n,r,i){return{to:Be(e,t),headers:n,body:r,grant:i}}var We=function(){function e(t,n,r){O.default(this,e),this.config=r,this.transport=t,this.pendingMessages=[],this.twilsock=n}var t;return _.default(e,[{key:"saveMessage",value:function(e){var t=this;return new Promise((function(n,r){var i={message:e,resolve:n,reject:r,alreadyRejected:!1,timeout:setTimeout((function(){Q.debug("request is timed out"),r(new we("request '".concat(e.to.method,"' to '").concat(e.to.host,"' timed out"))),i.alreadyRejected=!0}),2e4)};t.pendingMessages.push(i)}))}},{key:"sendPendingMessages",value:function(){for(var e=this,t=function(){var t=e.pendingMessages[0];if(!t.alreadyRejected)try{var n=t.message;e.actualSend(n).then((function(e){return t.resolve(e)})).catch((function(e){return t.reject(e)})),clearTimeout(t.timeout)}catch(e){return Q.debug("Failed to send pending message",e),"break"}e.pendingMessages.splice(0,1)};this.pendingMessages.length>0;){if("break"===t())break}}},{key:"rejectPendingMessages",value:function(){var e=this;this.pendingMessages.forEach((function(t){t.reject(new Fe("Unable to connect: "+e.twilsock.getTerminationReason)),t.alreadyRejected=!0,clearTimeout(t.timeout)})),this.pendingMessages.splice(0,this.pendingMessages.length)}},{key:"actualSend",value:(t=x.default(P.default.mark((function e(t){var n,r,i,a,s,o,u,c;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.to,i=t.headers,a=t.body,s=null!==(n=t.grant)&&void 0!==n?n:this.config.activeGrant,o={host:r.host,path:r.path,method:r.method,params:r.params,headers:i},u=new Message(s,i["Content-Type"]||"application/json",o),Q.trace("Sending upstream message",u),e.next=9,this.transport.sendWithReply(u,a);case 9:if(c=e.sent,Q.trace("Received upstream message response",c),!((f=c)&&f.header&&f.header.http_status)||(l=c.header.http_status.code)>=200&&l<300){e.next=13;break}throw new Ue(c.header.http_status.code,c.header.http_status.status,c.body);case 13:return e.abrupt("return",{status:c.header.http_status,headers:c.header.http_headers,body:c.body});case 14:case"end":return e.stop()}var l,f}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"send",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;if(this.twilsock.isTerminalState)return Promise.reject(new Fe("Unable to connect: "+this.twilsock.getTerminationReason));var a=qe(e,t,n,r,i);return this.twilsock.isConnected?this.actualSend(a):this.saveMessage(a)}}]),e}(),ze=function(){function e(){var t=this;O.default(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return _.default(e,[{key:"promise",get:function(){return this._promise}},{key:"update",value:function(e){this._resolve(e)}},{key:"set",value:function(e){this._resolve(e)}},{key:"fail",value:function(e){this._reject(e)}}]),e}(),Ge=function(){function e(t){O.default(this,e),this.id=t}return _.default(e,null,[{key:"create",value:function(t){if(t instanceof Object&&"storage_id"in t)return new e(t.storage_id);throw new we('Field "storage_id" is missing')}}]),e}(),Je=function(){function e(){return O.default(this,e),C.default(this,"initializedFlag","twilio_twilsock_token_storage"),C.default(this,"tokenStoragePrefix","twilio_continuation_token_"),e._instance||(this.initialize(),e._instance=this),e._instance}return _.default(e,[{key:"sessionStorage",value:function(){try{return t.sessionStorage}catch(e){return null}}},{key:"window",value:function(){try{return t.window}catch(e){return null}}},{key:"storeToken",value:function(e,t){this.canStore()&&this.sessionStorage.setItem(this.getKeyName(t),e)}},{key:"getStoredToken",value:function(e){return this.canStore()?this.sessionStorage.getItem(this.getKeyName(e)):null}},{key:"initialize",value:function(){var e=this;if(this.canStore()){this.sessionStorage.getItem(this.initializedFlag)&&this.clear(),this.sessionStorage.setItem(this.initializedFlag,"true");var t=this.sessionStorage.removeItem;this.window.addEventListener("unload",(function(){t(e.initializedFlag)}))}}},{key:"clear",value:function(){if(this.canStore()){for(var e=[],t=0;t<this.sessionStorage.length;t++){var n=this.sessionStorage.key(t);n&&0===n.indexOf(this.tokenStoragePrefix)&&e.push(n)}var r=this.sessionStorage.removeItem;e.forEach((function(e){return r(e)})),r(this.initializedFlag)}}},{key:"getKeyName",value:function(e){return"".concat(this.tokenStoragePrefix).concat(e)}},{key:"canStore",value:function(){return!!(this.sessionStorage&&this.sessionStorage.length&&this.window)}}]),e}();C.default(Je,"_instance",null);var Ve,$e,Ke=new Je,He=function(){function e(t,n,r,i,a,s){O.default(this,e),this.title=t,this.details=n,this.start=r,this.type=a,this.id=s,this.end=i}return _.default(e,[{key:"toTelemetryEvent",value:function(){var e=new Date,t=this.start,n=this.end?this.end:e;if(n<t){var r=n;n=t,t=r}var i=t.getTime()-e.getTime(),a=n.getTime()-e.getTime();return new pe(i,a,this.title,this.details,this.id,this.type)}}]),e}();e.TelemetryPoint=void 0,(Ve=e.TelemetryPoint||(e.TelemetryPoint={}))[Ve.Start=0]="Start",Ve[Ve.End=1]="End",e.EventSendingLimitation=void 0,($e=e.EventSendingLimitation||(e.EventSendingLimitation={}))[$e.MinEventsPortion=0]="MinEventsPortion",$e[$e.AnyEvents=1]="AnyEvents",$e[$e.AnyEventsIncludingUnfinished=2]="AnyEventsIncludingUnfinished";var Ye=function(){function t(e,n){O.default(this,t),C.default(this,"minEventsPortionToSend",50),C.default(this,"maxEventsPortionToSend",100),C.default(this,"pendingEvents",new Map),C.default(this,"readyEvents",[]),C.default(this,"hasInitializationFinished",!1),C.default(this,"_canSendTelemetry",!1),this.config=e,this.packetInterface=n}return _.default(t,[{key:"isTelemetryEnabled",get:function(){return this.config.confirmedCapabilities.has("telemetry.v1")}},{key:"canSendTelemetry",get:function(){return this._canSendTelemetry&&this.isTelemetryEnabled},set:function(t){Q.debug("TelemetryTracker.canSendTelemetry: ".concat(t," TelemetryTracker.isTelemetryEnabled: ").concat(this.isTelemetryEnabled)),this._canSendTelemetry&&!t&&(this.pendingEvents.clear(),this.readyEvents=[]),this._canSendTelemetry=t,t&&this.sendTelemetry(e.EventSendingLimitation.AnyEvents),t&&!this.hasInitializationFinished&&(this.hasInitializationFinished=!0)}},{key:"addTelemetryEvent",value:function(e){!this.canSendTelemetry&&this.hasInitializationFinished||this.readyEvents.push(e)}},{key:"addPartialEvent",value:function(t,n,r){Q.debug("Adding ".concat(r===e.TelemetryPoint.Start?"starting":"ending"," timepoint for '").concat(n,"' event"));var i=this.pendingEvents.has(n);if(r===e.TelemetryPoint.Start)i&&Q.debug("Overwriting starting point for '".concat(n,"' event")),this.pendingEvents.set(n,t);else{if(!i)return void Q.info("Could not find started event for '".concat(n,"' event"));this.addTelemetryEvent(this.merge(this.pendingEvents.get(n),t)),this.pendingEvents.delete(n)}}},{key:"getTelemetryToSend",value:function(t){return this.canSendTelemetry&&0!=this.readyEvents.length?t==e.EventSendingLimitation.MinEventsPortion&&this.readyEvents.length<this.minEventsPortionToSend?[]:this.getTelemetryPortion(t==e.EventSendingLimitation.AnyEventsIncludingUnfinished):[]}},{key:"getTelemetryPortion",value:function(e){var t=this,n=Math.min(this.readyEvents.length,this.maxEventsPortionToSend),r=this.readyEvents.splice(0,n);return e&&r.length<this.maxEventsPortionToSend&&this.pendingEvents.forEach((function(e,n){if(!(r.length>=t.maxEventsPortionToSend)){var i=t.pendingEvents.get(n);t.pendingEvents.delete(n),r.push(new He("[UNFINISHED] ".concat(i.title),i.details,i.start,null,i.type,i.id))}})),r}},{key:"merge",value:function(e,t){return new He(t.title?t.title:e.title,t.details?t.details:e.details,e.start,t.end,t.type?t.type:e.type,t.id?t.id:e.id)}},{key:"sendTelemetryIfMinimalPortionCollected",value:function(){this.sendTelemetry(e.EventSendingLimitation.MinEventsPortion)}},{key:"sendTelemetry",value:function(e){var t=this.getTelemetryToSend(e);if(0!==t.length)try{this.packetInterface.send(new he(t.map((function(e){return e.toTelemetryEvent()}))))}catch(e){Q.debug("Error while sending ".concat(t.length," telemetry events due to ").concat(e,"; they will be resubmitted")),this.readyEvents=this.readyEvents.concat(t)}}}]),t}();function Qe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Xe=function e(){O.default(this,e)};C.default(Xe,"TWILSOCK_CONNECT","twilsock.sdk.connect"),C.default(Xe,"TWILSOCK_INIT","twilsock.sdk.init"),e.TwilsockClient=function(t){T.default(f,t);var n,r,i,a,s,o,u,c,l=Qe(f);function f(t,n,r){var i;O.default(this,f),i=l.call(this),C.default(S.default(i),"version",X),C.default(S.default(i),"offlineStorageDeferred",new ze),r.continuationToken=r.continuationToken?r.continuationToken:Ke.getStoredToken(n);var a=i.config=new Z(t,n,r);Q.setLevel(a.logLevel);var s=new je(a.url),o=new Pe(s,a);return i.channel=new Oe(s,o,a),i.registrations=new Le(o),i.upstream=new We(o,i.channel,a),i.telemetryTracker=new Ye(a,o),i.channel.on("initialized",(function(){return i.telemetryTracker.canSendTelemetry=!0})),s.on("disconnected",(function(){return i.telemetryTracker.canSendTelemetry=!1})),i.registrations.on("registered",(function(e){return i.emit("registered",e)})),i.channel.on("message",(function(e,t){return setTimeout((function(){return i.emit("message",e,t)}),0)})),i.channel.on("stateChanged",(function(e){return setTimeout((function(){return i.emit("stateChanged",e)}),0)})),i.channel.on("connectionError",(function(e){return setTimeout((function(){return i.emit("connectionError",e)}),0)})),i.channel.on("tokenAboutToExpire",(function(){return setTimeout((function(){return i.emit("tokenAboutToExpire")}),0)})),i.channel.on("tokenExpired",(function(){return setTimeout((function(){return i.emit("tokenExpired")}),0)})),i.channel.on("connected",(function(){return i.registrations.updateRegistrations()})),i.channel.on("connected",(function(){return i.upstream.sendPendingMessages()})),i.channel.on("connected",(function(){return setTimeout((function(){return i.emit("connected")}),0)})),i.channel.on("beforeConnect",(function(){return i.telemetryTracker.addPartialEvent(new He("Establish WebSocket connection","",new Date),Xe.TWILSOCK_CONNECT,e.TelemetryPoint.Start)})),i.channel.on("connected",(function(){return i.telemetryTracker.addPartialEvent(new He("Establish WebSocket connection","",new Date,new Date),Xe.TWILSOCK_CONNECT,e.TelemetryPoint.End)})),i.channel.on("beforeSendInit",(function(){return i.telemetryTracker.addPartialEvent(new He("Send Twilsock init","",new Date),Xe.TWILSOCK_INIT,e.TelemetryPoint.Start)})),i.channel.on("initialized",(function(){return i.telemetryTracker.addPartialEvent(new He("Send Twilsock init","Succeeded",new Date,new Date),Xe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("sendInitFailed",(function(){return i.telemetryTracker.addPartialEvent(new He("Send Twilsock init","Failed",new Date,new Date),Xe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("initialized",(function(e){i.handleStorageId(n,e),Ke.storeToken(e.continuationToken,n),setTimeout((function(){return i.emit("initialized",e)}),0)})),i.channel.on("disconnected",(function(){return setTimeout((function(){return i.emit("disconnected")}),0)})),i.channel.on("disconnected",(function(){return i.upstream.rejectPendingMessages()})),i.channel.on("disconnected",(function(){return i.offlineStorageDeferred.fail(new we("Client disconnected"))})),i.offlineStorageDeferred.promise.catch((function(){})),i}return _.default(f,[{key:"emit",value:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return Q.debug("Emitting ".concat(e.toString(),"(").concat(r.map((function(e){return JSON.stringify(e)})).join(", "),")")),(t=E.default(I.default(f.prototype),"emit",this)).call.apply(t,[this,e].concat(r))}},{key:"handleStorageId",value:function(e,t){if(t.offlineStorage)if(t.offlineStorage.hasOwnProperty(e))try{this.offlineStorageDeferred.set(Ge.create(t.offlineStorage[e])),Q.debug("Offline storage for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage[e]),"."))}catch(n){this.offlineStorageDeferred.fail(new we("Failed to parse offline storage for ".concat(e," ").concat(JSON.stringify(t.offlineStorage[e]),". ").concat(n,".")))}else this.offlineStorageDeferred.fail(new we("No offline storage id for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage))));else this.offlineStorageDeferred.fail(new we("No offline storage id"))}},{key:"storageId",value:function(){return this.offlineStorageDeferred.promise}},{key:"isConnected",get:function(){return this.channel.isConnected}},{key:"state",get:function(){return this.channel.state}},{key:"updateToken",value:(c=x.default(P.default.mark((function e(t){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Q.trace("updating token '".concat(t,"'")),this.config.token!==t){e.next=3;break}return e.abrupt("return");case 3:return this.config.updateToken(t),e.next=6,this.channel.updateToken(t);case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"setNotificationsContext",value:(u=x.default(P.default.mark((function e(t,n){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.registrations.setNotificationsContext(t,n);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"removeNotificationsContext",value:(o=x.default(P.default.mark((function e(t){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.registrations.removeNotificationsContext(t);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"connect",value:function(){return this.channel.connect()}},{key:"disconnect",value:(s=x.default(P.default.mark((function t(){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEventsIncludingUnfinished),t.next=3,this.channel.disconnect();case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(){return s.apply(this,arguments)})},{key:"get",value:(a=x.default(P.default.mark((function t(n,r,i){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("GET",n,r,void 0,i);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n){return a.apply(this,arguments)})},{key:"post",value:(i=x.default(P.default.mark((function t(n,r,i,a){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("POST",n,r,i,a);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n,r){return i.apply(this,arguments)})},{key:"put",value:(r=x.default(P.default.mark((function t(n,r,i,a){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("PUT",n,r,i,a);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"delete",value:(n=x.default(P.default.mark((function t(n,r,i,a){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("DELETE",n,r,i,a);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,r,i){return n.apply(this,arguments)})},{key:"addTelemetryEvent",value:function(e){this.telemetryTracker.addTelemetryEvent(e),this.telemetryTracker.sendTelemetryIfMinimalPortionCollected()}},{key:"addPartialTelemetryEvent",value:function(t,n,r){this.telemetryTracker.addPartialEvent(t,n,r),r===e.TelemetryPoint.End&&this.telemetryTracker.sendTelemetryIfMinimalPortionCollected()}}]),f}(D),e.TwilsockClient=function(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":A.default(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}([p.validateConstructorTypes(p.nonEmptyString,p.nonEmptyString,[p.pureObject,"undefined",p.literal(null)]),function(e,t){if("object"===("undefined"==typeof Reflect?"undefined":A.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[String,String,Object])],e.TwilsockClient);var Ze=function(){function e(t){O.default(this,e),this.product=t,this.type="ers",this.notification_protocol_version=0,this.message_types=[]}return _.default(e,[{key:"populateInitRegistrations",value:function(e){var t=new Set(this.message_types);for(var n in e)t.add(e[n]);this.message_types=Array.from(t)}}]),e}();e.InitRegistration=Ze,e.TelemetryEventDescription=He,e.TelemetryTracker=Ye,e.TransportUnavailableError=Fe,e.Twilsock=e.TwilsockClient,e.TwilsockError=we}(Jg);var jE={},ME=o,LE=s,NE=An,UE=tn,DE=u,FE=Q,BE=b,qE=Object.assign,WE=Object.defineProperty,zE=!qE||LE((function(){if(ME&&1!==qE({b:1},qE(WE({},"a",{enumerable:!0,get:function(){WE(this,"b",{value:3,enumerable:!1})}}),{b:2})).b)return!0;var e={},t={},n=Symbol(),r="abcdefghijklmnopqrst";return e[n]=7,r.split("").forEach((function(e){t[e]=e})),7!=qE({},e)[n]||NE(qE({},t)).join("")!=r}))?function(e,t){for(var n=FE(e),r=arguments.length,i=1,a=UE.f,s=DE.f;r>i;)for(var o,u=BE(arguments[i++]),c=a?NE(u).concat(a(u)):NE(u),l=c.length,f=0;l>f;)o=c[f++],ME&&!s.call(u,o)||(n[o]=u[o]);return n}:qE,GE=zE;In({target:"Object",stat:!0,forced:Object.assign!==GE},{assign:GE}),function(e){Object.defineProperty(e,"__esModule",{value:!0});var t=Vg.exports,n=Gv.exports,r=ag.exports,i=Jv.exports,a=$v.exports,s=Hv.exports,o=Hg,u=gv.exports,c=Jg,l=Kv.exports,f=sg.exports,d=ig,p=Iv.exports,h=Bv.exports,v=Xf.exports,y=Jh;function m(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function g(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var b=m(t),k=m(n),w=m(r),x=m(i),_=m(a),S=m(s),E=m(o),T=m(u),R=m(l),I=m(f),O=m(p),C=m(h),P=g(v);function A(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":T.default(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function j(e,t){if("object"===("undefined"==typeof Reflect?"undefined":T.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function M(){}function L(){L.init.call(this)}function N(e){return void 0===e._maxListeners?L.defaultMaxListeners:e._maxListeners}function U(e,t,n){if(t)e.call(n);else for(var r=e.length,i=J(e,r),a=0;a<r;++a)i[a].call(n)}function D(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=J(e,i),s=0;s<i;++s)a[s].call(n,r)}function F(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=J(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function B(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=J(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function q(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=J(e,i),s=0;s<i;++s)a[s].apply(n,r)}function W(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new M,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=N(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function z(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function G(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function J(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}M.prototype=Object.create(null),L.EventEmitter=L,L.usingDomains=!1,L.prototype.domain=void 0,L.prototype._events=void 0,L.prototype._maxListeners=void 0,L.defaultMaxListeners=10,L.init=function(){this.domain=null,L.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new M,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},L.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},L.prototype.getMaxListeners=function(){return N(this)},L.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:U(n,l,this);break;case 2:D(n,l,this,arguments[1]);break;case 3:F(n,l,this,arguments[1],arguments[2]);break;case 4:B(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];q(n,l,this,i)}return!0},L.prototype.addListener=function(e,t){return W(this,e,t,!1)},L.prototype.on=L.prototype.addListener,L.prototype.prependListener=function(e,t){return W(this,e,t,!0)},L.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,z(this,e,t)),this},L.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,z(this,e,t)),this},L.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new M:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new M,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},L.prototype.off=function(e,t){return this.removeListener(e,t)},L.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new M,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new M:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new M,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},L.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},L.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):G.call(e,t)},L.prototype.listenerCount=G,L.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var V=P.getLogger("twilio-notificatiions");function $(e,t){return["".concat((new Date).toISOString()," Twilio.Notifications ").concat(e,":")].concat(Array.from(t))}var K=new(function(){function e(){k.default(this,e)}return w.default(e,[{key:"setLevel",value:function(e){V.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.trace.apply(null,$("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.debug.apply(null,$("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.info.apply(null,$("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.warn.apply(null,$("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.error.apply(null,$("E",t))}}]),e}());function H(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=S.default(e);if(t){var i=S.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _.default(this,n)}}var Y=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Set;k.default(this,e),this.token=t,this.notificationId=n,this.messageTypes=r};function Q(e,t){var n=new Set;return e.notificationId!==t.notificationId&&n.add("notificationId"),e.token!==t.token&&n.add("token"),function(e,t){return[].concat(C.default(C.default(e).filter((function(e){return!t.has(e)}))),C.default(C.default(t).filter((function(t){return!e.has(t)}))))}(e.messageTypes,t.messageTypes).length>0&&n.add("messageType"),[n.size>0,n]}var X=function(e){x.default(r,e);var t,n=H(r);function r(e){var t;return k.default(this,r),t=n.call(this),I.default(R.default(t),"desiredState",new Y),I.default(R.default(t),"currentState",new Y),I.default(R.default(t),"_hasActiveAttempt",!1),t.channelType=e,t}return w.default(r,[{key:"setNotificationId",value:function(e){this.desiredState.notificationId=e}},{key:"isActive",value:function(){return""!==this.desiredState.notificationId}},{key:"subscribe",value:function(e){this.desiredState.messageTypes.has(e)?K.debug("message type '".concat(e,"' for channel ").concat(this.channelType," is already registered")):this.desiredState.messageTypes.add(e)}},{key:"unsubscribe",value:function(e){this.desiredState.messageTypes.has(e)&&this.desiredState.messageTypes.delete(e)}},{key:"updateToken",value:function(e){this.desiredState.token=e}},{key:"commitChanges",value:(t=b.default(E.default.mark((function e(){var t,n,r,i,a,s;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._hasActiveAttempt){e.next=3;break}throw K.error("One registration attempt is already in progress"),new Error("One registration attempt is already in progress");case 3:if(t=Q(this.desiredState,this.currentState),n=O.default(t,2),r=n[0],i=n[1],r){e.next=6;break}return e.abrupt("return");case 6:if(this.currentState.notificationId||i.delete("notificationId"),K.trace("Persisting ".concat(this.channelType," registration"),i,this.desiredState),e.prev=8,this._hasActiveAttempt=!0,(a=new Y).token=this.desiredState.token,a.notificationId=this.desiredState.notificationId,a.messageTypes=new Set(this.desiredState.messageTypes),!(a.messageTypes.size>0)){e.next=24;break}return e.next=17,this.updateRegistration(a,i);case 17:s=e.sent,this.currentState.token=s.token,this.currentState.notificationId=s.notificationId,this.currentState.messageTypes=new Set(s.messageTypes),this.emit("stateChanged",this.channelType,"registered",this.currentState),e.next=30;break;case 24:return e.next=26,this.removeRegistration();case 26:this.currentState.token=a.token,this.currentState.notificationId=a.notificationId,this.currentState.messageTypes.clear(),this.emit("stateChanged",this.channelType,"unregistered",this.currentState);case 30:e.next=35;break;case 32:throw e.prev=32,e.t0=e.catch(8),e.t0;case 35:return e.prev=35,this._hasActiveAttempt=!1,e.finish(35);case 38:case"end":return e.stop()}}),e,this,[[8,32,35,38]])}))),function(){return t.apply(this,arguments)})}]),r}(L);function Z(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=S.default(e);if(t){var i=S.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _.default(this,n)}}var ee={min:2e3,max:12e4,randomness:.2},te=function(e){x.default(a,e);var t,n,r,i=Z(a);function a(e,t,n,r){var s;return k.default(this,a),s=i.call(this,e),I.default(R.default(s),"registrationId",null),s.context=t,s.twilsock=n,s.registrarUrl=r,s}return w.default(a,[{key:"updateRegistration",value:(r=b.default(E.default.mark((function e(t,n){var r,i,a,s,o,u=this;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!n.has("notificationId")){e.next=3;break}return e.next=3,this.removeRegistration();case 3:if(t.notificationId&&t.notificationId.length){e.next=6;break}throw K.error("No push notification ID for registration"),new Error("No push notification ID for registration");case 6:return K.trace("Registering",this.channelType,t),r={endpoint_platform:this.context.platform,channel_type:this.channelType,version:this.context.protocolVersion.toString(),message_types:Array.from(t.messageTypes),data:{registration_id:t.notificationId}},i=this.context.productId,a="".concat(this.registrarUrl,"?productId=").concat(i),s={"Content-Type":"application/json"},K.trace("Creating registration for channel ".concat(this.channelType)),e.prev=12,e.next=15,new d.AsyncRetrier(ee).run((function(){return u.twilsock.post(a,s,r,i)}));case 15:o=e.sent,this.registrationId=o.body.id,K.debug("Registration created: ",o),e.next=24;break;case 20:throw e.prev=20,e.t0=e.catch(12),K.error("Registration failed: ",e.t0),e.t0;case 24:return e.abrupt("return",t);case 25:case"end":return e.stop()}}),e,this,[[12,20]])}))),function(e,t){return r.apply(this,arguments)})},{key:"removeRegistration",value:(n=b.default(E.default.mark((function e(){var t,n,r,i=this;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.registrationId){e.next=2;break}return e.abrupt("return");case 2:return t=this.context.productId,n="".concat(this.registrarUrl,"/").concat(this.registrationId,"?productId=").concat(t),r={"Content-Type":"application/json"},K.trace("Removing registration for ".concat(this.channelType)),e.prev=6,e.next=9,new d.AsyncRetrier(Object.assign(ee,{maxAttemptsCount:3})).run((function(){return i.twilsock.delete(n,r,{},t)}));case 9:this.registrationId=null,this.currentState.notificationId="",K.debug("Registration removed for ".concat(this.channelType)),e.next=18;break;case 14:throw e.prev=14,e.t0=e.catch(6),K.error("Failed to remove registration ",this.channelType,e.t0),e.t0;case 18:case"end":return e.stop()}}),e,this,[[6,14]])}))),function(){return n.apply(this,arguments)})},{key:"sendDeviceRemoveRequest",value:(t=b.default(E.default.mark((function e(t){var n,r,i,a,s=this;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(""!==t){e.next=2;break}throw new Error("Empty registration ID");case 2:return n=this.context.productId,r="".concat(this.registrarUrl,"?productId=").concat(n),i={"Content-Type":"application/json"},a={binding_type:this.channelType,address:t},e.prev=6,K.trace("Removing old registrations for ".concat(this.channelType)),e.next=10,new d.AsyncRetrier(Object.assign(ee,{maxAttemptsCount:3})).run((function(){return s.twilsock.delete(r,i,a,n)}));case 10:this.registrationId=null,this.currentState.notificationId="",K.debug("Registration removed for ".concat(this.channelType)),e.next=19;break;case 15:throw e.prev=15,e.t0=e.catch(6),K.error("Failed to remove registration ",this.channelType,e.t0),e.t0;case 19:case"end":return e.stop()}}),e,this,[[6,15]])}))),function(e){return t.apply(this,arguments)})}]),a}(X),ne={exports:{}},re="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(re){var ie=new Uint8Array(16);ne.exports=function(){return re(ie),ie}}else{var ae=new Array(16);ne.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),ae[t]=e>>>((3&t)<<3)&255;return ae}}for(var se=[],oe=0;oe<256;++oe)se[oe]=(oe+256).toString(16).substr(1);var ue,ce,le=function(e,t){var n=t||0,r=se;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")},fe=ne.exports,de=le,pe=0,he=0;var ve=function(e,t,n){var r=t&&n||0,i=t||[],a=(e=e||{}).node||ue,s=void 0!==e.clockseq?e.clockseq:ce;if(null==a||null==s){var o=fe();null==a&&(a=ue=[1|o[0],o[1],o[2],o[3],o[4],o[5]]),null==s&&(s=ce=16383&(o[6]<<8|o[7]))}var u=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:he+1,l=u-pe+(c-he)/1e4;if(l<0&&void 0===e.clockseq&&(s=s+1&16383),(l<0||u>pe)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");pe=u,he=c,ce=s;var f=(1e4*(268435455&(u+=122192928e5))+c)%4294967296;i[r++]=f>>>24&255,i[r++]=f>>>16&255,i[r++]=f>>>8&255,i[r++]=255&f;var d=u/4294967296*1e4&268435455;i[r++]=d>>>8&255,i[r++]=255&d,i[r++]=d>>>24&15|16,i[r++]=d>>>16&255,i[r++]=s>>>8|128,i[r++]=255&s;for(var p=0;p<6;++p)i[r+p]=a[p];return t||de(i)},ye=ne.exports,me=le;var ge=ve,be=function(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||ye)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var a=0;a<16;++a)t[r+a]=i[a];return t||me(i)},ke=be;ke.v1=ge,ke.v4=be;var we=ke;function xe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=S.default(e);if(t){var i=S.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _.default(this,n)}}var _e,Se=function(e){x.default(a,e);var t,n,r,i=xe(a);function a(e,t,n){var r;return k.default(this,a),r=i.call(this,"twilsock"),I.default(R.default(r),"contextId",we.v4()),r.productId=e,r.platform=t,r.twilsock=n,r}return w.default(a,[{key:"updateRegistration",value:(r=b.default(E.default.mark((function e(t,n){var r,i;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n.has("messageType")){e.next=2;break}return e.abrupt("return",t);case 2:return r=Array.from(t.messageTypes),i={product_id:this.productId,notification_protocol_version:4,endpoint_platform:this.platform,message_types:r},e.prev=4,e.next=7,this.twilsock.setNotificationsContext(this.contextId,i);case 7:e.next=13;break;case 9:throw e.prev=9,e.t0=e.catch(4),K.error("Failed to update twilsock notification context: ".concat(e.t0)),e.t0;case 13:return e.abrupt("return",t);case 14:case"end":return e.stop()}}),e,this,[[4,9]])}))),function(e,t){return r.apply(this,arguments)})},{key:"removeRegistration",value:(n=b.default(E.default.mark((function e(){return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.twilsock.removeNotificationsContext(this.contextId);case 3:e.next=9;break;case 5:throw e.prev=5,e.t0=e.catch(0),K.error("Failed to remove twilsock notification context: ".concat(e.t0)),e.t0;case 9:case"end":return e.stop()}}),e,this,[[0,5]])}))),function(){return n.apply(this,arguments)})},{key:"sendDeviceRemoveRequest",value:(t=b.default(E.default.mark((function e(t){return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),a}(X);function Ee(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=S.default(e);if(t){var i=S.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _.default(this,n)}}var Te=y.literal("apn","fcm","twilsock");e.Notifications=_e=function(e){x.default(Client,e);var t,n,r,i=Ee(Client);function Client(e){var t,n,r,a,s,o,u,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};k.default(this,Client),u=i.call(this),l.logLevel=null!==(t=l.logLevel)&&void 0!==t?t:"error",K.setLevel(l.logLevel);var f=null!==(n=l.productId)&&void 0!==n?n:"notifications",d=!l.twilsockClient,p=l.twilsockClient=null!==(r=l.twilsockClient)&&void 0!==r?r:new c.TwilsockClient(e,f,l),h=null!==(a=l.notifications)&&void 0!==a?a:{},v=null!==(s=null!==(o=h.region)&&void 0!==o?o:l.region)&&void 0!==s?s:"us1",y="https://ers.".concat(v,".twilio.com/v1/registrations"),m=h.ersUrl||y;u.connectors=new Map;var g=_e._detectPlatform();return u.connectors.set("apn",new te("apn",{protocolVersion:4,productId:f,platform:g},p,m)),u.connectors.set("fcm",new te("fcm",{protocolVersion:3,productId:f,platform:g},p,m)),u.connectors.set("twilsock",new Se(f,g,p)),p.on("stateChanged",(function(e){return u.emit("transportState",e)})),u._connector("twilsock").on("stateChanged",(function(e,t,n){return u.emit("stateChanged",e,t,n)})),u._connector("apn").on("stateChanged",(function(e,t,n){return u.emit("stateChanged",e,t,n)})),u._connector("fcm").on("stateChanged",(function(e,t,n){return u.emit("stateChanged",e,t,n)})),p.on("message",(function(e,t){return u._routeMessage(e,t)})),u.updateToken(e),d&&(p.connect(),u.twilsock=p),u}return w.default(Client,[{key:"shutdown",value:(r=b.default(E.default.mark((function e(){return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectors.clear(),!this.twilsock){e.next=4;break}return e.next=4,this.twilsock.disconnect();case 4:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"setPushRegistrationId",value:function(e,t){K.debug("Set ".concat(e," push registration id '").concat(t,"'")),this._connector(e).setNotificationId(t)}},{key:"subscribe",value:function(e,t){K.debug("Add ".concat(e," subscriptions for message type ").concat(t)),this._connector(e).subscribe(t)}},{key:"unsubscribe",value:function(e,t){K.debug("Remove ".concat(e," subscriptions for message type ").concat(t)),this._connector(e).unsubscribe(t)}},{key:"updateToken",value:function(e){this.connectors.forEach((function(t){return t.updateToken(e)}))}},{key:"commitChanges",value:(n=b.default(E.default.mark((function e(){var t;return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=[],this.connectors.forEach((function(e){e.isActive()&&t.push(e.commitChanges())})),e.next=4,Promise.all(t);case 4:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"removeRegistrations",value:(t=b.default(E.default.mark((function e(t,n){return E.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._connector(t).sendDeviceRemoveRequest(n);case 2:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})},{key:"handlePushNotification",value:function(e){return{messageType:e.twi_message_type,payload:e.payload}}},{key:"_routeMessage",value:function(e,t){K.debug("Notification message arrived: ",e,t),this.emit("message",e,t)}},{key:"_connector",value:function(e){var t=this.connectors.get(e);if(!t)throw new Error("Unknown channel type: ".concat(e));return t}}],[{key:"_detectPlatform",value:function(){var e="";return"undefined"!=typeof navigator?(e="unknown",void 0!==navigator.product&&(e=navigator.product),void 0!==navigator.userAgent&&(e=navigator.userAgent)):e="web",e.substring(0,128)}}]),Client}(L),A([y.validateTypes(Te,y.nonEmptyString),j("design:type",Function),j("design:paramtypes",[String,String]),j("design:returntype",void 0)],e.Notifications.prototype,"setPushRegistrationId",null),A([y.validateTypes(Te,y.nonEmptyString),j("design:type",Function),j("design:paramtypes",[String,String]),j("design:returntype",void 0)],e.Notifications.prototype,"subscribe",null),A([y.validateTypes(Te,y.nonEmptyString),j("design:type",Function),j("design:paramtypes",[String,String]),j("design:returntype",void 0)],e.Notifications.prototype,"unsubscribe",null),A([y.validateTypes(y.nonEmptyString),j("design:type",Function),j("design:paramtypes",[String]),j("design:returntype",void 0)],e.Notifications.prototype,"updateToken",null),A([y.validateTypesAsync(Te,y.nonEmptyString),j("design:type",Function),j("design:paramtypes",[String,String]),j("design:returntype",Promise)],e.Notifications.prototype,"removeRegistrations",null),e.Notifications=_e=A([y.validateConstructorTypes(y.nonEmptyString,[y.pureObject,"undefined",y.literal(null)]),j("design:paramtypes",[String,Object])],e.Notifications)}(jE);var JE={};Object.defineProperty(JE,"__esModule",{value:!0});var VE=Vg.exports,$E=Gv.exports,KE=ag.exports,HE=Kv.exports,YE=Jv.exports,QE=$v.exports,XE=Hv.exports,ZE=sg.exports,eT=Hg,tT=gv.exports,nT=Jh,rT=Jg,iT=iE.exports,aT=Xf.exports,sT=Iv.exports,oT=ig,uT=Ob,cT=$g.exports,lT=uE.exports;function fT(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function dT(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var pT=fT(VE),hT=fT($E),vT=fT(KE),yT=fT(HE),mT=fT(YE),gT=fT(QE),bT=fT(XE),kT=fT(ZE),wT=fT(eT),xT=fT(tT),_T=fT(iT),ST=dT(aT),ET=fT(sT),TT=dT(uT),RT=fT(cT),IT=dT(lT);function OT(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":xT.default(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function CT(e,t){if("object"===("undefined"==typeof Reflect?"undefined":xT.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function PT(){}function AT(){AT.init.call(this)}function jT(e){return void 0===e._maxListeners?AT.defaultMaxListeners:e._maxListeners}function MT(e,t,n){if(t)e.call(n);else for(var r=e.length,i=WT(e,r),a=0;a<r;++a)i[a].call(n)}function LT(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=WT(e,i),s=0;s<i;++s)a[s].call(n,r)}function NT(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=WT(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function UT(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=WT(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function DT(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=WT(e,i),s=0;s<i;++s)a[s].apply(n,r)}function FT(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new PT,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=jT(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function BT(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function qT(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function WT(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}PT.prototype=Object.create(null),AT.EventEmitter=AT,AT.usingDomains=!1,AT.prototype.domain=void 0,AT.prototype._events=void 0,AT.prototype._maxListeners=void 0,AT.defaultMaxListeners=10,AT.init=function(){this.domain=null,AT.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new PT,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},AT.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},AT.prototype.getMaxListeners=function(){return jT(this)},AT.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:MT(n,l,this);break;case 2:LT(n,l,this,arguments[1]);break;case 3:NT(n,l,this,arguments[1],arguments[2]);break;case 4:UT(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];DT(n,l,this,i)}return!0},AT.prototype.addListener=function(e,t){return FT(this,e,t,!1)},AT.prototype.on=AT.prototype.addListener,AT.prototype.prependListener=function(e,t){return FT(this,e,t,!0)},AT.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,BT(this,e,t)),this},AT.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,BT(this,e,t)),this},AT.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new PT:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new PT,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},AT.prototype.off=function(e,t){return this.removeListener(e,t)},AT.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new PT,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new PT:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new PT,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},AT.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},AT.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):qT.call(e,t)},AT.prototype.listenerCount=qT,AT.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var zT=function(){function e(t){hT.default(this,e),this.base=t,this.args=new Array,this.paths=new Array}return vT.default(e,[{key:"pathSegment",value:function(e){return this.paths.push(encodeURIComponent(e)),this}},{key:"queryParam",value:function(e,t){return void 0!==t&&this.args.push(encodeURIComponent(e)+"="+encodeURIComponent(t)),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}}]),e}();function GT(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=bT.default(e);if(t){var i=bT.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gT.default(this,n)}}var JT=function(e){mT.default(n,e);var t=GT(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return hT.default(this,n),(r=t.call(this)).name=r.constructor.name,r.message="".concat(e," (status: ").concat(i,", code: ").concat(a,")"),r.status=i,r.code=a,r}return n}(_T.default(Error)),VT=function(e){mT.default(n,e);var t=GT(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3?arguments[3]:void 0;return hT.default(this,n),(r=t.call(this,e,i,a)).body=s,r}return n}(JT);function $T(e){return JSON.parse(JSON.stringify(e))}function KT(e){if(!(void 0===e||HT(e)))throw new JT("Invalid pageSize parameter. Expected a positive integer, was '".concat(e,"'."),400,20007)}function HT(e){return function(e){return!isNaN(parseInt(e))&&isFinite(e)}(e)&&e>0}var YT=ST.getLogger("twilio-sync");function QT(e,t){return["".concat((new Date).toISOString()," Sync ").concat(e,":")].concat(Array.from(t))}var XT=function(e){YT.setLevel(e)},ZT=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];YT.trace.apply(null,QT("T",t))},eR=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];YT.debug.apply(null,QT("D",t))},tR=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];YT.warn.apply(null,QT("W",t))},nR=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];YT.error.apply(null,QT("E",t))},rR="/v4/Subscriptions",iR="/v3/Maps",aR="/v3/Lists",sR="/v3/Documents",oR="/v3/Streams",uR="/v3/Insights";function cR(e,t,n){return e&&void 0!==e[t]?e[t]:n}var lR=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};hT.default(this,e);var n=t.region||"us1",r="https://cds.".concat(n,".twilio.com"),i=t.cdsUri||r;this.settings={subscriptionsUri:i+rR,documentsUri:i+sR,listsUri:i+aR,mapsUri:i+iR,streamsUri:i+oR,insightsUri:i+uR,sessionStorageEnabled:cR(t.Sync,"enableSessionStorage",!0),productId:t.productId}}return vT.default(e,[{key:"subscriptionsUri",get:function(){return this.settings.subscriptionsUri}},{key:"documentsUri",get:function(){return this.settings.documentsUri}},{key:"listsUri",get:function(){return this.settings.listsUri}},{key:"mapsUri",get:function(){return this.settings.mapsUri}},{key:"streamsUri",get:function(){return this.settings.streamsUri}},{key:"insightsUri",get:function(){return this.settings.insightsUri}},{key:"backoffConfig",get:function(){return this.settings.backoffConfig||{}}},{key:"sessionStorageEnabled",get:function(){return this.settings.sessionStorageEnabled}},{key:"productId",get:function(){return this.settings.productId}}]),e}();function fR(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return dR(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return dR(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function dR(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var pR=function(){function e(t){hT.default(this,e),this.localObject=t,this.pendingCorrelationId=null,this.pendingAction=null,this.established=!1,this.retryCount=0}return vT.default(e,[{key:"sid",get:function(){return this.localObject.sid}},{key:"type",get:function(){return this.localObject.type}},{key:"lastEventId",get:function(){return this.localObject.lastEventId}},{key:"indexName",get:function(){return this.localObject.indexName}},{key:"queryString",get:function(){return this.localObject.queryString}},{key:"isEstablished",get:function(){return this.established}},{key:"update",value:function(e,t){this.localObject._update(e,t)}},{key:"updatePending",value:function(e,t){this.pendingAction=e,this.pendingCorrelationId=t}},{key:"reset",value:function(){this.updatePending(null,null),this.retryCount=0,this.established=!1,this.setSubscriptionState("none")}},{key:"markAsFailed",value:function(e){this.rejectedWithError=e.error,this.updatePending(null,null),this.localObject.reportFailure(new JT("Failed to subscribe on service events: ".concat(e.error.message),e.error.status,e.error.code))}},{key:"complete",value:function(e){this.updatePending(null,null),this.established=!0,this.localObject._advanceLastEventId(e)}},{key:"setSubscriptionState",value:function(e){this.localObject._setSubscriptionState(e)}}]),e}(),hR=function(){function e(t){var n=this;hT.default(this,e),kT.default(this,"isConnected",!1),kT.default(this,"maxBatchSize",100),kT.default(this,"subscriptionTtlTimer",null),kT.default(this,"pendingPokeReason",null),this.services=t,this.subscriptions=new Map,this.persisted=new Map,this.latestPokeResponseArrivalTimestampByCorrelationId=new Map;this.backoff=oT.Backoff.exponential(Object.assign({randomisationFactor:.2,initialDelay:100,maxDelay:12e4},this.services.config.backoffConfig)),this.backoff.on("ready",(function(){var e=n.getSubscriptionUpdateBatch(),t=e.action,r=e.subscriptions;t?n.applyNewSubscriptionUpdateBatch(t,r):(n.backoff.reset(),eR("All subscriptions resolved."))}))}var t;return vT.default(e,[{key:"getSubscriptionUpdateBatch",value:function(){function e(e,t,n,r){var i,a=[],s=fR(e);try{for(s.s();!(i=s.n()).done;){var o=ET.default(i.value,2),u=o[0],c=o[1];if(!t.get(u)&&n!==c.pendingAction&&!c.rejectedWithError&&(a.push(c),r&&a.length>=r))break}}catch(e){s.e(e)}finally{s.f()}return a}var t=e(this.subscriptions,this.persisted,"establish",this.maxBatchSize);if(t.length>0)return{action:"establish",subscriptions:t};var n=e(this.persisted,this.subscriptions,"cancel",this.maxBatchSize);return n.length>0?{action:"cancel",subscriptions:n}:{action:null,subscriptions:null}}},{key:"persist",value:function(){this.backoff.backoff()}},{key:"applyNewSubscriptionUpdateBatch",value:(t=pT.default(wT.default.mark((function e(t,n){var r,i,a,s,o,u,c,l,f,d,p,h,v=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isConnected){e.next=4;break}return eR("Twilsock connection (required for subscription) not ready; waiting…"),this.backoff.reset(),e.abrupt("return");case 4:n=this.processLocalActions(t,n),r=(new Date).getTime(),i=fR(n);try{for(i.s();!(a=i.n()).done;)s=a.value,this.recordActionAttemptOn(s,t,r)}catch(e){i.e(e)}finally{i.f()}return o=this.pendingPokeReason,this.pendingPokeReason=null,e.prev=10,e.next=13,this.request(t,r,o,n);case 13:u=e.sent,c=u.body.max_batch_size,!isNaN(parseInt(c))&&isFinite(c)&&c>0&&(this.maxBatchSize=c),this.subscriptionTtlTimer||(l=u.body.ttl_in_s,!isNaN(parseFloat(l))&&isFinite(l)&&l>0&&(this.subscriptionTtlTimer=setTimeout((function(){return v.onSubscriptionTtlElapsed()}),1e3*l))),"establish"===t&&(f=u.body.estimated_delivery_in_ms,!isNaN(parseFloat(f))&&isFinite(f)&&f>0?setTimeout((function(){return v.verifyPokeDelivery(r,f,n)}),f):nR("Invalid timeout: ".concat(f)),n.filter((function(e){return e.pendingCorrelationId===r})).forEach((function(e){return e.setSubscriptionState("response_in_flight")}))),this.backoff.reset(),e.next=26;break;case 21:e.prev=21,e.t0=e.catch(10),d=fR(n);try{for(d.s();!(p=d.n()).done;)h=p.value,this.recordActionFailureOn(h,t)}catch(e){d.e(e)}finally{d.f()}e.t0 instanceof rT.TransportUnavailableError?(eR("Twilsock connection (required for subscription) not ready (c:".concat(r,"); waiting…")),this.backoff.reset()):(eR("Failed an attempt to ".concat(t," subscriptions (c:").concat(r,"); retrying"),e.t0),this.persist());case 26:case"end":return e.stop()}}),e,this,[[10,21]])}))),function(e,n){return t.apply(this,arguments)})},{key:"verifyPokeDelivery",value:function(e,t,n){var r=this,i=this.latestPokeResponseArrivalTimestampByCorrelationId.get(e),a=i?(new Date).getTime()-i:t;a>=t?(n.filter((function(t){return t.pendingCorrelationId===e})).forEach((function(e){e.updatePending(null,null),e.retryCount++,r.persisted.delete(e.sid)})),this.persist(),this.latestPokeResponseArrivalTimestampByCorrelationId.delete(e)):setTimeout((function(){return r.verifyPokeDelivery(e,t,n)}),t-a)}},{key:"processLocalActions",value:function(e,t){return"cancel"===e?t.filter((function(e){return!e.rejectedWithError})):t}},{key:"recordActionAttemptOn",value:function(e,t,n){if(e.setSubscriptionState("request_in_flight"),"establish"===t)this.persisted.set(e.sid,e),e.updatePending(t,n);else{var r=this.persisted.get(e.sid);r&&r.updatePending(t,n)}}},{key:"recordActionFailureOn",value:function(e,t){e.setSubscriptionState("none"),e.updatePending(null,null),"establish"===t&&this.persisted.delete(e.sid)}},{key:"request",value:function(e,t,n,r){var i=r.map((function(t){return{object_sid:t.sid,object_type:t.type,last_event_id:"establish"===e?t.lastEventId:void 0,index_name:"establish"===e?t.indexName:void 0,query_string:"establish"===e?t.queryString:void 0}})),a=r.filter((function(e){return e.retryCount>0})).length;eR("Attempting '".concat(e,"' request (c:").concat(t,"):"),i);var s={event_protocol_version:3,action:e,correlation_id:t,retried_requests:a,ttl_in_s:-1,requests:i};return"ttl"===n&&(s.reason=n),this.services.network.post(this.services.config.subscriptionsUri,s)}},{key:"add",value:function(e,t){eR("Establishing intent to subscribe to ".concat(e));var n=this.subscriptions.get(e);n&&t&&n.lastEventId===t.lastEventId||(this.persisted.delete(e),this.subscriptions.set(e,new pR(t)),this.persist())}},{key:"remove",value:function(e){eR("Establishing intent to unsubscribe from ".concat(e)),this.subscriptions.delete(e)&&this.persist()}},{key:"acceptMessage",value:function(e,t){var n;switch(ZT("Subscriptions received",e),e.correlation_id&&this.latestPokeResponseArrivalTimestampByCorrelationId.set(e.correlation_id,(new Date).getTime()),e.event_type){case"subscription_established":this.applySubscriptionEstablishedMessage(e.event,e.correlation_id);break;case"subscription_canceled":this.applySubscriptionCancelledMessage(e.event,e.correlation_id);break;case"subscription_failed":this.applySubscriptionFailedMessage(e.event,e.correlation_id);break;case(n=e.event_type.match(/^(?:map|list|document|stream|live_query)_/)||{}).input:var r;switch(n[0]){case"map_":r=e.event.map_sid;break;case"list_":r=e.event.list_sid;break;case"document_":r=e.event.document_sid;break;case"stream_":r=e.event.stream_sid;break;case"live_query_":r=e.event.query_id,t=!1,!0===e.strictly_ordered&&(t=!0);break;default:r=void 0}this.applyEventToSubscribedEntity(r,e,t);break;default:eR("Dropping unknown message type ".concat(e.event_type))}}},{key:"applySubscriptionEstablishedMessage",value:function(e,t){var n=e.object_sid,r=this.persisted.get(e.object_sid);r&&r.pendingCorrelationId===t?"interrupted"===e.replay_status?(eR("Event Replay for subscription to ".concat(n," (c:").concat(t,") interrupted; continuing eagerly.")),r.updatePending(null,null),this.persisted.delete(r.sid),this.backoff.reset()):"completed"===e.replay_status&&(eR("Event Replay for subscription to ".concat(n," (c:").concat(t,") completed. Subscription is ready.")),r.complete(e.last_event_id),this.persisted.set(e.object_sid,r),r.setSubscriptionState("established"),this.backoff.reset()):eR("Late message for ".concat(e.object_sid," (c:").concat(t,") dropped.")),this.persist()}},{key:"applySubscriptionCancelledMessage",value:function(e,t){var n=this.persisted.get(e.object_sid);n&&n.pendingCorrelationId===t?(n.updatePending(null,null),n.setSubscriptionState("none"),this.persisted.delete(e.object_sid)):eR("Late message for ".concat(e.object_sid," (c:").concat(t,") dropped.")),this.persist()}},{key:"applySubscriptionFailedMessage",value:function(e,t){var n=e.object_sid,r=this.subscriptions.get(n),i=this.persisted.get(n);r&&i?i.pendingCorrelationId===t&&(nR("Failed to subscribe on ".concat(i.sid),e.error),i.markAsFailed(e),i.setSubscriptionState("none")):!r&&i&&(this.persisted.delete(n),i.setSubscriptionState("none")),this.persist()}},{key:"applyEventToSubscribedEntity",value:function(e,t,n){if(e){var r;n=n||(r=this.persisted.get(e))&&r.isEstablished;var i=this.subscriptions.get(e);i?(t.event.type=t.event_type,i.update(t.event,n)):eR("Message dropped for SID '".concat(e,"', for which there is no subscription."))}}},{key:"onConnectionStateChanged",value:function(e){this.isConnected=e,e&&this.poke("reconnect")}},{key:"onSubscriptionTtlElapsed",value:function(){this.isConnected&&this.poke("ttl")}},{key:"poke",value:function(e){eR("Triggering event replay for all subscriptions, reason=".concat(e)),this.pendingPokeReason=e,this.subscriptionTtlTimer&&(clearTimeout(this.subscriptionTtlTimer),this.subscriptionTtlTimer=null);var t,n=[],r=fR(this.persisted.values());try{for(r.s();!(t=r.n()).done;){var i=t.value;i.reset(),i.rejectedWithError&&n.push(i)}}catch(e){r.e(e)}finally{r.f()}this.persisted.clear();for(var a=0,s=n;a<s.length;a++){var o=s[a];this.persisted.set(o.sid,o)}this.persist()}},{key:"shutdown",value:function(){this.backoff.reset(),this.subscriptions.clear()}}]),e}();function vR(e){if(e.body&&e.body.message)return e.body.message;switch(e.status){case 429:return"Throttled by server";case 404:return"Not found from server";default:return"Error from server"}}function yR(e){return e.body?e.body.code:0}function mR(e){return 409===e.status?new VT(vR(e),e.status,yR(e),e.body):e.status?new JT(vR(e),e.status,yR(e)):e instanceof rT.TransportUnavailableError?e:new JT(e.message,0,0)}var gR=function(){function e(t,n,r){hT.default(this,e),this.clientInfo=t,this.config=n,this.transport=r}return vT.default(e,[{key:"createHeaders",value:function(){return{"Content-Type":"application/json","Twilio-Sync-Client-Info":JSON.stringify(this.clientInfo),"Twilio-Request-Id":"RQ"+TT.v4().replace(/-/g,"")}}},{key:"backoffConfig",value:function(){return Object.assign({min:4e3,max:6e4,maxAttemptsTime:9e4,randomness:.2},this.config.backoffConfig)}},{key:"executeWithRetry",value:function(e){var t=this,n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return new Promise((function(r,i){var a=[502,503,504];n&&a.push(429);var s=new oT.Retrier(t.backoffConfig());s.on("attempt",(function(){e().then((function(e){return s.succeeded(e)})).catch((function(e){if(a.includes(e.status)){var t=parseInt(e.headers?e.headers["Retry-After"]:null);s.failed(mR(e),isNaN(t)?null:1e3*t)}else"Twilsock disconnected"===e.message?s.failed(mR(e)):(s.removeAllListeners(),s.cancel(),i(mR(e)))}))})),s.on("succeeded",(function(e){r(e)})),s.on("cancelled",(function(e){return i(mR(e))})),s.on("failed",(function(e){return i(mR(e))})),s.start()}))}},{key:"get",value:function(e){var t=this,n=this.createHeaders();return eR("GET",e,"ID:",n["Twilio-Request-Id"]),this.executeWithRetry((function(){return t.transport.get(e,n,t.config.productId)}),!0)}},{key:"post",value:function(e,t,n){var r=this,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=this.createHeaders();return null!=n&&(a["If-Match"]=n),eR("POST",e,"ID:",a["Twilio-Request-Id"]),this.executeWithRetry((function(){return r.transport.post(e,a,t,r.config.productId)}),i)}},{key:"put",value:function(e,t,n){var r=this,i=this.createHeaders();return null!=n&&(i["If-Match"]=n),eR("PUT",e,"ID:",i["Twilio-Request-Id"]),this.executeWithRetry((function(){return r.transport.put(e,i,t,r.config.productId)}),!1)}},{key:"delete",value:function(e){var t=this,n=this.createHeaders();return eR("DELETE",e,"ID:",n["Twilio-Request-Id"]),this.executeWithRetry((function(){return t.transport.delete(e,n,t.config.productId)}),!1)}}]),e}(),bR=function(){function e(t,n){hT.default(this,e),this.config=t,this.storageId=null;try{this.storage=n||sessionStorage}catch(e){}}return vT.default(e,[{key:"storageKey",value:function(e,t){return"".concat(this.storageId,"::").concat(e,"::").concat(t)}},{key:"isReady",get:function(){return this.config.sessionStorageEnabled&&!!this.storageId}},{key:"updateStorageId",value:function(e){this.storageId=e}},{key:"store",value:function(e,t,n){return this.isReady?this._store(this.storageKey(e,t),n):null}},{key:"read",value:function(e,t){return this.isReady?this._read(this.storageKey(e,t)):null}},{key:"remove",value:function(e,t,n){if(!this.isReady)return null;try{this.storage.removeItem(this.storageKey(e,t)),n&&this.storage.removeItem(this.storageKey(e,n))}catch(e){}}},{key:"update",value:function(e,t,n,r){if(!this.isReady)return null;this._apply(this.storageKey(e,t),r),n&&this._apply(this.storageKey(e,n),r)}},{key:"_store",value:function(e,t){try{this.storage.setItem(e,JSON.stringify(t))}catch(e){}}},{key:"_read",value:function(e){try{var t=this.storage.getItem(e);if(t)return JSON.parse(t)}catch(e){}return null}},{key:"_apply",value:function(e,t){var n=this._read(e);if(!n)return!1;this._store(e,Object.assign(n,t))}}]),e}();function kR(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return wR(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return wR(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function wR(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var xR=function(){function e(t,n){hT.default(this,e),this.services=t,this.removalHandler=n,this.subscriptionState="none",this._attachedListeners=new Map}return vT.default(e,[{key:"_advanceLastEventId",value:function(e,t){}},{key:"reportFailure",value:function(e){404===e.status?this.onRemoved(!1):this.broadcastEventToListeners("failure",e)}},{key:"_subscribe",value:function(){this.services.router._subscribe(this.sid,this)}},{key:"_unsubscribe",value:function(){this.services.router._unsubscribe(this.sid)}},{key:"_setSubscriptionState",value:function(e){this.subscriptionState=e,this.broadcastEventToListeners("_subscriptionStateChanged",e)}},{key:"close",value:function(){this._unsubscribe(),null!=this.removalHandler&&this.removalHandler(this.type,this.sid,this.uniqueName)}},{key:"attach",value:function(e){var t=e.listenerUuid;this._attachedListeners.get(t)||(this._attachedListeners.size||this._subscribe(),this._attachedListeners.set(t,e))}},{key:"detach",value:function(e){this._attachedListeners.delete(e),this._attachedListeners.size||this.close()}},{key:"broadcastEventToListeners",value:function(e,t){var n,r=kR(this._attachedListeners.values());try{for(r.s();!(n=r.n()).done;){n.value.emit(e,t)}}catch(e){r.e(e)}finally{r.f()}}}]),e}(),_R=function(){function e(t){hT.default(this,e),kT.default(this,"queuedRequests",[]),kT.default(this,"isRequestInFlight",!1),this.inputMergingFunction=t}return vT.default(e,[{key:"add",value:function(e,t){var n=this,r=new Promise((function(r,i){return n.queuedRequests.push({input:e,requestFunction:t,resolve:r,reject:i})}));return this.wakeupQueue(),r}},{key:"squashAndAdd",value:function(e,t){var n,r=this.queuedRequests;this.queuedRequests=[],r.length>0?(n=r.map((function(e){return e.input})).reduce(this.inputMergingFunction),n=this.inputMergingFunction(n,e)):n=e;var i=this.add(n,t);return r.forEach((function(e){return i.then(e.resolve,e.reject)})),i}},{key:"isEmpty",value:function(){return 0===this.queuedRequests.length&&!this.isRequestInFlight}},{key:"wakeupQueue",value:function(){var e=this;if(0!==this.queuedRequests.length&&!this.isRequestInFlight){var t=this.queuedRequests.shift();this.isRequestInFlight=!0,t.requestFunction(t.input).then(t.resolve,t.reject).then((function(t){e.isRequestInFlight=!1,e.wakeupQueue()}))}}}]),e}(),SR=function(){function e(t){hT.default(this,e),kT.default(this,"queueByNamespaceKey",new Map),this.inputReducer=t}var t,n;return vT.default(e,[{key:"add",value:function(){var e=pT.default(wT.default.mark((function e(t,n,r){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.invokeQueueMethod(t,(function(e){return e.add(n,r)})));case 1:case"end":return e.stop()}}),e,this)})));return function(t,n,r){return e.apply(this,arguments)}}()},{key:"squashAndAdd",value:(n=pT.default(wT.default.mark((function e(t,n,r){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.invokeQueueMethod(t,(function(e){return e.squashAndAdd(n,r)})));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"invokeQueueMethod",value:(t=pT.default(wT.default.mark((function e(t,n){var r,i;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.queueByNamespaceKey.has(t)||this.queueByNamespaceKey.set(t,new _R(this.inputReducer)),r=this.queueByNamespaceKey.get(t),i=n(r),this.queueByNamespaceKey.get(t).isEmpty()&&this.queueByNamespaceKey.delete(t),e.abrupt("return",i);case 5:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})}]),e}();function ER(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=bT.default(e);if(t){var i=bT.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gT.default(this,n)}}var TR=function(e){mT.default(n,e);var t=ER(n);function n(){var e;return hT.default(this,n),(e=t.call(this)).closed=!1,e.uuid=uT.v4(),e}return vT.default(n,[{key:"listenerUuid",get:function(){return this.uuid}},{key:"close",value:function(){this.removeAllListeners(),this.closed=!0}},{key:"ensureNotClosed",value:function(){if(this.closed)throw new Error("Invalid operation on closed object")}}]),n}(AT);function RR(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=bT.default(e);if(t){var i=bT.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gT.default(this,n)}}var IR=function(e){mT.default(f,e);var t,n,r,i,a,s,o,u,c,l=RR(f);function f(e,t,n){var r;hT.default(this,f),r=l.call(this,e,n),kT.default(yT.default(r),"isDeleted",!1);return r.updateMergingQueue=new _R((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.descriptor=t,r.descriptor.data=r.descriptor.data||{},r.descriptor.date_updated=new Date(r.descriptor.date_updated),r}return vT.default(f,[{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"document"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"data",get:function(){return this.descriptor.data}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"_update",value:function(e){switch(e.date_created=new Date(e.date_created),e.type){case"document_updated":if(e.id<=this.lastEventId){ZT("Document update skipped, current:",this.lastEventId,", remote:",e.id);break}var t=void 0!==this.descriptor.data?$T(this.descriptor.data):null;this.descriptor.last_event_id=e.id,this.descriptor.revision=e.document_revision,this.descriptor.date_updated=e.date_created,this.descriptor.data=e.document_data,this.broadcastEventToListeners("updated",{data:e.document_data,isLocal:!1,previousData:t}),this.services.storage.update(this.type,this.sid,this.uniqueName,{last_event_id:e.id,revision:e.document_revision,date_updated:e.date_created,data:e.document_data});break;case"document_removed":this.onRemoved(!1)}}},{key:"set",value:(c=pT.default(wT.default.mark((function e(t,n){var r,i=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n||{},e.abrupt("return",this.updateMergingQueue.squashAndAdd(r,(function(e){return i._setUnconditionally(t,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return c.apply(this,arguments)})},{key:"mutate",value:(u=pT.default(wT.default.mark((function e(t,n){var r,i=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n||{},e.abrupt("return",this.updateMergingQueue.add(r,(function(e){return i._setWithIfMatch(t,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"update",value:(o=pT.default(wT.default.mark((function e(t,n){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mutate((function(e){return Object.assign(e,t)}),n));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"setTtl",value:(s=pT.default(wT.default.mark((function e(t){var n;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._postUpdateToServer({ttl:t});case 2:n=e.sent,this.descriptor.date_expires=n.date_expires;case 4:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"_setUnconditionally",value:(a=pT.default(wT.default.mark((function e(t,n){var r;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._postUpdateToServer({data:t,revision:void 0,ttl:n});case 2:return r=e.sent,this._handleSuccessfulUpdateResult(r),e.abrupt("return",this.descriptor.data);case 5:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"_setWithIfMatch",value:(i=pT.default(wT.default.mark((function e(t,n){var r,i,a;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=t($T(this.descriptor.data)))){e.next=22;break}return i=this.revision,e.prev=3,e.next=6,this._postUpdateToServer({data:r,revision:i,ttl:n});case 6:return a=e.sent,this._handleSuccessfulUpdateResult(a),e.abrupt("return",this.descriptor.data);case 11:if(e.prev=11,e.t0=e.catch(3),412!==e.t0.status){e.next=19;break}return e.next=16,this._softSync();case 16:return e.abrupt("return",this._setWithIfMatch(t));case 19:throw e.t0;case 20:e.next=23;break;case 22:return e.abrupt("return",this.descriptor.data);case 23:case"end":return e.stop()}}),e,this,[[3,11]])}))),function(e,t){return i.apply(this,arguments)})},{key:"_handleSuccessfulUpdateResult",value:function(e){if(!(e.last_event_id<=this.descriptor.last_event_id)){var t=void 0!==this.descriptor.data?$T(this.descriptor.data):null;this.descriptor.revision=e.revision,this.descriptor.data=e.data,this.descriptor.last_event_id=e.last_event_id,this.descriptor.date_expires=e.date_expires,this.descriptor.date_updated=new Date(e.date_updated),this.services.storage.update(this.type,this.sid,this.uniqueName,{last_event_id:e.last_event_id,revision:e.revision,date_updated:e.date_updated,data:e.data}),this.broadcastEventToListeners("updated",{data:this.descriptor.data,isLocal:!0,previousData:t})}}},{key:"_postUpdateToServer",value:(r=pT.default(wT.default.mark((function e(t){var n,r,i;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isDeleted){e.next=17;break}return n={data:t.data},void 0!==t.ttl&&(n.ttl=t.ttl),r=t.revision,e.prev=4,e.next=7,this.services.network.post(this.uri,n,r);case 7:return i=e.sent,e.abrupt("return",{revision:i.body.revision,data:t.data,last_event_id:i.body.last_event_id,date_updated:i.body.date_updated,date_expires:i.body.date_expires});case 11:throw e.prev=11,e.t0=e.catch(4),404===e.t0.status&&this.onRemoved(!1),e.t0;case 15:e.next=18;break;case 17:return e.abrupt("return",Promise.reject(new JT("The Document has been removed",404,54100)));case 18:case"end":return e.stop()}}),e,this,[[4,11]])}))),function(e){return r.apply(this,arguments)})},{key:"_softSync",value:(n=pT.default(wT.default.mark((function e(){var t=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.services.network.get(this.uri).then((function(e){var n={type:"document_updated",id:e.body.last_event_id,document_revision:e.body.revision,document_data:e.body.data,date_created:e.body.date_updated};return t._update(n),t})).catch((function(e){404===e.status?t.onRemoved(!1):nR("Can't get updates for ".concat(t.sid,":"),e)})));case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"onRemoved",value:function(e){if(!this.isDeleted){var t=void 0!==this.descriptor.data?$T(this.descriptor.data):null;this.isDeleted=!0,this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e,previousData:t})}}},{key:"removeDocument",value:(t=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isDeleted){e.next=6;break}return e.next=3,this.services.network.delete(this.uri);case 3:this.onRemoved(!0),e.next=7;break;case 6:return e.abrupt("return",Promise.reject(new JT("The Document has been removed",404,54100)));case 7:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}],[{key:"type",get:function(){return"document"}}]),f}(xR),OR=function(e){mT.default(o,e);var t,n,r,i,a,s=RR(o);function o(e){var t;return hT.default(this,o),(t=s.call(this)).syncDocumentImpl=e,t.syncDocumentImpl.attach(yT.default(t)),t}return vT.default(o,[{key:"uri",get:function(){return this.syncDocumentImpl.uri}},{key:"revision",get:function(){return this.syncDocumentImpl.revision}},{key:"lastEventId",get:function(){return this.syncDocumentImpl.lastEventId}},{key:"dateExpires",get:function(){return this.syncDocumentImpl.dateExpires}},{key:"type",get:function(){return IR.type}},{key:"sid",get:function(){return this.syncDocumentImpl.sid}},{key:"data",get:function(){return this.syncDocumentImpl.data}},{key:"dateUpdated",get:function(){return this.syncDocumentImpl.dateUpdated}},{key:"uniqueName",get:function(){return this.syncDocumentImpl.uniqueName}},{key:"set",value:(a=pT.default(wT.default.mark((function e(t,n){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.set(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"mutate",value:(i=pT.default(wT.default.mark((function e(t,n){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.mutate(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return i.apply(this,arguments)})},{key:"update",value:(r=pT.default(wT.default.mark((function e(t,n){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.update(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"setTtl",value:(n=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.setTtl(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"removeDocument",value:(t=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.removeDocument());case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"close",value:function(){RT.default(bT.default(o.prototype),"close",this).call(this),this.syncDocumentImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return IR.type}}]),o}(TR);kT.default(OR,"removed","removed"),kT.default(OR,"updated","updated"),OT([nT.validateTypesAsync(nT.pureObject,["undefined",nT.objectSchema("document metadata",{ttl:[nT.nonNegativeInteger,"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Object,Object]),CT("design:returntype",Promise)],OR.prototype,"set",null),OT([nT.validateTypesAsync("function",["undefined",nT.objectSchema("document metadata",{ttl:[nT.nonNegativeInteger,"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Function,Object]),CT("design:returntype",Promise)],OR.prototype,"mutate",null),OT([nT.validateTypesAsync(nT.pureObject,["undefined",nT.objectSchema("document metadata",{ttl:[nT.nonNegativeInteger,"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Object,Object]),CT("design:returntype",Promise)],OR.prototype,"update",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger),CT("design:type",Function),CT("design:paramtypes",[Number]),CT("design:returntype",Promise)],OR.prototype,"setTtl",null);var CR=function(){function e(t){hT.default(this,e),this.descriptor=t}return vT.default(e,[{key:"uri",get:function(){return this.descriptor.uri}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.lastEventId}},{key:"dateUpdated",get:function(){return this.descriptor.dateUpdated}},{key:"dateExpires",get:function(){return this.descriptor.dateExpires}},{key:"index",get:function(){return this.descriptor.index}},{key:"data",get:function(){return this.descriptor.data}},{key:"update",value:function(e,t,n,r){return this.descriptor.lastEventId=e,this.descriptor.revision=t,this.descriptor.data=n,this.descriptor.dateUpdated=r,this}},{key:"updateDateExpires",value:function(e){this.descriptor.dateExpires=e}}]),e}(),Paginator=function(){function Paginator(e,t,n,r){hT.default(this,Paginator),this.prevToken=n,this.nextToken=r,this.items=e,this.source=t}var e,t;return vT.default(Paginator,[{key:"hasNextPage",get:function(){return!!this.nextToken}},{key:"hasPrevPage",get:function(){return!!this.prevToken}},{key:"nextPage",value:(t=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.hasNextPage){e.next=2;break}throw new Error("No next page");case 2:return e.abrupt("return",this.source(this.nextToken));case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"prevPage",value:(e=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.hasPrevPage){e.next=2;break}throw new Error("No previous page");case 2:return e.abrupt("return",this.source(this.prevToken));case 3:case"end":return e.stop()}}),e,this)}))),function(){return e.apply(this,arguments)})}]),Paginator}();function PR(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return AR(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return AR(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function AR(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var jR=function(){function e(t,n){hT.default(this,e),this.balanceFactor=0,this.key=t,this.value=n,this.parent=null,this.left=null,this.right=null}return vT.default(e,[{key:"isRoot",get:function(){return null===this.parent}},{key:"isLeaf",get:function(){return null===this.left&&null===this.right}},{key:"isLeftChild",get:function(){return this.parent.left===this}},{key:"update",value:function(e){this.value=e}},{key:"replace",value:function(e,t){e&&(this.left===t?this.left=t:this.right===t&&(this.right=t))}}]),e}(),MR=function(){function e(t,n){hT.default(this,e),this.isLessThan=t||function(e,t){return e<t},this.isEqual=n||function(e,t){return e===t},this.root=null,this.count=null}return vT.default(e,[{key:"size",get:function(){return this.count}},{key:"clear",value:function(){this.root=null,this.count=0}},{key:"set",value:function(e,t){var n=this.getNode(e);n?n.update(t):this.insert(e,t)}},{key:"insert",value:function(e,t){var n=new jR(e,t);if(this.count++,this.root){for(var r=this.root;;)if(this.isLessThan(e,r.key)){if(!r.left){r.left=n;break}r=r.left}else{if(!r.right){r.right=n;break}r=r.right}for(n.parent=r,r=n;r.parent;){var i=r.parent,a=i.balanceFactor;if(r.isLeftChild?i.balanceFactor++:i.balanceFactor--,Math.abs(i.balanceFactor)<Math.abs(a))break;if(i.balanceFactor<-1||i.balanceFactor>1){this.rebalance(i);break}r=i}}else this.root=n}},{key:"get",value:function(e){for(var t=this.root;t;){if(this.isEqual(e,t.key))return t.value;t=this.isLessThan(e,t.key)?t.left:t.right}return null}},{key:"delete",value:function(e){var t=this.getNode(e);if(!t||t.key!==e)return null;var n=t.parent,r=t.left,i=t.right;if(!!r!=!!i){var a=r||i;n||a?n&&!a?this.root=a:(n.replace(t,null),this.rebalance(n)):this.root=null}else{for(var s=t.left;s.right;)s=s.right;if(t.left===s)t.isRoot?(this.root=s,s.parent=null):(t.isLeftChild?t.parent.left=s:t.parent.right=s,s.parent=t.parent),s.right=t.right,s.right.parent=s,s.balanceFactor=t.balanceFactor,t={parent:s,isLeftChild:!0};else{var o=s.parent,u=s.left;o.right=u,u&&(u.parent=o),t.isRoot?(this.root=s,s.parent=null):(t.isLeftChild?t.parent.left=s:t.parent.right=s,s.parent=t.parent),s.right=t.right,s.right.parent=s,s.left=t.left,s.left.parent=s,s.balanceFactor=t.balanceFactor,t={parent:o,isLeftChild:!1}}}for(this.count--;t.parent;){var c=t.parent,l=c.balanceFactor;if(t.isLeftChild?c.balanceFactor-=1:c.balanceFactor+=1,Math.abs(c.balanceFactor)>Math.abs(l)){if(!(c.balanceFactor<-1||c.balanceFactor>1))break;if(this.rebalance(c),0!==c.parent.balanceFactor)break;t=c.parent}else t=c}return null}},{key:"getNode",value:function(e){for(var t=this.root;t;){if(this.isEqual(e,t.key))return t;t=this.isLessThan(e,t.key)?t.left:t.right}return null}},{key:"rebalance",value:function(e){e.balanceFactor<0?e.right.balanceFactor>0?(this.rotateRight(e.right),this.rotateLeft(e)):this.rotateLeft(e):e.balanceFactor>0&&(e.left.balanceFactor<0?(this.rotateLeft(e.left),this.rotateRight(e)):this.rotateRight(e))}},{key:"rotateLeft",value:function(e){var t=e.right;e.right=t.left,null!==t.left&&(t.left.parent=e),t.parent=e.parent,null===t.parent?this.root=t:e.isLeftChild?t.parent.left=t:t.parent.right=t,t.left=e,e.parent=t,e.balanceFactor=e.balanceFactor+1-Math.min(t.balanceFactor,0),t.balanceFactor=t.balanceFactor+1-Math.max(e.balanceFactor,0)}},{key:"rotateRight",value:function(e){var t=e.left;e.left=t.right,null!==t.right&&(t.right.parent=e),t.parent=e.parent,null===t.parent?this.root=t:e.isLeftChild?t.parent.left=t:t.parent.right=t,t.right=e,e.parent=t,e.balanceFactor=e.balanceFactor-1-Math.min(t.balanceFactor,0),t.balanceFactor=t.balanceFactor-1-Math.max(e.balanceFactor,0)}},{key:Symbol.iterator,value:wT.default.mark((function e(){var t,n,r;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=PR(this.getIterator()),e.prev=1,t.s();case 3:if((n=t.n()).done){e.next=9;break}return r=n.value,e.next=7,r;case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case"end":return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:"getIterator",value:wT.default.mark((function e(){var t,n,r,i=arguments;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=i.length>0&&void 0!==i[0]?i[0]:null,n=this.root;case 2:if(!n){e.next=8;break}if(!this.isEqual(t,n.key)&&(null!==t||n.left)){e.next=5;break}return e.abrupt("break",8);case 5:n=this.isLessThan(t,n.key)||null===t?n.left:n.right,e.next=2;break;case 8:if(n){e.next=10;break}return e.abrupt("return",null);case 10:r=!0;case 11:if(!r){e.next=29;break}return e.next=14,[n.key,n.value];case 14:if(r=!1,!n.right){e.next=21;break}for(n=n.right;n.left;)n=n.left;r=!0,e.next=27;break;case 21:if(!n.parent){e.next=26;break}r=n.parent.left===n,n=n.parent,e.next=27;break;case 26:return e.abrupt("break",37);case 27:e.next=35;break;case 29:if(!n.parent){e.next=34;break}r=n.parent.left===n,n=n.parent,e.next=35;break;case 34:return e.abrupt("break",37);case 35:e.next=11;break;case 37:return e.abrupt("return",null);case 38:case"end":return e.stop()}}),e,this)}))},{key:"getReverseIterator",value:wT.default.mark((function e(){var t,n,r,i=arguments;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=i.length>0&&void 0!==i[0]?i[0]:null,n=this.root;case 2:if(!n){e.next=8;break}if(!this.isEqual(t,n.key)&&(null!==t||n.right)){e.next=5;break}return e.abrupt("break",8);case 5:n=this.isLessThan(t,n.key)&&null!==t?n.left:n.right,e.next=2;break;case 8:if(n){e.next=10;break}return e.abrupt("return",null);case 10:r=!0;case 11:if(!r){e.next=29;break}return e.next=14,[n.key,n.value];case 14:if(r=!1,!n.left){e.next=21;break}for(n=n.left;n.right;)n=n.right;r=!0,e.next=27;break;case 21:if(!n.parent){e.next=26;break}r=n.parent.right===n,n=n.parent,e.next=27;break;case 26:return e.abrupt("break",37);case 27:e.next=35;break;case 29:if(!n.parent){e.next=34;break}r=n.parent.right===n,n=n.parent,e.next=35;break;case 34:return e.abrupt("break",37);case 35:e.next=11;break;case 37:return e.abrupt("return",null);case 38:case"end":return e.stop()}}),e,this)}))}]),e}();function LR(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return NR(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return NR(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function NR(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var UR=function(){function e(t,n){hT.default(this,e),this.value=t,this.revision=n||0}return vT.default(e,[{key:"isValid",get:function(){return!0}}]),e}(),DR=function(){function e(t){hT.default(this,e),this.revision=t}return vT.default(e,[{key:"isValid",get:function(){return!1}}]),e}(),FR=function(){function e(){hT.default(this,e),this.items=new MR}return vT.default(e,[{key:"store",value:function(e,t,n){var r=this.items.get(e);return r&&r.revision>n?r.isValid?r.value:null:(this.items.set(e,new UR(t,n)),t)}},{key:"delete",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=this.items.get(e);(!r||r.revision<t||r&&!0===n)&&this.items.set(e,new DR(t))}},{key:"isKnown",value:function(e,t){var n=this.items.get(e);return n&&n.revision>=t}},{key:"get",value:function(e){var t=this.items.get(e);return t&&t.isValid?t.value:null}},{key:"has",value:function(e){var t=this.items.get(e);return t&&t.isValid}},{key:"forEach",value:function(e){if(this.items){var t,n=LR(this.items);try{for(n.s();!(t=n.n()).done;){var r=ET.default(t.value,2),i=r[0],a=r[1];a.isValid&&e(i,a.value)}}catch(e){n.e(e)}finally{n.f()}}}}]),e}();function BR(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=bT.default(e);if(t){var i=bT.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gT.default(this,n)}}var qR=function(e){mT.default(v,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h=BR(v);function v(e,t,n){var r;hT.default(this,v);return(r=h.call(this,e,n)).updateMergingQueue=new SR((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new FR,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),r}return vT.default(v,[{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"links",get:function(){return this.descriptor.links}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"list"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"_addOrUpdateItemOnServer",value:(p=pT.default(wT.default.mark((function e(t,n,r,i){var a,s;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a={data:n},void 0!==i&&(a.ttl=i),e.next=4,this.services.network.post(t,a,r);case 4:return(s=e.sent).body.data=n,s.body.date_updated=new Date(s.body.date_updated),e.abrupt("return",s.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n,r){return p.apply(this,arguments)})},{key:"push",value:(d=pT.default(wT.default.mark((function e(t,n){var r,i,a;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=(n||{}).ttl,e.next=3,this._addOrUpdateItemOnServer(this.links.items,t,void 0,r);case 3:return i=e.sent,a=Number(i.index),this._handleItemMutated(a,i.url,i.last_event_id,i.revision,t,i.date_updated,i.date_expires,!0,!1),e.abrupt("return",this.cache.get(a));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return d.apply(this,arguments)})},{key:"set",value:(f=pT.default(wT.default.mark((function e(t,n,r){var i,a=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r||{},e.abrupt("return",this.updateMergingQueue.squashAndAdd(t,i,(function(e){return a._updateItemUnconditionally(t,n,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"_updateItemUnconditionally",value:(l=pT.default(wT.default.mark((function e(t,n,r){var i,a;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return i=e.sent,e.next=5,this._addOrUpdateItemOnServer(i.uri,n,void 0,r);case 5:return a=e.sent,this._handleItemMutated(t,a.url,a.last_event_id,a.revision,a.data,a.date_updated,a.date_expires,!1,!1),e.abrupt("return",this.cache.get(t));case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return l.apply(this,arguments)})},{key:"_updateItemWithIfMatch",value:(c=pT.default(wT.default.mark((function e(t,n,r){var i,a,s,o;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:if(i=e.sent,!(a=n($T(i.data)))){e.next=25;break}return s=i.revision,e.prev=6,e.next=9,this._addOrUpdateItemOnServer(i.uri,a,s,r);case 9:return o=e.sent,this._handleItemMutated(t,o.url,o.last_event_id,o.revision,o.data,o.date_updated,o.date_expires,!1,!1),e.abrupt("return",this.cache.get(t));case 14:if(e.prev=14,e.t0=e.catch(6),412!==e.t0.status){e.next=22;break}return e.next=19,this._getItemFromServer(t);case 19:return e.abrupt("return",this._updateItemWithIfMatch(t,n,r));case 22:throw e.t0;case 23:e.next=26;break;case 25:return e.abrupt("return",i);case 26:case"end":return e.stop()}}),e,this,[[6,14]])}))),function(e,t,n){return c.apply(this,arguments)})},{key:"mutate",value:(u=pT.default(wT.default.mark((function e(t,n,r){var i,a=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r||{},e.abrupt("return",this.updateMergingQueue.add(t,i,(function(e){return a._updateItemWithIfMatch(t,n,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"update",value:(o=pT.default(wT.default.mark((function e(t,n,r){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mutate(t,(function(e){return Object.assign(e,n)}),r));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return o.apply(this,arguments)})},{key:"remove",value:function(){var e=pT.default(wT.default.mark((function e(t){var n,r,i;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return n=e.sent,r=$T(n.data),e.next=6,this.services.network.delete(n.uri);case 6:i=e.sent,this._handleItemRemoved(t,i.body.last_event_id,r,new Date(i.body.date_updated),!1);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"get",value:function(){var e=pT.default(wT.default.mark((function e(t){var n;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=this.cache.get(t))){e.next=5;break}return e.abrupt("return",n);case 5:return e.abrupt("return",this._getItemFromServer(t));case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"_getItemFromServer",value:(s=pT.default(wT.default.mark((function e(t){var n;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.queryItems({index:t});case 2:if(!((n=e.sent).items.length<1)){e.next=7;break}throw new JT("No item with index ".concat(t," found"),404,54151);case 7:return e.abrupt("return",n.items[0]);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"queryItems",value:function(){var e=pT.default(wT.default.mark((function e(t){var n,r,i,a,s=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new zT(this.links.items).queryParam("From",t.from).queryParam("PageSize",t.limit).queryParam("Index",t.index).queryParam("PageToken",t.pageToken).queryParam("Order",t.order).build(),e.next=4,this.services.network.get(n);case 4:return r=e.sent,i=r.body.items.map((function(e){return e.date_updated=new Date(e.date_updated),s.cache.get(e.index)?s._handleItemMutated(e.index,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):s.cache.store(Number(e.index),new CR({index:Number(e.index),uri:e.url,revision:e.revision,lastEventId:e.last_event_id,dateUpdated:e.date_updated,dateExpires:e.date_expires,data:e.data}),e.last_event_id),s.cache.get(e.index)})),a=r.body.meta,e.abrupt("return",new Paginator(i,(function(e){return s.queryItems({pageToken:e})}),a.previous_token,a.next_token));case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"getItems",value:(a=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return KT((t=t||{}).pageSize),t.limit=t.pageSize||t.limit||50,t.order=t.order||"asc",e.abrupt("return",this.queryItems(t));case 5:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"getContext",value:(i=pT.default(wT.default.mark((function e(){var t;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.context){e.next=5;break}return e.next=3,this.services.network.get(this.links.context);case 3:t=e.sent,this._updateContextIfRequired(t.body.data,t.body.last_event_id);case 5:return e.abrupt("return",this.context);case 6:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"setTtl",value:(r=pT.default(wT.default.mark((function e(t){var n,r;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,n={ttl:t},e.next=4,this.services.network.post(this.uri,n);case 4:r=e.sent,this.descriptor.date_expires=r.body.date_expires,e.next=12;break;case 8:throw e.prev=8,e.t0=e.catch(0),404===e.t0.status&&this.onRemoved(!1),e.t0;case 12:case"end":return e.stop()}}),e,this,[[0,8]])}))),function(e){return r.apply(this,arguments)})},{key:"setItemTtl",value:(n=pT.default(wT.default.mark((function e(t,n){var r,i,a;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return r=e.sent,i={ttl:n},e.next=6,this.services.network.post(r.uri,i);case 6:a=e.sent,r.updateDateExpires(a.body.date_expires);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeList",value:(t=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}},{key:"shouldIgnoreEvent",value:function(e,t){return this.cache.isKnown(e,t)}},{key:"_update",value:function(e,t){var n=Number(e.item_index);switch(e.date_created=new Date(e.date_created),e.type){case"list_item_added":case"list_item_updated":this._handleItemMutated(n,e.item_url,e.id,e.item_revision,e.item_data,e.date_created,void 0,"list_item_added"===e.type,!0);break;case"list_item_removed":this._handleItemRemoved(n,e.id,e.item_data,e.date_created,!0);break;case"list_context_updated":this._handleContextUpdate(e.context_data,e.id,e.date_created);break;case"list_removed":this.onRemoved(!1)}t&&this._advanceLastEventId(e.id,e.list_revision)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e,t&&(this.descriptor.revision=t))}},{key:"_updateRootDateUpdated",value:function(e){(!this.descriptor.date_updated||e.getTime()>this.descriptor.date_updated.getTime())&&(this.descriptor.date_updated=e,this.services.storage.update(this.type,this.sid,this.uniqueName,{date_updated:e}))}},{key:"_handleItemMutated",value:function(e,t,n,r,i,a,s,o,u){if(this.shouldIgnoreEvent(e,n))ZT("Item ".concat(e," update skipped, current: ").concat(this.lastEventId,", remote: ").concat(n));else{this._updateRootDateUpdated(a);var c=this.cache.get(e);if(!c){var l=new CR({index:e,uri:t,lastEventId:n,revision:r,data:i,dateUpdated:a,dateExpires:s});return this.cache.store(e,l,n),void this.emitItemMutationEvent(l,u,o)}var f=$T(c.data);c.update(n,r,i,a),this.cache.store(e,c,n),void 0!==s&&c.updateDateExpires(s),this.emitItemMutationEvent(c,u,!1,f)}}},{key:"emitItemMutationEvent",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=n?"itemAdded":"itemUpdated",a={item:e,isLocal:!t};n||(a.previousItemData=r),this.broadcastEventToListeners(i,a)}},{key:"_handleItemRemoved",value:function(e,t,n,r,i){this._updateRootDateUpdated(r),this.cache.delete(e,t),this.broadcastEventToListeners("itemRemoved",{index:e,isLocal:!i,previousItemData:n})}},{key:"_handleContextUpdate",value:function(e,t,n){this._updateRootDateUpdated(n),this._updateContextIfRequired(e,t)&&this.broadcastEventToListeners("contextUpdated",{context:e,isLocal:!1})}},{key:"_updateContextIfRequired",value:function(e,t){return!this.contextEventId||t>this.contextEventId?(this.context=e,this.contextEventId=t,!0):(ZT("Context update skipped, current:",this.lastEventId,", remote:",t),!1)}}],[{key:"type",get:function(){return"list"}}]),v}(xR),WR=function(e){mT.default(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=BR(p);function p(e){var t;return hT.default(this,p),(t=d.call(this)).syncListImpl=e,t.syncListImpl.attach(yT.default(t)),t}return vT.default(p,[{key:"uri",get:function(){return this.syncListImpl.uri}},{key:"revision",get:function(){return this.syncListImpl.revision}},{key:"lastEventId",get:function(){return this.syncListImpl.lastEventId}},{key:"links",get:function(){return this.syncListImpl.links}},{key:"dateExpires",get:function(){return this.syncListImpl.dateExpires}},{key:"type",get:function(){return qR.type}},{key:"sid",get:function(){return this.syncListImpl.sid}},{key:"uniqueName",get:function(){return this.syncListImpl.uniqueName}},{key:"dateUpdated",get:function(){return this.syncListImpl.dateUpdated}},{key:"push",value:(f=pT.default(wT.default.mark((function e(t,n){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.push(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return f.apply(this,arguments)})},{key:"set",value:(l=pT.default(wT.default.mark((function e(t,n,r){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.set(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return l.apply(this,arguments)})},{key:"mutate",value:(c=pT.default(wT.default.mark((function e(t,n,r){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.mutate(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return c.apply(this,arguments)})},{key:"update",value:(u=pT.default(wT.default.mark((function e(t,n,r){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.update(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"remove",value:(o=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.remove(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"get",value:(s=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.get(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"getContext",value:(a=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.getContext());case 2:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"getItems",value:(i=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.getItems(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"setTtl",value:(r=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.setTtl(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"setItemTtl",value:(n=pT.default(wT.default.mark((function e(t,n){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.setItemTtl(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeList",value:(t=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.removeList());case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"close",value:function(){RT.default(bT.default(p.prototype),"close",this).call(this),this.syncListImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return qR.type}}]),p}(TR);kT.default(WR,"itemAdded","itemAdded"),kT.default(WR,"itemUpdated","itemUpdated"),kT.default(WR,"itemRemoved","itemRemoved"),kT.default(WR,"removed","removed"),OT([nT.validateTypesAsync(nT.pureObject,["undefined",nT.objectSchema("item metadata",{ttl:[nT.nonNegativeInteger,"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Object,Object]),CT("design:returntype",Promise)],WR.prototype,"push",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger,nT.pureObject,["undefined",nT.objectSchema("item metadata",{ttl:[nT.nonNegativeInteger,"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Number,Object,Object]),CT("design:returntype",Promise)],WR.prototype,"set",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger,"function",["undefined",nT.objectSchema("item metadata",{ttl:[nT.nonNegativeInteger,"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Number,Function,Object]),CT("design:returntype",Promise)],WR.prototype,"mutate",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger,nT.pureObject,["undefined",nT.objectSchema("item metadata",{ttl:[nT.nonNegativeInteger,"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Number,Object,Object]),CT("design:returntype",Promise)],WR.prototype,"update",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger),CT("design:type",Function),CT("design:paramtypes",[Number]),CT("design:returntype",Promise)],WR.prototype,"remove",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger),CT("design:type",Function),CT("design:paramtypes",[Number]),CT("design:returntype",Promise)],WR.prototype,"get",null),OT([nT.validateTypesAsync(["undefined",nT.objectSchema("query options",{from:[nT.nonNegativeInteger,"undefined"],pageSize:[nT.custom((function(e){return[HT(e),"a positive integer"]})),"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Object]),CT("design:returntype",Promise)],WR.prototype,"getItems",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger),CT("design:type",Function),CT("design:paramtypes",[Number]),CT("design:returntype",Promise)],WR.prototype,"setTtl",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger,nT.nonNegativeInteger),CT("design:type",Function),CT("design:paramtypes",[Number,Number]),CT("design:returntype",Promise)],WR.prototype,"setItemTtl",null);var zR=function(){function e(t){hT.default(this,e),this.descriptor=t}return vT.default(e,[{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"key",get:function(){return this.descriptor.key}},{key:"data",get:function(){return this.descriptor.data}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"update",value:function(e,t,n,r){return this.descriptor.last_event_id=e,this.descriptor.revision=t,this.descriptor.data=n,this.descriptor.date_updated=r,this}},{key:"updateDateExpires",value:function(e){this.descriptor.date_expires=e}}]),e}();function GR(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=bT.default(e);if(t){var i=bT.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gT.default(this,n)}}var JR=function(e){mT.default(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=GR(p);function p(e,t,n){var r;hT.default(this,p);return(r=d.call(this,e,n)).updateMergingQueue=new SR((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new FR,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),t.items&&t.items.forEach((function(e){e.date_updated=new Date(e.date_updated),r.cache.store(e.key,new zR(e),e.last_event_id)})),r}return vT.default(p,[{key:"uri",get:function(){return this.descriptor.url}},{key:"links",get:function(){return this.descriptor.links}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"map"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"set",value:(f=pT.default(wT.default.mark((function e(t,n,r){var i,a=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r||{},e.abrupt("return",this.updateMergingQueue.squashAndAdd(t,i,(function(e){return a._putItemUnconditionally(t,n,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"get",value:function(){var e=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=t){e.next=2;break}throw new JT("SyncMapItem key may not be empty",400,54209);case 2:if(!this.cache.has(t)){e.next=6;break}return e.abrupt("return",this.cache.get(t));case 6:return e.abrupt("return",this._getItemFromServer(t));case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"_getItemFromServer",value:(l=pT.default(wT.default.mark((function e(t){var n;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.queryItems({key:t});case 2:if(!((n=e.sent).items.length<1)){e.next=7;break}throw new JT("The specified Map Item does not exist",404,54201);case 7:return e.abrupt("return",n.items[0]);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"mutate",value:(c=pT.default(wT.default.mark((function e(t,n,r){var i,a=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=r||{},e.abrupt("return",this.updateMergingQueue.add(t,i,(function(e){return a._putItemWithIfMatch(t,n,e.ttl)})));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return c.apply(this,arguments)})},{key:"update",value:(u=pT.default(wT.default.mark((function e(t,n,r){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mutate(t,(function(e){return Object.assign(e,n)}),r));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"_putItemUnconditionally",value:(o=pT.default(wT.default.mark((function e(t,n,r){var i,a;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._putItemToServer(t,n,void 0,r);case 2:return i=e.sent,a=i.item,this._handleItemMutated(a.key,a.url,a.last_event_id,a.revision,a.data,a.date_updated,a.date_expires,i.added,!1),e.abrupt("return",this.cache.get(a.key));case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return o.apply(this,arguments)})},{key:"_putItemWithIfMatch",value:(s=pT.default(wT.default.mark((function e(t,n,r){var i,a,s,o,u;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t).catch((function(e){if(404===e.status)return new zR({key:t,data:{},last_event_id:-1,revision:"-1",url:null,date_updated:null,date_expires:null});throw e}));case 2:if(i=e.sent,!(a=n($T(i.data)))){e.next=26;break}return s=i.revision,e.prev=6,e.next=9,this._putItemToServer(t,a,s,r);case 9:return o=e.sent,u=o.item,this._handleItemMutated(u.key,u.url,u.last_event_id,u.revision,u.data,u.date_updated,u.date_expires,o.added,!1),e.abrupt("return",this.cache.get(u.key));case 15:if(e.prev=15,e.t0=e.catch(6),412!==e.t0.status){e.next=23;break}return e.next=20,this._getItemFromServer(t);case 20:return e.abrupt("return",this._putItemWithIfMatch(t,n,r));case 23:throw e.t0;case 24:e.next=27;break;case 26:return e.abrupt("return",i);case 27:case"end":return e.stop()}}),e,this,[[6,15]])}))),function(e,t,n){return s.apply(this,arguments)})},{key:"_putItemToServer",value:(a=pT.default(wT.default.mark((function e(t,n,r,i){var a,s,o,u,c;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=new zT(this.links.items).pathSegment(t).build(),s={data:n},void 0!==i&&(s.ttl=i),e.prev=3,e.next=6,this.services.network.put(a,s,r);case 6:return o=e.sent,(u=o.body).data=n,u.date_updated=new Date(u.date_updated),c=201===o.status.code,e.abrupt("return",{added:c,item:u});case 14:throw e.prev=14,e.t0=e.catch(3),404===e.t0.status&&this.onRemoved(!1),e.t0;case 18:case"end":return e.stop()}}),e,this,[[3,14]])}))),function(e,t,n,r){return a.apply(this,arguments)})},{key:"remove",value:function(){var e=pT.default(wT.default.mark((function e(t){var n,r,i;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return n=e.sent,r=$T(n.data),e.next=6,this.services.network.delete(n.uri);case 6:i=e.sent,this._handleItemRemoved(t,i.body.last_event_id,r,new Date(i.body.date_updated),!1);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"queryItems",value:function(){var e=pT.default(wT.default.mark((function e(t){var n,r,i,a,s=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new zT(this.links.items).queryParam("From",t.from).queryParam("PageSize",t.limit).queryParam("Key",t.key).queryParam("PageToken",t.pageToken).queryParam("Order",t.order).build(),e.next=4,this.services.network.get(n);case 4:return r=e.sent,i=r.body.items.map((function(e){return e.date_updated=new Date(e.date_updated),s.cache.get(e.key)?s._handleItemMutated(e.key,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):s.cache.store(e.key,new zR(e),e.last_event_id),s.cache.get(e.key)})),a=r.body.meta,e.abrupt("return",new Paginator(i,(function(e){return s.queryItems({pageToken:e})}),a.previous_token,a.next_token));case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"getItems",value:(i=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return KT((t=t||{}).pageSize),t.limit=t.pageSize||t.limit||50,t.order=t.order||"asc",e.abrupt("return",this.queryItems(t));case 5:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"shouldIgnoreEvent",value:function(e,t){return this.cache.isKnown(e,t)}},{key:"_update",value:function(e,t){switch(e.date_created=new Date(e.date_created),e.type){case"map_item_added":case"map_item_updated":this._handleItemMutated(e.item_key,e.item_url,e.id,e.item_revision,e.item_data,e.date_created,void 0,"map_item_added"===e.type,!0);break;case"map_item_removed":this._handleItemRemoved(e.item_key,e.id,e.item_data,e.date_created,!0);break;case"map_removed":this.onRemoved(!1)}t&&this._advanceLastEventId(e.id,e.map_revision)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e,t&&(this.descriptor.revision=t))}},{key:"_updateRootDateUpdated",value:function(e){(!this.descriptor.date_updated||e.getTime()>this.descriptor.date_updated.getTime())&&(this.descriptor.date_updated=e,this.services.storage.update(this.type,this.sid,this.uniqueName,{date_updated:e}))}},{key:"_handleItemMutated",value:function(e,t,n,r,i,a,s,o,u){if(this.shouldIgnoreEvent(e,n))ZT("SyncMapItem ",e," update skipped, current:",this.lastEventId,", remote:",n);else{this._updateRootDateUpdated(a);var c=this.cache.get(e);if(!c){var l=new zR({key:e,url:t,last_event_id:n,revision:r,data:i,date_updated:a,date_expires:s});return this.cache.store(e,l,n),void this.emitItemMutationEvent(l,u,o)}var f=$T(c.data);c.update(n,r,i,a),this.cache.store(e,c,n),void 0!==s&&c.updateDateExpires(s),this.emitItemMutationEvent(c,u,!1,f)}}},{key:"emitItemMutationEvent",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=n?"itemAdded":"itemUpdated",a={item:e,isLocal:!t};n||(a.previousItemData=r),this.broadcastEventToListeners(i,a)}},{key:"_handleItemRemoved",value:function(e,t,n,r,i){this._updateRootDateUpdated(r),this.cache.delete(e,t),this.broadcastEventToListeners("itemRemoved",{key:e,isLocal:!i,previousItemData:n})}},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}},{key:"setTtl",value:(r=pT.default(wT.default.mark((function e(t){var n,r;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,n={ttl:t},e.next=4,this.services.network.post(this.uri,n);case 4:r=e.sent,this.descriptor.date_expires=r.body.date_expires,e.next=12;break;case 8:throw e.prev=8,e.t0=e.catch(0),404===e.t0.status&&this.onRemoved(!1),e.t0;case 12:case"end":return e.stop()}}),e,this,[[0,8]])}))),function(e){return r.apply(this,arguments)})},{key:"setItemTtl",value:(n=pT.default(wT.default.mark((function e(t,n){var r,i,a;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.get(t);case 2:return r=e.sent,i={ttl:n},e.next=6,this.services.network.post(r.uri,i);case 6:a=e.sent,r.updateDateExpires(a.body.date_expires);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeMap",value:(t=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}],[{key:"type",get:function(){return"map"}}]),p}(xR),VR=function(e){mT.default(f,e);var t,n,r,i,a,s,o,u,c,l=GR(f);function f(e){var t;return hT.default(this,f),(t=l.call(this)).syncMapImpl=e,t.syncMapImpl.attach(yT.default(t)),t}return vT.default(f,[{key:"uri",get:function(){return this.syncMapImpl.uri}},{key:"links",get:function(){return this.syncMapImpl.links}},{key:"revision",get:function(){return this.syncMapImpl.revision}},{key:"lastEventId",get:function(){return this.syncMapImpl.lastEventId}},{key:"dateExpires",get:function(){return this.syncMapImpl.dateExpires}},{key:"type",get:function(){return JR.type}},{key:"sid",get:function(){return this.syncMapImpl.sid}},{key:"uniqueName",get:function(){return this.syncMapImpl.uniqueName}},{key:"dateUpdated",get:function(){return this.syncMapImpl.dateUpdated}},{key:"set",value:(c=pT.default(wT.default.mark((function e(t,n,r){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.set(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return c.apply(this,arguments)})},{key:"get",value:(u=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.get(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"mutate",value:(o=pT.default(wT.default.mark((function e(t,n,r){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.mutate(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return o.apply(this,arguments)})},{key:"update",value:(s=pT.default(wT.default.mark((function e(t,n,r){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.update(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return s.apply(this,arguments)})},{key:"remove",value:(a=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.remove(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"getItems",value:(i=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.getItems(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"setTtl",value:(r=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.setTtl(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"setItemTtl",value:(n=pT.default(wT.default.mark((function e(t,n){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncMapImpl.setItemTtl(t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeMap",value:(t=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.next=3,this.syncMapImpl.removeMap();case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"close",value:function(){RT.default(bT.default(f.prototype),"close",this).call(this),this.syncMapImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return JR.type}}]),f}(TR);function $R(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=bT.default(e);if(t){var i=bT.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gT.default(this,n)}}kT.default(VR,"itemAdded","itemAdded"),kT.default(VR,"itemUpdated","itemUpdated"),kT.default(VR,"itemRemoved","itemRemoved"),kT.default(VR,"removed","removed"),OT([nT.validateTypesAsync("string",nT.pureObject,["undefined",nT.objectSchema("item metadata",{ttl:[nT.nonNegativeInteger,"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[String,Object,Object]),CT("design:returntype",Promise)],VR.prototype,"set",null),OT([nT.validateTypesAsync("string"),CT("design:type",Function),CT("design:paramtypes",[String]),CT("design:returntype",Promise)],VR.prototype,"get",null),OT([nT.validateTypesAsync("string","function",["undefined",nT.objectSchema("item metadata",{ttl:[nT.nonNegativeInteger,"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[String,Function,Object]),CT("design:returntype",Promise)],VR.prototype,"mutate",null),OT([nT.validateTypesAsync("string",nT.pureObject,["undefined",nT.objectSchema("item metadata",{ttl:[nT.nonNegativeInteger,"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[String,Object,Object]),CT("design:returntype",Promise)],VR.prototype,"update",null),OT([nT.validateTypesAsync("string"),CT("design:type",Function),CT("design:paramtypes",[String]),CT("design:returntype",Promise)],VR.prototype,"remove",null),OT([nT.validateTypesAsync(["undefined",nT.objectSchema("query options",{from:["string","undefined"],pageSize:[nT.custom((function(e){return[HT(e),"a positive integer"]})),"undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Object]),CT("design:returntype",Promise)],VR.prototype,"getItems",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger),CT("design:type",Function),CT("design:paramtypes",[Number]),CT("design:returntype",Promise)],VR.prototype,"setTtl",null),OT([nT.validateTypesAsync("string",nT.nonNegativeInteger),CT("design:type",Function),CT("design:paramtypes",[String,Number]),CT("design:returntype",Promise)],VR.prototype,"setItemTtl",null);var KR=function(e){mT.default(a,e);var t,n,r,i=$R(a);function a(e,t,n){var r;return hT.default(this,a),(r=i.call(this,e,n)).descriptor=t,r}return vT.default(a,[{key:"uri",get:function(){return this.descriptor.url}},{key:"links",get:function(){return this.descriptor.links}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"stream"}},{key:"lastEventId",get:function(){return null}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"publishMessage",value:(r=pT.default(wT.default.mark((function e(t){var n,r,i,a;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={data:t},e.next=3,this.services.network.post(this.links.messages,n);case 3:return r=e.sent,i=r.body,a=this._handleMessagePublished(i.sid,t,!1),e.abrupt("return",a);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"setTtl",value:(n=pT.default(wT.default.mark((function e(t){var n,r;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,n={ttl:t},e.next=4,this.services.network.post(this.uri,n);case 4:r=e.sent,this.descriptor.date_expires=r.body.date_expires,e.next=12;break;case 8:throw e.prev=8,e.t0=e.catch(0),404===e.t0.status&&this.onRemoved(!1),e.t0;case 12:case"end":return e.stop()}}),e,this,[[0,8]])}))),function(e){return n.apply(this,arguments)})},{key:"removeStream",value:(t=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_update",value:function(e){switch(e.type){case"stream_message_published":this._handleMessagePublished(e.message_sid,e.message_data,!0);break;case"stream_removed":this.onRemoved(!1)}}},{key:"_handleMessagePublished",value:function(e,t,n){var r={sid:e,data:t};return this.broadcastEventToListeners("messagePublished",{message:r,isLocal:!n}),r}},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}}],[{key:"type",get:function(){return"stream"}}]),a}(xR);OT([nT.validateTypesAsync(nT.pureObject),CT("design:type",Function),CT("design:paramtypes",[Object]),CT("design:returntype",Promise)],KR.prototype,"publishMessage",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger),CT("design:type",Function),CT("design:paramtypes",[Number]),CT("design:returntype",Promise)],KR.prototype,"setTtl",null);var HR=function(e){mT.default(a,e);var t,n,r,i=$R(a);function a(e){var t;return hT.default(this,a),(t=i.call(this)).syncStreamImpl=e,t.syncStreamImpl.attach(yT.default(t)),t}return vT.default(a,[{key:"uri",get:function(){return this.syncStreamImpl.uri}},{key:"links",get:function(){return this.syncStreamImpl.links}},{key:"dateExpires",get:function(){return this.syncStreamImpl.dateExpires}},{key:"type",get:function(){return KR.type}},{key:"lastEventId",get:function(){return null}},{key:"sid",get:function(){return this.syncStreamImpl.sid}},{key:"uniqueName",get:function(){return this.syncStreamImpl.uniqueName}},{key:"publishMessage",value:(r=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncStreamImpl.publishMessage(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"setTtl",value:(n=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncStreamImpl.setTtl(t));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"removeStream",value:(t=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncStreamImpl.removeStream());case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"close",value:function(){RT.default(bT.default(a.prototype),"close",this).call(this),this.syncStreamImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return KR.type}}]),a}(TR);kT.default(HR,"messagePublished","messagePublished"),kT.default(HR,"removed","removed"),OT([nT.validateTypesAsync(nT.pureObject),CT("design:type",Function),CT("design:paramtypes",[Object]),CT("design:returntype",Promise)],HR.prototype,"publishMessage",null),OT([nT.validateTypesAsync(nT.nonNegativeInteger),CT("design:type",Function),CT("design:paramtypes",[Number]),CT("design:returntype",Promise)],HR.prototype,"setTtl",null);var YR=function e(t){hT.default(this,e),this.sdk="js",this.sdkVer=t,this.os=IT.os.family,this.osVer=IT.os.version,this.pl=IT.name,this.plVer=IT.version},QR=function(){function e(){hT.default(this,e),this.names=new Map,this.entities=new Map}return vT.default(e,[{key:"store",value:function(e){var t=this.entities.get(e.sid);return t||(this.entities.set(e.sid,e),e.uniqueName&&this.names.set(e.type+"::"+e.uniqueName,e.sid),e)}},{key:"getResolved",value:function(e,t){var n=this.names.get(t+"::"+e);return n?this.entities.get(n):null}},{key:"get",value:function(e,t){return this.entities.get(e)||this.getResolved(e,t)||null}},{key:"remove",value:function(e){var t=this.entities.get(e);t&&(this.entities.delete(e),t.uniqueName&&this.names.delete(t.type+"::"+t.uniqueName))}}]),e}();function XR(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=bT.default(e);if(t){var i=bT.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gT.default(this,n)}}var ZR=function(e){mT.default(n,e);var t=XR(n);function n(e,r,i,a){var s;return hT.default(this,n),(s=t.call(this,r,i)).descriptor=e,s.cache=new FR,a&&a.forEach((function(e){s.cache.store(e.key,{key:e.key,value:e.data},e.revision)})),s}return vT.default(n,[{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return null}},{key:"type",get:function(){return n.type}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"indexName",get:function(){return this.descriptor.indexName}},{key:"queryString",get:function(){return this.descriptor.queryExpression}},{key:"queryUri",get:function(){return this.descriptor.queryUri}},{key:"liveQueryDescriptor",get:function(){return this.descriptor}},{key:"onRemoved",value:function(){}},{key:"getItems",value:function(){var e={};return this.cache.forEach((function(t,n){e[t]=n.value})),e}},{key:"_update",value:function(e,t){switch(e.type){case"live_query_item_updated":this.handleItemMutated(e.item_key,e.item_data,e.item_revision);break;case"live_query_item_removed":this.handleItemRemoved(e.item_key,e.item_revision);break;case"live_query_updated":this.handleBatchUpdate(e.items)}t&&this._advanceLastEventId(e.last_event_id)}},{key:"handleItemMutated",value:function(e,t,n){if(this.shouldIgnoreEvent(e,n))ZT("Item ".concat(e," update skipped, revision: ").concat(n));else{var r={key:e,value:t};this.cache.store(e,r,n),this.broadcastEventToListeners("itemUpdated",r)}}},{key:"handleItemRemoved",value:function(e,t){var n=null===t;this.shouldIgnoreEvent(e,t)?ZT("Item ".concat(e," delete skipped, revision: ").concat(t)):(this.cache.delete(e,t,n),this.broadcastEventToListeners("itemRemoved",{key:e}))}},{key:"handleBatchUpdate",value:function(e){var t=this,n={};for(var r in null!=e&&e.forEach((function(e){n[e.key]={data:e.data,revision:e.revision}})),this.cache.forEach((function(e,r){var i=n[e];null!=i?t.handleItemMutated(e,i.data,i.revision):t.handleItemRemoved(e,null),delete n[e]})),n)this.handleItemMutated(r,n[r].data,n[r].revision)}},{key:"shouldIgnoreEvent",value:function(e,t){return null!=e&&null!=t&&this.cache.isKnown(e,t)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e)}}],[{key:"type",get:function(){return"live_query"}}]),n}(xR);function eI(e){return tI.apply(this,arguments)}function tI(){return(tI=pT.default(wT.default.mark((function e(t){var n,r,i,a,s,o;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.network,r=t.queryString,i=t.uri,a=t.type,null!=r){e.next=3;break}throw new JT("Invalid query",400,54507);case 3:return s={query_string:r},a===nI.type&&(s.type=a),e.next=7,n.post(i,s,void 0,!0);case 7:return o=e.sent,e.abrupt("return",o.body);case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var nI=function(e){mT.default(n,e);var t=XR(n);function n(e){var r;return hT.default(this,n),(r=t.call(this)).liveQueryImpl=e,r.liveQueryImpl.attach(yT.default(r)),r}return vT.default(n,[{key:"type",get:function(){return ZR.type}},{key:"lastEventId",get:function(){return this.liveQueryImpl.lastEventId}},{key:"sid",get:function(){return this.liveQueryImpl.sid}},{key:"close",value:function(){RT.default(bT.default(n.prototype),"close",this).call(this),this.liveQueryImpl.detach(this.listenerUuid)}},{key:"getItems",value:function(){return this.ensureNotClosed(),this.liveQueryImpl.getItems()}}],[{key:"type",get:function(){return ZR.type}}]),n}(TR);kT.default(nI,"itemUpdated","itemUpdated"),kT.default(nI,"itemRemoved","itemRemoved");var rI=function(e){mT.default(i,e);var t,n,r=XR(i);function i(e){var t;return hT.default(this,i),t=r.call(this),kT.default(yT.default(t),"queryExpression",null),kT.default(yT.default(t),"items",{}),Object.assign(yT.default(t),e),t.updateIndexName(e.indexName),t}return vT.default(i,[{key:"type",get:function(){return i.type}},{key:"search",value:(n=pT.default(wT.default.mark((function e(t){var n=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.items={},e.abrupt("return",eI({network:this.network,uri:this.queryUri,queryString:t}).then((function(e){n.queryExpression=t,e.items&&e.items.forEach((function(e){n.items[e.key]=e.data})),n.emit("searchResult",n.getItems())})).catch((function(e){throw nR("Error '".concat(e.message,"' while executing query '").concat(t,"'")),n.queryExpression=null,e})));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"subscribe",value:(t=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=this.queryExpression){e.next=2;break}return e.abrupt("return",Promise.reject(new JT("Invalid query",400,54507)));case 2:return e.abrupt("return",this.liveQueryCreator(this.indexName,this.queryExpression));case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"getItems",value:function(){return this.items}},{key:"updateIndexName",value:function(e){this.indexName=e,this.queryUri=this.generateQueryUri(this.indexName)}},{key:"generateQueryUri",value:function(e){return new zT(this.insightsUri).pathSegment(e).pathSegment("Items").build()}}],[{key:"type",get:function(){return"instant_query"}}]),i}(AT);kT.default(rI,"searchResult","searchResult"),OT([nT.validateTypesAsync("string"),CT("design:type",Function),CT("design:paramtypes",[String]),CT("design:returntype",Promise)],rI.prototype,"search",null),OT([nT.validateTypes(nT.nonEmptyString),CT("design:type",Function),CT("design:paramtypes",[String]),CT("design:returntype",void 0)],rI.prototype,"updateIndexName",null);function iI(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=bT.default(e);if(t){var i=bT.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return gT.default(this,n)}}function aI(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function sI(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?aI(Object(n),!0).forEach((function(t){kT.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):aI(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var oI="data_sync",uI="3.0.5-rc.21";function cI(e){if(e){if("string"==typeof e)return{id:e,mode:"open_or_create"};var t=e.mode||(e.id?"open_or_create":"create_new");return sI(sI({},e),{},{mode:t})}return{mode:"create_new"}}var lI="com.twilio.rtd.cds.document",fI="com.twilio.rtd.cds.list",dI="com.twilio.rtd.cds.map",pI="twilio.sync.event",Client=function(e){mT.default(Client,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y=iI(Client);function Client(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(hT.default(this,Client),t=y.call(this),!e)throw new Error("Sync library needs a valid Twilio token to be passed");n.hasOwnProperty("logLevel")?XT(n.logLevel):XT("silent");var r=n.productId=n.productId||oI;n.clientMetadata=n.clientMetadata||{},n.clientMetadata.hasOwnProperty("type")||(n.clientMetadata.type="sync"),n.clientMetadata.hasOwnProperty("sdk")||(n.clientMetadata.sdk="JS",n.clientMetadata.sdkv=uI);var i=!n.twilsockClient;if(!n.initRegistrations){var a=new rT.InitRegistration(r);Client.populateInitRegistrations(a),n.initRegistrations=[a]}var s=n.twilsockClient=n.twilsockClient||new rT.Twilsock(e,r,n);s.on("tokenAboutToExpire",(function(e){return t.emit("tokenAboutToExpire",e)})),s.on("tokenExpired",(function(){return t.emit("tokenExpired")})),s.on("connectionError",(function(e){return t.emit("connectionError",e)})),s.on("stateChanged",(function(e){t.emit("connectionStateChanged",e),t.services.subscriptions.onConnectionStateChanged("connected"===e)})),s.on("message",(function(e,n){return t._routeMessage(e,n)}));var o=new lR(n),u=new gR(new YR(uI),o,s),c=new bR(o);return t.services={config:o,twilsock:s,network:u,storage:c,router:yT.default(t),subscriptions:null},t.services.subscriptions=new hR(t.services),t.entities=new QR,i&&s.connect(),t}return vT.default(Client,[{key:"_routeMessage",value:function(e,t){switch(ZT("Notification type:",e,"content:",t),e){case lI:case fI:case dI:this.services.subscriptions.acceptMessage(t,!1);break;case pI:this.services.subscriptions.acceptMessage(t,!0)}}},{key:"_subscribe",value:function(e,t){this.services.subscriptions.add(e,t)}},{key:"_unsubscribe",value:function(e){this.services.subscriptions.remove(e)}},{key:"connectionState",get:function(){return this.services.twilsock.state}},{key:"ensureReady",value:(v=pT.default(wT.default.mark((function e(){var t;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.services.config.sessionStorageEnabled){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,e.next=5,this.services.twilsock.storageId();case 5:t=e.sent,this.services.storage.updateStorageId(t.id),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(2),tR("Failed to initialize storage",e.t0);case 12:case"end":return e.stop()}}),e,this,[[2,9]])}))),function(){return v.apply(this,arguments)})},{key:"storeRootInSessionCache",value:function(e,t,n){if(this.services.config.sessionStorageEnabled&&t){var r=$T(n);e!==WR.type&&e!==VR.type||(r.last_event_id=null,delete r.items),this.services.storage.store(e,t,r)}}},{key:"readRootFromSessionCache",value:function(e,t){return this.services.config.sessionStorageEnabled&&t?this.services.storage.read(e,t):null}},{key:"_get",value:(h=pT.default(wT.default.mark((function e(t,n){var r,i,a,s=arguments;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=s.length>2&&void 0!==s[2]&&s[2],n){e.next=3;break}throw new JT("Cannot get entity without id",404);case 3:return i=new zT(t).pathSegment(n).queryParam("Include",r?"items":void 0).build(),e.next=6,this.services.network.get(i);case 6:return a=e.sent,e.abrupt("return",a.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return h.apply(this,arguments)})},{key:"_createDocument",value:function(e,t,n){var r={unique_name:e,data:t||{}};return void 0!==n&&(r.ttl=n),this.services.network.post(this.services.config.documentsUri,r).then((function(e){return e.body.data=r.data,e.body}))}},{key:"_getDocument",value:(p=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(OR.type,t)||this._get(this.services.config.documentsUri,t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"_createList",value:function(e,t,n,r){var i={unique_name:e,purpose:t,context:n};return void 0!==r&&(i.ttl=r),this.services.network.post(this.services.config.listsUri,i).then((function(e){return e.body}))}},{key:"_getList",value:(d=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(WR.type,t)||this._get(this.services.config.listsUri,t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"_createMap",value:function(e,t){var n={unique_name:e};return void 0!==t&&(n.ttl=t),this.services.network.post(this.services.config.mapsUri,n).then((function(e){return e.body}))}},{key:"_getMap",value:(f=pT.default(wT.default.mark((function e(t){var n,r=arguments;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.length>1&&void 0!==r[1]&&r[1],e.abrupt("return",this.readRootFromSessionCache(VR.type,t)||this._get(this.services.config.mapsUri,t,n));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"_getStream",value:(l=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(HR.type,t)||this._get(this.services.config.streamsUri,t,!1));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"_createStream",value:(c=pT.default(wT.default.mark((function e(t,n){var r,i;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={unique_name:t},void 0!==n&&(r.ttl=n),e.next=4,this.services.network.post(this.services.config.streamsUri,r);case 4:return i=e.sent,e.abrupt("return",i.body);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return c.apply(this,arguments)})},{key:"_getLiveQuery",value:function(e){return this.readRootFromSessionCache(nI.type,e)}},{key:"getCached",value:function(e,t){return e&&this.entities.get(e,t)||null}},{key:"removeFromCacheAndSession",value:function(e,t,n){this.entities.remove(t),this.services.config.sessionStorageEnabled&&this.services.storage.remove(e,t,n)}},{key:"document",value:(u=pT.default(wT.default.mark((function e(t){var n,r,i,a,s=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=cI(t)).mode){e.next=9;break}return e.next=6,this._createDocument(n.id,n.data,n.ttl);case 6:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,OR.type))){e.next=14;break}return e.abrupt("return",new OR(i));case 14:return e.prev=14,e.next=17,this._getDocument(n.id);case 17:r=e.sent,e.next=39;break;case 20:if(e.prev=20,e.t0=e.catch(14),404===e.t0.status&&"open_existing"!==n.mode){e.next=26;break}throw e.t0;case 26:return e.prev=26,e.next=29,this._createDocument(n.id,n.data,n.ttl);case 29:r=e.sent,e.next=39;break;case 32:if(e.prev=32,e.t1=e.catch(26),409!==e.t1.status){e.next=38;break}return e.abrupt("return",this.document(t));case 38:throw e.t1;case 39:return this.storeRootInSessionCache(OR.type,n.id,r),a=new IR(this.services,r,(function(e,t,n){return s.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new OR(a));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return u.apply(this,arguments)})},{key:"map",value:(o=pT.default(wT.default.mark((function e(t){var n,r,i,a,s=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=cI(t)).mode){e.next=9;break}return e.next=6,this._createMap(n.id,n.ttl);case 6:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,VR.type))){e.next=14;break}return e.abrupt("return",new VR(i));case 14:return e.prev=14,e.next=17,this._getMap(n.id,n.includeItems);case 17:r=e.sent,e.next=39;break;case 20:if(e.prev=20,e.t0=e.catch(14),404===e.t0.status&&"open_existing"!==n.mode){e.next=26;break}throw e.t0;case 26:return e.prev=26,e.next=29,this._createMap(n.id,n.ttl);case 29:r=e.sent,e.next=39;break;case 32:if(e.prev=32,e.t1=e.catch(26),409!==e.t1.status){e.next=38;break}return e.abrupt("return",this.map(t));case 38:throw e.t1;case 39:return this.storeRootInSessionCache(VR.type,n.id,r),a=new JR(this.services,r,(function(e,t,n){return s.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new VR(a));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return o.apply(this,arguments)})},{key:"list",value:(s=pT.default(wT.default.mark((function e(t){var n,r,i,a,s=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=cI(t)).mode){e.next=9;break}return e.next=6,this._createList(n.id,n.purpose,n.context,n.ttl);case 6:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,WR.type))){e.next=14;break}return e.abrupt("return",new WR(i));case 14:return e.prev=14,e.next=17,this._getList(n.id);case 17:r=e.sent,e.next=39;break;case 20:if(e.prev=20,e.t0=e.catch(14),404===e.t0.status&&"open_existing"!==n.mode){e.next=26;break}throw e.t0;case 26:return e.prev=26,e.next=29,this._createList(n.id,n.purpose,n.context,n.ttl);case 29:r=e.sent,e.next=39;break;case 32:if(e.prev=32,e.t1=e.catch(26),409!==e.t1.status){e.next=38;break}return e.abrupt("return",this.list(t));case 38:throw e.t1;case 39:return this.storeRootInSessionCache(WR.type,n.id,r),a=new qR(this.services,r,(function(e,t,n){return s.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new WR(a));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return s.apply(this,arguments)})},{key:"stream",value:(a=pT.default(wT.default.mark((function e(t){var n,r,i,a,s,o=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=cI(t)).mode){e.next=9;break}return e.next=6,this._createStream(n.id,n.ttl);case 6:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,HR.type))){e.next=14;break}return e.abrupt("return",new HR(i));case 14:return e.prev=14,e.next=17,this._getStream(n.id);case 17:r=e.sent,e.next=39;break;case 20:if(e.prev=20,e.t0=e.catch(14),404===e.t0.status&&"open_existing"!==n.mode){e.next=26;break}throw e.t0;case 26:return e.prev=26,e.next=29,this._createStream(n.id,n.ttl);case 29:r=e.sent,e.next=39;break;case 32:if(e.prev=32,e.t1=e.catch(26),409!==e.t1.status){e.next=38;break}return e.abrupt("return",this.stream(t));case 38:throw e.t1;case 39:return this.storeRootInSessionCache(HR.type,n.id,r),a=function(e,t,n){return o.removeFromCacheAndSession(e,t,n)},s=new KR(this.services,r,a),s=this.entities.store(s),e.abrupt("return",new HR(s));case 44:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return a.apply(this,arguments)})},{key:"shutdown",value:(i=pT.default(wT.default.mark((function e(){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.subscriptions.shutdown();case 2:return e.next=4,this.services.twilsock.disconnect();case 4:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"updateToken",value:(r=pT.default(wT.default.mark((function e(t){return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.services.twilsock.updateToken(t).catch((function(e){var t,n=null==e||null===(t=e.reply)||void 0===t?void 0:t.status;if(401===(null==n?void 0:n.code)&&"UNAUTHORIZED"===(null==n?void 0:n.status))throw new JT("Updated token was rejected by server",400,51130);throw e})));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"liveQuery",value:(n=pT.default(wT.default.mark((function e(t,n){var r,i,a,s,o,u=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:return r=new zT(this.services.config.insightsUri).pathSegment(t).pathSegment("Items").build(),e.next=5,eI({network:this.services.network,uri:r,queryString:n,type:nI.type});case 5:return i=e.sent,(a=this.getCached(i.query_id,nI.type))||((s=this._getLiveQuery(i.query_id))||(s={indexName:t,queryExpression:n,sid:i.query_id,queryUri:r,last_event_id:i.last_event_id}),o=function(e,t,n){return u.removeFromCacheAndSession(e,t,n)},a=new ZR(s,this.services,o,i.items)),this.storeRootInSessionCache(nI.type,i.query_id,a.liveQueryDescriptor),a=this.entities.store(a),e.abrupt("return",new nI(a));case 11:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"instantQuery",value:(t=pT.default(wT.default.mark((function e(t){var n,r=this;return wT.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:return n=function(e,t){return r.liveQuery(e,t)},e.abrupt("return",new rI({indexName:t,network:this.services.network,insightsUri:this.services.config.insightsUri,liveQueryCreator:n}));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}],[{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([pI,lI,fI,dI])}},{key:"version",get:function(){return uI}}]),Client}(AT);kT.default(Client,"connectionStateChanged","connectionStateChanged"),kT.default(Client,"connectionError","connectionError"),kT.default(Client,"tokenAboutToExpire","tokenAboutToExpire"),kT.default(Client,"tokenExpired","tokenExpired"),OT([nT.validateTypesAsync(["undefined","string",nT.objectSchema("open document options",{id:["string","undefined"],mode:[nT.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[nT.nonNegativeInteger,"undefined"],data:[nT.pureObject,"undefined",nT.literal(null)]})]),CT("design:type",Function),CT("design:paramtypes",[Object]),CT("design:returntype",Promise)],Client.prototype,"document",null),OT([nT.validateTypesAsync(["undefined","string",nT.objectSchema("open map options",{id:["string","undefined"],mode:[nT.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[nT.nonNegativeInteger,"undefined"],data:[nT.pureObject,"undefined",nT.literal(null)],includeItems:["boolean","undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Object]),CT("design:returntype",Promise)],Client.prototype,"map",null),OT([nT.validateTypesAsync(["undefined","string",nT.objectSchema("open list options",{id:["string","undefined"],mode:[nT.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[nT.nonNegativeInteger,"undefined"],data:[nT.pureObject,"undefined",nT.literal(null)],purpose:["string","undefined"],context:[nT.pureObject,"undefined"],includeItems:["boolean","undefined"]})]),CT("design:type",Function),CT("design:paramtypes",[Object]),CT("design:returntype",Promise)],Client.prototype,"list",null),OT([nT.validateTypesAsync(["undefined","string",nT.objectSchema("open stream options",{id:["string","undefined"],mode:[nT.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[nT.nonNegativeInteger,"undefined"],data:[nT.pureObject,"undefined",nT.literal(null)]})]),CT("design:type",Function),CT("design:paramtypes",[Object]),CT("design:returntype",Promise)],Client.prototype,"stream",null),OT([nT.validateTypesAsync(nT.nonEmptyString),CT("design:type",Function),CT("design:paramtypes",[String]),CT("design:returntype",Promise)],Client.prototype,"updateToken",null),OT([nT.validateTypesAsync(nT.nonEmptyString,"string"),CT("design:type",Function),CT("design:paramtypes",[String,String]),CT("design:returntype",Promise)],Client.prototype,"liveQuery",null),OT([nT.validateTypesAsync(nT.nonEmptyString),CT("design:type",Function),CT("design:paramtypes",[String]),CT("design:returntype",Promise)],Client.prototype,"instantQuery",null),JE.Client=Client,JE.InsightsItem=function e(){hT.default(this,e)},JE.InstantQuery=rI,JE.LiveQuery=nI,JE.Paginator=Paginator;var hI=JE.SyncClient=Client;function vI(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function yI(e,t,n){return(yI=vI()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&Ia(i,n.prototype),i}).apply(null,arguments)}function mI(e){var t="function"==typeof Map?new Map:void 0;return(mI=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return yI(e,arguments,Aa(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),Ia(r,e)})(e)}JE.SyncDocument=OR,JE.SyncList=WR,JE.SyncListItem=CR,JE.SyncMap=VR,JE.SyncMapItem=zR,JE.SyncStream=HR;var gI,bI={},kI=WS,wI=function(e){if(kI(e))throw TypeError("The method doesn't accept regular expressions");return e},xI=pe("match"),_I=function(e){var t=/./;try{"/./"[e](t)}catch(n){try{return t[xI]=!1,"/./"[e](t)}catch(e){}}return!1},SI=In,EI=a.f,TI=Ut,RI=gr,II=wI,OI=k,CI=_I,PI="".startsWith,AI=Math.min,jI=CI("startsWith");SI({target:"String",proto:!0,forced:!!(jI||(gI=EI(String.prototype,"startsWith"),!gI||gI.writable))&&!jI},{startsWith:function(e){var t=RI(OI(this));II(e);var n=TI(AI(arguments.length>1?arguments[1]:void 0,t.length)),r=RI(e);return PI?PI.call(t,r,n):t.slice(n,n+r.length)===r}});var MI=j_.left,LI=L,NI=zs;In({target:"Array",proto:!0,forced:!ec("reduce")||!NI&&LI>79&&LI<83},{reduce:function(e){return MI(this,e,arguments.length,arguments.length>1?arguments[1]:void 0)}});var UI=s,DI=pe("iterator"),FI=!UI((function(){var e=new URL("b?a=1&b=2&c=3","http://a"),t=e.searchParams,n="";return e.pathname="c%20d",t.forEach((function(e,r){t.delete("b"),n+=r+e})),!t.sort||"http://a/c%20d?a=1&c=3"!==e.href||"3"!==t.get("c")||"a=1"!==String(new URLSearchParams("?a=1"))||!t[DI]||"a"!==new URL("https://a@b").username||"b"!==new URLSearchParams(new URLSearchParams("a=b")).get("a")||"xn--e1aybc"!==new URL("http://тест").host||"#%D0%B1"!==new URL("http://a#б").hash||"a1c3"!==n||"x"!==new URL("http://x",void 0).host})),BI=2147483647,qI=/[^\0-\u007E]/,WI=/[.\u3002\uFF0E\uFF61]/g,zI="Overflow: input needs wider integers to process",GI=Math.floor,JI=String.fromCharCode,VI=function(e){return e+22+75*(e<26)},$I=function(e,t,n){var r=0;for(e=n?GI(e/700):e>>1,e+=GI(e/t);e>455;r+=36)e=GI(e/35);return GI(r+36*e/(e+38))},KI=function(e){var t,n,r=[],i=(e=function(e){for(var t=[],n=0,r=e.length;n<r;){var i=e.charCodeAt(n++);if(i>=55296&&i<=56319&&n<r){var a=e.charCodeAt(n++);56320==(64512&a)?t.push(((1023&i)<<10)+(1023&a)+65536):(t.push(i),n--)}else t.push(i)}return t}(e)).length,a=128,s=0,o=72;for(t=0;t<e.length;t++)(n=e[t])<128&&r.push(JI(n));var u=r.length,c=u;for(u&&r.push("-");c<i;){var l=BI;for(t=0;t<e.length;t++)(n=e[t])>=a&&n<l&&(l=n);var f=c+1;if(l-a>GI((BI-s)/f))throw RangeError(zI);for(s+=(l-a)*f,a=l,t=0;t<e.length;t++){if((n=e[t])<a&&++s>BI)throw RangeError(zI);if(n==a){for(var d=s,p=36;;p+=36){var h=p<=o?1:p>=o+26?26:p-o;if(d<h)break;var v=d-h,y=36-h;r.push(JI(VI(h+v%y))),d=GI(v/y)}r.push(JI(VI(d))),o=$I(s,f,c==u),s=0,++c}}++s,++a}return r.join("")},HI=In,YI=R,QI=FI,XI=$e.exports,ZI=Ha,eO=Mr,tO=Ef,nO=xt,rO=as,iO=ee,aO=Nr,sO=qa,oO=De,uO=S,cO=gr,lO=Hn,fO=h,dO=ms,pO=hs,hO=pe,vO=YI("fetch"),yO=YI("Request"),mO=yO&&yO.prototype,gO=YI("Headers"),bO=hO("iterator"),kO="URLSearchParams",wO="URLSearchParamsIterator",xO=nO.set,_O=nO.getterFor(kO),SO=nO.getterFor(wO),EO=/\+/g,TO=Array(4),RO=function(e){return TO[e-1]||(TO[e-1]=RegExp("((?:%[\\da-f]{2}){"+e+"})","gi"))},IO=function(e){try{return decodeURIComponent(e)}catch(t){return e}},OO=function(e){var t=e.replace(EO," "),n=4;try{return decodeURIComponent(t)}catch(e){for(;n;)t=t.replace(RO(n--),IO);return t}},CO=/[!'()~]|%20/g,PO={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+"},AO=function(e){return PO[e]},jO=function(e){return encodeURIComponent(e).replace(CO,AO)},MO=function(e,t){if(t)for(var n,r,i=t.split("&"),a=0;a<i.length;)(n=i[a++]).length&&(r=n.split("="),e.push({key:OO(r.shift()),value:OO(r.join("="))}))},LO=function(e){this.entries.length=0,MO(this.entries,e)},NO=function(e,t){if(e<t)throw TypeError("Not enough arguments")},UO=tO((function(e,t){xO(this,{type:wO,iterator:dO(_O(e).entries),kind:t})}),"Iterator",(function(){var e=SO(this),t=e.kind,n=e.iterator.next(),r=n.value;return n.done||(n.value="keys"===t?r.key:"values"===t?r.value:[r.key,r.value]),n})),DO=function(){rO(this,DO,kO);var e,t,n,r,i,a,s,o,u,c=arguments.length>0?arguments[0]:void 0,l=this,f=[];if(xO(l,{type:kO,entries:f,updateURL:function(){},updateSearchParams:LO}),void 0!==c)if(uO(c))if("function"==typeof(e=pO(c)))for(n=(t=dO(c,e)).next;!(r=n.call(t)).done;){if((s=(a=(i=dO(oO(r.value))).next).call(i)).done||(o=a.call(i)).done||!a.call(i).done)throw TypeError("Expected sequence with length 2");f.push({key:cO(s.value),value:cO(o.value)})}else for(u in c)iO(c,u)&&f.push({key:u,value:cO(c[u])});else MO(f,"string"==typeof c?"?"===c.charAt(0)?c.slice(1):c:cO(c))},FO=DO.prototype;if(ZI(FO,{append:function(e,t){NO(arguments.length,2);var n=_O(this);n.entries.push({key:cO(e),value:cO(t)}),n.updateURL()},delete:function(e){NO(arguments.length,1);for(var t=_O(this),n=t.entries,r=cO(e),i=0;i<n.length;)n[i].key===r?n.splice(i,1):i++;t.updateURL()},get:function(e){NO(arguments.length,1);for(var t=_O(this).entries,n=cO(e),r=0;r<t.length;r++)if(t[r].key===n)return t[r].value;return null},getAll:function(e){NO(arguments.length,1);for(var t=_O(this).entries,n=cO(e),r=[],i=0;i<t.length;i++)t[i].key===n&&r.push(t[i].value);return r},has:function(e){NO(arguments.length,1);for(var t=_O(this).entries,n=cO(e),r=0;r<t.length;)if(t[r++].key===n)return!0;return!1},set:function(e,t){NO(arguments.length,1);for(var n,r=_O(this),i=r.entries,a=!1,s=cO(e),o=cO(t),u=0;u<i.length;u++)(n=i[u]).key===s&&(a?i.splice(u--,1):(a=!0,n.value=o));a||i.push({key:s,value:o}),r.updateURL()},sort:function(){var e,t,n,r=_O(this),i=r.entries,a=i.slice();for(i.length=0,n=0;n<a.length;n++){for(e=a[n],t=0;t<n;t++)if(i[t].key>e.key){i.splice(t,0,e);break}t===n&&i.push(e)}r.updateURL()},forEach:function(e){for(var t,n=_O(this).entries,r=aO(e,arguments.length>1?arguments[1]:void 0,3),i=0;i<n.length;)r((t=n[i++]).value,t.key,this)},keys:function(){return new UO(this,"keys")},values:function(){return new UO(this,"values")},entries:function(){return new UO(this,"entries")}},{enumerable:!0}),XI(FO,bO,FO.entries),XI(FO,"toString",(function(){for(var e,t=_O(this).entries,n=[],r=0;r<t.length;)e=t[r++],n.push(jO(e.key)+"="+jO(e.value));return n.join("&")}),{enumerable:!0}),eO(DO,kO),HI({global:!0,forced:!QI},{URLSearchParams:DO}),!QI&&"function"==typeof gO){var BO=function(e){if(uO(e)){var t,n=e.body;if(sO(n)===kO)return(t=e.headers?new gO(e.headers):new gO).has("content-type")||t.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"),lO(e,{body:fO(0,String(n)),headers:fO(0,t)})}return e};if("function"==typeof vO&&HI({global:!0,enumerable:!0,forced:!0},{fetch:function(e){return vO(e,arguments.length>1?BO(arguments[1]):{})}}),"function"==typeof yO){var qO=function(e){return rO(this,qO,"Request"),new yO(e,arguments.length>1?BO(arguments[1]):{})};mO.constructor=qO,qO.prototype=mO,HI({global:!0,forced:!0},{Request:qO})}}var WO,zO={URLSearchParams:DO,getState:_O},GO=In,JO=o,VO=FI,$O=i,KO=Nn,HO=$e.exports,YO=as,QO=ee,XO=zE,ZO=Hl,eC=af.codeAt,tC=function(e){var t,n,r=[],i=e.toLowerCase().replace(WI,".").split(".");for(t=0;t<i.length;t++)n=i[t],r.push(qI.test(n)?"xn--"+KI(n):n);return r.join(".")},nC=gr,rC=Mr,iC=zO,aC=xt,sC=$O.URL,oC=iC.URLSearchParams,uC=iC.getState,cC=aC.set,lC=aC.getterFor("URL"),fC=Math.floor,dC=Math.pow,pC="Invalid scheme",hC="Invalid host",vC="Invalid port",yC=/[A-Za-z]/,mC=/[\d+-.A-Za-z]/,gC=/\d/,bC=/^0x/i,kC=/^[0-7]+$/,wC=/^\d+$/,xC=/^[\dA-Fa-f]+$/,_C=/[\0\t\n\r #%/:<>?@[\\\]^|]/,SC=/[\0\t\n\r #/:<>?@[\\\]^|]/,EC=/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g,TC=/[\t\n\r]/g,RC=function(e,t){var n,r,i;if("["==t.charAt(0)){if("]"!=t.charAt(t.length-1))return hC;if(!(n=OC(t.slice(1,-1))))return hC;e.host=n}else if(UC(e)){if(t=tC(t),_C.test(t))return hC;if(null===(n=IC(t)))return hC;e.host=n}else{if(SC.test(t))return hC;for(n="",r=ZO(t),i=0;i<r.length;i++)n+=LC(r[i],PC);e.host=n}},IC=function(e){var t,n,r,i,a,s,o,u=e.split(".");if(u.length&&""==u[u.length-1]&&u.pop(),(t=u.length)>4)return e;for(n=[],r=0;r<t;r++){if(""==(i=u[r]))return e;if(a=10,i.length>1&&"0"==i.charAt(0)&&(a=bC.test(i)?16:8,i=i.slice(8==a?1:2)),""===i)s=0;else{if(!(10==a?wC:8==a?kC:xC).test(i))return e;s=parseInt(i,a)}n.push(s)}for(r=0;r<t;r++)if(s=n[r],r==t-1){if(s>=dC(256,5-t))return null}else if(s>255)return null;for(o=n.pop(),r=0;r<n.length;r++)o+=n[r]*dC(256,3-r);return o},OC=function(e){var t,n,r,i,a,s,o,u=[0,0,0,0,0,0,0,0],c=0,l=null,f=0,d=function(){return e.charAt(f)};if(":"==d()){if(":"!=e.charAt(1))return;f+=2,l=++c}for(;d();){if(8==c)return;if(":"!=d()){for(t=n=0;n<4&&xC.test(d());)t=16*t+parseInt(d(),16),f++,n++;if("."==d()){if(0==n)return;if(f-=n,c>6)return;for(r=0;d();){if(i=null,r>0){if(!("."==d()&&r<4))return;f++}if(!gC.test(d()))return;for(;gC.test(d());){if(a=parseInt(d(),10),null===i)i=a;else{if(0==i)return;i=10*i+a}if(i>255)return;f++}u[c]=256*u[c]+i,2!=++r&&4!=r||c++}if(4!=r)return;break}if(":"==d()){if(f++,!d())return}else if(d())return;u[c++]=t}else{if(null!==l)return;f++,l=++c}}if(null!==l)for(s=c-l,c=7;0!=c&&s>0;)o=u[c],u[c--]=u[l+s-1],u[l+--s]=o;else if(8!=c)return;return u},CC=function(e){var t,n,r,i;if("number"==typeof e){for(t=[],n=0;n<4;n++)t.unshift(e%256),e=fC(e/256);return t.join(".")}if("object"==typeof e){for(t="",r=function(e){for(var t=null,n=1,r=null,i=0,a=0;a<8;a++)0!==e[a]?(i>n&&(t=r,n=i),r=null,i=0):(null===r&&(r=a),++i);return i>n&&(t=r,n=i),t}(e),n=0;n<8;n++)i&&0===e[n]||(i&&(i=!1),r===n?(t+=n?":":"::",i=!0):(t+=e[n].toString(16),n<7&&(t+=":")));return"["+t+"]"}return e},PC={},AC=XO({},PC,{" ":1,'"':1,"<":1,">":1,"`":1}),jC=XO({},AC,{"#":1,"?":1,"{":1,"}":1}),MC=XO({},jC,{"/":1,":":1,";":1,"=":1,"@":1,"[":1,"\\":1,"]":1,"^":1,"|":1}),LC=function(e,t){var n=eC(e,0);return n>32&&n<127&&!QO(t,e)?e:encodeURIComponent(e)},NC={ftp:21,file:null,http:80,https:443,ws:80,wss:443},UC=function(e){return QO(NC,e.scheme)},DC=function(e){return""!=e.username||""!=e.password},FC=function(e){return!e.host||e.cannotBeABaseURL||"file"==e.scheme},BC=function(e,t){var n;return 2==e.length&&yC.test(e.charAt(0))&&(":"==(n=e.charAt(1))||!t&&"|"==n)},qC=function(e){var t;return e.length>1&&BC(e.slice(0,2))&&(2==e.length||"/"===(t=e.charAt(2))||"\\"===t||"?"===t||"#"===t)},WC=function(e){var t=e.path,n=t.length;!n||"file"==e.scheme&&1==n&&BC(t[0],!0)||t.pop()},zC=function(e){return"."===e||"%2e"===e.toLowerCase()},GC={},JC={},VC={},$C={},KC={},HC={},YC={},QC={},XC={},ZC={},eP={},tP={},nP={},rP={},iP={},aP={},sP={},oP={},uP={},cP={},lP={},fP=function(e,t,n,r){var i,a,s,o,u,c=n||GC,l=0,f="",d=!1,p=!1,h=!1;for(n||(e.scheme="",e.username="",e.password="",e.host=null,e.port=null,e.path=[],e.query=null,e.fragment=null,e.cannotBeABaseURL=!1,t=t.replace(EC,"")),t=t.replace(TC,""),i=ZO(t);l<=i.length;){switch(a=i[l],c){case GC:if(!a||!yC.test(a)){if(n)return pC;c=VC;continue}f+=a.toLowerCase(),c=JC;break;case JC:if(a&&(mC.test(a)||"+"==a||"-"==a||"."==a))f+=a.toLowerCase();else{if(":"!=a){if(n)return pC;f="",c=VC,l=0;continue}if(n&&(UC(e)!=QO(NC,f)||"file"==f&&(DC(e)||null!==e.port)||"file"==e.scheme&&!e.host))return;if(e.scheme=f,n)return void(UC(e)&&NC[e.scheme]==e.port&&(e.port=null));f="","file"==e.scheme?c=rP:UC(e)&&r&&r.scheme==e.scheme?c=$C:UC(e)?c=QC:"/"==i[l+1]?(c=KC,l++):(e.cannotBeABaseURL=!0,e.path.push(""),c=uP)}break;case VC:if(!r||r.cannotBeABaseURL&&"#"!=a)return pC;if(r.cannotBeABaseURL&&"#"==a){e.scheme=r.scheme,e.path=r.path.slice(),e.query=r.query,e.fragment="",e.cannotBeABaseURL=!0,c=lP;break}c="file"==r.scheme?rP:HC;continue;case $C:if("/"!=a||"/"!=i[l+1]){c=HC;continue}c=XC,l++;break;case KC:if("/"==a){c=ZC;break}c=oP;continue;case HC:if(e.scheme=r.scheme,a==WO)e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,e.path=r.path.slice(),e.query=r.query;else if("/"==a||"\\"==a&&UC(e))c=YC;else if("?"==a)e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,e.path=r.path.slice(),e.query="",c=cP;else{if("#"!=a){e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,e.path=r.path.slice(),e.path.pop(),c=oP;continue}e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,e.path=r.path.slice(),e.query=r.query,e.fragment="",c=lP}break;case YC:if(!UC(e)||"/"!=a&&"\\"!=a){if("/"!=a){e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,c=oP;continue}c=ZC}else c=XC;break;case QC:if(c=XC,"/"!=a||"/"!=f.charAt(l+1))continue;l++;break;case XC:if("/"!=a&&"\\"!=a){c=ZC;continue}break;case ZC:if("@"==a){d&&(f="%40"+f),d=!0,s=ZO(f);for(var v=0;v<s.length;v++){var y=s[v];if(":"!=y||h){var m=LC(y,MC);h?e.password+=m:e.username+=m}else h=!0}f=""}else if(a==WO||"/"==a||"?"==a||"#"==a||"\\"==a&&UC(e)){if(d&&""==f)return"Invalid authority";l-=ZO(f).length+1,f="",c=eP}else f+=a;break;case eP:case tP:if(n&&"file"==e.scheme){c=aP;continue}if(":"!=a||p){if(a==WO||"/"==a||"?"==a||"#"==a||"\\"==a&&UC(e)){if(UC(e)&&""==f)return hC;if(n&&""==f&&(DC(e)||null!==e.port))return;if(o=RC(e,f))return o;if(f="",c=sP,n)return;continue}"["==a?p=!0:"]"==a&&(p=!1),f+=a}else{if(""==f)return hC;if(o=RC(e,f))return o;if(f="",c=nP,n==tP)return}break;case nP:if(!gC.test(a)){if(a==WO||"/"==a||"?"==a||"#"==a||"\\"==a&&UC(e)||n){if(""!=f){var g=parseInt(f,10);if(g>65535)return vC;e.port=UC(e)&&g===NC[e.scheme]?null:g,f=""}if(n)return;c=sP;continue}return vC}f+=a;break;case rP:if(e.scheme="file","/"==a||"\\"==a)c=iP;else{if(!r||"file"!=r.scheme){c=oP;continue}if(a==WO)e.host=r.host,e.path=r.path.slice(),e.query=r.query;else if("?"==a)e.host=r.host,e.path=r.path.slice(),e.query="",c=cP;else{if("#"!=a){qC(i.slice(l).join(""))||(e.host=r.host,e.path=r.path.slice(),WC(e)),c=oP;continue}e.host=r.host,e.path=r.path.slice(),e.query=r.query,e.fragment="",c=lP}}break;case iP:if("/"==a||"\\"==a){c=aP;break}r&&"file"==r.scheme&&!qC(i.slice(l).join(""))&&(BC(r.path[0],!0)?e.path.push(r.path[0]):e.host=r.host),c=oP;continue;case aP:if(a==WO||"/"==a||"\\"==a||"?"==a||"#"==a){if(!n&&BC(f))c=oP;else if(""==f){if(e.host="",n)return;c=sP}else{if(o=RC(e,f))return o;if("localhost"==e.host&&(e.host=""),n)return;f="",c=sP}continue}f+=a;break;case sP:if(UC(e)){if(c=oP,"/"!=a&&"\\"!=a)continue}else if(n||"?"!=a)if(n||"#"!=a){if(a!=WO&&(c=oP,"/"!=a))continue}else e.fragment="",c=lP;else e.query="",c=cP;break;case oP:if(a==WO||"/"==a||"\\"==a&&UC(e)||!n&&("?"==a||"#"==a)){if(".."===(u=(u=f).toLowerCase())||"%2e."===u||".%2e"===u||"%2e%2e"===u?(WC(e),"/"==a||"\\"==a&&UC(e)||e.path.push("")):zC(f)?"/"==a||"\\"==a&&UC(e)||e.path.push(""):("file"==e.scheme&&!e.path.length&&BC(f)&&(e.host&&(e.host=""),f=f.charAt(0)+":"),e.path.push(f)),f="","file"==e.scheme&&(a==WO||"?"==a||"#"==a))for(;e.path.length>1&&""===e.path[0];)e.path.shift();"?"==a?(e.query="",c=cP):"#"==a&&(e.fragment="",c=lP)}else f+=LC(a,jC);break;case uP:"?"==a?(e.query="",c=cP):"#"==a?(e.fragment="",c=lP):a!=WO&&(e.path[0]+=LC(a,PC));break;case cP:n||"#"!=a?a!=WO&&("'"==a&&UC(e)?e.query+="%27":e.query+="#"==a?"%23":LC(a,PC)):(e.fragment="",c=lP);break;case lP:a!=WO&&(e.fragment+=LC(a,AC))}l++}},dP=function(e){var t,n,r=YO(this,dP,"URL"),i=arguments.length>1?arguments[1]:void 0,a=nC(e),s=cC(r,{type:"URL"});if(void 0!==i)if(i instanceof dP)t=lC(i);else if(n=fP(t={},nC(i)))throw TypeError(n);if(n=fP(s,a,null,t))throw TypeError(n);var o=s.searchParams=new oC,u=uC(o);u.updateSearchParams(s.query),u.updateURL=function(){s.query=String(o)||null},JO||(r.href=hP.call(r),r.origin=vP.call(r),r.protocol=yP.call(r),r.username=mP.call(r),r.password=gP.call(r),r.host=bP.call(r),r.hostname=kP.call(r),r.port=wP.call(r),r.pathname=xP.call(r),r.search=_P.call(r),r.searchParams=SP.call(r),r.hash=EP.call(r))},pP=dP.prototype,hP=function(){var e=lC(this),t=e.scheme,n=e.username,r=e.password,i=e.host,a=e.port,s=e.path,o=e.query,u=e.fragment,c=t+":";return null!==i?(c+="//",DC(e)&&(c+=n+(r?":"+r:"")+"@"),c+=CC(i),null!==a&&(c+=":"+a)):"file"==t&&(c+="//"),c+=e.cannotBeABaseURL?s[0]:s.length?"/"+s.join("/"):"",null!==o&&(c+="?"+o),null!==u&&(c+="#"+u),c},vP=function(){var e=lC(this),t=e.scheme,n=e.port;if("blob"==t)try{return new dP(t.path[0]).origin}catch(e){return"null"}return"file"!=t&&UC(e)?t+"://"+CC(e.host)+(null!==n?":"+n:""):"null"},yP=function(){return lC(this).scheme+":"},mP=function(){return lC(this).username},gP=function(){return lC(this).password},bP=function(){var e=lC(this),t=e.host,n=e.port;return null===t?"":null===n?CC(t):CC(t)+":"+n},kP=function(){var e=lC(this).host;return null===e?"":CC(e)},wP=function(){var e=lC(this).port;return null===e?"":String(e)},xP=function(){var e=lC(this),t=e.path;return e.cannotBeABaseURL?t[0]:t.length?"/"+t.join("/"):""},_P=function(){var e=lC(this).query;return e?"?"+e:""},SP=function(){return lC(this).searchParams},EP=function(){var e=lC(this).fragment;return e?"#"+e:""},TP=function(e,t){return{get:e,set:t,configurable:!0,enumerable:!0}};if(JO&&KO(pP,{href:TP(hP,(function(e){var t=lC(this),n=nC(e),r=fP(t,n);if(r)throw TypeError(r);uC(t.searchParams).updateSearchParams(t.query)})),origin:TP(vP),protocol:TP(yP,(function(e){var t=lC(this);fP(t,nC(e)+":",GC)})),username:TP(mP,(function(e){var t=lC(this),n=ZO(nC(e));if(!FC(t)){t.username="";for(var r=0;r<n.length;r++)t.username+=LC(n[r],MC)}})),password:TP(gP,(function(e){var t=lC(this),n=ZO(nC(e));if(!FC(t)){t.password="";for(var r=0;r<n.length;r++)t.password+=LC(n[r],MC)}})),host:TP(bP,(function(e){var t=lC(this);t.cannotBeABaseURL||fP(t,nC(e),eP)})),hostname:TP(kP,(function(e){var t=lC(this);t.cannotBeABaseURL||fP(t,nC(e),tP)})),port:TP(wP,(function(e){var t=lC(this);FC(t)||(""==(e=nC(e))?t.port=null:fP(t,e,nP))})),pathname:TP(xP,(function(e){var t=lC(this);t.cannotBeABaseURL||(t.path=[],fP(t,nC(e),sP))})),search:TP(_P,(function(e){var t=lC(this);""==(e=nC(e))?t.query=null:("?"==e.charAt(0)&&(e=e.slice(1)),t.query="",fP(t,e,cP)),uC(t.searchParams).updateSearchParams(t.query)})),searchParams:TP(SP),hash:TP(EP,(function(e){var t=lC(this);""!=(e=nC(e))?("#"==e.charAt(0)&&(e=e.slice(1)),t.fragment="",fP(t,e,lP)):t.fragment=null}))}),HO(pP,"toJSON",(function(){return hP.call(this)}),{enumerable:!0}),HO(pP,"toString",(function(){return hP.call(this)}),{enumerable:!0}),sC){var RP=sC.createObjectURL,IP=sC.revokeObjectURL;RP&&HO(dP,"createObjectURL",(function(e){return RP.apply(sC,arguments)})),IP&&HO(dP,"revokeObjectURL",(function(e){return IP.apply(sC,arguments)}))}function OP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}function CP(e){return function(e){if(Array.isArray(e))return pm(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||hm(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}rC(dP,"URL"),GO({global:!0,forced:!VO,sham:!JO},{URL:dP}),function(e){var t=void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};Object.defineProperty(e,"__esModule",{value:!0});var n=Vg.exports,r=sg.exports,i=Hg,a=Xf.exports,s=ig,o=Jh;function u(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var l=u(n),f=u(r),d=u(i),p=c(a);
|
130
142
|
/*! *****************************************************************************
|
131
143
|
Copyright (c) Microsoft Corporation.
|
132
144
|
|
@@ -141,4 +153,4 @@ this.Twilio=this.Twilio||{},this.Twilio.Conversations=function(e){"use strict";v
|
|
141
153
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
142
154
|
PERFORMANCE OF THIS SOFTWARE.
|
143
155
|
***************************************************************************** */
|
144
|
-
function h(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function v(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function y(e,t){return["".concat((new Date).toISOString()," MCS Client ").concat(e,":")].concat(Array.from(t))}var m=function(){function e(t){Ma(this,e),f.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return Ta(e,[{key:"setLevel",value:function(e){p.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.trace.apply(null,y(this.prefix+"T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.debug.apply(null,y(this.prefix+"D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.info.apply(null,y(this.prefix+"I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.warn.apply(null,y(this.prefix+"W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.error.apply(null,y(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){p.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.trace.apply(null,y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.debug.apply(null,y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.info.apply(null,y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.warn.apply(null,y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.error.apply(null,y("E",t))}}]),e}(),g=function(e,t){return"".concat((n=e,n.startsWith("http")?"":function(e){return"https://mcs.".concat(null!=e?e:"us1",".twilio.com")}(t))).concat(e);var n},b=function(){function e(t,n,r,i){var a,s,o,u,c,l;Ma(this,e);var f=null!==(a=null!==(s=i.MCS)&&void 0!==s?s:i)&&void 0!==a?a:{};this.region=null!==(o=null!==(u=f.region)&&void 0!==u?u:i.region)&&void 0!==o?o:"us1",this.mediaUrl=g(n,this.region),this.mediaSetUrl=r?g(r):"".concat(this.mediaUrl,"Set"),this.token=t,this.retryWhenThrottledOverride=null===(c=f.retryWhenThrottledOverride)||void 0===c||c,this.backoffConfigOverride=null!==(l=f.backoffConfigOverride)&&void 0!==l?l:e.backoffConfigDefault}return Ta(e,[{key:"updateToken",value:function(e){this.token=e}}],[{key:"backoffConfigDefault",get:function(){return{min:1e3,max:4e3,maxAttemptsCount:3}}},{key:"retryWhenThrottledDefault",get:function(){return true}}]),e}(),Media=function(){function Media(e,t,n){Ma(this,Media),this.config=e,this.network=t,this._update(n)}return Ta(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"serviceSid",get:function(){return this.state.serviceSid}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"fileName",get:function(){return this.state.filename}},{key:"filename",get:function(){return this.state.filename}},{key:"category",get:function(){return this.state.category}},{key:"getContentUrl",value:function(){var e=this;return l.default(d.default.mark((function t(){var n;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.network.get("".concat(e.config.mediaUrl,"/").concat(e.sid));case 2:return n=t.sent,e._update(n.body),t.abrupt("return",Promise.resolve(e.state.contentDirectUrl));case 5:case"end":return t.stop()}}),t)})))()}},{key:"getCachedContentUrl",value:function(){var e=this;return l.default(d.default.mark((function t(){return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e.state.contentDirectUrl){t.next=2;break}return t.abrupt("return",Promise.resolve(e.state.contentDirectUrl));case 2:return t.next=4,e.getContentUrl();case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}}),t)})))()}},{key:"_update",value:function(e){var t,n,r,i;this.state={sid:e.sid,serviceSid:e.service_sid,channelSid:e.channel_sid,messageSid:e.message_sid,dateCreated:e.date_created?new Date(e.date_created):null,dateUploadUpdated:e.date_upload_updated?new Date(e.date_upload_updated):null,dateUpdated:e.date_updated?new Date(e.date_updated):null,size:e.size,contentType:e.content_type,author:e.author,url:e.url,contentUrl:e.links.content,contentDirectUrl:null!==(t=e.links.content_direct_temporary)&&void 0!==t?t:null,filename:null!==(n=e.filename)&&void 0!==n?n:null,category:null!==(r=e.category)&&void 0!==r?r:"media",isMultipartUpstream:null!==(i=e.is_multipart_upstream)&&void 0!==i&&i}}}]),Media}(),k=function(e){Oa(n,e);var t=_C(n);function n(e,r,i,a,s){var o;return Ma(this,n),(o=t.call(this,e)).code=r,o.body=i,o.status=a,o.headers=s,o}return n}(fR(Error)),w=t.XMLHttpRequest||{};function x(e){var t=e.getResponseHeader("Content-Type");if(!t||0!==t.indexOf("application/json")||0===e.responseText.length)return e.responseText;try{return JSON.parse(e.responseText)}catch(t){return e.responseText}}var _,S,E=function(){function e(){Ma(this,e)}return Ta(e,[{key:"get",value:function(t,n){return l.default(d.default.mark((function r(){return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",e.request("GET",t,n));case 1:case"end":return r.stop()}}),r)})))()}},{key:"post",value:function(t,n,r){return l.default(d.default.mark((function i(){return d.default.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.abrupt("return",e.request("POST",t,n,r));case 1:case"end":return i.stop()}}),i)})))()}}],[{key:"request",value:function(e,t,n,r){return l.default(d.default.mark((function i(){return d.default.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.abrupt("return",new Promise((function(i,a){var s=new w;for(var o in s.open(e,t,!0),s.onreadystatechange=function(){if(4===s.readyState){var e,t=(e=s.getAllResponseHeaders())?e.split("\r\n").map((function(e){return e.split(": ")})).filter((function(e){return 2===e.length&&e[1].length>0})).reduce((function(e,t){return e[t[0]]=t[1],e}),{}):{},n=x(s);if(200<=s.status&&s.status<300)i({status:s.status,headers:t,body:n});else{var r,o,u=null!==(r=s.statusText)&&void 0!==r?r:"NONE";o="string"==typeof n?n&&1===n.split("\n",2).length?n:"":JSON.stringify(n);var c="".concat(s.status,": [").concat(u,"] ").concat(o);a(new k(c,s.status,n,u,t))}}},n)s.setRequestHeader(o,n[o]),"Content-Type"===o&&"application/json"===n[o]&&(r=JSON.stringify(r));s.send(r)})));case 1:case"end":return i.stop()}}),i)})))()}}]),e}(),T=m.scope("Network"),R=function(){function e(t,n){Ma(this,e),this.config=t,this.transport=n}return Ta(e,[{key:"backoffConfig",value:function(){return Object.assign(b.backoffConfigDefault,this.config.backoffConfigOverride)}},{key:"retryWhenThrottled",value:function(){var e,t;return null!==(e=null!==(t=this.config.retryWhenThrottledOverride)&&void 0!==t?t:b.retryWhenThrottledDefault)&&void 0!==e&&e}},{key:"executeWithRetry",value:function(e,t){var n=this;return l.default(d.default.mark((function r(){return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",new Promise((function(r,i){var a=[502,503,504];t&&a.push(429);var o=new s.Retrier(n.backoffConfig());o.on("attempt",l.default(d.default.mark((function t(){var n;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,e();case 3:n=t.sent,o.succeeded(n),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(0),a.indexOf(t.t0.status)>-1||"Twilsock disconnected"===t.t0.message?o.failed(t.t0):(o.removeAllListeners(),o.cancel(),i(t.t0));case 10:case"end":return t.stop()}}),t,null,[[0,7]])})))),o.on("succeeded",(function(e){r(e)})),o.on("cancelled",(function(e){return i(e)})),o.on("failed",(function(e){return i(e)})),o.start()})));case 1:case"end":return r.stop()}}),r)})))()}},{key:"get",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r,i;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r={"X-Twilio-Token":t.config.token},T.trace("sending GET request to ",e," headers ",r),n.prev=2,n.next=5,t.executeWithRetry((function(){return t.transport.get(e,r)}),t.retryWhenThrottled());case 5:return i=n.sent,T.trace("response",i),n.abrupt("return",i);case 10:throw n.prev=10,n.t0=n.catch(2),T.debug("get() error ".concat(n.t0)),n.t0;case 14:case"end":return n.stop()}}),n,null,[[2,10]])})))()}},{key:"post",value:function(e,n,r,i,a){var s=this;return l.default(d.default.mark((function o(){var u,c,l;return d.default.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return u={"X-Twilio-Token":s.config.token},"undefined"!=typeof FormData&&r instanceof FormData||!i||Object.assign(u,{"Content-Type":i}),c=new URL(e),n&&c.searchParams.append("Category",n),a&&c.searchParams.append("Filename",a),T.trace("sending POST request to ".concat(e," with headers ").concat(u)),o.prev=6,o.next=9,s.transport.post(c.href,u,r);case 9:l=o.sent,o.next=18;break;case 12:if(o.prev=12,o.t0=o.catch(6),!(void 0===t.XMLHttpRequest&&r instanceof FormData)){o.next=16;break}throw new TypeError("Posting FormData supported only with browser engine's FormData");case 16:throw T.debug("post() error ".concat(o.t0)),o.t0;case 18:return T.trace("response",l),o.abrupt("return",l);case 20:case"end":return o.stop()}}),o,null,[[6,12]])})))()}}]),e}(),I=m.scope("");e.default=(S=_=function(){function Client(e,t,n){var r,i;Ma(this,Client);var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};this.options=a,this.options.logLevel=null!==(r=this.options.logLevel)&&void 0!==r?r:"silent",this.config=new b(e,t,n,this.options),I.setLevel(this.options.logLevel),this.options.transport=null!==(i=this.options.transport)&&void 0!==i?i:new E,this.transport=this.options.transport,this.network=new R(this.config,this.transport)}return Ta(Client,[{key:"updateToken",value:function(e){I.info("updateToken"),this.config.updateToken(e)}},{key:"get",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,t.network.get("".concat(t.config.mediaUrl,"/").concat(e));case 2:return r=n.sent,n.abrupt("return",new Media(t.config,t.network,r.body));case 4:case"end":return n.stop()}}),n)})))()}},{key:"post",value:function(e,t,n,r){var i=this;return l.default(d.default.mark((function a(){var s;return d.default.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,i.network.post(i.config.mediaUrl,null!=n?n:"media",t,e,r);case 2:return s=a.sent,a.abrupt("return",new Media(i.config,i.network,s.body));case 4:case"end":return a.stop()}}),a)})))()}},{key:"postFormData",value:function(e,t){var n=this;return l.default(d.default.mark((function r(){var i;return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,n.network.post(n.config.mediaUrl,null!=t?t:"media",e);case 2:return i=r.sent,r.abrupt("return",new Media(n.config,n.network,i.body));case 4:case"end":return r.stop()}}),r)})))()}},{key:"mediaSetGet",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r,i;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r={command:"get",list:e.map((function(e){return{media_sid:e}}))},n.next=3,t.network.post("".concat(t.config.mediaSetUrl),null,JSON.stringify(r),"application/json");case 3:return i=n.sent,n.abrupt("return",i.map((function(e){if(200!==e.code)throw new Error("Failed to obtain detailed information about Media items (failed SID ".concat(e.media_record.sid,")"));return new Media(t.config,t.network,e.media_record)})));case 5:case"end":return n.stop()}}),n)})))()}}]),Client}(),f.default(_,"version","0.5.1-rc.12"),S),h([o.validateTypes(o.nonEmptyString),v("design:type",Function),v("design:paramtypes",[String]),v("design:returntype",void 0)],e.default.prototype,"updateToken",null),h([o.validateTypesAsync(o.nonEmptyString),v("design:type",Function),v("design:paramtypes",[String]),v("design:returntype",Promise)],e.default.prototype,"get",null),e.default=h([o.validateConstructorTypes(o.nonEmptyString,o.nonEmptyString,[o.nonEmptyString,o.literal(null)],[o.pureObject,"undefined"]),v("design:paramtypes",[String,String,Object,Object])],e.default),e.Client=e.default,e.McsClient=e.default,e.McsMedia=Media,e.Media=Media,e.default=e.default}(pR);var EC=is,TC="ArrayBuffer",RC=fk.ArrayBuffer;In({global:!0,forced:i.ArrayBuffer!==RC},{ArrayBuffer:RC}),EC(TC);var IC={},OC={};function CC(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function PC(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}Object.defineProperty(OC,"__esModule",{value:!0}),OC.Pointer=void 0;var AC=function(){function e(e){void 0===e&&(e=[""]),this.tokens=e}return e.fromJSON=function(t){var n=t.split("/").map(CC);if(""!==n[0])throw new Error("Invalid JSON Pointer: "+t);return new e(n)},e.prototype.toString=function(){return this.tokens.map(PC).join("/")},e.prototype.evaluate=function(e){for(var t=null,n="",r=e,i=1,a=this.tokens.length;i<a;i++)r=((t=r)||{})[n=this.tokens[i]];return{parent:t,key:n,value:r}},e.prototype.get=function(e){return this.evaluate(e).value},e.prototype.set=function(e,t){for(var n=e,r=1,i=this.tokens.length-1,a=this.tokens[r];r<i;r++)n=(n||{})[a];n&&(n[this.tokens[this.tokens.length-1]]=t)},e.prototype.push=function(e){this.tokens.push(e)},e.prototype.add=function(t){return new e(this.tokens.concat(String(t)))},e}();OC.Pointer=AC;var jC={},MC={};!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.clone=e.objectType=e.hasOwnProperty=void 0,e.hasOwnProperty=Object.prototype.hasOwnProperty,e.objectType=function(e){return void 0===e?"undefined":null===e?"null":Array.isArray(e)?"array":Ca(e)},e.clone=function t(n){if(null==n||"object"!=Ca(n))return n;if(n.constructor==Array){for(var r=n.length,i=new Array(r),a=0;a<r;a++)i[a]=t(n[a]);return i}var s={};for(var o in n)e.hasOwnProperty.call(n,o)&&(s[o]=t(n[o]));return s}}(MC);var LC={};Object.defineProperty(LC,"__esModule",{value:!0}),LC.compare=void 0;var NC=MC;function UC(e,t){if(e===t)return!0;var n=NC.objectType(e),r=NC.objectType(t);return"array"==n&&"array"==r?function(e,t){var n=e.length;if(n!==t.length)return!1;for(var r=0;r<n;r++)if(!UC(e[r],t[r]))return!1;return!0}(e,t):"object"==n&&"object"==r&&function(e,t){var n=Object.keys(e),r=Object.keys(t),i=n.length;if(i!==r.length)return!1;for(var a=0;a<i;a++){var s=n[a];if(!NC.hasOwnProperty.call(t,s)||!UC(e[s],t[s]))return!1}return!0}(e,t)}LC.compare=UC;var DC,FC=t&&t.__extends||(DC=function(e,t){return(DC=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}DC(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(jC,"__esModule",{value:!0}),jC.apply=jC.InvalidOperationError=jC.test=jC.copy=jC.move=jC.replace=jC.remove=jC.add=jC.TestError=jC.MissingError=void 0;var BC=OC,qC=MC,WC=LC,zC=function(e){function t(t){var n=e.call(this,"Value required at path: "+t)||this;return n.path=t,n.name="MissingError",n}return FC(t,e),t}(Error);jC.MissingError=zC;var GC=function(e){function t(t,n){var r=e.call(this,"Test failed: "+t+" != "+n)||this;return r.actual=t,r.expected=n,r.name="TestError",r}return FC(t,e),t}(Error);function JC(e,t,n){if(Array.isArray(e))if("-"==t)e.push(n);else{var r=parseInt(t,10);e.splice(r,0,n)}else e[t]=n}function VC(e,t){if(Array.isArray(e)){var n=parseInt(t,10);e.splice(n,1)}else delete e[t]}function $C(e,t){var n=BC.Pointer.fromJSON(t.path).evaluate(e);return void 0===n.parent?new zC(t.path):(JC(n.parent,n.key,qC.clone(t.value)),null)}function KC(e,t){var n=BC.Pointer.fromJSON(t.path).evaluate(e);return void 0===n.value?new zC(t.path):(VC(n.parent,n.key),null)}function HC(e,t){var n=BC.Pointer.fromJSON(t.path).evaluate(e);if(null===n.parent)return new zC(t.path);if(Array.isArray(n.parent)){if(parseInt(n.key,10)>=n.parent.length)return new zC(t.path)}else if(void 0===n.value)return new zC(t.path);return n.parent[n.key]=t.value,null}function YC(e,t){var n=BC.Pointer.fromJSON(t.from).evaluate(e);if(void 0===n.value)return new zC(t.from);var r=BC.Pointer.fromJSON(t.path).evaluate(e);return void 0===r.parent?new zC(t.path):(VC(n.parent,n.key),JC(r.parent,r.key,n.value),null)}function QC(e,t){var n=BC.Pointer.fromJSON(t.from).evaluate(e);if(void 0===n.value)return new zC(t.from);var r=BC.Pointer.fromJSON(t.path).evaluate(e);return void 0===r.parent?new zC(t.path):(JC(r.parent,r.key,qC.clone(n.value)),null)}function XC(e,t){var n=BC.Pointer.fromJSON(t.path).evaluate(e);return WC.compare(n.value,t.value)?null:new GC(n.value,t.value)}jC.TestError=GC,jC.add=$C,jC.remove=KC,jC.replace=HC,jC.move=YC,jC.copy=QC,jC.test=XC;var ZC=function(e){function t(t){var n=e.call(this,"Invalid operation: "+t.op)||this;return n.operation=t,n.name="InvalidOperationError",n}return FC(t,e),t}(Error);jC.InvalidOperationError=ZC,jC.apply=function(e,t){switch(t.op){case"add":return $C(e,t);case"remove":return KC(e,t);case"replace":return HC(e,t);case"move":return YC(e,t);case"copy":return QC(e,t);case"test":return XC(e,t)}return new ZC(t)};var eP={};Object.defineProperty(eP,"__esModule",{value:!0}),eP.diffAny=eP.diffObjects=eP.diffArrays=eP.intersection=eP.subtract=eP.isDestructive=void 0;var tP=LC,nP=MC;function rP(e,t){var n={};for(var r in e)nP.hasOwnProperty.call(e,r)&&void 0!==e[r]&&(n[r]=1);for(var i in t)nP.hasOwnProperty.call(t,i)&&void 0!==t[i]&&delete n[i];return Object.keys(n)}function iP(e){for(var t=e.length,n={},r=0;r<t;r++){var i=e[r];for(var a in i)nP.hasOwnProperty.call(i,a)&&void 0!==i[a]&&(n[a]=(n[a]||0)+1)}for(var a in n)n[a]<t&&delete n[a];return Object.keys(n)}function aP(e,t){return{operations:e.operations.concat(t),cost:e.cost+1}}function sP(e,t,n,r){void 0===r&&(r=uP);var i={"0,0":{operations:[],cost:0}};var a=isNaN(e.length)||e.length<=0?0:e.length,s=isNaN(t.length)||t.length<=0?0:t.length;return function n(r,a){var s=r+","+a,o=i[s];if(void 0===o){if(r>0&&a>0&&tP.compare(e[r-1],t[a-1]))o=n(r-1,a-1);else{var u=[];if(r>0){var c=n(r-1,a),l={op:"remove",index:r-1};u.push(aP(c,l))}if(a>0){var f=n(r,a-1),d={op:"add",index:r-1,value:t[a-1]};u.push(aP(f,d))}if(r>0&&a>0){var p=n(r-1,a-1),h={op:"replace",index:r-1,original:e[r-1],value:t[a-1]};u.push(aP(p,h))}o=u.sort((function(e,t){return e.cost-t.cost}))[0]}i[s]=o}return o}(a,s).operations.reduce((function(e,t){var i=e[0],s=e[1];if(function(e){return"add"===e.op}(t)){var o=t.index+1+s,u=o<a+s?String(o):"-",c={op:t.op,path:n.add(u).toString(),value:t.value};return[i.concat(c),s+1]}if(function(e){return"remove"===e.op}(t)){c={op:t.op,path:n.add(String(t.index+s)).toString()};return[i.concat(c),s-1]}var l=n.add(String(t.index+s)),f=r(t.original,t.value,l);return[i.concat.apply(i,f),s]}),[[],0])[0]}function oP(e,t,n,r){void 0===r&&(r=uP);var i=[];return rP(e,t).forEach((function(e){i.push({op:"remove",path:n.add(e).toString()})})),rP(t,e).forEach((function(e){i.push({op:"add",path:n.add(e).toString(),value:t[e]})})),iP([e,t]).forEach((function(a){i.push.apply(i,r(e[a],t[a],n.add(a)))})),i}function uP(e,t,n,r){if(void 0===r&&(r=uP),e===t)return[];var i=nP.objectType(e),a=nP.objectType(t);return"array"==i&&"array"==a?sP(e,t,n,r):"object"==i&&"object"==a?oP(e,t,n,r):[{op:"replace",path:n.toString(),value:t}]}eP.isDestructive=function(e){var t=e.op;return"remove"===t||"replace"===t||"copy"===t||"move"===t},eP.subtract=rP,eP.intersection=iP,eP.diffArrays=sP,eP.diffObjects=oP,eP.diffAny=uP,Object.defineProperty(IC,"__esModule",{value:!0}),IC.createTests=dP=IC.createPatch=IC.applyPatch=void 0;var cP=OC,lP=jC,fP=eP;IC.applyPatch=function(e,t){return t.map((function(t){return lP.apply(e,t)}))};var dP=IC.createPatch=function(e,t,n){var r=new cP.Pointer;return(n?function(e){return function t(n,r,i){var a=e(n,r,i);return Array.isArray(a)?a:fP.diffAny(n,r,i,t)}}(n):fP.diffAny)(e,t,r)};function pP(e,t){var n=cP.Pointer.fromJSON(t).evaluate(e);if(void 0!==n)return{op:"test",path:t,value:n.value}}function hP(e,t){return 0===dP(e,t).length}function vP(e){return JSON.parse(JSON.stringify(e))}function yP(e){return void 0===e||isNaN(Number(e))?null:Number(e)}function mP(e){try{return new Date(e)}catch(e){return null}}function gP(e,t,n){var r={};if(e)try{r=JSON.parse(e)}catch(e){n.warn(t,e)}return r}IC.createTests=function(e,t){var n=new Array;return t.filter(fP.isDestructive).forEach((function(t){var r=pP(e,t.path);if(r&&n.push(r),"from"in t){var i=pP(e,t.from);i&&n.push(i)}})),n};var bP=function(){function e(t){Ma(this,e),this.base=t.replace(/\/$/,""),this.args=[],this.paths=[]}return Ta(e,[{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}}]),e}();function kP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var wP=vd.scope("Participant"),Participant=function(e){Oa(Participant,e);var t,n,r=kP(Participant);function Participant(e,t,n,i,a){var s;if(Ma(this,Participant),(s=r.call(this)).conversation=n,s.links=i,s.services=a,s.state={attributes:gP(e.attributes,"Retrieved malformed attributes from the server for participant: "+t,wP),dateCreated:e.dateCreated?mP(e.dateCreated):null,dateUpdated:e.dateCreated?mP(e.dateUpdated):null,sid:t,typingTimeout:null,isTyping:!1,identity:e.identity||null,roleSid:e.roleSid||null,lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,lastReadTimestamp:e.lastConsumptionTimestamp?mP(e.lastConsumptionTimestamp):null,type:e.type||"chat",userInfo:e.userInfo},!e.identity&&!e.type)throw new Error("Received invalid Participant object from server: Missing identity or type of Participant.");return s}return Ta(Participant,[{key:"sid",get:function(){return this.state.sid}},{key:"attributes",get:function(){return this.state.attributes}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"identity",get:function(){return this.state.identity}},{key:"isTyping",get:function(){return this.state.isTyping}},{key:"lastReadMessageIndex",get:function(){return this.state.lastReadMessageIndex}},{key:"lastReadTimestamp",get:function(){return this.state.lastReadTimestamp}},{key:"roleSid",get:function(){return this.state.roleSid}},{key:"type",get:function(){return this.state.type}},{key:"_startTyping",value:function(e){var t=this;return clearTimeout(this.state.typingTimeout),this.state.isTyping=!0,this.emit("typingStarted",this),this.conversation.emit("typingStarted",this),this.state.typingTimeout=setTimeout((function(){return t._endTyping()}),e),this}},{key:"_endTyping",value:function(){this.state.typingTimeout&&(this.state.isTyping=!1,this.emit("typingEnded",this),this.conversation.emit("typingEnded",this),clearInterval(this.state.typingTimeout),this.state.typingTimeout=null)}},{key:"_update",value:function(e){var t=[],n=gP(e.attributes,"Retrieved malformed attributes from the server for participant: "+this.state.sid,wP);e.attributes&&!hP(this.state.attributes,n)&&(this.state.attributes=n,t.push("attributes"));var r=mP(e.dateUpdated);e.dateUpdated&&r.getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=r,t.push("dateUpdated"));var i=mP(e.dateCreated);if(e.dateCreated&&i.getTime()!==(this.state.dateCreated&&this.state.dateCreated.getTime())&&(this.state.dateCreated=i,t.push("dateCreated")),e.roleSid&&this.state.roleSid!==e.roleSid&&(this.state.roleSid=e.roleSid,t.push("roleSid")),!Number.isInteger(e.lastConsumedMessageIndex)&&null!==e.lastConsumedMessageIndex||this.state.lastReadMessageIndex===e.lastConsumedMessageIndex||(this.state.lastReadMessageIndex=e.lastConsumedMessageIndex,t.push("lastReadMessageIndex")),e.lastConsumptionTimestamp){var a=new Date(e.lastConsumptionTimestamp);this.state.lastReadTimestamp&&this.state.lastReadTimestamp.getTime()===a.getTime()||(this.state.lastReadTimestamp=a,t.push("lastReadTimestamp"))}return t.length>0&&this.emit("updated",{participant:this,updateReasons:t}),this}},{key:"getUser",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("chat"==this.type){e.next=2;break}throw new Error("Getting User is not supported for this Participant type: "+this.type);case 2:return e.abrupt("return",this.services.users.getUser(this.state.identity,this.state.userInfo));case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"remove",value:function(){var e=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.conversation.removeParticipant(this));case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"updateAttributes",value:(t=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(t)});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Participant}(Sl);function xP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}ja(Participant,"typingStarted","typingStarted"),ja(Participant,"typingEnded","typingEnded"),ja(Participant,"updated","updated"),wl([$y(["string","number","boolean","object",By(null)]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Participant.prototype,"updateAttributes",null);var _P=vd.scope("Participants"),SP=function(e){Oa(s,e);var t,n,r,i,a=xP(s);function s(e,t,n,r,i){var o;return Ma(this,s),(o=a.call(this)).conversation=e,o.participants=t,o.links=n,o.configuration=r,o.services=i,o}return Ta(s,[{key:"unsubscribe",value:(i=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.rosterEntityPromise){e.next=6;break}return e.next=3,this.rosterEntityPromise;case 3:e.sent.close(),this.rosterEntityPromise=null;case 6:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"subscribe",value:function(e){var t=this;return this.rosterEntityPromise=this.rosterEntityPromise||this.services.syncClient.map({id:e,mode:"open_existing"}).then((function(e){e.on("itemAdded",(function(e){_P.debug(t.conversation.sid+" itemAdded: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data).then((function(e){t.emit("participantJoined",e)}))})),e.on("itemRemoved",(function(e){_P.debug(t.conversation.sid+" itemRemoved: "+e.key);var n=e.key;if(t.participants.has(n)){var r=t.participants.get(n);t.participants.delete(n),t.emit("participantLeft",r)}})),e.on("itemUpdated",(function(e){_P.debug(t.conversation.sid+" itemUpdated: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data)}));var n=[],r=t;return e.getItems().then((function e(t){return t.items.forEach((function(e){n.push(r.upsertParticipant(e.key,e.data))})),t.hasNextPage?t.nextPage().then(e):null})).then((function(){return Promise.all(n)})).then((function(){return e}))})).catch((function(e){throw t.rosterEntityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&_P.error("Failed to get roster object for conversation",t.conversation.sid,e),_P.debug("ERROR: Failed to get roster object for conversation",t.conversation.sid,e),e}))}},{key:"upsertParticipant",value:(r=Sa(bl.mark((function e(t,n){var r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.participants.get(t))){e.next=3;break}return e.abrupt("return",r._update(n));case 3:return i={self:"".concat(this.links.participants,"/").concat(t)},r=new Participant(n,t,this.conversation,i,this.services),this.participants.set(t,r),r.on("updated",(function(e){return a.emit("participantUpdated",e)})),e.abrupt("return",r);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"getParticipants",value:function(){var e=this;return this.rosterEntityPromise.then((function(){var t=[];return e.participants.forEach((function(e){return t.push(e)})),t}))}},{key:"getParticipantBySid",value:(n=Sa(bl.mark((function e(t){var n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise.then((function(){var e=n.participants.get(t);if(!e)throw new Error("Participant with SID "+t+" was not found");return e})));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(t=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.abrupt("return",this.rosterEntityPromise.then((function(){if(r.participants.forEach((function(e){e.identity===t&&(n=e)})),!n)throw new Error("Participant with identity "+t+" was not found");return n})));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"add",value:function(){var e=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:t,attributes:void 0!==n?JSON.stringify(n):void 0});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}()},{key:"addNonChatParticipant",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.services.commandExecutor.mutateResource("post",this.links.participants,{attributes:JSON.stringify(n),messaging_binding:{address:t,proxy_address:e}})}},{key:"remove",value:function(e){return this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(e))}}]),s}(Sl),EP=In,TP=On,RP=Q,IP=Ut,OP=gr,CP=s,PP=$x,AP=ec,jP=Hx,MP=Yx,LP=L,NP=Xx,UP=[],DP=UP.sort,FP=CP((function(){UP.sort(void 0)})),BP=CP((function(){UP.sort(null)})),qP=AP("sort"),WP=!CP((function(){if(LP)return LP<70;if(!(jP&&jP>3)){if(MP)return!0;if(NP)return NP<603;var e,t,n,r,i="";for(e=65;e<76;e++){switch(t=String.fromCharCode(e),e){case 66:case 69:case 70:case 72:n=3;break;case 68:case 71:n=4;break;default:n=2}for(r=0;r<47;r++)UP.push({k:t+r,v:n})}for(UP.sort((function(e,t){return t.v-e.v})),r=0;r<UP.length;r++)t=UP[r].k.charAt(0),i.charAt(i.length-1)!==t&&(i+=t);return"DGBEFHACIJK"!==i}}));EP({target:"Array",proto:!0,forced:FP||!BP||!qP||!WP},{sort:function(e){void 0!==e&&TP(e);var t=RP(this);if(WP)return void 0===e?DP.call(t):DP.call(t,e);var n,r,i=[],a=IP(t.length);for(r=0;r<a;r++)r in t&&i.push(t[r]);for(n=(i=PP(i,function(e){return function(t,n){return void 0===n?-1:void 0===t?1:void 0!==e?+e(t,n)||0:OP(t)>OP(n)?1:-1}}(e))).length,r=0;r<n;)t[r]=i[r++];for(;r<a;)delete t[r++];return t}});var zP=vR,GP=k,JP=gr;In({target:"String",proto:!0,forced:!mR("includes")},{includes:function(e){return!!~JP(GP(this)).indexOf(JP(zP(e)),arguments.length>1?arguments[1]:void 0)}});var Media=function(){function Media(e,t){Ma(this,Media),ja(this,"mcsMedia",null),this.services=t,e instanceof pR.McsMedia&&(this.mcsMedia=e),this.state={sid:e.sid,category:e.category,filename:e.filename,contentType:e.contentType,size:e.size}}var e,t,n;return Ta(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"filename",get:function(){return this.state.filename}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"category",get:function(){return this.state.category}},{key:"getContentTemporaryUrl",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._fetchMcsMedia();case 2:return e.abrupt("return",this.mcsMedia.getContentUrl());case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getCachedTemporaryUrl",value:(t=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._fetchMcsMedia();case 2:return e.abrupt("return",this.mcsMedia.getCachedContentUrl());case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_fetchMcsMedia",value:(e=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.mcsMedia){e.next=8;break}if(!this.services.mcsClient){e.next=7;break}return e.next=4,this.services.mcsClient.get(this.state.sid);case 4:this.mcsMedia=e.sent,e.next=8;break;case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(){return e.apply(this,arguments)})}]),Media}(),AggregatedDeliveryReceipt=function(){function AggregatedDeliveryReceipt(e){Ma(this,AggregatedDeliveryReceipt),this.state=e}return Ta(AggregatedDeliveryReceipt,[{key:"total",get:function(){return this.state.total}},{key:"sent",get:function(){return this.state.sent}},{key:"delivered",get:function(){return this.state.delivered}},{key:"read",get:function(){return this.state.read}},{key:"undelivered",get:function(){return this.state.undelivered}},{key:"failed",get:function(){return this.state.failed}},{key:"_update",value:function(e){this.state=e}},{key:"_isEquals",value:function(e){var t=this.total===e.total,n=this.sent===e.sent,r=this.delivered===e.delivered,i=this.read===e.read,a=this.undelivered===e.undelivered,s=this.failed===e.failed;return t&&n&&r&&i&&a&&s}}]),AggregatedDeliveryReceipt}(),VP=function(){function e(t,n,r,i){Ma(this,e),this.state={prevToken:r,nextToken:i,source:n,items:t}}return Ta(e,[{key:"hasNextPage",get:function(){return!!this.state.nextToken}},{key:"hasPrevPage",get:function(){return!!this.state.prevToken}},{key:"items",get:function(){return this.state.items}},{key:"nextPage",value:function(){return this.hasNextPage?this.state.source(this.state.nextToken):Promise.reject(new Error("No next page"))}},{key:"prevPage",value:function(){return this.hasPrevPage?this.state.source(this.state.prevToken):Promise.reject(new Error("No previous page"))}}]),e}(),DetailedDeliveryReceipt=function DetailedDeliveryReceipt(e){Ma(this,DetailedDeliveryReceipt),this.sid=e.sid,this.messageSid=e.message_sid,this.conversationSid=e.conversation_sid,this.channelMessageSid=e.channel_message_sid,this.participantSid=e.participant_sid,this.status=e.status||"queued",this.errorCode=e.error_code||0,this.dateCreated=e.date_created,this.dateUpdated=e.date_updated};function $P(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var KP=vd.scope("Message"),Message=function(e){Oa(Message,e);var t,n,r,i,a,s,o=$P(Message);function Message(e,t,n,r,i,a){var s,u,c,l,f,d;return Ma(this,Message),(d=o.call(this)).conversation=n,d.links=r,d.configuration=i,d.services=a,d.state={sid:t.sid,index:e,author:null!==(s=t.author)&&void 0!==s?s:null,subject:null!==(u=t.subject)&&void 0!==u?u:null,body:t.text,timestamp:t.timestamp?new Date(t.timestamp):null,dateUpdated:t.dateUpdated?new Date(t.dateUpdated):null,lastUpdatedBy:null!==(c=t.lastUpdatedBy)&&void 0!==c?c:null,attributes:gP(t.attributes,"Got malformed attributes for the message ".concat(t.sid),KP),type:null!==(l=t.type)&&void 0!==l?l:"text",media:t.type&&"media"===t.type&&t.media?new Media(t.media,d.services):null,medias:t.type&&"media"===t.type&&t.medias?t.medias.map((function(e){return new Media(e,d.services)})):null,participantSid:null!==(f=t.memberSid)&&void 0!==f?f:null,aggregatedDeliveryReceipt:t.delivery?new AggregatedDeliveryReceipt(t.delivery):null},d}return Ta(Message,[{key:"sid",get:function(){return this.state.sid}},{key:"author",get:function(){return this.state.author}},{key:"subject",get:function(){return this.state.subject}},{key:"body",get:function(){return this.state.body}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"index",get:function(){return this.state.index}},{key:"lastUpdatedBy",get:function(){return this.state.lastUpdatedBy}},{key:"dateCreated",get:function(){return this.state.timestamp}},{key:"attributes",get:function(){return this.state.attributes}},{key:"type",get:function(){return this.state.type}},{key:"media",get:function(){return this.state.media}},{key:"attachedMedia",get:function(){return this.getMediaByCategory(["media"])}},{key:"participantSid",get:function(){return this.state.participantSid}},{key:"aggregatedDeliveryReceipt",get:function(){return this.state.aggregatedDeliveryReceipt}},{key:"getMediaByCategory",value:function(e){var t;return null===(t=this.state.medias)||void 0===t?void 0:t.filter((function(t){return e.includes(t.category)}))}},{key:"_update",value:function(e){var t=[];!e.text&&"string"!=typeof e.text||e.text===this.state.body||(this.state.body=e.text,t.push("body")),e.subject&&e.subject!==this.state.subject&&(this.state.subject=e.subject,t.push("subject")),e.lastUpdatedBy&&e.lastUpdatedBy!==this.state.lastUpdatedBy&&(this.state.lastUpdatedBy=e.lastUpdatedBy,t.push("lastUpdatedBy")),e.author&&e.author!==this.state.author&&(this.state.author=e.author,t.push("author")),e.dateUpdated&&new Date(e.dateUpdated).getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=new Date(e.dateUpdated),t.push("dateUpdated")),e.timestamp&&new Date(e.timestamp).getTime()!==(this.state.timestamp&&this.state.timestamp.getTime())&&(this.state.timestamp=new Date(e.timestamp),t.push("dateCreated"));var n=gP(e.attributes,"Got malformed attributes for the message ".concat(this.sid),KP);hP(this.state.attributes,n)||(this.state.attributes=n,t.push("attributes"));var r=e.delivery,i=this.state.aggregatedDeliveryReceipt;!!(r&&r.total&&r.delivered&&r.failed&&r.read&&r.sent&&r.undelivered)&&(i?i._isEquals(r)||(i._update(r),t.push("deliveryReceipt")):(this.state.aggregatedDeliveryReceipt=new AggregatedDeliveryReceipt(r),t.push("deliveryReceipt"))),t.length>0&&this.emit("updated",{message:this,updateReasons:t})}},{key:"getParticipant",value:(s=Sa(bl.mark((function e(){var t,n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=null,!this.state.participantSid){e.next=5;break}return e.next=4,this.conversation.getParticipantBySid(this.participantSid).catch((function(){return KP.debug('Participant with sid "'.concat(r.participantSid,'" not found for message ').concat(r.sid)),null}));case 4:t=e.sent;case 5:if(t||!this.state.author){e.next=9;break}return e.next=8,this.conversation.getParticipantByIdentity(this.state.author).catch((function(){return KP.debug('Participant with identity "'.concat(r.author,'" not found for message ').concat(r.sid)),null}));case 8:t=e.sent;case 9:if(!t){e.next=11;break}return e.abrupt("return",t);case 11:throw n="Participant with ",this.state.participantSid&&(n+="SID '"+this.state.participantSid+"' "),this.state.author&&(this.state.participantSid&&(n+="or "),n+="identity '"+this.state.author+"' "),"Participant with "===n&&(n="Participant "),n+="was not found",new Error(n);case 17:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"getDetailedDeliveryReceipts",value:(a=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getDetailedDeliveryReceiptsPaginator();case 2:t=e.sent,n=[];case 4:if(n=[].concat(SC(n),SC(t.items)),t.hasNextPage){e.next=8;break}return e.abrupt("break",13);case 8:return e.next=10,t.nextPage();case 10:t=e.sent,e.next=4;break;case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"remove",value:function(){var e=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("delete",this.links.self);case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"updateBody",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{body:t});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateAttributes",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"attachTemporaryUrlsFor",value:(n=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.map((function(e){return e.sid})),!this.services.mcsClient){e.next=7;break}return e.next=4,this.services.mcsClient.mediaSetGet(n);case 4:return e.abrupt("return",e.sent.map((function(e){return new Media(e,r.services)})));case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"_getDetailedDeliveryReceiptsPaginator",value:(t=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.configuration.links.messagesReceipts.replace("%s",this.conversation.sid).replace("%s",this.sid),r=new bP(n).arg("PageToken",null==t?void 0:t.pageToken).arg("PageSize",null==t?void 0:t.pageSize).build(),e.next=4,this.services.network.get(r);case 4:return i=e.sent,e.abrupt("return",new VP(i.body.delivery_receipts.map((function(e){return new DetailedDeliveryReceipt(e)})),(function(e,t){return a._getDetailedDeliveryReceiptsPaginator({pageToken:e,pageSize:t})}),i.body.meta.previous_token,i.body.meta.next_token));case 6:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Message}(Sl);function HP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return YP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return YP(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function YP(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function QP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}ja(Message,"updated","updated"),wl([$y("string"),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Message.prototype,"updateBody",null),wl([$y(["string","number","boolean","object",By(null)]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Message.prototype,"updateAttributes",null),wl([$y(Fy((function(e){return[e instanceof Array&&e.length>0&&e.reduce((function(e,t){return e&&t instanceof Media})),"a non-empty array of Media"]}))),xl("design:type",Function),xl("design:paramtypes",[Array]),xl("design:returntype",Promise)],Message.prototype,"attachTemporaryUrlsFor",null);var XP=vd.scope("Messages"),ZP=function(e){Oa(c,e);var t,n,r,i,a,s,o,u=QP(c);function c(e,t,n){var r;return Ma(this,c),(r=u.call(this)).conversation=e,r.configuration=t,r.services=n,r.messagesByIndex=new Map,r.messagesListPromise=null,r}return Ta(c,[{key:"subscribe",value:(o=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.messagesListPromise){e.next=2;break}return e.abrupt("return",this.messagesListPromise);case 2:return this.messagesListPromise=this.services.syncClient.list({id:t,mode:"open_existing"}),e.prev=3,e.next=6,this.messagesListPromise;case 6:return(n=e.sent).on("itemAdded",(function(e){XP.debug("".concat(r.conversation.sid," itemAdded: ").concat(e.item.index));var t={self:"".concat(r.conversation.links.messages,"/").concat(e.item.data.sid),conversation:r.conversation.links.self,messages_receipts:"".concat(r.conversation.links.messages,"/").concat(e.item.data.sid,"/Receipts")},n=new Message(e.item.index,e.item.data,r.conversation,t,r.configuration,r.services);r.messagesByIndex.has(n.index)?XP.debug("Message arrived, but is already known and ignored",r.conversation.sid,n.index):(r.messagesByIndex.set(n.index,n),n.on("updated",(function(e){return r.emit("messageUpdated",e)})),r.emit("messageAdded",n))})),n.on("itemRemoved",(function(e){XP.debug("#{this.conversation.sid} itemRemoved: ".concat(e.index));var t=e.index;if(r.messagesByIndex.has(t)){var n=r.messagesByIndex.get(t);r.messagesByIndex.delete(n.index),n.removeAllListeners("updated"),r.emit("messageRemoved",n)}})),n.on("itemUpdated",(function(e){XP.debug("".concat(r.conversation.sid," itemUpdated: ").concat(e.item.index));var t=r.messagesByIndex.get(e.item.index);t&&t._update(e.item.data)})),e.abrupt("return",n);case 13:throw e.prev=13,e.t0=e.catch(3),this.messagesListPromise=null,"disconnected"!==this.services.syncClient.connectionState&&XP.error("Failed to get messages object for conversation",this.conversation.sid,e.t0),XP.debug("ERROR: Failed to get messages object for conversation",this.conversation.sid,e.t0),e.t0;case 19:case"end":return e.stop()}}),e,this,[[3,13]])}))),function(e){return o.apply(this,arguments)})},{key:"unsubscribe",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.messagesListPromise){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.messagesListPromise;case 4:e.sent.close(),this.messagesListPromise=null;case 7:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"sendV2",value:(a=Sa(bl.mark((function e(t){var n,r,i,a,s,o,u;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:XP.debug("Sending message V2",t.mediaContent,t.attributes,t.emailOptions),r=[],i=HP(t.mediaContent),e.prev=3,i.s();case 5:if((a=i.n()).done){e.next=22;break}if(s=op(a.value,2),o=s[0],u=s[1],XP.debug("Adding media to a message as ".concat(u instanceof FormData?"FormData":"SendMediaOptions"),u),e.t0=r,!(u instanceof FormData)){e.next=15;break}return e.next=12,this.services.mcsClient.postFormData(u,o);case 12:e.t1=e.sent,e.next=18;break;case 15:return e.next=17,this.services.mcsClient.post(u.contentType,u.media,o,u.filename);case 17:e.t1=e.sent;case 18:e.t2=e.t1,e.t0.push.call(e.t0,e.t2);case 20:e.next=5;break;case 22:e.next=27;break;case 24:e.prev=24,e.t3=e.catch(3),i.e(e.t3);case 27:return e.prev=27,i.f(),e.finish(27);case 30:return e.next=32,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{body:t.text,subject:null===(n=t.emailOptions)||void 0===n?void 0:n.subject,media_sids:r.map((function(e){return e.sid})),attributes:void 0!==t.attributes?JSON.stringify(t.attributes):void 0});case 32:return e.abrupt("return",e.sent);case 33:case"end":return e.stop()}}),e,this,[[3,24,27,30]])}))),function(e){return a.apply(this,arguments)})},{key:"send",value:(i=Sa(bl.mark((function e(t){var n,r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]?i[1]:{},r=i.length>2?i[2]:void 0,XP.debug("Sending text message",t,n,r),e.next=5,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{body:null!=t?t:"",attributes:void 0!==n?JSON.stringify(n):void 0,subject:null==r?void 0:r.subject});case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"sendMedia",value:(r=Sa(bl.mark((function e(t){var n,r,i,a=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=a.length>1&&void 0!==a[1]?a[1]:{},r=a.length>2?a[2]:void 0,XP.debug("Sending media message",t,n,r),XP.debug("Sending media message as ".concat(t instanceof FormData?"FormData":"SendMediaOptions"),t,n),!(t instanceof FormData)){e.next=10;break}return e.next=7,this.services.mcsClient.postFormData(t);case 7:e.t0=e.sent,e.next=13;break;case 10:return e.next=12,this.services.mcsClient.post(t.contentType,t.media,"media",t.filename);case 12:e.t0=e.sent;case 13:return i=e.t0,e.next=16,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{media_sids:[i.sid],attributes:void 0!==n?JSON.stringify(n):void 0});case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getMessages",value:(n=Sa(bl.mark((function e(t,n){var r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=i.length>2&&void 0!==i[2]?i[2]:"backwards",e.abrupt("return",this._getMessages(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"_wrapPaginator",value:function(e,t,n){var r=this,i="desc"===e,a=function(){return t.nextPage().then((function(t){return r._wrapPaginator(e,t,n)}))},s=function(){return t.prevPage().then((function(t){return r._wrapPaginator(e,t,n)}))};return n(t.items).then((function(e){return{items:e.sort((function(e,t){return e.index-t.index})),hasPrevPage:i?t.hasNextPage:t.hasPrevPage,hasNextPage:i?t.hasPrevPage:t.hasNextPage,prevPage:i?a:s,nextPage:i?s:a}}))}},{key:"_upsertMessage",value:function(e,t){var n=this,r=this.messagesByIndex.get(e);if(r)return r;var i={self:"".concat(this.conversation.links.messages,"/").concat(t.sid),conversation:this.conversation.links.self,messages_receipts:"".concat(this.conversation.links.messages,"/").concat(t.sid,"/Receipts")},a=new Message(e,t,this.conversation,i,this.configuration,this.services);return this.messagesByIndex.set(a.index,a),a.on("updated",(function(e){return n.emit("messageUpdated",e)})),a}},{key:"_getMessages",value:(t=Sa(bl.mark((function e(){var t,n,r,i,a,s,o=this,u=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:30,n=u.length>1&&void 0!==u[1]?u[1]:"end",r=u.length>2&&void 0!==u[2]?u[2]:"forward",i="backwards"===r?"desc":"asc",e.next=6,this.messagesListPromise;case 6:return a=e.sent,e.next=9,a.getItems({from:"end"!==n?n:void 0,pageSize:t,order:i,limit:t});case 9:return s=e.sent,e.next=12,this._wrapPaginator(i,s,(function(e){return Promise.all(e.map((function(e){return o._upsertMessage(e.index,e.data)})))}));case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),c}(Sl),eA=function(){function e(t){Ma(this,e),ja(this,"attributes",{}),ja(this,"mediaContent",[]),ja(this,"emailOptions",{}),this.messagesEntity=t}var t;return Ta(e,[{key:"send",value:(t=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.messagesEntity.sendV2(this);case 2:return t=e.sent,e.abrupt("return",yP(t.messageId));case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),tA=function(){function e(t,n){Ma(this,e),this.limits=t,this.message=new eA(n)}return Ta(e,[{key:"setBody",value:function(e){return this.message.text=e,this}},{key:"setSubject",value:function(e){return this.message.emailOptions.subject=e,this}},{key:"setAttributes",value:function(e){return this.message.attributes=e,this}},{key:"addMedia",value:function(e){return this.message.mediaContent.push(["media",e]),this}},{key:"build",value:function(){if(this.message.mediaContent.length>this.limits.mediaAttachmentsCountLimit)throw new Error("Too many media attachments in the message (".concat(this.message.mediaContent.length," > ").concat(this.limits.mediaAttachmentsCountLimit,")"));return this.message}},{key:"getPayloadContentType",value:function(e){return"undefined"!=typeof FormData&&e instanceof FormData?e.get("Content-Type"):e.contentType}}]),e}();function nA(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return rA(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return rA(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function rA(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function iA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var aA=vd.scope("Conversation"),sA={lastMessage:"lastMessage",attributes:"attributes",createdBy:"createdBy",dateCreated:"dateCreated",dateUpdated:"dateUpdated",friendlyName:"friendlyName",lastConsumedMessageIndex:"lastConsumedMessageIndex",notificationLevel:"notificationLevel",sid:"sid",status:"status",uniqueName:"uniqueName",state:"state"};function oA(e){try{return new Date(e)}catch(e){return null}}var Conversation=function(e){Oa(Conversation,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y,m,g,b,k,w,x,_,S,E,T=iA(Conversation);function Conversation(e,t,n,r,i){var a;Ma(this,Conversation),(a=T.call(this)).sid=t,a.links=n,a.configuration=r,a.services=i;var s=e.attributes||{},o=e.createdBy,u=oA(e.dateCreated),c=oA(e.dateUpdated),l=e.friendlyName||null,f=Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,d=e.uniqueName||null;try{JSON.stringify(s)}catch(e){throw new Error("Attributes must be a valid JSON object.")}a.entityName=e.channel,a.channelState={uniqueName:d,status:"notParticipating",attributes:s,createdBy:o,dateCreated:u,dateUpdated:c,friendlyName:l,lastReadMessageIndex:f},e.notificationLevel&&(a.channelState.notificationLevel=e.notificationLevel);var p={participants:a.links.participants};return a.participants=new Map,a.participantsEntity=new SP(Ra(a),a.participants,p,a.configuration,a.services),a.participantsEntity.on("participantJoined",a.emit.bind(Ra(a),"participantJoined")),a.participantsEntity.on("participantLeft",a.emit.bind(Ra(a),"participantLeft")),a.participantsEntity.on("participantUpdated",(function(e){return a.emit("participantUpdated",e)})),a.messagesEntity=new ZP(Ra(a),r,i),a.messagesEntity.on("messageAdded",(function(e){return a._onMessageAdded(e)})),a.messagesEntity.on("messageUpdated",(function(e){return a.emit("messageUpdated",e)})),a.messagesEntity.on("messageRemoved",a.emit.bind(Ra(a),"messageRemoved")),a}return Ta(Conversation,[{key:"uniqueName",get:function(){return this.channelState.uniqueName}},{key:"status",get:function(){return this.channelState.status}},{key:"friendlyName",get:function(){return this.channelState.friendlyName}},{key:"dateUpdated",get:function(){return this.channelState.dateUpdated}},{key:"dateCreated",get:function(){return this.channelState.dateCreated}},{key:"createdBy",get:function(){return this.channelState.createdBy}},{key:"attributes",get:function(){return this.channelState.attributes}},{key:"lastReadMessageIndex",get:function(){return this.channelState.lastReadMessageIndex}},{key:"lastMessage",get:function(){return this.channelState.lastMessage}},{key:"notificationLevel",get:function(){return this.channelState.notificationLevel}},{key:"limits",get:function(){return this.configuration.limits}},{key:"state",get:function(){return this.channelState.state}},{key:"_subscribe",value:function(){var e,t=this;return this.entityPromise=null!==(e=this.entityPromise)&&void 0!==e?e:this.services.syncClient.document({id:this.entityName,mode:"open_existing"}).then((function(e){return t.entity=e,t.entity.on("updated",(function(e){t._update(e.data)})),t.entity.on("removed",(function(){return t.emit("removed",t)})),t._update(t.entity.data),e})).catch((function(e){throw t.entity=null,t.entityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&aA.error("Failed to get conversation object",e),aA.debug("ERROR: Failed to get conversation object",e),e}))}},{key:"_subscribeStreams",value:(E=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._subscribe();case 3:return aA.trace("_subscribeStreams, this.entity.data=",this.entity.data),t=this.entity.data.messages,n=this.entity.data.roster,e.next=8,Promise.all([this.messagesEntity.subscribe(t),this.participantsEntity.subscribe(n)]);case 8:e.next=15;break;case 10:throw e.prev=10,e.t0=e.catch(0),"disconnected"!==this.services.syncClient.connectionState&&aA.error("Failed to subscribe on conversation objects",this.sid,e.t0),aA.debug("ERROR: Failed to subscribe on conversation objects",this.sid,e.t0),e.t0;case 15:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(){return E.apply(this,arguments)})},{key:"_unsubscribe",value:(S=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.entity){e.next=5;break}return e.next=3,this.entity.close();case 3:this.entity=null,this.entityPromise=null;case 5:return e.abrupt("return",Promise.all([this.participantsEntity.unsubscribe(),this.messagesEntity.unsubscribe()]));case 6:case"end":return e.stop()}}),e,this)}))),function(){return S.apply(this,arguments)})},{key:"_setStatus",value:function(e,t){var n=this;this.statusSource=t,this.channelState.status!==e&&(this.channelState.status=e,"joined"===e?this._subscribeStreams().catch((function(t){if(aA.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n.services.syncClient.connectionState)throw t})):this.entityPromise&&this._unsubscribe().catch((function(t){if(aA.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n.services.syncClient.connectionState)throw t})))}},{key:"_statusSource",value:function(){return this.statusSource}},{key:"_update",value:function(e){var t,n,r,i,a;aA.trace("_update",e),Conversation.preprocessUpdate(e,this.sid);for(var s=new Set,o=0,u=Object.keys(e);o<u.length;o++){var c=u[o],l=sA[c];if(l)switch(l){case sA.status:if(!e.status||"unknown"===e.status||this.channelState.status===e.status)break;this.channelState.status=e.status,s.add(l);break;case sA.attributes:if(hP(this.channelState.attributes,e.attributes))break;this.channelState.attributes=e.attributes,s.add(l);break;case sA.lastConsumedMessageIndex:if(void 0===e.lastConsumedMessageIndex||e.lastConsumedMessageIndex===this.channelState.lastReadMessageIndex)break;this.channelState.lastReadMessageIndex=e.lastConsumedMessageIndex,s.add("lastReadMessageIndex");break;case sA.lastMessage:if(this.channelState.lastMessage&&!e.lastMessage){delete this.channelState.lastMessage,s.add(l);break}this.channelState.lastMessage=this.channelState.lastMessage||{},void 0!==(null===(t=e.lastMessage)||void 0===t?void 0:t.index)&&e.lastMessage.index!==this.channelState.lastMessage.index&&(this.channelState.lastMessage.index=e.lastMessage.index,s.add(l)),void 0!==(null===(n=e.lastMessage)||void 0===n?void 0:n.timestamp)&&(null===(r=this.channelState.lastMessage)||void 0===r||null===(i=r.dateCreated)||void 0===i?void 0:i.getTime())!==e.lastMessage.timestamp.getTime()&&(this.channelState.lastMessage.dateCreated=e.lastMessage.timestamp,s.add(l)),hP(this.channelState.lastMessage,{})&&delete this.channelState.lastMessage;break;case sA.state:var f=e.state||void 0;if(void 0!==f&&(f.dateUpdated=new Date(f.dateUpdated)),hP(this.channelState.state,f))break;this.channelState.state=f,s.add(l);break;default:var d=e[c]instanceof Date,p=d&&(null===(a=this.channelState[l])||void 0===a?void 0:a.getTime())===e[c].getTime(),h=!d&&this[l]===e[c];if(p||h)break;this.channelState[l]=e[c],s.add(l)}}s.size>0&&this.emit("updated",{conversation:this,updateReasons:SC(s)})}},{key:"_onMessageAdded",value:function(e){var t,n=nA(this.participants.values());try{for(n.s();!(t=n.n()).done;){var r=t.value;if(r.identity===e.author){r._endTyping();break}}}catch(e){n.e(e)}finally{n.f()}this.emit("messageAdded",e)}},{key:"_setLastReadMessageIndex",value:(_=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post","".concat(this.configuration.links.myConversations,"/").concat(this.sid),{last_read_message_index:t});case 2:return n=e.sent,e.abrupt("return",n.unread_messages_count);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return _.apply(this,arguments)})},{key:"add",value:function(){var e=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.add(t,n));case 1:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}()},{key:"addNonChatParticipant",value:(x=Sa(bl.mark((function e(t,n){var r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=i.length>2&&void 0!==i[2]?i[2]:{},e.abrupt("return",this.participantsEntity.addNonChatParticipant(t,n,null!=r?r:{}));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return x.apply(this,arguments)})},{key:"advanceLastReadMessageIndex",value:(w=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:if(!(t<this.lastReadMessageIndex)){e.next=6;break}return e.next=5,this._setLastReadMessageIndex(this.lastReadMessageIndex);case 5:return e.abrupt("return",e.sent);case 6:return e.next=8,this._setLastReadMessageIndex(t);case 8:return e.abrupt("return",e.sent);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return w.apply(this,arguments)})},{key:"delete",value:(k=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("delete",this.links.self);case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return k.apply(this,arguments)})},{key:"getAttributes",value:(b=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribe();case 2:return e.abrupt("return",this.attributes);case 3:case"end":return e.stop()}}),e,this)}))),function(){return b.apply(this,arguments)})},{key:"getMessages",value:(g=Sa(bl.mark((function e(t,n,r){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.messagesEntity.getMessages(t,n,r));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return g.apply(this,arguments)})},{key:"getParticipants",value:(m=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.participantsEntity.getParticipants());case 3:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"getParticipantsCount",value:(y=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new bP(this.configuration.links.conversations).path(this.sid).build(),e.next=3,this.services.network.get(t);case 3:return n=e.sent,e.abrupt("return",n.body.participants_count);case 5:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getParticipantBySid",value:(v=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.getParticipantBySid(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return v.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(h=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.getParticipantByIdentity(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"getMessagesCount",value:(p=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new bP(this.configuration.links.conversations).path(this.sid).build(),e.next=3,this.services.network.get(t);case 3:return n=e.sent,e.abrupt("return",n.body.messages_count);case 5:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"getUnreadMessagesCount",value:(d=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new bP(this.configuration.links.myConversations).path(this.sid).build(),e.next=3,this.services.network.get(t);case 3:if((n=e.sent).body.conversation_sid===this.sid){e.next=6;break}throw new Error("Conversation was not found in the user conversations list");case 6:if("number"!=typeof(r=n.body.unread_messages_count)){e.next=9;break}return e.abrupt("return",r);case 9:return e.abrupt("return",null);case 10:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"join",value:(f=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:this.configuration.userIdentity});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"leave",value:(l=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this.channelState.status){e.next=3;break}return e.next=3,this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(this.configuration.userIdentity));case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"removeParticipant",value:(c=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.participantsEntity.remove("string"==typeof t?t:t.sid);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"sendMessage",value:(u=Sa(bl.mark((function e(t,n,r){var i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t&&null!==t){e.next=5;break}return e.next=3,this.messagesEntity.send(t,n,r);case 3:return i=e.sent,e.abrupt("return",yP(i.index));case 5:return e.next=7,this.messagesEntity.sendMedia(t,n,r);case 7:return a=e.sent,e.abrupt("return",yP(a.index));case 9:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"prepareMessage",value:function(){return new tA(this.limits,this.messagesEntity)}},{key:"setAllMessagesRead",value:(o=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this.getMessages(1);case 4:if(!((t=e.sent).items.length>0)){e.next=7;break}return e.abrupt("return",this.advanceLastReadMessageIndex(t.items[0].index));case 7:return e.abrupt("return",Promise.resolve(0));case 8:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"setAllMessagesUnread",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this._setLastReadMessageIndex(null);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"setUserNotificationLevel",value:(a=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post","".concat(this.configuration.links.myConversations,"/").concat(this.sid),{notification_level:t});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"typing",value:function(){return this.services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateFriendlyName",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.friendlyName===t){e.next=3;break}return e.next=3,this.services.commandExecutor.mutateResource("post",this.links.self,{friendly_name:t});case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"updateLastReadMessageIndex",value:(n=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this._setLastReadMessageIndex(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"updateUniqueName",value:(t=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.uniqueName===t){e.next=4;break}return t||(t=""),e.next=4,this.services.commandExecutor.mutateResource("post",this.links.self,{unique_name:t});case 4:return e.abrupt("return",this);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}],[{key:"preprocessUpdate",value:function(e,t){try{"string"==typeof e.attributes?e.attributes=JSON.parse(e.attributes):e.attributes&&JSON.stringify(e.attributes)}catch(n){aA.warn("Retrieved malformed attributes from the server for conversation: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(n){aA.warn("Retrieved malformed dateCreated from the server for conversation: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(n){aA.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){aA.warn("Retrieved malformed lastMessage.timestamp from the server for conversation: "+t),delete e.lastMessage.timestamp}}}]),Conversation}(Sl);ja(Conversation,"participantJoined","participantJoined"),ja(Conversation,"participantLeft","participantLeft"),ja(Conversation,"participantUpdated","participantUpdated"),ja(Conversation,"messageAdded","messageAdded"),ja(Conversation,"messageRemoved","messageRemoved"),ja(Conversation,"messageUpdated","messageUpdated"),ja(Conversation,"typingEnded","typingEnded"),ja(Conversation,"typingStarted","typingStarted"),ja(Conversation,"updated","updated"),ja(Conversation,"removed","removed"),wl([$y(qy,["undefined","string","number","boolean","object",By(null)]),xl("design:type",Function),xl("design:paramtypes",[String,Object]),xl("design:returntype",Promise)],Conversation.prototype,"add",null),wl([$y(qy,qy,[Gy,"undefined"]),xl("design:type",Function),xl("design:paramtypes",[String,String,Object]),xl("design:returntype",Promise)],Conversation.prototype,"addNonChatParticipant",null),wl([$y(Wy),xl("design:type",Function),xl("design:paramtypes",[Number]),xl("design:returntype",Promise)],Conversation.prototype,"advanceLastReadMessageIndex",null),wl([$y(["undefined",Wy],["undefined",Wy],["undefined",By("backwards","forward")]),xl("design:type",Function),xl("design:paramtypes",[Number,Number,String]),xl("design:returntype",Promise)],Conversation.prototype,"getMessages",null),wl([$y(qy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"getParticipantBySid",null),wl([$y(qy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"getParticipantByIdentity",null),wl([$y([qy,Participant]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Conversation.prototype,"removeParticipant",null),wl([$y(["string",By(null),Fy((function(e){return[e instanceof FormData,"an instance of FormData"]})),zy("media options",{contentType:qy,media:Fy((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"]}))})],["undefined","string","number","boolean","object",By(null)],["undefined",By(null),zy("email attributes",{subject:[qy,"undefined"]})]),xl("design:type",Function),xl("design:paramtypes",[Object,Object,Object]),xl("design:returntype",Promise)],Conversation.prototype,"sendMessage",null),wl([$y(By("default","muted")),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"setUserNotificationLevel",null),wl([$y(["string","number","boolean","object",By(null)]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Conversation.prototype,"updateAttributes",null),wl([$y(["string",By(null)]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"updateFriendlyName",null),wl([$y([By(null),Wy]),xl("design:type",Function),xl("design:paramtypes",[Number]),xl("design:returntype",Promise)],Conversation.prototype,"updateLastReadMessageIndex",null),wl([$y(["string",By(null)]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"updateUniqueName",null);var uA=function(){function e(){var t=this;Ma(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return Ta(e,[{key:"promise",get:function(){return this._promise}},{key:"update",value:function(e){this._resolve(e)}},{key:"set",value:function(e){this.current=e,this._resolve(e)}},{key:"fail",value:function(e){this._reject(e)}}]),e}();function cA(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return lA(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return lA(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function lA(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function fA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function dA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?fA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):fA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function pA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var hA=vd.scope("Conversations"),vA=function(e){Oa(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=pA(p);function p(e,t){var n;return Ma(this,p),ja(Ra(n=d.call(this)),"conversations",new Map),ja(Ra(n),"myConversationsRead",new uA),ja(Ra(n),"tombstones",new Set),ja(Ra(n),"myConversationsFetched",!1),n.configuration=e,n.services=t,n}return Ta(p,[{key:"addConversation",value:(f=Sa(bl.mark((function e(t){var n,r,i,a,s,o,u,c,l,f;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=void 0!==(null==t?void 0:t.attributes)?t.attributes:{},e.next=3,this.services.commandExecutor.mutateResource("post",this.configuration.links.conversations,{friendly_name:t.friendlyName,unique_name:t.uniqueName,attributes:void 0!==a?JSON.stringify(a):void 0});case 3:if(s=e.sent,o=null!==(n=s.sid)&&void 0!==n?n:null,u=null!==(r=null===(i=s.sync_objects)||void 0===i?void 0:i.conversation)&&void 0!==r?r:null,c=dA({self:s.url},s.links),!(l=this.conversations.get(o))){e.next=12;break}return e.next=11,l._subscribe();case 11:return e.abrupt("return",l);case 12:return f=new Conversation({channel:u,entityName:null,uniqueName:null,attributes:null,createdBy:null,friendlyName:null,lastConsumedMessageIndex:null,dateCreated:null,dateUpdated:null},o,c,this.configuration,this.services),this.conversations.set(f.sid,f),this._registerForEvents(f),e.next=17,f._subscribe();case 17:return this.emit("conversationAdded",f),e.abrupt("return",f);case 19:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"fetchConversations",value:(l=Sa(bl.mark((function e(){var t,n,r,i,a,s,o,u=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._getMap();case 3:return(t=e.sent).on("itemAdded",(function(e){hA.debug("itemAdded: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),t.on("itemRemoved",(function(e){hA.debug("itemRemoved: ".concat(e.key));var t=e.key;u.myConversationsFetched||u.tombstones.add(t);var n=u.conversations.get(t);n&&("joined"===n.status&&(n._setStatus("notParticipating","sync"),u.emit("conversationLeft",n)),u.conversations.delete(t),u.emit("conversationRemoved",n),n.emit("removed",n))})),t.on("itemUpdated",(function(e){hA.debug("itemUpdated: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),e.next=9,this._fetchMyConversations();case 9:n=e.sent,r=[],i=cA(n);try{for(i.s();!(a=i.n()).done;)s=a.value,r.push(this._upsertConversation("rest",s.channel_sid,s))}catch(e){i.e(e)}finally{i.f()}return this.myConversationsRead.set(!0),e.next=16,Promise.all(r);case 16:return this.myConversationsFetched=!0,this.tombstones.clear(),hA.debug("The conversations list has been successfully fetched"),e.abrupt("return",this);case 22:throw e.prev=22,e.t0=e.catch(0),o="Failed to fetch the conversations list","disconnected"!==this.services.syncClient.connectionState&&hA.error(o,e.t0),hA.debug("ERROR: ".concat(o),e.t0),e.t0;case 28:case"end":return e.stop()}}),e,this,[[0,22]])}))),function(){return l.apply(this,arguments)})},{key:"getConversations",value:(c=Sa(bl.mark((function e(t){var n,r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return n=e.sent,e.next=5,n.getItems();case 5:return r=e.sent,e.abrupt("return",this._wrapPaginator(r,(function(e){return Promise.all(e.map((function(e){return i._upsertConversation("sync",e.key,e.data)})))})));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"getConversation",value:(u=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return n=e.sent,e.next=5,n.getItems({from:t});case 5:return r=e.sent,i=r.items.map((function(e){return a._upsertConversation("sync",e.key,e.data)})),e.abrupt("return",i.length>0?i[0]:null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(o=Sa(bl.mark((function e(t){var n,r,i,a,s;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new bP(this.configuration.links.myConversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a=i.conversation_sid,s={entityName:null,lastConsumedMessageIndex:i.last_read_message_index,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:i.sync_objects.conversation,notificationLevel:null==i?void 0:i.notification_level,sid:a},e.abrupt("return",this._upsertConversation("sync",a,s));case 8:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"peekConversation",value:(s=Sa(bl.mark((function e(t){var n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new bP(this.configuration.links.conversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:if(r=e.sent,"private"===(i=r.body).type){e.next=7;break}return e.abrupt("return",null);case 7:return a={entityName:null,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:"".concat(t,".channel"),sid:t},e.abrupt("return",this._upsertConversation("sync",t,a));case 9:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"_getMap",value:(a=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.syncClient.map({id:this.configuration.myConversations,mode:"open_existing"});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"_wrapPaginator",value:(i=Sa(bl.mark((function e(t,n){var r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n(t.items);case 2:return r=e.sent,e.abrupt("return",{items:r,hasNextPage:t.hasNextPage,hasPrevPage:t.hasPrevPage,nextPage:function(){return t.nextPage().then((function(e){return i._wrapPaginator(e,n)}))},prevPage:function(){return t.prevPage().then((function(e){return i._wrapPaginator(e,n)}))}});case 4:case"end":return e.stop()}}),e)}))),function(e,t){return i.apply(this,arguments)})},{key:"_updateConversation",value:(r=Sa(bl.mark((function e(t,n,r){var i,a,s,o=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=void 0!==n._statusSource()&&t!==n._statusSource(),a="rest"!==t||"sync"===n._statusSource(),!i||!a||"sync"===t){e.next=5;break}return hA.trace("upsertConversation: conversation is known from sync and came from chat, ignoring",{sid:n.sid,data:r.status,conversation:n.status}),e.abrupt("return");case 5:if("joined"!==r.status||"joined"===n.status){e.next=13;break}return n._setStatus("joined",t),s={},void 0!==r.notificationLevel&&(s.notificationLevel=r.notificationLevel),void 0!==r.lastConsumedMessageIndex&&(s.lastConsumedMessageIndex=r.lastConsumedMessageIndex),hP(s,{})||n._update(s),n._subscribe().then((function(){o.emit("conversationJoined",n)})),e.abrupt("return");case 13:if("notParticipating"!==r.status||"joined"!==n.status){e.next=20;break}return n._setStatus("notParticipating",t),n._update(r),e.next=18,n._subscribe();case 18:return this.emit("conversationLeft",n),e.abrupt("return");case 20:if("notParticipating"!==r.status){e.next=24;break}return e.next=23,n._subscribe();case 23:return e.abrupt("return");case 24:n._update(r);case 25:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"_upsertConversation",value:(n=Sa(bl.mark((function e(t,n,r){var i,a,s,o;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(hA.trace("upsertConversation called for ".concat(n),r),!(i=this.conversations.get(n))){e.next=9;break}return hA.trace("upsertConversation: the conversation ".concat(i.sid," is known;")+"its status is known from the source ".concat(i._statusSource()," ")+"and the update came from the source ".concat(t),i),e.next=6,this._updateConversation(t,i,r);case 6:return e.next=8,i._subscribe();case 8:return e.abrupt("return",i);case 9:if(!["chat","rest"].includes(t)||!this.tombstones.has(n)){e.next=12;break}return hA.trace("upsertChannel: the channel is deleted but reappeared again from chat, ignoring",n),e.abrupt("return");case 12:return hA.trace("upsertConversation: creating a local conversation object with sid "+n,r),a="".concat(this.configuration.links.conversations,"/").concat(n),s={self:a,messages:"".concat(a,"/Messages"),participants:"".concat(a,"/Participants")},o=new Conversation(r,n,s,this.configuration,this.services),this.conversations.set(n,o),e.next=19,o._subscribe();case 19:return this._registerForEvents(o),this.emit("conversationAdded",o),"joined"===r.status&&(o._setStatus("joined",t),this.emit("conversationJoined",o)),e.abrupt("return",o);case 23:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"_fetchMyConversations",value:(t=Sa(bl.mark((function e(){var t,n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=null;case 2:return r=new bP(this.configuration.links.myConversations),n&&r.arg("PageToken",n),e.next=6,this.services.network.get(r.build());case 6:i=e.sent,a=i.body.conversations.map((function(e){return{descriptor:e,channel_sid:e.conversation_sid,status:e.status,channel:e.sync_objects.conversation,messages:e.sync_objects.messages,roster:"".concat(e.conversation_sid,".roster"),lastConsumedMessageIndex:e.last_consumed_message_index,notificationLevel:e.notification_level}})),n=i.body.meta.next_token,t=[].concat(SC(t),SC(a));case 10:if(n){e.next=2;break}case 11:return e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_onConversationRemoved",value:function(e){var t=this.conversations.get(e);t&&(this.conversations.delete(e),this.emit("conversationRemoved",t))}},{key:"_registerForEvents",value:function(e){var t=this;e.on("removed",(function(){return t._onConversationRemoved(e.sid)})),e.on("updated",(function(e){return t.emit("conversationUpdated",e)})),e.on("participantJoined",this.emit.bind(this,"participantJoined")),e.on("participantLeft",this.emit.bind(this,"participantLeft")),e.on("participantUpdated",(function(e){return t.emit("participantUpdated",e)})),e.on("messageAdded",this.emit.bind(this,"messageAdded")),e.on("messageUpdated",(function(e){return t.emit("messageUpdated",e)})),e.on("messageRemoved",this.emit.bind(this,"messageRemoved")),e.on("typingStarted",this.emit.bind(this,"typingStarted")),e.on("typingEnded",this.emit.bind(this,"typingEnded"))}}]),p}(Sl),yA=In,mA=Hr.find,gA=dp,bA="find",kA=!0;function wA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}bA in[]&&Array(1).find((function(){kA=!1})),yA({target:"Array",proto:!0,forced:kA},{find:function(e){return mA(this,e,arguments.length>1?arguments[1]:void 0)}}),gA(bA);var xA=vd.scope("User"),User=function(e){Oa(User,e);var t,n,r,i,a,s=wA(User);function User(e,t,n,r,i){var a;return Ma(this,User),ja(Ra(a=s.call(this)),"updated","updated"),ja(Ra(a),"userSubscribed","userSubscribed"),ja(Ra(a),"userUnsubscribed","userUnsubscribed"),a.links=n,a.configuration=r,a.services=i,a.subscribed="initializing",a.setMaxListeners(0),a.state={identity:e,entityName:t,friendlyName:null,attributes:{},online:null,notifiable:null},a}return Ta(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:function(e,t){var n=[];switch(xA.debug("User for",this.state.identity,"updated:",e,t),e){case"friendlyName":this.state.friendlyName!==t.value&&(n.push("friendlyName"),this.state.friendlyName=t.value);break;case"attributes":var r=gP(t.value,"Retrieved malformed attributes from the server for user: ".concat(this.state.identity),xA);hP(this.state.attributes,r)||(this.state.attributes=r,n.push("attributes"));break;case"reachability":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"));break;default:return}n.length>0&&this.emit("updated",{user:this,updateReasons:n})}},{key:"_updateReachabilityInfo",value:(a=Sa(bl.mark((function e(t,n){var r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.configuration.reachabilityEnabled){e.next=2;break}return e.abrupt("return",Promise.resolve());case 2:return e.abrupt("return",t.get("reachability").then(n).catch((function(e){xA.warn("Failed to get reachability info for ",r.state.identity,e)})));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"_fetch",value:(i=Sa(bl.mark((function e(){var t=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.state.entityName){e.next=2;break}return e.abrupt("return",this);case 2:return this.promiseToFetch=this.services.syncClient.map({id:this.state.entityName,mode:"open_existing",includeItems:!0}).then((function(e){return t.entity=e,e.on("itemUpdated",(function(e){return xA.debug(t.state.entityName+" ("+t.state.identity+") itemUpdated: "+e.item.key),t._update(e.item.key,e.item.data)})),Promise.all([e.get("friendlyName").then((function(e){return t._update(e.key,e.data)})),e.get("attributes").then((function(e){return t._update(e.key,e.data)})),t._updateReachabilityInfo(e,(function(e){return t._update(e.key,e.data)}))])})).then((function(){return xA.debug("Fetched for",t.identity),t.subscribed="subscribed",t.emit("userSubscribed",t),t})).catch((function(e){throw t.promiseToFetch=null,e})),e.abrupt("return",this.promiseToFetch);case 4:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"_ensureFetched",value:function(){return this.promiseToFetch||this._fetch()}},{key:"updateAttributes",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("unsubscribed"!=this.subscribed){e.next=2;break}throw new Error("Can't modify unsubscribed object");case 2:return e.next=4,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(t)});case 4:return e.abrupt("return",this);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"updateFriendlyName",value:(n=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("unsubscribed"!=this.subscribed){e.next=2;break}throw new Error("Can't modify unsubscribed object");case 2:return e.next=4,this.services.commandExecutor.mutateResource("post",this.links.self,{friendly_name:t});case 4:return e.abrupt("return",this);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"unsubscribe",value:(t=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.promiseToFetch){e.next=7;break}return e.next=3,this.promiseToFetch;case 3:this.entity.close(),this.promiseToFetch=null,this.subscribed="unsubscribed",this.emit("userUnsubscribed",this);case 7:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),User}(Sl);function _A(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}wl([$y(["string","number","boolean","object",By(null)]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],User.prototype,"updateAttributes",null),wl([$y(["string"]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],User.prototype,"updateFriendlyName",null);var SA=function(e){Oa(a,e);var t,n,r,i=_A(a);function a(e,t){var n;Ma(this,a),n=i.call(this);var r={self:"".concat(e.links.users,"/").concat(e.userIdentity)};return n.configuration=e,n.services=t,n.fifoStack=[],n.myself=new User(n.configuration.userIdentity,n.configuration.userInfo,r,n.configuration,n.services),n.myself.on("updated",(function(e){return n.emit("userUpdated",e)})),n.myself.on("userSubscribed",(function(){return n.emit("userSubscribed",n.myself)})),n.myself.on("userUnsubscribed",(function(){n.emit("userUnsubscribed",n.myself),n.myself._ensureFetched()})),n.subscribedUsers=new Map,n}return Ta(a,[{key:"handleUnsubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)&&this.subscribedUsers.delete(e.identity);var t=-1;this.fifoStack.find((function(n,r){return n==e.identity&&(t=r,!0)}))&&this.fifoStack.splice(t,1),this.emit("userUnsubscribed",e)}},{key:"handleSubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)||(this.fifoStack.length>=this.configuration.userInfosToSubscribe&&this.subscribedUsers.get(this.fifoStack.shift()).unsubscribe(),this.fifoStack.push(e.identity),this.subscribedUsers.set(e.identity,e),this.emit("userSubscribed",e))}},{key:"getUser",value:(r=Sa(bl.mark((function e(t){var n,r,i,a=this,s=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=s.length>1&&void 0!==s[1]?s[1]:null,e.next=3,this.myself._ensureFetched();case 3:if(t!=this.myself.identity){e.next=5;break}return e.abrupt("return",this.myself);case 5:if(r=this.subscribedUsers.get(t)){e.next=18;break}if(n){e.next=11;break}return e.next=10,this.getSyncUniqueName(t);case 10:n=e.sent;case 11:return i={self:"".concat(this.configuration.links.users,"/").concat(t)},(r=new User(t,n,i,this.configuration,this.services)).on("updated",(function(e){return a.emit("userUpdated",e)})),r.on("userSubscribed",(function(){return a.handleSubscribeUser(r)})),r.on("userUnsubscribed",(function(){return a.handleUnsubscribeUser(r)})),e.next=18,r._ensureFetched();case 18:return e.abrupt("return",r);case 19:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.myself._ensureFetched();case 2:return t=[this.myself],this.subscribedUsers.forEach((function(e){return t.push(e)})),e.abrupt("return",t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getSyncUniqueName",value:(t=Sa(bl.mark((function e(t){var n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new bP(this.configuration.links.users).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,e.abrupt("return",r.body.sync_objects.user_info_map);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),a}(Sl),EA=vd.scope("TypingIndicator"),TA=function(){function e(t,n,r){Ma(this,e),this.configuration=n,this.services=r,this.getConversation=t,this.serviceTypingTimeout=null,this.sentUpdates=new Map}var t;return Ta(e,[{key:"typingTimeout",get:function(){return this.configuration.typingIndicatorTimeoutOverride||this.serviceTypingTimeout||this.configuration.typingIndicatorTimeoutDefault}},{key:"initialize",value:function(){var e=this;this.services.notificationClient.on("message",function(){var t=Sa(bl.mark((function t(n,r){return bl.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==hv.TYPING_INDICATOR){t.next=3;break}return t.next=3,e._handleRemoteTyping(r);case 3:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}())}},{key:"_handleRemoteTyping",value:(t=Sa(bl.mark((function e(t){var n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:EA.trace("Got new typing indicator ",t),this.getConversation(t.channel_sid).then((function(e){e&&e.participants.forEach((function(e){if(e.identity===t.identity){var r=n.configuration.typingIndicatorTimeoutOverride+1e3||1e3*t.typing_timeout;e._startTyping(r)}}))})).catch((function(e){throw EA.error(e),e}));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"send",value:function(e){var t=this.sentUpdates.get(e);return t&&t>Date.now()-this.typingTimeout?Promise.resolve():(this.sentUpdates.set(e,Date.now()),this._send(e))}},{key:"_send",value:function(e){var t=this;EA.trace("Sending typing indicator");var n=this.configuration.links.typing,r="ChannelSid=".concat(e);return this.services.twilsockClient.post(n,{"Content-Type":"application/x-www-form-urlencoded"},r,this.configuration.productId).then((function(e){e.body.hasOwnProperty("typing_timeout")&&(t.serviceTypingTimeout=1e3*e.body.typing_timeout)})).catch((function(e){throw EA.error("Failed to send typing indicator:",e),e}))}}]),e}(),PushNotification=function PushNotification(e){Ma(this,PushNotification),this.title=e.title||null,this.body=e.body||null,this.sound=e.sound||null,this.badge=e.badge||null,this.action=e.action||null,this.type=e.type||null,this.data=e.data||{}};function RA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function IA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?RA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):RA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var OA,CA,PA,AA=function(e){return e.replace(/(^\/+|\/+$)/g,"")},jA=function(){function e(t,n,r){Ma(this,e),this._serviceUrl=t,this._services=n,this._productId=r}var t,n,r;return Ta(e,[{key:"_preProcessUrl",value:function(e){var t=AA(e);return/^https?:\/\//.test(e)?t:"".concat(AA(this._serviceUrl),"/").concat(t)}},{key:"_makeRequest",value:(r=Sa(bl.mark((function e(t,n,r,i){var a,s,o,u;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=this._preProcessUrl(n),s=IA({"Content-Type":"application/json; charset=utf-8"},i||{}),e.t0=t,e.next="get"===e.t0?5:"post"===e.t0?11:"delete"===e.t0?15:19;break;case 5:return u=a,r&&(u+="?"+Object.entries(r).map((function(e){return e.map(encodeURIComponent).join("=")})).join("&")),e.next=9,this._services.transport.get(u,s,this._productId);case 9:return o=e.sent,e.abrupt("break",19);case 11:return e.next=13,this._services.transport.post(a,s,JSON.stringify(r),this._productId);case 13:return o=e.sent,e.abrupt("break",19);case 15:return e.next=17,this._services.transport.delete(a,s,null,this._productId);case 17:return o=e.sent,e.abrupt("break",19);case 19:if(!(o.status.code<200||o.status.code>=300)){e.next=21;break}throw new Error("Request responded with a non-success code ".concat(o.status.code));case 21:return e.abrupt("return",o);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"fetchResource",value:(n=Sa(bl.mark((function e(t,n){var r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=1,e.next=4,new cv({min:50,max:1600,maxAttemptsCount:6}).run((function(){return i._makeRequest("get",t,n)}));case 4:r=e.sent,e.next=10;break;case 7:throw e.prev=7,e.t0=e.catch(1),new Error('Fetch resource from "'.concat(t,'" failed.'));case 10:return e.abrupt("return",r.body);case 11:case"end":return e.stop()}}),e,null,[[1,7]])}))),function(e,t){return n.apply(this,arguments)})},{key:"mutateResource",value:(t=Sa(bl.mark((function e(t,n,r){var i;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._makeRequest(t,n,r,{"X-Twilio-Mutation-Id":hm.v4()});case 2:if(202!==(i=e.sent).status.code){e.next=7;break}return e.next=6,this.fetchResource(i.body.resource_url);case 6:return e.abrupt("return",e.sent);case 7:return e.abrupt("return",i.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,n,r){return t.apply(this,arguments)})}]),e}();function MA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function LA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?MA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):MA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function NA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var UA=vd.scope("Client"),DA="2.0.0-rc.1",FA=function e(){Ma(this,e)};e.Client=(CA=OA=function(e){Oa(Client,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v=NA(Client);function Client(e){var t,n,r,i,a,s,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Ma(this,Client),ja(Ra(s=v.call(this)),"connectionState","unknown"),ja(Ra(s),"conversationsPromise",null),ja(Ra(s),"_ensureReady",null),ja(Ra(s),"_resolveEnsureReady",null),ja(Ra(s),"_rejectEnsureReady",null),ja(Ra(s),"version",DA),ja(Ra(s),"parsePushNotification",PA.parsePushNotification),s.fpaToken=e,s.options=o,!s.options.disableDeepClone){var u=LA(LA({},s.options),{},{transport:void 0,twilsockClient:void 0});(u=vP(u)).transport=s.options.transport,u.twilsockClient=s.options.twilsockClient,s.options=u}s.options.logLevel=null!==(t=s.options.logLevel)&&void 0!==t?t:"silent",UA.setLevel(s.options.logLevel);var c=s.options.productId="ip_messaging";if(s.options.clientMetadata=s.options.clientMetadata||{},s.options.clientMetadata.hasOwnProperty("type")||(s.options.clientMetadata.type="conversations"),s.options.clientMetadata.hasOwnProperty("sdk")||(s.options.clientMetadata.sdk="JS",s.options.clientMetadata.sdkv=DA),s.options.Sync=s.options.Sync||{},void 0===s.options.Sync.enableSessionStorage&&(s.options.Sync.enableSessionStorage=!0),s.options.region&&(s.options.Sync.region=s.options.region),!e)throw new Error("A valid Twilio token should be provided");s.services=new FA;var l=!s.options.twilsockClient;if(!s.options.initRegistrations){var f=new vv.InitRegistration(c);PA.populateInitRegistrations(f),s.options.initRegistrations=[f]}s.services.twilsockClient=s.options.twilsockClient=null!==(n=s.options.twilsockClient)&&void 0!==n?n:new vv.TwilsockClient(e,c,s.options),s.services.twilsockClient.on("tokenAboutToExpire",(function(e){return s.emit("tokenAboutToExpire",e)})),s.services.twilsockClient.on("tokenExpired",(function(){return s.emit("tokenExpired")})),s.services.twilsockClient.on("connectionError",(function(e){return s.emit("connectionError",e)})),s.services.twilsockClient.on("stateChanged",(function(e){UA.debug("Handling stateChanged for ConversationsClient: new state ".concat(e)),e!==s.connectionState&&(s.connectionState=e,s.emit("connectionStateChanged",s.connectionState))})),s.services.transport=s.options.transport=null!==(r=s.options.transport)&&void 0!==r?r:s.options.twilsockClient,s.services.notificationClient=s.options.notificationsClient=null!==(i=s.options.notificationsClient)&&void 0!==i?i:new TS.Notifications(e,s.options),s.services.syncClient=s.options.syncClient=null!==(a=s.options.syncClient)&&void 0!==a?a:new uR(e,s.options);var d=o.Chat||o.IPMessaging||o||{},p=d.region||o.region,h=d.apiUri||d.typingUri||"https://aim.".concat(p||"us1",".twilio.com");s.services.commandExecutor=new jA(h,{transport:s.options.transport},c);var y=function(e){s._rejectEnsureReady(e),s.emit("stateChanged","failed")};return s.services.twilsockClient.once("connectionError",y),s.services.twilsockClient.once("disconnected",y),s.services.twilsockClient.once("connected",Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return UA.debug("ConversationsClient started INITIALIZING"),s.services.twilsockClient.off("connectionError",y),s.services.twilsockClient.off("disconnected",y),e.prev=3,t="conversations.client.startup",s.services.twilsockClient.addPartialTelemetryEvent(new vv.TelemetryEventDescription(t,"Conversations client startup",new Date),t,vv.TelemetryPoint.Start),e.next=8,s._initialize();case 8:s.services.twilsockClient.addPartialTelemetryEvent(new vv.TelemetryEventDescription("","",new Date),t,vv.TelemetryPoint.End),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(3),s._rejectEnsureReady(e.t0),s.emit("stateChanged","failed");case 15:case"end":return e.stop()}}),e,null,[[3,11]])})))),s._ensureReady=new Promise((function(e,t){s._resolveEnsureReady=e,s._rejectEnsureReady=t})).catch((function(e){})),l&&s.services.twilsockClient.connect(),s}return Ta(Client,[{key:"user",get:function(){return this.services.users.myself}},{key:"reachabilityEnabled",get:function(){return this.configuration.reachabilityEnabled}},{key:"token",get:function(){return this.fpaToken}},{key:"_subscribeToPushNotifications",value:function(e){var t=this;[hv.NEW_MESSAGE,hv.ADDED_TO_CONVERSATION,hv.REMOVED_FROM_CONVERSATION,hv.TYPING_INDICATOR,hv.CONSUMPTION_UPDATE].forEach((function(n){t.services.notificationClient.subscribe(e,n)}))}},{key:"_unsubscribeFromPushNotifications",value:function(e){var t=this;[hv.NEW_MESSAGE,hv.ADDED_TO_CONVERSATION,hv.REMOVED_FROM_CONVERSATION,hv.TYPING_INDICATOR,hv.CONSUMPTION_UPDATE].forEach((function(n){t.services.notificationClient.unsubscribe(e,n)}))}},{key:"_initialize",value:(h=Sa(bl.mark((function e(){var t,n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.fetchResource("Client/v2/Configuration");case 2:return t=e.sent,this.configuration=new Td(this.options,t,UA),this.services.typingIndicator=new TA(this.getConversationBySid.bind(this),this.configuration,this.services),this.services.network=new pv(this.configuration,this.services),this.services.users=new SA(this.configuration,this.services),this.services.users.on("userSubscribed",this.emit.bind(this,"userSubscribed")),this.services.users.on("userUpdated",(function(e){return n.emit("userUpdated",e)})),this.services.users.on("userUnsubscribed",this.emit.bind(this,"userUnsubscribed")),this.conversations=new vA(this.configuration,this.services),this.conversations.on("conversationAdded",this.emit.bind(this,"conversationAdded")),this.conversations.on("conversationRemoved",this.emit.bind(this,"conversationRemoved")),this.conversations.on("conversationJoined",this.emit.bind(this,"conversationJoined")),this.conversations.on("conversationLeft",this.emit.bind(this,"conversationLeft")),this.conversations.on("conversationUpdated",(function(e){return n.emit("conversationUpdated",e)})),this.conversations.on("participantJoined",this.emit.bind(this,"participantJoined")),this.conversations.on("participantLeft",this.emit.bind(this,"participantLeft")),this.conversations.on("participantUpdated",(function(e){return n.emit("participantUpdated",e)})),this.conversations.on("messageAdded",this.emit.bind(this,"messageAdded")),this.conversations.on("messageUpdated",(function(e){return n.emit("messageUpdated",e)})),this.conversations.on("messageRemoved",this.emit.bind(this,"messageRemoved")),this.conversations.on("typingStarted",this.emit.bind(this,"typingStarted")),this.conversations.on("typingEnded",this.emit.bind(this,"typingEnded")),this.conversationsPromise=this.conversations.fetchConversations().then((function(){return n.conversations})).catch((function(e){throw e})),e.next=27,this.services.users.myself._ensureFetched();case 27:PA.supportedPushChannels.forEach((function(e){return n._subscribeToPushNotifications(e)})),this.services.typingIndicator.initialize(),this.services.mcsClient=new pR.McsClient(this.fpaToken,this.configuration.links.mediaService,this.configuration.links.mediaSetService,LA(LA({},this.options),{},{transport:null})),this._resolveEnsureReady(),this.emit("stateChanged","initialized");case 32:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"shutdown",value:(p=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.services.twilsockClient.disconnect();case 4:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"updateToken",value:(d=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:if(UA.info("updateToken"),this.fpaToken!==t){e.next=5;break}return e.abrupt("return",this);case 5:return e.next=7,this.services.twilsockClient.updateToken(t);case 7:return e.next=9,this.services.notificationClient.updateToken(t);case 9:return e.next=11,this.services.mcsClient.updateToken(t);case 11:return this.fpaToken=t,e.abrupt("return",this);case 13:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"getConversationBySid",value:(f=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.conversations.myConversationsRead.promise;case 4:return e.next=6,this.conversations.getConversation(t);case 6:if(n=e.sent){e.next=11;break}return e.next=10,this.conversations.peekConversation(t);case 10:n=e.sent;case 11:if(n){e.next=13;break}throw new Error("Conversation with SID ".concat(t," is not found."));case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(l=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.conversations.myConversationsRead.promise;case 4:return e.next=6,this.conversations.getConversationByUniqueName(t);case 6:if(n=e.sent){e.next=9;break}throw new Error("Conversation with unique name ".concat(t," is not found."));case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"getSubscribedConversations",value:(c=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.conversationsPromise.then((function(e){return e.getConversations(t)})));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"createConversation",value:(u=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return t=t||{},e.abrupt("return",this.conversationsPromise.then((function(e){return e.addConversation(t)})));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"setPushRegistrationId",value:(o=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this.services.notificationClient.setPushRegistrationId(t,n),e.next=5,this.services.notificationClient.commitChanges();case 5:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"unsetPushRegistrationId",value:(s=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this._unsubscribeFromPushNotifications(t),e.next=5,this.services.notificationClient.commitChanges();case 5:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"removePushRegistrations",value:(a=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.notificationClient.removeRegistrations(t,n);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"handlePushNotification",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:UA.debug("handlePushNotification, notificationPayload=",t),this.emit("pushNotification",PA.parsePushNotification(t));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"getUser",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.services.users.getUser(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.services.users.getSubscribedUsers());case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})}],[{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([hv.TYPING_INDICATOR]),uR.populateInitRegistrations(e)}},{key:"create",value:(t=Sa(bl.mark((function e(t,n){var r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==n||!n.twilsockClient){e.next=2;break}throw new Error("Obsolete usage of ConversationsClient.create() factory method: if you pass twilsock from the outside then you must use ConversationsClient constructor and be prepared to work with uninitialized client.");case 2:return r=new PA(t,n),e.next=5,r._ensureReady;case 5:return e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"parsePushNotificationChatData",value:function(e){var t={};for(var n in PA.supportedPushDataFields)void 0!==e[n]&&null!==e[n]&&("message_index"===n?null!==yP(e[n])&&(t[PA.supportedPushDataFields[n]]=Number(e[n])):t[PA.supportedPushDataFields[n]]=e[n]);return t}},{key:"parsePushNotification",value:function(e){if(UA.debug("parsePushNotification, notificationPayload=",e),void 0!==e.aps){if(!e.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var t=PA.parsePushNotificationChatData(e),n=e.aps,r=null,i=null;return"string"==typeof n.alert?r=n.alert||null:(r=n.alert.body||null,i=n.alert.title||null),new PushNotification({title:i,body:r,sound:n.sound||null,badge:n.badge||null,action:n.category||null,type:e.twi_message_type,data:t})}if(void 0!==e.data){var a=e.data;if(!a.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var s=PA.parsePushNotificationChatData(e.data);return new PushNotification({title:a.twi_title||null,body:a.twi_body||null,sound:a.twi_sound||null,badge:null,action:a.twi_action||null,type:a.twi_message_type,data:s})}throw new Error("Provided push notification payload is not Programmable Chat notification")}}]),Client}(Sl),ja(OA,"version",DA),ja(OA,"supportedPushChannels",["fcm","apn"]),ja(OA,"supportedPushDataFields",{conversation_sid:"conversationSid",message_sid:"messageSid",message_index:"messageIndex"}),ja(OA,"conversationAdded","conversationAdded"),ja(OA,"conversationJoined","conversationJoined"),ja(OA,"conversationLeft","conversationLeft"),ja(OA,"conversationRemoved","conversationRemoved"),ja(OA,"conversationUpdated","conversationUpdated"),ja(OA,"conversationStateChanged","connectionStateChanged"),ja(OA,"participantJoined","participantJoined"),ja(OA,"participantLeft","participantLeft"),ja(OA,"participantUpdated","participantUpdated"),ja(OA,"messageAdded","messageAdded"),ja(OA,"messageRemoved","messageRemoved"),ja(OA,"messageUpdated","messageUpdated"),ja(OA,"tokenAboutToExpire","tokenAboutToExpire"),ja(OA,"tokenExpired","tokenExpired"),ja(OA,"typingEnded","typingEnded"),ja(OA,"typingStarted","typingStarted"),ja(OA,"pushNotification","pushNotification"),ja(OA,"userSubscribed","userSubscribed"),ja(OA,"userUnsubscribed","userUnsubscribed"),ja(OA,"userUpdated","userUpdated"),ja(OA,"connectionError","connectionError"),PA=CA),wl([$y(qy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"updateToken",null),wl([$y(qy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getConversationBySid",null),wl([$y(qy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getConversationByUniqueName",null),wl([$y(["undefined",zy("conversation options",{friendlyName:["string","undefined"],isPrivate:["boolean","undefined"],uniqueName:["string","undefined"]})]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],e.Client.prototype,"createConversation",null),wl([$y(By("fcm","apn"),"string"),xl("design:type",Function),xl("design:paramtypes",[String,String]),xl("design:returntype",Promise)],e.Client.prototype,"setPushRegistrationId",null),wl([$y(By("fcm","apn")),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"unsetPushRegistrationId",null),wl([$y(By("fcm","apn"),qy),xl("design:type",Function),xl("design:paramtypes",[String,String]),xl("design:returntype",Promise)],e.Client.prototype,"removePushRegistrations",null),wl([$y(Gy),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],e.Client.prototype,"handlePushNotification",null),wl([$y(qy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getUser",null),wl([$y("string",["undefined",Gy]),xl("design:type",Function),xl("design:paramtypes",[String,Object]),xl("design:returntype",Promise)],e.Client,"create",null),wl([Vy(Gy),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",PushNotification)],e.Client,"parsePushNotification",null),e.Client=PA=wl([Jy(qy,[Gy,"undefined",By(null)]),xl("design:paramtypes",[String,Object])],e.Client);var Client=e.Client;return e.AggregatedDeliveryReceipt=AggregatedDeliveryReceipt,e.Conversation=Conversation,e.DetailedDeliveryReceipt=DetailedDeliveryReceipt,e.Media=Media,e.Message=Message,e.Participant=Participant,e.PushNotification=PushNotification,e.RestPaginator=VP,e.User=User,e.default=Client,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
156
|
+
function h(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function v(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function y(e,t){return["".concat((new Date).toISOString()," MCS Client ").concat(e,":")].concat(Array.from(t))}var m=function(){function e(t){Ma(this,e),f.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return Ta(e,[{key:"setLevel",value:function(e){p.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.trace.apply(null,y(this.prefix+"T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.debug.apply(null,y(this.prefix+"D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.info.apply(null,y(this.prefix+"I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.warn.apply(null,y(this.prefix+"W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.error.apply(null,y(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){p.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.trace.apply(null,y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.debug.apply(null,y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.info.apply(null,y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.warn.apply(null,y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.error.apply(null,y("E",t))}}]),e}(),g=function(e,t){return"".concat((n=e,n.startsWith("http")?"":function(e){return"https://mcs.".concat(null!=e?e:"us1",".twilio.com")}(t))).concat(e);var n},b=function(){function e(t,n,r,i){var a,s,o,u,c,l;Ma(this,e);var f=null!==(a=null!==(s=i.MCS)&&void 0!==s?s:i)&&void 0!==a?a:{};this.region=null!==(o=null!==(u=f.region)&&void 0!==u?u:i.region)&&void 0!==o?o:"us1",this.mediaUrl=g(n,this.region),this.mediaSetUrl=r?g(r):"".concat(this.mediaUrl,"Set"),this.token=t,this.retryWhenThrottledOverride=null===(c=f.retryWhenThrottledOverride)||void 0===c||c,this.backoffConfigOverride=null!==(l=f.backoffConfigOverride)&&void 0!==l?l:e.backoffConfigDefault}return Ta(e,[{key:"updateToken",value:function(e){this.token=e}}],[{key:"backoffConfigDefault",get:function(){return{min:1e3,max:4e3,maxAttemptsCount:3}}},{key:"retryWhenThrottledDefault",get:function(){return true}}]),e}(),Media=function(){function Media(e,t,n){Ma(this,Media),this.config=e,this.network=t,this._update(n)}return Ta(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"serviceSid",get:function(){return this.state.serviceSid}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"fileName",get:function(){return this.state.filename}},{key:"filename",get:function(){return this.state.filename}},{key:"category",get:function(){return this.state.category}},{key:"getContentUrl",value:function(){var e=this;return l.default(d.default.mark((function t(){var n;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.network.get("".concat(e.config.mediaUrl,"/").concat(e.sid));case 2:return n=t.sent,e._update(n.body),t.abrupt("return",Promise.resolve(e.state.contentDirectUrl));case 5:case"end":return t.stop()}}),t)})))()}},{key:"getCachedContentUrl",value:function(){var e=this;return l.default(d.default.mark((function t(){return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e.state.contentDirectUrl){t.next=2;break}return t.abrupt("return",Promise.resolve(e.state.contentDirectUrl));case 2:return t.next=4,e.getContentUrl();case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}}),t)})))()}},{key:"_update",value:function(e){var t,n,r,i;this.state={sid:e.sid,serviceSid:e.service_sid,channelSid:e.channel_sid,messageSid:e.message_sid,dateCreated:e.date_created?new Date(e.date_created):null,dateUploadUpdated:e.date_upload_updated?new Date(e.date_upload_updated):null,dateUpdated:e.date_updated?new Date(e.date_updated):null,size:e.size,contentType:e.content_type,author:e.author,url:e.url,contentUrl:e.links.content,contentDirectUrl:null!==(t=e.links.content_direct_temporary)&&void 0!==t?t:null,filename:null!==(n=e.filename)&&void 0!==n?n:null,category:null!==(r=e.category)&&void 0!==r?r:"media",isMultipartUpstream:null!==(i=e.is_multipart_upstream)&&void 0!==i&&i}}}]),Media}(),k=function(e){Oa(n,e);var t=OP(n);function n(e,r,i,a,s){var o;return Ma(this,n),(o=t.call(this,e)).code=r,o.body=i,o.status=a,o.headers=s,o}return n}(mI(Error)),w=t.XMLHttpRequest||{};function x(e){var t=e.getResponseHeader("Content-Type");if(!t||0!==t.indexOf("application/json")||0===e.responseText.length)return e.responseText;try{return JSON.parse(e.responseText)}catch(t){return e.responseText}}var _,S,E=function(){function e(){Ma(this,e)}return Ta(e,[{key:"get",value:function(t,n){return l.default(d.default.mark((function r(){return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",e.request("GET",t,n));case 1:case"end":return r.stop()}}),r)})))()}},{key:"post",value:function(t,n,r){return l.default(d.default.mark((function i(){return d.default.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.abrupt("return",e.request("POST",t,n,r));case 1:case"end":return i.stop()}}),i)})))()}}],[{key:"request",value:function(e,t,n,r){return l.default(d.default.mark((function i(){return d.default.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.abrupt("return",new Promise((function(i,a){var s=new w;for(var o in s.open(e,t,!0),s.onreadystatechange=function(){if(4===s.readyState){var e,t=(e=s.getAllResponseHeaders())?e.split("\r\n").map((function(e){return e.split(": ")})).filter((function(e){return 2===e.length&&e[1].length>0})).reduce((function(e,t){return e[t[0]]=t[1],e}),{}):{},n=x(s);if(200<=s.status&&s.status<300)i({status:s.status,headers:t,body:n});else{var r,o,u=null!==(r=s.statusText)&&void 0!==r?r:"NONE";o="string"==typeof n?n&&1===n.split("\n",2).length?n:"":JSON.stringify(n);var c="".concat(s.status,": [").concat(u,"] ").concat(o);a(new k(c,s.status,n,u,t))}}},n)s.setRequestHeader(o,n[o]),"Content-Type"===o&&"application/json"===n[o]&&(r=JSON.stringify(r));s.send(r)})));case 1:case"end":return i.stop()}}),i)})))()}}]),e}(),T=m.scope("Network"),R=function(){function e(t,n){Ma(this,e),this.config=t,this.transport=n}return Ta(e,[{key:"backoffConfig",value:function(){return Object.assign(b.backoffConfigDefault,this.config.backoffConfigOverride)}},{key:"retryWhenThrottled",value:function(){var e,t;return null!==(e=null!==(t=this.config.retryWhenThrottledOverride)&&void 0!==t?t:b.retryWhenThrottledDefault)&&void 0!==e&&e}},{key:"executeWithRetry",value:function(e,t){var n=this;return l.default(d.default.mark((function r(){return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",new Promise((function(r,i){var a=[502,503,504];t&&a.push(429);var o=new s.Retrier(n.backoffConfig());o.on("attempt",l.default(d.default.mark((function t(){var n;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,e();case 3:n=t.sent,o.succeeded(n),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(0),a.indexOf(t.t0.status)>-1||"Twilsock disconnected"===t.t0.message?o.failed(t.t0):(o.removeAllListeners(),o.cancel(),i(t.t0));case 10:case"end":return t.stop()}}),t,null,[[0,7]])})))),o.on("succeeded",(function(e){r(e)})),o.on("cancelled",(function(e){return i(e)})),o.on("failed",(function(e){return i(e)})),o.start()})));case 1:case"end":return r.stop()}}),r)})))()}},{key:"get",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r,i;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r={"X-Twilio-Token":t.config.token},T.trace("sending GET request to ",e," headers ",r),n.prev=2,n.next=5,t.executeWithRetry((function(){return t.transport.get(e,r)}),t.retryWhenThrottled());case 5:return i=n.sent,T.trace("response",i),n.abrupt("return",i);case 10:throw n.prev=10,n.t0=n.catch(2),T.debug("get() error ".concat(n.t0)),n.t0;case 14:case"end":return n.stop()}}),n,null,[[2,10]])})))()}},{key:"post",value:function(e,n,r,i,a){var s=this;return l.default(d.default.mark((function o(){var u,c,l;return d.default.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return u={"X-Twilio-Token":s.config.token},"undefined"!=typeof FormData&&r instanceof FormData||!i||Object.assign(u,{"Content-Type":i}),c=new URL(e),n&&c.searchParams.append("Category",n),a&&c.searchParams.append("Filename",a),T.trace("sending POST request to ".concat(e," with headers ").concat(u)),o.prev=6,o.next=9,s.transport.post(c.href,u,r);case 9:l=o.sent,o.next=18;break;case 12:if(o.prev=12,o.t0=o.catch(6),!(void 0===t.XMLHttpRequest&&r instanceof FormData)){o.next=16;break}throw new TypeError("Posting FormData supported only with browser engine's FormData");case 16:throw T.debug("post() error ".concat(o.t0)),o.t0;case 18:return T.trace("response",l),o.abrupt("return",l);case 20:case"end":return o.stop()}}),o,null,[[6,12]])})))()}}]),e}(),I=m.scope("");e.default=(S=_=function(){function Client(e,t,n){var r,i;Ma(this,Client);var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};this.options=a,this.options.logLevel=null!==(r=this.options.logLevel)&&void 0!==r?r:"silent",this.config=new b(e,t,n,this.options),I.setLevel(this.options.logLevel),this.options.transport=null!==(i=this.options.transport)&&void 0!==i?i:new E,this.transport=this.options.transport,this.network=new R(this.config,this.transport)}return Ta(Client,[{key:"updateToken",value:function(e){I.info("updateToken"),this.config.updateToken(e)}},{key:"get",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,t.network.get("".concat(t.config.mediaUrl,"/").concat(e));case 2:return r=n.sent,n.abrupt("return",new Media(t.config,t.network,r.body));case 4:case"end":return n.stop()}}),n)})))()}},{key:"post",value:function(e,t,n,r){var i=this;return l.default(d.default.mark((function a(){var s;return d.default.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,i.network.post(i.config.mediaUrl,null!=n?n:"media",t,e,r);case 2:return s=a.sent,a.abrupt("return",new Media(i.config,i.network,s.body));case 4:case"end":return a.stop()}}),a)})))()}},{key:"postFormData",value:function(e,t){var n=this;return l.default(d.default.mark((function r(){var i;return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,n.network.post(n.config.mediaUrl,null!=t?t:"media",e);case 2:return i=r.sent,r.abrupt("return",new Media(n.config,n.network,i.body));case 4:case"end":return r.stop()}}),r)})))()}},{key:"mediaSetGet",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r,i;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r={command:"get",list:e.map((function(e){return{media_sid:e}}))},n.next=3,t.network.post("".concat(t.config.mediaSetUrl),null,JSON.stringify(r),"application/json");case 3:return i=n.sent,n.abrupt("return",i.map((function(e){if(200!==e.code)throw new Error("Failed to obtain detailed information about Media items (failed SID ".concat(e.media_record.sid,")"));return new Media(t.config,t.network,e.media_record)})));case 5:case"end":return n.stop()}}),n)})))()}}]),Client}(),f.default(_,"version","0.5.1-rc.12"),S),h([o.validateTypes(o.nonEmptyString),v("design:type",Function),v("design:paramtypes",[String]),v("design:returntype",void 0)],e.default.prototype,"updateToken",null),h([o.validateTypesAsync(o.nonEmptyString),v("design:type",Function),v("design:paramtypes",[String]),v("design:returntype",Promise)],e.default.prototype,"get",null),e.default=h([o.validateConstructorTypes(o.nonEmptyString,o.nonEmptyString,[o.nonEmptyString,o.literal(null)],[o.pureObject,"undefined"]),v("design:paramtypes",[String,String,Object,Object])],e.default),e.Client=e.default,e.McsClient=e.default,e.McsMedia=Media,e.Media=Media,e.default=e.default}(bI);var PP=is,AP="ArrayBuffer",jP=gw.ArrayBuffer;function MP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}In({global:!0,forced:i.ArrayBuffer!==jP},{ArrayBuffer:jP}),PP(AP);var LP=rd.scope("Participant"),Participant=function(e){Oa(Participant,e);var t,n,r=MP(Participant);function Participant(e,t,n,i,a){var s;if(Ma(this,Participant),(s=r.call(this)).conversation=n,s.links=i,s.services=a,s.state={attributes:zh(e.attributes,"Retrieved malformed attributes from the server for participant: "+t,LP),dateCreated:e.dateCreated?Wh(e.dateCreated):null,dateUpdated:e.dateCreated?Wh(e.dateUpdated):null,sid:t,typingTimeout:null,isTyping:!1,identity:e.identity||null,roleSid:e.roleSid||null,lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,lastReadTimestamp:e.lastConsumptionTimestamp?Wh(e.lastConsumptionTimestamp):null,type:e.type||"chat",userInfo:e.userInfo},!e.identity&&!e.type)throw new Error("Received invalid Participant object from server: Missing identity or type of Participant.");return s}return Ta(Participant,[{key:"sid",get:function(){return this.state.sid}},{key:"attributes",get:function(){return this.state.attributes}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"identity",get:function(){return this.state.identity}},{key:"isTyping",get:function(){return this.state.isTyping}},{key:"lastReadMessageIndex",get:function(){return this.state.lastReadMessageIndex}},{key:"lastReadTimestamp",get:function(){return this.state.lastReadTimestamp}},{key:"roleSid",get:function(){return this.state.roleSid}},{key:"type",get:function(){return this.state.type}},{key:"_startTyping",value:function(e){var t=this;return clearTimeout(this.state.typingTimeout),this.state.isTyping=!0,this.emit("typingStarted",this),this.conversation.emit("typingStarted",this),this.state.typingTimeout=setTimeout((function(){return t._endTyping()}),e),this}},{key:"_endTyping",value:function(){this.state.typingTimeout&&(this.state.isTyping=!1,this.emit("typingEnded",this),this.conversation.emit("typingEnded",this),clearInterval(this.state.typingTimeout),this.state.typingTimeout=null)}},{key:"_update",value:function(e){var t=[],n=zh(e.attributes,"Retrieved malformed attributes from the server for participant: "+this.state.sid,LP);e.attributes&&!Fh(this.state.attributes,n)&&(this.state.attributes=n,t.push("attributes"));var r=Wh(e.dateUpdated);e.dateUpdated&&r.getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=r,t.push("dateUpdated"));var i=Wh(e.dateCreated);if(e.dateCreated&&i.getTime()!==(this.state.dateCreated&&this.state.dateCreated.getTime())&&(this.state.dateCreated=i,t.push("dateCreated")),e.roleSid&&this.state.roleSid!==e.roleSid&&(this.state.roleSid=e.roleSid,t.push("roleSid")),!Number.isInteger(e.lastConsumedMessageIndex)&&null!==e.lastConsumedMessageIndex||this.state.lastReadMessageIndex===e.lastConsumedMessageIndex||(this.state.lastReadMessageIndex=e.lastConsumedMessageIndex,t.push("lastReadMessageIndex")),e.lastConsumptionTimestamp){var a=new Date(e.lastConsumptionTimestamp);this.state.lastReadTimestamp&&this.state.lastReadTimestamp.getTime()===a.getTime()||(this.state.lastReadTimestamp=a,t.push("lastReadTimestamp"))}return t.length>0&&this.emit("updated",{participant:this,updateReasons:t}),this}},{key:"getUser",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("chat"==this.type){e.next=2;break}throw new Error("Getting User is not supported for this Participant type: "+this.type);case 2:return e.abrupt("return",this.services.users.getUser(this.state.identity,this.state.userInfo));case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"remove",value:function(){var e=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.conversation.removeParticipant(this));case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"updateAttributes",value:(t=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(t)});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Participant}(lm);function NP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}ja(Participant,"typingStarted","typingStarted"),ja(Participant,"typingEnded","typingEnded"),ja(Participant,"updated","updated"),wl([Fy(["string","number","boolean","object",Ay(null)]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Participant.prototype,"updateAttributes",null);var UP=rd.scope("Participants"),DP=function(e){Oa(s,e);var t,n,r,i,a=NP(s);function s(e,t,n,r,i){var o;return Ma(this,s),(o=a.call(this)).conversation=e,o.participants=t,o.links=n,o.configuration=r,o.services=i,o}return Ta(s,[{key:"unsubscribe",value:(i=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.rosterEntityPromise){e.next=6;break}return e.next=3,this.rosterEntityPromise;case 3:e.sent.close(),this.rosterEntityPromise=null;case 6:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"subscribe",value:function(e){var t=this;return this.rosterEntityPromise=this.rosterEntityPromise||this.services.syncClient.map({id:e,mode:"open_existing"}).then((function(e){e.on("itemAdded",(function(e){UP.debug(t.conversation.sid+" itemAdded: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data).then((function(e){t.emit("participantJoined",e)}))})),e.on("itemRemoved",(function(e){UP.debug(t.conversation.sid+" itemRemoved: "+e.key);var n=e.key;if(t.participants.has(n)){var r=t.participants.get(n);t.participants.delete(n),t.emit("participantLeft",r)}})),e.on("itemUpdated",(function(e){UP.debug(t.conversation.sid+" itemUpdated: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data)}));var n=[],r=t;return e.getItems().then((function e(t){return t.items.forEach((function(e){n.push(r.upsertParticipant(e.key,e.data))})),t.hasNextPage?t.nextPage().then(e):null})).then((function(){return Promise.all(n)})).then((function(){return e}))})).catch((function(e){throw t.rosterEntityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&UP.error("Failed to get roster object for conversation",t.conversation.sid,e),UP.debug("ERROR: Failed to get roster object for conversation",t.conversation.sid,e),e}))}},{key:"upsertParticipant",value:(r=Sa(bl.mark((function e(t,n){var r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.participants.get(t))){e.next=3;break}return e.abrupt("return",r._update(n));case 3:return i={self:"".concat(this.links.participants,"/").concat(t)},r=new Participant(n,t,this.conversation,i,this.services),this.participants.set(t,r),r.on("updated",(function(e){return a.emit("participantUpdated",e)})),e.abrupt("return",r);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"getParticipants",value:function(){var e=this;return this.rosterEntityPromise.then((function(){var t=[];return e.participants.forEach((function(e){return t.push(e)})),t}))}},{key:"getParticipantBySid",value:(n=Sa(bl.mark((function e(t){var n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise.then((function(){var e=n.participants.get(t);if(!e)throw new Error("Participant with SID "+t+" was not found");return e})));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(t=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.abrupt("return",this.rosterEntityPromise.then((function(){if(r.participants.forEach((function(e){e.identity===t&&(n=e)})),!n)throw new Error("Participant with identity "+t+" was not found");return n})));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"add",value:function(){var e=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:t,attributes:void 0!==n?JSON.stringify(n):void 0});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}()},{key:"addNonChatParticipant",value:function(e,t,n){return this.services.commandExecutor.mutateResource("post",this.links.participants,{attributes:void 0!==n?JSON.stringify(n):void 0,messaging_binding:{address:t,proxy_address:e}})}},{key:"remove",value:function(e){return this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(e))}}]),s}(lm),FP=In,BP=On,qP=Q,WP=Ut,zP=gr,GP=s,JP=eS,VP=ec,$P=nS,KP=rS,HP=L,YP=aS,QP=[],XP=QP.sort,ZP=GP((function(){QP.sort(void 0)})),eA=GP((function(){QP.sort(null)})),tA=VP("sort"),nA=!GP((function(){if(HP)return HP<70;if(!($P&&$P>3)){if(KP)return!0;if(YP)return YP<603;var e,t,n,r,i="";for(e=65;e<76;e++){switch(t=String.fromCharCode(e),e){case 66:case 69:case 70:case 72:n=3;break;case 68:case 71:n=4;break;default:n=2}for(r=0;r<47;r++)QP.push({k:t+r,v:n})}for(QP.sort((function(e,t){return t.v-e.v})),r=0;r<QP.length;r++)t=QP[r].k.charAt(0),i.charAt(i.length-1)!==t&&(i+=t);return"DGBEFHACIJK"!==i}}));FP({target:"Array",proto:!0,forced:ZP||!eA||!tA||!nA},{sort:function(e){void 0!==e&&BP(e);var t=qP(this);if(nA)return void 0===e?XP.call(t):XP.call(t,e);var n,r,i=[],a=WP(t.length);for(r=0;r<a;r++)r in t&&i.push(t[r]);for(n=(i=JP(i,function(e){return function(t,n){return void 0===n?-1:void 0===t?1:void 0!==e?+e(t,n)||0:zP(t)>zP(n)?1:-1}}(e))).length,r=0;r<n;)t[r]=i[r++];for(;r<a;)delete t[r++];return t}});var rA=wI,iA=k,aA=gr;In({target:"String",proto:!0,forced:!_I("includes")},{includes:function(e){return!!~aA(iA(this)).indexOf(aA(rA(e)),arguments.length>1?arguments[1]:void 0)}});var Media=function(){function Media(e,t){Ma(this,Media),ja(this,"mcsMedia",null),this.services=t,e instanceof bI.McsMedia&&(this.mcsMedia=e),this.state={sid:e.sid,category:e.category,filename:e.filename,contentType:e.contentType,size:e.size}}var e,t,n;return Ta(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"filename",get:function(){return this.state.filename}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"category",get:function(){return this.state.category}},{key:"getContentTemporaryUrl",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._fetchMcsMedia();case 2:return e.abrupt("return",this.mcsMedia.getContentUrl());case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getCachedTemporaryUrl",value:(t=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._fetchMcsMedia();case 2:return e.abrupt("return",this.mcsMedia.getCachedContentUrl());case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_fetchMcsMedia",value:(e=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.mcsMedia){e.next=8;break}if(!this.services.mcsClient){e.next=7;break}return e.next=4,this.services.mcsClient.get(this.state.sid);case 4:this.mcsMedia=e.sent,e.next=8;break;case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(){return e.apply(this,arguments)})}]),Media}(),AggregatedDeliveryReceipt=function(){function AggregatedDeliveryReceipt(e){Ma(this,AggregatedDeliveryReceipt),this.state=e}return Ta(AggregatedDeliveryReceipt,[{key:"total",get:function(){return this.state.total}},{key:"sent",get:function(){return this.state.sent}},{key:"delivered",get:function(){return this.state.delivered}},{key:"read",get:function(){return this.state.read}},{key:"undelivered",get:function(){return this.state.undelivered}},{key:"failed",get:function(){return this.state.failed}},{key:"_update",value:function(e){this.state=e}},{key:"_isEquals",value:function(e){var t=this.total===e.total,n=this.sent===e.sent,r=this.delivered===e.delivered,i=this.read===e.read,a=this.undelivered===e.undelivered,s=this.failed===e.failed;return t&&n&&r&&i&&a&&s}}]),AggregatedDeliveryReceipt}(),sA=function(){function e(t,n,r,i){Ma(this,e),this.state={prevToken:r,nextToken:i,source:n,items:t}}return Ta(e,[{key:"hasNextPage",get:function(){return!!this.state.nextToken}},{key:"hasPrevPage",get:function(){return!!this.state.prevToken}},{key:"items",get:function(){return this.state.items}},{key:"nextPage",value:function(){return this.hasNextPage?this.state.source(this.state.nextToken):Promise.reject(new Error("No next page"))}},{key:"prevPage",value:function(){return this.hasPrevPage?this.state.source(this.state.prevToken):Promise.reject(new Error("No previous page"))}}]),e}(),DetailedDeliveryReceipt=function DetailedDeliveryReceipt(e){Ma(this,DetailedDeliveryReceipt),this.sid=e.sid,this.messageSid=e.message_sid,this.conversationSid=e.conversation_sid,this.channelMessageSid=e.channel_message_sid,this.participantSid=e.participant_sid,this.status=e.status||"queued",this.errorCode=e.error_code||0,this.dateCreated=e.date_created,this.dateUpdated=e.date_updated};function oA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var uA=rd.scope("Message"),Message=function(e){Oa(Message,e);var t,n,r,i,a,s,o=oA(Message);function Message(e,t,n,r,i,a){var s,u,c,l,f,d;return Ma(this,Message),(d=o.call(this)).conversation=n,d.links=r,d.configuration=i,d.services=a,d.state={sid:t.sid,index:e,author:null!==(s=t.author)&&void 0!==s?s:null,subject:null!==(u=t.subject)&&void 0!==u?u:null,body:t.text,timestamp:t.timestamp?new Date(t.timestamp):null,dateUpdated:t.dateUpdated?new Date(t.dateUpdated):null,lastUpdatedBy:null!==(c=t.lastUpdatedBy)&&void 0!==c?c:null,attributes:zh(t.attributes,"Got malformed attributes for the message ".concat(t.sid),uA),type:null!==(l=t.type)&&void 0!==l?l:"text",media:t.type&&"media"===t.type&&t.media?new Media(t.media,d.services):null,medias:t.type&&"media"===t.type&&t.medias?t.medias.map((function(e){return new Media(e,d.services)})):null,participantSid:null!==(f=t.memberSid)&&void 0!==f?f:null,aggregatedDeliveryReceipt:t.delivery?new AggregatedDeliveryReceipt(t.delivery):null},d}return Ta(Message,[{key:"sid",get:function(){return this.state.sid}},{key:"author",get:function(){return this.state.author}},{key:"subject",get:function(){return this.state.subject}},{key:"body",get:function(){return this.state.body}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"index",get:function(){return this.state.index}},{key:"lastUpdatedBy",get:function(){return this.state.lastUpdatedBy}},{key:"dateCreated",get:function(){return this.state.timestamp}},{key:"attributes",get:function(){return this.state.attributes}},{key:"type",get:function(){return this.state.type}},{key:"media",get:function(){return this.state.media}},{key:"attachedMedia",get:function(){return this.getMediaByCategory(["media"])}},{key:"participantSid",get:function(){return this.state.participantSid}},{key:"aggregatedDeliveryReceipt",get:function(){return this.state.aggregatedDeliveryReceipt}},{key:"getMediaByCategory",value:function(e){var t;return null===(t=this.state.medias)||void 0===t?void 0:t.filter((function(t){return e.includes(t.category)}))}},{key:"_update",value:function(e){var t=[];!e.text&&"string"!=typeof e.text||e.text===this.state.body||(this.state.body=e.text,t.push("body")),e.subject&&e.subject!==this.state.subject&&(this.state.subject=e.subject,t.push("subject")),e.lastUpdatedBy&&e.lastUpdatedBy!==this.state.lastUpdatedBy&&(this.state.lastUpdatedBy=e.lastUpdatedBy,t.push("lastUpdatedBy")),e.author&&e.author!==this.state.author&&(this.state.author=e.author,t.push("author")),e.dateUpdated&&new Date(e.dateUpdated).getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=new Date(e.dateUpdated),t.push("dateUpdated")),e.timestamp&&new Date(e.timestamp).getTime()!==(this.state.timestamp&&this.state.timestamp.getTime())&&(this.state.timestamp=new Date(e.timestamp),t.push("dateCreated"));var n=zh(e.attributes,"Got malformed attributes for the message ".concat(this.sid),uA);Fh(this.state.attributes,n)||(this.state.attributes=n,t.push("attributes"));var r=e.delivery,i=this.state.aggregatedDeliveryReceipt;!!(r&&r.total&&r.delivered&&r.failed&&r.read&&r.sent&&r.undelivered)&&(i?i._isEquals(r)||(i._update(r),t.push("deliveryReceipt")):(this.state.aggregatedDeliveryReceipt=new AggregatedDeliveryReceipt(r),t.push("deliveryReceipt"))),t.length>0&&this.emit("updated",{message:this,updateReasons:t})}},{key:"getParticipant",value:(s=Sa(bl.mark((function e(){var t,n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=null,!this.state.participantSid){e.next=5;break}return e.next=4,this.conversation.getParticipantBySid(this.participantSid).catch((function(){return uA.debug('Participant with sid "'.concat(r.participantSid,'" not found for message ').concat(r.sid)),null}));case 4:t=e.sent;case 5:if(t||!this.state.author){e.next=9;break}return e.next=8,this.conversation.getParticipantByIdentity(this.state.author).catch((function(){return uA.debug('Participant with identity "'.concat(r.author,'" not found for message ').concat(r.sid)),null}));case 8:t=e.sent;case 9:if(!t){e.next=11;break}return e.abrupt("return",t);case 11:throw n="Participant with ",this.state.participantSid&&(n+="SID '"+this.state.participantSid+"' "),this.state.author&&(this.state.participantSid&&(n+="or "),n+="identity '"+this.state.author+"' "),"Participant with "===n&&(n="Participant "),n+="was not found",new Error(n);case 17:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"getDetailedDeliveryReceipts",value:(a=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getDetailedDeliveryReceiptsPaginator();case 2:t=e.sent,n=[];case 4:if(n=[].concat(CP(n),CP(t.items)),t.hasNextPage){e.next=8;break}return e.abrupt("break",13);case 8:return e.next=10,t.nextPage();case 10:t=e.sent,e.next=4;break;case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"remove",value:function(){var e=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("delete",this.links.self);case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"updateBody",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{body:t});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateAttributes",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"attachTemporaryUrlsFor",value:(n=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.map((function(e){return e.sid})),!this.services.mcsClient){e.next=7;break}return e.next=4,this.services.mcsClient.mediaSetGet(n);case 4:return e.abrupt("return",e.sent.map((function(e){return new Media(e,r.services)})));case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"_getDetailedDeliveryReceiptsPaginator",value:(t=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.configuration.links.messagesReceipts.replace("%s",this.conversation.sid).replace("%s",this.sid),r=new Gh(n).arg("PageToken",null==t?void 0:t.pageToken).arg("PageSize",null==t?void 0:t.pageSize).build(),e.next=4,this.services.network.get(r);case 4:return i=e.sent,e.abrupt("return",new sA(i.body.delivery_receipts.map((function(e){return new DetailedDeliveryReceipt(e)})),(function(e,t){return a._getDetailedDeliveryReceiptsPaginator({pageToken:e,pageSize:t})}),i.body.meta.previous_token,i.body.meta.next_token));case 6:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Message}(lm);function cA(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return lA(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return lA(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function lA(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function fA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}ja(Message,"updated","updated"),wl([Fy("string"),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Message.prototype,"updateBody",null),wl([Fy(["string","number","boolean","object",Ay(null)]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Message.prototype,"updateAttributes",null),wl([Fy(Py((function(e){return[e instanceof Array&&e.length>0&&e.reduce((function(e,t){return e&&t instanceof Media})),"a non-empty array of Media"]}))),xl("design:type",Function),xl("design:paramtypes",[Array]),xl("design:returntype",Promise)],Message.prototype,"attachTemporaryUrlsFor",null);var dA=rd.scope("Messages"),pA=function(e){Oa(c,e);var t,n,r,i,a,s,o,u=fA(c);function c(e,t,n){var r;return Ma(this,c),(r=u.call(this)).conversation=e,r.configuration=t,r.services=n,r.messagesByIndex=new Map,r.messagesListPromise=null,r}return Ta(c,[{key:"subscribe",value:(o=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.messagesListPromise){e.next=2;break}return e.abrupt("return",this.messagesListPromise);case 2:return this.messagesListPromise=this.services.syncClient.list({id:t,mode:"open_existing"}),e.prev=3,e.next=6,this.messagesListPromise;case 6:return(n=e.sent).on("itemAdded",(function(e){dA.debug("".concat(r.conversation.sid," itemAdded: ").concat(e.item.index));var t={self:"".concat(r.conversation.links.messages,"/").concat(e.item.data.sid),conversation:r.conversation.links.self,messages_receipts:"".concat(r.conversation.links.messages,"/").concat(e.item.data.sid,"/Receipts")},n=new Message(e.item.index,e.item.data,r.conversation,t,r.configuration,r.services);r.messagesByIndex.has(n.index)?dA.debug("Message arrived, but is already known and ignored",r.conversation.sid,n.index):(r.messagesByIndex.set(n.index,n),n.on("updated",(function(e){return r.emit("messageUpdated",e)})),r.emit("messageAdded",n))})),n.on("itemRemoved",(function(e){dA.debug("#{this.conversation.sid} itemRemoved: ".concat(e.index));var t=e.index;if(r.messagesByIndex.has(t)){var n=r.messagesByIndex.get(t);r.messagesByIndex.delete(n.index),n.removeAllListeners("updated"),r.emit("messageRemoved",n)}})),n.on("itemUpdated",(function(e){dA.debug("".concat(r.conversation.sid," itemUpdated: ").concat(e.item.index));var t=r.messagesByIndex.get(e.item.index);t&&t._update(e.item.data)})),e.abrupt("return",n);case 13:throw e.prev=13,e.t0=e.catch(3),this.messagesListPromise=null,"disconnected"!==this.services.syncClient.connectionState&&dA.error("Failed to get messages object for conversation",this.conversation.sid,e.t0),dA.debug("ERROR: Failed to get messages object for conversation",this.conversation.sid,e.t0),e.t0;case 19:case"end":return e.stop()}}),e,this,[[3,13]])}))),function(e){return o.apply(this,arguments)})},{key:"unsubscribe",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.messagesListPromise){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.messagesListPromise;case 4:e.sent.close(),this.messagesListPromise=null;case 7:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"sendV2",value:(a=Sa(bl.mark((function e(t){var n,r,i,a,s,o,u;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:dA.debug("Sending message V2",t.mediaContent,t.attributes,t.emailOptions),r=[],i=cA(t.mediaContent),e.prev=3,i.s();case 5:if((a=i.n()).done){e.next=22;break}if(s=vm(a.value,2),o=s[0],u=s[1],dA.debug("Adding media to a message as ".concat(u instanceof FormData?"FormData":"SendMediaOptions"),u),e.t0=r,!(u instanceof FormData)){e.next=15;break}return e.next=12,this.services.mcsClient.postFormData(u,o);case 12:e.t1=e.sent,e.next=18;break;case 15:return e.next=17,this.services.mcsClient.post(u.contentType,u.media,o,u.filename);case 17:e.t1=e.sent;case 18:e.t2=e.t1,e.t0.push.call(e.t0,e.t2);case 20:e.next=5;break;case 22:e.next=27;break;case 24:e.prev=24,e.t3=e.catch(3),i.e(e.t3);case 27:return e.prev=27,i.f(),e.finish(27);case 30:return e.next=32,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{body:t.text,subject:null===(n=t.emailOptions)||void 0===n?void 0:n.subject,media_sids:r.map((function(e){return e.sid})),attributes:void 0!==t.attributes?JSON.stringify(t.attributes):void 0});case 32:return e.abrupt("return",e.sent);case 33:case"end":return e.stop()}}),e,this,[[3,24,27,30]])}))),function(e){return a.apply(this,arguments)})},{key:"send",value:(i=Sa(bl.mark((function e(t){var n,r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]?i[1]:{},r=i.length>2?i[2]:void 0,dA.debug("Sending text message",t,n,r),e.next=5,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{body:null!=t?t:"",attributes:void 0!==n?JSON.stringify(n):void 0,subject:null==r?void 0:r.subject});case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"sendMedia",value:(r=Sa(bl.mark((function e(t){var n,r,i,a=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=a.length>1&&void 0!==a[1]?a[1]:{},r=a.length>2?a[2]:void 0,dA.debug("Sending media message",t,n,r),dA.debug("Sending media message as ".concat(t instanceof FormData?"FormData":"SendMediaOptions"),t,n),!(t instanceof FormData)){e.next=10;break}return e.next=7,this.services.mcsClient.postFormData(t);case 7:e.t0=e.sent,e.next=13;break;case 10:return e.next=12,this.services.mcsClient.post(t.contentType,t.media,"media",t.filename);case 12:e.t0=e.sent;case 13:return i=e.t0,e.next=16,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{media_sids:[i.sid],attributes:void 0!==n?JSON.stringify(n):void 0});case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getMessages",value:(n=Sa(bl.mark((function e(t,n){var r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=i.length>2&&void 0!==i[2]?i[2]:"backwards",e.abrupt("return",this._getMessages(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"_wrapPaginator",value:function(e,t,n){var r=this,i="desc"===e,a=function(){return t.nextPage().then((function(t){return r._wrapPaginator(e,t,n)}))},s=function(){return t.prevPage().then((function(t){return r._wrapPaginator(e,t,n)}))};return n(t.items).then((function(e){return{items:e.sort((function(e,t){return e.index-t.index})),hasPrevPage:i?t.hasNextPage:t.hasPrevPage,hasNextPage:i?t.hasPrevPage:t.hasNextPage,prevPage:i?a:s,nextPage:i?s:a}}))}},{key:"_upsertMessage",value:function(e,t){var n=this,r=this.messagesByIndex.get(e);if(r)return r;var i={self:"".concat(this.conversation.links.messages,"/").concat(t.sid),conversation:this.conversation.links.self,messages_receipts:"".concat(this.conversation.links.messages,"/").concat(t.sid,"/Receipts")},a=new Message(e,t,this.conversation,i,this.configuration,this.services);return this.messagesByIndex.set(a.index,a),a.on("updated",(function(e){return n.emit("messageUpdated",e)})),a}},{key:"_getMessages",value:(t=Sa(bl.mark((function e(){var t,n,r,i,a,s,o=this,u=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:30,n=u.length>1&&void 0!==u[1]?u[1]:"end",r=u.length>2&&void 0!==u[2]?u[2]:"forward",i="backwards"===r?"desc":"asc",e.next=6,this.messagesListPromise;case 6:return a=e.sent,e.next=9,a.getItems({from:"end"!==n?n:void 0,pageSize:t,order:i,limit:t});case 9:return s=e.sent,e.next=12,this._wrapPaginator(i,s,(function(e){return Promise.all(e.map((function(e){return o._upsertMessage(e.index,e.data)})))}));case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),c}(lm),hA=function(){function e(t){Ma(this,e),ja(this,"attributes",{}),ja(this,"mediaContent",[]),ja(this,"emailOptions",{}),this.messagesEntity=t}var t;return Ta(e,[{key:"send",value:(t=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.messagesEntity.sendV2(this);case 2:return t=e.sent,e.abrupt("return",qh(t.index));case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),vA=function(){function e(t,n){Ma(this,e),this.limits=t,this.message=new hA(n)}return Ta(e,[{key:"setBody",value:function(e){return this.message.text=e,this}},{key:"setSubject",value:function(e){return this.message.emailOptions.subject=e,this}},{key:"setAttributes",value:function(e){return this.message.attributes=e,this}},{key:"addMedia",value:function(e){return this.message.mediaContent.push(["media",e]),this}},{key:"build",value:function(){if(this.message.mediaContent.length>this.limits.mediaAttachmentsCountLimit)throw new Error("Too many media attachments in the message (".concat(this.message.mediaContent.length," > ").concat(this.limits.mediaAttachmentsCountLimit,")"));return this.message}},{key:"getPayloadContentType",value:function(e){return"undefined"!=typeof FormData&&e instanceof FormData?e.get("Content-Type"):e.contentType}}]),e}();function yA(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return mA(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return mA(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function mA(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function gA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var bA=rd.scope("Conversation"),kA={lastMessage:"lastMessage",attributes:"attributes",createdBy:"createdBy",dateCreated:"dateCreated",dateUpdated:"dateUpdated",friendlyName:"friendlyName",lastConsumedMessageIndex:"lastConsumedMessageIndex",notificationLevel:"notificationLevel",sid:"sid",status:"status",uniqueName:"uniqueName",state:"state"};function wA(e){try{return new Date(e)}catch(e){return null}}var Conversation=function(e){Oa(Conversation,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y,m,g,b,k,w,x,_,S,E,T=gA(Conversation);function Conversation(e,t,n,r,i){var a;Ma(this,Conversation),(a=T.call(this)).sid=t,a.links=n,a.configuration=r,a.services=i;var s=e.attributes||{},o=e.createdBy,u=wA(e.dateCreated),c=wA(e.dateUpdated),l=e.friendlyName||null,f=Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,d=e.uniqueName||null;try{JSON.stringify(s)}catch(e){throw new Error("Attributes must be a valid JSON object.")}a.entityName=e.channel,a.channelState={uniqueName:d,status:"notParticipating",attributes:s,createdBy:o,dateCreated:u,dateUpdated:c,friendlyName:l,lastReadMessageIndex:f},e.notificationLevel&&(a.channelState.notificationLevel=e.notificationLevel);var p={participants:a.links.participants};return a.participants=new Map,a.participantsEntity=new DP(Ra(a),a.participants,p,a.configuration,a.services),a.participantsEntity.on("participantJoined",a.emit.bind(Ra(a),"participantJoined")),a.participantsEntity.on("participantLeft",a.emit.bind(Ra(a),"participantLeft")),a.participantsEntity.on("participantUpdated",(function(e){return a.emit("participantUpdated",e)})),a.messagesEntity=new pA(Ra(a),r,i),a.messagesEntity.on("messageAdded",(function(e){return a._onMessageAdded(e)})),a.messagesEntity.on("messageUpdated",(function(e){return a.emit("messageUpdated",e)})),a.messagesEntity.on("messageRemoved",a.emit.bind(Ra(a),"messageRemoved")),a}return Ta(Conversation,[{key:"uniqueName",get:function(){return this.channelState.uniqueName}},{key:"status",get:function(){return this.channelState.status}},{key:"friendlyName",get:function(){return this.channelState.friendlyName}},{key:"dateUpdated",get:function(){return this.channelState.dateUpdated}},{key:"dateCreated",get:function(){return this.channelState.dateCreated}},{key:"createdBy",get:function(){return this.channelState.createdBy}},{key:"attributes",get:function(){return this.channelState.attributes}},{key:"lastReadMessageIndex",get:function(){return this.channelState.lastReadMessageIndex}},{key:"lastMessage",get:function(){return this.channelState.lastMessage}},{key:"notificationLevel",get:function(){return this.channelState.notificationLevel}},{key:"limits",get:function(){return this.configuration.limits}},{key:"state",get:function(){return this.channelState.state}},{key:"_subscribe",value:function(){var e,t=this;return this.entityPromise=null!==(e=this.entityPromise)&&void 0!==e?e:this.services.syncClient.document({id:this.entityName,mode:"open_existing"}).then((function(e){return t.entity=e,t.entity.on("updated",(function(e){t._update(e.data)})),t.entity.on("removed",(function(){return t.emit("removed",t)})),t._update(t.entity.data),e})).catch((function(e){throw t.entity=null,t.entityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&bA.error("Failed to get conversation object",e),bA.debug("ERROR: Failed to get conversation object",e),e}))}},{key:"_subscribeStreams",value:(E=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._subscribe();case 3:return bA.trace("_subscribeStreams, this.entity.data=",this.entity.data),t=this.entity.data.messages,n=this.entity.data.roster,e.next=8,Promise.all([this.messagesEntity.subscribe(t),this.participantsEntity.subscribe(n)]);case 8:e.next=15;break;case 10:throw e.prev=10,e.t0=e.catch(0),"disconnected"!==this.services.syncClient.connectionState&&bA.error("Failed to subscribe on conversation objects",this.sid,e.t0),bA.debug("ERROR: Failed to subscribe on conversation objects",this.sid,e.t0),e.t0;case 15:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(){return E.apply(this,arguments)})},{key:"_unsubscribe",value:(S=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.entity){e.next=5;break}return e.next=3,this.entity.close();case 3:this.entity=null,this.entityPromise=null;case 5:return e.abrupt("return",Promise.all([this.participantsEntity.unsubscribe(),this.messagesEntity.unsubscribe()]));case 6:case"end":return e.stop()}}),e,this)}))),function(){return S.apply(this,arguments)})},{key:"_setStatus",value:function(e,t){var n=this;this.statusSource=t,this.channelState.status!==e&&(this.channelState.status=e,"joined"===e?this._subscribeStreams().catch((function(t){if(bA.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n.services.syncClient.connectionState)throw t})):this.entityPromise&&this._unsubscribe().catch((function(t){if(bA.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n.services.syncClient.connectionState)throw t})))}},{key:"_statusSource",value:function(){return this.statusSource}},{key:"_update",value:function(e){var t,n,r,i,a;bA.trace("_update",e),Conversation.preprocessUpdate(e,this.sid);for(var s=new Set,o=0,u=Object.keys(e);o<u.length;o++){var c=u[o],l=kA[c];if(l)switch(l){case kA.status:if(!e.status||"unknown"===e.status||this.channelState.status===e.status)break;this.channelState.status=e.status,s.add(l);break;case kA.attributes:if(Fh(this.channelState.attributes,e.attributes))break;this.channelState.attributes=e.attributes,s.add(l);break;case kA.lastConsumedMessageIndex:if(void 0===e.lastConsumedMessageIndex||e.lastConsumedMessageIndex===this.channelState.lastReadMessageIndex)break;this.channelState.lastReadMessageIndex=e.lastConsumedMessageIndex,s.add("lastReadMessageIndex");break;case kA.lastMessage:if(this.channelState.lastMessage&&!e.lastMessage){delete this.channelState.lastMessage,s.add(l);break}this.channelState.lastMessage=this.channelState.lastMessage||{},void 0!==(null===(t=e.lastMessage)||void 0===t?void 0:t.index)&&e.lastMessage.index!==this.channelState.lastMessage.index&&(this.channelState.lastMessage.index=e.lastMessage.index,s.add(l)),void 0!==(null===(n=e.lastMessage)||void 0===n?void 0:n.timestamp)&&(null===(r=this.channelState.lastMessage)||void 0===r||null===(i=r.dateCreated)||void 0===i?void 0:i.getTime())!==e.lastMessage.timestamp.getTime()&&(this.channelState.lastMessage.dateCreated=e.lastMessage.timestamp,s.add(l)),Fh(this.channelState.lastMessage,{})&&delete this.channelState.lastMessage;break;case kA.state:var f=e.state||void 0;if(void 0!==f&&(f.dateUpdated=new Date(f.dateUpdated)),Fh(this.channelState.state,f))break;this.channelState.state=f,s.add(l);break;default:var d=e[c]instanceof Date,p=d&&(null===(a=this.channelState[l])||void 0===a?void 0:a.getTime())===e[c].getTime(),h=!d&&this[l]===e[c];if(p||h)break;this.channelState[l]=e[c],s.add(l)}}s.size>0&&this.emit("updated",{conversation:this,updateReasons:CP(s)})}},{key:"_onMessageAdded",value:function(e){var t,n=yA(this.participants.values());try{for(n.s();!(t=n.n()).done;){var r=t.value;if(r.identity===e.author){r._endTyping();break}}}catch(e){n.e(e)}finally{n.f()}this.emit("messageAdded",e)}},{key:"_setLastReadMessageIndex",value:(_=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post","".concat(this.configuration.links.myConversations,"/").concat(this.sid),{last_read_message_index:t});case 2:return n=e.sent,e.abrupt("return",n.unread_messages_count);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return _.apply(this,arguments)})},{key:"add",value:function(){var e=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.add(t,n));case 1:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}()},{key:"addNonChatParticipant",value:(x=Sa(bl.mark((function e(t,n,r){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.addNonChatParticipant(t,n,null!=r?r:{}));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return x.apply(this,arguments)})},{key:"advanceLastReadMessageIndex",value:(w=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:if(!(t<this.lastReadMessageIndex)){e.next=6;break}return e.next=5,this._setLastReadMessageIndex(this.lastReadMessageIndex);case 5:return e.abrupt("return",e.sent);case 6:return e.next=8,this._setLastReadMessageIndex(t);case 8:return e.abrupt("return",e.sent);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return w.apply(this,arguments)})},{key:"delete",value:(k=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("delete",this.links.self);case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return k.apply(this,arguments)})},{key:"getAttributes",value:(b=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribe();case 2:return e.abrupt("return",this.attributes);case 3:case"end":return e.stop()}}),e,this)}))),function(){return b.apply(this,arguments)})},{key:"getMessages",value:(g=Sa(bl.mark((function e(t,n,r){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.messagesEntity.getMessages(t,n,r));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return g.apply(this,arguments)})},{key:"getParticipants",value:(m=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.participantsEntity.getParticipants());case 3:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"getParticipantsCount",value:(y=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new Gh(this.configuration.links.conversations).path(this.sid).build(),e.next=3,this.services.network.get(t);case 3:return n=e.sent,e.abrupt("return",n.body.participants_count);case 5:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getParticipantBySid",value:(v=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.getParticipantBySid(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return v.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(h=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.getParticipantByIdentity(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"getMessagesCount",value:(p=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new Gh(this.configuration.links.conversations).path(this.sid).build(),e.next=3,this.services.network.get(t);case 3:return n=e.sent,e.abrupt("return",n.body.messages_count);case 5:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"getUnreadMessagesCount",value:(d=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new Gh(this.configuration.links.myConversations).path(this.sid).build(),e.next=3,this.services.network.get(t);case 3:if((n=e.sent).body.conversation_sid===this.sid){e.next=6;break}throw new Error("Conversation was not found in the user conversations list");case 6:if("number"!=typeof(r=n.body.unread_messages_count)){e.next=9;break}return e.abrupt("return",r);case 9:return e.abrupt("return",null);case 10:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"join",value:(f=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:this.configuration.userIdentity});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"leave",value:(l=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this.channelState.status){e.next=3;break}return e.next=3,this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(this.configuration.userIdentity));case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"removeParticipant",value:(c=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.participantsEntity.remove("string"==typeof t?t:t.sid);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"sendMessage",value:(u=Sa(bl.mark((function e(t,n,r){var i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t&&null!==t){e.next=5;break}return e.next=3,this.messagesEntity.send(t,n,r);case 3:return i=e.sent,e.abrupt("return",qh(i.index));case 5:return e.next=7,this.messagesEntity.sendMedia(t,n,r);case 7:return a=e.sent,e.abrupt("return",qh(a.index));case 9:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"prepareMessage",value:function(){return new vA(this.limits,this.messagesEntity)}},{key:"setAllMessagesRead",value:(o=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this.getMessages(1);case 4:if(!((t=e.sent).items.length>0)){e.next=7;break}return e.abrupt("return",this.advanceLastReadMessageIndex(t.items[0].index));case 7:return e.abrupt("return",Promise.resolve(0));case 8:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"setAllMessagesUnread",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this._setLastReadMessageIndex(null);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"setUserNotificationLevel",value:(a=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post","".concat(this.configuration.links.myConversations,"/").concat(this.sid),{notification_level:t});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"typing",value:function(){return this.services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateFriendlyName",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.friendlyName===t){e.next=3;break}return e.next=3,this.services.commandExecutor.mutateResource("post",this.links.self,{friendly_name:t});case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"updateLastReadMessageIndex",value:(n=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this._setLastReadMessageIndex(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"updateUniqueName",value:(t=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.uniqueName===t){e.next=4;break}return t||(t=""),e.next=4,this.services.commandExecutor.mutateResource("post",this.links.self,{unique_name:t});case 4:return e.abrupt("return",this);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}],[{key:"preprocessUpdate",value:function(e,t){try{"string"==typeof e.attributes?e.attributes=JSON.parse(e.attributes):e.attributes&&JSON.stringify(e.attributes)}catch(n){bA.warn("Retrieved malformed attributes from the server for conversation: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(n){bA.warn("Retrieved malformed dateCreated from the server for conversation: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(n){bA.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){bA.warn("Retrieved malformed lastMessage.timestamp from the server for conversation: "+t),delete e.lastMessage.timestamp}}}]),Conversation}(lm);ja(Conversation,"participantJoined","participantJoined"),ja(Conversation,"participantLeft","participantLeft"),ja(Conversation,"participantUpdated","participantUpdated"),ja(Conversation,"messageAdded","messageAdded"),ja(Conversation,"messageRemoved","messageRemoved"),ja(Conversation,"messageUpdated","messageUpdated"),ja(Conversation,"typingEnded","typingEnded"),ja(Conversation,"typingStarted","typingStarted"),ja(Conversation,"updated","updated"),ja(Conversation,"removed","removed"),wl([Fy(jy,["undefined","string","number","boolean","object",Ay(null)]),xl("design:type",Function),xl("design:paramtypes",[String,Object]),xl("design:returntype",Promise)],Conversation.prototype,"add",null),wl([Fy(jy,jy,["undefined","string","number","boolean","object",Ay(null)]),xl("design:type",Function),xl("design:paramtypes",[String,String,Object]),xl("design:returntype",Promise)],Conversation.prototype,"addNonChatParticipant",null),wl([Fy(My),xl("design:type",Function),xl("design:paramtypes",[Number]),xl("design:returntype",Promise)],Conversation.prototype,"advanceLastReadMessageIndex",null),wl([Fy(["undefined",My],["undefined",My],["undefined",Ay("backwards","forward")]),xl("design:type",Function),xl("design:paramtypes",[Number,Number,String]),xl("design:returntype",Promise)],Conversation.prototype,"getMessages",null),wl([Fy(jy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"getParticipantBySid",null),wl([Fy(jy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"getParticipantByIdentity",null),wl([Fy([jy,Participant]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Conversation.prototype,"removeParticipant",null),wl([Fy(["string",Ay(null),Py((function(e){return[e instanceof FormData,"an instance of FormData"]})),Ly("media options",{contentType:jy,media:Py((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"]}))})],["undefined","string","number","boolean","object",Ay(null)],["undefined",Ay(null),Ly("email attributes",{subject:[jy,"undefined"]})]),xl("design:type",Function),xl("design:paramtypes",[Object,Object,Object]),xl("design:returntype",Promise)],Conversation.prototype,"sendMessage",null),wl([Fy(Ay("default","muted")),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"setUserNotificationLevel",null),wl([Fy(["string","number","boolean","object",Ay(null)]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Conversation.prototype,"updateAttributes",null),wl([Fy(["string"]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"updateFriendlyName",null),wl([Fy([Ay(null),My]),xl("design:type",Function),xl("design:paramtypes",[Number]),xl("design:returntype",Promise)],Conversation.prototype,"updateLastReadMessageIndex",null),wl([Fy(["string",Ay(null)]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"updateUniqueName",null);var xA=function(){function e(){var t=this;Ma(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return Ta(e,[{key:"promise",get:function(){return this._promise}},{key:"update",value:function(e){this._resolve(e)}},{key:"set",value:function(e){this.current=e,this._resolve(e)}},{key:"fail",value:function(e){this._reject(e)}}]),e}();function _A(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return SA(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return SA(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function SA(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function EA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function TA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?EA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):EA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function RA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var IA=rd.scope("Conversations"),OA=function(e){Oa(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=RA(p);function p(e,t){var n;return Ma(this,p),ja(Ra(n=d.call(this)),"conversations",new Map),ja(Ra(n),"myConversationsRead",new xA),ja(Ra(n),"tombstones",new Set),ja(Ra(n),"myConversationsFetched",!1),n.configuration=e,n.services=t,n}return Ta(p,[{key:"addConversation",value:(f=Sa(bl.mark((function e(t){var n,r,i,a,s,o,u,c,l,f;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=void 0!==(null==t?void 0:t.attributes)?t.attributes:{},e.next=3,this.services.commandExecutor.mutateResource("post",this.configuration.links.conversations,{friendly_name:t.friendlyName,unique_name:t.uniqueName,attributes:void 0!==a?JSON.stringify(a):void 0});case 3:if(s=e.sent,o=null!==(n=s.sid)&&void 0!==n?n:null,u=null!==(r=null===(i=s.sync_objects)||void 0===i?void 0:i.conversation)&&void 0!==r?r:null,c=TA({self:s.url},s.links),!(l=this.conversations.get(o))){e.next=12;break}return e.next=11,l._subscribe();case 11:return e.abrupt("return",l);case 12:return f=new Conversation({channel:u,entityName:null,uniqueName:null,attributes:null,createdBy:null,friendlyName:null,lastConsumedMessageIndex:null,dateCreated:null,dateUpdated:null},o,c,this.configuration,this.services),this.conversations.set(f.sid,f),this._registerForEvents(f),e.next=17,f._subscribe();case 17:return this.emit("conversationAdded",f),e.abrupt("return",f);case 19:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"fetchConversations",value:(l=Sa(bl.mark((function e(){var t,n,r,i,a,s,o,u=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._getMap();case 3:return(t=e.sent).on("itemAdded",(function(e){IA.debug("itemAdded: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),t.on("itemRemoved",(function(e){IA.debug("itemRemoved: ".concat(e.key));var t=e.key;u.myConversationsFetched||u.tombstones.add(t);var n=u.conversations.get(t);n&&("joined"===n.status&&(n._setStatus("notParticipating","sync"),u.emit("conversationLeft",n)),u.conversations.delete(t),u.emit("conversationRemoved",n),n.emit("removed",n))})),t.on("itemUpdated",(function(e){IA.debug("itemUpdated: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),e.next=9,this._fetchMyConversations();case 9:n=e.sent,r=[],i=_A(n);try{for(i.s();!(a=i.n()).done;)s=a.value,r.push(this._upsertConversation("rest",s.channel_sid,s))}catch(e){i.e(e)}finally{i.f()}return this.myConversationsRead.set(!0),e.next=16,Promise.all(r);case 16:return this.myConversationsFetched=!0,this.tombstones.clear(),IA.debug("The conversations list has been successfully fetched"),e.abrupt("return",this);case 22:throw e.prev=22,e.t0=e.catch(0),o="Failed to fetch the conversations list","disconnected"!==this.services.syncClient.connectionState&&IA.error(o,e.t0),IA.debug("ERROR: ".concat(o),e.t0),e.t0;case 28:case"end":return e.stop()}}),e,this,[[0,22]])}))),function(){return l.apply(this,arguments)})},{key:"getConversations",value:(c=Sa(bl.mark((function e(t){var n,r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return n=e.sent,e.next=5,n.getItems();case 5:return r=e.sent,e.abrupt("return",this._wrapPaginator(r,(function(e){return Promise.all(e.map((function(e){return i._upsertConversation("sync",e.key,e.data)})))})));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"getConversation",value:(u=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return n=e.sent,e.next=5,n.getItems({from:t});case 5:return r=e.sent,i=r.items.map((function(e){return a._upsertConversation("sync",e.key,e.data)})),e.abrupt("return",i.length>0?i[0]:null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(o=Sa(bl.mark((function e(t){var n,r,i,a,s;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new Gh(this.configuration.links.myConversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a=i.conversation_sid,s={entityName:null,lastConsumedMessageIndex:i.last_read_message_index,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:i.sync_objects.conversation,notificationLevel:null==i?void 0:i.notification_level,sid:a},e.abrupt("return",this._upsertConversation("sync",a,s));case 8:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"peekConversation",value:(s=Sa(bl.mark((function e(t){var n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new Gh(this.configuration.links.conversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a={entityName:null,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:"".concat(t,".channel"),sid:t},e.abrupt("return",this._upsertConversation("sync",t,a));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"_getMap",value:(a=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.syncClient.map({id:this.configuration.myConversations,mode:"open_existing"});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"_wrapPaginator",value:(i=Sa(bl.mark((function e(t,n){var r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n(t.items);case 2:return r=e.sent,e.abrupt("return",{items:r,hasNextPage:t.hasNextPage,hasPrevPage:t.hasPrevPage,nextPage:function(){return t.nextPage().then((function(e){return i._wrapPaginator(e,n)}))},prevPage:function(){return t.prevPage().then((function(e){return i._wrapPaginator(e,n)}))}});case 4:case"end":return e.stop()}}),e)}))),function(e,t){return i.apply(this,arguments)})},{key:"_updateConversation",value:(r=Sa(bl.mark((function e(t,n,r){var i,a,s,o=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=void 0!==n._statusSource()&&t!==n._statusSource(),a="rest"!==t||"sync"===n._statusSource(),!i||!a||"sync"===t){e.next=5;break}return IA.trace("upsertConversation: conversation is known from sync and came from chat, ignoring",{sid:n.sid,data:r.status,conversation:n.status}),e.abrupt("return");case 5:if("joined"!==r.status||"joined"===n.status){e.next=13;break}return n._setStatus("joined",t),s={},void 0!==r.notificationLevel&&(s.notificationLevel=r.notificationLevel),void 0!==r.lastConsumedMessageIndex&&(s.lastConsumedMessageIndex=r.lastConsumedMessageIndex),Fh(s,{})||n._update(s),n._subscribe().then((function(){o.emit("conversationJoined",n)})),e.abrupt("return");case 13:if("notParticipating"!==r.status||"joined"!==n.status){e.next=20;break}return n._setStatus("notParticipating",t),n._update(r),e.next=18,n._subscribe();case 18:return this.emit("conversationLeft",n),e.abrupt("return");case 20:if("notParticipating"!==r.status){e.next=24;break}return e.next=23,n._subscribe();case 23:return e.abrupt("return");case 24:n._update(r);case 25:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"_upsertConversation",value:(n=Sa(bl.mark((function e(t,n,r){var i,a,s,o;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(IA.trace("upsertConversation called for ".concat(n),r),!(i=this.conversations.get(n))){e.next=9;break}return IA.trace("upsertConversation: the conversation ".concat(i.sid," is known;")+"its status is known from the source ".concat(i._statusSource()," ")+"and the update came from the source ".concat(t),i),e.next=6,this._updateConversation(t,i,r);case 6:return e.next=8,i._subscribe();case 8:return e.abrupt("return",i);case 9:if(!["chat","rest"].includes(t)||!this.tombstones.has(n)){e.next=12;break}return IA.trace("upsertChannel: the channel is deleted but reappeared again from chat, ignoring",n),e.abrupt("return");case 12:return IA.trace("upsertConversation: creating a local conversation object with sid "+n,r),a="".concat(this.configuration.links.conversations,"/").concat(n),s={self:a,messages:"".concat(a,"/Messages"),participants:"".concat(a,"/Participants")},o=new Conversation(r,n,s,this.configuration,this.services),this.conversations.set(n,o),e.next=19,o._subscribe();case 19:return this._registerForEvents(o),this.emit("conversationAdded",o),"joined"===r.status&&(o._setStatus("joined",t),this.emit("conversationJoined",o)),e.abrupt("return",o);case 23:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"_fetchMyConversations",value:(t=Sa(bl.mark((function e(){var t,n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=null;case 2:return r=new Gh(this.configuration.links.myConversations),n&&r.arg("PageToken",n),e.next=6,this.services.network.get(r.build());case 6:i=e.sent,a=i.body.conversations.map((function(e){return{descriptor:e,channel_sid:e.conversation_sid,status:e.status,channel:e.sync_objects.conversation,messages:e.sync_objects.messages,roster:"".concat(e.conversation_sid,".roster"),lastConsumedMessageIndex:e.last_consumed_message_index,notificationLevel:e.notification_level}})),n=i.body.meta.next_token,t=[].concat(CP(t),CP(a));case 10:if(n){e.next=2;break}case 11:return e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_onConversationRemoved",value:function(e){var t=this.conversations.get(e);t&&(this.conversations.delete(e),this.emit("conversationRemoved",t))}},{key:"_registerForEvents",value:function(e){var t=this;e.on("removed",(function(){return t._onConversationRemoved(e.sid)})),e.on("updated",(function(e){return t.emit("conversationUpdated",e)})),e.on("participantJoined",this.emit.bind(this,"participantJoined")),e.on("participantLeft",this.emit.bind(this,"participantLeft")),e.on("participantUpdated",(function(e){return t.emit("participantUpdated",e)})),e.on("messageAdded",this.emit.bind(this,"messageAdded")),e.on("messageUpdated",(function(e){return t.emit("messageUpdated",e)})),e.on("messageRemoved",this.emit.bind(this,"messageRemoved")),e.on("typingStarted",this.emit.bind(this,"typingStarted")),e.on("typingEnded",this.emit.bind(this,"typingEnded"))}}]),p}(lm),CA=In,PA=Hr.find,AA=kd,jA="find",MA=!0;function LA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}jA in[]&&Array(1).find((function(){MA=!1})),CA({target:"Array",proto:!0,forced:MA},{find:function(e){return PA(this,e,arguments.length>1?arguments[1]:void 0)}}),AA(jA);var NA=function(e){Oa(a,e);var t,n,r,i=LA(a);function a(e,t,n){var r;return Ma(this,a),(r=i.call(this)).configuration=t,r.services=n,r.fifoStack=[],r.myself=e,r.myself.on("updated",(function(e){return r.emit("userUpdated",e)})),r.myself.on("userSubscribed",(function(){return r.emit("userSubscribed",r.myself)})),r.myself.on("userUnsubscribed",(function(){r.emit("userUnsubscribed",r.myself),r.myself._ensureFetched()})),r.subscribedUsers=new Map,r}return Ta(a,[{key:"handleUnsubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)&&this.subscribedUsers.delete(e.identity);var t=-1;this.fifoStack.find((function(n,r){return n==e.identity&&(t=r,!0)}))&&this.fifoStack.splice(t,1),this.emit("userUnsubscribed",e)}},{key:"handleSubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)||(this.fifoStack.length>=this.configuration.userInfosToSubscribe&&this.subscribedUsers.get(this.fifoStack.shift()).unsubscribe(),this.fifoStack.push(e.identity),this.subscribedUsers.set(e.identity,e),this.emit("userSubscribed",e))}},{key:"getUser",value:(r=Sa(bl.mark((function e(t){var n,r,i=this,a=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.length>1&&void 0!==a[1]?a[1]:null,e.next=3,this.myself._ensureFetched();case 3:if(t!=this.myself.identity){e.next=5;break}return e.abrupt("return",this.myself);case 5:if(r=this.subscribedUsers.get(t)){e.next=17;break}if(n){e.next=11;break}return e.next=10,this.getSyncUniqueName(t);case 10:n=e.sent;case 11:return(r=new User(t,n,this.configuration,this.services)).on("updated",(function(e){return i.emit("userUpdated",e)})),r.on("userSubscribed",(function(){return i.handleSubscribeUser(r)})),r.on("userUnsubscribed",(function(){return i.handleUnsubscribeUser(r)})),e.next=17,r._ensureFetched();case 17:return e.abrupt("return",r);case 18:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.myself._ensureFetched();case 2:return t=[this.myself],this.subscribedUsers.forEach((function(e){return t.push(e)})),e.abrupt("return",t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getSyncUniqueName",value:(t=Sa(bl.mark((function e(t){var n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new Gh(this.configuration.links.users).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,e.abrupt("return",r.body.sync_objects.user_info_map);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),a}(lm),UA=rd.scope("TypingIndicator"),DA=function(){function e(t,n,r){Ma(this,e),this.configuration=n,this.services=r,this.getConversation=t,this.serviceTypingTimeout=null,this.sentUpdates=new Map}var t;return Ta(e,[{key:"typingTimeout",get:function(){return this.configuration.typingIndicatorTimeoutOverride||this.serviceTypingTimeout||this.configuration.typingIndicatorTimeoutDefault}},{key:"initialize",value:function(){var e=this;this.services.notificationClient.on("message",function(){var t=Sa(bl.mark((function t(n,r){return bl.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==Gg.TYPING_INDICATOR){t.next=3;break}return t.next=3,e._handleRemoteTyping(r);case 3:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}())}},{key:"_handleRemoteTyping",value:(t=Sa(bl.mark((function e(t){var n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:UA.trace("Got new typing indicator ",t),this.getConversation(t.channel_sid).then((function(e){e&&e.participants.forEach((function(e){if(e.identity===t.identity){var r=n.configuration.typingIndicatorTimeoutOverride+1e3||1e3*t.typing_timeout;e._startTyping(r)}}))})).catch((function(e){throw UA.error(e),e}));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"send",value:function(e){var t=this.sentUpdates.get(e);return t&&t>Date.now()-this.typingTimeout?Promise.resolve():(this.sentUpdates.set(e,Date.now()),this._send(e))}},{key:"_send",value:function(e){var t=this;UA.trace("Sending typing indicator");var n=this.configuration.links.typing,r="ChannelSid=".concat(e);return this.services.twilsockClient.post(n,{"Content-Type":"application/x-www-form-urlencoded"},r,this.configuration.productId).then((function(e){e.body.hasOwnProperty("typing_timeout")&&(t.serviceTypingTimeout=1e3*e.body.typing_timeout)})).catch((function(e){throw UA.error("Failed to send typing indicator:",e),e}))}}]),e}(),PushNotification=function PushNotification(e){Ma(this,PushNotification),this.title=e.title||null,this.body=e.body||null,this.sound=e.sound||null,this.badge=e.badge||null,this.action=e.action||null,this.type=e.type||null,this.data=e.data||{}};function FA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function BA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?FA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):FA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var qA,WA,zA,GA=function(e){return e.replace(/(^\/+|\/+$)/g,"")},JA=function(){function e(t,n,r){Ma(this,e),this._serviceUrl=t,this._services=n,this._productId=r}var t,n,r;return Ta(e,[{key:"_preProcessUrl",value:function(e){var t=GA(e);return/^https?:\/\//.test(e)?t:"".concat(GA(this._serviceUrl),"/").concat(t)}},{key:"_makeRequest",value:(r=Sa(bl.mark((function e(t,n,r,i){var a,s,o,u;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=this._preProcessUrl(n),s=BA({"Content-Type":"application/json; charset=utf-8"},i||{}),e.t0=t,e.next="get"===e.t0?5:"post"===e.t0?11:"delete"===e.t0?15:19;break;case 5:return u=a,r&&(u+="?"+Object.entries(r).map((function(e){return e.map(encodeURIComponent).join("=")})).join("&")),e.next=9,this._services.transport.get(u,s,this._productId);case 9:return o=e.sent,e.abrupt("break",19);case 11:return e.next=13,this._services.transport.post(a,s,JSON.stringify(r),this._productId);case 13:return o=e.sent,e.abrupt("break",19);case 15:return e.next=17,this._services.transport.delete(a,s,null,this._productId);case 17:return o=e.sent,e.abrupt("break",19);case 19:if(!(o.status.code<200||o.status.code>=300)){e.next=21;break}throw new Error("Request responded with a non-success code ".concat(o.status.code));case 21:return e.abrupt("return",o);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"fetchResource",value:(n=Sa(bl.mark((function e(t,n){var r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=1,e.next=4,new Fg({min:50,max:1600,maxAttemptsCount:6}).run((function(){return i._makeRequest("get",t,n)}));case 4:r=e.sent,e.next=10;break;case 7:throw e.prev=7,e.t0=e.catch(1),new Error('Fetch resource from "'.concat(t,'" failed.'));case 10:return e.abrupt("return",r.body);case 11:case"end":return e.stop()}}),e,null,[[1,7]])}))),function(e,t){return n.apply(this,arguments)})},{key:"mutateResource",value:(t=Sa(bl.mark((function e(t,n,r){var i;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._makeRequest(t,n,r,{"X-Twilio-Mutation-Id":Ob.v4()});case 2:if(202!==(i=e.sent).status.code){e.next=7;break}return e.next=6,this.fetchResource(i.body.resource_url);case 6:return e.abrupt("return",e.sent);case 7:return e.abrupt("return",i.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,n,r){return t.apply(this,arguments)})}]),e}();function VA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function $A(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?VA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):VA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function KA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var HA=rd.scope("Client"),YA="2.0.0-rc.3",QA=function e(){Ma(this,e)};return e.Client=(WA=qA=function(e){Oa(Client,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v=KA(Client);function Client(e){var t,n,r,i,a,s,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Ma(this,Client),ja(Ra(s=v.call(this)),"connectionState","unknown"),ja(Ra(s),"conversationsPromise",null),ja(Ra(s),"_ensureReady",null),ja(Ra(s),"_resolveEnsureReady",null),ja(Ra(s),"_rejectEnsureReady",null),ja(Ra(s),"version",YA),ja(Ra(s),"parsePushNotification",zA.parsePushNotification),s.fpaToken=e,s.options=o,!s.options.disableDeepClone){var u=$A($A({},s.options),{},{transport:void 0,twilsockClient:void 0});(u=Bh(u)).transport=s.options.transport,u.twilsockClient=s.options.twilsockClient,s.options=u}s.options.logLevel=null!==(t=s.options.logLevel)&&void 0!==t?t:"silent",HA.setLevel(s.options.logLevel);var c=s.options.productId="ip_messaging";if(s.options.clientMetadata=s.options.clientMetadata||{},s.options.clientMetadata.hasOwnProperty("type")||(s.options.clientMetadata.type="conversations"),s.options.clientMetadata.hasOwnProperty("sdk")||(s.options.clientMetadata.sdk="JS",s.options.clientMetadata.sdkv=YA),s.options.Sync=s.options.Sync||{},void 0===s.options.Sync.enableSessionStorage&&(s.options.Sync.enableSessionStorage=!0),s.options.region&&(s.options.Sync.region=s.options.region),!e)throw new Error("A valid Twilio token should be provided");s.services=new QA,s._myself=new User("","",null,s.services);var l=!s.options.twilsockClient;if(!s.options.initRegistrations){var f=new Jg.InitRegistration(c);zA.populateInitRegistrations(f),s.options.initRegistrations=[f]}s.services.twilsockClient=s.options.twilsockClient=null!==(n=s.options.twilsockClient)&&void 0!==n?n:new Jg.TwilsockClient(e,c,s.options),s.services.twilsockClient.on("tokenAboutToExpire",(function(e){return s.emit("tokenAboutToExpire",e)})),s.services.twilsockClient.on("tokenExpired",(function(){return s.emit("tokenExpired")})),s.services.twilsockClient.on("connectionError",(function(e){return s.emit("connectionError",e)})),s.services.twilsockClient.on("stateChanged",(function(e){HA.debug("Handling stateChanged for ConversationsClient: new state ".concat(e)),e!==s.connectionState&&(s.connectionState=e,s.emit("connectionStateChanged",s.connectionState))})),s.services.transport=s.options.transport=null!==(r=s.options.transport)&&void 0!==r?r:s.options.twilsockClient,s.services.notificationClient=s.options.notificationsClient=null!==(i=s.options.notificationsClient)&&void 0!==i?i:new jE.Notifications(e,s.options),s.services.syncClient=s.options.syncClient=null!==(a=s.options.syncClient)&&void 0!==a?a:new hI(e,s.options);var d=o.Chat||o.IPMessaging||o||{},p=d.region||o.region,h=d.apiUri||d.typingUri||"https://aim.".concat(p||"us1",".twilio.com");s.services.commandExecutor=new JA(h,{transport:s.options.transport},c);var y=function(e){s._rejectEnsureReady(e),s.emit("stateChanged","failed")};return s.services.twilsockClient.once("connectionError",y),s.services.twilsockClient.once("disconnected",y),s.services.twilsockClient.once("connected",Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return HA.debug("ConversationsClient started INITIALIZING"),s.services.twilsockClient.off("connectionError",y),s.services.twilsockClient.off("disconnected",y),e.prev=3,t="conversations.client.startup",s.services.twilsockClient.addPartialTelemetryEvent(new Jg.TelemetryEventDescription(t,"Conversations client startup",new Date),t,Jg.TelemetryPoint.Start),e.next=8,s._initialize();case 8:s.services.twilsockClient.addPartialTelemetryEvent(new Jg.TelemetryEventDescription("","",new Date),t,Jg.TelemetryPoint.End),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(3),s._rejectEnsureReady(e.t0),s.emit("stateChanged","failed");case 15:case"end":return e.stop()}}),e,null,[[3,11]])})))),s._ensureReady=new Promise((function(e,t){s._resolveEnsureReady=e,s._rejectEnsureReady=t})).catch((function(e){})),l&&s.services.twilsockClient.connect(),s}return Ta(Client,[{key:"user",get:function(){return this._myself}},{key:"reachabilityEnabled",get:function(){if(!this.configuration)throw new Error("Reachability information could not yet be accessed as the client has not yet been initialized. Subscribe to the 'stateChanged' event to properly react to the client initialization.");return this.configuration.reachabilityEnabled}},{key:"token",get:function(){return this.fpaToken}},{key:"_subscribeToPushNotifications",value:function(e){var t=this;[Gg.NEW_MESSAGE,Gg.ADDED_TO_CONVERSATION,Gg.REMOVED_FROM_CONVERSATION,Gg.TYPING_INDICATOR,Gg.CONSUMPTION_UPDATE].forEach((function(n){t.services.notificationClient.subscribe(e,n)}))}},{key:"_unsubscribeFromPushNotifications",value:function(e){var t=this;[Gg.NEW_MESSAGE,Gg.ADDED_TO_CONVERSATION,Gg.REMOVED_FROM_CONVERSATION,Gg.TYPING_INDICATOR,Gg.CONSUMPTION_UPDATE].forEach((function(n){t.services.notificationClient.unsubscribe(e,n)}))}},{key:"_initialize",value:(h=Sa(bl.mark((function e(){var t,n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.fetchResource("Client/v2/Configuration");case 2:return t=e.sent,this.configuration=new hd(this.options,t,HA),this._myself._resolveInitialization(this.configuration,this.configuration.userIdentity,this.configuration.userInfo,!0),this.services.typingIndicator=new DA(this.getConversationBySid.bind(this),this.configuration,this.services),this.services.network=new zg(this.configuration,this.services),this.services.users=new NA(this._myself,this.configuration,this.services),this.services.users.on("userSubscribed",this.emit.bind(this,"userSubscribed")),this.services.users.on("userUpdated",(function(e){return n.emit("userUpdated",e)})),this.services.users.on("userUnsubscribed",this.emit.bind(this,"userUnsubscribed")),this.conversations=new OA(this.configuration,this.services),this.conversations.on("conversationAdded",this.emit.bind(this,"conversationAdded")),this.conversations.on("conversationRemoved",this.emit.bind(this,"conversationRemoved")),this.conversations.on("conversationJoined",this.emit.bind(this,"conversationJoined")),this.conversations.on("conversationLeft",this.emit.bind(this,"conversationLeft")),this.conversations.on("conversationUpdated",(function(e){return n.emit("conversationUpdated",e)})),this.conversations.on("participantJoined",this.emit.bind(this,"participantJoined")),this.conversations.on("participantLeft",this.emit.bind(this,"participantLeft")),this.conversations.on("participantUpdated",(function(e){return n.emit("participantUpdated",e)})),this.conversations.on("messageAdded",this.emit.bind(this,"messageAdded")),this.conversations.on("messageUpdated",(function(e){return n.emit("messageUpdated",e)})),this.conversations.on("messageRemoved",this.emit.bind(this,"messageRemoved")),this.conversations.on("typingStarted",this.emit.bind(this,"typingStarted")),this.conversations.on("typingEnded",this.emit.bind(this,"typingEnded")),this.conversationsPromise=this.conversations.fetchConversations().then((function(){return n.conversations})).catch((function(e){throw e})),e.next=28,this.services.users.myself._ensureFetched();case 28:zA.supportedPushChannels.forEach((function(e){return n._subscribeToPushNotifications(e)})),this.services.typingIndicator.initialize(),this.services.mcsClient=new bI.McsClient(this.fpaToken,this.configuration.links.mediaService,this.configuration.links.mediaSetService,$A($A({},this.options),{},{transport:null})),this._resolveEnsureReady(),this.emit("stateChanged","initialized");case 33:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"shutdown",value:(p=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.services.twilsockClient.disconnect();case 4:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"updateToken",value:(d=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:if(HA.info("updateToken"),this.fpaToken!==t){e.next=5;break}return e.abrupt("return",this);case 5:return e.next=7,this.services.twilsockClient.updateToken(t);case 7:return e.next=9,this.services.notificationClient.updateToken(t);case 9:return e.next=11,this.services.mcsClient.updateToken(t);case 11:return this.fpaToken=t,e.abrupt("return",this);case 13:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"getConversationBySid",value:(f=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.conversations.myConversationsRead.promise;case 4:return e.next=6,this.conversations.getConversation(t);case 6:if(n=e.sent){e.next=11;break}return e.next=10,this.conversations.peekConversation(t);case 10:n=e.sent;case 11:if(n){e.next=13;break}throw new Error("Conversation with SID ".concat(t," is not found."));case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(l=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.conversations.myConversationsRead.promise;case 4:return e.next=6,this.conversations.getConversationByUniqueName(t);case 6:if(n=e.sent){e.next=9;break}throw new Error("Conversation with unique name ".concat(t," is not found."));case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"getSubscribedConversations",value:(c=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.conversationsPromise.then((function(e){return e.getConversations(t)})));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"createConversation",value:(u=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return t=t||{},e.abrupt("return",this.conversationsPromise.then((function(e){return e.addConversation(t)})));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"setPushRegistrationId",value:(o=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this._subscribeToPushNotifications(t),this.services.notificationClient.setPushRegistrationId(t,n),e.next=6,this.services.notificationClient.commitChanges();case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"unsetPushRegistrationId",value:(s=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this._unsubscribeFromPushNotifications(t),e.next=5,this.services.notificationClient.commitChanges();case 5:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"removePushRegistrations",value:(a=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.notificationClient.removeRegistrations(t,n);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"handlePushNotification",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:HA.debug("handlePushNotification, notificationPayload=",t),this.emit("pushNotification",zA.parsePushNotification(t));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"getUser",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.services.users.getUser(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.services.users.getSubscribedUsers());case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})}],[{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([Gg.TYPING_INDICATOR]),hI.populateInitRegistrations(e)}},{key:"create",value:(t=Sa(bl.mark((function e(t,n){var r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==n||!n.twilsockClient){e.next=2;break}throw new Error("Obsolete usage of ConversationsClient.create() factory method: if you pass twilsock from the outside then you must use ConversationsClient constructor and be prepared to work with uninitialized client.");case 2:return r=new zA(t,n),e.next=5,r._ensureReady;case 5:return e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"parsePushNotificationChatData",value:function(e){var t={};for(var n in zA.supportedPushDataFields)void 0!==e[n]&&null!==e[n]&&("message_index"===n?null!==qh(e[n])&&(t[zA.supportedPushDataFields[n]]=Number(e[n])):t[zA.supportedPushDataFields[n]]=e[n]);return t}},{key:"parsePushNotification",value:function(e){if(HA.debug("parsePushNotification, notificationPayload=",e),void 0!==e.aps){if(!e.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var t=zA.parsePushNotificationChatData(e),n=e.aps,r=null,i=null;return"string"==typeof n.alert?r=n.alert||null:(r=n.alert.body||null,i=n.alert.title||null),new PushNotification({title:i,body:r,sound:n.sound||null,badge:n.badge||null,action:n.category||null,type:e.twi_message_type,data:t})}if(void 0!==e.data){var a=e.data;if(!a.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var s=zA.parsePushNotificationChatData(e.data);return new PushNotification({title:a.twi_title||null,body:a.twi_body||null,sound:a.twi_sound||null,badge:null,action:a.twi_action||null,type:a.twi_message_type,data:s})}throw new Error("Provided push notification payload is not Programmable Chat notification")}}]),Client}(lm),ja(qA,"version",YA),ja(qA,"supportedPushChannels",["fcm","apn"]),ja(qA,"supportedPushDataFields",{conversation_sid:"conversationSid",message_sid:"messageSid",message_index:"messageIndex"}),ja(qA,"conversationAdded","conversationAdded"),ja(qA,"conversationJoined","conversationJoined"),ja(qA,"conversationLeft","conversationLeft"),ja(qA,"conversationRemoved","conversationRemoved"),ja(qA,"conversationUpdated","conversationUpdated"),ja(qA,"participantJoined","participantJoined"),ja(qA,"participantLeft","participantLeft"),ja(qA,"participantUpdated","participantUpdated"),ja(qA,"messageAdded","messageAdded"),ja(qA,"messageRemoved","messageRemoved"),ja(qA,"messageUpdated","messageUpdated"),ja(qA,"tokenAboutToExpire","tokenAboutToExpire"),ja(qA,"tokenExpired","tokenExpired"),ja(qA,"typingEnded","typingEnded"),ja(qA,"typingStarted","typingStarted"),ja(qA,"pushNotification","pushNotification"),ja(qA,"userSubscribed","userSubscribed"),ja(qA,"userUnsubscribed","userUnsubscribed"),ja(qA,"userUpdated","userUpdated"),ja(qA,"stateChanged","stateChanged"),ja(qA,"connectionStateChanged","connectionStateChanged"),ja(qA,"connectionError","connectionError"),zA=WA),wl([Fy(jy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"updateToken",null),wl([Fy(jy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getConversationBySid",null),wl([Fy(jy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getConversationByUniqueName",null),wl([Fy(["undefined",Ly("conversation options",{friendlyName:["string","undefined"],isPrivate:["boolean","undefined"],uniqueName:["string","undefined"]})]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],e.Client.prototype,"createConversation",null),wl([Fy(Ay("fcm","apn"),"string"),xl("design:type",Function),xl("design:paramtypes",[String,String]),xl("design:returntype",Promise)],e.Client.prototype,"setPushRegistrationId",null),wl([Fy(Ay("fcm","apn")),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"unsetPushRegistrationId",null),wl([Fy(Ay("fcm","apn"),jy),xl("design:type",Function),xl("design:paramtypes",[String,String]),xl("design:returntype",Promise)],e.Client.prototype,"removePushRegistrations",null),wl([Fy(Ny),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],e.Client.prototype,"handlePushNotification",null),wl([Fy(jy),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getUser",null),wl([Fy("string",["undefined",Ny]),xl("design:type",Function),xl("design:paramtypes",[String,Object]),xl("design:returntype",Promise)],e.Client,"create",null),wl([Dy(Ny),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",PushNotification)],e.Client,"parsePushNotification",null),e.Client=zA=wl([Uy(jy,[Ny,"undefined"]),xl("design:paramtypes",[String,Object])],e.Client),e.AggregatedDeliveryReceipt=AggregatedDeliveryReceipt,e.Conversation=Conversation,e.DetailedDeliveryReceipt=DetailedDeliveryReceipt,e.Media=Media,e.Message=Message,e.MessageBuilder=vA,e.Participant=Participant,e.PushNotification=PushNotification,e.RestPaginator=sA,e.UnsentMessage=hA,e.User=User,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|