@twilio/conversations 2.1.0-rc.9 → 2.2.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +214 -0
- package/README.md +8 -4
- package/builds/browser.js +2911 -1974
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +572 -285
- package/builds/lib.js +2911 -1974
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +27160 -11795
- package/builds/twilio-conversations.min.js +1 -16
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/client.js +466 -281
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js +2 -2
- package/dist/configuration.js.map +1 -1
- package/dist/conversation.js +426 -370
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +25 -13
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +56 -32
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +21 -12
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +2 -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 +36 -25
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js +24 -18
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +89 -17
- 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.map +1 -1
- package/dist/services/typing-indicator.js +1 -1
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js +13 -3
- 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/docs/assets/js/search.js +1 -1
- package/docs/classes/CancellablePromise.html +3213 -0
- package/docs/classes/Client.html +243 -58
- package/docs/classes/Conversation.html +76 -47
- package/docs/classes/Media.html +2 -28
- package/docs/classes/Message.html +94 -39
- package/docs/classes/MessageBuilder.html +31 -8
- package/docs/classes/PushNotification.html +1 -1
- package/docs/classes/UnsentMessage.html +2 -2
- package/docs/index.html +25 -28
- package/docs/interfaces/ConversationLimits.html +12 -12
- package/docs/interfaces/ConversationState.html +2 -2
- package/docs/interfaces/ConversationUpdatedEventArgs.html +3001 -0
- package/docs/interfaces/PushNotificationData.html +48 -0
- package/docs/modules.html +24 -27
- package/package.json +24 -20
@@ -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")||"",O=i,C=I,P=O.process,A=O.Deno,j=P&&P.versions||A&&A.version,M=j&&j.v8;M?p=(d=M.split("."))[0]<4?1:d[0]+d[1]:C&&(!(d=C.match(/Edge\/(\d+)/))||d[1]>=74)&&(d=C.match(/Chrome\/(\d+)/))&&(p=d[1]);var L=p&&+p,N=L,U=s,D=!!Object.getOwnPropertySymbols&&!U((function(){var e=Symbol();return!String(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&N&&N<41})),F=D&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,B=R,q=F?function(e){return"symbol"==typeof e}:function(e){var t=B("Symbol");return"function"==typeof t&&Object(e)instanceof t},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,Oe=u,Ce=h,Pe=_,Ae=we,je=ee,Me=Re,Le=Object.getOwnPropertyDescriptor;a.f=Ie?Le:function(e,t){if(e=Pe(e),t=Ae(t),Me)try{return Le(e,t)}catch(e){}if(je(e,t))return Ce(!Oe.f.call(e,t),e[t])};var Ne={},Ue=S,De=function(e){if(!Ue(e))throw TypeError(String(e)+" is not an object");return e},Fe=o,Be=Re,qe=De,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,Ot=xt.enforce,Ct=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=Ot(n)).source||(i.source=Ct.join("string"==typeof t?t:""))),e!==_t?(a?!o&&e[t]&&(s=!0):delete e[t],s?e[t]=n:St(e,t,n)):s?e[t]=n:Tt(t,n)})(Function.prototype,"toString",(function(){return"function"==typeof this&&It(this).source||Rt(this)}));var Pt={},At=Math.ceil,jt=Math.floor,Mt=function(e){return isNaN(e=+e)?0:(e>0?jt:At)(e)},Lt=Mt,Nt=Math.min,Ut=function(e){return e>0?Nt(Lt(e),9007199254740991):0},Dt=Mt,Ft=Math.max,Bt=Math.min,qt=function(e,t){var n=Dt(e);return n<0?Ft(n+t,0):Bt(n,t)},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)}},On=function(e){if("function"!=typeof e)throw TypeError(String(e)+" is not a function");return e},Cn=Qt,Pn=Xt,An=Object.keys||function(e){return Cn(e,Pn)},jn=Ne,Mn=De,Ln=An,Nn=o?Object.defineProperties:function(e,t){Mn(e);for(var n,r=Ln(t),i=r.length,a=0;i>a;)jn.f(e,n=r[a++],t[n]);return e},Un=R("document","documentElement"),Dn=De,Fn=Nn,Bn=Xt,qn=ot,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=On,Qn=S,Xn=[].slice,Zn={},er=function(e,t,n){if(!(t in Zn)){for(var r=[],i=0;i<t;i++)r[i]="a["+i+"]";Zn[t]=Function("C,a","return new C("+r.join(",")+")")}return Zn[t](e,n)},tr=Function.bind||function(e){var t=Yn(this),n=Xn.call(arguments,1),r=function(){var i=n.concat(Xn.call(arguments));return this instanceof r?er(t,i.length,i):t.apply(e,i)};return Qn(t.prototype)&&(r.prototype=t.prototype),r},nr=In,rr=On,ir=De,ar=S,sr=Hn,or=tr,ur=s,cr=R("Reflect","construct"),lr=ur((function(){function e(){}return!(cr((function(){}),[],e)instanceof e)})),fr=!ur((function(){cr((function(){}))})),dr=lr||fr;nr({target:"Reflect",stat:!0,forced:dr,sham:dr},{construct:function(e,t){rr(e),ir(t);var n=arguments.length<3?e:rr(arguments[2]);if(fr&&!lr)return cr(e,t,n);if(e==n){switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3])}var r=[null];return r.push.apply(r,t),new(or.apply(e,r))}var i=n.prototype,a=sr(ar(i)?i:Object.prototype),s=Function.apply.call(e,a,t);return ar(s)?s:a}});var pr=Q,hr=An;In({target:"Object",stat:!0,forced:s((function(){hr(1)}))},{keys:function(e){return hr(pr(e))}});var vr=y,yr=Array.isArray||function(e){return"Array"==vr(e)},mr=q,gr=function(e){if(mr(e))throw TypeError("Cannot convert a Symbol value to a string");return String(e)},br={},kr=_,wr=Pt.f,xr={}.toString,_r="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];br.f=function(e){return _r&&"[object Window]"==xr.call(e)?function(e){try{return wr(e)}catch(e){return _r.slice()}}(e):wr(kr(e))};var Sr={},Er=pe;Sr.f=Er;var Tr=i,Rr=ee,Ir=Sr,Or=Ne.f,Cr=function(e){var t=Tr.Symbol||(Tr.Symbol={});Rr(t,e)||Or(t,e,{value:Ir.f(e)})},Pr=Ne.f,Ar=ee,jr=pe("toStringTag"),Mr=function(e,t,n){e&&!Ar(e=n?e:e.prototype,jr)&&Pr(e,jr,{configurable:!0,value:t})},Lr=On,Nr=function(e,t,n){if(Lr(e),void 0===t)return e;switch(n){case 0:return function(){return e.call(t)};case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}},Ur=S,Dr=yr,Fr=pe("species"),Br=function(e){var t;return Dr(e)&&("function"!=typeof(t=e.constructor)||t!==Array&&!Dr(t.prototype)?Ur(t)&&null===(t=t[Fr])&&(t=void 0):t=void 0),void 0===t?Array:t},qr=function(e,t){return new(Br(e))(0===t?0:t)},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=Cr,Ii=Mr,Oi=xt,Ci=Hr.forEach,Pi=st("hidden"),Ai="Symbol",ji=Ei("toPrimitive"),Mi=Oi.set,Li=Oi.getterFor(Ai),Ni=Object.prototype,Ui=Qr.Symbol,Di=Xr("JSON","stringify"),Fi=mi.f,Bi=gi.f,qi=vi.f,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 Ci(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 Ci(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 Ci(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}),Ci(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 Oa(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Ia(e,t)}function Ca(e){return(Ca="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Pa(e,t){return!t||"object"!==Ca(t)&&"function"!=typeof t?Ra(e):t}function Aa(e){return(Aa=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function ja(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ma(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}In({target:"Object",stat:!0,sham:!o},{getOwnPropertyDescriptors:function(e){for(var t,n,r=ka(e),i=wa.f,a=ba(r),s={},o=0;a.length>o;)void 0!==(n=i(r,t=a[o++]))&&xa(s,t,n);return s}});var La={};La[pe("toStringTag")]="z";var Na="[object z]"===String(La),Ua=Na,Da=y,Fa=pe("toStringTag"),Ba="Arguments"==Da(function(){return arguments}()),qa=Ua?Da:function(e){var t,n,r;return void 0===e?"Undefined":null===e?"Null":"string"==typeof(n=function(e,t){try{return e[t]}catch(e){}}(t=Object(e),Fa))?n:Ba?Da(t):"Object"==(r=Da(t))&&"function"==typeof t.callee?"Arguments":r},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)},Os=pe("iterator"),Cs=!1;try{var Ps=0,As={next:function(){return{done:!!Ps++}},return:function(){Cs=!0}};As[Os]=function(){return this},Array.from(As,(function(){throw 2}))}catch(e){}var js,Ms,Ls,Ns,Us=function(e,t){if(!t&&!Cs)return!1;var n=!1;try{var r={};r[Os]=function(){return{next:function(){return{done:n=!0}}}},e(r)}catch(e){}return n},Ds=De,Fs=On,Bs=pe("species"),qs=function(e,t){var n,r=Ds(e).constructor;return void 0===r||null==(n=Ds(r)[Bs])?t:Fs(n)},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,Oo=xo.MutationObserver||xo.WebKitMutationObserver,Co=xo.document,Po=xo.process,Ao=xo.Promise,jo=_o(xo,"queueMicrotask"),Mo=jo&&jo.value;Mo||(co=function(){var e,t;for(Io&&(e=Po.domain)&&e.exit();lo;){t=lo.fn,lo=lo.next;try{t()}catch(e){throw lo?po():fo=void 0,e}}fo=void 0,e&&e.enter()},Eo||Io||Ro||!Oo||!Co?!To&&Ao&&Ao.resolve?((yo=Ao.resolve(void 0)).constructor=Ao,mo=yo.then,po=function(){mo.call(yo,co)}):po=Io?function(){Po.nextTick(co)}:function(){So.call(xo,co)}:(ho=!0,vo=Co.createTextNode(""),new Oo(co).observe(vo,{characterData:!0}),po=function(){vo.data=ho=!ho}));var Lo=Mo||function(e){var t={fn:e,next:void 0};fo&&(fo.next=t),lo||(lo=t,po()),fo=t},No={},Uo=On,Do=function(e){var t,n;this.promise=new e((function(e,r){if(void 0!==t||void 0!==n)throw TypeError("Bad Promise constructor");t=e,n=r})),this.resolve=Uo(t),this.reject=Uo(n)};No.f=function(e){return new Do(e)};var Fo,Bo,qo,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=On,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,Ou=Ho.TypeError,Cu=Ho.document,Pu=Ho.process,Au=hu.f,ju=Au,Mu=!!(Cu&&Cu.createEvent&&Ho.dispatchEvent),Lu="function"==typeof PromiseRejectionEvent,Nu="unhandledrejection",Uu=!1,Du=mu(xu,(function(){var e=su(Ru),t=e!==String(Ru);if(!t&&66===ku)return!0;if(ku>=51&&/native code/.test(e))return!1;var n=new Ru((function(e){e(1)})),r=function(e){e((function(){}),(function(){}))};return(n.constructor={})[wu]=r,!(Uu=n.then((function(){}))instanceof r)||!t&&gu&&!Lu})),Fu=Du||!uu((function(e){Ru.all(e).catch((function(){}))})),Bu=function(e){var t;return!(!ru(e)||"function"!=typeof(t=e.then))&&t},qu=function(e,t){if(!e.notified){e.notified=!0;var n=e.reactions;fu((function(){for(var r=e.value,i=1==e.state,a=0;n.length>a;){var s,o,u,c=n[a++],l=i?c.ok:c.fail,f=c.resolve,d=c.reject,p=c.domain;try{l?(i||(2===e.rejection&&$u(e),e.rejection=1),!0===l?s=r:(p&&p.enter(),s=l(r),p&&(p.exit(),u=!0)),s===c.promise?d(Ou("Promise-chain cycle")):(o=Bu(s))?o.call(s,f,d):f(s)):d(r)}catch(e){p&&!u&&p.exit(),d(e)}}e.reactions=[],e.notified=!1,t&&!e.rejection&&Wu(e)}))}},zu=function(e,t,n){var r,i;Mu?((r=Cu.createEvent("Event")).promise=t,r.reason=n,r.initEvent(e,!1,!0),Ho.dispatchEvent(r)):r={promise:t,reason:n},!Lu&&(i=Ho["on"+e])?i(r):e===Nu&&pu("Unhandled promise rejection",n)},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 Ou("Promise can't be resolved itself");var r=Bu(t);r?fu((function(){var n={done:!1};try{r.call(t,Vu(Ku,n,e),Vu(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={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0},Yu=Ee("span").classList,Qu=Yu&&Yu.constructor&&Yu.constructor.prototype,Xu=Qu===Object.prototype?void 0:Qu,Zu=s,ec=function(e,t){var n=[][e];return!!n&&Zu((function(){n.call(null,t||function(){throw 1},1)}))},tc=Hr.forEach,nc=i,rc=Hu,ic=Xu,ac=ec("forEach")?[].forEach:function(e){return tc(this,e,arguments.length>1?arguments[1]:void 0)},sc=Ve,oc=function(e){if(e&&e.forEach!==ac)try{sc(e,"forEach",ac)}catch(t){e.forEach=ac}};for(var uc in rc)oc(nc[uc]&&nc[uc].prototype);oc(ic);var cc=S,lc=Za,fc=function(e,t,n){var r,i;return lc&&"function"==typeof(r=t.constructor)&&r!==n&&cc(i=r.prototype)&&i!==n.prototype&&lc(e,i),e},dc=k,pc=gr,hc="[\t\n\v\f\r \u2028\u2029\ufeff]",vc=RegExp("^"+hc+hc+"*"),yc=RegExp(hc+hc+"*$"),mc=function(e){return function(t){var n=pc(dc(t));return 1&e&&(n=n.replace(vc,"")),2&e&&(n=n.replace(yc,"")),n}},gc={start:mc(1),end:mc(2),trim:mc(3)},bc=o,kc=i,wc=kn,xc=Je.exports,_c=ee,Sc=y,Ec=fc,Tc=q,Rc=ge,Ic=s,Oc=Hn,Cc=Pt.f,Pc=a.f,Ac=Ne.f,jc=gc.trim,Mc="Number",Lc=kc.Number,Nc=Lc.prototype,Uc=Sc(Oc(Nc))==Mc,Dc=function(e){if(Tc(e))throw TypeError("Cannot convert a Symbol value to a number");var t,n,r,i,a,s,o,u,c=Rc(e,"number");if("string"==typeof c&&c.length>2)if(43===(t=(c=jc(c)).charCodeAt(0))||45===t){if(88===(n=c.charCodeAt(2))||120===n)return NaN}else if(48===t){switch(c.charCodeAt(1)){case 66:case 98:r=2,i=49;break;case 79:case 111:r=8,i=55;break;default:return+c}for(s=(a=c.slice(2)).length,o=0;o<s;o++)if((u=a.charCodeAt(o))<48||u>i)return NaN;return parseInt(a,r)}return+c};if(wc(Mc,!Lc(" 0o1")||!Lc("0b1")||Lc("+0x1"))){for(var Fc,Bc=function(e){var t=arguments.length<1?0:e,n=this;return n instanceof Bc&&(Uc?Ic((function(){Nc.valueOf.call(n)})):Sc(n)!=Mc)?Ec(new Lc(Dc(t)),n,Bc):Dc(t)},qc=bc?Cc(Lc):"MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger,fromString,range".split(","),zc=0;qc.length>zc;zc++)_c(Lc,Fc=qc[zc])&&!_c(Bc,Fc)&&Ac(Bc,Fc,Pc(Lc,Fc));Bc.prototype=Nc,Nc.constructor=Bc,xc(kc,Mc,Bc)}var Wc,Gc=Object.prototype,$c=Gc.hasOwnProperty,Vc="function"==typeof Symbol?Symbol:{},Jc=Vc.iterator||"@@iterator",Kc=Vc.asyncIterator||"@@asyncIterator",Hc=Vc.toStringTag||"@@toStringTag";function Yc(e,t,n,r){var i=t&&t.prototype instanceof rl?t:rl,a=Object.create(i.prototype),s=new yl(r||[]);return a._invoke=function(e,t,n){var r=Xc;return function(i,a){if(r===el)throw new Error("Generator is already running");if(r===tl){if("throw"===i)throw a;return gl()}for(n.method=i,n.arg=a;;){var s=n.delegate;if(s){var o=pl(s,n);if(o){if(o===nl)continue;return o}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===Xc)throw r=tl,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=el;var u=Qc(e,t,n);if("normal"===u.type){if(r=n.done?tl:Zc,u.arg===nl)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=tl,n.method="throw",n.arg=u.arg)}}}(e,n,s),a}function Qc(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}var Xc="suspendedStart",Zc="suspendedYield",el="executing",tl="completed",nl={};function rl(){}function il(){}function al(){}var sl={};sl[Jc]=function(){return this};var ol=Object.getPrototypeOf,ul=ol&&ol(ol(ml([])));ul&&ul!==Gc&&$c.call(ul,Jc)&&(sl=ul);var cl=al.prototype=rl.prototype=Object.create(sl);function ll(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function fl(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===il||"GeneratorFunction"===(t.displayName||t.name))}function dl(e,t){function n(r,i,a,s){var o=Qc(e[r],e,i);if("throw"!==o.type){var u=o.arg,c=u.value;return c&&"object"===Ca(c)&&$c.call(c,"__await")?t.resolve(c.__await).then((function(e){n("next",e,a,s)}),(function(e){n("throw",e,a,s)})):t.resolve(c).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,s)}))}s(o.arg)}var r;this._invoke=function(e,i){function a(){return new t((function(t,r){n(e,i,t,r)}))}return r=r?r.then(a,a):a()}}function pl(e,t){var n=e.iterator[t.method];if(n===Wc){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=Wc,pl(e,t),"throw"===t.method))return nl;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return nl}var r=Qc(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,nl;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=Wc),t.delegate=null,nl):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,nl)}function hl(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function vl(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function yl(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(hl,this),this.reset(!0)}function ml(e){if(e){var t=e[Jc];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($c.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=Wc,t.done=!0,t};return r.next=r}}return{next:gl}}function gl(){return{value:Wc,done:!0}}il.prototype=cl.constructor=al,al.constructor=il,al[Hc]=il.displayName="GeneratorFunction",ll(dl.prototype),dl.prototype[Kc]=function(){return this},ll(cl),cl[Hc]="Generator",cl[Jc]=function(){return this},cl.toString=function(){return"[object Generator]"},yl.prototype={constructor:yl,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=Wc,this.done=!1,this.delegate=null,this.method="next",this.arg=Wc,this.tryEntries.forEach(vl),!e)for(var t in this)"t"===t.charAt(0)&&$c.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=Wc)},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=Wc),!!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=$c.call(i,"catchLoc"),o=$c.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&&$c.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var i=r;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,nl):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),nl},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),vl(n),nl}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;vl(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:ml(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=Wc),nl}};var bl={wrap:Yc,isGeneratorFunction:fl,AsyncIterator:dl,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,al):(e.__proto__=al,Hc in e||(e[Hc]="GeneratorFunction")),e.prototype=Object.create(cl),e},awrap:function(e){return{__await:e}},async:function(e,t,n,r,i){void 0===i&&(i=Promise);var a=new dl(Yc(e,t,n,r),i);return fl(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},keys:function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},values:ml},kl=Object.freeze({__proto__:null,default:bl});function wl(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function xl(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}var _l=In,Sl=s,El=yr,Tl=S,Rl=Q,Il=Ut,Ol=ga,Cl=qr,Pl=oa,Al=L,jl=pe("isConcatSpreadable"),Ml=9007199254740991,Ll="Maximum allowed index exceeded",Nl=Al>=51||!Sl((function(){var e=[];return e[jl]=!1,e.concat()[0]!==e})),Ul=Pl("concat"),Dl=function(e){if(!Tl(e))return!1;var t=e[jl];return void 0!==t?!!t:El(e)};_l({target:"Array",proto:!0,forced:!Nl||!Ul},{concat:function(e){var t,n,r,i,a,s=Rl(this),o=Cl(s,0),u=0;for(t=-1,r=arguments.length;t<r;t++)if(Dl(a=-1===t?s:arguments[t])){if(u+(i=Il(a.length))>Ml)throw TypeError(Ll);for(n=0;n<i;n++,u++)n in a&&Ol(o,u,a[n])}else{if(u>=Ml)throw TypeError(Ll);Ol(o,u++,a)}return o.length=u,o}});var Fl=De,Bl=bs,ql=Nr,zl=Q,Wl=function(e,t,n,r){try{return r?t(Fl(n)[0],n[1]):t(n)}catch(t){Bl(e,"throw",t)}},Gl=ls,$l=Ut,Vl=ga,Jl=ms,Kl=hs,Hl=function(e){var t,n,r,i,a,s,o=zl(e),u="function"==typeof this?this:Array,c=arguments.length,l=c>1?arguments[1]:void 0,f=void 0!==l,d=Kl(o),p=0;if(f&&(l=ql(l,c>2?arguments[2]:void 0,2)),null==d||u==Array&&Gl(d))for(n=new u(t=$l(o.length));t>p;p++)s=f?l(o[p],p):o[p],Vl(n,p,s);else for(a=(i=Jl(o,d)).next,n=new u;!(r=a.call(i)).done;p++)s=f?Wl(i,l,[r.value,p],!0):r.value,Vl(n,p,s);return n.length=p,n},Yl=Hl;In({target:"Array",stat:!0,forced:!Us((function(e){Array.from(e)}))},{from:Yl});var Ql,Xl,Zl,ef=Mt,tf=gr,nf=k,rf=function(e){return function(t,n){var r,i,a=tf(nf(t)),s=ef(n),o=a.length;return s<0||s>=o?e?"":void 0:(r=a.charCodeAt(s))<55296||r>56319||s+1===o||(i=a.charCodeAt(s+1))<56320||i>57343?e?a.charAt(s):r:e?a.slice(s,s+2):i-56320+(r-55296<<10)+65536}},af={codeAt:rf(!1),charAt:rf(!0)},sf=!s((function(){function e(){}return e.prototype.constructor=null,Object.getPrototypeOf(new e)!==e.prototype})),of=ee,uf=Q,cf=sf,lf=st("IE_PROTO"),ff=Object.prototype,df=cf?Object.getPrototypeOf:function(e){return e=uf(e),of(e,lf)?e[lf]:"function"==typeof e.constructor&&e instanceof e.constructor?e.constructor.prototype:e instanceof Object?ff:null},pf=s,hf=df,vf=Ve,yf=pe("iterator"),mf=!1;[].keys&&("next"in(Zl=[].keys())?(Xl=hf(hf(Zl)))!==Object.prototype&&(Ql=Xl):mf=!0),(null==Ql||pf((function(){var e={};return Ql[yf].call(e)!==e})))&&(Ql={}),"function"!=typeof Ql[yf]&&vf(Ql,yf,(function(){return this}));var gf={IteratorPrototype:Ql,BUGGY_SAFARI_ITERATORS:mf},bf=gf.IteratorPrototype,kf=Hn,wf=h,xf=Mr,_f=ss,Sf=function(){return this},Ef=function(e,t,n){var r=t+" Iterator";return e.prototype=kf(bf,{next:wf(1,n)}),xf(e,r,!1),_f[r]=Sf,e},Tf=In,Rf=Ef,If=df,Of=Za,Cf=Mr,Pf=Ve,Af=Je.exports,jf=ss,Mf=gf.IteratorPrototype,Lf=gf.BUGGY_SAFARI_ITERATORS,Nf=pe("iterator"),Uf="keys",Df="values",Ff="entries",Bf=function(){return this},qf=function(e,t,n,r,i,a,s){Rf(n,t,r);var o,u,c,l=function(e){if(e===i&&v)return v;if(!Lf&&e in p)return p[e];switch(e){case Uf:case Df:case Ff:return function(){return new n(this,e)}}return function(){return new n(this)}},f=t+" Iterator",d=!1,p=e.prototype,h=p[Nf]||p["@@iterator"]||i&&p[i],v=!Lf&&h||l(i),y="Array"==t&&p.entries||h;if(y&&(o=If(y.call(new e)))!==Object.prototype&&o.next&&(If(o)!==Mf&&(Of?Of(o,Mf):"function"!=typeof o[Nf]&&Pf(o,Nf,Bf)),Cf(o,f,!0)),i==Df&&h&&h.name!==Df&&(d=!0,v=function(){return h.call(this)}),p[Nf]!==v&&Pf(p,Nf,v),jf[t]=v,i)if(u={values:l(Df),keys:a?v:l(Uf),entries:l(Ff)},s)for(c in u)(Lf||d||!(c in p))&&Af(p,c,u[c]);else Tf({target:t,proto:!0,forced:Lf||d},u);return u},zf=af.charAt,Wf=gr,Gf=xt,$f=qf,Vf="String Iterator",Jf=Gf.set,Kf=Gf.getterFor(Vf);$f(String,"String",(function(e){Jf(this,{type:Vf,string:Wf(e),index:0})}),(function(){var e,t=Kf(this),n=t.string,r=t.index;return r>=n.length?{value:void 0,done:!0}:(e=zf(n,r),t.index+=e.length,{value:e,done:!1})}));var Hf,Yf,Qf,Xf={exports:{}};function Zf(e,t){return["".concat((new Date).toISOString()," Conversations ").concat(e,":")].concat(Array.from(t))}Yf=t,Qf=function(){var e=function(){},t="undefined",n=("undefined"==typeof window?"undefined":Ca(window))!==t&&Ca(window.navigator)!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=["trace","debug","info","warn","error"];function i(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function a(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function s(r){return"debug"===r&&(r="log"),("undefined"==typeof console?"undefined":Ca(console))!==t&&("trace"===r&&n?a:void 0!==console[r]?i(console,r):void 0!==console.log?i(console,"log"):e)}function o(t,n){for(var i=0;i<r.length;i++){var a=r[i];this[a]=i<t?e:this.methodFactory(a,t,n)}this.log=this.debug}function u(e,n,r){return function(){("undefined"==typeof console?"undefined":Ca(console))!==t&&(o.call(this,n,r),this[e].apply(this,arguments))}}function c(e,t,n){return s(e)||u.apply(this,arguments)}function l(e,n,i){var a,s=this,u="loglevel";function l(){var e;if(("undefined"==typeof window?"undefined":Ca(window))!==t&&u){try{e=window.localStorage[u]}catch(e){}if(Ca(e)===t)try{var n=window.document.cookie,r=n.indexOf(encodeURIComponent(u)+"=");-1!==r&&(e=/^([^;]+)/.exec(n.slice(r))[1])}catch(e){}return void 0===s.levels[e]&&(e=void 0),e}}"string"==typeof e?u+=":"+e:"symbol"===Ca(e)&&(u=void 0),s.name=e,s.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},s.methodFactory=i||c,s.getLevel=function(){return a},s.setLevel=function(n,i){if("string"==typeof n&&void 0!==s.levels[n.toUpperCase()]&&(n=s.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=s.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(a=n,!1!==i&&function(e){var n=(r[e]||"silent").toUpperCase();if(("undefined"==typeof window?"undefined":Ca(window))!==t&&u){try{return void(window.localStorage[u]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(u)+"="+n+";"}catch(e){}}}(n),o.call(s,n,e),("undefined"==typeof console?"undefined":Ca(console))===t&&n<s.levels.SILENT)return"No console available for logging"},s.setDefaultLevel=function(e){l()||s.setLevel(e,!1)},s.enableAll=function(e){s.setLevel(s.levels.TRACE,e)},s.disableAll=function(e){s.setLevel(s.levels.SILENT,e)};var f=l();null==f&&(f=null==n?"WARN":n),s.setLevel(f,!1)}var f=new l,d={};f.getLogger=function(e){if("symbol"!==Ca(e)&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=d[e];return t||(t=d[e]=new l(e,f.getLevel(),f.methodFactory)),t};var p=("undefined"==typeof window?"undefined":Ca(window))!==t?window.log:void 0;return f.noConflict=function(){return("undefined"==typeof window?"undefined":Ca(window))!==t&&window.log===f&&(window.log=p),f},f.getLoggers=function(){return d},f.default=f,f},(Hf=Xf).exports?Hf.exports=Qf():Yf.log=Qf();var ed,td,nd=Xf.exports.getLogger("twilio-conversations"),rd=function(){function e(t){Ma(this,e),ja(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return Ta(e,[{key:"setLevel",value:function(e){nd.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.trace.apply(null,Zf(this.prefix+"T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.debug.apply(null,Zf(this.prefix+"D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.info.apply(null,Zf(this.prefix+"I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.warn.apply(null,Zf(this.prefix+"W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.error.apply(null,Zf(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){nd.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.trace.apply(null,Zf("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.debug.apply(null,Zf("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.info.apply(null,Zf("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.warn.apply(null,Zf("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];nd.error.apply(null,Zf("E",t))}}]),e}(),id={};Object.defineProperty(id,"__esModule",{value:!0});var ad=["weeks","years","months","days","hours","minutes","seconds"],sd=id.pattern=new RegExp("P(?:(\\d+(?:[\\.,]\\d+)?W)|(\\d+(?:[\\.,]\\d+)?Y)?(\\d+(?:[\\.,]\\d+)?M)?(\\d+(?:[\\.,]\\d+)?D)?(?:T(\\d+(?:[\\.,]\\d+)?H)?(\\d+(?:[\\.,]\\d+)?M)?(\\d+(?:[\\.,]\\d+)?S)?)?)"),od=td=id.parse=function(e){return e.match(sd).slice(1).reduce((function(e,t,n){return e[ad[n]]=parseFloat(t)||0,e}),{})},ud=id.end=function(e,t){var n=t?t.getTime():Date.now(),r=new Date(n);return r.setFullYear(r.getFullYear()+e.years),r.setMonth(r.getMonth()+e.months),r.setDate(r.getDate()+e.days),r.setHours(r.getHours()+e.hours),r.setMinutes(r.getMinutes()+e.minutes),r.setMilliseconds(r.getMilliseconds()+1e3*e.seconds),r.setDate(r.getDate()+7*e.weeks),r},cd=ed=id.toSeconds=function(e,t){var n=t?t.getTime():Date.now(),r=new Date(n);return(ud(e,r).getTime()-r.getTime())/1e3};function ld(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function fd(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ld(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ld(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}id.default={end:ud,toSeconds:cd,pattern:sd,parse:od};var dd="PT5S",pd="PT5S",hd=function e(){var t,n,r,i,a,s,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},u=arguments.length>1?arguments[1]:void 0,c=arguments.length>2?arguments[2]:void 0;Ma(this,e),ja(this,"typingIndicatorTimeoutDefault",5e3);var l=o.Chat||o.IPMessaging||o||{};this.productId=l.productId,this.links={myConversations:u.links.my_conversations,conversations:u.links.conversations,users:u.links.users,currentUser:u.links.current_user,typing:u.links.typing,mediaService:u.links.media_service,mediaSetService:u.links.media_set_service,messagesReceipts:u.links.messages_receipts},this.limits={mediaAttachmentsCountLimit:u.options.media_attachments_count_limit,mediaAttachmentSizeLimitInMb:u.options.media_attachment_size_limit_in_mb,mediaAttachmentsTotalSizeLimitInMb:u.options.media_attachments_total_size_limit_in_mb,emailHistoriesAllowedMimeTypes:u.options.email_histories_allowed_mime_types,emailBodiesAllowedMimeTypes:u.options.email_bodies_allowed_mime_types},this.typingIndicatorTimeoutOverride=l.typingIndicatorTimeoutOverride,this.backoffConfiguration=fd({min:1e3,max:4e3,maxAttemptsCount:3},l.backoffConfigOverride),this.retryWhenThrottled=void 0===l.retryWhenThrottledOverride||l.retryWhenThrottledOverride,this.userInfosToSubscribe=null!==(t=null!==(n=l.userInfosToSubscribeOverride)&&void 0!==n?n:u.options.user_infos_to_subscribe)&&void 0!==t?t:100,this.reachabilityEnabled=u.options.reachability_enabled,this.userIdentity=u.identity,this.userInfo=u.sync_objects.my_user_info,this.myConversations=u.sync_objects.my_conversations;var f=null!==(r=null!==(i=l.httpCacheIntervalOverride)&&void 0!==i?i:u.options.http_cache_interval)&&void 0!==r?r:dd;try{this.httpCacheInterval=ed(td(f))}catch(e){c.error("Failed to parse http cache interval ".concat(f,", using default value ").concat(dd)),this.httpCacheInterval=ed(td(dd))}var d=null!==(a=null!==(s=l.consumptionReportIntervalOverride)&&void 0!==s?s:u.options.consumption_report_interval)&&void 0!==a?a:pd;try{this.consumptionReportInterval=ed(td(d))}catch(e){c.error("Failed to parse consumption report interval ".concat(d,", using default value ").concat(pd)),this.consumptionReportInterval=ed(td(pd))}},vd=Hr.map;In({target:"Array",proto:!0,forced:!oa("map")},{map:function(e){return vd(this,e,arguments.length>1?arguments[1]:void 0)}});var yd=Hn,md=Ne,gd=pe("unscopables"),bd=Array.prototype;null==bd[gd]&&md.f(bd,gd,{configurable:!0,value:yd(null)});var kd=function(e){bd[gd][e]=!0},wd=_,xd=kd,_d=ss,Sd=xt,Ed=qf,Td="Array Iterator",Rd=Sd.set,Id=Sd.getterFor(Td),Od=Ed(Array,"Array",(function(e,t){Rd(this,{type:Td,target:wd(e),index:0,kind:t})}),(function(){var e=Id(this),t=e.target,n=e.kind,r=e.index++;return!t||r>=t.length?(e.target=void 0,{value:void 0,done:!0}):"keys"==n?{value:r,done:!1}:"values"==n?{value:t[r],done:!1}:{value:[r,t[r]],done:!1}}),"values");_d.Arguments=_d.Array,xd("keys"),xd("values"),xd("entries");var Cd=i,Pd=Hu,Ad=Xu,jd=Od,Md=Ve,Ld=pe,Nd=Ld("iterator"),Ud=Ld("toStringTag"),Dd=jd.values,Fd=function(e,t){if(e){if(e[Nd]!==Dd)try{Md(e,Nd,Dd)}catch(t){e[Nd]=Dd}if(e[Ud]||Md(e,Ud,t),Pd[t])for(var n in jd)if(e[n]!==jd[n])try{Md(e,n,jd[n])}catch(t){e[n]=jd[n]}}};for(var Bd in Pd)Fd(Cd[Bd]&&Cd[Bd].prototype,Bd);Fd(Ad,"DOMTokenList");var qd=De,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=af.charAt,Sp=function(e,t,n){return t+(n?_p(e,t).length:1)},Ep=Q,Tp=Math.floor,Rp="".replace,Ip=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,Op=/\$([$&'`]|\d{1,2})/g,Cp=y,Pp=hp,Ap=function(e,t){var n=e.exec;if("function"==typeof n){var r=n.call(e,t);if("object"!=typeof r)throw TypeError("RegExp exec method returned something other than an Object or null");return r}if("RegExp"!==Cp(e))throw TypeError("RegExp#exec called on incompatible receiver");return Pp.call(e,t)},jp=xp,Mp=s,Lp=De,Np=Mt,Up=Ut,Dp=gr,Fp=k,Bp=Sp,qp=function(e,t,n,r,i,a){var s=n+e.length,o=r.length,u=Op;return void 0!==i&&(i=Ep(i),u=Ip),Rp.call(a,u,(function(a,u){var c;switch(u.charAt(0)){case"$":return"$";case"&":return e;case"`":return t.slice(0,n);case"'":return t.slice(s);case"<":c=i[u.slice(1,-1)];break;default:var l=+u;if(0===l)return a;if(l>o){var f=Tp(l/10);return 0===f?a:f<=o?void 0===r[f-1]?u.charAt(1):r[f-1]+u.charAt(1):a}c=r[l-1]}return void 0===c?"":c}))},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=ec("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,Oh="Symbol(test)"==String(Sh("test")),Ch=/^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=Oh?t.slice(7,-1):t.replace(Ch,"$1");return""===n?void 0:n}}),mh({global:!0,forced:!0},{Symbol:Th})}Cr("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=kd;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"===Ca(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 Ov(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 Cv(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 Cv(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 Cv(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=Ov(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(Ca(e)),"a JSON type"]})),ey=Gv((function(e){return[["undefined","string","number","boolean","object"].includes(Ca(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"===Ca(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 Oy(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 Cy(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:Oy(n,l,this,arguments[1],arguments[2]);break;case 4:Cy(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)}}]),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"==Ca(t)&&t&&t.Object===Object&&t,T="object"==("undefined"==typeof self?"undefined":Ca(self))&&self&&self.Object===Object&&self,R=E||T||Function("return this")(),I=n&&!n.nodeType&&n,O=I&&e&&!e.nodeType&&e,C=O&&O.exports===I,P=C&&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=C?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)?Oe(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=Oe(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 O=R?e.value():e,C=I?t.value():t;return l||(l=new we),i(O,C,n,r,l)}}if(!T)return!1;return l||(l=new we),function(e,t,n,r,i,a){var s=1&n,o=Ce(e),u=o.length,c=Ce(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 Oe(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 Ce(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=Ca(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=Ca(e);return null!=e&&("object"==t||"function"==t)}function Ge(e){return null!=e&&"object"==Ca(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=rd.scope("User"),User=function(e){Oa(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(bl.mark((function e(t,n){var r,i;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:r=[],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(bl.mark((function e(t,n){var r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:if(this.configuration.reachabilityEnabled){e.next=4;break}return e.abrupt("return",Promise.resolve());case 4:return e.abrupt("return",t.get("reachability").then(n).catch((function(e){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(bl.mark((function e(){var t=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:if(this.state.entityName){e.next=4;break}return e.abrupt("return",this);case 4:return this.promiseToFetch=this.services.syncClient.map({id:this.state.entityName,mode:"open_existing",includeItems:!0}).then((function(e){return t.entity=e,e.on("itemUpdated",(function(e){return 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(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:return e.abrupt("return",this.promiseToFetch||this._fetch());case 3:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"updateAttributes",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:if("unsubscribed"!=this.subscribed){e.next=4;break}throw new Error("Can't modify unsubscribed object");case 4:return e.next=6,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(t)});case 6:return e.abrupt("return",this);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"updateFriendlyName",value:(n=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:if("unsubscribed"!=this.subscribed){e.next=4;break}throw new Error("Can't modify unsubscribed object");case 4:return e.next=6,this.services.commandExecutor.mutateResource("post",this.links.self,{friendly_name:t});case 6:return e.abrupt("return",this);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"unsubscribe",value:(t=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:if(!this.promiseToFetch){e.next=9;break}return e.next=5,this.promiseToFetch;case 5:this.entity.close(),this.promiseToFetch=null,this.subscribed="unsubscribed",this.emit("userUnsubscribed",this);case 9:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_resolveInitialization",value:function(e,t,n,r){this.configuration=e,this.identity=t,this.entityName=n,this.links={self:"".concat(this.configuration.links.users,"/").concat(this.identity)},this._resolveInitializationPromise(),r&&this.emit("updated",{user:this,updateReasons:["friendlyName","attributes","reachabilityOnline","reachabilityNotifiable"]})}}]),User}(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.")}()}wl([Xv(Zv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],User.prototype,"updateAttributes",null),wl([Xv(["string"]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("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=fc,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=qf,Im=is,Om=o,Cm=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}),Om||(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=Cm(t,!0),key:t,value:n,previous:r=s.last,next:void 0,removed:!1},s.first||(s.first=u),r&&(r.next=u),Om?s.size++:e.size++,"F"!==i&&(s.index[i]=u)),e},o=function(e,t){var n,r=a(e),i=Cm(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,Om?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),Om?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)}}),Om&&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"===Ca(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(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=this.cache.get(t))||this.isExpired(n.timestamp)){e.next=3;break}return e.abrupt("return",n.response);case 3:return r={},e.next=6,this.executeWithRetry((function(){return a.services.transport.get(t,r,a.configuration.productId)}),this.configuration.retryWhenThrottled);case 6:return i=e.sent,this.cache.set(t,{response:i,timestamp:Date.now()}),this.pokeTimer(),e.abrupt("return",i);case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()}]),e}(),gg=function e(){Ma(this,e)};ja(gg,"TYPING_INDICATOR","twilio.ipmsg.typing_indicator"),ja(gg,"NEW_MESSAGE","twilio.conversations.new_message"),ja(gg,"ADDED_TO_CONVERSATION","twilio.conversations.added_to_conversation"),ja(gg,"REMOVED_FROM_CONVERSATION","twilio.conversations.removed_from_conversation"),ja(gg,"CONSUMPTION_UPDATE","twilio.channel.consumption_update");var 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(kl),xg=Je.exports,_g=De,Sg=gr,Eg=s,Tg=zd,Rg="toString",Ig=RegExp.prototype,Og=Ig.toString,Cg=Eg((function(){return"/a/b"!=Og.call({source:"a",flags:"b"})})),Pg=Og.name!=Rg;(Cg||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"===Ca(e)?this.mapTransition(r({},this.defaults.init,e,{active:!0})):(this.addState(this.defaults.init.from),this.defaults.init)},configureData:function(e){return"function"==typeof e?e:"object"===Ca(e)?function(){return e}:function(){return{}}},configureMethods:function(e){return e||{}},configurePlugins:function(e,t){var n,r,i;for(n=0,r=(e=e||[]).length;n<r;n++)"function"==typeof(i=e[n])&&(e[n]=i=i()),i.configure&&i.configure(this);return e},configureTransitions:function(e){var t,n,r,i,a,s=this.defaults.wildcard;for(n=0;n<e.length;n++)for(r=e[n],i=Array.isArray(r.from)?r.from:[r.from||s],a=r.to||s,t=0;t<i.length;t++)this.mapTransition({name:r.name,from:i[t],to:a})},transitionFor:function(e,t){var n=this.defaults.wildcard;return this.map[e][t]||this.map[n][t]},transitionsFor:function(e){var t=this.defaults.wildcard;return Object.keys(this.map[e]).concat(Object.keys(this.map[t]))},allStates:function(){return this.states},allTransitions:function(){return this.transitions}}),e.exports=a},function(e,t,n){var r=n(0),i=n(6),a=n(1),s=[null,[]];function o(e,t){this.context=e,this.config=t,this.state=t.init.from,this.observers=[e]}r(o.prototype,{init:function(e){if(r(this.context,this.config.data.apply(this.context,e)),a.hook(this,"init"),this.config.init.active)return this.fire(this.config.init.name,[])},is:function(e){return Array.isArray(e)?e.indexOf(this.state)>=0:this.state===e},isPending:function(){return this.pending},can:function(e){return!this.isPending()&&!!this.seek(e)},cannot:function(e){return!this.can(e)},allStates:function(){return this.config.allStates()},allTransitions:function(){return this.config.allTransitions()},transitions:function(){return this.config.transitionsFor(this.state)},seek:function(e,t){var n=this.config.defaults.wildcard,r=this.config.transitionFor(this.state,e),i=r&&r.to;return"function"==typeof i?i.apply(this.context,t):i===n?this.state:i},fire:function(e,t){return this.transit(e,this.state,this.seek(e,t),t)},transit:function(e,t,n,r){var i=this.config.lifecycle,a=this.config.options.observeUnchangedState||t!==n;return n?this.isPending()?this.context.onPendingTransition(e,t,n):(this.config.addState(n),this.beginTransit(),r.unshift({transition:e,from:t,to:n,fsm:this.context}),this.observeEvents([this.observersForEvent(i.onBefore.transition),this.observersForEvent(i.onBefore[e]),a?this.observersForEvent(i.onLeave.state):s,a?this.observersForEvent(i.onLeave[t]):s,this.observersForEvent(i.on.transition),a?["doTransit",[this]]:s,a?this.observersForEvent(i.onEnter.state):s,a?this.observersForEvent(i.onEnter[n]):s,a?this.observersForEvent(i.on[n]):s,this.observersForEvent(i.onAfter.transition),this.observersForEvent(i.onAfter[e]),this.observersForEvent(i.on[e])],r)):this.context.onInvalidTransition(e,t,n)},beginTransit:function(){this.pending=!0},endTransit:function(e){return this.pending=!1,e},failTransit:function(e){throw this.pending=!1,e},doTransit:function(e){this.state=e.to},observe:function(e){if(2===e.length){var t={};t[e[0]]=e[1],this.observers.push(t)}else this.observers.push(e[0])},observersForEvent:function(e){for(var t,n=0,r=this.observers.length,i=[];n<r;n++)(t=this.observers[n])[e]&&i.push(t);return[e,i,!0]},observeEvents:function(e,t,n,r){if(0===e.length)return this.endTransit(void 0===r||r);var i=e[0][0],s=e[0][1],o=e[0][2];if(t[0].event=i,i&&o&&i!==n&&a.hook(this,"lifecycle",t),0===s.length)return e.shift(),this.observeEvents(e,t,i,r);var u=s.shift(),c=u[i].apply(u,t);return c&&"function"==typeof c.then?c.then(this.observeEvents.bind(this,e,t,i)).catch(this.failTransit.bind(this)):!1===c?this.endTransit(!1):this.observeEvents(e,t,i,c)},onInvalidTransition:function(e,t,n){throw new i("transition is invalid in current state",e,t,n,this.state)},onPendingTransition:function(e,t,n){throw new i("transition is invalid while previous transition is still in progress",e,t,n,this.state)}}),e.exports=o},function(e,t,n){var r=n(0),i=n(2),a=n(1),s=n(3),o=n(4),u={is:function(e){return this._fsm.is(e)},can:function(e){return this._fsm.can(e)},cannot:function(e){return this._fsm.cannot(e)},observe:function(){return this._fsm.observe(arguments)},transitions:function(){return this._fsm.transitions()},allTransitions:function(){return this._fsm.allTransitions()},allStates:function(){return this._fsm.allStates()},onInvalidTransition:function(e,t,n){return this._fsm.onInvalidTransition(e,t,n)},onPendingTransition:function(e,t,n){return this._fsm.onPendingTransition(e,t,n)}},c={state:{configurable:!1,enumerable:!0,get:function(){return this._fsm.state},set:function(e){throw Error("use transitions to change state")}}};function l(e){return f(this||{},e)}function f(e,t){return d(e,new s(t,l)),e._fsm(),e}function d(e,t){if("object"!==Ca(e)||Array.isArray(e))throw Error("StateMachine can only be applied to objects");a.build(e,t),Object.defineProperties(e,c),r(e,u),r(e,t.methods),t.allTransitions().forEach((function(t){e[i(t)]=function(){return this._fsm.fire(t,[].slice.call(arguments))}})),e._fsm=function(){this._fsm=new o(this,t),this._fsm.init(arguments)}}l.version="3.0.1",l.factory=function(){var e,t;"function"==typeof arguments[0]?(e=arguments[0],t=arguments[1]||{}):(e=function(){this._fsm.apply(this,arguments)},t=arguments[0]||{});var n=new s(t,l);return d(e.prototype,n),e.prototype._fsm.config=n,e},l.apply=f,l.defaults={wildcard:"*",init:{name:"init",from:"none"}},e.exports=l},function(e,t,n){e.exports=function(e,t,n,r,i){this.message=e,this.transition=t,this.from=n,this.to=r,this.current=i}}])},e.exports=n()}(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=df,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),Ob=!1,Cb={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(Cb,t)||ub(Pb,t)};for(Xg in Cb)(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 Cb)sb[Xg]&&hb(sb[Xg],wb);if((!Ib||!xb||xb===_b)&&(xb=wb.prototype,Ib))for(Xg in Cb)sb[Xg]&&hb(sb[Xg].prototype,xb);if(Ib&&pb(kb)!==xb&&hb(kb,xb),ab&&!ub(xb,Eb))for(Xg in Ob=!0,db(xb,Eb,{get:function(){return ob(this)?this[Tb]:void 0}}),Cb)sb[Xg]&&lb(sb[Xg],Tb,Xg);var jb={NATIVE_ARRAY_BUFFER_VIEWS:Ib,TYPED_ARRAY_CONSTRUCTOR:Rb,TYPED_ARRAY_TAG:Ob&&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 Cb){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 Cb)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 Cb)!(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(Cb,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=df,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,Ok=function(e){return[255&e]},Ck=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,Ok,t)},setUint8:function(e,t){Uk(this,1,e,Ok,t)},setInt16:function(e,t){Uk(this,2,e,Ck,t,arguments.length>2?arguments[2]:void 0)},setUint16:function(e,t){Uk(this,2,e,Ck,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=fc,Iw=xt.get,Ow=xt.set,Cw=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){Cw(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?Cw(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){Cw(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(Ow(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=Od,Ox=pe("iterator"),Cx=Tx.Uint8Array,Px=Ix.values,Ax=Ix.keys,jx=Ix.entries,Mx=Rx.aTypedArray,Lx=Rx.exportTypedArrayMethod,Nx=Cx&&Cx.prototype[Ox],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(Ox,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=ec,$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_=On,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],O_=/MSIE|Trident/.test(I),C_=I.match(/AppleWebKit\/(\d+)\./),P_=!!C_&&+C_[1],A_=s,j_=On,M_=Ut,L_=T_,N_=I_,U_=O_,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,OS=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?OS: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?OS: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 CS={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}(CS);var MS={exports:{}};!function(e,n){(function(){var r={function:!0,object:!0}["undefined"==typeof window?"undefined":Ca(window)]&&window||this,i=n,a=e&&!e.nodeType&&e,s=i&&a&&"object"==Ca(t)&&t;!s||s.global!==s&&s.window!==s&&s.self!==s||(r=s);var o=Math.pow(2,53)-1,u=/\bOpera/,c=Object.prototype,l=c.hasOwnProperty,f=c.toString;function d(e){return(e=String(e)).charAt(0).toUpperCase()+e.slice(1)}function p(e){return e=g(e),/^(?:webOS|i(?:OS|P))/.test(e)?e:d(e)}function h(e,t){for(var n in e)l.call(e,n)&&t(e[n],n,e)}function v(e){return null==e?d(e):f.call(e).slice(8,-1)}function y(e){return String(e).replace(/([ -])(?!$)/g,"$1?")}function m(e,t){var n=null;return function(e,t){var n=-1,r=e?e.length:0;if("number"==typeof r&&r>-1&&r<=o)for(;++n<r;)t(e[n],n,e);else h(e,t)}(e,(function(r,i){n=t(n,r,i,e)})),n}function g(e){return String(e).replace(/^ +| +$/g,"")}var b=function e(t){var n=r,i=t&&"object"==Ca(t)&&"String"!=v(t);i&&(n=t,t=null);var a=n.navigator||{},s=a.userAgent||"";t||(t=s);var o,c,l=i?!!a.likeChrome:/\bChrome\b/.test(t)&&!/internal|\n/i.test(f.toString()),d="Object",b=i?d:"ScriptBridgingProxyObject",k=i?d:"Environment",w=i&&n.java?"JavaPackage":v(n.java),x=i?d:"RuntimeObject",_=/\bJava/.test(w)&&n.java,S=_&&v(n.environment)==k,E=_?"a":"α",T=_?"b":"β",R=n.document||{},I=n.operamini||n.opera,O=u.test(O=i&&I?I["[[Class]]"]:v(I))?O:I=null,C=t,P=[],A=null,j=t==s,M=j&&I&&"function"==typeof I.version&&I.version(),L=m([{label:"EdgeHTML",pattern:"Edge"},"Trident",{label:"WebKit",pattern:"AppleWebKit"},"iCab","Presto","NetFront","Tasman","KHTML","Gecko"],(function(e,n){return e||RegExp("\\b"+(n.pattern||y(n))+"\\b","i").exec(t)&&(n.label||n)})),N=function(e){return m(e,(function(e,n){return e||RegExp("\\b"+(n.pattern||y(n))+"\\b","i").exec(t)&&(n.label||n)}))}(["Adobe AIR","Arora","Avant Browser","Breach","Camino","Electron","Epiphany","Fennec","Flock","Galeon","GreenBrowser","iCab","Iceweasel","K-Meleon","Konqueror","Lunascape","Maxthon",{label:"Microsoft Edge",pattern:"(?:Edge|Edg|EdgA|EdgiOS)"},"Midori","Nook Browser","PaleMoon","PhantomJS","Raven","Rekonq","RockMelt",{label:"Samsung Internet",pattern:"SamsungBrowser"},"SeaMonkey",{label:"Silk",pattern:"(?:Cloud9|Silk-Accelerated)"},"Sleipnir","SlimBrowser",{label:"SRWare Iron",pattern:"Iron"},"Sunrise","Swiftfox","Vivaldi","Waterfox","WebPositive",{label:"Yandex Browser",pattern:"YaBrowser"},{label:"UC Browser",pattern:"UCBrowser"},"Opera Mini",{label:"Opera Mini",pattern:"OPiOS"},"Opera",{label:"Opera",pattern:"OPR"},"Chromium","Chrome",{label:"Chrome",pattern:"(?:HeadlessChrome)"},{label:"Chrome Mobile",pattern:"(?:CriOS|CrMo)"},{label:"Firefox",pattern:"(?:Firefox|Minefield)"},{label:"Firefox for iOS",pattern:"FxiOS"},{label:"IE",pattern:"IEMobile"},{label:"IE",pattern:"MSIE"},"Safari"]),U=B([{label:"BlackBerry",pattern:"BB10"},"BlackBerry",{label:"Galaxy S",pattern:"GT-I9000"},{label:"Galaxy S2",pattern:"GT-I9100"},{label:"Galaxy S3",pattern:"GT-I9300"},{label:"Galaxy S4",pattern:"GT-I9500"},{label:"Galaxy S5",pattern:"SM-G900"},{label:"Galaxy S6",pattern:"SM-G920"},{label:"Galaxy S6 Edge",pattern:"SM-G925"},{label:"Galaxy S7",pattern:"SM-G930"},{label:"Galaxy S7 Edge",pattern:"SM-G935"},"Google TV","Lumia","iPad","iPod","iPhone","Kindle",{label:"Kindle Fire",pattern:"(?:Cloud9|Silk-Accelerated)"},"Nexus","Nook","PlayBook","PlayStation Vita","PlayStation","TouchPad","Transformer",{label:"Wii U",pattern:"WiiU"},"Wii","Xbox One",{label:"Xbox 360",pattern:"Xbox"},"Xoom"]),D=function(e){return m(e,(function(e,n,r){return e||(n[U]||n[/^[a-z]+(?: +[a-z]+\b)*/i.exec(U)]||RegExp("\\b"+y(r)+"(?:\\b|\\w*\\d)","i").exec(t))&&r}))}({Apple:{iPad:1,iPhone:1,iPod:1},Alcatel:{},Archos:{},Amazon:{Kindle:1,"Kindle Fire":1},Asus:{Transformer:1},"Barnes & Noble":{Nook:1},BlackBerry:{PlayBook:1},Google:{"Google TV":1,Nexus:1},HP:{TouchPad:1},HTC:{},Huawei:{},Lenovo:{},LG:{},Microsoft:{Xbox:1,"Xbox One":1},Motorola:{Xoom:1},Nintendo:{"Wii U":1,Wii:1},Nokia:{Lumia:1},Oppo:{},Samsung:{"Galaxy S":1,"Galaxy S2":1,"Galaxy S3":1,"Galaxy S4":1},Sony:{PlayStation:1,"PlayStation Vita":1},Xiaomi:{Mi:1,Redmi:1}}),F=function(e){return m(e,(function(e,n){var r=n.pattern||y(n);return!e&&(e=RegExp("\\b"+r+"(?:/[\\d.]+|[ \\w.]*)","i").exec(t))&&(e=function(e,t,n){var r={"10.0":"10",6.4:"10 Technical Preview",6.3:"8.1",6.2:"8",6.1:"Server 2008 R2 / 7","6.0":"Server 2008 / Vista",5.2:"Server 2003 / XP 64-bit",5.1:"XP",5.01:"2000 SP1","5.0":"2000","4.0":"NT","4.90":"ME"};return t&&n&&/^Win/i.test(e)&&!/^Windows Phone /i.test(e)&&(r=r[/[\d.]+$/.exec(e)])&&(e="Windows "+r),e=String(e),t&&n&&(e=e.replace(RegExp(t,"i"),n)),p(e.replace(/ ce$/i," CE").replace(/\bhpw/i,"web").replace(/\bMacintosh\b/,"Mac OS").replace(/_PowerPC\b/i," OS").replace(/\b(OS X) [^ \d]+/i,"$1").replace(/\bMac (OS X)\b/,"$1").replace(/\/(\d)/," $1").replace(/_/g,".").replace(/(?: BePC|[ .]*fc[ \d.]+)$/i,"").replace(/\bx86\.64\b/gi,"x86_64").replace(/\b(Windows Phone) OS\b/,"$1").replace(/\b(Chrome OS \w+) [\d.]+\b/,"$1").split(" on ")[0])}(e,r,n.label||n)),e}))}(["Windows Phone","KaiOS","Android","CentOS",{label:"Chrome OS",pattern:"CrOS"},"Debian",{label:"DragonFly BSD",pattern:"DragonFly"},"Fedora","FreeBSD","Gentoo","Haiku","Kubuntu","Linux Mint","OpenBSD","Red Hat","SuSE","Ubuntu","Xubuntu","Cygwin","Symbian OS","hpwOS","webOS ","webOS","Tablet OS","Tizen","Linux","Mac OS X","Macintosh","Mac","Windows 98;","Windows "]);function B(e){return m(e,(function(e,n){var r=n.pattern||y(n);return!e&&(e=RegExp("\\b"+r+" *\\d+[.\\w_]*","i").exec(t)||RegExp("\\b"+r+" *\\w+-[\\w]*","i").exec(t)||RegExp("\\b"+r+"(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)","i").exec(t))&&((e=String(n.label&&!RegExp(r,"i").test(n.label)?n.label:e).split("/"))[1]&&!/[\d.]+/.test(e[0])&&(e[0]+=" "+e[1]),n=n.label||n,e=p(e[0].replace(RegExp(r,"i"),n).replace(RegExp("; *(?:"+n+"[_-])?","i")," ").replace(RegExp("("+n+")[-_.]?(\\w)","i"),"$1 $2"))),e}))}function q(e){return m(e,(function(e,n){return e||(RegExp(n+"(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)","i").exec(t)||0)[1]||null}))}if(L&&(L=[L]),/\bAndroid\b/.test(F)&&!U&&(o=/\bAndroid[^;]*;(.*?)(?:Build|\) AppleWebKit)\b/i.exec(t))&&(U=g(o[1]).replace(/^[a-z]{2}-[a-z]{2};\s*/i,"")||null),D&&!U?U=B([D]):D&&U&&(U=U.replace(RegExp("^("+y(D)+")[-_.\\s]","i"),D+" ").replace(RegExp("^("+y(D)+")[-_.]?(\\w)","i"),D+" $2")),(o=/\bGoogle TV\b/.exec(U))&&(U=o[0]),/\bSimulator\b/i.test(t)&&(U=(U?U+" ":"")+"Simulator"),"Opera Mini"==N&&/\bOPiOS\b/.test(t)&&P.push("running in Turbo/Uncompressed mode"),"IE"==N&&/\blike iPhone OS\b/.test(t)?(D=(o=e(t.replace(/like iPhone OS/,""))).manufacturer,U=o.product):/^iP/.test(U)?(N||(N="Safari"),F="iOS"+((o=/ OS ([\d_]+)/i.exec(t))?" "+o[1].replace(/_/g,"."):"")):"Konqueror"==N&&/^Linux\b/i.test(F)?F="Kubuntu":D&&"Google"!=D&&(/Chrome/.test(N)&&!/\bMobile Safari\b/i.test(t)||/\bVita\b/.test(U))||/\bAndroid\b/.test(F)&&/^Chrome/.test(N)&&/\bVersion\//i.test(t)?(N="Android Browser",F=/\bAndroid\b/.test(F)?F:"Android"):"Silk"==N?(/\bMobi/i.test(t)||(F="Android",P.unshift("desktop mode")),/Accelerated *= *true/i.test(t)&&P.unshift("accelerated")):"UC Browser"==N&&/\bUCWEB\b/.test(t)?P.push("speed mode"):"PaleMoon"==N&&(o=/\bFirefox\/([\d.]+)\b/.exec(t))?P.push("identifying as Firefox "+o[1]):"Firefox"==N&&(o=/\b(Mobile|Tablet|TV)\b/i.exec(t))?(F||(F="Firefox OS"),U||(U=o[1])):!N||(o=!/\bMinefield\b/i.test(t)&&/\b(?:Firefox|Safari)\b/.exec(N))?(N&&!U&&/[\/,]|^[^(]+?\)/.test(t.slice(t.indexOf(o+"/")+8))&&(N=null),(o=U||D||F)&&(U||D||/\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(F))&&(N=/[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(F)?F:o)+" Browser")):"Electron"==N&&(o=(/\bChrome\/([\d.]+)\b/.exec(t)||0)[1])&&P.push("Chromium "+o),M||(M=q(["(?:Cloud9|CriOS|CrMo|Edge|Edg|EdgA|EdgiOS|FxiOS|HeadlessChrome|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$)|UCBrowser|YaBrowser)","Version",y(N),"(?:Firefox|Minefield|NetFront)"])),(o=("iCab"==L&&parseFloat(M)>3?"WebKit":/\bOpera\b/.test(N)&&(/\bOPR\b/.test(t)?"Blink":"Presto"))||/\b(?:Midori|Nook|Safari)\b/i.test(t)&&!/^(?:Trident|EdgeHTML)$/.test(L)&&"WebKit"||!L&&/\bMSIE\b/i.test(t)&&("Mac OS"==F?"Tasman":"Trident")||"WebKit"==L&&/\bPlayStation\b(?! Vita\b)/i.test(N)&&"NetFront")&&(L=[o]),"IE"==N&&(o=(/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(t)||0)[1])?(N+=" Mobile",F="Windows Phone "+(/\+$/.test(o)?o:o+".x"),P.unshift("desktop mode")):/\bWPDesktop\b/i.test(t)?(N="IE Mobile",F="Windows Phone 8.x",P.unshift("desktop mode"),M||(M=(/\brv:([\d.]+)/.exec(t)||0)[1])):"IE"!=N&&"Trident"==L&&(o=/\brv:([\d.]+)/.exec(t))&&(N&&P.push("identifying as "+N+(M?" "+M:"")),N="IE",M=o[1]),j){if(function(e,t){var n=null!=e?Ca(e[t]):"number";return!(/^(?:boolean|number|string|undefined)$/.test(n)||"object"==n&&!e[t])}(n,"global"))if(_&&(C=(o=_.lang.System).getProperty("os.arch"),F=F||o.getProperty("os.name")+" "+o.getProperty("os.version")),S){try{M=n.require("ringo/engine").version.join("."),N="RingoJS"}catch(e){(o=n.system)&&o.global.system==n.system&&(N="Narwhal",F||(F=o[0].os||null))}N||(N="Rhino")}else"object"==Ca(n.process)&&!n.process.browser&&(o=n.process)&&("object"==Ca(o.versions)&&("string"==typeof o.versions.electron?(P.push("Node "+o.versions.node),N="Electron",M=o.versions.electron):"string"==typeof o.versions.nw&&(P.push("Chromium "+M,"Node "+o.versions.node),N="NW.js",M=o.versions.nw)),N||(N="Node.js",C=o.arch,F=o.platform,M=(M=/[\d.]+/.exec(o.version))?M[0]:null));else v(o=n.runtime)==b?(N="Adobe AIR",F=o.flash.system.Capabilities.os):v(o=n.phantom)==x?(N="PhantomJS",M=(o=o.version||null)&&o.major+"."+o.minor+"."+o.patch):"number"==typeof R.documentMode&&(o=/\bTrident\/(\d+)/i.exec(t))?(M=[M,R.documentMode],(o=+o[1]+4)!=M[1]&&(P.push("IE "+M[1]+" mode"),L&&(L[1]=""),M[1]=o),M="IE"==N?String(M[1].toFixed(1)):M[0]):"number"==typeof R.documentMode&&/^(?:Chrome|Firefox)\b/.test(N)&&(P.push("masking as "+N+" "+M),N="IE",M="11.0",L=["Trident"],F="Windows");F=F&&p(F)}if(M&&(o=/(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(M)||/(?:alpha|beta)(?: ?\d)?/i.exec(t+";"+(j&&a.appMinorVersion))||/\bMinefield\b/i.test(t)&&"a")&&(A=/b/i.test(o)?"beta":"alpha",M=M.replace(RegExp(o+"\\+?$"),"")+("beta"==A?T:E)+(/\d+\+?/.exec(o)||"")),"Fennec"==N||"Firefox"==N&&/\b(?:Android|Firefox OS|KaiOS)\b/.test(F))N="Firefox Mobile";else if("Maxthon"==N&&M)M=M.replace(/\.[\d.]+/,".x");else if(/\bXbox\b/i.test(U))"Xbox 360"==U&&(F=null),"Xbox 360"==U&&/\bIEMobile\b/.test(t)&&P.unshift("mobile mode");else if(!/^(?:Chrome|IE|Opera)$/.test(N)&&(!N||U||/Browser|Mobi/.test(N))||"Windows CE"!=F&&!/Mobi/i.test(t))if("IE"==N&&j)try{null===n.external&&P.unshift("platform preview")}catch(e){P.unshift("embedded")}else(/\bBlackBerry\b/.test(U)||/\bBB10\b/.test(t))&&(o=(RegExp(U.replace(/ +/g," *")+"/([.\\d]+)","i").exec(t)||0)[1]||M)?(F=((o=[o,/BB10/.test(t)])[1]?(U=null,D="BlackBerry"):"Device Software")+" "+o[0],M=null):this!=h&&"Wii"!=U&&(j&&I||/Opera/.test(N)&&/\b(?:MSIE|Firefox)\b/i.test(t)||"Firefox"==N&&/\bOS X (?:\d+\.){2,}/.test(F)||"IE"==N&&(F&&!/^Win/.test(F)&&M>5.5||/\bWindows XP\b/.test(F)&&M>8||8==M&&!/\bTrident\b/.test(t)))&&!u.test(o=e.call(h,t.replace(u,"")+";"))&&o.name&&(o="ing as "+o.name+((o=o.version)?" "+o:""),u.test(N)?(/\bIE\b/.test(o)&&"Mac OS"==F&&(F=null),o="identify"+o):(o="mask"+o,N=O?p(O.replace(/([a-z])([A-Z])/g,"$1 $2")):"Opera",/\bIE\b/.test(o)&&(F=null),j||(M=null)),L=["Presto"],P.push(o));else N+=" Mobile";(o=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(t)||0)[1])&&(o=[parseFloat(o.replace(/\.(\d)$/,".0$1")),o],"Safari"==N&&"+"==o[1].slice(-1)?(N="WebKit Nightly",A="alpha",M=o[1].slice(0,-1)):M!=o[1]&&M!=(o[2]=(/\bSafari\/([\d.]+\+?)/i.exec(t)||0)[1])||(M=null),o[1]=(/\b(?:Headless)?Chrome\/([\d.]+)/i.exec(t)||0)[1],537.36==o[0]&&537.36==o[2]&&parseFloat(o[1])>=28&&"WebKit"==L&&(L=["Blink"]),j&&(l||o[1])?(L&&(L[1]="like Chrome"),o=o[1]||((o=o[0])<530?1:o<532?2:o<532.05?3:o<533?4:o<534.03?5:o<534.07?6:o<534.1?7:o<534.13?8:o<534.16?9:o<534.24?10:o<534.3?11:o<535.01?12:o<535.02?"13+":o<535.07?15:o<535.11?16:o<535.19?17:o<536.05?18:o<536.1?19:o<537.01?20:o<537.11?"21+":o<537.13?23:o<537.18?24:o<537.24?25:o<537.36?26:"Blink"!=L?"27":"28")):(L&&(L[1]="like Safari"),o=(o=o[0])<400?1:o<500?2:o<526?3:o<533?4:o<534?"4+":o<535?5:o<537?6:o<538?7:o<601?8:o<602?9:o<604?10:o<606?11:o<608?12:"12"),L&&(L[1]+=" "+(o+="number"==typeof o?".x":/[.+]/.test(o)?"":"+")),"Safari"==N&&(!M||parseInt(M)>45)?M=o:"Chrome"==N&&/\bHeadlessChrome/i.test(t)&&P.unshift("headless")),"Opera"==N&&(o=/\bzbov|zvav$/.exec(F))?(N+=" ",P.unshift("desktop mode"),"zvav"==o?(N+="Mini",M=null):N+="Mobile",F=F.replace(RegExp(" *"+o+"$"),"")):"Safari"==N&&/\bChrome\b/.exec(L&&L[1])?(P.unshift("desktop mode"),N="Chrome Mobile",M=null,/\bOS X\b/.test(F)?(D="Apple",F="iOS 4.3+"):F=null):/\bSRWare Iron\b/.test(N)&&!M&&(M=q("Chrome")),M&&0==M.indexOf(o=/[\d.]+$/.exec(F))&&t.indexOf("/"+o+"-")>-1&&(F=g(F.replace(o,""))),F&&-1!=F.indexOf(N)&&!RegExp(N+" OS").test(F)&&(F=F.replace(RegExp(" *"+y(N)+" *"),"")),L&&!/\b(?:Avant|Nook)\b/.test(N)&&(/Browser|Lunascape|Maxthon/.test(N)||"Safari"!=N&&/^iOS/.test(F)&&/\bSafari\b/.test(L[1])||/^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|SRWare Iron|Vivaldi|Web)/.test(N)&&L[1])&&(o=L[L.length-1])&&P.push(o),P.length&&(P=["("+P.join("; ")+")"]),D&&U&&U.indexOf(D)<0&&P.push("on "+D),U&&P.push((/^on /.test(P[P.length-1])?"":"on ")+U),F&&(o=/ ([\d.+]+)$/.exec(F),c=o&&"/"==F.charAt(F.length-o[0].length-1),F={architecture:32,family:o&&!c?F.replace(o[0],""):F,version:o?o[1]:null,toString:function(){var e=this.version;return this.family+(e&&!c?" "+e:"")+(64==this.architecture?" 64-bit":"")}}),(o=/\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(C))&&!/\bi686\b/i.test(C)?(F&&(F.architecture=64,F.family=F.family.replace(RegExp(" *"+o),"")),N&&(/\bWOW64\b/i.test(t)||j&&/\w(?:86|32)$/.test(a.cpuClass||a.platform)&&!/\bWin64; x64\b/i.test(t))&&P.unshift("32-bit")):F&&/^OS X/.test(F.family)&&"Chrome"==N&&parseFloat(M)>=39&&(F.architecture=64),t||(t=null);var 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=Xf.exports,v=Ag.exports,y=tb,m=CS.exports,g=Mm,b=MS.exports;function k(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function w(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var x=k(n),_=k(r),S=k(i),E=k(a),T=k(s),R=k(o),I=k(u),O=k(c),C=k(l),P=k(f),A=k(d),j=w(h),M=w(v),L=k(m),N=w(b);function U(){}function D(){D.init.call(this)}function F(e){return void 0===e._maxListeners?D.defaultMaxListeners:e._maxListeners}function B(e,t,n){if(t)e.call(n);else for(var r=e.length,i=K(e,r),a=0;a<r;++a)i[a].call(n)}function q(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=K(e,i),s=0;s<i;++s)a[s].call(n,r)}function z(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=K(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function W(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=K(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function G(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=K(e,i),s=0;s<i;++s)a[s].apply(n,r)}function $(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new U,e._eventsCount=0),s){if("function"==typeof s?s=a[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(i=F(e))&&i>0&&s.length>i){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,o=u,"function"==typeof console.warn?console.warn(o):console.log(o)}}else s=a[t]=n,++e._eventsCount;return e}function V(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function J(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function K(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}U.prototype=Object.create(null),D.EventEmitter=D,D.usingDomains=!1,D.prototype.domain=void 0,D.prototype._events=void 0,D.prototype._maxListeners=void 0,D.defaultMaxListeners=10,D.init=function(){this.domain=null,D.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new U,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},D.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},D.prototype.getMaxListeners=function(){return F(this)},D.prototype.emit=function(e){var t,n,r,i,a,s,o,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(o=this.domain,u){if(t=arguments[1],!o){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=o,t.domainThrown=!1,o.emit("error",t),!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:B(n,l,this);break;case 2:q(n,l,this,arguments[1]);break;case 3:z(n,l,this,arguments[1],arguments[2]);break;case 4:W(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];G(n,l,this,i)}return!0},D.prototype.addListener=function(e,t){return $(this,e,t,!1)},D.prototype.on=D.prototype.addListener,D.prototype.prependListener=function(e,t){return $(this,e,t,!0)},D.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,V(this,e,t)),this},D.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,V(this,e,t)),this},D.prototype.removeListener=function(e,t){var n,r,i,a,s;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new U:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new U,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,s||t)}return this},D.prototype.off=function(e,t){return this.removeListener(e,t)},D.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new U,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new U:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new U,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},D.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},D.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):J.call(e,t)},D.prototype.listenerCount=J,D.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var H=j.getLogger("twilsock");function Y(e,t){return["".concat((new Date).toISOString()," Twilsock ").concat(e,":")].concat(Array.from(t))}var Q=new(function(){function e(t){O.default(this,e),C.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?" "+t+":":""}return _.default(e,[{key:"setLevel",value:function(e){H.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.trace.apply(null,Y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.debug.apply(null,Y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.info.apply(null,Y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.warn.apply(null,Y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.error.apply(null,Y("E",t))}}],[{key:"setLevel",value:function(e){H.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.trace.apply(null,Y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.debug.apply(null,Y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.info.apply(null,Y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.warn.apply(null,Y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];H.error.apply(null,Y("E",t))}}]),e}())(""),X="0.12.2-rc.0",Z=function(){function e(t,n,r){O.default(this,e),C.default(this,"confirmedCapabilities",new Set),this.activeGrant=n,this._token=t;var i=r.region||"us1",a="wss://tsock.".concat(i,".twilio.com/v3/wsconnect"),s=r.twilsock||r.Twilsock||{};this.url=s.uri||a,this._continuationToken=r.continuationToken?r.continuationToken:null,this.logLevel=r.logLevel?r.logLevel:"error",this.retryPolicy=r.retryPolicy?r.retryPolicy:{min:1e3,max:12e4,randomness:.2},this.clientMetadata=r.clientMetadata?r.clientMetadata:{},this.clientMetadata.ver=X,this.initRegistrations=r.initRegistrations?r.initRegistrations:null,this.tweaks=r.tweaks?r.tweaks:null}return _.default(e,[{key:"token",get:function(){return this._token}},{key:"continuationToken",get:function(){return this._continuationToken}},{key:"updateToken",value:function(e){this._token=e}},{key:"updateContinuationToken",value:function(e){this._continuationToken=e}}]),e}(),ee=function e(t){O.default(this,e),this.id=t||"TM".concat(y.v4())};function te(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var ne=function(e){T.default(n,e);var t=te(n);function n(e,r,i,a,s){var o;return O.default(this,n),o=t.call(this),C.default(S.default(o),"method","init"),o.token=e,o.continuation_token=r,o.metadata=i,o.registrations=a,o.tweaks=s,o.capabilities=["client_update","offline_storage","telemetry.v1"],o}return n}(ee);function re(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var ie=function(e){T.default(n,e);var t=re(n);function n(e,r,i,a,s,o,u){var c;return O.default(this,n),(c=t.call(this,e)).continuationToken=r,c.continuationTokenStatus=a,c.offlineStorage=s,c.initRegistrations=o,c.debugInfo=u,c.confirmedCapabilities=i,c}return n}(ee);function ae(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var se=function(e){T.default(n,e);var t=ae(n);function n(e){var r;return O.default(this,n),r=t.call(this),C.default(S.default(r),"method","update"),r.token=e,r}return n}(ee);function oe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Message=function(e){T.default(Message,e);var t=oe(Message);function Message(e,n,r){var i;return O.default(this,Message),i=t.call(this),C.default(S.default(i),"method","message"),i.active_grant=e,i.payload_type=n,i.http_request=r,i}return Message}(ee);function ue(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var ce=function(e){T.default(n,e);var t=ue(n);function n(e){var r;return O.default(this,n),r=t.call(this,e),C.default(S.default(r),"method","reply"),C.default(S.default(r),"payload_type","application/json"),C.default(S.default(r),"status",{code:200,status:"OK"}),r}return n}(ee);function le(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var fe=function(e){T.default(n,e);var t=le(n);function n(){var e;return O.default(this,n),e=t.call(this),C.default(S.default(e),"method","close"),e}return n}(ee);function de(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var pe=function e(t,n,r,i,a,s){O.default(this,e),this.start=t,this.end=n,this.title=r,this.details=i,this.id=a,this.type=s},he=function(e){T.default(n,e);var t=de(n);function n(e){var r;return O.default(this,n),r=t.call(this),C.default(S.default(r),"method","telemetry.v1"),r.events=e,r}return n}(ee);function ve(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})).length}function ye(e){var t=encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})),n=new Uint8Array(t.length);return Array.prototype.forEach.call(t,(function(e,t){n[t]=e.charCodeAt(0)})),n}function me(e){var t=Array.prototype.map.call(e,(function(e){return String.fromCharCode(e)})).join("").replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n}));return decodeURIComponent(t)}function ge(e){return JSON.parse(me(e))}var be=function(){function e(){O.default(this,e)}return _.default(e,null,[{key:"parse",value:function(e){var t,n,r=new Uint8Array(e),i=function(e){for(var t="",n=0;n<e.length;++n){var r=String.fromCharCode(e[n]);if(t+=r,"\r"===r){n+=2;break}}var i=t.split(" ");return{size:n,protocol:i[0],version:i[1],headerSize:Number(i[2])}}(r);if("TWILSOCK"!==i.protocol||"V3.0"!==i.version)return Q.error("unsupported protocol: ".concat(i.protocol," ver ").concat(i.version)),null;try{t=ge(r.subarray(i.size,i.size+i.headerSize))}catch(t){return Q.error("failed to parse message header",t,e),null}if(Q.debug("message received: ",t.method),Q.trace("message received: ",t),t.payload_size>0){var a=2+i.size+i.headerSize,s=t.payload_size;if(t.hasOwnProperty("payload_type")&&0!==t.payload_type.indexOf("application/json"))0===t.payload_type.indexOf("text/plain")&&(n=me(r.subarray(a,a+s)));else try{n=ge(r.subarray(a,a+s))}catch(t){return Q.error("failed to parse message body",t,e),null}}return{method:t.method,header:t,payload:n}}},{key:"createPacket",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";e.payload_size=ve(t);var n=JSON.stringify(e),r="TWILSOCK V3.0 "+ve(n);Q.debug("send request:",r+n+t);var i=ye(r+"\r\n"+n+"\r\n"+t);return i.buffer}}]),e}();function ke(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var we=function(e){T.default(n,e);var t=ke(n);function n(e){return O.default(this,n),t.call(this,e)}return n}(L.default(Error));function xe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var _e=function(e){T.default(n,e);var t=xe(n);function n(e,r){var i;return O.default(this,n),(i=t.call(this,e)).reply=r,i}return n}(we);function Se(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Ee(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Se(Object(n),!0).forEach((function(t){C.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Se(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Te(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Re=function(e){T.default(n,e);var t=Te(n);function n(e){var r;return O.default(this,n),r=t.call(this),C.default(S.default(r),"newBackoff",null),C.default(S.default(r),"usedBackoff",null),C.default(S.default(r),"retrier",null),r.options=e?Ee({},e):{},r}return _.default(n,[{key:"inProgress",get:function(){return!!this.retrier}},{key:"start",value:function(){if(this.inProgress)throw new Error("Already waiting for next attempt, call finishAttempt(success : boolean) to finish it");this.createRetrier()}},{key:"stop",value:function(){this.cleanRetrier(),this.newBackoff=null,this.usedBackoff=null}},{key:"modifyBackoff",value:function(e){this.newBackoff=e}},{key:"attemptFailed",value:function(){if(!this.inProgress)throw new Error("No attempt is in progress");var e,t;this.newBackoff?!this.usedBackoff||this.usedBackoff<this.newBackoff?this.createRetrier():null===(e=this.retrier)||void 0===e||e.failed(new Error):null===(t=this.retrier)||void 0===t||t.failed(new Error)}},{key:"cancel",value:function(){var e;null===(e=this.retrier)||void 0===e||e.cancel()}},{key:"cleanRetrier",value:function(){var e,t;null===(e=this.retrier)||void 0===e||e.removeAllListeners(),null===(t=this.retrier)||void 0===t||t.cancel(),this.retrier=null}},{key:"getRetryPolicy",value:function(){var e=Ee({},this.options);return this.newBackoff&&(e.min=this.newBackoff,e.max=this.options.max&&this.options.max>this.newBackoff?this.options.max:this.newBackoff),e.maxAttemptsCount=this.options.maxAttemptsCount?this.options.maxAttemptsCount+1:void 0,e}},{key:"createRetrier",value:function(){var e=this;this.cleanRetrier();var t=this.getRetryPolicy();this.retrier=new g.Retrier(t),this.retrier.once("attempt",(function(){var t,n;null===(t=e.retrier)||void 0===t||t.on("attempt",(function(){return e.emit("attempt")})),null===(n=e.retrier)||void 0===n||n.failed(new Error("Skipping first attempt"))})),this.retrier.on("failed",(function(t){return e.emit("failed",t)})),this.usedBackoff=this.newBackoff,this.newBackoff=null,this.retrier.start()}}]),n}(D);function Ie(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Oe=function(e){T.default(i,e);var t,n,r=Ie(i);function i(e,t,n){var a;O.default(this,i),a=r.call(this),C.default(S.default(a),"disconnectingTimer",null),C.default(S.default(a),"disconnectedPromiseResolve",null),C.default(S.default(a),"terminalStates",["disconnected","rejected"]),C.default(S.default(a),"tokenExpiredSasCode",20104),C.default(S.default(a),"terminationReason","Connection is not initialized"),a.websocket=e,a.websocket.on("connected",(function(){return a.fsm.socketConnected()})),a.websocket.on("disconnected",(function(){return a.fsm.socketClosed()})),a.websocket.on("message",(function(e){return a.onIncomingMessage(e)})),a.websocket.on("socketError",(function(e){return a.emit("connectionError",{terminal:!1,message:"Socket error: ".concat(e.message),httpStatusCode:null,errorCode:null})})),a.transport=t,a.config=n,a.retrier=new Re(n.retryPolicy),a.retrier.on("attempt",(function(){return a.retry()})),a.retrier.on("failed",(function(e){Q.warn("Retrying failed: ".concat(e.message)),a.disconnect()})),"undefined"!=typeof window&&void 0!==window.addEventListener&&(window.addEventListener("online",(function(){Q.debug("Browser reported connectivity state: online"),a.resetBackoff(),a.fsm.systemOnline()})),window.addEventListener("offline",(function(){Q.debug("Browser reported connectivity state: offline"),a.websocket.close(),a.fsm.socketClosed()})));var s=M.factory({init:"disconnected",transitions:[{name:"userConnect",from:["disconnected","rejected"],to:"connecting"},{name:"userConnect",from:["connecting","connected"]},{name:"userDisconnect",from:["connecting","initialising","connected","updating","retrying","rejected","waitSocketClosed","waitOffloadSocketClosed"],to:"disconnecting"},{name:"userRetry",from:["retrying"],to:"connecting"},{name:"socketConnected",from:["connecting"],to:"initialising"},{name:"socketClosed",from:["connecting","initialising","connected","updating","error","waitOffloadSocketClosed"],to:"retrying"},{name:"socketClosed",from:["disconnecting"],to:"disconnected"},{name:"socketClosed",from:["waitSocketClosed"],to:"disconnected"},{name:"socketClosed",from:["rejected"],to:"rejected"},{name:"initSuccess",from:["initialising"],to:"connected"},{name:"initError",from:["initialising"],to:"error"},{name:"tokenRejected",from:["initialising","updating"],to:"rejected"},{name:"protocolError",from:["initialising","connected","updating"],to:"error"},{name:"receiveClose",from:["initialising","connected","updating"],to:"waitSocketClosed"},{name:"receiveOffload",from:["initialising","connected","updating"],to:"waitOffloadSocketClosed"},{name:"unsupportedProtocol",from:["initialising","connected","updating"],to:"unsupported"},{name:"receiveFatalClose",from:["initialising","connected","updating"],to:"unsupported"},{name:"userUpdateToken",from:["disconnected","rejected","connecting","retrying"],to:"connecting"},{name:"userUpdateToken",from:["connected"],to:"updating"},{name:"updateSuccess",from:["updating"],to:"connected"},{name:"updateError",from:["updating"],to:"error"},{name:"userSend",from:["connected"],to:"connected"},{name:"systemOnline",from:["retrying"],to:"connecting"}],methods:{onConnecting:function(){a.setupSocket(),a.emit("connecting")},onEnterInitialising:function(){a.sendInit()},onLeaveInitialising:function(){a.cancelInit()},onEnterUpdating:function(){a.sendUpdate()},onLeaveUpdating:function(){a.cancelUpdate()},onEnterRetrying:function(){a.initRetry(),a.emit("connecting")},onEnterConnected:function(){a.resetBackoff(),a.onConnected()},onUserUpdateToken:function(){a.resetBackoff()},onTokenRejected:function(){a.resetBackoff(),a.closeSocket(!0),a.finalizeSocket()},onUserDisconnect:function(){a.closeSocket(!0)},onEnterDisconnecting:function(){a.startDisconnectTimer()},onLeaveDisconnecting:function(){a.cancelDisconnectTimer()},onEnterWaitSocketClosed:function(){a.startDisconnectTimer()},onLeaveWaitSocketClosed:function(){a.cancelDisconnectTimer()},onEnterWaitOffloadSocketClosed:function(){a.startDisconnectTimer()},onLeaveWaitOffloadSocketClosed:function(){a.cancelDisconnectTimer()},onDisconnected:function(){a.resetBackoff(),a.finalizeSocket()},onReceiveClose:function(){a.onCloseReceived()},onReceiveOffload:function(e,t){Q.debug("onreceiveoffload: ",t),a.modifyBackoff(t.body),a.onCloseReceived()},onUnsupported:function(){a.closeSocket(!0),a.finalizeSocket()},onError:function(e,t){a.closeSocket(t),a.finalizeSocket()},onEnterState:function(e){"none"!==e.from&&a.changeState(e)},onInvalidTransition:function(e,t,n){Q.warn("FSM: unexpected transition",t,n)}}});return a.fsm=new s,a}return _.default(i,[{key:"changeState",value:function(e){Q.debug("FSM: ".concat(e.transition,": ").concat(e.from," --\x3e ").concat(e.to)),this.lastEmittedState!==this.state&&(this.lastEmittedState=this.state,this.emit("stateChanged",this.state))}},{key:"resetBackoff",value:function(){Q.trace("resetBackoff"),this.retrier.stop()}},{key:"modifyBackoff",value:function(e){Q.trace("modifyBackoff",e);var t=e?e.backoff_policy:null;t&&"number"==typeof t.reconnect_min_ms&&this.retrier.modifyBackoff(t.reconnect_min_ms)}},{key:"startDisconnectTimer",value:function(){var e=this;Q.trace("startDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null),this.disconnectingTimer=setTimeout((function(){Q.debug("disconnecting is timed out"),e.closeSocket(!0)}),3e3)}},{key:"cancelDisconnectTimer",value:function(){Q.trace("cancelDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null)}},{key:"isConnected",get:function(){return"connected"===this.state&&this.websocket.isConnected}},{key:"state",get:function(){switch(this.fsm.state){case"connecting":case"initialising":case"retrying":case"error":return"connecting";case"updating":case"connected":return"connected";case"rejected":return"denied";case"disconnecting":case"waitSocketClosed":case"waitOffloadSocketClosed":return"disconnecting";case"disconnected":default:return"disconnected"}}},{key:"initRetry",value:function(){Q.debug("initRetry"),this.retrier.inProgress?this.retrier.attemptFailed():this.retrier.start()}},{key:"retry",value:function(){"connecting"!=this.fsm.state?(Q.trace("retry"),this.websocket.close(),this.fsm.userRetry()):Q.trace("can\t retry as already connecting")}},{key:"onConnected",value:function(){this.emit("connected")}},{key:"finalizeSocket",value:function(){Q.trace("finalizeSocket"),this.websocket.close(),this.emit("disconnected"),this.disconnectedPromiseResolve&&(this.disconnectedPromiseResolve(),this.disconnectedPromiseResolve=null)}},{key:"setupSocket",value:function(){Q.trace("setupSocket:",this.config.token),this.emit("beforeConnect"),this.websocket.connect()}},{key:"onIncomingMessage",value:function(e){var t=be.parse(e);if(t){var n=t.method,r=t.header,i=t.payload;if("reply"!==n&&this.confirmReceiving(r),"notification"===n)this.emit("message",r.message_type,i);else if("reply"===r.method)this.transport.processReply({id:r.id,status:r.status,header:r,body:i});else if("client_update"===r.method)"token_about_to_expire"===r.client_update_type&&this.emit("tokenAboutToExpire");else if("close"===r.method)if(308===r.status.code)Q.debug("Connection has been offloaded"),this.fsm.receiveOffload({status:r.status.status,body:i});else if(406===r.status.code){var a="Server closed connection because can't parse protocol: ".concat(JSON.stringify(r.status));this.emitReplyConnectionError(a,r,!0),Q.error(a),this.fsm.receiveFatalClose()}else 417===r.status.code?(Q.error("Server closed connection because can't parse client reply: ".concat(JSON.stringify(r.status))),this.fsm.receiveFatalClose(r.status.status)):410===r.status.code?(Q.warn("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status),this.emit("tokenExpired")):401===r.status.code?(Q.error("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status)):(Q.warn("unexpected message: ",r.status),this.fsm.receiveOffload({status:r.status.status,body:null}))}}},{key:"sendInit",value:(n=x.default(P.default.mark((function e(){var t,n;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("sendInit"),e.prev=1,this.emit("beforeSendInit"),e.next=5,this.transport.sendInit();case 5:t=e.sent,this.config.updateContinuationToken(t.continuationToken),this.config.confirmedCapabilities=t.confirmedCapabilities,this.fsm.initSuccess(t),this.emit("initialized",t),this.emit("tokenUpdated"),e.next=17;break;case 13:e.prev=13,e.t0=e.catch(1),e.t0 instanceof _e?(n=!1,Q.warn("Init rejected by server: ".concat(JSON.stringify(e.t0.reply.status))),this.emit("sendInitFailed"),401===e.t0.reply.status.code||403===e.t0.reply.status.code?(n=!0,this.fsm.tokenRejected(e.t0.reply.status),e.t0.reply.status.errorCode===this.tokenExpiredSasCode&&this.emit("tokenExpired")):429===e.t0.reply.status.code?(this.modifyBackoff(e.t0.reply.body),this.fsm.initError(!0)):500===e.t0.reply.status.code?this.fsm.initError(!1):this.fsm.initError(!0),this.emitReplyConnectionError(e.t0.message,e.t0.reply,n)):(this.terminationReason=e.t0.message,this.emit("connectionError",{terminal:!0,message:"Unknown error during connection initialisation: ".concat(e.t0.message,"\n").concat(JSON.stringify(e.t0,null,2)),httpStatusCode:null,errorCode:null}),this.fsm.initError(!0)),this.emit("tokenUpdated",e.t0);case 17:case"end":return e.stop()}}),e,this,[[1,13]])}))),function(){return n.apply(this,arguments)})},{key:"sendUpdate",value:(t=x.default(P.default.mark((function e(){var t,n,r;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("sendUpdate"),t=new se(this.config.token),e.prev=2,e.next=5,this.transport.sendWithReply(t);case 5:n=e.sent,this.fsm.updateSuccess(n.body),this.emit("tokenUpdated"),e.next=14;break;case 10:e.prev=10,e.t0=e.catch(2),e.t0 instanceof _e?(r=!1,Q.warn("Token update rejected by server: ".concat(JSON.stringify(e.t0.reply.status))),401===e.t0.reply.status.code||403===e.t0.reply.status.code?(r=!0,this.fsm.tokenRejected(e.t0.reply.status),e.t0.reply.status.errorCode===this.tokenExpiredSasCode&&this.emit("tokenExpired")):429===e.t0.reply.status.code?(this.modifyBackoff(e.t0.reply.body),this.fsm.updateError(e.t0.reply.status)):this.fsm.updateError(e.t0.reply.status),this.emitReplyConnectionError(e.t0.message,e.t0.reply,r)):(this.emit("error",!1,e.t0.message,null,null),this.fsm.updateError(e.t0)),this.emit("tokenUpdated",e.t0);case 14:case"end":return e.stop()}}),e,this,[[2,10]])}))),function(){return t.apply(this,arguments)})},{key:"emitReplyConnectionError",value:function(e,t,n){var r=t.status&&t.status.description?t.status.description:e,i=t.status.code,a=t.status&&t.status.errorCode?t.status.errorCode:null;n&&(this.terminationReason=r),this.emit("connectionError",{terminal:n,message:"Connection error: ".concat(r),httpStatusCode:i,errorCode:a})}},{key:"cancelInit",value:function(){Q.trace("cancelInit")}},{key:"cancelUpdate",value:function(){Q.trace("cancelUpdate")}},{key:"confirmReceiving",value:function(e){Q.trace("confirmReceiving");try{this.transport.send(new ce(e.id))}catch(e){Q.debug("failed to confirm packet receiving",e)}}},{key:"closeSocket",value:function(e){var t=this;Q.trace("closeSocket (graceful: ".concat(e,")")),e&&this.transport.isConnected&&this.transport.sendClose(),this.websocket.close(),setTimeout((function(){return t.fsm.socketClosed()}),0)}},{key:"connect",value:function(){Q.trace("connect"),this.fsm.userConnect()}},{key:"disconnect",value:function(){var e=this;return Q.trace("disconnect"),this.fsm.is("disconnected")?Promise.resolve():new Promise((function(t){e.disconnectedPromiseResolve=t,e.fsm.userDisconnect()}))}},{key:"updateToken",value:function(e){var t=this;return Q.trace("updateToken:",e),new Promise((function(e,n){t.once("tokenUpdated",(function(t){t?n(t):e()})),t.fsm.userUpdateToken()}))}},{key:"isTerminalState",get:function(){return-1!==this.terminalStates.indexOf(this.fsm.state)}},{key:"getTerminationReason",get:function(){return this.terminationReason}},{key:"onCloseReceived",value:function(){this.websocket.close()}}]),i}(D),Ce=function(){function e(){O.default(this,e)}return _.default(e,null,[{key:"getMetadata",value:function(e){var t,n,r,i,a,s,o,u,c=e&&e.clientMetadata?e.clientMetadata:{},l={env:null!==(t=N.name)&&void 0!==t?t:"unknown",envv:null!==(n=N.version)&&void 0!==n?n:"unknown",os:null!==(r=null===(i=N.os)||void 0===i?void 0:i.family)&&void 0!==r?r:"unknown",osv:null!==(a=null===(s=N.os)||void 0===s?void 0:s.version)&&void 0!==a?a:"unknown",osa:null!==(o=null===(u=N.os)||void 0===u?void 0:u.architecture)&&void 0!==o?o:"unknown",sdk:"js-default"},f={};return["ver","env","envv","os","osv","osa","type","sdk","sdkv","dev","devv","devt","app","appv"].filter((function(e){return e in c||e in l})).forEach((function(e){return f[e]=e in c?c[e]:l[e]})),f}}]),e}();var Pe=function(){function e(t,n){var r=this;O.default(this,e),this.config=n,this.activeRequests=new Map,this.channel=t,this.channel.on("reply",(function(e){return r.processReply(e)})),this.channel.on("disconnected",(function(){r.activeRequests.forEach((function(e){clearTimeout(e.timeout),e.reject(new we("disconnected"))})),r.activeRequests.clear()}))}var t;return _.default(e,[{key:"isConnected",get:function(){return this.channel.isConnected}},{key:"processReply",value:function(e){var t,n=this.activeRequests.get(e.id);n&&(clearTimeout(n.timeout),this.activeRequests.delete(e.id),(t=e.status.code)>=200&&t<300?n.resolve(e):(n.reject(new _e("Transport failure: "+e.status.status,e)),Q.trace("message rejected")))}},{key:"storeRequest",value:function(e,t,n){var r={resolve:t,reject:n,timeout:setTimeout((function(){Q.trace("request",e,"is timed out"),n(new we("Twilsock: request timeout: "+e))}),3e4)};this.activeRequests.set(e,r)}},{key:"shutdown",value:function(){this.activeRequests.forEach((function(e){clearTimeout(e.timeout),e.reject(new we("Twilsock: request cancelled by user"))})),this.activeRequests.clear()}},{key:"sendInit",value:(t=x.default(P.default.mark((function e(){var t,n,r;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("sendInit"),t=Ce.getMetadata(this.config),n=new ne(this.config.token,this.config.continuationToken,t,this.config.initRegistrations,this.config.tweaks),e.next=5,this.sendWithReply(n);case 5:return r=e.sent,e.abrupt("return",new ie(r.id,r.header.continuation_token,new Set(r.header.capabilities),r.header.continuation_token_status,r.header.offline_storage,r.header.init_registrations,r.header.debug_info));case 7:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"sendClose",value:function(){var e=new fe;this.send(e)}},{key:"sendWithReply",value:function(e,t){var n=this;return new Promise((function(r,i){var a=n.send(e,t);n.storeRequest(a,r,i)}))}},{key:"send",value:function(e,t){e.id=e.id||"TM".concat(y.v4());var n=be.createPacket(e,function(e){switch(A.default(e)){case"undefined":return"";case"object":return JSON.stringify(e);default:return e}}(t));try{return this.channel.send(n),e.id}catch(t){throw Q.debug("failed to send ",e,t),Q.trace(t.stack),t}}}]),e}();function Ae(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var je=function(e){T.default(r,e);var n=Ae(r);function r(e){var i;return O.default(this,r),i=n.call(this),C.default(S.default(i),"socket",null),i.url=e,i.url=e,i.WebSocket=t.WebSocket||t.MozWebSocket||{},i}return _.default(r,[{key:"isConnected",get:function(){return!!this.socket&&1===this.socket.readyState}},{key:"connect",value:function(){var e,t=this;Q.trace("connecting to socket");try{e=new this.WebSocket(this.url)}catch(e){return Q.debug("Socket error: ".concat(this.url)),void this.emit("socketError",e)}e.binaryType="arraybuffer",e.onopen=function(){Q.debug("socket opened ".concat(t.url)),t.emit("connected")},e.onclose=function(e){Q.debug("socket closed",e),t.emit("disconnected",e)},e.onerror=function(e){Q.debug("Socket error:",e),t.emit("socketError",e)},e.onmessage=function(e){t.emit("message",e.data)},this.socket=e}},{key:"send",value:function(e){return this.socket&&this.socket.send(e)}},{key:"close",value:function(){if(Q.trace("closing socket"),this.socket){this.socket.onopen=null,this.socket.onclose=null,this.socket.onerror=null,this.socket.onmessage=null;try{this.socket.close()}finally{}}}}]),r}(D);function Me(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Le=function(e){T.default(u,e);var t,n,r,i,a,s,o=Me(u);function u(e){var t;return O.default(this,u),(t=o.call(this)).transport=e,t.registrations=new Map,t.registrationsInProgress=new Map,t}return _.default(u,[{key:"putNotificationContext",value:(s=x.default(P.default.mark((function e(t,n){var r;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={method:"put_notification_ctx",notification_ctx_id:t},e.next=3,this.transport.sendWithReply(r,n);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return s.apply(this,arguments)})},{key:"deleteNotificationContext",value:(a=x.default(P.default.mark((function e(t){var n;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={method:"delete_notification_ctx",notification_ctx_id:t},e.next=3,this.transport.sendWithReply(n);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"updateRegistration",value:(i=x.default(P.default.mark((function e(t,n){var r,i;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.debug("update registration for context",t),(r=this.registrationsInProgress.get(t))||(r=new Set,this.registrationsInProgress.set(t,r)),i=y.v4(),r.add(i),e.prev=5,e.next=8,this.putNotificationContext(t,n);case 8:Q.debug("registration attempt succeeded for context",n),r.delete(i),0===r.size&&(this.registrationsInProgress.delete(t),this.emit("registered",t)),e.next=19;break;case 13:e.prev=13,e.t0=e.catch(5),Q.warn("registration attempt failed for context",n),Q.debug(e.t0),r.delete(i),0===r.size&&(this.registrationsInProgress.delete(t),this.emit("registrationFailed",t,e.t0));case 19:case"end":return e.stop()}}),e,this,[[5,13]])}))),function(e,t){return i.apply(this,arguments)})},{key:"updateRegistrations",value:(r=x.default(P.default.mark((function e(){var t,n=this;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Q.trace("refreshing ".concat(this.registrations.size," registrations")),t=[],this.registrations.forEach((function(e,r){t.push(n.updateRegistration(r,e))})),e.next=5,Promise.all(t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"setNotificationsContext",value:(n=x.default(P.default.mark((function e(t,n){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t&&n){e.next=2;break}throw new we("Invalid arguments provided");case 2:return this.registrations.set(t,n),e.next=5,this.updateRegistration(t,n);case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeNotificationsContext",value:(t=x.default(P.default.mark((function e(t){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.registrations.has(t)){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.deleteNotificationContext(t);case 4:this.transport.isConnected&&this.registrations.delete(t);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),u}(D);function Ne(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Ue=function(e){T.default(n,e);var t=Ne(n);function n(e,r,i){var a;return O.default(this,n),(a=t.call(this,r)).status=e,a.description=r,a.body=i,a}return n}(we);function De(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Fe=function(e){T.default(n,e);var t=De(n);function n(e){return O.default(this,n),t.call(this,e)}return n}(we);function Be(e,t){var n=function(e){var t=e.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)(\/[^?#]*)(\?[^#]*|)(#.*|)$/);if(t){var n={protocol:t[1],host:t[2],hostname:t[3],port:t[4],pathname:t[5],search:t[6],hash:t[7],params:{}};if(n.search.length>0){var r=n.search.substring(1);n.params=r.split("&").map((function(e){return e.split("=")})).reduce((function(e,t){return e.hasOwnProperty(t[0])?Array.isArray(e[t[0]])?e[t[0]].push(t[1]):e[t[0]]=[e[t[0]],t[1]]:e[t[0]]=t[1],e}),{})}return n}throw new we("Incorrect URI: "+e)}(t),r={method:e,host:n.host,path:n.pathname};return n.params&&(r.params=n.params),r}function qe(e,t,n,r,i){return{to:Be(e,t),headers:n,body:r,grant:i}}var ze=function(){function e(t,n,r){O.default(this,e),this.config=r,this.transport=t,this.pendingMessages=[],this.twilsock=n}var t;return _.default(e,[{key:"saveMessage",value:function(e){var t=this;return new Promise((function(n,r){var i={message:e,resolve:n,reject:r,alreadyRejected:!1,timeout:setTimeout((function(){Q.debug("request is timed out"),r(new we("request '".concat(e.to.method,"' to '").concat(e.to.host,"' timed out"))),i.alreadyRejected=!0}),2e4)};t.pendingMessages.push(i)}))}},{key:"sendPendingMessages",value:function(){for(var e=this,t=function(){var t=e.pendingMessages[0];if(!t.alreadyRejected)try{var n=t.message;e.actualSend(n).then((function(e){return t.resolve(e)})).catch((function(e){return t.reject(e)})),clearTimeout(t.timeout)}catch(e){return Q.debug("Failed to send pending message",e),"break"}e.pendingMessages.splice(0,1)};this.pendingMessages.length>0;){if("break"===t())break}}},{key:"rejectPendingMessages",value:function(){var e=this;this.pendingMessages.forEach((function(t){t.reject(new Fe("Unable to connect: "+e.twilsock.getTerminationReason)),t.alreadyRejected=!0,clearTimeout(t.timeout)})),this.pendingMessages.splice(0,this.pendingMessages.length)}},{key:"actualSend",value:(t=x.default(P.default.mark((function e(t){var n,r,i,a,s,o,u,c;return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.to,i=t.headers,a=t.body,s=null!==(n=t.grant)&&void 0!==n?n:this.config.activeGrant,o={host:r.host,path:r.path,method:r.method,params:r.params,headers:i},u=new Message(s,i["Content-Type"]||"application/json",o),Q.trace("Sending upstream message",u),e.next=9,this.transport.sendWithReply(u,a);case 9:if(c=e.sent,Q.trace("Received upstream message response",c),!((f=c)&&f.header&&f.header.http_status)||(l=c.header.http_status.code)>=200&&l<300){e.next=13;break}throw new Ue(c.header.http_status.code,c.header.http_status.status,c.body);case 13:return e.abrupt("return",{status:c.header.http_status,headers:c.header.http_headers,body:c.body});case 14:case"end":return e.stop()}var l,f}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"send",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;if(this.twilsock.isTerminalState)return Promise.reject(new Fe("Unable to connect: "+this.twilsock.getTerminationReason));var a=qe(e,t,n,r,i);return this.twilsock.isConnected?this.actualSend(a):this.saveMessage(a)}}]),e}(),We=function(){function e(){var t=this;O.default(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return _.default(e,[{key:"promise",get:function(){return this._promise}},{key:"update",value:function(e){this._resolve(e)}},{key:"set",value:function(e){this._resolve(e)}},{key:"fail",value:function(e){this._reject(e)}}]),e}(),Ge=function(){function e(t){O.default(this,e),this.id=t}return _.default(e,null,[{key:"create",value:function(t){if(t instanceof Object&&"storage_id"in t)return new e(t.storage_id);throw new we('Field "storage_id" is missing')}}]),e}(),$e=function(){function e(){return O.default(this,e),C.default(this,"initializedFlag","twilio_twilsock_token_storage"),C.default(this,"tokenStoragePrefix","twilio_continuation_token_"),e._instance||(this.initialize(),e._instance=this),e._instance}return _.default(e,[{key:"sessionStorage",value:function(){try{return t.sessionStorage}catch(e){return null}}},{key:"window",value:function(){try{return t.window}catch(e){return null}}},{key:"storeToken",value:function(e,t){this.canStore()&&this.sessionStorage.setItem(this.getKeyName(t),e)}},{key:"getStoredToken",value:function(e){return this.canStore()?this.sessionStorage.getItem(this.getKeyName(e)):null}},{key:"initialize",value:function(){var e=this;if(this.canStore()){this.sessionStorage.getItem(this.initializedFlag)&&this.clear(),this.sessionStorage.setItem(this.initializedFlag,"true");var t=this.sessionStorage.removeItem;this.window.addEventListener("unload",(function(){t(e.initializedFlag)}))}}},{key:"clear",value:function(){if(this.canStore()){for(var e=[],t=0;t<this.sessionStorage.length;t++){var n=this.sessionStorage.key(t);n&&0===n.indexOf(this.tokenStoragePrefix)&&e.push(n)}var r=this.sessionStorage.removeItem;e.forEach((function(e){return r(e)})),r(this.initializedFlag)}}},{key:"getKeyName",value:function(e){return"".concat(this.tokenStoragePrefix).concat(e)}},{key:"canStore",value:function(){return!!(this.sessionStorage&&this.sessionStorage.length&&this.window)}}]),e}();C.default($e,"_instance",null);var Ve,Je,Ke=new $e,He=function(){function e(t,n,r,i,a,s){O.default(this,e),this.title=t,this.details=n,this.start=r,this.type=a,this.id=s,this.end=i}return _.default(e,[{key:"toTelemetryEvent",value:function(){var e=new Date,t=this.start,n=this.end?this.end:e;if(n<t){var r=n;n=t,t=r}var i=t.getTime()-e.getTime(),a=n.getTime()-e.getTime();return new pe(i,a,this.title,this.details,this.id,this.type)}}]),e}();e.TelemetryPoint=void 0,(Ve=e.TelemetryPoint||(e.TelemetryPoint={}))[Ve.Start=0]="Start",Ve[Ve.End=1]="End",e.EventSendingLimitation=void 0,(Je=e.EventSendingLimitation||(e.EventSendingLimitation={}))[Je.MinEventsPortion=0]="MinEventsPortion",Je[Je.AnyEvents=1]="AnyEvents",Je[Je.AnyEventsIncludingUnfinished=2]="AnyEventsIncludingUnfinished";var Ye=function(){function t(e,n){O.default(this,t),C.default(this,"minEventsPortionToSend",50),C.default(this,"maxEventsPortionToSend",100),C.default(this,"pendingEvents",new Map),C.default(this,"readyEvents",[]),C.default(this,"hasInitializationFinished",!1),C.default(this,"_canSendTelemetry",!1),this.config=e,this.packetInterface=n}return _.default(t,[{key:"isTelemetryEnabled",get:function(){return this.config.confirmedCapabilities.has("telemetry.v1")}},{key:"canSendTelemetry",get:function(){return this._canSendTelemetry&&this.isTelemetryEnabled},set:function(t){Q.debug("TelemetryTracker.canSendTelemetry: ".concat(t," TelemetryTracker.isTelemetryEnabled: ").concat(this.isTelemetryEnabled)),this._canSendTelemetry&&!t&&(this.pendingEvents.clear(),this.readyEvents=[]),this._canSendTelemetry=t,t&&this.sendTelemetry(e.EventSendingLimitation.AnyEvents),t&&!this.hasInitializationFinished&&(this.hasInitializationFinished=!0)}},{key:"addTelemetryEvent",value:function(e){!this.canSendTelemetry&&this.hasInitializationFinished||this.readyEvents.push(e)}},{key:"addPartialEvent",value:function(t,n,r){Q.debug("Adding ".concat(r===e.TelemetryPoint.Start?"starting":"ending"," timepoint for '").concat(n,"' event"));var i=this.pendingEvents.has(n);if(r===e.TelemetryPoint.Start)i&&Q.debug("Overwriting starting point for '".concat(n,"' event")),this.pendingEvents.set(n,t);else{if(!i)return void Q.info("Could not find started event for '".concat(n,"' event"));this.addTelemetryEvent(this.merge(this.pendingEvents.get(n),t)),this.pendingEvents.delete(n)}}},{key:"getTelemetryToSend",value:function(t){return this.canSendTelemetry&&0!=this.readyEvents.length?t==e.EventSendingLimitation.MinEventsPortion&&this.readyEvents.length<this.minEventsPortionToSend?[]:this.getTelemetryPortion(t==e.EventSendingLimitation.AnyEventsIncludingUnfinished):[]}},{key:"getTelemetryPortion",value:function(e){var t=this,n=Math.min(this.readyEvents.length,this.maxEventsPortionToSend),r=this.readyEvents.splice(0,n);return e&&r.length<this.maxEventsPortionToSend&&this.pendingEvents.forEach((function(e,n){if(!(r.length>=t.maxEventsPortionToSend)){var i=t.pendingEvents.get(n);t.pendingEvents.delete(n),r.push(new He("[UNFINISHED] ".concat(i.title),i.details,i.start,null,i.type,i.id))}})),r}},{key:"merge",value:function(e,t){return new He(t.title?t.title:e.title,t.details?t.details:e.details,e.start,t.end,t.type?t.type:e.type,t.id?t.id:e.id)}},{key:"sendTelemetryIfMinimalPortionCollected",value:function(){this.sendTelemetry(e.EventSendingLimitation.MinEventsPortion)}},{key:"sendTelemetry",value:function(e){var t=this.getTelemetryToSend(e);if(0!==t.length)try{this.packetInterface.send(new he(t.map((function(e){return e.toTelemetryEvent()}))))}catch(e){Q.debug("Error while sending ".concat(t.length," telemetry events due to ").concat(e,"; they will be resubmitted")),this.readyEvents=this.readyEvents.concat(t)}}}]),t}();function Qe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=I.default(e);if(t){var i=I.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return R.default(this,n)}}var Xe=function e(){O.default(this,e)};C.default(Xe,"TWILSOCK_CONNECT","twilsock.sdk.connect"),C.default(Xe,"TWILSOCK_INIT","twilsock.sdk.init"),e.TwilsockClient=function(t){T.default(f,t);var n,r,i,a,s,o,u,c,l=Qe(f);function f(t,n,r){var i;O.default(this,f),i=l.call(this),C.default(S.default(i),"version",X),C.default(S.default(i),"offlineStorageDeferred",new We),r.continuationToken=r.continuationToken?r.continuationToken:Ke.getStoredToken(n);var a=i.config=new Z(t,n,r);Q.setLevel(a.logLevel);var s=new je(a.url),o=new Pe(s,a);return i.channel=new Oe(s,o,a),i.registrations=new Le(o),i.upstream=new ze(o,i.channel,a),i.telemetryTracker=new Ye(a,o),i.channel.on("initialized",(function(){return i.telemetryTracker.canSendTelemetry=!0})),s.on("disconnected",(function(){return i.telemetryTracker.canSendTelemetry=!1})),i.registrations.on("registered",(function(e){return i.emit("registered",e)})),i.channel.on("message",(function(e,t){return setTimeout((function(){return i.emit("message",e,t)}),0)})),i.channel.on("stateChanged",(function(e){return setTimeout((function(){return i.emit("stateChanged",e)}),0)})),i.channel.on("connectionError",(function(e){return setTimeout((function(){return i.emit("connectionError",e)}),0)})),i.channel.on("tokenAboutToExpire",(function(){return setTimeout((function(){return i.emit("tokenAboutToExpire")}),0)})),i.channel.on("tokenExpired",(function(){return setTimeout((function(){return i.emit("tokenExpired")}),0)})),i.channel.on("connected",(function(){return i.registrations.updateRegistrations()})),i.channel.on("connected",(function(){return i.upstream.sendPendingMessages()})),i.channel.on("connected",(function(){return setTimeout((function(){return i.emit("connected")}),0)})),i.channel.on("beforeConnect",(function(){return i.telemetryTracker.addPartialEvent(new He("Establish WebSocket connection","",new Date),Xe.TWILSOCK_CONNECT,e.TelemetryPoint.Start)})),i.channel.on("connected",(function(){return i.telemetryTracker.addPartialEvent(new He("Establish WebSocket connection","",new Date,new Date),Xe.TWILSOCK_CONNECT,e.TelemetryPoint.End)})),i.channel.on("beforeSendInit",(function(){return i.telemetryTracker.addPartialEvent(new He("Send Twilsock init","",new Date),Xe.TWILSOCK_INIT,e.TelemetryPoint.Start)})),i.channel.on("initialized",(function(){return i.telemetryTracker.addPartialEvent(new He("Send Twilsock init","Succeeded",new Date,new Date),Xe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("sendInitFailed",(function(){return i.telemetryTracker.addPartialEvent(new He("Send Twilsock init","Failed",new Date,new Date),Xe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("initialized",(function(e){i.handleStorageId(n,e),Ke.storeToken(e.continuationToken,n),setTimeout((function(){return i.emit("initialized",e)}),0)})),i.channel.on("disconnected",(function(){return setTimeout((function(){return i.emit("disconnected")}),0)})),i.channel.on("disconnected",(function(){return i.upstream.rejectPendingMessages()})),i.channel.on("disconnected",(function(){return i.offlineStorageDeferred.fail(new we("Client disconnected"))})),i.offlineStorageDeferred.promise.catch((function(){})),i}return _.default(f,[{key:"emit",value:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return Q.debug("Emitting ".concat(e.toString(),"(").concat(r.map((function(e){return JSON.stringify(e)})).join(", "),")")),(t=E.default(I.default(f.prototype),"emit",this)).call.apply(t,[this,e].concat(r))}},{key:"handleStorageId",value:function(e,t){if(t.offlineStorage)if(t.offlineStorage.hasOwnProperty(e))try{this.offlineStorageDeferred.set(Ge.create(t.offlineStorage[e])),Q.debug("Offline storage for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage[e]),"."))}catch(n){this.offlineStorageDeferred.fail(new we("Failed to parse offline storage for ".concat(e," ").concat(JSON.stringify(t.offlineStorage[e]),". ").concat(n,".")))}else this.offlineStorageDeferred.fail(new we("No offline storage id for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage))));else this.offlineStorageDeferred.fail(new we("No offline storage id"))}},{key:"storageId",value:function(){return this.offlineStorageDeferred.promise}},{key:"isConnected",get:function(){return this.channel.isConnected}},{key:"state",get:function(){return this.channel.state}},{key:"updateToken",value:(c=x.default(P.default.mark((function e(t){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Q.trace("updating token '".concat(t,"'")),this.config.token!==t){e.next=3;break}return e.abrupt("return");case 3:return this.config.updateToken(t),e.next=6,this.channel.updateToken(t);case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"setNotificationsContext",value:(u=x.default(P.default.mark((function e(t,n){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.registrations.setNotificationsContext(t,n);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"removeNotificationsContext",value:(o=x.default(P.default.mark((function e(t){return P.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.registrations.removeNotificationsContext(t);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"connect",value:function(){return this.channel.connect()}},{key:"disconnect",value:(s=x.default(P.default.mark((function t(){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEventsIncludingUnfinished),t.next=3,this.channel.disconnect();case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(){return s.apply(this,arguments)})},{key:"get",value:(a=x.default(P.default.mark((function t(n,r,i){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("GET",n,r,void 0,i);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n){return a.apply(this,arguments)})},{key:"post",value:(i=x.default(P.default.mark((function t(n,r,i,a){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("POST",n,r,i,a);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n,r){return i.apply(this,arguments)})},{key:"put",value:(r=x.default(P.default.mark((function t(n,r,i,a){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("PUT",n,r,i,a);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"delete",value:(n=x.default(P.default.mark((function t(n,r,i,a){return P.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.telemetryTracker.sendTelemetry(e.EventSendingLimitation.AnyEvents),t.next=3,this.upstream.send("DELETE",n,r,i,a);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,r,i){return n.apply(this,arguments)})},{key:"addTelemetryEvent",value:function(e){this.telemetryTracker.addTelemetryEvent(e),this.telemetryTracker.sendTelemetryIfMinimalPortionCollected()}},{key:"addPartialTelemetryEvent",value:function(t,n,r){this.telemetryTracker.addPartialEvent(t,n,r),r===e.TelemetryPoint.End&&this.telemetryTracker.sendTelemetryIfMinimalPortionCollected()}}]),f}(D),e.TwilsockClient=function(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":A.default(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}([p.validateConstructorTypes(p.nonEmptyString,p.nonEmptyString,[p.pureObject,"undefined",p.literal(null)]),function(e,t){if("object"===("undefined"==typeof Reflect?"undefined":A.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[String,String,Object])],e.TwilsockClient);var Ze=function(){function e(t){O.default(this,e),this.product=t,this.type="ers",this.notification_protocol_version=0,this.message_types=[]}return _.default(e,[{key:"populateInitRegistrations",value:function(e){var t=new Set(this.message_types);for(var n in e)t.add(e[n]);this.message_types=Array.from(t)}}]),e}();e.InitRegistration=Ze,e.TelemetryEventDescription=He,e.TelemetryTracker=Ye,e.TransportUnavailableError=Fe,e.Twilsock=e.TwilsockClient,e.TwilsockError=we}(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=Xf.exports,y=tb,m=ih;function g(e){return e&&"object"===Ca(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),O=g(f),C=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),O.default(I.default(t),"desiredState",new X),O.default(I.default(t),"currentState",new X),O.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=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"),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),O.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"),O.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,OE=bg,CE=CS.exports,PE=Xf.exports,AE=qh.exports,jE=Mm,ME=tb,LE=ry.exports,NE=MS.exports;function UE(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function DE(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 FE=UE(gE),BE=UE(bE),qE=UE(kE),zE=UE(wE),WE=UE(xE),GE=UE(_E),$E=UE(SE),VE=UE(EE),JE=UE(TE),KE=UE(RE),HE=UE(CE),YE=DE(PE),QE=UE(AE),XE=DE(ME),ZE=UE(LE),eT=DE(NE);function tT(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":KE.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 nT(e,t){if("object"===("undefined"==typeof Reflect?"undefined":KE.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function rT(){}function iT(){iT.init.call(this)}function aT(e){return void 0===e._maxListeners?iT.defaultMaxListeners:e._maxListeners}function sT(e,t,n){if(t)e.call(n);else for(var r=e.length,i=hT(e,r),a=0;a<r;++a)i[a].call(n)}function oT(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=hT(e,i),s=0;s<i;++s)a[s].call(n,r)}function uT(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,s=hT(e,a),o=0;o<a;++o)s[o].call(n,r,i)}function cT(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var s=e.length,o=hT(e,s),u=0;u<s;++u)o[u].call(n,r,i,a)}function lT(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=hT(e,i),s=0;s<i;++s)a[s].apply(n,r)}function fT(e,t,n,r){var i,a,s,o;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),s=a[t]):(a=e._events=new rT,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=aT(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 dT(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 pT(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 hT(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}rT.prototype=Object.create(null),iT.EventEmitter=iT,iT.usingDomains=!1,iT.prototype.domain=void 0,iT.prototype._events=void 0,iT.prototype._maxListeners=void 0,iT.defaultMaxListeners=10,iT.init=function(){this.domain=null,iT.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new rT,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},iT.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},iT.prototype.getMaxListeners=function(){return aT(this)},iT.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:sT(n,l,this);break;case 2:oT(n,l,this,arguments[1]);break;case 3:uT(n,l,this,arguments[1],arguments[2]);break;case 4:cT(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];lT(n,l,this,i)}return!0},iT.prototype.addListener=function(e,t){return fT(this,e,t,!1)},iT.prototype.on=iT.prototype.addListener,iT.prototype.prependListener=function(e,t){return fT(this,e,t,!0)},iT.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,dT(this,e,t)),this},iT.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,dT(this,e,t)),this},iT.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 rT:(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 rT,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},iT.prototype.off=function(e,t){return this.removeListener(e,t)},iT.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new rT,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new rT: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 rT,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},iT.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):[]},iT.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):pT.call(e,t)},iT.prototype.listenerCount=pT,iT.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var vT=function(){function e(t){BE.default(this,e),this.base=t,this.args=new Array,this.paths=new Array}return qE.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 yT(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 GE.default(this,n)}}var mT=function(e){WE.default(n,e);var t=yT(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 BE.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}(HE.default(Error)),gT=function(e){WE.default(n,e);var t=yT(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 BE.default(this,n),(r=t.call(this,e,i,a)).body=s,r}return n}(mT);function bT(e){return JSON.parse(JSON.stringify(e))}function kT(e){if(!(void 0===e||wT(e)))throw new mT("Invalid pageSize parameter. Expected a positive integer, was '".concat(e,"'."),400,20007)}function wT(e){return function(e){return!isNaN(parseInt(e))&&isFinite(e)}(e)&&e>0}var xT=YE.getLogger("twilio-sync");function _T(e,t){return["".concat((new Date).toISOString()," Sync ").concat(e,":")].concat(Array.from(t))}var ST=function(e){xT.setLevel(e)},ET=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];xT.trace.apply(null,_T("T",t))},TT=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];xT.debug.apply(null,_T("D",t))},RT=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];xT.warn.apply(null,_T("W",t))},IT=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];xT.error.apply(null,_T("E",t))},OT="/v4/Subscriptions",CT="/v3/Maps",PT="/v3/Lists",AT="/v3/Documents",jT="/v3/Streams",MT="/v3/Insights";function LT(e,t,n){return e&&void 0!==e[t]?e[t]:n}var NT=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};BE.default(this,e);var n=t.region||"us1",r="https://cds.".concat(n,".twilio.com"),i=t.cdsUri||r;this.settings={subscriptionsUri:i+OT,documentsUri:i+AT,listsUri:i+PT,mapsUri:i+CT,streamsUri:i+jT,insightsUri:i+MT,sessionStorageEnabled:LT(t.Sync,"enableSessionStorage",!0),productId:t.productId}}return qE.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 UT(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 DT(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 DT(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 DT(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 FT=function(){function e(t){BE.default(this,e),this.localObject=t,this.pendingCorrelationId=null,this.pendingAction=null,this.established=!1,this.retryCount=0}return qE.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 mT("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}(),BT=function(){function e(t){var n=this;BE.default(this,e),VE.default(this,"isConnected",!1),VE.default(this,"maxBatchSize",100),VE.default(this,"subscriptionTtlTimer",null),VE.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(),TT("All subscriptions resolved."))}))}var t;return qE.default(e,[{key:"getSubscriptionUpdateBatch",value:function(){function e(e,t,n,r){var i,a=[],s=UT(e);try{for(s.s();!(i=s.n()).done;){var o=QE.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=FE.default(JE.default.mark((function e(t,n){var r,i,a,s,o,u,c,l,f,d,p,h,v=this;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isConnected){e.next=4;break}return TT("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=UT(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):IT("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=UT(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 OE.TransportUnavailableError?(TT("Twilsock connection (required for subscription) not ready (c:".concat(r,"); waiting…")),this.backoff.reset()):(TT("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;TT("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){TT("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 FT(t)),this.persist())}},{key:"remove",value:function(e){TT("Establishing intent to unsubscribe from ".concat(e)),this.subscriptions.delete(e)&&this.persist()}},{key:"acceptMessage",value:function(e,t){ET("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=UT(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:TT("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?(TT("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&&(TT("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()):TT("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)):TT("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&&(IT("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)):TT("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){TT("Triggering event replay for all subscriptions, reason=".concat(e)),this.pendingPokeReason=e,this.subscriptionTtlTimer&&(clearTimeout(this.subscriptionTtlTimer),this.subscriptionTtlTimer=null);var t,n=[],r=UT(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 qT(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 zT(e){return e.body?e.body.code:0}function WT(e){return 409===e.status?new gT(qT(e),e.status,zT(e),e.body):e.status?new mT(qT(e),e.status,zT(e)):e instanceof OE.TransportUnavailableError?e:new mT(e.message,0,0)}var GT=function(){function e(t,n,r){BE.default(this,e),this.clientInfo=t,this.config=n,this.transport=r}return qE.default(e,[{key:"createHeaders",value:function(){return{"Content-Type":"application/json","Twilio-Sync-Client-Info":JSON.stringify(this.clientInfo),"Twilio-Request-Id":"RQ"+XE.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(WT(e),isNaN(t)?null:1e3*t)}else"Twilsock disconnected"===e.message?s.failed(WT(e)):(s.removeAllListeners(),s.cancel(),i(WT(e)))}))})),s.on("succeeded",(function(e){r(e)})),s.on("cancelled",(function(e){return i(WT(e))})),s.on("failed",(function(e){return i(WT(e))})),s.start()}))}},{key:"get",value:function(e){var t=this,n=this.createHeaders();return TT("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),TT("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),TT("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 TT("DELETE",e,"ID:",n["Twilio-Request-Id"]),this.executeWithRetry((function(){return t.transport.delete(e,n,t.config.productId)}),!1)}}]),e}(),$T=function(){function e(t,n){BE.default(this,e),this.config=t,this.storageId=null;try{this.storage=n||sessionStorage}catch(e){}}return qE.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 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){BE.default(this,e),this.services=t,this.removalHandler=n,this.subscriptionState="none",this._attachedListeners=new Map}return qE.default(e,[{key:"_advanceLastEventId",value:function(e,t){}},{key:"reportFailure",value:function(e){404===e.status?this.onRemoved(!1):this.broadcastEventToListeners("failure",e)}},{key:"_subscribe",value:function(){this.services.router._subscribe(this.sid,this)}},{key:"_unsubscribe",value:function(){this.services.router._unsubscribe(this.sid)}},{key:"_setSubscriptionState",value:function(e){this.subscriptionState=e,this.broadcastEventToListeners("_subscriptionStateChanged",e)}},{key:"close",value:function(){this._unsubscribe(),null!=this.removalHandler&&this.removalHandler(this.type,this.sid,this.uniqueName)}},{key:"attach",value:function(e){var t=e.listenerUuid;this._attachedListeners.get(t)||(this._attachedListeners.size||this._subscribe(),this._attachedListeners.set(t,e))}},{key:"detach",value:function(e){this._attachedListeners.delete(e),this._attachedListeners.size||this.close()}},{key:"broadcastEventToListeners",value:function(e,t){var n,r=VT(this._attachedListeners.values());try{for(r.s();!(n=r.n()).done;){n.value.emit(e,t)}}catch(e){r.e(e)}finally{r.f()}}}]),e}(),HT=function(){function e(t){BE.default(this,e),VE.default(this,"queuedRequests",[]),VE.default(this,"isRequestInFlight",!1),this.inputMergingFunction=t}return qE.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}(),YT=function(){function e(t){BE.default(this,e),VE.default(this,"queueByNamespaceKey",new Map),this.inputReducer=t}var t,n,r;return qE.default(e,[{key:"add",value:(r=FE.default(JE.default.mark((function e(t,n,r){return JE.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=FE.default(JE.default.mark((function e(t,n,r){return JE.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=FE.default(JE.default.mark((function e(t,n){var r,i;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.queueByNamespaceKey.has(t)||this.queueByNamespaceKey.set(t,new HT(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 QT(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=$E.default(e);if(t){var i=$E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return GE.default(this,n)}}var XT=function(e){WE.default(n,e);var t=QT(n);function n(){var e;return BE.default(this,n),(e=t.call(this)).closed=!1,e.uuid=ME.v4(),e}return qE.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}(iT);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=$E.default(e);if(t){var i=$E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return GE.default(this,n)}}var eR=function(e){WE.default(f,e);var t,n,r,i,a,s,o,u,c,l=ZT(f);function f(e,t,n){var r;BE.default(this,f),r=l.call(this,e,n),VE.default(zE.default(r),"isDeleted",!1);return r.updateMergingQueue=new HT((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 qE.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){ET("Document update skipped, current:",this.lastEventId,", remote:",e.id);break}var t=void 0!==this.descriptor.data?bT(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=FE.default(JE.default.mark((function e(t,n){var r,i=this;return JE.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=FE.default(JE.default.mark((function e(t,n){var r,i=this;return JE.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=FE.default(JE.default.mark((function e(t,n){return JE.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=FE.default(JE.default.mark((function e(t){var n;return JE.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=FE.default(JE.default.mark((function e(t,n){var r;return JE.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=FE.default(JE.default.mark((function e(t,n){var r,i,a;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=t(bT(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?bT(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=FE.default(JE.default.mark((function e(t){var n,r,i;return JE.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 mT("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=FE.default(JE.default.mark((function e(){var t=this;return JE.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):IT("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?bT(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=FE.default(JE.default.mark((function e(){return JE.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 mT("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}(KT),tR=function(e){WE.default(o,e);var t,n,r,i,a,s=ZT(o);function o(e){var t;return BE.default(this,o),(t=s.call(this)).syncDocumentImpl=e,t.syncDocumentImpl.attach(zE.default(t)),t}return qE.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 eR.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=FE.default(JE.default.mark((function e(t,n){return JE.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=FE.default(JE.default.mark((function e(t,n){return JE.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=FE.default(JE.default.mark((function e(t,n){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(){return JE.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(){ZE.default($E.default(o.prototype),"close",this).call(this),this.syncDocumentImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return eR.type}}]),o}(XT);VE.default(tR,"removed","removed"),VE.default(tR,"updated","updated"),tT([IE.validateTypesAsync(IE.pureObject,["undefined",IE.objectSchema("document metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[Object,Object]),nT("design:returntype",Promise)],tR.prototype,"set",null),tT([IE.validateTypesAsync("function",["undefined",IE.objectSchema("document metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[Function,Object]),nT("design:returntype",Promise)],tR.prototype,"mutate",null),tT([IE.validateTypesAsync(IE.pureObject,["undefined",IE.objectSchema("document metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[Object,Object]),nT("design:returntype",Promise)],tR.prototype,"update",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger),nT("design:type",Function),nT("design:paramtypes",[Number]),nT("design:returntype",Promise)],tR.prototype,"setTtl",null);var nR=function(){function e(t){BE.default(this,e),this.descriptor=t}return qE.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){BE.default(this,Paginator),this.prevToken=n,this.nextToken=r,this.items=e,this.source=t}var e,t;return qE.default(Paginator,[{key:"hasNextPage",get:function(){return!!this.nextToken}},{key:"hasPrevPage",get:function(){return!!this.prevToken}},{key:"nextPage",value:(t=FE.default(JE.default.mark((function e(){return JE.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=FE.default(JE.default.mark((function e(){return JE.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 rR(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 iR(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 iR(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 iR(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 aR=function(){function e(t,n){BE.default(this,e),this.balanceFactor=0,this.key=t,this.value=n,this.parent=null,this.left=null,this.right=null}return qE.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}(),sR=function(){function e(t,n){BE.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 qE.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 aR(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:JE.default.mark((function e(){var t,n,r;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=rR(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:JE.default.mark((function e(){var t,n,r,i=arguments;return JE.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:JE.default.mark((function e(){var t,n,r,i=arguments;return JE.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 oR(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 uR(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 uR(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 uR(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 cR=function(){function e(t,n){BE.default(this,e),this.value=t,this.revision=n||0}return qE.default(e,[{key:"isValid",get:function(){return!0}}]),e}(),lR=function(){function e(t){BE.default(this,e),this.revision=t}return qE.default(e,[{key:"isValid",get:function(){return!1}}]),e}(),fR=function(){function e(){BE.default(this,e),this.items=new sR}return qE.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 cR(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 lR(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=oR(this.items);try{for(n.s();!(t=n.n()).done;){var r=QE.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 dR(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 GE.default(this,n)}}var pR=function(e){WE.default(y,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v=dR(y);function y(e,t,n){var r;BE.default(this,y);return(r=v.call(this,e,n)).updateMergingQueue=new YT((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new fR,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),r}return qE.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=FE.default(JE.default.mark((function e(t,n,r,i){var a,s;return JE.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=FE.default(JE.default.mark((function e(t,n){var r,i,a;return JE.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=FE.default(JE.default.mark((function e(t,n,r){var i,a=this;return JE.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=FE.default(JE.default.mark((function e(t,n,r){var i,a;return JE.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=FE.default(JE.default.mark((function e(t,n,r){var i,a,s,o;return JE.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(bT(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=FE.default(JE.default.mark((function e(t,n,r){var i,a=this;return JE.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=FE.default(JE.default.mark((function e(t,n,r){return JE.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=FE.default(JE.default.mark((function e(t){var n,r,i;return JE.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=bT(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=FE.default(JE.default.mark((function e(t){var n;return JE.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=FE.default(JE.default.mark((function e(t){var n;return JE.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 mT("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=FE.default(JE.default.mark((function e(t){var n,r,i,a,s=this;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new vT(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 nR({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=FE.default(JE.default.mark((function e(t){return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return kT((t=t||{}).pageSize),t.limit=t.pageSize||t.limit||50,t.order=t.order||"asc",e.abrupt("return",this.queryItems(t));case 5:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"getContext",value:(i=FE.default(JE.default.mark((function e(){var t;return JE.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=FE.default(JE.default.mark((function e(t){var n,r;return JE.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=FE.default(JE.default.mark((function e(t,n){var r,i,a;return JE.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=FE.default(JE.default.mark((function e(){return JE.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))ET("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 nR({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=bT(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):(ET("Context update skipped, current:",this.lastEventId,", remote:",t),!1)}}],[{key:"type",get:function(){return"list"}}]),y}(KT),hR=function(e){WE.default(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=dR(p);function p(e){var t;return BE.default(this,p),(t=d.call(this)).syncListImpl=e,t.syncListImpl.attach(zE.default(t)),t}return qE.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 pR.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=FE.default(JE.default.mark((function e(t,n){return JE.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=FE.default(JE.default.mark((function e(t,n,r){return JE.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=FE.default(JE.default.mark((function e(t,n,r){return JE.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=FE.default(JE.default.mark((function e(t,n,r){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(t,n){return JE.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=FE.default(JE.default.mark((function e(){return JE.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(){ZE.default($E.default(p.prototype),"close",this).call(this),this.syncListImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return pR.type}}]),p}(XT);VE.default(hR,"itemAdded","itemAdded"),VE.default(hR,"itemUpdated","itemUpdated"),VE.default(hR,"itemRemoved","itemRemoved"),VE.default(hR,"removed","removed"),tT([IE.validateTypesAsync(IE.pureObject,["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[Object,Object]),nT("design:returntype",Promise)],hR.prototype,"push",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger,IE.pureObject,["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[Number,Object,Object]),nT("design:returntype",Promise)],hR.prototype,"set",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger,"function",["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[Number,Function,Object]),nT("design:returntype",Promise)],hR.prototype,"mutate",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger,IE.pureObject,["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[Number,Object,Object]),nT("design:returntype",Promise)],hR.prototype,"update",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger),nT("design:type",Function),nT("design:paramtypes",[Number]),nT("design:returntype",Promise)],hR.prototype,"remove",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger),nT("design:type",Function),nT("design:paramtypes",[Number]),nT("design:returntype",Promise)],hR.prototype,"get",null),tT([IE.validateTypesAsync(["undefined",IE.objectSchema("query options",{from:[IE.nonNegativeInteger,"undefined"],pageSize:[IE.custom((function(e){return[wT(e),"a positive integer"]})),"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[Object]),nT("design:returntype",Promise)],hR.prototype,"getItems",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger),nT("design:type",Function),nT("design:paramtypes",[Number]),nT("design:returntype",Promise)],hR.prototype,"setTtl",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger,IE.nonNegativeInteger),nT("design:type",Function),nT("design:paramtypes",[Number,Number]),nT("design:returntype",Promise)],hR.prototype,"setItemTtl",null);var vR=function(){function e(t){BE.default(this,e),this.descriptor=t}return qE.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 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=$E.default(e);if(t){var i=$E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return GE.default(this,n)}}var mR=function(e){WE.default(h,e);var t,n,r,i,a,s,o,u,c,l,f,d,p=yR(h);function h(e,t,n){var r;BE.default(this,h);return(r=p.call(this,e,n)).updateMergingQueue=new YT((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new fR,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),t.items&&t.items.forEach((function(e){e.date_updated=new Date(e.date_updated),r.cache.store(e.key,new vR(e),e.last_event_id)})),r}return qE.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=FE.default(JE.default.mark((function e(t,n,r){var i,a=this;return JE.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=FE.default(JE.default.mark((function e(t){return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=t){e.next=2;break}throw new mT("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=FE.default(JE.default.mark((function e(t){var n;return JE.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 mT("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=FE.default(JE.default.mark((function e(t,n,r){var i,a=this;return JE.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=FE.default(JE.default.mark((function e(t,n,r){return JE.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=FE.default(JE.default.mark((function e(t,n,r){var i,a;return JE.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=FE.default(JE.default.mark((function e(t,n,r){var i,a,s,o,u;return JE.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 vR({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(bT(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=FE.default(JE.default.mark((function e(t,n,r,i){var a,s,o,u,c;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=new vT(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=FE.default(JE.default.mark((function e(t){var n,r,i;return JE.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=bT(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=FE.default(JE.default.mark((function e(t){var n,r,i,a,s=this;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new vT(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 vR(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=FE.default(JE.default.mark((function e(t){return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return kT((t=t||{}).pageSize),t.limit=t.pageSize||t.limit||50,t.order=t.order||"asc",e.abrupt("return",this.queryItems(t));case 5:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"shouldIgnoreEvent",value:function(e,t){return this.cache.isKnown(e,t)}},{key:"_update",value:function(e,t){switch(e.date_created=new Date(e.date_created),e.type){case"map_item_added":case"map_item_updated":this._handleItemMutated(e.item_key,e.item_url,e.id,e.item_revision,e.item_data,e.date_created,void 0,"map_item_added"===e.type,!0);break;case"map_item_removed":this._handleItemRemoved(e.item_key,e.id,e.item_data,e.date_created,!0);break;case"map_removed":this.onRemoved(!1)}t&&this._advanceLastEventId(e.id,e.map_revision)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e,t&&(this.descriptor.revision=t))}},{key:"_updateRootDateUpdated",value:function(e){(!this.descriptor.date_updated||e.getTime()>this.descriptor.date_updated.getTime())&&(this.descriptor.date_updated=e,this.services.storage.update(this.type,this.sid,this.uniqueName,{date_updated:e}))}},{key:"_handleItemMutated",value:function(e,t,n,r,i,a,s,o,u){if(this.shouldIgnoreEvent(e,n))ET("SyncMapItem ",e," update skipped, current:",this.lastEventId,", remote:",n);else{this._updateRootDateUpdated(a);var c=this.cache.get(e);if(!c){var l=new vR({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=bT(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=FE.default(JE.default.mark((function e(t){var n,r;return JE.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=FE.default(JE.default.mark((function e(t,n){var r,i,a;return JE.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=FE.default(JE.default.mark((function e(){return JE.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}(KT),gR=function(e){WE.default(f,e);var t,n,r,i,a,s,o,u,c,l=yR(f);function f(e){var t;return BE.default(this,f),(t=l.call(this)).syncMapImpl=e,t.syncMapImpl.attach(zE.default(t)),t}return qE.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 mR.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=FE.default(JE.default.mark((function e(t,n,r){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(t,n,r){return JE.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=FE.default(JE.default.mark((function e(t,n,r){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(t,n){return JE.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=FE.default(JE.default.mark((function e(){return JE.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(){ZE.default($E.default(f.prototype),"close",this).call(this),this.syncMapImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return mR.type}}]),f}(XT);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=$E.default(e);if(t){var i=$E.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return GE.default(this,n)}}VE.default(gR,"itemAdded","itemAdded"),VE.default(gR,"itemUpdated","itemUpdated"),VE.default(gR,"itemRemoved","itemRemoved"),VE.default(gR,"removed","removed"),tT([IE.validateTypesAsync("string",IE.pureObject,["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[String,Object,Object]),nT("design:returntype",Promise)],gR.prototype,"set",null),tT([IE.validateTypesAsync("string"),nT("design:type",Function),nT("design:paramtypes",[String]),nT("design:returntype",Promise)],gR.prototype,"get",null),tT([IE.validateTypesAsync("string","function",["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[String,Function,Object]),nT("design:returntype",Promise)],gR.prototype,"mutate",null),tT([IE.validateTypesAsync("string",IE.pureObject,["undefined",IE.objectSchema("item metadata",{ttl:[IE.nonNegativeInteger,"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[String,Object,Object]),nT("design:returntype",Promise)],gR.prototype,"update",null),tT([IE.validateTypesAsync("string"),nT("design:type",Function),nT("design:paramtypes",[String]),nT("design:returntype",Promise)],gR.prototype,"remove",null),tT([IE.validateTypesAsync(["undefined",IE.objectSchema("query options",{from:["string","undefined"],pageSize:[IE.custom((function(e){return[wT(e),"a positive integer"]})),"undefined"]})]),nT("design:type",Function),nT("design:paramtypes",[Object]),nT("design:returntype",Promise)],gR.prototype,"getItems",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger),nT("design:type",Function),nT("design:paramtypes",[Number]),nT("design:returntype",Promise)],gR.prototype,"setTtl",null),tT([IE.validateTypesAsync("string",IE.nonNegativeInteger),nT("design:type",Function),nT("design:paramtypes",[String,Number]),nT("design:returntype",Promise)],gR.prototype,"setItemTtl",null);var kR=function(e){WE.default(a,e);var t,n,r,i=bR(a);function a(e,t,n){var r;return BE.default(this,a),(r=i.call(this,e,n)).descriptor=t,r}return qE.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=FE.default(JE.default.mark((function e(t){var n,r,i,a;return JE.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=FE.default(JE.default.mark((function e(t){var n,r;return JE.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=FE.default(JE.default.mark((function e(){return JE.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}(KT);tT([IE.validateTypesAsync(IE.pureObject),nT("design:type",Function),nT("design:paramtypes",[Object]),nT("design:returntype",Promise)],kR.prototype,"publishMessage",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger),nT("design:type",Function),nT("design:paramtypes",[Number]),nT("design:returntype",Promise)],kR.prototype,"setTtl",null);var wR=function(e){WE.default(a,e);var t,n,r,i=bR(a);function a(e){var t;return BE.default(this,a),(t=i.call(this)).syncStreamImpl=e,t.syncStreamImpl.attach(zE.default(t)),t}return qE.default(a,[{key:"uri",get:function(){return this.syncStreamImpl.uri}},{key:"links",get:function(){return this.syncStreamImpl.links}},{key:"dateExpires",get:function(){return this.syncStreamImpl.dateExpires}},{key:"type",get:function(){return kR.type}},{key:"lastEventId",get:function(){return null}},{key:"sid",get:function(){return this.syncStreamImpl.sid}},{key:"uniqueName",get:function(){return this.syncStreamImpl.uniqueName}},{key:"publishMessage",value:(r=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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=FE.default(JE.default.mark((function e(){return JE.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(){ZE.default($E.default(a.prototype),"close",this).call(this),this.syncStreamImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return kR.type}}]),a}(XT);VE.default(wR,"messagePublished","messagePublished"),VE.default(wR,"removed","removed"),tT([IE.validateTypesAsync(IE.pureObject),nT("design:type",Function),nT("design:paramtypes",[Object]),nT("design:returntype",Promise)],wR.prototype,"publishMessage",null),tT([IE.validateTypesAsync(IE.nonNegativeInteger),nT("design:type",Function),nT("design:paramtypes",[Number]),nT("design:returntype",Promise)],wR.prototype,"setTtl",null);var xR=function e(t){BE.default(this,e),this.sdk="js",this.sdkVer=t,this.os=eT.os.family,this.osVer=eT.os.version,this.pl=eT.name,this.plVer=eT.version},_R=function(){function e(){BE.default(this,e),this.names=new Map,this.entities=new Map}return qE.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 SR(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 GE.default(this,n)}}var ER=function(e){WE.default(n,e);var t=SR(n);function n(e,r,i,a){var s;return BE.default(this,n),(s=t.call(this,r,i)).descriptor=e,s.cache=new fR,a&&a.forEach((function(e){s.cache.store(e.key,{key:e.key,value:e.data},e.revision)})),s}return qE.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))ET("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)?ET("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}(KT);function TR(e){return RR.apply(this,arguments)}function RR(){return(RR=FE.default(JE.default.mark((function e(t){var n,r,i,a,s,o;return JE.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 mT("Invalid query",400,54507);case 3:return s={query_string:r},a===IR.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 IR=function(e){WE.default(n,e);var t=SR(n);function n(e){var r;return BE.default(this,n),(r=t.call(this)).liveQueryImpl=e,r.liveQueryImpl.attach(zE.default(r)),r}return qE.default(n,[{key:"type",get:function(){return ER.type}},{key:"lastEventId",get:function(){return this.liveQueryImpl.lastEventId}},{key:"sid",get:function(){return this.liveQueryImpl.sid}},{key:"close",value:function(){ZE.default($E.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 ER.type}}]),n}(XT);VE.default(IR,"itemUpdated","itemUpdated"),VE.default(IR,"itemRemoved","itemRemoved");var OR=function(e){WE.default(i,e);var t,n,r=SR(i);function i(e){var t;return BE.default(this,i),t=r.call(this),VE.default(zE.default(t),"queryExpression",null),VE.default(zE.default(t),"items",{}),Object.assign(zE.default(t),e),t.updateIndexName(e.indexName),t}return qE.default(i,[{key:"type",get:function(){return i.type}},{key:"search",value:(n=FE.default(JE.default.mark((function e(t){var n=this;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.items={},e.abrupt("return",TR({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 IT("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=FE.default(JE.default.mark((function e(){return JE.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 mT("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 vT(this.insightsUri).pathSegment(e).pathSegment("Items").build()}}],[{key:"type",get:function(){return"instant_query"}}]),i}(iT);VE.default(OR,"searchResult","searchResult"),tT([IE.validateTypesAsync("string"),nT("design:type",Function),nT("design:paramtypes",[String]),nT("design:returntype",Promise)],OR.prototype,"search",null),tT([IE.validateTypes(IE.nonEmptyString),nT("design:type",Function),nT("design:paramtypes",[String]),nT("design:returntype",void 0)],OR.prototype,"updateIndexName",null);function CR(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 GE.default(this,n)}}function PR(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 AR(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?PR(Object(n),!0).forEach((function(t){VE.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):PR(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var jR="data_sync",MR="3.1.0-rc.0";function LR(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 AR(AR({},e),{},{mode:t})}return{mode:"create_new"}}var NR="com.twilio.rtd.cds.document",UR="com.twilio.rtd.cds.list",DR="com.twilio.rtd.cds.map",FR="twilio.sync.event",Client=function(e){WE.default(Client,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y=CR(Client);function Client(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(BE.default(this,Client),t=y.call(this),!e)throw new Error("Sync library needs a valid Twilio token to be passed");n.hasOwnProperty("logLevel")?ST(n.logLevel):ST("silent");var r=n.productId=n.productId||jR;n.clientMetadata=n.clientMetadata||{},n.clientMetadata.hasOwnProperty("type")||(n.clientMetadata.type="sync"),n.clientMetadata.hasOwnProperty("sdk")||(n.clientMetadata.sdk="JS",n.clientMetadata.sdkv=MR);var i=!n.twilsockClient;if(!n.initRegistrations){var a=new OE.InitRegistration(r);Client.populateInitRegistrations(a),n.initRegistrations=[a]}var s=n.twilsockClient=n.twilsockClient||new OE.Twilsock(e,r,n);s.on("tokenAboutToExpire",(function(e){return t.emit("tokenAboutToExpire",e)})),s.on("tokenExpired",(function(){return t.emit("tokenExpired")})),s.on("connectionError",(function(e){return t.emit("connectionError",e)})),s.on("stateChanged",(function(e){t.emit("connectionStateChanged",e),t.services.subscriptions.onConnectionStateChanged("connected"===e)})),s.on("message",(function(e,n){return t._routeMessage(e,n)}));var o=new NT(n),u=new GT(new xR(MR),o,s),c=new $T(o);return t.services={config:o,twilsock:s,network:u,storage:c,router:zE.default(t),subscriptions:null},t.services.subscriptions=new BT(t.services),t.entities=new _R,i&&s.connect(),t}return qE.default(Client,[{key:"_routeMessage",value:function(e,t){switch(ET("Notification type:",e,"content:",t),e){case NR:case UR:case DR:this.services.subscriptions.acceptMessage(t,!1);break;case FR: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=FE.default(JE.default.mark((function e(){var t;return JE.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),RT("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=bT(n);e!==hR.type&&e!==gR.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=FE.default(JE.default.mark((function e(t,n){var r,i,a,s=arguments;return JE.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 mT("Cannot get entity without id",404);case 3:return i=new vT(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=FE.default(JE.default.mark((function e(t){return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(tR.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=FE.default(JE.default.mark((function e(t){return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(hR.type,t)||this._get(this.services.config.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=FE.default(JE.default.mark((function e(t){var n,r=arguments;return JE.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(gR.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=FE.default(JE.default.mark((function e(t){return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(wR.type,t)||this._get(this.services.config.streamsUri,t,!1));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"_createStream",value:(c=FE.default(JE.default.mark((function e(t,n){var r,i;return JE.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(IR.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=FE.default(JE.default.mark((function e(t){var n,r,i,a,s=this;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=LR(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,tR.type))){e.next=14;break}return e.abrupt("return",new tR(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(tR.type,n.id,r),a=new eR(this.services,r,(function(e,t,n){return s.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new tR(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=FE.default(JE.default.mark((function e(t){var n,r,i,a,s=this;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=LR(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,gR.type))){e.next=14;break}return e.abrupt("return",new gR(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(gR.type,n.id,r),a=new mR(this.services,r,(function(e,t,n){return s.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new gR(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=FE.default(JE.default.mark((function e(t){var n,r,i,a,s=this;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=LR(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,hR.type))){e.next=14;break}return e.abrupt("return",new hR(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(hR.type,n.id,r),a=new pR(this.services,r,(function(e,t,n){return s.removeFromCacheAndSession(e,t,n)})),a=this.entities.store(a),e.abrupt("return",new hR(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=FE.default(JE.default.mark((function e(t){var n,r,i,a,s,o=this;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=LR(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,wR.type))){e.next=14;break}return e.abrupt("return",new wR(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(wR.type,n.id,r),a=function(e,t,n){return o.removeFromCacheAndSession(e,t,n)},s=new kR(this.services,r,a),s=this.entities.store(s),e.abrupt("return",new wR(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=FE.default(JE.default.mark((function e(){return JE.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=FE.default(JE.default.mark((function e(t){return JE.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 mT("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=FE.default(JE.default.mark((function e(t,n){var r,i,a,s,o,u=this;return JE.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:return r=new vT(this.services.config.insightsUri).pathSegment(t).pathSegment("Items").build(),e.next=5,TR({network:this.services.network,uri:r,queryString:n,type:IR.type});case 5:return i=e.sent,(a=this.getCached(i.query_id,IR.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 ER(s,this.services,o,i.items)),this.storeRootInSessionCache(IR.type,i.query_id,a.liveQueryDescriptor),a=this.entities.store(a),e.abrupt("return",new IR(a));case 11:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"instantQuery",value:(t=FE.default(JE.default.mark((function e(t){var n,r=this;return JE.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 OR({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([FR,NR,UR,DR])}},{key:"version",get:function(){return MR}}]),Client}(iT);VE.default(Client,"connectionStateChanged","connectionStateChanged"),VE.default(Client,"connectionError","connectionError"),VE.default(Client,"tokenAboutToExpire","tokenAboutToExpire"),VE.default(Client,"tokenExpired","tokenExpired"),tT([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)]})]),nT("design:type",Function),nT("design:paramtypes",[Object]),nT("design:returntype",Promise)],Client.prototype,"document",null),tT([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"]})]),nT("design:type",Function),nT("design:paramtypes",[Object]),nT("design:returntype",Promise)],Client.prototype,"map",null),tT([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"]})]),nT("design:type",Function),nT("design:paramtypes",[Object]),nT("design:returntype",Promise)],Client.prototype,"list",null),tT([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)]})]),nT("design:type",Function),nT("design:paramtypes",[Object]),nT("design:returntype",Promise)],Client.prototype,"stream",null),tT([IE.validateTypesAsync(IE.nonEmptyString),nT("design:type",Function),nT("design:paramtypes",[String]),nT("design:returntype",Promise)],Client.prototype,"updateToken",null),tT([IE.validateTypesAsync(IE.nonEmptyString,"string"),nT("design:type",Function),nT("design:paramtypes",[String,String]),nT("design:returntype",Promise)],Client.prototype,"liveQuery",null),tT([IE.validateTypesAsync(IE.nonEmptyString),nT("design:type",Function),nT("design:paramtypes",[String]),nT("design:returntype",Promise)],Client.prototype,"instantQuery",null),mE.Client=Client,mE.InsightsItem=function e(){BE.default(this,e)},mE.InstantQuery=OR,mE.LiveQuery=IR,mE.Paginator=Paginator;var BR=mE.SyncClient=Client;function qR(){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 zR(e,t,n){return(zR=qR()?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 WR(e){var t="function"==typeof Map?new Map:void 0;return(WR=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 zR(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=tR,mE.SyncList=hR,mE.SyncListItem=nR,mE.SyncMap=gR,mE.SyncMapItem=vR,mE.SyncStream=wR;var GR,$R={},VR=hS,JR=function(e){if(VR(e))throw TypeError("The method doesn't accept regular expressions");return e},KR=pe("match"),HR=function(e){var t=/./;try{"/./"[e](t)}catch(n){try{return t[KR]=!1,"/./"[e](t)}catch(e){}}return!1},YR=In,QR=a.f,XR=Ut,ZR=gr,eI=JR,tI=k,nI=HR,rI="".startsWith,iI=Math.min,aI=nI("startsWith");YR({target:"String",proto:!0,forced:!!(aI||(GR=QR(String.prototype,"startsWith"),!GR||GR.writable))&&!aI},{startsWith:function(e){var t=ZR(tI(this));eI(e);var n=XR(iI(arguments.length>1?arguments[1]:void 0,t.length)),r=ZR(e);return rI?rI.call(t,r,n):t.slice(n,n+r.length)===r}});var sI=a_.left,oI=L,uI=Ws;In({target:"Array",proto:!0,forced:!ec("reduce")||!uI&&oI>79&&oI<83},{reduce:function(e){return sI(this,e,arguments.length,arguments.length>1?arguments[1]:void 0)}});var cI=s,lI=pe("iterator"),fI=!cI((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[lI]||"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})),dI=2147483647,pI=/[^\0-\u007E]/,hI=/[.\u3002\uFF0E\uFF61]/g,vI="Overflow: input needs wider integers to process",yI=Math.floor,mI=String.fromCharCode,gI=function(e){return e+22+75*(e<26)},bI=function(e,t,n){var r=0;for(e=n?yI(e/700):e>>1,e+=yI(e/t);e>455;r+=36)e=yI(e/35);return yI(r+36*e/(e+38))},kI=function(e){var t,n,r=[],i=(e=function(e){for(var t=[],n=0,r=e.length;n<r;){var i=e.charCodeAt(n++);if(i>=55296&&i<=56319&&n<r){var a=e.charCodeAt(n++);56320==(64512&a)?t.push(((1023&i)<<10)+(1023&a)+65536):(t.push(i),n--)}else t.push(i)}return t}(e)).length,a=128,s=0,o=72;for(t=0;t<e.length;t++)(n=e[t])<128&&r.push(mI(n));var u=r.length,c=u;for(u&&r.push("-");c<i;){var l=dI;for(t=0;t<e.length;t++)(n=e[t])>=a&&n<l&&(l=n);var f=c+1;if(l-a>yI((dI-s)/f))throw RangeError(vI);for(s+=(l-a)*f,a=l,t=0;t<e.length;t++){if((n=e[t])<a&&++s>dI)throw RangeError(vI);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(mI(gI(h+v%y))),d=yI(v/y)}r.push(mI(gI(d))),o=bI(s,f,c==u),s=0,++c}}++s,++a}return r.join("")},wI=In,xI=R,_I=fI,SI=Je.exports,EI=Ha,TI=Mr,RI=Ef,II=xt,OI=as,CI=ee,PI=Nr,AI=qa,jI=De,MI=S,LI=gr,NI=Hn,UI=h,DI=ms,FI=hs,BI=pe,qI=xI("fetch"),zI=xI("Request"),WI=zI&&zI.prototype,GI=xI("Headers"),$I=BI("iterator"),VI="URLSearchParams",JI="URLSearchParamsIterator",KI=II.set,HI=II.getterFor(VI),YI=II.getterFor(JI),QI=/\+/g,XI=Array(4),ZI=function(e){return XI[e-1]||(XI[e-1]=RegExp("((?:%[\\da-f]{2}){"+e+"})","gi"))},eO=function(e){try{return decodeURIComponent(e)}catch(t){return e}},tO=function(e){var t=e.replace(QI," "),n=4;try{return decodeURIComponent(t)}catch(e){for(;n;)t=t.replace(ZI(n--),eO);return t}},nO=/[!'()~]|%20/g,rO={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+"},iO=function(e){return rO[e]},aO=function(e){return encodeURIComponent(e).replace(nO,iO)},sO=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:tO(r.shift()),value:tO(r.join("="))}))},oO=function(e){this.entries.length=0,sO(this.entries,e)},uO=function(e,t){if(e<t)throw TypeError("Not enough arguments")},cO=RI((function(e,t){KI(this,{type:JI,iterator:DI(HI(e).entries),kind:t})}),"Iterator",(function(){var e=YI(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})),lO=function(){OI(this,lO,VI);var e,t,n,r,i,a,s,o,u,c=arguments.length>0?arguments[0]:void 0,l=this,f=[];if(KI(l,{type:VI,entries:f,updateURL:function(){},updateSearchParams:oO}),void 0!==c)if(MI(c))if("function"==typeof(e=FI(c)))for(n=(t=DI(c,e)).next;!(r=n.call(t)).done;){if((s=(a=(i=DI(jI(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:LI(s.value),value:LI(o.value)})}else for(u in c)CI(c,u)&&f.push({key:u,value:LI(c[u])});else sO(f,"string"==typeof c?"?"===c.charAt(0)?c.slice(1):c:LI(c))},fO=lO.prototype;if(EI(fO,{append:function(e,t){uO(arguments.length,2);var n=HI(this);n.entries.push({key:LI(e),value:LI(t)}),n.updateURL()},delete:function(e){uO(arguments.length,1);for(var t=HI(this),n=t.entries,r=LI(e),i=0;i<n.length;)n[i].key===r?n.splice(i,1):i++;t.updateURL()},get:function(e){uO(arguments.length,1);for(var t=HI(this).entries,n=LI(e),r=0;r<t.length;r++)if(t[r].key===n)return t[r].value;return null},getAll:function(e){uO(arguments.length,1);for(var t=HI(this).entries,n=LI(e),r=[],i=0;i<t.length;i++)t[i].key===n&&r.push(t[i].value);return r},has:function(e){uO(arguments.length,1);for(var t=HI(this).entries,n=LI(e),r=0;r<t.length;)if(t[r++].key===n)return!0;return!1},set:function(e,t){uO(arguments.length,1);for(var n,r=HI(this),i=r.entries,a=!1,s=LI(e),o=LI(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=HI(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=HI(this).entries,r=PI(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 cO(this,"keys")},values:function(){return new cO(this,"values")},entries:function(){return new cO(this,"entries")}},{enumerable:!0}),SI(fO,$I,fO.entries),SI(fO,"toString",(function(){for(var e,t=HI(this).entries,n=[],r=0;r<t.length;)e=t[r++],n.push(aO(e.key)+"="+aO(e.value));return n.join("&")}),{enumerable:!0}),TI(lO,VI),wI({global:!0,forced:!_I},{URLSearchParams:lO}),!_I&&"function"==typeof GI){var dO=function(e){if(MI(e)){var t,n=e.body;if(AI(n)===VI)return(t=e.headers?new GI(e.headers):new GI).has("content-type")||t.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"),NI(e,{body:UI(0,String(n)),headers:UI(0,t)})}return e};if("function"==typeof qI&&wI({global:!0,enumerable:!0,forced:!0},{fetch:function(e){return qI(e,arguments.length>1?dO(arguments[1]):{})}}),"function"==typeof zI){var pO=function(e){return OI(this,pO,"Request"),new zI(e,arguments.length>1?dO(arguments[1]):{})};WI.constructor=pO,pO.prototype=WI,wI({global:!0,forced:!0},{Request:pO})}}var hO,vO={URLSearchParams:lO,getState:HI},yO=In,mO=o,gO=fI,bO=i,kO=Nn,wO=Je.exports,xO=as,_O=ee,SO=vE,EO=Hl,TO=af.codeAt,RO=function(e){var t,n,r=[],i=e.toLowerCase().replace(hI,".").split(".");for(t=0;t<i.length;t++)n=i[t],r.push(pI.test(n)?"xn--"+kI(n):n);return r.join(".")},IO=gr,OO=Mr,CO=vO,PO=xt,AO=bO.URL,jO=CO.URLSearchParams,MO=CO.getState,LO=PO.set,NO=PO.getterFor("URL"),UO=Math.floor,DO=Math.pow,FO="Invalid scheme",BO="Invalid host",qO="Invalid port",zO=/[A-Za-z]/,WO=/[\d+-.A-Za-z]/,GO=/\d/,$O=/^0x/i,VO=/^[0-7]+$/,JO=/^\d+$/,KO=/^[\dA-Fa-f]+$/,HO=/[\0\t\n\r #%/:<>?@[\\\]^|]/,YO=/[\0\t\n\r #/:<>?@[\\\]^|]/,QO=/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g,XO=/[\t\n\r]/g,ZO=function(e,t){var n,r,i;if("["==t.charAt(0)){if("]"!=t.charAt(t.length-1))return BO;if(!(n=tC(t.slice(1,-1))))return BO;e.host=n}else if(cC(e)){if(t=RO(t),HO.test(t))return BO;if(null===(n=eC(t)))return BO;e.host=n}else{if(YO.test(t))return BO;for(n="",r=EO(t),i=0;i<r.length;i++)n+=oC(r[i],rC);e.host=n}},eC=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=$O.test(i)?16:8,i=i.slice(8==a?1:2)),""===i)s=0;else{if(!(10==a?JO:8==a?VO:KO).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>=DO(256,5-t))return null}else if(s>255)return null;for(o=n.pop(),r=0;r<n.length;r++)o+=n[r]*DO(256,3-r);return o},tC=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&&KO.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(!GO.test(d()))return;for(;GO.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},nC=function(e){var t,n,r,i;if("number"==typeof e){for(t=[],n=0;n<4;n++)t.unshift(e%256),e=UO(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},rC={},iC=SO({},rC,{" ":1,'"':1,"<":1,">":1,"`":1}),aC=SO({},iC,{"#":1,"?":1,"{":1,"}":1}),sC=SO({},aC,{"/":1,":":1,";":1,"=":1,"@":1,"[":1,"\\":1,"]":1,"^":1,"|":1}),oC=function(e,t){var n=TO(e,0);return n>32&&n<127&&!_O(t,e)?e:encodeURIComponent(e)},uC={ftp:21,file:null,http:80,https:443,ws:80,wss:443},cC=function(e){return _O(uC,e.scheme)},lC=function(e){return""!=e.username||""!=e.password},fC=function(e){return!e.host||e.cannotBeABaseURL||"file"==e.scheme},dC=function(e,t){var n;return 2==e.length&&zO.test(e.charAt(0))&&(":"==(n=e.charAt(1))||!t&&"|"==n)},pC=function(e){var t;return e.length>1&&dC(e.slice(0,2))&&(2==e.length||"/"===(t=e.charAt(2))||"\\"===t||"?"===t||"#"===t)},hC=function(e){var t=e.path,n=t.length;!n||"file"==e.scheme&&1==n&&dC(t[0],!0)||t.pop()},vC=function(e){return"."===e||"%2e"===e.toLowerCase()},yC={},mC={},gC={},bC={},kC={},wC={},xC={},_C={},SC={},EC={},TC={},RC={},IC={},OC={},CC={},PC={},AC={},jC={},MC={},LC={},NC={},UC=function(e,t,n,r){var i,a,s,o,u,c=n||yC,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(QO,"")),t=t.replace(XO,""),i=EO(t);l<=i.length;){switch(a=i[l],c){case yC:if(!a||!zO.test(a)){if(n)return FO;c=gC;continue}f+=a.toLowerCase(),c=mC;break;case mC:if(a&&(WO.test(a)||"+"==a||"-"==a||"."==a))f+=a.toLowerCase();else{if(":"!=a){if(n)return FO;f="",c=gC,l=0;continue}if(n&&(cC(e)!=_O(uC,f)||"file"==f&&(lC(e)||null!==e.port)||"file"==e.scheme&&!e.host))return;if(e.scheme=f,n)return void(cC(e)&&uC[e.scheme]==e.port&&(e.port=null));f="","file"==e.scheme?c=OC:cC(e)&&r&&r.scheme==e.scheme?c=bC:cC(e)?c=_C:"/"==i[l+1]?(c=kC,l++):(e.cannotBeABaseURL=!0,e.path.push(""),c=MC)}break;case gC:if(!r||r.cannotBeABaseURL&&"#"!=a)return FO;if(r.cannotBeABaseURL&&"#"==a){e.scheme=r.scheme,e.path=r.path.slice(),e.query=r.query,e.fragment="",e.cannotBeABaseURL=!0,c=NC;break}c="file"==r.scheme?OC:wC;continue;case bC:if("/"!=a||"/"!=i[l+1]){c=wC;continue}c=SC,l++;break;case kC:if("/"==a){c=EC;break}c=jC;continue;case wC:if(e.scheme=r.scheme,a==hO)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&&cC(e))c=xC;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=LC;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=jC;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=NC}break;case xC:if(!cC(e)||"/"!=a&&"\\"!=a){if("/"!=a){e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,c=jC;continue}c=EC}else c=SC;break;case _C:if(c=SC,"/"!=a||"/"!=f.charAt(l+1))continue;l++;break;case SC:if("/"!=a&&"\\"!=a){c=EC;continue}break;case EC:if("@"==a){d&&(f="%40"+f),d=!0,s=EO(f);for(var v=0;v<s.length;v++){var y=s[v];if(":"!=y||h){var m=oC(y,sC);h?e.password+=m:e.username+=m}else h=!0}f=""}else if(a==hO||"/"==a||"?"==a||"#"==a||"\\"==a&&cC(e)){if(d&&""==f)return"Invalid authority";l-=EO(f).length+1,f="",c=TC}else f+=a;break;case TC:case RC:if(n&&"file"==e.scheme){c=PC;continue}if(":"!=a||p){if(a==hO||"/"==a||"?"==a||"#"==a||"\\"==a&&cC(e)){if(cC(e)&&""==f)return BO;if(n&&""==f&&(lC(e)||null!==e.port))return;if(o=ZO(e,f))return o;if(f="",c=AC,n)return;continue}"["==a?p=!0:"]"==a&&(p=!1),f+=a}else{if(""==f)return BO;if(o=ZO(e,f))return o;if(f="",c=IC,n==RC)return}break;case IC:if(!GO.test(a)){if(a==hO||"/"==a||"?"==a||"#"==a||"\\"==a&&cC(e)||n){if(""!=f){var g=parseInt(f,10);if(g>65535)return qO;e.port=cC(e)&&g===uC[e.scheme]?null:g,f=""}if(n)return;c=AC;continue}return qO}f+=a;break;case OC:if(e.scheme="file","/"==a||"\\"==a)c=CC;else{if(!r||"file"!=r.scheme){c=jC;continue}if(a==hO)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=LC;else{if("#"!=a){pC(i.slice(l).join(""))||(e.host=r.host,e.path=r.path.slice(),hC(e)),c=jC;continue}e.host=r.host,e.path=r.path.slice(),e.query=r.query,e.fragment="",c=NC}}break;case CC:if("/"==a||"\\"==a){c=PC;break}r&&"file"==r.scheme&&!pC(i.slice(l).join(""))&&(dC(r.path[0],!0)?e.path.push(r.path[0]):e.host=r.host),c=jC;continue;case PC:if(a==hO||"/"==a||"\\"==a||"?"==a||"#"==a){if(!n&&dC(f))c=jC;else if(""==f){if(e.host="",n)return;c=AC}else{if(o=ZO(e,f))return o;if("localhost"==e.host&&(e.host=""),n)return;f="",c=AC}continue}f+=a;break;case AC:if(cC(e)){if(c=jC,"/"!=a&&"\\"!=a)continue}else if(n||"?"!=a)if(n||"#"!=a){if(a!=hO&&(c=jC,"/"!=a))continue}else e.fragment="",c=NC;else e.query="",c=LC;break;case jC:if(a==hO||"/"==a||"\\"==a&&cC(e)||!n&&("?"==a||"#"==a)){if(".."===(u=(u=f).toLowerCase())||"%2e."===u||".%2e"===u||"%2e%2e"===u?(hC(e),"/"==a||"\\"==a&&cC(e)||e.path.push("")):vC(f)?"/"==a||"\\"==a&&cC(e)||e.path.push(""):("file"==e.scheme&&!e.path.length&&dC(f)&&(e.host&&(e.host=""),f=f.charAt(0)+":"),e.path.push(f)),f="","file"==e.scheme&&(a==hO||"?"==a||"#"==a))for(;e.path.length>1&&""===e.path[0];)e.path.shift();"?"==a?(e.query="",c=LC):"#"==a&&(e.fragment="",c=NC)}else f+=oC(a,aC);break;case MC:"?"==a?(e.query="",c=LC):"#"==a?(e.fragment="",c=NC):a!=hO&&(e.path[0]+=oC(a,rC));break;case LC:n||"#"!=a?a!=hO&&("'"==a&&cC(e)?e.query+="%27":e.query+="#"==a?"%23":oC(a,rC)):(e.fragment="",c=NC);break;case NC:a!=hO&&(e.fragment+=oC(a,iC))}l++}},DC=function(e){var t,n,r=xO(this,DC,"URL"),i=arguments.length>1?arguments[1]:void 0,a=IO(e),s=LO(r,{type:"URL"});if(void 0!==i)if(i instanceof DC)t=NO(i);else if(n=UC(t={},IO(i)))throw TypeError(n);if(n=UC(s,a,null,t))throw TypeError(n);var o=s.searchParams=new jO,u=MO(o);u.updateSearchParams(s.query),u.updateURL=function(){s.query=String(o)||null},mO||(r.href=BC.call(r),r.origin=qC.call(r),r.protocol=zC.call(r),r.username=WC.call(r),r.password=GC.call(r),r.host=$C.call(r),r.hostname=VC.call(r),r.port=JC.call(r),r.pathname=KC.call(r),r.search=HC.call(r),r.searchParams=YC.call(r),r.hash=QC.call(r))},FC=DC.prototype,BC=function(){var e=NO(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+="//",lC(e)&&(c+=n+(r?":"+r:"")+"@"),c+=nC(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},qC=function(){var e=NO(this),t=e.scheme,n=e.port;if("blob"==t)try{return new DC(t.path[0]).origin}catch(e){return"null"}return"file"!=t&&cC(e)?t+"://"+nC(e.host)+(null!==n?":"+n:""):"null"},zC=function(){return NO(this).scheme+":"},WC=function(){return NO(this).username},GC=function(){return NO(this).password},$C=function(){var e=NO(this),t=e.host,n=e.port;return null===t?"":null===n?nC(t):nC(t)+":"+n},VC=function(){var e=NO(this).host;return null===e?"":nC(e)},JC=function(){var e=NO(this).port;return null===e?"":String(e)},KC=function(){var e=NO(this),t=e.path;return e.cannotBeABaseURL?t[0]:t.length?"/"+t.join("/"):""},HC=function(){var e=NO(this).query;return e?"?"+e:""},YC=function(){return NO(this).searchParams},QC=function(){var e=NO(this).fragment;return e?"#"+e:""},XC=function(e,t){return{get:e,set:t,configurable:!0,enumerable:!0}};if(mO&&kO(FC,{href:XC(BC,(function(e){var t=NO(this),n=IO(e),r=UC(t,n);if(r)throw TypeError(r);MO(t.searchParams).updateSearchParams(t.query)})),origin:XC(qC),protocol:XC(zC,(function(e){var t=NO(this);UC(t,IO(e)+":",yC)})),username:XC(WC,(function(e){var t=NO(this),n=EO(IO(e));if(!fC(t)){t.username="";for(var r=0;r<n.length;r++)t.username+=oC(n[r],sC)}})),password:XC(GC,(function(e){var t=NO(this),n=EO(IO(e));if(!fC(t)){t.password="";for(var r=0;r<n.length;r++)t.password+=oC(n[r],sC)}})),host:XC($C,(function(e){var t=NO(this);t.cannotBeABaseURL||UC(t,IO(e),TC)})),hostname:XC(VC,(function(e){var t=NO(this);t.cannotBeABaseURL||UC(t,IO(e),RC)})),port:XC(JC,(function(e){var t=NO(this);fC(t)||(""==(e=IO(e))?t.port=null:UC(t,e,IC))})),pathname:XC(KC,(function(e){var t=NO(this);t.cannotBeABaseURL||(t.path=[],UC(t,IO(e),AC))})),search:XC(HC,(function(e){var t=NO(this);""==(e=IO(e))?t.query=null:("?"==e.charAt(0)&&(e=e.slice(1)),t.query="",UC(t,e,LC)),MO(t.searchParams).updateSearchParams(t.query)})),searchParams:XC(YC),hash:XC(QC,(function(e){var t=NO(this);""!=(e=IO(e))?("#"==e.charAt(0)&&(e=e.slice(1)),t.fragment="",UC(t,e,NC)):t.fragment=null}))}),wO(FC,"toJSON",(function(){return BC.call(this)}),{enumerable:!0}),wO(FC,"toString",(function(){return BC.call(this)}),{enumerable:!0}),AO){var ZC=AO.createObjectURL,eP=AO.revokeObjectURL;ZC&&wO(DC,"createObjectURL",(function(e){return ZC.apply(AO,arguments)})),eP&&wO(DC,"revokeObjectURL",(function(e){return eP.apply(AO,arguments)}))}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)}}function nP(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.")}()}OO(DC,"URL"),yO({global:!0,forced:!gO,sham:!mO},{URL:DC}),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=Xf.exports,s=Mm,o=ih;function u(e){return e&&"object"===Ca(e)&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var l=u(n),f=u(r),d=u(i),p=c(a);
|
130
|
-
/*! *****************************************************************************
|
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 h(e,t,n,r){var i,a=arguments.length,s=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(a<3?i(s):a>3?i(t,n,s):i(t,n))||s);return a>3&&s&&Object.defineProperty(t,n,s),s}function v(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Ca(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function y(e,t){return["".concat((new Date).toISOString()," MCS Client ").concat(e,":")].concat(Array.from(t))}var m=function(){function e(t){Ma(this,e),f.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return Ta(e,[{key:"setLevel",value:function(e){p.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.trace.apply(null,y(this.prefix+"T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.debug.apply(null,y(this.prefix+"D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.info.apply(null,y(this.prefix+"I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.warn.apply(null,y(this.prefix+"W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.error.apply(null,y(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){p.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.trace.apply(null,y("T",t))}},{key:"debug",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.debug.apply(null,y("D",t))}},{key:"info",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.info.apply(null,y("I",t))}},{key:"warn",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.warn.apply(null,y("W",t))}},{key:"error",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];p.error.apply(null,y("E",t))}}]),e}(),g=function(e,t){return"".concat((n=e,n.startsWith("http")?"":function(e){return"https://mcs.".concat(null!=e?e:"us1",".twilio.com")}(t))).concat(e);var n},b=function(){function e(t,n,r,i){var a,s,o,u,c,l;Ma(this,e);var f=null!==(a=null!==(s=i.MCS)&&void 0!==s?s:i)&&void 0!==a?a:{};this.region=null!==(o=null!==(u=f.region)&&void 0!==u?u:i.region)&&void 0!==o?o:"us1",this.mediaUrl=g(n,this.region),this.mediaSetUrl=r?g(r):"".concat(this.mediaUrl,"Set"),this.token=t,this.retryWhenThrottledOverride=null===(c=f.retryWhenThrottledOverride)||void 0===c||c,this.backoffConfigOverride=null!==(l=f.backoffConfigOverride)&&void 0!==l?l:e.backoffConfigDefault}return Ta(e,[{key:"updateToken",value:function(e){this.token=e}}],[{key:"backoffConfigDefault",get:function(){return{min:1e3,max:4e3,maxAttemptsCount:3}}},{key:"retryWhenThrottledDefault",get:function(){return true}}]),e}(),Media=function(){function Media(e,t,n){Ma(this,Media),this.config=e,this.network=t,this._update(n)}return Ta(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"serviceSid",get:function(){return this.state.serviceSid}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"fileName",get:function(){return this.state.filename}},{key:"filename",get:function(){return this.state.filename}},{key:"category",get:function(){return this.state.category}},{key:"getContentUrl",value:function(){var e=this;return l.default(d.default.mark((function t(){var n;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.network.get("".concat(e.config.mediaUrl,"/").concat(e.sid));case 2:return n=t.sent,e._update(n.body),t.abrupt("return",Promise.resolve(e.state.contentDirectUrl));case 5:case"end":return t.stop()}}),t)})))()}},{key:"getCachedContentUrl",value:function(){var e=this;return l.default(d.default.mark((function t(){return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e.state.contentDirectUrl){t.next=2;break}return t.abrupt("return",Promise.resolve(e.state.contentDirectUrl));case 2:return t.next=4,e.getContentUrl();case 4:return t.abrupt("return",t.sent);case 5:case"end":return t.stop()}}),t)})))()}},{key:"_update",value:function(e){var t,n,r,i;this.state={sid:e.sid,serviceSid:e.service_sid,channelSid:e.channel_sid,messageSid:e.message_sid,dateCreated:e.date_created?new Date(e.date_created):null,dateUploadUpdated:e.date_upload_updated?new Date(e.date_upload_updated):null,dateUpdated:e.date_updated?new Date(e.date_updated):null,size:e.size,contentType:e.content_type,author:e.author,url:e.url,contentUrl:e.links.content,contentDirectUrl:null!==(t=e.links.content_direct_temporary)&&void 0!==t?t:null,filename:null!==(n=e.filename)&&void 0!==n?n:null,category:null!==(r=e.category)&&void 0!==r?r:"media",isMultipartUpstream:null!==(i=e.is_multipart_upstream)&&void 0!==i&&i}}}]),Media}(),k=function(e){Oa(n,e);var t=tP(n);function n(e,r,i,a,s){var o;return Ma(this,n),(o=t.call(this,e)).code=r,o.body=i,o.status=a,o.headers=s,o}return n}(WR(Error)),w=t.XMLHttpRequest||{};function x(e){var t=e.getResponseHeader("Content-Type");if(!t||0!==t.indexOf("application/json")||0===e.responseText.length)return e.responseText;try{return JSON.parse(e.responseText)}catch(t){return e.responseText}}var _,S,E=function(){function e(){Ma(this,e)}return Ta(e,[{key:"get",value:function(t,n){return l.default(d.default.mark((function r(){return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",e.request("GET",t,n));case 1:case"end":return r.stop()}}),r)})))()}},{key:"post",value:function(t,n,r){return l.default(d.default.mark((function i(){return d.default.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.abrupt("return",e.request("POST",t,n,r));case 1:case"end":return i.stop()}}),i)})))()}}],[{key:"request",value:function(e,t,n,r){return l.default(d.default.mark((function i(){return d.default.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.abrupt("return",new Promise((function(i,a){var s=new w;for(var o in s.open(e,t,!0),s.onreadystatechange=function(){if(4===s.readyState){var e,t=(e=s.getAllResponseHeaders())?e.split("\r\n").map((function(e){return e.split(": ")})).filter((function(e){return 2===e.length&&e[1].length>0})).reduce((function(e,t){return e[t[0]]=t[1],e}),{}):{},n=x(s);if(200<=s.status&&s.status<300)i({status:s.status,headers:t,body:n});else{var r,o,u=null!==(r=s.statusText)&&void 0!==r?r:"NONE";o="string"==typeof n?n&&1===n.split("\n",2).length?n:"":JSON.stringify(n);var c="".concat(s.status,": [").concat(u,"] ").concat(o);a(new k(c,s.status,n,u,t))}}},n)s.setRequestHeader(o,n[o]),"Content-Type"===o&&"application/json"===n[o]&&(r=JSON.stringify(r));s.send(r)})));case 1:case"end":return i.stop()}}),i)})))()}}]),e}(),T=m.scope("Network"),R=function(){function e(t,n){Ma(this,e),this.config=t,this.transport=n}return Ta(e,[{key:"backoffConfig",value:function(){return Object.assign(b.backoffConfigDefault,this.config.backoffConfigOverride)}},{key:"retryWhenThrottled",value:function(){var e,t;return null!==(e=null!==(t=this.config.retryWhenThrottledOverride)&&void 0!==t?t:b.retryWhenThrottledDefault)&&void 0!==e&&e}},{key:"executeWithRetry",value:function(e,t){var n=this;return l.default(d.default.mark((function r(){return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",new Promise((function(r,i){var a=[502,503,504];t&&a.push(429);var o=new s.Retrier(n.backoffConfig());o.on("attempt",l.default(d.default.mark((function t(){var n;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,e();case 3:n=t.sent,o.succeeded(n),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(0),a.indexOf(t.t0.status)>-1||"Twilsock disconnected"===t.t0.message?o.failed(t.t0):(o.removeAllListeners(),o.cancel(),i(t.t0));case 10:case"end":return t.stop()}}),t,null,[[0,7]])})))),o.on("succeeded",(function(e){r(e)})),o.on("cancelled",(function(e){return i(e)})),o.on("failed",(function(e){return i(e)})),o.start()})));case 1:case"end":return r.stop()}}),r)})))()}},{key:"get",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r,i;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r={"X-Twilio-Token":t.config.token},T.trace("sending GET request to ",e," headers ",r),n.prev=2,n.next=5,t.executeWithRetry((function(){return t.transport.get(e,r)}),t.retryWhenThrottled());case 5:return i=n.sent,T.trace("response",i),n.abrupt("return",i);case 10:throw n.prev=10,n.t0=n.catch(2),T.debug("get() error ".concat(n.t0)),n.t0;case 14:case"end":return n.stop()}}),n,null,[[2,10]])})))()}},{key:"post",value:function(e,n,r,i,a){var s=this;return l.default(d.default.mark((function o(){var u,c,l;return d.default.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return u={"X-Twilio-Token":s.config.token},"undefined"!=typeof FormData&&r instanceof FormData||!i||Object.assign(u,{"Content-Type":i}),c=new URL(e),n&&c.searchParams.append("Category",n),a&&c.searchParams.append("Filename",a),T.trace("sending POST request to ".concat(e," with headers ").concat(u)),o.prev=6,o.next=9,s.transport.post(c.href,u,r);case 9:l=o.sent,o.next=18;break;case 12:if(o.prev=12,o.t0=o.catch(6),!(void 0===t.XMLHttpRequest&&r instanceof FormData)){o.next=16;break}throw new TypeError("Posting FormData supported only with browser engine's FormData");case 16:throw T.debug("post() error ".concat(o.t0)),o.t0;case 18:return T.trace("response",l),o.abrupt("return",l);case 20:case"end":return o.stop()}}),o,null,[[6,12]])})))()}}]),e}(),I=m.scope("");e.default=(S=_=function(){function Client(e,t,n){var r,i;Ma(this,Client);var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};this.options=a,this.options.logLevel=null!==(r=this.options.logLevel)&&void 0!==r?r:"silent",this.config=new b(e,t,n,this.options),I.setLevel(this.options.logLevel),this.options.transport=null!==(i=this.options.transport)&&void 0!==i?i:new E,this.transport=this.options.transport,this.network=new R(this.config,this.transport)}return Ta(Client,[{key:"updateToken",value:function(e){I.info("updateToken"),this.config.updateToken(e)}},{key:"get",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,t.network.get("".concat(t.config.mediaUrl,"/").concat(e));case 2:return r=n.sent,n.abrupt("return",new Media(t.config,t.network,r.body));case 4:case"end":return n.stop()}}),n)})))()}},{key:"post",value:function(e,t,n,r){var i=this;return l.default(d.default.mark((function a(){var s;return d.default.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,i.network.post(i.config.mediaUrl,null!=n?n:"media",t,e,r);case 2:return s=a.sent,a.abrupt("return",new Media(i.config,i.network,s.body));case 4:case"end":return a.stop()}}),a)})))()}},{key:"postFormData",value:function(e,t){var n=this;return l.default(d.default.mark((function r(){var i;return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,n.network.post(n.config.mediaUrl,null!=t?t:"media",e);case 2:return i=r.sent,r.abrupt("return",new Media(n.config,n.network,i.body));case 4:case"end":return r.stop()}}),r)})))()}},{key:"mediaSetGet",value:function(e){var t=this;return l.default(d.default.mark((function n(){var r,i;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r={command:"get",list:e.map((function(e){return{media_sid:e}}))},n.next=3,t.network.post("".concat(t.config.mediaSetUrl),null,r,"application/json");case 3:return i=n.sent,n.abrupt("return",i.body.map((function(e){if(200!==e.code)throw new Error("Failed to obtain detailed information about Media items (failed SID ".concat(e.media_record.sid,")"));return new Media(t.config,t.network,e.media_record)})));case 5:case"end":return n.stop()}}),n)})))()}}]),Client}(),f.default(_,"version","0.5.3-rc.0"),S),h([o.validateTypes(o.nonEmptyString),v("design:type",Function),v("design:paramtypes",[String]),v("design:returntype",void 0)],e.default.prototype,"updateToken",null),h([o.validateTypesAsync(o.nonEmptyString),v("design:type",Function),v("design:paramtypes",[String]),v("design:returntype",Promise)],e.default.prototype,"get",null),e.default=h([o.validateConstructorTypes(o.nonEmptyString,o.nonEmptyString,[o.nonEmptyString,o.literal(null)],[o.pureObject,"undefined"]),v("design:paramtypes",[String,String,Object,Object])],e.default),e.Client=e.default,e.McsClient=e.default,e.McsMedia=Media,e.Media=Media,e.default=e.default}($R);var rP=is,iP="ArrayBuffer",aP=Gk.ArrayBuffer;function sP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}In({global:!0,forced:i.ArrayBuffer!==aP},{ArrayBuffer:aP}),rP(iP);var oP=rd.scope("Participant"),Participant=function(e){Oa(Participant,e);var t,n,r,i=sP(Participant);function Participant(e,t,n,r,a){var s,o,u;if(Ma(this,Participant),(u=i.call(this)).conversation=n,u.links=r,u.services=a,u.state={attributes:nh(e.attributes,"Retrieved malformed attributes from the server for participant: "+t,oP),dateCreated:e.dateCreated?th(e.dateCreated):null,dateUpdated:e.dateCreated?th(e.dateUpdated):null,sid:t,typingTimeout:null,isTyping:!1,identity:e.identity,roleSid:null!==(s=e.roleSid)&&void 0!==s?s:"",lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,lastReadTimestamp:e.lastConsumptionTimestamp?th(e.lastConsumptionTimestamp):null,type:e.type||"chat",userInfo:e.userInfo,bindings:null!==(o=e.bindings)&&void 0!==o?o:{}},!e.identity&&!e.type)throw new Error("Received invalid Participant object from server: Missing identity or type of Participant.");return u}return Ta(Participant,[{key:"sid",get:function(){return this.state.sid}},{key:"attributes",get:function(){return this.state.attributes}},{key:"dateCreated",get:function(){return this.state.dateCreated}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"identity",get:function(){return this.state.identity}},{key:"isTyping",get:function(){return this.state.isTyping}},{key:"lastReadMessageIndex",get:function(){return this.state.lastReadMessageIndex}},{key:"lastReadTimestamp",get:function(){return this.state.lastReadTimestamp}},{key:"roleSid",get:function(){return this.state.roleSid}},{key:"type",get:function(){return this.state.type}},{key:"bindings",get:function(){var e;return null!==(e=this.state.bindings)&&void 0!==e?e:{}}},{key:"_startTyping",value:function(e){var t=this;return this.state.typingTimeout&&clearTimeout(this.state.typingTimeout),this.state.isTyping=!0,this.emit("typingStarted",this),this.conversation.emit("typingStarted",this),this.state.typingTimeout=Number(setTimeout((function(){return t._endTyping()}),e)),this}},{key:"_endTyping",value:function(){this.state.typingTimeout&&(this.state.isTyping=!1,this.emit("typingEnded",this),this.conversation.emit("typingEnded",this),clearInterval(this.state.typingTimeout),this.state.typingTimeout=null)}},{key:"_update",value:function(e){var t=[],n=nh(e.attributes,"Retrieved malformed attributes from the server for participant: "+this.state.sid,oP);e.attributes&&!By(this.state.attributes,n)&&(this.state.attributes=n,t.push("attributes"));var r=th(e.dateUpdated);e.dateUpdated&&(null==r?void 0:r.getTime())!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=r,t.push("dateUpdated"));var i=th(e.dateCreated);if(e.dateCreated&&(null==i?void 0:i.getTime())!==(this.state.dateCreated&&this.state.dateCreated.getTime())&&(this.state.dateCreated=i,t.push("dateCreated")),e.roleSid&&this.state.roleSid!==e.roleSid&&(this.state.roleSid=e.roleSid,t.push("roleSid")),!Number.isInteger(e.lastConsumedMessageIndex)&&null!==e.lastConsumedMessageIndex||this.state.lastReadMessageIndex===e.lastConsumedMessageIndex||(this.state.lastReadMessageIndex=e.lastConsumedMessageIndex,t.push("lastReadMessageIndex")),e.lastConsumptionTimestamp){var a=new Date(e.lastConsumptionTimestamp);this.state.lastReadTimestamp&&this.state.lastReadTimestamp.getTime()===a.getTime()||(this.state.lastReadTimestamp=a,t.push("lastReadTimestamp"))}return e.bindings&&!By(this.state.bindings,e.bindings)&&(this.state.bindings=e.bindings,t.push("bindings")),t.length>0&&this.emit("updated",{participant:this,updateReasons:t}),this}},{key:"getUser",value:(r=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("chat"==this.type){e.next=2;break}throw new Error("Getting User is not supported for this Participant type: "+this.type);case 2:return e.abrupt("return",this.services.users.getUser(this.state.identity,this.state.userInfo));case 3:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"remove",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.conversation.removeParticipant(this));case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"updateAttributes",value:(t=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:JSON.stringify(t)});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Participant}(Dy);function uP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}ja(Participant,"typingStarted","typingStarted"),ja(Participant,"typingEnded","typingEnded"),ja(Participant,"updated","updated"),wl([Xv(Zv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Participant.prototype,"updateAttributes",null);var cP=rd.scope("Participants"),lP=function(e){Oa(u,e);var t,n,r,i,a,s,o=uP(u);function u(e,t,n,r,i){var a;return Ma(this,u),ja(Ra(a=o.call(this)),"rosterEntityPromise",null),a.conversation=e,a.participants=t,a.links=n,a.configuration=r,a.services=i,a}return Ta(u,[{key:"unsubscribe",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.rosterEntityPromise){e.next=6;break}return e.next=3,this.rosterEntityPromise;case 3:e.sent.close(),this.rosterEntityPromise=null;case 6:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"subscribe",value:function(e){var t=this;return this.rosterEntityPromise=this.rosterEntityPromise||this.services.syncClient.map({id:e,mode:"open_existing"}).then((function(e){e.on("itemAdded",(function(e){cP.debug(t.conversation.sid+" itemAdded: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data).then((function(e){t.emit("participantJoined",e)}))})),e.on("itemRemoved",(function(e){cP.debug(t.conversation.sid+" itemRemoved: "+e.key);var n=e.key;if(t.participants.has(n)){var r=t.participants.get(n);t.participants.delete(n),r&&t.emit("participantLeft",r)}})),e.on("itemUpdated",(function(e){cP.debug(t.conversation.sid+" itemUpdated: "+e.item.key),t.upsertParticipant(e.item.key,e.item.data)}));var n=[];return e.getItems().then((function e(r){return r.items.forEach((function(e){n.push(t.upsertParticipant(e.key,e.data))})),r.hasNextPage?r.nextPage().then(e):null})).then((function(){return Promise.all(n)})).then((function(){return e}))})).catch((function(e){throw t.rosterEntityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&cP.error("Failed to get roster object for conversation",t.conversation.sid,e),cP.debug("ERROR: Failed to get roster object for conversation",t.conversation.sid,e),e}))}},{key:"upsertParticipant",value:(a=Sa(bl.mark((function e(t,n){var r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=this.participants.get(t))){e.next=3;break}return e.abrupt("return",r._update(n));case 3:return i={self:"".concat(this.links.participants,"/").concat(t)},r=new Participant(n,t,this.conversation,i,this.services),this.participants.set(t,r),r.on("updated",(function(e){return a.emit("participantUpdated",e)})),e.abrupt("return",r);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"getParticipants",value:(i=Sa(bl.mark((function e(){var t=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){var e=[];return t.participants.forEach((function(t){return e.push(t)})),e})):[]);case 1:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"getParticipantBySid",value:(r=Sa(bl.mark((function e(t){var n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){var e=n.participants.get(t);if(!e)throw new Error("Participant with SID "+t+" was not found");return e})):null);case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(n=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.abrupt("return",this.rosterEntityPromise?this.rosterEntityPromise.then((function(){if(r.participants.forEach((function(e){e.identity===t&&(n=e)})),!n)throw new Error("Participant with identity "+t+" was not found");return n})):null);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"add",value:(t=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:t,attributes:void 0!==n?JSON.stringify(n):void 0});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,n){return t.apply(this,arguments)})},{key:"addNonChatParticipant",value:function(e,t){var n,r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return this.services.commandExecutor.mutateResource("post",this.links.participants,{attributes:void 0!==i?JSON.stringify(i):void 0,messaging_binding:{address:t,proxy_address:e,name:null==a||null===(n=a.email)||void 0===n?void 0:n.name,level:null==a||null===(r=a.email)||void 0===r?void 0:r.level}})}},{key:"remove",value:function(e){return this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(e))}}]),u}(Dy),fP=In,dP=On,pP=Q,hP=Ut,vP=gr,yP=s,mP=T_,gP=ec,bP=I_,kP=O_,wP=L,xP=P_,_P=[],SP=_P.sort,EP=yP((function(){_P.sort(void 0)})),TP=yP((function(){_P.sort(null)})),RP=gP("sort"),IP=!yP((function(){if(wP)return wP<70;if(!(bP&&bP>3)){if(kP)return!0;if(xP)return xP<603;var e,t,n,r,i="";for(e=65;e<76;e++){switch(t=String.fromCharCode(e),e){case 66:case 69:case 70:case 72:n=3;break;case 68:case 71:n=4;break;default:n=2}for(r=0;r<47;r++)_P.push({k:t+r,v:n})}for(_P.sort((function(e,t){return t.v-e.v})),r=0;r<_P.length;r++)t=_P[r].k.charAt(0),i.charAt(i.length-1)!==t&&(i+=t);return"DGBEFHACIJK"!==i}}));fP({target:"Array",proto:!0,forced:EP||!TP||!RP||!IP},{sort:function(e){void 0!==e&&dP(e);var t=pP(this);if(IP)return void 0===e?SP.call(t):SP.call(t,e);var n,r,i=[],a=hP(t.length);for(r=0;r<a;r++)r in t&&i.push(t[r]);for(n=(i=mP(i,function(e){return function(t,n){return void 0===n?-1:void 0===t?1:void 0!==e?+e(t,n)||0:vP(t)>vP(n)?1:-1}}(e))).length,r=0;r<n;)t[r]=i[r++];for(;r<a;)delete t[r++];return t}});var OP=JR,CP=k,PP=gr;In({target:"String",proto:!0,forced:!HR("includes")},{includes:function(e){return!!~PP(CP(this)).indexOf(PP(OP(e)),arguments.length>1?arguments[1]:void 0)}});var Media=function(){function Media(e,t){Ma(this,Media),ja(this,"mcsMedia",null),this.services=t,e instanceof $R.McsMedia&&(this.mcsMedia=e),this.state={sid:e.sid,category:e.category,filename:e.filename,contentType:e.contentType,size:e.size}}var e,t,n;return Ta(Media,[{key:"sid",get:function(){return this.state.sid}},{key:"filename",get:function(){return this.state.filename}},{key:"contentType",get:function(){return this.state.contentType}},{key:"size",get:function(){return this.state.size}},{key:"category",get:function(){return this.state.category}},{key:"getContentTemporaryUrl",value:(n=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._fetchMcsMedia();case 2:return e.abrupt("return",null!==(t=null===(n=this.mcsMedia)||void 0===n?void 0:n.getContentUrl())&&void 0!==t?t:null);case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getCachedTemporaryUrl",value:(t=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._fetchMcsMedia();case 2:return e.abrupt("return",null!==(t=null===(n=this.mcsMedia)||void 0===n?void 0:n.getCachedContentUrl())&&void 0!==t?t:null);case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_fetchMcsMedia",value:(e=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.mcsMedia){e.next=8;break}if(!this.services.mcsClient){e.next=7;break}return e.next=4,this.services.mcsClient.get(this.state.sid);case 4:this.mcsMedia=e.sent,e.next=8;break;case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(){return e.apply(this,arguments)})}]),Media}(),AggregatedDeliveryReceipt=function(){function AggregatedDeliveryReceipt(e){Ma(this,AggregatedDeliveryReceipt),this.state=e}return Ta(AggregatedDeliveryReceipt,[{key:"total",get:function(){return this.state.total}},{key:"sent",get:function(){return this.state.sent}},{key:"delivered",get:function(){return this.state.delivered}},{key:"read",get:function(){return this.state.read}},{key:"undelivered",get:function(){return this.state.undelivered}},{key:"failed",get:function(){return this.state.failed}},{key:"_update",value:function(e){this.state=e}},{key:"_isEquals",value:function(e){var t=this.total===e.total,n=this.sent===e.sent,r=this.delivered===e.delivered,i=this.read===e.read,a=this.undelivered===e.undelivered,s=this.failed===e.failed;return t&&n&&r&&i&&a&&s}}]),AggregatedDeliveryReceipt}(),AP=function(){function e(t,n,r,i){Ma(this,e),this.state={prevToken:r,nextToken:i,source:n,items:t}}return Ta(e,[{key:"hasNextPage",get:function(){return!!this.state.nextToken}},{key:"hasPrevPage",get:function(){return!!this.state.prevToken}},{key:"items",get:function(){return this.state.items}},{key:"nextPage",value:function(){return this.hasNextPage?this.state.source(this.state.nextToken):Promise.reject(new Error("No next page"))}},{key:"prevPage",value:function(){return this.hasPrevPage?this.state.source(this.state.prevToken):Promise.reject(new Error("No previous page"))}}]),e}(),DetailedDeliveryReceipt=function DetailedDeliveryReceipt(e){Ma(this,DetailedDeliveryReceipt),this.sid=e.sid,this.messageSid=e.message_sid,this.conversationSid=e.conversation_sid,this.channelMessageSid=e.channel_message_sid,this.participantSid=e.participant_sid,this.status=e.status||"queued",this.errorCode=e.error_code||0,this.dateCreated=e.date_created,this.dateUpdated=e.date_updated};function jP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var MP=rd.scope("Message"),Message=function(e){Oa(Message,e);var t,n,r,i,a,s,o,u=jP(Message);function Message(e,t,n,r,i,a){var s,o,c,l,f;return Ma(this,Message),(f=u.call(this)).conversation=n,f.links=r,f.configuration=i,f.services=a,f.state={sid:t.sid,index:e,author:t.author,subject:t.subject,body:null!==(s=t.text)&&void 0!==s?s:null,timestamp:t.timestamp?new Date(t.timestamp):null,dateUpdated:t.dateUpdated?new Date(t.dateUpdated):null,lastUpdatedBy:null!==(o=t.lastUpdatedBy)&&void 0!==o?o:null,attributes:nh(t.attributes,"Got malformed attributes for the message ".concat(t.sid),MP),type:null!==(c=t.type)&&void 0!==c?c:"text",media:t.type&&"media"===t.type&&t.media?new Media(t.media,f.services):null,medias:t.type&&"media"===t.type&&t.medias?t.medias.map((function(e){return new Media(e,f.services)})):null,participantSid:null!==(l=t.memberSid)&&void 0!==l?l:null,aggregatedDeliveryReceipt:t.delivery?new AggregatedDeliveryReceipt(t.delivery):null},f}return Ta(Message,[{key:"sid",get:function(){return this.state.sid}},{key:"author",get:function(){return this.state.author}},{key:"subject",get:function(){return this.state.subject}},{key:"body",get:function(){return this.state.body}},{key:"dateUpdated",get:function(){return this.state.dateUpdated}},{key:"index",get:function(){return this.state.index}},{key:"lastUpdatedBy",get:function(){return this.state.lastUpdatedBy}},{key:"dateCreated",get:function(){return this.state.timestamp}},{key:"attributes",get:function(){return this.state.attributes}},{key:"type",get:function(){return this.state.type}},{key:"media",get:function(){return this.state.media}},{key:"attachedMedia",get:function(){return this.getMediaByCategory(["media"])}},{key:"participantSid",get:function(){return this.state.participantSid}},{key:"aggregatedDeliveryReceipt",get:function(){return this.state.aggregatedDeliveryReceipt}},{key:"getMediaByCategory",value:function(e){var t;return(null!==(t=this.state.medias)&&void 0!==t?t:[]).filter((function(t){return e.includes(t.category)}))}},{key:"getEmailBody",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategory(["body"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"getEmailHistory",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategory(["history"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"_update",value:function(e){var t=[];!e.text&&"string"!=typeof e.text||e.text===this.state.body||(this.state.body=e.text,t.push("body")),e.subject&&e.subject!==this.state.subject&&(this.state.subject=e.subject,t.push("subject")),e.lastUpdatedBy&&e.lastUpdatedBy!==this.state.lastUpdatedBy&&(this.state.lastUpdatedBy=e.lastUpdatedBy,t.push("lastUpdatedBy")),e.author&&e.author!==this.state.author&&(this.state.author=e.author,t.push("author")),e.dateUpdated&&new Date(e.dateUpdated).getTime()!==(this.state.dateUpdated&&this.state.dateUpdated.getTime())&&(this.state.dateUpdated=new Date(e.dateUpdated),t.push("dateUpdated")),e.timestamp&&new Date(e.timestamp).getTime()!==(this.state.timestamp&&this.state.timestamp.getTime())&&(this.state.timestamp=new Date(e.timestamp),t.push("dateCreated"));var n=nh(e.attributes,"Got malformed attributes for the message ".concat(this.sid),MP);By(this.state.attributes,n)||(this.state.attributes=n,t.push("attributes"));var r=e.delivery,i=this.state.aggregatedDeliveryReceipt;!!(r&&r.total&&r.delivered&&r.failed&&r.read&&r.sent&&r.undelivered)&&(i?i._isEquals(r)||(i._update(r),t.push("deliveryReceipt")):(this.state.aggregatedDeliveryReceipt=new AggregatedDeliveryReceipt(r),t.push("deliveryReceipt"))),t.length>0&&this.emit("updated",{message:this,updateReasons:t})}},{key:"getParticipant",value:(o=Sa(bl.mark((function e(){var t,n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=null,!this.state.participantSid){e.next=5;break}return e.next=4,this.conversation.getParticipantBySid(this.state.participantSid).catch((function(){return MP.debug('Participant with sid "'.concat(r.participantSid,'" not found for message ').concat(r.sid)),null}));case 4:t=e.sent;case 5:if(t||!this.state.author){e.next=9;break}return e.next=8,this.conversation.getParticipantByIdentity(this.state.author).catch((function(){return MP.debug('Participant with identity "'.concat(r.author,'" not found for message ').concat(r.sid)),null}));case 8:t=e.sent;case 9:if(!t){e.next=11;break}return e.abrupt("return",t);case 11:throw n="Participant with ",this.state.participantSid&&(n+="SID '"+this.state.participantSid+"' "),this.state.author&&(this.state.participantSid&&(n+="or "),n+="identity '"+this.state.author+"' "),"Participant with "===n&&(n="Participant "),n+="was not found",new Error(n);case 17:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"getDetailedDeliveryReceipts",value:(s=Sa(bl.mark((function e(){var t,n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getDetailedDeliveryReceiptsPaginator();case 2:t=e.sent,n=[];case 4:if(n=[].concat(nP(n),nP(t.items)),t.hasNextPage){e.next=8;break}return e.abrupt("break",13);case 8:return e.next=10,t.nextPage();case 10:t=e.sent,e.next=4;break;case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"remove",value:(a=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("delete",this.links.self);case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"updateBody",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{body:t});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateAttributes",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"attachTemporaryUrlsFor",value:(n=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=null==t?void 0:t.map((function(e){return e.sid})),!this.services.mcsClient||!n){e.next=7;break}return e.next=4,this.services.mcsClient.mediaSetGet(n);case 4:return e.abrupt("return",e.sent.map((function(e){return new Media(e,r.services)})));case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"_getDetailedDeliveryReceiptsPaginator",value:(t=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.configuration.links.messagesReceipts.replace("%s",this.conversation.sid).replace("%s",this.sid),r=new rh(n).arg("PageToken",null==t?void 0:t.pageToken).arg("PageSize",null==t?void 0:t.pageSize).build(),e.next=4,this.services.network.get(r);case 4:return i=e.sent,e.abrupt("return",new AP(i.body.delivery_receipts.map((function(e){return new DetailedDeliveryReceipt(e)})),(function(e,t){return a._getDetailedDeliveryReceiptsPaginator({pageToken:e,pageSize:t})}),i.body.meta.previous_token,i.body.meta.next_token));case 6:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),Message}(Dy);function LP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return NP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return NP(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function NP(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function UP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}ja(Message,"updated","updated"),wl([Qv([Vv,"undefined"]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Media)],Message.prototype,"getEmailBody",null),wl([Qv([Vv,"undefined"]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Media)],Message.prototype,"getEmailHistory",null),wl([Xv("string"),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Message.prototype,"updateBody",null),wl([Xv(Zv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Message.prototype,"updateAttributes",null),wl([Xv(Gv((function(e){return[e instanceof Array&&e.length>0&&e.reduce((function(e,t){return e&&t instanceof Media}),!0),"a non-empty array of Media"]}))),xl("design:type",Function),xl("design:paramtypes",[Array]),xl("design:returntype",Promise)],Message.prototype,"attachTemporaryUrlsFor",null);var DP=rd.scope("Messages"),FP=function(e){Oa(c,e);var t,n,r,i,a,s,o,u=UP(c);function c(e,t,n){var r;return Ma(this,c),(r=u.call(this)).conversation=e,r.configuration=t,r.services=n,r.messagesByIndex=new Map,r.messagesListPromise=null,r}return Ta(c,[{key:"subscribe",value:(o=Sa(bl.mark((function e(t){var n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.messagesListPromise){e.next=2;break}return e.abrupt("return",this.messagesListPromise);case 2:return this.messagesListPromise=this.services.syncClient.list({id:t,mode:"open_existing"}),e.prev=3,e.next=6,this.messagesListPromise;case 6:return(n=e.sent).on("itemAdded",(function(e){DP.debug("".concat(r.conversation.sid," itemAdded: ").concat(e.item.index));var t={self:"".concat(r.conversation.links.messages,"/").concat(e.item.data.sid),conversation:r.conversation.links.self,messages_receipts:"".concat(r.conversation.links.messages,"/").concat(e.item.data.sid,"/Receipts")},n=new Message(e.item.index,e.item.data,r.conversation,t,r.configuration,r.services);r.messagesByIndex.has(n.index)?DP.debug("Message arrived, but is already known and ignored",r.conversation.sid,n.index):(r.messagesByIndex.set(n.index,n),n.on("updated",(function(e){return r.emit("messageUpdated",e)})),r.emit("messageAdded",n))})),n.on("itemRemoved",(function(e){DP.debug("#{this.conversation.sid} itemRemoved: ".concat(e.index));var t=e.index;if(r.messagesByIndex.has(t)){var n=r.messagesByIndex.get(t);if(!n)return;r.messagesByIndex.delete(n.index),n.removeAllListeners("updated"),r.emit("messageRemoved",n)}})),n.on("itemUpdated",(function(e){DP.debug("".concat(r.conversation.sid," itemUpdated: ").concat(e.item.index));var t=r.messagesByIndex.get(e.item.index);t&&t._update(e.item.data)})),e.abrupt("return",n);case 13:throw e.prev=13,e.t0=e.catch(3),this.messagesListPromise=null,"disconnected"!==this.services.syncClient.connectionState&&DP.error("Failed to get messages object for conversation",this.conversation.sid,e.t0),DP.debug("ERROR: Failed to get messages object for conversation",this.conversation.sid,e.t0),e.t0;case 19:case"end":return e.stop()}}),e,this,[[3,13]])}))),function(e){return o.apply(this,arguments)})},{key:"unsubscribe",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.messagesListPromise){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.messagesListPromise;case 4:e.sent.close(),this.messagesListPromise=null;case 7:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"sendV2",value:(a=Sa(bl.mark((function e(t){var n,r,i,a,s,o,u,c,l;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:DP.debug("Sending message V2",t.mediaContent,t.attributes,t.emailOptions),r=[],i=LP(t.mediaContent),e.prev=3,i.s();case 5:if((a=i.n()).done){e.next=22;break}if(u=$y(a.value,2),c=u[0],l=u[1],DP.debug("Adding media to a message as ".concat(l instanceof FormData?"FormData":"SendMediaOptions"),l),e.t0=r,!(l instanceof FormData)){e.next=15;break}return e.next=12,this.services.mcsClient.postFormData(l,c);case 12:e.t1=e.sent,e.next=18;break;case 15:return e.next=17,this.services.mcsClient.post(null!==(s=l.contentType)&&void 0!==s?s:"",null!==(o=l.media)&&void 0!==o?o:"",c,l.filename);case 17:e.t1=e.sent;case 18:e.t2=e.t1,e.t0.push.call(e.t0,e.t2);case 20:e.next=5;break;case 22:e.next=27;break;case 24:e.prev=24,e.t3=e.catch(3),i.e(e.t3);case 27:return e.prev=27,i.f(),e.finish(27);case 30:return e.next=32,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{body:t.text,subject:null===(n=t.emailOptions)||void 0===n?void 0:n.subject,media_sids:r.map((function(e){return e.sid})),attributes:void 0!==t.attributes?JSON.stringify(t.attributes):void 0});case 32:return e.abrupt("return",e.sent);case 33:case"end":return e.stop()}}),e,this,[[3,24,27,30]])}))),function(e){return a.apply(this,arguments)})},{key:"send",value:(i=Sa(bl.mark((function e(t){var n,r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]?i[1]:{},r=i.length>2?i[2]:void 0,DP.debug("Sending text message",t,n,r),e.next=5,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{body:null!=t?t:"",attributes:void 0!==n?JSON.stringify(n):void 0,subject:null==r?void 0:r.subject});case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"sendMedia",value:(r=Sa(bl.mark((function e(t){var n,r,i,a,s,o=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=o.length>1&&void 0!==o[1]?o[1]:{},a=o.length>2?o[2]:void 0,DP.debug("Sending media message",t,i,a),DP.debug("Sending media message as ".concat(t instanceof FormData?"FormData":"SendMediaOptions"),t,i),!(t instanceof FormData)){e.next=10;break}return e.next=7,this.services.mcsClient.postFormData(t);case 7:e.t0=e.sent,e.next=13;break;case 10:return e.next=12,this.services.mcsClient.post(null!==(n=t.contentType)&&void 0!==n?n:"",null!==(r=t.media)&&void 0!==r?r:"","media",t.filename);case 12:e.t0=e.sent;case 13:return s=e.t0,e.next=16,this.services.commandExecutor.mutateResource("post",this.conversation.links.messages,{media_sids:[s.sid],attributes:void 0!==i?JSON.stringify(i):void 0});case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getMessages",value:(n=Sa(bl.mark((function e(t,n){var r,i=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=i.length>2&&void 0!==i[2]?i[2]:"backwards",e.abrupt("return",this._getMessages(t,n,r));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"_wrapPaginator",value:function(e,t,n){var r=this,i="desc"===e,a=function(){return t.nextPage().then((function(t){return r._wrapPaginator(e,t,n)}))},s=function(){return t.prevPage().then((function(t){return r._wrapPaginator(e,t,n)}))};return n(t.items).then((function(e){return{items:e.sort((function(e,t){return e.index-t.index})),hasPrevPage:i?t.hasNextPage:t.hasPrevPage,hasNextPage:i?t.hasPrevPage:t.hasNextPage,prevPage:i?a:s,nextPage:i?s:a}}))}},{key:"_upsertMessage",value:function(e,t){var n=this,r=this.messagesByIndex.get(e);if(r)return r;var i={self:"".concat(this.conversation.links.messages,"/").concat(t.sid),conversation:this.conversation.links.self,messages_receipts:"".concat(this.conversation.links.messages,"/").concat(t.sid,"/Receipts")},a=new Message(e,t,this.conversation,i,this.configuration,this.services);return this.messagesByIndex.set(a.index,a),a.on("updated",(function(e){return n.emit("messageUpdated",e)})),a}},{key:"_getMessages",value:(t=Sa(bl.mark((function e(){var t,n,r,i,a,s,o=this,u=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:30,n=u.length>1&&void 0!==u[1]?u[1]:"end",r=u.length>2&&void 0!==u[2]?u[2]:"forward",i="backwards"===r?"desc":"asc",e.next=6,this.messagesListPromise;case 6:return a=e.sent,e.next=9,null==a?void 0:a.getItems({from:"end"!==n?n:void 0,pageSize:t,order:i,limit:t});case 9:return s=e.sent,e.next=12,this._wrapPaginator(i,s,(function(e){return Promise.all(e.map((function(e){return o._upsertMessage(e.index,e.data)})))}));case 12:return e.abrupt("return",e.sent);case 13:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),c}(Dy),BP=function(){function e(t){Ma(this,e),ja(this,"attributes",{}),ja(this,"mediaContent",[]),ja(this,"emailOptions",{}),this.messagesEntity=t}var t;return Ta(e,[{key:"send",value:(t=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.messagesEntity.sendV2(this);case 2:return t=e.sent,e.abrupt("return",eh(t.index));case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),qP=function(){function e(t,n){Ma(this,e),this.limits=t,this.message=new BP(n),this.emailBodies=new Map,this.emailHistories=new Map}return Ta(e,[{key:"setBody",value:function(e){return this.message.text=e,this}},{key:"setSubject",value:function(e){return this.message.emailOptions.subject=e,this}},{key:"setAttributes",value:function(e){return this.message.attributes=e,this}},{key:"setEmailBody",value:function(e,t){return this.emailBodies.set(e,t),this}},{key:"setEmailHistory",value:function(e,t){return this.emailHistories.set(e,t),this}},{key:"addMedia",value:function(e){if("undefined"==typeof FormData&&e instanceof FormData)throw new Error("Could not add FormData content whilst not in a browser");if(!(e instanceof FormData)){var t=e;if(!t.contentType||!t.media)throw new Error("Media content in SendMediaOptions must contain non-empty contentType and media")}return this.message.mediaContent.push(["media",e]),this}},{key:"build",value:function(){var e=this;if(this.emailBodies.forEach((function(t,n){if(!e.limits.emailBodiesAllowedMimeTypes.includes(n))throw new Error("Unsupported email body MIME type ".concat(n))})),this.emailHistories.forEach((function(t,n){if(!e.limits.emailHistoriesAllowedMimeTypes.includes(n))throw new Error("Unsupported email history MIME type ".concat(n))})),this.emailBodies.size>this.limits.emailBodiesAllowedMimeTypes.length)throw new Error("Too many email bodies attached to the message (".concat(this.emailBodies.size," > ").concat(this.limits.emailBodiesAllowedMimeTypes.length,")"));if(this.emailHistories.size>this.limits.emailHistoriesAllowedMimeTypes.length)throw new Error("Too many email histories attached to the message (".concat(this.emailHistories.size," > ").concat(this.limits.emailHistoriesAllowedMimeTypes.length,")"));if(this.message.mediaContent.length>this.limits.mediaAttachmentsCountLimit)throw new Error("Too many media attachments in the message (".concat(this.message.mediaContent.length," > ").concat(this.limits.mediaAttachmentsCountLimit,")"));return this.emailBodies.forEach((function(t){e.message.mediaContent.push(["body",t])})),this.emailHistories.forEach((function(t){e.message.mediaContent.push(["history",t])})),this.message}},{key:"getPayloadContentType",value:function(e){return"undefined"!=typeof FormData&&e instanceof FormData?e.get("Content-Type"):e.contentType}}]),e}();function zP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return WP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return WP(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function WP(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function GP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var $P=rd.scope("Conversation"),VP={lastMessage:"lastMessage",attributes:"attributes",createdBy:"createdBy",dateCreated:"dateCreated",dateUpdated:"dateUpdated",friendlyName:"friendlyName",lastConsumedMessageIndex:"lastConsumedMessageIndex",notificationLevel:"notificationLevel",sid:"sid",status:"status",uniqueName:"uniqueName",state:"state",bindings:"bindings"};function JP(e){try{return new Date(e)}catch(e){return null}}var Conversation=function(e){Oa(Conversation,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v,y,m,g,b,k,w,x,_,S,E,T,R=GP(Conversation);function Conversation(e,t,n,r,i){var a,s;Ma(this,Conversation),(s=R.call(this)).sid=t,s.links=n,s.configuration=r,s.services=i;var o=e.attributes||{},u=e.createdBy,c=JP(e.dateCreated),l=JP(e.dateUpdated),f=e.friendlyName||null,d=Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,p=e.uniqueName||null;try{JSON.stringify(o)}catch(e){throw new Error("Attributes must be a valid JSON object.")}s.entityName=e.channel,s.channelState={uniqueName:p,status:"notParticipating",attributes:o,createdBy:u,dateCreated:c,dateUpdated:l,friendlyName:f,lastReadMessageIndex:d,bindings:null!==(a=e.bindings)&&void 0!==a?a:{}},e.notificationLevel&&(s.channelState.notificationLevel=e.notificationLevel);var h={participants:s.links.participants};return s.participants=new Map,s.participantsEntity=new lP(Ra(s),s.participants,h,s.configuration,s.services),s.participantsEntity.on("participantJoined",(function(e){return s.emit("participantJoined",e)})),s.participantsEntity.on("participantLeft",(function(e){return s.emit("participantLeft",e)})),s.participantsEntity.on("participantUpdated",(function(e){return s.emit("participantUpdated",e)})),s.messagesEntity=new FP(Ra(s),r,i),s.messagesEntity.on("messageAdded",(function(e){return s._onMessageAdded(e)})),s.messagesEntity.on("messageUpdated",(function(e){return s.emit("messageUpdated",e)})),s.messagesEntity.on("messageRemoved",(function(e){return s.emit("messageRemoved",e)})),s}return Ta(Conversation,[{key:"uniqueName",get:function(){return this.channelState.uniqueName}},{key:"status",get:function(){return this.channelState.status}},{key:"friendlyName",get:function(){return this.channelState.friendlyName}},{key:"dateUpdated",get:function(){return this.channelState.dateUpdated}},{key:"dateCreated",get:function(){return this.channelState.dateCreated}},{key:"createdBy",get:function(){var e;return null!==(e=this.channelState.createdBy)&&void 0!==e?e:""}},{key:"attributes",get:function(){return this.channelState.attributes}},{key:"lastReadMessageIndex",get:function(){return this.channelState.lastReadMessageIndex}},{key:"lastMessage",get:function(){var e;return null!==(e=this.channelState.lastMessage)&&void 0!==e?e:void 0}},{key:"notificationLevel",get:function(){var e;return null!==(e=this.channelState.notificationLevel)&&void 0!==e?e:"default"}},{key:"bindings",get:function(){return this.channelState.bindings}},{key:"limits",get:function(){return this.configuration.limits}},{key:"state",get:function(){return this.channelState.state}},{key:"_subscribe",value:function(){var e,t=this;return this.entityPromise=null!==(e=this.entityPromise)&&void 0!==e?e:this.services.syncClient.document({id:this.entityName,mode:"open_existing"}).then((function(e){return t.entity=e,t.entity.on("updated",(function(e){t._update(e.data)})),t.entity.on("removed",(function(){return t.emit("removed",t)})),t._update(t.entity.data),e})).catch((function(e){throw t.entity=null,t.entityPromise=null,"disconnected"!=t.services.syncClient.connectionState&&$P.error("Failed to get conversation object",e),$P.debug("ERROR: Failed to get conversation object",e),e}))}},{key:"_subscribeStreams",value:(T=Sa(bl.mark((function e(){var t,n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._subscribe();case 3:return $P.trace("_subscribeStreams, this.entity.data=",null===(t=this.entity)||void 0===t?void 0:t.data),i=null===(n=this.entity)||void 0===n?void 0:n.data.messages,a=null===(r=this.entity)||void 0===r?void 0:r.data.roster,e.next=8,Promise.all([this.messagesEntity.subscribe(i),this.participantsEntity.subscribe(a)]);case 8:e.next=15;break;case 10:throw e.prev=10,e.t0=e.catch(0),"disconnected"!==this.services.syncClient.connectionState&&$P.error("Failed to subscribe on conversation objects",this.sid,e.t0),$P.debug("ERROR: Failed to subscribe on conversation objects",this.sid,e.t0),e.t0;case 15:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(){return T.apply(this,arguments)})},{key:"_unsubscribe",value:(E=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.entity){e.next=5;break}return e.next=3,this.entity.close();case 3:this.entity=null,this.entityPromise=null;case 5:return e.abrupt("return",Promise.all([this.participantsEntity.unsubscribe(),this.messagesEntity.unsubscribe()]));case 6:case"end":return e.stop()}}),e,this)}))),function(){return E.apply(this,arguments)})},{key:"_setStatus",value:function(e,t){var n=this;this.statusSource=t,this.channelState.status!==e&&(this.channelState.status=e,"joined"===e?this._subscribeStreams().catch((function(t){if($P.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n.services.syncClient.connectionState)throw t})):this.entityPromise&&this._unsubscribe().catch((function(t){if($P.debug("ERROR while setting conversation status "+e,t),"disconnected"!==n.services.syncClient.connectionState)throw t})))}},{key:"_statusSource",value:function(){return this.statusSource}},{key:"_update",value:function(e){var t,n,r,i,a;$P.trace("_update",e),Conversation.preprocessUpdate(e,this.sid);for(var s=new Set,o=0,u=Object.keys(e);o<u.length;o++){var c=u[o],l=VP[c];if(l)switch(l){case VP.status:if(!e.status||"unknown"===e.status||this.channelState.status===e.status)break;this.channelState.status=e.status,s.add(l);break;case VP.attributes:if(By(this.channelState.attributes,e.attributes))break;this.channelState.attributes=e.attributes,s.add(l);break;case VP.lastConsumedMessageIndex:if(void 0===e.lastConsumedMessageIndex||e.lastConsumedMessageIndex===this.channelState.lastReadMessageIndex)break;this.channelState.lastReadMessageIndex=e.lastConsumedMessageIndex,s.add("lastReadMessageIndex");break;case VP.lastMessage:if(this.channelState.lastMessage&&!e.lastMessage){delete this.channelState.lastMessage,s.add(l);break}this.channelState.lastMessage=this.channelState.lastMessage||{},void 0!==(null===(t=e.lastMessage)||void 0===t?void 0:t.index)&&e.lastMessage.index!==this.channelState.lastMessage.index&&(this.channelState.lastMessage.index=e.lastMessage.index,s.add(l)),void 0!==(null===(n=e.lastMessage)||void 0===n?void 0:n.timestamp)&&(null===(r=this.channelState.lastMessage)||void 0===r||null===(i=r.dateCreated)||void 0===i?void 0:i.getTime())!==e.lastMessage.timestamp.getTime()&&(this.channelState.lastMessage.dateCreated=e.lastMessage.timestamp,s.add(l)),By(this.channelState.lastMessage,{})&&delete this.channelState.lastMessage;break;case VP.state:var f=e.state||void 0;if(void 0!==f&&(f.dateUpdated=new Date(f.dateUpdated)),By(this.channelState.state,f))break;this.channelState.state=f,s.add(l);break;case VP.bindings:if(By(this.channelState.bindings,e.bindings))break;this.channelState.bindings=e.bindings,s.add(l);break;default:var d=e[c]instanceof Date,p=d&&(null===(a=this.channelState[l])||void 0===a?void 0:a.getTime())===e[c].getTime(),h=!d&&this[l]===e[c];if(p||h)break;this.channelState[l]=e[c],s.add(l)}}s.size>0&&this.emit("updated",{conversation:this,updateReasons:nP(s)})}},{key:"_onMessageAdded",value:function(e){var t,n=zP(this.participants.values());try{for(n.s();!(t=n.n()).done;){var r=t.value;if(r.identity===e.author){r._endTyping();break}}}catch(e){n.e(e)}finally{n.f()}this.emit("messageAdded",e)}},{key:"_setLastReadMessageIndex",value:(S=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post","".concat(this.configuration.links.myConversations,"/").concat(this.sid),{last_read_message_index:t});case 2:return n=e.sent,e.abrupt("return",n.unread_messages_count);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return S.apply(this,arguments)})},{key:"add",value:(_=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.add(t,null!=n?n:{}));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return _.apply(this,arguments)})},{key:"addNonChatParticipant",value:(x=Sa(bl.mark((function e(t,n){var r,i,a=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=a.length>2&&void 0!==a[2]?a[2]:{},i=a.length>3&&void 0!==a[3]?a[3]:{},e.abrupt("return",this.participantsEntity.addNonChatParticipant(t,n,null!=r?r:{},null!=i?i:{}));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return x.apply(this,arguments)})},{key:"advanceLastReadMessageIndex",value:(w=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:if(!(t<(this.lastReadMessageIndex||0))){e.next=6;break}return e.next=5,this._setLastReadMessageIndex(this.lastReadMessageIndex);case 5:return e.abrupt("return",e.sent);case 6:return e.next=8,this._setLastReadMessageIndex(t);case 8:return e.abrupt("return",e.sent);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return w.apply(this,arguments)})},{key:"delete",value:(k=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("delete",this.links.self);case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return k.apply(this,arguments)})},{key:"getAttributes",value:(b=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribe();case 2:return e.abrupt("return",this.attributes);case 3:case"end":return e.stop()}}),e,this)}))),function(){return b.apply(this,arguments)})},{key:"getMessages",value:(g=Sa(bl.mark((function e(t,n,r){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.messagesEntity.getMessages(t,n,r));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return g.apply(this,arguments)})},{key:"getParticipants",value:(m=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this.participantsEntity.getParticipants());case 3:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"getParticipantsCount",value:(y=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.conversations).path(this.sid).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,e.abrupt("return",null!==(t=r.body.participants_count)&&void 0!==t?t:0);case 5:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getParticipantBySid",value:(v=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.participantsEntity.getParticipantBySid(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return v.apply(this,arguments)})},{key:"getParticipantByIdentity",value:(h=Sa(bl.mark((function e(){var t,n=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>0&&void 0!==n[0]?n[0]:"",e.abrupt("return",this.participantsEntity.getParticipantByIdentity(null!=t?t:""));case 2:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"getMessagesCount",value:(p=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.conversations).path(this.sid).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,e.abrupt("return",null!==(t=r.body.messages_count)&&void 0!==t?t:0);case 5:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"getUnreadMessagesCount",value:(d=Sa(bl.mark((function e(){var t,n,r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new rh(this.configuration.links.myConversations).path(this.sid).build(),e.next=3,this.services.network.get(t);case 3:if((n=e.sent).body.conversation_sid===this.sid){e.next=6;break}throw new Error("Conversation was not found in the user conversations list");case 6:if("number"!=typeof(r=n.body.unread_messages_count)){e.next=9;break}return e.abrupt("return",r);case 9:return e.abrupt("return",null);case 10:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"join",value:(f=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:this.configuration.userIdentity});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"leave",value:(l=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("joined"!==this.channelState.status){e.next=3;break}return e.next=3,this.services.commandExecutor.mutateResource("delete","".concat(this.links.participants,"/").concat(this.configuration.userIdentity));case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"removeParticipant",value:(c=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.participantsEntity.remove("string"==typeof t?t:t.sid);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"sendMessage",value:(u=Sa(bl.mark((function e(t,n,r){var i,a,s,o;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t&&null!==t){e.next=5;break}return e.next=3,this.messagesEntity.send(t,n,r);case 3:return s=e.sent,e.abrupt("return",null!==(a=eh(s.index))&&void 0!==a?a:0);case 5:return e.next=7,this.messagesEntity.sendMedia(t,n,r);case 7:return o=e.sent,e.abrupt("return",null!==(i=eh(o.index))&&void 0!==i?i:0);case 9:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"prepareMessage",value:function(){return new qP(this.limits,this.messagesEntity)}},{key:"setAllMessagesRead",value:(o=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this.getMessages(1);case 4:if(!((t=e.sent).items.length>0)){e.next=7;break}return e.abrupt("return",this.advanceLastReadMessageIndex(t.items[0].index));case 7:return e.abrupt("return",Promise.resolve(0));case 8:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"setAllMessagesUnread",value:(s=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.next=4,this._setLastReadMessageIndex(null);case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"setUserNotificationLevel",value:(a=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post","".concat(this.configuration.links.myConversations,"/").concat(this.sid),{notification_level:t});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"typing",value:function(){return this.services.typingIndicator.send(this.sid)}},{key:"updateAttributes",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateFriendlyName",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.friendlyName===t){e.next=3;break}return e.next=3,this.services.commandExecutor.mutateResource("post",this.links.self,{friendly_name:t});case 3:return e.abrupt("return",this);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"updateLastReadMessageIndex",value:(n=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._subscribeStreams();case 2:return e.abrupt("return",this._setLastReadMessageIndex(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"updateUniqueName",value:(t=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelState.uniqueName===t){e.next=4;break}return t||(t=""),e.next=4,this.services.commandExecutor.mutateResource("post",this.links.self,{unique_name:t});case 4:return e.abrupt("return",this);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}],[{key:"preprocessUpdate",value:function(e,t){try{"string"==typeof e.attributes?e.attributes=JSON.parse(e.attributes):e.attributes&&JSON.stringify(e.attributes)}catch(n){$P.warn("Retrieved malformed attributes from the server for conversation: "+t),e.attributes={}}try{e.dateCreated&&(e.dateCreated=new Date(e.dateCreated))}catch(n){$P.warn("Retrieved malformed dateCreated from the server for conversation: "+t),delete e.dateCreated}try{e.dateUpdated&&(e.dateUpdated=new Date(e.dateUpdated))}catch(n){$P.warn("Retrieved malformed dateUpdated from the server for conversation: "+t),delete e.dateUpdated}try{e.lastMessage&&e.lastMessage.timestamp&&(e.lastMessage.timestamp=new Date(e.lastMessage.timestamp))}catch(n){$P.warn("Retrieved malformed lastMessage.timestamp from the server for conversation: "+t),delete e.lastMessage.timestamp}}}]),Conversation}(Dy);ja(Conversation,"participantJoined","participantJoined"),ja(Conversation,"participantLeft","participantLeft"),ja(Conversation,"participantUpdated","participantUpdated"),ja(Conversation,"messageAdded","messageAdded"),ja(Conversation,"messageRemoved","messageRemoved"),ja(Conversation,"messageUpdated","messageUpdated"),ja(Conversation,"typingEnded","typingEnded"),ja(Conversation,"typingStarted","typingStarted"),ja(Conversation,"updated","updated"),ja(Conversation,"removed","removed"),wl([Xv(Vv,ey),xl("design:type",Function),xl("design:paramtypes",[String,Object]),xl("design:returntype",Promise)],Conversation.prototype,"add",null),wl([Xv(Vv,Vv,ey),xl("design:type",Function),xl("design:paramtypes",[String,String,Object,Object]),xl("design:returntype",Promise)],Conversation.prototype,"addNonChatParticipant",null),wl([Xv(Jv),xl("design:type",Function),xl("design:paramtypes",[Number]),xl("design:returntype",Promise)],Conversation.prototype,"advanceLastReadMessageIndex",null),wl([Xv(["undefined",Jv],["undefined",Jv],["undefined",$v("backwards","forward")]),xl("design:type",Function),xl("design:paramtypes",[Number,Number,String]),xl("design:returntype",Promise)],Conversation.prototype,"getMessages",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"getParticipantBySid",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"getParticipantByIdentity",null),wl([Xv([Vv,Participant]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Conversation.prototype,"removeParticipant",null),wl([Xv(["string",$v(null),Gv((function(e){return[e instanceof FormData,"an instance of FormData"]})),Kv("media options",{contentType:Vv,media:Gv((function(e){var t="string"==typeof e&&e.length>0||e instanceof Uint8Array||e instanceof ArrayBuffer;return"function"==typeof Blob&&(t=t||e instanceof Blob),[t,"a non-empty string, an instance of Buffer or an instance of Blob"]}))})],ey,["undefined",$v(null),Kv("email attributes",{subject:[Vv,"undefined"]})]),xl("design:type",Function),xl("design:paramtypes",[Object,Object,Object]),xl("design:returntype",Promise)],Conversation.prototype,"sendMessage",null),wl([Xv($v("default","muted")),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"setUserNotificationLevel",null),wl([Xv(Zv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],Conversation.prototype,"updateAttributes",null),wl([Xv(["string"]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"updateFriendlyName",null),wl([Xv([$v(null),Jv]),xl("design:type",Function),xl("design:paramtypes",[Number]),xl("design:returntype",Promise)],Conversation.prototype,"updateLastReadMessageIndex",null),wl([Xv(["string",$v(null)]),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],Conversation.prototype,"updateUniqueName",null);var KP=function(){function e(){var t=this;Ma(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return Ta(e,[{key:"promise",get:function(){return this._promise}},{key:"update",value:function(e){this._resolve(e)}},{key:"set",value:function(e){this.current=e,this._resolve(e)}},{key:"fail",value:function(e){this._reject(e)}}]),e}();function HP(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return YP(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return YP(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function YP(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function QP(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function XP(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?QP(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):QP(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function ZP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var eA=rd.scope("Conversations"),tA=function(e){Oa(p,e);var t,n,r,i,a,s,o,u,c,l,f,d=ZP(p);function p(e,t){var n;return Ma(this,p),ja(Ra(n=d.call(this)),"conversations",new Map),ja(Ra(n),"myConversationsRead",new KP),ja(Ra(n),"tombstones",new Set),ja(Ra(n),"myConversationsFetched",!1),n.configuration=e,n.services=t,n}return Ta(p,[{key:"addConversation",value:(f=Sa(bl.mark((function e(t){var n,r,i,a,s,o,u,c,l,f;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=void 0!==(null==t?void 0:t.attributes)?t.attributes:{},e.next=3,this.services.commandExecutor.mutateResource("post",this.configuration.links.conversations,{friendly_name:t.friendlyName,unique_name:t.uniqueName,attributes:void 0!==a?JSON.stringify(a):void 0});case 3:if(s=e.sent,o=null!==(n=s.sid)&&void 0!==n?n:null,u=null!==(r=null===(i=s.sync_objects)||void 0===i?void 0:i.conversation)&&void 0!==r?r:null,c=XP({self:s.url},s.links),!(l=this.conversations.get(o))){e.next=12;break}return e.next=11,l._subscribe();case 11:return e.abrupt("return",l);case 12:return f=new Conversation({channel:u,entityName:"",uniqueName:"",attributes:null,createdBy:"",friendlyName:"",lastConsumedMessageIndex:0,dateCreated:null,dateUpdated:null},o,c,this.configuration,this.services),this.conversations.set(f.sid,f),this._registerForEvents(f),e.next=17,f._subscribe();case 17:return this.emit("conversationAdded",f),e.abrupt("return",f);case 19:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"fetchConversations",value:(l=Sa(bl.mark((function e(){var t,n,r,i,a,s,o,u=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._getMap();case 3:return(t=e.sent).on("itemAdded",(function(e){eA.debug("itemAdded: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),t.on("itemRemoved",(function(e){eA.debug("itemRemoved: ".concat(e.key));var t=e.key;u.myConversationsFetched||u.tombstones.add(t);var n=u.conversations.get(t);n&&("joined"===n.status&&(n._setStatus("notParticipating","sync"),u.emit("conversationLeft",n)),u.conversations.delete(t),u.emit("conversationRemoved",n),n.emit("removed",n))})),t.on("itemUpdated",(function(e){eA.debug("itemUpdated: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),e.next=9,this._fetchMyConversations();case 9:n=e.sent,r=[],i=HP(n);try{for(i.s();!(a=i.n()).done;)s=a.value,r.push(this._upsertConversation("rest",s.channel_sid,s))}catch(e){i.e(e)}finally{i.f()}return this.myConversationsRead.set(!0),e.next=16,Promise.all(r);case 16:return this.myConversationsFetched=!0,this.tombstones.clear(),eA.debug("The conversations list has been successfully fetched"),e.abrupt("return",this);case 22:throw e.prev=22,e.t0=e.catch(0),o="Failed to fetch the conversations list","disconnected"!==this.services.syncClient.connectionState&&eA.error(o,e.t0),eA.debug("ERROR: ".concat(o),e.t0),e.t0;case 28:case"end":return e.stop()}}),e,this,[[0,22]])}))),function(){return l.apply(this,arguments)})},{key:"getConversations",value:(c=Sa(bl.mark((function e(){var t,n,r=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return t=e.sent,e.next=5,t.getItems();case 5:return n=e.sent,e.abrupt("return",this._wrapPaginator(n,(function(e){return Promise.all(e.map((function(e){return r._upsertConversation("sync",e.key,e.data)})))})));case 7:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"getConversation",value:(u=Sa(bl.mark((function e(t){var n,r,i,a=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getMap();case 2:return n=e.sent,e.next=5,n.getItems({key:t});case 5:return r=e.sent,i=r.items.map((function(e){return a._upsertConversation("sync",e.key,e.data)})),e.abrupt("return",i.length>0?i[0]:null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(o=Sa(bl.mark((function e(t){var n,r,i,a,s;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.myConversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a=i.conversation_sid,s={entityName:null,lastConsumedMessageIndex:i.last_read_message_index,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:i.sync_objects.conversation,notificationLevel:null==i?void 0:i.notification_level,sid:a},e.abrupt("return",a?this._upsertConversation("sync",a,s):null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"peekConversation",value:(s=Sa(bl.mark((function e(t){var n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new rh(this.configuration.links.conversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,a={entityName:null,status:(null==i?void 0:i.status)||"unknown",friendlyName:i.friendly_name,dateUpdated:i.date_updated,dateCreated:i.date_created,uniqueName:i.unique_name,createdBy:i.created_by,attributes:i.attributes,channel:"".concat(t,".channel"),sid:t},e.abrupt("return",this._upsertConversation("sync",t,a));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"_getMap",value:(a=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.syncClient.map({id:this.configuration.myConversations,mode:"open_existing"});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"_wrapPaginator",value:(i=Sa(bl.mark((function e(t,n){var r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n(t.items);case 2:return r=e.sent,e.abrupt("return",{items:r,hasNextPage:t.hasNextPage,hasPrevPage:t.hasPrevPage,nextPage:function(){return t.nextPage().then((function(e){return i._wrapPaginator(e,n)}))},prevPage:function(){return t.prevPage().then((function(e){return i._wrapPaginator(e,n)}))}});case 4:case"end":return e.stop()}}),e)}))),function(e,t){return i.apply(this,arguments)})},{key:"_updateConversation",value:(r=Sa(bl.mark((function e(t,n,r){var i,a,s,o=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=void 0!==n._statusSource()&&t!==n._statusSource(),a="rest"!==t||"sync"===n._statusSource(),!i||!a||"sync"===t){e.next=5;break}return eA.trace("upsertConversation: conversation is known from sync and came from chat, ignoring",{sid:n.sid,data:r.status,conversation:n.status}),e.abrupt("return");case 5:if("joined"!==r.status||"joined"===n.status){e.next=13;break}return n._setStatus("joined",t),s={},void 0!==r.notificationLevel&&(s.notificationLevel=r.notificationLevel),void 0!==r.lastConsumedMessageIndex&&(s.lastConsumedMessageIndex=r.lastConsumedMessageIndex),By(s,{})||n._update(s),n._subscribe().then((function(){o.emit("conversationJoined",n)})),e.abrupt("return");case 13:if("notParticipating"!==r.status||"joined"!==n.status){e.next=20;break}return n._setStatus("notParticipating",t),n._update(r),e.next=18,n._subscribe();case 18:return this.emit("conversationLeft",n),e.abrupt("return");case 20:if("notParticipating"!==r.status){e.next=24;break}return e.next=23,n._subscribe();case 23:return e.abrupt("return");case 24:n._update(r);case 25:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"_upsertConversation",value:(n=Sa(bl.mark((function e(t,n,r){var i,a,s,o;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(eA.trace("upsertConversation called for ".concat(n),r),!(i=this.conversations.get(n))){e.next=9;break}return eA.trace("upsertConversation: the conversation ".concat(i.sid," is known;")+"its status is known from the source ".concat(i._statusSource()," ")+"and the update came from the source ".concat(t),i),e.next=6,this._updateConversation(t,i,r);case 6:return e.next=8,i._subscribe();case 8:return e.abrupt("return",i);case 9:if(!["chat","rest"].includes(t)||!this.tombstones.has(n)){e.next=12;break}return eA.trace("upsertChannel: the channel is deleted but reappeared again from chat, ignoring",n),e.abrupt("return",null);case 12:return eA.trace("upsertConversation: creating a local conversation object with sid "+n,r),a="".concat(this.configuration.links.conversations,"/").concat(n),s={self:a,messages:"".concat(a,"/Messages"),participants:"".concat(a,"/Participants")},o=new Conversation(r,n,s,this.configuration,this.services),this.conversations.set(n,o),e.next=19,o._subscribe();case 19:return this._registerForEvents(o),this.emit("conversationAdded",o),"joined"===r.status&&(o._setStatus("joined",t),this.emit("conversationJoined",o)),e.abrupt("return",o);case 23:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"_fetchMyConversations",value:(t=Sa(bl.mark((function e(){var t,n,r,i,a,s;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=null;case 2:return i=new rh(this.configuration.links.myConversations),n&&i.arg("PageToken",n),e.next=6,this.services.network.get(i.build());case 6:a=e.sent,s=null===(r=a.body)||void 0===r?void 0:r.conversations.map((function(e){return{descriptor:e,channel_sid:e.conversation_sid,status:e.status,channel:e.sync_objects.conversation,messages:e.sync_objects.messages,roster:"".concat(e.conversation_sid,".roster"),lastConsumedMessageIndex:e.last_read_message_index,notificationLevel:e.notification_level}})),n=a.body.meta.next_token,t=[].concat(nP(t),nP(s));case 10:if(n){e.next=2;break}case 11:return e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_onConversationRemoved",value:function(e){var t=this.conversations.get(e);t&&(this.conversations.delete(e),this.emit("conversationRemoved",t))}},{key:"_registerForEvents",value:function(e){var t=this;e.on("removed",(function(){return t._onConversationRemoved(e.sid)})),e.on("updated",(function(e){return t.emit("conversationUpdated",e)})),e.on("participantJoined",(function(e){return t.emit("participantJoined",e)})),e.on("participantLeft",(function(e){return t.emit("participantLeft",e)})),e.on("participantUpdated",(function(e){return t.emit("participantUpdated",e)})),e.on("messageAdded",(function(e){return t.emit("messageAdded",e)})),e.on("messageUpdated",(function(e){return t.emit("messageUpdated",e)})),e.on("messageRemoved",(function(e){return t.emit("messageRemoved",e)})),e.on("typingStarted",(function(e){return t.emit("typingStarted",e)})),e.on("typingEnded",(function(e){return t.emit("typingEnded",e)}))}}]),p}(Dy),nA=In,rA=Hr.find,iA=kd,aA="find",sA=!0;function oA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}aA in[]&&Array(1).find((function(){sA=!1})),nA({target:"Array",proto:!0,forced:sA},{find:function(e){return rA(this,e,arguments.length>1?arguments[1]:void 0)}}),iA(aA);var uA=function(e){Oa(a,e);var t,n,r,i=oA(a);function a(e,t,n){var r;return Ma(this,a),(r=i.call(this)).configuration=t,r.services=n,r.fifoStack=[],r.myself=e,r.myself.on("updated",(function(e){return r.emit("userUpdated",e)})),r.myself.on("userSubscribed",(function(){return r.emit("userSubscribed",r.myself)})),r.myself.on("userUnsubscribed",(function(){r.emit("userUnsubscribed",r.myself),r.myself._ensureFetched()})),r.subscribedUsers=new Map,r}return Ta(a,[{key:"handleUnsubscribeUser",value:function(e){this.subscribedUsers.has(e.identity)&&this.subscribedUsers.delete(e.identity);var t=0;this.fifoStack.find((function(n,r){return n==e.identity&&(t=r,!0)}))&&this.fifoStack.splice(t,1),this.emit("userUnsubscribed",e)}},{key:"handleSubscribeUser",value:function(e){if(!this.subscribedUsers.has(e.identity)){if(this.fifoStack.length>=this.configuration.userInfosToSubscribe){var t,n,r=this.fifoStack.shift();null===(t=this.subscribedUsers)||void 0===t||null===(n=t.get(r))||void 0===n||n.unsubscribe()}this.fifoStack.push(e.identity),this.subscribedUsers.set(e.identity,e),this.emit("userSubscribed",e)}}},{key:"getUser",value:(r=Sa(bl.mark((function e(){var t,n,r,i,a=this,s=arguments;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=s.length>0&&void 0!==s[0]?s[0]:"",n=s.length>1&&void 0!==s[1]?s[1]:"",e.next=4,this.myself._ensureFetched();case 4:if(t!=this.myself.identity){e.next=6;break}return e.abrupt("return",this.myself);case 6:if(!(r=this.subscribedUsers.get(t))){e.next=9;break}return e.abrupt("return",r);case 9:if(e.t0=n,e.t0){e.next=14;break}return e.next=13,this.getSyncUniqueName(t);case 13:e.t0=e.sent;case 14:return n=e.t0,(i=new User(t,n,this.configuration,this.services)).on("updated",(function(e){return a.emit("userUpdated",e)})),i.on("userSubscribed",(function(){return a.handleSubscribeUser(i)})),i.on("userUnsubscribed",(function(){return a.handleUnsubscribeUser(i)})),e.next=21,i._ensureFetched();case 21:return e.abrupt("return",i);case 22:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.myself._ensureFetched();case 2:return t=[this.myself],this.subscribedUsers.forEach((function(e){return t.push(e)})),e.abrupt("return",t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"getSyncUniqueName",value:(t=Sa(bl.mark((function e(t){var n,r,i,a;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=new rh(this.configuration.links.users).path(t).build(),e.next=3,this.services.network.get(i);case 3:return a=e.sent,e.abrupt("return",null!==(n=null===(r=a.body)||void 0===r?void 0:r.sync_objects.user_info_map)&&void 0!==n?n:"");case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),a}(Dy),cA=rd.scope("TypingIndicator"),lA=function(){function e(t,n,r){Ma(this,e),this.configuration=n,this.services=r,this.getConversation=t,this.serviceTypingTimeout=null,this.sentUpdates=new Map}var t;return Ta(e,[{key:"typingTimeout",get:function(){return this.configuration.typingIndicatorTimeoutOverride||this.serviceTypingTimeout||this.configuration.typingIndicatorTimeoutDefault}},{key:"initialize",value:function(){var e=this;this.services.notificationClient.on("message",function(){var t=Sa(bl.mark((function t(n,r){return bl.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==gg.TYPING_INDICATOR){t.next=3;break}return t.next=3,e._handleRemoteTyping(r);case 3:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}())}},{key:"_handleRemoteTyping",value:(t=Sa(bl.mark((function e(t){var n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:cA.trace("Got new typing indicator ",t),this.getConversation(t.channel_sid).then((function(e){e&&e.participants.forEach((function(e){if(e.identity===t.identity){var r=n.configuration.typingIndicatorTimeoutOverride?n.configuration.typingIndicatorTimeoutOverride+1e3:1e3*t.typing_timeout;e._startTyping(r)}}))})).catch((function(e){throw cA.error(e),e}));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"send",value:function(e){var t=this.sentUpdates.get(e);return t&&t>Date.now()-this.typingTimeout?Promise.resolve():(this.sentUpdates.set(e,Date.now()),this._send(e))}},{key:"_send",value:function(e){var t=this;cA.trace("Sending typing indicator");var n=this.configuration.links.typing,r="ChannelSid=".concat(e);return this.services.twilsockClient.post(n,{"Content-Type":"application/x-www-form-urlencoded"},r,this.configuration.productId).then((function(e){e.body.hasOwnProperty("typing_timeout")&&(t.serviceTypingTimeout=1e3*e.body.typing_timeout)})).catch((function(e){throw cA.error("Failed to send typing indicator:",e),e}))}}]),e}(),PushNotification=function PushNotification(e){Ma(this,PushNotification),this.title=e.title||null,this.body=e.body||null,this.sound=e.sound||null,this.badge=e.badge||null,this.action=e.action||null,this.type=e.type||null,this.data=e.data||{}};function fA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function dA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?fA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):fA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var pA,hA,vA,yA=function(e){return e.replace(/(^\/+|\/+$)/g,"")},mA=function(){function e(t,n,r){Ma(this,e),this._serviceUrl=t,this._services=n,this._productId=r}var t,n,r;return Ta(e,[{key:"_preProcessUrl",value:function(e){var t=yA(e);return/^https?:\/\//.test(e)?t:"".concat(yA(this._serviceUrl),"/").concat(t)}},{key:"_makeRequest",value:(r=Sa(bl.mark((function e(t,n,r,i){var a,s,o,u;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=this._preProcessUrl(n),s=dA({"Content-Type":"application/json; charset=utf-8"},i||{}),e.t0=t,e.next="get"===e.t0?5:"post"===e.t0?11:"delete"===e.t0?15:19;break;case 5:return u=a,r&&(u+="?"+Object.entries(r).map((function(e){return e.map(encodeURIComponent).join("=")})).join("&")),e.next=9,this._services.transport.get(u,s,this._productId);case 9:return o=e.sent,e.abrupt("break",19);case 11:return e.next=13,this._services.transport.post(a,s,JSON.stringify(r),this._productId);case 13:return o=e.sent,e.abrupt("break",19);case 15:return e.next=17,this._services.transport.delete(a,s,{},this._productId);case 17:return o=e.sent,e.abrupt("break",19);case 19:if(!(o.status.code<200||o.status.code>=300)){e.next=21;break}throw new Error("Request responded with a non-success code ".concat(o.status.code));case 21:return e.abrupt("return",o);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"fetchResource",value:(n=Sa(bl.mark((function e(t,n){var r,i=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=1,e.next=4,new pg({min:50,max:1600,maxAttemptsCount:6}).run((function(){return i._makeRequest("get",t,n)}));case 4:return r=e.sent,e.abrupt("return",r.body);case 8:throw e.prev=8,e.t0=e.catch(1),new Error('Fetch resource from "'.concat(t,'" failed.'));case 11:case"end":return e.stop()}}),e,null,[[1,8]])}))),function(e,t){return n.apply(this,arguments)})},{key:"mutateResource",value:(t=Sa(bl.mark((function e(t,n,r){var i;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._makeRequest(t,n,r,{"X-Twilio-Mutation-Id":tb.v4()});case 2:if(202!==(i=e.sent).status.code){e.next=7;break}return e.next=6,this.fetchResource(i.body.resource_url);case 6:return e.abrupt("return",e.sent);case 7:return e.abrupt("return",i.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,n,r){return t.apply(this,arguments)})}]),e}();function gA(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function bA(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?gA(Object(n),!0).forEach((function(t){ja(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):gA(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function kA(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Aa(e);if(t){var i=Aa(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Pa(this,n)}}var wA=rd.scope("Client"),xA="2.1.0-rc.9",_A=function e(){Ma(this,e)};return e.Client=(hA=pA=function(e){Oa(Client,e);var t,n,r,i,a,s,o,u,c,l,f,d,p,h,v=kA(Client);function Client(e){var t,n,r,i,a,s,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Ma(this,Client),ja(Ra(s=v.call(this)),"connectionState","unknown"),ja(Ra(s),"version",xA),ja(Ra(s),"parsePushNotification",vA.parsePushNotification),s.fpaToken=null!=e?e:"",s.options=null!=o?o:{},!s.options.disableDeepClone){var u=bA(bA({},s.options),{},{transport:void 0,twilsockClient:void 0});(u=Zp(u)).transport=s.options.transport,u.twilsockClient=s.options.twilsockClient,s.options=u}s.options.logLevel=null!==(t=s.options.logLevel)&&void 0!==t?t:"silent",wA.setLevel(s.options.logLevel);var c=s.options.productId="ip_messaging";if(s.options.clientMetadata=s.options.clientMetadata||{},s.options.clientMetadata.hasOwnProperty("type")||(s.options.clientMetadata.type="conversations"),s.options.clientMetadata.hasOwnProperty("sdk")||(s.options.clientMetadata.sdk="JS",s.options.clientMetadata.sdkv=xA),s.options.Sync=s.options.Sync||{},void 0===s.options.Sync.enableSessionStorage&&(s.options.Sync.enableSessionStorage=!0),s.options.region&&(s.options.Sync.region=s.options.region),!e)throw new Error("A valid Twilio token should be provided");s.services=new _A,s._myself=new User("","",null,s.services);var l=!s.options.twilsockClient;if(!s.options.initRegistrations){var f=new bg.InitRegistration(c);vA.populateInitRegistrations(f),s.options.initRegistrations=[f]}s.services.twilsockClient=s.options.twilsockClient=null!==(n=s.options.twilsockClient)&&void 0!==n?n:new bg.TwilsockClient(e,c,s.options),s.services.twilsockClient.on("tokenAboutToExpire",(function(e){return s.emit("tokenAboutToExpire",e)})),s.services.twilsockClient.on("tokenExpired",(function(){return s.emit("tokenExpired")})),s.services.twilsockClient.on("connectionError",(function(e){return s.emit("connectionError",e)})),s.services.twilsockClient.on("stateChanged",(function(e){wA.debug("Handling stateChanged for ConversationsClient: new state ".concat(e)),e!==s.connectionState&&(s.connectionState=e,s.emit("connectionStateChanged",s.connectionState))})),s.services.transport=s.options.transport=null!==(r=s.options.transport)&&void 0!==r?r:s.options.twilsockClient,s.services.notificationClient=s.options.notificationsClient=null!==(i=s.options.notificationsClient)&&void 0!==i?i:new aE.Notifications(e,s.options),s.services.syncClient=s.options.syncClient=null!==(a=s.options.syncClient)&&void 0!==a?a:new BR(e,s.options);var d=(null==o?void 0:o.Chat)||(null==o?void 0:o.IPMessaging)||o||{},p=d.region||(null==o?void 0:o.region),h=d.apiUri||d.typingUri||"https://aim.".concat(p||"us1",".twilio.com");s.services.commandExecutor=new mA(h,{transport:s.options.transport},c);var y=function(e){s._rejectEnsureReady(e),s.emit("stateChanged","failed")};return s.services.twilsockClient.once("connectionError",y),s.services.twilsockClient.once("disconnected",y),s.services.twilsockClient.once("connected",Sa(bl.mark((function e(){var t;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return wA.debug("ConversationsClient started INITIALIZING"),s.services.twilsockClient.off("connectionError",y),s.services.twilsockClient.off("disconnected",y),e.prev=3,t="conversations.client.startup",s.services.twilsockClient.addPartialTelemetryEvent(new bg.TelemetryEventDescription(t,"Conversations client startup",new Date),t,bg.TelemetryPoint.Start),e.next=8,s._initialize();case 8:s.services.twilsockClient.addPartialTelemetryEvent(new bg.TelemetryEventDescription("","",new Date),t,bg.TelemetryPoint.End),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(3),s._rejectEnsureReady(e.t0),s.emit("stateChanged","failed");case 15:case"end":return e.stop()}}),e,null,[[3,11]])})))),s._ensureReady=new Promise((function(e,t){s._resolveEnsureReady=e,s._rejectEnsureReady=t})).catch((function(){})),l&&s.services.twilsockClient.connect(),s}return Ta(Client,[{key:"user",get:function(){return this._myself}},{key:"reachabilityEnabled",get:function(){if(!this.configuration)throw new Error("Reachability information could not yet be accessed as the client has not yet been initialized. Subscribe to the 'stateChanged' event to properly react to the client initialization.");return this.configuration.reachabilityEnabled}},{key:"token",get:function(){return this.fpaToken}},{key:"_subscribeToPushNotifications",value:function(e){var t=this;[gg.NEW_MESSAGE,gg.ADDED_TO_CONVERSATION,gg.REMOVED_FROM_CONVERSATION,gg.TYPING_INDICATOR,gg.CONSUMPTION_UPDATE].forEach((function(n){t.services.notificationClient.subscribe(e,n)}))}},{key:"_unsubscribeFromPushNotifications",value:function(e){var t=this;[gg.NEW_MESSAGE,gg.ADDED_TO_CONVERSATION,gg.REMOVED_FROM_CONVERSATION,gg.TYPING_INDICATOR,gg.CONSUMPTION_UPDATE].forEach((function(n){t.services.notificationClient.unsubscribe(e,n)}))}},{key:"_initialize",value:(h=Sa(bl.mark((function e(){var t,n=this;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.fetchResource("Client/v2/Configuration");case 2:return t=e.sent,this.configuration=new hd(this.options,t,wA),this._myself._resolveInitialization(this.configuration,this.configuration.userIdentity,this.configuration.userInfo,!0),this.services.typingIndicator=new lA(this.getConversationBySid.bind(this),this.configuration,this.services),this.services.network=new mg(this.configuration,this.services),this.services.users=new uA(this._myself,this.configuration,this.services),this.services.users.on("userSubscribed",(function(e){n.emit("userSubscribed",e)})),this.services.users.on("userUpdated",(function(e){return n.emit("userUpdated",e)})),this.services.users.on("userUnsubscribed",(function(e){n.emit("userUnsubscribed",e)})),this.conversations=new tA(this.configuration,this.services),this.conversations.on("conversationAdded",(function(e){n.emit("conversationAdded",e)})),this.conversations.on("conversationRemoved",(function(e){n.emit("conversationRemoved",e)})),this.conversations.on("conversationJoined",(function(e){n.emit("conversationJoined",e)})),this.conversations.on("conversationLeft",(function(e){n.emit("conversationLeft",e)})),this.conversations.on("conversationUpdated",(function(e){return n.emit("conversationUpdated",e)})),this.conversations.on("participantJoined",(function(e){n.emit("participantJoined",e)})),this.conversations.on("participantLeft",(function(e){n.emit("participantLeft",e)})),this.conversations.on("participantUpdated",(function(e){return n.emit("participantUpdated",e)})),this.conversations.on("messageAdded",(function(e){return n.emit("messageAdded",e)})),this.conversations.on("messageUpdated",(function(e){return n.emit("messageUpdated",e)})),this.conversations.on("messageRemoved",(function(e){return n.emit("messageRemoved",e)})),this.conversations.on("typingStarted",(function(e){return n.emit("typingStarted",e)})),this.conversations.on("typingEnded",(function(e){return n.emit("typingEnded",e)})),this.conversationsPromise=this.conversations.fetchConversations().then((function(){return n.conversations})).catch((function(e){throw e})),e.next=28,this.services.users.myself._ensureFetched();case 28:vA.supportedPushChannels.forEach((function(e){return n._subscribeToPushNotifications(e)})),this.services.typingIndicator.initialize(),this.services.mcsClient=new $R.McsClient(this.fpaToken,this.configuration.links.mediaService,this.configuration.links.mediaSetService,bA(bA({},this.options),{},{transport:void 0})),this._resolveEnsureReady(),this.emit("stateChanged","initialized");case 33:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"shutdown",value:(p=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.services.twilsockClient.disconnect();case 4:case"end":return e.stop()}}),e,this)}))),function(){return p.apply(this,arguments)})},{key:"updateToken",value:(d=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:if(wA.info("updateToken"),this.fpaToken!==t){e.next=5;break}return e.abrupt("return",this);case 5:return e.next=7,this.services.twilsockClient.updateToken(t);case 7:return e.next=9,this.services.notificationClient.updateToken(t);case 9:return e.next=11,this.services.mcsClient.updateToken(t);case 11:return this.fpaToken=t,e.abrupt("return",this);case 13:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"getConversationBySid",value:(f=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.conversations.myConversationsRead.promise;case 4:return e.next=6,this.conversations.getConversation(t);case 6:if(n=e.sent){e.next=11;break}return e.next=10,this.conversations.peekConversation(t);case 10:n=e.sent;case 11:if(n){e.next=13;break}throw new Error("Conversation with SID ".concat(t," is not found."));case 13:return e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(l=Sa(bl.mark((function e(t){var n;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.next=4,this.conversations.myConversationsRead.promise;case 4:return e.next=6,this.conversations.getConversationByUniqueName(t);case 6:if(n=e.sent){e.next=9;break}throw new Error("Conversation with unique name ".concat(t," is not found."));case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"getSubscribedConversations",value:(c=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.conversationsPromise.then((function(e){return e.getConversations()})));case 3:case"end":return e.stop()}}),e,this)}))),function(){return c.apply(this,arguments)})},{key:"createConversation",value:(u=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return t=t||{},e.abrupt("return",this.conversationsPromise.then((function(e){return e.addConversation(t)})));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"setPushRegistrationId",value:(o=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this._subscribeToPushNotifications(t),this.services.notificationClient.setPushRegistrationId(t,n),e.next=6,this.services.notificationClient.commitChanges();case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"unsetPushRegistrationId",value:(s=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this._unsubscribeFromPushNotifications(t),e.next=5,this.services.notificationClient.commitChanges();case 5:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"removePushRegistrations",value:(a=Sa(bl.mark((function e(t,n){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.notificationClient.removeRegistrations(t,n);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"handlePushNotification",value:(i=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:wA.debug("handlePushNotification, notificationPayload=",t),this.emit("pushNotification",vA.parsePushNotification(t));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"getUser",value:(r=Sa(bl.mark((function e(t){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.services.users.getUser(t));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Sa(bl.mark((function e(){return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return e.abrupt("return",this.services.users.getSubscribedUsers());case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})}],[{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([gg.TYPING_INDICATOR]),BR.populateInitRegistrations(e)}},{key:"create",value:(t=Sa(bl.mark((function e(t,n){var r;return bl.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==n||!n.twilsockClient){e.next=2;break}throw new Error("Obsolete usage of ConversationsClient.create() factory method: if you pass twilsock from the outside then you must use ConversationsClient constructor and be prepared to work with uninitialized client.");case 2:return r=new vA(t,n),e.next=5,r._ensureReady;case 5:return e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"parsePushNotificationChatData",value:function(e){var t={};for(var n in vA.supportedPushDataFields)void 0!==e[n]&&null!==e[n]&&("message_index"===n?null!==eh(e[n])&&(t[vA.supportedPushDataFields[n]]=Number(e[n])):t[vA.supportedPushDataFields[n]]=e[n]);return t}},{key:"parsePushNotification",value:function(e){if(wA.debug("parsePushNotification, notificationPayload=",e),void 0!==e.aps){if(!e.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var t,n=vA.parsePushNotificationChatData(e),r=e.aps,i=null;return"string"==typeof r.alert?t=r.alert||null:(t=r.alert.body||null,i=r.alert.title||null),new PushNotification({title:i,body:t,sound:r.sound||null,badge:r.badge||null,action:r.category||null,type:e.twi_message_type,data:n})}if(void 0!==e.data){var a=e.data;if(!a.twi_message_type)throw new Error("Provided push notification payload does not contain Programmable Chat push notification type");var s=vA.parsePushNotificationChatData(e.data);return new PushNotification({title:a.twi_title||null,body:a.twi_body||null,sound:a.twi_sound||null,badge:null,action:a.twi_action||null,type:a.twi_message_type,data:s})}throw new Error("Provided push notification payload is not Programmable Chat notification")}}]),Client}(Dy),ja(pA,"version",xA),ja(pA,"supportedPushChannels",["fcm","apn"]),ja(pA,"supportedPushDataFields",{conversation_sid:"conversationSid",message_sid:"messageSid",message_index:"messageIndex"}),ja(pA,"conversationAdded","conversationAdded"),ja(pA,"conversationJoined","conversationJoined"),ja(pA,"conversationLeft","conversationLeft"),ja(pA,"conversationRemoved","conversationRemoved"),ja(pA,"conversationUpdated","conversationUpdated"),ja(pA,"participantJoined","participantJoined"),ja(pA,"participantLeft","participantLeft"),ja(pA,"participantUpdated","participantUpdated"),ja(pA,"messageAdded","messageAdded"),ja(pA,"messageRemoved","messageRemoved"),ja(pA,"messageUpdated","messageUpdated"),ja(pA,"tokenAboutToExpire","tokenAboutToExpire"),ja(pA,"tokenExpired","tokenExpired"),ja(pA,"typingEnded","typingEnded"),ja(pA,"typingStarted","typingStarted"),ja(pA,"pushNotification","pushNotification"),ja(pA,"userSubscribed","userSubscribed"),ja(pA,"userUnsubscribed","userUnsubscribed"),ja(pA,"userUpdated","userUpdated"),ja(pA,"stateChanged","stateChanged"),ja(pA,"connectionStateChanged","connectionStateChanged"),ja(pA,"connectionError","connectionError"),vA=hA),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"updateToken",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getConversationBySid",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getConversationByUniqueName",null),wl([Xv(["undefined",Kv("conversation options",{friendlyName:["string","undefined"],isPrivate:["boolean","undefined"],uniqueName:["string","undefined"]})]),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],e.Client.prototype,"createConversation",null),wl([Xv($v("fcm","apn"),"string"),xl("design:type",Function),xl("design:paramtypes",[String,String]),xl("design:returntype",Promise)],e.Client.prototype,"setPushRegistrationId",null),wl([Xv($v("fcm","apn")),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"unsetPushRegistrationId",null),wl([Xv($v("fcm","apn"),Vv),xl("design:type",Function),xl("design:paramtypes",[String,String]),xl("design:returntype",Promise)],e.Client.prototype,"removePushRegistrations",null),wl([Xv(Hv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",Promise)],e.Client.prototype,"handlePushNotification",null),wl([Xv(Vv),xl("design:type",Function),xl("design:paramtypes",[String]),xl("design:returntype",Promise)],e.Client.prototype,"getUser",null),wl([Xv("string",["undefined",Hv]),xl("design:type",Function),xl("design:paramtypes",[String,Object]),xl("design:returntype",Promise)],e.Client,"create",null),wl([Qv(Hv),xl("design:type",Function),xl("design:paramtypes",[Object]),xl("design:returntype",PushNotification)],e.Client,"parsePushNotification",null),e.Client=vA=wl([Yv(Vv,[Hv,"undefined"]),xl("design:paramtypes",[String,Object])],e.Client),e.AggregatedDeliveryReceipt=AggregatedDeliveryReceipt,e.Conversation=Conversation,e.DetailedDeliveryReceipt=DetailedDeliveryReceipt,e.Media=Media,e.Message=Message,e.MessageBuilder=qP,e.NotificationTypes=gg,e.Participant=Participant,e.PushNotification=PushNotification,e.RestPaginator=AP,e.UnsentMessage=BP,e.User=User,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
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")(),o={},a=function(e){try{return!!e()}catch(e){return!0}},s=!a((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}},y={}.toString,v=function(e){return y.call(e).slice(8,-1)},m=v,g="".split,b=a((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==m(e)?g.call(e,""):Object(e)}:Object,w=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},x=b,k=w,_=function(e){return x(k(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]},C=R("navigator","userAgent")||"",O=i,I=C,A=O.process,P=O.Deno,j=A&&A.versions||P&&P.version,L=j&&j.v8;L?p=(d=L.split("."))[0]<4?1:d[0]+d[1]:I&&(!(d=I.match(/Edge\/(\d+)/))||d[1]>=74)&&(d=I.match(/Chrome\/(\d+)/))&&(p=d[1]);var M=p&&+p,N=M,D=a,U=!!Object.getOwnPropertySymbols&&!D((function(){var e=Symbol();return!String(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&N&&N<41})),F=U&&!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},J=$,K="__core-js_shared__",V=i[K]||J(K,{}),H=V;(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=w,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,oe=W.exports,ae=ee,se=re,ue=U,ce=F,le=oe("wks"),fe=ie.Symbol,de=ce?fe:fe&&fe.withoutSetter||se,pe=function(e){return ae(le,e)&&(ue||"string"==typeof le[e])||(ue&&ae(fe,e)?le[e]=fe[e]:le[e]=de("Symbol."+e)),le[e]},he=S,ye=q,ve=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)||ye(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)||ye(n))return n;throw TypeError("Can't convert object to primitive value")}return void 0===t&&(t="number"),ve(e,t)},be=ge,we=q,xe=function(e){var t=be(e,"string");return we(t)?t:String(t)},ke=S,_e=i.document,Se=ke(_e)&&ke(_e.createElement),Ee=function(e){return Se?_e.createElement(e):{}},Te=Ee,Re=!s&&!a((function(){return 7!=Object.defineProperty(Te("div"),"a",{get:function(){return 7}}).a})),Ce=s,Oe=u,Ie=h,Ae=_,Pe=xe,je=ee,Le=Re,Me=Object.getOwnPropertyDescriptor;o.f=Ce?Me:function(e,t){if(e=Ae(e),t=Pe(t),Le)try{return Me(e,t)}catch(e){}if(je(e,t))return Ie(!Oe.f.call(e,t),e[t])};var Ne={},De=S,Ue=function(e){if(!De(e))throw TypeError(String(e)+" is not an object");return e},Fe=s,Be=Re,qe=Ue,ze=xe,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,Je=s?function(e,t,n){return Ge.f(e,t,$e(1,n))}:function(e,t,n){return e[t]=n,e},Ke={exports:{}},Ve=V,He=Function.toString;"function"!=typeof Ve.inspectSource&&(Ve.inspectSource=function(e){return He.call(e)});var Ye,Qe,Xe,Ze=Ve.inspectSource,et=Ze,tt=i.WeakMap,nt="function"==typeof tt&&/native code/.test(et(tt)),rt=W.exports,it=re,ot=rt("keys"),at=function(e){return ot[e]||(ot[e]=it(e))},st={},ut=nt,ct=S,lt=Je,ft=ee,dt=V,pt=at,ht=st,yt="Object already initialized",vt=i.WeakMap;if(ut||dt.state){var mt=dt.state||(dt.state=new vt),gt=mt.get,bt=mt.has,wt=mt.set;Ye=function(e,t){if(bt.call(mt,e))throw new TypeError(yt);return t.facade=e,wt.call(mt,e,t),t},Qe=function(e){return gt.call(mt,e)||{}},Xe=function(e){return bt.call(mt,e)}}else{var xt=pt("state");ht[xt]=!0,Ye=function(e,t){if(ft(e,xt))throw new TypeError(yt);return t.facade=e,lt(e,xt,t),t},Qe=function(e){return ft(e,xt)?e[xt]:{}},Xe=function(e){return ft(e,xt)}}var kt={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=Je,Et=ee,Tt=$,Rt=Ze,Ct=kt.get,Ot=kt.enforce,It=String(String).split("String");(Ke.exports=function(e,t,n,r){var i,o=!!r&&!!r.unsafe,a=!!r&&!!r.enumerable,s=!!r&&!!r.noTargetGet;"function"==typeof n&&("string"!=typeof t||Et(n,"name")||St(n,"name",t),(i=Ot(n)).source||(i.source=It.join("string"==typeof t?t:""))),e!==_t?(o?!s&&e[t]&&(a=!0):delete e[t],a?e[t]=n:St(e,t,n)):a?e[t]=n:Tt(t,n)})(Function.prototype,"toString",(function(){return"function"==typeof this&&Ct(this).source||Rt(this)}));var At={},Pt=Math.ceil,jt=Math.floor,Lt=function(e){return isNaN(e=+e)?0:(e>0?jt:Pt)(e)},Mt=Lt,Nt=Math.min,Dt=function(e){return e>0?Nt(Mt(e),9007199254740991):0},Ut=Lt,Ft=Math.max,Bt=Math.min,qt=function(e,t){var n=Ut(e);return n<0?Ft(n+t,0):Bt(n,t)},zt=_,Wt=Dt,Gt=qt,$t=function(e){return function(t,n,r){var i,o=zt(t),a=Wt(o.length),s=Gt(r,a);if(e&&n!=n){for(;a>s;)if((i=o[s++])!=i)return!0}else for(;a>s;s++)if((e||s in o)&&o[s]===n)return e||s||0;return!e&&-1}},Jt={includes:$t(!0),indexOf:$t(!1)},Kt=ee,Vt=_,Ht=Jt.indexOf,Yt=st,Qt=function(e,t){var n,r=Vt(e),i=0,o=[];for(n in r)!Kt(Yt,n)&&Kt(r,n)&&o.push(n);for(;t.length>i;)Kt(r,n=t[i++])&&(~Ht(o,n)||o.push(n));return o},Xt=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],Zt=Qt,en=Xt.concat("length","prototype");At.f=Object.getOwnPropertyNames||function(e){return Zt(e,en)};var tn={};tn.f=Object.getOwnPropertySymbols;var nn=At,rn=tn,on=Ue,an=R("Reflect","ownKeys")||function(e){var t=nn.f(on(e)),n=rn.f;return n?t.concat(n(e)):t},sn=ee,un=an,cn=o,ln=Ne,fn=function(e,t){for(var n=un(t),r=ln.f,i=cn.f,o=0;o<n.length;o++){var a=n[o];sn(e,a)||r(e,a,i(t,a))}},dn=a,pn=/#|\.prototype\./,hn=function(e,t){var n=vn[yn(e)];return n==gn||n!=mn&&("function"==typeof t?dn(t):!!t)},yn=hn.normalize=function(e){return String(e).replace(pn,".").toLowerCase()},vn=hn.data={},mn=hn.NATIVE="N",gn=hn.POLYFILL="P",bn=hn,wn=i,xn=o.f,kn=Je,_n=Ke.exports,Sn=$,En=fn,Tn=bn,Rn=function(e,t){var n,r,i,o,a,s=e.target,u=e.global,c=e.stat;if(n=u?wn:c?wn[s]||Sn(s,{}):(wn[s]||{}).prototype)for(r in t){if(o=t[r],i=e.noTargetGet?(a=xn(n,r))&&a.value:n[r],!Tn(u?r:s+(c?".":"#")+r,e.forced)&&void 0!==i){if(typeof o==typeof i)continue;En(o,i)}(e.sham||i&&i.sham)&&kn(o,"sham",!0),_n(n,r,o,e)}},Cn=Ne.f,On=ee,In=pe("toStringTag"),An=function(e,t,n){e&&!On(e=n?e:e.prototype,In)&&Cn(e,In,{configurable:!0,value:t})},Pn=i,jn=An;Rn({global:!0},{Reflect:{}}),jn(Pn.Reflect,"Reflect",!0);var Ln,Mn=function(e){if("function"!=typeof e)throw TypeError(String(e)+" is not a function");return e},Nn=Qt,Dn=Xt,Un=Object.keys||function(e){return Nn(e,Dn)},Fn=Ne,Bn=Ue,qn=Un,zn=s?Object.defineProperties:function(e,t){Bn(e);for(var n,r=qn(t),i=r.length,o=0;i>o;)Fn.f(e,n=r[o++],t[n]);return e},Wn=R("document","documentElement"),Gn=Ue,$n=zn,Jn=Xt,Kn=st,Vn=Wn,Hn=Ee,Yn=at("IE_PROTO"),Qn=function(){},Xn=function(e){return"<script>"+e+"</"+"script>"},Zn=function(e){e.write(Xn("")),e.close();var t=e.parentWindow.Object;return e=null,t},er=function(){try{Ln=new ActiveXObject("htmlfile")}catch(e){}var e,t;er="undefined"!=typeof document?document.domain&&Ln?Zn(Ln):((t=Hn("iframe")).style.display="none",Vn.appendChild(t),t.src=String("javascript:"),(e=t.contentWindow.document).open(),e.write(Xn("document.F=Object")),e.close(),e.F):Zn(Ln);for(var n=Jn.length;n--;)delete er.prototype[Jn[n]];return er()};Kn[Yn]=!0;var tr=Object.create||function(e,t){var n;return null!==e?(Qn.prototype=Gn(e),n=new Qn,Qn.prototype=null,n[Yn]=e):n=er(),void 0===t?n:$n(n,t)},nr=Mn,rr=S,ir=[].slice,or={},ar=function(e,t,n){if(!(t in or)){for(var r=[],i=0;i<t;i++)r[i]="a["+i+"]";or[t]=Function("C,a","return new C("+r.join(",")+")")}return or[t](e,n)},sr=Function.bind||function(e){var t=nr(this),n=ir.call(arguments,1),r=function(){var i=n.concat(ir.call(arguments));return this instanceof r?ar(t,i.length,i):t.apply(e,i)};return rr(t.prototype)&&(r.prototype=t.prototype),r},ur=Rn,cr=Mn,lr=Ue,fr=S,dr=tr,pr=sr,hr=a,yr=R("Reflect","construct"),vr=hr((function(){function e(){}return!(yr((function(){}),[],e)instanceof e)})),mr=!hr((function(){yr((function(){}))})),gr=vr||mr;ur({target:"Reflect",stat:!0,forced:gr,sham:gr},{construct:function(e,t){cr(e),lr(t);var n=arguments.length<3?e:cr(arguments[2]);if(mr&&!vr)return yr(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(pr.apply(e,r))}var i=n.prototype,o=dr(fr(i)?i:Object.prototype),a=Function.apply.call(e,o,t);return fr(a)?a:o}});var br=Q,wr=Un;Rn({target:"Object",stat:!0,forced:a((function(){wr(1)}))},{keys:function(e){return wr(br(e))}});var xr=v,kr=Array.isArray||function(e){return"Array"==xr(e)},_r=q,Sr=function(e){if(_r(e))throw TypeError("Cannot convert a Symbol value to a string");return String(e)},Er={},Tr=_,Rr=At.f,Cr={}.toString,Or="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];Er.f=function(e){return Or&&"[object Window]"==Cr.call(e)?function(e){try{return Rr(e)}catch(e){return Or.slice()}}(e):Rr(Tr(e))};var Ir={},Ar=pe;Ir.f=Ar;var Pr=i,jr=ee,Lr=Ir,Mr=Ne.f,Nr=function(e){var t=Pr.Symbol||(Pr.Symbol={});jr(t,e)||Mr(t,e,{value:Lr.f(e)})},Dr=Mn,Ur=function(e,t,n){if(Dr(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)}},Fr=S,Br=kr,qr=pe("species"),zr=function(e){var t;return Br(e)&&("function"!=typeof(t=e.constructor)||t!==Array&&!Br(t.prototype)?Fr(t)&&null===(t=t[qr])&&(t=void 0):t=void 0),void 0===t?Array:t},Wr=function(e,t){return new(zr(e))(0===t?0:t)},Gr=Ur,$r=b,Jr=Q,Kr=Dt,Vr=Wr,Hr=[].push,Yr=function(e){var t=1==e,n=2==e,r=3==e,i=4==e,o=6==e,a=7==e,s=5==e||o;return function(u,c,l,f){for(var d,p,h=Jr(u),y=$r(h),v=Gr(c,l,3),m=Kr(y.length),g=0,b=f||Vr,w=t?b(u,m):n||a?b(u,0):void 0;m>g;g++)if((s||g in y)&&(p=v(d=y[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:Hr.call(w,d)}else switch(e){case 4:return!1;case 7:Hr.call(w,d)}return o?-1:r||i?i:w}},Qr={forEach:Yr(0),map:Yr(1),filter:Yr(2),some:Yr(3),every:Yr(4),find:Yr(5),findIndex:Yr(6),filterReject:Yr(7)},Xr=Rn,Zr=i,ei=R,ti=s,ni=U,ri=a,ii=ee,oi=kr,ai=S,si=q,ui=Ue,ci=Q,li=_,fi=xe,di=Sr,pi=h,hi=tr,yi=Un,vi=At,mi=Er,gi=tn,bi=o,wi=Ne,xi=u,ki=Je,_i=Ke.exports,Si=W.exports,Ei=st,Ti=re,Ri=pe,Ci=Ir,Oi=Nr,Ii=An,Ai=kt,Pi=Qr.forEach,ji=at("hidden"),Li="Symbol",Mi=Ri("toPrimitive"),Ni=Ai.set,Di=Ai.getterFor(Li),Ui=Object.prototype,Fi=Zr.Symbol,Bi=ei("JSON","stringify"),qi=bi.f,zi=wi.f,Wi=mi.f,Gi=xi.f,$i=Si("symbols"),Ji=Si("op-symbols"),Ki=Si("string-to-symbol-registry"),Vi=Si("symbol-to-string-registry"),Hi=Si("wks"),Yi=Zr.QObject,Qi=!Yi||!Yi.prototype||!Yi.prototype.findChild,Xi=ti&&ri((function(){return 7!=hi(zi({},"a",{get:function(){return zi(this,"a",{value:7}).a}})).a}))?function(e,t,n){var r=qi(Ui,t);r&&delete Ui[t],zi(e,t,n),r&&e!==Ui&&zi(Ui,t,r)}:zi,Zi=function(e,t){var n=$i[e]=hi(Fi.prototype);return Ni(n,{type:Li,tag:e,description:t}),ti||(n.description=t),n},eo=function(e,t,n){e===Ui&&eo(Ji,t,n),ui(e);var r=fi(t);return ui(n),ii($i,r)?(n.enumerable?(ii(e,ji)&&e[ji][r]&&(e[ji][r]=!1),n=hi(n,{enumerable:pi(0,!1)})):(ii(e,ji)||zi(e,ji,pi(1,{})),e[ji][r]=!0),Xi(e,r,n)):zi(e,r,n)},to=function(e,t){ui(e);var n=li(t),r=yi(n).concat(oo(n));return Pi(r,(function(t){ti&&!no.call(n,t)||eo(e,t,n[t])})),e},no=function(e){var t=fi(e),n=Gi.call(this,t);return!(this===Ui&&ii($i,t)&&!ii(Ji,t))&&(!(n||!ii(this,t)||!ii($i,t)||ii(this,ji)&&this[ji][t])||n)},ro=function(e,t){var n=li(e),r=fi(t);if(n!==Ui||!ii($i,r)||ii(Ji,r)){var i=qi(n,r);return!i||!ii($i,r)||ii(n,ji)&&n[ji][r]||(i.enumerable=!0),i}},io=function(e){var t=Wi(li(e)),n=[];return Pi(t,(function(e){ii($i,e)||ii(Ei,e)||n.push(e)})),n},oo=function(e){var t=e===Ui,n=Wi(t?Ji:li(e)),r=[];return Pi(n,(function(e){!ii($i,e)||t&&!ii(Ui,e)||r.push($i[e])})),r};(ni||(_i((Fi=function(){if(this instanceof Fi)throw TypeError("Symbol is not a constructor");var e=arguments.length&&void 0!==arguments[0]?di(arguments[0]):void 0,t=Ti(e),n=function(e){this===Ui&&n.call(Ji,e),ii(this,ji)&&ii(this[ji],t)&&(this[ji][t]=!1),Xi(this,t,pi(1,e))};return ti&&Qi&&Xi(Ui,t,{configurable:!0,set:n}),Zi(t,e)}).prototype,"toString",(function(){return Di(this).tag})),_i(Fi,"withoutSetter",(function(e){return Zi(Ti(e),e)})),xi.f=no,wi.f=eo,bi.f=ro,vi.f=mi.f=io,gi.f=oo,Ci.f=function(e){return Zi(Ri(e),e)},ti&&(zi(Fi.prototype,"description",{configurable:!0,get:function(){return Di(this).description}}),_i(Ui,"propertyIsEnumerable",no,{unsafe:!0}))),Xr({global:!0,wrap:!0,forced:!ni,sham:!ni},{Symbol:Fi}),Pi(yi(Hi),(function(e){Oi(e)})),Xr({target:Li,stat:!0,forced:!ni},{for:function(e){var t=di(e);if(ii(Ki,t))return Ki[t];var n=Fi(t);return Ki[t]=n,Vi[n]=t,n},keyFor:function(e){if(!si(e))throw TypeError(e+" is not a symbol");if(ii(Vi,e))return Vi[e]},useSetter:function(){Qi=!0},useSimple:function(){Qi=!1}}),Xr({target:"Object",stat:!0,forced:!ni,sham:!ti},{create:function(e,t){return void 0===t?hi(e):to(hi(e),t)},defineProperty:eo,defineProperties:to,getOwnPropertyDescriptor:ro}),Xr({target:"Object",stat:!0,forced:!ni},{getOwnPropertyNames:io,getOwnPropertySymbols:oo}),Xr({target:"Object",stat:!0,forced:ri((function(){gi.f(1)}))},{getOwnPropertySymbols:function(e){return gi.f(ci(e))}}),Bi)&&Xr({target:"JSON",stat:!0,forced:!ni||ri((function(){var e=Fi();return"[null]"!=Bi([e])||"{}"!=Bi({a:e})||"{}"!=Bi(Object(e))}))},{stringify:function(e,t,n){for(var r,i=[e],o=1;arguments.length>o;)i.push(arguments[o++]);if(r=t,(ai(t)||void 0!==e)&&!si(e))return oi(t)||(t=function(e,t){if("function"==typeof r&&(t=r.call(this,e,t)),!si(t))return t}),i[1]=t,Bi.apply(null,i)}});Fi.prototype[Mi]||ki(Fi.prototype,Mi,Fi.prototype.valueOf),Ii(Fi,Li),Ei[ji]=!0;var ao=a,so=M,uo=pe("species"),co=function(e){return so>=51||!ao((function(){var t=[];return(t.constructor={})[uo]=function(){return{foo:1}},1!==t[e](Boolean).foo}))},lo=Qr.filter;Rn({target:"Array",proto:!0,forced:!co("filter")},{filter:function(e){return lo(this,e,arguments.length>1?arguments[1]:void 0)}});var fo=Rn,po=a,ho=_,yo=o.f,vo=s,mo=po((function(){yo(1)}));fo({target:"Object",stat:!0,forced:!vo||mo,sham:!vo},{getOwnPropertyDescriptor:function(e,t){return yo(ho(e),t)}});var go=xe,bo=Ne,wo=h,xo=function(e,t,n){var r=go(t);r in e?bo.f(e,r,wo(0,n)):e[r]=n},ko=an,_o=_,So=o,Eo=xo;function To(e,t,n,r,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void n(e)}s.done?t(u):Promise.resolve(u).then(r,i)}function Ro(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var o=e.apply(t,n);function a(e){To(o,r,i,a,s,"next",e)}function s(e){To(o,r,i,a,s,"throw",e)}a(void 0)}))}}function Co(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Oo(e,t){return(Oo=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Io(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&&Oo(e,t)}function Ao(e){return(Ao="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 Po(e,t){if(t&&("object"===Ao(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return Co(e)}function jo(e){return(jo=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Lo(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Mo(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 No(e,t,n){return t&&Mo(e.prototype,t),n&&Mo(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function Do(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Rn({target:"Object",stat:!0,sham:!s},{getOwnPropertyDescriptors:function(e){for(var t,n,r=_o(e),i=So.f,o=ko(r),a={},s=0;o.length>s;)void 0!==(n=i(r,t=o[s++]))&&Eo(a,t,n);return a}});var Uo={};Uo[pe("toStringTag")]="z";var Fo="[object z]"===String(Uo),Bo=Fo,qo=v,zo=pe("toStringTag"),Wo="Arguments"==qo(function(){return arguments}()),Go=Bo?qo: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),zo))?n:Wo?qo(t):"Object"==(r=qo(t))&&"function"==typeof t.callee?"Arguments":r},$o=Go,Jo=Fo?{}.toString:function(){return"[object "+$o(this)+"]"},Ko=Fo,Vo=Ke.exports,Ho=Jo;Ko||Vo(Object.prototype,"toString",Ho,{unsafe:!0});var Yo=i.Promise,Qo=Ke.exports,Xo=function(e,t,n){for(var r in t)Qo(e,r,t[r],n);return e},Zo=S,ea=Ue,ta=function(e){if(!Zo(e)&&null!==e)throw TypeError("Can't set "+String(e)+" as a prototype");return e},na=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 ea(n),ta(r),t?e.call(n,r):n.__proto__=r,n}}():void 0),ra=R,ia=Ne,oa=s,aa=pe("species"),sa=function(e){var t=ra(e),n=ia.f;oa&&t&&!t[aa]&&n(t,aa,{configurable:!0,get:function(){return this}})},ua=function(e,t,n){if(!(e instanceof t))throw TypeError("Incorrect "+(n?n+" ":"")+"invocation");return e},ca={},la=ca,fa=pe("iterator"),da=Array.prototype,pa=function(e){return void 0!==e&&(la.Array===e||da[fa]===e)},ha=Go,ya=ca,va=pe("iterator"),ma=function(e){if(null!=e)return e[va]||e["@@iterator"]||ya[ha(e)]},ga=Ue,ba=ma,wa=function(e,t){var n=arguments.length<2?ba(e):t;if("function"!=typeof n)throw TypeError(String(e)+" is not iterable");return ga(n.call(e))},xa=Ue,ka=function(e,t,n){var r,i;xa(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 xa(r),n},_a=Ue,Sa=pa,Ea=Dt,Ta=Ur,Ra=wa,Ca=ma,Oa=ka,Ia=function(e,t){this.stopped=e,this.result=t},Aa=function(e,t,n){var r,i,o,a,s,u,c,l=n&&n.that,f=!(!n||!n.AS_ENTRIES),d=!(!n||!n.IS_ITERATOR),p=!(!n||!n.INTERRUPTED),h=Ta(t,l,1+f+p),y=function(e){return r&&Oa(r,"normal",e),new Ia(!0,e)},v=function(e){return f?(_a(e),p?h(e[0],e[1],y):h(e[0],e[1])):p?h(e,y):h(e)};if(d)r=e;else{if("function"!=typeof(i=Ca(e)))throw TypeError("Target is not iterable");if(Sa(i)){for(o=0,a=Ea(e.length);a>o;o++)if((s=v(e[o]))&&s instanceof Ia)return s;return new Ia(!1)}r=Ra(e,i)}for(u=r.next;!(c=u.call(r)).done;){try{s=v(c.value)}catch(e){Oa(r,"throw",e)}if("object"==typeof s&&s&&s instanceof Ia)return s}return new Ia(!1)},Pa=pe("iterator"),ja=!1;try{var La=0,Ma={next:function(){return{done:!!La++}},return:function(){ja=!0}};Ma[Pa]=function(){return this},Array.from(Ma,(function(){throw 2}))}catch(e){}var Na,Da,Ua,Fa,Ba=function(e,t){if(!t&&!ja)return!1;var n=!1;try{var r={};r[Pa]=function(){return{next:function(){return{done:n=!0}}}},e(r)}catch(e){}return n},qa=Ue,za=Mn,Wa=pe("species"),Ga=function(e,t){var n,r=qa(e).constructor;return void 0===r||null==(n=qa(r)[Wa])?t:za(n)},$a=/(?:ipad|iphone|ipod).*applewebkit/i.test(C),Ja="process"==v(i.process),Ka=i,Va=a,Ha=Ur,Ya=Wn,Qa=Ee,Xa=$a,Za=Ja,es=Ka.setImmediate,ts=Ka.clearImmediate,ns=Ka.process,rs=Ka.MessageChannel,is=Ka.Dispatch,os=0,as={},ss="onreadystatechange";try{Na=Ka.location}catch(e){}var us=function(e){if(as.hasOwnProperty(e)){var t=as[e];delete as[e],t()}},cs=function(e){return function(){us(e)}},ls=function(e){us(e.data)},fs=function(e){Ka.postMessage(String(e),Na.protocol+"//"+Na.host)};es&&ts||(es=function(e){for(var t=[],n=arguments.length,r=1;n>r;)t.push(arguments[r++]);return as[++os]=function(){("function"==typeof e?e:Function(e)).apply(void 0,t)},Da(os),os},ts=function(e){delete as[e]},Za?Da=function(e){ns.nextTick(cs(e))}:is&&is.now?Da=function(e){is.now(cs(e))}:rs&&!Xa?(Fa=(Ua=new rs).port2,Ua.port1.onmessage=ls,Da=Ha(Fa.postMessage,Fa,1)):Ka.addEventListener&&"function"==typeof postMessage&&!Ka.importScripts&&Na&&"file:"!==Na.protocol&&!Va(fs)?(Da=fs,Ka.addEventListener("message",ls,!1)):Da=ss in Qa("script")?function(e){Ya.appendChild(Qa("script")).onreadystatechange=function(){Ya.removeChild(this),us(e)}}:function(e){setTimeout(cs(e),0)});var ds,ps,hs,ys,vs,ms,gs,bs,ws={set:es,clear:ts},xs=i,ks=/ipad|iphone|ipod/i.test(C)&&void 0!==xs.Pebble,_s=/web0s(?!.*chrome)/i.test(C),Ss=i,Es=o.f,Ts=ws.set,Rs=$a,Cs=ks,Os=_s,Is=Ja,As=Ss.MutationObserver||Ss.WebKitMutationObserver,Ps=Ss.document,js=Ss.process,Ls=Ss.Promise,Ms=Es(Ss,"queueMicrotask"),Ns=Ms&&Ms.value;Ns||(ds=function(){var e,t;for(Is&&(e=js.domain)&&e.exit();ps;){t=ps.fn,ps=ps.next;try{t()}catch(e){throw ps?ys():hs=void 0,e}}hs=void 0,e&&e.enter()},Rs||Is||Os||!As||!Ps?!Cs&&Ls&&Ls.resolve?((gs=Ls.resolve(void 0)).constructor=Ls,bs=gs.then,ys=function(){bs.call(gs,ds)}):ys=Is?function(){js.nextTick(ds)}:function(){Ts.call(Ss,ds)}:(vs=!0,ms=Ps.createTextNode(""),new As(ds).observe(ms,{characterData:!0}),ys=function(){ms.data=vs=!vs}));var Ds=Ns||function(e){var t={fn:e,next:void 0};hs&&(hs.next=t),ps||(ps=t,ys()),hs=t},Us={},Fs=Mn,Bs=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=Fs(t),this.reject=Fs(n)};Us.f=function(e){return new Bs(e)};var qs,zs,Ws,Gs,$s=Ue,Js=S,Ks=Us,Vs=i,Hs="object"==typeof window,Ys=Rn,Qs=i,Xs=R,Zs=Yo,eu=Ke.exports,tu=Xo,nu=na,ru=An,iu=sa,ou=S,au=Mn,su=ua,uu=Ze,cu=Aa,lu=Ba,fu=Ga,du=ws.set,pu=Ds,hu=function(e,t){if($s(e),Js(t)&&t.constructor===e)return t;var n=Ks.f(e);return(0,n.resolve)(t),n.promise},yu=function(e,t){var n=Vs.console;n&&n.error&&(1===arguments.length?n.error(e):n.error(e,t))},vu=Us,mu=function(e){try{return{error:!1,value:e()}}catch(e){return{error:!0,value:e}}},gu=kt,bu=bn,wu=Hs,xu=Ja,ku=M,_u=pe("species"),Su="Promise",Eu=gu.get,Tu=gu.set,Ru=gu.getterFor(Su),Cu=Zs&&Zs.prototype,Ou=Zs,Iu=Cu,Au=Qs.TypeError,Pu=Qs.document,ju=Qs.process,Lu=vu.f,Mu=Lu,Nu=!!(Pu&&Pu.createEvent&&Qs.dispatchEvent),Du="function"==typeof PromiseRejectionEvent,Uu="unhandledrejection",Fu=!1,Bu=bu(Su,(function(){var e=uu(Ou),t=e!==String(Ou);if(!t&&66===ku)return!0;if(ku>=51&&/native code/.test(e))return!1;var n=new Ou((function(e){e(1)})),r=function(e){e((function(){}),(function(){}))};return(n.constructor={})[_u]=r,!(Fu=n.then((function(){}))instanceof r)||!t&&wu&&!Du})),qu=Bu||!lu((function(e){Ou.all(e).catch((function(){}))})),zu=function(e){var t;return!(!ou(e)||"function"!=typeof(t=e.then))&&t},Wu=function(e,t){if(!e.notified){e.notified=!0;var n=e.reactions;pu((function(){for(var r=e.value,i=1==e.state,o=0;n.length>o;){var a,s,u,c=n[o++],l=i?c.ok:c.fail,f=c.resolve,d=c.reject,p=c.domain;try{l?(i||(2===e.rejection&&Ku(e),e.rejection=1),!0===l?a=r:(p&&p.enter(),a=l(r),p&&(p.exit(),u=!0)),a===c.promise?d(Au("Promise-chain cycle")):(s=zu(a))?s.call(a,f,d):f(a)):d(r)}catch(e){p&&!u&&p.exit(),d(e)}}e.reactions=[],e.notified=!1,t&&!e.rejection&&$u(e)}))}},Gu=function(e,t,n){var r,i;Nu?((r=Pu.createEvent("Event")).promise=t,r.reason=n,r.initEvent(e,!1,!0),Qs.dispatchEvent(r)):r={promise:t,reason:n},!Du&&(i=Qs["on"+e])?i(r):e===Uu&&yu("Unhandled promise rejection",n)},$u=function(e){du.call(Qs,(function(){var t,n=e.facade,r=e.value;if(Ju(e)&&(t=mu((function(){xu?ju.emit("unhandledRejection",r,n):Gu(Uu,n,r)})),e.rejection=xu||Ju(e)?2:1,t.error))throw t.value}))},Ju=function(e){return 1!==e.rejection&&!e.parent},Ku=function(e){du.call(Qs,(function(){var t=e.facade;xu?ju.emit("rejectionHandled",t):Gu("rejectionhandled",t,e.value)}))},Vu=function(e,t,n){return function(r){e(t,r,n)}},Hu=function(e,t,n){e.done||(e.done=!0,n&&(e=n),e.value=t,e.state=2,Wu(e,!0))},Yu=function(e,t,n){if(!e.done){e.done=!0,n&&(e=n);try{if(e.facade===t)throw Au("Promise can't be resolved itself");var r=zu(t);r?pu((function(){var n={done:!1};try{r.call(t,Vu(Yu,n,e),Vu(Hu,n,e))}catch(t){Hu(n,t,e)}})):(e.value=t,e.state=1,Wu(e,!1))}catch(t){Hu({done:!1},t,e)}}};if(Bu&&(Iu=(Ou=function(e){su(this,Ou,Su),au(e),qs.call(this);var t=Eu(this);try{e(Vu(Yu,t),Vu(Hu,t))}catch(e){Hu(t,e)}}).prototype,(qs=function(e){Tu(this,{type:Su,done:!1,notified:!1,parent:!1,reactions:[],rejection:!1,state:0,value:void 0})}).prototype=tu(Iu,{then:function(e,t){var n=Ru(this),r=Lu(fu(this,Ou));return r.ok="function"!=typeof e||e,r.fail="function"==typeof t&&t,r.domain=xu?ju.domain:void 0,n.parent=!0,n.reactions.push(r),0!=n.state&&Wu(n,!1),r.promise},catch:function(e){return this.then(void 0,e)}}),zs=function(){var e=new qs,t=Eu(e);this.promise=e,this.resolve=Vu(Yu,t),this.reject=Vu(Hu,t)},vu.f=Lu=function(e){return e===Ou||e===Ws?new zs(e):Mu(e)},"function"==typeof Zs&&Cu!==Object.prototype)){Gs=Cu.then,Fu||(eu(Cu,"then",(function(e,t){var n=this;return new Ou((function(e,t){Gs.call(n,e,t)})).then(e,t)}),{unsafe:!0}),eu(Cu,"catch",Iu.catch,{unsafe:!0}));try{delete Cu.constructor}catch(e){}nu&&nu(Cu,Iu)}Ys({global:!0,wrap:!0,forced:Bu},{Promise:Ou}),ru(Ou,Su,!1),iu(Su),Ws=Xs(Su),Ys({target:Su,stat:!0,forced:Bu},{reject:function(e){var t=Lu(this);return t.reject.call(void 0,e),t.promise}}),Ys({target:Su,stat:!0,forced:Bu},{resolve:function(e){return hu(this,e)}}),Ys({target:Su,stat:!0,forced:qu},{all:function(e){var t=this,n=Lu(t),r=n.resolve,i=n.reject,o=mu((function(){var n=au(t.resolve),o=[],a=0,s=1;cu(e,(function(e){var u=a++,c=!1;o.push(void 0),s++,n.call(t,e).then((function(e){c||(c=!0,o[u]=e,--s||r(o))}),i)})),--s||r(o)}));return o.error&&i(o.value),n.promise},race:function(e){var t=this,n=Lu(t),r=n.reject,i=mu((function(){var i=au(t.resolve);cu(e,(function(e){i.call(t,e).then(n.resolve,r)}))}));return i.error&&r(i.value),n.promise}});var Qu=Qr.map;Rn({target:"Array",proto:!0,forced:!co("map")},{map:function(e){return Qu(this,e,arguments.length>1?arguments[1]:void 0)}});var Xu={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},Zu=Ee("span").classList,ec=Zu&&Zu.constructor&&Zu.constructor.prototype,tc=ec===Object.prototype?void 0:ec,nc=a,rc=function(e,t){var n=[][e];return!!n&&nc((function(){n.call(null,t||function(){throw 1},1)}))},ic=Qr.forEach,oc=i,ac=Xu,sc=tc,uc=rc("forEach")?[].forEach:function(e){return ic(this,e,arguments.length>1?arguments[1]:void 0)},cc=Je,lc=function(e){if(e&&e.forEach!==uc)try{cc(e,"forEach",uc)}catch(t){e.forEach=uc}};for(var fc in ac)lc(oc[fc]&&oc[fc].prototype);lc(sc);var dc,pc=Object.prototype,hc=pc.hasOwnProperty,yc="function"==typeof Symbol?Symbol:{},vc=yc.iterator||"@@iterator",mc=yc.asyncIterator||"@@asyncIterator",gc=yc.toStringTag||"@@toStringTag";function bc(e,t,n,r){var i=t&&t.prototype instanceof Tc?t:Tc,o=Object.create(i.prototype),a=new Fc(r||[]);return o._invoke=function(e,t,n){var r=xc;return function(i,o){if(r===_c)throw new Error("Generator is already running");if(r===Sc){if("throw"===i)throw o;return qc()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var s=Nc(a,n);if(s){if(s===Ec)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===xc)throw r=Sc,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=_c;var u=wc(e,t,n);if("normal"===u.type){if(r=n.done?Sc:kc,u.arg===Ec)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=Sc,n.method="throw",n.arg=u.arg)}}}(e,n,a),o}function wc(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}var xc="suspendedStart",kc="suspendedYield",_c="executing",Sc="completed",Ec={};function Tc(){}function Rc(){}function Cc(){}var Oc={};Oc[vc]=function(){return this};var Ic=Object.getPrototypeOf,Ac=Ic&&Ic(Ic(Bc([])));Ac&&Ac!==pc&&hc.call(Ac,vc)&&(Oc=Ac);var Pc=Cc.prototype=Tc.prototype=Object.create(Oc);function jc(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function Lc(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===Rc||"GeneratorFunction"===(t.displayName||t.name))}function Mc(e,t){function n(r,i,o,a){var s=wc(e[r],e,i);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"===Ao(c)&&hc.call(c,"__await")?t.resolve(c.__await).then((function(e){n("next",e,o,a)}),(function(e){n("throw",e,o,a)})):t.resolve(c).then((function(e){u.value=e,o(u)}),(function(e){return n("throw",e,o,a)}))}a(s.arg)}var r;this._invoke=function(e,i){function o(){return new t((function(t,r){n(e,i,t,r)}))}return r=r?r.then(o,o):o()}}function Nc(e,t){var n=e.iterator[t.method];if(n===dc){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=dc,Nc(e,t),"throw"===t.method))return Ec;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return Ec}var r=wc(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,Ec;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=dc),t.delegate=null,Ec):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,Ec)}function Dc(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 Uc(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function Fc(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(Dc,this),this.reset(!0)}function Bc(e){if(e){var t=e[vc];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(hc.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=dc,t.done=!0,t};return r.next=r}}return{next:qc}}function qc(){return{value:dc,done:!0}}Rc.prototype=Pc.constructor=Cc,Cc.constructor=Rc,Cc[gc]=Rc.displayName="GeneratorFunction",jc(Mc.prototype),Mc.prototype[mc]=function(){return this},jc(Pc),Pc[gc]="Generator",Pc[vc]=function(){return this},Pc.toString=function(){return"[object Generator]"},Fc.prototype={constructor:Fc,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=dc,this.done=!1,this.delegate=null,this.method="next",this.arg=dc,this.tryEntries.forEach(Uc),!e)for(var t in this)"t"===t.charAt(0)&&hc.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=dc)},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 o.type="throw",o.arg=e,t.next=n,r&&(t.method="next",t.arg=dc),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],o=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=hc.call(i,"catchLoc"),s=hc.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){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&&hc.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 o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,Ec):this.complete(o)},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),Ec},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),Uc(n),Ec}},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;Uc(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:Bc(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=dc),Ec}};var zc={wrap:bc,isGeneratorFunction:Lc,AsyncIterator:Mc,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,Cc):(e.__proto__=Cc,gc in e||(e[gc]="GeneratorFunction")),e.prototype=Object.create(Pc),e},awrap:function(e){return{__await:e}},async:function(e,t,n,r,i){void 0===i&&(i=Promise);var o=new Mc(bc(e,t,n,r),i);return Lc(t)?o:o.next().then((function(e){return e.done?e.value:o.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:Bc},Wc=Object.freeze({__proto__:null,default:zc});function Gc(e,t,n,r){var i,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Ao(Reflect))&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(o<3?i(a):o>3?i(t,n,a):i(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}function $c(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Ao(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}var Jc=Rn,Kc=a,Vc=kr,Hc=S,Yc=Q,Qc=Dt,Xc=xo,Zc=Wr,el=co,tl=M,nl=pe("isConcatSpreadable"),rl=9007199254740991,il="Maximum allowed index exceeded",ol=tl>=51||!Kc((function(){var e=[];return e[nl]=!1,e.concat()[0]!==e})),al=el("concat"),sl=function(e){if(!Hc(e))return!1;var t=e[nl];return void 0!==t?!!t:Vc(e)};Jc({target:"Array",proto:!0,forced:!ol||!al},{concat:function(e){var t,n,r,i,o,a=Yc(this),s=Zc(a,0),u=0;for(t=-1,r=arguments.length;t<r;t++)if(sl(o=-1===t?a:arguments[t])){if(u+(i=Qc(o.length))>rl)throw TypeError(il);for(n=0;n<i;n++,u++)n in o&&Xc(s,u,o[n])}else{if(u>=rl)throw TypeError(il);Xc(s,u++,o)}return s.length=u,s}});var ul=Ue,cl=ka,ll=Ur,fl=Q,dl=function(e,t,n,r){try{return r?t(ul(n)[0],n[1]):t(n)}catch(t){cl(e,"throw",t)}},pl=pa,hl=Dt,yl=xo,vl=wa,ml=ma,gl=function(e){var t,n,r,i,o,a,s=fl(e),u="function"==typeof this?this:Array,c=arguments.length,l=c>1?arguments[1]:void 0,f=void 0!==l,d=ml(s),p=0;if(f&&(l=ll(l,c>2?arguments[2]:void 0,2)),null==d||u==Array&&pl(d))for(n=new u(t=hl(s.length));t>p;p++)a=f?l(s[p],p):s[p],yl(n,p,a);else for(o=(i=vl(s,d)).next,n=new u;!(r=o.call(i)).done;p++)a=f?dl(i,l,[r.value,p],!0):r.value,yl(n,p,a);return n.length=p,n},bl=gl;Rn({target:"Array",stat:!0,forced:!Ba((function(e){Array.from(e)}))},{from:bl});var wl,xl,kl,_l=Lt,Sl=Sr,El=w,Tl=function(e){return function(t,n){var r,i,o=Sl(El(t)),a=_l(n),s=o.length;return a<0||a>=s?e?"":void 0:(r=o.charCodeAt(a))<55296||r>56319||a+1===s||(i=o.charCodeAt(a+1))<56320||i>57343?e?o.charAt(a):r:e?o.slice(a,a+2):i-56320+(r-55296<<10)+65536}},Rl={codeAt:Tl(!1),charAt:Tl(!0)},Cl=!a((function(){function e(){}return e.prototype.constructor=null,Object.getPrototypeOf(new e)!==e.prototype})),Ol=ee,Il=Q,Al=Cl,Pl=at("IE_PROTO"),jl=Object.prototype,Ll=Al?Object.getPrototypeOf:function(e){return e=Il(e),Ol(e,Pl)?e[Pl]:"function"==typeof e.constructor&&e instanceof e.constructor?e.constructor.prototype:e instanceof Object?jl:null},Ml=a,Nl=Ll,Dl=Je,Ul=pe("iterator"),Fl=!1;[].keys&&("next"in(kl=[].keys())?(xl=Nl(Nl(kl)))!==Object.prototype&&(wl=xl):Fl=!0),(null==wl||Ml((function(){var e={};return wl[Ul].call(e)!==e})))&&(wl={}),"function"!=typeof wl[Ul]&&Dl(wl,Ul,(function(){return this}));var Bl={IteratorPrototype:wl,BUGGY_SAFARI_ITERATORS:Fl},ql=Bl.IteratorPrototype,zl=tr,Wl=h,Gl=An,$l=ca,Jl=function(){return this},Kl=function(e,t,n){var r=t+" Iterator";return e.prototype=zl(ql,{next:Wl(1,n)}),Gl(e,r,!1),$l[r]=Jl,e},Vl=Rn,Hl=Kl,Yl=Ll,Ql=na,Xl=An,Zl=Je,ef=Ke.exports,tf=ca,nf=Bl.IteratorPrototype,rf=Bl.BUGGY_SAFARI_ITERATORS,of=pe("iterator"),af="keys",sf="values",uf="entries",cf=function(){return this},lf=function(e,t,n,r,i,o,a){Hl(n,t,r);var s,u,c,l=function(e){if(e===i&&y)return y;if(!rf&&e in p)return p[e];switch(e){case af:case sf:case uf:return function(){return new n(this,e)}}return function(){return new n(this)}},f=t+" Iterator",d=!1,p=e.prototype,h=p[of]||p["@@iterator"]||i&&p[i],y=!rf&&h||l(i),v="Array"==t&&p.entries||h;if(v&&(s=Yl(v.call(new e)))!==Object.prototype&&s.next&&(Yl(s)!==nf&&(Ql?Ql(s,nf):"function"!=typeof s[of]&&Zl(s,of,cf)),Xl(s,f,!0)),i==sf&&h&&h.name!==sf&&(d=!0,y=function(){return h.call(this)}),p[of]!==y&&Zl(p,of,y),tf[t]=y,i)if(u={values:l(sf),keys:o?y:l(af),entries:l(uf)},a)for(c in u)(rf||d||!(c in p))&&ef(p,c,u[c]);else Vl({target:t,proto:!0,forced:rf||d},u);return u},ff=Rl.charAt,df=Sr,pf=kt,hf=lf,yf="String Iterator",vf=pf.set,mf=pf.getterFor(yf);hf(String,"String",(function(e){vf(this,{type:yf,string:df(e),index:0})}),(function(){var e,t=mf(this),n=t.string,r=t.index;return r>=n.length?{value:void 0,done:!0}:(e=ff(n,r),t.index+=e.length,{value:e,done:!1})}));var gf,bf,wf,xf={exports:{}};function kf(e,t){return["".concat((new Date).toISOString()," Conversations ").concat(e,":")].concat(Array.from(t))}bf=t,wf=function(){var e=function(){},t="undefined",n=("undefined"==typeof window?"undefined":Ao(window))!==t&&Ao(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 o(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function a(r){return"debug"===r&&(r="log"),("undefined"==typeof console?"undefined":Ao(console))!==t&&("trace"===r&&n?o: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 o=r[i];this[o]=i<t?e:this.methodFactory(o,t,n)}this.log=this.debug}function u(e,n,r){return function(){("undefined"==typeof console?"undefined":Ao(console))!==t&&(s.call(this,n,r),this[e].apply(this,arguments))}}function c(e,t,n){return a(e)||u.apply(this,arguments)}function l(e,n,i){var o,a=this;n=null==n?"WARN":n;var u="loglevel";function l(){var e;if(("undefined"==typeof window?"undefined":Ao(window))!==t&&u){try{e=window.localStorage[u]}catch(e){}if(Ao(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===a.levels[e]&&(e=void 0),e}}"string"==typeof e?u+=":"+e:"symbol"===Ao(e)&&(u=void 0),a.name=e,a.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},a.methodFactory=i||c,a.getLevel=function(){return o},a.setLevel=function(n,i){if("string"==typeof n&&void 0!==a.levels[n.toUpperCase()]&&(n=a.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=a.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(o=n,!1!==i&&function(e){var n=(r[e]||"silent").toUpperCase();if(("undefined"==typeof window?"undefined":Ao(window))!==t&&u){try{return void(window.localStorage[u]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(u)+"="+n+";"}catch(e){}}}(n),s.call(a,n,e),("undefined"==typeof console?"undefined":Ao(console))===t&&n<a.levels.SILENT)return"No console available for logging"},a.setDefaultLevel=function(e){n=e,l()||a.setLevel(e,!1)},a.resetLevel=function(){a.setLevel(n,!1),function(){if(("undefined"==typeof window?"undefined":Ao(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){}}}()},a.enableAll=function(e){a.setLevel(a.levels.TRACE,e)},a.disableAll=function(e){a.setLevel(a.levels.SILENT,e)};var f=l();null==f&&(f=n),a.setLevel(f,!1)}var f=new l,d={};f.getLogger=function(e){if("symbol"!==Ao(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":Ao(window))!==t?window.log:void 0;return f.noConflict=function(){return("undefined"==typeof window?"undefined":Ao(window))!==t&&window.log===f&&(window.log=p),f},f.getLoggers=function(){return d},f.default=f,f},(gf=xf).exports?gf.exports=wf():bf.log=wf();var _f,Sf,Ef=xf.exports.getLogger("twilio-conversations"),Tf=function(){function e(t){Do(this,e),Lo(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return No(e,[{key:"setLevel",value:function(e){Ef.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];Ef.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];Ef.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];Ef.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];Ef.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];Ef.error.apply(null,kf(this.prefix+"E",t))}}],[{key:"scope",value:function(t){return new e(t)}},{key:"setLevel",value:function(e){Ef.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];Ef.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];Ef.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];Ef.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];Ef.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];Ef.error.apply(null,kf("E",t))}}]),e}(),Rf={};Object.defineProperty(Rf,"__esModule",{value:!0});var Cf=["weeks","years","months","days","hours","minutes","seconds"],Of=Rf.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=Sf=Rf.parse=function(e){return e.match(Of).slice(1).reduce((function(e,t,n){return e[Cf[n]]=parseFloat(t)||0,e}),{})},Af=Rf.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},Pf=_f=Rf.toSeconds=function(e,t){var n=t?t.getTime():Date.now(),r=new Date(n);return(Af(e,r).getTime()-r.getTime())/1e3};function jf(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 Lf(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?jf(Object(n),!0).forEach((function(t){Lo(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):jf(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}Rf.default={end:Af,toSeconds:Pf,pattern:Of,parse:If};var Mf="PT5S",Nf="PT5S",Df=No((function e(){var t,n,r,i,o,a,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;Do(this,e),Lo(this,"typingIndicatorTimeoutDefault",5e3);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=Lf({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:Mf;try{this.httpCacheInterval=_f(Sf(f))}catch(e){c.error("Failed to parse http cache interval ".concat(f,", using default value ").concat(Mf)),this.httpCacheInterval=_f(Sf(Mf))}var d=null!==(o=null!==(a=l.consumptionReportIntervalOverride)&&void 0!==a?a:u.options.consumption_report_interval)&&void 0!==o?o:Nf;try{this.consumptionReportInterval=_f(Sf(d))}catch(e){c.error("Failed to parse consumption report interval ".concat(d,", using default value ").concat(Nf)),this.consumptionReportInterval=_f(Sf(Nf))}})),Uf=tr,Ff=Ne,Bf=pe("unscopables"),qf=Array.prototype;null==qf[Bf]&&Ff.f(qf,Bf,{configurable:!0,value:Uf(null)});var zf=function(e){qf[Bf][e]=!0},Wf=_,Gf=zf,$f=ca,Jf=kt,Kf=lf,Vf="Array Iterator",Hf=Jf.set,Yf=Jf.getterFor(Vf),Qf=Kf(Array,"Array",(function(e,t){Hf(this,{type:Vf,target:Wf(e),index:0,kind:t})}),(function(){var e=Yf(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");$f.Arguments=$f.Array,Gf("keys"),Gf("values"),Gf("entries");var Xf=i,Zf=Xu,ed=tc,td=Qf,nd=Je,rd=pe,id=rd("iterator"),od=rd("toStringTag"),ad=td.values,sd=function(e,t){if(e){if(e[id]!==ad)try{nd(e,id,ad)}catch(t){e[id]=ad}if(e[od]||nd(e,od,t),Zf[t])for(var n in td)if(e[n]!==td[n])try{nd(e,n,td[n])}catch(t){e[n]=td[n]}}};for(var ud in Zf)sd(Xf[ud]&&Xf[ud].prototype,ud);sd(ed,"DOMTokenList");var cd=Rn,ld=a,fd=R("JSON","stringify"),dd=/[\uD800-\uDFFF]/g,pd=/^[\uD800-\uDBFF]$/,hd=/^[\uDC00-\uDFFF]$/,yd=function(e,t,n){var r=n.charAt(t-1),i=n.charAt(t+1);return pd.test(e)&&!hd.test(i)||hd.test(e)&&!pd.test(r)?"\\u"+e.charCodeAt(0).toString(16):e},vd=ld((function(){return'"\\udf06\\ud834"'!==fd("\udf06\ud834")||'"\\udead"'!==fd("\udead")}));fd&&cd({target:"JSON",stat:!0,forced:vd},{stringify:function(e,t,n){var r=fd.apply(null,arguments);return"string"==typeof r?r.replace(dd,yd):r}});var md=S,gd=na,bd=function(e,t,n){var r,i;return gd&&"function"==typeof(r=t.constructor)&&r!==n&&md(i=r.prototype)&&i!==n.prototype&&gd(e,i),e},wd=w,xd=Sr,kd="[\t\n\v\f\r \u2028\u2029\ufeff]",_d=RegExp("^"+kd+kd+"*"),Sd=RegExp(kd+kd+"*$"),Ed=function(e){return function(t){var n=xd(wd(t));return 1&e&&(n=n.replace(_d,"")),2&e&&(n=n.replace(Sd,"")),n}},Td={start:Ed(1),end:Ed(2),trim:Ed(3)},Rd=s,Cd=i,Od=bn,Id=Ke.exports,Ad=ee,Pd=v,jd=bd,Ld=q,Md=ge,Nd=a,Dd=tr,Ud=At.f,Fd=o.f,Bd=Ne.f,qd=Td.trim,zd="Number",Wd=Cd.Number,Gd=Wd.prototype,$d=Pd(Dd(Gd))==zd,Jd=function(e){if(Ld(e))throw TypeError("Cannot convert a Symbol value to a number");var t,n,r,i,o,a,s,u,c=Md(e,"number");if("string"==typeof c&&c.length>2)if(43===(t=(c=qd(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(a=(o=c.slice(2)).length,s=0;s<a;s++)if((u=o.charCodeAt(s))<48||u>i)return NaN;return parseInt(o,r)}return+c};if(Od(zd,!Wd(" 0o1")||!Wd("0b1")||Wd("+0x1"))){for(var Kd,Vd=function(e){var t=arguments.length<1?0:e,n=this;return n instanceof Vd&&($d?Nd((function(){Gd.valueOf.call(n)})):Pd(n)!=zd)?jd(new Wd(Jd(t)),n,Vd):Jd(t)},Hd=Rd?Ud(Wd):"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(","),Yd=0;Hd.length>Yd;Yd++)Ad(Wd,Kd=Hd[Yd])&&!Ad(Vd,Kd)&&Bd(Vd,Kd,Fd(Wd,Kd));Vd.prototype=Gd,Gd.constructor=Vd,Id(Cd,zd,Vd)}var Qd=Ue,Xd=function(){var e=Qd(this),t="";return e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.dotAll&&(t+="s"),e.unicode&&(t+="u"),e.sticky&&(t+="y"),t},Zd={},ep=a,tp=i.RegExp;Zd.UNSUPPORTED_Y=ep((function(){var e=tp("a","y");return e.lastIndex=2,null!=e.exec("abcd")})),Zd.BROKEN_CARET=ep((function(){var e=tp("^r","gy");return e.lastIndex=2,null!=e.exec("str")}));var np,rp,ip=a,op=i.RegExp,ap=ip((function(){var e=op(".","s");return!(e.dotAll&&e.exec("\n")&&"s"===e.flags)})),sp=a,up=i.RegExp,cp=sp((function(){var e=up("(?<a>b)","g");return"b"!==e.exec("b").groups.a||"bc"!=="b".replace(e,"$<a>c")})),lp=Sr,fp=Xd,dp=Zd,pp=W.exports,hp=tr,yp=kt.get,vp=ap,mp=cp,gp=RegExp.prototype.exec,bp=pp("native-string-replace",String.prototype.replace),wp=gp,xp=(np=/a/,rp=/b*/g,gp.call(np,"a"),gp.call(rp,"a"),0!==np.lastIndex||0!==rp.lastIndex),kp=dp.UNSUPPORTED_Y||dp.BROKEN_CARET,_p=void 0!==/()??/.exec("")[1];(xp||_p||kp||vp||mp)&&(wp=function(e){var t,n,r,i,o,a,s,u=this,c=yp(u),l=lp(e),f=c.raw;if(f)return f.lastIndex=u.lastIndex,t=wp.call(f,l),u.lastIndex=f.lastIndex,t;var d=c.groups,p=kp&&u.sticky,h=fp.call(u),y=u.source,v=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))&&(y="(?: "+y+")",m=" "+m,v++),n=new RegExp("^(?:"+y+")",h)),_p&&(n=new RegExp("^"+y+"$(?!\\s)",h)),xp&&(r=u.lastIndex),i=gp.call(p?n:u,m),p?i?(i.input=i.input.slice(v),i[0]=i[0].slice(v),i.index=u.lastIndex,u.lastIndex+=i[0].length):u.lastIndex=0:xp&&i&&(u.lastIndex=u.global?i.index+i[0].length:r),_p&&i&&i.length>1&&bp.call(i[0],n,(function(){for(o=1;o<arguments.length-2;o++)void 0===arguments[o]&&(i[o]=void 0)})),i&&d)for(i.groups=a=hp(null),o=0;o<d.length;o++)a[(s=d[o])[0]]=i[s[1]];return i});var Sp=wp;Rn({target:"RegExp",proto:!0,forced:/./.exec!==Sp},{exec:Sp});var Ep=Ke.exports,Tp=Sp,Rp=a,Cp=pe,Op=Je,Ip=Cp("species"),Ap=RegExp.prototype,Pp=function(e,t,n,r){var i=Cp(e),o=!Rp((function(){var t={};return t[i]=function(){return 7},7!=""[e](t)})),a=o&&!Rp((function(){var t=!1,n=/a/;return"split"===e&&((n={}).constructor={},n.constructor[Ip]=function(){return n},n.flags="",n[i]=/./[i]),n.exec=function(){return t=!0,null},n[i](""),!t}));if(!o||!a||n){var s=/./[i],u=t(i,""[e],(function(e,t,n,r,i){var a=t.exec;return a===Tp||a===Ap.exec?o&&!i?{done:!0,value:s.call(t,n,r)}:{done:!0,value:e.call(n,t,r)}:{done:!1}}));Ep(String.prototype,e,u[0]),Ep(Ap,i,u[1])}r&&Op(Ap[i],"sham",!0)},jp=Rl.charAt,Lp=function(e,t,n){return t+(n?jp(e,t).length:1)},Mp=Q,Np=Math.floor,Dp="".replace,Up=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,Fp=/\$([$&'`]|\d{1,2})/g,Bp=v,qp=Sp,zp=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"!==Bp(e))throw TypeError("RegExp#exec called on incompatible receiver");return qp.call(e,t)},Wp=Pp,Gp=a,$p=Ue,Jp=Lt,Kp=Dt,Vp=Sr,Hp=w,Yp=Lp,Qp=function(e,t,n,r,i,o){var a=n+e.length,s=r.length,u=Fp;return void 0!==i&&(i=Mp(i),u=Up),Dp.call(o,u,(function(o,u){var c;switch(u.charAt(0)){case"$":return"$";case"&":return e;case"`":return t.slice(0,n);case"'":return t.slice(a);case"<":c=i[u.slice(1,-1)];break;default:var l=+u;if(0===l)return o;if(l>s){var f=Np(l/10);return 0===f?o:f<=s?void 0===r[f-1]?u.charAt(1):r[f-1]+u.charAt(1):o}c=r[l-1]}return void 0===c?"":c}))},Xp=zp,Zp=pe("replace"),eh=Math.max,th=Math.min,nh="$0"==="a".replace(/./,"$0"),rh=!!/./[Zp]&&""===/./[Zp]("a","$0");Wp("replace",(function(e,t,n){var r=rh?"$":"$0";return[function(e,n){var r=Hp(this),i=null==e?void 0:e[Zp];return void 0!==i?i.call(e,r,n):t.call(Vp(r),e,n)},function(e,i){var o=$p(this),a=Vp(e);if("string"==typeof i&&-1===i.indexOf(r)&&-1===i.indexOf("$<")){var s=n(t,o,a,i);if(s.done)return s.value}var u="function"==typeof i;u||(i=Vp(i));var c=o.global;if(c){var l=o.unicode;o.lastIndex=0}for(var f=[];;){var d=Xp(o,a);if(null===d)break;if(f.push(d),!c)break;""===Vp(d[0])&&(o.lastIndex=Yp(a,Kp(o.lastIndex),l))}for(var p,h="",y=0,v=0;v<f.length;v++){d=f[v];for(var m=Vp(d[0]),g=eh(th(Jp(d.index),a.length),0),b=[],w=1;w<d.length;w++)b.push(void 0===(p=d[w])?p:String(p));var x=d.groups;if(u){var k=[m].concat(b,g,a);void 0!==x&&k.push(x);var _=Vp(i.apply(void 0,k))}else _=Qp(m,a,g,b,x,i);g>=y&&(h+=a.slice(y,g)+_,y=g+m.length)}return h+a.slice(y)}]}),!!Gp((function(){var e=/./;return e.exec=function(){var e=[];return e.groups={a:"7"},e},"7"!=="".replace(e,"$<a>")}))||!nh||rh);var ih=Rn,oh=_,ah=[].join,sh=b!=Object,uh=rc("join",",");function ch(e){return JSON.parse(JSON.stringify(e))}function lh(e){return void 0===e||isNaN(Number(e))?null:Number(e)}function fh(e){try{return new Date(e)}catch(e){return null}}function dh(e,t,n){var r={};if(e)try{r=JSON.parse(e)}catch(e){n.warn(t,e)}return r}ih({target:"Array",proto:!0,forced:sh||!uh},{join:function(e){return ah.call(oh(this),void 0===e?",":e)}});var ph=function(){function e(t){Do(this,e),this.base=t.replace(/\/$/,""),this.args=[],this.paths=[]}return No(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}(),hh={},yh=Rn,vh=S,mh=kr,gh=qt,bh=Dt,wh=_,xh=xo,kh=pe,_h=co("slice"),Sh=kh("species"),Eh=[].slice,Th=Math.max;yh({target:"Array",proto:!0,forced:!_h},{slice:function(e,t){var n,r,i,o=wh(this),a=bh(o.length),s=gh(e,a),u=gh(void 0===t?a:t,a);if(mh(o)&&("function"!=typeof(n=o.constructor)||n!==Array&&!mh(n.prototype)?vh(n)&&null===(n=n[Sh])&&(n=void 0):n=void 0,n===Array||void 0===n))return Eh.call(o,s,u);for(r=new(void 0===n?Array:n)(Th(u-s,0)),i=0;s<u;s++,i++)s in o&&xh(r,i,o[s]);return r.length=i,r}});var Rh=Rn,Ch=S,Oh=function(){var e=!1,t=/[ac]/;return t.exec=function(){return e=!0,/./.exec.apply(this,arguments)},!0===t.test("abc")&&e}(),Ih=/./.test;Rh({target:"RegExp",proto:!0,forced:!Oh},{test:function(e){if("function"!=typeof this.exec)return Ih.call(this,e);var t=this.exec(e);if(null!==t&&!Ch(t))throw new Error("RegExp exec method returned something other than an Object or null");return!!t}});var Ah=Rn,Ph=s,jh=i,Lh=ee,Mh=S,Nh=Ne.f,Dh=fn,Uh=jh.Symbol;if(Ph&&"function"==typeof Uh&&(!("description"in Uh.prototype)||void 0!==Uh().description)){var Fh={},Bh=function(){var e=arguments.length<1||void 0===arguments[0]?void 0:String(arguments[0]),t=this instanceof Bh?new Uh(e):void 0===e?Uh():Uh(e);return""===e&&(Fh[t]=!0),t};Dh(Bh,Uh);var qh=Bh.prototype=Uh.prototype;qh.constructor=Bh;var zh=qh.toString,Wh="Symbol(test)"==String(Uh("test")),Gh=/^Symbol\((.*)\)[^)]+$/;Nh(qh,"description",{configurable:!0,get:function(){var e=Mh(this)?this.valueOf():this,t=zh.call(e);if(Lh(Fh,e))return"";var n=Wh?t.slice(7,-1):t.replace(Gh,"$1");return""===n?void 0:n}}),Ah({global:!0,forced:!0},{Symbol:Bh})}Nr("iterator");var $h={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}($h);var Jh=s,Kh=Ne.f,Vh=Function.prototype,Hh=Vh.toString,Yh=/^\s*function ([^ (]*)/,Qh="name";Jh&&!(Qh in Vh)&&Kh(Vh,Qh,{configurable:!0,get:function(){try{return Hh.call(this).match(Yh)[1]}catch(e){return""}}});var Xh={exports:{}},Zh={exports:{}};!function(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports}(Zh);var ey={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,o=[],a=!0,s=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==n.return||n.return()}finally{if(s)throw i}}return o}},e.exports.__esModule=!0,e.exports.default=e.exports}(ey);var ty={exports:{}},ny={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}(ny),function(e){var t=ny.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}(ty);var ry={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}(ry),function(e){var t=Zh.exports,n=ey.exports,r=ty.exports,i=ry.exports;e.exports=function(e,o){return t(e)||n(e,o)||r(e,o)||i()},e.exports.__esModule=!0,e.exports.default=e.exports}(Xh);var iy={exports:{}},oy={exports:{}};!function(e){var t=ny.exports;e.exports=function(e){if(Array.isArray(e))return t(e)},e.exports.__esModule=!0,e.exports.default=e.exports}(oy);var ay={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}(ay);var sy={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}(sy),function(e){var t=oy.exports,n=ay.exports,r=ty.exports,i=sy.exports;e.exports=function(e){return t(e)||n(e)||r(e)||i()},e.exports.__esModule=!0,e.exports.default=e.exports}(iy);var uy={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}(uy);var cy={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}(cy);var ly={exports:{}},fy={exports:{}};!function(e){function t(n,r){return e.exports=t=Object.setPrototypeOf||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}(fy),function(e){var t=fy.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}(ly);var dy={exports:{}},py={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}(py),function(e){var t=$h.exports.default,n=py.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}(dy);var hy={exports:{}};!function(e){function t(n){return e.exports=t=Object.setPrototypeOf?Object.getPrototypeOf: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}(hy);var yy=Jt.includes,vy=zf;Rn({target:"Array",proto:!0},{includes:function(e){return yy(this,e,arguments.length>1?arguments[1]:void 0)}}),vy("includes");var my=S,gy=Math.floor,by=function(e){return!my(e)&&isFinite(e)&&gy(e)===e};Rn({target:"Number",stat:!0},{isInteger:by});var wy=s,xy=Un,ky=_,_y=u.f,Sy=function(e){return function(t){for(var n,r=ky(t),i=xy(r),o=i.length,a=0,s=[];o>a;)n=i[a++],wy&&!_y.call(r,n)||s.push(e?[n,r[n]]:r[n]);return s}},Ey={entries:Sy(!0),values:Sy(!1)}.entries;Rn({target:"Object",stat:!0},{entries:function(e){return Ey(e)}}),Object.defineProperty(hh,"__esModule",{value:!0});var Ty=Xh.exports,Ry=iy.exports,Cy=uy.exports,Oy=cy.exports,Iy=ly.exports,Ay=dy.exports,Py=hy.exports;function jy(e){return e&&"object"===Ao(e)&&"default"in e?e:{default:e}}var Ly=jy($h.exports),My=jy(Ty),Ny=jy(Ry),Dy=jy(Cy),Uy=jy(Oy),Fy=jy(Iy),By=jy(Ay),qy=jy(Py),zy=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return{checks:t}};function Wy(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Gy(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 Gy(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function Gy(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var $y=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return zy((function(e){var n,r=!1,i=[],o=Wy(t);try{for(o.s();!(n=o.n()).done;){var a=n.value;"string"!=typeof a?(r=r||e instanceof a,i.push("an instance of ".concat(a.name))):(r=r||Ly.default(e)===a,i.push("of type ".concat(a)))}}catch(e){o.e(e)}finally{o.f()}return[r,i]}))};function Jy(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 Ky(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 Ky(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function Ky(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 Vy(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=qy.default(e);if(t){var i=qy.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return By.default(this,n)}}function Hy(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 Yy(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 Yy(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function Yy(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 Qy=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=Hy(t.entries());try{for(r.s();!(n=r.n()).done;){var i=My.default(n.value,2),o=i[0],a=i[1],s=tv(e[o],a),u=My.default(s,4),c=u[0],l=u[1],f=u[2],d=u[3];if(!c)throw new Error("Argument ".concat(o+1," is expected to be ").concat(f).concat(d," but got ").concat(l))}}catch(e){r.e(e)}finally{r.f()}},Xy=function(e){var t,n,r;(["undefined","boolean","number","bigint","string"].includes(Ly.default(e))&&(n="string"==typeof e?'"'.concat(e,'"'):"".concat(e)),"object"===Ly.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=Ly.default(e)),n},Zy=function(e){var t,n=[],r=Hy(e);try{for(r.s();!(t=r.n()).done;){var i=t.value;n.push(ev(i))}}catch(e){r.e(e)}finally{r.f()}return n},ev=function(e){var t,n=[],r=Hy(Array.isArray(e)?e:[e]);try{for(r.s();!(t=r.n()).done;){var i=t.value;"string"!=typeof i&&"function"!=typeof i?n.push(i):n.push($y(i))}}catch(e){r.e(e)}finally{r.f()}return n},tv=function(e,t){var n,r,i=[],o=!1,a=Hy(e);try{for(a.s();!(r=a.n()).done;){var s,u=Hy(r.value.checks);try{for(u.s();!(s=u.n()).done;){var c=(0,s.value)(t),l=My.default(c,3),f=l[0],d=l[1],p=l[2];o=o||f,!n&&p&&(n=p),d&&(i=[].concat(Ny.default(i),"string"==typeof d?[d]:Ny.default(d)))}}catch(e){u.e(e)}finally{u.f()}}}catch(e){a.e(e)}finally{a.f()}if(o)return[!0];var h=n||Xy(t),y=i.length-1;return[!1,h,y>0?"".concat(i.slice(0,y).join(", ")," or ").concat(i[y]):i.join(", "),y>1?";":","]};function nv(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}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=zy((function(e){return["string"==typeof e&&e.length>0,"a non-empty string"]})),ov=zy((function(e){return["number"==typeof e&&Number.isInteger(e)&&e>=0,"a non-negative integer"]})),av=zy((function(e){return["object"===Ly.default(e)&&null!==e&&!Array.isArray(e),"a pure object (non-null and non-array)"]}));function sv(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 uv(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 uv(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function uv(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}hh.array=function(e,t){return zy((function(n){if(!Array.isArray(n))return[!1,"an array of ".concat(e)];var r,i=sv(n.entries());try{for(i.s();!(r=i.n()).done;){var o=My.default(r.value,2),a=o[0],s=o[1],u=tv(ev(t),s),c=My.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"a valid array of ".concat(e," (index ").concat(a," should be ").concat(d,")"),"malformed array of ".concat(e," (index ").concat(a," is ").concat(f,")")]}}catch(e){i.e(e)}finally{i.f()}return[!0]}))};var cv=hh.custom=zy,lv=hh.literal=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return zy((function(e){var n,r=!1,i=[],o=Jy(t);try{for(o.s();!(n=o.n()).done;){var a=n.value;r=r||e===a,i.push("string"==typeof a?'"'.concat(a,'"'):"".concat(a))}}catch(e){o.e(e)}finally{o.f()}return[r,i]}))},fv=hh.nonEmptyArray=function(e,t){return zy((function(n){if(!Array.isArray(n)||n.length<1)return[!1,"a non-empty array of ".concat(e)];var r,i=nv(n.entries());try{for(i.s();!(r=i.n()).done;){var o=My.default(r.value,2),a=o[0],s=o[1],u=tv(ev(t),s),c=My.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(a," should be ").concat(d,")"),"malformed array of ".concat(e," (index ").concat(a," is ").concat(f,")")]}}catch(e){i.e(e)}finally{i.f()}return[!0]}))},dv=hh.nonEmptyString=iv,pv=hh.nonNegativeInteger=ov,hv=hh.objectSchema=function(e,t){return zy((function(n){if("object"!==Ly.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 o=My.default(i[r],2),a=o[0],s=o[1],u=tv(ev(s),n[a]),c=My.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"valid ".concat(e,' (key "').concat(a,'" should be ').concat(d,")"),"malformed ".concat(e,' (key "').concat(a,'" is ').concat(f,")")]}return[!0]}))},yv=hh.pureObject=av;hh.runtimeTypeValidation=Qy,hh.stringifyReceivedType=Xy,hh.type=$y;var vv=hh.validateConstructorTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Zy(t);return function(e){return function(e){Fy.default(n,e);var t=Vy(n);function n(){Uy.default(this,n);for(var e=arguments.length,i=new Array(e),o=0;o<e;o++)i[o]=arguments[o];return Qy(r,i),t.call.apply(t,[this].concat(i))}return Dy.default(n)}(e)}},mv=hh.validateTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Zy(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 Qy(r,t),i.apply(this,t)}}},gv=hh.validateTypesAsync=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Zy(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{Qy(r,t)}catch(e){return Promise.reject(e)}return i.apply(this,t)}}},bv=cv((function(e){return[["string","number","boolean","object"].includes(Ao(e)),"a JSON type"]})),wv=cv((function(e){return[["undefined","string","number","boolean","object"].includes(Ao(e)),"an optional JSON type"]})),xv={},kv={exports:{}},_v={exports:{}};!function(e){var t=hy.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}(_v),function(e){var t=_v.exports;function n(){return"undefined"!=typeof Reflect&&Reflect.get?(e.exports=n=Reflect.get,e.exports.__esModule=!0,e.exports.default=e.exports):(e.exports=n=function(e,n,r){var i=t(e,n);if(i){var o=Object.getOwnPropertyDescriptor(i,n);return o.get?o.get.call(arguments.length<3?e:r):o.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}(kv);var Sv={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}(Sv),Object.defineProperty(xv,"__esModule",{value:!0});var Ev=cy.exports,Tv=uy.exports,Rv=py.exports,Cv=kv.exports,Ov=ly.exports,Iv=dy.exports,Av=hy.exports,Pv=Sv.exports;function jv(e){return e&&"object"===Ao(e)&&"default"in e?e:{default:e}}var Lv=jv(iy.exports),Mv=jv(Ev),Nv=jv(Tv),Dv=jv(Rv),Uv=jv(Cv),Fv=jv(Ov),Bv=jv(Iv),qv=jv(Av),zv=jv(Pv);function Wv(){}function Gv(){Gv.init.call(this)}function $v(e){return void 0===e._maxListeners?Gv.defaultMaxListeners:e._maxListeners}function Jv(e,t,n){if(t)e.call(n);else for(var r=e.length,i=em(e,r),o=0;o<r;++o)i[o].call(n)}function Kv(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,o=em(e,i),a=0;a<i;++a)o[a].call(n,r)}function Vv(e,t,n,r,i){if(t)e.call(n,r,i);else for(var o=e.length,a=em(e,o),s=0;s<o;++s)a[s].call(n,r,i)}function Hv(e,t,n,r,i,o){if(t)e.call(n,r,i,o);else for(var a=e.length,s=em(e,a),u=0;u<a;++u)s[u].call(n,r,i,o)}function Yv(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,o=em(e,i),a=0;a<i;++a)o[a].apply(n,r)}function Qv(e,t,n,r){var i,o,a,s;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]):(o=e._events=new Wv,e._eventsCount=0),a){if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),!a.warned&&(i=$v(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,"function"==typeof console.warn?console.warn(s):console.log(s)}}else a=o[t]=n,++e._eventsCount;return e}function Xv(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 Zv(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 em(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function tm(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=qv.default(e);if(t){var i=qv.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Bv.default(this,n)}}Wv.prototype=Object.create(null),Gv.EventEmitter=Gv,Gv.usingDomains=!1,Gv.prototype.domain=void 0,Gv.prototype._events=void 0,Gv.prototype._maxListeners=void 0,Gv.defaultMaxListeners=10,Gv.init=function(){this.domain=null,Gv.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new Wv,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},Gv.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},Gv.prototype.getMaxListeners=function(){return $v(this)},Gv.prototype.emit=function(e){var t,n,r,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.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=a[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:Jv(n,l,this);break;case 2:Kv(n,l,this,arguments[1]);break;case 3:Vv(n,l,this,arguments[1],arguments[2]);break;case 4:Hv(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),o=1;o<r;o++)i[o-1]=arguments[o];Yv(n,l,this,i)}return!0},Gv.prototype.addListener=function(e,t){return Qv(this,e,t,!1)},Gv.prototype.on=Gv.prototype.addListener,Gv.prototype.prependListener=function(e,t){return Qv(this,e,t,!0)},Gv.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,Xv(this,e,t)),this},Gv.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,Xv(this,e,t)),this},Gv.prototype.removeListener=function(e,t){var n,r,i,o,a;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 Wv:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length;o-- >0;)if(n[o]===t||n[o].listener&&n[o].listener===t){a=n[o].listener,i=o;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new Wv,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,a||t)}return this},Gv.prototype.off=function(e,t){return this.removeListener(e,t)},Gv.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new Wv,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new Wv:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new Wv,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},Gv.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):[]},Gv.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Zv.call(e,t)},Gv.prototype.listenerCount=Zv,Gv.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var nm=function(e){Fv.default(n,e);var t=tm(n);function n(){var e;return Mv.default(this,n),e=t.call(this),zv.default(Dv.default(e),"eventHistory",new Map),e}return Nv.default(n,[{key:"on",value:function(e,t){return Uv.default(qv.default(n.prototype),"on",this).call(this,e,t)}},{key:"once",value:function(e,t){return Uv.default(qv.default(n.prototype),"once",this).call(this,e,t)}},{key:"off",value:function(e,t){return Uv.default(qv.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),o=1;o<r;o++)i[o-1]=arguments[o];return this.eventHistory.set(e,i),(t=Uv.default(qv.default(n.prototype),"emit",this)).call.apply(t,[this,e].concat(i))}},{key:"addListener",value:function(e,t){return Uv.default(qv.default(n.prototype),"addListener",this).call(this,e,t)}},{key:"removeListener",value:function(e,t){return Uv.default(qv.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,Lv.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,Lv.default(r)),this):Uv.default(qv.default(n.prototype),"once",this).call(this,e,t)}}]),n}(Gv),rm=xv.ReplayEventEmitter=nm,im={exports:{}};!function(e,n){var r="__lodash_hash_undefined__",i=9007199254740991,o="[object Arguments]",a="[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]",y="[object RegExp]",v="[object Set]",m="[object String]",g="[object Symbol]",b="[object WeakMap]",w="[object ArrayBuffer]",x="[object DataView]",k=/^\[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[o]=S[a]=S[w]=S[s]=S[x]=S[u]=S[c]=S[l]=S[f]=S[d]=S[p]=S[y]=S[v]=S[m]=S[b]=!1;var E="object"==Ao(t)&&t&&t.Object===Object&&t,T="object"==("undefined"==typeof self?"undefined":Ao(self))&&self&&self.Object===Object&&self,R=E||T||Function("return this")(),C=n&&!n.nodeType&&n,O=C&&e&&!e.nodeType&&e,I=O&&O.exports===C,A=I&&E.process,P=function(){try{return A&&A.binding&&A.binding("util")}catch(e){}}(),j=P&&P.isTypedArray;function L(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 M(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 D(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n}var U,F,B=Array.prototype,q=Function.prototype,z=Object.prototype,W=R["__core-js_shared__"],G=q.toString,$=z.hasOwnProperty,J=function(){var e=/[^.]+$/.exec(W&&W.keys&&W.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),K=z.toString,V=RegExp("^"+G.call($).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),H=I?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=(U=Object.keys,F=Object,function(e){return U(F(e))}),ie=Pe(R,"DataView"),oe=Pe(R,"Map"),ae=Pe(R,"Promise"),se=Pe(R,"Set"),ue=Pe(R,"WeakMap"),ce=Pe(Object,"create"),le=Ne(ie),fe=Ne(oe),de=Ne(ae),pe=Ne(se),he=Ne(ue),ye=Y?Y.prototype:void 0,ve=ye?ye.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 xe(e){var t=this.__data__=new ge(e);this.size=t.size}function ke(e,t){var n=Fe(e),r=!n&&Ue(e),i=!n&&!r&&Be(e),o=!n&&!r&&!i&&$e(e),a=n||r||i||o,s=a?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&&!$.call(e,c)||a&&("length"==c||i&&("offset"==c||"parent"==c)||o&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||Me(c,u))||s.push(c);return s}function _e(e,t){for(var n=e.length;n--;)if(De(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=K.call(e);r&&(t?e[ee]=n:delete e[ee]);return i}(e):function(e){return K.call(e)}(e)}function Ee(e){return Ge(e)&&Se(e)==o}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),k=h?a:Le(e),_=b?a:Le(t),S=(k=k==o?p:k)==p,E=(_=_==o?p:_)==p,T=k==_;if(T&&Be(e)){if(!Be(t))return!1;h=!0,S=!1}if(T&&!S)return l||(l=new xe),h||$e(e)?Oe(e,t,n,r,i,l):function(e,t,n,r,i,o,a){switch(n){case x:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case w:return!(e.byteLength!=t.byteLength||!o(new Q(e),new Q(t)));case s:case u:case d:return De(+e,+t);case c:return e.name==t.name&&e.message==t.message;case y:case m:return e==t+"";case f:var l=N;case v:var p=1&r;if(l||(l=D),e.size!=t.size&&!p)return!1;var h=a.get(e);if(h)return h==t;r|=2,a.set(e,t);var b=Oe(l(e),l(t),r,i,o,a);return a.delete(e),b;case g:if(ve)return ve.call(e)==ve.call(t)}return!1}(e,t,k,n,r,i,l);if(!(1&n)){var R=S&&$.call(e,"__wrapped__"),C=E&&$.call(t,"__wrapped__");if(R||C){var O=R?e.value():e,I=C?t.value():t;return l||(l=new xe),i(O,I,n,r,l)}}if(!T)return!1;return l||(l=new xe),function(e,t,n,r,i,o){var a=1&n,s=Ie(e),u=s.length,c=Ie(t).length;if(u!=c&&!a)return!1;var l=u;for(;l--;){var f=s[l];if(!(a?f in t:$.call(t,f)))return!1}var d=o.get(e);if(d&&o.get(t))return d==t;var p=!0;o.set(e,t),o.set(t,e);var h=a;for(;++l<u;){var y=e[f=s[l]],v=t[f];if(r)var m=a?r(v,y,f,t,e,o):r(y,v,f,e,t,o);if(!(void 0===m?y===v||i(y,v,n,r,o):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 o.delete(e),o.delete(t),p}(e,t,n,r,i,l)}(e,t,n,r,Te,i))}function Re(e){return!(!We(e)||function(e){return!!J&&J in e}(e))&&(qe(e)?V:k).test(Ne(e))}function Ce(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 o in Object(e))$.call(e,o)&&"constructor"!=o&&i.push(o);return i}function Oe(e,t,n,r,i,o){var a=1&n,s=e.length,u=t.length;if(s!=u&&!(a&&u>s))return!1;var c=o.get(e);if(c&&o.get(t))return c==t;var l=-1,f=!0,d=2&n?new we:void 0;for(o.set(e,t),o.set(t,e);++l<s;){var p=e[l],h=t[l];if(r)var y=a?r(h,p,l,t,e,o):r(p,h,l,e,t,o);if(void 0!==y){if(y)continue;f=!1;break}if(d){if(!L(t,(function(e,t){if(!M(d,t)&&(p===e||i(p,e,n,r,o)))return d.push(t)}))){f=!1;break}}else if(p!==h&&!i(p,h,n,r,o)){f=!1;break}}return o.delete(e),o.delete(t),f}function Ie(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,Je,je)}function Ae(e,t){var n=e.__data__;return function(e){var t=Ao(e);return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}(t)?n["string"==typeof t?"string":"hash"]:n.map}function Pe(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(oe||ge),string:new me}},be.prototype.delete=function(e){var t=Ae(this,e).delete(e);return this.size-=t?1:0,t},be.prototype.get=function(e){return Ae(this,e).get(e)},be.prototype.has=function(e){return Ae(this,e).has(e)},be.prototype.set=function(e,t){var n=Ae(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)},xe.prototype.clear=function(){this.__data__=new ge,this.size=0},xe.prototype.delete=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n},xe.prototype.get=function(e){return this.__data__.get(e)},xe.prototype.has=function(e){return this.__data__.has(e)},xe.prototype.set=function(e,t){var n=this.__data__;if(n instanceof ge){var r=n.__data__;if(!oe||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,o=[];++n<r;){var a=e[n];t(a,n,e)&&(o[i++]=a)}return o}(te(e),(function(t){return X.call(e,t)})))}:function(){return[]},Le=Se;function Me(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 De(e,t){return e===t||e!=e&&t!=t}(ie&&Le(new ie(new ArrayBuffer(1)))!=x||oe&&Le(new oe)!=f||ae&&Le(ae.resolve())!=h||se&&Le(new se)!=v||ue&&Le(new ue)!=b)&&(Le=function(e){var t=Se(e),n=t==p?e.constructor:void 0,r=n?Ne(n):"";if(r)switch(r){case le:return x;case fe:return f;case de:return h;case pe:return v;case he:return b}return t});var Ue=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=Ao(e);return null!=e&&("object"==t||"function"==t)}function Ge(e){return null!=e&&"object"==Ao(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 Je(e){return null!=(t=e)&&ze(t.length)&&!qe(t)?ke(e):Ce(e);var t}e.exports=function(e,t){return Te(e,t)}}(im,im.exports);var om=im.exports;function am(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=jo(e);if(t){var i=jo(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Po(this,n)}}var sm=Tf.scope("User"),User=function(e){Io(User,e);var t,n,r,i,o,a,s,u=am(User);function User(e,t,n,r){var i;return Do(this,User),Lo(Co(i=u.call(this)),"promiseToFetch",null),Lo(Co(i),"updated","updated"),Lo(Co(i),"userSubscribed","userSubscribed"),Lo(Co(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 No(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=Ro(zc.mark((function e(t,n){var r,i;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._initializationPromise;case 2:r=[],sm.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=dh(n.value,"Retrieved malformed attributes from the server for user: ".concat(this.state.identity),sm),om(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:(a=Ro(zc.mark((function e(t,n){var r=this;return zc.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){sm.warn("Failed to get reachability info for ",r.state.identity,e)})));case 5:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"_fetch",value:(o=Ro(zc.mark((function e(){var t=this;return zc.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 sm.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 sm.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 o.apply(this,arguments)})},{key:"_ensureFetched",value:(i=Ro(zc.mark((function e(){return zc.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=Ro(zc.mark((function e(t){return zc.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=Ro(zc.mark((function e(t){return zc.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=Ro(zc.mark((function e(){return zc.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}(rm);function um(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 cm(e,t){if(e){if("string"==typeof e)return um(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)?um(e,t):void 0}}function lm(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,o=[],a=!0,s=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==n.return||n.return()}finally{if(s)throw i}}return o}}(e,t)||cm(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.")}()}Gc([gv(bv),$c("design:type",Function),$c("design:paramtypes",[Object]),$c("design:returntype",Promise)],User.prototype,"updateAttributes",null),Gc([gv(["string"]),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],User.prototype,"updateFriendlyName",null);var fm={exports:{}},dm=!a((function(){return Object.isExtensible(Object.preventExtensions({}))})),pm=Rn,hm=st,ym=S,vm=ee,mm=Ne.f,gm=At,bm=Er,wm=dm,xm=!1,km=re("meta"),_m=0,Sm=Object.isExtensible||function(){return!0},Em=function(e){mm(e,km,{value:{objectID:"O"+_m++,weakData:{}}})},Tm=fm.exports={enable:function(){Tm.enable=function(){},xm=!0;var e=gm.f,t=[].splice,n={};n[km]=1,e(n).length&&(gm.f=function(n){for(var r=e(n),i=0,o=r.length;i<o;i++)if(r[i]===km){t.call(r,i,1);break}return r},pm({target:"Object",stat:!0,forced:!0},{getOwnPropertyNames:bm.f}))},fastKey:function(e,t){if(!ym(e))return"symbol"==typeof e?e:("string"==typeof e?"S":"P")+e;if(!vm(e,km)){if(!Sm(e))return"F";if(!t)return"E";Em(e)}return e[km].objectID},getWeakData:function(e,t){if(!vm(e,km)){if(!Sm(e))return!0;if(!t)return!1;Em(e)}return e[km].weakData},onFreeze:function(e){return wm&&xm&&Sm(e)&&!vm(e,km)&&Em(e),e}};hm[km]=!0;var Rm=Rn,Cm=i,Om=bn,Im=Ke.exports,Am=fm.exports,Pm=Aa,jm=ua,Lm=S,Mm=a,Nm=Ba,Dm=An,Um=bd,Fm=function(e,t,n){var r=-1!==e.indexOf("Map"),i=-1!==e.indexOf("Weak"),o=r?"set":"add",a=Cm[e],s=a&&a.prototype,u=a,c={},l=function(e){var t=s[e];Im(s,e,"add"==e?function(e){return t.call(this,0===e?0:e),this}:"delete"==e?function(e){return!(i&&!Lm(e))&&t.call(this,0===e?0:e)}:"get"==e?function(e){return i&&!Lm(e)?void 0:t.call(this,0===e?0:e)}:"has"==e?function(e){return!(i&&!Lm(e))&&t.call(this,0===e?0:e)}:function(e,n){return t.call(this,0===e?0:e,n),this})};if(Om(e,"function"!=typeof a||!(i||s.forEach&&!Mm((function(){(new a).entries().next()})))))u=n.getConstructor(t,e,r,o),Am.enable();else if(Om(e,!0)){var f=new u,d=f[o](i?{}:-0,1)!=f,p=Mm((function(){f.has(1)})),h=Nm((function(e){new a(e)})),y=!i&&Mm((function(){for(var e=new a,t=5;t--;)e[o](t,t);return!e.has(-0)}));h||((u=t((function(t,n){jm(t,u,e);var i=Um(new a,t,u);return null!=n&&Pm(n,i[o],{that:i,AS_ENTRIES:r}),i}))).prototype=s,s.constructor=u),(p||y)&&(l("delete"),l("has"),r&&l("get")),(y||d)&&l(o),i&&s.clear&&delete s.clear}return c[e]=u,Rm({global:!0,forced:u!=a},c),Dm(u,e),i||n.setStrong(u,e,r),u},Bm=Ne.f,qm=tr,zm=Xo,Wm=Ur,Gm=ua,$m=Aa,Jm=lf,Km=sa,Vm=s,Hm=fm.exports.fastKey,Ym=kt.set,Qm=kt.getterFor,Xm={getConstructor:function(e,t,n,r){var i=e((function(e,o){Gm(e,i,t),Ym(e,{type:t,index:qm(null),first:void 0,last:void 0,size:0}),Vm||(e.size=0),null!=o&&$m(o,e[r],{that:e,AS_ENTRIES:n})})),o=Qm(t),a=function(e,t,n){var r,i,a=o(e),u=s(e,t);return u?u.value=n:(a.last=u={index:i=Hm(t,!0),key:t,value:n,previous:r=a.last,next:void 0,removed:!1},a.first||(a.first=u),r&&(r.next=u),Vm?a.size++:e.size++,"F"!==i&&(a.index[i]=u)),e},s=function(e,t){var n,r=o(e),i=Hm(t);if("F"!==i)return r.index[i];for(n=r.first;n;n=n.next)if(n.key==t)return n};return zm(i.prototype,{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,Vm?e.size=0:this.size=0},delete:function(e){var t=this,n=o(t),r=s(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),Vm?n.size--:t.size--}return!!r},forEach:function(e){for(var t,n=o(this),r=Wm(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!!s(this,e)}}),zm(i.prototype,n?{get:function(e){var t=s(this,e);return t&&t.value},set:function(e,t){return a(this,0===e?0:e,t)}}:{add:function(e){return a(this,e=0===e?0:e,e)}}),Vm&&Bm(i.prototype,"size",{get:function(){return o(this).size}}),i},setStrong:function(e,t,n){var r=t+" Iterator",i=Qm(t),o=Qm(r);Jm(e,t,(function(e,t){Ym(this,{type:r,target:e,state:i(e),kind:t,last:void 0})}),(function(){for(var e=o(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),Km(t)}};Fm("Map",(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),Xm);var Zm={};Object.defineProperty(Zm,"__esModule",{value:!0});var eg=uy.exports,tg=py.exports,ng=ly.exports,rg=dy.exports,ig=hy.exports,og=Sv.exports;function ag(e){return e&&"object"===Ao(e)&&"default"in e?e:{default:e}}var sg=ag(cy.exports),ug=ag(eg),cg=ag(tg),lg=ag(ng),fg=ag(rg),dg=ag(ig),pg=ag(og);function hg(){}function yg(){yg.init.call(this)}function vg(e){return void 0===e._maxListeners?yg.defaultMaxListeners:e._maxListeners}function mg(e,t,n){if(t)e.call(n);else for(var r=e.length,i=Eg(e,r),o=0;o<r;++o)i[o].call(n)}function gg(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,o=Eg(e,i),a=0;a<i;++a)o[a].call(n,r)}function bg(e,t,n,r,i){if(t)e.call(n,r,i);else for(var o=e.length,a=Eg(e,o),s=0;s<o;++s)a[s].call(n,r,i)}function wg(e,t,n,r,i,o){if(t)e.call(n,r,i,o);else for(var a=e.length,s=Eg(e,a),u=0;u<a;++u)s[u].call(n,r,i,o)}function xg(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,o=Eg(e,i),a=0;a<i;++a)o[a].apply(n,r)}function kg(e,t,n,r){var i,o,a,s;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]):(o=e._events=new hg,e._eventsCount=0),a){if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),!a.warned&&(i=vg(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,"function"==typeof console.warn?console.warn(s):console.log(s)}}else a=o[t]=n,++e._eventsCount;return e}function _g(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 Sg(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 Eg(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function Tg(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=dg.default(e);if(t){var i=dg.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return fg.default(this,n)}}hg.prototype=Object.create(null),yg.EventEmitter=yg,yg.usingDomains=!1,yg.prototype.domain=void 0,yg.prototype._events=void 0,yg.prototype._maxListeners=void 0,yg.defaultMaxListeners=10,yg.init=function(){this.domain=null,yg.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new hg,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},yg.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},yg.prototype.getMaxListeners=function(){return vg(this)},yg.prototype.emit=function(e){var t,n,r,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.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=a[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:mg(n,l,this);break;case 2:gg(n,l,this,arguments[1]);break;case 3:bg(n,l,this,arguments[1],arguments[2]);break;case 4:wg(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),o=1;o<r;o++)i[o-1]=arguments[o];xg(n,l,this,i)}return!0},yg.prototype.addListener=function(e,t){return kg(this,e,t,!1)},yg.prototype.on=yg.prototype.addListener,yg.prototype.prependListener=function(e,t){return kg(this,e,t,!0)},yg.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,_g(this,e,t)),this},yg.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,_g(this,e,t)),this},yg.prototype.removeListener=function(e,t){var n,r,i,o,a;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 hg:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length;o-- >0;)if(n[o]===t||n[o].listener&&n[o].listener===t){a=n[o].listener,i=o;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new hg,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,a||t)}return this},yg.prototype.off=function(e,t){return this.removeListener(e,t)},yg.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new hg,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new hg:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new hg,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},yg.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):[]},yg.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Sg.call(e,t)},yg.prototype.listenerCount=Sg,yg.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var Rg=function(e){lg.default(n,e);var t=Tg(n);function n(e){var r;return sg.default(this,n),r=t.call(this),pg.default(cg.default(r),"timeout",null),pg.default(cg.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 ug.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}(yg),Cg=function(e){lg.default(n,e);var t=Tg(n);function n(e){var r;return sg.default(this,n),r=t.call(this),pg.default(cg.default(r),"resolve",(function(){})),pg.default(cg.default(r),"reject",(function(){})),r.retrier=new Rg(e),r}return ug.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}(yg);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=dg.default(e);if(t){var i=dg.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return fg.default(this,n)}}function Ig(e){return null!=e}var Ag=function(e){lg.default(n,e);var t=Og(n);function n(e){var r;sg.default(this,n),r=t.call(this),pg.default(cg.default(r),"backoffDelay",0),pg.default(cg.default(r),"nextBackoffDelay",0),pg.default(cg.default(r),"backoffNumber",0),pg.default(cg.default(r),"timeoutID",null),pg.default(cg.default(r),"maxNumberOfRetry",-1);var i=e=e||{},o=i.initialDelay,a=i.maxDelay,s=i.randomisationFactor,u=i.factor;if(Ig(o)&&o<1)throw new Error("The initial timeout must be equal to or greater than 1.");if(Ig(a)&&a<=1)throw new Error("The maximal timeout must be greater than 1.");if(Ig(s)&&(s<0||s>1))throw new Error("The randomisation factor must be between 0 and 1.");if(Ig(u)&&u<=1)throw new Error("Exponential factor should be greater than 1.");if(r.initialDelay=o||100,r.maxDelay=a||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 ug.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}(yg),Pg=Zm.AsyncRetrier=Cg;Zm.Backoff=Ag;var jg=Zm.Retrier=Rg;function Lg(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 Mg(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 Mg(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function Mg(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 Ng=function(){function e(t,n){Do(this,e),this.configuration=t,this.services=n,this.cache=new Map,this.cacheLifetime=100*this.configuration.httpCacheInterval,this.cleanupCache()}return No(e,[{key:"isExpired",value:function(e){return!this.cacheLifetime||Date.now()-e>this.cacheLifetime}},{key:"cleanupCache",value:function(){var e,t=Lg(this.cache);try{for(t.s();!(e=t.n()).done;){var n=lm(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 o=[502,503,504];n&&o.push(429);var a=new jg(t.configuration.backoffConfiguration);a.on("attempt",(function(){e().then((function(e){return a.succeeded(e)})).catch((function(e){o.indexOf(e.status)>-1||"Twilsock disconnected"===e.message?a.failed(e):(a.removeAllListeners(),a.cancel(),i(e))}))})),a.on("succeeded",(function(e){r(e)})),a.on("cancelled",(function(e){return i(e)})),a.on("failed",(function(e){return i(e)})),a.start()}))}},{key:"get",value:function(){var e=Ro(zc.mark((function e(t){var n,r,i,o=this;return zc.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 o.services.transport.get(t,r,o.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}(),Dg=No((function e(){Do(this,e)}));function Ug(e){return(Ug="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)}Lo(Dg,"TYPING_INDICATOR","twilio.ipmsg.typing_indicator"),Lo(Dg,"NEW_MESSAGE","twilio.conversations.new_message"),Lo(Dg,"ADDED_TO_CONVERSATION","twilio.conversations.added_to_conversation"),Lo(Dg,"REMOVED_FROM_CONVERSATION","twilio.conversations.removed_from_conversation"),Lo(Dg,"CONSUMPTION_UPDATE","twilio.channel.consumption_update");var Fg={},Bg={exports:{}};!function(e){function t(e,t,n,r,i,o,a){try{var s=e[o](a),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,o){var a=e.apply(n,r);function s(e){t(a,i,o,s,u,"next",e)}function u(e){t(a,i,o,s,u,"throw",e)}s(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports}(Bg);var qg={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}(qg);var zg={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}(zg);var Wg={exports:{}},Gg={exports:{}},$g={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}($g),function(e){var t=$g.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}(Gg),function(e){var t=Gg.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 o=Object.getOwnPropertyDescriptor(i,n);return o.get?o.get.call(arguments.length<3?e:r):o.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}(Wg);var Jg={exports:{}},Kg={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}(Kg),function(e){var t=Kg.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}(Jg);var Vg={exports:{}},Hg={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}(Hg),function(e){var t=Hg.exports.default,n=zg.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}(Vg);var Yg={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}(Yg);var Qg={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}(Qg);var Xg,Zg=Object.prototype,eb=Zg.hasOwnProperty,tb="function"==typeof Symbol?Symbol:{},nb=tb.iterator||"@@iterator",rb=tb.asyncIterator||"@@asyncIterator",ib=tb.toStringTag||"@@toStringTag";function ob(e,t,n,r){var i=t&&t.prototype instanceof db?t:db,o=Object.create(i.prototype),a=new Eb(r||[]);return o._invoke=function(e,t,n){var r=sb;return function(i,o){if(r===cb)throw new Error("Generator is already running");if(r===lb){if("throw"===i)throw o;return Rb()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var s=kb(a,n);if(s){if(s===fb)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===sb)throw r=lb,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=cb;var u=ab(e,t,n);if("normal"===u.type){if(r=n.done?lb:ub,u.arg===fb)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=lb,n.method="throw",n.arg=u.arg)}}}(e,n,a),o}function ab(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}var sb="suspendedStart",ub="suspendedYield",cb="executing",lb="completed",fb={};function db(){}function pb(){}function hb(){}var yb={};yb[nb]=function(){return this};var vb=Object.getPrototypeOf,mb=vb&&vb(vb(Tb([])));mb&&mb!==Zg&&eb.call(mb,nb)&&(yb=mb);var gb=hb.prototype=db.prototype=Object.create(yb);function bb(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function wb(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===pb||"GeneratorFunction"===(t.displayName||t.name))}function xb(e,t){function n(r,i,o,a){var s=ab(e[r],e,i);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"===Ug(c)&&eb.call(c,"__await")?t.resolve(c.__await).then((function(e){n("next",e,o,a)}),(function(e){n("throw",e,o,a)})):t.resolve(c).then((function(e){u.value=e,o(u)}),(function(e){return n("throw",e,o,a)}))}a(s.arg)}var r;this._invoke=function(e,i){function o(){return new t((function(t,r){n(e,i,t,r)}))}return r=r?r.then(o,o):o()}}function kb(e,t){var n=e.iterator[t.method];if(n===Xg){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=Xg,kb(e,t),"throw"===t.method))return fb;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return fb}var r=ab(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,fb;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=Xg),t.delegate=null,fb):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,fb)}function _b(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 Sb(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function Eb(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(_b,this),this.reset(!0)}function Tb(e){if(e){var t=e[nb];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(eb.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=Xg,t.done=!0,t};return r.next=r}}return{next:Rb}}function Rb(){return{value:Xg,done:!0}}pb.prototype=gb.constructor=hb,hb.constructor=pb,hb[ib]=pb.displayName="GeneratorFunction",bb(xb.prototype),xb.prototype[rb]=function(){return this},bb(gb),gb[ib]="Generator",gb[nb]=function(){return this},gb.toString=function(){return"[object Generator]"},Eb.prototype={constructor:Eb,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=Xg,this.done=!1,this.delegate=null,this.method="next",this.arg=Xg,this.tryEntries.forEach(Sb),!e)for(var t in this)"t"===t.charAt(0)&&eb.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=Xg)},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 o.type="throw",o.arg=e,t.next=n,r&&(t.method="next",t.arg=Xg),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],o=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=eb.call(i,"catchLoc"),s=eb.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){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&&eb.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 o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,fb):this.complete(o)},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),fb},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),Sb(n),fb}},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;Sb(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:Tb(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=Xg),fb}};var Cb={wrap:ob,isGeneratorFunction:wb,AsyncIterator:xb,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,hb):(e.__proto__=hb,ib in e||(e[ib]="GeneratorFunction")),e.prototype=Object.create(gb),e},awrap:function(e){return{__await:e}},async:function(e,t,n,r,i){void 0===i&&(i=Promise);var o=new xb(ob(e,t,n,r),i);return wb(t)?o:o.next().then((function(e){return e.done?e.value:o.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:Tb},Ob=n(Object.freeze({__proto__:null,default:Cb})),Ib=Ke.exports,Ab=Ue,Pb=Sr,jb=a,Lb=Xd,Mb="toString",Nb=RegExp.prototype,Db=Nb.toString,Ub=jb((function(){return"/a/b"!=Db.call({source:"a",flags:"b"})})),Fb=Db.name!=Mb;(Ub||Fb)&&Ib(RegExp.prototype,Mb,(function(){var e=Ab(this),t=Pb(e.source),n=e.flags;return"/"+t+"/"+Pb(void 0===n&&e instanceof RegExp&&!("flags"in Nb)?Lb.call(e):n)}),{unsafe:!0});var Bb={},qb={exports:{}},zb={exports:{}};!function(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports}(zb);var Wb={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,o=[],a=!0,s=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==n.return||n.return()}finally{if(s)throw i}}return o}},e.exports.__esModule=!0,e.exports.default=e.exports}(Wb);var Gb={exports:{}},$b={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}($b),function(e){var t=$b.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}(Gb);var Jb={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}(Jb),function(e){var t=zb.exports,n=Wb.exports,r=Gb.exports,i=Jb.exports;e.exports=function(e,o){return t(e)||n(e,o)||r(e,o)||i()},e.exports.__esModule=!0,e.exports.default=e.exports}(qb);var Kb={exports:{}},Vb={exports:{}};!function(e){var t=$b.exports;e.exports=function(e){if(Array.isArray(e))return t(e)},e.exports.__esModule=!0,e.exports.default=e.exports}(Vb);var Hb={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}(Hb);var Yb={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}(Yb),function(e){var t=Vb.exports,n=Hb.exports,r=Gb.exports,i=Yb.exports;e.exports=function(e){return t(e)||n(e)||r(e)||i()},e.exports.__esModule=!0,e.exports.default=e.exports}(Kb),Object.defineProperty(Bb,"__esModule",{value:!0});var Qb=qb.exports,Xb=Kb.exports,Zb=Yg.exports,ew=Jg.exports,tw=Vg.exports,nw=$g.exports;function rw(e){return e&&"object"===Ug(e)&&"default"in e?e:{default:e}}var iw=rw(Hg.exports),ow=rw(Qb),aw=rw(Xb),sw=rw(Zb),uw=rw(ew),cw=rw(tw),lw=rw(nw),fw=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return{checks:t}};function dw(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 pw(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 pw(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function pw(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 hw=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return fw((function(e){var n,r=!1,i=[],o=dw(t);try{for(o.s();!(n=o.n()).done;){var a=n.value;"string"!=typeof a?(r=r||e instanceof a,i.push("an instance of ".concat(a.name))):(r=r||iw.default(e)===a,i.push("of type ".concat(a)))}}catch(e){o.e(e)}finally{o.f()}return[r,i]}))};function yw(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 vw(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 vw(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function vw(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 mw=fw((function(e){return["string"==typeof e&&e.length>0,"a non-empty string"]})),gw=fw((function(e){return["number"==typeof e&&Number.isInteger(e)&&e>=0,"a non-negative integer"]})),bw=fw((function(e){return["object"===iw.default(e)&&null!==e&&!Array.isArray(e),"a pure object (non-null and non-array)"]}));function ww(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=lw.default(e);if(t){var i=lw.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return cw.default(this,n)}}function xw(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 kw(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 kw(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function kw(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 _w=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=xw(t.entries());try{for(r.s();!(n=r.n()).done;){var i=ow.default(n.value,2),o=i[0],a=i[1],s=Rw(e[o],a),u=ow.default(s,4),c=u[0],l=u[1],f=u[2],d=u[3];if(!c)throw new Error("Argument ".concat(o+1," is expected to be ").concat(f).concat(d," but got ").concat(l))}}catch(e){r.e(e)}finally{r.f()}},Sw=function(e){var t,n,r;(["undefined","boolean","number","bigint","string"].includes(iw.default(e))&&(n="string"==typeof e?'"'.concat(e,'"'):"".concat(e)),"object"===iw.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=iw.default(e)),n},Ew=function(e){var t,n=[],r=xw(e);try{for(r.s();!(t=r.n()).done;){var i=t.value;n.push(Tw(i))}}catch(e){r.e(e)}finally{r.f()}return n},Tw=function(e){var t,n=[],r=xw(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(hw(i))}}catch(e){r.e(e)}finally{r.f()}return n},Rw=function(e,t){var n,r,i=[],o=!1,a=xw(e);try{for(a.s();!(r=a.n()).done;){var s,u=xw(r.value.checks);try{for(u.s();!(s=u.n()).done;){var c=(0,s.value)(t),l=ow.default(c,3),f=l[0],d=l[1],p=l[2];o=o||f,!n&&p&&(n=p),d&&(i=[].concat(aw.default(i),"string"==typeof d?[d]:aw.default(d)))}}catch(e){u.e(e)}finally{u.f()}}}catch(e){a.e(e)}finally{a.f()}if(o)return[!0];var h=n||Sw(t),y=i.length-1;return[!1,h,y>0?"".concat(i.slice(0,y).join(", ")," or ").concat(i[y]):i.join(", "),y>1?";":","]};function Cw(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 Ow(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 Ow(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function Ow(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}Bb.array=function(e,t){return fw((function(n){if(!Array.isArray(n))return[!1,"an array of ".concat(e)];var r,i=Cw(n.entries());try{for(i.s();!(r=i.n()).done;){var o=ow.default(r.value,2),a=o[0],s=o[1],u=Rw(Tw(t),s),c=ow.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"a valid array of ".concat(e," (index ").concat(a," should be ").concat(d,")"),"malformed array of ".concat(e," (index ").concat(a," is ").concat(f,")")]}}catch(e){i.e(e)}finally{i.f()}return[!0]}))},Bb.custom=fw,Bb.literal=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return fw((function(e){var n,r=!1,i=[],o=yw(t);try{for(o.s();!(n=o.n()).done;){var a=n.value;r=r||e===a,i.push("string"==typeof a?'"'.concat(a,'"'):"".concat(a))}}catch(e){o.e(e)}finally{o.f()}return[r,i]}))},Bb.nonEmptyString=mw,Bb.nonNegativeInteger=gw,Bb.objectSchema=function(e,t){return fw((function(n){if("object"!==iw.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 o=ow.default(i[r],2),a=o[0],s=o[1],u=Rw(Tw(s),n[a]),c=ow.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"valid ".concat(e,' (key "').concat(a,'" should be ').concat(d,")"),"malformed ".concat(e,' (key "').concat(a,'" is ').concat(f,")")]}return[!0]}))},Bb.pureObject=bw,Bb.runtimeTypeValidation=_w,Bb.stringifyReceivedType=Sw,Bb.type=hw,Bb.validateConstructorTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Ew(t);return function(e){return function(e){uw.default(n,e);var t=ww(n);function n(){sw.default(this,n);for(var e=arguments.length,i=new Array(e),o=0;o<e;o++)i[o]=arguments[o];return _w(r,i),t.call.apply(t,[this].concat(i))}return n}(e)}},Bb.validateTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Ew(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 _w(r,t),i.apply(this,t)}}},Bb.validateTypesAsync=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=Ew(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{_w(r,t)}catch(e){return Promise.reject(e)}return i.apply(this,t)}}};var Iw={exports:{}};!function(e){!function(t,n){e.exports?e.exports=n():t.log=n()}(t,(function(){var e=function(){},t="undefined",n=("undefined"==typeof window?"undefined":Ug(window))!==t&&Ug(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 o(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function a(r){return"debug"===r&&(r="log"),("undefined"==typeof console?"undefined":Ug(console))!==t&&("trace"===r&&n?o: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 o=r[i];this[o]=i<t?e:this.methodFactory(o,t,n)}this.log=this.debug}function u(e,n,r){return function(){("undefined"==typeof console?"undefined":Ug(console))!==t&&(s.call(this,n,r),this[e].apply(this,arguments))}}function c(e,t,n){return a(e)||u.apply(this,arguments)}function l(e,n,i){var o,a=this,u="loglevel";function l(){var e;if(("undefined"==typeof window?"undefined":Ug(window))!==t&&u){try{e=window.localStorage[u]}catch(e){}if(Ug(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===a.levels[e]&&(e=void 0),e}}"string"==typeof e?u+=":"+e:"symbol"===Ug(e)&&(u=void 0),a.name=e,a.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},a.methodFactory=i||c,a.getLevel=function(){return o},a.setLevel=function(n,i){if("string"==typeof n&&void 0!==a.levels[n.toUpperCase()]&&(n=a.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=a.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(o=n,!1!==i&&function(e){var n=(r[e]||"silent").toUpperCase();if(("undefined"==typeof window?"undefined":Ug(window))!==t&&u){try{return void(window.localStorage[u]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(u)+"="+n+";"}catch(e){}}}(n),s.call(a,n,e),("undefined"==typeof console?"undefined":Ug(console))===t&&n<a.levels.SILENT)return"No console available for logging"},a.setDefaultLevel=function(e){l()||a.setLevel(e,!1)},a.enableAll=function(e){a.setLevel(a.levels.TRACE,e)},a.disableAll=function(e){a.setLevel(a.levels.SILENT,e)};var f=l();null==f&&(f=null==n?"WARN":n),a.setLevel(f,!1)}var f=new l,d={};f.getLogger=function(e){if("symbol"!==Ug(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":Ug(window))!==t?window.log:void 0;return f.noConflict=function(){return("undefined"==typeof window?"undefined":Ug(window))!==t&&window.log===f&&(window.log=p),f},f.getLoggers=function(){return d},f.default=f,f}))}(Iw),Fm("Set",(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),Xm);var Aw={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,o,a=t.plugins;for(n=0,i=a.length;n<i;n++)(o=a[n]).methods&&r(e,o.methods),o.properties&&Object.defineProperties(e,o.properties)},hook:function(e,t,n){var r,i,o,a,s=e.config.plugins,u=[e.context];for(n&&(u=u.concat(n)),r=0,i=s.length;r<i;r++)a=s[r],(o=s[r][t])&&o.apply(a,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 o(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(o.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"===Ao(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"===Ao(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,o,a=this.defaults.wildcard;for(n=0;n<e.length;n++)for(r=e[n],i=Array.isArray(r.from)?r.from:[r.from||a],o=r.to||a,t=0;t<i.length;t++)this.mapTransition({name:r.name,from:i[t],to:o})},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=o},function(e,t,n){var r=n(0),i=n(6),o=n(1),a=[null,[]];function s(e,t){this.context=e,this.config=t,this.state=t.init.from,this.observers=[e]}r(s.prototype,{init:function(e){if(r(this.context,this.config.data.apply(this.context,e)),o.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,o=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]),o?this.observersForEvent(i.onLeave.state):a,o?this.observersForEvent(i.onLeave[t]):a,this.observersForEvent(i.on.transition),o?["doTransit",[this]]:a,o?this.observersForEvent(i.onEnter.state):a,o?this.observersForEvent(i.onEnter[n]):a,o?this.observersForEvent(i.on[n]):a,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],a=e[0][1],s=e[0][2];if(t[0].event=i,i&&s&&i!==n&&o.hook(this,"lifecycle",t),0===a.length)return e.shift(),this.observeEvents(e,t,i,r);var u=a.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=s},function(e,t,n){var r=n(0),i=n(2),o=n(1),a=n(3),s=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 a(t,l)),e._fsm(),e}function d(e,t){if("object"!==Ao(e)||Array.isArray(e))throw Error("StateMachine can only be applied to objects");o.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 s(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 a(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()}(Aw);var Pw={exports:{}},jw="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(jw){var Lw=new Uint8Array(16);Pw.exports=function(){return jw(Lw),Lw}}else{var Mw=new Array(16);Pw.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),Mw[t]=e>>>((3&t)<<3)&255;return Mw}}for(var Nw=[],Dw=0;Dw<256;++Dw)Nw[Dw]=(Dw+256).toString(16).substr(1);var Uw,Fw,Bw=function(e,t){var n=t||0,r=Nw;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("")},qw=Pw.exports,zw=Bw,Ww=0,Gw=0;var $w=function(e,t,n){var r=t&&n||0,i=t||[],o=(e=e||{}).node||Uw,a=void 0!==e.clockseq?e.clockseq:Fw;if(null==o||null==a){var s=qw();null==o&&(o=Uw=[1|s[0],s[1],s[2],s[3],s[4],s[5]]),null==a&&(a=Fw=16383&(s[6]<<8|s[7]))}var u=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:Gw+1,l=u-Ww+(c-Gw)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||u>Ww)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Ww=u,Gw=c,Fw=a;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++]=a>>>8|128,i[r++]=255&a;for(var p=0;p<6;++p)i[r+p]=o[p];return t||zw(i)},Jw=Pw.exports,Kw=Bw;var Vw=$w,Hw=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||Jw)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var o=0;o<16;++o)t[r+o]=i[o];return t||Kw(i)},Yw=Hw;Yw.v1=Vw,Yw.v4=Hw;var Qw,Xw,Zw,ex=Yw,tx={exports:{}},nx="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView,rx=nx,ix=s,ox=i,ax=S,sx=ee,ux=Go,cx=Je,lx=Ke.exports,fx=Ne.f,dx=Ll,px=na,hx=pe,yx=re,vx=ox.Int8Array,mx=vx&&vx.prototype,gx=ox.Uint8ClampedArray,bx=gx&&gx.prototype,wx=vx&&dx(vx),xx=mx&&dx(mx),kx=Object.prototype,_x=kx.isPrototypeOf,Sx=hx("toStringTag"),Ex=yx("TYPED_ARRAY_TAG"),Tx=yx("TYPED_ARRAY_CONSTRUCTOR"),Rx=rx&&!!px&&"Opera"!==ux(ox.opera),Cx=!1,Ox={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},Ix={BigInt64Array:8,BigUint64Array:8},Ax=function(e){if(!ax(e))return!1;var t=ux(e);return sx(Ox,t)||sx(Ix,t)};for(Qw in Ox)(Zw=(Xw=ox[Qw])&&Xw.prototype)?cx(Zw,Tx,Xw):Rx=!1;for(Qw in Ix)(Zw=(Xw=ox[Qw])&&Xw.prototype)&&cx(Zw,Tx,Xw);if((!Rx||"function"!=typeof wx||wx===Function.prototype)&&(wx=function(){throw TypeError("Incorrect invocation")},Rx))for(Qw in Ox)ox[Qw]&&px(ox[Qw],wx);if((!Rx||!xx||xx===kx)&&(xx=wx.prototype,Rx))for(Qw in Ox)ox[Qw]&&px(ox[Qw].prototype,xx);if(Rx&&dx(bx)!==xx&&px(bx,xx),ix&&!sx(xx,Sx))for(Qw in Cx=!0,fx(xx,Sx,{get:function(){return ax(this)?this[Ex]:void 0}}),Ox)ox[Qw]&&cx(ox[Qw],Ex,Qw);var Px={NATIVE_ARRAY_BUFFER_VIEWS:Rx,TYPED_ARRAY_CONSTRUCTOR:Tx,TYPED_ARRAY_TAG:Cx&&Ex,aTypedArray:function(e){if(Ax(e))return e;throw TypeError("Target is not a typed array")},aTypedArrayConstructor:function(e){if(px&&!_x.call(wx,e))throw TypeError("Target is not a typed array constructor");return e},exportTypedArrayMethod:function(e,t,n){if(ix){if(n)for(var r in Ox){var i=ox[r];if(i&&sx(i.prototype,e))try{delete i.prototype[e]}catch(e){}}xx[e]&&!n||lx(xx,e,n?t:Rx&&mx[e]||t)}},exportTypedArrayStaticMethod:function(e,t,n){var r,i;if(ix){if(px){if(n)for(r in Ox)if((i=ox[r])&&sx(i,e))try{delete i[e]}catch(e){}if(wx[e]&&!n)return;try{return lx(wx,e,n?t:Rx&&wx[e]||t)}catch(e){}}for(r in Ox)!(i=ox[r])||i[e]&&!n||lx(i,e,t)}},isView:function(e){if(!ax(e))return!1;var t=ux(e);return"DataView"===t||sx(Ox,t)||sx(Ix,t)},isTypedArray:Ax,TypedArray:wx,TypedArrayPrototype:xx},jx=i,Lx=a,Mx=Ba,Nx=Px.NATIVE_ARRAY_BUFFER_VIEWS,Dx=jx.ArrayBuffer,Ux=jx.Int8Array,Fx=!Nx||!Lx((function(){Ux(1)}))||!Lx((function(){new Ux(-1)}))||!Mx((function(e){new Ux,new Ux(null),new Ux(1.5),new Ux(e)}),!0)||Lx((function(){return 1!==new Ux(new Dx(2),1,void 0).length})),Bx=Lt,qx=Dt,zx=function(e){if(void 0===e)return 0;var t=Bx(e),n=qx(t);if(t!==n)throw RangeError("Wrong length or index");return n},Wx=Math.abs,Gx=Math.pow,$x=Math.floor,Jx=Math.log,Kx=Math.LN2,Vx=Q,Hx=qt,Yx=Dt,Qx=function(e){for(var t=Vx(this),n=Yx(t.length),r=arguments.length,i=Hx(r>1?arguments[1]:void 0,n),o=r>2?arguments[2]:void 0,a=void 0===o?n:Hx(o,n);a>i;)t[i++]=e;return t},Xx=i,Zx=s,ek=nx,tk=Je,nk=Xo,rk=a,ik=ua,ok=Lt,ak=Dt,sk=zx,uk={pack:function(e,t,n){var r,i,o,a=new Array(n),s=8*n-t-1,u=(1<<s)-1,c=u>>1,l=23===t?Gx(2,-24)-Gx(2,-77):0,f=e<0||0===e&&1/e<0?1:0,d=0;for((e=Wx(e))!=e||e===1/0?(i=e!=e?1:0,r=u):(r=$x(Jx(e)/Kx),e*(o=Gx(2,-r))<1&&(r--,o*=2),(e+=r+c>=1?l/o:l*Gx(2,1-c))*o>=2&&(r++,o/=2),r+c>=u?(i=0,r=u):r+c>=1?(i=(e*o-1)*Gx(2,t),r+=c):(i=e*Gx(2,c-1)*Gx(2,t),r=0));t>=8;a[d++]=255&i,i/=256,t-=8);for(r=r<<t|i,s+=t;s>0;a[d++]=255&r,r/=256,s-=8);return a[--d]|=128*f,a},unpack:function(e,t){var n,r=e.length,i=8*r-t-1,o=(1<<i)-1,a=o>>1,s=i-7,u=r-1,c=e[u--],l=127&c;for(c>>=7;s>0;l=256*l+e[u],u--,s-=8);for(n=l&(1<<-s)-1,l>>=-s,s+=t;s>0;n=256*n+e[u],u--,s-=8);if(0===l)l=1-a;else{if(l===o)return n?NaN:c?-1/0:1/0;n+=Gx(2,t),l-=a}return(c?-1:1)*n*Gx(2,l-t)}},ck=Ll,lk=na,fk=At.f,dk=Ne.f,pk=Qx,hk=An,yk=kt.get,vk=kt.set,mk="ArrayBuffer",gk="DataView",bk="Wrong index",wk=Xx.ArrayBuffer,xk=wk,kk=Xx.DataView,_k=kk&&kk.prototype,Sk=Object.prototype,Ek=Xx.RangeError,Tk=uk.pack,Rk=uk.unpack,Ck=function(e){return[255&e]},Ok=function(e){return[255&e,e>>8&255]},Ik=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]},Pk=function(e){return Tk(e,23,4)},jk=function(e){return Tk(e,52,8)},Lk=function(e,t){dk(e.prototype,t,{get:function(){return yk(this)[t]}})},Mk=function(e,t,n,r){var i=sk(n),o=yk(e);if(i+t>o.byteLength)throw Ek(bk);var a=yk(o.buffer).bytes,s=i+o.byteOffset,u=a.slice(s,s+t);return r?u:u.reverse()},Nk=function(e,t,n,r,i,o){var a=sk(n),s=yk(e);if(a+t>s.byteLength)throw Ek(bk);for(var u=yk(s.buffer).bytes,c=a+s.byteOffset,l=r(+i),f=0;f<t;f++)u[c+f]=l[o?f:t-f-1]};if(ek){if(!rk((function(){wk(1)}))||!rk((function(){new wk(-1)}))||rk((function(){return new wk,new wk(1.5),new wk(NaN),wk.name!=mk}))){for(var Dk,Uk=(xk=function(e){return ik(this,xk),new wk(sk(e))}).prototype=wk.prototype,Fk=fk(wk),Bk=0;Fk.length>Bk;)(Dk=Fk[Bk++])in xk||tk(xk,Dk,wk[Dk]);Uk.constructor=xk}lk&&ck(_k)!==Sk&&lk(_k,Sk);var qk=new kk(new xk(2)),zk=_k.setInt8;qk.setInt8(0,2147483648),qk.setInt8(1,2147483649),!qk.getInt8(0)&&qk.getInt8(1)||nk(_k,{setInt8:function(e,t){zk.call(this,e,t<<24>>24)},setUint8:function(e,t){zk.call(this,e,t<<24>>24)}},{unsafe:!0})}else xk=function(e){ik(this,xk,mk);var t=sk(e);vk(this,{bytes:pk.call(new Array(t),0),byteLength:t}),Zx||(this.byteLength=t)},kk=function(e,t,n){ik(this,kk,gk),ik(e,xk,gk);var r=yk(e).byteLength,i=ok(t);if(i<0||i>r)throw Ek("Wrong offset");if(i+(n=void 0===n?r-i:ak(n))>r)throw Ek("Wrong length");vk(this,{buffer:e,byteLength:n,byteOffset:i}),Zx||(this.buffer=e,this.byteLength=n,this.byteOffset=i)},Zx&&(Lk(xk,"byteLength"),Lk(kk,"buffer"),Lk(kk,"byteLength"),Lk(kk,"byteOffset")),nk(kk.prototype,{getInt8:function(e){return Mk(this,1,e)[0]<<24>>24},getUint8:function(e){return Mk(this,1,e)[0]},getInt16:function(e){var t=Mk(this,2,e,arguments.length>1?arguments[1]:void 0);return(t[1]<<8|t[0])<<16>>16},getUint16:function(e){var t=Mk(this,2,e,arguments.length>1?arguments[1]:void 0);return t[1]<<8|t[0]},getInt32:function(e){return Ak(Mk(this,4,e,arguments.length>1?arguments[1]:void 0))},getUint32:function(e){return Ak(Mk(this,4,e,arguments.length>1?arguments[1]:void 0))>>>0},getFloat32:function(e){return Rk(Mk(this,4,e,arguments.length>1?arguments[1]:void 0),23)},getFloat64:function(e){return Rk(Mk(this,8,e,arguments.length>1?arguments[1]:void 0),52)},setInt8:function(e,t){Nk(this,1,e,Ck,t)},setUint8:function(e,t){Nk(this,1,e,Ck,t)},setInt16:function(e,t){Nk(this,2,e,Ok,t,arguments.length>2?arguments[2]:void 0)},setUint16:function(e,t){Nk(this,2,e,Ok,t,arguments.length>2?arguments[2]:void 0)},setInt32:function(e,t){Nk(this,4,e,Ik,t,arguments.length>2?arguments[2]:void 0)},setUint32:function(e,t){Nk(this,4,e,Ik,t,arguments.length>2?arguments[2]:void 0)},setFloat32:function(e,t){Nk(this,4,e,Pk,t,arguments.length>2?arguments[2]:void 0)},setFloat64:function(e,t){Nk(this,8,e,jk,t,arguments.length>2?arguments[2]:void 0)}});hk(xk,mk),hk(kk,gk);var Wk={ArrayBuffer:xk,DataView:kk},Gk=Lt,$k=function(e){var t=Gk(e);if(t<0)throw RangeError("The argument can't be less than 0");return t},Jk=function(e,t){var n=$k(e);if(n%t)throw RangeError("Wrong offset");return n},Kk=Q,Vk=Dt,Hk=wa,Yk=ma,Qk=pa,Xk=Ur,Zk=Px.aTypedArrayConstructor,e_=Rn,t_=i,n_=s,r_=Fx,i_=Px,o_=Wk,a_=ua,s_=h,u_=Je,c_=by,l_=Dt,f_=zx,d_=Jk,p_=xe,h_=ee,y_=Go,v_=S,m_=q,g_=tr,b_=na,w_=At.f,x_=function(e){var t,n,r,i,o,a,s=Kk(e),u=arguments.length,c=u>1?arguments[1]:void 0,l=void 0!==c,f=Yk(s);if(null!=f&&!Qk(f))for(a=(o=Hk(s,f)).next,s=[];!(i=a.call(o)).done;)s.push(i.value);for(l&&u>2&&(c=Xk(c,arguments[2],2)),n=Vk(s.length),r=new(Zk(this))(n),t=0;n>t;t++)r[t]=l?c(s[t],t):s[t];return r},k_=Qr.forEach,__=sa,S_=Ne,E_=o,T_=bd,R_=kt.get,C_=kt.set,O_=S_.f,I_=E_.f,A_=Math.round,P_=t_.RangeError,j_=o_.ArrayBuffer,L_=o_.DataView,M_=i_.NATIVE_ARRAY_BUFFER_VIEWS,N_=i_.TYPED_ARRAY_CONSTRUCTOR,D_=i_.TYPED_ARRAY_TAG,U_=i_.TypedArray,F_=i_.TypedArrayPrototype,B_=i_.aTypedArrayConstructor,q_=i_.isTypedArray,z_="BYTES_PER_ELEMENT",W_="Wrong length",G_=function(e,t){for(var n=0,r=t.length,i=new(B_(e))(r);r>n;)i[n]=t[n++];return i},$_=function(e,t){O_(e,t,{get:function(){return R_(this)[t]}})},J_=function(e){var t;return e instanceof j_||"ArrayBuffer"==(t=y_(e))||"SharedArrayBuffer"==t},K_=function(e,t){return q_(e)&&!m_(t)&&t in e&&c_(+t)&&t>=0},V_=function(e,t){return t=p_(t),K_(e,t)?s_(2,e[t]):I_(e,t)},H_=function(e,t,n){return t=p_(t),!(K_(e,t)&&v_(n)&&h_(n,"value"))||h_(n,"get")||h_(n,"set")||n.configurable||h_(n,"writable")&&!n.writable||h_(n,"enumerable")&&!n.enumerable?O_(e,t,n):(e[t]=n.value,e)};n_?(M_||(E_.f=V_,S_.f=H_,$_(F_,"buffer"),$_(F_,"byteOffset"),$_(F_,"byteLength"),$_(F_,"length")),e_({target:"Object",stat:!0,forced:!M_},{getOwnPropertyDescriptor:V_,defineProperty:H_}),tx.exports=function(e,t,n){var r=e.match(/\d+$/)[0]/8,i=e+(n?"Clamped":"")+"Array",o="get"+e,a="set"+e,s=t_[i],u=s,c=u&&u.prototype,l={},f=function(e,t){O_(e,t,{get:function(){return function(e,t){var n=R_(e);return n.view[o](t*r+n.byteOffset,!0)}(this,t)},set:function(e){return function(e,t,i){var o=R_(e);n&&(i=(i=A_(i))<0?0:i>255?255:255&i),o.view[a](t*r+o.byteOffset,i,!0)}(this,t,e)},enumerable:!0})};M_?r_&&(u=t((function(e,t,n,o){return a_(e,u,i),T_(v_(t)?J_(t)?void 0!==o?new s(t,d_(n,r),o):void 0!==n?new s(t,d_(n,r)):new s(t):q_(t)?G_(u,t):x_.call(u,t):new s(f_(t)),e,u)})),b_&&b_(u,U_),k_(w_(s),(function(e){e in u||u_(u,e,s[e])})),u.prototype=c):(u=t((function(e,t,n,o){a_(e,u,i);var a,s,c,l=0,d=0;if(v_(t)){if(!J_(t))return q_(t)?G_(u,t):x_.call(u,t);a=t,d=d_(n,r);var p=t.byteLength;if(void 0===o){if(p%r)throw P_(W_);if((s=p-d)<0)throw P_(W_)}else if((s=l_(o)*r)+d>p)throw P_(W_);c=s/r}else c=f_(t),a=new j_(s=c*r);for(C_(e,{buffer:a,byteOffset:d,byteLength:s,length:c,view:new L_(a)});l<c;)f(e,l++)})),b_&&b_(u,U_),c=u.prototype=g_(F_)),c.constructor!==u&&u_(c,"constructor",u),u_(c,N_,u),D_&&u_(c,D_,i),l[i]=u,e_({global:!0,forced:u!=s,sham:!M_},l),z_ in u||u_(u,z_,r),z_ in c||u_(c,z_,r),__(i)}):tx.exports=function(){},(0,tx.exports)("Uint8",(function(e){return function(t,n,r){return e(this,t,n,r)}}));var Y_=Q,Q_=qt,X_=Dt,Z_=Math.min,eS=[].copyWithin||function(e,t){var n=Y_(this),r=X_(n.length),i=Q_(e,r),o=Q_(t,r),a=arguments.length>2?arguments[2]:void 0,s=Z_((void 0===a?r:Q_(a,r))-o,r-i),u=1;for(o<i&&i<o+s&&(u=-1,o+=s-1,i+=s-1);s-- >0;)o in n?n[i]=n[o]:delete n[i],i+=u,o+=u;return n},tS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("copyWithin",(function(e,t){return eS.call(tS(this),e,t,arguments.length>2?arguments[2]:void 0)}));var nS=Qr.every,rS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("every",(function(e){return nS(rS(this),e,arguments.length>1?arguments[1]:void 0)}));var iS=Qx,oS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("fill",(function(e){return iS.apply(oS(this),arguments)}));var aS=Ga,sS=Px.TYPED_ARRAY_CONSTRUCTOR,uS=Px.aTypedArrayConstructor,cS=function(e){return uS(aS(e,e[sS]))},lS=function(e,t){for(var n=0,r=t.length,i=new e(r);r>n;)i[n]=t[n++];return i},fS=cS,dS=Qr.filter,pS=function(e,t){return lS(fS(e),t)},hS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("filter",(function(e){var t=dS(hS(this),e,arguments.length>1?arguments[1]:void 0);return pS(this,t)}));var yS=Qr.find,vS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("find",(function(e){return yS(vS(this),e,arguments.length>1?arguments[1]:void 0)}));var mS=Qr.findIndex,gS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("findIndex",(function(e){return mS(gS(this),e,arguments.length>1?arguments[1]:void 0)}));var bS=Qr.forEach,wS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("forEach",(function(e){bS(wS(this),e,arguments.length>1?arguments[1]:void 0)}));var xS=Jt.includes,kS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("includes",(function(e){return xS(kS(this),e,arguments.length>1?arguments[1]:void 0)}));var _S=Jt.indexOf,SS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("indexOf",(function(e){return _S(SS(this),e,arguments.length>1?arguments[1]:void 0)}));var ES=i,TS=Px,RS=Qf,CS=pe("iterator"),OS=ES.Uint8Array,IS=RS.values,AS=RS.keys,PS=RS.entries,jS=TS.aTypedArray,LS=TS.exportTypedArrayMethod,MS=OS&&OS.prototype[CS],NS=!!MS&&("values"==MS.name||null==MS.name),DS=function(){return IS.call(jS(this))};LS("entries",(function(){return PS.call(jS(this))})),LS("keys",(function(){return AS.call(jS(this))})),LS("values",DS,!NS),LS(CS,DS,!NS);var US=Px.aTypedArray,FS=[].join;(0,Px.exportTypedArrayMethod)("join",(function(e){return FS.apply(US(this),arguments)}));var BS=_,qS=Lt,zS=Dt,WS=rc,GS=Math.min,$S=[].lastIndexOf,JS=!!$S&&1/[1].lastIndexOf(1,-0)<0,KS=WS("lastIndexOf"),VS=JS||!KS?function(e){if(JS)return $S.apply(this,arguments)||0;var t=BS(this),n=zS(t.length),r=n-1;for(arguments.length>1&&(r=GS(r,qS(arguments[1]))),r<0&&(r=n+r);r>=0;r--)if(r in t&&t[r]===e)return r||0;return-1}:$S,HS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("lastIndexOf",(function(e){return VS.apply(HS(this),arguments)}));var YS=Qr.map,QS=cS,XS=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("map",(function(e){return YS(XS(this),e,arguments.length>1?arguments[1]:void 0,(function(e,t){return new(QS(e))(t)}))}));var ZS=Mn,eE=Q,tE=b,nE=Dt,rE=function(e){return function(t,n,r,i){ZS(n);var o=eE(t),a=tE(o),s=nE(o.length),u=e?s-1:0,c=e?-1:1;if(r<2)for(;;){if(u in a){i=a[u],u+=c;break}if(u+=c,e?u<0:s<=u)throw TypeError("Reduce of empty array with no initial value")}for(;e?u>=0:s>u;u+=c)u in a&&(i=n(i,a[u],u,o));return i}},iE={left:rE(!1),right:rE(!0)},oE=iE.left,aE=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("reduce",(function(e){return oE(aE(this),e,arguments.length,arguments.length>1?arguments[1]:void 0)}));var sE=iE.right,uE=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("reduceRight",(function(e){return sE(uE(this),e,arguments.length,arguments.length>1?arguments[1]:void 0)}));var cE=Px.aTypedArray,lE=Px.exportTypedArrayMethod,fE=Math.floor;lE("reverse",(function(){for(var e,t=this,n=cE(t).length,r=fE(n/2),i=0;i<r;)e=t[i],t[i++]=t[--n],t[n]=e;return t}));var dE=Dt,pE=Jk,hE=Q,yE=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("set",(function(e){yE(this);var t=pE(arguments.length>1?arguments[1]:void 0,1),n=this.length,r=hE(e),i=dE(r.length),o=0;if(i+t>n)throw RangeError("Wrong length");for(;o<i;)this[t+o]=r[o++]}),a((function(){new Int8Array(1).set({})})));var vE=cS,mE=Px.aTypedArray,gE=[].slice;(0,Px.exportTypedArrayMethod)("slice",(function(e,t){for(var n=gE.call(mE(this),e,t),r=vE(this),i=0,o=n.length,a=new r(o);o>i;)a[i]=n[i++];return a}),a((function(){new Int8Array(1).slice()})));var bE=Qr.some,wE=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("some",(function(e){return bE(wE(this),e,arguments.length>1?arguments[1]:void 0)}));var xE=Math.floor,kE=function(e,t){var n=e.length,r=xE(n/2);return n<8?_E(e,t):SE(kE(e.slice(0,r),t),kE(e.slice(r),t),t)},_E=function(e,t){for(var n,r,i=e.length,o=1;o<i;){for(r=o,n=e[o];r&&t(e[r-1],n)>0;)e[r]=e[--r];r!==o++&&(e[r]=n)}return e},SE=function(e,t,n){for(var r=e.length,i=t.length,o=0,a=0,s=[];o<r||a<i;)o<r&&a<i?s.push(n(e[o],t[a])<=0?e[o++]:t[a++]):s.push(o<r?e[o++]:t[a++]);return s},EE=kE,TE=C.match(/firefox\/(\d+)/i),RE=!!TE&&+TE[1],CE=/MSIE|Trident/.test(C),OE=C.match(/AppleWebKit\/(\d+)\./),IE=!!OE&&+OE[1],AE=a,PE=Mn,jE=Dt,LE=EE,ME=RE,NE=CE,DE=M,UE=IE,FE=Px.aTypedArray,BE=Px.exportTypedArrayMethod,qE=i.Uint16Array,zE=qE&&qE.prototype.sort,WE=!!zE&&!AE((function(){var e=new qE(2);e.sort(null),e.sort({})})),GE=!!zE&&!AE((function(){if(DE)return DE<74;if(ME)return ME<67;if(NE)return!0;if(UE)return UE<602;var e,t,n=new qE(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}));BE("sort",(function(e){var t=this;if(void 0!==e&&PE(e),GE)return zE.call(t,e);FE(t);var n,r=jE(t.length),i=Array(r);for(n=0;n<r;n++)i[n]=t[n];for(i=LE(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}),!GE||WE);var $E=Dt,JE=qt,KE=cS,VE=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("subarray",(function(e,t){var n=VE(this),r=n.length,i=JE(e,r);return new(KE(n))(n.buffer,n.byteOffset+i*n.BYTES_PER_ELEMENT,$E((void 0===t?r:JE(t,r))-i))}));var HE=Px,YE=a,QE=i.Int8Array,XE=HE.aTypedArray,ZE=HE.exportTypedArrayMethod,eT=[].toLocaleString,tT=[].slice,nT=!!QE&&YE((function(){eT.call(new QE(1))}));ZE("toLocaleString",(function(){return eT.apply(nT?tT.call(XE(this)):XE(this),arguments)}),YE((function(){return[1,2].toLocaleString()!=new QE([1,2]).toLocaleString()}))||!YE((function(){QE.prototype.toLocaleString.call([1,2])})));var rT=Px.exportTypedArrayMethod,iT=a,oT=i.Uint8Array,aT=oT&&oT.prototype||{},sT=[].toString,uT=[].join;iT((function(){sT.call({})}))&&(sT=function(){return uT.call(this)});var cT=aT.toString!=sT;rT("toString",sT,cT);var lT=S,fT=v,dT=pe("match"),pT=function(e){var t;return lT(e)&&(void 0!==(t=e[dT])?!!t:"RegExp"==fT(e))},hT=Pp,yT=pT,vT=Ue,mT=w,gT=Ga,bT=Lp,wT=Dt,xT=Sr,kT=zp,_T=Sp,ST=a,ET=Zd.UNSUPPORTED_Y,TT=[].push,RT=Math.min,CT=4294967295;hT("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=xT(mT(this)),i=void 0===n?CT:n>>>0;if(0===i)return[];if(void 0===e)return[r];if(!yT(e))return t.call(r,e,i);for(var o,a,s,u=[],c=(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.unicode?"u":"")+(e.sticky?"y":""),l=0,f=new RegExp(e.source,c+"g");(o=_T.call(f,r))&&!((a=f.lastIndex)>l&&(u.push(r.slice(l,o.index)),o.length>1&&o.index<r.length&&TT.apply(u,o.slice(1)),s=o[0].length,l=a,u.length>=i));)f.lastIndex===o.index&&f.lastIndex++;return l===r.length?!s&&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=mT(this),o=null==t?void 0:t[e];return void 0!==o?o.call(t,i,n):r.call(xT(i),t,n)},function(e,i){var o=vT(this),a=xT(e),s=n(r,o,a,i,r!==t);if(s.done)return s.value;var u=gT(o,RegExp),c=o.unicode,l=(o.ignoreCase?"i":"")+(o.multiline?"m":"")+(o.unicode?"u":"")+(ET?"g":"y"),f=new u(ET?"^(?:"+o.source+")":o,l),d=void 0===i?CT:i>>>0;if(0===d)return[];if(0===a.length)return null===kT(f,a)?[a]:[];for(var p=0,h=0,y=[];h<a.length;){f.lastIndex=ET?0:h;var v,m=kT(f,ET?a.slice(h):a);if(null===m||(v=RT(wT(f.lastIndex+(ET?h:0)),a.length))===p)h=bT(a,h,c);else{if(y.push(a.slice(p,h)),y.length===d)return y;for(var g=1;g<=m.length-1;g++)if(y.push(m[g]),y.length===d)return y;h=p=v}}return y.push(a.slice(p)),y}]}),!!ST((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]})),ET);var OT={exports:{}},IT={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}(IT);var AT={exports:{}},PT={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}(PT),function(e){var t=Kg.exports,n=PT.exports;function r(i,o,a){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 o=new(Function.bind.apply(e,i));return r&&t(o,r.prototype),o},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}(AT),function(e){var t=$g.exports,n=Kg.exports,r=IT.exports,i=AT.exports;function o(a){var s="function"==typeof Map?new Map:void 0;return e.exports=o=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,o)}function o(){return i(e,arguments,t(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,e)},e.exports.__esModule=!0,e.exports.default=e.exports,o(a)}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports}(OT);var jT={};Object.defineProperty(jT,"__esModule",{value:!0});var LT=qg.exports,MT=zg.exports,NT=Jg.exports,DT=Vg.exports,UT=$g.exports,FT=Qg.exports;function BT(e){return e&&"object"===Ug(e)&&"default"in e?e:{default:e}}var qT=BT(Yg.exports),zT=BT(LT),WT=BT(MT),GT=BT(NT),$T=BT(DT),JT=BT(UT),KT=BT(FT);function VT(){}function HT(){HT.init.call(this)}function YT(e){return void 0===e._maxListeners?HT.defaultMaxListeners:e._maxListeners}function QT(e,t,n){if(t)e.call(n);else for(var r=e.length,i=oR(e,r),o=0;o<r;++o)i[o].call(n)}function XT(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,o=oR(e,i),a=0;a<i;++a)o[a].call(n,r)}function ZT(e,t,n,r,i){if(t)e.call(n,r,i);else for(var o=e.length,a=oR(e,o),s=0;s<o;++s)a[s].call(n,r,i)}function eR(e,t,n,r,i,o){if(t)e.call(n,r,i,o);else for(var a=e.length,s=oR(e,a),u=0;u<a;++u)s[u].call(n,r,i,o)}function tR(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,o=oR(e,i),a=0;a<i;++a)o[a].apply(n,r)}function nR(e,t,n,r){var i,o,a,s;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]):(o=e._events=new VT,e._eventsCount=0),a){if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),!a.warned&&(i=YT(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,"function"==typeof console.warn?console.warn(s):console.log(s)}}else a=o[t]=n,++e._eventsCount;return e}function rR(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 iR(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 oR(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}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=JT.default(e);if(t){var i=JT.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return $T.default(this,n)}}VT.prototype=Object.create(null),HT.EventEmitter=HT,HT.usingDomains=!1,HT.prototype.domain=void 0,HT.prototype._events=void 0,HT.prototype._maxListeners=void 0,HT.defaultMaxListeners=10,HT.init=function(){this.domain=null,HT.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new VT,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},HT.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},HT.prototype.getMaxListeners=function(){return YT(this)},HT.prototype.emit=function(e){var t,n,r,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.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=a[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:QT(n,l,this);break;case 2:XT(n,l,this,arguments[1]);break;case 3:ZT(n,l,this,arguments[1],arguments[2]);break;case 4:eR(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),o=1;o<r;o++)i[o-1]=arguments[o];tR(n,l,this,i)}return!0},HT.prototype.addListener=function(e,t){return nR(this,e,t,!1)},HT.prototype.on=HT.prototype.addListener,HT.prototype.prependListener=function(e,t){return nR(this,e,t,!0)},HT.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,rR(this,e,t)),this},HT.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,rR(this,e,t)),this},HT.prototype.removeListener=function(e,t){var n,r,i,o,a;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 VT:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length;o-- >0;)if(n[o]===t||n[o].listener&&n[o].listener===t){a=n[o].listener,i=o;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new VT,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,a||t)}return this},HT.prototype.off=function(e,t){return this.removeListener(e,t)},HT.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new VT,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new VT:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new VT,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},HT.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):[]},HT.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):iR.call(e,t)},HT.prototype.listenerCount=iR,HT.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var sR=function(e){GT.default(n,e);var t=aR(n);function n(e){var r;return qT.default(this,n),r=t.call(this),KT.default(WT.default(r),"timeout",null),KT.default(WT.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 zT.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}(HT),uR=function(e){GT.default(n,e);var t=aR(n);function n(e){var r;return qT.default(this,n),r=t.call(this),KT.default(WT.default(r),"resolve",(function(){})),KT.default(WT.default(r),"reject",(function(){})),r.retrier=new sR(e),r}return zT.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}(HT);function cR(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=JT.default(e);if(t){var i=JT.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return $T.default(this,n)}}function lR(e){return null!=e}var fR=function(e){GT.default(n,e);var t=cR(n);function n(e){var r;qT.default(this,n),r=t.call(this),KT.default(WT.default(r),"backoffDelay",0),KT.default(WT.default(r),"nextBackoffDelay",0),KT.default(WT.default(r),"backoffNumber",0),KT.default(WT.default(r),"timeoutID",null),KT.default(WT.default(r),"maxNumberOfRetry",-1);var i=e=e||{},o=i.initialDelay,a=i.maxDelay,s=i.randomisationFactor,u=i.factor;if(lR(o)&&o<1)throw new Error("The initial timeout must be equal to or greater than 1.");if(lR(a)&&a<=1)throw new Error("The maximal timeout must be greater than 1.");if(lR(s)&&(s<0||s>1))throw new Error("The randomisation factor must be between 0 and 1.");if(lR(u)&&u<=1)throw new Error("Exponential factor should be greater than 1.");if(r.initialDelay=o||100,r.maxDelay=a||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 zT.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}(HT);jT.AsyncRetrier=uR,jT.Backoff=fR,jT.Retrier=sR;var dR={exports:{}};!function(e,n){(function(){var r={function:!0,object:!0}["undefined"==typeof window?"undefined":Ao(window)]&&window||this,i=n,o=e&&!e.nodeType&&e,a=i&&o&&"object"==Ao(t)&&t;!a||a.global!==a&&a.window!==a&&a.self!==a||(r=a);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 y(e){return null==e?d(e):f.call(e).slice(8,-1)}function v(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"==Ao(t)&&"String"!=y(t);i&&(n=t,t=null);var o=n.navigator||{},a=o.userAgent||"";t||(t=a);var s,c,l=i?!!o.likeChrome:/\bChrome\b/.test(t)&&!/internal|\n/i.test(f.toString()),d="Object",b=i?d:"ScriptBridgingProxyObject",w=i?d:"Environment",x=i&&n.java?"JavaPackage":y(n.java),k=i?d:"RuntimeObject",_=/\bJava/.test(x)&&n.java,S=_&&y(n.environment)==w,E=_?"a":"α",T=_?"b":"β",R=n.document||{},C=n.operamini||n.opera,O=u.test(O=i&&C?C["[[Class]]"]:y(C))?O:C=null,I=t,A=[],P=null,j=t==a,L=j&&C&&"function"==typeof C.version&&C.version(),M=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||v(n))+"\\b","i").exec(t)&&(n.label||n)})),N=function(e){return m(e,(function(e,n){return e||RegExp("\\b"+(n.pattern||v(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"]),D=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"]),U=function(e){return m(e,(function(e,n,r){return e||(n[D]||n[/^[a-z]+(?: +[a-z]+\b)*/i.exec(D)]||RegExp("\\b"+v(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||v(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||v(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(M&&(M=[M]),/\bAndroid\b/.test(F)&&!D&&(s=/\bAndroid[^;]*;(.*?)(?:Build|\) AppleWebKit)\b/i.exec(t))&&(D=g(s[1]).replace(/^[a-z]{2}-[a-z]{2};\s*/i,"")||null),U&&!D?D=B([U]):U&&D&&(D=D.replace(RegExp("^("+v(U)+")[-_.\\s]","i"),U+" ").replace(RegExp("^("+v(U)+")[-_.]?(\\w)","i"),U+" $2")),(s=/\bGoogle TV\b/.exec(D))&&(D=s[0]),/\bSimulator\b/i.test(t)&&(D=(D?D+" ":"")+"Simulator"),"Opera Mini"==N&&/\bOPiOS\b/.test(t)&&A.push("running in Turbo/Uncompressed mode"),"IE"==N&&/\blike iPhone OS\b/.test(t)?(U=(s=e(t.replace(/like iPhone OS/,""))).manufacturer,D=s.product):/^iP/.test(D)?(N||(N="Safari"),F="iOS"+((s=/ OS ([\d_]+)/i.exec(t))?" "+s[1].replace(/_/g,"."):"")):"Konqueror"==N&&/^Linux\b/i.test(F)?F="Kubuntu":U&&"Google"!=U&&(/Chrome/.test(N)&&!/\bMobile Safari\b/i.test(t)||/\bVita\b/.test(D))||/\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",A.unshift("desktop mode")),/Accelerated *= *true/i.test(t)&&A.unshift("accelerated")):"UC Browser"==N&&/\bUCWEB\b/.test(t)?A.push("speed mode"):"PaleMoon"==N&&(s=/\bFirefox\/([\d.]+)\b/.exec(t))?A.push("identifying as Firefox "+s[1]):"Firefox"==N&&(s=/\b(Mobile|Tablet|TV)\b/i.exec(t))?(F||(F="Firefox OS"),D||(D=s[1])):!N||(s=!/\bMinefield\b/i.test(t)&&/\b(?:Firefox|Safari)\b/.exec(N))?(N&&!D&&/[\/,]|^[^(]+?\)/.test(t.slice(t.indexOf(s+"/")+8))&&(N=null),(s=D||U||F)&&(D||U||/\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(F))&&(N=/[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(F)?F:s)+" Browser")):"Electron"==N&&(s=(/\bChrome\/([\d.]+)\b/.exec(t)||0)[1])&&A.push("Chromium "+s),L||(L=q(["(?:Cloud9|CriOS|CrMo|Edge|Edg|EdgA|EdgiOS|FxiOS|HeadlessChrome|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$)|UCBrowser|YaBrowser)","Version",v(N),"(?:Firefox|Minefield|NetFront)"])),(s=("iCab"==M&&parseFloat(L)>3?"WebKit":/\bOpera\b/.test(N)&&(/\bOPR\b/.test(t)?"Blink":"Presto"))||/\b(?:Midori|Nook|Safari)\b/i.test(t)&&!/^(?:Trident|EdgeHTML)$/.test(M)&&"WebKit"||!M&&/\bMSIE\b/i.test(t)&&("Mac OS"==F?"Tasman":"Trident")||"WebKit"==M&&/\bPlayStation\b(?! Vita\b)/i.test(N)&&"NetFront")&&(M=[s]),"IE"==N&&(s=(/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(t)||0)[1])?(N+=" Mobile",F="Windows Phone "+(/\+$/.test(s)?s:s+".x"),A.unshift("desktop mode")):/\bWPDesktop\b/i.test(t)?(N="IE Mobile",F="Windows Phone 8.x",A.unshift("desktop mode"),L||(L=(/\brv:([\d.]+)/.exec(t)||0)[1])):"IE"!=N&&"Trident"==M&&(s=/\brv:([\d.]+)/.exec(t))&&(N&&A.push("identifying as "+N+(L?" "+L:"")),N="IE",L=s[1]),j){if(function(e,t){var n=null!=e?Ao(e[t]):"number";return!(/^(?:boolean|number|string|undefined)$/.test(n)||"object"==n&&!e[t])}(n,"global"))if(_&&(I=(s=_.lang.System).getProperty("os.arch"),F=F||s.getProperty("os.name")+" "+s.getProperty("os.version")),S){try{L=n.require("ringo/engine").version.join("."),N="RingoJS"}catch(e){(s=n.system)&&s.global.system==n.system&&(N="Narwhal",F||(F=s[0].os||null))}N||(N="Rhino")}else"object"==Ao(n.process)&&!n.process.browser&&(s=n.process)&&("object"==Ao(s.versions)&&("string"==typeof s.versions.electron?(A.push("Node "+s.versions.node),N="Electron",L=s.versions.electron):"string"==typeof s.versions.nw&&(A.push("Chromium "+L,"Node "+s.versions.node),N="NW.js",L=s.versions.nw)),N||(N="Node.js",I=s.arch,F=s.platform,L=(L=/[\d.]+/.exec(s.version))?L[0]:null));else y(s=n.runtime)==b?(N="Adobe AIR",F=s.flash.system.Capabilities.os):y(s=n.phantom)==k?(N="PhantomJS",L=(s=s.version||null)&&s.major+"."+s.minor+"."+s.patch):"number"==typeof R.documentMode&&(s=/\bTrident\/(\d+)/i.exec(t))?(L=[L,R.documentMode],(s=+s[1]+4)!=L[1]&&(A.push("IE "+L[1]+" mode"),M&&(M[1]=""),L[1]=s),L="IE"==N?String(L[1].toFixed(1)):L[0]):"number"==typeof R.documentMode&&/^(?:Chrome|Firefox)\b/.test(N)&&(A.push("masking as "+N+" "+L),N="IE",L="11.0",M=["Trident"],F="Windows");F=F&&p(F)}if(L&&(s=/(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(L)||/(?:alpha|beta)(?: ?\d)?/i.exec(t+";"+(j&&o.appMinorVersion))||/\bMinefield\b/i.test(t)&&"a")&&(P=/b/i.test(s)?"beta":"alpha",L=L.replace(RegExp(s+"\\+?$"),"")+("beta"==P?T:E)+(/\d+\+?/.exec(s)||"")),"Fennec"==N||"Firefox"==N&&/\b(?:Android|Firefox OS|KaiOS)\b/.test(F))N="Firefox Mobile";else if("Maxthon"==N&&L)L=L.replace(/\.[\d.]+/,".x");else if(/\bXbox\b/i.test(D))"Xbox 360"==D&&(F=null),"Xbox 360"==D&&/\bIEMobile\b/.test(t)&&A.unshift("mobile mode");else if(!/^(?:Chrome|IE|Opera)$/.test(N)&&(!N||D||/Browser|Mobi/.test(N))||"Windows CE"!=F&&!/Mobi/i.test(t))if("IE"==N&&j)try{null===n.external&&A.unshift("platform preview")}catch(e){A.unshift("embedded")}else(/\bBlackBerry\b/.test(D)||/\bBB10\b/.test(t))&&(s=(RegExp(D.replace(/ +/g," *")+"/([.\\d]+)","i").exec(t)||0)[1]||L)?(F=((s=[s,/BB10/.test(t)])[1]?(D=null,U="BlackBerry"):"Device Software")+" "+s[0],L=null):this!=h&&"Wii"!=D&&(j&&C||/Opera/.test(N)&&/\b(?:MSIE|Firefox)\b/i.test(t)||"Firefox"==N&&/\bOS X (?:\d+\.){2,}/.test(F)||"IE"==N&&(F&&!/^Win/.test(F)&&L>5.5||/\bWindows XP\b/.test(F)&&L>8||8==L&&!/\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(N)?(/\bIE\b/.test(s)&&"Mac OS"==F&&(F=null),s="identify"+s):(s="mask"+s,N=O?p(O.replace(/([a-z])([A-Z])/g,"$1 $2")):"Opera",/\bIE\b/.test(s)&&(F=null),j||(L=null)),M=["Presto"],A.push(s));else N+=" Mobile";(s=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(t)||0)[1])&&(s=[parseFloat(s.replace(/\.(\d)$/,".0$1")),s],"Safari"==N&&"+"==s[1].slice(-1)?(N="WebKit Nightly",P="alpha",L=s[1].slice(0,-1)):L!=s[1]&&L!=(s[2]=(/\bSafari\/([\d.]+\+?)/i.exec(t)||0)[1])||(L=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"==M&&(M=["Blink"]),j&&(l||s[1])?(M&&(M[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"!=M?"27":"28")):(M&&(M[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"),M&&(M[1]+=" "+(s+="number"==typeof s?".x":/[.+]/.test(s)?"":"+")),"Safari"==N&&(!L||parseInt(L)>45)?L=s:"Chrome"==N&&/\bHeadlessChrome/i.test(t)&&A.unshift("headless")),"Opera"==N&&(s=/\bzbov|zvav$/.exec(F))?(N+=" ",A.unshift("desktop mode"),"zvav"==s?(N+="Mini",L=null):N+="Mobile",F=F.replace(RegExp(" *"+s+"$"),"")):"Safari"==N&&/\bChrome\b/.exec(M&&M[1])?(A.unshift("desktop mode"),N="Chrome Mobile",L=null,/\bOS X\b/.test(F)?(U="Apple",F="iOS 4.3+"):F=null):/\bSRWare Iron\b/.test(N)&&!L&&(L=q("Chrome")),L&&0==L.indexOf(s=/[\d.]+$/.exec(F))&&t.indexOf("/"+s+"-")>-1&&(F=g(F.replace(s,""))),F&&-1!=F.indexOf(N)&&!RegExp(N+" OS").test(F)&&(F=F.replace(RegExp(" *"+v(N)+" *"),"")),M&&!/\b(?:Avant|Nook)\b/.test(N)&&(/Browser|Lunascape|Maxthon/.test(N)||"Safari"!=N&&/^iOS/.test(F)&&/\bSafari\b/.test(M[1])||/^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|SRWare Iron|Vivaldi|Web)/.test(N)&&M[1])&&(s=M[M.length-1])&&A.push(s),A.length&&(A=["("+A.join("; ")+")"]),U&&D&&D.indexOf(U)<0&&A.push("on "+U),D&&A.push((/^on /.test(A[A.length-1])?"":"on ")+D),F&&(s=/ ([\d.+]+)$/.exec(F),c=s&&"/"==F.charAt(F.length-s[0].length-1),F={architecture:32,family:s&&!c?F.replace(s[0],""):F,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(I))&&!/\bi686\b/i.test(I)?(F&&(F.architecture=64,F.family=F.family.replace(RegExp(" *"+s),"")),N&&(/\bWOW64\b/i.test(t)||j&&/\w(?:86|32)$/.test(o.cpuClass||o.platform)&&!/\bWin64; x64\b/i.test(t))&&A.unshift("32-bit")):F&&/^OS X/.test(F.family)&&"Chrome"==N&&parseFloat(L)>=39&&(F.architecture=64),t||(t=null);var z={};return z.description=t,z.layout=M&&M[0],z.manufacturer=U,z.name=N,z.prerelease=P,z.product=D,z.ua=t,z.version=N&&L,z.os=F||{architecture:null,family:null,version:null,toString:function(){return"null"}},z.parse=e,z.toString=function(){return this.description||""},z.version&&A.unshift(L),z.name&&A.unshift(N),F&&N&&(F!=String(F).split(" ")[0]||F!=N.split(" ")[0]&&!D)&&A.push(D?"("+F+")":"on "+F),A.length&&(z.description=A.join(" ")),z}();i&&o?h(b,(function(e,t){i[t]=e})):r.platform=b}).call(t)}(dR,dR.exports);var pR=Ue,hR=Dt,yR=Sr,vR=w,mR=Lp,gR=zp;Pp("match",(function(e,t,n){return[function(t){var n=vR(this),r=null==t?void 0:t[e];return void 0!==r?r.call(t,n):new RegExp(t)[e](yR(n))},function(e){var r=pR(this),i=yR(e),o=n(t,r,i);if(o.done)return o.value;if(!r.global)return gR(r,i);var a=r.unicode;r.lastIndex=0;for(var s,u=[],c=0;null!==(s=gR(r,i));){var l=yR(s[0]);u[c]=l,""===l&&(r.lastIndex=mR(i,hR(r.lastIndex),a)),c++}return 0===c?null:u}]}));var bR=Object.is||function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t},wR=Ue,xR=w,kR=bR,_R=Sr,SR=zp;Pp("search",(function(e,t,n){return[function(t){var n=xR(this),r=null==t?void 0:t[e];return void 0!==r?r.call(t,n):new RegExp(t)[e](_R(n))},function(e){var r=wR(this),i=_R(e),o=n(t,r,i);if(o.done)return o.value;var a=r.lastIndex;kR(a,0)||(r.lastIndex=0);var s=SR(r,i);return kR(r.lastIndex,a)||(r.lastIndex=a),null===s?-1:s.index}]}));var ER=Rn,TR=qt,RR=Lt,CR=Dt,OR=Q,IR=Wr,AR=xo,PR=co("splice"),jR=Math.max,LR=Math.min,MR=9007199254740991,NR="Maximum allowed length exceeded";ER({target:"Array",proto:!0,forced:!PR},{splice:function(e,t){var n,r,i,o,a,s,u=OR(this),c=CR(u.length),l=TR(e,c),f=arguments.length;if(0===f?n=r=0:1===f?(n=0,r=c-l):(n=f-2,r=LR(jR(RR(t),0),c-l)),c+n-r>MR)throw TypeError(NR);for(i=IR(u,r),o=0;o<r;o++)(a=l+o)in u&&AR(i,o,u[a]);if(i.length=r,n<r){for(o=l;o<c-r;o++)s=o+n,(a=o+r)in u?u[s]=u[a]:delete u[s];for(o=c;o>c-r+n;o--)delete u[o-1]}else if(n>r)for(o=c-r;o>l;o--)s=o+n-1,(a=o+r-1)in u?u[s]=u[a]:delete u[s];for(o=0;o<n;o++)u[o+l]=arguments[o+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=qg.exports,r=zg.exports,i=Wg.exports,o=Jg.exports,a=Vg.exports,s=$g.exports,u=Yg.exports,c=Qg.exports,l=Ob,f=Hg.exports,d=Bb,p=Iw.exports,h=Aw.exports,y=ex,v=OT.exports,m=jT,g=dR.exports;function b(e){return e&&"object"===Ug(e)&&"default"in e?e:{default:e}}function w(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var x=b(Bg.exports),k=b(n),_=b(r),S=b(i),E=b(o),T=b(a),R=b(s),C=b(u),O=b(c),I=b(l),A=b(f),P=w(p),j=w(h),L=b(v),M=w(g);function N(){}function D(){D.init.call(this)}function U(e){return void 0===e._maxListeners?D.defaultMaxListeners:e._maxListeners}function F(e,t,n){if(t)e.call(n);else for(var r=e.length,i=K(e,r),o=0;o<r;++o)i[o].call(n)}function B(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,o=K(e,i),a=0;a<i;++a)o[a].call(n,r)}function q(e,t,n,r,i){if(t)e.call(n,r,i);else for(var o=e.length,a=K(e,o),s=0;s<o;++s)a[s].call(n,r,i)}function z(e,t,n,r,i,o){if(t)e.call(n,r,i,o);else for(var a=e.length,s=K(e,a),u=0;u<a;++u)s[u].call(n,r,i,o)}function W(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,o=K(e,i),a=0;a<i;++a)o[a].apply(n,r)}function G(e,t,n,r){var i,o,a,s;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]):(o=e._events=new N,e._eventsCount=0),a){if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),!a.warned&&(i=U(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,"function"==typeof console.warn?console.warn(s):console.log(s)}}else a=o[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 J(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function K(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}N.prototype=Object.create(null),D.EventEmitter=D,D.usingDomains=!1,D.prototype.domain=void 0,D.prototype._events=void 0,D.prototype._maxListeners=void 0,D.defaultMaxListeners=10,D.init=function(){this.domain=null,D.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new N,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},D.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},D.prototype.getMaxListeners=function(){return U(this)},D.prototype.emit=function(e){var t,n,r,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.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=a[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),o=1;o<r;o++)i[o-1]=arguments[o];W(n,l,this,i)}return!0},D.prototype.addListener=function(e,t){return G(this,e,t,!1)},D.prototype.on=D.prototype.addListener,D.prototype.prependListener=function(e,t){return G(this,e,t,!0)},D.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,$(this,e,t)),this},D.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,$(this,e,t)),this},D.prototype.removeListener=function(e,t){var n,r,i,o,a;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,o=n.length;o-- >0;)if(n[o]===t||n[o].listener&&n[o].listener===t){a=n[o].listener,i=o;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,a||t)}return this},D.prototype.off=function(e,t){return this.removeListener(e,t)},D.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new 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),o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&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},D.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},D.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):J.call(e,t)},D.prototype.listenerCount=J,D.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var V=P.getLogger("twilsock");function H(e,t){return["".concat((new Date).toISOString()," Twilsock ").concat(e,":")].concat(Array.from(t))}var Y=new(function(){function e(t){C.default(this,e),O.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?" "+t+":":""}return k.default(e,[{key:"setLevel",value:function(e){V.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.trace.apply(null,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];V.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];V.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];V.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];V.error.apply(null,H("E",t))}}],[{key:"setLevel",value:function(e){V.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.trace.apply(null,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];V.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];V.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];V.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];V.error.apply(null,H("E",t))}}]),e}())(""),Q="0.12.2",X=function(){function e(t,n,r){C.default(this,e),O.default(this,"confirmedCapabilities",new Set),this.activeGrant=n,this._token=t;var i=r.region||"us1",o="wss://tsock.".concat(i,".twilio.com/v3/wsconnect"),a=r.twilsock||r.Twilsock||{};this.url=a.uri||o,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 k.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}(),Z=function e(t){C.default(this,e),this.id=t||"TM".concat(y.v4())};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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var te=function(e){E.default(n,e);var t=ee(n);function n(e,r,i,o,a){var s;return C.default(this,n),s=t.call(this),O.default(_.default(s),"method","init"),s.token=e,s.continuation_token=r,s.metadata=i,s.registrations=o,s.tweaks=a,s.capabilities=["client_update","offline_storage","telemetry.v1"],s}return n}(Z);function ne(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var re=function(e){E.default(n,e);var t=ne(n);function n(e,r,i,o,a,s,u){var c;return C.default(this,n),(c=t.call(this,e)).continuationToken=r,c.continuationTokenStatus=o,c.offlineStorage=a,c.initRegistrations=s,c.debugInfo=u,c.confirmedCapabilities=i,c}return n}(Z);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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var oe=function(e){E.default(n,e);var t=ie(n);function n(e){var r;return C.default(this,n),r=t.call(this),O.default(_.default(r),"method","update"),r.token=e,r}return n}(Z);function ae(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Message=function(e){E.default(Message,e);var t=ae(Message);function Message(e,n,r){var i;return C.default(this,Message),i=t.call(this),O.default(_.default(i),"method","message"),i.active_grant=e,i.payload_type=n,i.http_request=r,i}return Message}(Z);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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var ue=function(e){E.default(n,e);var t=se(n);function n(e){var r;return C.default(this,n),r=t.call(this,e),O.default(_.default(r),"method","reply"),O.default(_.default(r),"payload_type","application/json"),O.default(_.default(r),"status",{code:200,status:"OK"}),r}return n}(Z);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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var le=function(e){E.default(n,e);var t=ce(n);function n(){var e;return C.default(this,n),e=t.call(this),O.default(_.default(e),"method","close"),e}return n}(Z);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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var de=function e(t,n,r,i,o,a){C.default(this,e),this.start=t,this.end=n,this.title=r,this.details=i,this.id=o,this.type=a},pe=function(e){E.default(n,e);var t=fe(n);function n(e){var r;return C.default(this,n),r=t.call(this),O.default(_.default(r),"method","telemetry.v1"),r.events=e,r}return n}(Z);function he(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})).length}function ye(e){var t=encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})),n=new Uint8Array(t.length);return Array.prototype.forEach.call(t,(function(e,t){n[t]=e.charCodeAt(0)})),n}function ve(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 me(e){return JSON.parse(ve(e))}var ge=function(){function e(){C.default(this,e)}return k.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 Y.error("unsupported protocol: ".concat(i.protocol," ver ").concat(i.version)),null;try{t=me(r.subarray(i.size,i.size+i.headerSize))}catch(t){return Y.error("failed to parse message header",t,e),null}if(Y.debug("message received: ",t.method),Y.trace("message received: ",t),t.payload_size>0){var o=2+i.size+i.headerSize,a=t.payload_size;if(t.hasOwnProperty("payload_type")&&0!==t.payload_type.indexOf("application/json"))0===t.payload_type.indexOf("text/plain")&&(n=ve(r.subarray(o,o+a)));else try{n=me(r.subarray(o,o+a))}catch(t){return Y.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=he(t);var n=JSON.stringify(e),r="TWILSOCK V3.0 "+he(n);Y.debug("send request:",r+n+t);var i=ye(r+"\r\n"+n+"\r\n"+t);return i.buffer}}]),e}();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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var we=function(e){E.default(n,e);var t=be(n);function n(e){return C.default(this,n),t.call(this,e)}return n}(L.default(Error));function xe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var ke=function(e){E.default(n,e);var t=xe(n);function n(e,r){var i;return C.default(this,n),(i=t.call(this,e)).reply=r,i}return n}(we);function _e(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 Se(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?_e(Object(n),!0).forEach((function(t){O.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):_e(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Te=function(e){E.default(n,e);var t=Ee(n);function n(e){var r;return C.default(this,n),r=t.call(this),O.default(_.default(r),"newBackoff",null),O.default(_.default(r),"usedBackoff",null),O.default(_.default(r),"retrier",null),r.options=e?Se({},e):{},r}return k.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=Se({},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 m.Retrier(t),this.retrier.once("attempt",(function(){var t,n;null===(t=e.retrier)||void 0===t||t.on("attempt",(function(){return e.emit("attempt")})),null===(n=e.retrier)||void 0===n||n.failed(new Error("Skipping first attempt"))})),this.retrier.on("failed",(function(t){return e.emit("failed",t)})),this.usedBackoff=this.newBackoff,this.newBackoff=null,this.retrier.start()}}]),n}(D);function 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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Ce=function(e){E.default(i,e);var t,n,r=Re(i);function i(e,t,n){var o;C.default(this,i),o=r.call(this),O.default(_.default(o),"disconnectingTimer",null),O.default(_.default(o),"disconnectedPromiseResolve",null),O.default(_.default(o),"terminalStates",["disconnected","rejected"]),O.default(_.default(o),"tokenExpiredSasCode",20104),O.default(_.default(o),"terminationReason","Connection is not initialized"),o.websocket=e,o.websocket.on("connected",(function(){return o.fsm.socketConnected()})),o.websocket.on("disconnected",(function(){return o.fsm.socketClosed()})),o.websocket.on("message",(function(e){return o.onIncomingMessage(e)})),o.websocket.on("socketError",(function(e){return o.emit("connectionError",{terminal:!1,message:"Socket error: ".concat(e.message),httpStatusCode:null,errorCode:null})})),o.transport=t,o.config=n,o.retrier=new Te(n.retryPolicy),o.retrier.on("attempt",(function(){return o.retry()})),o.retrier.on("failed",(function(e){Y.warn("Retrying failed: ".concat(e.message)),o.disconnect()})),"undefined"!=typeof window&&void 0!==window.addEventListener&&(window.addEventListener("online",(function(){Y.debug("Browser reported connectivity state: online"),o.resetBackoff(),o.fsm.systemOnline()})),window.addEventListener("offline",(function(){Y.debug("Browser reported connectivity state: offline"),o.websocket.close(),o.fsm.socketClosed()})));var a=j.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(){o.setupSocket(),o.emit("connecting")},onEnterInitialising:function(){o.sendInit()},onLeaveInitialising:function(){o.cancelInit()},onEnterUpdating:function(){o.sendUpdate()},onLeaveUpdating:function(){o.cancelUpdate()},onEnterRetrying:function(){o.initRetry(),o.emit("connecting")},onEnterConnected:function(){o.resetBackoff(),o.onConnected()},onUserUpdateToken:function(){o.resetBackoff()},onTokenRejected:function(){o.resetBackoff(),o.closeSocket(!0),o.finalizeSocket()},onUserDisconnect:function(){o.closeSocket(!0)},onEnterDisconnecting:function(){o.startDisconnectTimer()},onLeaveDisconnecting:function(){o.cancelDisconnectTimer()},onEnterWaitSocketClosed:function(){o.startDisconnectTimer()},onLeaveWaitSocketClosed:function(){o.cancelDisconnectTimer()},onEnterWaitOffloadSocketClosed:function(){o.startDisconnectTimer()},onLeaveWaitOffloadSocketClosed:function(){o.cancelDisconnectTimer()},onDisconnected:function(){o.resetBackoff(),o.finalizeSocket()},onReceiveClose:function(){o.onCloseReceived()},onReceiveOffload:function(e,t){Y.debug("onreceiveoffload: ",t),o.modifyBackoff(t.body),o.onCloseReceived()},onUnsupported:function(){o.closeSocket(!0),o.finalizeSocket()},onError:function(e,t){o.closeSocket(t),o.finalizeSocket()},onEnterState:function(e){"none"!==e.from&&o.changeState(e)},onInvalidTransition:function(e,t,n){Y.warn("FSM: unexpected transition",t,n)}}});return o.fsm=new a,o}return k.default(i,[{key:"changeState",value:function(e){Y.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(){Y.trace("resetBackoff"),this.retrier.stop()}},{key:"modifyBackoff",value:function(e){Y.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;Y.trace("startDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null),this.disconnectingTimer=setTimeout((function(){Y.debug("disconnecting is timed out"),e.closeSocket(!0)}),3e3)}},{key:"cancelDisconnectTimer",value:function(){Y.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(){Y.debug("initRetry"),this.retrier.inProgress?this.retrier.attemptFailed():this.retrier.start()}},{key:"retry",value:function(){"connecting"!=this.fsm.state?(Y.trace("retry"),this.websocket.close(),this.fsm.userRetry()):Y.trace("can\t retry as already connecting")}},{key:"onConnected",value:function(){this.emit("connected")}},{key:"finalizeSocket",value:function(){Y.trace("finalizeSocket"),this.websocket.close(),this.emit("disconnected"),this.disconnectedPromiseResolve&&(this.disconnectedPromiseResolve(),this.disconnectedPromiseResolve=null)}},{key:"setupSocket",value:function(){Y.trace("setupSocket:",this.config.token),this.emit("beforeConnect"),this.websocket.connect()}},{key:"onIncomingMessage",value:function(e){var t=ge.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)Y.debug("Connection has been offloaded"),this.fsm.receiveOffload({status:r.status.status,body:i});else if(406===r.status.code){var o="Server closed connection because can't parse protocol: ".concat(JSON.stringify(r.status));this.emitReplyConnectionError(o,r,!0),Y.error(o),this.fsm.receiveFatalClose()}else 417===r.status.code?(Y.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?(Y.warn("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status),this.emit("tokenExpired")):401===r.status.code?(Y.error("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status)):(Y.warn("unexpected message: ",r.status),this.fsm.receiveOffload({status:r.status.status,body:null}))}}},{key:"sendInit",value:(n=x.default(I.default.mark((function e(){var t,n;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y.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 ke?(n=!1,Y.warn("Init rejected by server: ".concat(JSON.stringify(e.t0.reply.status))),this.emit("sendInitFailed"),401===e.t0.reply.status.code||403===e.t0.reply.status.code?(n=!0,this.fsm.tokenRejected(e.t0.reply.status),e.t0.reply.status.errorCode===this.tokenExpiredSasCode&&this.emit("tokenExpired")):429===e.t0.reply.status.code?(this.modifyBackoff(e.t0.reply.body),this.fsm.initError(!0)):500===e.t0.reply.status.code?this.fsm.initError(!1):this.fsm.initError(!0),this.emitReplyConnectionError(e.t0.message,e.t0.reply,n)):(this.terminationReason=e.t0.message,this.emit("connectionError",{terminal:!0,message:"Unknown error during connection initialisation: ".concat(e.t0.message,"\n").concat(JSON.stringify(e.t0,null,2)),httpStatusCode:null,errorCode:null}),this.fsm.initError(!0)),this.emit("tokenUpdated",e.t0);case 17:case"end":return e.stop()}}),e,this,[[1,13]])}))),function(){return n.apply(this,arguments)})},{key:"sendUpdate",value:(t=x.default(I.default.mark((function e(){var t,n,r;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y.trace("sendUpdate"),t=new oe(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 ke?(r=!1,Y.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,o=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:o})}},{key:"cancelInit",value:function(){Y.trace("cancelInit")}},{key:"cancelUpdate",value:function(){Y.trace("cancelUpdate")}},{key:"confirmReceiving",value:function(e){Y.trace("confirmReceiving");try{this.transport.send(new ue(e.id))}catch(e){Y.debug("failed to confirm packet receiving",e)}}},{key:"closeSocket",value:function(e){var t=this;Y.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(){Y.trace("connect"),this.fsm.userConnect()}},{key:"disconnect",value:function(){var e=this;return Y.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 Y.trace("updateToken:",e),new Promise((function(e,n){t.once("tokenUpdated",(function(t){t?n(t):e()})),t.fsm.userUpdateToken()}))}},{key:"isTerminalState",get:function(){return-1!==this.terminalStates.indexOf(this.fsm.state)}},{key:"getTerminationReason",get:function(){return this.terminationReason}},{key:"onCloseReceived",value:function(){this.websocket.close()}}]),i}(D),Oe=function(){function e(){C.default(this,e)}return k.default(e,null,[{key:"getMetadata",value:function(e){var t,n,r,i,o,a,s,u,c=e&&e.clientMetadata?e.clientMetadata:{},l={env:null!==(t=M.name)&&void 0!==t?t:"unknown",envv:null!==(n=M.version)&&void 0!==n?n:"unknown",os:null!==(r=null===(i=M.os)||void 0===i?void 0:i.family)&&void 0!==r?r:"unknown",osv:null!==(o=null===(a=M.os)||void 0===a?void 0:a.version)&&void 0!==o?o:"unknown",osa:null!==(s=null===(u=M.os)||void 0===u?void 0:u.architecture)&&void 0!==s?s:"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 Ie=function(){function e(t,n){var r=this;C.default(this,e),this.config=n,this.activeRequests=new Map,this.channel=t,this.channel.on("reply",(function(e){return r.processReply(e)})),this.channel.on("disconnected",(function(){r.activeRequests.forEach((function(e){clearTimeout(e.timeout),e.reject(new we("disconnected"))})),r.activeRequests.clear()}))}var t;return k.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 ke("Transport failure: "+e.status.status,e)),Y.trace("message rejected")))}},{key:"storeRequest",value:function(e,t,n){var r={resolve:t,reject:n,timeout:setTimeout((function(){Y.trace("request",e,"is timed out"),n(new we("Twilsock: request timeout: "+e))}),3e4)};this.activeRequests.set(e,r)}},{key:"shutdown",value:function(){this.activeRequests.forEach((function(e){clearTimeout(e.timeout),e.reject(new we("Twilsock: request cancelled by user"))})),this.activeRequests.clear()}},{key:"sendInit",value:(t=x.default(I.default.mark((function e(){var t,n,r;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y.trace("sendInit"),t=Oe.getMetadata(this.config),n=new te(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 re(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 le;this.send(e)}},{key:"sendWithReply",value:function(e,t){var n=this;return new Promise((function(r,i){var o=n.send(e,t);n.storeRequest(o,r,i)}))}},{key:"send",value:function(e,t){e.id=e.id||"TM".concat(y.v4());var n=ge.createPacket(e,function(e){switch(A.default(e)){case"undefined":return"";case"object":return JSON.stringify(e);default:return e}}(t));try{return this.channel.send(n),e.id}catch(t){throw Y.debug("failed to send ",e,t),Y.trace(t.stack),t}}}]),e}();function Ae(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Pe=function(e){E.default(r,e);var n=Ae(r);function r(e){var i;return C.default(this,r),i=n.call(this),O.default(_.default(i),"socket",null),i.url=e,i.url=e,i.WebSocket=t.WebSocket||t.MozWebSocket||{},i}return k.default(r,[{key:"isConnected",get:function(){return!!this.socket&&1===this.socket.readyState}},{key:"connect",value:function(){var e,t=this;Y.trace("connecting to socket");try{e=new this.WebSocket(this.url)}catch(e){return Y.debug("Socket error: ".concat(this.url)),void this.emit("socketError",e)}e.binaryType="arraybuffer",e.onopen=function(){Y.debug("socket opened ".concat(t.url)),t.emit("connected")},e.onclose=function(e){Y.debug("socket closed",e),t.emit("disconnected",e)},e.onerror=function(e){Y.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(Y.trace("closing socket"),this.socket){this.socket.onopen=null,this.socket.onclose=null,this.socket.onerror=null,this.socket.onmessage=null;try{this.socket.close()}finally{}}}}]),r}(D);function je(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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Le=function(e){E.default(u,e);var t,n,r,i,o,a,s=je(u);function u(e){var t;return C.default(this,u),(t=s.call(this)).transport=e,t.registrations=new Map,t.registrationsInProgress=new Map,t}return k.default(u,[{key:"putNotificationContext",value:(a=x.default(I.default.mark((function e(t,n){var r;return I.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 a.apply(this,arguments)})},{key:"deleteNotificationContext",value:(o=x.default(I.default.mark((function e(t){var n;return I.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 o.apply(this,arguments)})},{key:"updateRegistration",value:(i=x.default(I.default.mark((function e(t,n){var r,i;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y.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:Y.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),Y.warn("registration attempt failed for context",n),Y.debug(e.t0),r.delete(i),0===r.size&&(this.registrationsInProgress.delete(t),this.emit("registrationFailed",t,e.t0));case 19:case"end":return e.stop()}}),e,this,[[5,13]])}))),function(e,t){return i.apply(this,arguments)})},{key:"updateRegistrations",value:(r=x.default(I.default.mark((function e(){var t,n=this;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y.trace("refreshing ".concat(this.registrations.size," registrations")),t=[],this.registrations.forEach((function(e,r){t.push(n.updateRegistration(r,e))})),e.next=5,Promise.all(t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"setNotificationsContext",value:(n=x.default(I.default.mark((function e(t,n){return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t&&n){e.next=2;break}throw new we("Invalid arguments provided");case 2:return this.registrations.set(t,n),e.next=5,this.updateRegistration(t,n);case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeNotificationsContext",value:(t=x.default(I.default.mark((function e(t){return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.registrations.has(t)){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.deleteNotificationContext(t);case 4:this.transport.isConnected&&this.registrations.delete(t);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),u}(D);function 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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Ne=function(e){E.default(n,e);var t=Me(n);function n(e,r,i){var o;return C.default(this,n),(o=t.call(this,r)).status=e,o.description=r,o.body=i,o}return n}(we);function De(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Ue=function(e){E.default(n,e);var t=De(n);function n(e){return C.default(this,n),t.call(this,e)}return n}(we);function Fe(e,t){var n=function(e){var t=e.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)(\/[^?#]*)(\?[^#]*|)(#.*|)$/);if(t){var n={protocol:t[1],host:t[2],hostname:t[3],port:t[4],pathname:t[5],search:t[6],hash:t[7],params:{}};if(n.search.length>0){var r=n.search.substring(1);n.params=r.split("&").map((function(e){return e.split("=")})).reduce((function(e,t){return e.hasOwnProperty(t[0])?Array.isArray(e[t[0]])?e[t[0]].push(t[1]):e[t[0]]=[e[t[0]],t[1]]:e[t[0]]=t[1],e}),{})}return n}throw new we("Incorrect URI: "+e)}(t),r={method:e,host:n.host,path:n.pathname};return n.params&&(r.params=n.params),r}function Be(e,t,n,r,i){return{to:Fe(e,t),headers:n,body:r,grant:i}}var qe=function(){function e(t,n,r){C.default(this,e),this.config=r,this.transport=t,this.pendingMessages=[],this.twilsock=n}var t;return k.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(){Y.debug("request is timed out"),r(new we("request '".concat(e.to.method,"' to '").concat(e.to.host,"' timed out"))),i.alreadyRejected=!0}),2e4)};t.pendingMessages.push(i)}))}},{key:"sendPendingMessages",value:function(){for(var e=this,t=function(){var t=e.pendingMessages[0];if(!t.alreadyRejected)try{var n=t.message;e.actualSend(n).then((function(e){return t.resolve(e)})).catch((function(e){return t.reject(e)})),clearTimeout(t.timeout)}catch(e){return Y.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 Ue("Unable to connect: "+e.twilsock.getTerminationReason)),t.alreadyRejected=!0,clearTimeout(t.timeout)})),this.pendingMessages.splice(0,this.pendingMessages.length)}},{key:"actualSend",value:(t=x.default(I.default.mark((function e(t){var n,r,i,o,a,s,u,c;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.to,i=t.headers,o=t.body,a=null!==(n=t.grant)&&void 0!==n?n:this.config.activeGrant,s={host:r.host,path:r.path,method:r.method,params:r.params,headers:i},u=new Message(a,i["Content-Type"]||"application/json",s),Y.trace("Sending upstream message",u),e.next=9,this.transport.sendWithReply(u,o);case 9:if(c=e.sent,Y.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 Ne(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 Ue("Unable to connect: "+this.twilsock.getTerminationReason));var o=Be(e,t,n,r,i);return this.twilsock.isConnected?this.actualSend(o):this.saveMessage(o)}}]),e}(),ze=function(){function e(){var t=this;C.default(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return k.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}(),We=function(){function e(t){C.default(this,e),this.id=t}return k.default(e,null,[{key:"create",value:function(t){if(t instanceof Object&&"storage_id"in t)return new e(t.storage_id);throw new we('Field "storage_id" is missing')}}]),e}(),Ge=function(){function e(){return C.default(this,e),O.default(this,"initializedFlag","twilio_twilsock_token_storage"),O.default(this,"tokenStoragePrefix","twilio_continuation_token_"),e._instance||(this.initialize(),e._instance=this),e._instance}return k.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}();O.default(Ge,"_instance",null);var $e,Je,Ke=new Ge,Ve=function(){function e(t,n,r,i,o,a){C.default(this,e),this.title=t,this.details=n,this.start=r,this.type=o,this.id=a,this.end=i}return k.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(),o=n.getTime()-e.getTime();return new de(i,o,this.title,this.details,this.id,this.type)}}]),e}();e.TelemetryPoint=void 0,($e=e.TelemetryPoint||(e.TelemetryPoint={}))[$e.Start=0]="Start",$e[$e.End=1]="End",e.EventSendingLimitation=void 0,(Je=e.EventSendingLimitation||(e.EventSendingLimitation={}))[Je.MinEventsPortion=0]="MinEventsPortion",Je[Je.AnyEvents=1]="AnyEvents",Je[Je.AnyEventsIncludingUnfinished=2]="AnyEventsIncludingUnfinished";var He=function(){function t(e,n){C.default(this,t),O.default(this,"minEventsPortionToSend",50),O.default(this,"maxEventsPortionToSend",100),O.default(this,"pendingEvents",new Map),O.default(this,"readyEvents",[]),O.default(this,"hasInitializationFinished",!1),O.default(this,"_canSendTelemetry",!1),this.config=e,this.packetInterface=n}return k.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){Y.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){Y.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&&Y.debug("Overwriting starting point for '".concat(n,"' event")),this.pendingEvents.set(n,t);else{if(!i)return void Y.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 Ve("[UNFINISHED] ".concat(i.title),i.details,i.start,null,i.type,i.id))}})),r}},{key:"merge",value:function(e,t){return new Ve(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 pe(t.map((function(e){return e.toTelemetryEvent()}))))}catch(e){Y.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 Ye(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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Qe=function e(){C.default(this,e)};O.default(Qe,"TWILSOCK_CONNECT","twilsock.sdk.connect"),O.default(Qe,"TWILSOCK_INIT","twilsock.sdk.init"),e.TwilsockClient=function(t){E.default(f,t);var n,r,i,o,a,s,u,c,l=Ye(f);function f(t,n,r){var i;C.default(this,f),i=l.call(this),O.default(_.default(i),"version",Q),O.default(_.default(i),"offlineStorageDeferred",new ze),r.continuationToken=r.continuationToken?r.continuationToken:Ke.getStoredToken(n);var o=i.config=new X(t,n,r);Y.setLevel(o.logLevel);var a=new Pe(o.url),s=new Ie(a,o);return i.channel=new Ce(a,s,o),i.registrations=new Le(s),i.upstream=new qe(s,i.channel,o),i.telemetryTracker=new He(o,s),i.channel.on("initialized",(function(){return i.telemetryTracker.canSendTelemetry=!0})),a.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 Ve("Establish WebSocket connection","",new Date),Qe.TWILSOCK_CONNECT,e.TelemetryPoint.Start)})),i.channel.on("connected",(function(){return i.telemetryTracker.addPartialEvent(new Ve("Establish WebSocket connection","",new Date,new Date),Qe.TWILSOCK_CONNECT,e.TelemetryPoint.End)})),i.channel.on("beforeSendInit",(function(){return i.telemetryTracker.addPartialEvent(new Ve("Send Twilsock init","",new Date),Qe.TWILSOCK_INIT,e.TelemetryPoint.Start)})),i.channel.on("initialized",(function(){return i.telemetryTracker.addPartialEvent(new Ve("Send Twilsock init","Succeeded",new Date,new Date),Qe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("sendInitFailed",(function(){return i.telemetryTracker.addPartialEvent(new Ve("Send Twilsock init","Failed",new Date,new Date),Qe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("initialized",(function(e){i.handleStorageId(n,e),Ke.storeToken(e.continuationToken,n),setTimeout((function(){return i.emit("initialized",e)}),0)})),i.channel.on("disconnected",(function(){return setTimeout((function(){return i.emit("disconnected")}),0)})),i.channel.on("disconnected",(function(){return i.upstream.rejectPendingMessages()})),i.channel.on("disconnected",(function(){return i.offlineStorageDeferred.fail(new we("Client disconnected"))})),i.offlineStorageDeferred.promise.catch((function(){})),i}return k.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 Y.debug("Emitting ".concat(e.toString(),"(").concat(r.map((function(e){return JSON.stringify(e)})).join(", "),")")),(t=S.default(R.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(We.create(t.offlineStorage[e])),Y.debug("Offline storage for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage[e]),"."))}catch(n){this.offlineStorageDeferred.fail(new we("Failed to parse offline storage for ".concat(e," ").concat(JSON.stringify(t.offlineStorage[e]),". ").concat(n,".")))}else this.offlineStorageDeferred.fail(new we("No offline storage id for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage))));else this.offlineStorageDeferred.fail(new we("No offline storage id"))}},{key:"storageId",value:function(){return this.offlineStorageDeferred.promise}},{key:"isConnected",get:function(){return this.channel.isConnected}},{key:"state",get:function(){return this.channel.state}},{key:"updateToken",value:(c=x.default(I.default.mark((function e(t){return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Y.trace("updating token '".concat(t,"'")),this.config.token!==t){e.next=3;break}return e.abrupt("return");case 3:return this.config.updateToken(t),e.next=6,this.channel.updateToken(t);case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"setNotificationsContext",value:(u=x.default(I.default.mark((function e(t,n){return I.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:(s=x.default(I.default.mark((function e(t){return I.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 s.apply(this,arguments)})},{key:"connect",value:function(){return this.channel.connect()}},{key:"disconnect",value:(a=x.default(I.default.mark((function t(){return I.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 a.apply(this,arguments)})},{key:"get",value:(o=x.default(I.default.mark((function t(n,r,i){return I.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 o.apply(this,arguments)})},{key:"post",value:(i=x.default(I.default.mark((function t(n,r,i,o){return I.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,o);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n,r){return i.apply(this,arguments)})},{key:"put",value:(r=x.default(I.default.mark((function t(n,r,i,o){return I.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,o);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"delete",value:(n=x.default(I.default.mark((function t(n,r,i,o){return I.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,o);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,r,i){return n.apply(this,arguments)})},{key:"addTelemetryEvent",value:function(e){this.telemetryTracker.addTelemetryEvent(e),this.telemetryTracker.sendTelemetryIfMinimalPortionCollected()}},{key:"addPartialTelemetryEvent",value:function(t,n,r){this.telemetryTracker.addPartialEvent(t,n,r),r===e.TelemetryPoint.End&&this.telemetryTracker.sendTelemetryIfMinimalPortionCollected()}}]),f}(D),e.TwilsockClient=function(e,t,n,r){var i,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":A.default(Reflect))&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(o<3?i(a):o>3?i(t,n,a):i(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([d.validateConstructorTypes(d.nonEmptyString,d.nonEmptyString,[d.pureObject,"undefined",d.literal(null)]),function(e,t){if("object"===("undefined"==typeof Reflect?"undefined":A.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[String,String,Object])],e.TwilsockClient);var Xe=function(){function e(t){C.default(this,e),this.product=t,this.type="ers",this.notification_protocol_version=0,this.message_types=[]}return k.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=Xe,e.TelemetryEventDescription=Ve,e.TelemetryTracker=He,e.TransportUnavailableError=Ue,e.Twilsock=e.TwilsockClient,e.TwilsockError=we}(Fg);var DR={},UR={exports:{}};!function(e){function t(e,t,n,r,i,o,a){try{var s=e[o](a),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,o){var a=e.apply(n,r);function s(e){t(a,i,o,s,u,"next",e)}function u(e){t(a,i,o,s,u,"throw",e)}s(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports}(UR);var FR=n(Wc);function BR(e){return(BR="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)}var qR={},zR={exports:{}};!function(e){function t(e,t,n,r,i,o,a){try{var s=e[o](a),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,o){var a=e.apply(n,r);function s(e){t(a,i,o,s,u,"next",e)}function u(e){t(a,i,o,s,u,"throw",e)}s(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports}(zR);var WR={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}(WR);var GR={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}(GR);var $R={exports:{}},JR={exports:{}},KR={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}(KR),function(e){var t=KR.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}(JR),function(e){var t=JR.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 o=Object.getOwnPropertyDescriptor(i,n);return o.get?o.get.call(arguments.length<3?e:r):o.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}($R);var VR={exports:{}},HR={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}(HR),function(e){var t=HR.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}(VR);var YR={exports:{}},QR={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}(QR),function(e){var t=QR.exports.default,n=GR.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}(YR);var XR={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}(XR);var ZR={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}(ZR);var eC,tC=Object.prototype,nC=tC.hasOwnProperty,rC="function"==typeof Symbol?Symbol:{},iC=rC.iterator||"@@iterator",oC=rC.asyncIterator||"@@asyncIterator",aC=rC.toStringTag||"@@toStringTag";function sC(e,t,n,r){var i=t&&t.prototype instanceof hC?t:hC,o=Object.create(i.prototype),a=new RC(r||[]);return o._invoke=function(e,t,n){var r=cC;return function(i,o){if(r===fC)throw new Error("Generator is already running");if(r===dC){if("throw"===i)throw o;return OC()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var s=SC(a,n);if(s){if(s===pC)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===cC)throw r=dC,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=fC;var u=uC(e,t,n);if("normal"===u.type){if(r=n.done?dC:lC,u.arg===pC)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=dC,n.method="throw",n.arg=u.arg)}}}(e,n,a),o}function uC(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}var cC="suspendedStart",lC="suspendedYield",fC="executing",dC="completed",pC={};function hC(){}function yC(){}function vC(){}var mC={};mC[iC]=function(){return this};var gC=Object.getPrototypeOf,bC=gC&&gC(gC(CC([])));bC&&bC!==tC&&nC.call(bC,iC)&&(mC=bC);var wC=vC.prototype=hC.prototype=Object.create(mC);function xC(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function kC(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===yC||"GeneratorFunction"===(t.displayName||t.name))}function _C(e,t){function n(r,i,o,a){var s=uC(e[r],e,i);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"===BR(c)&&nC.call(c,"__await")?t.resolve(c.__await).then((function(e){n("next",e,o,a)}),(function(e){n("throw",e,o,a)})):t.resolve(c).then((function(e){u.value=e,o(u)}),(function(e){return n("throw",e,o,a)}))}a(s.arg)}var r;this._invoke=function(e,i){function o(){return new t((function(t,r){n(e,i,t,r)}))}return r=r?r.then(o,o):o()}}function SC(e,t){var n=e.iterator[t.method];if(n===eC){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=eC,SC(e,t),"throw"===t.method))return pC;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return pC}var r=uC(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,pC;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=eC),t.delegate=null,pC):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,pC)}function EC(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 TC(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function RC(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(EC,this),this.reset(!0)}function CC(e){if(e){var t=e[iC];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(nC.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=eC,t.done=!0,t};return r.next=r}}return{next:OC}}function OC(){return{value:eC,done:!0}}yC.prototype=wC.constructor=vC,vC.constructor=yC,vC[aC]=yC.displayName="GeneratorFunction",xC(_C.prototype),_C.prototype[oC]=function(){return this},xC(wC),wC[aC]="Generator",wC[iC]=function(){return this},wC.toString=function(){return"[object Generator]"},RC.prototype={constructor:RC,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=eC,this.done=!1,this.delegate=null,this.method="next",this.arg=eC,this.tryEntries.forEach(TC),!e)for(var t in this)"t"===t.charAt(0)&&nC.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=eC)},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 o.type="throw",o.arg=e,t.next=n,r&&(t.method="next",t.arg=eC),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],o=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=nC.call(i,"catchLoc"),s=nC.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){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&&nC.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 o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,pC):this.complete(o)},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),pC},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),TC(n),pC}},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;TC(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:CC(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=eC),pC}};var IC={wrap:sC,isGeneratorFunction:kC,AsyncIterator:_C,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,vC):(e.__proto__=vC,aC in e||(e[aC]="GeneratorFunction")),e.prototype=Object.create(wC),e},awrap:function(e){return{__await:e}},async:function(e,t,n,r,i){void 0===i&&(i=Promise);var o=new _C(sC(e,t,n,r),i);return kC(t)?o:o.next().then((function(e){return e.done?e.value:o.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:CC},AC=n(Object.freeze({__proto__:null,default:IC})),PC={},jC={exports:{}},LC={exports:{}};!function(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports}(LC);var MC={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,o=[],a=!0,s=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==n.return||n.return()}finally{if(s)throw i}}return o}},e.exports.__esModule=!0,e.exports.default=e.exports}(MC);var NC={exports:{}},DC={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}(DC),function(e){var t=DC.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}(NC);var UC={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}(UC),function(e){var t=LC.exports,n=MC.exports,r=NC.exports,i=UC.exports;e.exports=function(e,o){return t(e)||n(e,o)||r(e,o)||i()},e.exports.__esModule=!0,e.exports.default=e.exports}(jC);var FC={exports:{}},BC={exports:{}};!function(e){var t=DC.exports;e.exports=function(e){if(Array.isArray(e))return t(e)},e.exports.__esModule=!0,e.exports.default=e.exports}(BC);var qC={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}(qC);var zC={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}(zC),function(e){var t=BC.exports,n=qC.exports,r=NC.exports,i=zC.exports;e.exports=function(e){return t(e)||n(e)||r(e)||i()},e.exports.__esModule=!0,e.exports.default=e.exports}(FC),Object.defineProperty(PC,"__esModule",{value:!0});var WC=jC.exports,GC=FC.exports,$C=XR.exports,JC=VR.exports,KC=YR.exports,VC=KR.exports;function HC(e){return e&&"object"===BR(e)&&"default"in e?e:{default:e}}var YC=HC(QR.exports),QC=HC(WC),XC=HC(GC),ZC=HC($C),eO=HC(JC),tO=HC(KC),nO=HC(VC),rO=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return{checks:t}};function iO(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 oO(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 oO(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function oO(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 aO=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return rO((function(e){var n,r=!1,i=[],o=iO(t);try{for(o.s();!(n=o.n()).done;){var a=n.value;"string"!=typeof a?(r=r||e instanceof a,i.push("an instance of ".concat(a.name))):(r=r||YC.default(e)===a,i.push("of type ".concat(a)))}}catch(e){o.e(e)}finally{o.f()}return[r,i]}))};function sO(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 uO(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 uO(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function uO(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 cO=rO((function(e){return["string"==typeof e&&e.length>0,"a non-empty string"]})),lO=rO((function(e){return["number"==typeof e&&Number.isInteger(e)&&e>=0,"a non-negative integer"]})),fO=rO((function(e){return["object"===YC.default(e)&&null!==e&&!Array.isArray(e),"a pure object (non-null and non-array)"]}));function dO(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=nO.default(e);if(t){var i=nO.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return tO.default(this,n)}}function pO(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 hO(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 hO(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function hO(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 yO=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=pO(t.entries());try{for(r.s();!(n=r.n()).done;){var i=QC.default(n.value,2),o=i[0],a=i[1],s=bO(e[o],a),u=QC.default(s,4),c=u[0],l=u[1],f=u[2],d=u[3];if(!c)throw new Error("Argument ".concat(o+1," is expected to be ").concat(f).concat(d," but got ").concat(l))}}catch(e){r.e(e)}finally{r.f()}},vO=function(e){var t,n,r;(["undefined","boolean","number","bigint","string"].includes(YC.default(e))&&(n="string"==typeof e?'"'.concat(e,'"'):"".concat(e)),"object"===YC.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=YC.default(e)),n},mO=function(e){var t,n=[],r=pO(e);try{for(r.s();!(t=r.n()).done;){var i=t.value;n.push(gO(i))}}catch(e){r.e(e)}finally{r.f()}return n},gO=function(e){var t,n=[],r=pO(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(aO(i))}}catch(e){r.e(e)}finally{r.f()}return n},bO=function(e,t){var n,r,i=[],o=!1,a=pO(e);try{for(a.s();!(r=a.n()).done;){var s,u=pO(r.value.checks);try{for(u.s();!(s=u.n()).done;){var c=(0,s.value)(t),l=QC.default(c,3),f=l[0],d=l[1],p=l[2];o=o||f,!n&&p&&(n=p),d&&(i=[].concat(XC.default(i),"string"==typeof d?[d]:XC.default(d)))}}catch(e){u.e(e)}finally{u.f()}}}catch(e){a.e(e)}finally{a.f()}if(o)return[!0];var h=n||vO(t),y=i.length-1;return[!1,h,y>0?"".concat(i.slice(0,y).join(", ")," or ").concat(i[y]):i.join(", "),y>1?";":","]};function wO(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 xO(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 xO(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function xO(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}PC.array=function(e,t){return rO((function(n){if(!Array.isArray(n))return[!1,"an array of ".concat(e)];var r,i=wO(n.entries());try{for(i.s();!(r=i.n()).done;){var o=QC.default(r.value,2),a=o[0],s=o[1],u=bO(gO(t),s),c=QC.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"a valid array of ".concat(e," (index ").concat(a," should be ").concat(d,")"),"malformed array of ".concat(e," (index ").concat(a," is ").concat(f,")")]}}catch(e){i.e(e)}finally{i.f()}return[!0]}))},PC.custom=rO,PC.literal=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return rO((function(e){var n,r=!1,i=[],o=sO(t);try{for(o.s();!(n=o.n()).done;){var a=n.value;r=r||e===a,i.push("string"==typeof a?'"'.concat(a,'"'):"".concat(a))}}catch(e){o.e(e)}finally{o.f()}return[r,i]}))},PC.nonEmptyString=cO,PC.nonNegativeInteger=lO,PC.objectSchema=function(e,t){return rO((function(n){if("object"!==YC.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 o=QC.default(i[r],2),a=o[0],s=o[1],u=bO(gO(s),n[a]),c=QC.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"valid ".concat(e,' (key "').concat(a,'" should be ').concat(d,")"),"malformed ".concat(e,' (key "').concat(a,'" is ').concat(f,")")]}return[!0]}))},PC.pureObject=fO,PC.runtimeTypeValidation=yO,PC.stringifyReceivedType=vO,PC.type=aO,PC.validateConstructorTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=mO(t);return function(e){return function(e){eO.default(n,e);var t=dO(n);function n(){ZC.default(this,n);for(var e=arguments.length,i=new Array(e),o=0;o<e;o++)i[o]=arguments[o];return yO(r,i),t.call.apply(t,[this].concat(i))}return n}(e)}},PC.validateTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=mO(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 yO(r,t),i.apply(this,t)}}},PC.validateTypesAsync=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=mO(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{yO(r,t)}catch(e){return Promise.reject(e)}return i.apply(this,t)}}};var kO={exports:{}};!function(e){!function(t,n){e.exports?e.exports=n():t.log=n()}(t,(function(){var e=function(){},t="undefined",n=("undefined"==typeof window?"undefined":BR(window))!==t&&BR(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 o(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function a(r){return"debug"===r&&(r="log"),("undefined"==typeof console?"undefined":BR(console))!==t&&("trace"===r&&n?o: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 o=r[i];this[o]=i<t?e:this.methodFactory(o,t,n)}this.log=this.debug}function u(e,n,r){return function(){("undefined"==typeof console?"undefined":BR(console))!==t&&(s.call(this,n,r),this[e].apply(this,arguments))}}function c(e,t,n){return a(e)||u.apply(this,arguments)}function l(e,n,i){var o,a=this,u="loglevel";function l(){var e;if(("undefined"==typeof window?"undefined":BR(window))!==t&&u){try{e=window.localStorage[u]}catch(e){}if(BR(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===a.levels[e]&&(e=void 0),e}}"string"==typeof e?u+=":"+e:"symbol"===BR(e)&&(u=void 0),a.name=e,a.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},a.methodFactory=i||c,a.getLevel=function(){return o},a.setLevel=function(n,i){if("string"==typeof n&&void 0!==a.levels[n.toUpperCase()]&&(n=a.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=a.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(o=n,!1!==i&&function(e){var n=(r[e]||"silent").toUpperCase();if(("undefined"==typeof window?"undefined":BR(window))!==t&&u){try{return void(window.localStorage[u]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(u)+"="+n+";"}catch(e){}}}(n),s.call(a,n,e),("undefined"==typeof console?"undefined":BR(console))===t&&n<a.levels.SILENT)return"No console available for logging"},a.setDefaultLevel=function(e){l()||a.setLevel(e,!1)},a.enableAll=function(e){a.setLevel(a.levels.TRACE,e)},a.disableAll=function(e){a.setLevel(a.levels.SILENT,e)};var f=l();null==f&&(f=null==n?"WARN":n),a.setLevel(f,!1)}var f=new l,d={};f.getLogger=function(e){if("symbol"!==BR(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":BR(window))!==t?window.log:void 0;return f.noConflict=function(){return("undefined"==typeof window?"undefined":BR(window))!==t&&window.log===f&&(window.log=p),f},f.getLoggers=function(){return d},f.default=f,f}))}(kO);var _O={exports:{}},SO={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}(SO);var EO={exports:{}},TO={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}(TO),function(e){var t=HR.exports,n=TO.exports;function r(i,o,a){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 o=new(Function.bind.apply(e,i));return r&&t(o,r.prototype),o},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}(EO),function(e){var t=KR.exports,n=HR.exports,r=SO.exports,i=EO.exports;function o(a){var s="function"==typeof Map?new Map:void 0;return e.exports=o=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,o)}function o(){return i(e,arguments,t(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,e)},e.exports.__esModule=!0,e.exports.default=e.exports,o(a)}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports}(_O);var RO={};Object.defineProperty(RO,"__esModule",{value:!0});var CO=WR.exports,OO=GR.exports,IO=VR.exports,AO=YR.exports,PO=KR.exports,jO=ZR.exports;function LO(e){return e&&"object"===BR(e)&&"default"in e?e:{default:e}}var MO=LO(XR.exports),NO=LO(CO),DO=LO(OO),UO=LO(IO),FO=LO(AO),BO=LO(PO),qO=LO(jO);function zO(){}function WO(){WO.init.call(this)}function GO(e){return void 0===e._maxListeners?WO.defaultMaxListeners:e._maxListeners}function $O(e,t,n){if(t)e.call(n);else for(var r=e.length,i=ZO(e,r),o=0;o<r;++o)i[o].call(n)}function JO(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,o=ZO(e,i),a=0;a<i;++a)o[a].call(n,r)}function KO(e,t,n,r,i){if(t)e.call(n,r,i);else for(var o=e.length,a=ZO(e,o),s=0;s<o;++s)a[s].call(n,r,i)}function VO(e,t,n,r,i,o){if(t)e.call(n,r,i,o);else for(var a=e.length,s=ZO(e,a),u=0;u<a;++u)s[u].call(n,r,i,o)}function HO(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,o=ZO(e,i),a=0;a<i;++a)o[a].apply(n,r)}function YO(e,t,n,r){var i,o,a,s;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]):(o=e._events=new zO,e._eventsCount=0),a){if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),!a.warned&&(i=GO(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,"function"==typeof console.warn?console.warn(s):console.log(s)}}else a=o[t]=n,++e._eventsCount;return e}function QO(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 XO(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 ZO(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function eI(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=BO.default(e);if(t){var i=BO.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return FO.default(this,n)}}zO.prototype=Object.create(null),WO.EventEmitter=WO,WO.usingDomains=!1,WO.prototype.domain=void 0,WO.prototype._events=void 0,WO.prototype._maxListeners=void 0,WO.defaultMaxListeners=10,WO.init=function(){this.domain=null,WO.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new zO,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},WO.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},WO.prototype.getMaxListeners=function(){return GO(this)},WO.prototype.emit=function(e){var t,n,r,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.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=a[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:$O(n,l,this);break;case 2:JO(n,l,this,arguments[1]);break;case 3:KO(n,l,this,arguments[1],arguments[2]);break;case 4:VO(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),o=1;o<r;o++)i[o-1]=arguments[o];HO(n,l,this,i)}return!0},WO.prototype.addListener=function(e,t){return YO(this,e,t,!1)},WO.prototype.on=WO.prototype.addListener,WO.prototype.prependListener=function(e,t){return YO(this,e,t,!0)},WO.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,QO(this,e,t)),this},WO.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,QO(this,e,t)),this},WO.prototype.removeListener=function(e,t){var n,r,i,o,a;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 zO:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length;o-- >0;)if(n[o]===t||n[o].listener&&n[o].listener===t){a=n[o].listener,i=o;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new zO,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,a||t)}return this},WO.prototype.off=function(e,t){return this.removeListener(e,t)},WO.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new zO,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new zO:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new zO,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},WO.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):[]},WO.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):XO.call(e,t)},WO.prototype.listenerCount=XO,WO.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var tI=function(e){UO.default(n,e);var t=eI(n);function n(e){var r;return MO.default(this,n),r=t.call(this),qO.default(DO.default(r),"timeout",null),qO.default(DO.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 NO.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}(WO),nI=function(e){UO.default(n,e);var t=eI(n);function n(e){var r;return MO.default(this,n),r=t.call(this),qO.default(DO.default(r),"resolve",(function(){})),qO.default(DO.default(r),"reject",(function(){})),r.retrier=new tI(e),r}return NO.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}(WO);function rI(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=BO.default(e);if(t){var i=BO.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return FO.default(this,n)}}function iI(e){return null!=e}var oI=function(e){UO.default(n,e);var t=rI(n);function n(e){var r;MO.default(this,n),r=t.call(this),qO.default(DO.default(r),"backoffDelay",0),qO.default(DO.default(r),"nextBackoffDelay",0),qO.default(DO.default(r),"backoffNumber",0),qO.default(DO.default(r),"timeoutID",null),qO.default(DO.default(r),"maxNumberOfRetry",-1);var i=e=e||{},o=i.initialDelay,a=i.maxDelay,s=i.randomisationFactor,u=i.factor;if(iI(o)&&o<1)throw new Error("The initial timeout must be equal to or greater than 1.");if(iI(a)&&a<=1)throw new Error("The maximal timeout must be greater than 1.");if(iI(s)&&(s<0||s>1))throw new Error("The randomisation factor must be between 0 and 1.");if(iI(u)&&u<=1)throw new Error("Exponential factor should be greater than 1.");if(r.initialDelay=o||100,r.maxDelay=a||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 NO.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}(WO);RO.AsyncRetrier=nI,RO.Backoff=oI,RO.Retrier=tI,function(e){var t=void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};Object.defineProperty(e,"__esModule",{value:!0});var n=WR.exports,r=GR.exports,i=$R.exports,o=VR.exports,a=YR.exports,s=KR.exports,u=XR.exports,c=ZR.exports,l=AC,f=QR.exports,d=PC,p=kO.exports,h=Aw.exports,y=ex,v=_O.exports,m=RO,g=dR.exports;function b(e){return e&&"object"===BR(e)&&"default"in e?e:{default:e}}function w(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var x=b(zR.exports),k=b(n),_=b(r),S=b(i),E=b(o),T=b(a),R=b(s),C=b(u),O=b(c),I=b(l),A=b(f),P=w(p),j=w(h),L=b(v),M=w(g);function N(){}function D(){D.init.call(this)}function U(e){return void 0===e._maxListeners?D.defaultMaxListeners:e._maxListeners}function F(e,t,n){if(t)e.call(n);else for(var r=e.length,i=K(e,r),o=0;o<r;++o)i[o].call(n)}function B(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,o=K(e,i),a=0;a<i;++a)o[a].call(n,r)}function q(e,t,n,r,i){if(t)e.call(n,r,i);else for(var o=e.length,a=K(e,o),s=0;s<o;++s)a[s].call(n,r,i)}function z(e,t,n,r,i,o){if(t)e.call(n,r,i,o);else for(var a=e.length,s=K(e,a),u=0;u<a;++u)s[u].call(n,r,i,o)}function W(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,o=K(e,i),a=0;a<i;++a)o[a].apply(n,r)}function G(e,t,n,r){var i,o,a,s;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]):(o=e._events=new N,e._eventsCount=0),a){if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),!a.warned&&(i=U(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,"function"==typeof console.warn?console.warn(s):console.log(s)}}else a=o[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 J(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function K(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}N.prototype=Object.create(null),D.EventEmitter=D,D.usingDomains=!1,D.prototype.domain=void 0,D.prototype._events=void 0,D.prototype._maxListeners=void 0,D.defaultMaxListeners=10,D.init=function(){this.domain=null,D.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new N,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},D.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},D.prototype.getMaxListeners=function(){return U(this)},D.prototype.emit=function(e){var t,n,r,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.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=a[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),o=1;o<r;o++)i[o-1]=arguments[o];W(n,l,this,i)}return!0},D.prototype.addListener=function(e,t){return G(this,e,t,!1)},D.prototype.on=D.prototype.addListener,D.prototype.prependListener=function(e,t){return G(this,e,t,!0)},D.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,$(this,e,t)),this},D.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,$(this,e,t)),this},D.prototype.removeListener=function(e,t){var n,r,i,o,a;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,o=n.length;o-- >0;)if(n[o]===t||n[o].listener&&n[o].listener===t){a=n[o].listener,i=o;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,a||t)}return this},D.prototype.off=function(e,t){return this.removeListener(e,t)},D.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new 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),o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&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},D.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},D.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):J.call(e,t)},D.prototype.listenerCount=J,D.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var V=P.getLogger("twilsock");function H(e,t){return["".concat((new Date).toISOString()," Twilsock ").concat(e,":")].concat(Array.from(t))}var Y=new(function(){function e(t){C.default(this,e),O.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?" "+t+":":""}return k.default(e,[{key:"setLevel",value:function(e){V.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.trace.apply(null,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];V.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];V.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];V.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];V.error.apply(null,H("E",t))}}],[{key:"setLevel",value:function(e){V.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.trace.apply(null,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];V.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];V.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];V.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];V.error.apply(null,H("E",t))}}]),e}())(""),Q="0.12.2",X=function(){function e(t,n,r){C.default(this,e),O.default(this,"confirmedCapabilities",new Set),this.activeGrant=n,this._token=t;var i=r.region||"us1",o="wss://tsock.".concat(i,".twilio.com/v3/wsconnect"),a=r.twilsock||r.Twilsock||{};this.url=a.uri||o,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 k.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}(),Z=function e(t){C.default(this,e),this.id=t||"TM".concat(y.v4())};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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var te=function(e){E.default(n,e);var t=ee(n);function n(e,r,i,o,a){var s;return C.default(this,n),s=t.call(this),O.default(_.default(s),"method","init"),s.token=e,s.continuation_token=r,s.metadata=i,s.registrations=o,s.tweaks=a,s.capabilities=["client_update","offline_storage","telemetry.v1"],s}return n}(Z);function ne(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var re=function(e){E.default(n,e);var t=ne(n);function n(e,r,i,o,a,s,u){var c;return C.default(this,n),(c=t.call(this,e)).continuationToken=r,c.continuationTokenStatus=o,c.offlineStorage=a,c.initRegistrations=s,c.debugInfo=u,c.confirmedCapabilities=i,c}return n}(Z);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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var oe=function(e){E.default(n,e);var t=ie(n);function n(e){var r;return C.default(this,n),r=t.call(this),O.default(_.default(r),"method","update"),r.token=e,r}return n}(Z);function ae(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Message=function(e){E.default(Message,e);var t=ae(Message);function Message(e,n,r){var i;return C.default(this,Message),i=t.call(this),O.default(_.default(i),"method","message"),i.active_grant=e,i.payload_type=n,i.http_request=r,i}return Message}(Z);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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var ue=function(e){E.default(n,e);var t=se(n);function n(e){var r;return C.default(this,n),r=t.call(this,e),O.default(_.default(r),"method","reply"),O.default(_.default(r),"payload_type","application/json"),O.default(_.default(r),"status",{code:200,status:"OK"}),r}return n}(Z);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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var le=function(e){E.default(n,e);var t=ce(n);function n(){var e;return C.default(this,n),e=t.call(this),O.default(_.default(e),"method","close"),e}return n}(Z);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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var de=function e(t,n,r,i,o,a){C.default(this,e),this.start=t,this.end=n,this.title=r,this.details=i,this.id=o,this.type=a},pe=function(e){E.default(n,e);var t=fe(n);function n(e){var r;return C.default(this,n),r=t.call(this),O.default(_.default(r),"method","telemetry.v1"),r.events=e,r}return n}(Z);function he(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})).length}function ye(e){var t=encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode(Number("0x"+t))})),n=new Uint8Array(t.length);return Array.prototype.forEach.call(t,(function(e,t){n[t]=e.charCodeAt(0)})),n}function ve(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 me(e){return JSON.parse(ve(e))}var ge=function(){function e(){C.default(this,e)}return k.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 Y.error("unsupported protocol: ".concat(i.protocol," ver ").concat(i.version)),null;try{t=me(r.subarray(i.size,i.size+i.headerSize))}catch(t){return Y.error("failed to parse message header",t,e),null}if(Y.debug("message received: ",t.method),Y.trace("message received: ",t),t.payload_size>0){var o=2+i.size+i.headerSize,a=t.payload_size;if(t.hasOwnProperty("payload_type")&&0!==t.payload_type.indexOf("application/json"))0===t.payload_type.indexOf("text/plain")&&(n=ve(r.subarray(o,o+a)));else try{n=me(r.subarray(o,o+a))}catch(t){return Y.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=he(t);var n=JSON.stringify(e),r="TWILSOCK V3.0 "+he(n);Y.debug("send request:",r+n+t);var i=ye(r+"\r\n"+n+"\r\n"+t);return i.buffer}}]),e}();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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var we=function(e){E.default(n,e);var t=be(n);function n(e){return C.default(this,n),t.call(this,e)}return n}(L.default(Error));function xe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var ke=function(e){E.default(n,e);var t=xe(n);function n(e,r){var i;return C.default(this,n),(i=t.call(this,e)).reply=r,i}return n}(we);function _e(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 Se(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?_e(Object(n),!0).forEach((function(t){O.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):_e(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Te=function(e){E.default(n,e);var t=Ee(n);function n(e){var r;return C.default(this,n),r=t.call(this),O.default(_.default(r),"newBackoff",null),O.default(_.default(r),"usedBackoff",null),O.default(_.default(r),"retrier",null),r.options=e?Se({},e):{},r}return k.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=Se({},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 m.Retrier(t),this.retrier.once("attempt",(function(){var t,n;null===(t=e.retrier)||void 0===t||t.on("attempt",(function(){return e.emit("attempt")})),null===(n=e.retrier)||void 0===n||n.failed(new Error("Skipping first attempt"))})),this.retrier.on("failed",(function(t){return e.emit("failed",t)})),this.usedBackoff=this.newBackoff,this.newBackoff=null,this.retrier.start()}}]),n}(D);function 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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Ce=function(e){E.default(i,e);var t,n,r=Re(i);function i(e,t,n){var o;C.default(this,i),o=r.call(this),O.default(_.default(o),"disconnectingTimer",null),O.default(_.default(o),"disconnectedPromiseResolve",null),O.default(_.default(o),"terminalStates",["disconnected","rejected"]),O.default(_.default(o),"tokenExpiredSasCode",20104),O.default(_.default(o),"terminationReason","Connection is not initialized"),o.websocket=e,o.websocket.on("connected",(function(){return o.fsm.socketConnected()})),o.websocket.on("disconnected",(function(){return o.fsm.socketClosed()})),o.websocket.on("message",(function(e){return o.onIncomingMessage(e)})),o.websocket.on("socketError",(function(e){return o.emit("connectionError",{terminal:!1,message:"Socket error: ".concat(e.message),httpStatusCode:null,errorCode:null})})),o.transport=t,o.config=n,o.retrier=new Te(n.retryPolicy),o.retrier.on("attempt",(function(){return o.retry()})),o.retrier.on("failed",(function(e){Y.warn("Retrying failed: ".concat(e.message)),o.disconnect()})),"undefined"!=typeof window&&void 0!==window.addEventListener&&(window.addEventListener("online",(function(){Y.debug("Browser reported connectivity state: online"),o.resetBackoff(),o.fsm.systemOnline()})),window.addEventListener("offline",(function(){Y.debug("Browser reported connectivity state: offline"),o.websocket.close(),o.fsm.socketClosed()})));var a=j.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(){o.setupSocket(),o.emit("connecting")},onEnterInitialising:function(){o.sendInit()},onLeaveInitialising:function(){o.cancelInit()},onEnterUpdating:function(){o.sendUpdate()},onLeaveUpdating:function(){o.cancelUpdate()},onEnterRetrying:function(){o.initRetry(),o.emit("connecting")},onEnterConnected:function(){o.resetBackoff(),o.onConnected()},onUserUpdateToken:function(){o.resetBackoff()},onTokenRejected:function(){o.resetBackoff(),o.closeSocket(!0),o.finalizeSocket()},onUserDisconnect:function(){o.closeSocket(!0)},onEnterDisconnecting:function(){o.startDisconnectTimer()},onLeaveDisconnecting:function(){o.cancelDisconnectTimer()},onEnterWaitSocketClosed:function(){o.startDisconnectTimer()},onLeaveWaitSocketClosed:function(){o.cancelDisconnectTimer()},onEnterWaitOffloadSocketClosed:function(){o.startDisconnectTimer()},onLeaveWaitOffloadSocketClosed:function(){o.cancelDisconnectTimer()},onDisconnected:function(){o.resetBackoff(),o.finalizeSocket()},onReceiveClose:function(){o.onCloseReceived()},onReceiveOffload:function(e,t){Y.debug("onreceiveoffload: ",t),o.modifyBackoff(t.body),o.onCloseReceived()},onUnsupported:function(){o.closeSocket(!0),o.finalizeSocket()},onError:function(e,t){o.closeSocket(t),o.finalizeSocket()},onEnterState:function(e){"none"!==e.from&&o.changeState(e)},onInvalidTransition:function(e,t,n){Y.warn("FSM: unexpected transition",t,n)}}});return o.fsm=new a,o}return k.default(i,[{key:"changeState",value:function(e){Y.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(){Y.trace("resetBackoff"),this.retrier.stop()}},{key:"modifyBackoff",value:function(e){Y.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;Y.trace("startDisconnectTimer"),this.disconnectingTimer&&(clearTimeout(this.disconnectingTimer),this.disconnectingTimer=null),this.disconnectingTimer=setTimeout((function(){Y.debug("disconnecting is timed out"),e.closeSocket(!0)}),3e3)}},{key:"cancelDisconnectTimer",value:function(){Y.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(){Y.debug("initRetry"),this.retrier.inProgress?this.retrier.attemptFailed():this.retrier.start()}},{key:"retry",value:function(){"connecting"!=this.fsm.state?(Y.trace("retry"),this.websocket.close(),this.fsm.userRetry()):Y.trace("can\t retry as already connecting")}},{key:"onConnected",value:function(){this.emit("connected")}},{key:"finalizeSocket",value:function(){Y.trace("finalizeSocket"),this.websocket.close(),this.emit("disconnected"),this.disconnectedPromiseResolve&&(this.disconnectedPromiseResolve(),this.disconnectedPromiseResolve=null)}},{key:"setupSocket",value:function(){Y.trace("setupSocket:",this.config.token),this.emit("beforeConnect"),this.websocket.connect()}},{key:"onIncomingMessage",value:function(e){var t=ge.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)Y.debug("Connection has been offloaded"),this.fsm.receiveOffload({status:r.status.status,body:i});else if(406===r.status.code){var o="Server closed connection because can't parse protocol: ".concat(JSON.stringify(r.status));this.emitReplyConnectionError(o,r,!0),Y.error(o),this.fsm.receiveFatalClose()}else 417===r.status.code?(Y.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?(Y.warn("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status),this.emit("tokenExpired")):401===r.status.code?(Y.error("Server closed connection: ".concat(JSON.stringify(r.status))),this.fsm.receiveClose(r.status.status)):(Y.warn("unexpected message: ",r.status),this.fsm.receiveOffload({status:r.status.status,body:null}))}}},{key:"sendInit",value:(n=x.default(I.default.mark((function e(){var t,n;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y.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 ke?(n=!1,Y.warn("Init rejected by server: ".concat(JSON.stringify(e.t0.reply.status))),this.emit("sendInitFailed"),401===e.t0.reply.status.code||403===e.t0.reply.status.code?(n=!0,this.fsm.tokenRejected(e.t0.reply.status),e.t0.reply.status.errorCode===this.tokenExpiredSasCode&&this.emit("tokenExpired")):429===e.t0.reply.status.code?(this.modifyBackoff(e.t0.reply.body),this.fsm.initError(!0)):500===e.t0.reply.status.code?this.fsm.initError(!1):this.fsm.initError(!0),this.emitReplyConnectionError(e.t0.message,e.t0.reply,n)):(this.terminationReason=e.t0.message,this.emit("connectionError",{terminal:!0,message:"Unknown error during connection initialisation: ".concat(e.t0.message,"\n").concat(JSON.stringify(e.t0,null,2)),httpStatusCode:null,errorCode:null}),this.fsm.initError(!0)),this.emit("tokenUpdated",e.t0);case 17:case"end":return e.stop()}}),e,this,[[1,13]])}))),function(){return n.apply(this,arguments)})},{key:"sendUpdate",value:(t=x.default(I.default.mark((function e(){var t,n,r;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y.trace("sendUpdate"),t=new oe(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 ke?(r=!1,Y.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,o=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:o})}},{key:"cancelInit",value:function(){Y.trace("cancelInit")}},{key:"cancelUpdate",value:function(){Y.trace("cancelUpdate")}},{key:"confirmReceiving",value:function(e){Y.trace("confirmReceiving");try{this.transport.send(new ue(e.id))}catch(e){Y.debug("failed to confirm packet receiving",e)}}},{key:"closeSocket",value:function(e){var t=this;Y.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(){Y.trace("connect"),this.fsm.userConnect()}},{key:"disconnect",value:function(){var e=this;return Y.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 Y.trace("updateToken:",e),new Promise((function(e,n){t.once("tokenUpdated",(function(t){t?n(t):e()})),t.fsm.userUpdateToken()}))}},{key:"isTerminalState",get:function(){return-1!==this.terminalStates.indexOf(this.fsm.state)}},{key:"getTerminationReason",get:function(){return this.terminationReason}},{key:"onCloseReceived",value:function(){this.websocket.close()}}]),i}(D),Oe=function(){function e(){C.default(this,e)}return k.default(e,null,[{key:"getMetadata",value:function(e){var t,n,r,i,o,a,s,u,c=e&&e.clientMetadata?e.clientMetadata:{},l={env:null!==(t=M.name)&&void 0!==t?t:"unknown",envv:null!==(n=M.version)&&void 0!==n?n:"unknown",os:null!==(r=null===(i=M.os)||void 0===i?void 0:i.family)&&void 0!==r?r:"unknown",osv:null!==(o=null===(a=M.os)||void 0===a?void 0:a.version)&&void 0!==o?o:"unknown",osa:null!==(s=null===(u=M.os)||void 0===u?void 0:u.architecture)&&void 0!==s?s:"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 Ie=function(){function e(t,n){var r=this;C.default(this,e),this.config=n,this.activeRequests=new Map,this.channel=t,this.channel.on("reply",(function(e){return r.processReply(e)})),this.channel.on("disconnected",(function(){r.activeRequests.forEach((function(e){clearTimeout(e.timeout),e.reject(new we("disconnected"))})),r.activeRequests.clear()}))}var t;return k.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 ke("Transport failure: "+e.status.status,e)),Y.trace("message rejected")))}},{key:"storeRequest",value:function(e,t,n){var r={resolve:t,reject:n,timeout:setTimeout((function(){Y.trace("request",e,"is timed out"),n(new we("Twilsock: request timeout: "+e))}),3e4)};this.activeRequests.set(e,r)}},{key:"shutdown",value:function(){this.activeRequests.forEach((function(e){clearTimeout(e.timeout),e.reject(new we("Twilsock: request cancelled by user"))})),this.activeRequests.clear()}},{key:"sendInit",value:(t=x.default(I.default.mark((function e(){var t,n,r;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y.trace("sendInit"),t=Oe.getMetadata(this.config),n=new te(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 re(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 le;this.send(e)}},{key:"sendWithReply",value:function(e,t){var n=this;return new Promise((function(r,i){var o=n.send(e,t);n.storeRequest(o,r,i)}))}},{key:"send",value:function(e,t){e.id=e.id||"TM".concat(y.v4());var n=ge.createPacket(e,function(e){switch(A.default(e)){case"undefined":return"";case"object":return JSON.stringify(e);default:return e}}(t));try{return this.channel.send(n),e.id}catch(t){throw Y.debug("failed to send ",e,t),Y.trace(t.stack),t}}}]),e}();function Ae(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Pe=function(e){E.default(r,e);var n=Ae(r);function r(e){var i;return C.default(this,r),i=n.call(this),O.default(_.default(i),"socket",null),i.url=e,i.url=e,i.WebSocket=t.WebSocket||t.MozWebSocket||{},i}return k.default(r,[{key:"isConnected",get:function(){return!!this.socket&&1===this.socket.readyState}},{key:"connect",value:function(){var e,t=this;Y.trace("connecting to socket");try{e=new this.WebSocket(this.url)}catch(e){return Y.debug("Socket error: ".concat(this.url)),void this.emit("socketError",e)}e.binaryType="arraybuffer",e.onopen=function(){Y.debug("socket opened ".concat(t.url)),t.emit("connected")},e.onclose=function(e){Y.debug("socket closed",e),t.emit("disconnected",e)},e.onerror=function(e){Y.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(Y.trace("closing socket"),this.socket){this.socket.onopen=null,this.socket.onclose=null,this.socket.onerror=null,this.socket.onmessage=null;try{this.socket.close()}finally{}}}}]),r}(D);function je(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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Le=function(e){E.default(u,e);var t,n,r,i,o,a,s=je(u);function u(e){var t;return C.default(this,u),(t=s.call(this)).transport=e,t.registrations=new Map,t.registrationsInProgress=new Map,t}return k.default(u,[{key:"putNotificationContext",value:(a=x.default(I.default.mark((function e(t,n){var r;return I.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 a.apply(this,arguments)})},{key:"deleteNotificationContext",value:(o=x.default(I.default.mark((function e(t){var n;return I.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 o.apply(this,arguments)})},{key:"updateRegistration",value:(i=x.default(I.default.mark((function e(t,n){var r,i;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y.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:Y.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),Y.warn("registration attempt failed for context",n),Y.debug(e.t0),r.delete(i),0===r.size&&(this.registrationsInProgress.delete(t),this.emit("registrationFailed",t,e.t0));case 19:case"end":return e.stop()}}),e,this,[[5,13]])}))),function(e,t){return i.apply(this,arguments)})},{key:"updateRegistrations",value:(r=x.default(I.default.mark((function e(){var t,n=this;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Y.trace("refreshing ".concat(this.registrations.size," registrations")),t=[],this.registrations.forEach((function(e,r){t.push(n.updateRegistration(r,e))})),e.next=5,Promise.all(t);case 5:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"setNotificationsContext",value:(n=x.default(I.default.mark((function e(t,n){return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t&&n){e.next=2;break}throw new we("Invalid arguments provided");case 2:return this.registrations.set(t,n),e.next=5,this.updateRegistration(t,n);case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeNotificationsContext",value:(t=x.default(I.default.mark((function e(t){return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.registrations.has(t)){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.deleteNotificationContext(t);case 4:this.transport.isConnected&&this.registrations.delete(t);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),u}(D);function 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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Ne=function(e){E.default(n,e);var t=Me(n);function n(e,r,i){var o;return C.default(this,n),(o=t.call(this,r)).status=e,o.description=r,o.body=i,o}return n}(we);function De(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Ue=function(e){E.default(n,e);var t=De(n);function n(e){return C.default(this,n),t.call(this,e)}return n}(we);function Fe(e,t){var n=function(e){var t=e.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)(\/[^?#]*)(\?[^#]*|)(#.*|)$/);if(t){var n={protocol:t[1],host:t[2],hostname:t[3],port:t[4],pathname:t[5],search:t[6],hash:t[7],params:{}};if(n.search.length>0){var r=n.search.substring(1);n.params=r.split("&").map((function(e){return e.split("=")})).reduce((function(e,t){return e.hasOwnProperty(t[0])?Array.isArray(e[t[0]])?e[t[0]].push(t[1]):e[t[0]]=[e[t[0]],t[1]]:e[t[0]]=t[1],e}),{})}return n}throw new we("Incorrect URI: "+e)}(t),r={method:e,host:n.host,path:n.pathname};return n.params&&(r.params=n.params),r}function Be(e,t,n,r,i){return{to:Fe(e,t),headers:n,body:r,grant:i}}var qe=function(){function e(t,n,r){C.default(this,e),this.config=r,this.transport=t,this.pendingMessages=[],this.twilsock=n}var t;return k.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(){Y.debug("request is timed out"),r(new we("request '".concat(e.to.method,"' to '").concat(e.to.host,"' timed out"))),i.alreadyRejected=!0}),2e4)};t.pendingMessages.push(i)}))}},{key:"sendPendingMessages",value:function(){for(var e=this,t=function(){var t=e.pendingMessages[0];if(!t.alreadyRejected)try{var n=t.message;e.actualSend(n).then((function(e){return t.resolve(e)})).catch((function(e){return t.reject(e)})),clearTimeout(t.timeout)}catch(e){return Y.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 Ue("Unable to connect: "+e.twilsock.getTerminationReason)),t.alreadyRejected=!0,clearTimeout(t.timeout)})),this.pendingMessages.splice(0,this.pendingMessages.length)}},{key:"actualSend",value:(t=x.default(I.default.mark((function e(t){var n,r,i,o,a,s,u,c;return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.to,i=t.headers,o=t.body,a=null!==(n=t.grant)&&void 0!==n?n:this.config.activeGrant,s={host:r.host,path:r.path,method:r.method,params:r.params,headers:i},u=new Message(a,i["Content-Type"]||"application/json",s),Y.trace("Sending upstream message",u),e.next=9,this.transport.sendWithReply(u,o);case 9:if(c=e.sent,Y.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 Ne(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 Ue("Unable to connect: "+this.twilsock.getTerminationReason));var o=Be(e,t,n,r,i);return this.twilsock.isConnected?this.actualSend(o):this.saveMessage(o)}}]),e}(),ze=function(){function e(){var t=this;C.default(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return k.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}(),We=function(){function e(t){C.default(this,e),this.id=t}return k.default(e,null,[{key:"create",value:function(t){if(t instanceof Object&&"storage_id"in t)return new e(t.storage_id);throw new we('Field "storage_id" is missing')}}]),e}(),Ge=function(){function e(){return C.default(this,e),O.default(this,"initializedFlag","twilio_twilsock_token_storage"),O.default(this,"tokenStoragePrefix","twilio_continuation_token_"),e._instance||(this.initialize(),e._instance=this),e._instance}return k.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}();O.default(Ge,"_instance",null);var $e,Je,Ke=new Ge,Ve=function(){function e(t,n,r,i,o,a){C.default(this,e),this.title=t,this.details=n,this.start=r,this.type=o,this.id=a,this.end=i}return k.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(),o=n.getTime()-e.getTime();return new de(i,o,this.title,this.details,this.id,this.type)}}]),e}();e.TelemetryPoint=void 0,($e=e.TelemetryPoint||(e.TelemetryPoint={}))[$e.Start=0]="Start",$e[$e.End=1]="End",e.EventSendingLimitation=void 0,(Je=e.EventSendingLimitation||(e.EventSendingLimitation={}))[Je.MinEventsPortion=0]="MinEventsPortion",Je[Je.AnyEvents=1]="AnyEvents",Je[Je.AnyEventsIncludingUnfinished=2]="AnyEventsIncludingUnfinished";var He=function(){function t(e,n){C.default(this,t),O.default(this,"minEventsPortionToSend",50),O.default(this,"maxEventsPortionToSend",100),O.default(this,"pendingEvents",new Map),O.default(this,"readyEvents",[]),O.default(this,"hasInitializationFinished",!1),O.default(this,"_canSendTelemetry",!1),this.config=e,this.packetInterface=n}return k.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){Y.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){Y.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&&Y.debug("Overwriting starting point for '".concat(n,"' event")),this.pendingEvents.set(n,t);else{if(!i)return void Y.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 Ve("[UNFINISHED] ".concat(i.title),i.details,i.start,null,i.type,i.id))}})),r}},{key:"merge",value:function(e,t){return new Ve(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 pe(t.map((function(e){return e.toTelemetryEvent()}))))}catch(e){Y.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 Ye(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=R.default(e);if(t){var i=R.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return T.default(this,n)}}var Qe=function e(){C.default(this,e)};O.default(Qe,"TWILSOCK_CONNECT","twilsock.sdk.connect"),O.default(Qe,"TWILSOCK_INIT","twilsock.sdk.init"),e.TwilsockClient=function(t){E.default(f,t);var n,r,i,o,a,s,u,c,l=Ye(f);function f(t,n,r){var i;C.default(this,f),i=l.call(this),O.default(_.default(i),"version",Q),O.default(_.default(i),"offlineStorageDeferred",new ze),r.continuationToken=r.continuationToken?r.continuationToken:Ke.getStoredToken(n);var o=i.config=new X(t,n,r);Y.setLevel(o.logLevel);var a=new Pe(o.url),s=new Ie(a,o);return i.channel=new Ce(a,s,o),i.registrations=new Le(s),i.upstream=new qe(s,i.channel,o),i.telemetryTracker=new He(o,s),i.channel.on("initialized",(function(){return i.telemetryTracker.canSendTelemetry=!0})),a.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 Ve("Establish WebSocket connection","",new Date),Qe.TWILSOCK_CONNECT,e.TelemetryPoint.Start)})),i.channel.on("connected",(function(){return i.telemetryTracker.addPartialEvent(new Ve("Establish WebSocket connection","",new Date,new Date),Qe.TWILSOCK_CONNECT,e.TelemetryPoint.End)})),i.channel.on("beforeSendInit",(function(){return i.telemetryTracker.addPartialEvent(new Ve("Send Twilsock init","",new Date),Qe.TWILSOCK_INIT,e.TelemetryPoint.Start)})),i.channel.on("initialized",(function(){return i.telemetryTracker.addPartialEvent(new Ve("Send Twilsock init","Succeeded",new Date,new Date),Qe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("sendInitFailed",(function(){return i.telemetryTracker.addPartialEvent(new Ve("Send Twilsock init","Failed",new Date,new Date),Qe.TWILSOCK_INIT,e.TelemetryPoint.End)})),i.channel.on("initialized",(function(e){i.handleStorageId(n,e),Ke.storeToken(e.continuationToken,n),setTimeout((function(){return i.emit("initialized",e)}),0)})),i.channel.on("disconnected",(function(){return setTimeout((function(){return i.emit("disconnected")}),0)})),i.channel.on("disconnected",(function(){return i.upstream.rejectPendingMessages()})),i.channel.on("disconnected",(function(){return i.offlineStorageDeferred.fail(new we("Client disconnected"))})),i.offlineStorageDeferred.promise.catch((function(){})),i}return k.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 Y.debug("Emitting ".concat(e.toString(),"(").concat(r.map((function(e){return JSON.stringify(e)})).join(", "),")")),(t=S.default(R.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(We.create(t.offlineStorage[e])),Y.debug("Offline storage for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage[e]),"."))}catch(n){this.offlineStorageDeferred.fail(new we("Failed to parse offline storage for ".concat(e," ").concat(JSON.stringify(t.offlineStorage[e]),". ").concat(n,".")))}else this.offlineStorageDeferred.fail(new we("No offline storage id for '".concat(e,"' product: ").concat(JSON.stringify(t.offlineStorage))));else this.offlineStorageDeferred.fail(new we("No offline storage id"))}},{key:"storageId",value:function(){return this.offlineStorageDeferred.promise}},{key:"isConnected",get:function(){return this.channel.isConnected}},{key:"state",get:function(){return this.channel.state}},{key:"updateToken",value:(c=x.default(I.default.mark((function e(t){return I.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Y.trace("updating token '".concat(t,"'")),this.config.token!==t){e.next=3;break}return e.abrupt("return");case 3:return this.config.updateToken(t),e.next=6,this.channel.updateToken(t);case 6:return e.abrupt("return",e.sent);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"setNotificationsContext",value:(u=x.default(I.default.mark((function e(t,n){return I.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:(s=x.default(I.default.mark((function e(t){return I.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 s.apply(this,arguments)})},{key:"connect",value:function(){return this.channel.connect()}},{key:"disconnect",value:(a=x.default(I.default.mark((function t(){return I.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 a.apply(this,arguments)})},{key:"get",value:(o=x.default(I.default.mark((function t(n,r,i){return I.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 o.apply(this,arguments)})},{key:"post",value:(i=x.default(I.default.mark((function t(n,r,i,o){return I.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,o);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n,r){return i.apply(this,arguments)})},{key:"put",value:(r=x.default(I.default.mark((function t(n,r,i,o){return I.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,o);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"delete",value:(n=x.default(I.default.mark((function t(n,r,i,o){return I.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,o);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)}))),function(e,t,r,i){return n.apply(this,arguments)})},{key:"addTelemetryEvent",value:function(e){this.telemetryTracker.addTelemetryEvent(e),this.telemetryTracker.sendTelemetryIfMinimalPortionCollected()}},{key:"addPartialTelemetryEvent",value:function(t,n,r){this.telemetryTracker.addPartialEvent(t,n,r),r===e.TelemetryPoint.End&&this.telemetryTracker.sendTelemetryIfMinimalPortionCollected()}}]),f}(D),e.TwilsockClient=function(e,t,n,r){var i,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":A.default(Reflect))&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(o<3?i(a):o>3?i(t,n,a):i(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([d.validateConstructorTypes(d.nonEmptyString,d.nonEmptyString,[d.pureObject,"undefined",d.literal(null)]),function(e,t){if("object"===("undefined"==typeof Reflect?"undefined":A.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[String,String,Object])],e.TwilsockClient);var Xe=function(){function e(t){C.default(this,e),this.product=t,this.type="ers",this.notification_protocol_version=0,this.message_types=[]}return k.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=Xe,e.TelemetryEventDescription=Ve,e.TelemetryTracker=He,e.TransportUnavailableError=Ue,e.Twilsock=e.TwilsockClient,e.TwilsockError=we}(qR);var aI=s,sI=a,uI=Un,cI=tn,lI=u,fI=Q,dI=b,pI=Object.assign,hI=Object.defineProperty,yI=!pI||sI((function(){if(aI&&1!==pI({b:1},pI(hI({},"a",{enumerable:!0,get:function(){hI(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!=pI({},e)[n]||uI(pI({},t)).join("")!=r}))?function(e,t){for(var n=fI(e),r=arguments.length,i=1,o=cI.f,a=lI.f;r>i;)for(var s,u=dI(arguments[i++]),c=o?uI(u).concat(o(u)):uI(u),l=c.length,f=0;l>f;)s=c[f++],aI&&!a.call(u,s)||(n[s]=u[s]);return n}:pI,vI=yI;function mI(e){return(mI="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)}Rn({target:"Object",stat:!0,forced:Object.assign!==vI},{assign:vI}),function(e){Object.defineProperty(e,"__esModule",{value:!0});var t=UR.exports,n=cy.exports,r=uy.exports,i=ly.exports,o=dy.exports,a=hy.exports,s=FR,u=$h.exports,c=qR,l=py.exports,f=Sv.exports,d=Zm,p=Xh.exports,h=iy.exports,y=xf.exports,v=ex,m=hh;function g(e){return e&&"object"===Ao(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),x=g(n),k=g(r),_=g(i),S=g(o),E=g(a),T=g(s),R=g(u),C=g(l),O=g(f),I=g(p),A=g(h),P=b(y),j=b(v);function L(e,t,n,r){var i,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":R.default(Reflect))&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(o<3?i(a):o>3?i(t,n,a):i(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}function M(e,t){if("object"===("undefined"==typeof Reflect?"undefined":R.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function N(){}function D(){D.init.call(this)}function U(e){return void 0===e._maxListeners?D.defaultMaxListeners:e._maxListeners}function F(e,t,n){if(t)e.call(n);else for(var r=e.length,i=K(e,r),o=0;o<r;++o)i[o].call(n)}function B(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,o=K(e,i),a=0;a<i;++a)o[a].call(n,r)}function q(e,t,n,r,i){if(t)e.call(n,r,i);else for(var o=e.length,a=K(e,o),s=0;s<o;++s)a[s].call(n,r,i)}function z(e,t,n,r,i,o){if(t)e.call(n,r,i,o);else for(var a=e.length,s=K(e,a),u=0;u<a;++u)s[u].call(n,r,i,o)}function W(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,o=K(e,i),a=0;a<i;++a)o[a].apply(n,r)}function G(e,t,n,r){var i,o,a,s;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]):(o=e._events=new N,e._eventsCount=0),a){if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),!a.warned&&(i=U(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,"function"==typeof console.warn?console.warn(s):console.log(s)}}else a=o[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 J(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function K(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}N.prototype=Object.create(null),D.EventEmitter=D,D.usingDomains=!1,D.prototype.domain=void 0,D.prototype._events=void 0,D.prototype._maxListeners=void 0,D.defaultMaxListeners=10,D.init=function(){this.domain=null,D.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new N,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},D.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},D.prototype.getMaxListeners=function(){return U(this)},D.prototype.emit=function(e){var t,n,r,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.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=a[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),o=1;o<r;o++)i[o-1]=arguments[o];W(n,l,this,i)}return!0},D.prototype.addListener=function(e,t){return G(this,e,t,!1)},D.prototype.on=D.prototype.addListener,D.prototype.prependListener=function(e,t){return G(this,e,t,!0)},D.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,$(this,e,t)),this},D.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,$(this,e,t)),this},D.prototype.removeListener=function(e,t){var n,r,i,o,a;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,o=n.length;o-- >0;)if(n[o]===t||n[o].listener&&n[o].listener===t){a=n[o].listener,i=o;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,a||t)}return this},D.prototype.off=function(e,t){return this.removeListener(e,t)},D.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new 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),o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&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},D.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},D.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):J.call(e,t)},D.prototype.listenerCount=J,D.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var V=P.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(){x.default(this,e)}return k.default(e,[{key:"setLevel",value:function(e){V.setLevel(e)}},{key:"trace",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];V.trace.apply(null,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];V.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];V.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];V.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];V.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=k.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;x.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(A.default(A.default(e).filter((function(e){return!t.has(e)}))),A.default(A.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 x.default(this,r),t=n.call(this),O.default(C.default(t),"desiredState",new X),O.default(C.default(t),"currentState",new X),O.default(C.default(t),"_hasActiveAttempt",!1),t.channelType=e,t}return k.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=w.default(T.default.mark((function e(){var t,n,r,i,o,a;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=I.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,(o=new X).token=this.desiredState.token,o.notificationId=this.desiredState.notificationId,o.messageTypes=new Set(this.desiredState.messageTypes),!(o.messageTypes.size>0)){e.next=24;break}return e.next=17,this.updateRegistration(o,i);case 17:a=e.sent,this.currentState.token=a.token,this.currentState.notificationId=a.notificationId,this.currentState.messageTypes=new Set(a.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=o.token,this.currentState.notificationId=o.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}(D);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(o,e);var t,n,r,i=te(o);function o(e,t,n,r){var a;return x.default(this,o),a=i.call(this,e),O.default(C.default(a),"registrationId",null),a.context=t,a.twilsock=n,a.registrarUrl=r,a}return k.default(o,[{key:"updateRegistration",value:(r=w.default(T.default.mark((function e(t,n){var r,i,o,a,s,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,o="".concat(this.registrarUrl,"?productId=").concat(i),a={"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(o,a,r,i)}));case 15:s=e.sent,this.registrationId=s.body.id,Y.debug("Registration created: ",s),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=w.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=w.default(T.default.mark((function e(t){var n,r,i,o,a=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"},o={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 a.twilsock.delete(r,i,o,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)})}]),o}(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 oe,ae=function(e){_.default(o,e);var t,n,r,i=ie(o);function o(e,t,n){var r;return x.default(this,o),r=i.call(this,"twilsock"),O.default(C.default(r),"contextId",j.v4()),r.productId=e,r.platform=t,r.twilsock=n,r}return k.default(o,[{key:"updateRegistration",value:(r=w.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=w.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=w.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)})}]),o}(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 S.default(this,n)}}var ue=m.literal("apn","fcm","twilsock");e.Notifications=oe=function(e){_.default(Client,e);var t,n,r,i=se(Client);function Client(e){var t,n,r,o,a,s,u,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x.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!==(o=l.notifications)&&void 0!==o?o:{},y=null!==(a=null!==(s=h.region)&&void 0!==s?s:l.region)&&void 0!==a?a:"us1",v="https://ers.".concat(y,".twilio.com/v1/registrations"),m=h.ersUrl||v;u.connectors=new Map;var g=oe._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 ae(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 k.default(Client,[{key:"shutdown",value:(r=w.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=w.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=w.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}(D),L([m.validateTypes(ue,m.nonEmptyString),M("design:type",Function),M("design:paramtypes",[String,String]),M("design:returntype",void 0)],e.Notifications.prototype,"setPushRegistrationId",null),L([m.validateTypes(ue,m.nonEmptyString),M("design:type",Function),M("design:paramtypes",[String,String]),M("design:returntype",void 0)],e.Notifications.prototype,"subscribe",null),L([m.validateTypes(ue,m.nonEmptyString),M("design:type",Function),M("design:paramtypes",[String,String]),M("design:returntype",void 0)],e.Notifications.prototype,"unsubscribe",null),L([m.validateTypes(m.nonEmptyString),M("design:type",Function),M("design:paramtypes",[String]),M("design:returntype",void 0)],e.Notifications.prototype,"updateToken",null),L([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=oe=L([m.validateConstructorTypes(m.nonEmptyString,[m.pureObject,"undefined",m.literal(null)]),M("design:paramtypes",[String,Object])],e.Notifications)}(DR);var gI={},bI={exports:{}};!function(e){function t(e,t,n,r,i,o,a){try{var s=e[o](a),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,o){var a=e.apply(n,r);function s(e){t(a,i,o,s,u,"next",e)}function u(e){t(a,i,o,s,u,"throw",e)}s(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports}(bI);var wI={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}(wI);var xI={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}(xI);var kI={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}(kI);var _I={exports:{}},SI={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}(SI),function(e){var t=SI.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}(_I);var EI={exports:{}},TI={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}(TI),function(e){var t=TI.exports.default,n=kI.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}(EI);var RI={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}(RI);var CI={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}(CI);var OI,II=Object.prototype,AI=II.hasOwnProperty,PI="function"==typeof Symbol?Symbol:{},jI=PI.iterator||"@@iterator",LI=PI.asyncIterator||"@@asyncIterator",MI=PI.toStringTag||"@@toStringTag";function NI(e,t,n,r){var i=t&&t.prototype instanceof WI?t:WI,o=Object.create(i.prototype),a=new nA(r||[]);return o._invoke=function(e,t,n){var r=UI;return function(i,o){if(r===BI)throw new Error("Generator is already running");if(r===qI){if("throw"===i)throw o;return iA()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var s=ZI(a,n);if(s){if(s===zI)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===UI)throw r=qI,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=BI;var u=DI(e,t,n);if("normal"===u.type){if(r=n.done?qI:FI,u.arg===zI)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=qI,n.method="throw",n.arg=u.arg)}}}(e,n,a),o}function DI(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}var UI="suspendedStart",FI="suspendedYield",BI="executing",qI="completed",zI={};function WI(){}function GI(){}function $I(){}var JI={};JI[jI]=function(){return this};var KI=Object.getPrototypeOf,VI=KI&&KI(KI(rA([])));VI&&VI!==II&&AI.call(VI,jI)&&(JI=VI);var HI=$I.prototype=WI.prototype=Object.create(JI);function YI(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function QI(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===GI||"GeneratorFunction"===(t.displayName||t.name))}function XI(e,t){function n(r,i,o,a){var s=DI(e[r],e,i);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"===mI(c)&&AI.call(c,"__await")?t.resolve(c.__await).then((function(e){n("next",e,o,a)}),(function(e){n("throw",e,o,a)})):t.resolve(c).then((function(e){u.value=e,o(u)}),(function(e){return n("throw",e,o,a)}))}a(s.arg)}var r;this._invoke=function(e,i){function o(){return new t((function(t,r){n(e,i,t,r)}))}return r=r?r.then(o,o):o()}}function ZI(e,t){var n=e.iterator[t.method];if(n===OI){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=OI,ZI(e,t),"throw"===t.method))return zI;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return zI}var r=DI(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,zI;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=OI),t.delegate=null,zI):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,zI)}function eA(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 tA(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function nA(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(eA,this),this.reset(!0)}function rA(e){if(e){var t=e[jI];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(AI.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=OI,t.done=!0,t};return r.next=r}}return{next:iA}}function iA(){return{value:OI,done:!0}}GI.prototype=HI.constructor=$I,$I.constructor=GI,$I[MI]=GI.displayName="GeneratorFunction",YI(XI.prototype),XI.prototype[LI]=function(){return this},YI(HI),HI[MI]="Generator",HI[jI]=function(){return this},HI.toString=function(){return"[object Generator]"},nA.prototype={constructor:nA,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=OI,this.done=!1,this.delegate=null,this.method="next",this.arg=OI,this.tryEntries.forEach(tA),!e)for(var t in this)"t"===t.charAt(0)&&AI.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=OI)},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 o.type="throw",o.arg=e,t.next=n,r&&(t.method="next",t.arg=OI),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],o=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=AI.call(i,"catchLoc"),s=AI.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){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&&AI.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 o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,zI):this.complete(o)},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),zI},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),tA(n),zI}},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;tA(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:rA(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=OI),zI}};var oA={wrap:NI,isGeneratorFunction:QI,AsyncIterator:XI,mark:function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,$I):(e.__proto__=$I,MI in e||(e[MI]="GeneratorFunction")),e.prototype=Object.create(HI),e},awrap:function(e){return{__await:e}},async:function(e,t,n,r,i){void 0===i&&(i=Promise);var o=new XI(NI(e,t,n,r),i);return QI(t)?o:o.next().then((function(e){return e.done?e.value:o.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:rA},aA=n(Object.freeze({__proto__:null,default:oA})),sA={},uA={exports:{}},cA={exports:{}};!function(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports}(cA);var lA={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,o=[],a=!0,s=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==n.return||n.return()}finally{if(s)throw i}}return o}},e.exports.__esModule=!0,e.exports.default=e.exports}(lA);var fA={exports:{}},dA={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}(dA),function(e){var t=dA.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}(fA);var pA={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}(pA),function(e){var t=cA.exports,n=lA.exports,r=fA.exports,i=pA.exports;e.exports=function(e,o){return t(e)||n(e,o)||r(e,o)||i()},e.exports.__esModule=!0,e.exports.default=e.exports}(uA);var hA={exports:{}},yA={exports:{}};!function(e){var t=dA.exports;e.exports=function(e){if(Array.isArray(e))return t(e)},e.exports.__esModule=!0,e.exports.default=e.exports}(yA);var vA={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}(vA);var mA={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}(mA),function(e){var t=yA.exports,n=vA.exports,r=fA.exports,i=mA.exports;e.exports=function(e){return t(e)||n(e)||r(e)||i()},e.exports.__esModule=!0,e.exports.default=e.exports}(hA),Object.defineProperty(sA,"__esModule",{value:!0});var gA=uA.exports,bA=hA.exports,wA=wI.exports,xA=_I.exports,kA=EI.exports,_A=RI.exports;function SA(e){return e&&"object"===mI(e)&&"default"in e?e:{default:e}}var EA=SA(TI.exports),TA=SA(gA),RA=SA(bA),CA=SA(wA),OA=SA(xA),IA=SA(kA),AA=SA(_A),PA=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return{checks:t}};function jA(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return LA(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return LA(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function LA(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var MA=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return PA((function(e){var n,r=!1,i=[],o=jA(t);try{for(o.s();!(n=o.n()).done;){var a=n.value;"string"!=typeof a?(r=r||e instanceof a,i.push("an instance of ".concat(a.name))):(r=r||EA.default(e)===a,i.push("of type ".concat(a)))}}catch(e){o.e(e)}finally{o.f()}return[r,i]}))};function NA(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return DA(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 DA(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function DA(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 UA=PA((function(e){return["string"==typeof e&&e.length>0,"a non-empty string"]})),FA=PA((function(e){return["number"==typeof e&&Number.isInteger(e)&&e>=0,"a non-negative integer"]})),BA=PA((function(e){return["object"===EA.default(e)&&null!==e&&!Array.isArray(e),"a pure object (non-null and non-array)"]}));function qA(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.default(e);if(t){var i=AA.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return IA.default(this,n)}}function zA(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 WA(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 WA(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function WA(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 GA=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=zA(t.entries());try{for(r.s();!(n=r.n()).done;){var i=TA.default(n.value,2),o=i[0],a=i[1],s=VA(e[o],a),u=TA.default(s,4),c=u[0],l=u[1],f=u[2],d=u[3];if(!c)throw new Error("Argument ".concat(o+1," is expected to be ").concat(f).concat(d," but got ").concat(l))}}catch(e){r.e(e)}finally{r.f()}},$A=function(e){var t,n,r;(["undefined","boolean","number","bigint","string"].includes(EA.default(e))&&(n="string"==typeof e?'"'.concat(e,'"'):"".concat(e)),"object"===EA.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=EA.default(e)),n},JA=function(e){var t,n=[],r=zA(e);try{for(r.s();!(t=r.n()).done;){var i=t.value;n.push(KA(i))}}catch(e){r.e(e)}finally{r.f()}return n},KA=function(e){var t,n=[],r=zA(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(MA(i))}}catch(e){r.e(e)}finally{r.f()}return n},VA=function(e,t){var n,r,i=[],o=!1,a=zA(e);try{for(a.s();!(r=a.n()).done;){var s,u=zA(r.value.checks);try{for(u.s();!(s=u.n()).done;){var c=(0,s.value)(t),l=TA.default(c,3),f=l[0],d=l[1],p=l[2];o=o||f,!n&&p&&(n=p),d&&(i=[].concat(RA.default(i),"string"==typeof d?[d]:RA.default(d)))}}catch(e){u.e(e)}finally{u.f()}}}catch(e){a.e(e)}finally{a.f()}if(o)return[!0];var h=n||$A(t),y=i.length-1;return[!1,h,y>0?"".concat(i.slice(0,y).join(", ")," or ").concat(i[y]):i.join(", "),y>1?";":","]};function HA(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 YA(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 YA(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function YA(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}sA.array=function(e,t){return PA((function(n){if(!Array.isArray(n))return[!1,"an array of ".concat(e)];var r,i=HA(n.entries());try{for(i.s();!(r=i.n()).done;){var o=TA.default(r.value,2),a=o[0],s=o[1],u=VA(KA(t),s),c=TA.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"a valid array of ".concat(e," (index ").concat(a," should be ").concat(d,")"),"malformed array of ".concat(e," (index ").concat(a," is ").concat(f,")")]}}catch(e){i.e(e)}finally{i.f()}return[!0]}))},sA.custom=PA,sA.literal=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return PA((function(e){var n,r=!1,i=[],o=NA(t);try{for(o.s();!(n=o.n()).done;){var a=n.value;r=r||e===a,i.push("string"==typeof a?'"'.concat(a,'"'):"".concat(a))}}catch(e){o.e(e)}finally{o.f()}return[r,i]}))},sA.nonEmptyString=UA,sA.nonNegativeInteger=FA,sA.objectSchema=function(e,t){return PA((function(n){if("object"!==EA.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 o=TA.default(i[r],2),a=o[0],s=o[1],u=VA(KA(s),n[a]),c=TA.default(u,3),l=c[0],f=c[1],d=c[2];if(!l)return[!1,"valid ".concat(e,' (key "').concat(a,'" should be ').concat(d,")"),"malformed ".concat(e,' (key "').concat(a,'" is ').concat(f,")")]}return[!0]}))},sA.pureObject=BA,sA.runtimeTypeValidation=GA,sA.stringifyReceivedType=$A,sA.type=MA,sA.validateConstructorTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=JA(t);return function(e){return function(e){OA.default(n,e);var t=qA(n);function n(){CA.default(this,n);for(var e=arguments.length,i=new Array(e),o=0;o<e;o++)i[o]=arguments[o];return GA(r,i),t.call.apply(t,[this].concat(i))}return n}(e)}},sA.validateTypes=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=JA(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 GA(r,t),i.apply(this,t)}}},sA.validateTypesAsync=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=JA(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{GA(r,t)}catch(e){return Promise.reject(e)}return i.apply(this,t)}}};var QA={exports:{}},XA={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}(XA);var ZA={exports:{}},eP={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}(eP),function(e){var t=SI.exports,n=eP.exports;function r(i,o,a){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 o=new(Function.bind.apply(e,i));return r&&t(o,r.prototype),o},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}(ZA),function(e){var t=RI.exports,n=SI.exports,r=XA.exports,i=ZA.exports;function o(a){var s="function"==typeof Map?new Map:void 0;return e.exports=o=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,o)}function o(){return i(e,arguments,t(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,e)},e.exports.__esModule=!0,e.exports.default=e.exports,o(a)}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports}(QA);var tP={exports:{}};!function(e){!function(t,n){e.exports?e.exports=n():t.log=n()}(t,(function(){var e=function(){},t="undefined",n=("undefined"==typeof window?"undefined":mI(window))!==t&&mI(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 o(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function a(r){return"debug"===r&&(r="log"),("undefined"==typeof console?"undefined":mI(console))!==t&&("trace"===r&&n?o: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 o=r[i];this[o]=i<t?e:this.methodFactory(o,t,n)}this.log=this.debug}function u(e,n,r){return function(){("undefined"==typeof console?"undefined":mI(console))!==t&&(s.call(this,n,r),this[e].apply(this,arguments))}}function c(e,t,n){return a(e)||u.apply(this,arguments)}function l(e,n,i){var o,a=this,u="loglevel";function l(){var e;if(("undefined"==typeof window?"undefined":mI(window))!==t&&u){try{e=window.localStorage[u]}catch(e){}if(mI(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===a.levels[e]&&(e=void 0),e}}"string"==typeof e?u+=":"+e:"symbol"===mI(e)&&(u=void 0),a.name=e,a.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},a.methodFactory=i||c,a.getLevel=function(){return o},a.setLevel=function(n,i){if("string"==typeof n&&void 0!==a.levels[n.toUpperCase()]&&(n=a.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=a.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(o=n,!1!==i&&function(e){var n=(r[e]||"silent").toUpperCase();if(("undefined"==typeof window?"undefined":mI(window))!==t&&u){try{return void(window.localStorage[u]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(u)+"="+n+";"}catch(e){}}}(n),s.call(a,n,e),("undefined"==typeof console?"undefined":mI(console))===t&&n<a.levels.SILENT)return"No console available for logging"},a.setDefaultLevel=function(e){l()||a.setLevel(e,!1)},a.enableAll=function(e){a.setLevel(a.levels.TRACE,e)},a.disableAll=function(e){a.setLevel(a.levels.SILENT,e)};var f=l();null==f&&(f=null==n?"WARN":n),a.setLevel(f,!1)}var f=new l,d={};f.getLogger=function(e){if("symbol"!==mI(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":mI(window))!==t?window.log:void 0;return f.noConflict=function(){return("undefined"==typeof window?"undefined":mI(window))!==t&&window.log===f&&(window.log=p),f},f.getLoggers=function(){return d},f.default=f,f}))}(tP);var nP={};Object.defineProperty(nP,"__esModule",{value:!0});var rP=xI.exports,iP=kI.exports,oP=_I.exports,aP=EI.exports,sP=RI.exports,uP=CI.exports;function cP(e){return e&&"object"===mI(e)&&"default"in e?e:{default:e}}var lP=cP(wI.exports),fP=cP(rP),dP=cP(iP),pP=cP(oP),hP=cP(aP),yP=cP(sP),vP=cP(uP);function mP(){}function gP(){gP.init.call(this)}function bP(e){return void 0===e._maxListeners?gP.defaultMaxListeners:e._maxListeners}function wP(e,t,n){if(t)e.call(n);else for(var r=e.length,i=CP(e,r),o=0;o<r;++o)i[o].call(n)}function xP(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,o=CP(e,i),a=0;a<i;++a)o[a].call(n,r)}function kP(e,t,n,r,i){if(t)e.call(n,r,i);else for(var o=e.length,a=CP(e,o),s=0;s<o;++s)a[s].call(n,r,i)}function _P(e,t,n,r,i,o){if(t)e.call(n,r,i,o);else for(var a=e.length,s=CP(e,a),u=0;u<a;++u)s[u].call(n,r,i,o)}function SP(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,o=CP(e,i),a=0;a<i;++a)o[a].apply(n,r)}function EP(e,t,n,r){var i,o,a,s;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]):(o=e._events=new mP,e._eventsCount=0),a){if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),!a.warned&&(i=bP(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,"function"==typeof console.warn?console.warn(s):console.log(s)}}else a=o[t]=n,++e._eventsCount;return e}function TP(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 RP(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 CP(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}function OP(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=yP.default(e);if(t){var i=yP.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return hP.default(this,n)}}mP.prototype=Object.create(null),gP.EventEmitter=gP,gP.usingDomains=!1,gP.prototype.domain=void 0,gP.prototype._events=void 0,gP.prototype._maxListeners=void 0,gP.defaultMaxListeners=10,gP.init=function(){this.domain=null,gP.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new mP,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},gP.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},gP.prototype.getMaxListeners=function(){return bP(this)},gP.prototype.emit=function(e){var t,n,r,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.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=a[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:wP(n,l,this);break;case 2:xP(n,l,this,arguments[1]);break;case 3:kP(n,l,this,arguments[1],arguments[2]);break;case 4:_P(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),o=1;o<r;o++)i[o-1]=arguments[o];SP(n,l,this,i)}return!0},gP.prototype.addListener=function(e,t){return EP(this,e,t,!1)},gP.prototype.on=gP.prototype.addListener,gP.prototype.prependListener=function(e,t){return EP(this,e,t,!0)},gP.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,TP(this,e,t)),this},gP.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,TP(this,e,t)),this},gP.prototype.removeListener=function(e,t){var n,r,i,o,a;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 mP:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length;o-- >0;)if(n[o]===t||n[o].listener&&n[o].listener===t){a=n[o].listener,i=o;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new mP,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,a||t)}return this},gP.prototype.off=function(e,t){return this.removeListener(e,t)},gP.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new mP,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new mP:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new mP,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},gP.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):[]},gP.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):RP.call(e,t)},gP.prototype.listenerCount=RP,gP.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var IP=function(e){pP.default(n,e);var t=OP(n);function n(e){var r;return lP.default(this,n),r=t.call(this),vP.default(dP.default(r),"timeout",null),vP.default(dP.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 fP.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}(gP),AP=function(e){pP.default(n,e);var t=OP(n);function n(e){var r;return lP.default(this,n),r=t.call(this),vP.default(dP.default(r),"resolve",(function(){})),vP.default(dP.default(r),"reject",(function(){})),r.retrier=new IP(e),r}return fP.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}(gP);function PP(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=yP.default(e);if(t){var i=yP.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return hP.default(this,n)}}function jP(e){return null!=e}var LP=function(e){pP.default(n,e);var t=PP(n);function n(e){var r;lP.default(this,n),r=t.call(this),vP.default(dP.default(r),"backoffDelay",0),vP.default(dP.default(r),"nextBackoffDelay",0),vP.default(dP.default(r),"backoffNumber",0),vP.default(dP.default(r),"timeoutID",null),vP.default(dP.default(r),"maxNumberOfRetry",-1);var i=e=e||{},o=i.initialDelay,a=i.maxDelay,s=i.randomisationFactor,u=i.factor;if(jP(o)&&o<1)throw new Error("The initial timeout must be equal to or greater than 1.");if(jP(a)&&a<=1)throw new Error("The maximal timeout must be greater than 1.");if(jP(s)&&(s<0||s>1))throw new Error("The randomisation factor must be between 0 and 1.");if(jP(u)&&u<=1)throw new Error("Exponential factor should be greater than 1.");if(r.initialDelay=o||100,r.maxDelay=a||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 fP.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}(gP);nP.AsyncRetrier=AP,nP.Backoff=LP,nP.Retrier=IP;var MP={exports:{}},NP={exports:{}};!function(e){var t=RI.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}(NP),function(e){var t=NP.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 o=Object.getOwnPropertyDescriptor(i,n);return o.get?o.get.call(arguments.length<3?e:r):o.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}(MP),Object.defineProperty(gI,"__esModule",{value:!0});var DP=wI.exports,UP=xI.exports,FP=kI.exports,BP=_I.exports,qP=EI.exports,zP=RI.exports,WP=CI.exports,GP=aA,$P=TI.exports,JP=sA,KP=Fg,VP=QA.exports,HP=tP.exports,YP=uA.exports,QP=nP,XP=ex,ZP=MP.exports,ej=dR.exports;function tj(e){return e&&"object"===mI(e)&&"default"in e?e:{default:e}}function nj(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 rj=tj(bI.exports),ij=tj(DP),oj=tj(UP),aj=tj(FP),sj=tj(BP),uj=tj(qP),cj=tj(zP),lj=tj(WP),fj=tj(GP),dj=tj($P),pj=tj(VP),hj=nj(HP),yj=tj(YP),vj=nj(XP),mj=tj(ZP),gj=nj(ej);function bj(e,t,n,r){var i,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":dj.default(Reflect))&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(o<3?i(a):o>3?i(t,n,a):i(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}function wj(e,t){if("object"===("undefined"==typeof Reflect?"undefined":dj.default(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function xj(){}function kj(){kj.init.call(this)}function _j(e){return void 0===e._maxListeners?kj.defaultMaxListeners:e._maxListeners}function Sj(e,t,n){if(t)e.call(n);else for(var r=e.length,i=Pj(e,r),o=0;o<r;++o)i[o].call(n)}function Ej(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,o=Pj(e,i),a=0;a<i;++a)o[a].call(n,r)}function Tj(e,t,n,r,i){if(t)e.call(n,r,i);else for(var o=e.length,a=Pj(e,o),s=0;s<o;++s)a[s].call(n,r,i)}function Rj(e,t,n,r,i,o){if(t)e.call(n,r,i,o);else for(var a=e.length,s=Pj(e,a),u=0;u<a;++u)s[u].call(n,r,i,o)}function Cj(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,o=Pj(e,i),a=0;a<i;++a)o[a].apply(n,r)}function Oj(e,t,n,r){var i,o,a,s;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((o=e._events)?(o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),a=o[t]):(o=e._events=new xj,e._eventsCount=0),a){if("function"==typeof a?a=o[t]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),!a.warned&&(i=_j(e))&&i>0&&a.length>i){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,"function"==typeof console.warn?console.warn(s):console.log(s)}}else a=o[t]=n,++e._eventsCount;return e}function Ij(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 Aj(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 Pj(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}xj.prototype=Object.create(null),kj.EventEmitter=kj,kj.usingDomains=!1,kj.prototype.domain=void 0,kj.prototype._events=void 0,kj.prototype._maxListeners=void 0,kj.defaultMaxListeners=10,kj.init=function(){this.domain=null,kj.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new xj,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},kj.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},kj.prototype.getMaxListeners=function(){return _j(this)},kj.prototype.emit=function(e){var t,n,r,i,o,a,s,u="error"===e;if(a=this._events)u=u&&null==a.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=a[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:Sj(n,l,this);break;case 2:Ej(n,l,this,arguments[1]);break;case 3:Tj(n,l,this,arguments[1],arguments[2]);break;case 4:Rj(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),o=1;o<r;o++)i[o-1]=arguments[o];Cj(n,l,this,i)}return!0},kj.prototype.addListener=function(e,t){return Oj(this,e,t,!1)},kj.prototype.on=kj.prototype.addListener,kj.prototype.prependListener=function(e,t){return Oj(this,e,t,!0)},kj.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,Ij(this,e,t)),this},kj.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,Ij(this,e,t)),this},kj.prototype.removeListener=function(e,t){var n,r,i,o,a;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 xj:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length;o-- >0;)if(n[o]===t||n[o].listener&&n[o].listener===t){a=n[o].listener,i=o;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new xj,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,a||t)}return this},kj.prototype.off=function(e,t){return this.removeListener(e,t)},kj.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new xj,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new xj:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),o=0;o<i.length;++o)"removeListener"!==(r=i[o])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new xj,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},kj.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):[]},kj.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):Aj.call(e,t)},kj.prototype.listenerCount=Aj,kj.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var jj=function(){function e(t){ij.default(this,e),this.base=t,this.args=new Array,this.paths=new Array}return oj.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 Lj(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=cj.default(e);if(t){var i=cj.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return uj.default(this,n)}}var Mj=function(e){sj.default(n,e);var t=Lj(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return ij.default(this,n),(r=t.call(this)).name=r.constructor.name,r.message="".concat(e," (status: ").concat(i,", code: ").concat(o,")"),r.status=i,r.code=o,r}return n}(pj.default(Error)),Nj=function(e){sj.default(n,e);var t=Lj(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,a=arguments.length>3?arguments[3]:void 0;return ij.default(this,n),(r=t.call(this,e,i,o)).body=a,r}return n}(Mj);function Dj(e){return JSON.parse(JSON.stringify(e))}function Uj(e){if(!(void 0===e||Fj(e)))throw new Mj("Invalid pageSize parameter. Expected a positive integer, was '".concat(e,"'."),400,20007)}function Fj(e){return function(e){return!isNaN(parseInt(e))&&isFinite(e)}(e)&&e>0}var Bj=hj.getLogger("twilio-sync");function qj(e,t){return["".concat((new Date).toISOString()," Sync ").concat(e,":")].concat(Array.from(t))}var zj=function(e){Bj.setLevel(e)},Wj=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];Bj.trace.apply(null,qj("T",t))},Gj=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];Bj.debug.apply(null,qj("D",t))},$j=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];Bj.warn.apply(null,qj("W",t))},Jj=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];Bj.error.apply(null,qj("E",t))},Kj="/v4/Subscriptions",Vj="/v3/Maps",Hj="/v3/Lists",Yj="/v3/Documents",Qj="/v3/Streams",Xj="/v3/Insights";function Zj(e,t,n){return e&&void 0!==e[t]?e[t]:n}var eL=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};ij.default(this,e);var n=t.region||"us1",r="https://cds.".concat(n,".twilio.com"),i=t.cdsUri||r;this.settings={subscriptionsUri:i+Kj,documentsUri:i+Yj,listsUri:i+Hj,mapsUri:i+Vj,streamsUri:i+Qj,insightsUri:i+Xj,sessionStorageEnabled:Zj(t.Sync,"enableSessionStorage",!0),productId:t.productId}}return oj.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 tL(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 nL(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 nL(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function nL(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 rL=function(){function e(t){ij.default(this,e),this.localObject=t,this.pendingCorrelationId=null,this.pendingAction=null,this.established=!1,this.retryCount=0}return oj.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 Mj("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}(),iL=function(){function e(t){var n=this;ij.default(this,e),lj.default(this,"isConnected",!1),lj.default(this,"maxBatchSize",100),lj.default(this,"subscriptionTtlTimer",null),lj.default(this,"pendingPokeReason",null),this.services=t,this.subscriptions=new Map,this.persisted=new Map,this.latestPokeResponseArrivalTimestampByCorrelationId=new Map;this.backoff=QP.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(),Gj("All subscriptions resolved."))}))}var t;return oj.default(e,[{key:"getSubscriptionUpdateBatch",value:function(){function e(e,t,n,r){var i,o=[],a=tL(e);try{for(a.s();!(i=a.n()).done;){var s=yj.default(i.value,2),u=s[0],c=s[1];if(!t.get(u)&&n!==c.pendingAction&&!c.rejectedWithError&&(o.push(c),r&&o.length>=r))break}}catch(e){a.e(e)}finally{a.f()}return o}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=rj.default(fj.default.mark((function e(t,n){var r,i,o,a,s,u,c,l,f,d,p,h,y=this;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isConnected){e.next=4;break}return Gj("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=tL(n);try{for(i.s();!(o=i.n()).done;)a=o.value,this.recordActionAttemptOn(a,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 y.onSubscriptionTtlElapsed()}),1e3*l))),"establish"===t&&(f=u.body.estimated_delivery_in_ms,!isNaN(parseFloat(f))&&isFinite(f)&&f>0?setTimeout((function(){return y.verifyPokeDelivery(r,f,n)}),f):Jj("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=tL(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 KP.TransportUnavailableError?(Gj("Twilsock connection (required for subscription) not ready (c:".concat(r,"); waiting…")),this.backoff.reset()):(Gj("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),o=i?(new Date).getTime()-i:t;o>=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-o)}},{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}})),o=r.filter((function(e){return e.retryCount>0})).length;Gj("Attempting '".concat(e,"' request (c:").concat(t,"):"),i);var a={event_protocol_version:4,action:e,correlation_id:t,retried_requests:o,ttl_in_s:-1,requests:i};return"ttl"===n&&(a.reason=n),this.services.network.post(this.services.config.subscriptionsUri,a)}},{key:"add",value:function(e,t){Gj("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 rL(t)),this.persist())}},{key:"remove",value:function(e){Gj("Establishing intent to unsubscribe from ".concat(e)),this.subscriptions.delete(e)&&this.persist()}},{key:"acceptMessage",value:function(e,t){Wj("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 o,a=tL(r);try{for(a.s();!(o=a.n()).done;){var s=o.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:Gj("Dropping unknown message type ".concat(n))}}}catch(e){a.e(e)}finally{a.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?(Gj("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&&(Gj("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()):Gj("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)):Gj("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&&(Jj("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 o=this.subscriptions.get(e);o?(t.type=n,o.update(t,r)):Gj("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){Gj("Triggering event replay for all subscriptions, reason=".concat(e)),this.pendingPokeReason=e,this.subscriptionTtlTimer&&(clearTimeout(this.subscriptionTtlTimer),this.subscriptionTtlTimer=null);var t,n=[],r=tL(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 o=0,a=n;o<a.length;o++){var s=a[o];this.persisted.set(s.sid,s)}this.persist()}},{key:"shutdown",value:function(){this.backoff.reset(),this.subscriptions.clear()}}]),e}();function oL(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 aL(e){return e.body?e.body.code:0}function sL(e){return 409===e.status?new Nj(oL(e),e.status,aL(e),e.body):e.status?new Mj(oL(e),e.status,aL(e)):e instanceof KP.TransportUnavailableError?e:new Mj(e.message,0,0)}var uL=function(){function e(t,n,r){ij.default(this,e),this.clientInfo=t,this.config=n,this.transport=r}return oj.default(e,[{key:"createHeaders",value:function(){return{"Content-Type":"application/json","Twilio-Sync-Client-Info":JSON.stringify(this.clientInfo),"Twilio-Request-Id":"RQ"+vj.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 o=[502,503,504];n&&o.push(429);var a=new QP.Retrier(t.backoffConfig());a.on("attempt",(function(){e().then((function(e){return a.succeeded(e)})).catch((function(e){if(o.includes(e.status)){var t=parseInt(e.headers?e.headers["Retry-After"]:null);a.failed(sL(e),isNaN(t)?null:1e3*t)}else"Twilsock disconnected"===e.message?a.failed(sL(e)):(a.removeAllListeners(),a.cancel(),i(sL(e)))}))})),a.on("succeeded",(function(e){r(e)})),a.on("cancelled",(function(e){return i(sL(e))})),a.on("failed",(function(e){return i(sL(e))})),a.start()}))}},{key:"get",value:function(e){var t=this,n=this.createHeaders();return Gj("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],o=this.createHeaders();return null!=n&&(o["If-Match"]=n),Gj("POST",e,"ID:",o["Twilio-Request-Id"]),this.executeWithRetry((function(){return r.transport.post(e,o,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),Gj("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 Gj("DELETE",e,"ID:",n["Twilio-Request-Id"]),this.executeWithRetry((function(){return t.transport.delete(e,n,t.config.productId)}),!1)}}]),e}(),cL=function(){function e(t,n){ij.default(this,e),this.config=t,this.storageId=null;try{this.storage=n||sessionStorage}catch(e){}}return oj.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 lL(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 fL(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 fL(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function fL(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 dL=function(){function e(t,n){ij.default(this,e),this.services=t,this.removalHandler=n,this.subscriptionState="none",this._attachedListeners=new Map}return oj.default(e,[{key:"_advanceLastEventId",value:function(e,t){}},{key:"reportFailure",value:function(e){404===e.status?this.onRemoved(!1):this.broadcastEventToListeners("failure",e)}},{key:"_subscribe",value:function(){this.services.router._subscribe(this.sid,this)}},{key:"_unsubscribe",value:function(){this.services.router._unsubscribe(this.sid)}},{key:"_setSubscriptionState",value:function(e){this.subscriptionState=e,this.broadcastEventToListeners("_subscriptionStateChanged",e)}},{key:"close",value:function(){this._unsubscribe(),null!=this.removalHandler&&this.removalHandler(this.type,this.sid,this.uniqueName)}},{key:"attach",value:function(e){var t=e.listenerUuid;this._attachedListeners.get(t)||(this._attachedListeners.size||this._subscribe(),this._attachedListeners.set(t,e))}},{key:"detach",value:function(e){this._attachedListeners.delete(e),this._attachedListeners.size||this.close()}},{key:"broadcastEventToListeners",value:function(e,t){var n,r=lL(this._attachedListeners.values());try{for(r.s();!(n=r.n()).done;){n.value.emit(e,t)}}catch(e){r.e(e)}finally{r.f()}}}]),e}(),pL=function(){function e(t){ij.default(this,e),lj.default(this,"queuedRequests",[]),lj.default(this,"isRequestInFlight",!1),this.inputMergingFunction=t}return oj.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}(),hL=function(){function e(t){ij.default(this,e),lj.default(this,"queueByNamespaceKey",new Map),this.inputReducer=t}var t,n,r;return oj.default(e,[{key:"add",value:(r=rj.default(fj.default.mark((function e(t,n,r){return fj.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=rj.default(fj.default.mark((function e(t,n,r){return fj.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=rj.default(fj.default.mark((function e(t,n){var r,i;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.queueByNamespaceKey.has(t)||this.queueByNamespaceKey.set(t,new pL(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 yL(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=cj.default(e);if(t){var i=cj.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return uj.default(this,n)}}var vL=function(e){sj.default(n,e);var t=yL(n);function n(){var e;return ij.default(this,n),(e=t.call(this)).closed=!1,e.uuid=XP.v4(),e}return oj.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}(kj);function mL(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=cj.default(e);if(t){var i=cj.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return uj.default(this,n)}}var gL=function(e){sj.default(f,e);var t,n,r,i,o,a,s,u,c,l=mL(f);function f(e,t,n){var r;ij.default(this,f),r=l.call(this,e,n),lj.default(aj.default(r),"isDeleted",!1);return r.updateMergingQueue=new pL((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 oj.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){Wj("Document update skipped, current:",this.lastEventId,", remote:",e.id);break}var t=void 0!==this.descriptor.data?Dj(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=rj.default(fj.default.mark((function e(t,n){var r,i=this;return fj.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=rj.default(fj.default.mark((function e(t,n){var r,i=this;return fj.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=rj.default(fj.default.mark((function e(t,n){return fj.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:(a=rj.default(fj.default.mark((function e(t){var n;return fj.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 a.apply(this,arguments)})},{key:"_setUnconditionally",value:(o=rj.default(fj.default.mark((function e(t,n){var r;return fj.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 o.apply(this,arguments)})},{key:"_setWithIfMatch",value:(i=rj.default(fj.default.mark((function e(t,n){var r,i,o;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(r=t(Dj(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 o=e.sent,this._handleSuccessfulUpdateResult(o),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?Dj(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=rj.default(fj.default.mark((function e(t){var n,r,i;return fj.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 Mj("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=rj.default(fj.default.mark((function e(){var t=this;return fj.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):Jj("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?Dj(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=rj.default(fj.default.mark((function e(){return fj.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 Mj("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}(dL),bL=function(e){sj.default(s,e);var t,n,r,i,o,a=mL(s);function s(e){var t;return ij.default(this,s),(t=a.call(this)).syncDocumentImpl=e,t.syncDocumentImpl.attach(aj.default(t)),t}return oj.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 gL.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:(o=rj.default(fj.default.mark((function e(t,n){return fj.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 o.apply(this,arguments)})},{key:"mutate",value:(i=rj.default(fj.default.mark((function e(t,n){return fj.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=rj.default(fj.default.mark((function e(t,n){return fj.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=rj.default(fj.default.mark((function e(t){return fj.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=rj.default(fj.default.mark((function e(){return fj.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(){mj.default(cj.default(s.prototype),"close",this).call(this),this.syncDocumentImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return gL.type}}]),s}(vL);lj.default(bL,"removed","removed"),lj.default(bL,"updated","updated"),bj([JP.validateTypesAsync(JP.pureObject,["undefined",JP.objectSchema("document metadata",{ttl:[JP.nonNegativeInteger,"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Object,Object]),wj("design:returntype",Promise)],bL.prototype,"set",null),bj([JP.validateTypesAsync("function",["undefined",JP.objectSchema("document metadata",{ttl:[JP.nonNegativeInteger,"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Function,Object]),wj("design:returntype",Promise)],bL.prototype,"mutate",null),bj([JP.validateTypesAsync(JP.pureObject,["undefined",JP.objectSchema("document metadata",{ttl:[JP.nonNegativeInteger,"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Object,Object]),wj("design:returntype",Promise)],bL.prototype,"update",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger),wj("design:type",Function),wj("design:paramtypes",[Number]),wj("design:returntype",Promise)],bL.prototype,"setTtl",null);var wL=function(){function e(t){ij.default(this,e),this.descriptor=t}return oj.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){ij.default(this,Paginator),this.prevToken=n,this.nextToken=r,this.items=e,this.source=t}var e,t;return oj.default(Paginator,[{key:"hasNextPage",get:function(){return!!this.nextToken}},{key:"hasPrevPage",get:function(){return!!this.prevToken}},{key:"nextPage",value:(t=rj.default(fj.default.mark((function e(){return fj.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=rj.default(fj.default.mark((function e(){return fj.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 xL(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}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 _L=function(){function e(t,n){ij.default(this,e),this.balanceFactor=0,this.key=t,this.value=n,this.parent=null,this.left=null,this.right=null}return oj.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}(),SL=function(){function e(t,n){ij.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 oj.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 _L(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,o=i.balanceFactor;if(r.isLeftChild?i.balanceFactor++:i.balanceFactor--,Math.abs(i.balanceFactor)<Math.abs(o))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 o=r||i;n||o?n&&!o?this.root=o:(n.replace(t,null),this.rebalance(n)):this.root=null}else{for(var a=t.left;a.right;)a=a.right;if(t.left===a)t.isRoot?(this.root=a,a.parent=null):(t.isLeftChild?t.parent.left=a:t.parent.right=a,a.parent=t.parent),a.right=t.right,a.right.parent=a,a.balanceFactor=t.balanceFactor,t={parent:a,isLeftChild:!0};else{var s=a.parent,u=a.left;s.right=u,u&&(u.parent=s),t.isRoot?(this.root=a,a.parent=null):(t.isLeftChild?t.parent.left=a:t.parent.right=a,a.parent=t.parent),a.right=t.right,a.right.parent=a,a.left=t.left,a.left.parent=a,a.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:Symbol.iterator,value:fj.default.mark((function e(){var t,n,r;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=xL(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:fj.default.mark((function e(){var t,n,r,i=arguments;return fj.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:fj.default.mark((function e(){var t,n,r,i=arguments;return fj.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 EL(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 TL(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 TL(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function TL(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 RL=function(){function e(t,n){ij.default(this,e),this.value=t,this.revision=n||0}return oj.default(e,[{key:"isValid",get:function(){return!0}}]),e}(),CL=function(){function e(t){ij.default(this,e),this.revision=t}return oj.default(e,[{key:"isValid",get:function(){return!1}}]),e}(),OL=function(){function e(){ij.default(this,e),this.items=new SL}return oj.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 RL(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 CL(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=EL(this.items);try{for(n.s();!(t=n.n()).done;){var r=yj.default(t.value,2),i=r[0],o=r[1];o.isValid&&e(i,o.value)}}catch(e){n.e(e)}finally{n.f()}}}}]),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=cj.default(e);if(t){var i=cj.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return uj.default(this,n)}}var AL=function(e){sj.default(v,e);var t,n,r,i,o,a,s,u,c,l,f,d,p,h,y=IL(v);function v(e,t,n){var r;ij.default(this,v);return(r=y.call(this,e,n)).updateMergingQueue=new hL((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new OL,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),r}return oj.default(v,[{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"links",get:function(){return this.descriptor.links}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"list"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"_addOrUpdateItemOnServer",value:(h=rj.default(fj.default.mark((function e(t,n,r,i){var o,a;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o={data:n},void 0!==i&&(o.ttl=i),e.next=4,this.services.network.post(t,o,r);case 4:return(a=e.sent).body.data=n,a.body.date_updated=new Date(a.body.date_updated),e.abrupt("return",a.body);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n,r){return h.apply(this,arguments)})},{key:"push",value:(p=rj.default(fj.default.mark((function e(t,n){var r,i,o;return fj.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,o=Number(i.index),this._handleItemMutated(o,i.url,i.last_event_id,i.revision,t,i.date_updated,i.date_expires,!0,!1),e.abrupt("return",this.cache.get(o));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return p.apply(this,arguments)})},{key:"set",value:(d=rj.default(fj.default.mark((function e(t,n,r){var i,o=this;return fj.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 o._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=rj.default(fj.default.mark((function e(t,n,r){var i,o;return fj.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 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 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"_updateItemWithIfMatch",value:(l=rj.default(fj.default.mark((function e(t,n,r){var i,o,a,s;return fj.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,!(o=n(Dj(i.data)))){e.next=25;break}return a=i.revision,e.prev=6,e.next=9,this._addOrUpdateItemOnServer(i.uri,o,a,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=rj.default(fj.default.mark((function e(t,n,r){var i,o=this;return fj.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 o._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=rj.default(fj.default.mark((function e(t,n,r){return fj.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=rj.default(fj.default.mark((function e(t){var n,r,i;return fj.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=Dj(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=rj.default(fj.default.mark((function e(t){var n;return fj.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:(a=rj.default(fj.default.mark((function e(t){var n;return fj.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 Mj("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 a.apply(this,arguments)})},{key:"queryItems",value:function(){var e=rj.default(fj.default.mark((function e(t){var n,r,i,o,a=this;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new jj(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),a.cache.get(e.index)?a._handleItemMutated(e.index,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):a.cache.store(Number(e.index),new wL({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),a.cache.get(e.index)})),o=r.body.meta,e.abrupt("return",new Paginator(i,(function(e){return a.queryItems({pageToken:e})}),o.previous_token,o.next_token));case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"getItems",value:(o=rj.default(fj.default.mark((function e(t){return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Uj((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 o.apply(this,arguments)})},{key:"getContext",value:(i=rj.default(fj.default.mark((function e(){var t;return fj.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=rj.default(fj.default.mark((function e(t){var n,r;return fj.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=rj.default(fj.default.mark((function e(t,n){var r,i,o;return fj.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:o=e.sent,r.updateDateExpires(o.body.date_expires);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeList",value:(t=rj.default(fj.default.mark((function e(){return fj.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,o,a,s,u){if(this.shouldIgnoreEvent(e,n))Wj("Item ".concat(e," update skipped, current: ").concat(this.lastEventId,", remote: ").concat(n));else{this._updateRootDateUpdated(o);var c=this.cache.get(e);if(!c){var l=new wL({index:e,uri:t,lastEventId:n,revision:r,data:i,dateUpdated:o,dateExpires:a});return this.cache.store(e,l,n),void this.emitItemMutationEvent(l,u,s)}var f=Dj(c.data);c.update(n,r,i,o),this.cache.store(e,c,n),void 0!==a&&c.updateDateExpires(a),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",o={item:e,isLocal:!t};n||(o.previousItemData=r),this.broadcastEventToListeners(i,o)}},{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):(Wj("Context update skipped, current:",this.lastEventId,", remote:",t),!1)}}],[{key:"type",get:function(){return"list"}}]),v}(dL),PL=function(e){sj.default(p,e);var t,n,r,i,o,a,s,u,c,l,f,d=IL(p);function p(e){var t;return ij.default(this,p),(t=d.call(this)).syncListImpl=e,t.syncListImpl.attach(aj.default(t)),t}return oj.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 AL.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=rj.default(fj.default.mark((function e(t,n){return fj.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=rj.default(fj.default.mark((function e(t,n,r){return fj.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=rj.default(fj.default.mark((function e(t,n,r){return fj.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=rj.default(fj.default.mark((function e(t,n,r){return fj.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=rj.default(fj.default.mark((function e(t){return fj.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:(a=rj.default(fj.default.mark((function e(t){return fj.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 a.apply(this,arguments)})},{key:"getContext",value:(o=rj.default(fj.default.mark((function e(){return fj.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 o.apply(this,arguments)})},{key:"getItems",value:(i=rj.default(fj.default.mark((function e(t){return fj.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=rj.default(fj.default.mark((function e(t){return fj.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=rj.default(fj.default.mark((function e(t,n){return fj.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=rj.default(fj.default.mark((function e(){return fj.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(){mj.default(cj.default(p.prototype),"close",this).call(this),this.syncListImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return AL.type}}]),p}(vL);lj.default(PL,"itemAdded","itemAdded"),lj.default(PL,"itemUpdated","itemUpdated"),lj.default(PL,"itemRemoved","itemRemoved"),lj.default(PL,"removed","removed"),bj([JP.validateTypesAsync(JP.pureObject,["undefined",JP.objectSchema("item metadata",{ttl:[JP.nonNegativeInteger,"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Object,Object]),wj("design:returntype",Promise)],PL.prototype,"push",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger,JP.pureObject,["undefined",JP.objectSchema("item metadata",{ttl:[JP.nonNegativeInteger,"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Number,Object,Object]),wj("design:returntype",Promise)],PL.prototype,"set",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger,"function",["undefined",JP.objectSchema("item metadata",{ttl:[JP.nonNegativeInteger,"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Number,Function,Object]),wj("design:returntype",Promise)],PL.prototype,"mutate",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger,JP.pureObject,["undefined",JP.objectSchema("item metadata",{ttl:[JP.nonNegativeInteger,"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Number,Object,Object]),wj("design:returntype",Promise)],PL.prototype,"update",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger),wj("design:type",Function),wj("design:paramtypes",[Number]),wj("design:returntype",Promise)],PL.prototype,"remove",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger),wj("design:type",Function),wj("design:paramtypes",[Number]),wj("design:returntype",Promise)],PL.prototype,"get",null),bj([JP.validateTypesAsync(["undefined",JP.objectSchema("query options",{from:[JP.nonNegativeInteger,"undefined"],pageSize:[JP.custom((function(e){return[Fj(e),"a positive integer"]})),"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Object]),wj("design:returntype",Promise)],PL.prototype,"getItems",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger),wj("design:type",Function),wj("design:paramtypes",[Number]),wj("design:returntype",Promise)],PL.prototype,"setTtl",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger,JP.nonNegativeInteger),wj("design:type",Function),wj("design:paramtypes",[Number,Number]),wj("design:returntype",Promise)],PL.prototype,"setItemTtl",null);var jL=function(){function e(t){ij.default(this,e),this.descriptor=t}return oj.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 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=cj.default(e);if(t){var i=cj.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return uj.default(this,n)}}var ML=function(e){sj.default(h,e);var t,n,r,i,o,a,s,u,c,l,f,d,p=LL(h);function h(e,t,n){var r;ij.default(this,h);return(r=p.call(this,e,n)).updateMergingQueue=new hL((function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e})),r.cache=new OL,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 jL(e),e.last_event_id)})),r}return oj.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=rj.default(fj.default.mark((function e(t,n,r){var i,o=this;return fj.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 o._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=rj.default(fj.default.mark((function e(t){return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=t){e.next=2;break}throw new Mj("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=rj.default(fj.default.mark((function e(t){var n;return fj.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 Mj("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=rj.default(fj.default.mark((function e(t,n,r){var i,o=this;return fj.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 o._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=rj.default(fj.default.mark((function e(t,n,r){return fj.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=rj.default(fj.default.mark((function e(t,n,r){var i,o;return fj.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,o=i.item,this._handleItemMutated(o.key,o.url,o.last_event_id,o.revision,o.data,o.date_updated,o.date_expires,i.added,!1),e.abrupt("return",this.cache.get(o.key));case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"_putItemWithIfMatch",value:(s=rj.default(fj.default.mark((function e(t,n,r){var i,o,a,s,u;return fj.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 jL({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,!(o=n(Dj(i.data)))){e.next=26;break}return a=i.revision,e.prev=6,e.next=9,this._putItemToServer(t,o,a,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:(a=rj.default(fj.default.mark((function e(t,n,r,i){var o,a,s,u,c;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=new jj(this.links.items).pathSegment(t).build(),a={data:n},void 0!==i&&(a.ttl=i),e.prev=3,e.next=6,this.services.network.put(o,a,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 a.apply(this,arguments)})},{key:"remove",value:(o=rj.default(fj.default.mark((function e(t){var n,r,i;return fj.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=Dj(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:"queryItems",value:function(){var e=rj.default(fj.default.mark((function e(t){var n,r,i,o,a=this;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=t||{},n=new jj(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),a.cache.get(e.key)?a._handleItemMutated(e.key,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):a.cache.store(e.key,new jL(e),e.last_event_id),a.cache.get(e.key)})),o=r.body.meta,e.abrupt("return",new Paginator(i,(function(e){return a.queryItems({pageToken:e})}),o.previous_token,o.next_token));case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}()},{key:"getItems",value:(i=rj.default(fj.default.mark((function e(t){return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return Uj((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,o,a,s,u){if(this.shouldIgnoreEvent(e,n))Wj("SyncMapItem ",e," update skipped, current:",this.lastEventId,", remote:",n);else{this._updateRootDateUpdated(o);var c=this.cache.get(e);if(!c){var l=new jL({key:e,url:t,last_event_id:n,revision:r,data:i,date_updated:o,date_expires:a});return this.cache.store(e,l,n),void this.emitItemMutationEvent(l,u,s)}var f=Dj(c.data);c.update(n,r,i,o),this.cache.store(e,c,n),void 0!==a&&c.updateDateExpires(a),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",o={item:e,isLocal:!t};n||(o.previousItemData=r),this.broadcastEventToListeners(i,o)}},{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=rj.default(fj.default.mark((function e(t){var n,r;return fj.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=rj.default(fj.default.mark((function e(t,n){var r,i,o;return fj.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:o=e.sent,r.updateDateExpires(o.body.date_expires);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"removeMap",value:(t=rj.default(fj.default.mark((function e(){return fj.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}(dL),NL=function(e){sj.default(f,e);var t,n,r,i,o,a,s,u,c,l=LL(f);function f(e){var t;return ij.default(this,f),(t=l.call(this)).syncMapImpl=e,t.syncMapImpl.attach(aj.default(t)),t}return oj.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 ML.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=rj.default(fj.default.mark((function e(t,n,r){return fj.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=rj.default(fj.default.mark((function e(t){return fj.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=rj.default(fj.default.mark((function e(t,n,r){return fj.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:(a=rj.default(fj.default.mark((function e(t,n,r){return fj.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 a.apply(this,arguments)})},{key:"remove",value:(o=rj.default(fj.default.mark((function e(t){return fj.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 o.apply(this,arguments)})},{key:"getItems",value:(i=rj.default(fj.default.mark((function e(t){return fj.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=rj.default(fj.default.mark((function e(t){return fj.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=rj.default(fj.default.mark((function e(t,n){return fj.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=rj.default(fj.default.mark((function e(){return fj.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(){mj.default(cj.default(f.prototype),"close",this).call(this),this.syncMapImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return ML.type}}]),f}(vL);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=cj.default(e);if(t){var i=cj.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return uj.default(this,n)}}lj.default(NL,"itemAdded","itemAdded"),lj.default(NL,"itemUpdated","itemUpdated"),lj.default(NL,"itemRemoved","itemRemoved"),lj.default(NL,"removed","removed"),bj([JP.validateTypesAsync("string",JP.pureObject,["undefined",JP.objectSchema("item metadata",{ttl:[JP.nonNegativeInteger,"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[String,Object,Object]),wj("design:returntype",Promise)],NL.prototype,"set",null),bj([JP.validateTypesAsync("string"),wj("design:type",Function),wj("design:paramtypes",[String]),wj("design:returntype",Promise)],NL.prototype,"get",null),bj([JP.validateTypesAsync("string","function",["undefined",JP.objectSchema("item metadata",{ttl:[JP.nonNegativeInteger,"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[String,Function,Object]),wj("design:returntype",Promise)],NL.prototype,"mutate",null),bj([JP.validateTypesAsync("string",JP.pureObject,["undefined",JP.objectSchema("item metadata",{ttl:[JP.nonNegativeInteger,"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[String,Object,Object]),wj("design:returntype",Promise)],NL.prototype,"update",null),bj([JP.validateTypesAsync("string"),wj("design:type",Function),wj("design:paramtypes",[String]),wj("design:returntype",Promise)],NL.prototype,"remove",null),bj([JP.validateTypesAsync(["undefined",JP.objectSchema("query options",{from:["string","undefined"],pageSize:[JP.custom((function(e){return[Fj(e),"a positive integer"]})),"undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Object]),wj("design:returntype",Promise)],NL.prototype,"getItems",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger),wj("design:type",Function),wj("design:paramtypes",[Number]),wj("design:returntype",Promise)],NL.prototype,"setTtl",null),bj([JP.validateTypesAsync("string",JP.nonNegativeInteger),wj("design:type",Function),wj("design:paramtypes",[String,Number]),wj("design:returntype",Promise)],NL.prototype,"setItemTtl",null);var UL=function(e){sj.default(o,e);var t,n,r,i=DL(o);function o(e,t,n){var r;return ij.default(this,o),(r=i.call(this,e,n)).descriptor=t,r}return oj.default(o,[{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=rj.default(fj.default.mark((function e(t){var n,r,i,o;return fj.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,o=this._handleMessagePublished(i.sid,t,!1),e.abrupt("return",o);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"setTtl",value:(n=rj.default(fj.default.mark((function e(t){var n,r;return fj.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=rj.default(fj.default.mark((function e(){return fj.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"}}]),o}(dL);bj([JP.validateTypesAsync(JP.pureObject),wj("design:type",Function),wj("design:paramtypes",[Object]),wj("design:returntype",Promise)],UL.prototype,"publishMessage",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger),wj("design:type",Function),wj("design:paramtypes",[Number]),wj("design:returntype",Promise)],UL.prototype,"setTtl",null);var FL=function(e){sj.default(o,e);var t,n,r,i=DL(o);function o(e){var t;return ij.default(this,o),(t=i.call(this)).syncStreamImpl=e,t.syncStreamImpl.attach(aj.default(t)),t}return oj.default(o,[{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 UL.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=rj.default(fj.default.mark((function e(t){return fj.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=rj.default(fj.default.mark((function e(t){return fj.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=rj.default(fj.default.mark((function e(){return fj.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(){mj.default(cj.default(o.prototype),"close",this).call(this),this.syncStreamImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return UL.type}}]),o}(vL);lj.default(FL,"messagePublished","messagePublished"),lj.default(FL,"removed","removed"),bj([JP.validateTypesAsync(JP.pureObject),wj("design:type",Function),wj("design:paramtypes",[Object]),wj("design:returntype",Promise)],FL.prototype,"publishMessage",null),bj([JP.validateTypesAsync(JP.nonNegativeInteger),wj("design:type",Function),wj("design:paramtypes",[Number]),wj("design:returntype",Promise)],FL.prototype,"setTtl",null);var BL=function e(t){ij.default(this,e),this.sdk="js",this.sdkVer=t,this.os=gj.os.family,this.osVer=gj.os.version,this.pl=gj.name,this.plVer=gj.version},qL=function(){function e(){ij.default(this,e),this.names=new Map,this.entities=new Map}return oj.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 zL(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=cj.default(e);if(t){var i=cj.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return uj.default(this,n)}}var WL=function(e){sj.default(n,e);var t=zL(n);function n(e,r,i,o){var a;return ij.default(this,n),(a=t.call(this,r,i)).descriptor=e,a.cache=new OL,o&&o.forEach((function(e){a.cache.store(e.key,{key:e.key,value:e.data},e.revision)})),a}return oj.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))Wj("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)?Wj("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}(dL);function GL(e){return $L.apply(this,arguments)}function $L(){return($L=rj.default(fj.default.mark((function e(t){var n,r,i,o,a,s;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.network,r=t.queryString,i=t.uri,o=t.type,null!=r){e.next=3;break}throw new Mj("Invalid query",400,54507);case 3:return a={query_string:r},o===JL.type&&(a.type=o),e.next=7,n.post(i,a,void 0,!0);case 7:return s=e.sent,e.abrupt("return",s.body);case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var JL=function(e){sj.default(n,e);var t=zL(n);function n(e){var r;return ij.default(this,n),(r=t.call(this)).liveQueryImpl=e,r.liveQueryImpl.attach(aj.default(r)),r}return oj.default(n,[{key:"type",get:function(){return WL.type}},{key:"lastEventId",get:function(){return this.liveQueryImpl.lastEventId}},{key:"sid",get:function(){return this.liveQueryImpl.sid}},{key:"close",value:function(){mj.default(cj.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 WL.type}}]),n}(vL);lj.default(JL,"itemUpdated","itemUpdated"),lj.default(JL,"itemRemoved","itemRemoved");var KL=function(e){sj.default(i,e);var t,n,r=zL(i);function i(e){var t;return ij.default(this,i),t=r.call(this),lj.default(aj.default(t),"queryExpression",null),lj.default(aj.default(t),"items",{}),Object.assign(aj.default(t),e),t.updateIndexName(e.indexName),t}return oj.default(i,[{key:"type",get:function(){return i.type}},{key:"search",value:(n=rj.default(fj.default.mark((function e(t){var n=this;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.items={},e.abrupt("return",GL({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 Jj("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=rj.default(fj.default.mark((function e(){return fj.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 Mj("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 jj(this.insightsUri).pathSegment(e).pathSegment("Items").build()}}],[{key:"type",get:function(){return"instant_query"}}]),i}(kj);lj.default(KL,"searchResult","searchResult"),bj([JP.validateTypesAsync("string"),wj("design:type",Function),wj("design:paramtypes",[String]),wj("design:returntype",Promise)],KL.prototype,"search",null),bj([JP.validateTypes(JP.nonEmptyString),wj("design:type",Function),wj("design:paramtypes",[String]),wj("design:returntype",void 0)],KL.prototype,"updateIndexName",null);function VL(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=cj.default(e);if(t){var i=cj.default(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return uj.default(this,n)}}function HL(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 YL(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?HL(Object(n),!0).forEach((function(t){lj.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):HL(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var QL="data_sync",XL="3.1.0";function ZL(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 YL(YL({},e),{},{mode:t})}return{mode:"create_new"}}var eM="com.twilio.rtd.cds.document",tM="com.twilio.rtd.cds.list",nM="com.twilio.rtd.cds.map",rM="twilio.sync.event",Client=function(e){sj.default(Client,e);var t,n,r,i,o,a,s,u,c,l,f,d,p,h,y,v=VL(Client);function Client(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(ij.default(this,Client),t=v.call(this),!e)throw new Error("Sync library needs a valid Twilio token to be passed");n.hasOwnProperty("logLevel")?zj(n.logLevel):zj("silent");var r=n.productId=n.productId||QL;n.clientMetadata=n.clientMetadata||{},n.clientMetadata.hasOwnProperty("type")||(n.clientMetadata.type="sync"),n.clientMetadata.hasOwnProperty("sdk")||(n.clientMetadata.sdk="JS",n.clientMetadata.sdkv=XL);var i=!n.twilsockClient;if(!n.initRegistrations){var o=new KP.InitRegistration(r);Client.populateInitRegistrations(o),n.initRegistrations=[o]}var a=n.twilsockClient=n.twilsockClient||new KP.Twilsock(e,r,n);a.on("tokenAboutToExpire",(function(e){return t.emit("tokenAboutToExpire",e)})),a.on("tokenExpired",(function(){return t.emit("tokenExpired")})),a.on("connectionError",(function(e){return t.emit("connectionError",e)})),a.on("stateChanged",(function(e){t.emit("connectionStateChanged",e),t.services.subscriptions.onConnectionStateChanged("connected"===e)})),a.on("message",(function(e,n){return t._routeMessage(e,n)}));var s=new eL(n),u=new uL(new BL(XL),s,a),c=new cL(s);return t.services={config:s,twilsock:a,network:u,storage:c,router:aj.default(t),subscriptions:null},t.services.subscriptions=new iL(t.services),t.entities=new qL,i&&a.connect(),t}return oj.default(Client,[{key:"_routeMessage",value:function(e,t){switch(Wj("Notification type:",e,"content:",t),e){case eM:case tM:case nM:this.services.subscriptions.acceptMessage(t,!1);break;case rM: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:(y=rj.default(fj.default.mark((function e(){var t;return fj.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),$j("Failed to initialize storage",e.t0);case 12:case"end":return e.stop()}}),e,this,[[2,9]])}))),function(){return y.apply(this,arguments)})},{key:"storeRootInSessionCache",value:function(e,t,n){if(this.services.config.sessionStorageEnabled&&t){var r=Dj(n);e!==PL.type&&e!==NL.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=rj.default(fj.default.mark((function e(t,n){var r,i,o,a=arguments;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=a.length>2&&void 0!==a[2]&&a[2],n){e.next=3;break}throw new Mj("Cannot get entity without id",404);case 3:return i=new jj(t).pathSegment(n).queryParam("Include",r?"items":void 0).build(),e.next=6,this.services.network.get(i);case 6:return o=e.sent,e.abrupt("return",o.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=rj.default(fj.default.mark((function e(t){return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(bL.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=rj.default(fj.default.mark((function e(t){return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(PL.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=rj.default(fj.default.mark((function e(t){var n,r=arguments;return fj.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(NL.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=rj.default(fj.default.mark((function e(t){return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.readRootFromSessionCache(FL.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=rj.default(fj.default.mark((function e(t,n){var r,i;return fj.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(JL.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=rj.default(fj.default.mark((function e(t){var n,r,i,o,a=this;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=ZL(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,bL.type))){e.next=14;break}return e.abrupt("return",new bL(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(bL.type,n.id,r),o=new gL(this.services,r,(function(e,t,n){return a.removeFromCacheAndSession(e,t,n)})),o=this.entities.store(o),e.abrupt("return",new bL(o));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return u.apply(this,arguments)})},{key:"map",value:(s=rj.default(fj.default.mark((function e(t){var n,r,i,o,a=this;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=ZL(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,NL.type))){e.next=14;break}return e.abrupt("return",new NL(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(NL.type,n.id,r),o=new ML(this.services,r,(function(e,t,n){return a.removeFromCacheAndSession(e,t,n)})),o=this.entities.store(o),e.abrupt("return",new NL(o));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return s.apply(this,arguments)})},{key:"list",value:(a=rj.default(fj.default.mark((function e(t){var n,r,i,o,a=this;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=ZL(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,PL.type))){e.next=14;break}return e.abrupt("return",new PL(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(PL.type,n.id,r),o=new AL(this.services,r,(function(e,t,n){return a.removeFromCacheAndSession(e,t,n)})),o=this.entities.store(o),e.abrupt("return",new PL(o));case 43:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return a.apply(this,arguments)})},{key:"stream",value:(o=rj.default(fj.default.mark((function e(t){var n,r,i,o,a,s=this;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:if("create_new"!==(n=ZL(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,FL.type))){e.next=14;break}return e.abrupt("return",new FL(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(FL.type,n.id,r),o=function(e,t,n){return s.removeFromCacheAndSession(e,t,n)},a=new UL(this.services,r,o),a=this.entities.store(a),e.abrupt("return",new FL(a));case 44:case"end":return e.stop()}}),e,this,[[14,20],[26,32]])}))),function(e){return o.apply(this,arguments)})},{key:"shutdown",value:(i=rj.default(fj.default.mark((function e(){return fj.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=rj.default(fj.default.mark((function e(t){return fj.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 Mj("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=rj.default(fj.default.mark((function e(t,n){var r,i,o,a,s,u=this;return fj.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ensureReady();case 2:return r=new jj(this.services.config.insightsUri).pathSegment(t).pathSegment("Items").build(),e.next=5,GL({network:this.services.network,uri:r,queryString:n,type:JL.type});case 5:return i=e.sent,(o=this.getCached(i.query_id,JL.type))||((a=this._getLiveQuery(i.query_id))||(a={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)},o=new WL(a,this.services,s,i.items)),this.storeRootInSessionCache(JL.type,i.query_id,o.liveQueryDescriptor),o=this.entities.store(o),e.abrupt("return",new JL(o));case 11:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"instantQuery",value:(t=rj.default(fj.default.mark((function e(t){var n,r=this;return fj.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 KL({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([rM,eM,tM,nM])}},{key:"version",get:function(){return XL}}]),Client}(kj);lj.default(Client,"connectionStateChanged","connectionStateChanged"),lj.default(Client,"connectionError","connectionError"),lj.default(Client,"tokenAboutToExpire","tokenAboutToExpire"),lj.default(Client,"tokenExpired","tokenExpired"),bj([JP.validateTypesAsync(["undefined","string",JP.objectSchema("open document options",{id:["string","undefined"],mode:[JP.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[JP.nonNegativeInteger,"undefined"],data:[JP.pureObject,"undefined",JP.literal(null)]})]),wj("design:type",Function),wj("design:paramtypes",[Object]),wj("design:returntype",Promise)],Client.prototype,"document",null),bj([JP.validateTypesAsync(["undefined","string",JP.objectSchema("open map options",{id:["string","undefined"],mode:[JP.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[JP.nonNegativeInteger,"undefined"],data:[JP.pureObject,"undefined",JP.literal(null)],includeItems:["boolean","undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Object]),wj("design:returntype",Promise)],Client.prototype,"map",null),bj([JP.validateTypesAsync(["undefined","string",JP.objectSchema("open list options",{id:["string","undefined"],mode:[JP.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[JP.nonNegativeInteger,"undefined"],data:[JP.pureObject,"undefined",JP.literal(null)],purpose:["string","undefined"],context:[JP.pureObject,"undefined"],includeItems:["boolean","undefined"]})]),wj("design:type",Function),wj("design:paramtypes",[Object]),wj("design:returntype",Promise)],Client.prototype,"list",null),bj([JP.validateTypesAsync(["undefined","string",JP.objectSchema("open stream options",{id:["string","undefined"],mode:[JP.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[JP.nonNegativeInteger,"undefined"],data:[JP.pureObject,"undefined",JP.literal(null)]})]),wj("design:type",Function),wj("design:paramtypes",[Object]),wj("design:returntype",Promise)],Client.prototype,"stream",null),bj([JP.validateTypesAsync(JP.nonEmptyString),wj("design:type",Function),wj("design:paramtypes",[String]),wj("design:returntype",Promise)],Client.prototype,"updateToken",null),bj([JP.validateTypesAsync(JP.nonEmptyString,"string"),wj("design:type",Function),wj("design:paramtypes",[String,String]),wj("design:returntype",Promise)],Client.prototype,"liveQuery",null),bj([JP.validateTypesAsync(JP.nonEmptyString),wj("design:type",Function),wj("design:paramtypes",[String]),wj("design:returntype",Promise)],Client.prototype,"instantQuery",null),gI.Client=Client,gI.InsightsItem=function e(){ij.default(this,e)},gI.InstantQuery=KL,gI.LiveQuery=JL,gI.Paginator=Paginator;var iM=gI.SyncClient=Client;function oM(){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 aM(e,t,n){return(aM=oM()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&Oo(i,n.prototype),i}).apply(null,arguments)}function sM(e){var t="function"==typeof Map?new Map:void 0;return(sM=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 aM(e,arguments,jo(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),Oo(r,e)})(e)}gI.SyncDocument=bL,gI.SyncList=PL,gI.SyncListItem=wL,gI.SyncMap=NL,gI.SyncMapItem=jL,gI.SyncStream=FL;var uM,cM={},lM=pT,fM=function(e){if(lM(e))throw TypeError("The method doesn't accept regular expressions");return e},dM=pe("match"),pM=function(e){var t=/./;try{"/./"[e](t)}catch(n){try{return t[dM]=!1,"/./"[e](t)}catch(e){}}return!1},hM=Rn,yM=o.f,vM=Dt,mM=Sr,gM=fM,bM=w,wM=pM,xM="".startsWith,kM=Math.min,_M=wM("startsWith");hM({target:"String",proto:!0,forced:!!(_M||(uM=yM(String.prototype,"startsWith"),!uM||uM.writable))&&!_M},{startsWith:function(e){var t=mM(bM(this));gM(e);var n=vM(kM(arguments.length>1?arguments[1]:void 0,t.length)),r=mM(e);return xM?xM.call(t,r,n):t.slice(n,n+r.length)===r}});var SM=iE.left,EM=M,TM=Ja;Rn({target:"Array",proto:!0,forced:!rc("reduce")||!TM&&EM>79&&EM<83},{reduce:function(e){return SM(this,e,arguments.length,arguments.length>1?arguments[1]:void 0)}});var RM=a,CM=pe("iterator"),OM=!RM((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[CM]||"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})),IM=2147483647,AM=/[^\0-\u007E]/,PM=/[.\u3002\uFF0E\uFF61]/g,jM="Overflow: input needs wider integers to process",LM=Math.floor,MM=String.fromCharCode,NM=function(e){return e+22+75*(e<26)},DM=function(e,t,n){var r=0;for(e=n?LM(e/700):e>>1,e+=LM(e/t);e>455;r+=36)e=LM(e/35);return LM(r+36*e/(e+38))},UM=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 o=e.charCodeAt(n++);56320==(64512&o)?t.push(((1023&i)<<10)+(1023&o)+65536):(t.push(i),n--)}else t.push(i)}return t}(e)).length,o=128,a=0,s=72;for(t=0;t<e.length;t++)(n=e[t])<128&&r.push(MM(n));var u=r.length,c=u;for(u&&r.push("-");c<i;){var l=IM;for(t=0;t<e.length;t++)(n=e[t])>=o&&n<l&&(l=n);var f=c+1;if(l-o>LM((IM-a)/f))throw RangeError(jM);for(a+=(l-o)*f,o=l,t=0;t<e.length;t++){if((n=e[t])<o&&++a>IM)throw RangeError(jM);if(n==o){for(var d=a,p=36;;p+=36){var h=p<=s?1:p>=s+26?26:p-s;if(d<h)break;var y=d-h,v=36-h;r.push(MM(NM(h+y%v))),d=LM(y/v)}r.push(MM(NM(d))),s=DM(a,f,c==u),a=0,++c}}++a,++o}return r.join("")},FM=Rn,BM=R,qM=OM,zM=Ke.exports,WM=Xo,GM=An,$M=Kl,JM=kt,KM=ua,VM=ee,HM=Ur,YM=Go,QM=Ue,XM=S,ZM=Sr,eN=tr,tN=h,nN=wa,rN=ma,iN=pe,oN=BM("fetch"),aN=BM("Request"),sN=aN&&aN.prototype,uN=BM("Headers"),cN=iN("iterator"),lN="URLSearchParams",fN="URLSearchParamsIterator",dN=JM.set,pN=JM.getterFor(lN),hN=JM.getterFor(fN),yN=/\+/g,vN=Array(4),mN=function(e){return vN[e-1]||(vN[e-1]=RegExp("((?:%[\\da-f]{2}){"+e+"})","gi"))},gN=function(e){try{return decodeURIComponent(e)}catch(t){return e}},bN=function(e){var t=e.replace(yN," "),n=4;try{return decodeURIComponent(t)}catch(e){for(;n;)t=t.replace(mN(n--),gN);return t}},wN=/[!'()~]|%20/g,xN={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+"},kN=function(e){return xN[e]},_N=function(e){return encodeURIComponent(e).replace(wN,kN)},SN=function(e,t){if(t)for(var n,r,i=t.split("&"),o=0;o<i.length;)(n=i[o++]).length&&(r=n.split("="),e.push({key:bN(r.shift()),value:bN(r.join("="))}))},EN=function(e){this.entries.length=0,SN(this.entries,e)},TN=function(e,t){if(e<t)throw TypeError("Not enough arguments")},RN=$M((function(e,t){dN(this,{type:fN,iterator:nN(pN(e).entries),kind:t})}),"Iterator",(function(){var e=hN(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})),CN=function(){KM(this,CN,lN);var e,t,n,r,i,o,a,s,u,c=arguments.length>0?arguments[0]:void 0,l=this,f=[];if(dN(l,{type:lN,entries:f,updateURL:function(){},updateSearchParams:EN}),void 0!==c)if(XM(c))if("function"==typeof(e=rN(c)))for(n=(t=nN(c,e)).next;!(r=n.call(t)).done;){if((a=(o=(i=nN(QM(r.value))).next).call(i)).done||(s=o.call(i)).done||!o.call(i).done)throw TypeError("Expected sequence with length 2");f.push({key:ZM(a.value),value:ZM(s.value)})}else for(u in c)VM(c,u)&&f.push({key:u,value:ZM(c[u])});else SN(f,"string"==typeof c?"?"===c.charAt(0)?c.slice(1):c:ZM(c))},ON=CN.prototype;if(WM(ON,{append:function(e,t){TN(arguments.length,2);var n=pN(this);n.entries.push({key:ZM(e),value:ZM(t)}),n.updateURL()},delete:function(e){TN(arguments.length,1);for(var t=pN(this),n=t.entries,r=ZM(e),i=0;i<n.length;)n[i].key===r?n.splice(i,1):i++;t.updateURL()},get:function(e){TN(arguments.length,1);for(var t=pN(this).entries,n=ZM(e),r=0;r<t.length;r++)if(t[r].key===n)return t[r].value;return null},getAll:function(e){TN(arguments.length,1);for(var t=pN(this).entries,n=ZM(e),r=[],i=0;i<t.length;i++)t[i].key===n&&r.push(t[i].value);return r},has:function(e){TN(arguments.length,1);for(var t=pN(this).entries,n=ZM(e),r=0;r<t.length;)if(t[r++].key===n)return!0;return!1},set:function(e,t){TN(arguments.length,1);for(var n,r=pN(this),i=r.entries,o=!1,a=ZM(e),s=ZM(t),u=0;u<i.length;u++)(n=i[u]).key===a&&(o?i.splice(u--,1):(o=!0,n.value=s));o||i.push({key:a,value:s}),r.updateURL()},sort:function(){var e,t,n,r=pN(this),i=r.entries,o=i.slice();for(i.length=0,n=0;n<o.length;n++){for(e=o[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=pN(this).entries,r=HM(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 RN(this,"keys")},values:function(){return new RN(this,"values")},entries:function(){return new RN(this,"entries")}},{enumerable:!0}),zM(ON,cN,ON.entries),zM(ON,"toString",(function(){for(var e,t=pN(this).entries,n=[],r=0;r<t.length;)e=t[r++],n.push(_N(e.key)+"="+_N(e.value));return n.join("&")}),{enumerable:!0}),GM(CN,lN),FM({global:!0,forced:!qM},{URLSearchParams:CN}),!qM&&"function"==typeof uN){var IN=function(e){if(XM(e)){var t,n=e.body;if(YM(n)===lN)return(t=e.headers?new uN(e.headers):new uN).has("content-type")||t.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"),eN(e,{body:tN(0,String(n)),headers:tN(0,t)})}return e};if("function"==typeof oN&&FM({global:!0,enumerable:!0,forced:!0},{fetch:function(e){return oN(e,arguments.length>1?IN(arguments[1]):{})}}),"function"==typeof aN){var AN=function(e){return KM(this,AN,"Request"),new aN(e,arguments.length>1?IN(arguments[1]):{})};sN.constructor=AN,AN.prototype=sN,FM({global:!0,forced:!0},{Request:AN})}}var PN,jN={URLSearchParams:CN,getState:pN},LN=Rn,MN=s,NN=OM,DN=i,UN=zn,FN=Ke.exports,BN=ua,qN=ee,zN=yI,WN=gl,GN=Rl.codeAt,$N=function(e){var t,n,r=[],i=e.toLowerCase().replace(PM,".").split(".");for(t=0;t<i.length;t++)n=i[t],r.push(AM.test(n)?"xn--"+UM(n):n);return r.join(".")},JN=Sr,KN=An,VN=jN,HN=kt,YN=DN.URL,QN=VN.URLSearchParams,XN=VN.getState,ZN=HN.set,eD=HN.getterFor("URL"),tD=Math.floor,nD=Math.pow,rD="Invalid scheme",iD="Invalid host",oD="Invalid port",aD=/[A-Za-z]/,sD=/[\d+-.A-Za-z]/,uD=/\d/,cD=/^0x/i,lD=/^[0-7]+$/,fD=/^\d+$/,dD=/^[\dA-Fa-f]+$/,pD=/[\0\t\n\r #%/:<>?@[\\\]^|]/,hD=/[\0\t\n\r #/:<>?@[\\\]^|]/,yD=/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g,vD=/[\t\n\r]/g,mD=function(e,t){var n,r,i;if("["==t.charAt(0)){if("]"!=t.charAt(t.length-1))return iD;if(!(n=bD(t.slice(1,-1))))return iD;e.host=n}else if(RD(e)){if(t=$N(t),pD.test(t))return iD;if(null===(n=gD(t)))return iD;e.host=n}else{if(hD.test(t))return iD;for(n="",r=WN(t),i=0;i<r.length;i++)n+=ED(r[i],xD);e.host=n}},gD=function(e){var t,n,r,i,o,a,s,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(o=10,i.length>1&&"0"==i.charAt(0)&&(o=cD.test(i)?16:8,i=i.slice(8==o?1:2)),""===i)a=0;else{if(!(10==o?fD:8==o?lD:dD).test(i))return e;a=parseInt(i,o)}n.push(a)}for(r=0;r<t;r++)if(a=n[r],r==t-1){if(a>=nD(256,5-t))return null}else if(a>255)return null;for(s=n.pop(),r=0;r<n.length;r++)s+=n[r]*nD(256,3-r);return s},bD=function(e){var t,n,r,i,o,a,s,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&&dD.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(!uD.test(d()))return;for(;uD.test(d());){if(o=parseInt(d(),10),null===i)i=o;else{if(0==i)return;i=10*i+o}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(a=c-l,c=7;0!=c&&a>0;)s=u[c],u[c--]=u[l+a-1],u[l+--a]=s;else if(8!=c)return;return u},wD=function(e){var t,n,r,i;if("number"==typeof e){for(t=[],n=0;n<4;n++)t.unshift(e%256),e=tD(e/256);return t.join(".")}if("object"==typeof e){for(t="",r=function(e){for(var t=null,n=1,r=null,i=0,o=0;o<8;o++)0!==e[o]?(i>n&&(t=r,n=i),r=null,i=0):(null===r&&(r=o),++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},xD={},kD=zN({},xD,{" ":1,'"':1,"<":1,">":1,"`":1}),_D=zN({},kD,{"#":1,"?":1,"{":1,"}":1}),SD=zN({},_D,{"/":1,":":1,";":1,"=":1,"@":1,"[":1,"\\":1,"]":1,"^":1,"|":1}),ED=function(e,t){var n=GN(e,0);return n>32&&n<127&&!qN(t,e)?e:encodeURIComponent(e)},TD={ftp:21,file:null,http:80,https:443,ws:80,wss:443},RD=function(e){return qN(TD,e.scheme)},CD=function(e){return""!=e.username||""!=e.password},OD=function(e){return!e.host||e.cannotBeABaseURL||"file"==e.scheme},ID=function(e,t){var n;return 2==e.length&&aD.test(e.charAt(0))&&(":"==(n=e.charAt(1))||!t&&"|"==n)},AD=function(e){var t;return e.length>1&&ID(e.slice(0,2))&&(2==e.length||"/"===(t=e.charAt(2))||"\\"===t||"?"===t||"#"===t)},PD=function(e){var t=e.path,n=t.length;!n||"file"==e.scheme&&1==n&&ID(t[0],!0)||t.pop()},jD=function(e){return"."===e||"%2e"===e.toLowerCase()},LD={},MD={},ND={},DD={},UD={},FD={},BD={},qD={},zD={},WD={},GD={},$D={},JD={},KD={},VD={},HD={},YD={},QD={},XD={},ZD={},eU={},tU=function(e,t,n,r){var i,o,a,s,u,c=n||LD,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(yD,"")),t=t.replace(vD,""),i=WN(t);l<=i.length;){switch(o=i[l],c){case LD:if(!o||!aD.test(o)){if(n)return rD;c=ND;continue}f+=o.toLowerCase(),c=MD;break;case MD:if(o&&(sD.test(o)||"+"==o||"-"==o||"."==o))f+=o.toLowerCase();else{if(":"!=o){if(n)return rD;f="",c=ND,l=0;continue}if(n&&(RD(e)!=qN(TD,f)||"file"==f&&(CD(e)||null!==e.port)||"file"==e.scheme&&!e.host))return;if(e.scheme=f,n)return void(RD(e)&&TD[e.scheme]==e.port&&(e.port=null));f="","file"==e.scheme?c=KD:RD(e)&&r&&r.scheme==e.scheme?c=DD:RD(e)?c=qD:"/"==i[l+1]?(c=UD,l++):(e.cannotBeABaseURL=!0,e.path.push(""),c=XD)}break;case ND:if(!r||r.cannotBeABaseURL&&"#"!=o)return rD;if(r.cannotBeABaseURL&&"#"==o){e.scheme=r.scheme,e.path=r.path.slice(),e.query=r.query,e.fragment="",e.cannotBeABaseURL=!0,c=eU;break}c="file"==r.scheme?KD:FD;continue;case DD:if("/"!=o||"/"!=i[l+1]){c=FD;continue}c=zD,l++;break;case UD:if("/"==o){c=WD;break}c=QD;continue;case FD:if(e.scheme=r.scheme,o==PN)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("/"==o||"\\"==o&&RD(e))c=BD;else if("?"==o)e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,e.path=r.path.slice(),e.query="",c=ZD;else{if("#"!=o){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=QD;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=eU}break;case BD:if(!RD(e)||"/"!=o&&"\\"!=o){if("/"!=o){e.username=r.username,e.password=r.password,e.host=r.host,e.port=r.port,c=QD;continue}c=WD}else c=zD;break;case qD:if(c=zD,"/"!=o||"/"!=f.charAt(l+1))continue;l++;break;case zD:if("/"!=o&&"\\"!=o){c=WD;continue}break;case WD:if("@"==o){d&&(f="%40"+f),d=!0,a=WN(f);for(var y=0;y<a.length;y++){var v=a[y];if(":"!=v||h){var m=ED(v,SD);h?e.password+=m:e.username+=m}else h=!0}f=""}else if(o==PN||"/"==o||"?"==o||"#"==o||"\\"==o&&RD(e)){if(d&&""==f)return"Invalid authority";l-=WN(f).length+1,f="",c=GD}else f+=o;break;case GD:case $D:if(n&&"file"==e.scheme){c=HD;continue}if(":"!=o||p){if(o==PN||"/"==o||"?"==o||"#"==o||"\\"==o&&RD(e)){if(RD(e)&&""==f)return iD;if(n&&""==f&&(CD(e)||null!==e.port))return;if(s=mD(e,f))return s;if(f="",c=YD,n)return;continue}"["==o?p=!0:"]"==o&&(p=!1),f+=o}else{if(""==f)return iD;if(s=mD(e,f))return s;if(f="",c=JD,n==$D)return}break;case JD:if(!uD.test(o)){if(o==PN||"/"==o||"?"==o||"#"==o||"\\"==o&&RD(e)||n){if(""!=f){var g=parseInt(f,10);if(g>65535)return oD;e.port=RD(e)&&g===TD[e.scheme]?null:g,f=""}if(n)return;c=YD;continue}return oD}f+=o;break;case KD:if(e.scheme="file","/"==o||"\\"==o)c=VD;else{if(!r||"file"!=r.scheme){c=QD;continue}if(o==PN)e.host=r.host,e.path=r.path.slice(),e.query=r.query;else if("?"==o)e.host=r.host,e.path=r.path.slice(),e.query="",c=ZD;else{if("#"!=o){AD(i.slice(l).join(""))||(e.host=r.host,e.path=r.path.slice(),PD(e)),c=QD;continue}e.host=r.host,e.path=r.path.slice(),e.query=r.query,e.fragment="",c=eU}}break;case VD:if("/"==o||"\\"==o){c=HD;break}r&&"file"==r.scheme&&!AD(i.slice(l).join(""))&&(ID(r.path[0],!0)?e.path.push(r.path[0]):e.host=r.host),c=QD;continue;case HD:if(o==PN||"/"==o||"\\"==o||"?"==o||"#"==o){if(!n&&ID(f))c=QD;else if(""==f){if(e.host="",n)return;c=YD}else{if(s=mD(e,f))return s;if("localhost"==e.host&&(e.host=""),n)return;f="",c=YD}continue}f+=o;break;case YD:if(RD(e)){if(c=QD,"/"!=o&&"\\"!=o)continue}else if(n||"?"!=o)if(n||"#"!=o){if(o!=PN&&(c=QD,"/"!=o))continue}else e.fragment="",c=eU;else e.query="",c=ZD;break;case QD:if(o==PN||"/"==o||"\\"==o&&RD(e)||!n&&("?"==o||"#"==o)){if(".."===(u=(u=f).toLowerCase())||"%2e."===u||".%2e"===u||"%2e%2e"===u?(PD(e),"/"==o||"\\"==o&&RD(e)||e.path.push("")):jD(f)?"/"==o||"\\"==o&&RD(e)||e.path.push(""):("file"==e.scheme&&!e.path.length&&ID(f)&&(e.host&&(e.host=""),f=f.charAt(0)+":"),e.path.push(f)),f="","file"==e.scheme&&(o==PN||"?"==o||"#"==o))for(;e.path.length>1&&""===e.path[0];)e.path.shift();"?"==o?(e.query="",c=ZD):"#"==o&&(e.fragment="",c=eU)}else f+=ED(o,_D);break;case XD:"?"==o?(e.query="",c=ZD):"#"==o?(e.fragment="",c=eU):o!=PN&&(e.path[0]+=ED(o,xD));break;case ZD:n||"#"!=o?o!=PN&&("'"==o&&RD(e)?e.query+="%27":e.query+="#"==o?"%23":ED(o,xD)):(e.fragment="",c=eU);break;case eU:o!=PN&&(e.fragment+=ED(o,kD))}l++}},nU=function(e){var t,n,r=BN(this,nU,"URL"),i=arguments.length>1?arguments[1]:void 0,o=JN(e),a=ZN(r,{type:"URL"});if(void 0!==i)if(i instanceof nU)t=eD(i);else if(n=tU(t={},JN(i)))throw TypeError(n);if(n=tU(a,o,null,t))throw TypeError(n);var s=a.searchParams=new QN,u=XN(s);u.updateSearchParams(a.query),u.updateURL=function(){a.query=String(s)||null},MN||(r.href=iU.call(r),r.origin=oU.call(r),r.protocol=aU.call(r),r.username=sU.call(r),r.password=uU.call(r),r.host=cU.call(r),r.hostname=lU.call(r),r.port=fU.call(r),r.pathname=dU.call(r),r.search=pU.call(r),r.searchParams=hU.call(r),r.hash=yU.call(r))},rU=nU.prototype,iU=function(){var e=eD(this),t=e.scheme,n=e.username,r=e.password,i=e.host,o=e.port,a=e.path,s=e.query,u=e.fragment,c=t+":";return null!==i?(c+="//",CD(e)&&(c+=n+(r?":"+r:"")+"@"),c+=wD(i),null!==o&&(c+=":"+o)):"file"==t&&(c+="//"),c+=e.cannotBeABaseURL?a[0]:a.length?"/"+a.join("/"):"",null!==s&&(c+="?"+s),null!==u&&(c+="#"+u),c},oU=function(){var e=eD(this),t=e.scheme,n=e.port;if("blob"==t)try{return new nU(t.path[0]).origin}catch(e){return"null"}return"file"!=t&&RD(e)?t+"://"+wD(e.host)+(null!==n?":"+n:""):"null"},aU=function(){return eD(this).scheme+":"},sU=function(){return eD(this).username},uU=function(){return eD(this).password},cU=function(){var e=eD(this),t=e.host,n=e.port;return null===t?"":null===n?wD(t):wD(t)+":"+n},lU=function(){var e=eD(this).host;return null===e?"":wD(e)},fU=function(){var e=eD(this).port;return null===e?"":String(e)},dU=function(){var e=eD(this),t=e.path;return e.cannotBeABaseURL?t[0]:t.length?"/"+t.join("/"):""},pU=function(){var e=eD(this).query;return e?"?"+e:""},hU=function(){return eD(this).searchParams},yU=function(){var e=eD(this).fragment;return e?"#"+e:""},vU=function(e,t){return{get:e,set:t,configurable:!0,enumerable:!0}};if(MN&&UN(rU,{href:vU(iU,(function(e){var t=eD(this),n=JN(e),r=tU(t,n);if(r)throw TypeError(r);XN(t.searchParams).updateSearchParams(t.query)})),origin:vU(oU),protocol:vU(aU,(function(e){var t=eD(this);tU(t,JN(e)+":",LD)})),username:vU(sU,(function(e){var t=eD(this),n=WN(JN(e));if(!OD(t)){t.username="";for(var r=0;r<n.length;r++)t.username+=ED(n[r],SD)}})),password:vU(uU,(function(e){var t=eD(this),n=WN(JN(e));if(!OD(t)){t.password="";for(var r=0;r<n.length;r++)t.password+=ED(n[r],SD)}})),host:vU(cU,(function(e){var t=eD(this);t.cannotBeABaseURL||tU(t,JN(e),GD)})),hostname:vU(lU,(function(e){var t=eD(this);t.cannotBeABaseURL||tU(t,JN(e),$D)})),port:vU(fU,(function(e){var t=eD(this);OD(t)||(""==(e=JN(e))?t.port=null:tU(t,e,JD))})),pathname:vU(dU,(function(e){var t=eD(this);t.cannotBeABaseURL||(t.path=[],tU(t,JN(e),YD))})),search:vU(pU,(function(e){var t=eD(this);""==(e=JN(e))?t.query=null:("?"==e.charAt(0)&&(e=e.slice(1)),t.query="",tU(t,e,ZD)),XN(t.searchParams).updateSearchParams(t.query)})),searchParams:vU(hU),hash:vU(yU,(function(e){var t=eD(this);""!=(e=JN(e))?("#"==e.charAt(0)&&(e=e.slice(1)),t.fragment="",tU(t,e,eU)):t.fragment=null}))}),FN(rU,"toJSON",(function(){return iU.call(this)}),{enumerable:!0}),FN(rU,"toString",(function(){return iU.call(this)}),{enumerable:!0}),YN){var mU=YN.createObjectURL,gU=YN.revokeObjectURL;mU&&FN(nU,"createObjectURL",(function(e){return mU.apply(YN,arguments)})),gU&&FN(nU,"revokeObjectURL",(function(e){return gU.apply(YN,arguments)}))}function bU(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=jo(e);if(t){var i=jo(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Po(this,n)}}function wU(e){return function(e){if(Array.isArray(e))return um(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||cm(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.")}()}KN(nU,"URL"),LN({global:!0,forced:!NN,sham:!MN},{URL:nU}),function(e){var t=void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};Object.defineProperty(e,"__esModule",{value:!0});var n=Sv.exports,r=UR.exports,i=FR,o=xf.exports,a=Zm,s=hh;function u(e){return e&&"object"===Ao(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(o),h={exports:{}},y="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(y){var v=new Uint8Array(16);h.exports=function(){return y(v),v}}else{var m=new Array(16);h.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),m[t]=e>>>((3&t)<<3)&255;return m}}for(var g=[],b=0;b<256;++b)g[b]=(b+256).toString(16).substr(1);var w,x,k=function(e,t){var n=t||0,r=g;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("")},_=h.exports,S=k,E=0,T=0;var R=function(e,t,n){var r=t&&n||0,i=t||[],o=(e=e||{}).node||w,a=void 0!==e.clockseq?e.clockseq:x;if(null==o||null==a){var s=_();null==o&&(o=w=[1|s[0],s[1],s[2],s[3],s[4],s[5]]),null==a&&(a=x=16383&(s[6]<<8|s[7]))}var u=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:T+1,l=u-E+(c-T)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||u>E)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");E=u,T=c,x=a;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++]=a>>>8|128,i[r++]=255&a;for(var p=0;p<6;++p)i[r+p]=o[p];return t||S(i)},C=h.exports,O=k;var I=R,A=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||C)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var o=0;o<16;++o)t[r+o]=i[o];return t||O(i)},P=A;P.v1=I,P.v4=A;var j=P,L=function(e){Io(n,e);var t=bU(n);function n(e){var r;Do(this,n);var i,o=j.v4();return(r=t.call(this,(function(t,r){return i=r,e((function(e){n.cancellationMap.delete(o),t(e)}),(function(e){n.cancellationMap.delete(o),r(e)}),(function(e){n.cancellationMap.set(o,e)}))}))).id=o,r.rejectPromise=i,r}return No(n,[{key:"cancel",value:function(){var e=n.cancellationMap.get(this.id);return null==e||e(),this.rejectPromise&&(this.catch((function(){})),this.rejectPromise(new Error("Promise was cancelled"))),this}}]),n}(sM(Promise));function M(e,t,n,r){var i,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"===("undefined"==typeof Reflect?"undefined":Ao(Reflect))&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(o<3?i(a):o>3?i(t,n,a):i(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}function N(e,t){if("object"===("undefined"==typeof Reflect?"undefined":Ao(Reflect))&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function D(e,t){return["".concat((new Date).toISOString()," MCS Client ").concat(e,":")].concat(Array.from(t))}l.default(L,"cancellationMap",new Map);var U=function(){function e(t){Do(this,e),l.default(this,"prefix",""),this.prefix=null!=t&&t.length>0?t+" ":""}return No(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,D(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,D(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,D(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,D(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,D(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,D("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,D("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,D("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,D("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,D("E",t))}}]),e}(),F=function(e,t){return"".concat((n=e,n.startsWith("http")?"":function(e){return"https://mcs.".concat(null!=e?e:"us1",".twilio.com")}(t))).concat(e);var n},B=function(){function e(t,n,r,i){var o,a,s,u,c,l;Do(this,e);var f=null!==(o=null!==(a=i.MCS)&&void 0!==a?a:i)&&void 0!==o?o:{};this.region=null!==(s=null!==(u=f.region)&&void 0!==u?u:i.region)&&void 0!==s?s:"us1",this.mediaUrl=F(n,this.region),this.mediaSetUrl=r?F(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 No(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){Do(this,Media),this.config=e,this.network=t,this._update(n)}return No(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 L(function(){var t=f.default(d.default.mark((function t(n,r,i){var o,a;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=e.network.get("".concat(e.config.mediaUrl,"/").concat(e.sid)),i((function(){return o.cancel()})),t.prev=2,t.next=5,o;case 5:a=t.sent,e._update(a.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}(),q=function(e){Io(n,e);var t=bU(n);function n(e,r,i,o,a){var s;return Do(this,n),(s=t.call(this,e)).code=r,s.body=i,s.status=o,s.headers=a,s}return No(n)}(sM(Error)),z=t.XMLHttpRequest||{};var W,G=function(){function e(){Do(this,e)}return No(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 L((function(i,o,a){var s=new z,u=!1;for(var c in a((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}),{}):{},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}}(s);if(200<=s.status&&s.status<300)i({status:s.status,headers:t,body:n});else{var r,a,c=null!==(r=s.statusText)&&void 0!==r?r:"NONE";a="string"==typeof n?n&&1===n.split("\n",2).length?n:"":JSON.stringify(n);var l="".concat(s.status,": [").concat(c,"] ").concat(a);o(new q(l,s.status,n,c,t))}}},n)s.setRequestHeader(c,n[c]),"Content-Type"===c&&"application/json"===n[c]&&(r=JSON.stringify(r));s.send(r)}))}}]),e}(),$=U.scope("Network"),J=function(){function e(t,n){Do(this,e),this.config=t,this.transport=n}return No(e,[{key:"backoffConfig",value:function(){return Object.assign(B.backoffConfigDefault,this.config.backoffConfigOverride)}},{key:"retryWhenThrottled",value:function(){var e,t;return null!==(e=null!==(t=this.config.retryWhenThrottledOverride)&&void 0!==t?t:B.retryWhenThrottledDefault)&&void 0!==e&&e}},{key:"executeWithRetry",value:function(e,t){var n=this;return new L(function(){var r=f.default(d.default.mark((function r(i,o,s){var u,c;return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:u=new a.Retrier(n.backoffConfig()),c=[502,503,504],t&&c.push(429),s((function(){u.cancel(),u.removeAllListeners()})),u.on("attempt",f.default(d.default.mark((function t(){var n,r;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,n=e(),s((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(),o(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 o(e)})),u.on("failed",(function(e){return o(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 L(function(){var n=f.default(d.default.mark((function n(r,i,o){var a,s,u;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a={"X-Twilio-Token":t.config.token},s=t.executeWithRetry((function(){return t.transport.get(e,a)}),t.retryWhenThrottled()),$.trace("sending GET request to ",e," headers ",a),o((function(){return s.cancel()})),n.prev=4,n.next=7,s;case 7:u=n.sent,$.trace("response",u),r(u),n.next=16;break;case 12:n.prev=12,n.t0=n.catch(4),$.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,o){var a=this,s={"X-Twilio-Token":this.config.token};"undefined"!=typeof FormData&&r instanceof FormData||!i||Object.assign(s,{"Content-Type":i});var u=new URL(e);return n&&u.searchParams.append("Category",n),o&&u.searchParams.append("Filename",o),new L(function(){var n=f.default(d.default.mark((function n(i,o,c){var l,f;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return l=a.transport.post(u.href,s,r),c((function(){return l.cancel()})),$.trace("sending POST request to ".concat(e," with headers ").concat(s)),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 o(new TypeError("Posting FormData supported only with browser engine's FormData")),n.abrupt("return");case 14:return $.debug("post() error ".concat(n.t0)),o(n.t0),n.abrupt("return");case 17:$.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}(),K=U.scope("");e.default=(W=function(){function Client(e,t,n){var r,i;Do(this,Client);var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};this.options=o,this.options.logLevel=null!==(r=this.options.logLevel)&&void 0!==r?r:"silent",this.config=new B(e,t,n,this.options),K.setLevel(this.options.logLevel),this.options.transport=null!==(i=this.options.transport)&&void 0!==i?i:new G,this.transport=this.options.transport,this.network=new J(this.config,this.transport)}return No(Client,[{key:"updateToken",value:function(e){K.info("updateToken"),this.config.updateToken(e)}},{key:"get",value:function(e){var t=this;return new L(function(){var n=f.default(d.default.mark((function n(r,i,o){var a,s;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=t.network.get("".concat(t.config.mediaUrl,"/").concat(e)),o((function(){return a.cancel()})),n.prev=2,n.next=5,a;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,n,r){var i=this;return new L(function(){var o=f.default(d.default.mark((function o(a,s,u){var c,l;return d.default.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return c=i.network.post(i.config.mediaUrl,null!=n?n:"media",t,e,r),u((function(){return c.cancel()})),o.prev=2,o.next=5,c;case 5:l=o.sent,a(new Media(i.config,i.network,l.body)),o.next=12;break;case 9:o.prev=9,o.t0=o.catch(2),s(o.t0);case 12:case"end":return o.stop()}}),o,null,[[2,9]])})));return function(e,t,n){return o.apply(this,arguments)}}())}},{key:"postFormData",value:function(e,t){var n=this;return new L(function(){var r=f.default(d.default.mark((function r(i,o,a){var s,u;return d.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return s=n.network.post(n.config.mediaUrl,null!=t?t:"media",e),a((function(){return s.cancel()})),r.prev=2,r.next=5,s;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),o(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 L(function(){var n=f.default(d.default.mark((function n(r,i,o){var a,s,u,c;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a={command:"get",list:e.map((function(e){return{media_sid:e}}))},s=t.network.post("".concat(t.config.mediaSetUrl),null,a,"application/json"),o((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 L(function(){var n=f.default(d.default.mark((function n(r,i,o){var a,s,u,c;return d.default.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a={command:"get",list:e.map((function(e){return{media_sid:e}}))},s=t.network.post("".concat(t.config.mediaSetUrl),null,a,"application/json"),o((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}(),l.default(W,"version","0.6.0-rc.8"),W),M([s.validateTypes(s.nonEmptyString),N("design:type",Function),N("design:paramtypes",[String]),N("design:returntype",void 0)],e.default.prototype,"updateToken",null),M([s.validateTypesAsync(s.nonEmptyString),N("design:type",Function),N("design:paramtypes",[String]),N("design:returntype",L)],e.default.prototype,"get",null),e.default=M([s.validateConstructorTypes(s.nonEmptyString,s.nonEmptyString,[s.nonEmptyString,s.literal(null)],[s.pureObject,"undefined"]),N("design:paramtypes",[String,String,Object,Object])],e.default),e.CancellablePromise=L,e.Client=e.default,e.McsClient=e.default,e.McsMedia=Media,e.Media=Media}(cM);var xU=Dt,kU=Lt,_U=Px.aTypedArray;(0,Px.exportTypedArrayMethod)("at",(function(e){var t=_U(this),n=xU(t.length),r=kU(e),i=r>=0?r:n+r;return i<0||i>=n?void 0:t[i]}));var SU=sa,EU="ArrayBuffer",TU=Wk.ArrayBuffer;function RU(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=jo(e);if(t){var i=jo(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Po(this,n)}}Rn({global:!0,forced:i.ArrayBuffer!==TU},{ArrayBuffer:TU}),SU(EU);var CU=Tf.scope("Participant"),Participant=function(e){Io(Participant,e);var t,n,r,i=RU(Participant);function Participant(e,t,n,r,o){var a,s,u;if(Do(this,Participant),(u=i.call(this)).conversation=n,u.links=r,u.services=o,u.state={attributes:dh(e.attributes,"Retrieved malformed attributes from the server for participant: "+t,CU),dateCreated:e.dateCreated?fh(e.dateCreated):null,dateUpdated:e.dateCreated?fh(e.dateUpdated):null,sid:t,typingTimeout:null,isTyping:!1,identity:e.identity,roleSid:null!==(a=e.roleSid)&&void 0!==a?a:"",lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,lastReadTimestamp:e.lastConsumptionTimestamp?fh(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 No(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=dh(e.attributes,"Retrieved malformed attributes from the server for participant: "+this.state.sid,CU);e.attributes&&!om(this.state.attributes,n)&&(this.state.attributes=n,t.push("attributes"));var r=fh(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=fh(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 o=new Date(e.lastConsumptionTimestamp);this.state.lastReadTimestamp&&this.state.lastReadTimestamp.getTime()===o.getTime()||(this.state.lastReadTimestamp=o,t.push("lastReadTimestamp"))}return e.bindings&&!om(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=Ro(zc.mark((function e(){return zc.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=Ro(zc.mark((function e(){return zc.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=Ro(zc.mark((function e(t){return zc.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}(rm);function OU(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=jo(e);if(t){var i=jo(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Po(this,n)}}Lo(Participant,"typingStarted","typingStarted"),Lo(Participant,"typingEnded","typingEnded"),Lo(Participant,"updated","updated"),Gc([gv(bv),$c("design:type",Function),$c("design:paramtypes",[Object]),$c("design:returntype",Promise)],Participant.prototype,"updateAttributes",null);var IU=Tf.scope("Participants"),AU=function(e){Io(l,e);var t,n,r,i,o,a,s,u,c=OU(l);function l(e,t,n,r,i){var o;return Do(this,l),Lo(Co(o=c.call(this)),"rosterEntityPromise",null),o.conversation=e,o.participants=t,o.links=n,o.configuration=r,o.services=i,o}return No(l,[{key:"unsubscribe",value:(u=Ro(zc.mark((function e(){return zc.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){IU.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){IU.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){IU.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&&IU.error("Failed to get roster object for conversation",t.conversation.sid,e),IU.debug("ERROR: Failed to get roster object for conversation",t.conversation.sid,e),e}))}},{key:"upsertParticipantFromResponse",value:(s=Ro(zc.mark((function e(t){var n,r,i,o,a,s,u,c;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.sid,i=t.attributes,o=t.date_created,a=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(o),dateUpdated:new Date(a),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:(a=Ro(zc.mark((function e(t,n){var r,i,o=this;return zc.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 o.emit("participantUpdated",e)})),e.abrupt("return",r);case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"getParticipants",value:(o=Ro(zc.mark((function e(){var t=this;return zc.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 o.apply(this,arguments)})},{key:"getParticipantBySid",value:(i=Ro(zc.mark((function e(t){var n=this;return zc.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=Ro(zc.mark((function e(t){var n,r=this;return zc.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=Ro(zc.mark((function e(t,n){return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.participants,{identity:t,attributes:void 0!==n?JSON.stringify(n):void 0});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"addNonChatParticipant",value:(t=Ro(zc.mark((function e(t,n){var r,i,o,a,s=arguments;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=s.length>2&&void 0!==s[2]?s[2]:{},a=s.length>3&&void 0!==s[3]?s[3]:{},e.next=4,this.services.commandExecutor.mutateResource("post",this.links.participants,{attributes:void 0!==o?JSON.stringify(o):void 0,messaging_binding:{address:n,proxy_address:t,name:null==a||null===(r=a.email)||void 0===r?void 0:r.name,level:null==a||null===(i=a.email)||void 0===i?void 0:i.level}});case 4:return e.abrupt("return",e.sent);case 5: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}(rm),PU=Rn,jU=Mn,LU=Q,MU=Dt,NU=Sr,DU=a,UU=EE,FU=rc,BU=RE,qU=CE,zU=M,WU=IE,GU=[],$U=GU.sort,JU=DU((function(){GU.sort(void 0)})),KU=DU((function(){GU.sort(null)})),VU=FU("sort"),HU=!DU((function(){if(zU)return zU<70;if(!(BU&&BU>3)){if(qU)return!0;if(WU)return WU<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++)GU.push({k:t+r,v:n})}for(GU.sort((function(e,t){return t.v-e.v})),r=0;r<GU.length;r++)t=GU[r].k.charAt(0),i.charAt(i.length-1)!==t&&(i+=t);return"DGBEFHACIJK"!==i}}));PU({target:"Array",proto:!0,forced:JU||!KU||!VU||!HU},{sort:function(e){void 0!==e&&jU(e);var t=LU(this);if(HU)return void 0===e?$U.call(t):$U.call(t,e);var n,r,i=[],o=MU(t.length);for(r=0;r<o;r++)r in t&&i.push(t[r]);for(n=(i=UU(i,function(e){return function(t,n){return void 0===n?-1:void 0===t?1:void 0!==e?+e(t,n)||0:NU(t)>NU(n)?1:-1}}(e))).length,r=0;r<n;)t[r]=i[r++];for(;r<o;)delete t[r++];return t}});var YU=fM,QU=w,XU=Sr;Rn({target:"String",proto:!0,forced:!pM("includes")},{includes:function(e){return!!~XU(QU(this)).indexOf(XU(YU(e)),arguments.length>1?arguments[1]:void 0)}});var Media=function(){function Media(e,t){Do(this,Media),Lo(this,"mcsMedia",null),this.services=t,e instanceof cM.McsMedia&&(this.mcsMedia=e),this.state={sid:e.sid,category:e.category,filename:e.filename,contentType:e.contentType,size:e.size}}return No(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 cM.CancellablePromise(function(){var t=Ro(zc.mark((function t(n,r,i){var o,a,s,u;return zc.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=e._fetchMcsMedia(),s=null===(o=e.mcsMedia)||void 0===o?void 0:o.getContentUrl(),i((function(){a.cancel(),s&&s.cancel()})),t.prev=3,e.mcsMedia){t.next=9;break}return t.next=7,a;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 cM.CancellablePromise(function(){var t=Ro(zc.mark((function t(n,r,i){var o;return zc.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o=e.services.mcsClient.get(e.state.sid),!e.services.mcsClient){t.next=14;break}return i((function(){return o.cancel()})),t.prev=3,t.next=6,o;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){Do(this,AggregatedDeliveryReceipt),this.state=e}return No(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,o=this.undelivered===e.undelivered,a=this.failed===e.failed;return t&&n&&r&&i&&o&&a}}]),AggregatedDeliveryReceipt}(),ZU=function(){function e(t,n,r,i){Do(this,e),this.state={prevToken:r,nextToken:i,source:n,items:t}}return No(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=No((function DetailedDeliveryReceipt(e){Do(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})),eF={};function tF(e){return e&&"object"===Ao(e)&&"default"in e?e:{default:e}}Object.defineProperty(eF,"__esModule",{value:!0});var nF=tF(xf.exports),rF=function(e){var t=nF.default.getLevel();nF.default.setLevel("warn"),nF.default.warn(e),nF.default.setLevel(t)},iF=eF.deprecated=function(e,t,n){return function(r,i,o){if("function"!=typeof o.value&&void 0===(null==o?void 0:o.get))throw new Error("The deprecated decorator can only be applied to methods or getters");if("function"!=typeof o.value){var a=o.get;o.get=function(){return rF("The getter ".concat(e," is deprecated").concat(t?", use "+t+" instead":"").concat(n?", "+n:".")),null==a?void 0:a.apply(this)}}else{var s=o.value;o.value=function(){rF("The method ".concat(e," is deprecated").concat(t?", use "+t+" instead":"").concat(n?", "+n:"."));for(var r=arguments.length,i=new Array(r),o=0;o<r;o++)i[o]=arguments[o];return s.apply(this,i)}}}},oF=eF.deprecationWarning=rF;function aF(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 sF(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?aF(Object(n),!0).forEach((function(t){Lo(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):aF(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function uF(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=jo(e);if(t){var i=jo(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Po(this,n)}}var cF=Tf.scope("Message"),Message=function(e){Io(Message,e);var t,n,r,i,o,a,s,u=uF(Message);function Message(e,t,n,r,i,o){var a,s,c,l,f;return Do(this,Message),(f=u.call(this)).conversation=n,f.links=r,f.configuration=i,f.services=o,f.state={sid:t.sid,index:e,author:t.author,subject:t.subject,body:null!==(a=t.text)&&void 0!==a?a:null,timestamp:t.timestamp?new Date(t.timestamp):null,dateUpdated:t.dateUpdated?new Date(t.dateUpdated):null,lastUpdatedBy:null!==(s=t.lastUpdatedBy)&&void 0!==s?s:null,attributes:dh(t.attributes,"Got malformed attributes for the message ".concat(t.sid),cF),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(sF(sF({},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 No(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:"getMediaByCategory",value:function(e){return this.getMediaByCategories(e)}},{key:"getMediaByCategories",value:function(e){var t;return(null!==(t=this.state.medias)&&void 0!==t?t:[]).filter((function(t){return e.includes(t.category)}))}},{key:"getEmailBody",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategories(["body"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"getEmailHistory",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"text/plain";return null!==(e=null===(t=this.getMediaByCategories(["history"]))||void 0===t?void 0:t.filter((function(e){return e.contentType==n})).shift())&&void 0!==e?e:null}},{key:"_update",value:function(e){var t=[];!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=dh(e.attributes,"Got malformed attributes for the message ".concat(this.sid),cF);om(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=Ro(zc.mark((function e(){var t,n,r=this;return zc.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 cF.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 cF.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=Ro(zc.mark((function e(){var t,n;return zc.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(wU(n),wU(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:(o=Ro(zc.mark((function e(){return zc.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:"updateBody",value:(i=Ro(zc.mark((function e(t){return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{body:t});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"updateAttributes",value:(r=Ro(zc.mark((function e(t){return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.commandExecutor.mutateResource("post",this.links.self,{attributes:void 0!==t?JSON.stringify(t):void 0});case 2:return e.abrupt("return",this);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"attachTemporaryUrlsFor",value:(n=Ro(zc.mark((function e(t){var n,r=this;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=null==t?void 0:t.map((function(e){return e.sid})),!this.services.mcsClient||!n){e.next=7;break}return e.next=4,this.services.mcsClient.mediaSetGet(n);case 4:return e.abrupt("return",e.sent.map((function(e){return new Media(e,r.services)})));case 7:throw new Error("Media Content Service is unavailable");case 8:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"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 cM.CancellablePromise(function(){var n=Ro(zc.mark((function n(r,i,o){var a,s;return zc.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(a=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 o((function(){a.cancel()})),n.prev=5,n.next=8,a;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=Ro(zc.mark((function e(t){var n,r,i,o=this;return zc.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 ph(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 ZU(i.body.delivery_receipts.map((function(e){return new DetailedDeliveryReceipt(e)})),(function(e,t){return o._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}(rm);function lF(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 fF(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 fF(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function fF(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 dF(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=jo(e);if(t){var i=jo(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Po(this,n)}}Lo(Message,"updated","updated"),Gc([iF("getMediaByCategory","getMediaByCategories"),$c("design:type",Function),$c("design:paramtypes",[Array]),$c("design:returntype",Array)],Message.prototype,"getMediaByCategory",null),Gc([mv([dv,"undefined"]),$c("design:type",Function),$c("design:paramtypes",[Object]),$c("design:returntype",Media)],Message.prototype,"getEmailBody",null),Gc([mv([dv,"undefined"]),$c("design:type",Function),$c("design:paramtypes",[Object]),$c("design:returntype",Media)],Message.prototype,"getEmailHistory",null),Gc([gv("string"),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],Message.prototype,"updateBody",null),Gc([gv(bv),$c("design:type",Function),$c("design:paramtypes",[Object]),$c("design:returntype",Promise)],Message.prototype,"updateAttributes",null),Gc([iF("attachTemporaryUrlsFor","getTemporaryContentUrlsForMedia"),$c("design:type",Function),$c("design:paramtypes",[Array]),$c("design:returntype",Promise)],Message.prototype,"attachTemporaryUrlsFor",null),Gc([gv(fv("media",Media)),$c("design:type",Function),$c("design:paramtypes",[Array]),$c("design:returntype",cM.CancellablePromise)],Message.prototype,"getTemporaryContentUrlsForMedia",null),Gc([gv(fv("strings","string")),$c("design:type",Function),$c("design:paramtypes",[Array]),$c("design:returntype",cM.CancellablePromise)],Message.prototype,"getTemporaryContentUrlsForMediaSids",null);var pF=Tf.scope("Messages"),hF=function(e){Io(u,e);var t,n,r,i,o,a,s=dF(u);function u(e,t,n){var r;return Do(this,u),(r=s.call(this)).conversation=e,r.configuration=t,r.services=n,r.messagesByIndex=new Map,r.messagesListPromise=null,r}return No(u,[{key:"subscribe",value:(a=Ro(zc.mark((function e(t){var n,r=this;return zc.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){pF.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)?pF.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){pF.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){pF.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&&pF.error("Failed to get messages object for conversation",this.conversation.sid,e.t0),pF.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 a.apply(this,arguments)})},{key:"unsubscribe",value:(o=Ro(zc.mark((function e(){return zc.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 o.apply(this,arguments)})},{key:"sendV2",value:function(e){var t=this;return pF.debug("Sending message V2",e.mediaContent,e.attributes,e.emailOptions),new cM.CancellablePromise(function(){var n=Ro(zc.mark((function n(r,i,o){var a,s,u,c,l,f,d,p,h,y,v,m;return zc.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:s=[],u=[],o((function(){u.forEach((function(e){return e.cancel()}))})),c=lF(e.mediaContent),n.prev=4,c.s();case 6:if((l=c.n()).done){n.next=25;break}return f=lm(l.value,2),d=f[0],p=f[1],n.prev=8,pF.debug("Adding media to a message as ".concat(p instanceof FormData?"FormData":"SendMediaOptions"),p),v=p instanceof FormData?t.services.mcsClient.postFormData(p,d):t.services.mcsClient.post(null!==(h=p.contentType)&&void 0!==h?h:"",null!==(y=p.media)&&void 0!==y?y:"",d,p.filename),u.push(v),n.t0=s,n.next=15,v;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===(a=e.emailOptions)||void 0===a?void 0:a.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=Ro(zc.mark((function e(t){var n,r,i=arguments;return zc.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,pF.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=Ro(zc.mark((function e(t){var n,r,i,o,a,s=arguments;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=s.length>1&&void 0!==s[1]?s[1]:{},o=s.length>2?s[2]:void 0,pF.debug("Sending media message",t,i,o),pF.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 a=e.t0,e.next=16,this.services.commandExecutor.mutateResource("post",this.conversation._links.messages,{media_sids:[a.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=Ro(zc.mark((function e(t,n){var r,i=arguments;return zc.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,o=function(){return t.nextPage().then((function(t){return r._wrapPaginator(e,t,n)}))},a=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?o:a,nextPage:i?a:o}}))}},{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")},o=new Message(e,t,this.conversation,i,this.configuration,this.services);return this.messagesByIndex.set(o.index,o),o.on("updated",(function(e){return n.emit("messageUpdated",e)})),o}},{key:"_getMessages",value:(t=Ro(zc.mark((function e(){var t,n,r,i,o,a,s=this,u=arguments;return zc.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 o=e.sent,e.next=9,null==o?void 0:o.getItems({from:"end"!==n?n:void 0,pageSize:t,order:i,limit:t});case 9:return a=e.sent,e.next=12,this._wrapPaginator(i,a,(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}(rm),yF=function(){function e(t){Do(this,e),Lo(this,"attributes",{}),Lo(this,"mediaContent",[]),Lo(this,"emailOptions",{}),this.messagesEntity=t}return No(e,[{key:"send",value:function(){var e=this;return new cM.CancellablePromise(function(){var t=Ro(zc.mark((function t(n,r,i){var o,a;return zc.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=e.messagesEntity.sendV2(e),i((function(){return o.cancel()})),t.prev=2,t.next=5,o;case 5:a=t.sent,n(lh(a.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}(),vF=function(){function e(t,n){Do(this,e),this.limits=t,this.message=new yF(n),this.emailBodies=new Map,this.emailHistories=new Map}return No(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 mF(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 gF(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 gF(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function gF(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 bF(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=jo(e);if(t){var i=jo(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Po(this,n)}}var wF={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){Io(Conversation,e);var t,n,r,i,o,a,s,u,c,l,f,d,p,h,y,v,m,g,b,w,x,k,_,S,E,T,R,C,O=bF(Conversation);function Conversation(e,t,n,r,i){var o,a,s;Do(this,Conversation),(s=O.call(this)).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!==(o=e.attributes)&&void 0!==o?o:{},createdBy:e.createdBy,dateCreated:fh(e.dateCreated),dateUpdated:fh(e.dateUpdated),friendlyName:e.friendlyName||null,lastReadMessageIndex:Number.isInteger(e.lastConsumedMessageIndex)?e.lastConsumedMessageIndex:null,bindings:null!==(a=e.bindings)&&void 0!==a?a:{}},e.notificationLevel&&(s._internalState.notificationLevel=e.notificationLevel);var u={participants:s._links.participants};return s._participants=new Map,s._participantsEntity=new AU(Co(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 hF(Co(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 No(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:(C=Ro(zc.mark((function e(t,n){return zc.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 C.apply(this,arguments)})},{key:"addNonChatParticipant",value:(R=Ro(zc.mark((function e(t,n){var r,i,o=arguments;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=o.length>2&&void 0!==o[2]?o[2]:{},i=o.length>3&&void 0!==o[3]?o[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 R.apply(this,arguments)})},{key:"advanceLastReadMessageIndex",value:(T=Ro(zc.mark((function e(t){var n;return zc.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 T.apply(this,arguments)})},{key:"delete",value:(E=Ro(zc.mark((function e(){return zc.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 E.apply(this,arguments)})},{key:"getAttributes",value:(S=Ro(zc.mark((function e(){return zc.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:(_=Ro(zc.mark((function e(t,n,r){return zc.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:(k=Ro(zc.mark((function e(){return zc.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 k.apply(this,arguments)})},{key:"getParticipantsCount",value:(x=Ro(zc.mark((function e(){var t,n,r;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new ph(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 x.apply(this,arguments)})},{key:"getParticipantBySid",value:(w=Ro(zc.mark((function e(t){return zc.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=Ro(zc.mark((function e(){var t,n=arguments;return zc.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=Ro(zc.mark((function e(){var t,n,r;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new ph(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=Ro(zc.mark((function e(){var t,n,r;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new ph(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:(v=Ro(zc.mark((function e(){return zc.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:(y=Ro(zc.mark((function e(){return zc.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 y.apply(this,arguments)})},{key:"removeParticipant",value:(h=Ro(zc.mark((function e(t){return zc.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=Ro(zc.mark((function e(t,n,r){var i,o,a,s;return zc.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 a=e.sent,e.abrupt("return",null!==(o=lh(a.index))&&void 0!==o?o:0);case 5:return e.next=7,this._messagesEntity.sendMedia(t,n,r);case 7:return s=e.sent,e.abrupt("return",null!==(i=lh(s.index))&&void 0!==i?i:0);case 9:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return p.apply(this,arguments)})},{key:"prepareMessage",value:function(){return new vF(this.limits,this._messagesEntity)}},{key:"setAllMessagesRead",value:(d=Ro(zc.mark((function e(){var t;return zc.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=Ro(zc.mark((function e(){return zc.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=Ro(zc.mark((function e(t){return zc.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=Ro(zc.mark((function e(t){return zc.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=Ro(zc.mark((function e(t){return zc.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=Ro(zc.mark((function e(t){return zc.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=Ro(zc.mark((function e(t){return zc.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:(o=Ro(zc.mark((function e(){var t=this;return zc.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 o.apply(this,arguments)})},{key:"_fetchStreams",value:(i=Ro(zc.mark((function e(){var t,n,r;return zc.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=Ro(zc.mark((function e(){var t,n,r,i,o,a,s;return zc.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),o=null===(n=this._entity)||void 0===n?void 0:n.data,a=o.messages,s=o.roster,e.next=9,Promise.all([this._messagesEntity.subscribe(null!==(r=this._messagesList)&&void 0!==r?r:a),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=Ro(zc.mark((function e(){return zc.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,o;Conversation._logger.trace("_update",e),Conversation.preprocessUpdate(e,this.sid);for(var a=new Set,s=0,u=Object.keys(e);s<u.length;s++){var c=u[s],l=wF[c];if(l)switch(l){case wF.status:if(!e.status||"unknown"===e.status||this._internalState.status===e.status)break;this._internalState.status=e.status,a.add(l);break;case wF.attributes:if(om(this._internalState.attributes,e.attributes))break;this._internalState.attributes=e.attributes,a.add(l);break;case wF.lastConsumedMessageIndex:if(void 0===e.lastConsumedMessageIndex||e.lastConsumedMessageIndex===this._internalState.lastReadMessageIndex)break;this._internalState.lastReadMessageIndex=e.lastConsumedMessageIndex,a.add("lastReadMessageIndex");break;case wF.lastMessage:if(this._internalState.lastMessage&&!e.lastMessage){delete this._internalState.lastMessage,a.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,a.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,a.add(l)),om(this._internalState.lastMessage,{})&&delete this._internalState.lastMessage;break;case wF.state:var f=e.state||void 0;if(void 0!==f&&(f.dateUpdated=new Date(f.dateUpdated)),om(this._internalState.state,f))break;this._internalState.state=f,a.add(l);break;case wF.bindings:if(om(this._internalState.bindings,e.bindings))break;this._internalState.bindings=e.bindings,a.add(l);break;default:var d=e[c]instanceof Date,p=d&&(null===(o=this._internalState[l])||void 0===o?void 0:o.getTime())===e[c].getTime(),h=!d&&this[l]===e[c];if(p||h)break;this._internalState[l]=e[c],a.add(l)}}a.size>0&&this.emit("updated",{conversation:this,updateReasons:wU(a)})}},{key:"_onMessageAdded",value:function(e){var t,n=mF(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=Ro(zc.mark((function e(t){var n;return zc.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}(rm);Lo(Conversation,"participantJoined","participantJoined"),Lo(Conversation,"participantLeft","participantLeft"),Lo(Conversation,"participantUpdated","participantUpdated"),Lo(Conversation,"messageAdded","messageAdded"),Lo(Conversation,"messageRemoved","messageRemoved"),Lo(Conversation,"messageUpdated","messageUpdated"),Lo(Conversation,"typingEnded","typingEnded"),Lo(Conversation,"typingStarted","typingStarted"),Lo(Conversation,"updated","updated"),Lo(Conversation,"removed","removed"),Lo(Conversation,"_logger",Tf.scope("Conversation")),Gc([gv(dv,wv),$c("design:type",Function),$c("design:paramtypes",[String,Object]),$c("design:returntype",Promise)],Conversation.prototype,"add",null),Gc([gv(dv,dv,wv),$c("design:type",Function),$c("design:paramtypes",[String,String,Object,Object]),$c("design:returntype",Promise)],Conversation.prototype,"addNonChatParticipant",null),Gc([gv(pv),$c("design:type",Function),$c("design:paramtypes",[Number]),$c("design:returntype",Promise)],Conversation.prototype,"advanceLastReadMessageIndex",null),Gc([gv(["undefined",pv],["undefined",pv],["undefined",lv("backwards","forward")]),$c("design:type",Function),$c("design:paramtypes",[Number,Number,String]),$c("design:returntype",Promise)],Conversation.prototype,"getMessages",null),Gc([gv(dv),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],Conversation.prototype,"getParticipantBySid",null),Gc([gv(dv),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],Conversation.prototype,"getParticipantByIdentity",null),Gc([gv([dv,Participant]),$c("design:type",Function),$c("design:paramtypes",[Object]),$c("design:returntype",Promise)],Conversation.prototype,"removeParticipant",null),Gc([gv(["string",FormData,lv(null),hv("media options",{contentType:dv,media:cv((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"]}))})],wv,["undefined",lv(null),hv("email attributes",{subject:[dv,"undefined"]})]),$c("design:type",Function),$c("design:paramtypes",[Object,Object,Object]),$c("design:returntype",Promise)],Conversation.prototype,"sendMessage",null),Gc([gv(lv("default","muted")),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],Conversation.prototype,"setUserNotificationLevel",null),Gc([gv(bv),$c("design:type",Function),$c("design:paramtypes",[Object]),$c("design:returntype",Promise)],Conversation.prototype,"updateAttributes",null),Gc([gv("string"),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],Conversation.prototype,"updateFriendlyName",null),Gc([gv([lv(null),pv]),$c("design:type",Function),$c("design:paramtypes",[Number]),$c("design:returntype",Promise)],Conversation.prototype,"updateLastReadMessageIndex",null),Gc([gv(["string",lv(null)]),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],Conversation.prototype,"updateUniqueName",null);var xF=function(){function e(){var t=this;Do(this,e),this._promise=new Promise((function(e,n){t._resolve=e,t._reject=n}))}return No(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 kF(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 _F(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 _F(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 o,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function _F(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 SF(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 EF(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?SF(Object(n),!0).forEach((function(t){Lo(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):SF(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function TF(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=jo(e);if(t){var i=jo(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Po(this,n)}}var RF=Tf.scope("Conversations"),CF=function(e){Io(p,e);var t,n,r,i,o,a,s,u,c,l,f,d=TF(p);function p(e,t){var n;return Do(this,p),Lo(Co(n=d.call(this)),"conversations",new Map),Lo(Co(n),"myConversationsRead",new xF),Lo(Co(n),"tombstones",new Set),Lo(Co(n),"myConversationsFetched",!1),n.configuration=e,n.services=t,n}return No(p,[{key:"addConversation",value:(f=Ro(zc.mark((function e(t){var n,r,i,o,a,s,u,c,l,f;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=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!==o?JSON.stringify(o):void 0});case 3:if(a=e.sent,s=null!==(n=a.sid)&&void 0!==n?n:null,u=null!==(r=null===(i=a.sync_objects)||void 0===i?void 0:i.conversation)&&void 0!==r?r:null,c=EF({self:a.url},a.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=Ro(zc.mark((function e(){var t,n,r,i,o,a,s,u=this;return zc.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){RF.debug("itemAdded: ".concat(e.item.key)),u._upsertConversation("sync",e.item.key,e.item.data)})),t.on("itemRemoved",(function(e){RF.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){RF.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=kF(n);try{for(i.s();!(o=i.n()).done;)a=o.value,r.push(this._upsertConversation("rest",a.channel_sid,a))}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(),RF.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&&RF.error(s,e.t0),RF.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=Ro(zc.mark((function e(){var t,n,r=this;return zc.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=Ro(zc.mark((function e(t){var n,r,i,o=this;return zc.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 o._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=Ro(zc.mark((function e(t){var n,r,i,o,a;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new ph(this.configuration.links.myConversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,o=i.conversation_sid,a={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:o},e.abrupt("return",o?this._upsertConversation("sync",o,a):null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"peekConversation",value:(a=Ro(zc.mark((function e(t){var n,r,i,o;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new ph(this.configuration.links.conversations).path(t).build(),e.next=3,this.services.network.get(n);case 3:return r=e.sent,i=r.body,o={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,o));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"_getMap",value:(o=Ro(zc.mark((function e(){return zc.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 o.apply(this,arguments)})},{key:"_wrapPaginator",value:(i=Ro(zc.mark((function e(t,n){var r,i=this;return zc.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=Ro(zc.mark((function e(t,n,r){var i,o,a;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=void 0!==n._statusSource&&t!==n._statusSource,o="rest"!==t||"sync"===n._statusSource,!i||!o||"sync"===t){e.next=5;break}return RF.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),a={},void 0!==r.notificationLevel&&(a.notificationLevel=r.notificationLevel),void 0!==r.lastConsumedMessageIndex&&(a.lastConsumedMessageIndex=r.lastConsumedMessageIndex),om(a,{})||n._update(a),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=Ro(zc.mark((function e(t,n,r){var i,o,a,s;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(RF.trace("upsertConversation called for ".concat(n),r),!(i=this.conversations.get(n))){e.next=9;break}return RF.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 RF.trace("upsertChannel: the conversation is deleted but reappeared again from REST, ignoring",n),e.abrupt("return",null);case 12:return RF.trace("upsertConversation: creating a local conversation object with sid "+n,r),o="".concat(this.configuration.links.conversations,"/").concat(n),a={self:o,messages:"".concat(o,"/Messages"),participants:"".concat(o,"/Participants")},s=new Conversation(r,n,a,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 RF.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=Ro(zc.mark((function e(){var t,n,r,i,o,a;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=[],n=null;case 2:return i=new ph(this.configuration.links.myConversations),n&&i.arg("PageToken",n),e.next=6,this.services.network.get(i.build());case 6:o=e.sent,a=null===(r=o.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=o.body.meta.next_token,t=[].concat(wU(t),wU(a));case 10:if(n){e.next=2;break}case 11:return e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_onConversationRemoved",value:function(e){var t=this.conversations.get(e);t&&(this.conversations.delete(e),this.emit("conversationRemoved",t))}},{key:"_registerForEvents",value:function(e){var t=this;e.on("removed",(function(){return t._onConversationRemoved(e.sid)})),e.on("updated",(function(e){return t.emit("conversationUpdated",e)})),e.on("participantJoined",(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}(rm),OF=Rn,IF=Qr.find,AF=zf,PF="find",jF=!0;function LF(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=jo(e);if(t){var i=jo(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Po(this,n)}}PF in[]&&Array(1).find((function(){jF=!1})),OF({target:"Array",proto:!0,forced:jF},{find:function(e){return IF(this,e,arguments.length>1?arguments[1]:void 0)}}),AF(PF);var MF=function(e){Io(o,e);var t,n,r,i=LF(o);function o(e,t,n){var r;return Do(this,o),(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 No(o,[{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=Ro(zc.mark((function e(t,n){var r,i,o,a=this;return zc.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(o=new User(t,n,this.configuration,this.services)).on("updated",(function(e){return a.emit("userUpdated",e)})),o.on("userSubscribed",(function(){return a.handleSubscribeUser(o)})),o.on("userUnsubscribed",(function(){return a.handleUnsubscribeUser(o)})),e.next=20,o._ensureFetched();case 20:return e.abrupt("return",o);case 21:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"getSubscribedUsers",value:(n=Ro(zc.mark((function e(){var t;return zc.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=Ro(zc.mark((function e(t){var n,r,i,o;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=new ph(this.configuration.links.users).path(t).build(),e.next=3,this.services.network.get(i);case 3:return o=e.sent,e.abrupt("return",null!==(n=null===(r=o.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)})}]),o}(rm),NF=Tf.scope("TypingIndicator"),DF=function(){function e(t,n,r){Do(this,e),this.configuration=n,this.services=r,this.getConversation=t,this.serviceTypingTimeout=null,this.sentUpdates=new Map}var t;return No(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=Ro(zc.mark((function t(n,r){return zc.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n!==Dg.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=Ro(zc.mark((function e(t){var n=this;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:NF.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 NF.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;NF.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 NF.error("Failed to send typing indicator:",e),e}))}}]),e}(),PushNotification=No((function PushNotification(e){Do(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||{}})),UF="2.2.0-rc.11";function FF(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 BF(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?FF(Object(n),!0).forEach((function(t){Lo(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):FF(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var qF,zF,WF=function(e){return e.replace(/(^\/+|\/+$)/g,"")},GF=function(){function e(t,n,r){Do(this,e),this._serviceUrl=t,this._services=n,this._productId=r}var t,n,r;return No(e,[{key:"_preProcessUrl",value:function(e){var t=WF(e);return/^https?:\/\//.test(e)?t:"".concat(WF(this._serviceUrl),"/").concat(t)}},{key:"_makeRequest",value:(r=Ro(zc.mark((function e(t,n,r,i){var o,a,s,u;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=this._preProcessUrl(n),a=BF({"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=o,r&&(u+="?"+Object.entries(r).map((function(e){return e.map(encodeURIComponent).join("=")})).join("&")),e.next=9,this._services.transport.get(u,a,this._productId);case 9:return s=e.sent,e.abrupt("break",19);case 11:return e.next=13,this._services.transport.post(o,a,JSON.stringify(r),this._productId);case 13:return s=e.sent,e.abrupt("break",19);case 15:return e.next=17,this._services.transport.delete(o,a,{},this._productId);case 17:return s=e.sent,e.abrupt("break",19);case 19:if(!(s.status.code<200||s.status.code>=300)){e.next=21;break}throw new Error("Request responded with a non-success code ".concat(s.status.code));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=Ro(zc.mark((function e(t,n){var r,i=this;return zc.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=Ro(zc.mark((function e(t,n,r){var i;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._makeRequest(t,n,r,{"X-Twilio-Mutation-Id":ex.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 $F(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 JF(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?$F(Object(n),!0).forEach((function(t){Lo(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):$F(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function KF(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=jo(e);if(t){var i=jo(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return Po(this,n)}}var VF=No((function e(){Do(this,e)}));return e.Client=(qF=function(e){Io(Client,e);var t,n,r,i,o,a,s,u,c,l,f,d,p,h,y,v=KF(Client);function Client(e){var t,n,r,i,o,a,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Do(this,Client),Lo(Co(a=v.call(this)),"version",UF),Lo(Co(a),"connectionState","unknown"),Lo(Co(a),"parsePushNotification",zF.parsePushNotification),a._fpaToken=null!=e?e:"",a._options=null!=s?s:{},!a._options.disableDeepClone){var u=JF(JF({},a._options),{},{transport:void 0,twilsockClient:void 0});(u=ch(u)).transport=a._options.transport,u.twilsockClient=a._options.twilsockClient,a._options=u}a._options.logLevel=null!==(t=a._options.logLevel)&&void 0!==t?t:"silent",zF._logger.setLevel(a._options.logLevel);var c=a._options.productId="ip_messaging";if(a._options.clientMetadata=a._options.clientMetadata||{},a._options.clientMetadata.hasOwnProperty("type")||(a._options.clientMetadata.type="conversations"),a._options.clientMetadata.hasOwnProperty("sdk")||(a._options.clientMetadata.sdk="JS",a._options.clientMetadata.sdkv=UF),a._options.Sync=a._options.Sync||{},void 0===a._options.Sync.enableSessionStorage&&(a._options.Sync.enableSessionStorage=!0),a._options.region&&(a._options.Sync.region=a._options.region),!e)throw new Error("A valid Twilio token should be provided");a._services=new VF,a._myself=new User("","",null,a._services);var l=!a._options.twilsockClient;if(!a._options.initRegistrations){var f=new Fg.InitRegistration(c);zF.populateInitRegistrations(f),a._options.initRegistrations=[f]}a._services.twilsockClient=a._options.twilsockClient=null!==(n=a._options.twilsockClient)&&void 0!==n?n:new Fg.TwilsockClient(e,c,a._options),a._services.twilsockClient.on("tokenAboutToExpire",(function(){return a.emit("tokenAboutToExpire")})),a._services.twilsockClient.on("tokenExpired",(function(){return a.emit("tokenExpired")})),a._services.twilsockClient.on("connectionError",(function(e){return a.emit("connectionError",e)})),a._services.twilsockClient.on("stateChanged",(function(e){zF._logger.debug("Handling stateChanged for ConversationsClient: new state ".concat(e)),e!==a.connectionState&&(a.connectionState=e,a.emit("connectionStateChanged",a.connectionState))})),a._services.transport=a._options.transport=null!==(r=a._options.transport)&&void 0!==r?r:a._options.twilsockClient,a._services.notificationClient=a._options.notificationsClient=null!==(i=a._options.notificationsClient)&&void 0!==i?i:new DR.Notifications(e,a._options),a._services.syncClient=a._options.syncClient=null!==(o=a._options.syncClient)&&void 0!==o?o:new iM(e,a._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");a._services.commandExecutor=new GF(h,{transport:a._options.transport},c);var y=function(e){a._rejectEnsureReady(e),a.emit("stateChanged","failed"),a.emit("initFailed",{error:e})},m=function(){y({terminal:!0,message:"Twilsock has disconnected."})};return a._services.twilsockClient.on("connectionError",y),a._services.twilsockClient.on("disconnected",m),a._services.twilsockClient.on("connected",Ro(zc.mark((function e(){var t,n;return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return zF._logger.debug("ConversationsClient started INITIALIZING"),a._services.twilsockClient.off("connectionError",y),a._services.twilsockClient.off("disconnected",m),e.prev=3,t="conversations.client.startup",a._services.twilsockClient.addPartialTelemetryEvent(new Fg.TelemetryEventDescription(t,"Conversations client startup",new Date),t,Fg.TelemetryPoint.Start),e.next=8,a._initialize();case 8:a._services.twilsockClient.addPartialTelemetryEvent(new Fg.TelemetryEventDescription("","",new Date),t,Fg.TelemetryPoint.End),e.next=17;break;case 11:e.prev=11,e.t0=e.catch(3),n={terminal:!0,message:e.t0.message},a._rejectEnsureReady(n),a.emit("stateChanged","failed"),a.emit("initFailed",{error:n});case 17:case"end":return e.stop()}}),e,null,[[3,11]])})))),a._ensureReady=new Promise((function(e,t){a._resolveEnsureReady=e,a._rejectEnsureReady=t})).catch((function(){})),l&&a._services.twilsockClient.connect(),a}return No(Client,[{key:"user",get:function(){return this._myself}},{key:"reachabilityEnabled",get:function(){if(!this._configuration)throw new Error("Reachability information could not yet be accessed as the client has not yet been initialized. Subscribe to the 'stateChanged' event to properly react to the client initialization.");return this._configuration.reachabilityEnabled}},{key:"token",get:function(){return this._fpaToken}},{key:"shutdown",value:(y=Ro(zc.mark((function e(){return zc.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 y.apply(this,arguments)})},{key:"updateToken",value:(h=Ro(zc.mark((function e(t){return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:if(zF._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=Ro(zc.mark((function e(t){var n;return zc.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=12;break}return oF("The method getConversationBySid is deprecated to retrieve conversations you're not part of. Use peekConversationBySid instead."),e.next=11,this.peekConversationBySid(t);case 11:n=e.sent;case 12:if(n){e.next=14;break}throw new Error("Conversation with SID ".concat(t," was not found."));case 14:return e.abrupt("return",n);case 15:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"peekConversationBySid",value:(d=Ro(zc.mark((function e(t){var n;return zc.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 d.apply(this,arguments)})},{key:"getConversationByUniqueName",value:(f=Ro(zc.mark((function e(t){var n;return zc.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 f.apply(this,arguments)})},{key:"getSubscribedConversations",value:(l=Ro(zc.mark((function e(){return zc.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=Ro(zc.mark((function e(t){return zc.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=Ro(zc.mark((function e(t,n){return zc.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:(s=Ro(zc.mark((function e(t){return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:return this._unsubscribeFromPushNotifications(t),e.next=5,this._services.notificationClient.commitChanges();case 5:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"removePushRegistrations",value:(a=Ro(zc.mark((function e(t,n){return zc.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:(o=Ro(zc.mark((function e(t){return zc.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._ensureReady;case 2:zF._logger.debug("handlePushNotification, notificationPayload=",t),this.emit("pushNotification",zF.parsePushNotification(t));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"getUser",value:(i=Ro(zc.mark((function e(t){return zc.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=Ro(zc.mark((function e(){return zc.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 cM.CancellablePromise(function(){var n=Ro(zc.mark((function n(r,i,o){var a,s;return zc.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 a=t._services.mcsClient.mediaSetGetContentUrls(e),o((function(){a.cancel()})),n.prev=5,n.next=8,a;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:(n=Ro(zc.mark((function e(){var t,n=this;return zc.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 Df(this._options,t,zF._logger),this._myself._resolveInitialization(this._configuration,this._configuration.userIdentity,this._configuration.userInfo,!0),this._services.typingIndicator=new DF(this.getConversationBySid.bind(this),this._configuration,this._services),this._services.network=new Ng(this._configuration,this._services),this._services.users=new MF(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 CF(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:zF._supportedPushChannels.forEach((function(e){return n._subscribeToPushNotifications(e)})),this._services.typingIndicator.initialize(),this._services.mcsClient=new cM.McsClient(this._fpaToken,this._configuration.links.mediaService,this._configuration.links.mediaSetService,JF(JF({},this._options),{},{transport:void 0})),this._resolveEnsureReady(),this.emit("stateChanged","initialized"),this.emit("initialized",{});case 34:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"_subscribeToPushNotifications",value:function(e){var t=this;[Dg.NEW_MESSAGE,Dg.ADDED_TO_CONVERSATION,Dg.REMOVED_FROM_CONVERSATION,Dg.TYPING_INDICATOR,Dg.CONSUMPTION_UPDATE].forEach((function(n){t._services.notificationClient.subscribe(e,n)}))}},{key:"_unsubscribeFromPushNotifications",value:function(e){var t=this;[Dg.NEW_MESSAGE,Dg.ADDED_TO_CONVERSATION,Dg.REMOVED_FROM_CONVERSATION,Dg.TYPING_INDICATOR,Dg.CONSUMPTION_UPDATE].forEach((function(n){t._services.notificationClient.unsubscribe(e,n)}))}}],[{key:"create",value:(t=Ro(zc.mark((function e(t,n){var r;return zc.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 zF(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(zF._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=zF._parsePushNotificationChatData(e),o=e.aps,a=null;if("string"==typeof o.alert)t=o.alert||null;else t=(null===(n=o.alert)||void 0===n?void 0:n.body)||null,a=(null===(r=o.alert)||void 0===r?void 0:r.title)||null;return new PushNotification({title:a,body:t,sound:o.sound||null,badge:o.badge||null,action:o.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=zF._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 zF._supportedPushDataFields){var r=e[n];if(null!=r)if("message_index"!==n&&"media_count"!==n){if("media"!==n)t[zF._supportedPushDataFields[n]]=r;else if("string"==typeof r)try{t[zF._supportedPushDataFields[n]]=JSON.parse(r)}catch(e){zF._logger.debug("Media message notification parsing error")}}else{var i=lh(r);null!==i&&(t[zF._supportedPushDataFields[n]]=i)}}return t}},{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([Dg.TYPING_INDICATOR]),iM.populateInitRegistrations(e)}}]),Client}(rm),Lo(qF,"conversationAdded","conversationAdded"),Lo(qF,"conversationJoined","conversationJoined"),Lo(qF,"conversationLeft","conversationLeft"),Lo(qF,"conversationRemoved","conversationRemoved"),Lo(qF,"conversationUpdated","conversationUpdated"),Lo(qF,"participantJoined","participantJoined"),Lo(qF,"participantLeft","participantLeft"),Lo(qF,"participantUpdated","participantUpdated"),Lo(qF,"messageAdded","messageAdded"),Lo(qF,"messageRemoved","messageRemoved"),Lo(qF,"messageUpdated","messageUpdated"),Lo(qF,"tokenAboutToExpire","tokenAboutToExpire"),Lo(qF,"tokenExpired","tokenExpired"),Lo(qF,"typingEnded","typingEnded"),Lo(qF,"typingStarted","typingStarted"),Lo(qF,"pushNotification","pushNotification"),Lo(qF,"userSubscribed","userSubscribed"),Lo(qF,"userUnsubscribed","userUnsubscribed"),Lo(qF,"userUpdated","userUpdated"),Lo(qF,"stateChanged","stateChanged"),Lo(qF,"initialized","initialized"),Lo(qF,"initFailed","initFailed"),Lo(qF,"connectionStateChanged","connectionStateChanged"),Lo(qF,"connectionError","connectionError"),Lo(qF,"version",UF),Lo(qF,"_logger",Tf.scope("Client")),Lo(qF,"_supportedPushChannels",["fcm","apn"]),Lo(qF,"_supportedPushDataFields",{conversation_sid:"conversationSid",conversation_title:"conversationTitle",message_sid:"messageSid",message_index:"messageIndex",media_count:"mediaCount",media:"media"}),zF=qF),Gc([iF("token"),$c("design:type",String),$c("design:paramtypes",[])],e.Client.prototype,"token",null),Gc([gv(dv),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],e.Client.prototype,"updateToken",null),Gc([gv(dv),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],e.Client.prototype,"getConversationBySid",null),Gc([gv(dv),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],e.Client.prototype,"peekConversationBySid",null),Gc([gv(dv),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],e.Client.prototype,"getConversationByUniqueName",null),Gc([gv(["undefined",hv("conversation options",{friendlyName:["string","undefined"],isPrivate:["boolean","undefined"],uniqueName:["string","undefined"]})]),$c("design:type",Function),$c("design:paramtypes",[Object]),$c("design:returntype",Promise)],e.Client.prototype,"createConversation",null),Gc([gv(lv("fcm","apn"),"string"),$c("design:type",Function),$c("design:paramtypes",[String,String]),$c("design:returntype",Promise)],e.Client.prototype,"setPushRegistrationId",null),Gc([gv(lv("fcm","apn")),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],e.Client.prototype,"unsetPushRegistrationId",null),Gc([gv(lv("fcm","apn"),dv),$c("design:type",Function),$c("design:paramtypes",[String,String]),$c("design:returntype",Promise)],e.Client.prototype,"removePushRegistrations",null),Gc([gv(yv),$c("design:type",Function),$c("design:paramtypes",[Object]),$c("design:returntype",Promise)],e.Client.prototype,"handlePushNotification",null),Gc([gv(dv),$c("design:type",Function),$c("design:paramtypes",[String]),$c("design:returntype",Promise)],e.Client.prototype,"getUser",null),Gc([gv(fv("strings","string")),$c("design:type",Function),$c("design:paramtypes",[Array]),$c("design:returntype",cM.CancellablePromise)],e.Client.prototype,"getTemporaryContentUrlsForMediaSids",null),Gc([gv(fv("media",Media)),$c("design:type",Function),$c("design:paramtypes",[Array]),$c("design:returntype",cM.CancellablePromise)],e.Client.prototype,"getTemporaryContentUrlsForMedia",null),Gc([iF("Client.create()","new Client()"),gv("string",["undefined",yv]),$c("design:type",Function),$c("design:paramtypes",[String,Object]),$c("design:returntype",Promise)],e.Client,"create",null),Gc([mv(yv),$c("design:type",Function),$c("design:paramtypes",[Object]),$c("design:returntype",PushNotification)],e.Client,"parsePushNotification",null),e.Client=zF=Gc([vv(dv,[yv,"undefined"]),$c("design:paramtypes",[String,Object])],e.Client),e.AggregatedDeliveryReceipt=AggregatedDeliveryReceipt,e.CancellablePromise=cM.CancellablePromise,e.Conversation=Conversation,e.DetailedDeliveryReceipt=DetailedDeliveryReceipt,e.Media=Media,e.Message=Message,e.MessageBuilder=vF,e.NotificationTypes=Dg,e.Participant=Participant,e.PushNotification=PushNotification,e.RestPaginator=ZU,e.UnsentMessage=yF,e.User=User,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|