@twilio/conversations 3.0.0-canary.5 → 3.0.0-canary2.100
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/README.md +22 -18
- package/builds/browser.js +1360 -2410
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +74 -69
- package/builds/lib.js +1360 -2410
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +25229 -25615
- package/builds/twilio-conversations.min.js +1 -16
- package/dist/aggregated-delivery-receipt.js +1 -1
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/client.js +99 -70
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +30 -12
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js.map +1 -1
- package/dist/conversation.js +92 -23
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +21 -5
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +13 -19
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +6 -4
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +4 -2
- package/dist/data/users.js.map +1 -1
- package/dist/detailed-delivery-receipt.js.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces/attributes.js.map +1 -1
- package/dist/interfaces/notification-types.js.map +1 -1
- package/dist/logger.js +2 -4
- package/dist/logger.js.map +1 -1
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +24 -21
- package/dist/message.js.map +1 -1
- package/dist/node_modules/tslib/tslib.es6.js +1 -1
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/packages/conversations/package.json.js +1 -1
- package/dist/participant.js +2 -2
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +38 -15
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +7 -5
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +2 -2
- package/dist/user.js.map +1 -1
- package/dist/util/deferred.js.map +1 -1
- package/dist/util/index.js.map +1 -1
- package/package.json +27 -23
@@ -126,19 +126,4 @@ 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")||"",C=i,O=I,P=C.process,A=C.Deno,j=P&&P.versions||A&&A.version,M=j&&j.v8;M?p=(d=M.split("."))[0]<4?1:d[0]+d[1]:O&&(!(d=O.match(/Edge\/(\d+)/))||d[1]>=74)&&(d=O.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},z=S,W={exports:{}},G=i,$=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[J]||V(J,{}),H=K;(W.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=W.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)&&!z(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!z(r=n.call(e)))return r;if("string"!==t&&"function"==typeof(n=e.toString)&&!z(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,Ce=u,Oe=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 Oe(!Ce.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,ze=we,We=Object.defineProperty;Ne.f=Fe?We:function(e,t,n){if(qe(e),t=ze(t),qe(n),Be)try{return We(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,$e=h,Ve=o?function(e,t,n){return Ge.f(e,t,$e(1,n))}:function(e,t,n){return e[t]=n,e},Je={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=W.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=$,Rt=Ze,It=xt.get,Ct=xt.enforce,Ot=String(String).split("String");(Je.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=Ct(n)).source||(i.source=Ot.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)},zt=_,Wt=Ut,Gt=qt,$t=function(e){return function(t,n,r){var i,a=zt(t),s=Wt(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:$t(!0),indexOf:$t(!1)},Jt=ee,Kt=_,Ht=Vt.indexOf,Yt=ot,Qt=function(e,t){var n,r=Kt(e),i=0,a=[];for(n in r)!Jt(Yt,n)&&Jt(r,n)&&a.push(n);for(;t.length>i;)Jt(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=Je.exports,En=$,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)}},Cn=function(e){if("function"!=typeof e)throw TypeError(String(e)+" is not a function");return e},On=Qt,Pn=Xt,An=Object.keys||function(e){return On(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,zn=Un,Wn=Ee,Gn=st("IE_PROTO"),$n=function(){},Vn=function(e){return"<script>"+e+"</"+"script>"},Jn=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?Jn(nn):((t=Wn("iframe")).style.display="none",zn.appendChild(t),t.src=String("javascript:"),(e=t.contentWindow.document).open(),e.write(Vn("document.F=Object")),e.close(),e.F):Jn(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?($n.prototype=Dn(e),n=new $n,$n.prototype=null,n[Gn]=e):n=Kn(),void 0===t?n:Fn(n,t)},Yn=Cn,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=Cn,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,Cr=Ne.f,Or=function(e){var t=Tr.Symbol||(Tr.Symbol={});Rr(t,e)||Cr(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=Cn,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)},zr=Nr,Wr=b,Gr=Q,$r=Ut,Vr=qr,Jr=[].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=Wr(h),y=zr(c,l,3),m=$r(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:Jr.call(k,d)}else switch(e){case 4:return!1;case 7:Jr.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=Je.exports,xi=W.exports,_i=ot,Si=re,Ei=pe,Ti=Sr,Ri=Or,Ii=Mr,Ci=xt,Oi=Hr.forEach,Pi=st("hidden"),Ai="Symbol",ji=Ei("toPrimitive"),Mi=Ci.set,Li=Ci.getterFor(Ai),Ni=Object.prototype,Ui=Qr.Symbol,Di=Xr("JSON","stringify"),Fi=mi.f,Bi=gi.f,qi=vi.f,zi=bi.f,Wi=xi("symbols"),Gi=xi("op-symbols"),$i=xi("string-to-symbol-registry"),Vi=xi("symbol-to-string-registry"),Ji=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=Wi[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(Wi,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 Oi(r,(function(t){Zr&&!ea.call(n,t)||Xi(e,t,n[t])})),e},ea=function(e){var t=ci(e),n=zi.call(this,t);return!(this===Ni&&ni(Wi,t)&&!ni(Gi,t))&&(!(n||!ni(this,t)||!ni(Wi,t)||ni(this,Pi)&&this[Pi][t])||n)},ta=function(e,t){var n=ui(e),r=ci(t);if(n!==Ni||!ni(Wi,r)||ni(Gi,r)){var i=Fi(n,r);return!i||!ni(Wi,r)||ni(n,Pi)&&n[Pi][r]||(i.enumerable=!0),i}},na=function(e){var t=qi(ui(e)),n=[];return Oi(t,(function(e){ni(Wi,e)||ni(_i,e)||n.push(e)})),n},ra=function(e){var t=e===Ni,n=qi(t?Gi:ui(e)),r=[];return Oi(n,(function(e){!ni(Wi,e)||t&&!ni(Ni,e)||r.push(Wi[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}),Oi(pi(Ji),(function(e){Ri(e)})),Yr({target:Ai,stat:!0,forced:!ei},{for:function(e){var t=li(e);if(ni($i,t))return $i[t];var n=Ui(t);return $i[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 Ca(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 Oa(e){return(Oa="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"!==Oa(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},za=qa,Wa=Na?{}.toString:function(){return"[object "+za(this)+"]"},Ga=Na,$a=Je.exports,Va=Wa;Ga||$a(Object.prototype,"toString",Va,{unsafe:!0});var Ja=i.Promise,Ka=Je.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)},Cs=pe("iterator"),Os=!1;try{var Ps=0,As={next:function(){return{done:!!Ps++}},return:function(){Os=!0}};As[Cs]=function(){return this},Array.from(As,(function(){throw 2}))}catch(e){}var js,Ms,Ls,Ns,Us=function(e,t){if(!t&&!Os)return!1;var n=!1;try{var r={};r[Cs]=function(){return{next:function(){return{done:n=!0}}}},e(r)}catch(e){}return n},Ds=De,Fs=Cn,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)},zs=/(?:ipad|iphone|ipod).*applewebkit/i.test(I),Ws="process"==y(i.process),Gs=i,$s=s,Vs=Nr,Js=Un,Ks=Ee,Hs=zs,Ys=Ws,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&&!$s(uo)?(Ms=uo,Gs.addEventListener("message",oo,!1)):Ms=io in Ks("script")?function(e){Js.appendChild(Ks("script")).onreadystatechange=function(){Js.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=zs,To=ko,Ro=wo,Io=Ws,Co=xo.MutationObserver||xo.WebKitMutationObserver,Oo=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||!Co||!Oo?!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=Oo.createTextNode(""),new Co(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=Cn,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,zo,Wo=De,Go=S,$o=No,Vo=i,Jo="object"==typeof window,Ko=In,Ho=i,Yo=R,Qo=Ja,Xo=Je.exports,Zo=Ha,eu=Za,tu=Mr,nu=is,ru=S,iu=Cn,au=as,su=Ze,ou=Is,uu=Us,cu=qs,lu=go.set,fu=Lo,du=function(e,t){if(Wo(e),Go(t)&&t.constructor===e)return t;var n=$o.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=Jo,bu=Ws,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,Cu=Ho.TypeError,Ou=Ho.document,Pu=Ho.process,Au=hu.f,ju=Au,Mu=!!(Ou&&Ou.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&&$u(e),e.rejection=1),!0===l?s=r:(p&&p.enter(),s=l(r),p&&(p.exit(),u=!0)),s===c.promise?d(Cu("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&&Wu(e)}))}},zu=function(e,t,n){var r,i;Mu?((r=Ou.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)},Wu=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):zu(Nu,n,r)})),e.rejection=bu||Gu(e)?2:1,t.error))throw t.value}))},Gu=function(e){return 1!==e.rejection&&!e.parent},$u=function(e){lu.call(Ho,(function(){var t=e.facade;bu?Pu.emit("rejectionHandled",t):zu("rejectionhandled",t,e.value)}))},Vu=function(e,t,n){return function(r){e(t,r,n)}},Ju=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 Cu("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(Ju,n,e))}catch(t){Ju(n,t,e)}})):(e.value=t,e.state=1,qu(e,!1))}catch(t){Ju({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(Ju,t))}catch(e){Ju(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(Ju,t)},hu.f=Au=function(e){return e===Ru||e===qo?new Bo(e):ju(e)},"function"==typeof Qo&&Tu!==Object.prototype)){zo=Tu.then,Uu||(Xo(Tu,"then",(function(e,t){var n=this;return new Ru((function(e,t){zo.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=Hr.map;In({target:"Array",proto:!0,forced:!oa("map")},{map:function(e){return Hu(this,e,arguments.length>1?arguments[1]:void 0)}});var Yu={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},Qu=Ee("span").classList,Xu=Qu&&Qu.constructor&&Qu.constructor.prototype,Zu=Xu===Object.prototype?void 0:Xu,ec=s,tc=function(e,t){var n=[][e];return!!n&&ec((function(){n.call(null,t||function(){throw 1},1)}))},nc=Hr.forEach,rc=i,ic=Yu,ac=Zu,sc=tc("forEach")?[].forEach:function(e){return nc(this,e,arguments.length>1?arguments[1]:void 0)},oc=Ve,uc=function(e){if(e&&e.forEach!==sc)try{oc(e,"forEach",sc)}catch(t){e.forEach=sc}};for(var cc in ic)uc(rc[cc]&&rc[cc].prototype);uc(ac);var lc,fc=Object.prototype,dc=fc.hasOwnProperty,pc="function"==typeof Symbol?Symbol:{},hc=pc.iterator||"@@iterator",vc=pc.asyncIterator||"@@asyncIterator",yc=pc.toStringTag||"@@toStringTag";function mc(e,t,n,r){var i=t&&t.prototype instanceof Sc?t:Sc,a=Object.create(i.prototype),s=new Uc(r||[]);return a._invoke=function(e,t,n){var r=bc;return function(i,a){if(r===wc)throw new Error("Generator is already running");if(r===xc){if("throw"===i)throw a;return Fc()}for(n.method=i,n.arg=a;;){var s=n.delegate;if(s){var o=Mc(s,n);if(o){if(o===_c)continue;return o}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===bc)throw r=xc,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=wc;var u=gc(e,t,n);if("normal"===u.type){if(r=n.done?xc:kc,u.arg===_c)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=xc,n.method="throw",n.arg=u.arg)}}}(e,n,s),a}function gc(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}var bc="suspendedStart",kc="suspendedYield",wc="executing",xc="completed",_c={};function Sc(){}function Ec(){}function Tc(){}var Rc={};Rc[hc]=function(){return this};var Ic=Object.getPrototypeOf,Cc=Ic&&Ic(Ic(Dc([])));Cc&&Cc!==fc&&dc.call(Cc,hc)&&(Rc=Cc);var Oc=Tc.prototype=Sc.prototype=Object.create(Rc);function Pc(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function Ac(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===Ec||"GeneratorFunction"===(t.displayName||t.name))}function jc(e,t){function n(r,i,a,s){var o=gc(e[r],e,i);if("throw"!==o.type){var u=o.arg,c=u.value;return c&&"object"===Oa(c)&&dc.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 Mc(e,t){var n=e.iterator[t.method];if(n===lc){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=lc,Mc(e,t),"throw"===t.method))return _c;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return _c}var r=gc(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,_c;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=lc),t.delegate=null,_c):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,_c)}function Lc(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 Nc(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function Uc(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(Lc,this),this.reset(!0)}function Dc(e){if(e){var t=e[hc];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(dc.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=lc,t.done=!0,t};return r.next=r}}return{next:Fc}}function Fc(){return{value:lc,done:!0}}Ec.prototype=Oc.constructor=Tc,Tc.constructor=Ec,Tc[yc]=Ec.displayName="GeneratorFunction",Pc(jc.prototype),jc.prototype[vc]=function(){return this},Pc(Oc),Oc[yc]="Generator",Oc[hc]=function(){return this},Oc.toString=function(){return"[object Generator]"},Uc.prototype={constructor:Uc,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=lc,this.done=!1,this.delegate=null,this.method="next",this.arg=lc,this.tryEntries.forEach(Nc),!e)for(var t in this)"t"===t.charAt(0)&&dc.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=lc)},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=lc),!!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=dc.call(i,"catchLoc"),o=dc.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&&dc.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,_c):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),_c},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),Nc(n),_c}},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;Nc(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:Dc(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=lc),_c}};var Bc={wrap:mc,isGeneratorFunction:Ac,AsyncIterator:jc,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,Tc):(e.__proto__=Tc,yc in e||(e[yc]="GeneratorFunction")),e.prototype=Object.create(Oc),e},awrap:function(e){return{__await:e}},async:function(e,t,n,r,i){void 0===i&&(i=Promise);var a=new jc(mc(e,t,n,r),i);return Ac(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:Dc},qc=Object.freeze({__proto__:null,default:Bc});function zc(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":Oa(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 Wc(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Oa(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}var Gc=In,$c=s,Vc=yr,Jc=S,Kc=Q,Hc=Ut,Yc=ga,Qc=qr,Xc=oa,Zc=L,el=pe("isConcatSpreadable"),tl=9007199254740991,nl="Maximum allowed index exceeded",rl=Zc>=51||!$c((function(){var e=[];return e[el]=!1,e.concat()[0]!==e})),il=Xc("concat"),al=function(e){if(!Jc(e))return!1;var t=e[el];return void 0!==t?!!t:Vc(e)};Gc({target:"Array",proto:!0,forced:!rl||!il},{concat:function(e){var t,n,r,i,a,s=Kc(this),o=Qc(s,0),u=0;for(t=-1,r=arguments.length;t<r;t++)if(al(a=-1===t?s:arguments[t])){if(u+(i=Hc(a.length))>tl)throw TypeError(nl);for(n=0;n<i;n++,u++)n in a&&Yc(o,u,a[n])}else{if(u>=tl)throw TypeError(nl);Yc(o,u++,a)}return o.length=u,o}});var sl=De,ol=bs,ul=Nr,cl=Q,ll=function(e,t,n,r){try{return r?t(sl(n)[0],n[1]):t(n)}catch(t){ol(e,"throw",t)}},fl=ls,dl=Ut,pl=ga,hl=ms,vl=hs,yl=function(e){var t,n,r,i,a,s,o=cl(e),u="function"==typeof this?this:Array,c=arguments.length,l=c>1?arguments[1]:void 0,f=void 0!==l,d=vl(o),p=0;if(f&&(l=ul(l,c>2?arguments[2]:void 0,2)),null==d||u==Array&&fl(d))for(n=new u(t=dl(o.length));t>p;p++)s=f?l(o[p],p):o[p],pl(n,p,s);else for(a=(i=hl(o,d)).next,n=new u;!(r=a.call(i)).done;p++)s=f?ll(i,l,[r.value,p],!0):r.value,pl(n,p,s);return n.length=p,n},ml=yl;In({target:"Array",stat:!0,forced:!Us((function(e){Array.from(e)}))},{from:ml});var gl,bl,kl,wl=Mt,xl=gr,_l=k,Sl=function(e){return function(t,n){var r,i,a=xl(_l(t)),s=wl(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}},El={codeAt:Sl(!1),charAt:Sl(!0)},Tl=!s((function(){function e(){}return e.prototype.constructor=null,Object.getPrototypeOf(new e)!==e.prototype})),Rl=ee,Il=Q,Cl=Tl,Ol=st("IE_PROTO"),Pl=Object.prototype,Al=Cl?Object.getPrototypeOf:function(e){return e=Il(e),Rl(e,Ol)?e[Ol]:"function"==typeof e.constructor&&e instanceof e.constructor?e.constructor.prototype:e instanceof Object?Pl:null},jl=s,Ml=Al,Ll=Ve,Nl=pe("iterator"),Ul=!1;[].keys&&("next"in(kl=[].keys())?(bl=Ml(Ml(kl)))!==Object.prototype&&(gl=bl):Ul=!0),(null==gl||jl((function(){var e={};return gl[Nl].call(e)!==e})))&&(gl={}),"function"!=typeof gl[Nl]&&Ll(gl,Nl,(function(){return this}));var Dl={IteratorPrototype:gl,BUGGY_SAFARI_ITERATORS:Ul},Fl=Dl.IteratorPrototype,Bl=Hn,ql=h,zl=Mr,Wl=ss,Gl=function(){return this},$l=function(e,t,n){var r=t+" Iterator";return e.prototype=Bl(Fl,{next:ql(1,n)}),zl(e,r,!1),Wl[r]=Gl,e},Vl=In,Jl=$l,Kl=Al,Hl=Za,Yl=Mr,Ql=Ve,Xl=Je.exports,Zl=ss,ef=Dl.IteratorPrototype,tf=Dl.BUGGY_SAFARI_ITERATORS,nf=pe("iterator"),rf="keys",af="values",sf="entries",of=function(){return this},uf=function(e,t,n,r,i,a,s){Jl(n,t,r);var o,u,c,l=function(e){if(e===i&&v)return v;if(!tf&&e in p)return p[e];switch(e){case rf:case af:case sf: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=!tf&&h||l(i),y="Array"==t&&p.entries||h;if(y&&(o=Kl(y.call(new e)))!==Object.prototype&&o.next&&(Kl(o)!==ef&&(Hl?Hl(o,ef):"function"!=typeof o[nf]&&Ql(o,nf,of)),Yl(o,f,!0)),i==af&&h&&h.name!==af&&(d=!0,v=function(){return h.call(this)}),p[nf]!==v&&Ql(p,nf,v),Zl[t]=v,i)if(u={values:l(af),keys:a?v:l(rf),entries:l(sf)},s)for(c in u)(tf||d||!(c in p))&&Xl(p,c,u[c]);else Vl({target:t,proto:!0,forced:tf||d},u);return u},cf=El.charAt,lf=gr,ff=xt,df=uf,pf="String Iterator",hf=ff.set,vf=ff.getterFor(pf);df(String,"String",(function(e){hf(this,{type:pf,string:lf(e),index:0})}),(function(){var e,t=vf(this),n=t.string,r=t.index;return r>=n.length?{value:void 0,done:!0}:(e=cf(n,r),t.index+=e.length,{value:e,done:!1})}));var yf,mf,gf,bf={exports:{}};function kf(e,t){return["".concat((new Date).toISOString()," Conversations ").concat(e,":")].concat(Array.from(t))}mf=t,gf=function(){var e=function(){},t="undefined",n=("undefined"==typeof window?"undefined":Oa(window))!==t&&Oa(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":Oa(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":Oa(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":Oa(window))!==t&&u){try{e=window.localStorage[u]}catch(e){}if(Oa(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"===Oa(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":Oa(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":Oa(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"!==Oa(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":Oa(window))!==t?window.log:void 0;return f.noConflict=function(){return("undefined"==typeof window?"undefined":Oa(window))!==t&&window.log===f&&(window.log=p),f},f.getLoggers=function(){return d},f.default=f,f},(yf=bf).exports?yf.exports=gf():mf.log=gf();var wf,xf,_f=bf.exports.getLogger("twilio-conversations"),Sf=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){_f.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];_f.trace.apply(null,kf(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];_f.debug.apply(null,kf(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];_f.info.apply(null,kf(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];_f.warn.apply(null,kf(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];_f.error.apply(null,kf(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){_f.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];_f.trace.apply(null,kf("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];_f.debug.apply(null,kf("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];_f.info.apply(null,kf("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];_f.warn.apply(null,kf("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];_f.error.apply(null,kf("E",t))}}]),e}(),Ef={};Object.defineProperty(Ef,"__esModule",{value:!0});var Tf=["weeks","years","months","days","hours","minutes","seconds"],Rf=Ef.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)?)?)"),If=xf=Ef.parse=function(e){return e.match(Rf).slice(1).reduce((function(e,t,n){return e[Tf[n]]=parseFloat(t)||0,e}),{})},Cf=Ef.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},Of=wf=Ef.toSeconds=function(e,t){var n=t?t.getTime():Date.now(),r=new Date(n);return(Cf(e,r).getTime()-r.getTime())/1e3};function Pf(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 Af(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Pf(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Pf(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}Ef.default={end:Cf,toSeconds:Of,pattern:Rf,parse:If};var jf="PT5S",Mf="PT5S",Lf=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,emailHistoriesAllowedContentTypes:u.options.email_histories_allowed_mime_types,emailBodiesAllowedContentTypes:u.options.email_bodies_allowed_mime_types},this.typingIndicatorTimeoutOverride=l.typingIndicatorTimeoutOverride,this.backoffConfiguration=Af({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:jf;try{this.httpCacheInterval=wf(xf(f))}catch(e){c.error("Failed to parse http cache interval ".concat(f,", using default value ").concat(jf)),this.httpCacheInterval=wf(xf(jf))}var d=null!==(a=null!==(s=l.consumptionReportIntervalOverride)&&void 0!==s?s:u.options.consumption_report_interval)&&void 0!==a?a:Mf;try{this.consumptionReportInterval=wf(xf(d))}catch(e){c.error("Failed to parse consumption report interval ".concat(d,", using default value ").concat(Mf)),this.consumptionReportInterval=wf(xf(Mf))}},Nf=Hn,Uf=Ne,Df=pe("unscopables"),Ff=Array.prototype;null==Ff[Df]&&Uf.f(Ff,Df,{configurable:!0,value:Nf(null)});var Bf=function(e){Ff[Df][e]=!0},qf=_,zf=Bf,Wf=ss,Gf=xt,$f=uf,Vf="Array Iterator",Jf=Gf.set,Kf=Gf.getterFor(Vf),Hf=$f(Array,"Array",(function(e,t){Jf(this,{type:Vf,target:qf(e),index:0,kind:t})}),(function(){var e=Kf(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");Wf.Arguments=Wf.Array,zf("keys"),zf("values"),zf("entries");var Yf=i,Qf=Yu,Xf=Zu,Zf=Hf,ed=Ve,td=pe,nd=td("iterator"),rd=td("toStringTag"),id=Zf.values,ad=function(e,t){if(e){if(e[nd]!==id)try{ed(e,nd,id)}catch(t){e[nd]=id}if(e[rd]||ed(e,rd,t),Qf[t])for(var n in Zf)if(e[n]!==Zf[n])try{ed(e,n,Zf[n])}catch(t){e[n]=Zf[n]}}};for(var sd in Qf)ad(Yf[sd]&&Yf[sd].prototype,sd);ad(Xf,"DOMTokenList");var od=S,ud=Za,cd=function(e,t,n){var r,i;return ud&&"function"==typeof(r=t.constructor)&&r!==n&&od(i=r.prototype)&&i!==n.prototype&&ud(e,i),e},ld=k,fd=gr,dd="[\t\n\v\f\r \u2028\u2029\ufeff]",pd=RegExp("^"+dd+dd+"*"),hd=RegExp(dd+dd+"*$"),vd=function(e){return function(t){var n=fd(ld(t));return 1&e&&(n=n.replace(pd,"")),2&e&&(n=n.replace(hd,"")),n}},yd={start:vd(1),end:vd(2),trim:vd(3)},md=o,gd=i,bd=kn,kd=Je.exports,wd=ee,xd=y,_d=cd,Sd=q,Ed=ge,Td=s,Rd=Hn,Id=Pt.f,Cd=a.f,Od=Ne.f,Pd=yd.trim,Ad="Number",jd=gd.Number,Md=jd.prototype,Ld=xd(Rd(Md))==Ad,Nd=function(e){if(Sd(e))throw TypeError("Cannot convert a Symbol value to a number");var t,n,r,i,a,s,o,u,c=Ed(e,"number");if("string"==typeof c&&c.length>2)if(43===(t=(c=Pd(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(bd(Ad,!jd(" 0o1")||!jd("0b1")||jd("+0x1"))){for(var Ud,Dd=function(e){var t=arguments.length<1?0:e,n=this;return n instanceof Dd&&(Ld?Td((function(){Md.valueOf.call(n)})):xd(n)!=Ad)?_d(new jd(Nd(t)),n,Dd):Nd(t)},Fd=md?Id(jd):"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(","),Bd=0;Fd.length>Bd;Bd++)wd(jd,Ud=Fd[Bd])&&!wd(Dd,Ud)&&Od(Dd,Ud,Cd(jd,Ud));Dd.prototype=Md,Md.constructor=Dd,kd(gd,Ad,Dd)}var qd=De,zd=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},Wd={},Gd=s,$d=i.RegExp;Wd.UNSUPPORTED_Y=Gd((function(){var e=$d("a","y");return e.lastIndex=2,null!=e.exec("abcd")})),Wd.BROKEN_CARET=Gd((function(){var e=$d("^r","gy");return e.lastIndex=2,null!=e.exec("str")}));var Vd,Jd,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=zd,np=Wd,rp=W.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/,Jd=/b*/g,up.call(Vd,"a"),up.call(Jd,"a"),0!==Vd.lastIndex||0!==Jd.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=Je.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=El.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,Cp=/\$([$&'`]|\d{1,2})/g,Op=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"!==Op(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=Cp;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}))},zp=Ap,Wp=pe("replace"),Gp=Math.max,$p=Math.min,Vp="$0"==="a".replace(/./,"$0"),Jp=!!/./[Wp]&&""===/./[Wp]("a","$0");jp("replace",(function(e,t,n){var r=Jp?"$":"$0";return[function(e,n){var r=Fp(this),i=null==e?void 0:e[Wp];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=zp(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($p(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||Jp);var Kp=In,Hp=_,Yp=[].join,Qp=b!=Object,Xp=tc("join",",");function Zp(e){return JSON.parse(JSON.stringify(e))}function eh(e){return void 0===e||isNaN(Number(e))?null:Number(e)}function th(e){try{return new Date(e)}catch(e){return null}}function nh(e,t,n){var r={};if(e)try{r=JSON.parse(e)}catch(e){n.warn(t,e)}return r}Kp({target:"Array",proto:!0,forced:Qp||!Xp},{join:function(e){return Yp.call(Hp(this),void 0===e?",":e)}});var rh=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}(),ih={},ah=In,sh=S,oh=yr,uh=qt,ch=Ut,lh=_,fh=ga,dh=pe,ph=oa("slice"),hh=dh("species"),vh=[].slice,yh=Math.max;ah({target:"Array",proto:!0,forced:!ph},{slice:function(e,t){var n,r,i,a=lh(this),s=ch(a.length),o=uh(e,s),u=uh(void 0===t?s:t,s);if(oh(a)&&("function"!=typeof(n=a.constructor)||n!==Array&&!oh(n.prototype)?sh(n)&&null===(n=n[hh])&&(n=void 0):n=void 0,n===Array||void 0===n))return vh.call(a,o,u);for(r=new(void 0===n?Array:n)(yh(u-o,0)),i=0;o<u;o++,i++)o in a&&fh(r,i,a[o]);return r.length=i,r}});var mh=In,gh=o,bh=i,kh=ee,wh=S,xh=Ne.f,_h=dn,Sh=bh.Symbol;if(gh&&"function"==typeof Sh&&(!("description"in Sh.prototype)||void 0!==Sh().description)){var Eh={},Th=function(){var e=arguments.length<1||void 0===arguments[0]?void 0:String(arguments[0]),t=this instanceof Th?new Sh(e):void 0===e?Sh():Sh(e);return""===e&&(Eh[t]=!0),t};_h(Th,Sh);var Rh=Th.prototype=Sh.prototype;Rh.constructor=Th;var Ih=Rh.toString,Ch="Symbol(test)"==String(Sh("test")),Oh=/^Symbol\((.*)\)[^)]+$/;xh(Rh,"description",{configurable:!0,get:function(){var e=wh(this)?this.valueOf():this,t=Ih.call(e);if(kh(Eh,e))return"";var n=Ch?t.slice(7,-1):t.replace(Oh,"$1");return""===n?void 0:n}}),mh({global:!0,forced:!0},{Symbol:Th})}Or("iterator");var Ph={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}(Ph);var Ah=o,jh=Ne.f,Mh=Function.prototype,Lh=Mh.toString,Nh=/^\s*function ([^ (]*)/,Uh="name";Ah&&!(Uh in Mh)&&jh(Mh,Uh,{configurable:!0,get:function(){try{return Lh.call(this).match(Nh)[1]}catch(e){return""}}});var Dh=S,Fh=Math.floor,Bh=function(e){return!Dh(e)&&isFinite(e)&&Fh(e)===e};In({target:"Number",stat:!0},{isInteger:Bh});var qh={exports:{}},zh={exports:{}};!function(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.default=e.exports,e.exports.__esModule=!0}(zh);var Wh={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}(Wh);var Gh={exports:{}},$h={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}($h),function(e){var t=$h.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}(Gh);var Vh={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}(Vh),function(e){var t=zh.exports,n=Wh.exports,r=Gh.exports,i=Vh.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}(qh);var Jh=o,Kh=An,Hh=_,Yh=u.f,Qh=function(e){return function(t){for(var n,r=Hh(t),i=Kh(r),a=i.length,s=0,o=[];a>s;)n=i[s++],Jh&&!Yh.call(r,n)||o.push(e?[n,r[n]]:r[n]);return o}},Xh={entries:Qh(!0),values:Qh(!1)}.entries;In({target:"Object",stat:!0},{entries:function(e){return Xh(e)}});var Zh={exports:{}},ev={exports:{}};!function(e){var t=$h.exports;e.exports=function(e){if(Array.isArray(e))return t(e)},e.exports.default=e.exports,e.exports.__esModule=!0}(ev);var tv={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}(tv);var nv={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}(nv),function(e){var t=ev.exports,n=tv.exports,r=Gh.exports,i=nv.exports;e.exports=function(e){return t(e)||n(e)||r(e)||i()},e.exports.default=e.exports,e.exports.__esModule=!0}(Zh);var rv={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}(rv);var iv={exports:{}},av={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}(av),function(e){var t=av.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}(iv);var sv={exports:{}},ov={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}(ov),function(e){var t=Ph.exports.default,n=ov.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}(sv);var uv={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}(uv);var cv=Vt.includes,lv=Bf;In({target:"Array",proto:!0},{includes:function(e){return cv(this,e,arguments.length>1?arguments[1]:void 0)}}),lv("includes"),Object.defineProperty(ih,"__esModule",{value:!0});var fv=qh.exports,dv=Zh.exports,pv=rv.exports,hv=iv.exports,vv=sv.exports,yv=uv.exports;function mv(e){return e&&"object"===Oa(e)&&"default"in e?e:{default:e}}var gv=mv(Ph.exports),bv=mv(fv),kv=mv(dv),wv=mv(pv),xv=mv(hv),_v=mv(vv),Sv=mv(yv),Ev=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return{checks:t}};function Tv(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 Rv(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 Rv(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 Rv(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 Iv=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Ev((function(e){var n,r=!1,i=[],a=Tv(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||gv.default(e)===s,i.push("of type ".concat(s)))}}catch(e){a.e(e)}finally{a.f()}return[r,i]}))};function Cv(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 Ov(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 Ov(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 Ov(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=Ev((function(e){return["string"==typeof e&&e.length>0,"a non-empty string"]})),Av=Ev((function(e){return["number"==typeof e&&Number.isInteger(e)&&e>=0,"a non-negative integer"]})),jv=Ev((function(e){return["object"===gv.default(e)&&null!==e&&!Array.isArray(e),"a pure object (non-null and non-array)"]}));function Mv(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=Sv.default(e);if(t){var i=Sv.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _v.default(this,n)}}function Lv(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 Nv(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 Nv(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 Nv(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 Uv=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=Lv(t.entries());try{for(r.s();!(n=r.n()).done;){var i=bv.default(n.value,2),a=i[0],s=i[1],o=qv(e[a],s),u=bv.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()}},Dv=function(e){var t,n,r;(["undefined","boolean","number","bigint","string"].includes(gv.default(e))&&(n="string"==typeof e?'"'.concat(e,'"'):"".concat(e)),"object"===gv.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=gv.default(e)),n},Fv=function(e){var t,n=[],r=Lv(e);try{for(r.s();!(t=r.n()).done;){var i=t.value;n.push(Bv(i))}}catch(e){r.e(e)}finally{r.f()}return n},Bv=function(e){var t,n=[],r=Lv(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(Iv(i))}}catch(e){r.e(e)}finally{r.f()}return n},qv=function(e,t){var n,r,i=[],a=!1,s=Lv(e);try{for(s.s();!(r=s.n()).done;){var o,u=Lv(r.value.checks);try{for(u.s();!(o=u.n()).done;){var c=(0,o.value)(t),l=bv.default(c,3),f=l[0],d=l[1],p=l[2];a=a||f,!n&&p&&(n=p),d&&(i=[].concat(kv.default(i),"string"==typeof d?[d]:kv.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||Dv(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 zv(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 Wv(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 Wv(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 Wv(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}ih.array=function(e,t){return Ev((function(n){if(!Array.isArray(n))return[!1,"an array of ".concat(e)];var r,i=zv(n.entries());try{for(i.s();!(r=i.n()).done;){var a=bv.default(r.value,2),s=a[0],o=a[1],u=qv(Bv(t),o),c=bv.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 Gv=ih.custom=Ev,$v=ih.literal=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Ev((function(e){var n,r=!1,i=[],a=Cv(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]}))},Vv=ih.nonEmptyString=Pv,Jv=ih.nonNegativeInteger=Av,Kv=ih.objectSchema=function(e,t){return Ev((function(n){if("object"!==gv.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=bv.default(i[r],2),s=a[0],o=a[1],u=qv(Bv(o),n[s]),c=bv.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]}))},Hv=ih.pureObject=jv;ih.runtimeTypeValidation=Uv,ih.stringifyReceivedType=Dv,ih.type=Iv;var Yv=ih.validateConstructorTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Fv(t);return function(e){return function(e){xv.default(n,e);var t=Mv(n);function n(){wv.default(this,n);for(var e=arguments.length,i=new Array(e),a=0;a<e;a++)i[a]=arguments[a];return Uv(r,i),t.call.apply(t,[this].concat(i))}return n}(e)}},Qv=ih.validateTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Fv(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 Uv(r,t),i.apply(this,t)}}},Xv=ih.validateTypesAsync=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Fv(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{Uv(r,t)}catch(e){return Promise.reject(e)}return i.apply(this,t)}}},Zv=Gv((function(e){return[["string","number","boolean","object"].includes(Oa(e)),"a JSON type"]})),ey=Gv((function(e){return[["undefined","string","number","boolean","object"].includes(Oa(e)),"an optional JSON type"]})),ty={},ny={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}(ny);var ry={exports:{}},iy={exports:{}};!function(e){var t=uv.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}(iy),function(e){var t=iy.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}(ry);var ay={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}(ay),Object.defineProperty(ty,"__esModule",{value:!0});var sy=rv.exports,oy=ny.exports,uy=ov.exports,cy=ry.exports,ly=iv.exports,fy=sv.exports,dy=uv.exports,py=ay.exports;function hy(e){return e&&"object"===Oa(e)&&"default"in e?e:{default:e}}var vy=hy(Zh.exports),yy=hy(sy),my=hy(oy),gy=hy(uy),by=hy(cy),ky=hy(ly),wy=hy(fy),xy=hy(dy),_y=hy(py);function Sy(){}function Ey(){Ey.init.call(this)}function Ty(e){return void 0===e._maxListeners?Ey.defaultMaxListeners:e._maxListeners}function Ry(e,t,n){if(t)e.call(n);else for(var r=e.length,i=Ly(e,r),a=0;a<r;++a)i[a].call(n)}function Iy(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=Ly(e,i),s=0;s<i;++s)a[s].call(n,r)}function Cy(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=Ly(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function Oy(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=Ly(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function Py(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=Ly(e,i),s=0;s<i;++s)a[s].apply(n,r)}function Ay(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 Sy,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=Ty(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 jy(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 My(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 Ly(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function Ny(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=xy.default(e);if(t){var i=xy.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return wy.default(this,n)}}Sy.prototype=Object.create(null),Ey.EventEmitter=Ey,Ey.usingDomains=!1,Ey.prototype.domain=void 0,Ey.prototype._events=void 0,Ey.prototype._maxListeners=void 0,Ey.defaultMaxListeners=10,Ey.init=function(){this.domain=null,Ey.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new Sy,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Ey.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},Ey.prototype.getMaxListeners=function(){return Ty(this)},Ey.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:Ry(n,l,this);break;case 2:Iy(n,l,this,arguments[1]);break;case 3:Cy(n,l,this,arguments[1],arguments[2]);break;case 4:Oy(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];Py(n,l,this,i)}return!0},Ey.prototype.addListener=function(e,t){return Ay(this,e,t,!1)},Ey.prototype.on=Ey.prototype.addListener,Ey.prototype.prependListener=function(e,t){return Ay(this,e,t,!0)},Ey.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,jy(this,e,t)),this},Ey.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,jy(this,e,t)),this},Ey.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 Sy:(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 Sy,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},Ey.prototype.off=function(e,t){return this.removeListener(e,t)},Ey.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new Sy,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new Sy: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 Sy,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},Ey.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):[]},Ey.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):My.call(e,t)},Ey.prototype.listenerCount=My,Ey.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var Uy=function(e){ky.default(n,e);var t=Ny(n);function n(){var e;return yy.default(this,n),e=t.call(this),_y.default(gy.default(e),"eventHistory",new Map),e}return my.default(n,[{key:"on",value:function(e,t){return by.default(xy.default(n.prototype),"on",this).call(this,e,t)}},{key:"once",value:function(e,t){return by.default(xy.default(n.prototype),"once",this).call(this,e,t)}},{key:"off",value:function(e,t){return by.default(xy.default(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=by.default(xy.default(n.prototype),"emit",this)).call.apply(t,[this,e].concat(i))}},{key:"addListener",value:function(e,t){return by.default(xy.default(n.prototype),"addListener",this).call(this,e,t)}},{key:"removeListener",value:function(e,t){return by.default(xy.default(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,vy.default(n)),this.addListener(e,t)}},{key:"onWithReplay",value:function(e,t){return this.addListenerWithReplay(e,t)}},{key:"onceWithReplay",value:function(e,t){var r=this.eventHistory.get(e);return void 0!==r?(t.apply(void 0,vy.default(r)),this):by.default(xy.default(n.prototype),"once",this).call(this,e,t)}}]),n}(Ey),Dy=ty.ReplayEventEmitter=Uy,Fy={exports:{}};!function(e,n){var r="__lodash_hash_undefined__",i=9007199254740991,a="[object Arguments]",s="[object Array]",o="[object Boolean]",u="[object Date]",c="[object Error]",l="[object Function]",f="[object Map]",d="[object Number]",p="[object Object]",h="[object Promise]",v="[object RegExp]",y="[object Set]",m="[object String]",g="[object Symbol]",b="[object WeakMap]",k="[object ArrayBuffer]",w="[object DataView]",x=/^\[object .+?Constructor\]$/,_=/^(?:0|[1-9]\d*)$/,S={};S["[object Float32Array]"]=S["[object Float64Array]"]=S["[object Int8Array]"]=S["[object Int16Array]"]=S["[object Int32Array]"]=S["[object Uint8Array]"]=S["[object Uint8ClampedArray]"]=S["[object Uint16Array]"]=S["[object Uint32Array]"]=!0,S[a]=S[s]=S[k]=S[o]=S[w]=S[u]=S[c]=S[l]=S[f]=S[d]=S[p]=S[v]=S[y]=S[m]=S[b]=!1;var E="object"==Oa(t)&&t&&t.Object===Object&&t,T="object"==("undefined"==typeof self?"undefined":Oa(self))&&self&&self.Object===Object&&self,R=E||T||Function("return this")(),I=n&&!n.nodeType&&n,C=I&&e&&!e.nodeType&&e,O=C&&C.exports===I,P=O&&E.process,A=function(){try{return P&&P.binding&&P.binding("util")}catch(e){}}(),j=A&&A.isTypedArray;function M(e,t){for(var n=-1,r=null==e?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}function L(e,t){return e.has(t)}function N(e){var t=-1,n=Array(e.size);return e.forEach((function(e,r){n[++t]=[r,e]})),n}function U(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n}var D,F,B=Array.prototype,q=Function.prototype,z=Object.prototype,W=R["__core-js_shared__"],G=q.toString,$=z.hasOwnProperty,V=function(){var e=/[^.]+$/.exec(W&&W.keys&&W.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),J=z.toString,K=RegExp("^"+G.call($).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),H=O?R.Buffer:void 0,Y=R.Symbol,Q=R.Uint8Array,X=z.propertyIsEnumerable,Z=B.splice,ee=Y?Y.toStringTag:void 0,te=Object.getOwnPropertySymbols,ne=H?H.isBuffer:void 0,re=(D=Object.keys,F=Object,function(e){return D(F(e))}),ie=Ae(R,"DataView"),ae=Ae(R,"Map"),se=Ae(R,"Promise"),oe=Ae(R,"Set"),ue=Ae(R,"WeakMap"),ce=Ae(Object,"create"),le=Ne(ie),fe=Ne(ae),de=Ne(se),pe=Ne(oe),he=Ne(ue),ve=Y?Y.prototype:void 0,ye=ve?ve.valueOf:void 0;function me(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function ge(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function be(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function ke(e){var t=-1,n=null==e?0:e.length;for(this.__data__=new be;++t<n;)this.add(e[t])}function we(e){var t=this.__data__=new ge(e);this.size=t.size}function xe(e,t){var n=Fe(e),r=!n&&De(e),i=!n&&!r&&Be(e),a=!n&&!r&&!i&&$e(e),s=n||r||i||a,o=s?function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],u=o.length;for(var c in e)!t&&!$.call(e,c)||s&&("length"==c||i&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||Le(c,u))||o.push(c);return o}function _e(e,t){for(var n=e.length;n--;)if(Ue(e[n][0],t))return n;return-1}function Se(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":ee&&ee in Object(e)?function(e){var t=$.call(e,ee),n=e[ee];try{e[ee]=void 0;var r=!0}catch(e){}var i=J.call(e);r&&(t?e[ee]=n:delete e[ee]);return i}(e):function(e){return J.call(e)}(e)}function Ee(e){return Ge(e)&&Se(e)==a}function Te(e,t,n,r,i){return e===t||(null==e||null==t||!Ge(e)&&!Ge(t)?e!=e&&t!=t:function(e,t,n,r,i,l){var h=Fe(e),b=Fe(t),x=h?s:Me(e),_=b?s:Me(t),S=(x=x==a?p:x)==p,E=(_=_==a?p:_)==p,T=x==_;if(T&&Be(e)){if(!Be(t))return!1;h=!0,S=!1}if(T&&!S)return l||(l=new we),h||$e(e)?Ce(e,t,n,r,i,l):function(e,t,n,r,i,a,s){switch(n){case w:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case k:return!(e.byteLength!=t.byteLength||!a(new Q(e),new Q(t)));case o:case u:case d:return Ue(+e,+t);case c:return e.name==t.name&&e.message==t.message;case v:case m:return e==t+"";case f:var l=N;case y:var p=1&r;if(l||(l=U),e.size!=t.size&&!p)return!1;var h=s.get(e);if(h)return h==t;r|=2,s.set(e,t);var b=Ce(l(e),l(t),r,i,a,s);return s.delete(e),b;case g:if(ye)return ye.call(e)==ye.call(t)}return!1}(e,t,x,n,r,i,l);if(!(1&n)){var R=S&&$.call(e,"__wrapped__"),I=E&&$.call(t,"__wrapped__");if(R||I){var C=R?e.value():e,O=I?t.value():t;return l||(l=new we),i(C,O,n,r,l)}}if(!T)return!1;return l||(l=new we),function(e,t,n,r,i,a){var s=1&n,o=Oe(e),u=o.length,c=Oe(t).length;if(u!=c&&!s)return!1;var l=u;for(;l--;){var f=o[l];if(!(s?f in t:$.call(t,f)))return!1}var d=a.get(e);if(d&&a.get(t))return d==t;var p=!0;a.set(e,t),a.set(t,e);var h=s;for(;++l<u;){var v=e[f=o[l]],y=t[f];if(r)var m=s?r(y,v,f,t,e,a):r(v,y,f,e,t,a);if(!(void 0===m?v===y||i(v,y,n,r,a):m)){p=!1;break}h||(h="constructor"==f)}if(p&&!h){var g=e.constructor,b=t.constructor;g==b||!("constructor"in e)||!("constructor"in t)||"function"==typeof g&&g instanceof g&&"function"==typeof b&&b instanceof b||(p=!1)}return a.delete(e),a.delete(t),p}(e,t,n,r,i,l)}(e,t,n,r,Te,i))}function Re(e){return!(!We(e)||function(e){return!!V&&V in e}(e))&&(qe(e)?K:x).test(Ne(e))}function Ie(e){if(n=(t=e)&&t.constructor,r="function"==typeof n&&n.prototype||z,t!==r)return re(e);var t,n,r,i=[];for(var a in Object(e))$.call(e,a)&&"constructor"!=a&&i.push(a);return i}function Ce(e,t,n,r,i,a){var s=1&n,o=e.length,u=t.length;if(o!=u&&!(s&&u>o))return!1;var c=a.get(e);if(c&&a.get(t))return c==t;var l=-1,f=!0,d=2&n?new ke:void 0;for(a.set(e,t),a.set(t,e);++l<o;){var p=e[l],h=t[l];if(r)var v=s?r(h,p,l,t,e,a):r(p,h,l,e,t,a);if(void 0!==v){if(v)continue;f=!1;break}if(d){if(!M(t,(function(e,t){if(!L(d,t)&&(p===e||i(p,e,n,r,a)))return d.push(t)}))){f=!1;break}}else if(p!==h&&!i(p,h,n,r,a)){f=!1;break}}return a.delete(e),a.delete(t),f}function Oe(e){return function(e,t,n){var r=t(e);return Fe(e)?r:function(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}(r,n(e))}(e,Ve,je)}function Pe(e,t){var n=e.__data__;return function(e){var t=Oa(e);return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}(t)?n["string"==typeof t?"string":"hash"]:n.map}function Ae(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return Re(n)?n:void 0}me.prototype.clear=function(){this.__data__=ce?ce(null):{},this.size=0},me.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},me.prototype.get=function(e){var t=this.__data__;if(ce){var n=t[e];return n===r?void 0:n}return $.call(t,e)?t[e]:void 0},me.prototype.has=function(e){var t=this.__data__;return ce?void 0!==t[e]:$.call(t,e)},me.prototype.set=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=ce&&void 0===t?r:t,this},ge.prototype.clear=function(){this.__data__=[],this.size=0},ge.prototype.delete=function(e){var t=this.__data__,n=_e(t,e);return!(n<0)&&(n==t.length-1?t.pop():Z.call(t,n,1),--this.size,!0)},ge.prototype.get=function(e){var t=this.__data__,n=_e(t,e);return n<0?void 0:t[n][1]},ge.prototype.has=function(e){return _e(this.__data__,e)>-1},ge.prototype.set=function(e,t){var n=this.__data__,r=_e(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this},be.prototype.clear=function(){this.size=0,this.__data__={hash:new me,map:new(ae||ge),string:new me}},be.prototype.delete=function(e){var t=Pe(this,e).delete(e);return this.size-=t?1:0,t},be.prototype.get=function(e){return Pe(this,e).get(e)},be.prototype.has=function(e){return Pe(this,e).has(e)},be.prototype.set=function(e,t){var n=Pe(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this},ke.prototype.add=ke.prototype.push=function(e){return this.__data__.set(e,r),this},ke.prototype.has=function(e){return this.__data__.has(e)},we.prototype.clear=function(){this.__data__=new ge,this.size=0},we.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},we.prototype.get=function(e){return this.__data__.get(e)},we.prototype.has=function(e){return this.__data__.has(e)},we.prototype.set=function(e,t){var n=this.__data__;if(n instanceof ge){var r=n.__data__;if(!ae||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new be(r)}return n.set(e,t),this.size=n.size,this};var je=te?function(e){return null==e?[]:(e=Object(e),function(e,t){for(var n=-1,r=null==e?0:e.length,i=0,a=[];++n<r;){var s=e[n];t(s,n,e)&&(a[i++]=s)}return a}(te(e),(function(t){return X.call(e,t)})))}:function(){return[]},Me=Se;function Le(e,t){return!!(t=null==t?i:t)&&("number"==typeof e||_.test(e))&&e>-1&&e%1==0&&e<t}function Ne(e){if(null!=e){try{return G.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function Ue(e,t){return e===t||e!=e&&t!=t}(ie&&Me(new ie(new ArrayBuffer(1)))!=w||ae&&Me(new ae)!=f||se&&Me(se.resolve())!=h||oe&&Me(new oe)!=y||ue&&Me(new ue)!=b)&&(Me=function(e){var t=Se(e),n=t==p?e.constructor:void 0,r=n?Ne(n):"";if(r)switch(r){case le:return w;case fe:return f;case de:return h;case pe:return y;case he:return b}return t});var De=Ee(function(){return arguments}())?Ee:function(e){return Ge(e)&&$.call(e,"callee")&&!X.call(e,"callee")},Fe=Array.isArray;var Be=ne||function(){return!1};function qe(e){if(!We(e))return!1;var t=Se(e);return t==l||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}function ze(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=i}function We(e){var t=Oa(e);return null!=e&&("object"==t||"function"==t)}function Ge(e){return null!=e&&"object"==Oa(e)}var $e=j?function(e){return function(t){return e(t)}}(j):function(e){return Ge(e)&&ze(e.length)&&!!S[Se(e)]};function Ve(e){return null!=(t=e)&&ze(t.length)&&!qe(t)?xe(e):Ie(e);var t}e.exports=function(e,t){return Te(e,t)}}(Fy,Fy.exports);var By=Fy.exports;function qy(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 zy=Sf.scope("User"),User=function(e){Ca(User,e);var t,n,r,i,a,s,o,u=qy(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(Bc.mark((function e(t,n){var r,i;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:r=[],zy.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=nh(n.value,"Retrieved malformed attributes from the server for user: ".concat(this.state.identity),zy),By(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(Bc.mark((function e(t,n){var r=this;return Bc.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){zy.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(Bc.mark((function e(){var t=this;return Bc.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 zy.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 zy.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(Bc.mark((function e(){return Bc.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(Bc.mark((function e(t){return Bc.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(Bc.mark((function e(t){return Bc.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(Bc.mark((function e(){return Bc.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}(Dy);function Wy(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 Gy(e,t){if(e){if("string"==typeof e)return Wy(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)?Wy(e,t):void 0}}function $y(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)||Gy(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.")}()}zc([Xv(Zv),Wc("design:type",Function),Wc("design:paramtypes",[Object]),Wc("design:returntype",Promise)],User.prototype,"updateAttributes",null),zc([Xv(["string"]),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],User.prototype,"updateFriendlyName",null);var Vy={exports:{}},Jy=!s((function(){return Object.isExtensible(Object.preventExtensions({}))})),Ky=In,Hy=ot,Yy=S,Qy=ee,Xy=Ne.f,Zy=Pt,em=br,tm=Jy,nm=!1,rm=re("meta"),im=0,am=Object.isExtensible||function(){return!0},sm=function(e){Xy(e,rm,{value:{objectID:"O"+im++,weakData:{}}})},om=Vy.exports={enable:function(){om.enable=function(){},nm=!0;var e=Zy.f,t=[].splice,n={};n[rm]=1,e(n).length&&(Zy.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},Ky({target:"Object",stat:!0,forced:!0},{getOwnPropertyNames:em.f}))},fastKey:function(e,t){if(!Yy(e))return"symbol"==typeof e?e:("string"==typeof e?"S":"P")+e;if(!Qy(e,rm)){if(!am(e))return"F";if(!t)return"E";sm(e)}return e[rm].objectID},getWeakData:function(e,t){if(!Qy(e,rm)){if(!am(e))return!0;if(!t)return!1;sm(e)}return e[rm].weakData},onFreeze:function(e){return tm&&nm&&am(e)&&!Qy(e,rm)&&sm(e),e}};Hy[rm]=!0;var um=In,cm=i,lm=kn,fm=Je.exports,dm=Vy.exports,pm=Is,hm=as,vm=S,ym=s,mm=Us,gm=Mr,bm=cd,km=function(e,t,n){var r=-1!==e.indexOf("Map"),i=-1!==e.indexOf("Weak"),a=r?"set":"add",s=cm[e],o=s&&s.prototype,u=s,c={},l=function(e){var t=o[e];fm(o,e,"add"==e?function(e){return t.call(this,0===e?0:e),this}:"delete"==e?function(e){return!(i&&!vm(e))&&t.call(this,0===e?0:e)}:"get"==e?function(e){return i&&!vm(e)?void 0:t.call(this,0===e?0:e)}:"has"==e?function(e){return!(i&&!vm(e))&&t.call(this,0===e?0:e)}:function(e,n){return t.call(this,0===e?0:e,n),this})};if(lm(e,"function"!=typeof s||!(i||o.forEach&&!ym((function(){(new s).entries().next()})))))u=n.getConstructor(t,e,r,a),dm.enable();else if(lm(e,!0)){var f=new u,d=f[a](i?{}:-0,1)!=f,p=ym((function(){f.has(1)})),h=mm((function(e){new s(e)})),v=!i&&ym((function(){for(var e=new s,t=5;t--;)e[a](t,t);return!e.has(-0)}));h||((u=t((function(t,n){hm(t,u,e);var i=bm(new s,t,u);return null!=n&&pm(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,um({global:!0,forced:u!=s},c),gm(u,e),i||n.setStrong(u,e,r),u},wm=Ne.f,xm=Hn,_m=Ha,Sm=Nr,Em=as,Tm=Is,Rm=uf,Im=is,Cm=o,Om=Vy.exports.fastKey,Pm=xt.set,Am=xt.getterFor,jm={getConstructor:function(e,t,n,r){var i=e((function(e,a){Em(e,i,t),Pm(e,{type:t,index:xm(null),first:void 0,last:void 0,size:0}),Cm||(e.size=0),null!=a&&Tm(a,e[r],{that:e,AS_ENTRIES:n})})),a=Am(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=Om(t,!0),key:t,value:n,previous:r=s.last,next:void 0,removed:!1},s.first||(s.first=u),r&&(r.next=u),Cm?s.size++:e.size++,"F"!==i&&(s.index[i]=u)),e},o=function(e,t){var n,r=a(e),i=Om(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,Cm?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),Cm?n.size--:t.size--}return!!r},forEach:function(e){for(var t,n=a(this),r=Sm(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)}}),Cm&&wm(i.prototype,"size",{get:function(){return a(this).size}}),i},setStrong:function(e,t,n){var r=t+" Iterator",i=Am(t),a=Am(r);Rm(e,t,(function(e,t){Pm(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),Im(t)}};km("Map",(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),jm);var Mm={};Object.defineProperty(Mm,"__esModule",{value:!0});var Lm=ny.exports,Nm=ov.exports,Um=iv.exports,Dm=sv.exports,Fm=uv.exports,Bm=ay.exports;function qm(e){return e&&"object"===Oa(e)&&"default"in e?e:{default:e}}var zm=qm(rv.exports),Wm=qm(Lm),Gm=qm(Nm),$m=qm(Um),Vm=qm(Dm),Jm=qm(Fm),Km=qm(Bm);function Hm(){}function Ym(){Ym.init.call(this)}function Qm(e){return void 0===e._maxListeners?Ym.defaultMaxListeners:e._maxListeners}function Xm(e,t,n){if(t)e.call(n);else for(var r=e.length,i=sg(e,r),a=0;a<r;++a)i[a].call(n)}function Zm(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=sg(e,i),s=0;s<i;++s)a[s].call(n,r)}function eg(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=sg(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function tg(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=sg(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function ng(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=sg(e,i),s=0;s<i;++s)a[s].apply(n,r)}function rg(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 Hm,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=Qm(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 ig(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 ag(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 sg(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function og(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=Jm.default(e);if(t){var i=Jm.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Vm.default(this,n)}}Hm.prototype=Object.create(null),Ym.EventEmitter=Ym,Ym.usingDomains=!1,Ym.prototype.domain=void 0,Ym.prototype._events=void 0,Ym.prototype._maxListeners=void 0,Ym.defaultMaxListeners=10,Ym.init=function(){this.domain=null,Ym.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new Hm,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Ym.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},Ym.prototype.getMaxListeners=function(){return Qm(this)},Ym.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:Xm(n,l,this);break;case 2:Zm(n,l,this,arguments[1]);break;case 3:eg(n,l,this,arguments[1],arguments[2]);break;case 4:tg(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];ng(n,l,this,i)}return!0},Ym.prototype.addListener=function(e,t){return rg(this,e,t,!1)},Ym.prototype.on=Ym.prototype.addListener,Ym.prototype.prependListener=function(e,t){return rg(this,e,t,!0)},Ym.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,ig(this,e,t)),this},Ym.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,ig(this,e,t)),this},Ym.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 Hm:(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 Hm,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},Ym.prototype.off=function(e,t){return this.removeListener(e,t)},Ym.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new Hm,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new Hm: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 Hm,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},Ym.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):[]},Ym.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):ag.call(e,t)},Ym.prototype.listenerCount=ag,Ym.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var ug=function(e){$m.default(n,e);var t=og(n);function n(e){var r;return zm.default(this,n),r=t.call(this),Km.default(Gm.default(r),"timeout",null),Km.default(Gm.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 Wm.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}(Ym),cg=function(e){$m.default(n,e);var t=og(n);function n(e){var r;return zm.default(this,n),r=t.call(this),Km.default(Gm.default(r),"resolve",(function(){})),Km.default(Gm.default(r),"reject",(function(){})),r.retrier=new ug(e),r}return Wm.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}(Ym);function lg(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=Jm.default(e);if(t){var i=Jm.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Vm.default(this,n)}}function fg(e){return null!=e}var dg=function(e){$m.default(n,e);var t=lg(n);function n(e){var r;zm.default(this,n),r=t.call(this),Km.default(Gm.default(r),"backoffDelay",0),Km.default(Gm.default(r),"nextBackoffDelay",0),Km.default(Gm.default(r),"backoffNumber",0),Km.default(Gm.default(r),"timeoutID",null),Km.default(Gm.default(r),"maxNumberOfRetry",-1);var i=e=e||{},a=i.initialDelay,s=i.maxDelay,o=i.randomisationFactor,u=i.factor;if(fg(a)&&a<1)throw new Error("The initial timeout must be equal to or greater than 1.");if(fg(s)&&s<=1)throw new Error("The maximal timeout must be greater than 1.");if(fg(o)&&(o<0||o>1))throw new Error("The randomisation factor must be between 0 and 1.");if(fg(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 Wm.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}(Ym),pg=Mm.AsyncRetrier=cg;Mm.Backoff=dg;var hg=Mm.Retrier=ug;function vg(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 yg(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 yg(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 yg(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 mg=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=vg(this.cache);try{for(t.s();!(e=t.n()).done;){var n=$y(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 hg(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(Bc.mark((function e(t){var n,r,i,a=this;return Bc.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 bg={},kg={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}(kg);var wg=n(qc),xg=Je.exports,_g=De,Sg=gr,Eg=s,Tg=zd,Rg="toString",Ig=RegExp.prototype,Cg=Ig.toString,Og=Eg((function(){return"/a/b"!=Cg.call({source:"a",flags:"b"})})),Pg=Cg.name!=Rg;(Og||Pg)&&xg(RegExp.prototype,Rg,(function(){var e=_g(this),t=Sg(e.source),n=e.flags;return"/"+t+"/"+Sg(void 0===n&&e instanceof RegExp&&!("flags"in Ig)?Tg.call(e):n)}),{unsafe:!0}),km("Set",(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),jm);var Ag={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"===Oa(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"===Oa(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"!==Oa(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()}(Ag);var jg={exports:{}},Mg="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(Mg){var Lg=new Uint8Array(16);jg.exports=function(){return Mg(Lg),Lg}}else{var Ng=new Array(16);jg.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),Ng[t]=e>>>((3&t)<<3)&255;return Ng}}for(var Ug=[],Dg=0;Dg<256;++Dg)Ug[Dg]=(Dg+256).toString(16).substr(1);var Fg,Bg,qg=function(e,t){var n=t||0,r=Ug;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("")},zg=jg.exports,Wg=qg,Gg=0,$g=0;var Vg=function(e,t,n){var r=t&&n||0,i=t||[],a=(e=e||{}).node||Fg,s=void 0!==e.clockseq?e.clockseq:Bg;if(null==a||null==s){var o=zg();null==a&&(a=Fg=[1|o[0],o[1],o[2],o[3],o[4],o[5]]),null==s&&(s=Bg=16383&(o[6]<<8|o[7]))}var u=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:$g+1,l=u-Gg+(c-$g)/1e4;if(l<0&&void 0===e.clockseq&&(s=s+1&16383),(l<0||u>Gg)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Gg=u,$g=c,Bg=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||Wg(i)},Jg=jg.exports,Kg=qg;var Hg=Vg,Yg=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||Jg)();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||Kg(i)},Qg=Yg;Qg.v1=Hg,Qg.v4=Yg;var Xg,Zg,eb,tb=Qg,nb={exports:{}},rb="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,ib=rb,ab=o,sb=i,ob=S,ub=ee,cb=qa,lb=Ve,fb=Je.exports,db=Ne.f,pb=Al,hb=Za,vb=pe,yb=re,mb=sb.Int8Array,gb=mb&&mb.prototype,bb=sb.Uint8ClampedArray,kb=bb&&bb.prototype,wb=mb&&pb(mb),xb=gb&&pb(gb),_b=Object.prototype,Sb=_b.isPrototypeOf,Eb=vb("toStringTag"),Tb=yb("TYPED_ARRAY_TAG"),Rb=yb("TYPED_ARRAY_CONSTRUCTOR"),Ib=ib&&!!hb&&"Opera"!==cb(sb.opera),Cb=!1,Ob={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},Pb={BigInt64Array:8,BigUint64Array:8},Ab=function(e){if(!ob(e))return!1;var t=cb(e);return ub(Ob,t)||ub(Pb,t)};for(Xg in Ob)(eb=(Zg=sb[Xg])&&Zg.prototype)?lb(eb,Rb,Zg):Ib=!1;for(Xg in Pb)(eb=(Zg=sb[Xg])&&Zg.prototype)&&lb(eb,Rb,Zg);if((!Ib||"function"!=typeof wb||wb===Function.prototype)&&(wb=function(){throw TypeError("Incorrect invocation")},Ib))for(Xg in Ob)sb[Xg]&&hb(sb[Xg],wb);if((!Ib||!xb||xb===_b)&&(xb=wb.prototype,Ib))for(Xg in Ob)sb[Xg]&&hb(sb[Xg].prototype,xb);if(Ib&&pb(kb)!==xb&&hb(kb,xb),ab&&!ub(xb,Eb))for(Xg in Cb=!0,db(xb,Eb,{get:function(){return ob(this)?this[Tb]:void 0}}),Ob)sb[Xg]&&lb(sb[Xg],Tb,Xg);var jb={NATIVE_ARRAY_BUFFER_VIEWS:Ib,TYPED_ARRAY_CONSTRUCTOR:Rb,TYPED_ARRAY_TAG:Cb&&Tb,aTypedArray:function(e){if(Ab(e))return e;throw TypeError("Target is not a typed array")},aTypedArrayConstructor:function(e){if(hb&&!Sb.call(wb,e))throw TypeError("Target is not a typed array constructor");return e},exportTypedArrayMethod:function(e,t,n){if(ab){if(n)for(var r in Ob){var i=sb[r];if(i&&ub(i.prototype,e))try{delete i.prototype[e]}catch(e){}}xb[e]&&!n||fb(xb,e,n?t:Ib&&gb[e]||t)}},exportTypedArrayStaticMethod:function(e,t,n){var r,i;if(ab){if(hb){if(n)for(r in Ob)if((i=sb[r])&&ub(i,e))try{delete i[e]}catch(e){}if(wb[e]&&!n)return;try{return fb(wb,e,n?t:Ib&&wb[e]||t)}catch(e){}}for(r in Ob)!(i=sb[r])||i[e]&&!n||fb(i,e,t)}},isView:function(e){if(!ob(e))return!1;var t=cb(e);return"DataView"===t||ub(Ob,t)||ub(Pb,t)},isTypedArray:Ab,TypedArray:wb,TypedArrayPrototype:xb},Mb=i,Lb=s,Nb=Us,Ub=jb.NATIVE_ARRAY_BUFFER_VIEWS,Db=Mb.ArrayBuffer,Fb=Mb.Int8Array,Bb=!Ub||!Lb((function(){Fb(1)}))||!Lb((function(){new Fb(-1)}))||!Nb((function(e){new Fb,new Fb(null),new Fb(1.5),new Fb(e)}),!0)||Lb((function(){return 1!==new Fb(new Db(2),1,void 0).length})),qb=Mt,zb=Ut,Wb=function(e){if(void 0===e)return 0;var t=qb(e),n=zb(t);if(t!==n)throw RangeError("Wrong length or index");return n},Gb=Math.abs,$b=Math.pow,Vb=Math.floor,Jb=Math.log,Kb=Math.LN2,Hb=Q,Yb=qt,Qb=Ut,Xb=function(e){for(var t=Hb(this),n=Qb(t.length),r=arguments.length,i=Yb(r>1?arguments[1]:void 0,n),a=r>2?arguments[2]:void 0,s=void 0===a?n:Yb(a,n);s>i;)t[i++]=e;return t},Zb=i,ek=o,tk=rb,nk=Ve,rk=Ha,ik=s,ak=as,sk=Mt,ok=Ut,uk=Wb,ck={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?$b(2,-24)-$b(2,-77):0,f=e<0||0===e&&1/e<0?1:0,d=0;for((e=Gb(e))!=e||e===1/0?(i=e!=e?1:0,r=u):(r=Vb(Jb(e)/Kb),e*(a=$b(2,-r))<1&&(r--,a*=2),(e+=r+c>=1?l/a:l*$b(2,1-c))*a>=2&&(r++,a/=2),r+c>=u?(i=0,r=u):r+c>=1?(i=(e*a-1)*$b(2,t),r+=c):(i=e*$b(2,c-1)*$b(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+=$b(2,t),l-=s}return(c?-1:1)*n*$b(2,l-t)}},lk=Al,fk=Za,dk=Pt.f,pk=Ne.f,hk=Xb,vk=Mr,yk=xt.get,mk=xt.set,gk="ArrayBuffer",bk="DataView",kk="Wrong index",wk=Zb.ArrayBuffer,xk=wk,_k=Zb.DataView,Sk=_k&&_k.prototype,Ek=Object.prototype,Tk=Zb.RangeError,Rk=ck.pack,Ik=ck.unpack,Ck=function(e){return[255&e]},Ok=function(e){return[255&e,e>>8&255]},Pk=function(e){return[255&e,e>>8&255,e>>16&255,e>>24&255]},Ak=function(e){return e[3]<<24|e[2]<<16|e[1]<<8|e[0]},jk=function(e){return Rk(e,23,4)},Mk=function(e){return Rk(e,52,8)},Lk=function(e,t){pk(e.prototype,t,{get:function(){return yk(this)[t]}})},Nk=function(e,t,n,r){var i=uk(n),a=yk(e);if(i+t>a.byteLength)throw Tk(kk);var s=yk(a.buffer).bytes,o=i+a.byteOffset,u=s.slice(o,o+t);return r?u:u.reverse()},Uk=function(e,t,n,r,i,a){var s=uk(n),o=yk(e);if(s+t>o.byteLength)throw Tk(kk);for(var u=yk(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(tk){if(!ik((function(){wk(1)}))||!ik((function(){new wk(-1)}))||ik((function(){return new wk,new wk(1.5),new wk(NaN),wk.name!=gk}))){for(var Dk,Fk=(xk=function(e){return ak(this,xk),new wk(uk(e))}).prototype=wk.prototype,Bk=dk(wk),qk=0;Bk.length>qk;)(Dk=Bk[qk++])in xk||nk(xk,Dk,wk[Dk]);Fk.constructor=xk}fk&&lk(Sk)!==Ek&&fk(Sk,Ek);var zk=new _k(new xk(2)),Wk=Sk.setInt8;zk.setInt8(0,2147483648),zk.setInt8(1,2147483649),!zk.getInt8(0)&&zk.getInt8(1)||rk(Sk,{setInt8:function(e,t){Wk.call(this,e,t<<24>>24)},setUint8:function(e,t){Wk.call(this,e,t<<24>>24)}},{unsafe:!0})}else xk=function(e){ak(this,xk,gk);var t=uk(e);mk(this,{bytes:hk.call(new Array(t),0),byteLength:t}),ek||(this.byteLength=t)},_k=function(e,t,n){ak(this,_k,bk),ak(e,xk,bk);var r=yk(e).byteLength,i=sk(t);if(i<0||i>r)throw Tk("Wrong offset");if(i+(n=void 0===n?r-i:ok(n))>r)throw Tk("Wrong length");mk(this,{buffer:e,byteLength:n,byteOffset:i}),ek||(this.buffer=e,this.byteLength=n,this.byteOffset=i)},ek&&(Lk(xk,"byteLength"),Lk(_k,"buffer"),Lk(_k,"byteLength"),Lk(_k,"byteOffset")),rk(_k.prototype,{getInt8:function(e){return Nk(this,1,e)[0]<<24>>24},getUint8:function(e){return Nk(this,1,e)[0]},getInt16:function(e){var t=Nk(this,2,e,arguments.length>1?arguments[1]:void 0);return(t[1]<<8|t[0])<<16>>16},getUint16:function(e){var t=Nk(this,2,e,arguments.length>1?arguments[1]:void 0);return t[1]<<8|t[0]},getInt32:function(e){return Ak(Nk(this,4,e,arguments.length>1?arguments[1]:void 0))},getUint32:function(e){return Ak(Nk(this,4,e,arguments.length>1?arguments[1]:void 0))>>>0},getFloat32:function(e){return Ik(Nk(this,4,e,arguments.length>1?arguments[1]:void 0),23)},getFloat64:function(e){return Ik(Nk(this,8,e,arguments.length>1?arguments[1]:void 0),52)},setInt8:function(e,t){Uk(this,1,e,Ck,t)},setUint8:function(e,t){Uk(this,1,e,Ck,t)},setInt16:function(e,t){Uk(this,2,e,Ok,t,arguments.length>2?arguments[2]:void 0)},setUint16:function(e,t){Uk(this,2,e,Ok,t,arguments.length>2?arguments[2]:void 0)},setInt32:function(e,t){Uk(this,4,e,Pk,t,arguments.length>2?arguments[2]:void 0)},setUint32:function(e,t){Uk(this,4,e,Pk,t,arguments.length>2?arguments[2]:void 0)},setFloat32:function(e,t){Uk(this,4,e,jk,t,arguments.length>2?arguments[2]:void 0)},setFloat64:function(e,t){Uk(this,8,e,Mk,t,arguments.length>2?arguments[2]:void 0)}});vk(xk,gk),vk(_k,bk);var Gk={ArrayBuffer:xk,DataView:_k},$k=Mt,Vk=function(e){var t=$k(e);if(t<0)throw RangeError("The argument can't be less than 0");return t},Jk=function(e,t){var n=Vk(e);if(n%t)throw RangeError("Wrong offset");return n},Kk=Q,Hk=Ut,Yk=ms,Qk=hs,Xk=ls,Zk=Nr,ew=jb.aTypedArrayConstructor,tw=In,nw=i,rw=o,iw=Bb,aw=jb,sw=Gk,ow=as,uw=h,cw=Ve,lw=Bh,fw=Ut,dw=Wb,pw=Jk,hw=we,vw=ee,yw=qa,mw=S,gw=q,bw=Hn,kw=Za,ww=Pt.f,xw=function(e){var t,n,r,i,a,s,o=Kk(e),u=arguments.length,c=u>1?arguments[1]:void 0,l=void 0!==c,f=Qk(o);if(null!=f&&!Xk(f))for(s=(a=Yk(o,f)).next,o=[];!(i=s.call(a)).done;)o.push(i.value);for(l&&u>2&&(c=Zk(c,arguments[2],2)),n=Hk(o.length),r=new(ew(this))(n),t=0;n>t;t++)r[t]=l?c(o[t],t):o[t];return r},_w=Hr.forEach,Sw=is,Ew=Ne,Tw=a,Rw=cd,Iw=xt.get,Cw=xt.set,Ow=Ew.f,Pw=Tw.f,Aw=Math.round,jw=nw.RangeError,Mw=sw.ArrayBuffer,Lw=sw.DataView,Nw=aw.NATIVE_ARRAY_BUFFER_VIEWS,Uw=aw.TYPED_ARRAY_CONSTRUCTOR,Dw=aw.TYPED_ARRAY_TAG,Fw=aw.TypedArray,Bw=aw.TypedArrayPrototype,qw=aw.aTypedArrayConstructor,zw=aw.isTypedArray,Ww="BYTES_PER_ELEMENT",Gw="Wrong length",$w=function(e,t){for(var n=0,r=t.length,i=new(qw(e))(r);r>n;)i[n]=t[n++];return i},Vw=function(e,t){Ow(e,t,{get:function(){return Iw(this)[t]}})},Jw=function(e){var t;return e instanceof Mw||"ArrayBuffer"==(t=yw(e))||"SharedArrayBuffer"==t},Kw=function(e,t){return zw(e)&&!gw(t)&&t in e&&lw(+t)&&t>=0},Hw=function(e,t){return t=hw(t),Kw(e,t)?uw(2,e[t]):Pw(e,t)},Yw=function(e,t,n){return t=hw(t),!(Kw(e,t)&&mw(n)&&vw(n,"value"))||vw(n,"get")||vw(n,"set")||n.configurable||vw(n,"writable")&&!n.writable||vw(n,"enumerable")&&!n.enumerable?Ow(e,t,n):(e[t]=n.value,e)};rw?(Nw||(Tw.f=Hw,Ew.f=Yw,Vw(Bw,"buffer"),Vw(Bw,"byteOffset"),Vw(Bw,"byteLength"),Vw(Bw,"length")),tw({target:"Object",stat:!0,forced:!Nw},{getOwnPropertyDescriptor:Hw,defineProperty:Yw}),nb.exports=function(e,t,n){var r=e.match(/\d+$/)[0]/8,i=e+(n?"Clamped":"")+"Array",a="get"+e,s="set"+e,o=nw[i],u=o,c=u&&u.prototype,l={},f=function(e,t){Ow(e,t,{get:function(){return function(e,t){var n=Iw(e);return n.view[a](t*r+n.byteOffset,!0)}(this,t)},set:function(e){return function(e,t,i){var a=Iw(e);n&&(i=(i=Aw(i))<0?0:i>255?255:255&i),a.view[s](t*r+a.byteOffset,i,!0)}(this,t,e)},enumerable:!0})};Nw?iw&&(u=t((function(e,t,n,a){return ow(e,u,i),Rw(mw(t)?Jw(t)?void 0!==a?new o(t,pw(n,r),a):void 0!==n?new o(t,pw(n,r)):new o(t):zw(t)?$w(u,t):xw.call(u,t):new o(dw(t)),e,u)})),kw&&kw(u,Fw),_w(ww(o),(function(e){e in u||cw(u,e,o[e])})),u.prototype=c):(u=t((function(e,t,n,a){ow(e,u,i);var s,o,c,l=0,d=0;if(mw(t)){if(!Jw(t))return zw(t)?$w(u,t):xw.call(u,t);s=t,d=pw(n,r);var p=t.byteLength;if(void 0===a){if(p%r)throw jw(Gw);if((o=p-d)<0)throw jw(Gw)}else if((o=fw(a)*r)+d>p)throw jw(Gw);c=o/r}else c=dw(t),s=new Mw(o=c*r);for(Cw(e,{buffer:s,byteOffset:d,byteLength:o,length:c,view:new Lw(s)});l<c;)f(e,l++)})),kw&&kw(u,Fw),c=u.prototype=bw(Bw)),c.constructor!==u&&cw(c,"constructor",u),cw(c,Uw,u),Dw&&cw(c,Dw,i),l[i]=u,tw({global:!0,forced:u!=o,sham:!Nw},l),Ww in u||cw(u,Ww,r),Ww in c||cw(c,Ww,r),Sw(i)}):nb.exports=function(){},(0,nb.exports)("Uint8",(function(e){return function(t,n,r){return e(this,t,n,r)}}));var Qw=Q,Xw=qt,Zw=Ut,ex=Math.min,tx=[].copyWithin||function(e,t){var n=Qw(this),r=Zw(n.length),i=Xw(e,r),a=Xw(t,r),s=arguments.length>2?arguments[2]:void 0,o=ex((void 0===s?r:Xw(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},nx=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("copyWithin",(function(e,t){return tx.call(nx(this),e,t,arguments.length>2?arguments[2]:void 0)}));var rx=Hr.every,ix=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("every",(function(e){return rx(ix(this),e,arguments.length>1?arguments[1]:void 0)}));var ax=Xb,sx=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("fill",(function(e){return ax.apply(sx(this),arguments)}));var ox=qs,ux=jb.TYPED_ARRAY_CONSTRUCTOR,cx=jb.aTypedArrayConstructor,lx=function(e){return cx(ox(e,e[ux]))},fx=function(e,t){for(var n=0,r=t.length,i=new e(r);r>n;)i[n]=t[n++];return i},dx=lx,px=Hr.filter,hx=function(e,t){return fx(dx(e),t)},vx=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("filter",(function(e){var t=px(vx(this),e,arguments.length>1?arguments[1]:void 0);return hx(this,t)}));var yx=Hr.find,mx=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("find",(function(e){return yx(mx(this),e,arguments.length>1?arguments[1]:void 0)}));var gx=Hr.findIndex,bx=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("findIndex",(function(e){return gx(bx(this),e,arguments.length>1?arguments[1]:void 0)}));var kx=Hr.forEach,wx=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("forEach",(function(e){kx(wx(this),e,arguments.length>1?arguments[1]:void 0)}));var xx=Vt.includes,_x=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("includes",(function(e){return xx(_x(this),e,arguments.length>1?arguments[1]:void 0)}));var Sx=Vt.indexOf,Ex=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("indexOf",(function(e){return Sx(Ex(this),e,arguments.length>1?arguments[1]:void 0)}));var Tx=i,Rx=jb,Ix=Hf,Cx=pe("iterator"),Ox=Tx.Uint8Array,Px=Ix.values,Ax=Ix.keys,jx=Ix.entries,Mx=Rx.aTypedArray,Lx=Rx.exportTypedArrayMethod,Nx=Ox&&Ox.prototype[Cx],Ux=!!Nx&&("values"==Nx.name||null==Nx.name),Dx=function(){return Px.call(Mx(this))};Lx("entries",(function(){return jx.call(Mx(this))})),Lx("keys",(function(){return Ax.call(Mx(this))})),Lx("values",Dx,!Ux),Lx(Cx,Dx,!Ux);var Fx=jb.aTypedArray,Bx=[].join;(0,jb.exportTypedArrayMethod)("join",(function(e){return Bx.apply(Fx(this),arguments)}));var qx=_,zx=Mt,Wx=Ut,Gx=tc,$x=Math.min,Vx=[].lastIndexOf,Jx=!!Vx&&1/[1].lastIndexOf(1,-0)<0,Kx=Gx("lastIndexOf"),Hx=Jx||!Kx?function(e){if(Jx)return Vx.apply(this,arguments)||0;var t=qx(this),n=Wx(t.length),r=n-1;for(arguments.length>1&&(r=$x(r,zx(arguments[1]))),r<0&&(r=n+r);r>=0;r--)if(r in t&&t[r]===e)return r||0;return-1}:Vx,Yx=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("lastIndexOf",(function(e){return Hx.apply(Yx(this),arguments)}));var Qx=Hr.map,Xx=lx,Zx=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("map",(function(e){return Qx(Zx(this),e,arguments.length>1?arguments[1]:void 0,(function(e,t){return new(Xx(e))(t)}))}));var e_=Cn,t_=Q,n_=b,r_=Ut,i_=function(e){return function(t,n,r,i){e_(n);var a=t_(t),s=n_(a),o=r_(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}},a_={left:i_(!1),right:i_(!0)},s_=a_.left,o_=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("reduce",(function(e){return s_(o_(this),e,arguments.length,arguments.length>1?arguments[1]:void 0)}));var u_=a_.right,c_=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("reduceRight",(function(e){return u_(c_(this),e,arguments.length,arguments.length>1?arguments[1]:void 0)}));var l_=jb.aTypedArray,f_=jb.exportTypedArrayMethod,d_=Math.floor;f_("reverse",(function(){for(var e,t=this,n=l_(t).length,r=d_(n/2),i=0;i<r;)e=t[i],t[i++]=t[--n],t[n]=e;return t}));var p_=Ut,h_=Jk,v_=Q,y_=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("set",(function(e){y_(this);var t=h_(arguments.length>1?arguments[1]:void 0,1),n=this.length,r=v_(e),i=p_(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 m_=lx,g_=jb.aTypedArray,b_=[].slice;(0,jb.exportTypedArrayMethod)("slice",(function(e,t){for(var n=b_.call(g_(this),e,t),r=m_(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,w_=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("some",(function(e){return k_(w_(this),e,arguments.length>1?arguments[1]:void 0)}));var x_=Math.floor,__=function(e,t){var n=e.length,r=x_(n/2);return n<8?S_(e,t):E_(__(e.slice(0,r),t),__(e.slice(r),t),t)},S_=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},E_=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},T_=__,R_=I.match(/firefox\/(\d+)/i),I_=!!R_&&+R_[1],C_=/MSIE|Trident/.test(I),O_=I.match(/AppleWebKit\/(\d+)\./),P_=!!O_&&+O_[1],A_=s,j_=Cn,M_=Ut,L_=T_,N_=I_,U_=C_,D_=L,F_=P_,B_=jb.aTypedArray,q_=jb.exportTypedArrayMethod,z_=i.Uint16Array,W_=z_&&z_.prototype.sort,G_=!!W_&&!A_((function(){var e=new z_(2);e.sort(null),e.sort({})})),$_=!!W_&&!A_((function(){if(D_)return D_<74;if(N_)return N_<67;if(U_)return!0;if(F_)return F_<602;var e,t,n=new z_(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}));q_("sort",(function(e){var t=this;if(void 0!==e&&j_(e),$_)return W_.call(t,e);B_(t);var n,r=M_(t.length),i=Array(r);for(n=0;n<r;n++)i[n]=t[n];for(i=L_(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}),!$_||G_);var V_=Ut,J_=qt,K_=lx,H_=jb.aTypedArray;(0,jb.exportTypedArrayMethod)("subarray",(function(e,t){var n=H_(this),r=n.length,i=J_(e,r);return new(K_(n))(n.buffer,n.byteOffset+i*n.BYTES_PER_ELEMENT,V_((void 0===t?r:J_(t,r))-i))}));var Y_=jb,Q_=s,X_=i.Int8Array,Z_=Y_.aTypedArray,eS=Y_.exportTypedArrayMethod,tS=[].toLocaleString,nS=[].slice,rS=!!X_&&Q_((function(){tS.call(new X_(1))}));eS("toLocaleString",(function(){return tS.apply(rS?nS.call(Z_(this)):Z_(this),arguments)}),Q_((function(){return[1,2].toLocaleString()!=new X_([1,2]).toLocaleString()}))||!Q_((function(){X_.prototype.toLocaleString.call([1,2])})));var iS=jb.exportTypedArrayMethod,aS=s,sS=i.Uint8Array,oS=sS&&sS.prototype||{},uS=[].toString,cS=[].join;aS((function(){uS.call({})}))&&(uS=function(){return cS.call(this)});var lS=oS.toString!=uS;iS("toString",uS,lS);var fS=S,dS=y,pS=pe("match"),hS=function(e){var t;return fS(e)&&(void 0!==(t=e[pS])?!!t:"RegExp"==dS(e))},vS=xp,yS=hS,mS=De,gS=k,bS=qs,kS=Sp,wS=Ut,xS=gr,_S=Ap,SS=hp,ES=s,TS=Wd.UNSUPPORTED_Y,RS=[].push,IS=Math.min,CS=4294967295;vS("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=xS(gS(this)),i=void 0===n?CS:n>>>0;if(0===i)return[];if(void 0===e)return[r];if(!yS(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=SS.call(f,r))&&!((s=f.lastIndex)>l&&(u.push(r.slice(l,a.index)),a.length>1&&a.index<r.length&&RS.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=gS(this),a=null==t?void 0:t[e];return void 0!==a?a.call(t,i,n):r.call(xS(i),t,n)},function(e,i){var a=mS(this),s=xS(e),o=n(r,a,s,i,r!==t);if(o.done)return o.value;var u=bS(a,RegExp),c=a.unicode,l=(a.ignoreCase?"i":"")+(a.multiline?"m":"")+(a.unicode?"u":"")+(TS?"g":"y"),f=new u(TS?"^(?:"+a.source+")":a,l),d=void 0===i?CS:i>>>0;if(0===d)return[];if(0===s.length)return null===_S(f,s)?[s]:[];for(var p=0,h=0,v=[];h<s.length;){f.lastIndex=TS?0:h;var y,m=_S(f,TS?s.slice(h):s);if(null===m||(y=IS(wS(f.lastIndex+(TS?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}]}),!!ES((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]})),TS);var OS={exports:{}},PS={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}(PS);var AS={exports:{}},jS={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}(jS),function(e){var t=av.exports,n=jS.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}(AS),function(e){var t=uv.exports,n=av.exports,r=PS.exports,i=AS.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}(OS);var MS={exports:{}};!function(e,n){(function(){var r={function:!0,object:!0}["undefined"==typeof window?"undefined":Oa(window)]&&window||this,i=n,a=e&&!e.nodeType&&e,s=i&&a&&"object"==Oa(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"==Oa(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,C=u.test(C=i&&I?I["[[Class]]"]:v(I))?C:I=null,O=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?Oa(e[t]):"number";return!(/^(?:boolean|number|string|undefined)$/.test(n)||"object"==n&&!e[t])}(n,"global"))if(_&&(O=(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"==Oa(n.process)&&!n.process.browser&&(o=n.process)&&("object"==Oa(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",O=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=C?p(C.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(O))&&!/\bi686\b/i.test(O)?(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 z={};return z.description=t,z.layout=L&&L[0],z.manufacturer=D,z.name=N,z.prerelease=A,z.product=U,z.ua=t,z.version=N&&M,z.os=F||{architecture:null,family:null,version:null,toString:function(){return"null"}},z.parse=e,z.toString=function(){return this.description||""},z.version&&P.unshift(M),z.name&&P.unshift(N),F&&N&&(F!=String(F).split(" ")[0]||F!=N.split(" ")[0]&&!U)&&P.push(U?"("+F+")":"on "+F),P.length&&(z.description=P.join(" ")),z}();i&&a?h(b,(function(e,t){i[t]=e})):r.platform=b}).call(t)}(MS,MS.exports);var LS=De,NS=Ut,US=gr,DS=k,FS=Sp,BS=Ap;xp("match",(function(e,t,n){return[function(t){var n=DS(this),r=null==t?void 0:t[e];return void 0!==r?r.call(t,n):new RegExp(t)[e](US(n))},function(e){var r=LS(this),i=US(e),a=n(t,r,i);if(a.done)return a.value;if(!r.global)return BS(r,i);var s=r.unicode;r.lastIndex=0;for(var o,u=[],c=0;null!==(o=BS(r,i));){var l=US(o[0]);u[c]=l,""===l&&(r.lastIndex=FS(i,NS(r.lastIndex),s)),c++}return 0===c?null:u}]}));var qS=Object.is||function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t},zS=De,WS=k,GS=qS,$S=gr,VS=Ap;xp("search",(function(e,t,n){return[function(t){var n=WS(this),r=null==t?void 0:t[e];return void 0!==r?r.call(t,n):new RegExp(t)[e]($S(n))},function(e){var r=zS(this),i=$S(e),a=n(t,r,i);if(a.done)return a.value;var s=r.lastIndex;GS(s,0)||(r.lastIndex=0);var o=VS(r,i);return GS(r.lastIndex,s)||(r.lastIndex=s),null===o?-1:o.index}]}));var JS=In,KS=qt,HS=Mt,YS=Ut,QS=Q,XS=qr,ZS=ga,eE=oa("splice"),tE=Math.max,nE=Math.min,rE=9007199254740991,iE="Maximum allowed length exceeded";JS({target:"Array",proto:!0,forced:!eE},{splice:function(e,t){var n,r,i,a,s,o,u=QS(this),c=YS(u.length),l=KS(e,c),f=arguments.length;if(0===f?n=r=0:1===f?(n=0,r=c-l):(n=f-2,r=nE(tE(HS(t),0),c-l)),c+n-r>rE)throw TypeError(iE);for(i=XS(u,r),a=0;a<r;a++)(s=l+a)in u&&ZS(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=kg.exports,r=ny.exports,i=ov.exports,a=ry.exports,s=iv.exports,o=sv.exports,u=uv.exports,c=rv.exports,l=ay.exports,f=wg,d=Ph.exports,p=ih,h=bf.exports,v=Ag.exports,y=tb,m=OS.exports,g=Mm,b=ty,k=MS.exports;function w(e){return e&&"object"===Oa(e)&&"default"in e?e:{default:e}}function x(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 _=w(n),S=w(r),E=w(i),T=w(a),R=w(s),I=w(o),C=w(u),O=w(c),P=w(l),A=w(f),j=w(d),M=x(h),L=x(v),N=w(m),U=x(k);var D=M.getLogger("twilsock");function F(e,t){return["".concat((new Date).toISOString()," Twilsock ").concat(e,":")].concat(Array.from(t))}var B=new(function(){function e(t){O.default(this,e),P.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?" "+t+":":""}return S.default(e,[{key:"setLevel",value:function(e){D.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];D.trace.apply(null,F("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];D.debug.apply(null,F("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];D.info.apply(null,F("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];D.warn.apply(null,F("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];D.error.apply(null,F("E",t))}}],[{key:"setLevel",value:function(e){D.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];D.trace.apply(null,F("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];D.debug.apply(null,F("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];D.info.apply(null,F("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];D.warn.apply(null,F("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];D.error.apply(null,F("E",t))}}]),e}())(""),q="0.13.0-rc.0",z=function(){function e(t,n,r){O.default(this,e),P.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=q,this.initRegistrations=r.initRegistrations?r.initRegistrations:null,this.tweaks=r.tweaks?r.tweaks:null}return S.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}(),W=function e(t){O.default(this,e),this.id=t||"TM".concat(y.v4())};function G(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var $=function(e){R.default(n,e);var t=G(n);function n(e,r,i,a,s){var o;return O.default(this,n),o=t.call(this),P.default(E.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}(W);function V(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var J=function(e){R.default(n,e);var t=V(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}(W);function K(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var H=function(e){R.default(n,e);var t=K(n);function n(e){var r;return O.default(this,n),r=t.call(this),P.default(E.default(r),"method","update"),r.token=e,r}return n}(W);function Y(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var Message=function(e){R.default(Message,e);var t=Y(Message);function Message(e,n,r){var i;return O.default(this,Message),i=t.call(this),P.default(E.default(i),"method","message"),i.active_grant=e,i.payload_type=n,i.http_request=r,i}return Message}(W);function Q(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var X=function(e){R.default(n,e);var t=Q(n);function n(e){var r;return O.default(this,n),r=t.call(this,e),P.default(E.default(r),"method","reply"),P.default(E.default(r),"payload_type","application/json"),P.default(E.default(r),"status",{code:200,status:"OK"}),r}return n}(W);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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var ee=function(e){R.default(n,e);var t=Z(n);function n(){var e;return O.default(this,n),e=t.call(this),P.default(E.default(e),"method","close"),e}return n}(W);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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var ne=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},re=function(e){R.default(n,e);var t=te(n);function n(e){var r;return O.default(this,n),r=t.call(this),P.default(E.default(r),"method","telemetry.v1"),r.events=e,r}return n}(W);function ie(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})).length}function ae(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 se(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 oe(e){return JSON.parse(se(e))}var ue=function(){function e(){O.default(this,e)}return S.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 B.error("unsupported protocol: ".concat(i.protocol," ver ").concat(i.version)),null;try{t=oe(r.subarray(i.size,i.size+i.headerSize))}catch(t){return B.error("failed to parse message header",t,e),null}if(B.debug("message received: ",t.method),B.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=se(r.subarray(a,a+s)));else try{n=oe(r.subarray(a,a+s))}catch(t){return B.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=ie(t);var n=JSON.stringify(e),r="TWILSOCK V3.0 "+ie(n);B.debug("send request:",r+n+t);var i=ae(r+"\r\n"+n+"\r\n"+t);return i.buffer}}]),e}();function ce(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var le=function(e){R.default(n,e);var t=ce(n);function n(e){return O.default(this,n),t.call(this,e)}return n}(N.default(Error));function fe(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var de=function(e){R.default(n,e);var t=fe(n);function n(e,r){var i;return O.default(this,n),(i=t.call(this,e)).reply=r,i}return n}(le);function pe(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 he(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?pe(Object(n),!0).forEach((function(t){P.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):pe(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function ve(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var ye=function(e){R.default(n,e);var t=ve(n);function n(e){var r;return O.default(this,n),r=t.call(this),P.default(E.default(r),"newBackoff",null),P.default(E.default(r),"usedBackoff",null),P.default(E.default(r),"retrier",null),r.options=e?he({},e):{},r}return S.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=he({},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}(b.ReplayEventEmitter);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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var ge=function(e){R.default(i,e);var t,n,r=me(i);function i(e,t,n){var a;O.default(this,i),a=r.call(this),P.default(E.default(a),"disconnectingTimer",null),P.default(E.default(a),"disconnectedPromiseResolve",null),P.default(E.default(a),"terminalStates",["disconnected","rejected"]),P.default(E.default(a),"tokenExpiredSasCode",20104),P.default(E.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){a.emit("connectionError",{terminal:!1,message:"Socket error: ".concat(e.message),httpStatusCode:null,errorCode:null}),a.emit("stateChanged","retrying")})),a.transport=t,a.config=n,a.retrier=new ye(n.retryPolicy),a.retrier.on("attempt",(function(){return a.retry()})),a.retrier.on("failed",(function(e){B.warn("Retrying failed: ".concat(e.message)),a.disconnect()})),"undefined"!=typeof window&&void 0!==window.addEventListener&&(window.addEventListener("online",(function(){B.debug("Browser reported connectivity state: online"),a.resetBackoff(),a.fsm.systemOnline()})),window.addEventListener("offline",(function(){B.debug("Browser reported connectivity state: offline"),a.websocket.close(),a.fsm.socketClosed()})));var s=L.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){B.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){B.warn("FSM: unexpected transition",t,n)}}});return a.fsm=new s,a}return S.default(i,[{key:"changeState",value:function(e){B.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(){B.trace("resetBackoff"),this.retrier.stop()}},{key:"modifyBackoff",value:function(e){B.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;B.trace("startDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null),this.disconnectingTimer=setTimeout((function(){B.debug("disconnecting is timed out"),e.closeSocket(!0)}),3e3)}},{key:"cancelDisconnectTimer",value:function(){B.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(){B.debug("initRetry"),this.retrier.inProgress?this.retrier.attemptFailed():this.retrier.start()}},{key:"retry",value:function(){"connecting"!=this.fsm.state?(B.trace("retry"),this.websocket.close(),this.fsm.userRetry()):B.trace("can\t retry as already connecting")}},{key:"onConnected",value:function(){this.emit("connected")}},{key:"finalizeSocket",value:function(){B.trace("finalizeSocket"),this.websocket.close(),this.emit("disconnected"),this.disconnectedPromiseResolve&&(this.disconnectedPromiseResolve(),this.disconnectedPromiseResolve=null)}},{key:"setupSocket",value:function(){B.trace("setupSocket:",this.config.token),this.emit("beforeConnect"),this.websocket.connect()}},{key:"onIncomingMessage",value:function(e){var t=ue.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)B.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),B.error(a),this.fsm.receiveFatalClose()}else 417===r.status.code?(B.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?(B.warn("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status),this.emit("tokenExpired")):401===r.status.code?(B.error("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status)):(B.warn("unexpected message: ",r.status),this.fsm.receiveOffload({status:r.status.status,body:null}))}}},{key:"sendInit",value:(n=_.default(A.default.mark((function e(){var t,n;return A.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return B.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 de?(n=!1,B.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=_.default(A.default.mark((function e(){var t,n,r;return A.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return B.trace("sendUpdate"),t=new H(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 de?(r=!1,B.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(){B.trace("cancelInit")}},{key:"cancelUpdate",value:function(){B.trace("cancelUpdate")}},{key:"confirmReceiving",value:function(e){B.trace("confirmReceiving");try{this.transport.send(new X(e.id))}catch(e){B.debug("failed to confirm packet receiving",e)}}},{key:"closeSocket",value:function(e){var t=this;B.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(){B.trace("connect"),this.fsm.userConnect()}},{key:"disconnect",value:function(){var e=this;return B.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 B.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}(b.ReplayEventEmitter),be=function(){function e(){O.default(this,e)}return S.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=U.name)&&void 0!==t?t:"unknown",envv:null!==(n=U.version)&&void 0!==n?n:"unknown",os:null!==(r=null===(i=U.os)||void 0===i?void 0:i.family)&&void 0!==r?r:"unknown",osv:null!==(a=null===(s=U.os)||void 0===s?void 0:s.version)&&void 0!==a?a:"unknown",osa:null!==(o=null===(u=U.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 ke=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 le("disconnected"))})),r.activeRequests.clear()}))}var t;return S.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 de("Transport failure: "+e.status.status,e)),B.trace("message rejected")))}},{key:"storeRequest",value:function(e,t,n){var r={resolve:t,reject:n,timeout:setTimeout((function(){B.trace("request",e,"is timed out"),n(new le("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 le("Twilsock: request cancelled by user"))})),this.activeRequests.clear()}},{key:"sendInit",value:(t=_.default(A.default.mark((function e(){var t,n,r;return A.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return B.trace("sendInit"),t=be.getMetadata(this.config),n=new $(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 J(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 ee;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=ue.createPacket(e,function(e){switch(j.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 B.debug("failed to send ",e,t),B.trace(t.stack),t}}}]),e}();function we(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var xe=function(e){R.default(r,e);var n=we(r);function r(e){var i;return O.default(this,r),i=n.call(this),P.default(E.default(i),"socket",null),i.url=e,i.url=e,i.WebSocket=t.WebSocket||t.MozWebSocket||{},i}return S.default(r,[{key:"isConnected",get:function(){return!!this.socket&&1===this.socket.readyState}},{key:"connect",value:function(){var e,t=this;B.trace("connecting to socket");try{e=new this.WebSocket(this.url)}catch(e){return B.debug("Socket error: ".concat(this.url)),void this.emit("socketError",e)}e.binaryType="arraybuffer",e.onopen=function(){B.debug("socket opened ".concat(t.url)),t.emit("connected")},e.onclose=function(e){B.debug("socket closed",e),t.emit("disconnected",e)},e.onerror=function(e){B.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(B.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}(b.ReplayEventEmitter);function _e(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var Se=function(e){R.default(u,e);var t,n,r,i,a,s,o=_e(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 S.default(u,[{key:"putNotificationContext",value:(s=_.default(A.default.mark((function e(t,n){var r;return A.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=_.default(A.default.mark((function e(t){var n;return A.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=_.default(A.default.mark((function e(t,n){var r,i;return A.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return B.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:B.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),B.warn("registration attempt failed for context",n),B.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=_.default(A.default.mark((function e(){var t,n=this;return A.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return B.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=_.default(A.default.mark((function e(t,n){return A.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t&&n){e.next=2;break}throw new le("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=_.default(A.default.mark((function e(t){return A.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}(b.ReplayEventEmitter);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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var Te=function(e){R.default(n,e);var t=Ee(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}(le);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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var Ie=function(e){R.default(n,e);var t=Re(n);function n(e){return O.default(this,n),t.call(this,e)}return n}(le);function Ce(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 le("Incorrect URI: "+e)}(t),r={method:e,host:n.host,path:n.pathname};return n.params&&(r.params=n.params),r}function Oe(e,t,n,r,i){return{to:Ce(e,t),headers:n,body:r,grant:i}}var Pe=function(){function e(t,n,r){O.default(this,e),this.config=r,this.transport=t,this.pendingMessages=[],this.twilsock=n}var t;return S.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(){B.debug("request is timed out"),r(new le("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 B.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 Ie("Unable to connect: "+e.twilsock.getTerminationReason)),t.alreadyRejected=!0,clearTimeout(t.timeout)})),this.pendingMessages.splice(0,this.pendingMessages.length)}},{key:"actualSend",value:(t=_.default(A.default.mark((function e(t){var n,r,i,a,s,o,u,c;return A.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),B.trace("Sending upstream message",u),e.next=9,this.transport.sendWithReply(u,a);case 9:if(c=e.sent,B.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 Te(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 Ie("Unable to connect: "+this.twilsock.getTerminationReason));var a=Oe(e,t,n,r,i);return this.twilsock.isConnected?this.actualSend(a):this.saveMessage(a)}}]),e}(),Ae=function(){function e(){var t=this;O.default(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return S.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}(),je=function(){function e(t){O.default(this,e),this.id=t}return S.default(e,null,[{key:"create",value:function(t){if(t instanceof Object&&"storage_id"in t)return new e(t.storage_id);throw new le('Field "storage_id" is missing')}}]),e}(),Me=function(){function e(){return O.default(this,e),P.default(this,"initializedFlag","twilio_twilsock_token_storage"),P.default(this,"tokenStoragePrefix","twilio_continuation_token_"),e._instance||(this.initialize(),e._instance=this),e._instance}return S.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}();P.default(Me,"_instance",null);var Le,Ne,Ue=new Me,De=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 S.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 ne(i,a,this.title,this.details,this.id,this.type)}}]),e}();e.TelemetryPoint=void 0,(Le=e.TelemetryPoint||(e.TelemetryPoint={}))[Le.Start=0]="Start",Le[Le.End=1]="End",e.EventSendingLimitation=void 0,(Ne=e.EventSendingLimitation||(e.EventSendingLimitation={}))[Ne.MinEventsPortion=0]="MinEventsPortion",Ne[Ne.AnyEvents=1]="AnyEvents",Ne[Ne.AnyEventsIncludingUnfinished=2]="AnyEventsIncludingUnfinished";var Fe=function(){function t(e,n){O.default(this,t),P.default(this,"minEventsPortionToSend",50),P.default(this,"maxEventsPortionToSend",100),P.default(this,"pendingEvents",new Map),P.default(this,"readyEvents",[]),P.default(this,"hasInitializationFinished",!1),P.default(this,"_canSendTelemetry",!1),this.config=e,this.packetInterface=n}return S.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){B.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){B.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&&B.debug("Overwriting starting point for '".concat(n,"' event")),this.pendingEvents.set(n,t);else{if(!i)return void B.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 De("[UNFINISHED] ".concat(i.title),i.details,i.start,null,i.type,i.id))}})),r}},{key:"merge",value:function(e,t){return new De(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 re(t.map((function(e){return e.toTelemetryEvent()}))))}catch(e){B.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 Be(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=C.default(e);if(t){var i=C.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return I.default(this,n)}}var qe=function e(){O.default(this,e)};P.default(qe,"TWILSOCK_CONNECT","twilsock.sdk.connect"),P.default(qe,"TWILSOCK_INIT","twilsock.sdk.init"),e.TwilsockClient=function(t){R.default(f,t);var n,r,i,a,s,o,u,c,l=Be(f);function f(t,n,r){var i;O.default(this,f),i=l.call(this),P.default(E.default(i),"version",q),P.default(E.default(i),"offlineStorageDeferred",new Ae),r.continuationToken=r.continuationToken?r.continuationToken:Ue.getStoredToken(n);var a=i.config=new z(t,n,r);B.setLevel(a.logLevel);var s=new xe(a.url),o=new ke(s,a);return i.channel=new ge(s,o,a),i.registrations=new Se(o),i.upstream=new Pe(o,i.channel,a),i.telemetryTracker=new Fe(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 De("Establish WebSocket connection","",new Date),qe.TWILSOCK_CONNECT,e.TelemetryPoint.Start)})),i.channel.on("connected",(function(){return i.telemetryTracker.addPartialEvent(new De("Establish WebSocket connection","",new Date,new Date),qe.TWILSOCK_CONNECT,e.TelemetryPoint.End)})),i.channel.on("beforeSendInit",(function(){return i.telemetryTracker.addPartialEvent(new De("Send Twilsock init","",new Date),qe.TWILSOCK_INIT,e.TelemetryPoint.Start)})),i.channel.on("initialized",(function(){return i.telemetryTracker.addPartialEvent(new De("Send Twilsock init","Succeeded",new Date,new Date),qe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("sendInitFailed",(function(){return i.telemetryTracker.addPartialEvent(new De("Send Twilsock init","Failed",new Date,new Date),qe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("initialized",(function(e){i.handleStorageId(n,e),Ue.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 le("Client disconnected"))})),i.offlineStorageDeferred.promise.catch((function(){})),i}return S.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 B.debug("Emitting ".concat(e.toString(),"(").concat(r.map((function(e){return JSON.stringify(e)})).join(", "),")")),(t=T.default(C.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(je.create(t.offlineStorage[e])),B.debug("Offline storage for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage[e]),"."))}catch(n){this.offlineStorageDeferred.fail(new le("Failed to parse offline storage for ".concat(e," ").concat(JSON.stringify(t.offlineStorage[e]),". ").concat(n,".")))}else this.offlineStorageDeferred.fail(new le("No offline storage id for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage))));else this.offlineStorageDeferred.fail(new le("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=_.default(A.default.mark((function e(t){return A.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(B.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=_.default(A.default.mark((function e(t,n){return A.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=_.default(A.default.mark((function e(t){return A.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=_.default(A.default.mark((function t(){return A.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=_.default(A.default.mark((function t(n,r,i){return A.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=_.default(A.default.mark((function t(n,r,i,a){return A.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=_.default(A.default.mark((function t(n,r,i,a){return A.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=_.default(A.default.mark((function t(n,r,i,a){return A.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}(b.ReplayEventEmitter),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":j.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":j.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 S.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=De,e.TelemetryTracker=Fe,e.TransportUnavailableError=Ie,e.Twilsock=e.TwilsockClient,e.TwilsockError=le}(bg);var aE={},sE=o,oE=s,uE=An,cE=tn,lE=u,fE=Q,dE=b,pE=Object.assign,hE=Object.defineProperty,vE=!pE||oE((function(){if(sE&&1!==pE({b:1},pE(hE({},"a",{enumerable:!0,get:function(){hE(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!=pE({},e)[n]||uE(pE({},t)).join("")!=r}))?function(e,t){for(var n=fE(e),r=arguments.length,i=1,a=cE.f,s=lE.f;r>i;)for(var o,u=dE(arguments[i++]),c=a?uE(u).concat(a(u)):uE(u),l=c.length,f=0;l>f;)o=c[f++],sE&&!s.call(u,o)||(n[o]=u[o]);return n}:pE,yE=vE;In({target:"Object",stat:!0,forced:Object.assign!==yE},{assign:yE}),function(e){Object.defineProperty(e,"__esModule",{value:!0});var t=kg.exports,n=rv.exports,r=ny.exports,i=iv.exports,a=sv.exports,s=uv.exports,o=wg,u=Ph.exports,c=bg,l=ov.exports,f=ay.exports,d=Mm,p=qh.exports,h=Zh.exports,v=bf.exports,y=tb,m=ih;function g(e){return e&&"object"===Oa(e)&&"default"in e?e:{default:e}}function b(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 k=g(t),w=g(n),x=g(r),_=g(i),S=g(a),E=g(s),T=g(o),R=g(u),I=g(l),C=g(f),O=g(p),P=g(h),A=b(v),j=b(y);function M(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":R.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 L(e,t){if("object"===("undefined"==typeof Reflect?"undefined":R.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function N(){}function U(){U.init.call(this)}function D(e){return void 0===e._maxListeners?U.defaultMaxListeners:e._maxListeners}function F(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 B(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 q(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 z(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 W(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 G(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 N,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=D(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 $(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 V(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}N.prototype=Object.create(null),U.EventEmitter=U,U.usingDomains=!1,U.prototype.domain=void 0,U.prototype._events=void 0,U.prototype._maxListeners=void 0,U.defaultMaxListeners=10,U.init=function(){this.domain=null,U.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new N,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},U.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},U.prototype.getMaxListeners=function(){return D(this)},U.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:F(n,l,this);break;case 2:B(n,l,this,arguments[1]);break;case 3:q(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];W(n,l,this,i)}return!0},U.prototype.addListener=function(e,t){return G(this,e,t,!1)},U.prototype.on=U.prototype.addListener,U.prototype.prependListener=function(e,t){return G(this,e,t,!0)},U.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,$(this,e,t)),this},U.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,$(this,e,t)),this},U.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 N:(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 N,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},U.prototype.off=function(e,t){return this.removeListener(e,t)},U.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new N,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new N: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 N,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},U.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):[]},U.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):V.call(e,t)},U.prototype.listenerCount=V,U.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var K=A.getLogger("twilio-notificatiions");function H(e,t){return["".concat((new Date).toISOString()," Twilio.Notifications ").concat(e,":")].concat(Array.from(t))}var Y=new(function(){function e(){w.default(this,e)}return x.default(e,[{key:"setLevel",value:function(e){K.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];K.trace.apply(null,H("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];K.debug.apply(null,H("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];K.info.apply(null,H("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];K.warn.apply(null,H("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];K.error.apply(null,H("E",t))}}]),e}());function Q(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=E.default(e);if(t){var i=E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return S.default(this,n)}}var X=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;w.default(this,e),this.token=t,this.notificationId=n,this.messageTypes=r};function Z(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(P.default(P.default(e).filter((function(e){return!t.has(e)}))),P.default(P.default(t).filter((function(t){return!e.has(t)}))))}(e.messageTypes,t.messageTypes).length>0&&n.add("messageType"),[n.size>0,n]}var ee=function(e){_.default(r,e);var t,n=Q(r);function r(e){var t;return w.default(this,r),t=n.call(this),C.default(I.default(t),"desiredState",new X),C.default(I.default(t),"currentState",new X),C.default(I.default(t),"_hasActiveAttempt",!1),t.channelType=e,t}return x.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)?Y.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=k.default(T.default.mark((function e(){var t,n,r,i,a,s;return T.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._hasActiveAttempt){e.next=3;break}throw Y.error("One registration attempt is already in progress"),new Error("One registration attempt is already in progress");case 3:if(t=Z(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"),Y.trace("Persisting ".concat(this.channelType," registration"),i,this.desiredState),e.prev=8,this._hasActiveAttempt=!0,(a=new X).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}(U);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=E.default(e);if(t){var i=E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return S.default(this,n)}}var ne={min:2e3,max:12e4,randomness:.2},re=function(e){_.default(a,e);var t,n,r,i=te(a);function a(e,t,n,r){var s;return w.default(this,a),s=i.call(this,e),C.default(I.default(s),"registrationId",null),s.context=t,s.twilsock=n,s.registrarUrl=r,s}return x.default(a,[{key:"updateRegistration",value:(r=k.default(T.default.mark((function e(t,n){var r,i,a,s,o,u=this;return T.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 Y.error("No push notification ID for registration"),new Error("No push notification ID for registration");case 6:return Y.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"},Y.trace("Creating registration for channel ".concat(this.channelType)),e.prev=12,e.next=15,new d.AsyncRetrier(ne).run((function(){return u.twilsock.post(a,s,r,i)}));case 15:o=e.sent,this.registrationId=o.body.id,Y.debug("Registration created: ",o),e.next=24;break;case 20:throw e.prev=20,e.t0=e.catch(12),Y.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=k.default(T.default.mark((function e(){var t,n,r,i=this;return T.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"},Y.trace("Removing registration for ".concat(this.channelType)),e.prev=6,e.next=9,new d.AsyncRetrier(Object.assign(ne,{maxAttemptsCount:3})).run((function(){return i.twilsock.delete(n,r,{},t)}));case 9:this.registrationId=null,this.currentState.notificationId="",Y.debug("Registration removed for ".concat(this.channelType)),e.next=18;break;case 14:throw e.prev=14,e.t0=e.catch(6),Y.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=k.default(T.default.mark((function e(t){var n,r,i,a,s=this;return T.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,Y.trace("Removing old registrations for ".concat(this.channelType)),e.next=10,new d.AsyncRetrier(Object.assign(ne,{maxAttemptsCount:3})).run((function(){return s.twilsock.delete(r,i,a,n)}));case 10:this.registrationId=null,this.currentState.notificationId="",Y.debug("Registration removed for ".concat(this.channelType)),e.next=19;break;case 15:throw e.prev=15,e.t0=e.catch(6),Y.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}(ee);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=E.default(e);if(t){var i=E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return S.default(this,n)}}var ae,se=function(e){_.default(a,e);var t,n,r,i=ie(a);function a(e,t,n){var r;return w.default(this,a),r=i.call(this,"twilsock"),C.default(I.default(r),"contextId",j.v4()),r.productId=e,r.platform=t,r.twilsock=n,r}return x.default(a,[{key:"updateRegistration",value:(r=k.default(T.default.mark((function e(t,n){var r,i;return T.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),Y.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=k.default(T.default.mark((function e(){return T.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),Y.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=k.default(T.default.mark((function e(t){return T.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}(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=E.default(e);if(t){var i=E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return S.default(this,n)}}var ue=m.literal("apn","fcm","twilsock");e.Notifications=ae=function(e){_.default(Client,e);var t,n,r,i=oe(Client);function Client(e){var t,n,r,a,s,o,u,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};w.default(this,Client),u=i.call(this),l.logLevel=null!==(t=l.logLevel)&&void 0!==t?t:"error",Y.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=ae._detectPlatform();return u.connectors.set("apn",new re("apn",{protocolVersion:4,productId:f,platform:g},p,m)),u.connectors.set("fcm",new re("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 x.default(Client,[{key:"shutdown",value:(r=k.default(T.default.mark((function e(){return T.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){Y.debug("Set ".concat(e," push registration id '").concat(t,"'")),this._connector(e).setNotificationId(t)}},{key:"subscribe",value:function(e,t){Y.debug("Add ".concat(e," subscriptions for message type ").concat(t)),this._connector(e).subscribe(t)}},{key:"unsubscribe",value:function(e,t){Y.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=k.default(T.default.mark((function e(){var t;return T.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=k.default(T.default.mark((function e(t,n){return T.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){Y.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}(U),M([m.validateTypes(ue,m.nonEmptyString),L("design:type",Function),L("design:paramtypes",[String,String]),L("design:returntype",void 0)],e.Notifications.prototype,"setPushRegistrationId",null),M([m.validateTypes(ue,m.nonEmptyString),L("design:type",Function),L("design:paramtypes",[String,String]),L("design:returntype",void 0)],e.Notifications.prototype,"subscribe",null),M([m.validateTypes(ue,m.nonEmptyString),L("design:type",Function),L("design:paramtypes",[String,String]),L("design:returntype",void 0)],e.Notifications.prototype,"unsubscribe",null),M([m.validateTypes(m.nonEmptyString),L("design:type",Function),L("design:paramtypes",[String]),L("design:returntype",void 0)],e.Notifications.prototype,"updateToken",null),M([m.validateTypesAsync(ue,m.nonEmptyString),L("design:type",Function),L("design:paramtypes",[String,String]),L("design:returntype",Promise)],e.Notifications.prototype,"removeRegistrations",null),e.Notifications=ae=M([m.validateConstructorTypes(m.nonEmptyString,[m.pureObject,"undefined",m.literal(null)]),L("design:paramtypes",[String,Object])],e.Notifications)}(aE);var mE={};Object.defineProperty(mE,"__esModule",{value:!0});var gE=kg.exports,bE=rv.exports,kE=ny.exports,wE=ov.exports,xE=iv.exports,_E=sv.exports,SE=uv.exports,EE=ay.exports,TE=wg,RE=Ph.exports,IE=ih,CE=bg,OE=OS.exports,PE=bf.exports,AE=qh.exports,jE=Mm,ME=tb,LE=ry.exports,NE=ty,UE=MS.exports;function DE(e){return e&&"object"===Oa(e)&&"default"in e?e:{default:e}}function FE(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 BE=DE(gE),qE=DE(bE),zE=DE(kE),WE=DE(wE),GE=DE(xE),$E=DE(_E),VE=DE(SE),JE=DE(EE),KE=DE(TE),HE=DE(RE),YE=DE(OE),QE=FE(PE),XE=DE(AE),ZE=FE(ME),eT=DE(LE),tT=FE(UE);function nT(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":HE.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 rT(e,t){if("object"===("undefined"==typeof Reflect?"undefined":HE.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}var iT=function(){function e(t){qE.default(this,e),this.base=t,this.args=new Array,this.paths=new Array}return zE.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 aT(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=VE.default(e);if(t){var i=VE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return $E.default(this,n)}}var sT=function(e){GE.default(n,e);var t=aT(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 qE.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)),oT=function(e){GE.default(n,e);var t=aT(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 qE.default(this,n),(r=t.call(this,e,i,a)).body=s,r}return n}(sT);function uT(e){return JSON.parse(JSON.stringify(e))}function cT(e){if(!(void 0===e||lT(e)))throw new sT("Invalid pageSize parameter. Expected a positive integer, was '".concat(e,"'."),400,20007)}function lT(e){return function(e){return!isNaN(parseInt(e))&&isFinite(e)}(e)&&e>0}var fT=QE.getLogger("twilio-sync");function dT(e,t){return["".concat((new Date).toISOString()," Sync ").concat(e,":")].concat(Array.from(t))}var pT=function(e){fT.setLevel(e)},hT=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];fT.trace.apply(null,dT("T",t))},vT=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];fT.debug.apply(null,dT("D",t))},yT=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];fT.warn.apply(null,dT("W",t))},mT=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];fT.error.apply(null,dT("E",t))},gT="/v4/Subscriptions",bT="/v3/Maps",kT="/v3/Lists",wT="/v3/Documents",xT="/v3/Streams",_T="/v3/Insights";function ST(e,t,n){return e&&void 0!==e[t]?e[t]:n}var ET=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};qE.default(this,e);var n=t.region||"us1",r="https://cds.".concat(n,".twilio.com"),i=t.cdsUri||r;this.settings={subscriptionsUri:i+gT,documentsUri:i+wT,listsUri:i+kT,mapsUri:i+bT,streamsUri:i+xT,insightsUri:i+_T,sessionStorageEnabled:ST(t.Sync,"enableSessionStorage",!0),productId:t.productId}}return zE.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 TT(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 RT(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 RT(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 RT(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 IT=function(){function e(t){qE.default(this,e),this.localObject=t,this.pendingCorrelationId=null,this.pendingAction=null,this.established=!1,this.retryCount=0}return zE.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 sT("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}(),CT=function(){function e(t){var n=this;qE.default(this,e),JE.default(this,"isConnected",!1),JE.default(this,"maxBatchSize",100),JE.default(this,"subscriptionTtlTimer",null),JE.default(this,"pendingPokeReason",null),this.services=t,this.subscriptions=new Map,this.persisted=new Map,this.latestPokeResponseArrivalTimestampByCorrelationId=new Map;this.backoff=jE.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(),vT("All subscriptions resolved."))}))}var t;return zE.default(e,[{key:"getSubscriptionUpdateBatch",value:function(){function e(e,t,n,r){var i,a=[],s=TT(e);try{for(s.s();!(i=s.n()).done;){var o=XE.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=BE.default(KE.default.mark((function e(t,n){var r,i,a,s,o,u,c,l,f,d,p,h,v=this;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isConnected){e.next=4;break}return vT("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=TT(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):mT("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=TT(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 CE.TransportUnavailableError?(vT("Twilsock connection (required for subscription) not ready (c:".concat(r,"); waiting…")),this.backoff.reset()):(vT("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;vT("Attempting '".concat(e,"' request (c:").concat(t,"):"),i);var s={event_protocol_version:4,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){vT("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 IT(t)),this.persist())}},{key:"remove",value:function(e){vT("Establishing intent to unsubscribe from ".concat(e)),this.subscriptions.delete(e)&&this.persist()}},{key:"acceptMessage",value:function(e,t){hT("Subscriptions received",e);var n=e.event_type,r=void 0!==e.events?e.events:[e.event],i=e.correlation_id;i&&this.latestPokeResponseArrivalTimestampByCorrelationId.set(i,(new Date).getTime());var a,s=TT(r);try{for(s.s();!(a=s.n()).done;){var o=a.value,u=void 0;switch(e.event_type){case"subscription_established":this.applySubscriptionEstablishedMessage(o,i);break;case"subscription_canceled":this.applySubscriptionCancelledMessage(o,i);break;case"subscription_failed":this.applySubscriptionFailedMessage(o,i);break;case(u=n.match(/^(?:map|list|document|stream|live_query)_/)||{}).input:var c=void 0;switch(u[0]){case"map_":c=o.map_sid;break;case"list_":c=o.list_sid;break;case"document_":c=o.document_sid;break;case"stream_":c=o.stream_sid;break;case"live_query_":c=o.query_id,t=!1,!0===e.strictly_ordered&&(t=!0);break;default:c=void 0}this.applyEventToSubscribedEntity(c,o,n,t);break;default:vT("Dropping unknown message type ".concat(n))}}}catch(e){s.e(e)}finally{s.f()}}},{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?(vT("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&&(vT("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()):vT("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)):vT("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&&(mT("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,r){if(e){var i;r=r||(i=this.persisted.get(e))&&i.isEstablished;var a=this.subscriptions.get(e);a?(t.type=n,a.update(t,r)):vT("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){vT("Triggering event replay for all subscriptions, reason=".concat(e)),this.pendingPokeReason=e,this.subscriptionTtlTimer&&(clearTimeout(this.subscriptionTtlTimer),this.subscriptionTtlTimer=null);var t,n=[],r=TT(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 OT(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 PT(e){return e.body?e.body.code:0}function AT(e){return 409===e.status?new oT(OT(e),e.status,PT(e),e.body):e.status?new sT(OT(e),e.status,PT(e)):e instanceof CE.TransportUnavailableError?e:new sT(e.message,0,0)}var jT=function(){function e(t,n,r){qE.default(this,e),this.clientInfo=t,this.config=n,this.transport=r}return zE.default(e,[{key:"createHeaders",value:function(){return{"Content-Type":"application/json","Twilio-Sync-Client-Info":JSON.stringify(this.clientInfo),"Twilio-Request-Id":"RQ"+ZE.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 jE.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(AT(e),isNaN(t)?null:1e3*t)}else"Twilsock disconnected"===e.message?s.failed(AT(e)):(s.removeAllListeners(),s.cancel(),i(AT(e)))}))})),s.on("succeeded",(function(e){r(e)})),s.on("cancelled",(function(e){return i(AT(e))})),s.on("failed",(function(e){return i(AT(e))})),s.start()}))}},{key:"get",value:function(e){var t=this,n=this.createHeaders();return vT("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),vT("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),vT("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 vT("DELETE",e,"ID:",n["Twilio-Request-Id"]),this.executeWithRetry((function(){return t.transport.delete(e,n,t.config.productId)}),!1)}}]),e}(),MT=function(){function e(t,n){qE.default(this,e),this.config=t,this.storageId=null;try{this.storage=n||sessionStorage}catch(e){}}return zE.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 LT(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 NT(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 NT(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 NT(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 UT=function(){function e(t,n){qE.default(this,e),this.services=t,this.removalHandler=n,this.subscriptionState="none",this._attachedListeners=new Map}return zE.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){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var i,a=LT(this._attachedListeners.values());try{for(a.s();!(i=a.n()).done;){var s=i.value;s.emit.apply(s,[e].concat(n))}}catch(e){a.e(e)}finally{a.f()}}}]),e}(),DT=function(){function e(t){qE.default(this,e),JE.default(this,"queuedRequests",[]),JE.default(this,"isRequestInFlight",!1),this.inputMergingFunction=t}return zE.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}(),FT=function(){function e(t){qE.default(this,e),JE.default(this,"queueByNamespaceKey",new Map),this.inputReducer=t}var t,n,r;return zE.default(e,[{key:"add",value:(r=BE.default(KE.default.mark((function e(t,n,r){return KE.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)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"squashAndAdd",value:(n=BE.default(KE.default.mark((function e(t,n,r){return KE.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=BE.default(KE.default.mark((function e(t,n){var r,i;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.queueByNamespaceKey.has(t)||this.queueByNamespaceKey.set(t,new DT(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 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=VE.default(e);if(t){var i=VE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return $E.default(this,n)}}var qT=function(e){GE.default(n,e);var t=BT(n);function n(){var e;return qE.default(this,n),(e=t.call(this)).closed=!1,e.uuid=ME.v4(),e}return zE.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}(NE.ReplayEventEmitter);function zT(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=VE.default(e);if(t){var i=VE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return $E.default(this,n)}}var WT=function(e){GE.default(f,e);var t,n,r,i,a,s,o,u,c,l=zT(f);function f(e,t,n){var r;qE.default(this,f),r=l.call(this,e,n),JE.default(WE.default(r),"isDeleted",!1);return r.updateMergingQueue=new DT((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 zE.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){hT("Document update skipped, current:",this.lastEventId,", remote:",e.id);break}var t=void 0!==this.descriptor.data?uT(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=BE.default(KE.default.mark((function e(t,n){var r,i=this;return KE.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=BE.default(KE.default.mark((function e(t,n){var r,i=this;return KE.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=BE.default(KE.default.mark((function e(t,n){return KE.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=BE.default(KE.default.mark((function e(t){var n;return KE.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=BE.default(KE.default.mark((function e(t,n){var r;return KE.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=BE.default(KE.default.mark((function e(t,n){var r,i,a;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=t(uT(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?uT(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=BE.default(KE.default.mark((function e(t){var n,r,i;return KE.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 sT("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=BE.default(KE.default.mark((function e(){var t=this;return KE.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):mT("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?uT(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=BE.default(KE.default.mark((function e(){return KE.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 sT("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}(UT),GT=function(e){GE.default(o,e);var t,n,r,i,a,s=zT(o);function o(e){var t;return qE.default(this,o),(t=s.call(this)).syncDocumentImpl=e,t.syncDocumentImpl.attach(WE.default(t)),t}return zE.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=BE.default(KE.default.mark((function e(t,n){return KE.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=BE.default(KE.default.mark((function e(t,n){return KE.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=BE.default(KE.default.mark((function e(t,n){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(){return KE.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(){eT.default(VE.default(o.prototype),"close",this).call(this),this.syncDocumentImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return WT.type}}]),o}(qT);JE.default(GT,"removed","removed"),JE.default(GT,"updated","updated"),nT([IE.validateTypesAsync(IE.pureObject,["undefined",IE.objectSchema("document metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Object,Object]),rT("design:returntype",Promise)],GT.prototype,"set",null),nT([IE.validateTypesAsync("function",["undefined",IE.objectSchema("document metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Function,Object]),rT("design:returntype",Promise)],GT.prototype,"mutate",null),nT([IE.validateTypesAsync(IE.pureObject,["undefined",IE.objectSchema("document metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Object,Object]),rT("design:returntype",Promise)],GT.prototype,"update",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger),rT("design:type",Function),rT("design:paramtypes",[Number]),rT("design:returntype",Promise)],GT.prototype,"setTtl",null);var $T=function(){function e(t){qE.default(this,e),this.descriptor=t}return zE.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){qE.default(this,Paginator),this.prevToken=n,this.nextToken=r,this.items=e,this.source=t}var e,t;return zE.default(Paginator,[{key:"hasNextPage",get:function(){return!!this.nextToken}},{key:"hasPrevPage",get:function(){return!!this.prevToken}},{key:"nextPage",value:(t=BE.default(KE.default.mark((function e(){return KE.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=BE.default(KE.default.mark((function e(){return KE.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 VT(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 JT(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 JT(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 JT(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 KT=function(){function e(t,n){qE.default(this,e),this.balanceFactor=0,this.key=t,this.value=n,this.parent=null,this.left=null,this.right=null}return zE.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}(),HT=function(){function e(t,n){qE.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 zE.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 KT(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:KE.default.mark((function e(){var t,n,r;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=VT(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:KE.default.mark((function e(){var t,n,r,i=arguments;return KE.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:KE.default.mark((function e(){var t,n,r,i=arguments;return KE.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 YT(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 QT(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 QT(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 QT(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 XT=function(){function e(t,n){qE.default(this,e),this.value=t,this.revision=n||0}return zE.default(e,[{key:"isValid",get:function(){return!0}}]),e}(),ZT=function(){function e(t){qE.default(this,e),this.revision=t}return zE.default(e,[{key:"isValid",get:function(){return!1}}]),e}(),eR=function(){function e(){qE.default(this,e),this.items=new HT}return zE.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 XT(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 ZT(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=YT(this.items);try{for(n.s();!(t=n.n()).done;){var r=XE.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 tR(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=VE.default(e);if(t){var i=VE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return $E.default(this,n)}}var nR=function(e){GE.default(y,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v=tR(y);function y(e,t,n){var r;qE.default(this,y);return(r=v.call(this,e,n)).updateMergingQueue=new FT((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new eR,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),r}return zE.default(y,[{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:(h=BE.default(KE.default.mark((function e(t,n,r,i){var a,s;return KE.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 h.apply(this,arguments)})},{key:"push",value:(p=BE.default(KE.default.mark((function e(t,n){var r,i,a;return KE.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 p.apply(this,arguments)})},{key:"set",value:(d=BE.default(KE.default.mark((function e(t,n,r){var i,a=this;return KE.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 d.apply(this,arguments)})},{key:"_updateItemUnconditionally",value:(f=BE.default(KE.default.mark((function e(t,n,r){var i,a;return KE.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 f.apply(this,arguments)})},{key:"_updateItemWithIfMatch",value:(l=BE.default(KE.default.mark((function e(t,n,r){var i,a,s,o;return KE.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(uT(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 l.apply(this,arguments)})},{key:"mutate",value:(c=BE.default(KE.default.mark((function e(t,n,r){var i,a=this;return KE.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 c.apply(this,arguments)})},{key:"update",value:(u=BE.default(KE.default.mark((function e(t,n,r){return KE.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:"remove",value:(o=BE.default(KE.default.mark((function e(t){var n,r,i;return KE.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=uT(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)}))),function(e){return o.apply(this,arguments)})},{key:"get",value:function(){var e=BE.default(KE.default.mark((function e(t){var n;return KE.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=BE.default(KE.default.mark((function e(t){var n;return KE.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 sT("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=BE.default(KE.default.mark((function e(t){var n,r,i,a,s=this;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new iT(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=BE.default(KE.default.mark((function e(t){return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return cT((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=BE.default(KE.default.mark((function e(){var t;return KE.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=BE.default(KE.default.mark((function e(t){var n,r;return KE.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=BE.default(KE.default.mark((function e(t,n){var r,i,a;return KE.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=BE.default(KE.default.mark((function e(){return KE.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))hT("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=uT(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):(hT("Context update skipped, current:",this.lastEventId,", remote:",t),!1)}}],[{key:"type",get:function(){return"list"}}]),y}(UT),rR=function(e){GE.default(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=tR(p);function p(e){var t;return qE.default(this,p),(t=d.call(this)).syncListImpl=e,t.syncListImpl.attach(WE.default(t)),t}return zE.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 nR.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=BE.default(KE.default.mark((function e(t,n){return KE.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=BE.default(KE.default.mark((function e(t,n,r){return KE.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=BE.default(KE.default.mark((function e(t,n,r){return KE.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=BE.default(KE.default.mark((function e(t,n,r){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(t,n){return KE.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=BE.default(KE.default.mark((function e(){return KE.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(){eT.default(VE.default(p.prototype),"close",this).call(this),this.syncListImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return nR.type}}]),p}(qT);JE.default(rR,"itemAdded","itemAdded"),JE.default(rR,"itemUpdated","itemUpdated"),JE.default(rR,"itemRemoved","itemRemoved"),JE.default(rR,"removed","removed"),nT([IE.validateTypesAsync(IE.pureObject,["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Object,Object]),rT("design:returntype",Promise)],rR.prototype,"push",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger,IE.pureObject,["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Number,Object,Object]),rT("design:returntype",Promise)],rR.prototype,"set",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger,"function",["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Number,Function,Object]),rT("design:returntype",Promise)],rR.prototype,"mutate",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger,IE.pureObject,["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Number,Object,Object]),rT("design:returntype",Promise)],rR.prototype,"update",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger),rT("design:type",Function),rT("design:paramtypes",[Number]),rT("design:returntype",Promise)],rR.prototype,"remove",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger),rT("design:type",Function),rT("design:paramtypes",[Number]),rT("design:returntype",Promise)],rR.prototype,"get",null),nT([IE.validateTypesAsync(["undefined",IE.objectSchema("query options",{from:[IE.nonNegativeInteger,"undefined"],pageSize:[IE.custom((function(e){return[lT(e),"a positive integer"]})),"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Object]),rT("design:returntype",Promise)],rR.prototype,"getItems",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger),rT("design:type",Function),rT("design:paramtypes",[Number]),rT("design:returntype",Promise)],rR.prototype,"setTtl",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger,IE.nonNegativeInteger),rT("design:type",Function),rT("design:paramtypes",[Number,Number]),rT("design:returntype",Promise)],rR.prototype,"setItemTtl",null);var iR=function(){function e(t){qE.default(this,e),this.descriptor=t}return zE.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 aR(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=VE.default(e);if(t){var i=VE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return $E.default(this,n)}}var sR=function(e){GE.default(h,e);var t,n,r,i,a,s,o,u,c,l,f,d,p=aR(h);function h(e,t,n){var r;qE.default(this,h);return(r=p.call(this,e,n)).updateMergingQueue=new FT((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new eR,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 iR(e),e.last_event_id)})),r}return zE.default(h,[{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:(d=BE.default(KE.default.mark((function e(t,n,r){var i,a=this;return KE.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 d.apply(this,arguments)})},{key:"get",value:function(){var e=BE.default(KE.default.mark((function e(t){return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=t){e.next=2;break}throw new sT("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:(f=BE.default(KE.default.mark((function e(t){var n;return KE.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 sT("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 f.apply(this,arguments)})},{key:"mutate",value:(l=BE.default(KE.default.mark((function e(t,n,r){var i,a=this;return KE.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 l.apply(this,arguments)})},{key:"update",value:(c=BE.default(KE.default.mark((function e(t,n,r){return KE.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 c.apply(this,arguments)})},{key:"_putItemUnconditionally",value:(u=BE.default(KE.default.mark((function e(t,n,r){var i,a;return KE.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 u.apply(this,arguments)})},{key:"_putItemWithIfMatch",value:(o=BE.default(KE.default.mark((function e(t,n,r){var i,a,s,o,u;return KE.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 iR({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(uT(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 o.apply(this,arguments)})},{key:"_putItemToServer",value:(s=BE.default(KE.default.mark((function e(t,n,r,i){var a,s,o,u,c;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=new iT(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 s.apply(this,arguments)})},{key:"remove",value:(a=BE.default(KE.default.mark((function e(t){var n,r,i;return KE.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=uT(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)}))),function(e){return a.apply(this,arguments)})},{key:"queryItems",value:function(){var e=BE.default(KE.default.mark((function e(t){var n,r,i,a,s=this;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new iT(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 iR(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=BE.default(KE.default.mark((function e(t){return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return cT((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))hT("SyncMapItem ",e," update skipped, current:",this.lastEventId,", remote:",n);else{this._updateRootDateUpdated(a);var c=this.cache.get(e);if(!c){var l=new iR({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=uT(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=BE.default(KE.default.mark((function e(t){var n,r;return KE.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=BE.default(KE.default.mark((function e(t,n){var r,i,a;return KE.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=BE.default(KE.default.mark((function e(){return KE.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"}}]),h}(UT),oR=function(e){GE.default(f,e);var t,n,r,i,a,s,o,u,c,l=aR(f);function f(e){var t;return qE.default(this,f),(t=l.call(this)).syncMapImpl=e,t.syncMapImpl.attach(WE.default(t)),t}return zE.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 sR.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=BE.default(KE.default.mark((function e(t,n,r){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(t,n,r){return KE.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=BE.default(KE.default.mark((function e(t,n,r){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(t,n){return KE.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=BE.default(KE.default.mark((function e(){return KE.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(){eT.default(VE.default(f.prototype),"close",this).call(this),this.syncMapImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return sR.type}}]),f}(qT);function uR(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=VE.default(e);if(t){var i=VE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return $E.default(this,n)}}JE.default(oR,"itemAdded","itemAdded"),JE.default(oR,"itemUpdated","itemUpdated"),JE.default(oR,"itemRemoved","itemRemoved"),JE.default(oR,"removed","removed"),nT([IE.validateTypesAsync("string",IE.pureObject,["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[String,Object,Object]),rT("design:returntype",Promise)],oR.prototype,"set",null),nT([IE.validateTypesAsync("string"),rT("design:type",Function),rT("design:paramtypes",[String]),rT("design:returntype",Promise)],oR.prototype,"get",null),nT([IE.validateTypesAsync("string","function",["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[String,Function,Object]),rT("design:returntype",Promise)],oR.prototype,"mutate",null),nT([IE.validateTypesAsync("string",IE.pureObject,["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[String,Object,Object]),rT("design:returntype",Promise)],oR.prototype,"update",null),nT([IE.validateTypesAsync("string"),rT("design:type",Function),rT("design:paramtypes",[String]),rT("design:returntype",Promise)],oR.prototype,"remove",null),nT([IE.validateTypesAsync(["undefined",IE.objectSchema("query options",{from:["string","undefined"],pageSize:[IE.custom((function(e){return[lT(e),"a positive integer"]})),"undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Object]),rT("design:returntype",Promise)],oR.prototype,"getItems",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger),rT("design:type",Function),rT("design:paramtypes",[Number]),rT("design:returntype",Promise)],oR.prototype,"setTtl",null),nT([IE.validateTypesAsync("string",IE.nonNegativeInteger),rT("design:type",Function),rT("design:paramtypes",[String,Number]),rT("design:returntype",Promise)],oR.prototype,"setItemTtl",null);var cR=function(e){GE.default(a,e);var t,n,r,i=uR(a);function a(e,t,n){var r;return qE.default(this,a),(r=i.call(this,e,n)).descriptor=t,r}return zE.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=BE.default(KE.default.mark((function e(t){var n,r,i,a;return KE.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=BE.default(KE.default.mark((function e(t){var n,r;return KE.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=BE.default(KE.default.mark((function e(){return KE.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}(UT);nT([IE.validateTypesAsync(IE.pureObject),rT("design:type",Function),rT("design:paramtypes",[Object]),rT("design:returntype",Promise)],cR.prototype,"publishMessage",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger),rT("design:type",Function),rT("design:paramtypes",[Number]),rT("design:returntype",Promise)],cR.prototype,"setTtl",null);var lR=function(e){GE.default(a,e);var t,n,r,i=uR(a);function a(e){var t;return qE.default(this,a),(t=i.call(this)).syncStreamImpl=e,t.syncStreamImpl.attach(WE.default(t)),t}return zE.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 cR.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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=BE.default(KE.default.mark((function e(){return KE.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(){eT.default(VE.default(a.prototype),"close",this).call(this),this.syncStreamImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return cR.type}}]),a}(qT);JE.default(lR,"messagePublished","messagePublished"),JE.default(lR,"removed","removed"),nT([IE.validateTypesAsync(IE.pureObject),rT("design:type",Function),rT("design:paramtypes",[Object]),rT("design:returntype",Promise)],lR.prototype,"publishMessage",null),nT([IE.validateTypesAsync(IE.nonNegativeInteger),rT("design:type",Function),rT("design:paramtypes",[Number]),rT("design:returntype",Promise)],lR.prototype,"setTtl",null);var fR=function e(t){qE.default(this,e),this.sdk="js",this.sdkVer=t,this.os=tT.os.family,this.osVer=tT.os.version,this.pl=tT.name,this.plVer=tT.version},dR=function(){function e(){qE.default(this,e),this.names=new Map,this.entities=new Map}return zE.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 pR(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=VE.default(e);if(t){var i=VE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return $E.default(this,n)}}var hR=function(e){GE.default(n,e);var t=pR(n);function n(e,r,i,a){var s;return qE.default(this,n),(s=t.call(this,r,i)).descriptor=e,s.cache=new eR,a&&a.forEach((function(e){s.cache.store(e.key,{key:e.key,value:e.data},e.revision)})),s}return zE.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))hT("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)?hT("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}(UT);function vR(e){return yR.apply(this,arguments)}function yR(){return(yR=BE.default(KE.default.mark((function e(t){var n,r,i,a,s,o;return KE.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 sT("Invalid query",400,54507);case 3:return s={query_string:r},a===mR.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 mR=function(e){GE.default(n,e);var t=pR(n);function n(e){var r;return qE.default(this,n),(r=t.call(this)).liveQueryImpl=e,r.liveQueryImpl.attach(WE.default(r)),r}return zE.default(n,[{key:"type",get:function(){return hR.type}},{key:"lastEventId",get:function(){return this.liveQueryImpl.lastEventId}},{key:"sid",get:function(){return this.liveQueryImpl.sid}},{key:"close",value:function(){eT.default(VE.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 hR.type}}]),n}(qT);JE.default(mR,"itemUpdated","itemUpdated"),JE.default(mR,"itemRemoved","itemRemoved");var gR=function(e){GE.default(i,e);var t,n,r=pR(i);function i(e){var t;return qE.default(this,i),t=r.call(this),JE.default(WE.default(t),"queryExpression",null),JE.default(WE.default(t),"items",{}),Object.assign(WE.default(t),e),t.updateIndexName(e.indexName),t}return zE.default(i,[{key:"type",get:function(){return i.type}},{key:"search",value:(n=BE.default(KE.default.mark((function e(t){var n=this;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.items={},e.abrupt("return",vR({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 mT("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=BE.default(KE.default.mark((function e(){return KE.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 sT("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 iT(this.insightsUri).pathSegment(e).pathSegment("Items").build()}}],[{key:"type",get:function(){return"instant_query"}}]),i}(NE.ReplayEventEmitter);JE.default(gR,"searchResult","searchResult"),nT([IE.validateTypesAsync("string"),rT("design:type",Function),rT("design:paramtypes",[String]),rT("design:returntype",Promise)],gR.prototype,"search",null),nT([IE.validateTypes(IE.nonEmptyString),rT("design:type",Function),rT("design:paramtypes",[String]),rT("design:returntype",void 0)],gR.prototype,"updateIndexName",null);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=VE.default(e);if(t){var i=VE.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return $E.default(this,n)}}function kR(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 wR(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?kR(Object(n),!0).forEach((function(t){JE.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):kR(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var xR="data_sync",_R="3.2.0-rc.0";function SR(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 wR(wR({},e),{},{mode:t})}return{mode:"create_new"}}var ER="com.twilio.rtd.cds.document",TR="com.twilio.rtd.cds.list",RR="com.twilio.rtd.cds.map",IR="twilio.sync.event",Client=function(e){GE.default(Client,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y=bR(Client);function Client(e){var t,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(qE.default(this,Client),n=y.call(this),!e)throw new Error("Sync library needs a valid Twilio token to be passed");r.hasOwnProperty("logLevel")?pT(r.logLevel):pT("silent");var i=r.productId=r.productId||xR;r.clientMetadata=r.clientMetadata||{},r.clientMetadata.hasOwnProperty("type")||(r.clientMetadata.type="sync"),r.clientMetadata.hasOwnProperty("sdk")||(r.clientMetadata.sdk="JS",r.clientMetadata.sdkv=_R);var a=!r.twilsockClient;if(!r.initRegistrations){var s=new CE.InitRegistration(i);Client.populateInitRegistrations(s),r.initRegistrations=[s]}var o=r.twilsockClient=null!==(t=r.twilsockClient)&&void 0!==t?t:new CE.Twilsock(e,i,r);o.on("tokenAboutToExpire",(function(){return n.emit("tokenAboutToExpire")})),o.on("tokenExpired",(function(){return n.emit("tokenExpired")})),o.on("connectionError",(function(e){return n.emit("connectionError",e)})),o.onWithReplay("stateChanged",(function(e){n.emit("connectionStateChanged",e),n.services.subscriptions.onConnectionStateChanged("connected"===e)})),o.on("message",(function(e,t){return n._routeMessage(e,t)}));var u=new ET(r),c=new jT(new fR(_R),u,o),l=new MT(u);return n.services={config:u,twilsock:o,network:c,storage:l,router:WE.default(n),subscriptions:null},n.services.subscriptions=new CT(n.services),n.entities=new dR,a&&o.connect(),n}return zE.default(Client,[{key:"_routeMessage",value:function(e,t){switch(hT("Notification type:",e,"content:",t),e){case ER:case TR:case RR:this.services.subscriptions.acceptMessage(t,!1);break;case IR: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=BE.default(KE.default.mark((function e(){var t;return KE.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),yT("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=uT(n);e!==rR.type&&e!==oR.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=BE.default(KE.default.mark((function e(t,n){var r,i,a,s=arguments;return KE.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 sT("Cannot get entity without id",404);case 3:return i=new iT(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=BE.default(KE.default.mark((function e(t){return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(GT.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=BE.default(KE.default.mark((function e(t){return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(rR.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=BE.default(KE.default.mark((function e(t){var n,r=arguments;return KE.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(oR.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=BE.default(KE.default.mark((function e(t){return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(lR.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=BE.default(KE.default.mark((function e(t,n){var r,i;return KE.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(mR.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=BE.default(KE.default.mark((function e(t){var n,r,i,a,s=this;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=SR(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,GT.type))){e.next=14;break}return e.abrupt("return",new GT(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(GT.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 GT(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=BE.default(KE.default.mark((function e(t){var n,r,i,a,s=this;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=SR(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,oR.type))){e.next=14;break}return e.abrupt("return",new oR(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(oR.type,n.id,r),a=new sR(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 o.apply(this,arguments)})},{key:"list",value:(s=BE.default(KE.default.mark((function e(t){var n,r,i,a,s=this;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=SR(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,rR.type))){e.next=14;break}return e.abrupt("return",new rR(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(rR.type,n.id,r),a=new nR(this.services,r,(function(e,t,n){return s.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new rR(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=BE.default(KE.default.mark((function e(t){var n,r,i,a,s,o=this;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=SR(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,lR.type))){e.next=14;break}return e.abrupt("return",new lR(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(lR.type,n.id,r),a=function(e,t,n){return o.removeFromCacheAndSession(e,t,n)},s=new cR(this.services,r,a),s=this.entities.store(s),e.abrupt("return",new lR(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=BE.default(KE.default.mark((function e(){return KE.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=BE.default(KE.default.mark((function e(t){return KE.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 sT("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=BE.default(KE.default.mark((function e(t,n){var r,i,a,s,o,u=this;return KE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:return r=new iT(this.services.config.insightsUri).pathSegment(t).pathSegment("Items").build(),e.next=5,vR({network:this.services.network,uri:r,queryString:n,type:mR.type});case 5:return i=e.sent,(a=this.getCached(i.query_id,mR.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 hR(s,this.services,o,i.items)),this.storeRootInSessionCache(mR.type,i.query_id,a.liveQueryDescriptor),a=this.entities.store(a),e.abrupt("return",new mR(a));case 11:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"instantQuery",value:(t=BE.default(KE.default.mark((function e(t){var n,r=this;return KE.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 gR({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([IR,ER,TR,RR])}},{key:"version",get:function(){return _R}}]),Client}(NE.ReplayEventEmitter);JE.default(Client,"connectionStateChanged","connectionStateChanged"),JE.default(Client,"connectionError","connectionError"),JE.default(Client,"tokenAboutToExpire","tokenAboutToExpire"),JE.default(Client,"tokenExpired","tokenExpired"),nT([IE.validateTypesAsync(["undefined","string",IE.objectSchema("open document options",{id:["string","undefined"],mode:[IE.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[IE.nonNegativeInteger,"undefined"],data:[IE.pureObject,"undefined",IE.literal(null)]})]),rT("design:type",Function),rT("design:paramtypes",[Object]),rT("design:returntype",Promise)],Client.prototype,"document",null),nT([IE.validateTypesAsync(["undefined","string",IE.objectSchema("open map options",{id:["string","undefined"],mode:[IE.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[IE.nonNegativeInteger,"undefined"],data:[IE.pureObject,"undefined",IE.literal(null)],includeItems:["boolean","undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Object]),rT("design:returntype",Promise)],Client.prototype,"map",null),nT([IE.validateTypesAsync(["undefined","string",IE.objectSchema("open list options",{id:["string","undefined"],mode:[IE.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[IE.nonNegativeInteger,"undefined"],data:[IE.pureObject,"undefined",IE.literal(null)],purpose:["string","undefined"],context:[IE.pureObject,"undefined"],includeItems:["boolean","undefined"]})]),rT("design:type",Function),rT("design:paramtypes",[Object]),rT("design:returntype",Promise)],Client.prototype,"list",null),nT([IE.validateTypesAsync(["undefined","string",IE.objectSchema("open stream options",{id:["string","undefined"],mode:[IE.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[IE.nonNegativeInteger,"undefined"],data:[IE.pureObject,"undefined",IE.literal(null)]})]),rT("design:type",Function),rT("design:paramtypes",[Object]),rT("design:returntype",Promise)],Client.prototype,"stream",null),nT([IE.validateTypesAsync(IE.nonEmptyString),rT("design:type",Function),rT("design:paramtypes",[String]),rT("design:returntype",Promise)],Client.prototype,"updateToken",null),nT([IE.validateTypesAsync(IE.nonEmptyString,"string"),rT("design:type",Function),rT("design:paramtypes",[String,String]),rT("design:returntype",Promise)],Client.prototype,"liveQuery",null),nT([IE.validateTypesAsync(IE.nonEmptyString),rT("design:type",Function),rT("design:paramtypes",[String]),rT("design:returntype",Promise)],Client.prototype,"instantQuery",null),mE.Client=Client,mE.InsightsItem=function e(){qE.default(this,e)},mE.InstantQuery=gR,mE.LiveQuery=mR,mE.Paginator=Paginator;var CR=mE.SyncClient=Client;function OR(){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 PR(e,t,n){return(PR=OR()?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 AR(e){var t="function"==typeof Map?new Map:void 0;return(AR=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 PR(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)}mE.SyncDocument=GT,mE.SyncList=rR,mE.SyncListItem=$T,mE.SyncMap=oR,mE.SyncMapItem=iR,mE.SyncStream=lR;var jR,MR={},LR=hS,NR=function(e){if(LR(e))throw TypeError("The method doesn't accept regular expressions");return e},UR=pe("match"),DR=function(e){var t=/./;try{"/./"[e](t)}catch(n){try{return t[UR]=!1,"/./"[e](t)}catch(e){}}return!1},FR=In,BR=a.f,qR=Ut,zR=gr,WR=NR,GR=k,$R=DR,VR="".startsWith,JR=Math.min,KR=$R("startsWith");FR({target:"String",proto:!0,forced:!!(KR||(jR=BR(String.prototype,"startsWith"),!jR||jR.writable))&&!KR},{startsWith:function(e){var t=zR(GR(this));WR(e);var n=qR(JR(arguments.length>1?arguments[1]:void 0,t.length)),r=zR(e);return VR?VR.call(t,r,n):t.slice(n,n+r.length)===r}});var HR=a_.left,YR=L,QR=Ws;In({target:"Array",proto:!0,forced:!tc("reduce")||!QR&&YR>79&&YR<83},{reduce:function(e){return HR(this,e,arguments.length,arguments.length>1?arguments[1]:void 0)}});var XR=s,ZR=pe("iterator"),eI=!XR((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[ZR]||"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})),tI=2147483647,nI=/[^\0-\u007E]/,rI=/[.\u3002\uFF0E\uFF61]/g,iI="Overflow: input needs wider integers to process",aI=Math.floor,sI=String.fromCharCode,oI=function(e){return e+22+75*(e<26)},uI=function(e,t,n){var r=0;for(e=n?aI(e/700):e>>1,e+=aI(e/t);e>455;r+=36)e=aI(e/35);return aI(r+36*e/(e+38))},cI=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(sI(n));var u=r.length,c=u;for(u&&r.push("-");c<i;){var l=tI;for(t=0;t<e.length;t++)(n=e[t])>=a&&n<l&&(l=n);var f=c+1;if(l-a>aI((tI-s)/f))throw RangeError(iI);for(s+=(l-a)*f,a=l,t=0;t<e.length;t++){if((n=e[t])<a&&++s>tI)throw RangeError(iI);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(sI(oI(h+v%y))),d=aI(v/y)}r.push(sI(oI(d))),o=uI(s,f,c==u),s=0,++c}}++s,++a}return r.join("")},lI=In,fI=R,dI=eI,pI=Je.exports,hI=Ha,vI=Mr,yI=$l,mI=xt,gI=as,bI=ee,kI=Nr,wI=qa,xI=De,_I=S,SI=gr,EI=Hn,TI=h,RI=ms,II=hs,CI=pe,OI=fI("fetch"),PI=fI("Request"),AI=PI&&PI.prototype,jI=fI("Headers"),MI=CI("iterator"),LI="URLSearchParams",NI="URLSearchParamsIterator",UI=mI.set,DI=mI.getterFor(LI),FI=mI.getterFor(NI),BI=/\+/g,qI=Array(4),zI=function(e){return qI[e-1]||(qI[e-1]=RegExp("((?:%[\\da-f]{2}){"+e+"})","gi"))},WI=function(e){try{return decodeURIComponent(e)}catch(t){return e}},GI=function(e){var t=e.replace(BI," "),n=4;try{return decodeURIComponent(t)}catch(e){for(;n;)t=t.replace(zI(n--),WI);return t}},$I=/[!'()~]|%20/g,VI={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+"},JI=function(e){return VI[e]},KI=function(e){return encodeURIComponent(e).replace($I,JI)},HI=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:GI(r.shift()),value:GI(r.join("="))}))},YI=function(e){this.entries.length=0,HI(this.entries,e)},QI=function(e,t){if(e<t)throw TypeError("Not enough arguments")},XI=yI((function(e,t){UI(this,{type:NI,iterator:RI(DI(e).entries),kind:t})}),"Iterator",(function(){var e=FI(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})),ZI=function(){gI(this,ZI,LI);var e,t,n,r,i,a,s,o,u,c=arguments.length>0?arguments[0]:void 0,l=this,f=[];if(UI(l,{type:LI,entries:f,updateURL:function(){},updateSearchParams:YI}),void 0!==c)if(_I(c))if("function"==typeof(e=II(c)))for(n=(t=RI(c,e)).next;!(r=n.call(t)).done;){if((s=(a=(i=RI(xI(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:SI(s.value),value:SI(o.value)})}else for(u in c)bI(c,u)&&f.push({key:u,value:SI(c[u])});else HI(f,"string"==typeof c?"?"===c.charAt(0)?c.slice(1):c:SI(c))},eC=ZI.prototype;if(hI(eC,{append:function(e,t){QI(arguments.length,2);var n=DI(this);n.entries.push({key:SI(e),value:SI(t)}),n.updateURL()},delete:function(e){QI(arguments.length,1);for(var t=DI(this),n=t.entries,r=SI(e),i=0;i<n.length;)n[i].key===r?n.splice(i,1):i++;t.updateURL()},get:function(e){QI(arguments.length,1);for(var t=DI(this).entries,n=SI(e),r=0;r<t.length;r++)if(t[r].key===n)return t[r].value;return null},getAll:function(e){QI(arguments.length,1);for(var t=DI(this).entries,n=SI(e),r=[],i=0;i<t.length;i++)t[i].key===n&&r.push(t[i].value);return r},has:function(e){QI(arguments.length,1);for(var t=DI(this).entries,n=SI(e),r=0;r<t.length;)if(t[r++].key===n)return!0;return!1},set:function(e,t){QI(arguments.length,1);for(var n,r=DI(this),i=r.entries,a=!1,s=SI(e),o=SI(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=DI(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=DI(this).entries,r=kI(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 XI(this,"keys")},values:function(){return new XI(this,"values")},entries:function(){return new XI(this,"entries")}},{enumerable:!0}),pI(eC,MI,eC.entries),pI(eC,"toString",(function(){for(var e,t=DI(this).entries,n=[],r=0;r<t.length;)e=t[r++],n.push(KI(e.key)+"="+KI(e.value));return n.join("&")}),{enumerable:!0}),vI(ZI,LI),lI({global:!0,forced:!dI},{URLSearchParams:ZI}),!dI&&"function"==typeof jI){var tC=function(e){if(_I(e)){var t,n=e.body;if(wI(n)===LI)return(t=e.headers?new jI(e.headers):new jI).has("content-type")||t.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"),EI(e,{body:TI(0,String(n)),headers:TI(0,t)})}return e};if("function"==typeof OI&&lI({global:!0,enumerable:!0,forced:!0},{fetch:function(e){return OI(e,arguments.length>1?tC(arguments[1]):{})}}),"function"==typeof PI){var nC=function(e){return gI(this,nC,"Request"),new PI(e,arguments.length>1?tC(arguments[1]):{})};AI.constructor=nC,nC.prototype=AI,lI({global:!0,forced:!0},{Request:nC})}}var rC,iC={URLSearchParams:ZI,getState:DI},aC=In,sC=o,oC=eI,uC=i,cC=Nn,lC=Je.exports,fC=as,dC=ee,pC=vE,hC=yl,vC=El.codeAt,yC=function(e){var t,n,r=[],i=e.toLowerCase().replace(rI,".").split(".");for(t=0;t<i.length;t++)n=i[t],r.push(nI.test(n)?"xn--"+cI(n):n);return r.join(".")},mC=gr,gC=Mr,bC=iC,kC=xt,wC=uC.URL,xC=bC.URLSearchParams,_C=bC.getState,SC=kC.set,EC=kC.getterFor("URL"),TC=Math.floor,RC=Math.pow,IC="Invalid scheme",CC="Invalid host",OC="Invalid port",PC=/[A-Za-z]/,AC=/[\d+-.A-Za-z]/,jC=/\d/,MC=/^0x/i,LC=/^[0-7]+$/,NC=/^\d+$/,UC=/^[\dA-Fa-f]+$/,DC=/[\0\t\n\r #%/:<>?@[\\\]^|]/,FC=/[\0\t\n\r #/:<>?@[\\\]^|]/,BC=/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g,qC=/[\t\n\r]/g,zC=function(e,t){var n,r,i;if("["==t.charAt(0)){if("]"!=t.charAt(t.length-1))return CC;if(!(n=GC(t.slice(1,-1))))return CC;e.host=n}else if(XC(e)){if(t=yC(t),DC.test(t))return CC;if(null===(n=WC(t)))return CC;e.host=n}else{if(FC.test(t))return CC;for(n="",r=hC(t),i=0;i<r.length;i++)n+=YC(r[i],VC);e.host=n}},WC=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=MC.test(i)?16:8,i=i.slice(8==a?1:2)),""===i)s=0;else{if(!(10==a?NC:8==a?LC:UC).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>=RC(256,5-t))return null}else if(s>255)return null;for(o=n.pop(),r=0;r<n.length;r++)o+=n[r]*RC(256,3-r);return o},GC=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&&UC.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(!jC.test(d()))return;for(;jC.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},$C=function(e){var t,n,r,i;if("number"==typeof e){for(t=[],n=0;n<4;n++)t.unshift(e%256),e=TC(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},VC={},JC=pC({},VC,{" ":1,'"':1,"<":1,">":1,"`":1}),KC=pC({},JC,{"#":1,"?":1,"{":1,"}":1}),HC=pC({},KC,{"/":1,":":1,";":1,"=":1,"@":1,"[":1,"\\":1,"]":1,"^":1,"|":1}),YC=function(e,t){var n=vC(e,0);return n>32&&n<127&&!dC(t,e)?e:encodeURIComponent(e)},QC={ftp:21,file:null,http:80,https:443,ws:80,wss:443},XC=function(e){return dC(QC,e.scheme)},ZC=function(e){return""!=e.username||""!=e.password},eO=function(e){return!e.host||e.cannotBeABaseURL||"file"==e.scheme},tO=function(e,t){var n;return 2==e.length&&PC.test(e.charAt(0))&&(":"==(n=e.charAt(1))||!t&&"|"==n)},nO=function(e){var t;return e.length>1&&tO(e.slice(0,2))&&(2==e.length||"/"===(t=e.charAt(2))||"\\"===t||"?"===t||"#"===t)},rO=function(e){var t=e.path,n=t.length;!n||"file"==e.scheme&&1==n&&tO(t[0],!0)||t.pop()},iO=function(e){return"."===e||"%2e"===e.toLowerCase()},aO={},sO={},oO={},uO={},cO={},lO={},fO={},dO={},pO={},hO={},vO={},yO={},mO={},gO={},bO={},kO={},wO={},xO={},_O={},SO={},EO={},TO=function(e,t,n,r){var i,a,s,o,u,c=n||aO,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(BC,"")),t=t.replace(qC,""),i=hC(t);l<=i.length;){switch(a=i[l],c){case aO:if(!a||!PC.test(a)){if(n)return IC;c=oO;continue}f+=a.toLowerCase(),c=sO;break;case sO:if(a&&(AC.test(a)||"+"==a||"-"==a||"."==a))f+=a.toLowerCase();else{if(":"!=a){if(n)return IC;f="",c=oO,l=0;continue}if(n&&(XC(e)!=dC(QC,f)||"file"==f&&(ZC(e)||null!==e.port)||"file"==e.scheme&&!e.host))return;if(e.scheme=f,n)return void(XC(e)&&QC[e.scheme]==e.port&&(e.port=null));f="","file"==e.scheme?c=gO:XC(e)&&r&&r.scheme==e.scheme?c=uO:XC(e)?c=dO:"/"==i[l+1]?(c=cO,l++):(e.cannotBeABaseURL=!0,e.path.push(""),c=_O)}break;case oO:if(!r||r.cannotBeABaseURL&&"#"!=a)return IC;if(r.cannotBeABaseURL&&"#"==a){e.scheme=r.scheme,e.path=r.path.slice(),e.query=r.query,e.fragment="",e.cannotBeABaseURL=!0,c=EO;break}c="file"==r.scheme?gO:lO;continue;case uO:if("/"!=a||"/"!=i[l+1]){c=lO;continue}c=pO,l++;break;case cO:if("/"==a){c=hO;break}c=xO;continue;case lO:if(e.scheme=r.scheme,a==rC)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&&XC(e))c=fO;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=SO;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=xO;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=EO}break;case fO:if(!XC(e)||"/"!=a&&"\\"!=a){if("/"!=a){e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,c=xO;continue}c=hO}else c=pO;break;case dO:if(c=pO,"/"!=a||"/"!=f.charAt(l+1))continue;l++;break;case pO:if("/"!=a&&"\\"!=a){c=hO;continue}break;case hO:if("@"==a){d&&(f="%40"+f),d=!0,s=hC(f);for(var v=0;v<s.length;v++){var y=s[v];if(":"!=y||h){var m=YC(y,HC);h?e.password+=m:e.username+=m}else h=!0}f=""}else if(a==rC||"/"==a||"?"==a||"#"==a||"\\"==a&&XC(e)){if(d&&""==f)return"Invalid authority";l-=hC(f).length+1,f="",c=vO}else f+=a;break;case vO:case yO:if(n&&"file"==e.scheme){c=kO;continue}if(":"!=a||p){if(a==rC||"/"==a||"?"==a||"#"==a||"\\"==a&&XC(e)){if(XC(e)&&""==f)return CC;if(n&&""==f&&(ZC(e)||null!==e.port))return;if(o=zC(e,f))return o;if(f="",c=wO,n)return;continue}"["==a?p=!0:"]"==a&&(p=!1),f+=a}else{if(""==f)return CC;if(o=zC(e,f))return o;if(f="",c=mO,n==yO)return}break;case mO:if(!jC.test(a)){if(a==rC||"/"==a||"?"==a||"#"==a||"\\"==a&&XC(e)||n){if(""!=f){var g=parseInt(f,10);if(g>65535)return OC;e.port=XC(e)&&g===QC[e.scheme]?null:g,f=""}if(n)return;c=wO;continue}return OC}f+=a;break;case gO:if(e.scheme="file","/"==a||"\\"==a)c=bO;else{if(!r||"file"!=r.scheme){c=xO;continue}if(a==rC)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=SO;else{if("#"!=a){nO(i.slice(l).join(""))||(e.host=r.host,e.path=r.path.slice(),rO(e)),c=xO;continue}e.host=r.host,e.path=r.path.slice(),e.query=r.query,e.fragment="",c=EO}}break;case bO:if("/"==a||"\\"==a){c=kO;break}r&&"file"==r.scheme&&!nO(i.slice(l).join(""))&&(tO(r.path[0],!0)?e.path.push(r.path[0]):e.host=r.host),c=xO;continue;case kO:if(a==rC||"/"==a||"\\"==a||"?"==a||"#"==a){if(!n&&tO(f))c=xO;else if(""==f){if(e.host="",n)return;c=wO}else{if(o=zC(e,f))return o;if("localhost"==e.host&&(e.host=""),n)return;f="",c=wO}continue}f+=a;break;case wO:if(XC(e)){if(c=xO,"/"!=a&&"\\"!=a)continue}else if(n||"?"!=a)if(n||"#"!=a){if(a!=rC&&(c=xO,"/"!=a))continue}else e.fragment="",c=EO;else e.query="",c=SO;break;case xO:if(a==rC||"/"==a||"\\"==a&&XC(e)||!n&&("?"==a||"#"==a)){if(".."===(u=(u=f).toLowerCase())||"%2e."===u||".%2e"===u||"%2e%2e"===u?(rO(e),"/"==a||"\\"==a&&XC(e)||e.path.push("")):iO(f)?"/"==a||"\\"==a&&XC(e)||e.path.push(""):("file"==e.scheme&&!e.path.length&&tO(f)&&(e.host&&(e.host=""),f=f.charAt(0)+":"),e.path.push(f)),f="","file"==e.scheme&&(a==rC||"?"==a||"#"==a))for(;e.path.length>1&&""===e.path[0];)e.path.shift();"?"==a?(e.query="",c=SO):"#"==a&&(e.fragment="",c=EO)}else f+=YC(a,KC);break;case _O:"?"==a?(e.query="",c=SO):"#"==a?(e.fragment="",c=EO):a!=rC&&(e.path[0]+=YC(a,VC));break;case SO:n||"#"!=a?a!=rC&&("'"==a&&XC(e)?e.query+="%27":e.query+="#"==a?"%23":YC(a,VC)):(e.fragment="",c=EO);break;case EO:a!=rC&&(e.fragment+=YC(a,JC))}l++}},RO=function(e){var t,n,r=fC(this,RO,"URL"),i=arguments.length>1?arguments[1]:void 0,a=mC(e),s=SC(r,{type:"URL"});if(void 0!==i)if(i instanceof RO)t=EC(i);else if(n=TO(t={},mC(i)))throw TypeError(n);if(n=TO(s,a,null,t))throw TypeError(n);var o=s.searchParams=new xC,u=_C(o);u.updateSearchParams(s.query),u.updateURL=function(){s.query=String(o)||null},sC||(r.href=CO.call(r),r.origin=OO.call(r),r.protocol=PO.call(r),r.username=AO.call(r),r.password=jO.call(r),r.host=MO.call(r),r.hostname=LO.call(r),r.port=NO.call(r),r.pathname=UO.call(r),r.search=DO.call(r),r.searchParams=FO.call(r),r.hash=BO.call(r))},IO=RO.prototype,CO=function(){var e=EC(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+="//",ZC(e)&&(c+=n+(r?":"+r:"")+"@"),c+=$C(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},OO=function(){var e=EC(this),t=e.scheme,n=e.port;if("blob"==t)try{return new RO(t.path[0]).origin}catch(e){return"null"}return"file"!=t&&XC(e)?t+"://"+$C(e.host)+(null!==n?":"+n:""):"null"},PO=function(){return EC(this).scheme+":"},AO=function(){return EC(this).username},jO=function(){return EC(this).password},MO=function(){var e=EC(this),t=e.host,n=e.port;return null===t?"":null===n?$C(t):$C(t)+":"+n},LO=function(){var e=EC(this).host;return null===e?"":$C(e)},NO=function(){var e=EC(this).port;return null===e?"":String(e)},UO=function(){var e=EC(this),t=e.path;return e.cannotBeABaseURL?t[0]:t.length?"/"+t.join("/"):""},DO=function(){var e=EC(this).query;return e?"?"+e:""},FO=function(){return EC(this).searchParams},BO=function(){var e=EC(this).fragment;return e?"#"+e:""},qO=function(e,t){return{get:e,set:t,configurable:!0,enumerable:!0}};if(sC&&cC(IO,{href:qO(CO,(function(e){var t=EC(this),n=mC(e),r=TO(t,n);if(r)throw TypeError(r);_C(t.searchParams).updateSearchParams(t.query)})),origin:qO(OO),protocol:qO(PO,(function(e){var t=EC(this);TO(t,mC(e)+":",aO)})),username:qO(AO,(function(e){var t=EC(this),n=hC(mC(e));if(!eO(t)){t.username="";for(var r=0;r<n.length;r++)t.username+=YC(n[r],HC)}})),password:qO(jO,(function(e){var t=EC(this),n=hC(mC(e));if(!eO(t)){t.password="";for(var r=0;r<n.length;r++)t.password+=YC(n[r],HC)}})),host:qO(MO,(function(e){var t=EC(this);t.cannotBeABaseURL||TO(t,mC(e),vO)})),hostname:qO(LO,(function(e){var t=EC(this);t.cannotBeABaseURL||TO(t,mC(e),yO)})),port:qO(NO,(function(e){var t=EC(this);eO(t)||(""==(e=mC(e))?t.port=null:TO(t,e,mO))})),pathname:qO(UO,(function(e){var t=EC(this);t.cannotBeABaseURL||(t.path=[],TO(t,mC(e),wO))})),search:qO(DO,(function(e){var t=EC(this);""==(e=mC(e))?t.query=null:("?"==e.charAt(0)&&(e=e.slice(1)),t.query="",TO(t,e,SO)),_C(t.searchParams).updateSearchParams(t.query)})),searchParams:qO(FO),hash:qO(BO,(function(e){var t=EC(this);""!=(e=mC(e))?("#"==e.charAt(0)&&(e=e.slice(1)),t.fragment="",TO(t,e,EO)):t.fragment=null}))}),lC(IO,"toJSON",(function(){return CO.call(this)}),{enumerable:!0}),lC(IO,"toString",(function(){return CO.call(this)}),{enumerable:!0}),wC){var zO=wC.createObjectURL,WO=wC.revokeObjectURL;zO&&lC(RO,"createObjectURL",(function(e){return zO.apply(wC,arguments)})),WO&&lC(RO,"revokeObjectURL",(function(e){return WO.apply(wC,arguments)}))}function GO(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 $O(e){return function(e){if(Array.isArray(e))return Wy(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Gy(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.")}()}gC(RO,"URL"),aC({global:!0,forced:!oC,sham:!sC},{URL:RO}),function(e){var t=void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};Object.defineProperty(e,"__esModule",{value:!0});var n=kg.exports,r=ay.exports,i=wg,a=bf.exports,s=Mm,o=ih;function u(e){return e&&"object"===Oa(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),h=function(e){Ca(n,e);var t=GO(n);function n(e){var r,i,a;return Ma(this,n),(r=t.call(this,(function(t,n){return a=n,e(t,n,(function(e){i=e}))}))).cancel=i,r.rejectPromise=a,r}return Ta(n,[{key:"cancel",value:function(){this.onCancel&&this.onCancel(),this.rejectPromise&&this.rejectPromise(new Error("Promise was cancelled"))}}]),n}(AR(Promise));
|
130
|
-
/*! *****************************************************************************
|
131
|
-
Copyright (c) Microsoft Corporation.
|
132
|
-
|
133
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
134
|
-
purpose with or without fee is hereby granted.
|
135
|
-
|
136
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
137
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
138
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
139
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
140
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
141
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
142
|
-
PERFORMANCE OF THIS SOFTWARE.
|
143
|
-
***************************************************************************** */
|
144
|
-
function v(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":Oa(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 y(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Oa(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function m(e,t){return["".concat((new Date).toISOString()," MCS Client ").concat(e,":")].concat(Array.from(t))}var g=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,m(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,m(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,m(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,m(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,m(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,m("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,m("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,m("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,m("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,m("E",t))}}]),e}(),b=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},k=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=b(n,this.region),this.mediaSetUrl=r?b(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 new h(function(){var t=l.default(d.default.mark((function t(n,r,i){var a,s;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=e.network.get("".concat(e.config.mediaUrl,"/").concat(e.sid)),i((function(){return a.cancel()})),t.prev=2,t.next=5,a;case 5:s=t.sent,e._update(s.body),n(e.state.contentDirectUrl),t.next=13;break;case 10:t.prev=10,t.t0=t.catch(2),r(t.t0);case 13:case"end":return t.stop()}}),t,null,[[2,10]])})));return function(e,n,r){return t.apply(this,arguments)}}())}},{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}(),w=function(e){Ca(n,e);var t=GO(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}(AR(Error)),x=t.XMLHttpRequest||{};var _,S,E=function(){function e(){Ma(this,e)}return Ta(e,[{key:"get",value:function(t,n){return e.request("GET",t,n)}},{key:"post",value:function(t,n,r){return e.request("POST",t,n,r)}}],[{key:"request",value:function(e,t,n,r){return new h((function(i,a,s){var o=new x,u=!1;for(var c in s((function(){o.abort(),u=!0})),o.open(e,t,!0),o.onreadystatechange=function(){if(4===o.readyState&&!u){var e,t=(e=o.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=function(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}}(o);if(200<=o.status&&o.status<300)i({status:o.status,headers:t,body:n});else{var r,s,c=null!==(r=o.statusText)&&void 0!==r?r:"NONE";s="string"==typeof n?n&&1===n.split("\n",2).length?n:"":JSON.stringify(n);var l="".concat(o.status,": [").concat(c,"] ").concat(s);a(new w(l,o.status,n,c,t))}}},n)o.setRequestHeader(c,n[c]),"Content-Type"===c&&"application/json"===n[c]&&(r=JSON.stringify(r));o.send(r)}))}}]),e}(),T=g.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(k.backoffConfigDefault,this.config.backoffConfigOverride)}},{key:"retryWhenThrottled",value:function(){var e,t;return null!==(e=null!==(t=this.config.retryWhenThrottledOverride)&&void 0!==t?t:k.retryWhenThrottledDefault)&&void 0!==e&&e}},{key:"executeWithRetry",value:function(e,t){var n=this;return new h(function(){var r=l.default(d.default.mark((function r(i,a,o){var u,c;return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:u=new s.Retrier(n.backoffConfig()),o((function(){e.cancel(),u.removeAllListeners(),u.cancel()})),c=[502,503,504],t&&c.push(429),u.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,u.succeeded(n),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(0),c.indexOf(t.t0.status)>-1||"Twilsock disconnected"===t.t0.message?u.failed(t.t0):(u.removeAllListeners(),u.cancel(),a(t.t0));case 10:case"end":return t.stop()}}),t,null,[[0,7]])})))),u.on("succeeded",(function(e){i(e)})),u.on("cancelled",(function(e){return a(e)})),u.on("failed",(function(e){return a(e)})),u.start();case 9:case"end":return r.stop()}}),r)})));return function(e,t,n){return r.apply(this,arguments)}}())}},{key:"get",value:function(e){var t=this;return new h(function(){var n=l.default(d.default.mark((function n(r,i,a){var s,o,u;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return s={"X-Twilio-Token":t.config.token},o=t.executeWithRetry((function(){return t.transport.get(e,s)}),t.retryWhenThrottled()),T.trace("sending GET request to ",e," headers ",s),a((function(){return o.cancel()})),n.prev=4,n.next=7,o;case 7:u=n.sent,T.trace("response",u),r(u),n.next=16;break;case 12:n.prev=12,n.t0=n.catch(4),T.debug("get() error ".concat(n.t0)),i(n.t0);case 16:case"end":return n.stop()}}),n,null,[[4,12]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"post",value:function(e,n,r,i,a){var s=this,o={"X-Twilio-Token":this.config.token};"undefined"!=typeof FormData&&r instanceof FormData||!i||Object.assign(o,{"Content-Type":i});var u=new URL(e);return n&&u.searchParams.append("Category",n),a&&u.searchParams.append("Filename",a),new h(function(){var n=l.default(d.default.mark((function n(i,a,c){var l,f;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return l=s.transport.post(u.href,o,r),c((function(){return l.cancel()})),T.trace("sending POST request to ".concat(e," with headers ").concat(o)),n.prev=3,n.next=6,l;case 6:f=n.sent,n.next=17;break;case 9:if(n.prev=9,n.t0=n.catch(3),!(void 0===t.XMLHttpRequest&&r instanceof FormData)){n.next=14;break}return a(new TypeError("Posting FormData supported only with browser engine's FormData")),n.abrupt("return");case 14:return T.debug("post() error ".concat(n.t0)),a(n.t0),n.abrupt("return");case 17:T.trace("response",f),i(f);case 19:case"end":return n.stop()}}),n,null,[[3,9]])})));return function(e,t,r){return n.apply(this,arguments)}}())}}]),e}(),I=g.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 k(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 new h(function(){var n=l.default(d.default.mark((function n(r,i,a){var s,o;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return s=t.network.get("".concat(t.config.mediaUrl,"/").concat(e)),a((function(){return s.cancel()})),n.prev=2,n.next=5,s;case 5:o=n.sent,r(new Media(t.config,t.network,o.body)),n.next=12;break;case 9:n.prev=9,n.t0=n.catch(2),i(n.t0);case 12:case"end":return n.stop()}}),n,null,[[2,9]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"post",value:function(e,t,n,r){var i=this;return new h(function(){var a=l.default(d.default.mark((function a(s,o,u){var c,l;return d.default.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return c=i.network.post(i.config.mediaUrl,null!=n?n:"media",t,e,r),u((function(){return c.cancel()})),a.prev=2,a.next=5,c;case 5:l=a.sent,s(new Media(i.config,i.network,l.body)),a.next=12;break;case 9:a.prev=9,a.t0=a.catch(2),o(a.t0);case 12:case"end":return a.stop()}}),a,null,[[2,9]])})));return function(e,t,n){return a.apply(this,arguments)}}())}},{key:"postFormData",value:function(e,t){var n=this;return new h(function(){var r=l.default(d.default.mark((function r(i,a,s){var o,u;return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=n.network.post(n.config.mediaUrl,null!=t?t:"media",e),s((function(){return o.cancel()})),r.prev=2,r.next=5,o;case 5:u=r.sent,i(new Media(n.config,n.network,u.body)),r.next=12;break;case 9:r.prev=9,r.t0=r.catch(2),a(r.t0);case 12:case"end":return r.stop()}}),r,null,[[2,9]])})));return function(e,t,n){return r.apply(this,arguments)}}())}},{key:"mediaSetGet",value:function(e){var t=this;return new h(function(){var n=l.default(d.default.mark((function n(r,i,a){var s,o,u,c;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return s={command:"get",list:e.map((function(e){return{media_sid:e}}))},o=t.network.post("".concat(t.config.mediaSetUrl),null,s,"application/json"),a((function(){return o.cancel()})),n.prev=3,n.next=6,o;case 6:u=n.sent,c=u.body.map((function(e){if(200===e.code)return new Media(t.config,t.network,e.media_record);i("Failed to obtain detailed information about Media items (failed SID ".concat(e.media_record.sid,")"))})),r(c),n.next=14;break;case 11:n.prev=11,n.t0=n.catch(3),i(n.t0);case 14:case"end":return n.stop()}}),n,null,[[3,11]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"mediaSetGetContentUrls",value:function(e){var t=this;return new h(function(){var n=l.default(d.default.mark((function n(r,i,a){var s,o,u,c;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return s={command:"get",list:e.map((function(e){return{media_sid:e}}))},o=t.network.post("".concat(t.config.mediaSetUrl),null,s,"application/json"),a((function(){return o.cancel()})),n.prev=3,n.next=6,o;case 6:u=n.sent,c=new Map,u.body.forEach((function(e){200===e.code?c.set(e.media_record.sid,e.media_record.links.content_direct_temporary):i("Failed to obtain detailed information about Media items (failed SID ".concat(e.media_record.sid,")"))})),r(c),n.next=15;break;case 12:n.prev=12,n.t0=n.catch(3),i(n.t0);case 15:case"end":return n.stop()}}),n,null,[[3,12]])})));return function(e,t,r){return n.apply(this,arguments)}}())}}]),Client}(),f.default(_,"version","0.6.0-rc.1"),S),v([o.validateTypes(o.nonEmptyString),y("design:type",Function),y("design:paramtypes",[String]),y("design:returntype",void 0)],e.default.prototype,"updateToken",null),v([o.validateTypesAsync(o.nonEmptyString),y("design:type",Function),y("design:paramtypes",[String]),y("design:returntype",h)],e.default.prototype,"get",null),e.default=v([o.validateConstructorTypes(o.nonEmptyString,o.nonEmptyString,[o.nonEmptyString,o.literal(null)],[o.pureObject,"undefined"]),y("design:paramtypes",[String,String,Object,Object])],e.default),e.CancellablePromise=h,e.Client=e.default,e.McsClient=e.default,e.McsMedia=Media,e.Media=Media,e.default=e.default}(MR);var VO=is,JO="ArrayBuffer",KO=Gk.ArrayBuffer;function HO(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!==KO},{ArrayBuffer:KO}),VO(JO);var YO=Sf.scope("Participant"),Participant=function(e){Ca(Participant,e);var t,n,r,i=HO(Participant);function Participant(e,t,n,r,a){var s,o,u;if(Ma(this,Participant),(u=i.call(this)).conversation=n,u.links=r,u.services=a,u.state={attributes:nh(e.attributes,"Retrieved malformed attributes from the server for participant: "+t,YO),dateCreated:e.dateCreated?th(e.dateCreated):null,dateUpdated:e.dateCreated?th(e.dateUpdated):null,sid:t,typingTimeout:null,isTyping:!1,identity:e.identity,roleSid:null!==(s=e.roleSid)&&void 0!==s?s:"",lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,lastReadTimestamp:e.lastConsumptionTimestamp?th(e.lastConsumptionTimestamp):null,type:e.type||"chat",userInfo:e.userInfo,bindings:null!==(o=e.bindings)&&void 0!==o?o:{}},!e.identity&&!e.type)throw new Error("Received invalid Participant object from server: Missing identity or type of Participant.");return u}return Ta(Participant,[{key:"sid",get:function(){return this.state.sid}},{key:"attributes",get:function(){return this.state.attributes}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"identity",get:function(){return this.state.identity}},{key:"isTyping",get:function(){return this.state.isTyping}},{key:"lastReadMessageIndex",get:function(){return this.state.lastReadMessageIndex}},{key:"lastReadTimestamp",get:function(){return this.state.lastReadTimestamp}},{key:"roleSid",get:function(){return this.state.roleSid}},{key:"type",get:function(){return this.state.type}},{key:"bindings",get:function(){var e;return null!==(e=this.state.bindings)&&void 0!==e?e:{}}},{key:"_startTyping",value:function(e){var t=this;return this.state.typingTimeout&&clearTimeout(this.state.typingTimeout),this.state.isTyping=!0,this.emit("typingStarted",this),this.conversation.emit("typingStarted",this),this.state.typingTimeout=Number(setTimeout((function(){return t._endTyping()}),e)),this}},{key:"_endTyping",value:function(){this.state.typingTimeout&&(this.state.isTyping=!1,this.emit("typingEnded",this),this.conversation.emit("typingEnded",this),clearInterval(this.state.typingTimeout),this.state.typingTimeout=null)}},{key:"_update",value:function(e){var t=[],n=nh(e.attributes,"Retrieved malformed attributes from the server for participant: "+this.state.sid,YO);e.attributes&&!By(this.state.attributes,n)&&(this.state.attributes=n,t.push("attributes"));var r=th(e.dateUpdated);e.dateUpdated&&(null==r?void 0:r.getTime())!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=r,t.push("dateUpdated"));var i=th(e.dateCreated);if(e.dateCreated&&(null==i?void 0:i.getTime())!==(this.state.dateCreated&&this.state.dateCreated.getTime())&&(this.state.dateCreated=i,t.push("dateCreated")),e.roleSid&&this.state.roleSid!==e.roleSid&&(this.state.roleSid=e.roleSid,t.push("roleSid")),!Number.isInteger(e.lastConsumedMessageIndex)&&null!==e.lastConsumedMessageIndex||this.state.lastReadMessageIndex===e.lastConsumedMessageIndex||(this.state.lastReadMessageIndex=e.lastConsumedMessageIndex,t.push("lastReadMessageIndex")),e.lastConsumptionTimestamp){var a=new Date(e.lastConsumptionTimestamp);this.state.lastReadTimestamp&&this.state.lastReadTimestamp.getTime()===a.getTime()||(this.state.lastReadTimestamp=a,t.push("lastReadTimestamp"))}return e.bindings&&!By(this.state.bindings,e.bindings)&&(this.state.bindings=e.bindings,t.push("bindings")),t.length>0&&this.emit("updated",{participant:this,updateReasons:t}),this}},{key:"getUser",value:(r=Sa(Bc.mark((function e(){return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("chat"==this.type){e.next=2;break}throw new Error("Getting User is not supported for this Participant type: "+this.type);case 2:return e.abrupt("return",this.services.users.getUser(this.state.identity,this.state.userInfo));case 3:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"remove",value:(n=Sa(Bc.mark((function e(){return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.conversation.removeParticipant(this));case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"updateAttributes",value:(t=Sa(Bc.mark((function e(t){return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(t)});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Participant}(Dy);function QO(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"),zc([Xv(Zv),Wc("design:type",Function),Wc("design:paramtypes",[Object]),Wc("design:returntype",Promise)],Participant.prototype,"updateAttributes",null);var XO=Sf.scope("Participants"),ZO=function(e){Ca(l,e);var t,n,r,i,a,s,o,u,c=QO(l);function l(e,t,n,r,i){var a;return Ma(this,l),ja(Ra(a=c.call(this)),"rosterEntityPromise",null),a.conversation=e,a.participants=t,a.links=n,a.configuration=r,a.services=i,a}return Ta(l,[{key:"unsubscribe",value:(u=Sa(Bc.mark((function e(){return Bc.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 u.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){XO.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){XO.debug(t.conversation.sid+" itemRemoved: "+e.key);var n=e.key;if(t.participants.has(n)){var r=t.participants.get(n);t.participants.delete(n),r&&t.emit("participantLeft",r)}})),e.on("itemUpdated",(function(e){XO.debug(t.conversation.sid+" itemUpdated: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data)}));var n=[];return e.getItems().then((function e(r){return r.items.forEach((function(e){n.push(t.upsertParticipant(e.key,e.data))})),r.hasNextPage?r.nextPage().then(e):null})).then((function(){return Promise.all(n)})).then((function(){return e}))})).catch((function(e){throw t.rosterEntityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&XO.error("Failed to get roster object for conversation",t.conversation.sid,e),XO.debug("ERROR: Failed to get roster object for conversation",t.conversation.sid,e),e}))}},{key:"upsertParticipantFromResponse",value:(o=Sa(Bc.mark((function e(t){var n,r,i,a,s,o,u,c;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.sid,i=t.attributes,a=t.date_created,s=t.date_updated,o=t.identity,u=t.role_sid,c=t.messaging_binding,e.next=3,this.upsertParticipant(r,{attributes:JSON.parse(i),dateCreated:new Date(a),dateUpdated:new Date(s),identity:o,roleSid:u,lastConsumedMessageIndex:null,lastConsumptionTimestamp:null,type:null!==(n=null==c?void 0:c.type)&&void 0!==n?n:"chat"});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"upsertParticipant",value:(s=Sa(Bc.mark((function e(t,n){var r,i,a=this;return Bc.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 s.apply(this,arguments)})},{key:"getParticipants",value:(a=Sa(Bc.mark((function e(){var t=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){var e=[];return t.participants.forEach((function(t){return e.push(t)})),e})):[]);case 1:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"getParticipantBySid",value:(i=Sa(Bc.mark((function e(t){var n=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){var e=n.participants.get(t);if(!e)throw new Error("Participant with SID "+t+" was not found");return e})):null);case 1:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(r=Sa(Bc.mark((function e(t){var n,r=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){if(r.participants.forEach((function(e){e.identity===t&&(n=e)})),!n)throw new Error("Participant with identity "+t+" was not found");return n})):null);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"add",value:(n=Sa(Bc.mark((function e(t,n){var r;return Bc.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 r=e.sent,e.next=5,this.upsertParticipantFromResponse(r);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:"addNonChatParticipant",value:(t=Sa(Bc.mark((function e(t,n){var r,i,a,s,o,u=arguments;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=u.length>2&&void 0!==u[2]?u[2]:{},s=u.length>3&&void 0!==u[3]?u[3]:{},e.next=4,this.services.commandExecutor.mutateResource("post",this.links.participants,{attributes:void 0!==a?JSON.stringify(a):void 0,messaging_binding:{address:n,proxy_address:t,name:null==s||null===(r=s.email)||void 0===r?void 0:r.name,level:null==s||null===(i=s.email)||void 0===i?void 0:i.level}});case 4:return o=e.sent,e.next=7,this.upsertParticipantFromResponse(o);case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})},{key:"remove",value:function(e){return this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(e))}}]),l}(Dy),eP=In,tP=Cn,nP=Q,rP=Ut,iP=gr,aP=s,sP=T_,oP=tc,uP=I_,cP=C_,lP=L,fP=P_,dP=[],pP=dP.sort,hP=aP((function(){dP.sort(void 0)})),vP=aP((function(){dP.sort(null)})),yP=oP("sort"),mP=!aP((function(){if(lP)return lP<70;if(!(uP&&uP>3)){if(cP)return!0;if(fP)return fP<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++)dP.push({k:t+r,v:n})}for(dP.sort((function(e,t){return t.v-e.v})),r=0;r<dP.length;r++)t=dP[r].k.charAt(0),i.charAt(i.length-1)!==t&&(i+=t);return"DGBEFHACIJK"!==i}}));eP({target:"Array",proto:!0,forced:hP||!vP||!yP||!mP},{sort:function(e){void 0!==e&&tP(e);var t=nP(this);if(mP)return void 0===e?pP.call(t):pP.call(t,e);var n,r,i=[],a=rP(t.length);for(r=0;r<a;r++)r in t&&i.push(t[r]);for(n=(i=sP(i,function(e){return function(t,n){return void 0===n?-1:void 0===t?1:void 0!==e?+e(t,n)||0:iP(t)>iP(n)?1:-1}}(e))).length,r=0;r<n;)t[r]=i[r++];for(;r<a;)delete t[r++];return t}});var gP=NR,bP=k,kP=gr;In({target:"String",proto:!0,forced:!DR("includes")},{includes:function(e){return!!~kP(bP(this)).indexOf(kP(gP(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 MR.McsMedia&&(this.mcsMedia=e),this.state={sid:e.sid,category:e.category,filename:e.filename,contentType:e.contentType,size:e.size}}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:function(){var e=this;return new MR.CancellablePromise(function(){var t=Sa(Bc.mark((function t(n,r,i){var a,s,o,u;return Bc.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(s=e._fetchMcsMedia(),o=null===(a=e.mcsMedia)||void 0===a?void 0:a.getContentUrl(),i((function(){s.cancel(),o&&o.cancel()})),t.prev=3,e.mcsMedia){t.next=9;break}return t.next=7,s;case 7:u=t.sent,o=u.getContentUrl();case 9:if(t.t0=n,!o){t.next=16;break}return t.next=13,o;case 13:t.t1=t.sent,t.next=17;break;case 16:t.t1=null;case 17:t.t2=t.t1,(0,t.t0)(t.t2),t.next=24;break;case 21:t.prev=21,t.t3=t.catch(3),r(t.t3);case 24:case"end":return t.stop()}}),t,null,[[3,21]])})));return function(e,n,r){return t.apply(this,arguments)}}())}},{key:"_fetchMcsMedia",value:function(){var e=this;return new MR.CancellablePromise(function(){var t=Sa(Bc.mark((function t(n,r,i){var a;return Bc.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=e.services.mcsClient.get(e.state.sid),!e.services.mcsClient){t.next=14;break}return i((function(){return a.cancel()})),t.prev=3,t.next=6,a;case 6:e.mcsMedia=t.sent,n(e.mcsMedia),t.next=13;break;case 10:t.prev=10,t.t0=t.catch(3),r(t.t0);case 13:return t.abrupt("return");case 14:r(new Error("Media Content Service is unavailable"));case 15:case"end":return t.stop()}}),t,null,[[3,10]])})));return function(e,n,r){return t.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}(),wP=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 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)}}var _P=Sf.scope("Message"),Message=function(e){Ca(Message,e);var t,n,r,i,a,s,o=xP(Message);function Message(e,t,n,r,i,a){var s,u,c,l,f;return Ma(this,Message),(f=o.call(this)).conversation=n,f.links=r,f.configuration=i,f.services=a,f.state={sid:t.sid,index:e,author:t.author,subject:t.subject,body:null!==(s=t.text)&&void 0!==s?s:null,timestamp:t.timestamp?new Date(t.timestamp):null,dateUpdated:t.dateUpdated?new Date(t.dateUpdated):null,lastUpdatedBy:null!==(u=t.lastUpdatedBy)&&void 0!==u?u:null,attributes:nh(t.attributes,"Got malformed attributes for the message ".concat(t.sid),_P),type:null!==(c=t.type)&&void 0!==c?c:"text",media:t.type&&"media"===t.type&&t.media?new Media(t.media,f.services):null,medias:t.type&&"media"===t.type&&t.medias?t.medias.map((function(e){return new Media(e,f.services)})):null,participantSid:null!==(l=t.memberSid)&&void 0!==l?l:null,aggregatedDeliveryReceipt:t.delivery?new AggregatedDeliveryReceipt(t.delivery):null},f}return Ta(Message,[{key:"sid",get:function(){return this.state.sid}},{key:"author",get:function(){return this.state.author}},{key:"subject",get:function(){return this.state.subject}},{key:"body",get:function(){return this.state.body}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"index",get:function(){return this.state.index}},{key:"lastUpdatedBy",get:function(){return this.state.lastUpdatedBy}},{key:"dateCreated",get:function(){return this.state.timestamp}},{key:"attributes",get:function(){return this.state.attributes}},{key:"type",get:function(){return this.state.type}},{key:"media",get:function(){return this.state.media}},{key:"attachedMedia",get:function(){return this.getMediaByCategories(["media"])}},{key:"participantSid",get:function(){return this.state.participantSid}},{key:"aggregatedDeliveryReceipt",get:function(){return this.state.aggregatedDeliveryReceipt}},{key:"getMediaByCategories",value:function(e){var t;return(null!==(t=this.state.medias)&&void 0!==t?t:[]).filter((function(t){return e.includes(t.category)}))}},{key:"getEmailBody",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategories(["body"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"getEmailHistory",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategories(["history"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"_update",value:function(e){var t=[];!e.text&&"string"!=typeof e.text||e.text===this.state.body||(this.state.body=e.text,t.push("body")),e.subject&&e.subject!==this.state.subject&&(this.state.subject=e.subject,t.push("subject")),e.lastUpdatedBy&&e.lastUpdatedBy!==this.state.lastUpdatedBy&&(this.state.lastUpdatedBy=e.lastUpdatedBy,t.push("lastUpdatedBy")),e.author&&e.author!==this.state.author&&(this.state.author=e.author,t.push("author")),e.dateUpdated&&new Date(e.dateUpdated).getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=new Date(e.dateUpdated),t.push("dateUpdated")),e.timestamp&&new Date(e.timestamp).getTime()!==(this.state.timestamp&&this.state.timestamp.getTime())&&(this.state.timestamp=new Date(e.timestamp),t.push("dateCreated"));var n=nh(e.attributes,"Got malformed attributes for the message ".concat(this.sid),_P);By(this.state.attributes,n)||(this.state.attributes=n,t.push("attributes"));var r=e.delivery,i=this.state.aggregatedDeliveryReceipt;!!(r&&r.total&&r.delivered&&r.failed&&r.read&&r.sent&&r.undelivered)&&(i?i._isEquals(r)||(i._update(r),t.push("deliveryReceipt")):(this.state.aggregatedDeliveryReceipt=new AggregatedDeliveryReceipt(r),t.push("deliveryReceipt"))),t.length>0&&this.emit("updated",{message:this,updateReasons:t})}},{key:"getParticipant",value:(s=Sa(Bc.mark((function e(){var t,n,r=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=null,!this.state.participantSid){e.next=5;break}return e.next=4,this.conversation.getParticipantBySid(this.state.participantSid).catch((function(){return _P.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 _P.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(Bc.mark((function e(){var t,n;return Bc.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($O(n),$O(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:(i=Sa(Bc.mark((function e(){return Bc.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 i.apply(this,arguments)})},{key:"updateBody",value:(r=Sa(Bc.mark((function e(t){return Bc.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 r.apply(this,arguments)})},{key:"updateAttributes",value:(n=Sa(Bc.mark((function e(t){return Bc.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 n.apply(this,arguments)})},{key:"getTemporaryContentUrlsForMedia",value:function(e){var t,n=null!==(t=null==e?void 0:e.map((function(e){return e.sid})))&&void 0!==t?t:[];return this.getTemporaryContentUrlsForMediaSids(n)}},{key:"getTemporaryContentUrlsForMediaSids",value:function(e){var t=this;return new MR.CancellablePromise(function(){var n=Sa(Bc.mark((function n(r,i,a){var s,o;return Bc.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(s=t.services.mcsClient.mediaSetGetContentUrls(null!=e?e:[]),t.services.mcsClient&&e){n.next=4;break}return i(new Error("Media Content Service is unavailable")),n.abrupt("return");case 4:return a((function(){s.cancel()})),n.prev=5,n.next=8,s;case 8:o=n.sent,r(o),n.next=15;break;case 12:n.prev=12,n.t0=n.catch(5),i(n.t0);case 15:case"end":return n.stop()}}),n,null,[[5,12]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"getTemporaryContentUrlsForAttachedMedia",value:function(){var e,t=this.attachedMedia,n=null!==(e=null==t?void 0:t.map((function(e){return e.sid})))&&void 0!==e?e:[];return this.getTemporaryContentUrlsForMediaSids(n)}},{key:"_getDetailedDeliveryReceiptsPaginator",value:(t=Sa(Bc.mark((function e(t){var n,r,i,a=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.configuration.links.messagesReceipts.replace("%s",this.conversation.sid).replace("%s",this.sid),r=new rh(n).arg("PageToken",null==t?void 0:t.pageToken).arg("PageSize",null==t?void 0:t.pageSize).build(),e.next=4,this.services.network.get(r);case 4:return i=e.sent,e.abrupt("return",new wP(i.body.delivery_receipts.map((function(e){return new DetailedDeliveryReceipt(e)})),(function(e,t){return a._getDetailedDeliveryReceiptsPaginator({pageToken:e,pageSize:t})}),i.body.meta.previous_token,i.body.meta.next_token));case 6:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Message}(Dy);function SP(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 EP(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 EP(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 EP(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 TP(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"),zc([Qv([Vv,"undefined"]),Wc("design:type",Function),Wc("design:paramtypes",[Object]),Wc("design:returntype",Media)],Message.prototype,"getEmailBody",null),zc([Qv([Vv,"undefined"]),Wc("design:type",Function),Wc("design:paramtypes",[Object]),Wc("design:returntype",Media)],Message.prototype,"getEmailHistory",null),zc([Xv("string"),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],Message.prototype,"updateBody",null),zc([Xv(Zv),Wc("design:type",Function),Wc("design:paramtypes",[Object]),Wc("design:returntype",Promise)],Message.prototype,"updateAttributes",null),zc([Xv(Gv((function(e){return[e instanceof Array&&e.length>0&&e.reduce((function(e,t){return e&&t instanceof Media}),!0),"a non-empty array of Media"]}))),Wc("design:type",Function),Wc("design:paramtypes",[Array]),Wc("design:returntype",MR.CancellablePromise)],Message.prototype,"getTemporaryContentUrlsForMedia",null);var RP=Sf.scope("Messages"),IP=function(e){Ca(u,e);var t,n,r,i,a,s,o=TP(u);function u(e,t,n){var r;return Ma(this,u),(r=o.call(this)).conversation=e,r.configuration=t,r.services=n,r.messagesByIndex=new Map,r.messagesListPromise=null,r}return Ta(u,[{key:"subscribe",value:(s=Sa(Bc.mark((function e(t){var n,r=this;return Bc.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){RP.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)?RP.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){RP.debug("#{this.conversation.sid} itemRemoved: ".concat(e.index));var t=e.index;if(r.messagesByIndex.has(t)){var n=r.messagesByIndex.get(t);if(!n)return;r.messagesByIndex.delete(n.index),n.removeAllListeners("updated"),r.emit("messageRemoved",n)}})),n.on("itemUpdated",(function(e){RP.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&&RP.error("Failed to get messages object for conversation",this.conversation.sid,e.t0),RP.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 s.apply(this,arguments)})},{key:"unsubscribe",value:(a=Sa(Bc.mark((function e(){return Bc.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 a.apply(this,arguments)})},{key:"sendV2",value:function(e){var t=this;return RP.debug("Sending message V2",e.mediaContent,e.attributes,e.emailOptions),new MR.CancellablePromise(function(){var n=Sa(Bc.mark((function n(r,i,a){var s,o,u,c,l,f,d,p,h,v,y,m;return Bc.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:o=[],u=[],a((function(){u.forEach((function(e){return e.cancel()}))})),c=SP(e.mediaContent),n.prev=4,c.s();case 6:if((l=c.n()).done){n.next=25;break}return f=$y(l.value,2),d=f[0],p=f[1],n.prev=8,RP.debug("Adding media to a message as ".concat(p instanceof FormData?"FormData":"SendMediaOptions"),p),y=p instanceof FormData?t.services.mcsClient.postFormData(p,d):t.services.mcsClient.post(null!==(h=p.contentType)&&void 0!==h?h:"",null!==(v=p.media)&&void 0!==v?v:"",d,p.filename),u.push(y),n.t0=o,n.next=15,y;case 15:n.t1=n.sent,n.t0.push.call(n.t0,n.t1),n.next=23;break;case 19:return n.prev=19,n.t2=n.catch(8),i(n.t2),n.abrupt("return");case 23:n.next=6;break;case 25:n.next=30;break;case 27:n.prev=27,n.t3=n.catch(4),c.e(n.t3);case 30:return n.prev=30,c.f(),n.finish(30);case 33:return m=t.services.commandExecutor.mutateResource("post",t.conversation._links.messages,{body:e.text,subject:null===(s=e.emailOptions)||void 0===s?void 0:s.subject,media_sids:o.map((function(e){return e.sid})),attributes:void 0!==e.attributes?JSON.stringify(e.attributes):void 0}),n.prev=34,n.t4=r,n.next=38,m;case 38:n.t5=n.sent,(0,n.t4)(n.t5),n.next=45;break;case 42:n.prev=42,n.t6=n.catch(34),i(n.t6);case 45:case"end":return n.stop()}}),n,null,[[4,27,30,33],[8,19],[34,42]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"send",value:(i=Sa(Bc.mark((function e(t){var n,r,i=arguments;return Bc.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,RP.debug("Sending text message",t,n,r),e.abrupt("return",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 4:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"sendMedia",value:(r=Sa(Bc.mark((function e(t){var n,r,i,a,s,o=arguments;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=o.length>1&&void 0!==o[1]?o[1]:{},a=o.length>2?o[2]:void 0,RP.debug("Sending media message",t,i,a),RP.debug("Sending media message as ".concat(t instanceof FormData?"FormData":"SendMediaOptions"),t,i),!(t instanceof FormData)){e.next=10;break}return e.next=7,this.services.mcsClient.postFormData(t);case 7:e.t0=e.sent,e.next=13;break;case 10:return e.next=12,this.services.mcsClient.post(null!==(n=t.contentType)&&void 0!==n?n:"",null!==(r=t.media)&&void 0!==r?r:"","media",t.filename);case 12:e.t0=e.sent;case 13:return s=e.t0,e.next=16,this.services.commandExecutor.mutateResource("post",this.conversation._links.messages,{media_sids:[s.sid],attributes:void 0!==i?JSON.stringify(i):void 0});case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getMessages",value:(n=Sa(Bc.mark((function e(t,n){var r,i=arguments;return Bc.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(Bc.mark((function e(){var t,n,r,i,a,s,o=this,u=arguments;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:30,n=u.length>1&&void 0!==u[1]?u[1]:"end",r=u.length>2&&void 0!==u[2]?u[2]:"forward",i="backwards"===r?"desc":"asc",e.next=6,this.messagesListPromise;case 6:return a=e.sent,e.next=9,null==a?void 0:a.getItems({from:"end"!==n?n:void 0,pageSize:t,order:i,limit:t});case 9:return s=e.sent,e.next=12,this._wrapPaginator(i,s,(function(e){return Promise.all(e.map((function(e){return o._upsertMessage(e.index,e.data)})))}));case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),u}(Dy),CP=function(){function e(t){Ma(this,e),ja(this,"attributes",{}),ja(this,"mediaContent",[]),ja(this,"emailOptions",{}),this.messagesEntity=t}return Ta(e,[{key:"send",value:function(){var e=this;return new MR.CancellablePromise(function(){var t=Sa(Bc.mark((function t(n,r,i){var a,s;return Bc.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=e.messagesEntity.sendV2(e),i((function(){return a.cancel()})),t.prev=2,t.next=5,a;case 5:s=t.sent,n(eh(s.index)),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(2),r(t.t0);case 12:case"end":return t.stop()}}),t,null,[[2,9]])})));return function(e,n,r){return t.apply(this,arguments)}}())}}]),e}(),OP=function(){function e(t,n){Ma(this,e),this.limits=t,this.message=new CP(n),this.emailBodies=new Map,this.emailHistories=new Map}return Ta(e,[{key:"setBody",value:function(e){return this.message.text=e,this}},{key:"setSubject",value:function(e){return this.message.emailOptions.subject=e,this}},{key:"setAttributes",value:function(e){return this.message.attributes=e,this}},{key:"setEmailBody",value:function(e,t){return this.emailBodies.set(e,t),this}},{key:"setEmailHistory",value:function(e,t){return this.emailHistories.set(e,t),this}},{key:"addMedia",value:function(e){if("undefined"==typeof FormData&&e instanceof FormData)throw new Error("Could not add FormData content whilst not in a browser");if(!(e instanceof FormData)){var t=e;if(!t.contentType||!t.media)throw new Error("Media content in SendMediaOptions must contain non-empty contentType and media")}return this.message.mediaContent.push(["media",e]),this}},{key:"build",value:function(){var e=this;if(this.emailBodies.forEach((function(t,n){if(!e.limits.emailBodiesAllowedContentTypes.includes(n))throw new Error("Unsupported email body content type ".concat(n))})),this.emailHistories.forEach((function(t,n){if(!e.limits.emailHistoriesAllowedContentTypes.includes(n))throw new Error("Unsupported email history content type ".concat(n))})),this.emailBodies.size>this.limits.emailBodiesAllowedContentTypes.length)throw new Error("Too many email bodies attached to the message (".concat(this.emailBodies.size," > ").concat(this.limits.emailBodiesAllowedContentTypes.length,")"));if(this.emailHistories.size>this.limits.emailHistoriesAllowedContentTypes.length)throw new Error("Too many email histories attached to the message (".concat(this.emailHistories.size," > ").concat(this.limits.emailHistoriesAllowedContentTypes.length,")"));if(this.message.mediaContent.length>this.limits.mediaAttachmentsCountLimit)throw new Error("Too many media attachments in the message (".concat(this.message.mediaContent.length," > ").concat(this.limits.mediaAttachmentsCountLimit,")"));return this.emailBodies.forEach((function(t){e.message.mediaContent.push(["body",t])})),this.emailHistories.forEach((function(t){e.message.mediaContent.push(["history",t])})),this.message}},{key:"buildAndSend",value:function(){return this.build().send()}},{key:"getPayloadContentType",value:function(e){return"undefined"!=typeof FormData&&e instanceof FormData?e.get("Content-Type"):e.contentType}}]),e}();function PP(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 AP(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 AP(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 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 jP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var MP={lastMessage:"lastMessage",attributes:"attributes",createdBy:"createdBy",dateCreated:"dateCreated",dateUpdated:"dateUpdated",friendlyName:"friendlyName",lastConsumedMessageIndex:"lastConsumedMessageIndex",notificationLevel:"notificationLevel",sid:"sid",status:"status",uniqueName:"uniqueName",state:"state",bindings:"bindings"},Conversation=function(e){Ca(Conversation,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y,m,g,b,k,w,x,_,S,E,T,R,I=jP(Conversation);function Conversation(e,t,n,r,i){var a,s,o;Ma(this,Conversation),(o=I.call(this)).sid=t,o._links=n,o._configuration=r,o._services=i,o._entityName=e.channel,o._internalState={uniqueName:e.uniqueName||null,status:"notParticipating",attributes:null!==(a=e.attributes)&&void 0!==a?a:{},createdBy:e.createdBy,dateCreated:th(e.dateCreated),dateUpdated:th(e.dateUpdated),friendlyName:e.friendlyName||null,lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,bindings:null!==(s=e.bindings)&&void 0!==s?s:{}},e.notificationLevel&&(o._internalState.notificationLevel=e.notificationLevel);var u={participants:o._links.participants};return o._participants=new Map,o._participantsEntity=new ZO(Ra(o),o._participants,u,o._configuration,o._services),o._participantsEntity.on("participantJoined",(function(e){return o.emit("participantJoined",e)})),o._participantsEntity.on("participantLeft",(function(e){return o.emit("participantLeft",e)})),o._participantsEntity.on("participantUpdated",(function(e){return o.emit("participantUpdated",e)})),o._messagesEntity=new IP(Ra(o),r,i),o._messagesEntity.on("messageAdded",(function(e){return o._onMessageAdded(e)})),o._messagesEntity.on("messageUpdated",(function(e){return o.emit("messageUpdated",e)})),o._messagesEntity.on("messageRemoved",(function(e){return o.emit("messageRemoved",e)})),o}return Ta(Conversation,[{key:"uniqueName",get:function(){return this._internalState.uniqueName}},{key:"status",get:function(){return this._internalState.status}},{key:"friendlyName",get:function(){return this._internalState.friendlyName}},{key:"dateUpdated",get:function(){return this._internalState.dateUpdated}},{key:"dateCreated",get:function(){return this._internalState.dateCreated}},{key:"createdBy",get:function(){var e;return null!==(e=this._internalState.createdBy)&&void 0!==e?e:""}},{key:"attributes",get:function(){return this._internalState.attributes}},{key:"lastReadMessageIndex",get:function(){return this._internalState.lastReadMessageIndex}},{key:"lastMessage",get:function(){var e;return null!==(e=this._internalState.lastMessage)&&void 0!==e?e:void 0}},{key:"notificationLevel",get:function(){var e;return null!==(e=this._internalState.notificationLevel)&&void 0!==e?e:"default"}},{key:"bindings",get:function(){return this._internalState.bindings}},{key:"limits",get:function(){return this._configuration.limits}},{key:"state",get:function(){return this._internalState.state}},{key:"_statusSource",get:function(){return this._dataSource}},{key:"add",value:(R=Sa(Bc.mark((function e(t,n){return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this._participantsEntity.add(t,null!=n?n:{}));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return R.apply(this,arguments)})},{key:"addNonChatParticipant",value:(T=Sa(Bc.mark((function e(t,n){var r,i,a=arguments;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=a.length>2&&void 0!==a[2]?a[2]:{},i=a.length>3&&void 0!==a[3]?a[3]:{},e.abrupt("return",this._participantsEntity.addNonChatParticipant(t,n,null!=r?r:{},null!=i?i:{}));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return T.apply(this,arguments)})},{key:"advanceLastReadMessageIndex",value:(E=Sa(Bc.mark((function e(t){var n;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:if(!(t<(null!==(n=this.lastReadMessageIndex)&&void 0!==n?n:0))){e.next=6;break}return e.next=5,this._setLastReadMessageIndex(this.lastReadMessageIndex);case 5:return e.abrupt("return",e.sent);case 6:return e.next=8,this._setLastReadMessageIndex(t);case 8:return e.abrupt("return",e.sent);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return E.apply(this,arguments)})},{key:"delete",value:(S=Sa(Bc.mark((function e(){return Bc.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 S.apply(this,arguments)})},{key:"getAttributes",value:(_=Sa(Bc.mark((function e(){return Bc.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 _.apply(this,arguments)})},{key:"getMessages",value:(x=Sa(Bc.mark((function e(t,n,r){return Bc.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 x.apply(this,arguments)})},{key:"getParticipants",value:(w=Sa(Bc.mark((function e(){return Bc.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 w.apply(this,arguments)})},{key:"getParticipantsCount",value:(k=Sa(Bc.mark((function e(){var t,n,r;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this._configuration.links.conversations).path(this.sid).build(),e.next=3,this._services.network.get(n);case 3:return r=e.sent,e.abrupt("return",null!==(t=r.body.participants_count)&&void 0!==t?t:0);case 5:case"end":return e.stop()}}),e,this)}))),function(){return k.apply(this,arguments)})},{key:"getParticipantBySid",value:(b=Sa(Bc.mark((function e(t){return Bc.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 b.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(g=Sa(Bc.mark((function e(){var t,n=arguments;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:"",e.abrupt("return",this._participantsEntity.getParticipantByIdentity(null!=t?t:""));case 2:case"end":return e.stop()}}),e,this)}))),function(){return g.apply(this,arguments)})},{key:"getMessagesCount",value:(m=Sa(Bc.mark((function e(){var t,n,r;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this._configuration.links.conversations).path(this.sid).build(),e.next=3,this._services.network.get(n);case 3:return r=e.sent,e.abrupt("return",null!==(t=r.body.messages_count)&&void 0!==t?t:0);case 5:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"getUnreadMessagesCount",value:(y=Sa(Bc.mark((function e(){var t,n,r;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new rh(this._configuration.links.myConversations).path(this.sid).build(),e.next=3,this._services.network.get(t);case 3:if((n=e.sent).body.conversation_sid===this.sid){e.next=6;break}throw new Error("Conversation was not found in the user conversations list");case 6:if("number"!=typeof(r=n.body.unread_messages_count)){e.next=9;break}return e.abrupt("return",r);case 9:return e.abrupt("return",null);case 10:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"join",value:(v=Sa(Bc.mark((function e(){return Bc.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 v.apply(this,arguments)})},{key:"leave",value:(h=Sa(Bc.mark((function e(){return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this._internalState.status){e.next=3;break}return e.next=3,this._services.commandExecutor.mutateResource("delete","".concat(this._links.participants,"/").concat(this._configuration.userIdentity));case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"removeParticipant",value:(p=Sa(Bc.mark((function e(t){return Bc.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 p.apply(this,arguments)})},{key:"sendMessage",value:(d=Sa(Bc.mark((function e(t,n,r){var i,a,s,o;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t&&null!==t){e.next=5;break}return e.next=3,this._messagesEntity.send(t,n,r);case 3:return s=e.sent,e.abrupt("return",null!==(a=eh(s.index))&&void 0!==a?a:0);case 5:return e.next=7,this._messagesEntity.sendMedia(t,n,r);case 7:return o=e.sent,e.abrupt("return",null!==(i=eh(o.index))&&void 0!==i?i:0);case 9:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return d.apply(this,arguments)})},{key:"prepareMessage",value:function(){return new OP(this.limits,this._messagesEntity)}},{key:"setAllMessagesRead",value:(f=Sa(Bc.mark((function e(){var t;return Bc.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",0);case 8:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"setAllMessagesUnread",value:(l=Sa(Bc.mark((function e(){return Bc.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 l.apply(this,arguments)})},{key:"setUserNotificationLevel",value:(c=Sa(Bc.mark((function e(t){return Bc.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 c.apply(this,arguments)})},{key:"typing",value:function(){return this._services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:(u=Sa(Bc.mark((function e(t){return Bc.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 u.apply(this,arguments)})},{key:"updateFriendlyName",value:(o=Sa(Bc.mark((function e(t){return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._internalState.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 o.apply(this,arguments)})},{key:"updateLastReadMessageIndex",value:(s=Sa(Bc.mark((function e(t){return Bc.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 s.apply(this,arguments)})},{key:"updateUniqueName",value:(a=Sa(Bc.mark((function e(t){return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._internalState.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 a.apply(this,arguments)})},{key:"_subscribe",value:(i=Sa(Bc.mark((function e(){var t=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._entityPromise){e.next=2;break}return e.abrupt("return",this._entityPromise);case 2:return this._entityPromise=this._services.syncClient.document({id:this._entityName,mode:"open_existing"}),e.prev=3,e.next=6,this._entityPromise;case 6:return this._entity=e.sent,this._entity.on("updated",(function(e){return t._update(e.data)})),this._entity.on("removed",(function(){return t.emit("removed",t)})),this._update(this._entity.data),e.abrupt("return",this._entity);case 13:throw e.prev=13,e.t0=e.catch(3),this._entity=null,this._entityPromise=null,"disconnected"!=this._services.syncClient.connectionState&&Conversation._logger.error("Failed to get conversation object",e.t0),Conversation._logger.debug("ERROR: Failed to get conversation object",e.t0),e.t0;case 20:case"end":return e.stop()}}),e,this,[[3,13]])}))),function(){return i.apply(this,arguments)})},{key:"_subscribeStreams",value:(r=Sa(Bc.mark((function e(){var t,n,r,i,a;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._subscribe();case 3:return Conversation._logger.trace("_subscribeStreams, this.entity.data=",null===(t=this._entity)||void 0===t?void 0:t.data),r=null===(n=this._entity)||void 0===n?void 0:n.data,i=r.messages,a=r.roster,e.next=9,Promise.all([this._messagesEntity.subscribe(i),this._participantsEntity.subscribe(a)]);case 9:e.next=16;break;case 11:throw e.prev=11,e.t0=e.catch(0),"disconnected"!==this._services.syncClient.connectionState&&Conversation._logger.error("Failed to subscribe on conversation objects",this.sid,e.t0),Conversation._logger.debug("ERROR: Failed to subscribe on conversation objects",this.sid,e.t0),e.t0;case 16:case"end":return e.stop()}}),e,this,[[0,11]])}))),function(){return r.apply(this,arguments)})},{key:"_unsubscribe",value:(n=Sa(Bc.mark((function e(){return Bc.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 n.apply(this,arguments)})},{key:"_setStatus",value:function(e,t){var n=this;this._dataSource=t,this._internalState.status!==e&&(this._internalState.status=e,"joined"!==e?this._entityPromise&&this._unsubscribe().catch((function(t){if(Conversation._logger.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n._services.syncClient.connectionState)throw t})):this._subscribeStreams().catch((function(t){if(Conversation._logger.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n._services.syncClient.connectionState)throw t})))}},{key:"_update",value:function(e){var t,n,r,i,a;Conversation._logger.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=MP[c];if(l)switch(l){case MP.status:if(!e.status||"unknown"===e.status||this._internalState.status===e.status)break;this._internalState.status=e.status,s.add(l);break;case MP.attributes:if(By(this._internalState.attributes,e.attributes))break;this._internalState.attributes=e.attributes,s.add(l);break;case MP.lastConsumedMessageIndex:if(void 0===e.lastConsumedMessageIndex||e.lastConsumedMessageIndex===this._internalState.lastReadMessageIndex)break;this._internalState.lastReadMessageIndex=e.lastConsumedMessageIndex,s.add("lastReadMessageIndex");break;case MP.lastMessage:if(this._internalState.lastMessage&&!e.lastMessage){delete this._internalState.lastMessage,s.add(l);break}this._internalState.lastMessage=this._internalState.lastMessage||{},void 0!==(null===(t=e.lastMessage)||void 0===t?void 0:t.index)&&e.lastMessage.index!==this._internalState.lastMessage.index&&(this._internalState.lastMessage.index=e.lastMessage.index,s.add(l)),void 0!==(null===(n=e.lastMessage)||void 0===n?void 0:n.timestamp)&&(null===(r=this._internalState.lastMessage)||void 0===r||null===(i=r.dateCreated)||void 0===i?void 0:i.getTime())!==e.lastMessage.timestamp.getTime()&&(this._internalState.lastMessage.dateCreated=e.lastMessage.timestamp,s.add(l)),By(this._internalState.lastMessage,{})&&delete this._internalState.lastMessage;break;case MP.state:var f=e.state||void 0;if(void 0!==f&&(f.dateUpdated=new Date(f.dateUpdated)),By(this._internalState.state,f))break;this._internalState.state=f,s.add(l);break;case MP.bindings:if(By(this._internalState.bindings,e.bindings))break;this._internalState.bindings=e.bindings,s.add(l);break;default:var d=e[c]instanceof Date,p=d&&(null===(a=this._internalState[l])||void 0===a?void 0:a.getTime())===e[c].getTime(),h=!d&&this[l]===e[c];if(p||h)break;this._internalState[l]=e[c],s.add(l)}}s.size>0&&this.emit("updated",{conversation:this,updateReasons:$O(s)})}},{key:"_onMessageAdded",value:function(e){var t,n=PP(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:(t=Sa(Bc.mark((function e(t){var n;return Bc.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 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){Conversation._logger.warn("Retrieved malformed attributes from the server for conversation: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(n){Conversation._logger.warn("Retrieved malformed dateCreated from the server for conversation: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(n){Conversation._logger.warn("Retrieved malformed dateUpdated from the server for conversation: "+t),delete e.dateUpdated}try{e.lastMessage&&e.lastMessage.timestamp&&(e.lastMessage.timestamp=new Date(e.lastMessage.timestamp))}catch(n){Conversation._logger.warn("Retrieved malformed lastMessage.timestamp from the server for conversation: "+t),delete e.lastMessage.timestamp}}}]),Conversation}(Dy);ja(Conversation,"participantJoined","participantJoined"),ja(Conversation,"participantLeft","participantLeft"),ja(Conversation,"participantUpdated","participantUpdated"),ja(Conversation,"messageAdded","messageAdded"),ja(Conversation,"messageRemoved","messageRemoved"),ja(Conversation,"messageUpdated","messageUpdated"),ja(Conversation,"typingEnded","typingEnded"),ja(Conversation,"typingStarted","typingStarted"),ja(Conversation,"updated","updated"),ja(Conversation,"removed","removed"),ja(Conversation,"_logger",Sf.scope("Conversation")),zc([Xv(Vv,ey),Wc("design:type",Function),Wc("design:paramtypes",[String,Object]),Wc("design:returntype",Promise)],Conversation.prototype,"add",null),zc([Xv(Vv,Vv,ey),Wc("design:type",Function),Wc("design:paramtypes",[String,String,Object,Object]),Wc("design:returntype",Promise)],Conversation.prototype,"addNonChatParticipant",null),zc([Xv(Jv),Wc("design:type",Function),Wc("design:paramtypes",[Number]),Wc("design:returntype",Promise)],Conversation.prototype,"advanceLastReadMessageIndex",null),zc([Xv(["undefined",Jv],["undefined",Jv],["undefined",$v("backwards","forward")]),Wc("design:type",Function),Wc("design:paramtypes",[Number,Number,String]),Wc("design:returntype",Promise)],Conversation.prototype,"getMessages",null),zc([Xv(Vv),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],Conversation.prototype,"getParticipantBySid",null),zc([Xv(Vv),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],Conversation.prototype,"getParticipantByIdentity",null),zc([Xv([Vv,Participant]),Wc("design:type",Function),Wc("design:paramtypes",[Object]),Wc("design:returntype",Promise)],Conversation.prototype,"removeParticipant",null),zc([Xv(["string",FormData,$v(null),Kv("media options",{contentType:Vv,media:Gv((function(e){var t="string"==typeof e&&e.length>0||e instanceof Uint8Array||e instanceof ArrayBuffer;return"function"==typeof Blob&&(t=t||e instanceof Blob),[t,"a non-empty string, an instance of Buffer or an instance of Blob"]}))})],ey,["undefined",$v(null),Kv("email attributes",{subject:[Vv,"undefined"]})]),Wc("design:type",Function),Wc("design:paramtypes",[Object,Object,Object]),Wc("design:returntype",Promise)],Conversation.prototype,"sendMessage",null),zc([Xv($v("default","muted")),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],Conversation.prototype,"setUserNotificationLevel",null),zc([Xv(Zv),Wc("design:type",Function),Wc("design:paramtypes",[Object]),Wc("design:returntype",Promise)],Conversation.prototype,"updateAttributes",null),zc([Xv("string"),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],Conversation.prototype,"updateFriendlyName",null),zc([Xv([$v(null),Jv]),Wc("design:type",Function),Wc("design:paramtypes",[Number]),Wc("design:returntype",Promise)],Conversation.prototype,"updateLastReadMessageIndex",null),zc([Xv(["string",$v(null)]),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],Conversation.prototype,"updateUniqueName",null);var LP=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 NP(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 UP(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 UP(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 UP(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 DP(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 FP(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?DP(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):DP(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function BP(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 qP=Sf.scope("Conversations"),zP=function(e){Ca(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=BP(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 LP),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(Bc.mark((function e(t){var n,r,i,a,s,o,u,c,l,f;return Bc.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=FP({self:s.url},s.links),!(l=this.conversations.get(o))){e.next=12;break}return e.next=11,l._subscribe();case 11:return e.abrupt("return",l);case 12:return f=new Conversation({channel:u,entityName:"",uniqueName:"",attributes:null,createdBy:"",friendlyName:"",lastConsumedMessageIndex:0,dateCreated:null,dateUpdated:null},o,c,this.configuration,this.services),this.conversations.set(f.sid,f),this._registerForEvents(f),e.next=17,f._subscribe();case 17:return this.emit("conversationAdded",f),e.abrupt("return",f);case 19:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"fetchConversations",value:(l=Sa(Bc.mark((function e(){var t,n,r,i,a,s,o,u=this;return Bc.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){qP.debug("itemAdded: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),t.on("itemRemoved",(function(e){qP.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){qP.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=NP(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(),qP.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&&qP.error(o,e.t0),qP.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(Bc.mark((function e(){var t,n,r=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return t=e.sent,e.next=5,t.getItems();case 5:return n=e.sent,e.abrupt("return",this._wrapPaginator(n,(function(e){return Promise.all(e.map((function(e){return r._upsertConversation("sync",e.key,e.data)})))})));case 7:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"getConversation",value:(u=Sa(Bc.mark((function e(t){var n,r,i,a=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return n=e.sent,e.next=5,n.getItems({key:t});case 5:return r=e.sent,i=r.items.map((function(e){return a._upsertConversation("sync",e.key,e.data)})),e.abrupt("return",i.length>0?i[0]:null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(o=Sa(Bc.mark((function e(t){var n,r,i,a,s;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.myConversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a=i.conversation_sid,s={entityName:null,lastConsumedMessageIndex:i.last_read_message_index,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:i.sync_objects.conversation,notificationLevel:null==i?void 0:i.notification_level,sid:a},e.abrupt("return",a?this._upsertConversation("sync",a,s):null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"peekConversation",value:(s=Sa(Bc.mark((function e(t){var n,r,i,a;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.conversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a={entityName:null,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:"".concat(t,".channel"),sid:t},e.abrupt("return",this._upsertConversation("sync",t,a));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"_getMap",value:(a=Sa(Bc.mark((function e(){return Bc.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(Bc.mark((function e(t,n){var r,i=this;return Bc.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(Bc.mark((function e(t,n,r){var i,a,s;return Bc.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 qP.trace("upsertConversation: conversation is known from sync and came from REST, ignoring",{sid:n.sid,data:r.status,conversation:n.status}),e.abrupt("return");case 5:if("joined"!==r.status||"joined"===n.status){e.next=15;break}return n._setStatus("joined",t),s={},void 0!==r.notificationLevel&&(s.notificationLevel=r.notificationLevel),void 0!==r.lastConsumedMessageIndex&&(s.lastConsumedMessageIndex=r.lastConsumedMessageIndex),By(s,{})||n._update(s),e.next=13,n._subscribe();case 13:return this.emit("conversationJoined",n),e.abrupt("return");case 15:if("notParticipating"!==r.status||"joined"!==n.status){e.next=22;break}return n._setStatus("notParticipating",t),n._update(r),e.next=20,n._subscribe();case 20:return this.emit("conversationLeft",n),e.abrupt("return");case 22:if("notParticipating"!==r.status){e.next=26;break}return e.next=25,n._subscribe();case 25:return e.abrupt("return");case 26:n._update(r);case 27:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"_upsertConversation",value:(n=Sa(Bc.mark((function e(t,n,r){var i,a,s,o;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(qP.trace("upsertConversation called for ".concat(n),r),!(i=this.conversations.get(n))){e.next=9;break}return qP.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("rest"!==t||!this.tombstones.has(n)){e.next=12;break}return qP.trace("upsertChannel: the channel is deleted but reappeared again from REST, ignoring",n),e.abrupt("return",null);case 12:return qP.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(Bc.mark((function e(){var t,n,r,i,a,s;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=null;case 2:return i=new rh(this.configuration.links.myConversations),n&&i.arg("PageToken",n),e.next=6,this.services.network.get(i.build());case 6:a=e.sent,s=null===(r=a.body)||void 0===r?void 0:r.conversations.map((function(e){return{descriptor:e,channel_sid:e.conversation_sid,status:e.status,channel:e.sync_objects.conversation,messages:e.sync_objects.messages,roster:"".concat(e.conversation_sid,".roster"),lastConsumedMessageIndex:e.last_read_message_index,notificationLevel:e.notification_level}})),n=a.body.meta.next_token,t=[].concat($O(t),$O(s));case 10:if(n){e.next=2;break}case 11:return e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_onConversationRemoved",value:function(e){var t=this.conversations.get(e);t&&(this.conversations.delete(e),this.emit("conversationRemoved",t))}},{key:"_registerForEvents",value:function(e){var t=this;e.on("removed",(function(){return t._onConversationRemoved(e.sid)})),e.on("updated",(function(e){return t.emit("conversationUpdated",e)})),e.on("participantJoined",(function(e){return t.emit("participantJoined",e)})),e.on("participantLeft",(function(e){return t.emit("participantLeft",e)})),e.on("participantUpdated",(function(e){return t.emit("participantUpdated",e)})),e.on("messageAdded",(function(e){return t.emit("messageAdded",e)})),e.on("messageUpdated",(function(e){return t.emit("messageUpdated",e)})),e.on("messageRemoved",(function(e){return t.emit("messageRemoved",e)})),e.on("typingStarted",(function(e){return t.emit("typingStarted",e)})),e.on("typingEnded",(function(e){return t.emit("typingEnded",e)}))}}]),p}(Dy),WP=In,GP=Hr.find,$P=Bf,VP="find",JP=!0;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)}}VP in[]&&Array(1).find((function(){JP=!1})),WP({target:"Array",proto:!0,forced:JP},{find:function(e){return GP(this,e,arguments.length>1?arguments[1]:void 0)}}),$P(VP);var HP=function(e){Ca(a,e);var t,n,r,i=KP(a);function a(e,t,n){var r;return Ma(this,a),(r=i.call(this)).configuration=t,r.services=n,r.fifoStack=[],r.myself=e,r.myself.on("updated",(function(e){return r.emit("userUpdated",e)})),r.myself.on("userSubscribed",(function(){return r.emit("userSubscribed",r.myself)})),r.myself.on("userUnsubscribed",(function(){r.emit("userUnsubscribed",r.myself),r.myself._ensureFetched()})),r.subscribedUsers=new Map,r}return Ta(a,[{key:"handleUnsubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)&&this.subscribedUsers.delete(e.identity);var t=0;this.fifoStack.find((function(n,r){return n==e.identity&&(t=r,!0)}))&&this.fifoStack.splice(t,1),this.emit("userUnsubscribed",e)}},{key:"handleSubscribeUser",value:function(e){if(!this.subscribedUsers.has(e.identity)){if(this.fifoStack.length>=this.configuration.userInfosToSubscribe){var t,n,r=this.fifoStack.shift();null===(t=this.subscribedUsers)||void 0===t||null===(n=t.get(r))||void 0===n||n.unsubscribe()}this.fifoStack.push(e.identity),this.subscribedUsers.set(e.identity,e),this.emit("userSubscribed",e)}}},{key:"getUser",value:(r=Sa(Bc.mark((function e(t,n){var r,i,a,s=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.myself._ensureFetched();case 2:if(t!=this.myself.identity){e.next=4;break}return e.abrupt("return",this.myself);case 4:if(!(i=this.subscribedUsers.get(t))){e.next=7;break}return e.abrupt("return",i);case 7:if(null===(r=n)||void 0===r){e.next=11;break}e.next=14;break;case 11:return e.next=13,this.getSyncUniqueName(t);case 13:n=e.sent;case 14:return(a=new User(t,n,this.configuration,this.services)).on("updated",(function(e){return s.emit("userUpdated",e)})),a.on("userSubscribed",(function(){return s.handleSubscribeUser(a)})),a.on("userUnsubscribed",(function(){return s.handleUnsubscribeUser(a)})),e.next=20,a._ensureFetched();case 20:return e.abrupt("return",a);case 21:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(Bc.mark((function e(){var t;return Bc.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(Bc.mark((function e(t){var n,r,i,a;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=new rh(this.configuration.links.users).path(t).build(),e.next=3,this.services.network.get(i);case 3:return a=e.sent,e.abrupt("return",null!==(n=null===(r=a.body)||void 0===r?void 0:r.sync_objects.user_info_map)&&void 0!==n?n:"");case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),a}(Dy),YP=Sf.scope("TypingIndicator"),QP=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(Bc.mark((function t(n,r){return Bc.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(Bc.mark((function e(t){var n=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:YP.trace("Got new typing indicator ",t),this.getConversation(t.channel_sid).then((function(e){e&&e._participants.forEach((function(e){if(e.identity===t.identity){var r=n.configuration.typingIndicatorTimeoutOverride?n.configuration.typingIndicatorTimeoutOverride+1e3:1e3*t.typing_timeout;e._startTyping(r)}}))})).catch((function(e){throw YP.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;YP.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 YP.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||{}},XP="3.0.0-rc.2";function ZP(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 eA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ZP(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ZP(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var tA,nA,rA,iA=function(e){return e.replace(/(^\/+|\/+$)/g,"")},aA=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=iA(e);return/^https?:\/\//.test(e)?t:"".concat(iA(this._serviceUrl),"/").concat(t)}},{key:"_makeRequest",value:(r=Sa(Bc.mark((function e(t,n,r,i){var a,s,o,u;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=this._preProcessUrl(n),s=eA({"Content-Type":"application/json; charset=utf-8"},i||{}),e.t0=t,e.next="get"===e.t0?5:"post"===e.t0?11:"delete"===e.t0?15:19;break;case 5:return u=a,r&&(u+="?"+Object.entries(r).map((function(e){return e.map(encodeURIComponent).join("=")})).join("&")),e.next=9,this._services.transport.get(u,s,this._productId);case 9:return o=e.sent,e.abrupt("break",19);case 11:return e.next=13,this._services.transport.post(a,s,JSON.stringify(r),this._productId);case 13:return o=e.sent,e.abrupt("break",19);case 15:return e.next=17,this._services.transport.delete(a,s,{},this._productId);case 17:return o=e.sent,e.abrupt("break",19);case 19:if(!(o.status.code<200||o.status.code>=300)){e.next=21;break}throw new Error("Request responded with a non-success code ".concat(o.status.code));case 21:return e.abrupt("return",o);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"fetchResource",value:(n=Sa(Bc.mark((function e(t,n){var r,i=this;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=1,e.next=4,new pg({min:50,max:1600,maxAttemptsCount:6}).run((function(){return i._makeRequest("get",t,n)}));case 4:return r=e.sent,e.abrupt("return",r.body);case 8:throw e.prev=8,e.t0=e.catch(1),new Error('Fetch resource from "'.concat(t,'" failed.'));case 11:case"end":return e.stop()}}),e,null,[[1,8]])}))),function(e,t){return n.apply(this,arguments)})},{key:"mutateResource",value:(t=Sa(Bc.mark((function e(t,n,r){var i;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._makeRequest(t,n,r,{"X-Twilio-Mutation-Id":tb.v4()});case 2:if(202!==(i=e.sent).status.code){e.next=7;break}return e.next=6,this.fetchResource(i.body.resource_url);case 6:return e.abrupt("return",e.sent);case 7:return e.abrupt("return",i.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,n,r){return t.apply(this,arguments)})}]),e}();function sA(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 oA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?sA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):sA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function uA(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 cA=function e(){Ma(this,e)};return e.Client=(nA=tA=function(e){Ca(Client,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y=uA(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=y.call(this)),"version",XP),ja(Ra(s),"connectionState","unknown"),ja(Ra(s),"parsePushNotification",rA.parsePushNotification),s._fpaToken=null!=e?e:"",s._options=null!=o?o:{},!s._options.disableDeepClone){var u=oA(oA({},s._options),{},{transport:void 0,twilsockClient:void 0});(u=Zp(u)).transport=s._options.transport,u.twilsockClient=s._options.twilsockClient,s._options=u}s._options.logLevel=null!==(t=s._options.logLevel)&&void 0!==t?t:"silent",rA._logger.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=XP),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 cA,s._myself=new User("","",null,s._services);var l=!s._options.twilsockClient;if(!s._options.initRegistrations){var f=new bg.InitRegistration(c);rA.populateInitRegistrations(f),s._options.initRegistrations=[f]}s._services.twilsockClient=s._options.twilsockClient=null!==(n=s._options.twilsockClient)&&void 0!==n?n:new bg.TwilsockClient(e,c,s._options),s._services.twilsockClient.on("tokenAboutToExpire",(function(){return s.emit("tokenAboutToExpire")})),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){rA._logger.debug("Handling stateChanged for ConversationsClient: new state ".concat(e)),e!==s.connectionState&&(s.connectionState=e,s.emit("connectionStateChanged",s.connectionState))})),s._services.transport=s._options.transport=null!==(r=s._options.transport)&&void 0!==r?r:s._options.twilsockClient,s._services.notificationClient=s._options.notificationsClient=null!==(i=s._options.notificationsClient)&&void 0!==i?i:new aE.Notifications(e,s._options),s._services.syncClient=s._options.syncClient=null!==(a=s._options.syncClient)&&void 0!==a?a:new CR(e,s._options);var d=(null==o?void 0:o.Chat)||(null==o?void 0:o.IPMessaging)||o||{},p=d.region||(null==o?void 0:o.region),h=d.apiUri||d.typingUri||"https://aim.".concat(p||"us1",".twilio.com");s._services.commandExecutor=new aA(h,{transport:s._options.transport},c);var v=function(e){s._rejectEnsureReady(e),s.emit("stateChanged",{state:"failed",error:e})};return s._services.twilsockClient.onceWithReplay("connectionError",v),s._services.twilsockClient.onceWithReplay("disconnected",v),s._services.twilsockClient.onceWithReplay("connected",Sa(Bc.mark((function e(){var t;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return rA._logger.debug("ConversationsClient started INITIALIZING"),s._services.twilsockClient.off("connectionError",v),s._services.twilsockClient.off("disconnected",v),e.prev=3,t="conversations.client.startup",s._services.twilsockClient.addPartialTelemetryEvent(new bg.TelemetryEventDescription(t,"Conversations client startup",new Date),t,bg.TelemetryPoint.Start),e.next=8,s._initialize();case 8:s._services.twilsockClient.addPartialTelemetryEvent(new bg.TelemetryEventDescription("","",new Date),t,bg.TelemetryPoint.End),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(3),s._rejectEnsureReady(e.t0),s.emit("stateChanged",{state:"failed",error:e.t0});case 15:case"end":return e.stop()}}),e,null,[[3,11]])})))),s._ensureReady=new Promise((function(e,t){s._resolveEnsureReady=e,s._rejectEnsureReady=t})).catch((function(){})),l&&s._services.twilsockClient.connect(),s}return Ta(Client,[{key:"user",get:function(){return this._myself}},{key:"reachabilityEnabled",get:function(){if(!this._configuration)throw new Error("Reachability information could not yet be accessed as the client has not yet been initialized. Subscribe to the 'stateChanged' event to properly react to the client initialization.");return this._configuration.reachabilityEnabled}},{key:"shutdown",value:(v=Sa(Bc.mark((function e(){return Bc.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 v.apply(this,arguments)})},{key:"updateToken",value:(h=Sa(Bc.mark((function e(t){return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:if(rA._logger.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 h.apply(this,arguments)})},{key:"getConversationBySid",value:(p=Sa(Bc.mark((function e(t){var n;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this._conversationsEntity.myConversationsRead.promise;case 4:return e.next=6,this._conversationsEntity.getConversation(t);case 6:if(n=e.sent){e.next=9;break}throw new Error("Conversation with SID ".concat(t," is not found."));case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"peekConversationBySid",value:(d=Sa(Bc.mark((function e(t){var n;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this._conversationsEntity.peekConversation(t);case 4:if(n=e.sent){e.next=7;break}throw new Error("Conversation with SID ".concat(t," is not found."));case 7:return e.abrupt("return",n);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(f=Sa(Bc.mark((function e(t){var n;return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this._conversationsEntity.myConversationsRead.promise;case 4:return e.next=6,this._conversationsEntity.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 f.apply(this,arguments)})},{key:"getSubscribedConversations",value:(l=Sa(Bc.mark((function e(){return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this._conversationsPromise.then((function(e){return e.getConversations()})));case 3:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"createConversation",value:(c=Sa(Bc.mark((function e(t){return Bc.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 c.apply(this,arguments)})},{key:"setPushRegistrationId",value:(u=Sa(Bc.mark((function e(t,n){return Bc.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 u.apply(this,arguments)})},{key:"unsetPushRegistrationId",value:(o=Sa(Bc.mark((function e(t){return Bc.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 o.apply(this,arguments)})},{key:"removePushRegistrations",value:(s=Sa(Bc.mark((function e(t,n){return Bc.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 s.apply(this,arguments)})},{key:"handlePushNotification",value:(a=Sa(Bc.mark((function e(t){return Bc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:rA._logger.debug("handlePushNotification, notificationPayload=",t),this.emit("pushNotification",rA.parsePushNotification(t));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"getUser",value:(i=Sa(Bc.mark((function e(t){return Bc.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 i.apply(this,arguments)})},{key:"getSubscribedUsers",value:(r=Sa(Bc.mark((function e(){return Bc.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 r.apply(this,arguments)})},{key:"getTemporaryContentUrlsForMediaSids",value:function(e){var t=this;return new MR.CancellablePromise(function(){var n=Sa(Bc.mark((function n(r,i,a){var s,o;return Bc.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(t._services.mcsClient&&e){n.next=3;break}return i(new Error("Media Content Service is unavailable")),n.abrupt("return");case 3:return s=t._services.mcsClient.mediaSetGetContentUrls(e),a((function(){s.cancel()})),n.prev=5,n.next=8,s;case 8:o=n.sent,r(o),n.next=15;break;case 12:n.prev=12,n.t0=n.catch(5),i(n.t0);case 15:case"end":return n.stop()}}),n,null,[[5,12]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"getTemporaryContentUrlsForMedia",value:function(e){var t=e.map((function(e){return e.sid}));return this.getTemporaryContentUrlsForMediaSids(t)}},{key:"_initialize",value:(n=Sa(Bc.mark((function e(){var t,n=this;return Bc.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 Lf(this._options,t,rA._logger),this._myself._resolveInitialization(this._configuration,this._configuration.userIdentity,this._configuration.userInfo,!0),this._services.typingIndicator=new QP(this.getConversationBySid.bind(this),this._configuration,this._services),this._services.network=new mg(this._configuration,this._services),this._services.users=new HP(this._myself,this._configuration,this._services),this._services.users.on("userSubscribed",(function(e){n.emit("userSubscribed",e)})),this._services.users.on("userUpdated",(function(e){return n.emit("userUpdated",e)})),this._services.users.on("userUnsubscribed",(function(e){n.emit("userUnsubscribed",e)})),this._conversationsEntity=new zP(this._configuration,this._services),this._conversationsEntity.on("conversationAdded",(function(e){n.emit("conversationAdded",e)})),this._conversationsEntity.on("conversationRemoved",(function(e){n.emit("conversationRemoved",e)})),this._conversationsEntity.on("conversationJoined",(function(e){n.emit("conversationJoined",e)})),this._conversationsEntity.on("conversationLeft",(function(e){n.emit("conversationLeft",e)})),this._conversationsEntity.on("conversationUpdated",(function(e){return n.emit("conversationUpdated",e)})),this._conversationsEntity.on("participantJoined",(function(e){n.emit("participantJoined",e)})),this._conversationsEntity.on("participantLeft",(function(e){n.emit("participantLeft",e)})),this._conversationsEntity.on("participantUpdated",(function(e){return n.emit("participantUpdated",e)})),this._conversationsEntity.on("messageAdded",(function(e){return n.emit("messageAdded",e)})),this._conversationsEntity.on("messageUpdated",(function(e){return n.emit("messageUpdated",e)})),this._conversationsEntity.on("messageRemoved",(function(e){return n.emit("messageRemoved",e)})),this._conversationsEntity.on("typingStarted",(function(e){return n.emit("typingStarted",e)})),this._conversationsEntity.on("typingEnded",(function(e){return n.emit("typingEnded",e)})),this._conversationsPromise=this._conversationsEntity.fetchConversations().then((function(){return n._conversationsEntity})).catch((function(e){throw e})),e.next=28,this._services.users.myself._ensureFetched();case 28:rA._supportedPushChannels.forEach((function(e){return n._subscribeToPushNotifications(e)})),this._services.typingIndicator.initialize(),this._services.mcsClient=new MR.McsClient(this._fpaToken,this._configuration.links.mediaService,this._configuration.links.mediaSetService,oA(oA({},this._options),{},{transport:void 0})),this._resolveEnsureReady(),this.emit("stateChanged",{state:"initialized"});case 33:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{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:"create",value:(t=Sa(Bc.mark((function e(t,n){var r;return Bc.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 rA(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:"parsePushNotification",value:function(e){if(rA._logger.debug("parsePushNotification, notificationPayload=",e),void 0!==e.aps){if(!e.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var t,n=rA._parsePushNotificationChatData(e),r=e.aps,i=null;return"string"==typeof r.alert?t=r.alert||null:(t=r.alert.body||null,i=r.alert.title||null),new PushNotification({title:i,body:t,sound:r.sound||null,badge:r.badge||null,action:r.category||null,type:e.twi_message_type,data:n})}if(void 0!==e.data){var a=e.data;if(!a.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var s=rA._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")}},{key:"_parsePushNotificationChatData",value:function(e){var t={};for(var n in rA._supportedPushDataFields){var r=e[n];if(null!=r)if("message_index"!==n&&"media_count"!==n){if("media"!==n)t[rA._supportedPushDataFields[n]]=r;else if("string"==typeof r)try{t[rA._supportedPushDataFields[n]]=JSON.parse(r)}catch(e){rA._logger.debug("Media message notification parsing error")}}else{var i=eh(r);null!==i&&(t[rA._supportedPushDataFields[n]]=i)}}return t}},{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([gg.TYPING_INDICATOR]),CR.populateInitRegistrations(e)}}]),Client}(Dy),ja(tA,"conversationAdded","conversationAdded"),ja(tA,"conversationJoined","conversationJoined"),ja(tA,"conversationLeft","conversationLeft"),ja(tA,"conversationRemoved","conversationRemoved"),ja(tA,"conversationUpdated","conversationUpdated"),ja(tA,"participantJoined","participantJoined"),ja(tA,"participantLeft","participantLeft"),ja(tA,"participantUpdated","participantUpdated"),ja(tA,"messageAdded","messageAdded"),ja(tA,"messageRemoved","messageRemoved"),ja(tA,"messageUpdated","messageUpdated"),ja(tA,"tokenAboutToExpire","tokenAboutToExpire"),ja(tA,"tokenExpired","tokenExpired"),ja(tA,"typingEnded","typingEnded"),ja(tA,"typingStarted","typingStarted"),ja(tA,"pushNotification","pushNotification"),ja(tA,"userSubscribed","userSubscribed"),ja(tA,"userUnsubscribed","userUnsubscribed"),ja(tA,"userUpdated","userUpdated"),ja(tA,"stateChanged","stateChanged"),ja(tA,"connectionStateChanged","connectionStateChanged"),ja(tA,"connectionError","connectionError"),ja(tA,"version",XP),ja(tA,"_logger",Sf.scope("Client")),ja(tA,"_supportedPushChannels",["fcm","apn"]),ja(tA,"_supportedPushDataFields",{conversation_sid:"conversationSid",conversation_title:"conversationTitle",message_sid:"messageSid",message_index:"messageIndex",media_count:"mediaCount",media:"media"}),rA=nA),zc([Xv(Vv),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],e.Client.prototype,"updateToken",null),zc([Xv(Vv),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],e.Client.prototype,"getConversationBySid",null),zc([Xv(Vv),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],e.Client.prototype,"peekConversationBySid",null),zc([Xv(Vv),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],e.Client.prototype,"getConversationByUniqueName",null),zc([Xv(["undefined",Kv("conversation options",{friendlyName:["string","undefined"],isPrivate:["boolean","undefined"],uniqueName:["string","undefined"]})]),Wc("design:type",Function),Wc("design:paramtypes",[Object]),Wc("design:returntype",Promise)],e.Client.prototype,"createConversation",null),zc([Xv($v("fcm","apn"),"string"),Wc("design:type",Function),Wc("design:paramtypes",[String,String]),Wc("design:returntype",Promise)],e.Client.prototype,"setPushRegistrationId",null),zc([Xv($v("fcm","apn")),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],e.Client.prototype,"unsetPushRegistrationId",null),zc([Xv($v("fcm","apn"),Vv),Wc("design:type",Function),Wc("design:paramtypes",[String,String]),Wc("design:returntype",Promise)],e.Client.prototype,"removePushRegistrations",null),zc([Xv(Hv),Wc("design:type",Function),Wc("design:paramtypes",[Object]),Wc("design:returntype",Promise)],e.Client.prototype,"handlePushNotification",null),zc([Xv(Vv),Wc("design:type",Function),Wc("design:paramtypes",[String]),Wc("design:returntype",Promise)],e.Client.prototype,"getUser",null),zc([Xv("string",["undefined",Hv]),Wc("design:type",Function),Wc("design:paramtypes",[String,Object]),Wc("design:returntype",Promise)],e.Client,"create",null),zc([Qv(Hv),Wc("design:type",Function),Wc("design:paramtypes",[Object]),Wc("design:returntype",PushNotification)],e.Client,"parsePushNotification",null),e.Client=rA=zc([Yv(Vv,[Hv,"undefined"]),Wc("design:paramtypes",[String,Object])],e.Client),e.AggregatedDeliveryReceipt=AggregatedDeliveryReceipt,e.Conversation=Conversation,e.DetailedDeliveryReceipt=DetailedDeliveryReceipt,e.Media=Media,e.Message=Message,e.MessageBuilder=OP,e.NotificationTypes=gg,e.Participant=Participant,e.PushNotification=PushNotification,e.RestPaginator=wP,e.UnsentMessage=CP,e.User=User,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
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={},o=function(e){try{return!!e()}catch(e){return!0}},s=!o((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),u=!o((function(){var e=function(){}.bind();return"function"!=typeof e||e.hasOwnProperty("prototype")})),c=u,l=Function.prototype.call,f=c?l.bind(l):function(){return l.apply(l,arguments)},d={},p={}.propertyIsEnumerable,h=Object.getOwnPropertyDescriptor,v=h&&!p.call({1:2},1);d.f=v?function(e){var t=h(this,e);return!!t&&t.enumerable}:p;var y,m,g=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},b=u,w=Function.prototype,k=w.call,x=b&&w.bind.bind(k,k),_=function(e){return b?x(e):function(){return k.apply(e,arguments)}},S=_,O=S({}.toString),E=S("".slice),T=function(e){return E(O(e),8,-1)},R=T,I=_,C=function(e){if("Function"===R(e))return I(e)},P=o,A=T,j=Object,M=C("".split),L=P((function(){return!j("z").propertyIsEnumerable(0)}))?function(e){return"String"==A(e)?M(e,""):j(e)}:j,U=function(e){return null==e},N=U,F=TypeError,D=function(e){if(N(e))throw F("Can't call method on "+e);return e},q=L,B=D,z=function(e){return q(B(e))},W="object"==typeof document&&document.all,$={all:W,IS_HTMLDDA:void 0===W&&void 0!==W},K=$.all,H=$.IS_HTMLDDA?function(e){return"function"==typeof e||e===K}:function(e){return"function"==typeof e},G=H,V=$.all,Y=$.IS_HTMLDDA?function(e){return"object"==typeof e?null!==e:G(e)||e===V}:function(e){return"object"==typeof e?null!==e:G(e)},J=i,Q=H,X=function(e){return Q(e)?e:void 0},Z=function(e,t){return arguments.length<2?X(J[e]):J[e]&&J[e][t]},ee=C({}.isPrototypeOf),te=Z("navigator","userAgent")||"",ne=i,re=te,ie=ne.process,ae=ne.Deno,oe=ie&&ie.versions||ae&&ae.version,se=oe&&oe.v8;se&&(m=(y=se.split("."))[0]>0&&y[0]<4?1:+(y[0]+y[1])),!m&&re&&(!(y=re.match(/Edge\/(\d+)/))||y[1]>=74)&&(y=re.match(/Chrome\/(\d+)/))&&(m=+y[1]);var ue=m,ce=ue,le=o,fe=!!Object.getOwnPropertySymbols&&!le((function(){var e=Symbol();return!String(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&ce&&ce<41})),de=fe&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,pe=Z,he=H,ve=ee,ye=Object,me=de?function(e){return"symbol"==typeof e}:function(e){var t=pe("Symbol");return he(t)&&ve(t.prototype,ye(e))},ge=String,be=function(e){try{return ge(e)}catch(e){return"Object"}},we=H,ke=be,xe=TypeError,_e=function(e){if(we(e))return e;throw xe(ke(e)+" is not a function")},Se=_e,Oe=U,Ee=function(e,t){var n=e[t];return Oe(n)?void 0:Se(n)},Te=f,Re=H,Ie=Y,Ce=TypeError,Pe={exports:{}},Ae=i,je=Object.defineProperty,Me=function(e,t){try{je(Ae,e,{value:t,configurable:!0,writable:!0})}catch(n){Ae[e]=t}return t},Le=Me,Ue="__core-js_shared__",Ne=i[Ue]||Le(Ue,{}),Fe=Ne;(Pe.exports=function(e,t){return Fe[e]||(Fe[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.25.5",mode:"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.25.5/LICENSE",source:"https://github.com/zloirock/core-js"});var De=D,qe=Object,Be=function(e){return qe(De(e))},ze=Be,We=C({}.hasOwnProperty),$e=Object.hasOwn||function(e,t){return We(ze(e),t)},Ke=C,He=0,Ge=Math.random(),Ve=Ke(1..toString),Ye=function(e){return"Symbol("+(void 0===e?"":e)+")_"+Ve(++He+Ge,36)},Je=i,Qe=Pe.exports,Xe=$e,Ze=Ye,et=fe,tt=de,nt=Qe("wks"),rt=Je.Symbol,it=rt&&rt.for,at=tt?rt:rt&&rt.withoutSetter||Ze,ot=function(e){if(!Xe(nt,e)||!et&&"string"!=typeof nt[e]){var t="Symbol."+e;et&&Xe(rt,e)?nt[e]=rt[e]:nt[e]=tt&&it?it(t):at(t)}return nt[e]},st=f,ut=Y,ct=me,lt=Ee,ft=function(e,t){var n,r;if("string"===t&&Re(n=e.toString)&&!Ie(r=Te(n,e)))return r;if(Re(n=e.valueOf)&&!Ie(r=Te(n,e)))return r;if("string"!==t&&Re(n=e.toString)&&!Ie(r=Te(n,e)))return r;throw Ce("Can't convert object to primitive value")},dt=TypeError,pt=ot("toPrimitive"),ht=function(e,t){if(!ut(e)||ct(e))return e;var n,r=lt(e,pt);if(r){if(void 0===t&&(t="default"),n=st(r,e,t),!ut(n)||ct(n))return n;throw dt("Can't convert object to primitive value")}return void 0===t&&(t="number"),ft(e,t)},vt=ht,yt=me,mt=function(e){var t=vt(e,"string");return yt(t)?t:t+""},gt=Y,bt=i.document,wt=gt(bt)&>(bt.createElement),kt=function(e){return wt?bt.createElement(e):{}},xt=kt,_t=!s&&!o((function(){return 7!=Object.defineProperty(xt("div"),"a",{get:function(){return 7}}).a})),St=s,Ot=f,Et=d,Tt=g,Rt=z,It=mt,Ct=$e,Pt=_t,At=Object.getOwnPropertyDescriptor;a.f=St?At:function(e,t){if(e=Rt(e),t=It(t),Pt)try{return At(e,t)}catch(e){}if(Ct(e,t))return Tt(!Ot(Et.f,e,t),e[t])};var jt={},Mt=s&&o((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype})),Lt=Y,Ut=String,Nt=TypeError,Ft=function(e){if(Lt(e))return e;throw Nt(Ut(e)+" is not an object")},Dt=s,qt=_t,Bt=Mt,zt=Ft,Wt=mt,$t=TypeError,Kt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,Gt="enumerable",Vt="configurable",Yt="writable";jt.f=Dt?Bt?function(e,t,n){if(zt(e),t=Wt(t),zt(n),"function"==typeof e&&"prototype"===t&&"value"in n&&Yt in n&&!n.writable){var r=Ht(e,t);r&&r.writable&&(e[t]=n.value,n={configurable:Vt in n?n.configurable:r.configurable,enumerable:Gt in n?n.enumerable:r.enumerable,writable:!1})}return Kt(e,t,n)}:Kt:function(e,t,n){if(zt(e),t=Wt(t),zt(n),qt)try{return Kt(e,t,n)}catch(e){}if("get"in n||"set"in n)throw $t("Accessors not supported");return"value"in n&&(e[t]=n.value),e};var Jt=jt,Qt=g,Xt=s?function(e,t,n){return Jt.f(e,t,Qt(1,n))}:function(e,t,n){return e[t]=n,e},Zt={exports:{}},en=s,tn=$e,nn=Function.prototype,rn=en&&Object.getOwnPropertyDescriptor,an=tn(nn,"name"),on={EXISTS:an,PROPER:an&&"something"===function(){}.name,CONFIGURABLE:an&&(!en||en&&rn(nn,"name").configurable)},sn=H,un=Ne,cn=C(Function.toString);sn(un.inspectSource)||(un.inspectSource=function(e){return cn(e)});var ln,fn,dn,pn=un.inspectSource,hn=H,vn=i.WeakMap,yn=hn(vn)&&/native code/.test(String(vn)),mn=Pe.exports,gn=Ye,bn=mn("keys"),wn=function(e){return bn[e]||(bn[e]=gn(e))},kn={},xn=yn,_n=i,Sn=Y,On=Xt,En=$e,Tn=Ne,Rn=wn,In=kn,Cn="Object already initialized",Pn=_n.TypeError,An=_n.WeakMap;if(xn||Tn.state){var jn=Tn.state||(Tn.state=new An);jn.get=jn.get,jn.has=jn.has,jn.set=jn.set,ln=function(e,t){if(jn.has(e))throw Pn(Cn);return t.facade=e,jn.set(e,t),t},fn=function(e){return jn.get(e)||{}},dn=function(e){return jn.has(e)}}else{var Mn=Rn("state");In[Mn]=!0,ln=function(e,t){if(En(e,Mn))throw Pn(Cn);return t.facade=e,On(e,Mn,t),t},fn=function(e){return En(e,Mn)?e[Mn]:{}},dn=function(e){return En(e,Mn)}}var Ln={set:ln,get:fn,has:dn,enforce:function(e){return dn(e)?fn(e):ln(e,{})},getterFor:function(e){return function(t){var n;if(!Sn(t)||(n=fn(t)).type!==e)throw Pn("Incompatible receiver, "+e+" required");return n}}},Un=o,Nn=H,Fn=$e,Dn=s,qn=on.CONFIGURABLE,Bn=pn,zn=Ln.enforce,Wn=Ln.get,$n=Object.defineProperty,Kn=Dn&&!Un((function(){return 8!==$n((function(){}),"length",{value:8}).length})),Hn=String(String).split("String"),Gn=Zt.exports=function(e,t,n){"Symbol("===String(t).slice(0,7)&&(t="["+String(t).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),n&&n.getter&&(t="get "+t),n&&n.setter&&(t="set "+t),(!Fn(e,"name")||qn&&e.name!==t)&&(Dn?$n(e,"name",{value:t,configurable:!0}):e.name=t),Kn&&n&&Fn(n,"arity")&&e.length!==n.arity&&$n(e,"length",{value:n.arity});try{n&&Fn(n,"constructor")&&n.constructor?Dn&&$n(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch(e){}var r=zn(e);return Fn(r,"source")||(r.source=Hn.join("string"==typeof t?t:"")),e};Function.prototype.toString=Gn((function(){return Nn(this)&&Wn(this).source||Bn(this)}),"toString");var Vn=H,Yn=jt,Jn=Zt.exports,Qn=Me,Xn=function(e,t,n,r){r||(r={});var i=r.enumerable,a=void 0!==r.name?r.name:t;if(Vn(n)&&Jn(n,a,r),r.global)i?e[t]=n:Qn(t,n);else{try{r.unsafe?e[t]&&(i=!0):delete e[t]}catch(e){}i?e[t]=n:Yn.f(e,t,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},Zn={},er=Math.ceil,tr=Math.floor,nr=Math.trunc||function(e){var t=+e;return(t>0?tr:er)(t)},rr=nr,ir=function(e){var t=+e;return t!=t||0===t?0:rr(t)},ar=ir,or=Math.max,sr=Math.min,ur=function(e,t){var n=ar(e);return n<0?or(n+t,0):sr(n,t)},cr=ir,lr=Math.min,fr=function(e){return e>0?lr(cr(e),9007199254740991):0},dr=fr,pr=function(e){return dr(e.length)},hr=z,vr=ur,yr=pr,mr=function(e){return function(t,n,r){var i,a=hr(t),o=yr(a),s=vr(r,o);if(e&&n!=n){for(;o>s;)if((i=a[s++])!=i)return!0}else for(;o>s;s++)if((e||s in a)&&a[s]===n)return e||s||0;return!e&&-1}},gr={includes:mr(!0),indexOf:mr(!1)},br=$e,wr=z,kr=gr.indexOf,xr=kn,_r=C([].push),Sr=function(e,t){var n,r=wr(e),i=0,a=[];for(n in r)!br(xr,n)&&br(r,n)&&_r(a,n);for(;t.length>i;)br(r,n=t[i++])&&(~kr(a,n)||_r(a,n));return a},Or=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],Er=Sr,Tr=Or.concat("length","prototype");Zn.f=Object.getOwnPropertyNames||function(e){return Er(e,Tr)};var Rr={};Rr.f=Object.getOwnPropertySymbols;var Ir=Z,Cr=Zn,Pr=Rr,Ar=Ft,jr=C([].concat),Mr=Ir("Reflect","ownKeys")||function(e){var t=Cr.f(Ar(e)),n=Pr.f;return n?jr(t,n(e)):t},Lr=$e,Ur=Mr,Nr=a,Fr=jt,Dr=function(e,t,n){for(var r=Ur(t),i=Fr.f,a=Nr.f,o=0;o<r.length;o++){var s=r[o];Lr(e,s)||n&&Lr(n,s)||i(e,s,a(t,s))}},qr=o,Br=H,zr=/#|\.prototype\./,Wr=function(e,t){var n=Kr[$r(e)];return n==Gr||n!=Hr&&(Br(t)?qr(t):!!t)},$r=Wr.normalize=function(e){return String(e).replace(zr,".").toLowerCase()},Kr=Wr.data={},Hr=Wr.NATIVE="N",Gr=Wr.POLYFILL="P",Vr=Wr,Yr=i,Jr=a.f,Qr=Xt,Xr=Xn,Zr=Me,ei=Dr,ti=Vr,ni=function(e,t){var n,r,i,a,o,s=e.target,u=e.global,c=e.stat;if(n=u?Yr:c?Yr[s]||Zr(s,{}):(Yr[s]||{}).prototype)for(r in t){if(a=t[r],i=e.dontCallGetSet?(o=Jr(n,r))&&o.value:n[r],!ti(u?r:s+(c?".":"#")+r,e.forced)&&void 0!==i){if(typeof a==typeof i)continue;ei(a,i)}(e.sham||i&&i.sham)&&Qr(a,"sham",!0),Xr(n,r,a,e)}},ri=jt.f,ii=$e,ai=ot("toStringTag"),oi=function(e,t,n){e&&!n&&(e=e.prototype),e&&!ii(e,ai)&&ri(e,ai,{configurable:!0,value:t})},si=i,ui=oi;ni({global:!0},{Reflect:{}}),ui(si.Reflect,"Reflect",!0);var ci=u,li=Function.prototype,fi=li.apply,di=li.call,pi="object"==typeof Reflect&&Reflect.apply||(ci?di.bind(fi):function(){return di.apply(fi,arguments)}),hi=C([].slice),vi=C,yi=_e,mi=Y,gi=$e,bi=hi,wi=u,ki=Function,xi=vi([].concat),_i=vi([].join),Si={},Oi=function(e,t,n){if(!gi(Si,t)){for(var r=[],i=0;i<t;i++)r[i]="a["+i+"]";Si[t]=ki("C,a","return new C("+_i(r,",")+")")}return Si[t](e,n)},Ei=wi?ki.bind:function(e){var t=yi(this),n=t.prototype,r=bi(arguments,1),i=function(){var n=xi(r,bi(arguments));return this instanceof i?Oi(t,n.length,n):t.apply(e,n)};return mi(n)&&(i.prototype=n),i},Ti={};Ti[ot("toStringTag")]="z";var Ri="[object z]"===String(Ti),Ii=Ri,Ci=H,Pi=T,Ai=ot("toStringTag"),ji=Object,Mi="Arguments"==Pi(function(){return arguments}()),Li=Ii?Pi: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=ji(e),Ai))?n:Mi?Pi(t):"Object"==(r=Pi(t))&&Ci(t.callee)?"Arguments":r},Ui=C,Ni=o,Fi=H,Di=Li,qi=pn,Bi=function(){},zi=[],Wi=Z("Reflect","construct"),$i=/^\s*(?:class|function)\b/,Ki=Ui($i.exec),Hi=!$i.exec(Bi),Gi=function(e){if(!Fi(e))return!1;try{return Wi(Bi,zi,e),!0}catch(e){return!1}},Vi=function(e){if(!Fi(e))return!1;switch(Di(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Hi||!!Ki($i,qi(e))}catch(e){return!0}};Vi.sham=!0;var Yi=!Wi||Ni((function(){var e;return Gi(Gi.call)||!Gi(Object)||!Gi((function(){e=!0}))||e}))?Vi:Gi,Ji=Yi,Qi=be,Xi=TypeError,Zi=function(e){if(Ji(e))return e;throw Xi(Qi(e)+" is not a constructor")},ea={},ta=Sr,na=Or,ra=Object.keys||function(e){return ta(e,na)},ia=s,aa=Mt,oa=jt,sa=Ft,ua=z,ca=ra;ea.f=ia&&!aa?Object.defineProperties:function(e,t){sa(e);for(var n,r=ua(t),i=ca(t),a=i.length,o=0;a>o;)oa.f(e,n=i[o++],r[n]);return e};var la,fa=Z("document","documentElement"),da=Ft,pa=ea,ha=Or,va=kn,ya=fa,ma=kt,ga=wn("IE_PROTO"),ba=function(){},wa=function(e){return"<script>"+e+"</"+"script>"},ka=function(e){e.write(wa("")),e.close();var t=e.parentWindow.Object;return e=null,t},xa=function(){try{la=new ActiveXObject("htmlfile")}catch(e){}var e,t;xa="undefined"!=typeof document?document.domain&&la?ka(la):((t=ma("iframe")).style.display="none",ya.appendChild(t),t.src=String("javascript:"),(e=t.contentWindow.document).open(),e.write(wa("document.F=Object")),e.close(),e.F):ka(la);for(var n=ha.length;n--;)delete xa.prototype[ha[n]];return xa()};va[ga]=!0;var _a=Object.create||function(e,t){var n;return null!==e?(ba.prototype=da(e),n=new ba,ba.prototype=null,n[ga]=e):n=xa(),void 0===t?n:pa.f(n,t)},Sa=ni,Oa=pi,Ea=Ei,Ta=Zi,Ra=Ft,Ia=Y,Ca=_a,Pa=o,Aa=Z("Reflect","construct"),ja=Object.prototype,Ma=[].push,La=Pa((function(){function e(){}return!(Aa((function(){}),[],e)instanceof e)})),Ua=!Pa((function(){Aa((function(){}))})),Na=La||Ua;Sa({target:"Reflect",stat:!0,forced:Na,sham:Na},{construct:function(e,t){Ta(e),Ra(t);var n=arguments.length<3?e:Ta(arguments[2]);if(Ua&&!La)return Aa(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 Oa(Ma,r,t),new(Oa(Ea,e,r))}var i=n.prototype,a=Ca(Ia(i)?i:ja),o=Oa(e,a,t);return Ia(o)?o:a}});var Fa=Be,Da=ra;ni({target:"Object",stat:!0,forced:o((function(){Da(1)}))},{keys:function(e){return Da(Fa(e))}});var qa=Li,Ba=String,za=function(e){if("Symbol"===qa(e))throw TypeError("Cannot convert a Symbol value to a string");return Ba(e)},Wa={},$a=mt,Ka=jt,Ha=g,Ga=function(e,t,n){var r=$a(t);r in e?Ka.f(e,r,Ha(0,n)):e[r]=n},Va=ur,Ya=pr,Ja=Ga,Qa=Array,Xa=Math.max,Za=function(e,t,n){for(var r=Ya(e),i=Va(t,r),a=Va(void 0===n?r:n,r),o=Qa(Xa(a-i,0)),s=0;i<a;i++,s++)Ja(o,s,e[i]);return o.length=s,o},eo=T,to=z,no=Zn.f,ro=Za,io="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];Wa.f=function(e){return io&&"Window"==eo(e)?function(e){try{return no(e)}catch(e){return ro(io)}}(e):no(to(e))};var ao={},oo=ot;ao.f=oo;var so=i,uo=$e,co=ao,lo=jt.f,fo=function(e){var t=so.Symbol||(so.Symbol={});uo(t,e)||lo(t,e,{value:co.f(e)})},po=f,ho=Z,vo=ot,yo=Xn,mo=_e,go=u,bo=C(C.bind),wo=function(e,t){return mo(e),void 0===t?e:go?bo(e,t):function(){return e.apply(t,arguments)}},ko=T,xo=Array.isArray||function(e){return"Array"==ko(e)},_o=xo,So=Yi,Oo=Y,Eo=ot("species"),To=Array,Ro=function(e){var t;return _o(e)&&(t=e.constructor,(So(t)&&(t===To||_o(t.prototype))||Oo(t)&&null===(t=t[Eo]))&&(t=void 0)),void 0===t?To:t},Io=function(e,t){return new(Ro(e))(0===t?0:t)},Co=wo,Po=L,Ao=Be,jo=pr,Mo=Io,Lo=C([].push),Uo=function(e){var t=1==e,n=2==e,r=3==e,i=4==e,a=6==e,o=7==e,s=5==e||a;return function(u,c,l,f){for(var d,p,h=Ao(u),v=Po(h),y=Co(c,l),m=jo(v),g=0,b=f||Mo,w=t?b(u,m):n||o?b(u,0):void 0;m>g;g++)if((s||g in v)&&(p=y(d=v[g],g,h),e))if(t)w[g]=p;else if(p)switch(e){case 3:return!0;case 5:return d;case 6:return g;case 2:Lo(w,d)}else switch(e){case 4:return!1;case 7:Lo(w,d)}return a?-1:r||i?i:w}},No={forEach:Uo(0),map:Uo(1),filter:Uo(2),some:Uo(3),every:Uo(4),find:Uo(5),findIndex:Uo(6),filterReject:Uo(7)},Fo=ni,Do=i,qo=f,Bo=C,zo=s,Wo=fe,$o=o,Ko=$e,Ho=ee,Go=Ft,Vo=z,Yo=mt,Jo=za,Qo=g,Xo=_a,Zo=ra,es=Zn,ts=Wa,ns=Rr,rs=a,is=jt,as=ea,os=d,ss=Xn,us=Pe.exports,cs=kn,ls=Ye,fs=ot,ds=ao,ps=fo,hs=function(){var e=ho("Symbol"),t=e&&e.prototype,n=t&&t.valueOf,r=vo("toPrimitive");t&&!t[r]&&yo(t,r,(function(e){return po(n,this)}),{arity:1})},vs=oi,ys=Ln,ms=No.forEach,gs=wn("hidden"),bs="Symbol",ws=ys.set,ks=ys.getterFor(bs),xs=Object.prototype,_s=Do.Symbol,Ss=_s&&_s.prototype,Os=Do.TypeError,Es=Do.QObject,Ts=rs.f,Rs=is.f,Is=ts.f,Cs=os.f,Ps=Bo([].push),As=us("symbols"),js=us("op-symbols"),Ms=us("wks"),Ls=!Es||!Es.prototype||!Es.prototype.findChild,Us=zo&&$o((function(){return 7!=Xo(Rs({},"a",{get:function(){return Rs(this,"a",{value:7}).a}})).a}))?function(e,t,n){var r=Ts(xs,t);r&&delete xs[t],Rs(e,t,n),r&&e!==xs&&Rs(xs,t,r)}:Rs,Ns=function(e,t){var n=As[e]=Xo(Ss);return ws(n,{type:bs,tag:e,description:t}),zo||(n.description=t),n},Fs=function(e,t,n){e===xs&&Fs(js,t,n),Go(e);var r=Yo(t);return Go(n),Ko(As,r)?(n.enumerable?(Ko(e,gs)&&e[gs][r]&&(e[gs][r]=!1),n=Xo(n,{enumerable:Qo(0,!1)})):(Ko(e,gs)||Rs(e,gs,Qo(1,{})),e[gs][r]=!0),Us(e,r,n)):Rs(e,r,n)},Ds=function(e,t){Go(e);var n=Vo(t),r=Zo(n).concat(Ws(n));return ms(r,(function(t){zo&&!qo(qs,n,t)||Fs(e,t,n[t])})),e},qs=function(e){var t=Yo(e),n=qo(Cs,this,t);return!(this===xs&&Ko(As,t)&&!Ko(js,t))&&(!(n||!Ko(this,t)||!Ko(As,t)||Ko(this,gs)&&this[gs][t])||n)},Bs=function(e,t){var n=Vo(e),r=Yo(t);if(n!==xs||!Ko(As,r)||Ko(js,r)){var i=Ts(n,r);return!i||!Ko(As,r)||Ko(n,gs)&&n[gs][r]||(i.enumerable=!0),i}},zs=function(e){var t=Is(Vo(e)),n=[];return ms(t,(function(e){Ko(As,e)||Ko(cs,e)||Ps(n,e)})),n},Ws=function(e){var t=e===xs,n=Is(t?js:Vo(e)),r=[];return ms(n,(function(e){!Ko(As,e)||t&&!Ko(xs,e)||Ps(r,As[e])})),r};Wo||(_s=function(){if(Ho(Ss,this))throw Os("Symbol is not a constructor");var e=arguments.length&&void 0!==arguments[0]?Jo(arguments[0]):void 0,t=ls(e),n=function(e){this===xs&&qo(n,js,e),Ko(this,gs)&&Ko(this[gs],t)&&(this[gs][t]=!1),Us(this,t,Qo(1,e))};return zo&&Ls&&Us(xs,t,{configurable:!0,set:n}),Ns(t,e)},ss(Ss=_s.prototype,"toString",(function(){return ks(this).tag})),ss(_s,"withoutSetter",(function(e){return Ns(ls(e),e)})),os.f=qs,is.f=Fs,as.f=Ds,rs.f=Bs,es.f=ts.f=zs,ns.f=Ws,ds.f=function(e){return Ns(fs(e),e)},zo&&(Rs(Ss,"description",{configurable:!0,get:function(){return ks(this).description}}),ss(xs,"propertyIsEnumerable",qs,{unsafe:!0}))),Fo({global:!0,constructor:!0,wrap:!0,forced:!Wo,sham:!Wo},{Symbol:_s}),ms(Zo(Ms),(function(e){ps(e)})),Fo({target:bs,stat:!0,forced:!Wo},{useSetter:function(){Ls=!0},useSimple:function(){Ls=!1}}),Fo({target:"Object",stat:!0,forced:!Wo,sham:!zo},{create:function(e,t){return void 0===t?Xo(e):Ds(Xo(e),t)},defineProperty:Fs,defineProperties:Ds,getOwnPropertyDescriptor:Bs}),Fo({target:"Object",stat:!0,forced:!Wo},{getOwnPropertyNames:zs}),hs(),vs(_s,bs),cs[gs]=!0;var $s=fe&&!!Symbol.for&&!!Symbol.keyFor,Ks=ni,Hs=Z,Gs=$e,Vs=za,Ys=Pe.exports,Js=$s,Qs=Ys("string-to-symbol-registry"),Xs=Ys("symbol-to-string-registry");Ks({target:"Symbol",stat:!0,forced:!Js},{for:function(e){var t=Vs(e);if(Gs(Qs,t))return Qs[t];var n=Hs("Symbol")(t);return Qs[t]=n,Xs[n]=t,n}});var Zs=ni,eu=$e,tu=me,nu=be,ru=$s,iu=(0,Pe.exports)("symbol-to-string-registry");Zs({target:"Symbol",stat:!0,forced:!ru},{keyFor:function(e){if(!tu(e))throw TypeError(nu(e)+" is not a symbol");if(eu(iu,e))return iu[e]}});var au=ni,ou=Z,su=pi,uu=f,cu=C,lu=o,fu=xo,du=H,pu=Y,hu=me,vu=hi,yu=fe,mu=ou("JSON","stringify"),gu=cu(/./.exec),bu=cu("".charAt),wu=cu("".charCodeAt),ku=cu("".replace),xu=cu(1..toString),_u=/[\uD800-\uDFFF]/g,Su=/^[\uD800-\uDBFF]$/,Ou=/^[\uDC00-\uDFFF]$/,Eu=!yu||lu((function(){var e=ou("Symbol")();return"[null]"!=mu([e])||"{}"!=mu({a:e})||"{}"!=mu(Object(e))})),Tu=lu((function(){return'"\\udf06\\ud834"'!==mu("\udf06\ud834")||'"\\udead"'!==mu("\udead")})),Ru=function(e,t){var n=vu(arguments),r=t;if((pu(t)||void 0!==e)&&!hu(e))return fu(t)||(t=function(e,t){if(du(r)&&(t=uu(r,this,e,t)),!hu(t))return t}),n[1]=t,su(mu,null,n)},Iu=function(e,t,n){var r=bu(n,t-1),i=bu(n,t+1);return gu(Su,e)&&!gu(Ou,i)||gu(Ou,e)&&!gu(Su,r)?"\\u"+xu(wu(e,0),16):e};mu&&au({target:"JSON",stat:!0,arity:3,forced:Eu||Tu},{stringify:function(e,t,n){var r=vu(arguments),i=su(Eu?Ru:mu,null,r);return Tu&&"string"==typeof i?ku(i,_u,Iu):i}});var Cu=Rr,Pu=Be;ni({target:"Object",stat:!0,forced:!fe||o((function(){Cu.f(1)}))},{getOwnPropertySymbols:function(e){var t=Cu.f;return t?t(Pu(e)):[]}});var Au=o,ju=ue,Mu=ot("species"),Lu=function(e){return ju>=51||!Au((function(){var t=[];return(t.constructor={})[Mu]=function(){return{foo:1}},1!==t[e](Boolean).foo}))},Uu=No.filter;ni({target:"Array",proto:!0,forced:!Lu("filter")},{filter:function(e){return Uu(this,e,arguments.length>1?arguments[1]:void 0)}});var Nu=ni,Fu=o,Du=z,qu=a.f,Bu=s,zu=Fu((function(){qu(1)}));Nu({target:"Object",stat:!0,forced:!Bu||zu,sham:!Bu},{getOwnPropertyDescriptor:function(e,t){return qu(Du(e),t)}});var Wu=Mr,$u=z,Ku=a,Hu=Ga;function Gu(e,t,n,r,i,a,o){try{var s=e[a](o),u=s.value}catch(e){return void n(e)}s.done?t(u):Promise.resolve(u).then(r,i)}function Vu(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var a=e.apply(t,n);function o(e){Gu(a,r,i,o,s,"next",e)}function s(e){Gu(a,r,i,o,s,"throw",e)}o(void 0)}))}}function Yu(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Ju(e,t){return Ju=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ju(e,t)}function Qu(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}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Ju(e,t)}function Xu(e){return Xu="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},Xu(e)}function Zu(e,t){if(t&&("object"===Xu(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return Yu(e)}function ec(e){return ec=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ec(e)}function tc(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 nc(e,t,n){return t&&tc(e.prototype,t),n&&tc(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function rc(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ic(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}ni({target:"Object",stat:!0,sham:!s},{getOwnPropertyDescriptors:function(e){for(var t,n,r=$u(e),i=Ku.f,a=Wu(r),o={},s=0;a.length>s;)void 0!==(n=i(r,t=a[s++]))&&Hu(o,t,n);return o}});var ac=Li,oc=Ri?{}.toString:function(){return"[object "+ac(this)+"]"};Ri||Xn(Object.prototype,"toString",oc,{unsafe:!0});var sc,uc,cc,lc,fc="process"==T(i.process),dc=H,pc=String,hc=TypeError,vc=C,yc=Ft,mc=function(e){if("object"==typeof e||dc(e))return e;throw hc("Can't set "+pc(e)+" as a prototype")},gc=Object.setPrototypeOf||("__proto__"in{}?function(){var e,t=!1,n={};try{(e=vc(Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set))(n,[]),t=n instanceof Array}catch(e){}return function(n,r){return yc(n),mc(r),t?e(n,r):n.__proto__=r,n}}():void 0),bc=Z,wc=jt,kc=s,xc=ot("species"),_c=function(e){var t=bc(e),n=wc.f;kc&&t&&!t[xc]&&n(t,xc,{configurable:!0,get:function(){return this}})},Sc=ee,Oc=TypeError,Ec=function(e,t){if(Sc(t,e))return e;throw Oc("Incorrect invocation")},Tc=Ft,Rc=Zi,Ic=U,Cc=ot("species"),Pc=function(e,t){var n,r=Tc(e).constructor;return void 0===r||Ic(n=Tc(r)[Cc])?t:Rc(n)},Ac=TypeError,jc=function(e,t){if(e<t)throw Ac("Not enough arguments");return e},Mc=/(?:ipad|iphone|ipod).*applewebkit/i.test(te),Lc=i,Uc=pi,Nc=wo,Fc=H,Dc=$e,qc=o,Bc=fa,zc=hi,Wc=kt,$c=jc,Kc=Mc,Hc=fc,Gc=Lc.setImmediate,Vc=Lc.clearImmediate,Yc=Lc.process,Jc=Lc.Dispatch,Qc=Lc.Function,Xc=Lc.MessageChannel,Zc=Lc.String,el=0,tl={},nl="onreadystatechange";try{sc=Lc.location}catch(e){}var rl=function(e){if(Dc(tl,e)){var t=tl[e];delete tl[e],t()}},il=function(e){return function(){rl(e)}},al=function(e){rl(e.data)},ol=function(e){Lc.postMessage(Zc(e),sc.protocol+"//"+sc.host)};Gc&&Vc||(Gc=function(e){$c(arguments.length,1);var t=Fc(e)?e:Qc(e),n=zc(arguments,1);return tl[++el]=function(){Uc(t,void 0,n)},uc(el),el},Vc=function(e){delete tl[e]},Hc?uc=function(e){Yc.nextTick(il(e))}:Jc&&Jc.now?uc=function(e){Jc.now(il(e))}:Xc&&!Kc?(lc=(cc=new Xc).port2,cc.port1.onmessage=al,uc=Nc(lc.postMessage,lc)):Lc.addEventListener&&Fc(Lc.postMessage)&&!Lc.importScripts&&sc&&"file:"!==sc.protocol&&!qc(ol)?(uc=ol,Lc.addEventListener("message",al,!1)):uc=nl in Wc("script")?function(e){Bc.appendChild(Wc("script")).onreadystatechange=function(){Bc.removeChild(this),rl(e)}}:function(e){setTimeout(il(e),0)});var sl,ul,cl,ll,fl,dl,pl,hl,vl={set:Gc,clear:Vc},yl=i,ml=/ipad|iphone|ipod/i.test(te)&&void 0!==yl.Pebble,gl=/web0s(?!.*chrome)/i.test(te),bl=i,wl=wo,kl=a.f,xl=vl.set,_l=Mc,Sl=ml,Ol=gl,El=fc,Tl=bl.MutationObserver||bl.WebKitMutationObserver,Rl=bl.document,Il=bl.process,Cl=bl.Promise,Pl=kl(bl,"queueMicrotask"),Al=Pl&&Pl.value;Al||(sl=function(){var e,t;for(El&&(e=Il.domain)&&e.exit();ul;){t=ul.fn,ul=ul.next;try{t()}catch(e){throw ul?ll():cl=void 0,e}}cl=void 0,e&&e.enter()},_l||El||Ol||!Tl||!Rl?!Sl&&Cl&&Cl.resolve?((pl=Cl.resolve(void 0)).constructor=Cl,hl=wl(pl.then,pl),ll=function(){hl(sl)}):El?ll=function(){Il.nextTick(sl)}:(xl=wl(xl,bl),ll=function(){xl(sl)}):(fl=!0,dl=Rl.createTextNode(""),new Tl(sl).observe(dl,{characterData:!0}),ll=function(){dl.data=fl=!fl}));var jl=Al||function(e){var t={fn:e,next:void 0};cl&&(cl.next=t),ul||(ul=t,ll()),cl=t},Ml=i,Ll=function(e){try{return{error:!1,value:e()}}catch(e){return{error:!0,value:e}}},Ul=function(){this.head=null,this.tail=null};Ul.prototype={add:function(e){var t={item:e,next:null};this.head?this.tail.next=t:this.head=t,this.tail=t},get:function(){var e=this.head;if(e)return this.head=e.next,this.tail===e&&(this.tail=null),e.item}};var Nl=Ul,Fl=i.Promise,Dl="object"==typeof Deno&&Deno&&"object"==typeof Deno.version,ql=!Dl&&!fc&&"object"==typeof window&&"object"==typeof document,Bl=i,zl=Fl,Wl=H,$l=Vr,Kl=pn,Hl=ot,Gl=ql,Vl=Dl,Yl=ue;zl&&zl.prototype;var Jl=Hl("species"),Ql=!1,Xl=Wl(Bl.PromiseRejectionEvent),Zl=$l("Promise",(function(){var e=Kl(zl),t=e!==String(zl);if(!t&&66===Yl)return!0;if(!Yl||Yl<51||!/native code/.test(e)){var n=new zl((function(e){e(1)})),r=function(e){e((function(){}),(function(){}))};if((n.constructor={})[Jl]=r,!(Ql=n.then((function(){}))instanceof r))return!0}return!t&&(Gl||Vl)&&!Xl})),ef={CONSTRUCTOR:Zl,REJECTION_EVENT:Xl,SUBCLASSING:Ql},tf={},nf=_e,rf=TypeError,af=function(e){var t,n;this.promise=new e((function(e,r){if(void 0!==t||void 0!==n)throw rf("Bad Promise constructor");t=e,n=r})),this.resolve=nf(t),this.reject=nf(n)};tf.f=function(e){return new af(e)};var of,sf,uf,cf=ni,lf=fc,ff=i,df=f,pf=Xn,hf=gc,vf=oi,yf=_c,mf=_e,gf=H,bf=Y,wf=Ec,kf=Pc,xf=vl.set,_f=jl,Sf=function(e,t){var n=Ml.console;n&&n.error&&(1==arguments.length?n.error(e):n.error(e,t))},Of=Ll,Ef=Nl,Tf=Ln,Rf=Fl,If=tf,Cf="Promise",Pf=ef.CONSTRUCTOR,Af=ef.REJECTION_EVENT,jf=ef.SUBCLASSING,Mf=Tf.getterFor(Cf),Lf=Tf.set,Uf=Rf&&Rf.prototype,Nf=Rf,Ff=Uf,Df=ff.TypeError,qf=ff.document,Bf=ff.process,zf=If.f,Wf=zf,$f=!!(qf&&qf.createEvent&&ff.dispatchEvent),Kf="unhandledrejection",Hf=function(e){var t;return!(!bf(e)||!gf(t=e.then))&&t},Gf=function(e,t){var n,r,i,a=t.value,o=1==t.state,s=o?e.ok:e.fail,u=e.resolve,c=e.reject,l=e.domain;try{s?(o||(2===t.rejection&&Xf(t),t.rejection=1),!0===s?n=a:(l&&l.enter(),n=s(a),l&&(l.exit(),i=!0)),n===e.promise?c(Df("Promise-chain cycle")):(r=Hf(n))?df(r,n,u,c):u(n)):c(a)}catch(e){l&&!i&&l.exit(),c(e)}},Vf=function(e,t){e.notified||(e.notified=!0,_f((function(){for(var n,r=e.reactions;n=r.get();)Gf(n,e);e.notified=!1,t&&!e.rejection&&Jf(e)})))},Yf=function(e,t,n){var r,i;$f?((r=qf.createEvent("Event")).promise=t,r.reason=n,r.initEvent(e,!1,!0),ff.dispatchEvent(r)):r={promise:t,reason:n},!Af&&(i=ff["on"+e])?i(r):e===Kf&&Sf("Unhandled promise rejection",n)},Jf=function(e){df(xf,ff,(function(){var t,n=e.facade,r=e.value;if(Qf(e)&&(t=Of((function(){lf?Bf.emit("unhandledRejection",r,n):Yf(Kf,n,r)})),e.rejection=lf||Qf(e)?2:1,t.error))throw t.value}))},Qf=function(e){return 1!==e.rejection&&!e.parent},Xf=function(e){df(xf,ff,(function(){var t=e.facade;lf?Bf.emit("rejectionHandled",t):Yf("rejectionhandled",t,e.value)}))},Zf=function(e,t,n){return function(r){e(t,r,n)}},ed=function(e,t,n){e.done||(e.done=!0,n&&(e=n),e.value=t,e.state=2,Vf(e,!0))},td=function(e,t,n){if(!e.done){e.done=!0,n&&(e=n);try{if(e.facade===t)throw Df("Promise can't be resolved itself");var r=Hf(t);r?_f((function(){var n={done:!1};try{df(r,t,Zf(td,n,e),Zf(ed,n,e))}catch(t){ed(n,t,e)}})):(e.value=t,e.state=1,Vf(e,!1))}catch(t){ed({done:!1},t,e)}}};if(Pf&&(Ff=(Nf=function(e){wf(this,Ff),mf(e),df(of,this);var t=Mf(this);try{e(Zf(td,t),Zf(ed,t))}catch(e){ed(t,e)}}).prototype,(of=function(e){Lf(this,{type:Cf,done:!1,notified:!1,parent:!1,reactions:new Ef,rejection:!1,state:0,value:void 0})}).prototype=pf(Ff,"then",(function(e,t){var n=Mf(this),r=zf(kf(this,Nf));return n.parent=!0,r.ok=!gf(e)||e,r.fail=gf(t)&&t,r.domain=lf?Bf.domain:void 0,0==n.state?n.reactions.add(r):_f((function(){Gf(r,n)})),r.promise})),sf=function(){var e=new of,t=Mf(e);this.promise=e,this.resolve=Zf(td,t),this.reject=Zf(ed,t)},If.f=zf=function(e){return e===Nf||undefined===e?new sf(e):Wf(e)},gf(Rf)&&Uf!==Object.prototype)){uf=Uf.then,jf||pf(Uf,"then",(function(e,t){var n=this;return new Nf((function(e,t){df(uf,n,e,t)})).then(e,t)}),{unsafe:!0});try{delete Uf.constructor}catch(e){}hf&&hf(Uf,Ff)}cf({global:!0,constructor:!0,wrap:!0,forced:Pf},{Promise:Nf}),vf(Nf,Cf,!1),yf(Cf);var nd={},rd=nd,id=ot("iterator"),ad=Array.prototype,od=function(e){return void 0!==e&&(rd.Array===e||ad[id]===e)},sd=Li,ud=Ee,cd=U,ld=nd,fd=ot("iterator"),dd=function(e){if(!cd(e))return ud(e,fd)||ud(e,"@@iterator")||ld[sd(e)]},pd=f,hd=_e,vd=Ft,yd=be,md=dd,gd=TypeError,bd=function(e,t){var n=arguments.length<2?md(e):t;if(hd(n))return vd(pd(n,e));throw gd(yd(e)+" is not iterable")},wd=f,kd=Ft,xd=Ee,_d=function(e,t,n){var r,i;kd(e);try{if(!(r=xd(e,"return"))){if("throw"===t)throw n;return n}r=wd(r,e)}catch(e){i=!0,r=e}if("throw"===t)throw n;if(i)throw r;return kd(r),n},Sd=wo,Od=f,Ed=Ft,Td=be,Rd=od,Id=pr,Cd=ee,Pd=bd,Ad=dd,jd=_d,Md=TypeError,Ld=function(e,t){this.stopped=e,this.result=t},Ud=Ld.prototype,Nd=function(e,t,n){var r,i,a,o,s,u,c,l=n&&n.that,f=!(!n||!n.AS_ENTRIES),d=!(!n||!n.IS_RECORD),p=!(!n||!n.IS_ITERATOR),h=!(!n||!n.INTERRUPTED),v=Sd(t,l),y=function(e){return r&&jd(r,"normal",e),new Ld(!0,e)},m=function(e){return f?(Ed(e),h?v(e[0],e[1],y):v(e[0],e[1])):h?v(e,y):v(e)};if(d)r=e.iterator;else if(p)r=e;else{if(!(i=Ad(e)))throw Md(Td(e)+" is not iterable");if(Rd(i)){for(a=0,o=Id(e);o>a;a++)if((s=m(e[a]))&&Cd(Ud,s))return s;return new Ld(!1)}r=Pd(e,i)}for(u=d?e.next:r.next;!(c=Od(u,r)).done;){try{s=m(c.value)}catch(e){jd(r,"throw",e)}if("object"==typeof s&&s&&Cd(Ud,s))return s}return new Ld(!1)},Fd=ot("iterator"),Dd=!1;try{var qd=0,Bd={next:function(){return{done:!!qd++}},return:function(){Dd=!0}};Bd[Fd]=function(){return this},Array.from(Bd,(function(){throw 2}))}catch(e){}var zd=function(e,t){if(!t&&!Dd)return!1;var n=!1;try{var r={};r[Fd]=function(){return{next:function(){return{done:n=!0}}}},e(r)}catch(e){}return n},Wd=Fl,$d=ef.CONSTRUCTOR||!zd((function(e){Wd.all(e).then(void 0,(function(){}))})),Kd=f,Hd=_e,Gd=tf,Vd=Ll,Yd=Nd;ni({target:"Promise",stat:!0,forced:$d},{all:function(e){var t=this,n=Gd.f(t),r=n.resolve,i=n.reject,a=Vd((function(){var n=Hd(t.resolve),a=[],o=0,s=1;Yd(e,(function(e){var u=o++,c=!1;s++,Kd(n,t,e).then((function(e){c||(c=!0,a[u]=e,--s||r(a))}),i)})),--s||r(a)}));return a.error&&i(a.value),n.promise}});var Jd=ni,Qd=ef.CONSTRUCTOR,Xd=Fl,Zd=Z,ep=H,tp=Xn,np=Xd&&Xd.prototype;if(Jd({target:"Promise",proto:!0,forced:Qd,real:!0},{catch:function(e){return this.then(void 0,e)}}),ep(Xd)){var rp=Zd("Promise").prototype.catch;np.catch!==rp&&tp(np,"catch",rp,{unsafe:!0})}var ip=f,ap=_e,op=tf,sp=Ll,up=Nd;ni({target:"Promise",stat:!0,forced:$d},{race:function(e){var t=this,n=op.f(t),r=n.reject,i=sp((function(){var i=ap(t.resolve);up(e,(function(e){ip(i,t,e).then(n.resolve,r)}))}));return i.error&&r(i.value),n.promise}});var cp=f,lp=tf;ni({target:"Promise",stat:!0,forced:ef.CONSTRUCTOR},{reject:function(e){var t=lp.f(this);return cp(t.reject,void 0,e),t.promise}});var fp=Ft,dp=Y,pp=tf,hp=function(e,t){if(fp(e),dp(t)&&t.constructor===e)return t;var n=pp.f(e);return(0,n.resolve)(t),n.promise},vp=ni,yp=ef.CONSTRUCTOR,mp=hp;Z("Promise"),vp({target:"Promise",stat:!0,forced:yp},{resolve:function(e){return mp(this,e)}});var gp=No.map;ni({target:"Array",proto:!0,forced:!Lu("map")},{map:function(e){return gp(this,e,arguments.length>1?arguments[1]:void 0)}});var bp={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},wp=kt("span").classList,kp=wp&&wp.constructor&&wp.constructor.prototype,xp=kp===Object.prototype?void 0:kp,_p=o,Sp=function(e,t){var n=[][e];return!!n&&_p((function(){n.call(null,t||function(){return 1},1)}))},Op=No.forEach,Ep=Sp("forEach")?[].forEach:function(e){return Op(this,e,arguments.length>1?arguments[1]:void 0)},Tp=i,Rp=bp,Ip=xp,Cp=Ep,Pp=Xt,Ap=function(e){if(e&&e.forEach!==Cp)try{Pp(e,"forEach",Cp)}catch(t){e.forEach=Cp}};for(var jp in Rp)Rp[jp]&&Ap(Tp[jp]&&Tp[jp].prototype);Ap(Ip);var Mp,Lp=Object.prototype,Up=Lp.hasOwnProperty,Np="function"==typeof Symbol?Symbol:{},Fp=Np.iterator||"@@iterator",Dp=Np.asyncIterator||"@@asyncIterator",qp=Np.toStringTag||"@@toStringTag";function Bp(e,t,n,r){var i=t&&t.prototype instanceof Vp?t:Vp,a=Object.create(i.prototype),o=new sh(r||[]);return a._invoke=function(e,t,n){var r=Wp;return function(i,a){if(r===Kp)throw new Error("Generator is already running");if(r===Hp){if("throw"===i)throw a;return ch()}for(n.method=i,n.arg=a;;){var o=n.delegate;if(o){var s=ih(o,n);if(s){if(s===Gp)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===Wp)throw r=Hp,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=Kp;var u=zp(e,t,n);if("normal"===u.type){if(r=n.done?Hp:$p,u.arg===Gp)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=Hp,n.method="throw",n.arg=u.arg)}}}(e,n,o),a}function zp(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}var Wp="suspendedStart",$p="suspendedYield",Kp="executing",Hp="completed",Gp={};function Vp(){}function Yp(){}function Jp(){}var Qp={};Qp[Fp]=function(){return this};var Xp=Object.getPrototypeOf,Zp=Xp&&Xp(Xp(uh([])));Zp&&Zp!==Lp&&Up.call(Zp,Fp)&&(Qp=Zp);var eh=Jp.prototype=Vp.prototype=Object.create(Qp);function th(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function nh(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===Yp||"GeneratorFunction"===(t.displayName||t.name))}function rh(e,t){function n(r,i,a,o){var s=zp(e[r],e,i);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"===Xu(c)&&Up.call(c,"__await")?t.resolve(c.__await).then((function(e){n("next",e,a,o)}),(function(e){n("throw",e,a,o)})):t.resolve(c).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,o)}))}o(s.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 ih(e,t){var n=e.iterator[t.method];if(n===Mp){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=Mp,ih(e,t),"throw"===t.method))return Gp;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return Gp}var r=zp(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,Gp;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=Mp),t.delegate=null,Gp):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,Gp)}function ah(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 oh(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function sh(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(ah,this),this.reset(!0)}function uh(e){if(e){var t=e[Fp];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(Up.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=Mp,t.done=!0,t};return r.next=r}}return{next:ch}}function ch(){return{value:Mp,done:!0}}Yp.prototype=eh.constructor=Jp,Jp.constructor=Yp,Jp[qp]=Yp.displayName="GeneratorFunction",th(rh.prototype),rh.prototype[Dp]=function(){return this},th(eh),eh[qp]="Generator",eh[Fp]=function(){return this},eh.toString=function(){return"[object Generator]"},sh.prototype={constructor:sh,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=Mp,this.done=!1,this.delegate=null,this.method="next",this.arg=Mp,this.tryEntries.forEach(oh),!e)for(var t in this)"t"===t.charAt(0)&&Up.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=Mp)},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=Mp),!!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 o=Up.call(i,"catchLoc"),s=Up.call(i,"finallyLoc");if(o&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(o){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)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&&Up.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,Gp):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),Gp},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),oh(n),Gp}},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;oh(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:uh(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=Mp),Gp}};var lh={wrap:Bp,isGeneratorFunction:nh,AsyncIterator:rh,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,Jp):(e.__proto__=Jp,qp in e||(e[qp]="GeneratorFunction")),e.prototype=Object.create(eh),e},awrap:function(e){return{__await:e}},async:function(e,t,n,r,i){void 0===i&&(i=Promise);var a=new rh(Bp(e,t,n,r),i);return nh(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:uh},fh=Object.freeze({__proto__:null,default:lh});function dh(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Xu(Reflect))&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}function ph(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Xu(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}var hh=TypeError,vh=function(e){if(e>9007199254740991)throw hh("Maximum allowed index exceeded");return e},yh=ni,mh=o,gh=xo,bh=Y,wh=Be,kh=pr,xh=vh,_h=Ga,Sh=Io,Oh=Lu,Eh=ue,Th=ot("isConcatSpreadable"),Rh=Eh>=51||!mh((function(){var e=[];return e[Th]=!1,e.concat()[0]!==e})),Ih=Oh("concat"),Ch=function(e){if(!bh(e))return!1;var t=e[Th];return void 0!==t?!!t:gh(e)};yh({target:"Array",proto:!0,arity:1,forced:!Rh||!Ih},{concat:function(e){var t,n,r,i,a,o=wh(this),s=Sh(o,0),u=0;for(t=-1,r=arguments.length;t<r;t++)if(Ch(a=-1===t?o:arguments[t]))for(i=kh(a),xh(u+i),n=0;n<i;n++,u++)n in a&&_h(s,u,a[n]);else xh(u+1),_h(s,u++,a);return s.length=u,s}});var Ph=Ft,Ah=_d,jh=wo,Mh=f,Lh=Be,Uh=function(e,t,n,r){try{return r?t(Ph(n)[0],n[1]):t(n)}catch(t){Ah(e,"throw",t)}},Nh=od,Fh=Yi,Dh=pr,qh=Ga,Bh=bd,zh=dd,Wh=Array,$h=function(e){var t=Lh(e),n=Fh(this),r=arguments.length,i=r>1?arguments[1]:void 0,a=void 0!==i;a&&(i=jh(i,r>2?arguments[2]:void 0));var o,s,u,c,l,f,d=zh(t),p=0;if(!d||this===Wh&&Nh(d))for(o=Dh(t),s=n?new this(o):Wh(o);o>p;p++)f=a?i(t[p],p):t[p],qh(s,p,f);else for(l=(c=Bh(t,d)).next,s=n?new this:[];!(u=Mh(l,c)).done;p++)f=a?Uh(c,i,[u.value,p],!0):u.value,qh(s,p,f);return s.length=p,s},Kh=$h;ni({target:"Array",stat:!0,forced:!zd((function(e){Array.from(e)}))},{from:Kh});var Hh,Gh,Vh,Yh=C,Jh=ir,Qh=za,Xh=D,Zh=Yh("".charAt),ev=Yh("".charCodeAt),tv=Yh("".slice),nv=function(e){return function(t,n){var r,i,a=Qh(Xh(t)),o=Jh(n),s=a.length;return o<0||o>=s?e?"":void 0:(r=ev(a,o))<55296||r>56319||o+1===s||(i=ev(a,o+1))<56320||i>57343?e?Zh(a,o):r:e?tv(a,o,o+2):i-56320+(r-55296<<10)+65536}},rv={codeAt:nv(!1),charAt:nv(!0)},iv=!o((function(){function e(){}return e.prototype.constructor=null,Object.getPrototypeOf(new e)!==e.prototype})),av=$e,ov=H,sv=Be,uv=iv,cv=wn("IE_PROTO"),lv=Object,fv=lv.prototype,dv=uv?lv.getPrototypeOf:function(e){var t=sv(e);if(av(t,cv))return t[cv];var n=t.constructor;return ov(n)&&t instanceof n?n.prototype:t instanceof lv?fv:null},pv=o,hv=H,vv=Y,yv=dv,mv=Xn,gv=ot("iterator"),bv=!1;[].keys&&("next"in(Vh=[].keys())?(Gh=yv(yv(Vh)))!==Object.prototype&&(Hh=Gh):bv=!0);var wv=!vv(Hh)||pv((function(){var e={};return Hh[gv].call(e)!==e}));wv&&(Hh={}),hv(Hh[gv])||mv(Hh,gv,(function(){return this}));var kv={IteratorPrototype:Hh,BUGGY_SAFARI_ITERATORS:bv},xv=kv.IteratorPrototype,_v=_a,Sv=g,Ov=oi,Ev=nd,Tv=function(){return this},Rv=function(e,t,n,r){var i=t+" Iterator";return e.prototype=_v(xv,{next:Sv(+!r,n)}),Ov(e,i,!1),Ev[i]=Tv,e},Iv=ni,Cv=f,Pv=H,Av=Rv,jv=dv,Mv=gc,Lv=oi,Uv=Xt,Nv=Xn,Fv=nd,Dv=on.PROPER,qv=on.CONFIGURABLE,Bv=kv.IteratorPrototype,zv=kv.BUGGY_SAFARI_ITERATORS,Wv=ot("iterator"),$v="keys",Kv="values",Hv="entries",Gv=function(){return this},Vv=function(e,t,n,r,i,a,o){Av(n,t,r);var s,u,c,l=function(e){if(e===i&&v)return v;if(!zv&&e in p)return p[e];switch(e){case $v:case Kv:case Hv:return function(){return new n(this,e)}}return function(){return new n(this)}},f=t+" Iterator",d=!1,p=e.prototype,h=p[Wv]||p["@@iterator"]||i&&p[i],v=!zv&&h||l(i),y="Array"==t&&p.entries||h;if(y&&(s=jv(y.call(new e)))!==Object.prototype&&s.next&&(jv(s)!==Bv&&(Mv?Mv(s,Bv):Pv(s[Wv])||Nv(s,Wv,Gv)),Lv(s,f,!0)),Dv&&i==Kv&&h&&h.name!==Kv&&(qv?Uv(p,"name",Kv):(d=!0,v=function(){return Cv(h,this)})),i)if(u={values:l(Kv),keys:a?v:l($v),entries:l(Hv)},o)for(c in u)(zv||d||!(c in p))&&Nv(p,c,u[c]);else Iv({target:t,proto:!0,forced:zv||d},u);return p[Wv]!==v&&Nv(p,Wv,v,{name:i}),Fv[t]=v,u},Yv=function(e,t){return{value:e,done:t}},Jv=rv.charAt,Qv=za,Xv=Ln,Zv=Vv,ey=Yv,ty="String Iterator",ny=Xv.set,ry=Xv.getterFor(ty);Zv(String,"String",(function(e){ny(this,{type:ty,string:Qv(e),index:0})}),(function(){var e,t=ry(this),n=t.string,r=t.index;return r>=n.length?ey(void 0,!0):(e=Jv(n,r),t.index+=e.length,ey(e,!1))}));var iy,ay,oy,sy={exports:{}};function uy(e,t){return["".concat((new Date).toISOString()," Conversations ").concat(e,":")].concat(Array.from(t))}ay=t,oy=function(){var e=function(){},t="undefined",n=("undefined"==typeof window?"undefined":Xu(window))!==t&&Xu(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 o(r){return"debug"===r&&(r="log"),("undefined"==typeof console?"undefined":Xu(console))!==t&&("trace"===r&&n?a:void 0!==console[r]?i(console,r):void 0!==console.log?i(console,"log"):e)}function s(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":Xu(console))!==t&&(s.call(this,n,r),this[e].apply(this,arguments))}}function c(e,t,n){return o(e)||u.apply(this,arguments)}function l(e,n,i){var a,o=this;n=null==n?"WARN":n;var u="loglevel";function l(){var e;if(("undefined"==typeof window?"undefined":Xu(window))!==t&&u){try{e=window.localStorage[u]}catch(e){}if(Xu(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===o.levels[e]&&(e=void 0),e}}"string"==typeof e?u+=":"+e:"symbol"===Xu(e)&&(u=void 0),o.name=e,o.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},o.methodFactory=i||c,o.getLevel=function(){return a},o.setLevel=function(n,i){if("string"==typeof n&&void 0!==o.levels[n.toUpperCase()]&&(n=o.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=o.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":Xu(window))!==t&&u){try{return void(window.localStorage[u]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(u)+"="+n+";"}catch(e){}}}(n),s.call(o,n,e),("undefined"==typeof console?"undefined":Xu(console))===t&&n<o.levels.SILENT)return"No console available for logging"},o.setDefaultLevel=function(e){n=e,l()||o.setLevel(e,!1)},o.resetLevel=function(){o.setLevel(n,!1),function(){if(("undefined"==typeof window?"undefined":Xu(window))!==t&&u){try{return void window.localStorage.removeItem(u)}catch(e){}try{window.document.cookie=encodeURIComponent(u)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}()},o.enableAll=function(e){o.setLevel(o.levels.TRACE,e)},o.disableAll=function(e){o.setLevel(o.levels.SILENT,e)};var f=l();null==f&&(f=n),o.setLevel(f,!1)}var f=new l,d={};f.getLogger=function(e){if("symbol"!==Xu(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":Xu(window))!==t?window.log:void 0;return f.noConflict=function(){return("undefined"==typeof window?"undefined":Xu(window))!==t&&window.log===f&&(window.log=p),f},f.getLoggers=function(){return d},f.default=f,f},(iy=sy).exports?iy.exports=oy():ay.log=oy();var cy,ly,fy=sy.exports.getLogger("twilio-conversations"),dy=function(){function e(t){rc(this,e),ic(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return nc(e,[{key:"setLevel",value:function(e){fy.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];fy.trace.apply(null,uy(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];fy.debug.apply(null,uy(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];fy.info.apply(null,uy(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];fy.warn.apply(null,uy(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];fy.error.apply(null,uy(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){fy.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];fy.trace.apply(null,uy("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];fy.debug.apply(null,uy("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];fy.info.apply(null,uy("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];fy.warn.apply(null,uy("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];fy.error.apply(null,uy("E",t))}}]),e}(),py={};Object.defineProperty(py,"__esModule",{value:!0});var hy=["weeks","years","months","days","hours","minutes","seconds"],vy=py.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)?)?)"),yy=ly=py.parse=function(e){return e.match(vy).slice(1).reduce((function(e,t,n){return e[hy[n]]=parseFloat(t)||0,e}),{})},my=py.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},gy=cy=py.toSeconds=function(e,t){var n=t?t.getTime():Date.now(),r=new Date(n);return(my(e,r).getTime()-r.getTime())/1e3};function by(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 wy(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?by(Object(n),!0).forEach((function(t){ic(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):by(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}py.default={end:my,toSeconds:gy,pattern:vy,parse:yy};var ky="PT5S",xy="PT5S",_y=nc((function e(){var t,n,r,i,a,o,s=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;rc(this,e),ic(this,"links",void 0),ic(this,"limits",void 0),ic(this,"productId",void 0),ic(this,"typingIndicatorTimeoutOverride",void 0),ic(this,"typingIndicatorTimeoutDefault",5e3),ic(this,"backoffConfiguration",void 0),ic(this,"retryWhenThrottled",void 0),ic(this,"consumptionReportInterval",void 0),ic(this,"userInfosToSubscribe",void 0),ic(this,"httpCacheInterval",void 0),ic(this,"reachabilityEnabled",void 0),ic(this,"userIdentity",void 0),ic(this,"userInfo",void 0),ic(this,"myConversations",void 0);var l=s.Chat||s.IPMessaging||s||{};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,emailHistoriesAllowedContentTypes:u.options.email_histories_allowed_mime_types,emailBodiesAllowedContentTypes:u.options.email_bodies_allowed_mime_types},this.typingIndicatorTimeoutOverride=l.typingIndicatorTimeoutOverride,this.backoffConfiguration=wy({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:ky;try{this.httpCacheInterval=cy(ly(f))}catch(e){c.error("Failed to parse http cache interval ".concat(f,", using default value ").concat(ky)),this.httpCacheInterval=cy(ly(ky))}var d=null!==(a=null!==(o=l.consumptionReportIntervalOverride)&&void 0!==o?o:u.options.consumption_report_interval)&&void 0!==a?a:xy;try{this.consumptionReportInterval=cy(ly(d))}catch(e){c.error("Failed to parse consumption report interval ".concat(d,", using default value ").concat(xy)),this.consumptionReportInterval=cy(ly(xy))}})),Sy=ot,Oy=_a,Ey=jt.f,Ty=Sy("unscopables"),Ry=Array.prototype;null==Ry[Ty]&&Ey(Ry,Ty,{configurable:!0,value:Oy(null)});var Iy=function(e){Ry[Ty][e]=!0},Cy=z,Py=Iy,Ay=nd,jy=Ln,My=jt.f,Ly=Vv,Uy=Yv,Ny=s,Fy="Array Iterator",Dy=jy.set,qy=jy.getterFor(Fy),By=Ly(Array,"Array",(function(e,t){Dy(this,{type:Fy,target:Cy(e),index:0,kind:t})}),(function(){var e=qy(this),t=e.target,n=e.kind,r=e.index++;return!t||r>=t.length?(e.target=void 0,Uy(void 0,!0)):Uy("keys"==n?r:"values"==n?t[r]:[r,t[r]],!1)}),"values"),zy=Ay.Arguments=Ay.Array;if(Py("keys"),Py("values"),Py("entries"),Ny&&"values"!==zy.name)try{My(zy,"name",{value:"values"})}catch(e){}var Wy=i,$y=bp,Ky=xp,Hy=By,Gy=Xt,Vy=ot,Yy=Vy("iterator"),Jy=Vy("toStringTag"),Qy=Hy.values,Xy=function(e,t){if(e){if(e[Yy]!==Qy)try{Gy(e,Yy,Qy)}catch(t){e[Yy]=Qy}if(e[Jy]||Gy(e,Jy,t),$y[t])for(var n in Hy)if(e[n]!==Hy[n])try{Gy(e,n,Hy[n])}catch(t){e[n]=Hy[n]}}};for(var Zy in $y)Xy(Wy[Zy]&&Wy[Zy].prototype,Zy);Xy(Ky,"DOMTokenList");var em=H,tm=Y,nm=gc,rm=function(e,t,n){var r,i;return nm&&em(r=t.constructor)&&r!==n&&tm(i=r.prototype)&&i!==n.prototype&&nm(e,i),e},im=C(1..valueOf),am=D,om=za,sm=C("".replace),um="[\t\n\v\f\r \u2028\u2029\ufeff]",cm=RegExp("^"+um+um+"*"),lm=RegExp(um+um+"*$"),fm=function(e){return function(t){var n=om(am(t));return 1&e&&(n=sm(n,cm,"")),2&e&&(n=sm(n,lm,"")),n}},dm={start:fm(1),end:fm(2),trim:fm(3)},pm=s,hm=i,vm=C,ym=Vr,mm=Xn,gm=$e,bm=rm,wm=ee,km=me,xm=ht,_m=o,Sm=Zn.f,Om=a.f,Em=jt.f,Tm=im,Rm=dm.trim,Im="Number",Cm=hm.Number,Pm=Cm.prototype,Am=hm.TypeError,jm=vm("".slice),Mm=vm("".charCodeAt),Lm=function(e){var t=xm(e,"number");return"bigint"==typeof t?t:Um(t)},Um=function(e){var t,n,r,i,a,o,s,u,c=xm(e,"number");if(km(c))throw Am("Cannot convert a Symbol value to a number");if("string"==typeof c&&c.length>2)if(c=Rm(c),43===(t=Mm(c,0))||45===t){if(88===(n=Mm(c,2))||120===n)return NaN}else if(48===t){switch(Mm(c,1)){case 66:case 98:r=2,i=49;break;case 79:case 111:r=8,i=55;break;default:return+c}for(o=(a=jm(c,2)).length,s=0;s<o;s++)if((u=Mm(a,s))<48||u>i)return NaN;return parseInt(a,r)}return+c};if(ym(Im,!Cm(" 0o1")||!Cm("0b1")||Cm("+0x1"))){for(var Nm,Fm=function(e){var t=arguments.length<1?0:Cm(Lm(e)),n=this;return wm(Pm,n)&&_m((function(){Tm(n)}))?bm(Object(t),n,Fm):t},Dm=pm?Sm(Cm):"MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,EPSILON,MAX_SAFE_INTEGER,MIN_SAFE_INTEGER,isFinite,isInteger,isNaN,isSafeInteger,parseFloat,parseInt,fromString,range".split(","),qm=0;Dm.length>qm;qm++)gm(Cm,Nm=Dm[qm])&&!gm(Fm,Nm)&&Em(Fm,Nm,Om(Cm,Nm));Fm.prototype=Pm,Pm.constructor=Fm,mm(hm,Im,Fm,{constructor:!0})}var Bm,zm,Wm=Ft,$m=function(){var e=Wm(this),t="";return e.hasIndices&&(t+="d"),e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.dotAll&&(t+="s"),e.unicode&&(t+="u"),e.unicodeSets&&(t+="v"),e.sticky&&(t+="y"),t},Km=o,Hm=i.RegExp,Gm=Km((function(){var e=Hm("a","y");return e.lastIndex=2,null!=e.exec("abcd")})),Vm=Gm||Km((function(){return!Hm("a","y").sticky})),Ym=Gm||Km((function(){var e=Hm("^r","gy");return e.lastIndex=2,null!=e.exec("str")})),Jm={BROKEN_CARET:Ym,MISSED_STICKY:Vm,UNSUPPORTED_Y:Gm},Qm=o,Xm=i.RegExp,Zm=Qm((function(){var e=Xm(".","s");return!(e.dotAll&&e.exec("\n")&&"s"===e.flags)})),eg=o,tg=i.RegExp,ng=eg((function(){var e=tg("(?<a>b)","g");return"b"!==e.exec("b").groups.a||"bc"!=="b".replace(e,"$<a>c")})),rg=f,ig=C,ag=za,og=$m,sg=Jm,ug=Pe.exports,cg=_a,lg=Ln.get,fg=Zm,dg=ng,pg=ug("native-string-replace",String.prototype.replace),hg=RegExp.prototype.exec,vg=hg,yg=ig("".charAt),mg=ig("".indexOf),gg=ig("".replace),bg=ig("".slice),wg=(zm=/b*/g,rg(hg,Bm=/a/,"a"),rg(hg,zm,"a"),0!==Bm.lastIndex||0!==zm.lastIndex),kg=sg.BROKEN_CARET,xg=void 0!==/()??/.exec("")[1];(wg||xg||kg||fg||dg)&&(vg=function(e){var t,n,r,i,a,o,s,u=this,c=lg(u),l=ag(e),f=c.raw;if(f)return f.lastIndex=u.lastIndex,t=rg(vg,f,l),u.lastIndex=f.lastIndex,t;var d=c.groups,p=kg&&u.sticky,h=rg(og,u),v=u.source,y=0,m=l;if(p&&(h=gg(h,"y",""),-1===mg(h,"g")&&(h+="g"),m=bg(l,u.lastIndex),u.lastIndex>0&&(!u.multiline||u.multiline&&"\n"!==yg(l,u.lastIndex-1))&&(v="(?: "+v+")",m=" "+m,y++),n=new RegExp("^(?:"+v+")",h)),xg&&(n=new RegExp("^"+v+"$(?!\\s)",h)),wg&&(r=u.lastIndex),i=rg(hg,p?n:u,m),p?i?(i.input=bg(i.input,y),i[0]=bg(i[0],y),i.index=u.lastIndex,u.lastIndex+=i[0].length):u.lastIndex=0:wg&&i&&(u.lastIndex=u.global?i.index+i[0].length:r),xg&&i&&i.length>1&&rg(pg,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=o=cg(null),a=0;a<d.length;a++)o[(s=d[a])[0]]=i[s[1]];return i});var _g=vg;ni({target:"RegExp",proto:!0,forced:/./.exec!==_g},{exec:_g});var Sg=C,Og=Xn,Eg=_g,Tg=o,Rg=ot,Ig=Xt,Cg=Rg("species"),Pg=RegExp.prototype,Ag=function(e,t,n,r){var i=Rg(e),a=!Tg((function(){var t={};return t[i]=function(){return 7},7!=""[e](t)})),o=a&&!Tg((function(){var t=!1,n=/a/;return"split"===e&&((n={}).constructor={},n.constructor[Cg]=function(){return n},n.flags="",n[i]=/./[i]),n.exec=function(){return t=!0,null},n[i](""),!t}));if(!a||!o||n){var s=Sg(/./[i]),u=t(i,""[e],(function(e,t,n,r,i){var o=Sg(e),u=t.exec;return u===Eg||u===Pg.exec?a&&!i?{done:!0,value:s(t,n,r)}:{done:!0,value:o(n,t,r)}:{done:!1}}));Og(String.prototype,e,u[0]),Og(Pg,i,u[1])}r&&Ig(Pg[i],"sham",!0)},jg=rv.charAt,Mg=function(e,t,n){return t+(n?jg(e,t).length:1)},Lg=C,Ug=Be,Ng=Math.floor,Fg=Lg("".charAt),Dg=Lg("".replace),qg=Lg("".slice),Bg=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,zg=/\$([$&'`]|\d{1,2})/g,Wg=f,$g=Ft,Kg=H,Hg=T,Gg=_g,Vg=TypeError,Yg=function(e,t){var n=e.exec;if(Kg(n)){var r=Wg(n,e,t);return null!==r&&$g(r),r}if("RegExp"===Hg(e))return Wg(Gg,e,t);throw Vg("RegExp#exec called on incompatible receiver")},Jg=pi,Qg=f,Xg=C,Zg=Ag,eb=o,tb=Ft,nb=H,rb=U,ib=ir,ab=fr,ob=za,sb=D,ub=Mg,cb=Ee,lb=function(e,t,n,r,i,a){var o=n+e.length,s=r.length,u=zg;return void 0!==i&&(i=Ug(i),u=Bg),Dg(a,u,(function(a,u){var c;switch(Fg(u,0)){case"$":return"$";case"&":return e;case"`":return qg(t,0,n);case"'":return qg(t,o);case"<":c=i[qg(u,1,-1)];break;default:var l=+u;if(0===l)return a;if(l>s){var f=Ng(l/10);return 0===f?a:f<=s?void 0===r[f-1]?Fg(u,1):r[f-1]+Fg(u,1):a}c=r[l-1]}return void 0===c?"":c}))},fb=Yg,db=ot("replace"),pb=Math.max,hb=Math.min,vb=Xg([].concat),yb=Xg([].push),mb=Xg("".indexOf),gb=Xg("".slice),bb="$0"==="a".replace(/./,"$0"),wb=!!/./[db]&&""===/./[db]("a","$0"),kb=!eb((function(){var e=/./;return e.exec=function(){var e=[];return e.groups={a:"7"},e},"7"!=="".replace(e,"$<a>")}));Zg("replace",(function(e,t,n){var r=wb?"$":"$0";return[function(e,n){var r=sb(this),i=rb(e)?void 0:cb(e,db);return i?Qg(i,e,r,n):Qg(t,ob(r),e,n)},function(e,i){var a=tb(this),o=ob(e);if("string"==typeof i&&-1===mb(i,r)&&-1===mb(i,"$<")){var s=n(t,a,o,i);if(s.done)return s.value}var u=nb(i);u||(i=ob(i));var c=a.global;if(c){var l=a.unicode;a.lastIndex=0}for(var f=[];;){var d=fb(a,o);if(null===d)break;if(yb(f,d),!c)break;""===ob(d[0])&&(a.lastIndex=ub(o,ab(a.lastIndex),l))}for(var p,h="",v=0,y=0;y<f.length;y++){for(var m=ob((d=f[y])[0]),g=pb(hb(ib(d.index),o.length),0),b=[],w=1;w<d.length;w++)yb(b,void 0===(p=d[w])?p:String(p));var k=d.groups;if(u){var x=vb([m],b,g,o);void 0!==k&&yb(x,k);var _=ob(Jg(i,void 0,x))}else _=lb(m,o,g,b,k,i);g>=v&&(h+=gb(o,v,g)+_,v=g+m.length)}return h+gb(o,v)}]}),!kb||!bb||wb);var xb=ni,_b=L,Sb=z,Ob=Sp,Eb=C([].join),Tb=_b!=Object,Rb=Ob("join",",");function Ib(e){return JSON.parse(JSON.stringify(e))}function Cb(e){return void 0===e||isNaN(Number(e))?null:Number(e)}function Pb(e){try{return new Date(e)}catch(e){return null}}function Ab(e,t,n){var r={};if(e)try{r=JSON.parse(e)}catch(e){n.warn(t,e)}return r}xb({target:"Array",proto:!0,forced:Tb||!Rb},{join:function(e){return Eb(Sb(this),void 0===e?",":e)}});var jb=function(){function e(t){rc(this,e),ic(this,"base",void 0),ic(this,"args",void 0),ic(this,"paths",void 0),this.base=t.replace(/\/$/,""),this.args=[],this.paths=[]}return nc(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}(),Mb={},Lb=ni,Ub=xo,Nb=Yi,Fb=Y,Db=ur,qb=pr,Bb=z,zb=Ga,Wb=ot,$b=hi,Kb=Lu("slice"),Hb=Wb("species"),Gb=Array,Vb=Math.max;Lb({target:"Array",proto:!0,forced:!Kb},{slice:function(e,t){var n,r,i,a=Bb(this),o=qb(a),s=Db(e,o),u=Db(void 0===t?o:t,o);if(Ub(a)&&(n=a.constructor,(Nb(n)&&(n===Gb||Ub(n.prototype))||Fb(n)&&null===(n=n[Hb]))&&(n=void 0),n===Gb||void 0===n))return $b(a,s,u);for(r=new(void 0===n?Gb:n)(Vb(u-s,0)),i=0;s<u;s++,i++)s in a&&zb(r,i,a[s]);return r.length=i,r}});var Yb,Jb,Qb=ni,Xb=f,Zb=H,ew=Ft,tw=za,nw=(Yb=!1,(Jb=/[ac]/).exec=function(){return Yb=!0,/./.exec.apply(this,arguments)},!0===Jb.test("abc")&&Yb),rw=/./.test;Qb({target:"RegExp",proto:!0,forced:!nw},{test:function(e){var t=ew(this),n=tw(e),r=t.exec;if(!Zb(r))return Xb(rw,t,n);var i=Xb(r,t,n);return null!==i&&(ew(i),!0)}});var iw=ni,aw=s,ow=i,sw=C,uw=$e,cw=H,lw=ee,fw=za,dw=jt.f,pw=Dr,hw=ow.Symbol,vw=hw&&hw.prototype;if(aw&&cw(hw)&&(!("description"in vw)||void 0!==hw().description)){var yw={},mw=function(){var e=arguments.length<1||void 0===arguments[0]?void 0:fw(arguments[0]),t=lw(vw,this)?new hw(e):void 0===e?hw():hw(e);return""===e&&(yw[t]=!0),t};pw(mw,hw),mw.prototype=vw,vw.constructor=mw;var gw="Symbol(test)"==String(hw("test")),bw=sw(vw.valueOf),ww=sw(vw.toString),kw=/^Symbol\((.*)\)[^)]+$/,xw=sw("".replace),_w=sw("".slice);dw(vw,"description",{configurable:!0,get:function(){var e=bw(this);if(uw(yw,e))return"";var t=ww(e),n=gw?_w(t,7,-1):xw(t,kw,"$1");return""===n?void 0:n}}),iw({global:!0,constructor:!0,forced:!0},{Symbol:mw})}fo("iterator");var Sw={exports:{}};!function(e){function t(n){return e.exports=t="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.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}(Sw);var Ow=s,Ew=on.EXISTS,Tw=C,Rw=jt.f,Iw=Function.prototype,Cw=Tw(Iw.toString),Pw=/function\b(?:\s|\/\*[\S\s]*?\*\/|\/\/[^\n\r]*[\n\r]+)*([^\s(/]*)/,Aw=Tw(Pw.exec);Ow&&!Ew&&Rw(Iw,"name",{configurable:!0,get:function(){try{return Aw(Pw,Cw(this))[1]}catch(e){return""}}});var jw={exports:{}},Mw={exports:{}};!function(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports}(Mw);var Lw={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=[],o=!0,s=!1;try{for(n=n.call(e);!(o=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);o=!0);}catch(e){s=!0,i=e}finally{try{o||null==n.return||n.return()}finally{if(s)throw i}}return a}},e.exports.__esModule=!0,e.exports.default=e.exports}(Lw);var Uw={exports:{}},Nw={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.__esModule=!0,e.exports.default=e.exports}(Nw),function(e){var t=Nw.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.__esModule=!0,e.exports.default=e.exports}(Uw);var Fw={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.__esModule=!0,e.exports.default=e.exports}(Fw),function(e){var t=Mw.exports,n=Lw.exports,r=Uw.exports,i=Fw.exports;e.exports=function(e,a){return t(e)||n(e,a)||r(e,a)||i()},e.exports.__esModule=!0,e.exports.default=e.exports}(jw);var Dw={exports:{}},qw={exports:{}};!function(e){var t=Nw.exports;e.exports=function(e){if(Array.isArray(e))return t(e)},e.exports.__esModule=!0,e.exports.default=e.exports}(qw);var Bw={exports:{}};!function(e){e.exports=function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)},e.exports.__esModule=!0,e.exports.default=e.exports}(Bw);var zw={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.__esModule=!0,e.exports.default=e.exports}(zw),function(e){var t=qw.exports,n=Bw.exports,r=Uw.exports,i=zw.exports;e.exports=function(e){return t(e)||n(e)||r(e)||i()},e.exports.__esModule=!0,e.exports.default=e.exports}(Dw);var Ww={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),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports}(Ww);var $w={exports:{}};!function(e){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports}($w);var Kw={exports:{}},Hw={exports:{}};!function(e){function t(n,r){return e.exports=t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},e.exports.__esModule=!0,e.exports.default=e.exports,t(n,r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}(Hw),function(e){var t=Hw.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}}),Object.defineProperty(e,"prototype",{writable:!1}),n&&t(e,n)},e.exports.__esModule=!0,e.exports.default=e.exports}(Kw);var Gw={exports:{}},Vw={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.__esModule=!0,e.exports.default=e.exports}(Vw),function(e){var t=Sw.exports.default,n=Vw.exports;e.exports=function(e,r){if(r&&("object"===t(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return n(e)},e.exports.__esModule=!0,e.exports.default=e.exports}(Gw);var Yw={exports:{}};!function(e){function t(n){return e.exports=t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},e.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}(Yw);var Jw=gr.includes,Qw=Iy;ni({target:"Array",proto:!0,forced:o((function(){return!Array(1).includes()}))},{includes:function(e){return Jw(this,e,arguments.length>1?arguments[1]:void 0)}}),Qw("includes");var Xw=Y,Zw=Math.floor,ek=Number.isInteger||function(e){return!Xw(e)&&isFinite(e)&&Zw(e)===e};ni({target:"Number",stat:!0},{isInteger:ek});var tk=s,nk=C,rk=ra,ik=z,ak=nk(d.f),ok=nk([].push),sk=function(e){return function(t){for(var n,r=ik(t),i=rk(r),a=i.length,o=0,s=[];a>o;)n=i[o++],tk&&!ak(r,n)||ok(s,e?[n,r[n]]:r[n]);return s}},uk={entries:sk(!0),values:sk(!1)}.entries;ni({target:"Object",stat:!0},{entries:function(e){return uk(e)}}),Object.defineProperty(Mb,"__esModule",{value:!0});var ck=jw.exports,lk=Dw.exports,fk=Ww.exports,dk=$w.exports,pk=Kw.exports,hk=Gw.exports,vk=Yw.exports;function yk(e){return e&&"object"===Xu(e)&&"default"in e?e:{default:e}}var mk=yk(Sw.exports),gk=yk(ck),bk=yk(lk),wk=yk(fk),kk=yk(dk),xk=yk(pk),_k=yk(hk),Sk=yk(vk),Ok=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return{checks:t}};function Ek(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 Tk(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 Tk(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function Tk(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 Rk=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Ok((function(e){var n,r=!1,i=[],a=Ek(t);try{for(a.s();!(n=a.n()).done;){var o=n.value;"string"!=typeof o?(r=r||e instanceof o,i.push("an instance of ".concat(o.name))):(r=r||mk.default(e)===o,i.push("of type ".concat(o)))}}catch(e){a.e(e)}finally{a.f()}return[r,i]}))};function Ik(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 Ck(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 Ck(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function Ck(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 Pk(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=Sk.default(e);if(t){var i=Sk.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _k.default(this,n)}}function Ak(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 jk(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 jk(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function jk(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 Mk=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=Ak(t.entries());try{for(r.s();!(n=r.n()).done;){var i=gk.default(n.value,2),a=i[0],o=i[1],s=Fk(e[a],o),u=gk.default(s,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()}},Lk=function(e){var t,n,r;(["undefined","boolean","number","bigint","string"].includes(mk.default(e))&&(n="string"==typeof e?'"'.concat(e,'"'):"".concat(e)),"object"===mk.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=mk.default(e)),n},Uk=function(e){var t,n=[],r=Ak(e);try{for(r.s();!(t=r.n()).done;){var i=t.value;n.push(Nk(i))}}catch(e){r.e(e)}finally{r.f()}return n},Nk=function(e){var t,n=[],r=Ak(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(Rk(i))}}catch(e){r.e(e)}finally{r.f()}return n},Fk=function(e,t){var n,r,i=[],a=!1,o=Ak(e);try{for(o.s();!(r=o.n()).done;){var s,u=Ak(r.value.checks);try{for(u.s();!(s=u.n()).done;){var c=(0,s.value)(t),l=gk.default(c,3),f=l[0],d=l[1],p=l[2];a=a||f,!n&&p&&(n=p),d&&(i=[].concat(bk.default(i),"string"==typeof d?[d]:bk.default(d)))}}catch(e){u.e(e)}finally{u.f()}}}catch(e){o.e(e)}finally{o.f()}if(a)return[!0];var h=n||Lk(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 Dk(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 qk(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 qk(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function qk(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 Bk=Ok((function(e){return["string"==typeof e&&e.length>0,"a non-empty string"]})),zk=Ok((function(e){return["number"==typeof e&&Number.isInteger(e)&&e>=0,"a non-negative integer"]})),Wk=Ok((function(e){return["object"===mk.default(e)&&null!==e&&!Array.isArray(e),"a pure object (non-null and non-array)"]}));function $k(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 Kk(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 Kk(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function Kk(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}Mb.array=function(e,t){return Ok((function(n){if(!Array.isArray(n))return[!1,"an array of ".concat(e)];var r,i=$k(n.entries());try{for(i.s();!(r=i.n()).done;){var a=gk.default(r.value,2),o=a[0],s=a[1],u=Fk(Nk(t),s),c=gk.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"a valid array of ".concat(e," (index ").concat(o," should be ").concat(d,")"),"malformed array of ".concat(e," (index ").concat(o," is ").concat(f,")")]}}catch(e){i.e(e)}finally{i.f()}return[!0]}))};var Hk=Mb.custom=Ok,Gk=Mb.literal=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Ok((function(e){var n,r=!1,i=[],a=Ik(t);try{for(a.s();!(n=a.n()).done;){var o=n.value;r=r||e===o,i.push("string"==typeof o?'"'.concat(o,'"'):"".concat(o))}}catch(e){a.e(e)}finally{a.f()}return[r,i]}))},Vk=Mb.nonEmptyArray=function(e,t){return Ok((function(n){if(!Array.isArray(n)||n.length<1)return[!1,"a non-empty array of ".concat(e)];var r,i=Dk(n.entries());try{for(i.s();!(r=i.n()).done;){var a=gk.default(r.value,2),o=a[0],s=a[1],u=Fk(Nk(t),s),c=gk.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"a valid non-empty array of ".concat(e," (index ").concat(o," should be ").concat(d,")"),"malformed array of ".concat(e," (index ").concat(o," is ").concat(f,")")]}}catch(e){i.e(e)}finally{i.f()}return[!0]}))},Yk=Mb.nonEmptyString=Bk,Jk=Mb.nonNegativeInteger=zk,Qk=Mb.objectSchema=function(e,t){return Ok((function(n){if("object"!==mk.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=gk.default(i[r],2),o=a[0],s=a[1],u=Fk(Nk(s),n[o]),c=gk.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"valid ".concat(e,' (key "').concat(o,'" should be ').concat(d,")"),"malformed ".concat(e,' (key "').concat(o,'" is ').concat(f,")")]}return[!0]}))},Xk=Mb.pureObject=Wk;Mb.runtimeTypeValidation=Mk,Mb.stringifyReceivedType=Lk,Mb.type=Rk;var Zk=Mb.validateConstructorTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Uk(t);return function(e){return function(e){xk.default(n,e);var t=Pk(n);function n(){kk.default(this,n);for(var e=arguments.length,i=new Array(e),a=0;a<e;a++)i[a]=arguments[a];return Mk(r,i),t.call.apply(t,[this].concat(i))}return wk.default(n)}(e)}},ex=Mb.validateTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Uk(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 Mk(r,t),i.apply(this,t)}}},tx=Mb.validateTypesAsync=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Uk(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{Mk(r,t)}catch(e){return Promise.reject(e)}return i.apply(this,t)}}},nx=Hk((function(e){return[["string","number","boolean","object"].includes(Xu(e)),"a JSON type"]})),rx=Hk((function(e){return[["undefined","string","number","boolean","object"].includes(Xu(e)),"an optional JSON type"]})),ix={},ax={exports:{}},ox={exports:{}};!function(e){var t=Yw.exports;e.exports=function(e,n){for(;!Object.prototype.hasOwnProperty.call(e,n)&&null!==(e=t(e)););return e},e.exports.__esModule=!0,e.exports.default=e.exports}(ox),function(e){var t=ox.exports;function n(){return"undefined"!=typeof Reflect&&Reflect.get?(e.exports=n=Reflect.get.bind(),e.exports.__esModule=!0,e.exports.default=e.exports):(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(arguments.length<3?e:r):a.value}},e.exports.__esModule=!0,e.exports.default=e.exports),n.apply(this,arguments)}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports}(ax);var sx={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.__esModule=!0,e.exports.default=e.exports}(sx),Object.defineProperty(ix,"__esModule",{value:!0});var ux=$w.exports,cx=Ww.exports,lx=Vw.exports,fx=ax.exports,dx=Kw.exports,px=Gw.exports,hx=Yw.exports,vx=sx.exports;function yx(e){return e&&"object"===Xu(e)&&"default"in e?e:{default:e}}var mx=yx(Dw.exports),gx=yx(ux),bx=yx(cx),wx=yx(lx),kx=yx(fx),xx=yx(dx),_x=yx(px),Sx=yx(hx),Ox=yx(vx);function Ex(){}function Tx(){Tx.init.call(this)}function Rx(e){return void 0===e._maxListeners?Tx.defaultMaxListeners:e._maxListeners}function Ix(e,t,n){if(t)e.call(n);else for(var r=e.length,i=Nx(e,r),a=0;a<r;++a)i[a].call(n)}function Cx(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=Nx(e,i),o=0;o<i;++o)a[o].call(n,r)}function Px(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,o=Nx(e,a),s=0;s<a;++s)o[s].call(n,r,i)}function Ax(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var o=e.length,s=Nx(e,o),u=0;u<o;++u)s[u].call(n,r,i,a)}function jx(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=Nx(e,i),o=0;o<i;++o)a[o].apply(n,r)}function Mx(e,t,n,r){var i,a,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),o=a[t]):(a=e._events=new Ex,e._eventsCount=0),o){if("function"==typeof o?o=a[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),!o.warned&&(i=Rx(e))&&i>0&&o.length>i){o.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=e,s.type=t,s.count=o.length,function(e){"function"==typeof console.warn?console.warn(e):console.log(e)}(s)}}else o=a[t]=n,++e._eventsCount;return e}function Lx(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 Ux(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 Nx(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function Fx(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=Sx.default(e);if(t){var i=Sx.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return _x.default(this,n)}}Ex.prototype=Object.create(null),Tx.EventEmitter=Tx,Tx.usingDomains=!1,Tx.prototype.domain=void 0,Tx.prototype._events=void 0,Tx.prototype._maxListeners=void 0,Tx.defaultMaxListeners=10,Tx.init=function(){this.domain=null,Tx.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new Ex,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Tx.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},Tx.prototype.getMaxListeners=function(){return Rx(this)},Tx.prototype.emit=function(e){var t,n,r,i,a,o,s,u="error"===e;if(o=this._events)u=u&&null==o.error;else if(!u)return!1;if(s=this.domain,u){if(t=arguments[1],!s){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=s,t.domainThrown=!1,s.emit("error",t),!1}if(!(n=o[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:Ix(n,l,this);break;case 2:Cx(n,l,this,arguments[1]);break;case 3:Px(n,l,this,arguments[1],arguments[2]);break;case 4:Ax(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];jx(n,l,this,i)}return!0},Tx.prototype.addListener=function(e,t){return Mx(this,e,t,!1)},Tx.prototype.on=Tx.prototype.addListener,Tx.prototype.prependListener=function(e,t){return Mx(this,e,t,!0)},Tx.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,Lx(this,e,t)),this},Tx.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,Lx(this,e,t)),this},Tx.prototype.removeListener=function(e,t){var n,r,i,a,o;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 Ex:(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){o=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 Ex,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,o||t)}return this},Tx.prototype.off=function(e,t){return this.removeListener(e,t)},Tx.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new Ex,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new Ex: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 Ex,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},Tx.prototype.listeners=function(e){var t,n,r=this._events;return n=r&&(t=r[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):[],n},Tx.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Ux.call(e,t)},Tx.prototype.listenerCount=Ux,Tx.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var Dx=function(e){xx.default(n,e);var t=Fx(n);function n(){var e;return gx.default(this,n),e=t.call(this),Ox.default(wx.default(e),"eventHistory",new Map),e}return bx.default(n,[{key:"on",value:function(e,t){return kx.default(Sx.default(n.prototype),"on",this).call(this,e,t)}},{key:"once",value:function(e,t){return kx.default(Sx.default(n.prototype),"once",this).call(this,e,t)}},{key:"off",value:function(e,t){return kx.default(Sx.default(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=kx.default(Sx.default(n.prototype),"emit",this)).call.apply(t,[this,e].concat(i))}},{key:"addListener",value:function(e,t){return kx.default(Sx.default(n.prototype),"addListener",this).call(this,e,t)}},{key:"removeListener",value:function(e,t){return kx.default(Sx.default(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,mx.default(n)),this.addListener(e,t)}},{key:"onWithReplay",value:function(e,t){return this.addListenerWithReplay(e,t)}},{key:"onceWithReplay",value:function(e,t){var r=this.eventHistory.get(e);return void 0!==r?(t.apply(void 0,mx.default(r)),this):kx.default(Sx.default(n.prototype),"once",this).call(this,e,t)}}]),n}(Tx),qx=ix.ReplayEventEmitter=Dx,Bx={exports:{}};!function(e,n){var r="__lodash_hash_undefined__",i=9007199254740991,a="[object Arguments]",o="[object Array]",s="[object Boolean]",u="[object Date]",c="[object Error]",l="[object Function]",f="[object Map]",d="[object Number]",p="[object Object]",h="[object Promise]",v="[object RegExp]",y="[object Set]",m="[object String]",g="[object Symbol]",b="[object WeakMap]",w="[object ArrayBuffer]",k="[object DataView]",x=/^\[object .+?Constructor\]$/,_=/^(?:0|[1-9]\d*)$/,S={};S["[object Float32Array]"]=S["[object Float64Array]"]=S["[object Int8Array]"]=S["[object Int16Array]"]=S["[object Int32Array]"]=S["[object Uint8Array]"]=S["[object Uint8ClampedArray]"]=S["[object Uint16Array]"]=S["[object Uint32Array]"]=!0,S[a]=S[o]=S[w]=S[s]=S[k]=S[u]=S[c]=S[l]=S[f]=S[d]=S[p]=S[v]=S[y]=S[m]=S[b]=!1;var O="object"==Xu(t)&&t&&t.Object===Object&&t,E="object"==("undefined"==typeof self?"undefined":Xu(self))&&self&&self.Object===Object&&self,T=O||E||Function("return this")(),R=n&&!n.nodeType&&n,I=R&&e&&!e.nodeType&&e,C=I&&I.exports===R,P=C&&O.process,A=function(){try{return P&&P.binding&&P.binding("util")}catch(e){}}(),j=A&&A.isTypedArray;function M(e,t){for(var n=-1,r=null==e?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}function L(e,t){return e.has(t)}function U(e){var t=-1,n=Array(e.size);return e.forEach((function(e,r){n[++t]=[r,e]})),n}function N(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n}var F,D,q=Array.prototype,B=Function.prototype,z=Object.prototype,W=T["__core-js_shared__"],$=B.toString,K=z.hasOwnProperty,H=function(){var e=/[^.]+$/.exec(W&&W.keys&&W.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),G=z.toString,V=RegExp("^"+$.call(K).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Y=C?T.Buffer:void 0,J=T.Symbol,Q=T.Uint8Array,X=z.propertyIsEnumerable,Z=q.splice,ee=J?J.toStringTag:void 0,te=Object.getOwnPropertySymbols,ne=Y?Y.isBuffer:void 0,re=(F=Object.keys,D=Object,function(e){return F(D(e))}),ie=Ae(T,"DataView"),ae=Ae(T,"Map"),oe=Ae(T,"Promise"),se=Ae(T,"Set"),ue=Ae(T,"WeakMap"),ce=Ae(Object,"create"),le=Ue(ie),fe=Ue(ae),de=Ue(oe),pe=Ue(se),he=Ue(ue),ve=J?J.prototype:void 0,ye=ve?ve.valueOf:void 0;function me(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function ge(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function be(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function we(e){var t=-1,n=null==e?0:e.length;for(this.__data__=new be;++t<n;)this.add(e[t])}function ke(e){var t=this.__data__=new ge(e);this.size=t.size}function xe(e,t){var n=De(e),r=!n&&Fe(e),i=!n&&!r&&qe(e),a=!n&&!r&&!i&&Ke(e),o=n||r||i||a,s=o?function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],u=s.length;for(var c in e)!t&&!K.call(e,c)||o&&("length"==c||i&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||Le(c,u))||s.push(c);return s}function _e(e,t){for(var n=e.length;n--;)if(Ne(e[n][0],t))return n;return-1}function Se(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":ee&&ee in Object(e)?function(e){var t=K.call(e,ee),n=e[ee];try{e[ee]=void 0;var r=!0}catch(e){}var i=G.call(e);r&&(t?e[ee]=n:delete e[ee]);return i}(e):function(e){return G.call(e)}(e)}function Oe(e){return $e(e)&&Se(e)==a}function Ee(e,t,n,r,i){return e===t||(null==e||null==t||!$e(e)&&!$e(t)?e!=e&&t!=t:function(e,t,n,r,i,l){var h=De(e),b=De(t),x=h?o:Me(e),_=b?o:Me(t),S=(x=x==a?p:x)==p,O=(_=_==a?p:_)==p,E=x==_;if(E&&qe(e)){if(!qe(t))return!1;h=!0,S=!1}if(E&&!S)return l||(l=new ke),h||Ke(e)?Ie(e,t,n,r,i,l):function(e,t,n,r,i,a,o){switch(n){case k:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case w:return!(e.byteLength!=t.byteLength||!a(new Q(e),new Q(t)));case s:case u:case d:return Ne(+e,+t);case c:return e.name==t.name&&e.message==t.message;case v:case m:return e==t+"";case f:var l=U;case y:var p=1&r;if(l||(l=N),e.size!=t.size&&!p)return!1;var h=o.get(e);if(h)return h==t;r|=2,o.set(e,t);var b=Ie(l(e),l(t),r,i,a,o);return o.delete(e),b;case g:if(ye)return ye.call(e)==ye.call(t)}return!1}(e,t,x,n,r,i,l);if(!(1&n)){var T=S&&K.call(e,"__wrapped__"),R=O&&K.call(t,"__wrapped__");if(T||R){var I=T?e.value():e,C=R?t.value():t;return l||(l=new ke),i(I,C,n,r,l)}}if(!E)return!1;return l||(l=new ke),function(e,t,n,r,i,a){var o=1&n,s=Ce(e),u=s.length,c=Ce(t).length;if(u!=c&&!o)return!1;var l=u;for(;l--;){var f=s[l];if(!(o?f in t:K.call(t,f)))return!1}var d=a.get(e);if(d&&a.get(t))return d==t;var p=!0;a.set(e,t),a.set(t,e);var h=o;for(;++l<u;){var v=e[f=s[l]],y=t[f];if(r)var m=o?r(y,v,f,t,e,a):r(v,y,f,e,t,a);if(!(void 0===m?v===y||i(v,y,n,r,a):m)){p=!1;break}h||(h="constructor"==f)}if(p&&!h){var g=e.constructor,b=t.constructor;g==b||!("constructor"in e)||!("constructor"in t)||"function"==typeof g&&g instanceof g&&"function"==typeof b&&b instanceof b||(p=!1)}return a.delete(e),a.delete(t),p}(e,t,n,r,i,l)}(e,t,n,r,Ee,i))}function Te(e){return!(!We(e)||function(e){return!!H&&H in e}(e))&&(Be(e)?V:x).test(Ue(e))}function Re(e){if(n=(t=e)&&t.constructor,r="function"==typeof n&&n.prototype||z,t!==r)return re(e);var t,n,r,i=[];for(var a in Object(e))K.call(e,a)&&"constructor"!=a&&i.push(a);return i}function Ie(e,t,n,r,i,a){var o=1&n,s=e.length,u=t.length;if(s!=u&&!(o&&u>s))return!1;var c=a.get(e);if(c&&a.get(t))return c==t;var l=-1,f=!0,d=2&n?new we:void 0;for(a.set(e,t),a.set(t,e);++l<s;){var p=e[l],h=t[l];if(r)var v=o?r(h,p,l,t,e,a):r(p,h,l,e,t,a);if(void 0!==v){if(v)continue;f=!1;break}if(d){if(!M(t,(function(e,t){if(!L(d,t)&&(p===e||i(p,e,n,r,a)))return d.push(t)}))){f=!1;break}}else if(p!==h&&!i(p,h,n,r,a)){f=!1;break}}return a.delete(e),a.delete(t),f}function Ce(e){return function(e,t,n){var r=t(e);return De(e)?r:function(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}(r,n(e))}(e,He,je)}function Pe(e,t){var n=e.__data__;return function(e){var t=Xu(e);return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}(t)?n["string"==typeof t?"string":"hash"]:n.map}function Ae(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return Te(n)?n:void 0}me.prototype.clear=function(){this.__data__=ce?ce(null):{},this.size=0},me.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},me.prototype.get=function(e){var t=this.__data__;if(ce){var n=t[e];return n===r?void 0:n}return K.call(t,e)?t[e]:void 0},me.prototype.has=function(e){var t=this.__data__;return ce?void 0!==t[e]:K.call(t,e)},me.prototype.set=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=ce&&void 0===t?r:t,this},ge.prototype.clear=function(){this.__data__=[],this.size=0},ge.prototype.delete=function(e){var t=this.__data__,n=_e(t,e);return!(n<0)&&(n==t.length-1?t.pop():Z.call(t,n,1),--this.size,!0)},ge.prototype.get=function(e){var t=this.__data__,n=_e(t,e);return n<0?void 0:t[n][1]},ge.prototype.has=function(e){return _e(this.__data__,e)>-1},ge.prototype.set=function(e,t){var n=this.__data__,r=_e(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this},be.prototype.clear=function(){this.size=0,this.__data__={hash:new me,map:new(ae||ge),string:new me}},be.prototype.delete=function(e){var t=Pe(this,e).delete(e);return this.size-=t?1:0,t},be.prototype.get=function(e){return Pe(this,e).get(e)},be.prototype.has=function(e){return Pe(this,e).has(e)},be.prototype.set=function(e,t){var n=Pe(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this},we.prototype.add=we.prototype.push=function(e){return this.__data__.set(e,r),this},we.prototype.has=function(e){return this.__data__.has(e)},ke.prototype.clear=function(){this.__data__=new ge,this.size=0},ke.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},ke.prototype.get=function(e){return this.__data__.get(e)},ke.prototype.has=function(e){return this.__data__.has(e)},ke.prototype.set=function(e,t){var n=this.__data__;if(n instanceof ge){var r=n.__data__;if(!ae||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new be(r)}return n.set(e,t),this.size=n.size,this};var je=te?function(e){return null==e?[]:(e=Object(e),function(e,t){for(var n=-1,r=null==e?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}(te(e),(function(t){return X.call(e,t)})))}:function(){return[]},Me=Se;function Le(e,t){return!!(t=null==t?i:t)&&("number"==typeof e||_.test(e))&&e>-1&&e%1==0&&e<t}function Ue(e){if(null!=e){try{return $.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function Ne(e,t){return e===t||e!=e&&t!=t}(ie&&Me(new ie(new ArrayBuffer(1)))!=k||ae&&Me(new ae)!=f||oe&&Me(oe.resolve())!=h||se&&Me(new se)!=y||ue&&Me(new ue)!=b)&&(Me=function(e){var t=Se(e),n=t==p?e.constructor:void 0,r=n?Ue(n):"";if(r)switch(r){case le:return k;case fe:return f;case de:return h;case pe:return y;case he:return b}return t});var Fe=Oe(function(){return arguments}())?Oe:function(e){return $e(e)&&K.call(e,"callee")&&!X.call(e,"callee")},De=Array.isArray;var qe=ne||function(){return!1};function Be(e){if(!We(e))return!1;var t=Se(e);return t==l||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}function ze(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=i}function We(e){var t=Xu(e);return null!=e&&("object"==t||"function"==t)}function $e(e){return null!=e&&"object"==Xu(e)}var Ke=j?function(e){return function(t){return e(t)}}(j):function(e){return $e(e)&&ze(e.length)&&!!S[Se(e)]};function He(e){return null!=(t=e)&&ze(t.length)&&!Be(t)?xe(e):Re(e);var t}e.exports=function(e,t){return Ee(e,t)}}(Bx,Bx.exports);var zx=Bx.exports;function Wx(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}var $x=dy.scope("User"),User=function(e){Qu(User,e);var t,n,r,i,a,o,s,u=Wx(User);function User(e,t,n,r){var i;return rc(this,User),ic(Yu(i=u.call(this)),"links",void 0),ic(Yu(i),"configuration",void 0),ic(Yu(i),"services",void 0),ic(Yu(i),"entity",void 0),ic(Yu(i),"state",void 0),ic(Yu(i),"promiseToFetch",null),ic(Yu(i),"subscribed",void 0),ic(Yu(i),"_initializationPromise",void 0),ic(Yu(i),"_resolveInitializationPromise",void 0),ic(Yu(i),"updated","updated"),ic(Yu(i),"userSubscribed","userSubscribed"),ic(Yu(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 nc(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:(s=Vu(lh.mark((function e(t,n){var r,i;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:r=[],$x.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=Ab(n.value,"Retrieved malformed attributes from the server for user: ".concat(this.state.identity),$x),zx(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 s.apply(this,arguments)})},{key:"_updateReachabilityInfo",value:(o=Vu(lh.mark((function e(t,n){var r=this;return lh.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){$x.warn("Failed to get reachability info for ",r.state.identity,e)})));case 5:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"_fetch",value:(a=Vu(lh.mark((function e(){var t=this;return lh.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 $x.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 $x.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=Vu(lh.mark((function e(){return lh.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=Vu(lh.mark((function e(t){return lh.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=Vu(lh.mark((function e(t){return lh.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=Vu(lh.mark((function e(){return lh.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(encodeURIComponent(this.identity))},this._resolveInitializationPromise(),r&&this.emit("updated",{user:this,updateReasons:["friendlyName","attributes","reachabilityOnline","reachabilityNotifiable"]})}}]),User}(qx);function Kx(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 Hx(e,t){if(e){if("string"==typeof e)return Kx(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)?Kx(e,t):void 0}}function Gx(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=[],o=!0,s=!1;try{for(n=n.call(e);!(o=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);o=!0);}catch(e){s=!0,i=e}finally{try{o||null==n.return||n.return()}finally{if(s)throw i}}return a}}(e,t)||Hx(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.")}()}dh([tx(nx),ph("design:type",Function),ph("design:paramtypes",[Object]),ph("design:returntype",Promise)],User.prototype,"updateAttributes",null),dh([tx(["string"]),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],User.prototype,"updateFriendlyName",null);var Vx={exports:{}},Yx=o((function(){if("function"==typeof ArrayBuffer){var e=new ArrayBuffer(8);Object.isExtensible(e)&&Object.defineProperty(e,"a",{value:8})}})),Jx=o,Qx=Y,Xx=T,Zx=Yx,e_=Object.isExtensible,t_=Jx((function(){e_(1)}))||Zx?function(e){return!!Qx(e)&&((!Zx||"ArrayBuffer"!=Xx(e))&&(!e_||e_(e)))}:e_,n_=!o((function(){return Object.isExtensible(Object.preventExtensions({}))})),r_=ni,i_=C,a_=kn,o_=Y,s_=$e,u_=jt.f,c_=Zn,l_=Wa,f_=t_,d_=n_,p_=!1,h_=Ye("meta"),v_=0,y_=function(e){u_(e,h_,{value:{objectID:"O"+v_++,weakData:{}}})},m_=Vx.exports={enable:function(){m_.enable=function(){},p_=!0;var e=c_.f,t=i_([].splice),n={};n[h_]=1,e(n).length&&(c_.f=function(n){for(var r=e(n),i=0,a=r.length;i<a;i++)if(r[i]===h_){t(r,i,1);break}return r},r_({target:"Object",stat:!0,forced:!0},{getOwnPropertyNames:l_.f}))},fastKey:function(e,t){if(!o_(e))return"symbol"==typeof e?e:("string"==typeof e?"S":"P")+e;if(!s_(e,h_)){if(!f_(e))return"F";if(!t)return"E";y_(e)}return e[h_].objectID},getWeakData:function(e,t){if(!s_(e,h_)){if(!f_(e))return!0;if(!t)return!1;y_(e)}return e[h_].weakData},onFreeze:function(e){return d_&&p_&&f_(e)&&!s_(e,h_)&&y_(e),e}};a_[h_]=!0;var g_=ni,b_=i,w_=C,k_=Vr,x_=Xn,__=Vx.exports,S_=Nd,O_=Ec,E_=H,T_=U,R_=Y,I_=o,C_=zd,P_=oi,A_=rm,j_=function(e,t,n){var r=-1!==e.indexOf("Map"),i=-1!==e.indexOf("Weak"),a=r?"set":"add",o=b_[e],s=o&&o.prototype,u=o,c={},l=function(e){var t=w_(s[e]);x_(s,e,"add"==e?function(e){return t(this,0===e?0:e),this}:"delete"==e?function(e){return!(i&&!R_(e))&&t(this,0===e?0:e)}:"get"==e?function(e){return i&&!R_(e)?void 0:t(this,0===e?0:e)}:"has"==e?function(e){return!(i&&!R_(e))&&t(this,0===e?0:e)}:function(e,n){return t(this,0===e?0:e,n),this})};if(k_(e,!E_(o)||!(i||s.forEach&&!I_((function(){(new o).entries().next()})))))u=n.getConstructor(t,e,r,a),__.enable();else if(k_(e,!0)){var f=new u,d=f[a](i?{}:-0,1)!=f,p=I_((function(){f.has(1)})),h=C_((function(e){new o(e)})),v=!i&&I_((function(){for(var e=new o,t=5;t--;)e[a](t,t);return!e.has(-0)}));h||((u=t((function(e,t){O_(e,s);var n=A_(new o,e,u);return T_(t)||S_(t,n[a],{that:n,AS_ENTRIES:r}),n}))).prototype=s,s.constructor=u),(p||v)&&(l("delete"),l("has"),r&&l("get")),(v||d)&&l(a),i&&s.clear&&delete s.clear}return c[e]=u,g_({global:!0,constructor:!0,forced:u!=o},c),P_(u,e),i||n.setStrong(u,e,r),u},M_=Xn,L_=function(e,t,n){for(var r in t)M_(e,r,t[r],n);return e},U_=jt.f,N_=_a,F_=L_,D_=wo,q_=Ec,B_=U,z_=Nd,W_=Vv,$_=Yv,K_=_c,H_=s,G_=Vx.exports.fastKey,V_=Ln.set,Y_=Ln.getterFor,J_={getConstructor:function(e,t,n,r){var i=e((function(e,i){q_(e,a),V_(e,{type:t,index:N_(null),first:void 0,last:void 0,size:0}),H_||(e.size=0),B_(i)||z_(i,e[r],{that:e,AS_ENTRIES:n})})),a=i.prototype,o=Y_(t),s=function(e,t,n){var r,i,a=o(e),s=u(e,t);return s?s.value=n:(a.last=s={index:i=G_(t,!0),key:t,value:n,previous:r=a.last,next:void 0,removed:!1},a.first||(a.first=s),r&&(r.next=s),H_?a.size++:e.size++,"F"!==i&&(a.index[i]=s)),e},u=function(e,t){var n,r=o(e),i=G_(t);if("F"!==i)return r.index[i];for(n=r.first;n;n=n.next)if(n.key==t)return n};return F_(a,{clear:function(){for(var e=o(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,H_?e.size=0:this.size=0},delete:function(e){var t=this,n=o(t),r=u(t,e);if(r){var i=r.next,a=r.previous;delete n.index[r.index],r.removed=!0,a&&(a.next=i),i&&(i.previous=a),n.first==r&&(n.first=i),n.last==r&&(n.last=a),H_?n.size--:t.size--}return!!r},forEach:function(e){for(var t,n=o(this),r=D_(e,arguments.length>1?arguments[1]:void 0);t=t?t.next:n.first;)for(r(t.value,t.key,this);t&&t.removed;)t=t.previous},has:function(e){return!!u(this,e)}}),F_(a,n?{get:function(e){var t=u(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)}}),H_&&U_(a,"size",{get:function(){return o(this).size}}),i},setStrong:function(e,t,n){var r=t+" Iterator",i=Y_(t),a=Y_(r);W_(e,t,(function(e,t){V_(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?n.key:"values"==t?n.value:[n.key,n.value],!1):(e.target=void 0,$_(void 0,!0))}),n?"entries":"values",!n,!0),K_(t)}};j_("Map",(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),J_);var Q_={};Object.defineProperty(Q_,"__esModule",{value:!0});var X_=Ww.exports,Z_=Vw.exports,eS=Kw.exports,tS=Gw.exports,nS=Yw.exports,rS=sx.exports;function iS(e){return e&&"object"===Xu(e)&&"default"in e?e:{default:e}}var aS=iS($w.exports),oS=iS(X_),sS=iS(Z_),uS=iS(eS),cS=iS(tS),lS=iS(nS),fS=iS(rS);function dS(){}function pS(){pS.init.call(this)}function hS(e){return void 0===e._maxListeners?pS.defaultMaxListeners:e._maxListeners}function vS(e,t,n){if(t)e.call(n);else for(var r=e.length,i=_S(e,r),a=0;a<r;++a)i[a].call(n)}function yS(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=_S(e,i),o=0;o<i;++o)a[o].call(n,r)}function mS(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,o=_S(e,a),s=0;s<a;++s)o[s].call(n,r,i)}function gS(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var o=e.length,s=_S(e,o),u=0;u<o;++u)s[u].call(n,r,i,a)}function bS(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=_S(e,i),o=0;o<i;++o)a[o].apply(n,r)}function wS(e,t,n,r){var i,a,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),o=a[t]):(a=e._events=new dS,e._eventsCount=0),o){if("function"==typeof o?o=a[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),!o.warned&&(i=hS(e))&&i>0&&o.length>i){o.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=e,s.type=t,s.count=o.length,function(e){"function"==typeof console.warn?console.warn(e):console.log(e)}(s)}}else o=a[t]=n,++e._eventsCount;return e}function kS(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 xS(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 _S(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function SS(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=lS.default(e);if(t){var i=lS.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return cS.default(this,n)}}dS.prototype=Object.create(null),pS.EventEmitter=pS,pS.usingDomains=!1,pS.prototype.domain=void 0,pS.prototype._events=void 0,pS.prototype._maxListeners=void 0,pS.defaultMaxListeners=10,pS.init=function(){this.domain=null,pS.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new dS,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},pS.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},pS.prototype.getMaxListeners=function(){return hS(this)},pS.prototype.emit=function(e){var t,n,r,i,a,o,s,u="error"===e;if(o=this._events)u=u&&null==o.error;else if(!u)return!1;if(s=this.domain,u){if(t=arguments[1],!s){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=s,t.domainThrown=!1,s.emit("error",t),!1}if(!(n=o[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:vS(n,l,this);break;case 2:yS(n,l,this,arguments[1]);break;case 3:mS(n,l,this,arguments[1],arguments[2]);break;case 4:gS(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];bS(n,l,this,i)}return!0},pS.prototype.addListener=function(e,t){return wS(this,e,t,!1)},pS.prototype.on=pS.prototype.addListener,pS.prototype.prependListener=function(e,t){return wS(this,e,t,!0)},pS.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,kS(this,e,t)),this},pS.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,kS(this,e,t)),this},pS.prototype.removeListener=function(e,t){var n,r,i,a,o;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 dS:(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){o=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 dS,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,o||t)}return this},pS.prototype.off=function(e,t){return this.removeListener(e,t)},pS.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new dS,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new dS: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 dS,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},pS.prototype.listeners=function(e){var t,n,r=this._events;return n=r&&(t=r[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):[],n},pS.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):xS.call(e,t)},pS.prototype.listenerCount=xS,pS.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var OS=function(e){uS.default(n,e);var t=SS(n);function n(e){var r;return aS.default(this,n),r=t.call(this),fS.default(sS.default(r),"minDelay",void 0),fS.default(sS.default(r),"maxDelay",void 0),fS.default(sS.default(r),"initialDelay",void 0),fS.default(sS.default(r),"maxAttemptsCount",void 0),fS.default(sS.default(r),"maxAttemptsTime",void 0),fS.default(sS.default(r),"randomness",void 0),fS.default(sS.default(r),"prevDelay",void 0),fS.default(sS.default(r),"currDelay",void 0),fS.default(sS.default(r),"timeout",null),fS.default(sS.default(r),"inProgress",void 0),fS.default(sS.default(r),"attemptNum",void 0),fS.default(sS.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 oS.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}(pS),ES=function(e){uS.default(n,e);var t=SS(n);function n(e){var r;return aS.default(this,n),r=t.call(this),fS.default(sS.default(r),"retrier",void 0),fS.default(sS.default(r),"resolve",(function(){})),fS.default(sS.default(r),"reject",(function(){})),r.retrier=new OS(e),r}return oS.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}(pS);function TS(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=lS.default(e);if(t){var i=lS.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return cS.default(this,n)}}function RS(e){return null!=e}var IS=function(e){uS.default(n,e);var t=TS(n);function n(e){var r;aS.default(this,n),r=t.call(this),fS.default(sS.default(r),"maxDelay",void 0),fS.default(sS.default(r),"initialDelay",void 0),fS.default(sS.default(r),"factor",void 0),fS.default(sS.default(r),"randomisationFactor",void 0),fS.default(sS.default(r),"backoffDelay",0),fS.default(sS.default(r),"nextBackoffDelay",0),fS.default(sS.default(r),"backoffNumber",0),fS.default(sS.default(r),"timeoutID",null),fS.default(sS.default(r),"maxNumberOfRetry",-1);var i=e=e||{},a=i.initialDelay,o=i.maxDelay,s=i.randomisationFactor,u=i.factor;if(RS(a)&&a<1)throw new Error("The initial timeout must be equal to or greater than 1.");if(RS(o)&&o<=1)throw new Error("The maximal timeout must be greater than 1.");if(RS(s)&&(s<0||s>1))throw new Error("The randomisation factor must be between 0 and 1.");if(RS(u)&&u<=1)throw new Error("Exponential factor should be greater than 1.");if(r.initialDelay=a||100,r.maxDelay=o||1e4,r.maxDelay<=r.initialDelay)throw new Error("The maximal backoff delay must be greater than the initial backoff delay.");return r.randomisationFactor=s||0,r.factor=u||2,r.reset(),r}return oS.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}(pS),CS=Q_.AsyncRetrier=ES;Q_.Backoff=IS;var PS=Q_.Retrier=OS;function AS(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 jS(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 jS(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function jS(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 MS=function(){function e(t,n){rc(this,e),ic(this,"configuration",void 0),ic(this,"services",void 0),ic(this,"cacheLifetime",void 0),ic(this,"cache",void 0),ic(this,"timer",void 0),this.configuration=t,this.services=n,this.cache=new Map,this.cacheLifetime=100*this.configuration.httpCacheInterval,this.cleanupCache()}return nc(e,[{key:"isExpired",value:function(e){return!this.cacheLifetime||Date.now()-e>this.cacheLifetime}},{key:"cleanupCache",value:function(){var e,t=AS(this.cache);try{for(t.s();!(e=t.n()).done;){var n=Gx(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;return new Promise((function(n,r){var i=new PS(t.configuration.backoffConfiguration);i.on("attempt",(function(){e().then((function(e){if(e.statusCode>=400&&e.statusCode<500){var t=JSON.parse(e.payload);i.failed(new Error("".concat(t.message)))}else i.succeeded(e)})).catch((function(e){i.removeAllListeners(),i.cancel(),r(e)}))})),i.on("succeeded",(function(e){n(e)})),i.on("cancelled",(function(e){return r(e)})),i.on("failed",(function(e){return r(e)})),i.start()}))}},{key:"get",value:function(){var e=Vu(lh.mark((function e(t){var n,r,i=this;return lh.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 e.next=5,this.executeWithRetry((function(){return i.services.transport.get({url:t,grant:i.configuration.productId})}),this.configuration.retryWhenThrottled);case 5:return r=e.sent,this.cache.set(t,{response:r,timestamp:Date.now()}),this.pokeTimer(),e.abrupt("return",r);case 9:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()}]),e}(),LS=nc((function e(){rc(this,e)}));ic(LS,"TYPING_INDICATOR","twilio.ipmsg.typing_indicator"),ic(LS,"NEW_MESSAGE","twilio.conversations.new_message"),ic(LS,"ADDED_TO_CONVERSATION","twilio.conversations.added_to_conversation"),ic(LS,"REMOVED_FROM_CONVERSATION","twilio.conversations.removed_from_conversation"),ic(LS,"CONSUMPTION_UPDATE","twilio.channel.consumption_update");var US={},NS={exports:{}},FS={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.__esModule=!0,e.exports.default=e.exports}(FS),function(e){var t=Hw.exports,n=FS.exports;function r(i,a,o){return n()?(e.exports=r=Reflect.construct.bind(),e.exports.__esModule=!0,e.exports.default=e.exports):(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.__esModule=!0,e.exports.default=e.exports),r.apply(null,arguments)}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}(NS);var DS={exports:{}};!function(e){function t(e,t,n,r,i,a,o){try{var s=e[a](o),u=s.value}catch(e){return void n(e)}s.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 o=e.apply(n,r);function s(e){t(o,i,a,s,u,"next",e)}function u(e){t(o,i,a,s,u,"throw",e)}s(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports}(DS);var qS=n(fh),BS={},zS={exports:{}},WS={exports:{}};!function(e){e.exports=function(e){return-1!==Function.toString.call(e).indexOf("[native code]")},e.exports.__esModule=!0,e.exports.default=e.exports}(WS),function(e){var t=Yw.exports,n=Hw.exports,r=WS.exports,i=NS.exports;function a(o){var s="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!==s){if(s.has(e))return s.get(e);s.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.__esModule=!0,e.exports.default=e.exports,a(o)}e.exports=a,e.exports.__esModule=!0,e.exports.default=e.exports}(zS);var $S=function(e){return crypto.getRandomValues(new Uint8Array(e))},KS=function(e,t,n){var r=(2<<Math.log(e.length-1)/Math.LN2)-1,i=-~(1.6*r*t/e.length);return function(){for(var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t,o="";;)for(var s=n(i),u=i;u--;)if((o+=e[s[u]&r]||"").length===a)return o}},HS=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:21;return crypto.getRandomValues(new Uint8Array(e)).reduce((function(e,t){return e+=(t&=63)<36?t.toString(36):t<62?(t-26).toString(36).toUpperCase():t>62?"-":"_"}),"")},GS=Object.freeze({__proto__:null,nanoid:HS,customAlphabet:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:21;return KS(e,t,$S)},customRandom:KS,urlAlphabet:"useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",random:$S}),VS=n(GS),YS=ni,JS=n_,QS=o,XS=Y,ZS=Vx.exports.onFreeze,eO=Object.freeze;YS({target:"Object",stat:!0,forced:QS((function(){eO(1)})),sham:!JS},{freeze:function(e){return eO&&XS(e)?eO(ZS(e)):e}}),Object.defineProperty(BS,"__esModule",{value:!0});var tO=sy.exports,nO=Vw.exports,rO=sx.exports,iO=Ww.exports,aO=$w.exports,oO=Kw.exports,sO=Gw.exports,uO=Yw.exports,cO=zS.exports,lO=VS,fO=Dw.exports;function dO(e){return e&&"object"===Xu(e)&&"default"in e?e:{default:e}}var pO=dO(tO),hO=dO(nO),vO=dO(rO),yO=dO(iO),mO=dO(aO),gO=dO(oO),bO=dO(sO),wO=dO(uO),kO=dO(cO),xO=dO(fO),_O=function(e){var t=pO.default.getLevel();pO.default.setLevel("warn"),pO.default.warn(e),pO.default.setLevel(t)};function SO(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=wO.default(e);if(t){var i=wO.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return bO.default(this,n)}}var OO=function(e){gO.default(n,e);var t=SO(n);function n(){return mO.default(this,n),t.call(this,"Promise was cancelled")}return yO.default(n)}(kO.default(Error)),EO=function(e){gO.default(n,e);var t=SO(n);function n(e){var r;mO.default(this,n);var i,a=lO.nanoid();return r=t.call(this,(function(t,r){return i=r,e((function(e){n.onCancelCallbackMap.delete(a),t(e)}),(function(e){n.onCancelCallbackMap.delete(a),r(e)}),(function(e){n.onCancelCallbackMap.set(a,e)}))})),vO.default(hO.default(r),"id",void 0),vO.default(hO.default(r),"rejectPromise",void 0),r.id=a,r.rejectPromise=i,r}return yO.default(n,[{key:"cancel",value:function(){var e=n.onCancelCallbackMap.get(this.id);return null==e||e(),this.rejectPromise&&(this.catch((function(){})),this.rejectPromise(new OO)),this}}]),n}(kO.default(Promise));function TO(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=wO.default(e);if(t){var i=wO.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return bO.default(this,n)}}vO.default(EO,"onCancelCallbackMap",new Map);var RO={unknown:"Unknown error",cancelled:"Job was cancelled",timeout:"Timeout occurred",mediaUploadError:"Media upload error",mediaFetchError:"Media fetch error",tooManyAttachments:"Too many attachments",unsupportedEmailBodyContentType:"Unsupported email body content type",unsupportedEmailHistoryContentType:"Unsupported email history content type",transportDisconnected:"Transport has been disconnected",networkBecameUnreachable:"Network became unreachable",unauthorized:"Unauthorized",tokenExpired:"Token expired",tokenUpdatedLocally:"Transport disconnected, token updated locally and will be used at reconnect",tooManyRequests:"Request failed with 429 reply",hostnameUnverified:"Failed on ssl handshake: CERTIFICATE_VERIFY_FAILED",sslHandshakeError:"Failed on ssl handshake: UNAUTHORIZED",closeMessageReceived:"Twilsock received a close message from the server",cannotParse:"Error while parsing an incoming message"},IO=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;mO.default(this,e),vO.default(this,"reason",void 0),vO.default(this,"message",void 0),vO.default(this,"status",void 0),vO.default(this,"code",void 0),vO.default(this,"description",void 0),this.reason=t,this.message=n,this.status=r,this.code=i,this.description=RO[t]}return yO.default(e,[{key:"toString",value:function(){return"".concat(this.description," ").concat(this.status,":").concat(this.code," ").concat(this.message)}}]),e}(),CO=function(e){gO.default(n,e);var t=TO(n);function n(e){var r;return mO.default(this,n),r=t.call(this,"".concat(e)),vO.default(hO.default(r),"errorInfo",void 0),r.errorInfo=e,Object.freeze(e),r}return yO.default(n)}(kO.default(Error)),PO=function(){function e(){var t=this;mO.default(this,e),vO.default(this,"promise",void 0),vO.default(this,"_resolve",void 0),vO.default(this,"_reject",void 0),vO.default(this,"_isDone",!1),this.promise=new Promise((function(e,n){t._resolve=function(n){t._isDone=!0,e(n)},t._reject=function(e){t._isDone=!0,n(e)}}))}return yO.default(e,[{key:"resolve",get:function(){return this._resolve}},{key:"reject",get:function(){return this._reject}},{key:"isDone",get:function(){return this._isDone}}]),e}(),AO=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";mO.default(this,e),vO.default(this,"_prefix",void 0),vO.default(this,"_logger",void 0),this._prefix=n,this._logger=tO.getLogger(t)}return yO.default(e,[{key:"setLevel",value:function(e){this._logger.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this._logger.trace.apply(null,this._prepareLine("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this._logger.debug.apply(null,this._prepareLine("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this._logger.info.apply(null,this._prepareLine("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this._logger.warn.apply(null,this._prepareLine("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];this._logger.error.apply(null,this._prepareLine("E",t))}},{key:"_prepareLine",value:function(e,t){return["".concat((new Date).toISOString()," ").concat(this._prefix," ").concat(e,":")].concat(xO.default(t))}}]),e}();BS.CancellablePromise=EO,BS.CancellationError=OO,BS.Deferred=PO,BS.ErrorInfo=IO,BS.Logger=AO,BS.TwilioError=CO,BS.deprecated=function(e,t,n){return function(r,i,a){if("function"!=typeof a.value&&void 0===(null==a?void 0:a.get))throw new Error("The deprecated decorator can only be applied to methods or getters");if("function"!=typeof a.value){var o=a.get;a.get=function(){return _O("The getter ".concat(e," is deprecated").concat(t?", use "+t+" instead":"").concat(n?", "+n:".")),null==o?void 0:o.apply(this)}}else{var s=a.value;a.value=function(){_O("The method ".concat(e," is deprecated").concat(t?", use "+t+" instead":"").concat(n?", "+n:"."));for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];return s.apply(this,i)}}}},BS.deprecationWarning=_O;var jO="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,MO=ir,LO=fr,UO=RangeError,NO=function(e){if(void 0===e)return 0;var t=MO(e),n=LO(t);if(t!==n)throw UO("Wrong length or index");return n},FO=Array,DO=Math.abs,qO=Math.pow,BO=Math.floor,zO=Math.log,WO=Math.LN2,$O={pack:function(e,t,n){var r,i,a,o=FO(n),s=8*n-t-1,u=(1<<s)-1,c=u>>1,l=23===t?qO(2,-24)-qO(2,-77):0,f=e<0||0===e&&1/e<0?1:0,d=0;for((e=DO(e))!=e||e===1/0?(i=e!=e?1:0,r=u):(r=BO(zO(e)/WO),e*(a=qO(2,-r))<1&&(r--,a*=2),(e+=r+c>=1?l/a:l*qO(2,1-c))*a>=2&&(r++,a/=2),r+c>=u?(i=0,r=u):r+c>=1?(i=(e*a-1)*qO(2,t),r+=c):(i=e*qO(2,c-1)*qO(2,t),r=0));t>=8;)o[d++]=255&i,i/=256,t-=8;for(r=r<<t|i,s+=t;s>0;)o[d++]=255&r,r/=256,s-=8;return o[--d]|=128*f,o},unpack:function(e,t){var n,r=e.length,i=8*r-t-1,a=(1<<i)-1,o=a>>1,s=i-7,u=r-1,c=e[u--],l=127&c;for(c>>=7;s>0;)l=256*l+e[u--],s-=8;for(n=l&(1<<-s)-1,l>>=-s,s+=t;s>0;)n=256*n+e[u--],s-=8;if(0===l)l=1-o;else{if(l===a)return n?NaN:c?-1/0:1/0;n+=qO(2,t),l-=o}return(c?-1:1)*n*qO(2,l-t)}},KO=Be,HO=ur,GO=pr,VO=function(e){for(var t=KO(this),n=GO(t),r=arguments.length,i=HO(r>1?arguments[1]:void 0,n),a=r>2?arguments[2]:void 0,o=void 0===a?n:HO(a,n);o>i;)t[i++]=e;return t},YO=i,JO=C,QO=s,XO=jO,ZO=on,eE=Xt,tE=L_,nE=o,rE=Ec,iE=ir,aE=fr,oE=NO,sE=$O,uE=dv,cE=gc,lE=Zn.f,fE=jt.f,dE=VO,pE=Za,hE=oi,vE=ZO.PROPER,yE=ZO.CONFIGURABLE,mE=Ln.get,gE=Ln.set,bE="ArrayBuffer",wE="DataView",kE="Wrong index",xE=YO.ArrayBuffer,_E=xE,SE=_E&&_E.prototype,OE=YO.DataView,EE=OE&&OE.prototype,TE=Object.prototype,RE=YO.Array,IE=YO.RangeError,CE=JO(dE),PE=JO([].reverse),AE=sE.pack,jE=sE.unpack,ME=function(e){return[255&e]},LE=function(e){return[255&e,e>>8&255]},UE=function(e){return[255&e,e>>8&255,e>>16&255,e>>24&255]},NE=function(e){return e[3]<<24|e[2]<<16|e[1]<<8|e[0]},FE=function(e){return AE(e,23,4)},DE=function(e){return AE(e,52,8)},qE=function(e,t){fE(e.prototype,t,{get:function(){return mE(this)[t]}})},BE=function(e,t,n,r){var i=oE(n),a=mE(e);if(i+t>a.byteLength)throw IE(kE);var o=mE(a.buffer).bytes,s=i+a.byteOffset,u=pE(o,s,s+t);return r?u:PE(u)},zE=function(e,t,n,r,i,a){var o=oE(n),s=mE(e);if(o+t>s.byteLength)throw IE(kE);for(var u=mE(s.buffer).bytes,c=o+s.byteOffset,l=r(+i),f=0;f<t;f++)u[c+f]=l[a?f:t-f-1]};if(XO){var WE=vE&&xE.name!==bE;if(nE((function(){xE(1)}))&&nE((function(){new xE(-1)}))&&!nE((function(){return new xE,new xE(1.5),new xE(NaN),1!=xE.length||WE&&!yE})))WE&&yE&&eE(xE,"name",bE);else{(_E=function(e){return rE(this,SE),new xE(oE(e))}).prototype=SE;for(var $E,KE=lE(xE),HE=0;KE.length>HE;)($E=KE[HE++])in _E||eE(_E,$E,xE[$E]);SE.constructor=_E}cE&&uE(EE)!==TE&&cE(EE,TE);var GE=new OE(new _E(2)),VE=JO(EE.setInt8);GE.setInt8(0,2147483648),GE.setInt8(1,2147483649),!GE.getInt8(0)&&GE.getInt8(1)||tE(EE,{setInt8:function(e,t){VE(this,e,t<<24>>24)},setUint8:function(e,t){VE(this,e,t<<24>>24)}},{unsafe:!0})}else SE=(_E=function(e){rE(this,SE);var t=oE(e);gE(this,{bytes:CE(RE(t),0),byteLength:t}),QO||(this.byteLength=t)}).prototype,EE=(OE=function(e,t,n){rE(this,EE),rE(e,SE);var r=mE(e).byteLength,i=iE(t);if(i<0||i>r)throw IE("Wrong offset");if(i+(n=void 0===n?r-i:aE(n))>r)throw IE("Wrong length");gE(this,{buffer:e,byteLength:n,byteOffset:i}),QO||(this.buffer=e,this.byteLength=n,this.byteOffset=i)}).prototype,QO&&(qE(_E,"byteLength"),qE(OE,"buffer"),qE(OE,"byteLength"),qE(OE,"byteOffset")),tE(EE,{getInt8:function(e){return BE(this,1,e)[0]<<24>>24},getUint8:function(e){return BE(this,1,e)[0]},getInt16:function(e){var t=BE(this,2,e,arguments.length>1?arguments[1]:void 0);return(t[1]<<8|t[0])<<16>>16},getUint16:function(e){var t=BE(this,2,e,arguments.length>1?arguments[1]:void 0);return t[1]<<8|t[0]},getInt32:function(e){return NE(BE(this,4,e,arguments.length>1?arguments[1]:void 0))},getUint32:function(e){return NE(BE(this,4,e,arguments.length>1?arguments[1]:void 0))>>>0},getFloat32:function(e){return jE(BE(this,4,e,arguments.length>1?arguments[1]:void 0),23)},getFloat64:function(e){return jE(BE(this,8,e,arguments.length>1?arguments[1]:void 0),52)},setInt8:function(e,t){zE(this,1,e,ME,t)},setUint8:function(e,t){zE(this,1,e,ME,t)},setInt16:function(e,t){zE(this,2,e,LE,t,arguments.length>2?arguments[2]:void 0)},setUint16:function(e,t){zE(this,2,e,LE,t,arguments.length>2?arguments[2]:void 0)},setInt32:function(e,t){zE(this,4,e,UE,t,arguments.length>2?arguments[2]:void 0)},setUint32:function(e,t){zE(this,4,e,UE,t,arguments.length>2?arguments[2]:void 0)},setFloat32:function(e,t){zE(this,4,e,FE,t,arguments.length>2?arguments[2]:void 0)},setFloat64:function(e,t){zE(this,8,e,DE,t,arguments.length>2?arguments[2]:void 0)}});hE(_E,bE),hE(OE,wE);var YE={ArrayBuffer:_E,DataView:OE},JE=_c,QE="ArrayBuffer",XE=YE.ArrayBuffer;ni({global:!0,constructor:!0,forced:i.ArrayBuffer!==XE},{ArrayBuffer:XE}),JE(QE);var ZE={exports:{}};!function(e,n){(function(){var r={function:!0,object:!0}["undefined"==typeof window?"undefined":Xu(window)]&&window||this,i=n,a=e&&!e.nodeType&&e,o=i&&a&&"object"==Xu(t)&&t;!o||o.global!==o&&o.window!==o&&o.self!==o||(r=o);var s=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<=s)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"==Xu(t)&&"String"!=v(t);i&&(n=t,t=null);var a=n.navigator||{},o=a.userAgent||"";t||(t=o);var s,c,l=i?!!a.likeChrome:/\bChrome\b/.test(t)&&!/internal|\n/i.test(f.toString()),d="Object",b=i?d:"ScriptBridgingProxyObject",w=i?d:"Environment",k=i&&n.java?"JavaPackage":v(n.java),x=i?d:"RuntimeObject",_=/\bJava/.test(k)&&n.java,S=_&&v(n.environment)==w,O=_?"a":"α",E=_?"b":"β",T=n.document||{},R=n.operamini||n.opera,I=u.test(I=i&&R?R["[[Class]]"]:v(R))?I:R=null,C=t,P=[],A=null,j=t==o,M=j&&R&&"function"==typeof R.version&&R.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)})),U=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"]),N=q([{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"]),F=function(e){return m(e,(function(e,n,r){return e||(n[N]||n[/^[a-z]+(?: +[a-z]+\b)*/i.exec(N)]||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}}),D=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 q(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 B(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(D)&&!N&&(s=/\bAndroid[^;]*;(.*?)(?:Build|\) AppleWebKit)\b/i.exec(t))&&(N=g(s[1]).replace(/^[a-z]{2}-[a-z]{2};\s*/i,"")||null),F&&!N?N=q([F]):F&&N&&(N=N.replace(RegExp("^("+y(F)+")[-_.\\s]","i"),F+" ").replace(RegExp("^("+y(F)+")[-_.]?(\\w)","i"),F+" $2")),(s=/\bGoogle TV\b/.exec(N))&&(N=s[0]),/\bSimulator\b/i.test(t)&&(N=(N?N+" ":"")+"Simulator"),"Opera Mini"==U&&/\bOPiOS\b/.test(t)&&P.push("running in Turbo/Uncompressed mode"),"IE"==U&&/\blike iPhone OS\b/.test(t)?(F=(s=e(t.replace(/like iPhone OS/,""))).manufacturer,N=s.product):/^iP/.test(N)?(U||(U="Safari"),D="iOS"+((s=/ OS ([\d_]+)/i.exec(t))?" "+s[1].replace(/_/g,"."):"")):"Konqueror"==U&&/^Linux\b/i.test(D)?D="Kubuntu":F&&"Google"!=F&&(/Chrome/.test(U)&&!/\bMobile Safari\b/i.test(t)||/\bVita\b/.test(N))||/\bAndroid\b/.test(D)&&/^Chrome/.test(U)&&/\bVersion\//i.test(t)?(U="Android Browser",D=/\bAndroid\b/.test(D)?D:"Android"):"Silk"==U?(/\bMobi/i.test(t)||(D="Android",P.unshift("desktop mode")),/Accelerated *= *true/i.test(t)&&P.unshift("accelerated")):"UC Browser"==U&&/\bUCWEB\b/.test(t)?P.push("speed mode"):"PaleMoon"==U&&(s=/\bFirefox\/([\d.]+)\b/.exec(t))?P.push("identifying as Firefox "+s[1]):"Firefox"==U&&(s=/\b(Mobile|Tablet|TV)\b/i.exec(t))?(D||(D="Firefox OS"),N||(N=s[1])):!U||(s=!/\bMinefield\b/i.test(t)&&/\b(?:Firefox|Safari)\b/.exec(U))?(U&&!N&&/[\/,]|^[^(]+?\)/.test(t.slice(t.indexOf(s+"/")+8))&&(U=null),(s=N||F||D)&&(N||F||/\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(D))&&(U=/[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(D)?D:s)+" Browser")):"Electron"==U&&(s=(/\bChrome\/([\d.]+)\b/.exec(t)||0)[1])&&P.push("Chromium "+s),M||(M=B(["(?:Cloud9|CriOS|CrMo|Edge|Edg|EdgA|EdgiOS|FxiOS|HeadlessChrome|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$)|UCBrowser|YaBrowser)","Version",y(U),"(?:Firefox|Minefield|NetFront)"])),(s=("iCab"==L&&parseFloat(M)>3?"WebKit":/\bOpera\b/.test(U)&&(/\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"==D?"Tasman":"Trident")||"WebKit"==L&&/\bPlayStation\b(?! Vita\b)/i.test(U)&&"NetFront")&&(L=[s]),"IE"==U&&(s=(/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(t)||0)[1])?(U+=" Mobile",D="Windows Phone "+(/\+$/.test(s)?s:s+".x"),P.unshift("desktop mode")):/\bWPDesktop\b/i.test(t)?(U="IE Mobile",D="Windows Phone 8.x",P.unshift("desktop mode"),M||(M=(/\brv:([\d.]+)/.exec(t)||0)[1])):"IE"!=U&&"Trident"==L&&(s=/\brv:([\d.]+)/.exec(t))&&(U&&P.push("identifying as "+U+(M?" "+M:"")),U="IE",M=s[1]),j){if(function(e,t){var n=null!=e?Xu(e[t]):"number";return!(/^(?:boolean|number|string|undefined)$/.test(n)||"object"==n&&!e[t])}(n,"global"))if(_&&(C=(s=_.lang.System).getProperty("os.arch"),D=D||s.getProperty("os.name")+" "+s.getProperty("os.version")),S){try{M=n.require("ringo/engine").version.join("."),U="RingoJS"}catch(e){(s=n.system)&&s.global.system==n.system&&(U="Narwhal",D||(D=s[0].os||null))}U||(U="Rhino")}else"object"==Xu(n.process)&&!n.process.browser&&(s=n.process)&&("object"==Xu(s.versions)&&("string"==typeof s.versions.electron?(P.push("Node "+s.versions.node),U="Electron",M=s.versions.electron):"string"==typeof s.versions.nw&&(P.push("Chromium "+M,"Node "+s.versions.node),U="NW.js",M=s.versions.nw)),U||(U="Node.js",C=s.arch,D=s.platform,M=(M=/[\d.]+/.exec(s.version))?M[0]:null));else v(s=n.runtime)==b?(U="Adobe AIR",D=s.flash.system.Capabilities.os):v(s=n.phantom)==x?(U="PhantomJS",M=(s=s.version||null)&&s.major+"."+s.minor+"."+s.patch):"number"==typeof T.documentMode&&(s=/\bTrident\/(\d+)/i.exec(t))?(M=[M,T.documentMode],(s=+s[1]+4)!=M[1]&&(P.push("IE "+M[1]+" mode"),L&&(L[1]=""),M[1]=s),M="IE"==U?String(M[1].toFixed(1)):M[0]):"number"==typeof T.documentMode&&/^(?:Chrome|Firefox)\b/.test(U)&&(P.push("masking as "+U+" "+M),U="IE",M="11.0",L=["Trident"],D="Windows");D=D&&p(D)}if(M&&(s=/(?:[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(s)?"beta":"alpha",M=M.replace(RegExp(s+"\\+?$"),"")+("beta"==A?E:O)+(/\d+\+?/.exec(s)||"")),"Fennec"==U||"Firefox"==U&&/\b(?:Android|Firefox OS|KaiOS)\b/.test(D))U="Firefox Mobile";else if("Maxthon"==U&&M)M=M.replace(/\.[\d.]+/,".x");else if(/\bXbox\b/i.test(N))"Xbox 360"==N&&(D=null),"Xbox 360"==N&&/\bIEMobile\b/.test(t)&&P.unshift("mobile mode");else if(!/^(?:Chrome|IE|Opera)$/.test(U)&&(!U||N||/Browser|Mobi/.test(U))||"Windows CE"!=D&&!/Mobi/i.test(t))if("IE"==U&&j)try{null===n.external&&P.unshift("platform preview")}catch(e){P.unshift("embedded")}else(/\bBlackBerry\b/.test(N)||/\bBB10\b/.test(t))&&(s=(RegExp(N.replace(/ +/g," *")+"/([.\\d]+)","i").exec(t)||0)[1]||M)?(D=((s=[s,/BB10/.test(t)])[1]?(N=null,F="BlackBerry"):"Device Software")+" "+s[0],M=null):this!=h&&"Wii"!=N&&(j&&R||/Opera/.test(U)&&/\b(?:MSIE|Firefox)\b/i.test(t)||"Firefox"==U&&/\bOS X (?:\d+\.){2,}/.test(D)||"IE"==U&&(D&&!/^Win/.test(D)&&M>5.5||/\bWindows XP\b/.test(D)&&M>8||8==M&&!/\bTrident\b/.test(t)))&&!u.test(s=e.call(h,t.replace(u,"")+";"))&&s.name&&(s="ing as "+s.name+((s=s.version)?" "+s:""),u.test(U)?(/\bIE\b/.test(s)&&"Mac OS"==D&&(D=null),s="identify"+s):(s="mask"+s,U=I?p(I.replace(/([a-z])([A-Z])/g,"$1 $2")):"Opera",/\bIE\b/.test(s)&&(D=null),j||(M=null)),L=["Presto"],P.push(s));else U+=" Mobile";(s=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(t)||0)[1])&&(s=[parseFloat(s.replace(/\.(\d)$/,".0$1")),s],"Safari"==U&&"+"==s[1].slice(-1)?(U="WebKit Nightly",A="alpha",M=s[1].slice(0,-1)):M!=s[1]&&M!=(s[2]=(/\bSafari\/([\d.]+\+?)/i.exec(t)||0)[1])||(M=null),s[1]=(/\b(?:Headless)?Chrome\/([\d.]+)/i.exec(t)||0)[1],537.36==s[0]&&537.36==s[2]&&parseFloat(s[1])>=28&&"WebKit"==L&&(L=["Blink"]),j&&(l||s[1])?(L&&(L[1]="like Chrome"),s=s[1]||((s=s[0])<530?1:s<532?2:s<532.05?3:s<533?4:s<534.03?5:s<534.07?6:s<534.1?7:s<534.13?8:s<534.16?9:s<534.24?10:s<534.3?11:s<535.01?12:s<535.02?"13+":s<535.07?15:s<535.11?16:s<535.19?17:s<536.05?18:s<536.1?19:s<537.01?20:s<537.11?"21+":s<537.13?23:s<537.18?24:s<537.24?25:s<537.36?26:"Blink"!=L?"27":"28")):(L&&(L[1]="like Safari"),s=(s=s[0])<400?1:s<500?2:s<526?3:s<533?4:s<534?"4+":s<535?5:s<537?6:s<538?7:s<601?8:s<602?9:s<604?10:s<606?11:s<608?12:"12"),L&&(L[1]+=" "+(s+="number"==typeof s?".x":/[.+]/.test(s)?"":"+")),"Safari"==U&&(!M||parseInt(M)>45)?M=s:"Chrome"==U&&/\bHeadlessChrome/i.test(t)&&P.unshift("headless")),"Opera"==U&&(s=/\bzbov|zvav$/.exec(D))?(U+=" ",P.unshift("desktop mode"),"zvav"==s?(U+="Mini",M=null):U+="Mobile",D=D.replace(RegExp(" *"+s+"$"),"")):"Safari"==U&&/\bChrome\b/.exec(L&&L[1])?(P.unshift("desktop mode"),U="Chrome Mobile",M=null,/\bOS X\b/.test(D)?(F="Apple",D="iOS 4.3+"):D=null):/\bSRWare Iron\b/.test(U)&&!M&&(M=B("Chrome")),M&&0==M.indexOf(s=/[\d.]+$/.exec(D))&&t.indexOf("/"+s+"-")>-1&&(D=g(D.replace(s,""))),D&&-1!=D.indexOf(U)&&!RegExp(U+" OS").test(D)&&(D=D.replace(RegExp(" *"+y(U)+" *"),"")),L&&!/\b(?:Avant|Nook)\b/.test(U)&&(/Browser|Lunascape|Maxthon/.test(U)||"Safari"!=U&&/^iOS/.test(D)&&/\bSafari\b/.test(L[1])||/^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|SRWare Iron|Vivaldi|Web)/.test(U)&&L[1])&&(s=L[L.length-1])&&P.push(s),P.length&&(P=["("+P.join("; ")+")"]),F&&N&&N.indexOf(F)<0&&P.push("on "+F),N&&P.push((/^on /.test(P[P.length-1])?"":"on ")+N),D&&(s=/ ([\d.+]+)$/.exec(D),c=s&&"/"==D.charAt(D.length-s[0].length-1),D={architecture:32,family:s&&!c?D.replace(s[0],""):D,version:s?s[1]:null,toString:function(){var e=this.version;return this.family+(e&&!c?" "+e:"")+(64==this.architecture?" 64-bit":"")}}),(s=/\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(C))&&!/\bi686\b/i.test(C)?(D&&(D.architecture=64,D.family=D.family.replace(RegExp(" *"+s),"")),U&&(/\bWOW64\b/i.test(t)||j&&/\w(?:86|32)$/.test(a.cpuClass||a.platform)&&!/\bWin64; x64\b/i.test(t))&&P.unshift("32-bit")):D&&/^OS X/.test(D.family)&&"Chrome"==U&&parseFloat(M)>=39&&(D.architecture=64),t||(t=null);var z={};return z.description=t,z.layout=L&&L[0],z.manufacturer=F,z.name=U,z.prerelease=A,z.product=N,z.ua=t,z.version=U&&M,z.os=D||{architecture:null,family:null,version:null,toString:function(){return"null"}},z.parse=e,z.toString=function(){return this.description||""},z.version&&P.unshift(M),z.name&&P.unshift(U),D&&U&&(D!=String(D).split(" ")[0]||D!=U.split(" ")[0]&&!N)&&P.push(N?"("+D+")":"on "+D),P.length&&(z.description=P.join(" ")),z}();i&&a?h(b,(function(e,t){i[t]=e})):r.platform=b}).call(t)}(ZE,ZE.exports);var eT={},tT=Symbol("@ts-pattern/matcher"),nT="@ts-pattern/anonymous-select-key",rT=function(e){return Boolean(e&&"object"==Xu(e))},iT=function(e){return e&&!!e[tT]},aT=function e(t,n,r){if(rT(t)){if(iT(t)){var i=t[tT]().match(n),a=i.matched,o=i.selections;return a&&o&&Object.keys(o).forEach((function(e){return r(e,o[e])})),a}if(!rT(n))return!1;if(Array.isArray(t))return!!Array.isArray(n)&&t.length===n.length&&t.every((function(t,i){return e(t,n[i],r)}));if(t instanceof Map)return n instanceof Map&&Array.from(t.keys()).every((function(i){return e(t.get(i),n.get(i),r)}));if(t instanceof Set){if(!(n instanceof Set))return!1;if(0===t.size)return 0===n.size;if(1===t.size){var s=Array.from(t.values())[0];return iT(s)?Array.from(n.values()).every((function(t){return e(s,t,r)})):n.has(s)}return Array.from(t.values()).every((function(e){return n.has(e)}))}return Object.keys(t).every((function(i){var a,o=t[i];return(i in n||iT(a=o)&&"optional"===a[tT]().matcherType)&&e(o,n[i],r)}))}return Object.is(n,t)},oT=function e(t){var n,r,i;return rT(t)?iT(t)?null!=(n=null==(r=(i=t[tT]()).getSelectionKeys)?void 0:r.call(i))?n:[]:Array.isArray(t)?sT(t,e):sT(Object.values(t),e):[]},sT=function(e,t){return e.reduce((function(e,n){return e.concat(t(n))}),[])};function uT(e){var t;return(t={})[tT]=function(){return{match:function(t){var n={},r=function(e,t){n[e]=t};return void 0===t?(oT(e).forEach((function(e){return r(e,void 0)})),{matched:!0,selections:n}):{matched:aT(e,t,r),selections:n}},getSelectionKeys:function(){return oT(e)},matcherType:"optional"}},t}function cT(e){var t;return(t={})[tT]=function(){return{match:function(t){if(!Array.isArray(t))return{matched:!1};var n={};if(0===t.length)return oT(e).forEach((function(e){n[e]=[]})),{matched:!0,selections:n};var r=function(e,t){n[e]=(n[e]||[]).concat([t])};return{matched:t.every((function(t){return aT(e,t,r)})),selections:n}},getSelectionKeys:function(){return oT(e)}}},t}function lT(){var e,t=[].slice.call(arguments);return(e={})[tT]=function(){return{match:function(e){var n={},r=function(e,t){n[e]=t};return{matched:t.every((function(t){return aT(t,e,r)})),selections:n}},getSelectionKeys:function(){return sT(t,oT)},matcherType:"and"}},e}function fT(){var e,t=[].slice.call(arguments);return(e={})[tT]=function(){return{match:function(e){var n={},r=function(e,t){n[e]=t};return sT(t,oT).forEach((function(e){return r(e,void 0)})),{matched:t.some((function(t){return aT(t,e,r)})),selections:n}},getSelectionKeys:function(){return sT(t,oT)},matcherType:"or"}},e}function dT(e){var t;return(t={})[tT]=function(){return{match:function(t){return{matched:!aT(e,t,(function(){}))}},getSelectionKeys:function(){return[]},matcherType:"not"}},t}function pT(e){var t;return(t={})[tT]=function(){return{match:function(t){return{matched:Boolean(e(t))}}}},t}function hT(){var e,t=[].slice.call(arguments),n="string"==typeof t[0]?t[0]:void 0,r=2===t.length?t[1]:"string"==typeof t[0]?void 0:t[0];return(e={})[tT]=function(){return{match:function(e){var t,i=((t={})[null!=n?n:nT]=e,t);return{matched:void 0===r||aT(r,e,(function(e,t){i[e]=t})),selections:i}},getSelectionKeys:function(){return[null!=n?n:nT].concat(void 0===r?[]:oT(r))}}},e}var vT=pT((function(e){return!0})),yT=vT,mT=pT((function(e){return"string"==typeof e})),gT=pT((function(e){return"number"==typeof e})),bT=pT((function(e){return"boolean"==typeof e})),wT=pT((function(e){return"bigint"==typeof e})),kT=pT((function(e){return"symbol"==Xu(e)})),xT=pT((function(e){return null==e})),_T={__proto__:null,optional:uT,array:cT,intersection:lT,union:fT,not:dT,when:pT,select:hT,any:vT,_:yT,string:mT,number:gT,boolean:bT,bigint:wT,symbol:kT,nullish:xT,instanceOf:function(e){return pT(function(e){return function(t){return t instanceof e}}(e))},typed:function(){return{array:cT,optional:uT,intersection:lT,union:fT,not:dT,select:hT,when:pT}}},ST=function(){function e(e,t){this.value=void 0,this.cases=void 0,this.value=e,this.cases=t}var t=e.prototype;return t.with=function(){var t=[].slice.call(arguments),n=t[t.length-1],r=[t[0]],i=[];return 3===t.length&&"function"==typeof t[1]?(r.push(t[0]),i.push(t[1])):t.length>2&&r.push.apply(r,t.slice(1,t.length-1)),new e(this.value,this.cases.concat([{match:function(e){var t={},n=Boolean(r.some((function(n){return aT(n,e,(function(e,n){t[e]=n}))}))&&i.every((function(t){return t(e)})));return{matched:n,value:n&&Object.keys(t).length?nT in t?t[nT]:t:e}},handler:n}]))},t.when=function(t,n){return new e(this.value,this.cases.concat([{match:function(e){return{matched:Boolean(t(e)),value:e}},handler:n}]))},t.otherwise=function(t){return new e(this.value,this.cases.concat([{match:function(e){return{matched:!0,value:e}},handler:t}])).run()},t.exhaustive=function(){return this.run()},t.run=function(){for(var e=this.value,t=void 0,n=0;n<this.cases.length;n++){var r=this.cases[n],i=r.match(this.value);if(i.matched){e=i.value,t=r.handler;break}}if(!t){var a;try{a=JSON.stringify(this.value)}catch(e){a=this.value}throw new Error("Pattern matching error: no pattern matches value "+a)}return t(e,this.value)},e}();eT.P=_T,eT.Pattern=_T,eT.isMatching=function(){var e=[].slice.call(arguments);if(1===e.length){var t=e[0];return function(e){return aT(t,e,(function(){}))}}if(2===e.length){var n=e,r=n[0],i=n[1];return aT(r,i,(function(){}))}throw new Error("isMatching wasn't given the right number of arguments: expected 1 or 2, received "+e.length+".")},eT.match=function(e){return new ST(e,[])};var OT=ni,ET=Fl,TT=o,RT=Z,IT=H,CT=Pc,PT=hp,AT=Xn,jT=ET&&ET.prototype;if(OT({target:"Promise",proto:!0,real:!0,forced:!!ET&&TT((function(){jT.finally.call({then:function(){}},(function(){}))}))},{finally:function(e){var t=CT(this,RT("Promise")),n=IT(e);return this.then(n?function(n){return PT(t,e()).then((function(){return n}))}:e,n?function(n){return PT(t,e()).then((function(){throw n}))}:e)}}),IT(ET)){var MT=RT("Promise").prototype.finally;jT.finally!==MT&&AT(jT,"finally",MT,{unsafe:!0})}function LT(){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 UT(e,t,n){return UT=LT()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&Ju(i,n.prototype),i},UT.apply(null,arguments)}function NT(e){var t="function"==typeof Map?new Map:void 0;return NT=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 UT(e,arguments,ec(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),Ju(r,e)},NT(e)}var FT={},DT="[a-fA-F\\d:]",qT=function(e){return e&&e.includeBoundaries?"(?:(?<=\\s|^)(?=".concat(DT,")|(?<=").concat(DT,")(?=\\s|$))"):""},BT="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",zT="[a-fA-F\\d]{1,4}",WT="\n(?:\n(?:".concat(zT,":){7}(?:").concat(zT,"|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8\n(?:").concat(zT,":){6}(?:").concat(BT,"|:").concat(zT,"|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4\n(?:").concat(zT,":){5}(?::").concat(BT,"|(?::").concat(zT,"){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4\n(?:").concat(zT,":){4}(?:(?::").concat(zT,"){0,1}:").concat(BT,"|(?::").concat(zT,"){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4\n(?:").concat(zT,":){3}(?:(?::").concat(zT,"){0,2}:").concat(BT,"|(?::").concat(zT,"){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4\n(?:").concat(zT,":){2}(?:(?::").concat(zT,"){0,3}:").concat(BT,"|(?::").concat(zT,"){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4\n(?:").concat(zT,":){1}(?:(?::").concat(zT,"){0,4}:").concat(BT,"|(?::").concat(zT,"){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4\n(?::(?:(?::").concat(zT,"){0,5}:").concat(BT,"|(?::").concat(zT,"){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4\n)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1\n").replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),$T=new RegExp("(?:^".concat(BT,"$)|(?:^").concat(WT,"$)")),KT=new RegExp("^".concat(BT,"$")),HT=new RegExp("^".concat(WT,"$")),GT=function(e){return e&&e.exact?$T:new RegExp("(?:".concat(qT(e)).concat(BT).concat(qT(e),")|(?:").concat(qT(e)).concat(WT).concat(qT(e),")"),"g")};GT.v4=function(e){return e&&e.exact?KT:new RegExp("".concat(qT(e)).concat(BT).concat(qT(e)),"g")},GT.v6=function(e){return e&&e.exact?HT:new RegExp("".concat(qT(e)).concat(WT).concat(qT(e)),"g")};var VT=GT,YT=function(e){return VT({exact:!0}).test(e)};function JT(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 QT(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?JT(Object(n),!0).forEach((function(t){ic(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):JT(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function XT(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 ZT(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 ZT(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function ZT(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 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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}YT.v4=function(e){return VT.v4({exact:!0}).test(e)},YT.v6=function(e){return VT.v6({exact:!0}).test(e)},YT.version=function(e){return YT(e)?YT.v4(e)?4:6:void 0};var tR=YT,nR=function(e){Qu(n,e);var t=eR(n);function n(){var e;return rc(this,n),(e=t.call(this,"Request was cancelled")).name="CancelError",e}return nc(n,[{key:"isCanceled",get:function(){return!0}}]),n}(NT(Error)),rR={timeout:5e3},iR={v4:["https://ipv4.icanhazip.com/","https://api.ipify.org/"],v6:["https://ipv6.icanhazip.com/","https://api6.ipify.org/"]},aR=function(e,t,n){var r,i=new XMLHttpRequest,a=new Promise((function(a,o){r=o,i.addEventListener("error",o,{once:!0}),i.addEventListener("timeout",o,{once:!0}),i.addEventListener("load",(function(){var e=i.responseText.trim();e&&tR[n](e)?a(e):o()}),{once:!0}),i.open("GET",e),i.timeout=t.timeout,i.send()}));return a.cancel=function(){i.abort(),r(new nR)},a},oR=function(e,t){var n,r=Vu(lh.mark((function r(){var i,a,o,s,u;return lh.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:i=[].concat.apply(iR[e],t.fallbackUrls||[]),a=XT(i),r.prev=2,a.s();case 4:if((o=a.n()).done){r.next=20;break}return s=o.value,r.prev=6,n=aR(s,t,e),r.next=10,n;case 10:return u=r.sent,r.abrupt("return",u);case 14:if(r.prev=14,r.t0=r.catch(6),!(r.t0 instanceof nR)){r.next=18;break}throw r.t0;case 18:r.next=4;break;case 20:r.next=25;break;case 22:r.prev=22,r.t1=r.catch(2),a.e(r.t1);case 25:return r.prev=25,a.f(),r.finish(25);case 28:throw new Error("Couldn't find your IP");case 29:case"end":return r.stop()}}),r,null,[[2,22,25,28],[6,14]])})))();return r.cancel=function(){n.cancel()},r};function sR(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 uR(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?sR(Object(n),!0).forEach((function(t){ic(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):sR(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}FT.v4=function(e){return oR("v4",QT(QT({},rR),e))},FT.v6=function(e){return oR("v6",QT(QT({},rR),e))};var cR,lR=FT,fR=function(){var e=Vu(lh.mark((function e(t){var n;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=uR({timeout:5e3,ipVersion:4},t),!navigator||navigator.onLine){e.next=3;break}return e.abrupt("return",!1);case 3:return n=4===t.ipVersion?"v4":"v6",e.prev=4,e.next=7,lR[n](t);case 7:return e.abrupt("return",!0);case 10:return e.prev=10,e.t0=e.catch(4),e.abrupt("return",!1);case 13:case"end":return e.stop()}}),e,null,[[4,10]])})));return function(t){return e.apply(this,arguments)}}(),dR=fR,pR=Y,hR=T,vR=ot("match"),yR=function(e){var t;return pR(e)&&(void 0!==(t=e[vR])?!!t:"RegExp"==hR(e))},mR=yR,gR=TypeError,bR=function(e){if(mR(e))throw gR("The method doesn't accept regular expressions");return e},wR=ot("match"),kR=function(e){var t=/./;try{"/./"[e](t)}catch(n){try{return t[wR]=!1,"/./"[e](t)}catch(e){}}return!1},xR=ni,_R=C,SR=a.f,OR=fr,ER=za,TR=bR,RR=D,IR=kR,CR=_R("".startsWith),PR=_R("".slice),AR=Math.min,jR=IR("startsWith");xR({target:"String",proto:!0,forced:!!(jR||(cR=SR(String.prototype,"startsWith"),!cR||cR.writable))&&!jR},{startsWith:function(e){var t=ER(RR(this));TR(e);var n=OR(AR(arguments.length>1?arguments[1]:void 0,t.length)),r=ER(e);return CR?CR(t,r,n):PR(t,n,n+r.length)===r}});var MR="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",LR={nanoid:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:21,t="",n=e;n--;)t+=MR[64*Math.random()|0];return t},customAlphabet:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:21;return function(){for(var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t,r="",i=n;i--;)r+=e[Math.random()*e.length|0];return r}}};function UR(e){return function(e){if(Array.isArray(e))return Kx(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Hx(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.")}()}var NR={};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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)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}function qR(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 BR(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?qR(Object(n),!0).forEach((function(t){ic(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):qR(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Type=e.TypeBuilder=e.Modifier=e.Hint=e.Kind=void 0,e.Kind=Symbol.for("TypeBox.Kind"),e.Hint=Symbol.for("TypeBox.Hint"),e.Modifier=Symbol.for("TypeBox.Modifier");var t=0,n=function(){function n(){rc(this,n)}return nc(n,[{key:"ReadonlyOptional",value:function(t){return BR(ic({},e.Modifier,"ReadonlyOptional"),t)}},{key:"Readonly",value:function(t){return BR(ic({},e.Modifier,"Readonly"),t)}},{key:"Optional",value:function(t){return BR(ic({},e.Modifier,"Optional"),t)}},{key:"Any",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},t),{},ic({},e.Kind,"Any")))}},{key:"Array",value:function(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.Create(BR(BR({},r),{},(ic(n={},e.Kind,"Array"),ic(n,"type","array"),ic(n,"items",t),n)))}},{key:"Boolean",value:function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},n),{},(ic(t={},e.Kind,"Boolean"),ic(t,"type","boolean"),t)))}},{key:"ConstructorParameters",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.Tuple(UR(e.parameters),BR({},t))}},{key:"Constructor",value:function(t,n){var r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("Tuple"===t[e.Kind]){var a,o=void 0===t.items?[]:t.items;return this.Create(BR(BR({},i),{},(ic(a={},e.Kind,"Constructor"),ic(a,"type","constructor"),ic(a,"parameters",o),ic(a,"returns",n),a)))}if(globalThis.Array.isArray(t))return this.Create(BR(BR({},i),{},(ic(r={},e.Kind,"Constructor"),ic(r,"type","constructor"),ic(r,"parameters",t),ic(r,"returns",n),r)));throw new Error("TypeBuilder.Constructor: Invalid parameters")}},{key:"Enum",value:function(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=Object.keys(t).filter((function(e){return isNaN(e)})).map((function(e){return t[e]})),a=i.map((function(t){var n,r;return"string"==typeof t?(ic(n={},e.Kind,"Literal"),ic(n,"type","string"),ic(n,"const",t),n):(ic(r={},e.Kind,"Literal"),ic(r,"type","number"),ic(r,"const",t),r)}));return this.Create(BR(BR({},r),{},(ic(n={},e.Kind,"Union"),ic(n,e.Hint,"Enum"),ic(n,"anyOf",a),n)))}},{key:"Function",value:function(t,n){var r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("Tuple"===t[e.Kind]){var a,o=void 0===t.items?[]:t.items;return this.Create(BR(BR({},i),{},(ic(a={},e.Kind,"Function"),ic(a,"type","function"),ic(a,"parameters",o),ic(a,"returns",n),a)))}if(globalThis.Array.isArray(t))return this.Create(BR(BR({},i),{},(ic(r={},e.Kind,"Function"),ic(r,"type","function"),ic(r,"parameters",t),ic(r,"returns",n),r)));throw new Error("TypeBuilder.Function: Invalid parameters")}},{key:"InstanceType",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return BR(BR({},t),this.Clone(e.returns))}},{key:"Integer",value:function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},n),{},(ic(t={},e.Kind,"Integer"),ic(t,"type","integer"),t)))}},{key:"Intersect",value:function(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=function(t){return t[e.Modifier]&&"Optional"===t[e.Modifier]||"ReadonlyOptional"===t[e.Modifier]},a=new Set,o=new Set,s=FR(t);try{for(s.s();!(n=s.n()).done;)for(var u=n.value,c=0,l=Object.entries(u.properties);c<l.length;c++){var f=Gx(l[c],2),d=f[0],p=f[1];i(p)&&o.add(d)}}catch(e){s.e(e)}finally{s.f()}var h,v=FR(t);try{for(v.s();!(h=v.n()).done;)for(var y=h.value,m=0,g=Object.keys(y.properties);m<g.length;m++){var b=g[m];o.has(b)||a.add(b)}}catch(e){v.e(e)}finally{v.f()}var w,k,x,_={},S=FR(t);try{for(S.s();!(w=S.n()).done;)for(var O=w.value,E=0,T=Object.entries(O.properties);E<T.length;E++){var R,I=Gx(T[E],2),C=I[0],P=I[1];_[C]=void 0===_[C]?P:(ic(R={},e.Kind,"Union"),ic(R,"anyOf",[_[C],BR({},P)]),R)}}catch(e){S.e(e)}finally{S.f()}return a.size>0?this.Create(BR(BR({},r),{},(ic(k={},e.Kind,"Object"),ic(k,"type","object"),ic(k,"properties",_),ic(k,"required",UR(a)),k))):this.Create(BR(BR({},r),{},(ic(x={},e.Kind,"Object"),ic(x,"type","object"),ic(x,"properties",_),x)))}},{key:"KeyOf",value:function(t){var n,r=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=Object.keys(t.properties).map((function(t){var n;return r.Create(BR(BR({},i),{},(ic(n={},e.Kind,"Literal"),ic(n,"type","string"),ic(n,"const",t),n)))}));return this.Create(BR(BR({},i),{},(ic(n={},e.Kind,"Union"),ic(n,e.Hint,"KeyOf"),ic(n,"anyOf",a),n)))}},{key:"Literal",value:function(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.Create(BR(BR({},r),{},(ic(n={},e.Kind,"Literal"),ic(n,"const",t),ic(n,"type",Xu(t)),n)))}},{key:"Never",value:function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},n),{},(ic(t={},e.Kind,"Never"),ic(t,"allOf",[{type:"boolean",const:!1},{type:"boolean",const:!0}]),t)))}},{key:"Null",value:function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},n),{},(ic(t={},e.Kind,"Null"),ic(t,"type","null"),t)))}},{key:"Number",value:function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},n),{},(ic(t={},e.Kind,"Number"),ic(t,"type","number"),t)))}},{key:"Object",value:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((function(t){var n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=Object.keys(t),o=a.filter((function(n){var r=t[n][e.Modifier];return r&&("Optional"===r||"ReadonlyOptional"===r)})),s=a.filter((function(e){return!o.includes(e)}));return s.length>0?this.Create(BR(BR({},i),{},(ic(n={},e.Kind,"Object"),ic(n,"type","object"),ic(n,"properties",t),ic(n,"required",s),n))):this.Create(BR(BR({},i),{},(ic(r={},e.Kind,"Object"),ic(r,"type","object"),ic(r,"properties",t),r)))}))},{key:"Omit",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i="Union"===n[e.Kind]?n.anyOf.map((function(e){return e.const})):n,a=BR(BR(BR({},this.Clone(t)),r),{},ic({},e.Hint,"Omit"));a.required&&(a.required=a.required.filter((function(e){return!i.includes(e)})),0===a.required.length&&delete a.required);for(var o=0,s=Object.keys(a.properties);o<s.length;o++){var u=s[o];i.includes(u)&&delete a.properties[u]}return this.Create(a)}},{key:"Parameters",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.Type.Tuple(t.parameters,BR({},n))}},{key:"Partial",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=BR(BR(BR({},this.Clone(t)),n),{},ic({},e.Hint,"Partial"));delete r.required;for(var i=0,a=Object.keys(r.properties);i<a.length;i++){var o=a[i],s=r.properties[o],u=s[e.Modifier];switch(u){case"ReadonlyOptional":case"Readonly":s[e.Modifier]="ReadonlyOptional";break;default:s[e.Modifier]="Optional"}}return this.Create(r)}},{key:"Pick",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i="Union"===n[e.Kind]?n.anyOf.map((function(e){return e.const})):n,a=BR(BR(BR({},this.Clone(t)),r),{},ic({},e.Hint,"Pick"));a.required&&(a.required=a.required.filter((function(e){return i.includes(e)})),0===a.required.length&&delete a.required);for(var o=0,s=Object.keys(a.properties);o<s.length;o++){var u=s[o];i.includes(u)||delete a.properties[u]}return this.Create(a)}},{key:"Promise",value:function(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.Create(BR(BR({},r),{},(ic(n={},e.Kind,"Promise"),ic(n,"type","promise"),ic(n,"item",t),n)))}},{key:"Record",value:function(t,n){var r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("Union"===t[e.Kind])return this.Object(t.anyOf.reduce((function(e,t){return BR(BR({},e),{},ic({},t.const,n))}),{}),BR(BR({},i),{},ic({},e.Hint,"Record")));var a="Number"===t[e.Kind]?"^(0|[1-9][0-9]*)$":"String"===t[e.Kind]&&t.pattern?t.pattern:"^.*$";return this.Create(BR(BR({},i),{},(ic(r={},e.Kind,"Record"),ic(r,"type","object"),ic(r,"patternProperties",ic({},a,n)),ic(r,"additionalProperties",!1),r)))}},{key:"Recursive",value:function(n){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};void 0===i.$id&&(i.$id="T".concat(t++));var a=n((ic(r={},e.Kind,"Self"),ic(r,"$ref","".concat(i.$id)),r));return a.$id=i.$id,this.Create(BR(BR({},i),a))}},{key:"Ref",value:function(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(void 0===t.$id)throw Error("TypeBuilder.Ref: Referenced schema must specify an $id");return this.Create(BR(BR({},r),{},(ic(n={},e.Kind,"Ref"),ic(n,"$ref",t.$id),n)))}},{key:"RegEx",value:function(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.Create(BR(BR({},r),{},(ic(n={},e.Kind,"String"),ic(n,"type","string"),ic(n,"pattern",t.source),n)))}},{key:"Required",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=BR(BR(BR({},this.Clone(t)),n),{},ic({},e.Hint,"Required"));r.required=Object.keys(r.properties);for(var i=0,a=Object.keys(r.properties);i<a.length;i++){var o=a[i],s=r.properties[o],u=s[e.Modifier];switch(u){case"ReadonlyOptional":case"Readonly":s[e.Modifier]="Readonly";break;default:delete s[e.Modifier]}}return this.Create(r)}},{key:"ReturnType",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return BR(BR({},t),this.Clone(e.returns))}},{key:"Strict",value:function(e){return JSON.parse(JSON.stringify(e))}},{key:"String",value:function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},n),{},(ic(t={},e.Kind,"String"),ic(t,"type","string"),t)))}},{key:"Tuple",value:function(t){var n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=!1,o=t.length,s=t.length,u=t.length>0?BR(BR({},i),{},(ic(n={},e.Kind,"Tuple"),ic(n,"type","array"),ic(n,"items",t),ic(n,"additionalItems",a),ic(n,"minItems",o),ic(n,"maxItems",s),n)):BR(BR({},i),{},(ic(r={},e.Kind,"Tuple"),ic(r,"type","array"),ic(r,"minItems",o),ic(r,"maxItems",s),r));return this.Create(u)}},{key:"Undefined",value:function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},n),{},(ic(t={},e.Kind,"Undefined"),ic(t,"type","object"),ic(t,"specialized","Undefined"),t)))}},{key:"Union",value:function(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return 0===t.length?e.Type.Never(BR({},r)):this.Create(BR(BR({},r),{},(ic(n={},e.Kind,"Union"),ic(n,"anyOf",t),n)))}},{key:"Uint8Array",value:function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},n),{},(ic(t={},e.Kind,"Uint8Array"),ic(t,"type","object"),ic(t,"specialized","Uint8Array"),t)))}},{key:"Unknown",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},t),{},ic({},e.Kind,"Unknown")))}},{key:"Unsafe",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},t),{},ic({},e.Kind,t[e.Kind]||"Unsafe")))}},{key:"Void",value:function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.Create(BR(BR({},n),{},(ic(t={},e.Kind,"Void"),ic(t,"type","null"),t)))}},{key:"Create",value:function(e){return e}},{key:"Clone",value:function(e){var t,n=this;return"object"!==Xu(t=e)||null===t||Array.isArray(t)?function(e){return"object"===Xu(e)&&null!==e&&Array.isArray(e)}(e)?e.map((function(e){return n.Clone(e)})):e:Object.keys(e).reduce((function(t,r){return BR(BR({},t),{},ic({},r,n.Clone(e[r])))}),Object.getOwnPropertySymbols(e).reduce((function(t,r){return BR(BR({},t),{},ic({},r,n.Clone(e[r])))}),{}))}}]),n}();e.TypeBuilder=n,e.Type=new n}(NR);var zR={},WR={},$R={},KR={},HR={};function GR(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 VR(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 VR(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function VR(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 YR(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}!function(e){var t,n;Object.defineProperty(e,"__esModule",{value:!0}),e.Format=void 0,t=e.Format||(e.Format={}),n=new Map,t.Clear=function(){return n.clear()},t.Has=function(e){return n.has(e)},t.Set=function(e,t){n.set(e,t)},t.Get=function(e){return n.get(e)}}(HR),function(e){var n=t&&t.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),r=t&&t.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(e,"__esModule",{value:!0}),r(HR,e)}(KR),function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.ValueErrors=e.ValueErrorsUnknownTypeError=e.ValueErrorType=void 0;var t,n=NR,r=KR;!function(e){e[e.Array=0]="Array",e[e.ArrayMinItems=1]="ArrayMinItems",e[e.ArrayMaxItems=2]="ArrayMaxItems",e[e.ArrayUniqueItems=3]="ArrayUniqueItems",e[e.Boolean=4]="Boolean",e[e.Function=5]="Function",e[e.Integer=6]="Integer",e[e.IntegerMultipleOf=7]="IntegerMultipleOf",e[e.IntegerExclusiveMinimum=8]="IntegerExclusiveMinimum",e[e.IntegerExclusiveMaximum=9]="IntegerExclusiveMaximum",e[e.IntegerMinimum=10]="IntegerMinimum",e[e.IntegerMaximum=11]="IntegerMaximum",e[e.Literal=12]="Literal",e[e.Never=13]="Never",e[e.Null=14]="Null",e[e.Number=15]="Number",e[e.NumberMultipleOf=16]="NumberMultipleOf",e[e.NumberExclusiveMinimum=17]="NumberExclusiveMinimum",e[e.NumberExclusiveMaximum=18]="NumberExclusiveMaximum",e[e.NumberMinumum=19]="NumberMinumum",e[e.NumberMaximum=20]="NumberMaximum",e[e.Object=21]="Object",e[e.ObjectMinProperties=22]="ObjectMinProperties",e[e.ObjectMaxProperties=23]="ObjectMaxProperties",e[e.ObjectAdditionalProperties=24]="ObjectAdditionalProperties",e[e.Promise=25]="Promise",e[e.RecordKeyNumeric=26]="RecordKeyNumeric",e[e.RecordKeyString=27]="RecordKeyString",e[e.String=28]="String",e[e.StringMinLength=29]="StringMinLength",e[e.StringMaxLength=30]="StringMaxLength",e[e.StringPattern=31]="StringPattern",e[e.StringFormatUnknown=32]="StringFormatUnknown",e[e.StringFormat=33]="StringFormat",e[e.TupleZeroLength=34]="TupleZeroLength",e[e.TupleLength=35]="TupleLength",e[e.Undefined=36]="Undefined",e[e.Union=37]="Union",e[e.Uint8Array=38]="Uint8Array",e[e.Uint8ArrayMinByteLength=39]="Uint8ArrayMinByteLength",e[e.Uint8ArrayMaxByteLength=40]="Uint8ArrayMaxByteLength",e[e.Void=41]="Void"}(t=e.ValueErrorType||(e.ValueErrorType={}));var i=function(e){Qu(n,e);var t=YR(n);function n(e){var r;return rc(this,n),(r=t.call(this,"ValueErrors: Unknown type")).schema=e,r}return nc(n)}(NT(Error));e.ValueErrorsUnknownTypeError=i,function(e){var a=lh.mark(I),o=lh.mark(C),s=lh.mark(P),u=lh.mark(A),c=lh.mark(j),l=lh.mark(M),f=lh.mark(L),d=lh.mark(U),p=lh.mark(N),h=lh.mark(F),v=lh.mark(D),y=lh.mark(q),m=lh.mark(B),g=lh.mark(z),b=lh.mark(W),w=lh.mark($),k=lh.mark(K),x=lh.mark(H),_=lh.mark(G),S=lh.mark(V),O=lh.mark(Y),E=lh.mark(J),T=lh.mark(Q),R=lh.mark(X);function I(e,t,n,r){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),a)}function C(e,n,r,i){var a;return lh.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(globalThis.Array.isArray(i)){o.next=4;break}return o.next=3,{type:t.Array,schema:e,path:r,value:i,message:"Expected array"};case 3:return o.abrupt("return",o.sent);case 4:if(void 0===e.minItems||i.length>=e.minItems){o.next=7;break}return o.next=7,{type:t.ArrayMinItems,schema:e,path:r,value:i,message:"Expected array length to be greater or equal to ".concat(e.minItems)};case 7:if(void 0===e.maxItems||i.length<=e.maxItems){o.next=10;break}return o.next=10,{type:t.ArrayMinItems,schema:e,path:r,value:i,message:"Expected array length to be less or equal to ".concat(e.maxItems)};case 10:if(!0!==e.uniqueItems||new Set(i).size===i.length){o.next=13;break}return o.next=13,{type:t.ArrayUniqueItems,schema:e,path:r,value:i,message:"Expected array elements to be unique"};case 13:a=0;case 14:if(!(a<i.length)){o.next=19;break}return o.delegateYield(Q(e.items,n,"".concat(r,"/").concat(a),i[a]),"t0",16);case 16:a++,o.next=14;break;case 19:case"end":return o.stop()}}),o)}function P(e,n,r,i){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("boolean"==typeof i){n.next=4;break}return n.next=3,{type:t.Boolean,schema:e,path:r,value:i,message:"Expected boolean"};case 3:return n.abrupt("return",n.sent);case 4:case"end":return n.stop()}}),s)}function A(e,t,n,r){return lh.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.delegateYield(Q(e.returns,t,n,r.prototype),"t0",1);case 1:case"end":return i.stop()}}),u)}function j(e,n,r,i){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("function"==typeof i){n.next=4;break}return n.next=3,{type:t.Function,schema:e,path:r,value:i,message:"Expected function"};case 3:return n.abrupt("return",n.sent);case 4:case"end":return n.stop()}}),c)}function M(e,n,r,i){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("number"==typeof i){n.next=4;break}return n.next=3,{type:t.Number,schema:e,path:r,value:i,message:"Expected number"};case 3:return n.abrupt("return",n.sent);case 4:if(globalThis.Number.isInteger(i)){n.next=7;break}return n.next=7,{type:t.Integer,schema:e,path:r,value:i,message:"Expected integer"};case 7:if(!e.multipleOf||i%e.multipleOf==0){n.next=10;break}return n.next=10,{type:t.IntegerMultipleOf,schema:e,path:r,value:i,message:"Expected integer to be a multiple of ".concat(e.multipleOf)};case 10:if(!e.exclusiveMinimum||i>e.exclusiveMinimum){n.next=13;break}return n.next=13,{type:t.IntegerExclusiveMinimum,schema:e,path:r,value:i,message:"Expected integer to be greater than ".concat(e.exclusiveMinimum)};case 13:if(!e.exclusiveMaximum||i<e.exclusiveMaximum){n.next=16;break}return n.next=16,{type:t.IntegerExclusiveMaximum,schema:e,path:r,value:i,message:"Expected integer to be less than ".concat(e.exclusiveMaximum)};case 16:if(!e.minimum||i>=e.minimum){n.next=19;break}return n.next=19,{type:t.IntegerMinimum,schema:e,path:r,value:i,message:"Expected integer to be greater or equal to ".concat(e.minimum)};case 19:if(!e.maximum||i<=e.maximum){n.next=22;break}return n.next=22,{type:t.IntegerMaximum,schema:e,path:r,value:i,message:"Expected integer to be less or equal to ".concat(e.maximum)};case 22:case"end":return n.stop()}}),l)}function L(e,n,r,i){var a;return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(i===e.const){n.next=5;break}return a="string"==typeof e.const?"'".concat(e.const,"'"):e.const,n.next=4,{type:t.Literal,schema:e,path:r,value:i,message:"Expected ".concat(a)};case 4:return n.abrupt("return",n.sent);case 5:case"end":return n.stop()}}),f)}function U(e,n,r,i){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,{type:t.Never,schema:e,path:r,value:i,message:"Value cannot be validated"};case 2:case"end":return n.stop()}}),d)}function N(e,n,r,i){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(null===i){n.next=4;break}return n.next=3,{type:t.Null,schema:e,path:r,value:i,message:"Expected null"};case 3:return n.abrupt("return",n.sent);case 4:case"end":return n.stop()}}),p)}function F(e,n,r,i){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("number"==typeof i){n.next=4;break}return n.next=3,{type:t.Number,schema:e,path:r,value:i,message:"Expected number"};case 3:return n.abrupt("return",n.sent);case 4:if(!e.multipleOf||i%e.multipleOf==0){n.next=7;break}return n.next=7,{type:t.NumberMultipleOf,schema:e,path:r,value:i,message:"Expected number to be a multiple of ".concat(e.multipleOf)};case 7:if(!e.exclusiveMinimum||i>e.exclusiveMinimum){n.next=10;break}return n.next=10,{type:t.NumberExclusiveMinimum,schema:e,path:r,value:i,message:"Expected number to be greater than ".concat(e.exclusiveMinimum)};case 10:if(!e.exclusiveMaximum||i<e.exclusiveMaximum){n.next=13;break}return n.next=13,{type:t.NumberExclusiveMaximum,schema:e,path:r,value:i,message:"Expected number to be less than ".concat(e.exclusiveMaximum)};case 13:if(!e.minimum||i>=e.minimum){n.next=16;break}return n.next=16,{type:t.NumberMaximum,schema:e,path:r,value:i,message:"Expected number to be greater or equal to ".concat(e.minimum)};case 16:if(!e.maximum||i<=e.maximum){n.next=19;break}return n.next=19,{type:t.NumberMinumum,schema:e,path:r,value:i,message:"Expected number to be less or equal to ".concat(e.maximum)};case 19:case"end":return n.stop()}}),h)}function D(e,n,r,i){var a,o,s,u,c,l,f,d;return lh.wrap((function(p){for(;;)switch(p.prev=p.next){case 0:if("object"===Xu(i)&&null!==i&&!globalThis.Array.isArray(i)){p.next=4;break}return p.next=3,{type:t.Object,schema:e,path:r,value:i,message:"Expected object"};case 3:return p.abrupt("return",p.sent);case 4:if(void 0===e.minProperties||globalThis.Object.keys(i).length>=e.minProperties){p.next=7;break}return p.next=7,{type:t.ObjectMinProperties,schema:e,path:r,value:i,message:"Expected object to have at least ".concat(e.minProperties," properties")};case 7:if(void 0===e.maxProperties||globalThis.Object.keys(i).length<=e.maxProperties){p.next=10;break}return p.next=10,{type:t.ObjectMaxProperties,schema:e,path:r,value:i,message:"Expected object to have less than ".concat(e.minProperties," properties")};case 10:if(a=globalThis.Object.keys(e.properties),!1!==e.additionalProperties){p.next=30;break}o=GR(globalThis.Object.keys(i)),p.prev=13,o.s();case 15:if((s=o.n()).done){p.next=22;break}if(u=s.value,a.includes(u)){p.next=20;break}return p.next=20,{type:t.ObjectAdditionalProperties,schema:e,path:"".concat(r,"/").concat(u),value:i[u],message:"Unexpected property"};case 20:p.next=15;break;case 22:p.next=27;break;case 24:p.prev=24,p.t0=p.catch(13),o.e(p.t0);case 27:return p.prev=27,o.f(),p.finish(27);case 30:c=GR(a),p.prev=31,c.s();case 33:if((l=c.n()).done){p.next=44;break}if(f=l.value,d=e.properties[f],!e.required||!e.required.includes(f)){p.next=40;break}return p.delegateYield(Q(d,n,"".concat(r,"/").concat(f),i[f]),"t1",38);case 38:p.next=42;break;case 40:if(void 0===i[f]){p.next=42;break}return p.delegateYield(Q(d,n,"".concat(r,"/").concat(f),i[f]),"t2",42);case 42:p.next=33;break;case 44:p.next=49;break;case 46:p.prev=46,p.t3=p.catch(31),c.e(p.t3);case 49:return p.prev=49,c.f(),p.finish(49);case 52:case"end":return p.stop()}}),v,null,[[13,24,27,30],[31,46,49,52]])}function q(e,n,r,i){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("object"===Xu(i)&&"function"==typeof i.then){n.next=3;break}return n.next=3,{type:t.Promise,schema:e,path:r,value:i,message:"Expected Promise"};case 3:case"end":return n.stop()}}),y)}function B(e,n,r,i){var a,o,s,u,c,l,f,d,p,h,v,y;return lh.wrap((function(m){for(;;)switch(m.prev=m.next){case 0:if("object"===Xu(i)&&null!==i&&!globalThis.Array.isArray(i)){m.next=4;break}return m.next=3,{type:t.Object,schema:e,path:r,value:i,message:"Expected object"};case 3:return m.abrupt("return",m.sent);case 4:if(a=Gx(globalThis.Object.entries(e.patternProperties)[0],2),o=a[0],s=a[1],u=new RegExp(o),globalThis.Object.keys(i).every((function(e){return u.test(e)}))){m.next=13;break}return l=(c="^(0|[1-9][0-9]*)$"===o)?t.RecordKeyNumeric:t.RecordKeyString,f=c?"Expected all object property keys to be numeric":"Expected all object property keys to be strings",m.next=12,{type:l,schema:e,path:r,value:i,message:f};case 12:return m.abrupt("return",m.sent);case 13:d=GR(globalThis.Object.entries(i)),m.prev=14,d.s();case 16:if((p=d.n()).done){m.next=21;break}return h=Gx(p.value,2),v=h[0],y=h[1],m.delegateYield(Q(s,n,"".concat(r,"/").concat(v),y),"t0",19);case 19:m.next=16;break;case 21:m.next=26;break;case 23:m.prev=23,m.t1=m.catch(14),d.e(m.t1);case 26:return m.prev=26,d.f(),m.finish(26);case 29:case"end":return m.stop()}}),m,null,[[14,23,26,29]])}function z(e,t,n,r){var i;return lh.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:if(void 0!==(i=t.find((function(t){return t.$id===e.$ref})))){a.next=3;break}throw new Error("ValueErrors.Ref: Cannot find schema with $id '".concat(e.$ref,"'."));case 3:return a.delegateYield(Q(i,t,n,r),"t0",4);case 4:case"end":return a.stop()}}),g)}function W(e,t,n,r){var i;return lh.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:if(void 0!==(i=t.find((function(t){return t.$id===e.$ref})))){a.next=3;break}throw new Error("ValueErrors.Self: Cannot find schema with $id '".concat(e.$ref,"'."));case 3:return a.delegateYield(Q(i,t,n,r),"t0",4);case 4:case"end":return a.stop()}}),b)}function $(e,n,i,a){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("string"==typeof a){n.next=4;break}return n.next=3,{type:t.String,schema:e,path:i,value:a,message:"Expected string"};case 3:return n.abrupt("return",n.sent);case 4:if(void 0===e.minLength||a.length>=e.minLength){n.next=7;break}return n.next=7,{type:t.StringMinLength,schema:e,path:i,value:a,message:"Expected string length greater or equal to ".concat(e.minLength)};case 7:if(void 0===e.maxLength||a.length<=e.maxLength){n.next=10;break}return n.next=10,{type:t.StringMaxLength,schema:e,path:i,value:a,message:"Expected string length less or equal to ".concat(e.maxLength)};case 10:if(void 0===e.pattern){n.next=15;break}if(new RegExp(e.pattern).test(a)){n.next=15;break}return n.next=15,{type:t.StringPattern,schema:e,path:i,value:a,message:"Expected string to match pattern ".concat(e.pattern)};case 15:if(void 0===e.format){n.next=25;break}if(r.Format.Has(e.format)){n.next=21;break}return n.next=19,{type:t.StringFormatUnknown,schema:e,path:i,value:a,message:"Unknown string format '".concat(e.format,"'")};case 19:n.next=25;break;case 21:if(r.Format.Get(e.format)(a)){n.next=25;break}return n.next=25,{type:t.StringFormat,schema:e,path:i,value:a,message:"Expected string to match format '".concat(e.format,"'")};case 25:case"end":return n.stop()}}),w)}function K(e,n,r,i){var a;return lh.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(globalThis.Array.isArray(i)){o.next=4;break}return o.next=3,{type:t.Array,schema:e,path:r,value:i,message:"Expected Array"};case 3:return o.abrupt("return",o.sent);case 4:if(void 0!==e.items||0===i.length){o.next=8;break}return o.next=7,{type:t.TupleZeroLength,schema:e,path:r,value:i,message:"Expected tuple to have 0 elements"};case 7:return o.abrupt("return",o.sent);case 8:if(i.length===e.maxItems){o.next=11;break}return o.next=11,{type:t.TupleLength,schema:e,path:r,value:i,message:"Expected tuple to have ".concat(e.maxItems," elements")};case 11:if(e.items){o.next=13;break}return o.abrupt("return");case 13:a=0;case 14:if(!(a<e.items.length)){o.next=19;break}return o.delegateYield(Q(e.items[a],n,"".concat(r,"/").concat(a),i[a]),"t0",16);case 16:a++,o.next=14;break;case 19:case"end":return o.stop()}}),k)}function H(e,n,r,i){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(void 0===i){n.next=3;break}return n.next=3,{type:t.Undefined,schema:e,path:r,value:i,message:"Expected undefined"};case 3:case"end":return n.stop()}}),x)}function G(e,n,r,i){var a,o,s,u,c,l,f,d;return lh.wrap((function(p){for(;;)switch(p.prev=p.next){case 0:a=[],o=GR(e.anyOf),p.prev=2,o.s();case 4:if((s=o.n()).done){p.next=12;break}if(u=s.value,0!==(c=UR(Q(u,n,r,i))).length){p.next=9;break}return p.abrupt("return");case 9:a.push.apply(a,UR(c));case 10:p.next=4;break;case 12:p.next=17;break;case 14:p.prev=14,p.t0=p.catch(2),o.e(p.t0);case 17:return p.prev=17,o.f(),p.finish(17);case 20:l=0,f=a;case 21:if(!(l<f.length)){p.next=28;break}return d=f[l],p.next=25,d;case 25:l++,p.next=21;break;case 28:if(!(a.length>0)){p.next=31;break}return p.next=31,{type:t.Union,schema:e,path:r,value:i,message:"Expected value of union"};case 31:case"end":return p.stop()}}),_,null,[[2,14,17,20]])}function V(e,n,r,i){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(i instanceof globalThis.Uint8Array){n.next=4;break}return n.next=3,{type:t.Uint8Array,schema:e,path:r,value:i,message:"Expected Uint8Array"};case 3:return n.abrupt("return",n.sent);case 4:if(!e.maxByteLength||i.length<=e.maxByteLength){n.next=7;break}return n.next=7,{type:t.Uint8ArrayMaxByteLength,schema:e,path:r,value:i,message:"Expected Uint8Array to have a byte length less or equal to ".concat(e.maxByteLength)};case 7:if(!e.minByteLength||i.length>=e.minByteLength){n.next=10;break}return n.next=10,{type:t.Uint8ArrayMinByteLength,schema:e,path:r,value:i,message:"Expected Uint8Array to have a byte length greater or equal to ".concat(e.maxByteLength)};case 10:case"end":return n.stop()}}),S)}function Y(e,t,n,r){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),O)}function J(e,n,r,i){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(null===i){n.next=4;break}return n.next=3,{type:t.Void,schema:e,path:r,value:i,message:"Expected null"};case 3:return n.abrupt("return",n.sent);case 4:case"end":return n.stop()}}),E)}function Q(e,t,r,a){var o,s;return lh.wrap((function(u){for(;;)switch(u.prev=u.next){case 0:o=void 0===e.$id?t:[e].concat(UR(t)),s=e,u.t0=s[n.Kind],u.next="Any"===u.t0?5:"Array"===u.t0?7:"Boolean"===u.t0?9:"Constructor"===u.t0?11:"Function"===u.t0?13:"Integer"===u.t0?15:"Literal"===u.t0?17:"Never"===u.t0?19:"Null"===u.t0?21:"Number"===u.t0?23:"Object"===u.t0?25:"Promise"===u.t0?27:"Record"===u.t0?29:"Ref"===u.t0?31:"Self"===u.t0?33:"String"===u.t0?35:"Tuple"===u.t0?37:"Undefined"===u.t0?39:"Union"===u.t0?41:"Uint8Array"===u.t0?43:"Unknown"===u.t0?45:"Void"===u.t0?47:49;break;case 5:return u.delegateYield(I(),"t1",6);case 6:return u.abrupt("return",u.t1);case 7:return u.delegateYield(C(s,o,r,a),"t2",8);case 8:return u.abrupt("return",u.t2);case 9:return u.delegateYield(P(s,0,r,a),"t3",10);case 10:return u.abrupt("return",u.t3);case 11:return u.delegateYield(A(s,o,r,a),"t4",12);case 12:return u.abrupt("return",u.t4);case 13:return u.delegateYield(j(s,0,r,a),"t5",14);case 14:return u.abrupt("return",u.t5);case 15:return u.delegateYield(M(s,0,r,a),"t6",16);case 16:return u.abrupt("return",u.t6);case 17:return u.delegateYield(L(s,0,r,a),"t7",18);case 18:return u.abrupt("return",u.t7);case 19:return u.delegateYield(U(s,0,r,a),"t8",20);case 20:return u.abrupt("return",u.t8);case 21:return u.delegateYield(N(s,0,r,a),"t9",22);case 22:return u.abrupt("return",u.t9);case 23:return u.delegateYield(F(s,0,r,a),"t10",24);case 24:return u.abrupt("return",u.t10);case 25:return u.delegateYield(D(s,o,r,a),"t11",26);case 26:return u.abrupt("return",u.t11);case 27:return u.delegateYield(q(s,0,r,a),"t12",28);case 28:return u.abrupt("return",u.t12);case 29:return u.delegateYield(B(s,o,r,a),"t13",30);case 30:return u.abrupt("return",u.t13);case 31:return u.delegateYield(z(s,o,r,a),"t14",32);case 32:return u.abrupt("return",u.t14);case 33:return u.delegateYield(W(s,o,r,a),"t15",34);case 34:return u.abrupt("return",u.t15);case 35:return u.delegateYield($(s,0,r,a),"t16",36);case 36:return u.abrupt("return",u.t16);case 37:return u.delegateYield(K(s,o,r,a),"t17",38);case 38:return u.abrupt("return",u.t17);case 39:return u.delegateYield(H(s,0,r,a),"t18",40);case 40:return u.abrupt("return",u.t18);case 41:return u.delegateYield(G(s,o,r,a),"t19",42);case 42:return u.abrupt("return",u.t19);case 43:return u.delegateYield(V(s,0,r,a),"t20",44);case 44:return u.abrupt("return",u.t20);case 45:return u.delegateYield(Y(),"t21",46);case 46:return u.abrupt("return",u.t21);case 47:return u.delegateYield(J(s,0,r,a),"t22",48);case 48:return u.abrupt("return",u.t22);case 49:throw new i(e);case 50:case"end":return u.stop()}}),T)}function X(e,t,n){return lh.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.delegateYield(Q(e,t,"",n),"t0",1);case 1:case"end":return r.stop()}}),R)}e.Errors=X}(e.ValueErrors||(e.ValueErrors={}))}($R),function(e){var n=t&&t.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),r=t&&t.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(e,"__esModule",{value:!0}),r($R,e)}(WR);var JR={},QR={},XR={};function ZR(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 eI(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 eI(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function eI(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 tI(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}function nI(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 rI(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 rI(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function rI(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 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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.TypeGuard=e.TypeGuardInvalidTypeError=void 0;var t=NR,n=function(e){Qu(n,e);var t=tI(n);function n(e){var r;return rc(this,n),(r=t.call(this,"TypeGuard: Invalid type")).schema=e,r}return nc(n)}(NT(Error));e.TypeGuardInvalidTypeError=n,function(e){function r(e){return"object"===Xu(e)&&null!==e&&!Array.isArray(e)}function i(e){return"object"===Xu(e)&&null!==e&&Array.isArray(e)}function a(e){try{return new RegExp(e),!0}catch(e){return!1}}function o(e){if("string"!=typeof e)return!1;for(var t=0;t<e.length;t++){var n=e.charCodeAt(t);if(n>=7&&n<=13||27===n||127===n)return!1}return!0}function s(e){return"string"==typeof e}function u(e){return"number"==typeof e}function c(e){return"boolean"==typeof e}function l(e){return void 0===e||void 0!==e&&u(e)}function f(e){return void 0===e||void 0!==e&&c(e)}function d(e){return void 0===e||void 0!==e&&s(e)}function p(e){return r(e)&&"Any"===e[t.Kind]&&d(e.$id)}function h(e){return r(e)&&"Array"===e[t.Kind]&&"array"===e.type&&d(e.$id)&&L(e.items)&&l(e.minItems)&&l(e.maxItems)&&f(e.uniqueItems)}function v(e){return r(e)&&"Boolean"===e[t.Kind]&&"boolean"===e.type&&d(e.$id)}function y(e){if(!(r(e)&&"Constructor"===e[t.Kind]&&"constructor"===e.type&&d(e.$id)&&i(e.parameters)&&L(e.returns)))return!1;var n,a=ZR(e.parameters);try{for(a.s();!(n=a.n()).done;){if(!L(n.value))return!1}}catch(e){a.e(e)}finally{a.f()}return!0}function m(e){if(!(r(e)&&"Function"===e[t.Kind]&&"function"===e.type&&d(e.$id)&&i(e.parameters)&&L(e.returns)))return!1;var n,a=ZR(e.parameters);try{for(a.s();!(n=a.n()).done;){if(!L(n.value))return!1}}catch(e){a.e(e)}finally{a.f()}return!0}function g(e){return r(e)&&"Integer"===e[t.Kind]&&"integer"===e.type&&d(e.$id)&&l(e.multipleOf)&&l(e.minimum)&&l(e.maximum)&&l(e.exclusiveMinimum)&&l(e.exclusiveMaximum)}function b(e){return r(e)&&"Literal"===e[t.Kind]&&d(e.$id)&&(s(e.const)||u(e.const)||c(e.const))}function w(e){return r(e)&&"Never"===e[t.Kind]&&i(e.allOf)&&2===e.allOf.length&&r(e.allOf[0])&&s(e.allOf[0].type)&&"boolean"===e.allOf[0].type&&!1===e.allOf[0].const&&r(e.allOf[1])&&s(e.allOf[1].type)&&"boolean"===e.allOf[1].type&&!0===e.allOf[1].const}function k(e){return r(e)&&"Null"===e[t.Kind]&&"null"===e.type&&d(e.$id)}function x(e){return r(e)&&"Number"===e[t.Kind]&&"number"===e.type&&d(e.$id)&&l(e.multipleOf)&&l(e.minimum)&&l(e.maximum)&&l(e.exclusiveMinimum)&&l(e.exclusiveMaximum)}function _(e){if(!(r(e)&&"Object"===e[t.Kind]&&"object"===e.type&&d(e.$id)&&r(e.properties)&&f(e.additionalProperties)&&l(e.minProperties)&&l(e.maxProperties)))return!1;for(var n=0,i=Object.entries(e.properties);n<i.length;n++){var a=Gx(i[n],2),s=a[0],u=a[1];if(!o(s))return!1;if(!L(u))return!1}return!0}function S(e){return r(e)&&"Promise"===e[t.Kind]&&"promise"===e.type&&d(e.$id)&&L(e.item)}function O(e){if(!(r(e)&&"Record"===e[t.Kind]&&"object"===e.type&&d(e.$id)&&!1===e.additionalProperties&&r(e.patternProperties)))return!1;var n=Object.keys(e.patternProperties);return 1===n.length&&(!!a(n[0])&&!!L(e.patternProperties[n[0]]))}function E(e){return r(e)&&"Self"===e[t.Kind]&&d(e.$id)&&s(e.$ref)}function T(e){return r(e)&&"Ref"===e[t.Kind]&&d(e.$id)&&s(e.$ref)}function R(e){return r(e)&&"String"===e[t.Kind]&&"string"===e.type&&d(e.$id)&&l(e.minLength)&&l(e.maxLength)&&(void 0===(n=e.pattern)||void 0!==n&&s(n)&&o(n)&&a(n))&&function(e){return void 0===e||void 0!==e&&s(e)&&o(e)}(e.format);var n}function I(e){if(!(r(e)&&"Tuple"===e[t.Kind]&&"array"===e.type&&d(e.$id)&&u(e.minItems)&&u(e.maxItems)&&e.minItems===e.maxItems))return!1;if(void 0===e.items&&void 0===e.additionalItems&&0===e.minItems)return!0;if(!i(e.items))return!1;var n,a=ZR(e.items);try{for(a.s();!(n=a.n()).done;){if(!L(n.value))return!1}}catch(e){a.e(e)}finally{a.f()}return!0}function C(e){return r(e)&&"Undefined"===e[t.Kind]&&"object"===e.type&&d(e.$id)&&"Undefined"===e.specialized}function P(e){if(!(r(e)&&"Union"===e[t.Kind]&&i(e.anyOf)&&d(e.$id)))return!1;var n,a=ZR(e.anyOf);try{for(a.s();!(n=a.n()).done;){if(!L(n.value))return!1}}catch(e){a.e(e)}finally{a.f()}return!0}function A(e){return r(e)&&"Uint8Array"===e[t.Kind]&&"object"===e.type&&d(e.$id)&&"Uint8Array"===e.specialized&&l(e.minByteLength)&&l(e.maxByteLength)}function j(e){return r(e)&&"Unknown"===e[t.Kind]&&d(e.$id)}function M(e){return r(e)&&"Void"===e[t.Kind]&&"null"===e.type&&d(e.$id)}function L(e){return p(e)||h(e)||v(e)||y(e)||m(e)||g(e)||b(e)||w(e)||k(e)||x(e)||_(e)||S(e)||O(e)||E(e)||T(e)||R(e)||I(e)||C(e)||P(e)||A(e)||j(e)||M(e)}e.TAny=p,e.TArray=h,e.TBoolean=v,e.TConstructor=y,e.TFunction=m,e.TInteger=g,e.TLiteral=b,e.TNever=w,e.TNull=k,e.TNumber=x,e.TObject=_,e.TPromise=S,e.TRecord=O,e.TSelf=E,e.TRef=T,e.TString=R,e.TTuple=I,e.TUndefined=C,e.TUnion=P,e.TUint8Array=A,e.TUnknown=j,e.TVoid=M,e.TSchema=L,e.Assert=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];if(!L(e))throw new n(e);var r,i=ZR(t);try{for(i.s();!(r=i.n()).done;){var a=r.value;if(!L(a))throw new n(a)}}catch(e){i.e(e)}finally{i.f()}}}(e.TypeGuard||(e.TypeGuard={}))}(XR),function(e){var n=t&&t.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),r=t&&t.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(e,"__esModule",{value:!0}),r(XR,e)}(QR),function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.TypeCompiler=e.TypeCompilerUnknownTypeError=e.Property=e.TypeCheck=void 0;var t,n=WR,r=QR,i=KR,a=NR,o=function(){function e(t,n,r,i){rc(this,e),this.schema=t,this.references=n,this.checkFunc=r,this.code=i}return nc(e,[{key:"Code",value:function(){return this.code}},{key:"Errors",value:function(e){return n.ValueErrors.Errors(this.schema,this.references,e)}},{key:"Check",value:function(e){return this.checkFunc(e)}}]),e}();e.TypeCheck=o,function(e){function t(e){return 36===e}function n(e){return 95===e}function r(e){return e>=48&&e<=57}function i(e){return e>=65&&e<=90||e>=97&&e<=122}e.Check=function(e){if(0===e.length)return!1;var a=e.charCodeAt(0);if(!(t(a)||n(a)||i(a)))return!1;for(var o=1;o<e.length;o++){var s=e.charCodeAt(o);if(!(t(s)||n(s)||i(s)||r(s)))return!1}return!0}}(t=e.Property||(e.Property={}));var s=function(e){Qu(n,e);var t=iI(n);function n(e){var r;return rc(this,n),(r=t.call(this,"TypeCompiler: Unknown type")).schema=e,r}return nc(n)}(NT(Error));e.TypeCompilerUnknownTypeError=s,function(e){var n=lh.mark(C),u=lh.mark(P),c=lh.mark(A),l=lh.mark(j),f=lh.mark(M),d=lh.mark(L),p=lh.mark(U),h=lh.mark(N),v=lh.mark(F),y=lh.mark(D),m=lh.mark(q),g=lh.mark(B),b=lh.mark(z),w=lh.mark(W),k=lh.mark($),x=lh.mark(K),_=lh.mark(H),S=lh.mark(G),O=lh.mark(V),E=lh.mark(Y),T=lh.mark(J),R=lh.mark(Q),I=lh.mark(X);function C(e,t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,"(true)";case 2:case"end":return e.stop()}}),n)}function P(e,t){var n;return lh.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(n=ie(e.items,"value"),void 0===e.minItems){r.next=4;break}return r.next=4,"(".concat(t,".length >= ").concat(e.minItems,")");case 4:if(void 0===e.maxItems){r.next=7;break}return r.next=7,"(".concat(t,".length <= ").concat(e.maxItems,")");case 7:if(void 0===e.uniqueItems){r.next=10;break}return r.next=10,"(new Set(".concat(t,").size === ").concat(t,".length)");case 10:return r.next=12,"(Array.isArray(".concat(t,") && ").concat(t,".every(value => ").concat(n,"))");case 12:case"end":return r.stop()}}),u)}function A(e,t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,"(typeof ".concat(t," === 'boolean')");case 2:case"end":return e.stop()}}),c)}function j(e,t){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.delegateYield(X(e.returns,"".concat(t,".prototype")),"t0",1);case 1:case"end":return n.stop()}}),l)}function M(e,t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,"(typeof ".concat(t," === 'function')");case 2:case"end":return e.stop()}}),f)}function L(e,t){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,"(typeof ".concat(t," === 'number' && Number.isInteger(").concat(t,"))");case 2:if(void 0===e.multipleOf){n.next=5;break}return n.next=5,"(".concat(t," % ").concat(e.multipleOf," === 0)");case 5:if(void 0===e.exclusiveMinimum){n.next=8;break}return n.next=8,"(".concat(t," > ").concat(e.exclusiveMinimum,")");case 8:if(void 0===e.exclusiveMaximum){n.next=11;break}return n.next=11,"(".concat(t," < ").concat(e.exclusiveMaximum,")");case 11:if(void 0===e.minimum){n.next=14;break}return n.next=14,"(".concat(t," >= ").concat(e.minimum,")");case 14:if(void 0===e.maximum){n.next=17;break}return n.next=17,"(".concat(t," <= ").concat(e.maximum,")");case 17:case"end":return n.stop()}}),d)}function U(e,t){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("number"!=typeof e.const&&"boolean"!=typeof e.const){n.next=5;break}return n.next=3,"(".concat(t," === ").concat(e.const,")");case 3:n.next=7;break;case 5:return n.next=7,"(".concat(t," === '").concat(e.const,"')");case 7:case"end":return n.stop()}}),p)}function N(e,t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,"(false)";case 2:case"end":return e.stop()}}),h)}function F(e,t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,"(".concat(t," === null)");case 2:case"end":return e.stop()}}),v)}function D(e,t){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,"(typeof ".concat(t," === 'number')");case 2:if(void 0===e.multipleOf){n.next=5;break}return n.next=5,"(".concat(t," % ").concat(e.multipleOf," === 0)");case 5:if(void 0===e.exclusiveMinimum){n.next=8;break}return n.next=8,"(".concat(t," > ").concat(e.exclusiveMinimum,")");case 8:if(void 0===e.exclusiveMaximum){n.next=11;break}return n.next=11,"(".concat(t," < ").concat(e.exclusiveMaximum,")");case 11:if(void 0===e.minimum){n.next=14;break}return n.next=14,"(".concat(t," >= ").concat(e.minimum,")");case 14:if(void 0===e.maximum){n.next=17;break}return n.next=17,"(".concat(t," <= ").concat(e.maximum,")");case 17:case"end":return n.stop()}}),y)}function q(e,n){var r,i,a,o,s,u,c,l;return lh.wrap((function(f){for(;;)switch(f.prev=f.next){case 0:return f.next=2,"(typeof ".concat(n," === 'object' && ").concat(n," !== null && !Array.isArray(").concat(n,"))");case 2:if(void 0===e.minProperties){f.next=5;break}return f.next=5,"(Object.keys(".concat(n,").length >= ").concat(e.minProperties,")");case 5:if(void 0===e.maxProperties){f.next=8;break}return f.next=8,"(Object.keys(".concat(n,").length <= ").concat(e.maxProperties,")");case 8:if(r=globalThis.Object.keys(e.properties),!1!==e.additionalProperties){f.next=18;break}if(!e.required||e.required.length!==r.length){f.next=15;break}return f.next=13,"(Object.keys(".concat(n,").length === ").concat(r.length,")");case 13:f.next=18;break;case 15:return i="[".concat(r.map((function(e){return"'".concat(e,"'")})).join(", "),"]"),f.next=18,"(Object.keys(".concat(n,").every(key => ").concat(i,".includes(key)))");case 18:a=nI(r),f.prev=19,a.s();case 21:if((o=a.n()).done){f.next=34;break}if(s=o.value,u=t.Check(s)?"".concat(n,".").concat(s):"".concat(n,"['").concat(s,"']"),c=e.properties[s],!e.required||!e.required.includes(s)){f.next=29;break}return f.delegateYield(X(c,u),"t0",27);case 27:f.next=32;break;case 29:return l=ie(c,u),f.next=32,"(".concat(u," === undefined ? true : (").concat(l,"))");case 32:f.next=21;break;case 34:f.next=39;break;case 36:f.prev=36,f.t1=f.catch(19),a.e(f.t1);case 39:return f.prev=39,a.f(),f.finish(39);case 42:case"end":return f.stop()}}),m,null,[[19,36,39,42]])}function B(e,t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,"(typeof value === 'object' && typeof ".concat(t,".then === 'function')");case 2:case"end":return e.stop()}}),g)}function z(e,t){var n,r,i,a,o;return lh.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,"(typeof ".concat(t," === 'object' && ").concat(t," !== null && !Array.isArray(").concat(t,"))");case 2:return n=Gx(globalThis.Object.entries(e.patternProperties)[0],2),r=n[0],i=n[1],a=se("new RegExp(/".concat(r,"/)")),s.next=6,"(Object.keys(".concat(t,").every(key => ").concat(a,".test(key)))");case 6:return o=ie(i,"value"),s.next=9,"(Object.values(".concat(t,").every(value => ").concat(o,"))");case 9:case"end":return s.stop()}}),b)}function W(e,t){var n;return lh.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(!te.has(e.$ref)){r.next=4;break}return r.next=3,"(".concat(ae(e.$ref),"(").concat(t,"))");case 3:return r.abrupt("return",r.sent);case 4:if(Z.has(e.$ref)){r.next=6;break}throw Error("TypeCompiler.Ref: Cannot de-reference schema with $id '".concat(e.$ref,"'"));case 6:return n=Z.get(e.$ref),r.delegateYield(X(n,t),"t0",8);case 8:case"end":return r.stop()}}),w)}function $(e,t){var n;return lh.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=ae(e.$ref),r.next=3,"(".concat(n,"(").concat(t,"))");case 3:case"end":return r.stop()}}),k)}function K(e,t){var n;return lh.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,"(typeof ".concat(t," === 'string')");case 2:if(void 0===e.minLength){r.next=5;break}return r.next=5,"(".concat(t,".length >= ").concat(e.minLength,")");case 5:if(void 0===e.maxLength){r.next=8;break}return r.next=8,"(".concat(t,".length <= ").concat(e.maxLength,")");case 8:if(void 0===e.pattern){r.next=12;break}return n=se("new RegExp(/".concat(e.pattern,"/);")),r.next=12,"(".concat(n,".test(").concat(t,"))");case 12:if(void 0===e.format){r.next=15;break}return r.next=15,"(format('".concat(e.format,"', ").concat(t,"))");case 15:case"end":return r.stop()}}),x)}function H(e,t){var n,r;return lh.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,"(Array.isArray(".concat(t,"))");case 2:if(void 0!==e.items){i.next=6;break}return i.next=5,"(".concat(t,".length === 0)");case 5:return i.abrupt("return",i.sent);case 6:return i.next=8,"(".concat(t,".length === ").concat(e.maxItems,")");case 8:n=0;case 9:if(!(n<e.items.length)){i.next=16;break}return r=ie(e.items[n],"".concat(t,"[").concat(n,"]")),i.next=13,"(".concat(r,")");case 13:n++,i.next=9;break;case 16:case"end":return i.stop()}}),_)}function G(e,t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,"(".concat(t," === undefined)");case 2:case"end":return e.stop()}}),S)}function V(e,t){var n;return lh.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.anyOf.map((function(e){return ie(e,t)})),r.next=3,"(".concat(n.join(" || "),")");case 3:case"end":return r.stop()}}),O)}function Y(e,t){return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,"(".concat(t," instanceof Uint8Array)");case 2:if(!e.maxByteLength){n.next=5;break}return n.next=5,"(".concat(t,".length <= ").concat(e.maxByteLength,")");case 5:if(!e.minByteLength){n.next=8;break}return n.next=8,"(".concat(t,".length >= ").concat(e.minByteLength,")");case 8:case"end":return n.stop()}}),E)}function J(e,t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,"(true)";case 2:case"end":return e.stop()}}),T)}function Q(e,t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,"(".concat(t," === null)");case 2:case"end":return e.stop()}}),R)}function X(e,t){var n,r,i;return lh.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(!e.$id||te.has(e.$id)){o.next=8;break}return te.add(e.$id),n=ae(e.$id),r=oe(n,e,"value"),u=r,ee.add(u),o.next=7,"(".concat(n,"(").concat(t,"))");case 7:return o.abrupt("return");case 8:i=e,o.t0=i[a.Kind],o.next="Any"===o.t0?12:"Array"===o.t0?14:"Boolean"===o.t0?16:"Constructor"===o.t0?18:"Function"===o.t0?20:"Integer"===o.t0?22:"Literal"===o.t0?24:"Never"===o.t0?26:"Null"===o.t0?28:"Number"===o.t0?30:"Object"===o.t0?32:"Promise"===o.t0?34:"Record"===o.t0?36:"Ref"===o.t0?38:"Self"===o.t0?40:"String"===o.t0?42:"Tuple"===o.t0?44:"Undefined"===o.t0?46:"Union"===o.t0?48:"Uint8Array"===o.t0?50:"Unknown"===o.t0?52:"Void"===o.t0?54:56;break;case 12:return o.delegateYield(C(),"t1",13);case 13:return o.abrupt("return",o.t1);case 14:return o.delegateYield(P(i,t),"t2",15);case 15:return o.abrupt("return",o.t2);case 16:return o.delegateYield(A(0,t),"t3",17);case 17:return o.abrupt("return",o.t3);case 18:return o.delegateYield(j(i,t),"t4",19);case 19:return o.abrupt("return",o.t4);case 20:return o.delegateYield(M(0,t),"t5",21);case 21:return o.abrupt("return",o.t5);case 22:return o.delegateYield(L(i,t),"t6",23);case 23:return o.abrupt("return",o.t6);case 24:return o.delegateYield(U(i,t),"t7",25);case 25:return o.abrupt("return",o.t7);case 26:return o.delegateYield(N(),"t8",27);case 27:return o.abrupt("return",o.t8);case 28:return o.delegateYield(F(0,t),"t9",29);case 29:return o.abrupt("return",o.t9);case 30:return o.delegateYield(D(i,t),"t10",31);case 31:return o.abrupt("return",o.t10);case 32:return o.delegateYield(q(i,t),"t11",33);case 33:return o.abrupt("return",o.t11);case 34:return o.delegateYield(B(0,t),"t12",35);case 35:return o.abrupt("return",o.t12);case 36:return o.delegateYield(z(i,t),"t13",37);case 37:return o.abrupt("return",o.t13);case 38:return o.delegateYield(W(i,t),"t14",39);case 39:return o.abrupt("return",o.t14);case 40:return o.delegateYield($(i,t),"t15",41);case 41:return o.abrupt("return",o.t15);case 42:return o.delegateYield(K(i,t),"t16",43);case 43:return o.abrupt("return",o.t16);case 44:return o.delegateYield(H(i,t),"t17",45);case 45:return o.abrupt("return",o.t17);case 46:return o.delegateYield(G(0,t),"t18",47);case 47:return o.abrupt("return",o.t18);case 48:return o.delegateYield(V(i,t),"t19",49);case 49:return o.abrupt("return",o.t19);case 50:return o.delegateYield(Y(i,t),"t20",51);case 51:return o.abrupt("return",o.t20);case 52:return o.delegateYield(J(),"t21",53);case 53:return o.abrupt("return",o.t21);case 54:return o.delegateYield(Q(0,t),"t22",55);case 55:return o.abrupt("return",o.t22);case 56:throw new s(e);case 57:case"end":return o.stop()}var u}),I)}var Z=new Map,ee=new Set,te=new Set;function ne(){Z.clear(),ee.clear(),te.clear()}function re(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=nI(t);try{for(n.s();!(e=n.n()).done;){var r=e.value;if(!r.$id)throw new Error("TypeCompiler: Referenced schemas must specify an $id.");if(Z.has(r.$id))throw new Error("TypeCompiler: Duplicate schema $id found for '".concat(r.$id,"'"));Z.set(r.$id,r)}}catch(e){n.e(e)}finally{n.f()}}function ie(e,t){return UR(X(e,t)).join(" && ")}function ae(e){return"check_".concat(e.replace(/-/g,"_"))}function oe(e,t,n){var r=UR(X(t,n)).map((function(e){return" ".concat(e)})).join(" &&\n");return"function ".concat(e,"(value) {\n return (\n").concat(r,"\n )\n}")}function se(e){var t="local_".concat(ee.size);return ee.add("const ".concat(t," = ").concat(e)),t}function ue(){return UR(ee.values())}function ce(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];ne(),re(t);var n=oe("check",e,"value"),r=ue();return"".concat(r.join("\n"),"\nreturn ").concat(n)}e.Compile=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];r.TypeGuard.Assert(e,t);var n=ce(e,t),a=globalThis.Function("format",n),s=a((function(e,t){return!!i.Format.Has(e)&&i.Format.Get(e)(t)}));return new o(e,t,s,n)}}(e.TypeCompiler||(e.TypeCompiler={}))}(JR),function(e){var n=t&&t.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),r=t&&t.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.ValueErrorType=void 0;var i=WR;Object.defineProperty(e,"ValueErrorType",{enumerable:!0,get:function(){return i.ValueErrorType}}),r(JR,e)}(zR);var aI=o,oI=ot("iterator"),sI=!aI((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[oI]||"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})),uI=Zt.exports,cI=jt,lI=s,fI=C,dI=f,pI=o,hI=ra,vI=Rr,yI=d,mI=Be,gI=L,bI=Object.assign,wI=Object.defineProperty,kI=fI([].concat),xI=!bI||pI((function(){if(lI&&1!==bI({b:1},bI(wI({},"a",{enumerable:!0,get:function(){wI(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!=bI({},e)[n]||hI(bI({},t)).join("")!=r}))?function(e,t){for(var n=mI(e),r=arguments.length,i=1,a=vI.f,o=yI.f;r>i;)for(var s,u=gI(arguments[i++]),c=a?kI(hI(u),a(u)):hI(u),l=c.length,f=0;l>f;)s=c[f++],lI&&!dI(o,u,s)||(n[s]=u[s]);return n}:bI,_I=C,SI=2147483647,OI=/[^\0-\u007E]/,EI=/[.\u3002\uFF0E\uFF61]/g,TI="Overflow: input needs wider integers to process",RI=RangeError,II=_I(EI.exec),CI=Math.floor,PI=String.fromCharCode,AI=_I("".charCodeAt),jI=_I([].join),MI=_I([].push),LI=_I("".replace),UI=_I("".split),NI=_I("".toLowerCase),FI=function(e){return e+22+75*(e<26)},DI=function(e,t,n){var r=0;for(e=n?CI(e/700):e>>1,e+=CI(e/t);e>455;)e=CI(e/35),r+=36;return CI(r+36*e/(e+38))},qI=function(e){var t=[];e=function(e){for(var t=[],n=0,r=e.length;n<r;){var i=AI(e,n++);if(i>=55296&&i<=56319&&n<r){var a=AI(e,n++);56320==(64512&a)?MI(t,((1023&i)<<10)+(1023&a)+65536):(MI(t,i),n--)}else MI(t,i)}return t}(e);var n,r,i=e.length,a=128,o=0,s=72;for(n=0;n<e.length;n++)(r=e[n])<128&&MI(t,PI(r));var u=t.length,c=u;for(u&&MI(t,"-");c<i;){var l=SI;for(n=0;n<e.length;n++)(r=e[n])>=a&&r<l&&(l=r);var f=c+1;if(l-a>CI((SI-o)/f))throw RI(TI);for(o+=(l-a)*f,a=l,n=0;n<e.length;n++){if((r=e[n])<a&&++o>SI)throw RI(TI);if(r==a){for(var d=o,p=36;;){var h=p<=s?1:p>=s+26?26:p-s;if(d<h)break;var v=d-h,y=36-h;MI(t,PI(FI(h+v%y))),d=CI(v/y),p+=36}MI(t,PI(FI(d))),s=DI(o,f,c==u),o=0,c++}}o++,a++}return jI(t,"")},BI=Za,zI=Math.floor,WI=function(e,t){var n=e.length,r=zI(n/2);return n<8?$I(e,t):KI(e,WI(BI(e,0,r),t),WI(BI(e,r),t),t)},$I=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},KI=function(e,t,n,r){for(var i=t.length,a=n.length,o=0,s=0;o<i||s<a;)e[o+s]=o<i&&s<a?r(t[o],n[s])<=0?t[o++]:n[s++]:o<i?t[o++]:n[s++];return e},HI=WI,GI=ni,VI=i,YI=f,JI=C,QI=s,XI=sI,ZI=Xn,eC=L_,tC=oi,nC=Rv,rC=Ln,iC=Ec,aC=H,oC=$e,sC=wo,uC=Li,cC=Ft,lC=Y,fC=za,dC=_a,pC=g,hC=bd,vC=dd,yC=jc,mC=HI,gC=ot("iterator"),bC="URLSearchParams",wC="URLSearchParamsIterator",kC=rC.set,xC=rC.getterFor(bC),_C=rC.getterFor(wC),SC=Object.getOwnPropertyDescriptor,OC=function(e){if(!QI)return VI[e];var t=SC(VI,e);return t&&t.value},EC=OC("fetch"),TC=OC("Request"),RC=OC("Headers"),IC=TC&&TC.prototype,CC=RC&&RC.prototype,PC=VI.RegExp,AC=VI.TypeError,jC=VI.decodeURIComponent,MC=VI.encodeURIComponent,LC=JI("".charAt),UC=JI([].join),NC=JI([].push),FC=JI("".replace),DC=JI([].shift),qC=JI([].splice),BC=JI("".split),zC=JI("".slice),WC=/\+/g,$C=Array(4),KC=function(e){return $C[e-1]||($C[e-1]=PC("((?:%[\\da-f]{2}){"+e+"})","gi"))},HC=function(e){try{return jC(e)}catch(t){return e}},GC=function(e){var t=FC(e,WC," "),n=4;try{return jC(t)}catch(e){for(;n;)t=FC(t,KC(n--),HC);return t}},VC=/[!'()~]|%20/g,YC={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+"},JC=function(e){return YC[e]},QC=function(e){return FC(MC(e),VC,JC)},XC=nC((function(e,t){kC(this,{type:wC,iterator:hC(xC(e).entries),kind:t})}),"Iterator",(function(){var e=_C(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}),!0),ZC=function(e){this.entries=[],this.url=null,void 0!==e&&(lC(e)?this.parseObject(e):this.parseQuery("string"==typeof e?"?"===LC(e,0)?zC(e,1):e:fC(e)))};ZC.prototype={type:bC,bindURL:function(e){this.url=e,this.update()},parseObject:function(e){var t,n,r,i,a,o,s,u=vC(e);if(u)for(n=(t=hC(e,u)).next;!(r=YI(n,t)).done;){if(a=(i=hC(cC(r.value))).next,(o=YI(a,i)).done||(s=YI(a,i)).done||!YI(a,i).done)throw AC("Expected sequence with length 2");NC(this.entries,{key:fC(o.value),value:fC(s.value)})}else for(var c in e)oC(e,c)&&NC(this.entries,{key:c,value:fC(e[c])})},parseQuery:function(e){if(e)for(var t,n,r=BC(e,"&"),i=0;i<r.length;)(t=r[i++]).length&&(n=BC(t,"="),NC(this.entries,{key:GC(DC(n)),value:GC(UC(n,"="))}))},serialize:function(){for(var e,t=this.entries,n=[],r=0;r<t.length;)e=t[r++],NC(n,QC(e.key)+"="+QC(e.value));return UC(n,"&")},update:function(){this.entries.length=0,this.parseQuery(this.url.query)},updateURL:function(){this.url&&this.url.update()}};var eP=function(){iC(this,tP);var e=arguments.length>0?arguments[0]:void 0;kC(this,new ZC(e))},tP=eP.prototype;if(eC(tP,{append:function(e,t){yC(arguments.length,2);var n=xC(this);NC(n.entries,{key:fC(e),value:fC(t)}),n.updateURL()},delete:function(e){yC(arguments.length,1);for(var t=xC(this),n=t.entries,r=fC(e),i=0;i<n.length;)n[i].key===r?qC(n,i,1):i++;t.updateURL()},get:function(e){yC(arguments.length,1);for(var t=xC(this).entries,n=fC(e),r=0;r<t.length;r++)if(t[r].key===n)return t[r].value;return null},getAll:function(e){yC(arguments.length,1);for(var t=xC(this).entries,n=fC(e),r=[],i=0;i<t.length;i++)t[i].key===n&&NC(r,t[i].value);return r},has:function(e){yC(arguments.length,1);for(var t=xC(this).entries,n=fC(e),r=0;r<t.length;)if(t[r++].key===n)return!0;return!1},set:function(e,t){yC(arguments.length,1);for(var n,r=xC(this),i=r.entries,a=!1,o=fC(e),s=fC(t),u=0;u<i.length;u++)(n=i[u]).key===o&&(a?qC(i,u--,1):(a=!0,n.value=s));a||NC(i,{key:o,value:s}),r.updateURL()},sort:function(){var e=xC(this);mC(e.entries,(function(e,t){return e.key>t.key?1:-1})),e.updateURL()},forEach:function(e){for(var t,n=xC(this).entries,r=sC(e,arguments.length>1?arguments[1]:void 0),i=0;i<n.length;)r((t=n[i++]).value,t.key,this)},keys:function(){return new XC(this,"keys")},values:function(){return new XC(this,"values")},entries:function(){return new XC(this,"entries")}},{enumerable:!0}),ZI(tP,gC,tP.entries,{name:"entries"}),ZI(tP,"toString",(function(){return xC(this).serialize()}),{enumerable:!0}),tC(eP,bC),GI({global:!0,constructor:!0,forced:!XI},{URLSearchParams:eP}),!XI&&aC(RC)){var nP=JI(CC.has),rP=JI(CC.set),iP=function(e){if(lC(e)){var t,n=e.body;if(uC(n)===bC)return t=e.headers?new RC(e.headers):new RC,nP(t,"content-type")||rP(t,"content-type","application/x-www-form-urlencoded;charset=UTF-8"),dC(e,{body:pC(0,fC(n)),headers:pC(0,t)})}return e};if(aC(EC)&&GI({global:!0,enumerable:!0,dontCallGetSet:!0,forced:!0},{fetch:function(e){return EC(e,arguments.length>1?iP(arguments[1]):{})}}),aC(TC)){var aP=function(e){return iC(this,IC),new TC(e,arguments.length>1?iP(arguments[1]):{})};IC.constructor=aP,aP.prototype=IC,GI({global:!0,constructor:!0,dontCallGetSet:!0,forced:!0},{Request:aP})}}var oP,sP=ni,uP=s,cP=sI,lP=i,fP=wo,dP=C,pP=Xn,hP=function(e,t,n){return n.get&&uI(n.get,t,{getter:!0}),n.set&&uI(n.set,t,{setter:!0}),cI.f(e,t,n)},vP=Ec,yP=$e,mP=xI,gP=$h,bP=Za,wP=rv.codeAt,kP=function(e){var t,n,r=[],i=UI(LI(NI(e),EI,"."),".");for(t=0;t<i.length;t++)n=i[t],MI(r,II(OI,n)?"xn--"+qI(n):n);return jI(r,".")},xP=za,_P=oi,SP=jc,OP={URLSearchParams:eP,getState:xC},EP=Ln,TP=EP.set,RP=EP.getterFor("URL"),IP=OP.URLSearchParams,CP=OP.getState,PP=lP.URL,AP=lP.TypeError,jP=lP.parseInt,MP=Math.floor,LP=Math.pow,UP=dP("".charAt),NP=dP(/./.exec),FP=dP([].join),DP=dP(1..toString),qP=dP([].pop),BP=dP([].push),zP=dP("".replace),WP=dP([].shift),$P=dP("".split),KP=dP("".slice),HP=dP("".toLowerCase),GP=dP([].unshift),VP="Invalid scheme",YP="Invalid host",JP="Invalid port",QP=/[a-z]/i,XP=/[\d+-.a-z]/i,ZP=/\d/,eA=/^0x/i,tA=/^[0-7]+$/,nA=/^\d+$/,rA=/^[\da-f]+$/i,iA=/[\0\t\n\r #%/:<>?@[\\\]^|]/,aA=/[\0\t\n\r #/:<>?@[\\\]^|]/,oA=/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g,sA=/[\t\n\r]/g,uA=function(e){var t,n,r,i;if("number"==typeof e){for(t=[],n=0;n<4;n++)GP(t,e%256),e=MP(e/256);return FP(t,".")}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+=DP(e[n],16),n<7&&(t+=":")));return"["+t+"]"}return e},cA={},lA=mP({},cA,{" ":1,'"':1,"<":1,">":1,"`":1}),fA=mP({},lA,{"#":1,"?":1,"{":1,"}":1}),dA=mP({},fA,{"/":1,":":1,";":1,"=":1,"@":1,"[":1,"\\":1,"]":1,"^":1,"|":1}),pA=function(e,t){var n=wP(e,0);return n>32&&n<127&&!yP(t,e)?e:encodeURIComponent(e)},hA={ftp:21,file:null,http:80,https:443,ws:80,wss:443},vA=function(e,t){var n;return 2==e.length&&NP(QP,UP(e,0))&&(":"==(n=UP(e,1))||!t&&"|"==n)},yA=function(e){var t;return e.length>1&&vA(KP(e,0,2))&&(2==e.length||"/"===(t=UP(e,2))||"\\"===t||"?"===t||"#"===t)},mA=function(e){return"."===e||"%2e"===HP(e)},gA={},bA={},wA={},kA={},xA={},_A={},SA={},OA={},EA={},TA={},RA={},IA={},CA={},PA={},AA={},jA={},MA={},LA={},UA={},NA={},FA={},DA=function(e,t,n){var r,i,a,o=xP(e);if(t){if(i=this.parse(o))throw AP(i);this.searchParams=null}else{if(void 0!==n&&(r=new DA(n,!0)),i=this.parse(o,null,r))throw AP(i);(a=CP(new IP)).bindURL(this),this.searchParams=a}};DA.prototype={type:"URL",parse:function(e,t,n){var r,i,a,o,s,u=this,c=t||gA,l=0,f="",d=!1,p=!1,h=!1;for(e=xP(e),t||(u.scheme="",u.username="",u.password="",u.host=null,u.port=null,u.path=[],u.query=null,u.fragment=null,u.cannotBeABaseURL=!1,e=zP(e,oA,"")),e=zP(e,sA,""),r=gP(e);l<=r.length;){switch(i=r[l],c){case gA:if(!i||!NP(QP,i)){if(t)return VP;c=wA;continue}f+=HP(i),c=bA;break;case bA:if(i&&(NP(XP,i)||"+"==i||"-"==i||"."==i))f+=HP(i);else{if(":"!=i){if(t)return VP;f="",c=wA,l=0;continue}if(t&&(u.isSpecial()!=yP(hA,f)||"file"==f&&(u.includesCredentials()||null!==u.port)||"file"==u.scheme&&!u.host))return;if(u.scheme=f,t)return void(u.isSpecial()&&hA[u.scheme]==u.port&&(u.port=null));f="","file"==u.scheme?c=PA:u.isSpecial()&&n&&n.scheme==u.scheme?c=kA:u.isSpecial()?c=OA:"/"==r[l+1]?(c=xA,l++):(u.cannotBeABaseURL=!0,BP(u.path,""),c=UA)}break;case wA:if(!n||n.cannotBeABaseURL&&"#"!=i)return VP;if(n.cannotBeABaseURL&&"#"==i){u.scheme=n.scheme,u.path=bP(n.path),u.query=n.query,u.fragment="",u.cannotBeABaseURL=!0,c=FA;break}c="file"==n.scheme?PA:_A;continue;case kA:if("/"!=i||"/"!=r[l+1]){c=_A;continue}c=EA,l++;break;case xA:if("/"==i){c=TA;break}c=LA;continue;case _A:if(u.scheme=n.scheme,i==oP)u.username=n.username,u.password=n.password,u.host=n.host,u.port=n.port,u.path=bP(n.path),u.query=n.query;else if("/"==i||"\\"==i&&u.isSpecial())c=SA;else if("?"==i)u.username=n.username,u.password=n.password,u.host=n.host,u.port=n.port,u.path=bP(n.path),u.query="",c=NA;else{if("#"!=i){u.username=n.username,u.password=n.password,u.host=n.host,u.port=n.port,u.path=bP(n.path),u.path.length--,c=LA;continue}u.username=n.username,u.password=n.password,u.host=n.host,u.port=n.port,u.path=bP(n.path),u.query=n.query,u.fragment="",c=FA}break;case SA:if(!u.isSpecial()||"/"!=i&&"\\"!=i){if("/"!=i){u.username=n.username,u.password=n.password,u.host=n.host,u.port=n.port,c=LA;continue}c=TA}else c=EA;break;case OA:if(c=EA,"/"!=i||"/"!=UP(f,l+1))continue;l++;break;case EA:if("/"!=i&&"\\"!=i){c=TA;continue}break;case TA:if("@"==i){d&&(f="%40"+f),d=!0,a=gP(f);for(var v=0;v<a.length;v++){var y=a[v];if(":"!=y||h){var m=pA(y,dA);h?u.password+=m:u.username+=m}else h=!0}f=""}else if(i==oP||"/"==i||"?"==i||"#"==i||"\\"==i&&u.isSpecial()){if(d&&""==f)return"Invalid authority";l-=gP(f).length+1,f="",c=RA}else f+=i;break;case RA:case IA:if(t&&"file"==u.scheme){c=jA;continue}if(":"!=i||p){if(i==oP||"/"==i||"?"==i||"#"==i||"\\"==i&&u.isSpecial()){if(u.isSpecial()&&""==f)return YP;if(t&&""==f&&(u.includesCredentials()||null!==u.port))return;if(o=u.parseHost(f))return o;if(f="",c=MA,t)return;continue}"["==i?p=!0:"]"==i&&(p=!1),f+=i}else{if(""==f)return YP;if(o=u.parseHost(f))return o;if(f="",c=CA,t==IA)return}break;case CA:if(!NP(ZP,i)){if(i==oP||"/"==i||"?"==i||"#"==i||"\\"==i&&u.isSpecial()||t){if(""!=f){var g=jP(f,10);if(g>65535)return JP;u.port=u.isSpecial()&&g===hA[u.scheme]?null:g,f=""}if(t)return;c=MA;continue}return JP}f+=i;break;case PA:if(u.scheme="file","/"==i||"\\"==i)c=AA;else{if(!n||"file"!=n.scheme){c=LA;continue}if(i==oP)u.host=n.host,u.path=bP(n.path),u.query=n.query;else if("?"==i)u.host=n.host,u.path=bP(n.path),u.query="",c=NA;else{if("#"!=i){yA(FP(bP(r,l),""))||(u.host=n.host,u.path=bP(n.path),u.shortenPath()),c=LA;continue}u.host=n.host,u.path=bP(n.path),u.query=n.query,u.fragment="",c=FA}}break;case AA:if("/"==i||"\\"==i){c=jA;break}n&&"file"==n.scheme&&!yA(FP(bP(r,l),""))&&(vA(n.path[0],!0)?BP(u.path,n.path[0]):u.host=n.host),c=LA;continue;case jA:if(i==oP||"/"==i||"\\"==i||"?"==i||"#"==i){if(!t&&vA(f))c=LA;else if(""==f){if(u.host="",t)return;c=MA}else{if(o=u.parseHost(f))return o;if("localhost"==u.host&&(u.host=""),t)return;f="",c=MA}continue}f+=i;break;case MA:if(u.isSpecial()){if(c=LA,"/"!=i&&"\\"!=i)continue}else if(t||"?"!=i)if(t||"#"!=i){if(i!=oP&&(c=LA,"/"!=i))continue}else u.fragment="",c=FA;else u.query="",c=NA;break;case LA:if(i==oP||"/"==i||"\\"==i&&u.isSpecial()||!t&&("?"==i||"#"==i)){if(".."===(s=HP(s=f))||"%2e."===s||".%2e"===s||"%2e%2e"===s?(u.shortenPath(),"/"==i||"\\"==i&&u.isSpecial()||BP(u.path,"")):mA(f)?"/"==i||"\\"==i&&u.isSpecial()||BP(u.path,""):("file"==u.scheme&&!u.path.length&&vA(f)&&(u.host&&(u.host=""),f=UP(f,0)+":"),BP(u.path,f)),f="","file"==u.scheme&&(i==oP||"?"==i||"#"==i))for(;u.path.length>1&&""===u.path[0];)WP(u.path);"?"==i?(u.query="",c=NA):"#"==i&&(u.fragment="",c=FA)}else f+=pA(i,fA);break;case UA:"?"==i?(u.query="",c=NA):"#"==i?(u.fragment="",c=FA):i!=oP&&(u.path[0]+=pA(i,cA));break;case NA:t||"#"!=i?i!=oP&&("'"==i&&u.isSpecial()?u.query+="%27":u.query+="#"==i?"%23":pA(i,cA)):(u.fragment="",c=FA);break;case FA:i!=oP&&(u.fragment+=pA(i,lA))}l++}},parseHost:function(e){var t,n,r;if("["==UP(e,0)){if("]"!=UP(e,e.length-1))return YP;if(t=function(e){var t,n,r,i,a,o,s,u=[0,0,0,0,0,0,0,0],c=0,l=null,f=0,d=function(){return UP(e,f)};if(":"==d()){if(":"!=UP(e,1))return;f+=2,l=++c}for(;d();){if(8==c)return;if(":"!=d()){for(t=n=0;n<4&&NP(rA,d());)t=16*t+jP(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(!NP(ZP,d()))return;for(;NP(ZP,d());){if(a=jP(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(o=c-l,c=7;0!=c&&o>0;)s=u[c],u[c--]=u[l+o-1],u[l+--o]=s;else if(8!=c)return;return u}(KP(e,1,-1)),!t)return YP;this.host=t}else if(this.isSpecial()){if(e=kP(e),NP(iA,e))return YP;if(t=function(e){var t,n,r,i,a,o,s,u=$P(e,".");if(u.length&&""==u[u.length-1]&&u.length--,(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"==UP(i,0)&&(a=NP(eA,i)?16:8,i=KP(i,8==a?1:2)),""===i)o=0;else{if(!NP(10==a?nA:8==a?tA:rA,i))return e;o=jP(i,a)}BP(n,o)}for(r=0;r<t;r++)if(o=n[r],r==t-1){if(o>=LP(256,5-t))return null}else if(o>255)return null;for(s=qP(n),r=0;r<n.length;r++)s+=n[r]*LP(256,3-r);return s}(e),null===t)return YP;this.host=t}else{if(NP(aA,e))return YP;for(t="",n=gP(e),r=0;r<n.length;r++)t+=pA(n[r],cA);this.host=t}},cannotHaveUsernamePasswordPort:function(){return!this.host||this.cannotBeABaseURL||"file"==this.scheme},includesCredentials:function(){return""!=this.username||""!=this.password},isSpecial:function(){return yP(hA,this.scheme)},shortenPath:function(){var e=this.path,t=e.length;!t||"file"==this.scheme&&1==t&&vA(e[0],!0)||e.length--},serialize:function(){var e=this,t=e.scheme,n=e.username,r=e.password,i=e.host,a=e.port,o=e.path,s=e.query,u=e.fragment,c=t+":";return null!==i?(c+="//",e.includesCredentials()&&(c+=n+(r?":"+r:"")+"@"),c+=uA(i),null!==a&&(c+=":"+a)):"file"==t&&(c+="//"),c+=e.cannotBeABaseURL?o[0]:o.length?"/"+FP(o,"/"):"",null!==s&&(c+="?"+s),null!==u&&(c+="#"+u),c},setHref:function(e){var t=this.parse(e);if(t)throw AP(t);this.searchParams.update()},getOrigin:function(){var e=this.scheme,t=this.port;if("blob"==e)try{return new qA(e.path[0]).origin}catch(e){return"null"}return"file"!=e&&this.isSpecial()?e+"://"+uA(this.host)+(null!==t?":"+t:""):"null"},getProtocol:function(){return this.scheme+":"},setProtocol:function(e){this.parse(xP(e)+":",gA)},getUsername:function(){return this.username},setUsername:function(e){var t=gP(xP(e));if(!this.cannotHaveUsernamePasswordPort()){this.username="";for(var n=0;n<t.length;n++)this.username+=pA(t[n],dA)}},getPassword:function(){return this.password},setPassword:function(e){var t=gP(xP(e));if(!this.cannotHaveUsernamePasswordPort()){this.password="";for(var n=0;n<t.length;n++)this.password+=pA(t[n],dA)}},getHost:function(){var e=this.host,t=this.port;return null===e?"":null===t?uA(e):uA(e)+":"+t},setHost:function(e){this.cannotBeABaseURL||this.parse(e,RA)},getHostname:function(){var e=this.host;return null===e?"":uA(e)},setHostname:function(e){this.cannotBeABaseURL||this.parse(e,IA)},getPort:function(){var e=this.port;return null===e?"":xP(e)},setPort:function(e){this.cannotHaveUsernamePasswordPort()||(""==(e=xP(e))?this.port=null:this.parse(e,CA))},getPathname:function(){var e=this.path;return this.cannotBeABaseURL?e[0]:e.length?"/"+FP(e,"/"):""},setPathname:function(e){this.cannotBeABaseURL||(this.path=[],this.parse(e,MA))},getSearch:function(){var e=this.query;return e?"?"+e:""},setSearch:function(e){""==(e=xP(e))?this.query=null:("?"==UP(e,0)&&(e=KP(e,1)),this.query="",this.parse(e,NA)),this.searchParams.update()},getSearchParams:function(){return this.searchParams.facade},getHash:function(){var e=this.fragment;return e?"#"+e:""},setHash:function(e){""!=(e=xP(e))?("#"==UP(e,0)&&(e=KP(e,1)),this.fragment="",this.parse(e,FA)):this.fragment=null},update:function(){this.query=this.searchParams.serialize()||null}};var qA=function(e){var t=vP(this,BA),n=SP(arguments.length,1)>1?arguments[1]:void 0,r=TP(t,new DA(e,!1,n));uP||(t.href=r.serialize(),t.origin=r.getOrigin(),t.protocol=r.getProtocol(),t.username=r.getUsername(),t.password=r.getPassword(),t.host=r.getHost(),t.hostname=r.getHostname(),t.port=r.getPort(),t.pathname=r.getPathname(),t.search=r.getSearch(),t.searchParams=r.getSearchParams(),t.hash=r.getHash())},BA=qA.prototype,zA=function(e,t){return{get:function(){return RP(this)[e]()},set:t&&function(e){return RP(this)[t](e)},configurable:!0,enumerable:!0}};if(uP&&(hP(BA,"href",zA("serialize","setHref")),hP(BA,"origin",zA("getOrigin")),hP(BA,"protocol",zA("getProtocol","setProtocol")),hP(BA,"username",zA("getUsername","setUsername")),hP(BA,"password",zA("getPassword","setPassword")),hP(BA,"host",zA("getHost","setHost")),hP(BA,"hostname",zA("getHostname","setHostname")),hP(BA,"port",zA("getPort","setPort")),hP(BA,"pathname",zA("getPathname","setPathname")),hP(BA,"search",zA("getSearch","setSearch")),hP(BA,"searchParams",zA("getSearchParams")),hP(BA,"hash",zA("getHash","setHash"))),pP(BA,"toJSON",(function(){return RP(this).serialize()}),{enumerable:!0}),pP(BA,"toString",(function(){return RP(this).serialize()}),{enumerable:!0}),PP){var WA=PP.createObjectURL,$A=PP.revokeObjectURL;WA&&pP(qA,"createObjectURL",fP(WA,PP)),$A&&pP(qA,"revokeObjectURL",fP($A,PP))}_P(qA,"URL"),sP({global:!0,constructor:!0,forced:!cP,sham:!uP},{URL:qA});var KA={},HA={},GA=t&&t.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(HA,"__esModule",{value:!0}),HA.StateMachine=void 0;var VA=function(){function e(e){var t,n,r=this;if(this._configuration={},this._listeners=new Set,this._scopeStack=[],"function"!=typeof e)throw new Error("The StateMachine constructor expects a callback as the first argument");if(this._scopeStack.unshift("config"),e({initialState:function(e){r._checkConfigScope(),r._currentState=e},state:function(e,t){r._checkConfigScope();var n={on:{}};r._scopeStack.unshift("state"),t({onEnter:function(e){r._checkStateScope("onEnter"),n.onEnter=e},onExit:function(e){r._checkStateScope("onExit"),n.onExit=e},on:function(e,t){r._checkStateScope("on"),n.on[e]=t}}),r._scopeStack.shift(),r._configuration[e]=n}}),this._scopeStack.shift(),void 0===this._currentState)throw new Error("No initial state provided");if(0===Object.keys(this._configuration).length)throw new Error("No state definition was provided");null===(n=null===(t=this._configuration[this._currentState.type])||void 0===t?void 0:t.onEnter)||void 0===n||n.call(t,{state:this._currentState})}return e.prototype.transition=function(e){var t,n,r,i,a,o=this._configuration[this._currentState.type];if(o){var s=o.on[e.type];if(s){var u=s({state:this._currentState,event:e,transitionTo:function(e,t){return{state:e,sideEffect:null!=t?t:null}},dontTransition:function(e){return{state:null,sideEffect:null!=e?e:null}}}),c=u.state,l=u.sideEffect,f=this._currentState;null!==c&&(null===(r=o.onExit)||void 0===r||r.call(o,{state:this._currentState}),this._currentState=c,null===(a=null===(i=this._configuration[c.type])||void 0===i?void 0:i.onEnter)||void 0===a||a.call(i,{state:c}));try{for(var d=GA(this._listeners),p=d.next();!p.done;p=d.next()){(0,p.value)(f,null!=c?c:f,e)}}catch(e){t={error:e}}finally{try{p&&!p.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}l&&setTimeout((function(){null==l||l()}),0)}}},e.prototype.subscribe=function(e){var t=this;return this._listeners.add(e),e(null,this._currentState,null),function(){t._listeners.delete(e)}},Object.defineProperty(e.prototype,"state",{get:function(){return this._currentState},enumerable:!1,configurable:!0}),e.prototype._checkConfigScope=function(){if("config"!==this._scopeStack[0])throw new Error("Call to `initialState` is allowed only from within the config callback, but not inside a state callback")},e.prototype._checkStateScope=function(e){if("state"!==this._scopeStack[0])throw new Error("Call to `".concat(e,"` is allowed only from within a state callback"))},e}();HA.StateMachine=VA,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.StateMachine=void 0;var t=HA;Object.defineProperty(e,"StateMachine",{enumerable:!0,get:function(){return t.StateMachine}})}(KA),function(e){var t=void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};Object.defineProperty(e,"__esModule",{value:!0});var n=Dw.exports,r=DS.exports,i=$w.exports,a=Ww.exports,o=Vw.exports,s=Kw.exports,u=Gw.exports,c=Yw.exports,l=sx.exports,f=qS,d=BS,p=ix,h=jw.exports,v=ZE.exports,y=eT,m=dR,g=LR,b=NR,w=zR,k=KA;function x(e){return e&&"object"===Xu(e)&&"default"in e?e:{default:e}}function _(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var 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 S,O=x(NS.exports),E=x(n),T=x(r),R=x(i),I=x(a),C=x(o),P=x(s),A=x(u),j=x(c),M=x(l),L=x(f),U=x(h),N=_(v),F=x(m),D=function(){function e(t,n){var r=this,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;R.default(this,e),M.default(this,"message",void 0),M.default(this,"_onFinished",void 0),M.default(this,"_timer",void 0),M.default(this,"_deferredResponse",new d.Deferred),this.message=t,this._onFinished=i,this._timer=setTimeout((function(){var e;if(!r._deferredResponse.isDone){var t=new d.ErrorInfo("timeout","Request timeout: ".concat(r.message.id));r._deferredResponse.reject(new d.TwilioError(t)),null===(e=r._onFinished)||void 0===e||e.call(r,r)}}),n)}return I.default(e,[{key:"complete",value:function(e){var t;this._deferredResponse.isDone||(clearTimeout(this._timer),this._deferredResponse.resolve(e),null===(t=this._onFinished)||void 0===t||t.call(this,this))}},{key:"cancel",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new d.ErrorInfo("cancelled","Request has been cancelled");this._deferredResponse.isDone||(clearTimeout(this._timer),this._deferredResponse.reject(new d.TwilioError(t)),null===(e=this._onFinished)||void 0===e||e.call(this,this))}},{key:"promise",get:function(){return this._deferredResponse.promise}}]),e}(),q=new d.Logger("twilsock","Twilsock"),B=new TextEncoder,z=new TextDecoder;function W(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 $(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 $(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}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}function K(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=j.default(e);if(t){var i=j.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return A.default(this,n)}}var H=null!==(S=t.WebSocket)&&void 0!==S?S:{},G=function(e){P.default(n,e);var t=K(n);function n(){var e;R.default(this,n);for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];return e=t.call.apply(t,[this].concat(i)),M.default(C.default(e),"_webSocket",null),M.default(C.default(e),"_state","disconnected"),M.default(C.default(e),"_listeners",[]),e}return I.default(n,[{key:"connect",value:function(e){var t=this;if(q.info("Call to Transport.connect(".concat(e,")")),"disconnected"===this._state){this._state="connecting";try{this._webSocket=new H(e)}catch(e){return q.error("Error in Transport.connect:",e),void this._doDisconnect(new d.ErrorInfo("unknown","Error in Transport.connect"))}this._webSocket.binaryType="arraybuffer",this._subscribeToEvent("open",(function(){q.info('WebSocket "open" event'),t._state="connected",t.emit("connected")})),this._subscribeToEvent("error",(function(e){q.info('WebSocket "error" event:',e),t._doDisconnect(new d.ErrorInfo("unknown","Failed to connect WebSocket"))})),this._subscribeToEvent("close",(function(e){q.info('WebSocket "close" event:',e),t._doDisconnect(new d.ErrorInfo("transportDisconnected",'WebSocket "close" event received'))})),this._subscribeToEvent("message",(function(e){q.info('WebSocket "message" event:',z.decode(e.data));var n=e.data;n instanceof ArrayBuffer&&t.emit("messageReceived",n)}))}else q.warn('Cannot connect in state "'.concat(this._state,'". Ignored.'))}},{key:"sendMessage",value:function(e){q.info("Call to Transport.sendMessage(".concat(z.decode(e),")"));var t=new Error("Transport is not ready. Call `connect()` first");if(null===this._webSocket)throw t;try{this._webSocket.send(e)}catch(e){throw t}}},{key:"disconnect",value:function(e){this._doDisconnect(new d.ErrorInfo("transportDisconnected","Transport.Disconnect called: ".concat(e)))}},{key:"_doDisconnect",value:function(e){var t;(q.info("Call to Transport.doDisconnect(".concat(e,"): ").concat(this._state)),"disconnected"!==this._state)&&(this._state="disconnected",null===(t=this._webSocket)||void 0===t||t.close(),this._unsubscribeFromListeners(),this.emit("disconnected",e))}},{key:"_subscribeToEvent",value:function(e,t){var n;null===(n=this._webSocket)||void 0===n||n.addEventListener(e,t),this._listeners.push([e,t])}},{key:"_unsubscribeFromListeners",value:function(){var e,t=W(this._listeners);try{for(t.s();!(e=t.n()).done;){var n,r=U.default(e.value,2),i=r[0],a=r[1];null===(n=this._webSocket)||void 0===n||n.removeEventListener(i,a)}}catch(e){t.e(e)}finally{t.f()}this._listeners=[]}}]),n}(p.ReplayEventEmitter);function V(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}var Y=function(e){var t,n,r,i,a,o,s,u;return function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?V(Object(n),!0).forEach((function(t){M.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):V(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({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===(o=N.os)||void 0===o?void 0:o.version)&&void 0!==a?a:"unknown",osa:String(null!==(s=null===(u=N.os)||void 0===u?void 0:u.architecture)&&void 0!==s?s:"unknown"),sdk:"js-default"},e)},J=I.default((function e(t,n,r){var i,a,o,s,u,c,l,f,d,p;R.default(this,e),M.default(this,"retryPolicy",void 0),M.default(this,"url",void 0),M.default(this,"activeGrant",void 0),M.default(this,"logLevel",void 0),M.default(this,"clientMetadata",void 0),M.default(this,"tweaks",void 0),M.default(this,"token",void 0),M.default(this,"continuationToken",void 0),M.default(this,"initRegistrations",void 0);var h=null!==(i=r.region)&&void 0!==i?i:"us1",v="wss://tsock.".concat(h,".twilio.com/v3/wsconnect"),y=null!==(a=null!==(o=r.twilsock)&&void 0!==o?o:r.Twilsock)&&void 0!==a?a:{};this.token=t,this.continuationToken=null!==(s=r.continuationToken)&&void 0!==s?s:null,this.activeGrant=n,this.url=null!==(u=y.uri)&&void 0!==u?u:v,this.logLevel=null!==(c=r.logLevel)&&void 0!==c?c:"error",this.retryPolicy=null!==(l=r.retryPolicy)&&void 0!==l?l:{min:1e3,max:12e4,randomness:.2},this.clientMetadata=Y(null!==(f=r.clientMetadata)&&void 0!==f?f:{}),this.clientMetadata.ver="0.13.1",this.initRegistrations=null!==(d=r.initRegistrations)&&void 0!==d?d:null,this.tweaks=null!==(p=r.tweaks)&&void 0!==p?p:null}));function Q(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=j.default(e);if(t){var i=j.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return A.default(this,n)}}var X=function(e){P.default(r,e);var n=Q(r);function r(){var e;R.default(this,r);for(var t=arguments.length,i=new Array(t),a=0;a<t;a++)i[a]=arguments[a];return e=n.call.apply(n,[this].concat(i)),M.default(C.default(e),"_timer",null),M.default(C.default(e),"_isNetworkAvailable",!0),e}return I.default(r,[{key:"isNetworkAvailable",get:function(){return this._isNetworkAvailable}},{key:"start",value:function(){null===this._timer&&(this.emit("changed",this._isNetworkAvailable),this._checkConnectivity())}},{key:"stop",value:function(){var e;null!==this._timer&&("number"==typeof(e=this._timer)&&"function"==typeof t.clearTimeout?t.clearTimeout(e):function(e){e&&"function"==typeof e.close&&e.close()}(e),this._timer=null)}},{key:"_checkConnectivity",value:function(){var e=this,t=this._isNetworkAvailable;F.default().then((function(t){e._isNetworkAvailable=t})).catch((function(t){q.warn("Error on checking connectivity",t),e._isNetworkAvailable=!1})).finally((function(){t!==e._isNetworkAvailable&&e.emit("changed",e._isNetworkAvailable),e._timer=setTimeout((function(){e._checkConnectivity()}),5e3)}))}}]),r}(p.ReplayEventEmitter),Z=b.Type.Union([b.Type.Literal("init"),b.Type.Literal("update"),b.Type.Literal("ping"),b.Type.Literal("close"),b.Type.Literal("notification"),b.Type.Literal("message"),b.Type.Literal("reply"),b.Type.Literal("client_update")]),ee=b.Type.Object({method:Z,id:b.Type.String(),payload_size:b.Type.Optional(b.Type.Number()),payload_type:b.Type.Optional(b.Type.String())}),te=w.TypeCompiler.Compile(ee);function ne(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 re(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ne(Object(n),!0).forEach((function(t){M.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ne(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var ie="TWILSOCK V3.0",ae=g.customAlphabet("1234567890abcdef",32),Message=function(){function Message(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"RQ".concat(ae());R.default(this,Message),M.default(this,"method",void 0),M.default(this,"headers",void 0),M.default(this,"payloadType",void 0),M.default(this,"payload",void 0),M.default(this,"id",void 0),this.method=e,this.headers=t,this.payloadType=n,this.payload=r,this.id=i}return I.default(Message,[{key:"encode",value:function(){var e,t={method:this.method,id:this.id};""!==this.payload&&(t.payload_size=B.encode(this.payload).length,t.payload_type=this.payloadType);var n=JSON.stringify(re(re({},null!==(e=this.headers)&&void 0!==e?e:{}),t)),r=B.encode(n).length,i=""===this.payload?"":"\r\n";return B.encode("".concat(ie," ").concat(r,"\r\n").concat(n,"\r\n").concat(this.payload).concat(i))}}],[{key:"parse",value:function(e){var t,n=z.decode(e);if(!n.startsWith(ie))throw new Error("Invalid Twilsock prefix");var r=n.split("\r\n"),i=U.default(r,3),a=i[0],o=i[1],s=i[2],u=Number(a.split(" ")[2]);if(o.length!==u)throw new Error("Invalid header size: expected ".concat(u,", got ").concat(o.length));var c=JSON.parse(o);if(!te.Check(c))throw new Error("Invalid headers received");var l=null!==(t=c.payload_type)&&void 0!==t?t:"";return new Message(c.method,c,l,s,c.id)}}]),Message}(),oe=I.default((function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"ers",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:4,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];R.default(this,e),M.default(this,"product",void 0),M.default(this,"type",void 0),M.default(this,"notification_protocol_version",void 0),M.default(this,"message_types",void 0),this.product=t,this.type=n,this.notification_protocol_version=r,this.message_types=i,Object.freeze(i)})),se=b.Type.Object({code:b.Type.Number(),status:b.Type.String(),errorCode:b.Type.Optional(b.Type.Number())}),ue=b.Type.Object({status:se,http_status:b.Type.Optional(se),continuation_token:b.Type.Optional(b.Type.String()),http_headers:b.Type.Optional(b.Type.Record(b.Type.String(),b.Type.String()))}),ce=w.TypeCompiler.Compile(ue),le=b.Type.Object({backoff_policy:b.Type.Optional(b.Type.Object({reconnect_min_ms:b.Type.Optional(b.Type.Number()),reconnect_max_ms:b.Type.Optional(b.Type.Number())}))}),fe=w.TypeCompiler.Compile(le);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=j.default(e);if(t){var i=j.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return A.default(this,n)}}var pe=function(e){P.default(n,e);var t=de(n);function n(e,r,i,a){var o,s,u,c,l,f;if(R.default(this,n),c=t.call(this,"reply",r,i,a,e),M.default(C.default(c),"replyHeaders",void 0),M.default(C.default(c),"replyPayload",void 0),!ce.Check(r))throw new Error("Invalid reply headers passed");c.replyHeaders={status:r.status,httpStatus:null!==(o=r.http_status)&&void 0!==o?o:{code:200,status:"ok"},continuationToken:null!==(s=r.continuation_token)&&void 0!==s?s:"",httpHeaders:null!==(u=r.http_headers)&&void 0!==u?u:{}};try{var d,p,h=JSON.parse(a);if(fe.Check(h))l=null===(d=h.backoff_policy)||void 0===d?void 0:d.reconnect_min_ms,f=null===(p=h.backoff_policy)||void 0===p?void 0:p.reconnect_max_ms}catch(e){}finally{var v,y;c.replyPayload={backoffPolicy:{reconnectMinMs:null!==(v=l)&&void 0!==v?v:1e3,reconnectMaxMs:null!==(y=f)&&void 0!==y?y:2e3}}}return c}return I.default(n)}(Message),he=I.default((function e(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:null;R.default(this,e),M.default(this,"capabilities",void 0),M.default(this,"token",void 0),M.default(this,"continuation_token",void 0),M.default(this,"registrations",void 0),M.default(this,"tweaks",void 0),M.default(this,"metadata",void 0),this.capabilities=t,this.token=n,this.continuation_token=r,this.registrations=i,this.tweaks=a,this.metadata=o,Object.freeze(i),Object.freeze(a),Object.freeze(o)}));function ve(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 ye(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ve(Object(n),!0).forEach((function(t){M.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ve(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var me=function(){function e(t,n,r,i,a){R.default(this,e),M.default(this,"host",void 0),M.default(this,"path",void 0),M.default(this,"method",void 0),M.default(this,"params",void 0),M.default(this,"headers",void 0),this.host=t,this.path=n,this.method=r,this.params=i,this.headers=a,Object.freeze(i),Object.freeze(a)}return I.default(e,null,[{key:"from",value:function(t){var n=new URL(t.url),r=E.default(new URLSearchParams(n.searchParams).entries()).reduce((function(e,t){var n=U.default(t,2),r=n[0],i=n[1];return ye(ye({},e),{},M.default({},r,i))}),{});return new e(n.host,n.pathname,t.method,r,t.headers)}}]),e}(),ge=I.default((function e(t,n){R.default(this,e),M.default(this,"active_grant",void 0),M.default(this,"http_request",void 0),this.active_grant=t,this.http_request=n,Object.freeze(n)})),be=b.Type.Object({status:se}),we=w.TypeCompiler.Compile(be);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=j.default(e);if(t){var i=j.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return A.default(this,n)}}var xe=function(e){P.default(n,e);var t=ke(n);function n(e,r,i,a){var o;if(R.default(this,n),o=t.call(this,"close",r,i,a,e),M.default(C.default(o),"status",void 0),!we.Check(r))throw new Error("Invalid close headers passed");return o.status=r.status,o}return I.default(n)}(Message),_e=b.Type.Object({client_update_type:b.Type.Optional(b.Type.String())}),Se=w.TypeCompiler.Compile(_e);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=j.default(e);if(t){var i=j.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return A.default(this,n)}}var Ee=function(e){P.default(n,e);var t=Oe(n);function n(e,r,i,a){var o,s;if(R.default(this,n),s=t.call(this,"client_update",r,i,a,e),M.default(C.default(s),"clientUpdateType",void 0),!Se.Check(r))throw new Error("Invalid client update headers passed");return s.clientUpdateType=null!==(o=r.client_update_type)&&void 0!==o?o:"",s}return I.default(n)}(Message),Te=b.Type.Object({message_type:b.Type.Optional(b.Type.String())}),Re=w.TypeCompiler.Compile(Te);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=j.default(e);if(t){var i=j.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return A.default(this,n)}}var Ce=function(e){P.default(n,e);var t=Ie(n);function n(e,r,i,a){var o,s;if(R.default(this,n),s=t.call(this,"notification",r,i,a,e),M.default(C.default(s),"messageType",void 0),!Re.Check(r))throw new Error("Invalid notification headers passed");return s.messageType=null!==(o=r.message_type)&&void 0!==o?o:"",s}return I.default(n)}(Message),Pe=I.default((function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"GET",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:6e4;R.default(this,e),M.default(this,"url",void 0),M.default(this,"method",void 0),M.default(this,"headers",void 0),M.default(this,"payload",void 0),M.default(this,"grant",void 0),M.default(this,"timeout",void 0),this.url=t,this.method=n,this.headers=r,this.payload=i,this.grant=a,this.timeout=o,Object.freeze(r)})),Ae=I.default((function e(t,n,r,i){R.default(this,e),M.default(this,"statusCode",void 0),M.default(this,"status",void 0),M.default(this,"headers",void 0),M.default(this,"payload",void 0),this.statusCode=t,this.status=n,this.headers=r,this.payload=i,Object.freeze(r)}));function je(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 Me(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 Me(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function Me(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 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=j.default(e);if(t){var i=j.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return A.default(this,n)}}var Ue={code:200,status:"Ok"},Ne={code:400,status:"Bad Request"},Fe=20104,De=function(e,t){return new d.ErrorInfo(t,e.status,e.code,e.errorCode)},qe=function(e){P.default(n,e);var t=Le(n);function n(e,r){var i,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};R.default(this,n),i=t.call(this),M.default(C.default(i),"lastError",null),M.default(C.default(i),"_config",void 0),M.default(C.default(i),"_fsm",void 0),M.default(C.default(i),"_pendingRequests",new Map),M.default(C.default(i),"_sentRequests",new Map),M.default(C.default(i),"_connectivityMonitor",new X),M.default(C.default(i),"_failedReconnectionAttempts",0),M.default(C.default(i),"_webSocket",null),M.default(C.default(i),"_watchdogTimer",null),i._config=new J(e,r,a),a.logLevel&&q.setLevel(a.logLevel);var o=function(e){var t=e.event;return(0,e.dontTransition)((function(){i._handleMessageReceived(t.message)}))},s=function(e){return(0,e.transitionTo)({type:"disconnected",errorInfo:new d.ErrorInfo("unknown","Disconnect called")})},u=function(e){var t=e.event;return(0,e.transitionTo)({type:"waitAndReconnect"},(function(){i.emit("nonFatalError",t.errorInfo)}))},c=function(e){return(0,e.transitionTo)({type:"waitAndReconnect"},(function(){i.emit("nonFatalError",new d.ErrorInfo("networkBecameUnreachable","Network became unreachable"))}))},l=function(e){var t=e.event;return(0,e.transitionTo)({type:"disconnected",errorInfo:t.errorInfo},(function(){i.emit("fatalError",t.errorInfo)}))};return i._fsm=new k.StateMachine((function(e){var t=e.initialState,n=e.state;t({type:"disconnected",errorInfo:new d.ErrorInfo("unknown","Twilsock created")}),n("disconnected",(function(e){var t=e.onEnter,n=e.onExit,r=e.on;t((function(e){var t=e.state;i._failedReconnectionAttempts=0,i._connectivityMonitor.stop(),i._failAllSentRequests(t.errorInfo),i._failAllPendingRequests(t.errorInfo),i._disconnectWebSocket(),i.emit("disconnected",t.errorInfo.message)})),n((function(){i._connectivityMonitor.start()})),r("connect",(function(e){return(0,e.transitionTo)({type:"connecting"})})),r("updateToken",(function(e){var t=e.event,n=e.transitionTo;return i._config.token=t.token,t.request.cancel(),n({type:"connecting"})})),r("sendRequest",(function(e){var t=e.event,n=e.dontTransition,r=new d.ErrorInfo("transportDisconnected","Cannot send request in the disconnected state");return t.request.cancel(r),n()}))})),n("connecting",(function(e){var t=e.onEnter,n=e.on;t((function(){i._connectWebSocket(),i.emit("connecting")})),n("updateToken",(function(e){var t=e.event,n=e.dontTransition,r=new d.ErrorInfo("tokenUpdatedLocally");return i._config.token=t.token,t.request.cancel(r),n()})),n("sendRequest",(function(e){var t=e.event,n=e.dontTransition;return i._addPendingRequest(t.request),n()})),n("transportConnected",(function(e){return(0,e.transitionTo)({type:"initializing"})})),n("disconnect",(function(e){return s(e)})),n("networkBecameUnreachable",(function(e){return c(e)})),n("nonFatalError",(function(e){return u(e)})),n("fatalError",(function(e){return l(e)}))})),n("initializing",(function(e){var t,n=e.onEnter,r=e.onExit,a=e.on;n((function(){(t=i._createInitRequest(5e3)).promise.then((function(){q.debug("Init message received"),i._fsm.transition({type:"initMessageReceived"})})).catch((function(e){e instanceof d.ErrorInfo&&"timeout"===e.reason&&i._onTimeout()})),i._sendRequest(t)})),r((function(){t.cancel()})),a("timeout",(function(e){return(0,e.transitionTo)({type:"waitAndReconnect"},(function(){var e=new d.ErrorInfo("timeout");i.emit("nonFatalError",e)}))})),a("updateToken",(function(e){var t=e.event,n=e.dontTransition;return i._config.token=t.token,i._addPendingRequest(t.request),n()})),a("sendRequest",(function(e){var t=e.event,n=e.dontTransition;return i._addPendingRequest(t.request),n()})),a("initMessageReceived",(function(e){return(0,e.transitionTo)({type:"connected"})})),a("tooManyRequests",(function(e){var t=e.event;return(0,e.transitionTo)({type:"waitAndReconnect",waitTime:t.waitTime},(function(){var e=new d.ErrorInfo("tooManyRequests");i.emit("nonFatalError",e)}))})),a("messageReceived",(function(e){return o(e)})),a("disconnect",(function(e){return s(e)})),a("networkBecameUnreachable",(function(e){return c(e)})),a("nonFatalError",(function(e){return u(e)})),a("fatalError",(function(e){return l(e)}))})),n("connected",(function(e){var t=e.onEnter,n=e.onExit,r=e.on;t((function(){i._failedReconnectionAttempts=0,i._startWatchdogTimer(),i._sendAllPendingRequests(),i.emit("connected")})),n((function(){i._cancelWatchdogTimer()})),r("updateToken",(function(e){var t=e.event,n=e.dontTransition;return i._config.token=t.token,i._sendRequest(t.request),n()})),r("sendRequest",(function(e){var t=e.event,n=e.dontTransition;return i._sendRequest(t.request),n()})),r("tooManyRequests",(function(e){var t=e.event;return(0,e.transitionTo)({type:"throttling",waitTime:t.waitTime},(function(){var e=new d.ErrorInfo("tooManyRequests");i.emit("nonFatalError",e)}))})),r("messageReceived",(function(e){return o(e)})),r("disconnect",(function(e){return s(e)})),r("networkBecameUnreachable",(function(e){return c(e)})),r("nonFatalError",(function(e){return u(e)})),r("fatalError",(function(e){return l(e)}))})),n("waitAndReconnect",(function(e){var t=e.onEnter,n=e.onExit,r=e.on,a=null;t((function(e){var t,n=null!==(t=e.state.waitTime)&&void 0!==t?t:i._calculateDefaultWaitTime();q.debug("Started the reconnection timer for ".concat(n," ms"));var r=new d.ErrorInfo("transportDisconnected","Transport disconnected, started the reconnection timer...");i._failAllSentRequests(r),i._disconnectWebSocket(),i._connectivityMonitor.isNetworkAvailable&&(a=setTimeout((function(){i._onTimeout()}),n)),i._failedReconnectionAttempts++,i.emit("disconnected","Wait and reconnect")})),n((function(){null!==a&&(clearTimeout(a),a=null)})),r("timeout",(function(e){return(0,e.transitionTo)({type:"connecting"})})),r("connect",(function(e){return(0,e.transitionTo)({type:"connecting"})})),r("updateToken",(function(e){var t=e.event,n=e.dontTransition;i._config.token=t.token;var r=new d.ErrorInfo("tokenUpdatedLocally");return t.request.cancel(r),n()})),r("sendRequest",(function(e){var t=e.event,n=e.dontTransition;return i._addPendingRequest(t.request),n()})),r("networkBecameReachable",(function(e){var t=e.transitionTo;return i._failedReconnectionAttempts=0,t({type:"connecting"})})),r("networkBecameUnreachable",(function(e){var t=e.dontTransition;return null!==a&&(clearTimeout(a),a=null),t()})),r("disconnect",(function(e){return s(e)}))})),n("throttling",(function(e){var t,n=e.onEnter,r=e.onExit,a=e.on;n((function(e){var n=e.state;t=setTimeout((function(){i._onTimeout()}),n.waitTime)})),r((function(){clearTimeout(t)})),a("timeout",(function(e){return(0,e.transitionTo)({type:"connected"})})),a("updateToken",(function(e){var t=e.event,n=e.dontTransition;return i._config.token=t.token,i._addPendingRequest(t.request),n()})),a("sendRequest",(function(e){var t=e.event,n=e.dontTransition;return i._addPendingRequest(t.request),n()})),a("messageReceived",(function(e){return o(e)})),a("disconnect",(function(e){return s(e)})),a("networkBecameUnreachable",(function(e){return c(e)})),a("nonFatalError",(function(e){return u(e)})),a("fatalError",(function(e){return l(e)}))}))})),i._fsm.subscribe((function(e,t,n){null!==e&&null!==n?q.debug("FSM transition ".concat(n.type,": ").concat(e.type," -> ").concat(t.type)):q.debug("FSM initiated: ".concat(t.type))})),i._connectivityMonitor.on("changed",(function(e){q.debug('ConnectivityMonitor "changed" event: '.concat(e)),i._fsm.transition({type:e?"networkBecameReachable":"networkBecameUnreachable"})})),i}return I.default(n,[{key:"connect",value:function(){q.debug("Call to TwilsockClient.connect"),this._fsm.transition({type:"connect"})}},{key:"disconnect",value:function(){q.debug("Call to TwilsockClient.disconnect"),this._fsm.transition({type:"disconnect"})}},{key:"get",value:function(e){var t=e.url,n=e.headers,r=e.grant,i=e.typeCheck,a=new Pe(t,"GET",n,"",r);return this._sendHttpRequest(a,i)}},{key:"post",value:function(e){var t,n=e.url,r=e.headers,i=e.body,a=e.grant,o=e.typeCheck;i=null!==(t=i)&&void 0!==t?t:"";var s=new Pe(n,"POST",r,"string"==typeof i?i:JSON.stringify(i),a);return this._sendHttpRequest(s,o)}},{key:"put",value:function(e){var t,n=e.url,r=e.headers,i=e.body,a=e.grant,o=e.typeCheck;i=null!==(t=i)&&void 0!==t?t:"";var s=new Pe(n,"PUT",r,"string"==typeof i?i:JSON.stringify(i),a);return this._sendHttpRequest(s,o)}},{key:"delete",value:function(e){var t,n=e.url,r=e.headers,i=e.body,a=e.grant,o=e.typeCheck;i=null!==(t=i)&&void 0!==t?t:"";var s=new Pe(n,"DELETE",r,"string"==typeof i?i:JSON.stringify(i),a);return this._sendHttpRequest(s,o)}},{key:"updateToken",value:function(e){var t=this;return new d.CancellablePromise(function(){var n=T.default(L.default.mark((function n(r,i,a){var o;return L.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return q.debug("Call to TwilsockClient.updateToken:",e),o=t._createUpdateTokenRequest(e),t._fsm.transition({type:"updateToken",token:e,request:o}),a((function(){q.debug("Update token request has been cancelled by the user"),o.cancel()})),n.prev=4,n.next=7,o.promise;case 7:n.next=16;break;case 9:if(n.prev=9,n.t0=n.catch(4),!(n.t0 instanceof d.TwilioError&&"tokenUpdatedLocally"===n.t0.errorInfo.reason)){n.next=15;break}return q.debug("Token was updated locally"),r(),n.abrupt("return");case 15:i(n.t0);case 16:q.debug("Token was updated remotely"),r();case 18:case"end":return n.stop()}}),n,null,[[4,9]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"populateInitRegistrations",value:function(e){var t=E.default(e.values());q.debug("Call to TwilsockClient.populateInitRegistrations:",t.join(", ")),this._config.initRegistrations=[new oe(this._config.activeGrant,"ers",4,t)]}},{key:"_sendHttpRequest",value:function(e,t){var n=this;return new d.CancellablePromise(function(){var r=T.default(L.default.mark((function r(i,a,o){var s,u,c;return L.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return q.debug("Call to TwilsockClient.sendRequest:",JSON.stringify(e)),s=n._createUpstreamRequest(e),n._fsm.transition({type:"sendRequest",request:s}),o((function(){q.debug("Request ".concat(s.message.id," has been cancelled by the user")),s.cancel()})),r.prev=4,r.next=7,s.promise;case 7:u=r.sent,r.next=14;break;case 10:return r.prev=10,r.t0=r.catch(4),a(r.t0),r.abrupt("return");case 14:if(u instanceof pe){r.next=17;break}return a(new Error("Expected instance of ReplyMessage")),r.abrupt("return");case 17:if(!t){r.next=31;break}if(r.prev=18,c=JSON.parse(u.payload),t.Check(c)){r.next=23;break}return a(new Error("Payload doesn't match the provided schema")),r.abrupt("return");case 23:return i(new Ae(u.replyHeaders.httpStatus.code,u.replyHeaders.httpStatus.status,u.replyHeaders.httpHeaders,c)),r.abrupt("return");case 27:return r.prev=27,r.t1=r.catch(18),a(r.t1),r.abrupt("return");case 31:i(new Ae(u.replyHeaders.httpStatus.code,u.replyHeaders.httpStatus.status,u.replyHeaders.httpHeaders,u.payload));case 32:case"end":return r.stop()}}),r,null,[[4,10],[18,27]])})));return function(e,t,n){return r.apply(this,arguments)}}())}},{key:"_failAllPendingRequests",value:function(e){var t,n=je(this._pendingRequests.values());try{for(n.s();!(t=n.n()).done;){t.value.cancel(e)}}catch(e){n.e(e)}finally{n.f()}this._pendingRequests.clear()}},{key:"_failAllSentRequests",value:function(e){var t,n=je(this._sentRequests.values());try{for(n.s();!(t=n.n()).done;){t.value.cancel(e)}}catch(e){n.e(e)}finally{n.f()}this._sentRequests.clear()}},{key:"_sendAllPendingRequests",value:function(){var e,t=je(this._pendingRequests.values());try{for(t.s();!(e=t.n()).done;){var n=e.value;this._sendRequest(n)}}catch(e){t.e(e)}finally{t.f()}this._pendingRequests.clear()}},{key:"_addPendingRequest",value:function(e){this._pendingRequests.set(e.message.id,e)}},{key:"_calculateDefaultWaitTime",value:function(){var e=1e3*Math.pow(2,this._failedReconnectionAttempts)+Math.floor(1e3*Math.random())-1e3;return Math.min(e,45e3)}},{key:"_connectWebSocket",value:function(){var e=this;if(q.debug("Call to TwilsockClient._connectWebSocket"),null!==this._webSocket)throw new Error("Websocket already exists");this._webSocket=new G,this._webSocket.on("connected",(function(){q.debug('TwilsockTransport "connected" event'),e._fsm.transition({type:"transportConnected"})})),this._webSocket.on("disconnected",(function(t){e._fsm.transition({type:"nonFatalError",errorInfo:t})})),this._webSocket.on("messageReceived",(function(t){var n;e._restartWatchdogTimer();try{n=Message.parse(t)}catch(t){q.warn("Error while parsing an incoming message",t);var r=new d.ErrorInfo("cannotParse");return void e._fsm.transition({type:"fatalError",errorInfo:r})}e._fsm.transition({type:"messageReceived",message:n})})),this._webSocket.connect(this._config.url)}},{key:"_disconnectWebSocket",value:function(){var e;q.debug("Call to TwilsockClient._disconnectWebSocket"),null===(e=this._webSocket)||void 0===e||e.disconnect("TwilsockClient._disconnectWebSocket called"),this._webSocket=null}},{key:"_startWatchdogTimer",value:function(){var e=this;if(null!==this._watchdogTimer)throw new Error("The watchdog time is already running");this._watchdogTimer=setTimeout((function(){q.warn("Watchdog timeout"),e._fsm.transition({type:"nonFatalError",errorInfo:new d.ErrorInfo("timeout","Watchdog timeout")})}),43e3)}},{key:"_createInitRequest",value:function(e){var t=this,n=new he(["client_update"],this._config.token,this._config.continuationToken,this._config.initRegistrations,this._config.tweaks,this._config.clientMetadata),r=new Message("init",n);return new D(r,e,(function(e){t._onRequestFinished(e)}))}},{key:"_createUpdateTokenRequest",value:function(e){var t=this,n=new Message("update",{token:e});return new D(n,6e4,(function(e){t._onRequestFinished(e)}))}},{key:"_createUpstreamRequest",value:function(e){var t,n,r=this,i=new ge(null!==(t=e.grant)&&void 0!==t?t:this._config.activeGrant,me.from(e)),a=new Message("message",i,null!==(n=e.headers["Content-Type"])&&void 0!==n?n:"application/json",e.payload);return new D(a,e.timeout,(function(e){r._onRequestFinished(e)}))}},{key:"_onRequestFinished",value:function(e){this._pendingRequests.delete(e.message.id),this._sentRequests.delete(e.message.id)}},{key:"_onTimeout",value:function(){q.debug("Call to TwilsockClient._onTimeout"),this._fsm.transition({type:"timeout"})}},{key:"_cancelWatchdogTimer",value:function(){if(null===this._watchdogTimer)throw new Error("The watchdog time is not running");clearTimeout(this._watchdogTimer),this._watchdogTimer=null}},{key:"_restartWatchdogTimer",value:function(){null!==this._watchdogTimer&&(this._cancelWatchdogTimer(),this._startWatchdogTimer())}},{key:"_handleMessageReceived",value:function(e){var t=this,n=[e.id,e.headers,e.payloadType,e.payload];y.match(e.method).with("reply",(function(){t._handleReplyMessage(O.default(pe,n))})).with("close",(function(){t._handleCloseMessage(O.default(xe,n))})).with("client_update",(function(){t._handleClientUpdateMessage(O.default(Ee,n))})).with("notification",(function(){t._handleNotificationMessage(O.default(Ce,n))})).with("ping",(function(){t._sendMessageReply(e,Ue)})).otherwise((function(e){q.warn('Skipped a message with an unexpected method "'.concat(e,'"'))}))}},{key:"_handleReplyMessage",value:function(e){var t=this,n=this._sentRequests.get(e.id);if(n){var r=e.replyHeaders.status;if(r.code<200||r.code>=300){var i=y.match(r).with({errorCode:Fe},(function(){return De(r,"tokenExpired")})).with({code:401},(function(){return De(r,"unauthorized")})).with({code:429},(function(){return De(r,"tooManyRequests")})).otherwise((function(){return De(r,"unknown")}));return n.cancel(i),r.errorCode===Fe&&(q.warn("Received a token expired reply"),this.emit("tokenExpired")),void y.match(r.code).with(401,(function(){t._fsm.transition({type:"fatalError",errorInfo:i})})).with(429,(function(){var n=e.replyPayload.backoffPolicy,r=n.reconnectMinMs,i=n.reconnectMaxMs,a=Math.floor(Math.random()*(i-r)+r);t._fsm.transition({type:"tooManyRequests",waitTime:a})})).otherwise((function(){t._fsm.transition({type:"nonFatalError",errorInfo:i})}))}var a=e.replyHeaders.continuationToken;void 0!==a&&(this._config.continuationToken=a),n.complete(e)}else q.warn("Skipped a reply to an unknown request: ".concat(e.id))}},{key:"_handleCloseMessage",value:function(e){var t=this;q.debug("Server has initiated the process of closing the connection: ".concat(e.payload)),this._sendMessageReply(e,Ue);var n=De(e.status,"closeMessageReceived");if(308===e.status.code&&51232===e.status.errorCode)return q.debug("Token with a different instanceSid"),void this._fsm.transition({type:"fatalError",errorInfo:n});var r=e.status.code;y.match(r).with(308,(function(){q.debug("Offloading to another instance"),t._fsm.transition({type:"nonFatalError",errorInfo:n})})).with(401,406,410,417,(function(){q.debug("Server closed connection due to a fatal error: ".concat(n));var r=y.match(e.status).with({code:410},{errorCode:Fe},(function(){return De(e.status,"tokenExpired")})).with({code:401},(function(){return De(e.status,"unauthorized")})).otherwise((function(){return n}));t._fsm.transition({type:"fatalError",errorInfo:r})})).otherwise((function(){q.warn("Unexpected close message ".concat(n)),t._fsm.transition({type:"nonFatalError",errorInfo:n})}))}},{key:"_handleClientUpdateMessage",value:function(e){this._sendMessageReply(e,Ue),"token_about_to_expire"!==e.clientUpdateType?q.warn("Ignoring an unknown client update ".concat(e.clientUpdateType)):this.emit("tokenAboutToExpire")}},{key:"_handleNotificationMessage",value:function(e){if(""===e.payload)return q.warn("Skipped a notification message with no payload: ".concat(e.id)),void this._sendMessageReply(e,Ne,"Notification message must carry data");this._sendMessageReply(e,Ue),""!==e.messageType?this.emit("targetedMessageReceived",e.messageType,e.payload):this.emit("messageReceived",e.payload)}},{key:"_sendMessageReply",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";if(null!==this._webSocket){var r=new Message("reply",{status:t},""!==n?"text/plain":"",n,e.id);this._webSocket.sendMessage(r.encode())}}},{key:"_sendRequest",value:function(e){if(null===this._webSocket)throw new Error("WebSocket not initialized");this._webSocket.sendMessage(e.message.encode()),this._sentRequests.set(e.message.id,e)}}]),n}(p.ReplayEventEmitter);Object.defineProperty(e,"CancellablePromise",{enumerable:!0,get:function(){return d.CancellablePromise}}),Object.defineProperty(e,"CancellationError",{enumerable:!0,get:function(){return d.CancellationError}}),Object.defineProperty(e,"ErrorInfo",{enumerable:!0,get:function(){return d.ErrorInfo}}),e.InitRegistration=oe,e.TwilsockClient=qe}(US);var YA={},JA=f,QA=$e,XA=ee,ZA=$m,ej=RegExp.prototype,tj=on.PROPER,nj=Xn,rj=Ft,ij=za,aj=o,oj=function(e){var t=e.flags;return void 0!==t||"flags"in ej||QA(e,"flags")||!XA(ej,e)?t:JA(ZA,e)},sj="toString",uj=RegExp.prototype.toString,cj=aj((function(){return"/a/b"!=uj.call({source:"a",flags:"b"})})),lj=tj&&uj.name!=sj;(cj||lj)&&nj(RegExp.prototype,sj,(function(){var e=rj(this);return"/"+ij(e.source)+"/"+ij(oj(e))}),{unsafe:!0});var fj=xI;ni({target:"Object",stat:!0,arity:2,forced:Object.assign!==fj},{assign:fj}),j_("Set",(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),J_),function(e){Object.defineProperty(e,"__esModule",{value:!0});var t=DS.exports,n=$w.exports,r=Ww.exports,i=Vw.exports,a=Kw.exports,o=Gw.exports,s=Yw.exports,u=sx.exports,c=qS,l=Sw.exports,f=US,d=Q_,p=jw.exports,h=Dw.exports,v=sy.exports,y=VS,m=Mb;function g(e){return e&&"object"===Xu(e)&&"default"in e?e:{default:e}}function b(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 w=g(t),k=g(n),x=g(r),_=g(i),S=g(a),O=g(o),E=g(s),T=g(u),R=g(c),I=g(l),C=g(p),P=g(h),A=b(v);function j(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":I.default(Reflect))&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}function M(e,t){if("object"===("undefined"==typeof Reflect?"undefined":I.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function L(){}function U(){U.init.call(this)}function N(e){return void 0===e._maxListeners?U.defaultMaxListeners:e._maxListeners}function F(e,t,n){if(t)e.call(n);else for(var r=e.length,i=H(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=H(e,i),o=0;o<i;++o)a[o].call(n,r)}function q(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,o=H(e,a),s=0;s<a;++s)o[s].call(n,r,i)}function B(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var o=e.length,s=H(e,o),u=0;u<o;++u)s[u].call(n,r,i,a)}function z(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=H(e,i),o=0;o<i;++o)a[o].apply(n,r)}function W(e,t,n,r){var i,a,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),o=a[t]):(a=e._events=new L,e._eventsCount=0),o){if("function"==typeof o?o=a[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),!o.warned&&(i=N(e))&&i>0&&o.length>i){o.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=e,s.type=t,s.count=o.length,function(e){"function"==typeof console.warn?console.warn(e):console.log(e)}(s)}}else o=a[t]=n,++e._eventsCount;return e}function $(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 K(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 H(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}L.prototype=Object.create(null),U.EventEmitter=U,U.usingDomains=!1,U.prototype.domain=void 0,U.prototype._events=void 0,U.prototype._maxListeners=void 0,U.defaultMaxListeners=10,U.init=function(){this.domain=null,U.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new L,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},U.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},U.prototype.getMaxListeners=function(){return N(this)},U.prototype.emit=function(e){var t,n,r,i,a,o,s,u="error"===e;if(o=this._events)u=u&&null==o.error;else if(!u)return!1;if(s=this.domain,u){if(t=arguments[1],!s){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=s,t.domainThrown=!1,s.emit("error",t),!1}if(!(n=o[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:F(n,l,this);break;case 2:D(n,l,this,arguments[1]);break;case 3:q(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];z(n,l,this,i)}return!0},U.prototype.addListener=function(e,t){return W(this,e,t,!1)},U.prototype.on=U.prototype.addListener,U.prototype.prependListener=function(e,t){return W(this,e,t,!0)},U.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,$(this,e,t)),this},U.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,$(this,e,t)),this},U.prototype.removeListener=function(e,t){var n,r,i,a,o;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){o=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,o||t)}return this},U.prototype.off=function(e,t){return this.removeListener(e,t)},U.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},U.prototype.listeners=function(e){var t,n,r=this._events;return n=r&&(t=r[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):[],n},U.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):K.call(e,t)},U.prototype.listenerCount=K,U.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var G=A.getLogger("twilio-notificatiions");function V(e,t){return["".concat((new Date).toISOString()," Twilio.Notifications ").concat(e,":")].concat(Array.from(t))}var Y=function(){function e(){k.default(this,e)}return x.default(e,[{key:"setLevel",value:function(e){G.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];G.trace.apply(null,V("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];G.debug.apply(null,V("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];G.info.apply(null,V("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];G.warn.apply(null,V("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];G.error.apply(null,V("E",t))}}]),e}(),J=new Y;function Q(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=E.default(e);if(t){var i=E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return O.default(this,n)}}var X=x.default((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),T.default(this,"token",void 0),T.default(this,"notificationId",void 0),T.default(this,"messageTypes",void 0),this.token=t,this.notificationId=n,this.messageTypes=r}));function Z(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(P.default(P.default(e).filter((function(e){return!t.has(e)}))),P.default(P.default(t).filter((function(t){return!e.has(t)}))))}(e.messageTypes,t.messageTypes).length>0&&n.add("messageType"),[n.size>0,n]}var ee=function(e){S.default(r,e);var t,n=Q(r);function r(e){var t;return k.default(this,r),t=n.call(this),T.default(_.default(t),"channelType",void 0),T.default(_.default(t),"desiredState",new X),T.default(_.default(t),"currentState",new X),T.default(_.default(t),"_hasActiveAttempt",!1),t.channelType=e,t}return x.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)?J.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=w.default(R.default.mark((function e(){var t,n,r,i,a,o;return R.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._hasActiveAttempt){e.next=3;break}throw J.error("One registration attempt is already in progress"),new Error("One registration attempt is already in progress");case 3:if(t=Z(this.desiredState,this.currentState),n=C.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"),J.trace("Persisting ".concat(this.channelType," registration"),i,this.desiredState),e.prev=8,this._hasActiveAttempt=!0,(a=new X).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:o=e.sent,this.currentState.token=o.token,this.currentState.notificationId=o.notificationId,this.currentState.messageTypes=new Set(o.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}(U);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=E.default(e);if(t){var i=E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return O.default(this,n)}}var ne={min:2e3,max:12e4,randomness:.2},re=function(e){S.default(a,e);var t,n,r,i=te(a);function a(e,t,n,r){var o;return k.default(this,a),o=i.call(this,e),T.default(_.default(o),"context",void 0),T.default(_.default(o),"twilsock",void 0),T.default(_.default(o),"registrarUrl",void 0),T.default(_.default(o),"registrationId",null),o.context=t,o.twilsock=n,o.registrarUrl=r,o}return x.default(a,[{key:"updateRegistration",value:(r=w.default(R.default.mark((function e(t,n){var r,i,a,o,s,u=this;return R.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 J.error("No push notification ID for registration"),new Error("No push notification ID for registration");case 6:return J.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),o={"Content-Type":"application/json"},J.trace("Creating registration for channel ".concat(this.channelType)),e.prev=12,e.t0=JSON,e.next=16,new d.AsyncRetrier(ne).run((function(){return u.twilsock.post({url:a,headers:o,body:r,grant:i})}));case 16:e.t1=e.sent.payload,s=e.t0.parse.call(e.t0,e.t1),this.registrationId=s.id,J.debug("Registration created: ",s),e.next=26;break;case 22:throw e.prev=22,e.t2=e.catch(12),J.error("Registration failed: ",e.t2),e.t2;case 26:return e.abrupt("return",t);case 27:case"end":return e.stop()}}),e,this,[[12,22]])}))),function(e,t){return r.apply(this,arguments)})},{key:"removeRegistration",value:(n=w.default(R.default.mark((function e(){var t,n,r,i=this;return R.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"},J.trace("Removing registration for ".concat(this.channelType)),e.prev=6,e.next=9,new d.AsyncRetrier(Object.assign(ne,{maxAttemptsCount:3})).run((function(){return i.twilsock.delete({url:n,headers:r,grant:t})}));case 9:this.registrationId=null,this.currentState.notificationId="",J.debug("Registration removed for ".concat(this.channelType)),e.next=18;break;case 14:throw e.prev=14,e.t0=e.catch(6),J.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=w.default(R.default.mark((function e(t){var n,r,i,a,o=this;return R.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,J.trace("Removing old registrations for ".concat(this.channelType)),e.next=10,new d.AsyncRetrier(Object.assign(ne,{maxAttemptsCount:3})).run((function(){return o.twilsock.delete({url:r,headers:i,body:a,grant:n})}));case 10:this.registrationId=null,this.currentState.notificationId="",J.debug("Registration removed for ".concat(this.channelType)),e.next=19;break;case 15:throw e.prev=15,e.t0=e.catch(6),J.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}(ee);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=E.default(e);if(t){var i=E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return O.default(this,n)}}var ae,oe=function(e){S.default(a,e);var t,n,r,i=ie(a);function a(e,t,n){var r;return k.default(this,a),r=i.call(this,"twilsock"),T.default(_.default(r),"productId",void 0),T.default(_.default(r),"platform",void 0),T.default(_.default(r),"twilsock",void 0),T.default(_.default(r),"contextId",y.nanoid()),r.productId=e,r.platform=t,r.twilsock=n,r}return x.default(a,[{key:"updateRegistration",value:(r=w.default(R.default.mark((function e(t,n){return R.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:Array.from(t.messageTypes),this.productId,this.platform,e.prev=4,e.next=11;break;case 7:throw e.prev=7,e.t0=e.catch(4),J.error("Failed to update twilsock notification context: ".concat(e.t0)),e.t0;case 11:return e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this,[[4,7]])}))),function(e,t){return r.apply(this,arguments)})},{key:"removeRegistration",value:(n=w.default(R.default.mark((function e(){return R.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,e.next=7;break;case 3:throw e.prev=3,e.t0=e.catch(0),J.error("Failed to remove twilsock notification context: ".concat(e.t0)),e.t0;case 7:case"end":return e.stop()}}),e,null,[[0,3]])}))),function(){return n.apply(this,arguments)})},{key:"sendDeviceRemoveRequest",value:(t=w.default(R.default.mark((function e(t){return R.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}(ee);function se(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=E.default(e);if(t){var i=E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return O.default(this,n)}}var ue=m.literal("apn","fcm","twilsock");e.Notifications=ae=function(e){S.default(Client,e);var t,n,r,i=se(Client);function Client(e){var t,n,r,a,o,s,u,c=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};k.default(this,Client),u=i.call(this),T.default(_.default(u),"twilsock",void 0),T.default(_.default(u),"connectors",void 0),c.logLevel=null!==(t=c.logLevel)&&void 0!==t?t:"error",J.setLevel(c.logLevel);var l=null!==(n=c.productId)&&void 0!==n?n:"notifications",d=!c.twilsockClient,p=c.twilsockClient=null!==(r=c.twilsockClient)&&void 0!==r?r:new f.TwilsockClient(e,l,c),h=null!==(a=c.notifications)&&void 0!==a?a:{},v=null!==(o=null!==(s=h.region)&&void 0!==s?s:c.region)&&void 0!==o?o:"us1",y="https://ers.".concat(v,".twilio.com/v1/registrations"),m=h.ersUrl||y;u.connectors=new Map;var g=ae._detectPlatform();return u.connectors.set("apn",new re("apn",{protocolVersion:4,productId:l,platform:g},p,m)),u.connectors.set("fcm",new re("fcm",{protocolVersion:3,productId:l,platform:g},p,m)),u.connectors.set("twilsock",new oe(l,g,p)),p.on("connecting",(function(){return u.emit("transportState","connecting")})),p.on("connected",(function(){return u.emit("transportState","connected")})),p.on("disconnected",(function(){return u.emit("transportState","disconnected")})),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("targetedMessageReceived",(function(e,t){return u._routeMessage(e,t)})),u.updateToken(e),d&&(p.connect(),u.twilsock=p),u}return x.default(Client,[{key:"shutdown",value:(r=w.default(R.default.mark((function e(){return R.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){J.debug("Set ".concat(e," push registration id '").concat(t,"'")),this._connector(e).setNotificationId(t)}},{key:"subscribe",value:function(e,t){J.debug("Add ".concat(e," subscriptions for message type ").concat(t)),this._connector(e).subscribe(t)}},{key:"unsubscribe",value:function(e,t){J.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=w.default(R.default.mark((function e(){var t;return R.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=w.default(R.default.mark((function e(t,n){return R.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){J.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}(U),j([m.validateTypes(ue,m.nonEmptyString),M("design:type",Function),M("design:paramtypes",[String,String]),M("design:returntype",void 0)],e.Notifications.prototype,"setPushRegistrationId",null),j([m.validateTypes(ue,m.nonEmptyString),M("design:type",Function),M("design:paramtypes",[String,String]),M("design:returntype",void 0)],e.Notifications.prototype,"subscribe",null),j([m.validateTypes(ue,m.nonEmptyString),M("design:type",Function),M("design:paramtypes",[String,String]),M("design:returntype",void 0)],e.Notifications.prototype,"unsubscribe",null),j([m.validateTypes(m.nonEmptyString),M("design:type",Function),M("design:paramtypes",[String]),M("design:returntype",void 0)],e.Notifications.prototype,"updateToken",null),j([m.validateTypesAsync(ue,m.nonEmptyString),M("design:type",Function),M("design:paramtypes",[String,String]),M("design:returntype",Promise)],e.Notifications.prototype,"removeRegistrations",null),e.Notifications=ae=j([m.validateConstructorTypes(m.nonEmptyString,[m.pureObject,"undefined",m.literal(null)]),M("design:paramtypes",[String,Object])],e.Notifications)}(YA);var dj={},pj=f,hj=Ft,vj=U,yj=fr,mj=za,gj=D,bj=Ee,wj=Mg,kj=Yg;Ag("match",(function(e,t,n){return[function(t){var n=gj(this),r=vj(t)?void 0:bj(t,e);return r?pj(r,t,n):new RegExp(t)[e](mj(n))},function(e){var r=hj(this),i=mj(e),a=n(t,r,i);if(a.done)return a.value;if(!r.global)return kj(r,i);var o=r.unicode;r.lastIndex=0;for(var s,u=[],c=0;null!==(s=kj(r,i));){var l=mj(s[0]);u[c]=l,""===l&&(r.lastIndex=wj(i,yj(r.lastIndex),o)),c++}return 0===c?null:u}]}));var xj={exports:{}},_j="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(_j){var Sj=new Uint8Array(16);xj.exports=function(){return _j(Sj),Sj}}else{var Oj=new Array(16);xj.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),Oj[t]=e>>>((3&t)<<3)&255;return Oj}}for(var Ej=[],Tj=0;Tj<256;++Tj)Ej[Tj]=(Tj+256).toString(16).substr(1);var Rj,Ij,Cj=function(e,t){var n=t||0,r=Ej;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("")},Pj=xj.exports,Aj=Cj,jj=0,Mj=0;var Lj=function(e,t,n){var r=t&&n||0,i=t||[],a=(e=e||{}).node||Rj,o=void 0!==e.clockseq?e.clockseq:Ij;if(null==a||null==o){var s=Pj();null==a&&(a=Rj=[1|s[0],s[1],s[2],s[3],s[4],s[5]]),null==o&&(o=Ij=16383&(s[6]<<8|s[7]))}var u=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:Mj+1,l=u-jj+(c-Mj)/1e4;if(l<0&&void 0===e.clockseq&&(o=o+1&16383),(l<0||u>jj)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");jj=u,Mj=c,Ij=o;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++]=o>>>8|128,i[r++]=255&o;for(var p=0;p<6;++p)i[r+p]=a[p];return t||Aj(i)},Uj=xj.exports,Nj=Cj;var Fj=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||Uj)();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||Nj(i)},Dj=Lj,qj=Fj,Bj=qj;Bj.v1=Dj,Bj.v4=qj;var zj=Bj;Object.defineProperty(dj,"__esModule",{value:!0});var Wj=DS.exports,$j=$w.exports,Kj=Ww.exports,Hj=Vw.exports,Gj=Kw.exports,Vj=Gw.exports,Yj=Yw.exports,Jj=sx.exports,Qj=qS,Xj=Sw.exports,Zj=Mb,eM=US,tM=zS.exports,nM=sy.exports,rM=jw.exports,iM=Q_,aM=zj,oM=ax.exports,sM=ix,uM=ZE.exports;function cM(e){return e&&"object"===Xu(e)&&"default"in e?e:{default:e}}function lM(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 fM=cM(Wj),dM=cM($j),pM=cM(Kj),hM=cM(Hj),vM=cM(Gj),yM=cM(Vj),mM=cM(Yj),gM=cM(Jj),bM=cM(Qj),wM=cM(Xj),kM=cM(tM),xM=lM(nM),_M=cM(rM),SM=lM(aM),OM=cM(oM),EM=lM(uM);function TM(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":wM.default(Reflect))&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}function RM(e,t){if("object"===("undefined"==typeof Reflect?"undefined":wM.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}var IM=function(){function e(t){dM.default(this,e),this.base=t,this.args=new Array,this.paths=new Array}return pM.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 CM(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=mM.default(e);if(t){var i=mM.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return yM.default(this,n)}}var SyncError=function(e){vM.default(SyncError,e);var t=CM(SyncError);function SyncError(e){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return dM.default(this,SyncError),(n=t.call(this)).name=n.constructor.name,n.message="".concat(e," (status: ").concat(r,", code: ").concat(i,")"),n.status=r,n.code=i,n}return pM.default(SyncError)}(kM.default(Error)),PM=function(e){vM.default(n,e);var t=CM(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,o=arguments.length>3?arguments[3]:void 0;return dM.default(this,n),(r=t.call(this,e,i,a)).body=o,r}return pM.default(n)}(SyncError);function AM(e){return JSON.parse(JSON.stringify(e))}function jM(e){if(!(void 0===e||MM(e)))throw new SyncError("Invalid pageSize parameter. Expected a positive integer, was '".concat(e,"'."),400,20007)}function MM(e){return function(e){return!isNaN(parseInt(e))&&isFinite(e)}(e)&&e>0}var LM=xM.getLogger("twilio-sync");function UM(e,t){return["".concat((new Date).toISOString()," Sync ").concat(e,":")].concat(Array.from(t))}var NM=function(e){LM.setLevel(e)},FM=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];LM.trace.apply(null,UM("T",t))},DM=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];LM.debug.apply(null,UM("D",t))},qM=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];LM.warn.apply(null,UM("W",t))},BM=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];LM.error.apply(null,UM("E",t))},zM="/v4/Subscriptions",WM="/v3/Maps",$M="/v3/Lists",KM="/v3/Documents",HM="/v3/Streams",GM="/v3/Insights";function VM(e,t,n){return e&&void 0!==e[t]?e[t]:n}var YM=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};dM.default(this,e);var n=t.region||"us1",r="https://cds.".concat(n,".twilio.com"),i=t.cdsUri||r;this.settings={subscriptionsUri:i+zM,documentsUri:i+KM,listsUri:i+$M,mapsUri:i+WM,streamsUri:i+HM,insightsUri:i+GM,sessionStorageEnabled:VM(t.Sync,"enableSessionStorage",!0),productId:t.productId}}return pM.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 JM(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 QM(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 QM(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function QM(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 XM=function(){function e(t){dM.default(this,e),this.localObject=t,this.pendingCorrelationId=null,this.pendingAction=null,this.established=!1,this.retryCount=0}return pM.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 SyncError("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}(),ZM=function(){function e(t){var n=this;dM.default(this,e),gM.default(this,"isConnected",!1),gM.default(this,"maxBatchSize",100),gM.default(this,"subscriptionTtlTimer",null),gM.default(this,"pendingPokeReason",null),this.services=t,this.subscriptions=new Map,this.persisted=new Map,this.latestPokeResponseArrivalTimestampByCorrelationId=new Map;this.backoff=iM.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(),DM("All subscriptions resolved."))}))}var t;return pM.default(e,[{key:"getSubscriptionUpdateBatch",value:function(){function e(e,t,n,r){var i,a=[],o=JM(e);try{for(o.s();!(i=o.n()).done;){var s=_M.default(i.value,2),u=s[0],c=s[1];if(!t.get(u)&&n!==c.pendingAction&&!c.rejectedWithError&&(a.push(c),r&&a.length>=r))break}}catch(e){o.e(e)}finally{o.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=fM.default(bM.default.mark((function e(t,n){var r,i,a,o,s,u,c,l,f,d,p,h,v=this;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isConnected){e.next=4;break}return DM("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=JM(n);try{for(i.s();!(a=i.n()).done;)o=a.value,this.recordActionAttemptOn(o,t,r)}catch(e){i.e(e)}finally{i.f()}return s=this.pendingPokeReason,this.pendingPokeReason=null,e.prev=10,e.next=13,this.request(t,r,s,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):BM("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=JM(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 eM.TransportUnavailableError?(DM("Twilsock connection (required for subscription) not ready (c:".concat(r,"); waiting…")),this.backoff.reset()):(DM("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;DM("Attempting '".concat(e,"' request (c:").concat(t,"):"),i);var o={event_protocol_version:4,action:e,correlation_id:t,retried_requests:a,ttl_in_s:-1,requests:i};return"ttl"===n&&(o.reason=n),this.services.network.post(this.services.config.subscriptionsUri,o)}},{key:"add",value:function(e,t){DM("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 XM(t)),this.persist())}},{key:"remove",value:function(e){DM("Establishing intent to unsubscribe from ".concat(e)),this.subscriptions.delete(e)&&this.persist()}},{key:"acceptMessage",value:function(e,t){FM("Subscriptions received",e);var n=e.event_type,r=void 0!==e.events?e.events:[e.event],i=e.correlation_id;i&&this.latestPokeResponseArrivalTimestampByCorrelationId.set(i,(new Date).getTime());var a,o=JM(r);try{for(o.s();!(a=o.n()).done;){var s=a.value,u=void 0;switch(e.event_type){case"subscription_established":this.applySubscriptionEstablishedMessage(s,i);break;case"subscription_canceled":this.applySubscriptionCancelledMessage(s,i);break;case"subscription_failed":this.applySubscriptionFailedMessage(s,i);break;case(u=n.match(/^(?:map|list|document|stream|live_query)_/)||{}).input:var c=void 0;switch(u[0]){case"map_":c=s.map_sid;break;case"list_":c=s.list_sid;break;case"document_":c=s.document_sid;break;case"stream_":c=s.stream_sid;break;case"live_query_":c=s.query_id,t=!1,!0===e.strictly_ordered&&(t=!0);break;default:c=void 0}this.applyEventToSubscribedEntity(c,s,n,t);break;default:DM("Dropping unknown message type ".concat(n))}}}catch(e){o.e(e)}finally{o.f()}}},{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?(DM("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&&(DM("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()):DM("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)):DM("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&&(BM("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,r){if(e){var i;r=r||(i=this.persisted.get(e))&&i.isEstablished;var a=this.subscriptions.get(e);a?(t.type=n,a.update(t,r)):DM("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){DM("Triggering event replay for all subscriptions, reason=".concat(e)),this.pendingPokeReason=e,this.subscriptionTtlTimer&&(clearTimeout(this.subscriptionTtlTimer),this.subscriptionTtlTimer=null);var t,n=[],r=JM(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,o=n;a<o.length;a++){var s=o[a];this.persisted.set(s.sid,s)}this.persist()}},{key:"shutdown",value:function(){this.backoff.reset(),this.subscriptions.clear()}}]),e}();function eL(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 tL(e){return e.body?e.body.code:0}function nL(e){return 409===e.status?new PM(eL(e),e.status,tL(e),e.body):e.status?new SyncError(eL(e),e.status,tL(e)):e instanceof eM.TransportUnavailableError?e:new SyncError(e.message,0,0)}var rL=function(){function e(t,n,r){dM.default(this,e),this.clientInfo=t,this.config=n,this.transport=r}return pM.default(e,[{key:"createHeaders",value:function(){return{"Content-Type":"application/json","Twilio-Sync-Client-Info":JSON.stringify(this.clientInfo),"Twilio-Request-Id":"RQ"+SM.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 o=new iM.Retrier(t.backoffConfig());o.on("attempt",(function(){e().then((function(e){return o.succeeded(e)})).catch((function(e){if(a.includes(e.status)){var t=parseInt(e.headers?e.headers["Retry-After"]:null);o.failed(nL(e),isNaN(t)?null:1e3*t)}else"Twilsock disconnected"===e.message?o.failed(nL(e)):(o.removeAllListeners(),o.cancel(),i(nL(e)))}))})),o.on("succeeded",(function(e){r(e)})),o.on("cancelled",(function(e){return i(nL(e))})),o.on("failed",(function(e){return i(nL(e))})),o.start()}))}},{key:"get",value:function(e){var t=this,n=this.createHeaders();return DM("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),DM("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),DM("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 DM("DELETE",e,"ID:",n["Twilio-Request-Id"]),this.executeWithRetry((function(){return t.transport.delete(e,n,t.config.productId)}),!1)}}]),e}(),iL=function(){function e(t,n){dM.default(this,e),this.config=t,this.storageId=null;try{this.storage=n||sessionStorage}catch(e){}}return pM.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 aL(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 oL(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 oL(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function oL(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 sL=function(){function e(t,n){dM.default(this,e),this.services=t,this.removalHandler=n,this.subscriptionState="none",this._attachedListeners=new Map}return pM.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){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var i,a=aL(this._attachedListeners.values());try{for(a.s();!(i=a.n()).done;){var o=i.value;o.emit.apply(o,[e].concat(n))}}catch(e){a.e(e)}finally{a.f()}}}]),e}(),uL=function(){function e(t){dM.default(this,e),gM.default(this,"queuedRequests",[]),gM.default(this,"isRequestInFlight",!1),this.inputMergingFunction=t}return pM.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}(),cL=function(){function e(t){dM.default(this,e),gM.default(this,"queueByNamespaceKey",new Map),this.inputReducer=t}var t,n,r;return pM.default(e,[{key:"add",value:(r=fM.default(bM.default.mark((function e(t,n,r){return bM.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)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"squashAndAdd",value:(n=fM.default(bM.default.mark((function e(t,n,r){return bM.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=fM.default(bM.default.mark((function e(t,n){var r,i;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.queueByNamespaceKey.has(t)||this.queueByNamespaceKey.set(t,new uL(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 lL(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=mM.default(e);if(t){var i=mM.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return yM.default(this,n)}}var fL=function(e){vM.default(n,e);var t=lL(n);function n(){var e;return dM.default(this,n),(e=t.call(this)).closed=!1,e.uuid=aM.v4(),e}return pM.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}(sM.ReplayEventEmitter);function dL(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=mM.default(e);if(t){var i=mM.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return yM.default(this,n)}}var pL=function(e){vM.default(f,e);var t,n,r,i,a,o,s,u,c,l=dL(f);function f(e,t,n){var r;dM.default(this,f),r=l.call(this,e,n),gM.default(hM.default(r),"isDeleted",!1);return r.updateMergingQueue=new uL((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 pM.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){FM("Document update skipped, current:",this.lastEventId,", remote:",e.id);break}var t=void 0!==this.descriptor.data?AM(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=fM.default(bM.default.mark((function e(t,n){var r,i=this;return bM.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=fM.default(bM.default.mark((function e(t,n){var r,i=this;return bM.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:(s=fM.default(bM.default.mark((function e(t,n){return bM.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 s.apply(this,arguments)})},{key:"setTtl",value:(o=fM.default(bM.default.mark((function e(t){var n;return bM.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 o.apply(this,arguments)})},{key:"_setUnconditionally",value:(a=fM.default(bM.default.mark((function e(t,n){var r;return bM.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=fM.default(bM.default.mark((function e(t,n){var r,i,a;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=t(AM(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?AM(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=fM.default(bM.default.mark((function e(t){var n,r,i;return bM.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 SyncError("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=fM.default(bM.default.mark((function e(){var t=this;return bM.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):BM("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?AM(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=fM.default(bM.default.mark((function e(){return bM.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 SyncError("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}(sL),hL=function(e){vM.default(s,e);var t,n,r,i,a,o=dL(s);function s(e){var t;return dM.default(this,s),(t=o.call(this)).syncDocumentImpl=e,t.syncDocumentImpl.attach(hM.default(t)),t}return pM.default(s,[{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 pL.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=fM.default(bM.default.mark((function e(t,n){return bM.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=fM.default(bM.default.mark((function e(t,n){return bM.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=fM.default(bM.default.mark((function e(t,n){return bM.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=fM.default(bM.default.mark((function e(t){return bM.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=fM.default(bM.default.mark((function e(){return bM.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(){OM.default(mM.default(s.prototype),"close",this).call(this),this.syncDocumentImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return pL.type}}]),s}(fL);gM.default(hL,"removed","removed"),gM.default(hL,"updated","updated"),TM([Zj.validateTypesAsync(Zj.pureObject,["undefined",Zj.objectSchema("document metadata",{ttl:[Zj.nonNegativeInteger,"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Object,Object]),RM("design:returntype",Promise)],hL.prototype,"set",null),TM([Zj.validateTypesAsync("function",["undefined",Zj.objectSchema("document metadata",{ttl:[Zj.nonNegativeInteger,"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Function,Object]),RM("design:returntype",Promise)],hL.prototype,"mutate",null),TM([Zj.validateTypesAsync(Zj.pureObject,["undefined",Zj.objectSchema("document metadata",{ttl:[Zj.nonNegativeInteger,"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Object,Object]),RM("design:returntype",Promise)],hL.prototype,"update",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger),RM("design:type",Function),RM("design:paramtypes",[Number]),RM("design:returntype",Promise)],hL.prototype,"setTtl",null);var vL=function(){function e(t){dM.default(this,e),this.descriptor=t}return pM.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){dM.default(this,Paginator),this.prevToken=n,this.nextToken=r,this.items=e,this.source=t}var e,t;return pM.default(Paginator,[{key:"hasNextPage",get:function(){return!!this.nextToken}},{key:"hasPrevPage",get:function(){return!!this.prevToken}},{key:"nextPage",value:(t=fM.default(bM.default.mark((function e(){return bM.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=fM.default(bM.default.mark((function e(){return bM.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 yL(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 mL(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 mL(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function mL(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 gL=function(){function e(t,n){dM.default(this,e),this.balanceFactor=0,this.key=t,this.value=n,this.parent=null,this.left=null,this.right=null}return pM.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}(),bL=function(e){function t(e,n){dM.default(this,t),this.isLessThan=e||function(e,t){return e<t},this.isEqual=n||function(e,t){return e===t},this.root=null,this.count=null}return pM.default(t,[{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 gL(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 o=t.left;o.right;)o=o.right;if(t.left===o)t.isRoot?(this.root=o,o.parent=null):(t.isLeftChild?t.parent.left=o:t.parent.right=o,o.parent=t.parent),o.right=t.right,o.right.parent=o,o.balanceFactor=t.balanceFactor,t={parent:o,isLeftChild:!0};else{var s=o.parent,u=o.left;s.right=u,u&&(u.parent=s),t.isRoot?(this.root=o,o.parent=null):(t.isLeftChild?t.parent.left=o:t.parent.right=o,o.parent=t.parent),o.right=t.right,o.right.parent=o,o.left=t.left,o.left.parent=o,o.balanceFactor=t.balanceFactor,t={parent:s,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:e,value:bM.default.mark((function e(){var t,n,r;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=yL(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:bM.default.mark((function e(){var t,n,r,i=arguments;return bM.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:bM.default.mark((function e(){var t,n,r,i=arguments;return bM.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)}))}]),t}(Symbol.iterator);function wL(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 kL(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 kL(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function kL(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 xL=function(){function e(t,n){dM.default(this,e),this.value=t,this.revision=n||0}return pM.default(e,[{key:"isValid",get:function(){return!0}}]),e}(),_L=function(){function e(t){dM.default(this,e),this.revision=t}return pM.default(e,[{key:"isValid",get:function(){return!1}}]),e}(),SL=function(){function e(){dM.default(this,e),this.items=new bL}return pM.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 xL(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 _L(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=wL(this.items);try{for(n.s();!(t=n.n()).done;){var r=_M.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 OL(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=mM.default(e);if(t){var i=mM.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return yM.default(this,n)}}var EL=function(e){vM.default(y,e);var t,n,r,i,a,o,s,u,c,l,f,d,p,h,v=OL(y);function y(e,t,n){var r;dM.default(this,y);return(r=v.call(this,e,n)).updateMergingQueue=new cL((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new SL,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),r}return pM.default(y,[{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:(h=fM.default(bM.default.mark((function e(t,n,r,i){var a,o;return bM.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(o=e.sent).body.data=n,o.body.date_updated=new Date(o.body.date_updated),e.abrupt("return",o.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n,r){return h.apply(this,arguments)})},{key:"push",value:(p=fM.default(bM.default.mark((function e(t,n){var r,i,a;return bM.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 p.apply(this,arguments)})},{key:"set",value:(d=fM.default(bM.default.mark((function e(t,n,r){var i,a=this;return bM.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 d.apply(this,arguments)})},{key:"_updateItemUnconditionally",value:(f=fM.default(bM.default.mark((function e(t,n,r){var i,a;return bM.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 f.apply(this,arguments)})},{key:"_updateItemWithIfMatch",value:(l=fM.default(bM.default.mark((function e(t,n,r){var i,a,o,s;return bM.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(AM(i.data)))){e.next=25;break}return o=i.revision,e.prev=6,e.next=9,this._addOrUpdateItemOnServer(i.uri,a,o,r);case 9:return s=e.sent,this._handleItemMutated(t,s.url,s.last_event_id,s.revision,s.data,s.date_updated,s.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 l.apply(this,arguments)})},{key:"mutate",value:(c=fM.default(bM.default.mark((function e(t,n,r){var i,a=this;return bM.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 c.apply(this,arguments)})},{key:"update",value:(u=fM.default(bM.default.mark((function e(t,n,r){return bM.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:"remove",value:(s=fM.default(bM.default.mark((function e(t){var n,r,i;return bM.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=AM(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)}))),function(e){return s.apply(this,arguments)})},{key:"get",value:function(){var e=fM.default(bM.default.mark((function e(t){var n;return bM.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:(o=fM.default(bM.default.mark((function e(t){var n;return bM.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 SyncError("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 o.apply(this,arguments)})},{key:"queryItems",value:function(){var e=fM.default(bM.default.mark((function e(t){var n,r,i,a,o=this;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new IM(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),o.cache.get(e.index)?o._handleItemMutated(e.index,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):o.cache.store(Number(e.index),new vL({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),o.cache.get(e.index)})),a=r.body.meta,e.abrupt("return",new Paginator(i,(function(e){return o.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=fM.default(bM.default.mark((function e(t){return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return jM((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=fM.default(bM.default.mark((function e(){var t;return bM.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=fM.default(bM.default.mark((function e(t){var n,r;return bM.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=fM.default(bM.default.mark((function e(t,n){var r,i,a;return bM.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=fM.default(bM.default.mark((function e(){return bM.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,o,s,u){if(this.shouldIgnoreEvent(e,n))FM("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 vL({index:e,uri:t,lastEventId:n,revision:r,data:i,dateUpdated:a,dateExpires:o});return this.cache.store(e,l,n),void this.emitItemMutationEvent(l,u,s)}var f=AM(c.data);c.update(n,r,i,a),this.cache.store(e,c,n),void 0!==o&&c.updateDateExpires(o),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):(FM("Context update skipped, current:",this.lastEventId,", remote:",t),!1)}}],[{key:"type",get:function(){return"list"}}]),y}(sL),TL=function(e){vM.default(p,e);var t,n,r,i,a,o,s,u,c,l,f,d=OL(p);function p(e){var t;return dM.default(this,p),(t=d.call(this)).syncListImpl=e,t.syncListImpl.attach(hM.default(t)),t}return pM.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 EL.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=fM.default(bM.default.mark((function e(t,n){return bM.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=fM.default(bM.default.mark((function e(t,n,r){return bM.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=fM.default(bM.default.mark((function e(t,n,r){return bM.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=fM.default(bM.default.mark((function e(t,n,r){return bM.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:(s=fM.default(bM.default.mark((function e(t){return bM.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 s.apply(this,arguments)})},{key:"get",value:(o=fM.default(bM.default.mark((function e(t){return bM.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 o.apply(this,arguments)})},{key:"getContext",value:(a=fM.default(bM.default.mark((function e(){return bM.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=fM.default(bM.default.mark((function e(t){return bM.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=fM.default(bM.default.mark((function e(t){return bM.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=fM.default(bM.default.mark((function e(t,n){return bM.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=fM.default(bM.default.mark((function e(){return bM.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(){OM.default(mM.default(p.prototype),"close",this).call(this),this.syncListImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return EL.type}}]),p}(fL);gM.default(TL,"itemAdded","itemAdded"),gM.default(TL,"itemUpdated","itemUpdated"),gM.default(TL,"itemRemoved","itemRemoved"),gM.default(TL,"removed","removed"),TM([Zj.validateTypesAsync(Zj.pureObject,["undefined",Zj.objectSchema("item metadata",{ttl:[Zj.nonNegativeInteger,"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Object,Object]),RM("design:returntype",Promise)],TL.prototype,"push",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger,Zj.pureObject,["undefined",Zj.objectSchema("item metadata",{ttl:[Zj.nonNegativeInteger,"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Number,Object,Object]),RM("design:returntype",Promise)],TL.prototype,"set",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger,"function",["undefined",Zj.objectSchema("item metadata",{ttl:[Zj.nonNegativeInteger,"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Number,Function,Object]),RM("design:returntype",Promise)],TL.prototype,"mutate",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger,Zj.pureObject,["undefined",Zj.objectSchema("item metadata",{ttl:[Zj.nonNegativeInteger,"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Number,Object,Object]),RM("design:returntype",Promise)],TL.prototype,"update",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger),RM("design:type",Function),RM("design:paramtypes",[Number]),RM("design:returntype",Promise)],TL.prototype,"remove",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger),RM("design:type",Function),RM("design:paramtypes",[Number]),RM("design:returntype",Promise)],TL.prototype,"get",null),TM([Zj.validateTypesAsync(["undefined",Zj.objectSchema("query options",{from:[Zj.nonNegativeInteger,"undefined"],pageSize:[Zj.custom((function(e){return[MM(e),"a positive integer"]})),"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Object]),RM("design:returntype",Promise)],TL.prototype,"getItems",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger),RM("design:type",Function),RM("design:paramtypes",[Number]),RM("design:returntype",Promise)],TL.prototype,"setTtl",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger,Zj.nonNegativeInteger),RM("design:type",Function),RM("design:paramtypes",[Number,Number]),RM("design:returntype",Promise)],TL.prototype,"setItemTtl",null);var RL=function(){function e(t){dM.default(this,e),this.descriptor=t}return pM.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 IL(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=mM.default(e);if(t){var i=mM.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return yM.default(this,n)}}var CL=function(e){vM.default(h,e);var t,n,r,i,a,o,s,u,c,l,f,d,p=IL(h);function h(e,t,n){var r;dM.default(this,h);return(r=p.call(this,e,n)).updateMergingQueue=new cL((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new SL,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 RL(e),e.last_event_id)})),r}return pM.default(h,[{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:(d=fM.default(bM.default.mark((function e(t,n,r){var i,a=this;return bM.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 d.apply(this,arguments)})},{key:"get",value:function(){var e=fM.default(bM.default.mark((function e(t){return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=t){e.next=2;break}throw new SyncError("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:(f=fM.default(bM.default.mark((function e(t){var n;return bM.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 SyncError("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 f.apply(this,arguments)})},{key:"mutate",value:(l=fM.default(bM.default.mark((function e(t,n,r){var i,a=this;return bM.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 l.apply(this,arguments)})},{key:"update",value:(c=fM.default(bM.default.mark((function e(t,n,r){return bM.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 c.apply(this,arguments)})},{key:"_putItemUnconditionally",value:(u=fM.default(bM.default.mark((function e(t,n,r){var i,a;return bM.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 u.apply(this,arguments)})},{key:"_putItemWithIfMatch",value:(s=fM.default(bM.default.mark((function e(t,n,r){var i,a,o,s,u;return bM.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 RL({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(AM(i.data)))){e.next=26;break}return o=i.revision,e.prev=6,e.next=9,this._putItemToServer(t,a,o,r);case 9:return s=e.sent,u=s.item,this._handleItemMutated(u.key,u.url,u.last_event_id,u.revision,u.data,u.date_updated,u.date_expires,s.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:(o=fM.default(bM.default.mark((function e(t,n,r,i){var a,o,s,u,c;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=new IM(this.links.items).pathSegment(t).build(),o={data:n},void 0!==i&&(o.ttl=i),e.prev=3,e.next=6,this.services.network.put(a,o,r);case 6:return s=e.sent,(u=s.body).data=n,u.date_updated=new Date(u.date_updated),c=201===s.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 o.apply(this,arguments)})},{key:"remove",value:(a=fM.default(bM.default.mark((function e(t){var n,r,i;return bM.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=AM(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)}))),function(e){return a.apply(this,arguments)})},{key:"queryItems",value:function(){var e=fM.default(bM.default.mark((function e(t){var n,r,i,a,o=this;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new IM(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),o.cache.get(e.key)?o._handleItemMutated(e.key,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):o.cache.store(e.key,new RL(e),e.last_event_id),o.cache.get(e.key)})),a=r.body.meta,e.abrupt("return",new Paginator(i,(function(e){return o.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=fM.default(bM.default.mark((function e(t){return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return jM((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,o,s,u){if(this.shouldIgnoreEvent(e,n))FM("SyncMapItem ",e," update skipped, current:",this.lastEventId,", remote:",n);else{this._updateRootDateUpdated(a);var c=this.cache.get(e);if(!c){var l=new RL({key:e,url:t,last_event_id:n,revision:r,data:i,date_updated:a,date_expires:o});return this.cache.store(e,l,n),void this.emitItemMutationEvent(l,u,s)}var f=AM(c.data);c.update(n,r,i,a),this.cache.store(e,c,n),void 0!==o&&c.updateDateExpires(o),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=fM.default(bM.default.mark((function e(t){var n,r;return bM.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=fM.default(bM.default.mark((function e(t,n){var r,i,a;return bM.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=fM.default(bM.default.mark((function e(){return bM.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"}}]),h}(sL),PL=function(e){vM.default(f,e);var t,n,r,i,a,o,s,u,c,l=IL(f);function f(e){var t;return dM.default(this,f),(t=l.call(this)).syncMapImpl=e,t.syncMapImpl.attach(hM.default(t)),t}return pM.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 CL.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=fM.default(bM.default.mark((function e(t,n,r){return bM.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=fM.default(bM.default.mark((function e(t){return bM.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:(s=fM.default(bM.default.mark((function e(t,n,r){return bM.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 s.apply(this,arguments)})},{key:"update",value:(o=fM.default(bM.default.mark((function e(t,n,r){return bM.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 o.apply(this,arguments)})},{key:"remove",value:(a=fM.default(bM.default.mark((function e(t){return bM.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=fM.default(bM.default.mark((function e(t){return bM.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=fM.default(bM.default.mark((function e(t){return bM.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=fM.default(bM.default.mark((function e(t,n){return bM.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=fM.default(bM.default.mark((function e(){return bM.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(){OM.default(mM.default(f.prototype),"close",this).call(this),this.syncMapImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return CL.type}}]),f}(fL);function AL(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=mM.default(e);if(t){var i=mM.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return yM.default(this,n)}}gM.default(PL,"itemAdded","itemAdded"),gM.default(PL,"itemUpdated","itemUpdated"),gM.default(PL,"itemRemoved","itemRemoved"),gM.default(PL,"removed","removed"),TM([Zj.validateTypesAsync("string",Zj.pureObject,["undefined",Zj.objectSchema("item metadata",{ttl:[Zj.nonNegativeInteger,"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[String,Object,Object]),RM("design:returntype",Promise)],PL.prototype,"set",null),TM([Zj.validateTypesAsync("string"),RM("design:type",Function),RM("design:paramtypes",[String]),RM("design:returntype",Promise)],PL.prototype,"get",null),TM([Zj.validateTypesAsync("string","function",["undefined",Zj.objectSchema("item metadata",{ttl:[Zj.nonNegativeInteger,"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[String,Function,Object]),RM("design:returntype",Promise)],PL.prototype,"mutate",null),TM([Zj.validateTypesAsync("string",Zj.pureObject,["undefined",Zj.objectSchema("item metadata",{ttl:[Zj.nonNegativeInteger,"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[String,Object,Object]),RM("design:returntype",Promise)],PL.prototype,"update",null),TM([Zj.validateTypesAsync("string"),RM("design:type",Function),RM("design:paramtypes",[String]),RM("design:returntype",Promise)],PL.prototype,"remove",null),TM([Zj.validateTypesAsync(["undefined",Zj.objectSchema("query options",{from:["string","undefined"],pageSize:[Zj.custom((function(e){return[MM(e),"a positive integer"]})),"undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Object]),RM("design:returntype",Promise)],PL.prototype,"getItems",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger),RM("design:type",Function),RM("design:paramtypes",[Number]),RM("design:returntype",Promise)],PL.prototype,"setTtl",null),TM([Zj.validateTypesAsync("string",Zj.nonNegativeInteger),RM("design:type",Function),RM("design:paramtypes",[String,Number]),RM("design:returntype",Promise)],PL.prototype,"setItemTtl",null);var jL=function(e){vM.default(a,e);var t,n,r,i=AL(a);function a(e,t,n){var r;return dM.default(this,a),(r=i.call(this,e,n)).descriptor=t,r}return pM.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=fM.default(bM.default.mark((function e(t){var n,r,i,a;return bM.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=fM.default(bM.default.mark((function e(t){var n,r;return bM.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=fM.default(bM.default.mark((function e(){return bM.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}(sL);TM([Zj.validateTypesAsync(Zj.pureObject),RM("design:type",Function),RM("design:paramtypes",[Object]),RM("design:returntype",Promise)],jL.prototype,"publishMessage",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger),RM("design:type",Function),RM("design:paramtypes",[Number]),RM("design:returntype",Promise)],jL.prototype,"setTtl",null);var ML=function(e){vM.default(a,e);var t,n,r,i=AL(a);function a(e){var t;return dM.default(this,a),(t=i.call(this)).syncStreamImpl=e,t.syncStreamImpl.attach(hM.default(t)),t}return pM.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 jL.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=fM.default(bM.default.mark((function e(t){return bM.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=fM.default(bM.default.mark((function e(t){return bM.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=fM.default(bM.default.mark((function e(){return bM.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(){OM.default(mM.default(a.prototype),"close",this).call(this),this.syncStreamImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return jL.type}}]),a}(fL);gM.default(ML,"messagePublished","messagePublished"),gM.default(ML,"removed","removed"),TM([Zj.validateTypesAsync(Zj.pureObject),RM("design:type",Function),RM("design:paramtypes",[Object]),RM("design:returntype",Promise)],ML.prototype,"publishMessage",null),TM([Zj.validateTypesAsync(Zj.nonNegativeInteger),RM("design:type",Function),RM("design:paramtypes",[Number]),RM("design:returntype",Promise)],ML.prototype,"setTtl",null);var LL=pM.default((function e(t){dM.default(this,e),this.sdk="js",this.sdkVer=t,this.os=EM.os.family,this.osVer=EM.os.version,this.pl=EM.name,this.plVer=EM.version})),UL=function(){function e(){dM.default(this,e),this.names=new Map,this.entities=new Map}return pM.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 NL(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=mM.default(e);if(t){var i=mM.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return yM.default(this,n)}}var FL=pM.default((function e(){dM.default(this,e)})),DL=function(e){vM.default(n,e);var t=NL(n);function n(e,r,i,a){var o;return dM.default(this,n),(o=t.call(this,r,i)).descriptor=e,o.cache=new SL,a&&a.forEach((function(e){o.cache.store(e.key,{key:e.key,value:e.data},e.revision)})),o}return pM.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))FM("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)?FM("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}(sL);function qL(e){return BL.apply(this,arguments)}function BL(){return BL=fM.default(bM.default.mark((function e(t){var n,r,i,a,o,s;return bM.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 SyncError("Invalid query",400,54507);case 3:return o={query_string:r},a===zL.type&&(o.type=a),e.next=7,n.post(i,o,void 0,!0);case 7:return s=e.sent,e.abrupt("return",s.body);case 9:case"end":return e.stop()}}),e)}))),BL.apply(this,arguments)}var zL=function(e){vM.default(n,e);var t=NL(n);function n(e){var r;return dM.default(this,n),(r=t.call(this)).liveQueryImpl=e,r.liveQueryImpl.attach(hM.default(r)),r}return pM.default(n,[{key:"type",get:function(){return DL.type}},{key:"lastEventId",get:function(){return this.liveQueryImpl.lastEventId}},{key:"sid",get:function(){return this.liveQueryImpl.sid}},{key:"close",value:function(){OM.default(mM.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 DL.type}}]),n}(fL);gM.default(zL,"itemUpdated","itemUpdated"),gM.default(zL,"itemRemoved","itemRemoved");var WL=function(e){vM.default(i,e);var t,n,r=NL(i);function i(e){var t;return dM.default(this,i),t=r.call(this),gM.default(hM.default(t),"queryExpression",null),gM.default(hM.default(t),"items",{}),Object.assign(hM.default(t),e),t.updateIndexName(e.indexName),t}return pM.default(i,[{key:"type",get:function(){return i.type}},{key:"search",value:(n=fM.default(bM.default.mark((function e(t){var n=this;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.items={},e.abrupt("return",qL({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 BM("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=fM.default(bM.default.mark((function e(){return bM.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 SyncError("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 IM(this.insightsUri).pathSegment(e).pathSegment("Items").build()}}],[{key:"type",get:function(){return"instant_query"}}]),i}(sM.ReplayEventEmitter);gM.default(WL,"searchResult","searchResult"),TM([Zj.validateTypesAsync("string"),RM("design:type",Function),RM("design:paramtypes",[String]),RM("design:returntype",Promise)],WL.prototype,"search",null),TM([Zj.validateTypes(Zj.nonEmptyString),RM("design:type",Function),RM("design:paramtypes",[String]),RM("design:returntype",void 0)],WL.prototype,"updateIndexName",null);function $L(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=mM.default(e);if(t){var i=mM.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return yM.default(this,n)}}function KL(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 HL(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?KL(Object(n),!0).forEach((function(t){gM.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):KL(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var GL="data_sync",VL="3.2.2";function YL(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 HL(HL({},e),{},{mode:t})}return{mode:"create_new"}}var JL="com.twilio.rtd.cds.document",QL="com.twilio.rtd.cds.list",XL="com.twilio.rtd.cds.map",ZL="twilio.sync.event",Client=function(e){vM.default(Client,e);var t,n,r,i,a,o,s,u,c,l,f,d,p,h,v,y=$L(Client);function Client(e){var t,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(dM.default(this,Client),n=y.call(this),!e)throw new Error("Sync library needs a valid Twilio token to be passed");r.hasOwnProperty("logLevel")?NM(r.logLevel):NM("silent");var i=r.productId=r.productId||GL;r.clientMetadata=r.clientMetadata||{},r.clientMetadata.hasOwnProperty("type")||(r.clientMetadata.type="sync"),r.clientMetadata.hasOwnProperty("sdk")||(r.clientMetadata.sdk="JS",r.clientMetadata.sdkv=VL);var a=!r.twilsockClient;if(!r.initRegistrations){var o=new eM.InitRegistration(i);Client.populateInitRegistrations(o),r.initRegistrations=[o]}var s=r.twilsockClient=null!==(t=r.twilsockClient)&&void 0!==t?t:new eM.Twilsock(e,i,r);s.on("tokenAboutToExpire",(function(){return n.emit("tokenAboutToExpire")})),s.on("tokenExpired",(function(){return n.emit("tokenExpired")})),s.on("connectionError",(function(e){return n.emit("connectionError",e)})),s.on("stateChanged",(function(e){n.emit("connectionStateChanged",e),n.services.subscriptions.onConnectionStateChanged("connected"===e)})),s.on("message",(function(e,t){return n._routeMessage(e,t)}));var u=new YM(r),c=new rL(new LL(VL),u,s),l=new iL(u);return n.services={config:u,twilsock:s,network:c,storage:l,router:hM.default(n),subscriptions:null},n.services.subscriptions=new ZM(n.services),n.entities=new UL,a&&s.connect(),n}return pM.default(Client,[{key:"_routeMessage",value:function(e,t){switch(FM("Notification type:",e,"content:",t),e){case JL:case QL:case XL:this.services.subscriptions.acceptMessage(t,!1);break;case ZL: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=fM.default(bM.default.mark((function e(){var t;return bM.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),qM("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=AM(n);e!==TL.type&&e!==PL.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=fM.default(bM.default.mark((function e(t,n){var r,i,a,o=arguments;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=o.length>2&&void 0!==o[2]&&o[2],n){e.next=3;break}throw new SyncError("Cannot get entity without id",404);case 3:return i=new IM(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=fM.default(bM.default.mark((function e(t){return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(hL.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=fM.default(bM.default.mark((function e(t){return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(TL.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=fM.default(bM.default.mark((function e(t){var n,r=arguments;return bM.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(PL.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=fM.default(bM.default.mark((function e(t){return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(ML.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=fM.default(bM.default.mark((function e(t,n){var r,i;return bM.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(zL.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=fM.default(bM.default.mark((function e(t){var n,r,i,a,o=this;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=YL(t)).mode){e.next=9;break}return e.next=6,this._createDocument(n.id,n.data,n.ttl);case 6:case 17:case 29:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,hL.type))){e.next=14;break}return e.abrupt("return",new hL(i));case 14:return e.prev=14,e.next=17,this._getDocument(n.id);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 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(hL.type,n.id,r),a=new pL(this.services,r,(function(e,t,n){return o.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new hL(a));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return u.apply(this,arguments)})},{key:"map",value:(s=fM.default(bM.default.mark((function e(t){var n,r,i,a,o=this;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=YL(t)).mode){e.next=9;break}return e.next=6,this._createMap(n.id,n.ttl);case 6:case 17:case 29:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,PL.type))){e.next=14;break}return e.abrupt("return",new PL(i));case 14:return e.prev=14,e.next=17,this._getMap(n.id,n.includeItems);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 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(PL.type,n.id,r),a=new CL(this.services,r,(function(e,t,n){return o.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new PL(a));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return s.apply(this,arguments)})},{key:"list",value:(o=fM.default(bM.default.mark((function e(t){var n,r,i,a,o=this;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=YL(t)).mode){e.next=9;break}return e.next=6,this._createList(n.id,n.purpose,n.context,n.ttl);case 6:case 17:case 29:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,TL.type))){e.next=14;break}return e.abrupt("return",new TL(i));case 14:return e.prev=14,e.next=17,this._getList(n.id);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 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(TL.type,n.id,r),a=new EL(this.services,r,(function(e,t,n){return o.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new TL(a));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return o.apply(this,arguments)})},{key:"stream",value:(a=fM.default(bM.default.mark((function e(t){var n,r,i,a,o,s=this;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=YL(t)).mode){e.next=9;break}return e.next=6,this._createStream(n.id,n.ttl);case 6:case 17:case 29:r=e.sent,e.next=39;break;case 9:if(!(i=this.getCached(n.id,ML.type))){e.next=14;break}return e.abrupt("return",new ML(i));case 14:return e.prev=14,e.next=17,this._getStream(n.id);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 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(ML.type,n.id,r),a=function(e,t,n){return s.removeFromCacheAndSession(e,t,n)},o=new jL(this.services,r,a),o=this.entities.store(o),e.abrupt("return",new ML(o));case 44:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return a.apply(this,arguments)})},{key:"shutdown",value:(i=fM.default(bM.default.mark((function e(){return bM.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=fM.default(bM.default.mark((function e(t){return bM.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 SyncError("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=fM.default(bM.default.mark((function e(t,n){var r,i,a,o,s,u=this;return bM.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:return r=new IM(this.services.config.insightsUri).pathSegment(t).pathSegment("Items").build(),e.next=5,qL({network:this.services.network,uri:r,queryString:n,type:zL.type});case 5:return i=e.sent,(a=this.getCached(i.query_id,zL.type))||((o=this._getLiveQuery(i.query_id))||(o={indexName:t,queryExpression:n,sid:i.query_id,queryUri:r,last_event_id:i.last_event_id}),s=function(e,t,n){return u.removeFromCacheAndSession(e,t,n)},a=new DL(o,this.services,s,i.items)),this.storeRootInSessionCache(zL.type,i.query_id,a.liveQueryDescriptor),a=this.entities.store(a),e.abrupt("return",new zL(a));case 11:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"instantQuery",value:(t=fM.default(bM.default.mark((function e(t){var n,r=this;return bM.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 WL({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([ZL,JL,QL,XL])}},{key:"version",get:function(){return VL}}]),Client}(sM.ReplayEventEmitter);gM.default(Client,"connectionStateChanged","connectionStateChanged"),gM.default(Client,"connectionError","connectionError"),gM.default(Client,"tokenAboutToExpire","tokenAboutToExpire"),gM.default(Client,"tokenExpired","tokenExpired"),TM([Zj.validateTypesAsync(["undefined","string",Zj.objectSchema("open document options",{id:["string","undefined"],mode:[Zj.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[Zj.nonNegativeInteger,"undefined"],data:[Zj.pureObject,"undefined",Zj.literal(null)]})]),RM("design:type",Function),RM("design:paramtypes",[Object]),RM("design:returntype",Promise)],Client.prototype,"document",null),TM([Zj.validateTypesAsync(["undefined","string",Zj.objectSchema("open map options",{id:["string","undefined"],mode:[Zj.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[Zj.nonNegativeInteger,"undefined"],data:[Zj.pureObject,"undefined",Zj.literal(null)],includeItems:["boolean","undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Object]),RM("design:returntype",Promise)],Client.prototype,"map",null),TM([Zj.validateTypesAsync(["undefined","string",Zj.objectSchema("open list options",{id:["string","undefined"],mode:[Zj.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[Zj.nonNegativeInteger,"undefined"],data:[Zj.pureObject,"undefined",Zj.literal(null)],purpose:["string","undefined"],context:[Zj.pureObject,"undefined"],includeItems:["boolean","undefined"]})]),RM("design:type",Function),RM("design:paramtypes",[Object]),RM("design:returntype",Promise)],Client.prototype,"list",null),TM([Zj.validateTypesAsync(["undefined","string",Zj.objectSchema("open stream options",{id:["string","undefined"],mode:[Zj.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[Zj.nonNegativeInteger,"undefined"],data:[Zj.pureObject,"undefined",Zj.literal(null)]})]),RM("design:type",Function),RM("design:paramtypes",[Object]),RM("design:returntype",Promise)],Client.prototype,"stream",null),TM([Zj.validateTypesAsync(Zj.nonEmptyString),RM("design:type",Function),RM("design:paramtypes",[String]),RM("design:returntype",Promise)],Client.prototype,"updateToken",null),TM([Zj.validateTypesAsync(Zj.nonEmptyString,"string"),RM("design:type",Function),RM("design:paramtypes",[String,String]),RM("design:returntype",Promise)],Client.prototype,"liveQuery",null),TM([Zj.validateTypesAsync(Zj.nonEmptyString),RM("design:type",Function),RM("design:paramtypes",[String]),RM("design:returntype",Promise)],Client.prototype,"instantQuery",null),dj.Client=Client,dj.InsightsItem=FL,dj.InstantQuery=WL,dj.LiveQuery=zL,dj.Paginator=Paginator;var eU=dj.SyncClient=Client;dj.SyncDocument=hL,dj.SyncList=TL,dj.SyncListItem=vL,dj.SyncMap=PL,dj.SyncMapItem=RL,dj.SyncStream=ML;var tU={},nU=_e,rU=Be,iU=L,aU=pr,oU=TypeError,sU=function(e){return function(t,n,r,i){nU(n);var a=rU(t),o=iU(a),s=aU(a),u=e?s-1:0,c=e?-1:1;if(r<2)for(;;){if(u in o){i=o[u],u+=c;break}if(u+=c,e?u<0:s<=u)throw oU("Reduce of empty array with no initial value")}for(;e?u>=0:s>u;u+=c)u in o&&(i=n(i,o[u],u,a));return i}},uU={left:sU(!1),right:sU(!0)},cU=uU.left,lU=ue,fU=fc;ni({target:"Array",proto:!0,forced:!Sp("reduce")||!fU&&lU>79&&lU<83},{reduce:function(e){var t=arguments.length;return cU(this,e,t,t>1?arguments[1]:void 0)}});var dU=pi,pU=f,hU=C,vU=Ag,yU=Ft,mU=U,gU=yR,bU=D,wU=Pc,kU=Mg,xU=fr,_U=za,SU=Ee,OU=Za,EU=Yg,TU=_g,RU=o,IU=Jm.UNSUPPORTED_Y,CU=4294967295,PU=Math.min,AU=[].push,jU=hU(/./.exec),MU=hU(AU),LU=hU("".slice),UU=!RU((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]}));function NU(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}vU("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=_U(bU(this)),i=void 0===n?CU:n>>>0;if(0===i)return[];if(void 0===e)return[r];if(!gU(e))return pU(t,r,e,i);for(var a,o,s,u=[],c=(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.unicode?"u":"")+(e.sticky?"y":""),l=0,f=new RegExp(e.source,c+"g");(a=pU(TU,f,r))&&!((o=f.lastIndex)>l&&(MU(u,LU(r,l,a.index)),a.length>1&&a.index<r.length&&dU(AU,u,OU(a,1)),s=a[0].length,l=o,u.length>=i));)f.lastIndex===a.index&&f.lastIndex++;return l===r.length?!s&&jU(f,"")||MU(u,""):MU(u,LU(r,l)),u.length>i?OU(u,0,i):u}:"0".split(void 0,0).length?function(e,n){return void 0===e&&0===n?[]:pU(t,this,e,n)}:t,[function(t,n){var i=bU(this),a=mU(t)?void 0:SU(t,e);return a?pU(a,t,i,n):pU(r,_U(i),t,n)},function(e,i){var a=yU(this),o=_U(e),s=n(r,a,o,i,r!==t);if(s.done)return s.value;var u=wU(a,RegExp),c=a.unicode,l=(a.ignoreCase?"i":"")+(a.multiline?"m":"")+(a.unicode?"u":"")+(IU?"g":"y"),f=new u(IU?"^(?:"+a.source+")":a,l),d=void 0===i?CU:i>>>0;if(0===d)return[];if(0===o.length)return null===EU(f,o)?[o]:[];for(var p=0,h=0,v=[];h<o.length;){f.lastIndex=IU?0:h;var y,m=EU(f,IU?LU(o,h):o);if(null===m||(y=PU(xU(f.lastIndex+(IU?h:0)),o.length))===p)h=kU(o,h,c);else{if(MU(v,LU(o,p,h)),v.length===d)return v;for(var g=1;g<=m.length-1;g++)if(MU(v,m[g]),v.length===d)return v;h=p=y}}return MU(v,LU(o,p)),v}]}),!UU,IU),function(e){var t=void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};Object.defineProperty(e,"__esModule",{value:!0});var n=BS,r=DS.exports,i=sx.exports,a=qS,o=sy.exports,s=Q_,u=Mb;function c(e){return e&&"object"===Xu(e)&&"default"in e?e:{default:e}}function l(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 f=c(r),d=c(i),p=c(a),h=l(o);function v(e,t,n,r){var i,a=arguments.length,o=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Xu(Reflect))&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(a<3?i(o):a>3?i(t,n,o):i(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}function y(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Xu(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function m(e,t){return["".concat((new Date).toISOString()," MCS Client ").concat(e,":")].concat(Array.from(t))}var g=function(){function e(t){rc(this,e),d.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return nc(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,m(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];h.debug.apply(null,m(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];h.info.apply(null,m(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];h.warn.apply(null,m(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];h.error.apply(null,m(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new 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,m("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,m("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,m("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,m("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,m("E",t))}}]),e}(),b=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},w=function(){function e(t,n,r,i){var a,o,s,u,c,l;rc(this,e),d.default(this,"token",void 0),d.default(this,"retryWhenThrottledOverride",void 0),d.default(this,"backoffConfigOverride",void 0),d.default(this,"mediaUrl",void 0),d.default(this,"mediaSetUrl",void 0),d.default(this,"region",void 0);var f=null!==(a=null!==(o=i.MCS)&&void 0!==o?o:i)&&void 0!==a?a:{};this.region=null!==(s=null!==(u=f.region)&&void 0!==u?u:i.region)&&void 0!==s?s:"us1",this.mediaUrl=b(n,this.region),this.mediaSetUrl=r?b(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 nc(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){rc(this,Media),d.default(this,"state",void 0),d.default(this,"network",void 0),d.default(this,"config",void 0),this.config=e,this.network=t,this._update(n)}return nc(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 new n.CancellablePromise(function(){var t=f.default(p.default.mark((function t(n,r,i){var a,o;return p.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=e.network.get("".concat(e.config.mediaUrl,"/").concat(e.sid)),i((function(){return a.cancel()})),t.prev=2,t.next=5,a;case 5:o=t.sent,e._update(o.body),n(e.state.contentDirectUrl),t.next=13;break;case 10:t.prev=10,t.t0=t.catch(2),r(t.t0);case 13:case"end":return t.stop()}}),t,null,[[2,10]])})));return function(e,n,r){return t.apply(this,arguments)}}())}},{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){Qu(n,e);var t=NU(n);function n(e,r,i,a,o){var s;return rc(this,n),s=t.call(this,e),d.default(Yu(s),"code",void 0),d.default(Yu(s),"body",void 0),d.default(Yu(s),"status",void 0),d.default(Yu(s),"headers",void 0),s.code=r,s.body=i,s.status=a,s.headers=o,s}return nc(n)}(NT(Error)),x=t.XMLHttpRequest||{};var _,S=function(){function e(){rc(this,e)}return nc(e,[{key:"get",value:function(t,n){return e.request("GET",t,n)}},{key:"post",value:function(t,n,r){return e.request("POST",t,n,r)}}],[{key:"request",value:function(e,t,r,i){return new n.CancellablePromise((function(n,a,o){var s=new x,u=!1;for(var c in o((function(){s.abort(),u=!0})),s.open(e,t,!0),s.onreadystatechange=function(){if(4===s.readyState&&!u){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}),{}):{},r=function(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}}(s);if(200<=s.status&&s.status<300)n({status:s.status,headers:t,body:r});else{var i,o,c=null!==(i=s.statusText)&&void 0!==i?i:"NONE";if("string"==typeof r)if(r&&1===r.split("\n",2).length)o=r;else{var l,f=null===(l=r.replace(/<.*?>/g,"").split(/\r\n/g).filter((function(e){return e.length}))[0])||void 0===l?void 0:l.split(" ");o=(null==f?void 0:f.length)>2?null==f?void 0:f.slice(1).join(" "):""}else o=JSON.stringify(r);var d="".concat(s.status,": [").concat(c,"] ").concat(o);a(new k(d,s.status,r,c,t))}}},r)s.setRequestHeader(c,r[c]),"Content-Type"===c&&"application/json"===r[c]&&(i=JSON.stringify(i));s.send(i)}))}}]),e}(),O=g.scope("Network"),E=function(){function e(t,n){rc(this,e),d.default(this,"config",void 0),d.default(this,"transport",void 0),this.config=t,this.transport=n}return nc(e,[{key:"backoffConfig",value:function(){return Object.assign(w.backoffConfigDefault,this.config.backoffConfigOverride)}},{key:"retryWhenThrottled",value:function(){var e,t;return null!==(e=null!==(t=this.config.retryWhenThrottledOverride)&&void 0!==t?t:w.retryWhenThrottledDefault)&&void 0!==e&&e}},{key:"executeWithRetry",value:function(e,t){var r=this;return new n.CancellablePromise(function(){var n=f.default(p.default.mark((function n(i,a,o){var u,c;return p.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:u=new s.Retrier(r.backoffConfig()),c=[502,503,504],t&&c.push(429),o((function(){u.cancel(),u.removeAllListeners()})),u.on("attempt",f.default(p.default.mark((function t(){var n,r;return p.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,n=e(),o((function(){n.cancel(),u.cancel(),u.removeAllListeners()})),t.next=5,n;case 5:r=t.sent,u.succeeded(r),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(0),c.indexOf(t.t0.status)>-1||"Twilsock disconnected"===t.t0.message?u.failed(t.t0):(u.removeAllListeners(),u.cancel(),a(t.t0));case 12:case"end":return t.stop()}}),t,null,[[0,9]])})))),u.on("succeeded",(function(e){i(e)})),u.on("cancelled",(function(e){return a(e)})),u.on("failed",(function(e){return a(e)})),u.start();case 9:case"end":return n.stop()}}),n)})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"get",value:function(e){var t=this;return new n.CancellablePromise(function(){var n=f.default(p.default.mark((function n(r,i,a){var o,s,u;return p.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o={"X-Twilio-Token":t.config.token},s=t.executeWithRetry((function(){return t.transport.get(e,o)}),t.retryWhenThrottled()),O.trace("sending GET request to ",e," headers ",o),a((function(){return s.cancel()})),n.prev=4,n.next=7,s;case 7:u=n.sent,O.trace("response",u),r(u),n.next=16;break;case 12:n.prev=12,n.t0=n.catch(4),O.debug("get() error ".concat(n.t0)),i(n.t0);case 16:case"end":return n.stop()}}),n,null,[[4,12]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"post",value:function(e,r,i,a,o){var s=this,u={"X-Twilio-Token":this.config.token};"undefined"!=typeof FormData&&i instanceof FormData||!a||Object.assign(u,{"Content-Type":a});var c=new URL(e);return r&&c.searchParams.append("Category",r),o&&c.searchParams.append("Filename",o),new n.CancellablePromise(function(){var n=f.default(p.default.mark((function n(r,a,o){var l,f;return p.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return l=s.transport.post(c.href,u,i),o((function(){return l.cancel()})),O.trace("sending POST request to ".concat(e," with headers ").concat(u)),n.prev=3,n.next=6,l;case 6:f=n.sent,n.next=17;break;case 9:if(n.prev=9,n.t0=n.catch(3),!(void 0===t.XMLHttpRequest&&i instanceof FormData)){n.next=14;break}return a(new TypeError("Posting FormData supported only with browser engine's FormData")),n.abrupt("return");case 14:return O.debug("post() error ".concat(n.t0)),a(n.t0),n.abrupt("return");case 17:O.trace("response",f),r(f);case 19:case"end":return n.stop()}}),n,null,[[3,9]])})));return function(e,t,r){return n.apply(this,arguments)}}())}}]),e}(),T=g.scope("");e.default=(_=function(){function Client(e,t,n){var r,i;rc(this,Client);var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};d.default(this,"transport",void 0),d.default(this,"options",void 0),d.default(this,"network",void 0),d.default(this,"config",void 0),this.options=a,this.options.logLevel=null!==(r=this.options.logLevel)&&void 0!==r?r:"silent",this.config=new w(e,t,n,this.options),T.setLevel(this.options.logLevel),this.options.transport=null!==(i=this.options.transport)&&void 0!==i?i:new S,this.transport=this.options.transport,this.network=new E(this.config,this.transport)}return nc(Client,[{key:"updateToken",value:function(e){T.info("updateToken"),this.config.updateToken(e)}},{key:"get",value:function(e){var t=this;return new n.CancellablePromise(function(){var n=f.default(p.default.mark((function n(r,i,a){var o,s;return p.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=t.network.get("".concat(t.config.mediaUrl,"/").concat(e)),a((function(){return o.cancel()})),n.prev=2,n.next=5,o;case 5:s=n.sent,r(new Media(t.config,t.network,s.body)),n.next=12;break;case 9:n.prev=9,n.t0=n.catch(2),i(n.t0);case 12:case"end":return n.stop()}}),n,null,[[2,9]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"post",value:function(e,t,r,i){var a=this;return new n.CancellablePromise(function(){var n=f.default(p.default.mark((function n(o,s,u){var c,l;return p.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return c=a.network.post(a.config.mediaUrl,null!=r?r:"media",t,e,i),u((function(){return c.cancel()})),n.prev=2,n.next=5,c;case 5:l=n.sent,o(new Media(a.config,a.network,l.body)),n.next=12;break;case 9:n.prev=9,n.t0=n.catch(2),s(n.t0);case 12:case"end":return n.stop()}}),n,null,[[2,9]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"postFormData",value:function(e,t){var r=this;return new n.CancellablePromise(function(){var n=f.default(p.default.mark((function n(i,a,o){var s,u;return p.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return s=r.network.post(r.config.mediaUrl,null!=t?t:"media",e),o((function(){return s.cancel()})),n.prev=2,n.next=5,s;case 5:u=n.sent,i(new Media(r.config,r.network,u.body)),n.next=12;break;case 9:n.prev=9,n.t0=n.catch(2),a(n.t0);case 12:case"end":return n.stop()}}),n,null,[[2,9]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"mediaSetGet",value:function(e){var t=this;return new n.CancellablePromise(function(){var n=f.default(p.default.mark((function n(r,i,a){var o,s,u,c;return p.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o={command:"get",list:e.map((function(e){return{media_sid:e}}))},s=t.network.post("".concat(t.config.mediaSetUrl),null,o,"application/json"),a((function(){return s.cancel()})),n.prev=3,n.next=6,s;case 6:u=n.sent,c=u.body.map((function(e){if(200===e.code)return new Media(t.config,t.network,e.media_record);i("Failed to obtain detailed information about Media items (failed SID ".concat(e.media_record.sid,")"))})),r(c),n.next=14;break;case 11:n.prev=11,n.t0=n.catch(3),i(n.t0);case 14:case"end":return n.stop()}}),n,null,[[3,11]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"mediaSetGetContentUrls",value:function(e){var t=this;return new n.CancellablePromise(function(){var n=f.default(p.default.mark((function n(r,i,a){var o,s,u,c;return p.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o={command:"get",list:e.map((function(e){return{media_sid:e}}))},s=t.network.post("".concat(t.config.mediaSetUrl),null,o,"application/json"),a((function(){return s.cancel()})),n.prev=3,n.next=6,s;case 6:u=n.sent,c=new Map,u.body.forEach((function(e){200===e.code?c.set(e.media_record.sid,e.media_record.links.content_direct_temporary):i("Failed to obtain detailed information about Media items (failed SID ".concat(e.media_record.sid,")"))})),r(c),n.next=15;break;case 12:n.prev=12,n.t0=n.catch(3),i(n.t0);case 15:case"end":return n.stop()}}),n,null,[[3,12]])})));return function(e,t,r){return n.apply(this,arguments)}}())}}]),Client}(),d.default(_,"version","0.6.1"),_),v([u.validateTypes(u.nonEmptyString),y("design:type",Function),y("design:paramtypes",[String]),y("design:returntype",void 0)],e.default.prototype,"updateToken",null),v([u.validateTypesAsync(u.nonEmptyString),y("design:type",Function),y("design:paramtypes",[String]),y("design:returntype",n.CancellablePromise)],e.default.prototype,"get",null),e.default=v([u.validateConstructorTypes(u.nonEmptyString,u.nonEmptyString,[u.nonEmptyString,u.literal(null)],[u.pureObject,"undefined"]),y("design:paramtypes",[String,String,Object,Object])],e.default),Object.defineProperty(e,"CancellablePromise",{enumerable:!0,get:function(){return n.CancellablePromise}}),e.Client=e.default,e.McsClient=e.default,e.McsMedia=Media,e.Media=Media}(tU);var FU,DU,qU,BU={exports:{}},zU=jO,WU=s,$U=i,KU=H,HU=Y,GU=$e,VU=Li,YU=be,JU=Xt,QU=Xn,XU=jt.f,ZU=ee,eN=dv,tN=gc,nN=ot,rN=Ye,iN=Ln.enforce,aN=Ln.get,oN=$U.Int8Array,sN=oN&&oN.prototype,uN=$U.Uint8ClampedArray,cN=uN&&uN.prototype,lN=oN&&eN(oN),fN=sN&&eN(sN),dN=Object.prototype,pN=$U.TypeError,hN=nN("toStringTag"),vN=rN("TYPED_ARRAY_TAG"),yN="TypedArrayConstructor",mN=zU&&!!tN&&"Opera"!==VU($U.opera),gN=!1,bN={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},wN={BigInt64Array:8,BigUint64Array:8},kN=function(e){var t=eN(e);if(HU(t)){var n=aN(t);return n&&GU(n,yN)?n.TypedArrayConstructor:kN(t)}},xN=function(e){if(!HU(e))return!1;var t=VU(e);return GU(bN,t)||GU(wN,t)};for(FU in bN)(qU=(DU=$U[FU])&&DU.prototype)?iN(qU).TypedArrayConstructor=DU:mN=!1;for(FU in wN)(qU=(DU=$U[FU])&&DU.prototype)&&(iN(qU).TypedArrayConstructor=DU);if((!mN||!KU(lN)||lN===Function.prototype)&&(lN=function(){throw pN("Incorrect invocation")},mN))for(FU in bN)$U[FU]&&tN($U[FU],lN);if((!mN||!fN||fN===dN)&&(fN=lN.prototype,mN))for(FU in bN)$U[FU]&&tN($U[FU].prototype,fN);if(mN&&eN(cN)!==fN&&tN(cN,fN),WU&&!GU(fN,hN))for(FU in gN=!0,XU(fN,hN,{get:function(){return HU(this)?this[vN]:void 0}}),bN)$U[FU]&&JU($U[FU],vN,FU);var _N={NATIVE_ARRAY_BUFFER_VIEWS:mN,TYPED_ARRAY_TAG:gN&&vN,aTypedArray:function(e){if(xN(e))return e;throw pN("Target is not a typed array")},aTypedArrayConstructor:function(e){if(KU(e)&&(!tN||ZU(lN,e)))return e;throw pN(YU(e)+" is not a typed array constructor")},exportTypedArrayMethod:function(e,t,n,r){if(WU){if(n)for(var i in bN){var a=$U[i];if(a&&GU(a.prototype,e))try{delete a.prototype[e]}catch(n){try{a.prototype[e]=t}catch(e){}}}fN[e]&&!n||QU(fN,e,n?t:mN&&sN[e]||t,r)}},exportTypedArrayStaticMethod:function(e,t,n){var r,i;if(WU){if(tN){if(n)for(r in bN)if((i=$U[r])&&GU(i,e))try{delete i[e]}catch(e){}if(lN[e]&&!n)return;try{return QU(lN,e,n?t:mN&&lN[e]||t)}catch(e){}}for(r in bN)!(i=$U[r])||i[e]&&!n||QU(i,e,t)}},getTypedArrayConstructor:kN,isView:function(e){if(!HU(e))return!1;var t=VU(e);return"DataView"===t||GU(bN,t)||GU(wN,t)},isTypedArray:xN,TypedArray:lN,TypedArrayPrototype:fN},SN=i,ON=o,EN=zd,TN=_N.NATIVE_ARRAY_BUFFER_VIEWS,RN=SN.ArrayBuffer,IN=SN.Int8Array,CN=!TN||!ON((function(){IN(1)}))||!ON((function(){new IN(-1)}))||!EN((function(e){new IN,new IN(null),new IN(1.5),new IN(e)}),!0)||ON((function(){return 1!==new IN(new RN(2),1,void 0).length})),PN=ir,AN=RangeError,jN=function(e){var t=PN(e);if(t<0)throw AN("The argument can't be less than 0");return t},MN=RangeError,LN=function(e,t){var n=jN(e);if(n%t)throw MN("Wrong offset");return n},UN=Li,NN=C("".slice),FN=ht,DN=TypeError,qN=function(e){var t=FN(e,"number");if("number"==typeof t)throw DN("Can't convert number to bigint");return BigInt(t)},BN=wo,zN=f,WN=Zi,$N=Be,KN=pr,HN=bd,GN=dd,VN=od,YN=function(e){return"Big"===NN(UN(e),0,3)},JN=_N.aTypedArrayConstructor,QN=qN,XN=ni,ZN=i,eF=f,tF=s,nF=CN,rF=_N,iF=YE,aF=Ec,oF=g,sF=Xt,uF=ek,cF=fr,lF=NO,fF=LN,dF=mt,pF=$e,hF=Li,vF=Y,yF=me,mF=_a,gF=ee,bF=gc,wF=Zn.f,kF=function(e){var t,n,r,i,a,o,s,u,c=WN(this),l=$N(e),f=arguments.length,d=f>1?arguments[1]:void 0,p=void 0!==d,h=GN(l);if(h&&!VN(h))for(u=(s=HN(l,h)).next,l=[];!(o=zN(u,s)).done;)l.push(o.value);for(p&&f>2&&(d=BN(d,arguments[2])),n=KN(l),r=new(JN(c))(n),i=YN(r),t=0;n>t;t++)a=p?d(l[t],t):l[t],r[t]=i?QN(a):+a;return r},xF=No.forEach,_F=_c,SF=jt,OF=a,EF=rm,TF=Ln.get,RF=Ln.set,IF=Ln.enforce,CF=SF.f,PF=OF.f,AF=Math.round,jF=ZN.RangeError,MF=iF.ArrayBuffer,LF=MF.prototype,UF=iF.DataView,NF=rF.NATIVE_ARRAY_BUFFER_VIEWS,FF=rF.TYPED_ARRAY_TAG,DF=rF.TypedArray,qF=rF.TypedArrayPrototype,BF=rF.aTypedArrayConstructor,zF=rF.isTypedArray,WF="BYTES_PER_ELEMENT",$F="Wrong length",KF=function(e,t){BF(e);for(var n=0,r=t.length,i=new e(r);r>n;)i[n]=t[n++];return i},HF=function(e,t){CF(e,t,{get:function(){return TF(this)[t]}})},GF=function(e){var t;return gF(LF,e)||"ArrayBuffer"==(t=hF(e))||"SharedArrayBuffer"==t},VF=function(e,t){return zF(e)&&!yF(t)&&t in e&&uF(+t)&&t>=0},YF=function(e,t){return t=dF(t),VF(e,t)?oF(2,e[t]):PF(e,t)},JF=function(e,t,n){return t=dF(t),!(VF(e,t)&&vF(n)&&pF(n,"value"))||pF(n,"get")||pF(n,"set")||n.configurable||pF(n,"writable")&&!n.writable||pF(n,"enumerable")&&!n.enumerable?CF(e,t,n):(e[t]=n.value,e)};tF?(NF||(OF.f=YF,SF.f=JF,HF(qF,"buffer"),HF(qF,"byteOffset"),HF(qF,"byteLength"),HF(qF,"length")),XN({target:"Object",stat:!0,forced:!NF},{getOwnPropertyDescriptor:YF,defineProperty:JF}),BU.exports=function(e,t,n){var r=e.match(/\d+$/)[0]/8,i=e+(n?"Clamped":"")+"Array",a="get"+e,o="set"+e,s=ZN[i],u=s,c=u&&u.prototype,l={},f=function(e,t){CF(e,t,{get:function(){return function(e,t){var n=TF(e);return n.view[a](t*r+n.byteOffset,!0)}(this,t)},set:function(e){return function(e,t,i){var a=TF(e);n&&(i=(i=AF(i))<0?0:i>255?255:255&i),a.view[o](t*r+a.byteOffset,i,!0)}(this,t,e)},enumerable:!0})};NF?nF&&(u=t((function(e,t,n,i){return aF(e,c),EF(vF(t)?GF(t)?void 0!==i?new s(t,fF(n,r),i):void 0!==n?new s(t,fF(n,r)):new s(t):zF(t)?KF(u,t):eF(kF,u,t):new s(lF(t)),e,u)})),bF&&bF(u,DF),xF(wF(s),(function(e){e in u||sF(u,e,s[e])})),u.prototype=c):(u=t((function(e,t,n,i){aF(e,c);var a,o,s,l=0,d=0;if(vF(t)){if(!GF(t))return zF(t)?KF(u,t):eF(kF,u,t);a=t,d=fF(n,r);var p=t.byteLength;if(void 0===i){if(p%r)throw jF($F);if((o=p-d)<0)throw jF($F)}else if((o=cF(i)*r)+d>p)throw jF($F);s=o/r}else s=lF(t),a=new MF(o=s*r);for(RF(e,{buffer:a,byteOffset:d,byteLength:o,length:s,view:new UF(a)});l<s;)f(e,l++)})),bF&&bF(u,DF),c=u.prototype=mF(qF)),c.constructor!==u&&sF(c,"constructor",u),IF(c).TypedArrayConstructor=u,FF&&sF(c,FF,i);var d=u!=s;l[i]=u,XN({global:!0,constructor:!0,forced:d,sham:!NF},l),WF in u||sF(u,WF,r),WF in c||sF(c,WF,r),_F(i)}):BU.exports=function(){},(0,BU.exports)("Uint8",(function(e){return function(t,n,r){return e(this,t,n,r)}}));var QF=pr,XF=ir,ZF=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("at",(function(e){var t=ZF(this),n=QF(t),r=XF(e),i=r>=0?r:n+r;return i<0||i>=n?void 0:t[i]}));var eD=be,tD=TypeError,nD=function(e,t){if(!delete e[t])throw tD("Cannot delete property "+eD(t)+" of "+eD(e))},rD=Be,iD=ur,aD=pr,oD=nD,sD=Math.min,uD=[].copyWithin||function(e,t){var n=rD(this),r=aD(n),i=iD(e,r),a=iD(t,r),o=arguments.length>2?arguments[2]:void 0,s=sD((void 0===o?r:iD(o,r))-a,r-i),u=1;for(a<i&&i<a+s&&(u=-1,a+=s-1,i+=s-1);s-- >0;)a in n?n[i]=n[a]:oD(n,i),i+=u,a+=u;return n},cD=_N,lD=C(uD),fD=cD.aTypedArray;(0,cD.exportTypedArrayMethod)("copyWithin",(function(e,t){return lD(fD(this),e,t,arguments.length>2?arguments[2]:void 0)}));var dD=No.every,pD=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("every",(function(e){return dD(pD(this),e,arguments.length>1?arguments[1]:void 0)}));var hD=VO,vD=qN,yD=Li,mD=f,gD=o,bD=_N.aTypedArray,wD=_N.exportTypedArrayMethod,kD=C("".slice);wD("fill",(function(e){var t=arguments.length;bD(this);var n="Big"===kD(yD(this),0,3)?vD(e):+e;return mD(hD,this,n,t>1?arguments[1]:void 0,t>2?arguments[2]:void 0)}),gD((function(){var e=0;return new Int8Array(2).fill({valueOf:function(){return e++}}),1!==e})));var xD=pr,_D=Pc,SD=_N.aTypedArrayConstructor,OD=_N.getTypedArrayConstructor,ED=function(e){return SD(_D(e,OD(e)))},TD=function(e,t){for(var n=0,r=xD(t),i=new e(r);r>n;)i[n]=t[n++];return i},RD=ED,ID=No.filter,CD=function(e,t){return TD(RD(e),t)},PD=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("filter",(function(e){var t=ID(PD(this),e,arguments.length>1?arguments[1]:void 0);return CD(this,t)}));var AD=No.find,jD=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("find",(function(e){return AD(jD(this),e,arguments.length>1?arguments[1]:void 0)}));var MD=No.findIndex,LD=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("findIndex",(function(e){return MD(LD(this),e,arguments.length>1?arguments[1]:void 0)}));var UD=wo,ND=L,FD=Be,DD=pr,qD=function(e){var t=1==e;return function(n,r,i){for(var a,o=FD(n),s=ND(o),u=UD(r,i),c=DD(s);c-- >0;)if(u(a=s[c],c,o))switch(e){case 0:return a;case 1:return c}return t?-1:void 0}},BD={findLast:qD(0),findLastIndex:qD(1)},zD=BD.findLast,WD=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("findLast",(function(e){return zD(WD(this),e,arguments.length>1?arguments[1]:void 0)}));var $D=BD.findLastIndex,KD=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("findLastIndex",(function(e){return $D(KD(this),e,arguments.length>1?arguments[1]:void 0)}));var HD=No.forEach,GD=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("forEach",(function(e){HD(GD(this),e,arguments.length>1?arguments[1]:void 0)}));var VD=gr.includes,YD=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("includes",(function(e){return VD(YD(this),e,arguments.length>1?arguments[1]:void 0)}));var JD=gr.indexOf,QD=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("indexOf",(function(e){return JD(QD(this),e,arguments.length>1?arguments[1]:void 0)}));var XD=i,ZD=o,eq=C,tq=_N,nq=By,rq=ot("iterator"),iq=XD.Uint8Array,aq=eq(nq.values),oq=eq(nq.keys),sq=eq(nq.entries),uq=tq.aTypedArray,cq=tq.exportTypedArrayMethod,lq=iq&&iq.prototype,fq=!ZD((function(){lq[rq].call([1])})),dq=!!lq&&lq.values&&lq[rq]===lq.values&&"values"===lq.values.name,pq=function(){return aq(uq(this))};cq("entries",(function(){return sq(uq(this))}),fq),cq("keys",(function(){return oq(uq(this))}),fq),cq("values",pq,fq||!dq,{name:"values"}),cq(rq,pq,fq||!dq,{name:"values"});var hq=_N.aTypedArray,vq=_N.exportTypedArrayMethod,yq=C([].join);vq("join",(function(e){return yq(hq(this),e)}));var mq=pi,gq=z,bq=ir,wq=pr,kq=Sp,xq=Math.min,_q=[].lastIndexOf,Sq=!!_q&&1/[1].lastIndexOf(1,-0)<0,Oq=kq("lastIndexOf"),Eq=Sq||!Oq?function(e){if(Sq)return mq(_q,this,arguments)||0;var t=gq(this),n=wq(t),r=n-1;for(arguments.length>1&&(r=xq(r,bq(arguments[1]))),r<0&&(r=n+r);r>=0;r--)if(r in t&&t[r]===e)return r||0;return-1}:_q,Tq=pi,Rq=Eq,Iq=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("lastIndexOf",(function(e){var t=arguments.length;return Tq(Rq,Iq(this),t>1?[e,arguments[1]]:[e])}));var Cq=No.map,Pq=ED,Aq=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("map",(function(e){return Cq(Aq(this),e,arguments.length>1?arguments[1]:void 0,(function(e,t){return new(Pq(e))(t)}))}));var jq=uU.left,Mq=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("reduce",(function(e){var t=arguments.length;return jq(Mq(this),e,t,t>1?arguments[1]:void 0)}));var Lq=uU.right,Uq=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("reduceRight",(function(e){var t=arguments.length;return Lq(Uq(this),e,t,t>1?arguments[1]:void 0)}));var Nq=_N.aTypedArray,Fq=_N.exportTypedArrayMethod,Dq=Math.floor;Fq("reverse",(function(){for(var e,t=this,n=Nq(t).length,r=Dq(n/2),i=0;i<r;)e=t[i],t[i++]=t[--n],t[n]=e;return t}));var qq=i,Bq=f,zq=_N,Wq=pr,$q=LN,Kq=Be,Hq=o,Gq=qq.RangeError,Vq=qq.Int8Array,Yq=Vq&&Vq.prototype,Jq=Yq&&Yq.set,Qq=zq.aTypedArray,Xq=zq.exportTypedArrayMethod,Zq=!Hq((function(){var e=new Uint8ClampedArray(2);return Bq(Jq,e,{length:1,0:3},1),3!==e[1]})),eB=Zq&&zq.NATIVE_ARRAY_BUFFER_VIEWS&&Hq((function(){var e=new Vq(2);return e.set(1),e.set("2",1),0!==e[0]||2!==e[1]}));Xq("set",(function(e){Qq(this);var t=$q(arguments.length>1?arguments[1]:void 0,1),n=Kq(e);if(Zq)return Bq(Jq,this,n,t);var r=this.length,i=Wq(n),a=0;if(i+t>r)throw Gq("Wrong length");for(;a<i;)this[t+a]=n[a++]}),!Zq||eB);var tB=ED,nB=hi,rB=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("slice",(function(e,t){for(var n=nB(rB(this),e,t),r=tB(this),i=0,a=n.length,o=new r(a);a>i;)o[i]=n[i++];return o}),o((function(){new Int8Array(1).slice()})));var iB=No.some,aB=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("some",(function(e){return iB(aB(this),e,arguments.length>1?arguments[1]:void 0)}));var oB=te.match(/firefox\/(\d+)/i),sB=!!oB&&+oB[1],uB=/MSIE|Trident/.test(te),cB=te.match(/AppleWebKit\/(\d+)\./),lB=!!cB&&+cB[1],fB=C,dB=o,pB=_e,hB=HI,vB=sB,yB=uB,mB=ue,gB=lB,bB=_N.aTypedArray,wB=_N.exportTypedArrayMethod,kB=i.Uint16Array,xB=kB&&fB(kB.prototype.sort),_B=!(!xB||dB((function(){xB(new kB(2),null)}))&&dB((function(){xB(new kB(2),{})}))),SB=!!xB&&!dB((function(){if(mB)return mB<74;if(vB)return vB<67;if(yB)return!0;if(gB)return gB<602;var e,t,n=new kB(516),r=Array(516);for(e=0;e<516;e++)t=e%4,n[e]=515-e,r[e]=e-2*t+3;for(xB(n,(function(e,t){return(e/4|0)-(t/4|0)})),e=0;e<516;e++)if(n[e]!==r[e])return!0}));wB("sort",(function(e){return void 0!==e&&pB(e),SB?xB(this,e):hB(bB(this),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))}),!SB||_B);var OB=fr,EB=ur,TB=ED,RB=_N.aTypedArray;(0,_N.exportTypedArrayMethod)("subarray",(function(e,t){var n=RB(this),r=n.length,i=EB(e,r);return new(TB(n))(n.buffer,n.byteOffset+i*n.BYTES_PER_ELEMENT,OB((void 0===t?r:EB(t,r))-i))}));var IB=pi,CB=_N,PB=o,AB=hi,jB=i.Int8Array,MB=CB.aTypedArray,LB=CB.exportTypedArrayMethod,UB=[].toLocaleString,NB=!!jB&&PB((function(){UB.call(new jB(1))}));LB("toLocaleString",(function(){return IB(UB,NB?AB(MB(this)):MB(this),AB(arguments))}),PB((function(){return[1,2].toLocaleString()!=new jB([1,2]).toLocaleString()}))||!PB((function(){jB.prototype.toLocaleString.call([1,2])})));var FB=_N.exportTypedArrayMethod,DB=o,qB=C,BB=i.Uint8Array,zB=BB&&BB.prototype||{},WB=[].toString,$B=qB([].join);DB((function(){WB.call({})}))&&(WB=function(){return $B(this)});var KB=zB.toString!=WB;function HB(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}FB("toString",WB,KB);var GB=dy.scope("Participant"),Participant=function(e){Qu(Participant,e);var t,n,r,i=HB(Participant);function Participant(e,t,n,r,a){var o,s,u;if(rc(this,Participant),ic(Yu(u=i.call(this)),"state",void 0),ic(Yu(u),"links",void 0),ic(Yu(u),"services",void 0),ic(Yu(u),"conversation",void 0),u.conversation=n,u.links=r,u.services=a,u.state={attributes:Ab(e.attributes,"Retrieved malformed attributes from the server for participant: "+t,GB),dateCreated:e.dateCreated?Pb(e.dateCreated):null,dateUpdated:e.dateCreated?Pb(e.dateUpdated):null,sid:t,typingTimeout:null,isTyping:!1,identity:e.identity,roleSid:null!==(o=e.roleSid)&&void 0!==o?o:"",lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,lastReadTimestamp:e.lastConsumptionTimestamp?Pb(e.lastConsumptionTimestamp):null,type:e.type||"chat",userInfo:e.userInfo,bindings:null!==(s=e.bindings)&&void 0!==s?s:{}},!e.identity&&!e.type)throw new Error("Received invalid Participant object from server: Missing identity or type of Participant.");return u}return nc(Participant,[{key:"sid",get:function(){return this.state.sid}},{key:"attributes",get:function(){return this.state.attributes}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"identity",get:function(){return this.state.identity}},{key:"isTyping",get:function(){return this.state.isTyping}},{key:"lastReadMessageIndex",get:function(){return this.state.lastReadMessageIndex}},{key:"lastReadTimestamp",get:function(){return this.state.lastReadTimestamp}},{key:"roleSid",get:function(){return this.state.roleSid}},{key:"type",get:function(){return this.state.type}},{key:"bindings",get:function(){var e;return null!==(e=this.state.bindings)&&void 0!==e?e:{}}},{key:"_startTyping",value:function(e){var t=this;return this.state.typingTimeout&&clearTimeout(this.state.typingTimeout),this.state.isTyping=!0,this.emit("typingStarted",this),this.conversation.emit("typingStarted",this),this.state.typingTimeout=Number(setTimeout((function(){return t._endTyping()}),e)),this}},{key:"_endTyping",value:function(){this.state.typingTimeout&&(this.state.isTyping=!1,this.emit("typingEnded",this),this.conversation.emit("typingEnded",this),clearInterval(this.state.typingTimeout),this.state.typingTimeout=null)}},{key:"_update",value:function(e){var t=[],n=Ab(e.attributes,"Retrieved malformed attributes from the server for participant: "+this.state.sid,GB);e.attributes&&!zx(this.state.attributes,n)&&(this.state.attributes=n,t.push("attributes"));var r=Pb(e.dateUpdated);e.dateUpdated&&(null==r?void 0:r.getTime())!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=r,t.push("dateUpdated"));var i=Pb(e.dateCreated);if(e.dateCreated&&(null==i?void 0:i.getTime())!==(this.state.dateCreated&&this.state.dateCreated.getTime())&&(this.state.dateCreated=i,t.push("dateCreated")),e.roleSid&&this.state.roleSid!==e.roleSid&&(this.state.roleSid=e.roleSid,t.push("roleSid")),!Number.isInteger(e.lastConsumedMessageIndex)&&null!==e.lastConsumedMessageIndex||this.state.lastReadMessageIndex===e.lastConsumedMessageIndex||(this.state.lastReadMessageIndex=e.lastConsumedMessageIndex,t.push("lastReadMessageIndex")),e.lastConsumptionTimestamp){var a=new Date(e.lastConsumptionTimestamp);this.state.lastReadTimestamp&&this.state.lastReadTimestamp.getTime()===a.getTime()||(this.state.lastReadTimestamp=a,t.push("lastReadTimestamp"))}return e.bindings&&!zx(this.state.bindings,e.bindings)&&(this.state.bindings=e.bindings,t.push("bindings")),t.length>0&&this.emit("updated",{participant:this,updateReasons:t}),this}},{key:"getUser",value:(r=Vu(lh.mark((function e(){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("chat"==this.type){e.next=2;break}throw new Error("Getting User is not supported for this Participant type: "+this.type);case 2:return e.abrupt("return",this.services.users.getUser(this.state.identity,this.state.userInfo));case 3:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"remove",value:(n=Vu(lh.mark((function e(){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.conversation.removeParticipant(this));case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"updateAttributes",value:(t=Vu(lh.mark((function e(t){return lh.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}(qx);function VB(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}ic(Participant,"typingStarted","typingStarted"),ic(Participant,"typingEnded","typingEnded"),ic(Participant,"updated","updated"),dh([tx(nx),ph("design:type",Function),ph("design:paramtypes",[Object]),ph("design:returntype",Promise)],Participant.prototype,"updateAttributes",null);var YB=dy.scope("Participants"),JB=function(e){Qu(l,e);var t,n,r,i,a,o,s,u,c=VB(l);function l(e,t,n,r,i){var a;return rc(this,l),ic(Yu(a=c.call(this)),"configuration",void 0),ic(Yu(a),"services",void 0),ic(Yu(a),"links",void 0),ic(Yu(a),"rosterEntityPromise",null),ic(Yu(a),"conversation",void 0),ic(Yu(a),"participants",void 0),a.conversation=e,a.participants=t,a.links=n,a.configuration=r,a.services=i,a}return nc(l,[{key:"unsubscribe",value:(u=Vu(lh.mark((function e(){return lh.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 u.apply(this,arguments)})},{key:"subscribe",value:function(e){var t=this,n="string"==typeof e?this.services.syncClient.map({id:e,mode:"open_existing"}):Promise.resolve(e);return this.rosterEntityPromise=this.rosterEntityPromise||n.then((function(e){e.on("itemAdded",(function(e){YB.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){YB.debug(t.conversation.sid+" itemRemoved: "+e.key);var n=e.key;if(t.participants.has(n)){var r=t.participants.get(n);t.participants.delete(n),r&&t.emit("participantLeft",r)}})),e.on("itemUpdated",(function(e){YB.debug(t.conversation.sid+" itemUpdated: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data)}));var n=[];return e.getItems().then((function e(r){return r.items.forEach((function(e){n.push(t.upsertParticipant(e.key,e.data))})),r.hasNextPage?r.nextPage().then(e):null})).then((function(){return Promise.all(n)})).then((function(){return e}))})).catch((function(e){throw t.rosterEntityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&YB.error("Failed to get roster object for conversation",t.conversation.sid,e),YB.debug("ERROR: Failed to get roster object for conversation",t.conversation.sid,e),e}))}},{key:"upsertParticipantFromResponse",value:(s=Vu(lh.mark((function e(t){var n,r,i,a,o,s,u,c;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.sid,i=t.attributes,a=t.date_created,o=t.date_updated,s=t.identity,u=t.role_sid,c=t.messaging_binding,e.next=3,this.upsertParticipant(r,{attributes:i,dateCreated:new Date(a),dateUpdated:new Date(o),identity:s,roleSid:u,lastConsumedMessageIndex:null,lastConsumptionTimestamp:null,type:null!==(n=null==c?void 0:c.type)&&void 0!==n?n:"chat"});case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"upsertParticipant",value:(o=Vu(lh.mark((function e(t,n){var r,i,a=this;return lh.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 o.apply(this,arguments)})},{key:"getParticipants",value:(a=Vu(lh.mark((function e(){var t=this;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){var e=[];return t.participants.forEach((function(t){return e.push(t)})),e})):[]);case 1:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"getParticipantBySid",value:(i=Vu(lh.mark((function e(t){var n=this;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){var e=n.participants.get(t);if(!e)throw new Error("Participant with SID "+t+" was not found");return e})):null);case 1:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(r=Vu(lh.mark((function e(t){var n,r=this;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){if(r.participants.forEach((function(e){e.identity===t&&(n=e)})),!n)throw new Error("Participant with identity "+t+" was not found");return n})):null);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"add",value:(n=Vu(lh.mark((function e(t,n){var r;return lh.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 r=e.sent,e.next=5,this.upsertParticipantFromResponse(r);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:"addNonChatParticipant",value:(t=Vu(lh.mark((function e(t,n){var r,i,a,o,s,u=arguments;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=u.length>2&&void 0!==u[2]?u[2]:{},o=u.length>3&&void 0!==u[3]?u[3]:{},e.next=4,this.services.commandExecutor.mutateResource("post",this.links.participants,{attributes:void 0!==a?JSON.stringify(a):void 0,messaging_binding:{address:n,proxy_address:t,name:null==o||null===(r=o.email)||void 0===r?void 0:r.name,level:null==o||null===(i=o.email)||void 0===i?void 0:i.level}});case 4:return s=e.sent,e.next=7,this.upsertParticipantFromResponse(s);case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})},{key:"remove",value:function(e){return this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(e))}}]),l}(qx),QB=ni,XB=C,ZB=_e,ez=Be,tz=pr,nz=nD,rz=za,iz=o,az=HI,oz=Sp,sz=sB,uz=uB,cz=ue,lz=lB,fz=[],dz=XB(fz.sort),pz=XB(fz.push),hz=iz((function(){fz.sort(void 0)})),vz=iz((function(){fz.sort(null)})),yz=oz("sort"),mz=!iz((function(){if(cz)return cz<70;if(!(sz&&sz>3)){if(uz)return!0;if(lz)return lz<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++)fz.push({k:t+r,v:n})}for(fz.sort((function(e,t){return t.v-e.v})),r=0;r<fz.length;r++)t=fz[r].k.charAt(0),i.charAt(i.length-1)!==t&&(i+=t);return"DGBEFHACIJK"!==i}}));QB({target:"Array",proto:!0,forced:hz||!vz||!yz||!mz},{sort:function(e){void 0!==e&&ZB(e);var t=ez(this);if(mz)return void 0===e?dz(t):dz(t,e);var n,r,i=[],a=tz(t);for(r=0;r<a;r++)r in t&&pz(i,t[r]);for(az(i,function(e){return function(t,n){return void 0===n?-1:void 0===t?1:void 0!==e?+e(t,n)||0:rz(t)>rz(n)?1:-1}}(e)),n=tz(i),r=0;r<n;)t[r]=i[r++];for(;r<a;)nz(t,r++);return t}});var gz=ni,bz=bR,wz=D,kz=za,xz=kR,_z=C("".indexOf);gz({target:"String",proto:!0,forced:!xz("includes")},{includes:function(e){return!!~_z(kz(wz(this)),kz(bz(e)),arguments.length>1?arguments[1]:void 0)}});var Media=function(){function Media(e,t){rc(this,Media),ic(this,"state",void 0),ic(this,"services",void 0),ic(this,"mcsMedia",null),this.services=t,e instanceof tU.McsMedia&&(this.mcsMedia=e),this.state={sid:e.sid,category:e.category,filename:e.filename,contentType:e.contentType,size:e.size}}return nc(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"filename",get:function(){return this.state.filename}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"category",get:function(){return this.state.category}},{key:"getContentTemporaryUrl",value:function(){var e=this;return new tU.CancellablePromise(function(){var t=Vu(lh.mark((function t(n,r,i){var a,o,s,u;return lh.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o=e._fetchMcsMedia(),s=null===(a=e.mcsMedia)||void 0===a?void 0:a.getContentUrl(),i((function(){o.cancel(),s&&s.cancel()})),t.prev=3,e.mcsMedia){t.next=9;break}return t.next=7,o;case 7:u=t.sent,s=u.getContentUrl();case 9:if(t.t0=n,!s){t.next=16;break}return t.next=13,s;case 13:t.t1=t.sent,t.next=17;break;case 16:t.t1=null;case 17:t.t2=t.t1,(0,t.t0)(t.t2),t.next=24;break;case 21:t.prev=21,t.t3=t.catch(3),r(t.t3);case 24:case"end":return t.stop()}}),t,null,[[3,21]])})));return function(e,n,r){return t.apply(this,arguments)}}())}},{key:"_fetchMcsMedia",value:function(){var e=this;return new tU.CancellablePromise(function(){var t=Vu(lh.mark((function t(n,r,i){var a;return lh.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=e.services.mcsClient.get(e.state.sid),!e.services.mcsClient){t.next=14;break}return i((function(){return a.cancel()})),t.prev=3,t.next=6,a;case 6:e.mcsMedia=t.sent,n(e.mcsMedia),t.next=13;break;case 10:t.prev=10,t.t0=t.catch(3),r(t.t0);case 13:return t.abrupt("return");case 14:r(new Error("Media Content Service is unavailable"));case 15:case"end":return t.stop()}}),t,null,[[3,10]])})));return function(e,n,r){return t.apply(this,arguments)}}())}}]),Media}(),AggregatedDeliveryReceipt=function(){function AggregatedDeliveryReceipt(e){rc(this,AggregatedDeliveryReceipt),ic(this,"state",void 0),this.state=e}return nc(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,o=this.failed===e.failed;return t&&n&&r&&i&&a&&o}}]),AggregatedDeliveryReceipt}(),Sz=function(){function e(t,n,r,i){rc(this,e),ic(this,"state",void 0),this.state={prevToken:r,nextToken:i,source:n,items:t}}return nc(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=nc((function DetailedDeliveryReceipt(e){rc(this,DetailedDeliveryReceipt),ic(this,"sid",void 0),ic(this,"messageSid",void 0),ic(this,"conversationSid",void 0),ic(this,"channelMessageSid",void 0),ic(this,"participantSid",void 0),ic(this,"status",void 0),ic(this,"errorCode",void 0),ic(this,"dateCreated",void 0),ic(this,"dateUpdated",void 0),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 Oz(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 Ez(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Oz(Object(n),!0).forEach((function(t){ic(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Oz(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Tz(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}var Rz=dy.scope("Message"),Message=function(e){Qu(Message,e);var t,n,r,i,a,o,s=Tz(Message);function Message(e,t,n,r,i,a){var o,u,c,l,f;return rc(this,Message),ic(Yu(f=s.call(this)),"conversation",void 0),ic(Yu(f),"links",void 0),ic(Yu(f),"configuration",void 0),ic(Yu(f),"services",void 0),ic(Yu(f),"state",void 0),f.conversation=n,f.links=r,f.configuration=i,f.services=a,f.state={sid:t.sid,index:e,author:t.author,subject:t.subject,body:null!==(o=t.text)&&void 0!==o?o:null,timestamp:t.timestamp?new Date(t.timestamp):null,dateUpdated:t.dateUpdated?new Date(t.dateUpdated):null,lastUpdatedBy:null!==(u=t.lastUpdatedBy)&&void 0!==u?u:null,attributes:Ab(t.attributes,"Got malformed attributes for the message ".concat(t.sid),Rz),type:null!==(c=t.type)&&void 0!==c?c:"text",media:"media"===t.type&&t.media?new Media(t.media,f.services):null,medias:"media"===t.type&&t.medias?t.medias.map((function(e){return new Media(e,f.services)})):"media"===t.type&&t.media&&!t.medias?[new Media(Ez(Ez({},t.media),{},{category:"media"}),f.services)]:null,participantSid:null!==(l=t.memberSid)&&void 0!==l?l:null,aggregatedDeliveryReceipt:t.delivery?new AggregatedDeliveryReceipt(t.delivery):null},f}return nc(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.getMediaByCategories(["media"])}},{key:"participantSid",get:function(){return this.state.participantSid}},{key:"aggregatedDeliveryReceipt",get:function(){return this.state.aggregatedDeliveryReceipt}},{key:"getMediaByCategories",value:function(e){var t;return(null!==(t=this.state.medias)&&void 0!==t?t:[]).filter((function(t){return e.includes(t.category)}))}},{key:"getEmailBody",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategories(["body"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"getEmailHistory",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategories(["history"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"_update",value:function(e){var t=[];!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=Ab(e.attributes,"Got malformed attributes for the message ".concat(this.sid),Rz);zx(this.state.attributes,n)||(this.state.attributes=n,t.push("attributes"));var r=e.delivery,i=this.state.aggregatedDeliveryReceipt;!!(r&&r.total&&r.delivered&&r.failed&&r.read&&r.sent&&r.undelivered)&&(i?i._isEquals(r)||(i._update(r),t.push("deliveryReceipt")):(this.state.aggregatedDeliveryReceipt=new AggregatedDeliveryReceipt(r),t.push("deliveryReceipt"))),t.length>0&&this.emit("updated",{message:this,updateReasons:t})}},{key:"getParticipant",value:(o=Vu(lh.mark((function e(){var t,n,r=this;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=null,!this.state.participantSid){e.next=5;break}return e.next=4,this.conversation.getParticipantBySid(this.state.participantSid).catch((function(){return Rz.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 Rz.debug('Participant with identity "'.concat(r.author,'" not found for message ').concat(r.sid)),null}));case 8:t=e.sent;case 9:if(!t){e.next=11;break}return e.abrupt("return",t);case 11:throw n="Participant with ",this.state.participantSid&&(n+="SID '"+this.state.participantSid+"' "),this.state.author&&(this.state.participantSid&&(n+="or "),n+="identity '"+this.state.author+"' "),"Participant with "===n&&(n="Participant "),n+="was not found",new Error(n);case 17:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"getDetailedDeliveryReceipts",value:(a=Vu(lh.mark((function e(){var t,n;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getDetailedDeliveryReceiptsPaginator();case 2:t=e.sent,n=t.items;case 4:if(!t.hasNextPage){e.next=11;break}return e.next=7,t.nextPage();case 7:t=e.sent,n=[].concat(UR(n),UR(t.items)),e.next=4;break;case 11:return e.abrupt("return",n);case 12:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"remove",value:(i=Vu(lh.mark((function e(){return lh.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 i.apply(this,arguments)})},{key:"updateBody",value:(r=Vu(lh.mark((function e(t){return lh.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 r.apply(this,arguments)})},{key:"updateAttributes",value:(n=Vu(lh.mark((function e(t){return lh.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 n.apply(this,arguments)})},{key:"getTemporaryContentUrlsForMedia",value:function(e){var t=e.map((function(e){return e.sid}));return this.getTemporaryContentUrlsForMediaSids(t)}},{key:"getTemporaryContentUrlsForMediaSids",value:function(e){var t=this;return new tU.CancellablePromise(function(){var n=Vu(lh.mark((function n(r,i,a){var o,s;return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(o=t.services.mcsClient.mediaSetGetContentUrls(null!=e?e:[]),t.services.mcsClient&&e){n.next=4;break}return i(new Error("Media Content Service is unavailable")),n.abrupt("return");case 4:return a((function(){o.cancel()})),n.prev=5,n.next=8,o;case 8:s=n.sent,r(s),n.next=15;break;case 12:n.prev=12,n.t0=n.catch(5),i(n.t0);case 15:case"end":return n.stop()}}),n,null,[[5,12]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"getTemporaryContentUrlsForAttachedMedia",value:function(){var e,t=this.attachedMedia,n=null!==(e=null==t?void 0:t.map((function(e){return e.sid})))&&void 0!==e?e:[];return this.getTemporaryContentUrlsForMediaSids(n)}},{key:"_getDetailedDeliveryReceiptsPaginator",value:(t=Vu(lh.mark((function e(t){var n,r,i,a=this;return lh.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 jb(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 Sz(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}(qx);function Iz(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 Cz(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 Cz(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function Cz(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 Pz(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}ic(Message,"updated","updated"),dh([ex([Yk,"undefined"]),ph("design:type",Function),ph("design:paramtypes",[Object]),ph("design:returntype",Media)],Message.prototype,"getEmailBody",null),dh([ex([Yk,"undefined"]),ph("design:type",Function),ph("design:paramtypes",[Object]),ph("design:returntype",Media)],Message.prototype,"getEmailHistory",null),dh([tx("string"),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],Message.prototype,"updateBody",null),dh([tx(nx),ph("design:type",Function),ph("design:paramtypes",[Object]),ph("design:returntype",Promise)],Message.prototype,"updateAttributes",null),dh([tx(Vk("media",Media)),ph("design:type",Function),ph("design:paramtypes",[Array]),ph("design:returntype",tU.CancellablePromise)],Message.prototype,"getTemporaryContentUrlsForMedia",null),dh([tx(Vk("strings","string")),ph("design:type",Function),ph("design:paramtypes",[Array]),ph("design:returntype",tU.CancellablePromise)],Message.prototype,"getTemporaryContentUrlsForMediaSids",null);var Az=dy.scope("Messages"),jz=function(e){Qu(u,e);var t,n,r,i,a,o,s=Pz(u);function u(e,t,n){var r;return rc(this,u),ic(Yu(r=s.call(this)),"conversation",void 0),ic(Yu(r),"configuration",void 0),ic(Yu(r),"services",void 0),ic(Yu(r),"messagesByIndex",void 0),ic(Yu(r),"messagesListPromise",void 0),r.conversation=e,r.configuration=t,r.services=n,r.messagesByIndex=new Map,r.messagesListPromise=null,r}return nc(u,[{key:"subscribe",value:(o=Vu(lh.mark((function e(t){var n,r=this;return lh.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="string"==typeof t?this.services.syncClient.list({id:t,mode:"open_existing"}):Promise.resolve(t),e.prev=3,e.next=6,this.messagesListPromise;case 6:return(n=e.sent).on("itemAdded",(function(e){Az.debug("".concat(r.conversation.sid," itemAdded: ").concat(e.item.index)),r._upsertMessage(e.item.index,e.item.data)})),n.on("itemRemoved",(function(e){Az.debug("#{this.conversation.sid} itemRemoved: ".concat(e.index));var t=e.index;if(r.messagesByIndex.has(t)){var n=r.messagesByIndex.get(t);if(!n)return;r.messagesByIndex.delete(n.index),n.removeAllListeners("updated"),r.emit("messageRemoved",n)}})),n.on("itemUpdated",(function(e){Az.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&&Az.error("Failed to get messages object for conversation",this.conversation.sid,e.t0),Az.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:(a=Vu(lh.mark((function e(){return lh.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 a.apply(this,arguments)})},{key:"sendV2",value:function(e){var t=this;return Az.debug("Sending message V2",e.mediaContent,e.attributes,e.emailOptions),new tU.CancellablePromise(function(){var n=Vu(lh.mark((function n(r,i,a){var o,s,u,c,l,f,d,p,h,v,y,m;return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:s=[],u=[],a((function(){u.forEach((function(e){return e.cancel()}))})),c=Iz(e.mediaContent),n.prev=4,c.s();case 6:if((l=c.n()).done){n.next=25;break}return f=Gx(l.value,2),d=f[0],p=f[1],n.prev=8,Az.debug("Adding media to a message as ".concat(p instanceof FormData?"FormData":"SendMediaOptions"),p),y=p instanceof FormData?t.services.mcsClient.postFormData(p,d):t.services.mcsClient.post(null!==(h=p.contentType)&&void 0!==h?h:"",null!==(v=p.media)&&void 0!==v?v:"",d,p.filename),u.push(y),n.t0=s,n.next=15,y;case 15:n.t1=n.sent,n.t0.push.call(n.t0,n.t1),n.next=23;break;case 19:return n.prev=19,n.t2=n.catch(8),i(n.t2),n.abrupt("return");case 23:n.next=6;break;case 25:n.next=30;break;case 27:n.prev=27,n.t3=n.catch(4),c.e(n.t3);case 30:return n.prev=30,c.f(),n.finish(30);case 33:return m=t.services.commandExecutor.mutateResource("post",t.conversation._links.messages,{body:e.text,subject:null===(o=e.emailOptions)||void 0===o?void 0:o.subject,media_sids:s.map((function(e){return e.sid})),attributes:void 0!==e.attributes?JSON.stringify(e.attributes):void 0}),n.prev=34,n.t4=r,n.next=38,m;case 38:n.t5=n.sent,(0,n.t4)(n.t5),n.next=45;break;case 42:n.prev=42,n.t6=n.catch(34),i(n.t6);case 45:case"end":return n.stop()}}),n,null,[[4,27,30,33],[8,19],[34,42]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"send",value:(i=Vu(lh.mark((function e(t){var n,r,i=arguments;return lh.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,Az.debug("Sending text message",t,n,r),e.abrupt("return",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 4:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"sendMedia",value:(r=Vu(lh.mark((function e(t){var n,r,i,a,o,s=arguments;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=s.length>1&&void 0!==s[1]?s[1]:{},a=s.length>2?s[2]:void 0,Az.debug("Sending media message",t,i,a),Az.debug("Sending media message as ".concat(t instanceof FormData?"FormData":"SendMediaOptions"),t,i),!(t instanceof FormData)){e.next=10;break}return e.next=7,this.services.mcsClient.postFormData(t);case 7:e.t0=e.sent,e.next=13;break;case 10:return e.next=12,this.services.mcsClient.post(null!==(n=t.contentType)&&void 0!==n?n:"",null!==(r=t.media)&&void 0!==r?r:"","media",t.filename);case 12:e.t0=e.sent;case 13:return o=e.t0,e.next=16,this.services.commandExecutor.mutateResource("post",this.conversation._links.messages,{media_sids:[o.sid],attributes:void 0!==i?JSON.stringify(i):void 0});case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getMessages",value:(n=Vu(lh.mark((function e(t,n){var r,i=arguments;return lh.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)}))},o=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:o,nextPage:i?o:a}}))}},{key:"_upsertMessage",value:function(e,t){var n=this,r=this.messagesByIndex.get(e);if(r)return Az.debug("Attempted to upsert a message, but it is already known and therefore ignored",this.conversation.sid),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)})),this.emit("messageAdded",a),a}},{key:"_getMessages",value:(t=Vu(lh.mark((function e(){var t,n,r,i,a,o,s=this,u=arguments;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:30,n=u.length>1&&void 0!==u[1]?u[1]:"end",r=u.length>2&&void 0!==u[2]?u[2]:"forward",i="backwards"===r?"desc":"asc",e.next=6,this.messagesListPromise;case 6:return a=e.sent,e.next=9,null==a?void 0:a.getItems({from:"end"!==n?n:void 0,pageSize:t,order:i,limit:t});case 9:return o=e.sent,e.next=12,this._wrapPaginator(i,o,(function(e){return Promise.all(e.map((function(e){return s._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)})}]),u}(qx),Mz=function(){function e(t){rc(this,e),ic(this,"messagesEntity",void 0),ic(this,"text",void 0),ic(this,"attributes",{}),ic(this,"mediaContent",[]),ic(this,"emailOptions",{}),this.messagesEntity=t}return nc(e,[{key:"send",value:function(){var e=this;return new tU.CancellablePromise(function(){var t=Vu(lh.mark((function t(n,r,i){var a,o;return lh.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=e.messagesEntity.sendV2(e),i((function(){return a.cancel()})),t.prev=2,t.next=5,a;case 5:o=t.sent,n(Cb(o.index)),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(2),r(t.t0);case 12:case"end":return t.stop()}}),t,null,[[2,9]])})));return function(e,n,r){return t.apply(this,arguments)}}())}}]),e}(),Lz=function(){function e(t,n){rc(this,e),ic(this,"limits",void 0),ic(this,"message",void 0),ic(this,"emailBodies",void 0),ic(this,"emailHistories",void 0),this.limits=t,this.message=new Mz(n),this.emailBodies=new Map,this.emailHistories=new Map}return nc(e,[{key:"setBody",value:function(e){return this.message.text=e,this}},{key:"setSubject",value:function(e){return this.message.emailOptions.subject=e,this}},{key:"setAttributes",value:function(e){return this.message.attributes=e,this}},{key:"setEmailBody",value:function(e,t){return this.emailBodies.set(e,t),this}},{key:"setEmailHistory",value:function(e,t){return this.emailHistories.set(e,t),this}},{key:"addMedia",value:function(e){if("undefined"==typeof FormData&&e instanceof FormData)throw new Error("Could not add FormData content whilst not in a browser");if(!(e instanceof FormData)){var t=e;if(!t.contentType||!t.media)throw new Error("Media content in SendMediaOptions must contain non-empty contentType and media")}return this.message.mediaContent.push(["media",e]),this}},{key:"build",value:function(){var e=this;if(this.emailBodies.forEach((function(t,n){if(!e.limits.emailBodiesAllowedContentTypes.includes(n))throw new Error("Unsupported email body content type ".concat(n))})),this.emailHistories.forEach((function(t,n){if(!e.limits.emailHistoriesAllowedContentTypes.includes(n))throw new Error("Unsupported email history content type ".concat(n))})),this.emailBodies.size>this.limits.emailBodiesAllowedContentTypes.length)throw new Error("Too many email bodies attached to the message (".concat(this.emailBodies.size," > ").concat(this.limits.emailBodiesAllowedContentTypes.length,")"));if(this.emailHistories.size>this.limits.emailHistoriesAllowedContentTypes.length)throw new Error("Too many email histories attached to the message (".concat(this.emailHistories.size," > ").concat(this.limits.emailHistoriesAllowedContentTypes.length,")"));if(this.message.mediaContent.length>this.limits.mediaAttachmentsCountLimit)throw new Error("Too many media attachments in the message (".concat(this.message.mediaContent.length," > ").concat(this.limits.mediaAttachmentsCountLimit,")"));return this.emailBodies.forEach((function(t){e.message.mediaContent.push(["body",t])})),this.emailHistories.forEach((function(t){e.message.mediaContent.push(["history",t])})),this.message}},{key:"buildAndSend",value:function(){return this.build().send()}},{key:"getPayloadContentType",value:function(e){return"undefined"!=typeof FormData&&e instanceof FormData?e.get("Content-Type"):e.contentType}}]),e}();function Uz(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 Nz(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 Nz(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function Nz(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 Fz(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}var Dz={lastMessage:"lastMessage",attributes:"attributes",createdBy:"createdBy",dateCreated:"dateCreated",dateUpdated:"dateUpdated",friendlyName:"friendlyName",lastConsumedMessageIndex:"lastConsumedMessageIndex",notificationLevel:"notificationLevel",sid:"sid",status:"status",uniqueName:"uniqueName",state:"state",bindings:"bindings"},Conversation=function(e){Qu(Conversation,e);var t,n,r,i,a,o,s,u,c,l,f,d,p,h,v,y,m,g,b,w,k,x,_,S,O,E,T,R,I=Fz(Conversation);function Conversation(e,t,n,r,i){var a,o,s;rc(this,Conversation),ic(Yu(s=I.call(this)),"sid",void 0),ic(Yu(s),"_links",void 0),ic(Yu(s),"_participants",void 0),ic(Yu(s),"_configuration",void 0),ic(Yu(s),"_services",void 0),ic(Yu(s),"_internalState",void 0),ic(Yu(s),"_entityName",void 0),ic(Yu(s),"_messagesEntity",void 0),ic(Yu(s),"_messagesList",void 0),ic(Yu(s),"_participantsEntity",void 0),ic(Yu(s),"_participantsMap",void 0),ic(Yu(s),"_dataSource",void 0),ic(Yu(s),"_entityPromise",void 0),ic(Yu(s),"_entity",void 0),s.sid=t,s._links=n,s._configuration=r,s._services=i,s._entityName=e.channel,s._internalState={uniqueName:e.uniqueName||null,status:"notParticipating",attributes:null!==(a=e.attributes)&&void 0!==a?a:{},createdBy:e.createdBy,dateCreated:Pb(e.dateCreated),dateUpdated:Pb(e.dateUpdated),friendlyName:e.friendlyName||null,lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,bindings:null!==(o=e.bindings)&&void 0!==o?o:{}},e.notificationLevel&&(s._internalState.notificationLevel=e.notificationLevel);var u={participants:s._links.participants};return s._participants=new Map,s._participantsEntity=new JB(Yu(s),s._participants,u,s._configuration,s._services),s._participantsEntity.on("participantJoined",(function(e){return s.emit("participantJoined",e)})),s._participantsEntity.on("participantLeft",(function(e){return s.emit("participantLeft",e)})),s._participantsEntity.on("participantUpdated",(function(e){return s.emit("participantUpdated",e)})),s._messagesEntity=new jz(Yu(s),r,i),s._messagesEntity.on("messageAdded",(function(e){return s._onMessageAdded(e)})),s._messagesEntity.on("messageUpdated",(function(e){return s.emit("messageUpdated",e)})),s._messagesEntity.on("messageRemoved",(function(e){return s.emit("messageRemoved",e)})),s}return nc(Conversation,[{key:"uniqueName",get:function(){return this._internalState.uniqueName}},{key:"status",get:function(){return this._internalState.status}},{key:"friendlyName",get:function(){return this._internalState.friendlyName}},{key:"dateUpdated",get:function(){return this._internalState.dateUpdated}},{key:"dateCreated",get:function(){return this._internalState.dateCreated}},{key:"createdBy",get:function(){var e;return null!==(e=this._internalState.createdBy)&&void 0!==e?e:""}},{key:"attributes",get:function(){return this._internalState.attributes}},{key:"lastReadMessageIndex",get:function(){return this._internalState.lastReadMessageIndex}},{key:"lastMessage",get:function(){var e;return null!==(e=this._internalState.lastMessage)&&void 0!==e?e:void 0}},{key:"notificationLevel",get:function(){var e;return null!==(e=this._internalState.notificationLevel)&&void 0!==e?e:"default"}},{key:"bindings",get:function(){return this._internalState.bindings}},{key:"limits",get:function(){return this._configuration.limits}},{key:"state",get:function(){return this._internalState.state}},{key:"_statusSource",get:function(){return this._dataSource}},{key:"add",value:(R=Vu(lh.mark((function e(t,n){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this._participantsEntity.add(t,null!=n?n:{}));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return R.apply(this,arguments)})},{key:"addNonChatParticipant",value:(T=Vu(lh.mark((function e(t,n){var r,i,a=arguments;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=a.length>2&&void 0!==a[2]?a[2]:{},i=a.length>3&&void 0!==a[3]?a[3]:{},e.abrupt("return",this._participantsEntity.addNonChatParticipant(t,n,null!=r?r:{},null!=i?i:{}));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return T.apply(this,arguments)})},{key:"advanceLastReadMessageIndex",value:(E=Vu(lh.mark((function e(t){var n;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:if(!(t<(null!==(n=this.lastReadMessageIndex)&&void 0!==n?n:0))){e.next=6;break}return e.next=5,this._setLastReadMessageIndex(this.lastReadMessageIndex);case 5:case 8:return e.abrupt("return",e.sent);case 6:return e.next=8,this._setLastReadMessageIndex(t);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return E.apply(this,arguments)})},{key:"delete",value:(O=Vu(lh.mark((function e(){return lh.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 O.apply(this,arguments)})},{key:"getAttributes",value:(S=Vu(lh.mark((function e(){return lh.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 S.apply(this,arguments)})},{key:"getMessages",value:(_=Vu(lh.mark((function e(t,n,r){return lh.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 _.apply(this,arguments)})},{key:"getParticipants",value:(x=Vu(lh.mark((function e(){return lh.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 x.apply(this,arguments)})},{key:"getParticipantsCount",value:(k=Vu(lh.mark((function e(){var t,n,r;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new jb(this._configuration.links.conversations).path(this.sid).build(),e.next=3,this._services.network.get(n);case 3:return r=e.sent,e.abrupt("return",null!==(t=r.body.participants_count)&&void 0!==t?t:0);case 5:case"end":return e.stop()}}),e,this)}))),function(){return k.apply(this,arguments)})},{key:"getParticipantBySid",value:(w=Vu(lh.mark((function e(t){return lh.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 w.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(b=Vu(lh.mark((function e(){var t,n=arguments;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:"",e.abrupt("return",this._participantsEntity.getParticipantByIdentity(null!=t?t:""));case 2:case"end":return e.stop()}}),e,this)}))),function(){return b.apply(this,arguments)})},{key:"getMessagesCount",value:(g=Vu(lh.mark((function e(){var t,n,r;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new jb(this._configuration.links.conversations).path(this.sid).build(),e.next=3,this._services.network.get(n);case 3:return r=e.sent,e.abrupt("return",null!==(t=r.body.messages_count)&&void 0!==t?t:0);case 5:case"end":return e.stop()}}),e,this)}))),function(){return g.apply(this,arguments)})},{key:"getUnreadMessagesCount",value:(m=Vu(lh.mark((function e(){var t,n,r;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new jb(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 m.apply(this,arguments)})},{key:"join",value:(y=Vu(lh.mark((function e(){return lh.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 y.apply(this,arguments)})},{key:"leave",value:(v=Vu(lh.mark((function e(){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this._internalState.status){e.next=3;break}return e.next=3,this._services.commandExecutor.mutateResource("delete","".concat(this._links.participants,"/").concat(this._configuration.userIdentity));case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(){return v.apply(this,arguments)})},{key:"removeParticipant",value:(h=Vu(lh.mark((function e(t){return lh.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 h.apply(this,arguments)})},{key:"sendMessage",value:(p=Vu(lh.mark((function e(t,n,r){var i,a,o,s;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t&&null!==t){e.next=6;break}return e.next=3,this._messagesEntity.send(t,n,r);case 3:e.t0=e.sent,e.next=9;break;case 6:return e.next=8,this._messagesEntity.sendMedia(t,n,r);case 8:e.t0=e.sent;case 9:i=e.t0,a="string"==typeof t||null===t?"text":"media";try{o=JSON.parse(i.attributes)}catch(e){}return s={sid:i.sid,text:i.body,type:a,author:i.author,subject:i.subject,lastUpdatedBy:i.participant_sid,attributes:o,dateUpdated:i.date_updated,timestamp:i.date_created,memberSid:i.participant_sid,medias:Array.isArray(i.media)?i.media.map((function(e){return{sid:e.sid,size:Number(e.size),category:e.category,filename:e.filename,contentType:e.content_type}})):null,media:i.media&&"object"===Xu(i.media)&&!Array.isArray(i.media)?{sid:i.media.sid,size:Number(i.media.size),category:i.media.category,filename:i.media.filename,contentType:i.media.content_type}:null},e.abrupt("return",this._messagesEntity._upsertMessage(i.index,s));case 14:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return p.apply(this,arguments)})},{key:"prepareMessage",value:function(){return new Lz(this.limits,this._messagesEntity)}},{key:"setAllMessagesRead",value:(d=Vu(lh.mark((function e(){var t;return lh.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",0);case 8:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"setAllMessagesUnread",value:(f=Vu(lh.mark((function e(){return lh.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 f.apply(this,arguments)})},{key:"setUserNotificationLevel",value:(l=Vu(lh.mark((function e(t){return lh.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 l.apply(this,arguments)})},{key:"typing",value:function(){return this._services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:(c=Vu(lh.mark((function e(t){return lh.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 c.apply(this,arguments)})},{key:"updateFriendlyName",value:(u=Vu(lh.mark((function e(t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._internalState.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 u.apply(this,arguments)})},{key:"updateLastReadMessageIndex",value:(s=Vu(lh.mark((function e(t){return lh.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 s.apply(this,arguments)})},{key:"updateUniqueName",value:(o=Vu(lh.mark((function e(t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._internalState.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 o.apply(this,arguments)})},{key:"_subscribe",value:(a=Vu(lh.mark((function e(){var t=this;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._entityPromise){e.next=2;break}return e.abrupt("return",this._entityPromise);case 2:return this._entityPromise=this._services.syncClient.document({id:this._entityName,mode:"open_existing"}),e.prev=3,e.next=6,this._entityPromise;case 6:return this._entity=e.sent,this._entity.on("updated",(function(e){return t._update(e.data)})),this._entity.on("removed",(function(){return t.emit("removed",t)})),this._update(this._entity.data),e.abrupt("return",this._entity);case 13:throw e.prev=13,e.t0=e.catch(3),this._entity=null,this._entityPromise=null,"disconnected"!=this._services.syncClient.connectionState&&Conversation._logger.error("Failed to get conversation object",e.t0),Conversation._logger.debug("ERROR: Failed to get conversation object",e.t0),e.t0;case 20:case"end":return e.stop()}}),e,this,[[3,13]])}))),function(){return a.apply(this,arguments)})},{key:"_fetchStreams",value:(i=Vu(lh.mark((function e(){var t,n,r;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribe();case 2:return Conversation._logger.trace("_streamsAvailable, this.entity.data=",null===(t=this._entity)||void 0===t?void 0:t.data),r=null===(n=this._entity)||void 0===n?void 0:n.data,e.next=6,this._services.syncClient.list({id:r.messages,mode:"open_existing"});case 6:return this._messagesList=e.sent,e.next=9,this._services.syncClient.map({id:r.roster,mode:"open_existing"});case 9:this._participantsMap=e.sent;case 10:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"_subscribeStreams",value:(r=Vu(lh.mark((function e(){var t,n,r,i,a,o,s;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._subscribe();case 3:return Conversation._logger.trace("_subscribeStreams, this.entity.data=",null===(t=this._entity)||void 0===t?void 0:t.data),a=null===(n=this._entity)||void 0===n?void 0:n.data,o=a.messages,s=a.roster,e.next=9,Promise.all([this._messagesEntity.subscribe(null!==(r=this._messagesList)&&void 0!==r?r:o),this._participantsEntity.subscribe(null!==(i=this._participantsMap)&&void 0!==i?i:s)]);case 9:e.next=16;break;case 11:throw e.prev=11,e.t0=e.catch(0),"disconnected"!==this._services.syncClient.connectionState&&Conversation._logger.error("Failed to subscribe on conversation objects",this.sid,e.t0),Conversation._logger.debug("ERROR: Failed to subscribe on conversation objects",this.sid,e.t0),e.t0;case 16:case"end":return e.stop()}}),e,this,[[0,11]])}))),function(){return r.apply(this,arguments)})},{key:"_unsubscribe",value:(n=Vu(lh.mark((function e(){return lh.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 n.apply(this,arguments)})},{key:"_setStatus",value:function(e,t){var n=this;this._dataSource=t,this._internalState.status!==e&&(this._internalState.status=e,"joined"!==e?this._entityPromise&&this._unsubscribe().catch((function(t){if(Conversation._logger.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n._services.syncClient.connectionState)throw t})):this._subscribeStreams().catch((function(t){if(Conversation._logger.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n._services.syncClient.connectionState)throw t})))}},{key:"_update",value:function(e){var t,n,r,i,a;Conversation._logger.trace("_update",e),Conversation.preprocessUpdate(e,this.sid);for(var o=new Set,s=0,u=Object.keys(e);s<u.length;s++){var c=u[s],l=Dz[c];if(l)switch(l){case Dz.status:if(!e.status||"unknown"===e.status||this._internalState.status===e.status)break;this._internalState.status=e.status,o.add(l);break;case Dz.attributes:if(zx(this._internalState.attributes,e.attributes))break;this._internalState.attributes=e.attributes,o.add(l);break;case Dz.lastConsumedMessageIndex:if(void 0===e.lastConsumedMessageIndex||e.lastConsumedMessageIndex===this._internalState.lastReadMessageIndex)break;this._internalState.lastReadMessageIndex=e.lastConsumedMessageIndex,o.add("lastReadMessageIndex");break;case Dz.lastMessage:if(this._internalState.lastMessage&&!e.lastMessage){delete this._internalState.lastMessage,o.add(l);break}this._internalState.lastMessage=this._internalState.lastMessage||{},void 0!==(null===(t=e.lastMessage)||void 0===t?void 0:t.index)&&e.lastMessage.index!==this._internalState.lastMessage.index&&(this._internalState.lastMessage.index=e.lastMessage.index,o.add(l)),void 0!==(null===(n=e.lastMessage)||void 0===n?void 0:n.timestamp)&&(null===(r=this._internalState.lastMessage)||void 0===r||null===(i=r.dateCreated)||void 0===i?void 0:i.getTime())!==e.lastMessage.timestamp.getTime()&&(this._internalState.lastMessage.dateCreated=e.lastMessage.timestamp,o.add(l)),zx(this._internalState.lastMessage,{})&&delete this._internalState.lastMessage;break;case Dz.state:var f=e.state||void 0;if(void 0!==f&&(f.dateUpdated=new Date(f.dateUpdated)),zx(this._internalState.state,f))break;this._internalState.state=f,o.add(l);break;case Dz.bindings:if(zx(this._internalState.bindings,e.bindings))break;this._internalState.bindings=e.bindings,o.add(l);break;default:var d=e[c]instanceof Date,p=d&&(null===(a=this._internalState[l])||void 0===a?void 0:a.getTime())===e[c].getTime(),h=!d&&this[l]===e[c];if(p||h)break;this._internalState[l]=e[c],o.add(l)}}o.size>0&&this.emit("updated",{conversation:this,updateReasons:UR(o)})}},{key:"_onMessageAdded",value:function(e){var t,n=Uz(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:(t=Vu(lh.mark((function e(t){var n;return lh.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 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){Conversation._logger.warn("Retrieved malformed attributes from the server for conversation: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(n){Conversation._logger.warn("Retrieved malformed dateCreated from the server for conversation: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(n){Conversation._logger.warn("Retrieved malformed dateUpdated from the server for conversation: "+t),delete e.dateUpdated}try{e.lastMessage&&e.lastMessage.timestamp&&(e.lastMessage.timestamp=new Date(e.lastMessage.timestamp))}catch(n){Conversation._logger.warn("Retrieved malformed lastMessage.timestamp from the server for conversation: "+t),delete e.lastMessage.timestamp}}}]),Conversation}(qx);ic(Conversation,"participantJoined","participantJoined"),ic(Conversation,"participantLeft","participantLeft"),ic(Conversation,"participantUpdated","participantUpdated"),ic(Conversation,"messageAdded","messageAdded"),ic(Conversation,"messageRemoved","messageRemoved"),ic(Conversation,"messageUpdated","messageUpdated"),ic(Conversation,"typingEnded","typingEnded"),ic(Conversation,"typingStarted","typingStarted"),ic(Conversation,"updated","updated"),ic(Conversation,"removed","removed"),ic(Conversation,"_logger",dy.scope("Conversation")),dh([tx(Yk,rx),ph("design:type",Function),ph("design:paramtypes",[String,Object]),ph("design:returntype",Promise)],Conversation.prototype,"add",null),dh([tx(Yk,Yk,rx),ph("design:type",Function),ph("design:paramtypes",[String,String,Object,Object]),ph("design:returntype",Promise)],Conversation.prototype,"addNonChatParticipant",null),dh([tx(Jk),ph("design:type",Function),ph("design:paramtypes",[Number]),ph("design:returntype",Promise)],Conversation.prototype,"advanceLastReadMessageIndex",null),dh([tx(["undefined",Jk],["undefined",Jk],["undefined",Gk("backwards","forward")]),ph("design:type",Function),ph("design:paramtypes",[Number,Number,String]),ph("design:returntype",Promise)],Conversation.prototype,"getMessages",null),dh([tx(Yk),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],Conversation.prototype,"getParticipantBySid",null),dh([tx(Yk),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],Conversation.prototype,"getParticipantByIdentity",null),dh([tx([Yk,Participant]),ph("design:type",Function),ph("design:paramtypes",[Object]),ph("design:returntype",Promise)],Conversation.prototype,"removeParticipant",null),dh([tx(["string",FormData,Gk(null),Qk("media options",{contentType:Yk,media:Hk((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"]}))})],rx,["undefined",Gk(null),Qk("email attributes",{subject:[Yk,"undefined"]})]),ph("design:type",Function),ph("design:paramtypes",[Object,Object,Object]),ph("design:returntype",Promise)],Conversation.prototype,"sendMessage",null),dh([tx(Gk("default","muted")),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],Conversation.prototype,"setUserNotificationLevel",null),dh([tx(nx),ph("design:type",Function),ph("design:paramtypes",[Object]),ph("design:returntype",Promise)],Conversation.prototype,"updateAttributes",null),dh([tx("string"),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],Conversation.prototype,"updateFriendlyName",null),dh([tx([Gk(null),Jk]),ph("design:type",Function),ph("design:paramtypes",[Number]),ph("design:returntype",Promise)],Conversation.prototype,"updateLastReadMessageIndex",null),dh([tx(["string",Gk(null)]),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],Conversation.prototype,"updateUniqueName",null);var qz=function(){function e(){var t=this;rc(this,e),ic(this,"_promise",void 0),ic(this,"_resolve",void 0),ic(this,"_reject",void 0),ic(this,"current",void 0),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return nc(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 Bz(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 zz(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 zz(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,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function zz(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 Wz(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 $z(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Wz(Object(n),!0).forEach((function(t){ic(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Wz(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Kz(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}var Hz=dy.scope("Conversations"),Gz=function(e){Qu(p,e);var t,n,r,i,a,o,s,u,c,l,f,d=Kz(p);function p(e,t){var n;return rc(this,p),ic(Yu(n=d.call(this)),"conversations",new Map),ic(Yu(n),"myConversationsRead",new qz),ic(Yu(n),"configuration",void 0),ic(Yu(n),"services",void 0),ic(Yu(n),"tombstones",new Set),ic(Yu(n),"myConversationsFetched",!1),n.configuration=e,n.services=t,n}return nc(p,[{key:"addConversation",value:(f=Vu(lh.mark((function e(t){var n,r,i,a,o,s,u,c,l,f;return lh.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(o=e.sent,s=null!==(n=o.sid)&&void 0!==n?n:null,u=null!==(r=null===(i=o.sync_objects)||void 0===i?void 0:i.conversation)&&void 0!==r?r:null,c=$z({self:o.url},o.links),!(l=this.conversations.get(s))){e.next=12;break}return e.next=11,l._subscribe();case 11:return e.abrupt("return",l);case 12:return f=new Conversation({channel:u,entityName:"",uniqueName:"",attributes:null,createdBy:"",friendlyName:"",lastConsumedMessageIndex:0,dateCreated:null,dateUpdated:null},s,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=Vu(lh.mark((function e(){var t,n,r,i,a,o,s,u=this;return lh.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){Hz.debug("itemAdded: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),t.on("itemRemoved",(function(e){Hz.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){Hz.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=Bz(n);try{for(i.s();!(a=i.n()).done;)o=a.value,r.push(this._upsertConversation("rest",o.channel_sid,o))}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(),Hz.debug("The conversations list has been successfully fetched"),e.abrupt("return",this);case 22:throw e.prev=22,e.t0=e.catch(0),s="Failed to fetch the conversations list","disconnected"!==this.services.syncClient.connectionState&&Hz.error(s,e.t0),Hz.debug("ERROR: ".concat(s),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=Vu(lh.mark((function e(){var t,n,r=this;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return t=e.sent,e.next=5,t.getItems();case 5:return n=e.sent,e.abrupt("return",this._wrapPaginator(n,(function(e){return Promise.all(e.map((function(e){return r._upsertConversation("sync",e.key,e.data)})))})));case 7:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"getConversation",value:(u=Vu(lh.mark((function e(t){var n,r,i,a=this;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return n=e.sent,e.next=5,n.getItems({key:t});case 5:return r=e.sent,i=r.items.map((function(e){return a._upsertConversation("sync",e.key,e.data)})),e.abrupt("return",i.length>0?i[0]:null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(s=Vu(lh.mark((function e(t){var n,r,i,a,o;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new jb(this.configuration.links.myConversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=JSON.parse(r.payload),a=i.conversation_sid,o={entityName:null,lastConsumedMessageIndex:i.last_read_message_index,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:i.sync_objects.conversation,notificationLevel:null==i?void 0:i.notification_level,sid:a},e.abrupt("return",a?this._upsertConversation("sync",a,o):null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"peekConversation",value:(o=Vu(lh.mark((function e(t){var n,r,i,a;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new jb(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 o.apply(this,arguments)})},{key:"_getMap",value:(a=Vu(lh.mark((function e(){return lh.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=Vu(lh.mark((function e(t,n){var r,i=this;return lh.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.filter((function(e){return null!==e})),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=Vu(lh.mark((function e(t,n,r){var i,a,o;return lh.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 Hz.trace("upsertConversation: conversation is known from sync and came from REST, ignoring",{sid:n.sid,data:r.status,conversation:n.status}),e.abrupt("return");case 5:if("joined"!==r.status||"joined"===n.status){e.next=15;break}return n._setStatus("joined",t),o={},void 0!==r.notificationLevel&&(o.notificationLevel=r.notificationLevel),void 0!==r.lastConsumedMessageIndex&&(o.lastConsumedMessageIndex=r.lastConsumedMessageIndex),zx(o,{})||n._update(o),e.next=13,n._subscribe();case 13:return this.emit("conversationJoined",n),e.abrupt("return");case 15:if("notParticipating"!==r.status||"joined"!==n.status){e.next=22;break}return n._setStatus("notParticipating",t),n._update(r),e.next=20,n._subscribe();case 20:return this.emit("conversationLeft",n),e.abrupt("return");case 22:if("notParticipating"!==r.status){e.next=26;break}return e.next=25,n._subscribe();case 25:return e.abrupt("return");case 26:n._update(r);case 27:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"_upsertConversation",value:(n=Vu(lh.mark((function e(t,n,r){var i,a,o,s;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Hz.trace("upsertConversation called for ".concat(n),r),!(i=this.conversations.get(n))){e.next=9;break}return Hz.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("rest"!==t||!this.tombstones.has(n)){e.next=12;break}return Hz.trace("upsertChannel: the conversation is deleted but reappeared again from REST, ignoring",n),e.abrupt("return",null);case 12:return Hz.trace("upsertConversation: creating a local conversation object with sid "+n,r),a="".concat(this.configuration.links.conversations,"/").concat(n),o={self:a,messages:"".concat(a,"/Messages"),participants:"".concat(a,"/Participants")},s=new Conversation(r,n,o,this.configuration,this.services),this.conversations.set(n,s),e.prev=17,e.next=20,s._subscribe();case 20:if("joined"!==r.status){e.next=23;break}return e.next=23,s._fetchStreams();case 23:e.next=32;break;case 25:if(e.prev=25,e.t0=e.catch(17),"SyncError"===e.t0.name){e.next=29;break}throw e.t0;case 29:return Hz.trace("upsertChannel: the conversation is missing some Sync entity(ies), ignoring",n,e.t0),this.conversations.delete(n),e.abrupt("return",null);case 32:return this._registerForEvents(s),this.emit("conversationAdded",s),"joined"===r.status&&(s._setStatus("joined",t),this.emit("conversationJoined",s)),e.abrupt("return",s);case 36:case"end":return e.stop()}}),e,this,[[17,25]])}))),function(e,t,r){return n.apply(this,arguments)})},{key:"_fetchMyConversations",value:(t=Vu(lh.mark((function e(){var t,n,r,i,a,o;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=null;case 2:return i=new jb(this.configuration.links.myConversations),n&&i.arg("PageToken",n),e.next=6,this.services.network.get(i.build());case 6:a=e.sent,o=null===(r=a.body)||void 0===r?void 0:r.conversations.map((function(e){return{descriptor:e,channel_sid:e.conversation_sid,status:e.status,channel:e.sync_objects.conversation,messages:e.sync_objects.messages,roster:"".concat(e.conversation_sid,".roster"),lastConsumedMessageIndex:e.last_read_message_index,notificationLevel:e.notification_level}})),n=a.body.meta.next_token,t=[].concat(UR(t),UR(o));case 10:if(n){e.next=2;break}case 11:return e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_onConversationRemoved",value:function(e){var t=this.conversations.get(e);t&&(this.conversations.delete(e),this.emit("conversationRemoved",t))}},{key:"_registerForEvents",value:function(e){var t=this;e.on("removed",(function(){return t._onConversationRemoved(e.sid)})),e.on("updated",(function(e){return t.emit("conversationUpdated",e)})),e.on("participantJoined",(function(e){return t.emit("participantJoined",e)})),e.on("participantLeft",(function(e){return t.emit("participantLeft",e)})),e.on("participantUpdated",(function(e){return t.emit("participantUpdated",e)})),e.on("messageAdded",(function(e){return t.emit("messageAdded",e)})),e.on("messageUpdated",(function(e){return t.emit("messageUpdated",e)})),e.on("messageRemoved",(function(e){return t.emit("messageRemoved",e)})),e.on("typingStarted",(function(e){return t.emit("typingStarted",e)})),e.on("typingEnded",(function(e){return t.emit("typingEnded",e)}))}}]),p}(qx),Vz=ni,Yz=No.find,Jz=Iy,Qz="find",Xz=!0;Qz in[]&&Array(1).find((function(){Xz=!1})),Vz({target:"Array",proto:!0,forced:Xz},{find:function(e){return Yz(this,e,arguments.length>1?arguments[1]:void 0)}}),Jz(Qz);var Zz=s,eW=xo,tW=TypeError,nW=Object.getOwnPropertyDescriptor,rW=Zz&&!function(){if(void 0!==this)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}(),iW=ni,aW=Be,oW=ur,sW=ir,uW=pr,cW=rW?function(e,t){if(eW(e)&&!nW(e,"length").writable)throw tW("Cannot set read only .length");return e.length=t}:function(e,t){return e.length=t},lW=vh,fW=Io,dW=Ga,pW=nD,hW=Lu("splice"),vW=Math.max,yW=Math.min;function mW(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}iW({target:"Array",proto:!0,forced:!hW},{splice:function(e,t){var n,r,i,a,o,s,u=aW(this),c=uW(u),l=oW(e,c),f=arguments.length;for(0===f?n=r=0:1===f?(n=0,r=c-l):(n=f-2,r=yW(vW(sW(t),0),c-l)),lW(c+n-r),i=fW(u,r),a=0;a<r;a++)(o=l+a)in u&&dW(i,a,u[o]);if(i.length=r,n<r){for(a=l;a<c-r;a++)s=a+n,(o=a+r)in u?u[s]=u[o]:pW(u,s);for(a=c;a>c-r+n;a--)pW(u,a-1)}else if(n>r)for(a=c-r;a>l;a--)s=a+n-1,(o=a+r-1)in u?u[s]=u[o]:pW(u,s);for(a=0;a<n;a++)u[a+l]=arguments[a+2];return cW(u,c-r+n),i}});var gW=function(e){Qu(a,e);var t,n,r,i=mW(a);function a(e,t,n){var r;return rc(this,a),ic(Yu(r=i.call(this)),"configuration",void 0),ic(Yu(r),"services",void 0),ic(Yu(r),"subscribedUsers",void 0),ic(Yu(r),"fifoStack",void 0),ic(Yu(r),"myself",void 0),r.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 nc(a,[{key:"handleUnsubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)&&this.subscribedUsers.delete(e.identity);var t=0;this.fifoStack.find((function(n,r){return n==e.identity&&(t=r,!0)}))&&this.fifoStack.splice(t,1),this.emit("userUnsubscribed",e)}},{key:"handleSubscribeUser",value:function(e){if(!this.subscribedUsers.has(e.identity)){if(this.fifoStack.length>=this.configuration.userInfosToSubscribe){var t,n,r=this.fifoStack.shift();null===(t=this.subscribedUsers)||void 0===t||null===(n=t.get(r))||void 0===n||n.unsubscribe()}this.fifoStack.push(e.identity),this.subscribedUsers.set(e.identity,e),this.emit("userSubscribed",e)}}},{key:"getUser",value:(r=Vu(lh.mark((function e(t,n){var r,i,a,o=this;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.myself._ensureFetched();case 2:if(t!=this.myself.identity){e.next=4;break}return e.abrupt("return",this.myself);case 4:if(!(i=this.subscribedUsers.get(t))){e.next=7;break}return e.abrupt("return",i);case 7:if(null===(r=n)||void 0===r){e.next=11;break}e.next=14;break;case 11:return e.next=13,this.getSyncUniqueName(t);case 13:n=e.sent;case 14:return(a=new User(t,n,this.configuration,this.services)).on("updated",(function(e){return o.emit("userUpdated",e)})),a.on("userSubscribed",(function(){return o.handleSubscribeUser(a)})),a.on("userUnsubscribed",(function(){return o.handleUnsubscribeUser(a)})),e.next=20,a._ensureFetched();case 20:return e.abrupt("return",a);case 21:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Vu(lh.mark((function e(){var t;return lh.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=Vu(lh.mark((function e(t){var n,r,i,a;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new jb(this.configuration.links.users).path(t).build(),e.next=3,this.services.network.get(r);case 3:return i=e.sent,a=JSON.parse(i.payload||"null"),e.abrupt("return",null!==(n=null==a?void 0:a.sync_objects.user_info_map)&&void 0!==n?n:"");case 6:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),a}(qx),bW=dy.scope("TypingIndicator"),wW=function(){function e(t,n,r){rc(this,e),ic(this,"services",void 0),ic(this,"configuration",void 0),ic(this,"sentUpdates",void 0),ic(this,"getConversation",void 0),ic(this,"serviceTypingTimeout",void 0),this.configuration=n,this.services=r,this.getConversation=t,this.serviceTypingTimeout=null,this.sentUpdates=new Map}var t;return nc(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=Vu(lh.mark((function t(n,r){return lh.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==LS.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=Vu(lh.mark((function e(t){var n=this;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:bW.trace("Got new typing indicator ",t),this.getConversation(t.channel_sid).then((function(e){e&&e._participants.forEach((function(e){if(e.identity===t.identity){var r=n.configuration.typingIndicatorTimeoutOverride?n.configuration.typingIndicatorTimeoutOverride+1e3:1e3*t.typing_timeout;e._startTyping(r)}}))})).catch((function(e){throw bW.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;bW.trace("Sending typing indicator");var n=this.configuration.links.typing,r="ChannelSid=".concat(e);return this.services.twilsockClient.post({url:n,headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r,grant:this.configuration.productId}).then((function(e){var n=JSON.parse(e.payload);n.hasOwnProperty("typing_timeout")&&(t.serviceTypingTimeout=1e3*n.typing_timeout)})).catch((function(e){throw bW.error("Failed to send typing indicator:",e),e}))}}]),e}(),PushNotification=nc((function PushNotification(e){rc(this,PushNotification),ic(this,"title",void 0),ic(this,"body",void 0),ic(this,"sound",void 0),ic(this,"badge",void 0),ic(this,"action",void 0),ic(this,"type",void 0),ic(this,"data",void 0),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||{}})),kW="2.2.0";function xW(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 _W(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?xW(Object(n),!0).forEach((function(t){ic(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):xW(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var SW,OW,EW=function(e){return e.replace(/(^\/+|\/+$)/g,"")},TW=function(){function e(t,n,r){rc(this,e),ic(this,"_serviceUrl",void 0),ic(this,"_services",void 0),ic(this,"_productId",void 0),this._serviceUrl=t,this._services=n,this._productId=r}var t,n,r;return nc(e,[{key:"_preProcessUrl",value:function(e){var t=EW(e);return/^https?:\/\//.test(e)?t:"".concat(EW(this._serviceUrl),"/").concat(t)}},{key:"_makeRequest",value:(r=Vu(lh.mark((function e(t,n,r,i){var a,o,s,u;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=this._preProcessUrl(n),o=_W({"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((function(e){return encodeURIComponent(String(e))})).join("=")})).join("&")),e.next=9,this._services.transport.get({url:u,headers:o,grant:this._productId});case 9:case 13:case 17:return s=e.sent,e.abrupt("break",19);case 11:return e.next=13,this._services.transport.post({url:a,headers:o,body:JSON.stringify(r),grant:this._productId});case 15:return e.next=17,this._services.transport.delete({url:a,headers:o,grant:this._productId});case 19:if(!(s.statusCode<200||s.statusCode>=300)){e.next=21;break}throw new Error("Request responded with a non-success code ".concat(s.statusCode));case 21:return e.abrupt("return",s);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"fetchResource",value:(n=Vu(lh.mark((function e(t,n){var r,i=this;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=1,e.next=4,new CS({min:50,max:1600,maxAttemptsCount:6}).run((function(){return i._makeRequest("get",t,n)}));case 4:return r=e.sent,e.abrupt("return",JSON.parse(r.payload));case 8:throw e.prev=8,e.t0=e.catch(1),new Error('Fetch resource from "'.concat(t,'" failed.'));case 11:case"end":return e.stop()}}),e,null,[[1,8]])}))),function(e,t){return n.apply(this,arguments)})},{key:"mutateResource",value:(t=Vu(lh.mark((function e(t,n,r){var i,a;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._makeRequest(t,n,r,{"X-Twilio-Mutation-Id":HS()});case 2:if(i=e.sent,a=JSON.parse(i.payload),202!==i.statusCode){e.next=8;break}return e.next=7,this.fetchResource(a.resource_url);case 7:return e.abrupt("return",e.sent);case 8:return e.abrupt("return",a);case 9:case"end":return e.stop()}}),e,this)}))),function(e,n,r){return t.apply(this,arguments)})}]),e}();function RW(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 IW(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?RW(Object(n),!0).forEach((function(t){ic(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):RW(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function CW(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=ec(e);if(t){var i=ec(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Zu(this,n)}}var PW=nc((function e(){rc(this,e),ic(this,"commandExecutor",void 0),ic(this,"twilsockClient",void 0),ic(this,"users",void 0),ic(this,"notificationClient",void 0),ic(this,"network",void 0),ic(this,"typingIndicator",void 0),ic(this,"syncClient",void 0),ic(this,"mcsClient",void 0),ic(this,"transport",void 0)}));return e.Client=(SW=function(e){Qu(Client,e);var t,n,r,i,a,o,s,u,c,l,f,d,p,h,v=CW(Client);function Client(e){var t,n,r,i,a,o,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(rc(this,Client),ic(Yu(o=v.call(this)),"version",kW),ic(Yu(o),"connectionState","unknown"),ic(Yu(o),"_ensureReady",void 0),ic(Yu(o),"_options",void 0),ic(Yu(o),"_services",void 0),ic(Yu(o),"_myself",void 0),ic(Yu(o),"_resolveEnsureReady",void 0),ic(Yu(o),"_rejectEnsureReady",void 0),ic(Yu(o),"_fpaToken",void 0),ic(Yu(o),"_configuration",void 0),ic(Yu(o),"_conversationsEntity",void 0),ic(Yu(o),"_conversationsPromise",void 0),ic(Yu(o),"parsePushNotification",OW.parsePushNotification),o._fpaToken=null!=e?e:"",o._options=null!=s?s:{},!o._options.disableDeepClone){var u=IW(IW({},o._options),{},{transport:void 0,twilsockClient:void 0});(u=Ib(u)).transport=o._options.transport,u.twilsockClient=o._options.twilsockClient,o._options=u}o._options.logLevel=null!==(t=o._options.logLevel)&&void 0!==t?t:"silent",OW._logger.setLevel(o._options.logLevel);var c=o._options.productId="ip_messaging";if(o._options.clientMetadata=o._options.clientMetadata||{},o._options.clientMetadata.hasOwnProperty("type")||(o._options.clientMetadata.type="conversations"),o._options.clientMetadata.hasOwnProperty("sdk")||(o._options.clientMetadata.sdk="JS",o._options.clientMetadata.sdkv=kW),o._options.Sync=o._options.Sync||{},void 0===o._options.Sync.enableSessionStorage&&(o._options.Sync.enableSessionStorage=!0),o._options.region&&(o._options.Sync.region=o._options.region),!e)throw new Error("A valid Twilio token should be provided");o._services=new PW,o._myself=new User("","",null,o._services);var l=!o._options.twilsockClient;if(!o._options.initRegistrations){var f=new US.InitRegistration(c);OW.populateInitRegistrations(f),o._options.initRegistrations=[f]}o._services.twilsockClient=o._options.twilsockClient=null!==(n=o._options.twilsockClient)&&void 0!==n?n:new US.TwilsockClient(e,c,o._options),o._services.twilsockClient.on("tokenAboutToExpire",(function(){return o.emit("tokenAboutToExpire")})),o._services.twilsockClient.on("tokenExpired",(function(){return o.emit("tokenExpired")})),o._services.twilsockClient.on("disconnected",(function(){OW._logger.debug("Handling stateChanged for ConversationsClient: new state disconnected"),"disconnected"!==o.connectionState&&(o.connectionState="disconnected",o.emit("connectionStateChanged",o.connectionState))})),o._services.twilsockClient.on("connecting",(function(){OW._logger.debug("Handling stateChanged for ConversationsClient: new state connecting"),"connecting"!==o.connectionState&&(o.connectionState="connecting",o.emit("connectionStateChanged",o.connectionState))})),o._services.twilsockClient.on("connected",(function(){OW._logger.debug("Handling stateChanged for ConversationsClient: new state connected"),"connected"!==o.connectionState&&(o.connectionState="connected",o.emit("connectionStateChanged",o.connectionState))})),o._services.transport=o._options.transport=null!==(r=o._options.transport)&&void 0!==r?r:o._options.twilsockClient,o._services.notificationClient=o._options.notificationsClient=null!==(i=o._options.notificationsClient)&&void 0!==i?i:new YA.Notifications(e,o._options),o._services.syncClient=o._options.syncClient=null!==(a=o._options.syncClient)&&void 0!==a?a:new eU(e,o._options);var d=(null==s?void 0:s.Chat)||(null==s?void 0:s.IPMessaging)||s||{},p=d.region||(null==s?void 0:s.region),h=d.apiUri||d.typingUri||"https://aim.".concat(p||"us1",".twilio.com");o._services.commandExecutor=new TW(h,{transport:o._options.transport},c);var y=function(e){o._rejectEnsureReady(e),o.emit("initFailed",{error:e})},m=function(){y({terminal:!0,message:"Twilsock has disconnected."})};return o._services.twilsockClient.once("disconnected",m),o._services.twilsockClient.once("connected",Vu(lh.mark((function e(){var t;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return OW._logger.debug("ConversationsClient started INITIALIZING"),o._services.twilsockClient.off("disconnected",m),e.prev=2,e.next=6,o._initialize();case 6:e.next=13;break;case 8:e.prev=8,e.t0=e.catch(2),t={terminal:!0,message:e.t0.message},o._rejectEnsureReady(t),o.emit("initFailed",{error:t});case 13:case"end":return e.stop()}}),e,null,[[2,8]])})))),o._ensureReady=new Promise((function(e,t){o._resolveEnsureReady=e,o._rejectEnsureReady=t})).catch((function(){})),l&&o._services.twilsockClient.connect(),o}return nc(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 'initialized' and 'initFailed' events to properly react to the client initialization.");return this._configuration.reachabilityEnabled}},{key:"shutdown",value:(h=Vu(lh.mark((function e(){return lh.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 h.apply(this,arguments)})},{key:"updateToken",value:(p=Vu(lh.mark((function e(t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:if(OW._logger.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 p.apply(this,arguments)})},{key:"getConversationBySid",value:(d=Vu(lh.mark((function e(t){var n;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this._conversationsEntity.myConversationsRead.promise;case 4:return e.next=6,this._conversationsEntity.getConversation(t);case 6:if(n=e.sent){e.next=9;break}throw new Error("Conversation with SID ".concat(t," was not found."));case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"peekConversationBySid",value:(f=Vu(lh.mark((function e(t){var n;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this._conversationsEntity.peekConversation(t);case 4:if(n=e.sent){e.next=7;break}throw new Error("Conversation with SID ".concat(t," was not found."));case 7:return e.abrupt("return",n);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(l=Vu(lh.mark((function e(t){var n;return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this._conversationsEntity.myConversationsRead.promise;case 4:return e.next=6,this._conversationsEntity.getConversationByUniqueName(t);case 6:if(n=e.sent){e.next=9;break}throw new Error("Conversation with unique name ".concat(t," was 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=Vu(lh.mark((function e(){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this._conversationsPromise.then((function(e){return e.getConversations()})));case 3:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"createConversation",value:(u=Vu(lh.mark((function e(t){return lh.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:(s=Vu(lh.mark((function e(t,n){return lh.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 s.apply(this,arguments)})},{key:"unsetPushRegistrationId",value:(o=Vu(lh.mark((function e(t){return lh.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 o.apply(this,arguments)})},{key:"removePushRegistrations",value:(a=Vu(lh.mark((function e(t,n){return lh.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=Vu(lh.mark((function e(t){return lh.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:OW._logger.debug("handlePushNotification, notificationPayload=",t),this.emit("pushNotification",OW.parsePushNotification(t));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"getUser",value:(r=Vu(lh.mark((function e(t){return lh.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=Vu(lh.mark((function e(){return lh.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:"getTemporaryContentUrlsForMediaSids",value:function(e){var t=this;return new tU.CancellablePromise(function(){var n=Vu(lh.mark((function n(r,i,a){var o,s;return lh.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(t._services.mcsClient&&e){n.next=3;break}return i(new Error("Media Content Service is unavailable")),n.abrupt("return");case 3:return o=t._services.mcsClient.mediaSetGetContentUrls(e),a((function(){o.cancel()})),n.prev=5,n.next=8,o;case 8:s=n.sent,r(s),n.next=15;break;case 12:n.prev=12,n.t0=n.catch(5),i(n.t0);case 15:case"end":return n.stop()}}),n,null,[[5,12]])})));return function(e,t,r){return n.apply(this,arguments)}}())}},{key:"getTemporaryContentUrlsForMedia",value:function(e){var t=e.map((function(e){return e.sid}));return this.getTemporaryContentUrlsForMediaSids(t)}},{key:"_initialize",value:(t=Vu(lh.mark((function e(){var t,n=this;return lh.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 _y(this._options,t,OW._logger),this._myself._resolveInitialization(this._configuration,this._configuration.userIdentity,this._configuration.userInfo,!0),this._services.typingIndicator=new wW(this.getConversationBySid.bind(this),this._configuration,this._services),this._services.network=new MS(this._configuration,this._services),this._services.users=new gW(this._myself,this._configuration,this._services),this._services.users.on("userSubscribed",(function(e){n.emit("userSubscribed",e)})),this._services.users.on("userUpdated",(function(e){return n.emit("userUpdated",e)})),this._services.users.on("userUnsubscribed",(function(e){n.emit("userUnsubscribed",e)})),this._conversationsEntity=new Gz(this._configuration,this._services),this._conversationsEntity.on("conversationAdded",(function(e){n.emit("conversationAdded",e)})),this._conversationsEntity.on("conversationRemoved",(function(e){n.emit("conversationRemoved",e)})),this._conversationsEntity.on("conversationJoined",(function(e){n.emit("conversationJoined",e)})),this._conversationsEntity.on("conversationLeft",(function(e){n.emit("conversationLeft",e)})),this._conversationsEntity.on("conversationUpdated",(function(e){return n.emit("conversationUpdated",e)})),this._conversationsEntity.on("participantJoined",(function(e){n.emit("participantJoined",e)})),this._conversationsEntity.on("participantLeft",(function(e){n.emit("participantLeft",e)})),this._conversationsEntity.on("participantUpdated",(function(e){return n.emit("participantUpdated",e)})),this._conversationsEntity.on("messageAdded",(function(e){return n.emit("messageAdded",e)})),this._conversationsEntity.on("messageUpdated",(function(e){return n.emit("messageUpdated",e)})),this._conversationsEntity.on("messageRemoved",(function(e){return n.emit("messageRemoved",e)})),this._conversationsEntity.on("typingStarted",(function(e){return n.emit("typingStarted",e)})),this._conversationsEntity.on("typingEnded",(function(e){return n.emit("typingEnded",e)})),this._conversationsPromise=this._conversationsEntity.fetchConversations().then((function(){return n._conversationsEntity})).catch((function(e){throw e})),e.next=28,this._services.users.myself._ensureFetched();case 28:OW._supportedPushChannels.forEach((function(e){return n._subscribeToPushNotifications(e)})),this._services.typingIndicator.initialize(),this._services.mcsClient=new tU.McsClient(this._fpaToken,this._configuration.links.mediaService,this._configuration.links.mediaSetService,IW(IW({},this._options),{},{transport:void 0})),this._resolveEnsureReady(),this.emit("initialized");case 33:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_subscribeToPushNotifications",value:function(e){var t=this;[LS.NEW_MESSAGE,LS.ADDED_TO_CONVERSATION,LS.REMOVED_FROM_CONVERSATION,LS.TYPING_INDICATOR,LS.CONSUMPTION_UPDATE].forEach((function(n){t._services.notificationClient.subscribe(e,n)}))}},{key:"_unsubscribeFromPushNotifications",value:function(e){var t=this;[LS.NEW_MESSAGE,LS.ADDED_TO_CONVERSATION,LS.REMOVED_FROM_CONVERSATION,LS.TYPING_INDICATOR,LS.CONSUMPTION_UPDATE].forEach((function(n){t._services.notificationClient.unsubscribe(e,n)}))}}],[{key:"parsePushNotification",value:function(e){if(OW._logger.debug("parsePushNotification, notificationPayload=",e),void 0!==e.aps){if(!e.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var t,n,r,i=OW._parsePushNotificationChatData(e),a=e.aps,o=null;if("string"==typeof a.alert)t=a.alert||null;else t=(null===(n=a.alert)||void 0===n?void 0:n.body)||null,o=(null===(r=a.alert)||void 0===r?void 0:r.title)||null;return new PushNotification({title:o,body:t,sound:a.sound||null,badge:a.badge||null,action:a.category||null,type:e.twi_message_type,data:i})}if(void 0!==e.data){var s=e.data;if(!s.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var u=OW._parsePushNotificationChatData(e.data);return new PushNotification({title:s.twi_title||null,body:s.twi_body||null,sound:s.twi_sound||null,badge:null,action:s.twi_action||null,type:s.twi_message_type,data:u})}throw new Error("Provided push notification payload is not Programmable Chat notification")}},{key:"_parsePushNotificationChatData",value:function(e){var t={};for(var n in OW._supportedPushDataFields){var r=e[n];if(null!=r)if("message_index"!==n&&"media_count"!==n){if("media"!==n)t[OW._supportedPushDataFields[n]]=r;else if("string"==typeof r)try{t[OW._supportedPushDataFields[n]]=JSON.parse(r)}catch(e){OW._logger.debug("Media message notification parsing error")}}else{var i=Cb(r);null!==i&&(t[OW._supportedPushDataFields[n]]=i)}}return t}},{key:"populateInitRegistrations",value:function(e){}}]),Client}(qx),ic(SW,"conversationAdded","conversationAdded"),ic(SW,"conversationJoined","conversationJoined"),ic(SW,"conversationLeft","conversationLeft"),ic(SW,"conversationRemoved","conversationRemoved"),ic(SW,"conversationUpdated","conversationUpdated"),ic(SW,"participantJoined","participantJoined"),ic(SW,"participantLeft","participantLeft"),ic(SW,"participantUpdated","participantUpdated"),ic(SW,"messageAdded","messageAdded"),ic(SW,"messageRemoved","messageRemoved"),ic(SW,"messageUpdated","messageUpdated"),ic(SW,"tokenAboutToExpire","tokenAboutToExpire"),ic(SW,"tokenExpired","tokenExpired"),ic(SW,"typingEnded","typingEnded"),ic(SW,"typingStarted","typingStarted"),ic(SW,"pushNotification","pushNotification"),ic(SW,"userSubscribed","userSubscribed"),ic(SW,"userUnsubscribed","userUnsubscribed"),ic(SW,"userUpdated","userUpdated"),ic(SW,"initialized","initialized"),ic(SW,"initFailed","initFailed"),ic(SW,"connectionStateChanged","connectionStateChanged"),ic(SW,"connectionError","connectionError"),ic(SW,"version",kW),ic(SW,"_logger",dy.scope("Client")),ic(SW,"_supportedPushChannels",["fcm","apn"]),ic(SW,"_supportedPushDataFields",{conversation_sid:"conversationSid",conversation_title:"conversationTitle",message_sid:"messageSid",message_index:"messageIndex",media_count:"mediaCount",media:"media"}),OW=SW),dh([tx(Yk),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],e.Client.prototype,"updateToken",null),dh([tx(Yk),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],e.Client.prototype,"getConversationBySid",null),dh([tx(Yk),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],e.Client.prototype,"peekConversationBySid",null),dh([tx(Yk),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],e.Client.prototype,"getConversationByUniqueName",null),dh([tx(["undefined",Qk("conversation options",{friendlyName:["string","undefined"],isPrivate:["boolean","undefined"],uniqueName:["string","undefined"]})]),ph("design:type",Function),ph("design:paramtypes",[Object]),ph("design:returntype",Promise)],e.Client.prototype,"createConversation",null),dh([tx(Gk("fcm","apn"),"string"),ph("design:type",Function),ph("design:paramtypes",[String,String]),ph("design:returntype",Promise)],e.Client.prototype,"setPushRegistrationId",null),dh([tx(Gk("fcm","apn")),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],e.Client.prototype,"unsetPushRegistrationId",null),dh([tx(Gk("fcm","apn"),Yk),ph("design:type",Function),ph("design:paramtypes",[String,String]),ph("design:returntype",Promise)],e.Client.prototype,"removePushRegistrations",null),dh([tx(Xk),ph("design:type",Function),ph("design:paramtypes",[Object]),ph("design:returntype",Promise)],e.Client.prototype,"handlePushNotification",null),dh([tx(Yk),ph("design:type",Function),ph("design:paramtypes",[String]),ph("design:returntype",Promise)],e.Client.prototype,"getUser",null),dh([tx(Vk("strings","string")),ph("design:type",Function),ph("design:paramtypes",[Array]),ph("design:returntype",tU.CancellablePromise)],e.Client.prototype,"getTemporaryContentUrlsForMediaSids",null),dh([tx(Vk("media",Media)),ph("design:type",Function),ph("design:paramtypes",[Array]),ph("design:returntype",tU.CancellablePromise)],e.Client.prototype,"getTemporaryContentUrlsForMedia",null),dh([ex(Xk),ph("design:type",Function),ph("design:paramtypes",[Object]),ph("design:returntype",PushNotification)],e.Client,"parsePushNotification",null),e.Client=OW=dh([Zk(Yk,[Xk,"undefined"]),ph("design:paramtypes",[String,Object])],e.Client),e.AggregatedDeliveryReceipt=AggregatedDeliveryReceipt,e.CancellablePromise=tU.CancellablePromise,e.Conversation=Conversation,e.DetailedDeliveryReceipt=DetailedDeliveryReceipt,e.Media=Media,e.Message=Message,e.MessageBuilder=Lz,e.NotificationTypes=LS,e.Participant=Participant,e.PushNotification=PushNotification,e.RestPaginator=Sz,e.UnsentMessage=Mz,e.User=User,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|