@amityco/ts-sdk 6.3.1 → 6.3.2-3fa3a47.0

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.
Files changed (50) hide show
  1. package/dist/@types/domains/channel.d.ts +1 -1
  2. package/dist/@types/domains/channel.d.ts.map +1 -1
  3. package/dist/@types/domains/user.d.ts +1 -0
  4. package/dist/@types/domains/user.d.ts.map +1 -1
  5. package/dist/channelRepsitory/channelMembership/observers/getMembers.d.ts.map +1 -1
  6. package/dist/client/api/logout.d.ts.map +1 -1
  7. package/dist/client/api/setSessionState.d.ts.map +1 -1
  8. package/dist/commentRepository/api/tests/deleteComment.test.d.ts +2 -0
  9. package/dist/commentRepository/api/tests/deleteComment.test.d.ts.map +1 -0
  10. package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
  11. package/dist/core/model/index.d.ts +1 -1
  12. package/dist/core/model/index.d.ts.map +1 -1
  13. package/dist/core/transports/mqtt.d.ts.map +1 -1
  14. package/dist/index.cjs.js +179 -75
  15. package/dist/index.esm.js +179 -75
  16. package/dist/index.umd.js +2 -2
  17. package/dist/userRepository/observers/getUsers.d.ts.map +1 -1
  18. package/dist/userRepository/observers/index.d.ts +1 -0
  19. package/dist/userRepository/observers/index.d.ts.map +1 -1
  20. package/dist/userRepository/observers/searchUserByDisplayName.d.ts +19 -0
  21. package/dist/userRepository/observers/searchUserByDisplayName.d.ts.map +1 -0
  22. package/dist/userRepository/observers/tests/searchUserByDisplayName.test.d.ts +2 -0
  23. package/dist/userRepository/observers/tests/searchUserByDisplayName.test.d.ts.map +1 -0
  24. package/dist/utils/isEqual.d.ts +17 -0
  25. package/dist/utils/isEqual.d.ts.map +1 -0
  26. package/dist/utils/liveObject.d.ts.map +1 -1
  27. package/dist/utils/tests/isEquals.test.d.ts +2 -0
  28. package/dist/utils/tests/isEquals.test.d.ts.map +1 -0
  29. package/package.json +1 -1
  30. package/src/@types/domains/channel.ts +1 -1
  31. package/src/@types/domains/user.ts +2 -0
  32. package/src/channelRepsitory/channelMembership/observers/getMembers.ts +17 -15
  33. package/src/channelRepsitory/channelMembership/observers/tests/getMembers.test.ts +0 -62
  34. package/src/channelRepsitory/channelMembership/observers/tests/searchMembers.test.ts +0 -31
  35. package/src/client/api/logout.ts +13 -10
  36. package/src/client/api/setSessionState.ts +7 -2
  37. package/src/commentRepository/api/tests/deleteComment.test.ts +60 -0
  38. package/src/communityRepository/communityMembership/observers/getMembers.ts +14 -10
  39. package/src/communityRepository/communityMembership/observers/tests/getMembers.test.ts +1 -27
  40. package/src/core/model/index.ts +2 -11
  41. package/src/core/transports/mqtt.ts +14 -24
  42. package/src/messageRepository/observers/getMessages.ts +1 -1
  43. package/src/userRepository/observers/getUsers.ts +18 -11
  44. package/src/userRepository/observers/index.ts +1 -0
  45. package/src/userRepository/observers/searchUserByDisplayName.ts +30 -0
  46. package/src/userRepository/observers/tests/getUsers.test.ts +1 -29
  47. package/src/userRepository/observers/tests/searchUserByDisplayName.test.ts +113 -0
  48. package/src/utils/isEqual.ts +69 -0
  49. package/src/utils/liveObject.ts +21 -2
  50. package/src/utils/tests/isEquals.test.ts +86 -0
package/dist/index.umd.js CHANGED
@@ -1,6 +1,6 @@
1
- var Amity=function(e){"use strict";const t=Object.freeze({ONLY_ADMIN_CAN_POST:"ONLY_ADMIN_CAN_POST",ADMIN_REVIEW_POST_REQUIRED:"ADMIN_REVIEW_POST_REQUIRED",ANYONE_CAN_POST:"ANYONE_CAN_POST"}),n=Object.freeze({ONLY_ADMIN_CAN_POST:{needApprovalOnPostCreation:!1,onlyAdminCanPost:!0},ADMIN_REVIEW_POST_REQUIRED:{needApprovalOnPostCreation:!0,onlyAdminCanPost:!1},ANYONE_CAN_POST:{needApprovalOnPostCreation:!1,onlyAdminCanPost:!1}}),r="ONLY_ADMIN_CAN_POST",o=Object.freeze({STORY:"story",CLIP:"clip",CHAT:"chat",POST:"post",MESSAGE:"message"}),s=Object.freeze({FILE:"file",IMAGE:"image",VIDEO:"video"}),i=Object.freeze({"1080P":"1080p","720P":"720p","480P":"480p","360P":"360p",ORIGINAL:"original"}),a=Object.freeze({UPLOADED:"uploaded",TRANSCODING:"transcoding",TRANSCODED:"transcoded",TRANSCODE_FAILED:"transcodeFailed"}),c=Object.freeze({LOW:"low",MEDIUM:"medium",HIGH:"high",ORIGINAL:"original"}),l=Object.freeze({TEXT:"text",IMAGE:"image",FILE:"file",VIDEO:"video",AUDIO:"audio",CUSTOM:"custom"}),u=Object.freeze({TEXT:"text",IMAGE:"image",FILE:"file",VIDEO:"video",LIVESTREAM:"liveStream",POLL:"poll",CUSTOM:"custom"});const d=function(){try{return"v6.3.1-umd"}catch(e){return"__dev__"}}(),h=5,f="cache_then_server",p="For using Live Collection feature you need to enable Cache!",g=6e5,m="dead",y=2e3,v=6e4,b=e=>JSON.stringify(e,((e,t)=>{return"object"==typeof t?(n=t,Object.keys(n).sort().reduce(((e,t)=>Object.assign(Object.assign({},e),{[t]:n[t]})),{})):t;var n})),w=e=>JSON.parse(e),C=(e,t)=>e===t||!(!e||!t)&&("object"==typeof e&&Object.keys(e).every((n=>C(e[n],t[n])))),_=e=>[400400,400300].includes(e),k="function"==typeof atob,S="function"==typeof btoa,A="function"==typeof Buffer,E="function"==typeof TextDecoder?new TextDecoder:void 0,I="function"==typeof TextEncoder?new TextEncoder:void 0,O=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),T=(e=>{let t={};return e.forEach(((e,n)=>t[e]=n)),t})(O),x=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,R=String.fromCharCode.bind(String),P="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):(e,t=(e=>e))=>new Uint8Array(Array.prototype.slice.call(e,0).map(t)),M=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),j=S?e=>btoa(e):A?e=>Buffer.from(e,"binary").toString("base64"):e=>{let t,n,r,o,s="";const i=e.length%3;for(let i=0;i<e.length;){if((n=e.charCodeAt(i++))>255||(r=e.charCodeAt(i++))>255||(o=e.charCodeAt(i++))>255)throw new TypeError("invalid character found");t=n<<16|r<<8|o,s+=O[t>>18&63]+O[t>>12&63]+O[t>>6&63]+O[63&t]}return i?s.slice(0,i-3)+"===".substring(i):s},F=A?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let n=0,r=e.length;n<r;n+=4096)t.push(R.apply(null,e.subarray(n,n+4096)));return j(t.join(""))},N=e=>{if(e.length<2)return(t=e.charCodeAt(0))<128?e:t<2048?R(192|t>>>6)+R(128|63&t):R(224|t>>>12&15)+R(128|t>>>6&63)+R(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return R(240|t>>>18&7)+R(128|t>>>12&63)+R(128|t>>>6&63)+R(128|63&t)},B=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,U=A?e=>Buffer.from(e,"utf8").toString("base64"):I?e=>F(I.encode(e)):e=>j(e.replace(B,N)),D=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,L=e=>{switch(e.length){case 4:var t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return R(55296+(t>>>10))+R(56320+(1023&t));case 3:return R((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return R((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},q=k?e=>atob(M(e)):A?e=>Buffer.from(e,"base64").toString("binary"):e=>{if(e=e.replace(/\s+/g,""),!x.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let t,n,r,o="";for(let s=0;s<e.length;)t=T[e.charAt(s++)]<<18|T[e.charAt(s++)]<<12|(n=T[e.charAt(s++)])<<6|(r=T[e.charAt(s++)]),o+=64===n?R(t>>16&255):64===r?R(t>>16&255,t>>8&255):R(t>>16&255,t>>8&255,255&t);return o},$=A?e=>P(Buffer.from(e,"base64")):e=>P(q(e),(e=>e.charCodeAt(0))),z=A?e=>Buffer.from(e,"base64").toString("utf8"):E?e=>E.decode($(e)):e=>q(e).replace(D,L),H=e=>z(M(e.replace(/[-_]/g,(e=>"-"==e?"+":"/")))),V=e=>["skip"].some((t=>t in e)),W=e=>["after","before","first","last","limit"].some((t=>t in e)),K=e=>"limit"in e,Q=e=>(null==e?void 0:e.hasOwnProperty("data"))&&(null==e?void 0:e.hasOwnProperty("nextPage"))&&(null==e?void 0:e.hasOwnProperty("prevPage")),J=(e,t)=>{var n;if(!e||!Object.keys(e).length)return;let r={};return"skiplimit"===t?r={skip:null!==(n=e.after)&&void 0!==n?n:0,limit:e.limit}:"afterbefore"===t&&W(e)?Number.isNaN(Number(null==e?void 0:e.before))?Number.isNaN(Number(null==e?void 0:e.after))?Number.isNaN(Number(null==e?void 0:e.limit))||(r={last:e.limit}):r={after:e.after,first:e.limit}:r={before:e.before,last:e.limit}:"afterbeforeraw"===t&&(r=e),Object.keys(r).length?((e,t=!1)=>t?(e=>e.replace(/=/g,"").replace(/[+\/]/g,(e=>"+"==e?"-":"_")))(U(e)):U(e))(JSON.stringify(r)):void 0},G=e=>{if(!e)return;const t=JSON.parse(H(e));if(V(t))return{after:t.skip,limit:t.limit};if(W(t)){if("before"in t)return{before:t.before,limit:t.last};if("after"in t)return{after:t.after,limit:t.first}}},Y=e=>{if(!e)return;const t=JSON.parse(H(e));return K(t)?t:void 0},X=e=>"locally"in e,Z=e=>"optimistically"in e,ee=e=>X(e)||Z(e),te=e=>null==e?void 0:e.hasOwnProperty("cachedAt"),ne=(e,t=6e4)=>{var n;return Date.now()-(null!==(n=null==e?void 0:e.cachedAt)&&void 0!==n?n:0)<=t},re=(e,...t)=>({func:e,args:t}),oe=(e,t=6e4)=>"cache_only"===e?{lifeSpan:1/0}:{lifeSpan:t<v?v:t},se=({func:e,args:t},n,r=oe("cache_then_server"))=>{let o;const{lifeSpan:s}=oe("cache_then_server",r.lifeSpan);if(ee(e)){try{o=Z(e)?e.optimistically(...t):e.locally(...t)}catch(e){null==n||n(ie(void 0,{origin:"local",loading:!1,error:e}))}const r=te(o)&&ne(o,s);if(null==n||n(ie(o,{origin:"local",loading:!(X(e)&&r)})),r)return}else null==n||n(ie(void 0,{origin:"local",loading:!0}));e(...t).then((e=>{null==n||n(ie(e,{origin:"server",loading:!1}))})).catch((e=>{null==n||n(ie(void 0,{origin:"server",loading:!1,error:e}))}))};function ie(e,t){return Q(e)||te(e)?Object.assign(Object.assign({},t),e):Object.assign(Object.assign({},t),{data:e})}const ae={user:({userId:e})=>e,file:({fileId:e})=>e,role:({roleId:e})=>e,channel:({channelId:e})=>e,subChannel:({subChannelId:e})=>e,channelUsers:({channelId:e,userId:t})=>`${e}#${t}`,message:({messageId:e})=>e,channelMarker:({entityId:e,userId:t})=>`${e}#${t}`,subChannelMarker:({entityId:e,feedId:t,userId:n})=>`${e}#${t}#${n}`,messageMarker:({feedId:e,contentId:t,creatorId:n})=>`${e}#${t}#${n}`,feedMarker:({feedId:e,entityId:t})=>`${e}#${t}`,userMarker:({userId:e})=>e,community:({communityId:e})=>e,category:({categoryId:e})=>e,communityUsers:({communityId:e,userId:t})=>`${e}#${t}`,post:({postId:e})=>e,comment:({commentId:e})=>e,poll:({pollId:e})=>e,reaction:({reactionId:e})=>e,stream:({streamId:e})=>e,follow:({from:e,to:t})=>`${e}#${t}`,followInfo:({userId:e})=>e,followCount:({userId:e})=>e,feed:({targetId:e,feedId:t})=>`${e}#${t}`},ce=e=>ae[e],le={file:["fileId","attributes"],user:["userId","avatarFileId"],role:["roleId"],channel:["channelId","rateLimit"],subChannel:["subChannelId"],channelUsers:["channelId","userId","membership"],message:["messageId"],community:["communityId","postSetting"],category:["categoryId"],communityUsers:["userId","communityId","communityMembership"],post:["postId","feedId"],comment:["commentId","referenceId"],poll:["pollId"],reaction:["reactionId"],stream:["streamId"],follow:["from","to"],feed:["feedId","feedType"],followInfo:["userId","status"],followCount:["userId","followerCount"]},ue=e=>{var t;return null===(t=Object.entries(le).find((([t,n])=>((e,t)=>{const n=Object.keys(e);return t.every((e=>n.includes(e)))})(e,n))))||void 0===t?void 0:t[0]},de=e=>{var t;const n=ue(e);if(n)return null===(t=le[n])||void 0===t?void 0:t[0]},he={users:"user",files:"file",roles:"role",channels:"channel",messageFeeds:"subChannel",channelUsers:"channelUsers",messages:"message",userEntityMarkers:"channelMarker",userFeedMarkers:"subChannelMarker",contentMarkers:"messageMarker",feedMarkers:"feedMarker",userMarkers:"userMarker",communities:"community",categories:"category",communityUsers:"communityUsers",posts:"post",postChildren:"post",comments:"comment",polls:"poll",reactions:"reaction",videoStreamings:"stream",follows:"follow",followCounts:"followCount",feeds:"feed"},fe=(e,t)=>!("updatedAt"in e)||!("updatedAt"in t)||new Date(e.updatedAt)<new Date(t.updatedAt);function pe(e=(new Date).toISOString()){return new Date(new Date(e).getTime()+1).toISOString()}class ge extends Error{constructor(e,t,n){super(`Amity SDK (${t}): ${e}`),this.code=t,this.level=n,this.type="ASC",this.timestamp=Date.now(),Error.captureStackTrace&&Error.captureStackTrace(this,ge)}}class me extends ge{constructor(e,t,n){super(e,t,n)}}class ye extends ge{constructor(e=8e5,t="fatal"){super("Unexpected error",e,t)}}class ve extends ge{constructor(e,t="SDK client is having connection issues"){super(`${t} (${e})`,"disconnected"===e?800211:800210,"error"),this.event=e}}let be=null;const we=()=>{if(!be)throw new ge("There is no active client",8e5,"fatal");return be},Ce=e=>{be=e};var _e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ke(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Se(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}const Ae=e=>{if("[object Object]"!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype},{hasOwnProperty:Ee}=Object.prototype,{propertyIsEnumerable:Ie}=Object,Oe=(e,t,n)=>Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}),Te=_e,xe={concatArrays:!1,ignoreUndefined:!1},Re=e=>{const t=[];for(const n in e)Ee.call(e,n)&&t.push(n);if(Object.getOwnPropertySymbols){const n=Object.getOwnPropertySymbols(e);for(const r of n)Ie.call(e,r)&&t.push(r)}return t};function Pe(e){return Array.isArray(e)?function(e){const t=e.slice(0,0);return Re(e).forEach((n=>{Oe(t,n,Pe(e[n]))})),t}(e):Ae(e)?function(e){const t=null===Object.getPrototypeOf(e)?Object.create(null):{};return Re(e).forEach((n=>{Oe(t,n,Pe(e[n]))})),t}(e):e}const Me=(e,t,n,r)=>(n.forEach((n=>{void 0===t[n]&&r.ignoreUndefined||(n in e&&e[n]!==Object.getPrototypeOf(e)?Oe(e,n,je(e[n],t[n],r)):Oe(e,n,Pe(t[n])))})),e);function je(e,t,n){return n.concatArrays&&Array.isArray(e)&&Array.isArray(t)?((e,t,n)=>{let r=e.slice(0,0),o=0;return[e,t].forEach((t=>{const s=[];for(let n=0;n<t.length;n++)Ee.call(t,n)&&(s.push(String(n)),Oe(r,o++,t===e?t[n]:Pe(t[n])));r=Me(r,t,Re(t).filter((e=>!s.includes(e))),n)})),r})(e,t,n):Ae(t)&&Ae(e)?Me(e,t,Re(t),n):Pe(t)}const Fe=function(...e){const t=je(Pe(xe),this!==Te&&this||{},xe);let n={_:{}};for(const r of e)if(void 0!==r){if(!Ae(r))throw new TypeError("`"+r+"` is not an Option Object");n=je(n,{_:r},t)}return n._}.bind({concatArrays:!0,ignoreUndefined:!0});function Ne(e,t){return new Promise(((n,r)=>{try{const r=e();null==t||t(null,r),n(r)}catch(e){null==t||t(e),r(e)}}))}function Be(e,t,n){return Promise.all(e).then((e=>{var r;const o=null!==(r=null==n?void 0:n(e))&&void 0!==r?r:null;return null==t||t(null,o),Promise.resolve(o)}),(e=>(null==t||t(e),Promise.reject(e))))}const Ue={getItem:(e,t)=>Ne((()=>window.localStorage.getItem(e)),t),setItem:(e,t,n)=>Ne((()=>window.localStorage.setItem(e,t)),n),removeItem:(e,t)=>Ne((()=>window.localStorage.removeItem(e)),t),mergeItem:(e,t,n)=>Ne((()=>function(e,t){const n=window.localStorage.getItem(e);if(n){const r=JSON.parse(n),o=JSON.parse(t),s=JSON.stringify(Fe(r,o));window.localStorage.setItem(e,s)}else window.localStorage.setItem(e,t)}(e,t)),n),clear:e=>Ne((()=>window.localStorage.clear()),e),getAllKeys:e=>Ne((()=>{const e=window.localStorage.length,t=[];for(let n=0;n<e;n+=1){const e=window.localStorage.key(n)||"";t.push(e)}return t}),e),flushGetRequests:()=>{},multiGet:(e,t)=>Be(e.map((e=>Ue.getItem(e))),t,(t=>t.map(((t,n)=>[e[n],t])))),multiSet:(e,t)=>Be(e.map((e=>Ue.setItem(e[0],e[1]))),t),multiRemove:(e,t)=>Be(e.map((e=>Ue.removeItem(e))),t),multiMerge:(e,t)=>Be(e.map((e=>Ue.mergeItem(e[0],e[1]))),t)},De=e=>{const{log:t,cache:n}=we();if(n)return t("cache/api/queryCache",{key:e}),Object.keys(n.data).filter((t=>{const n=w(t);return C(e,n)})).map((e=>n.data[e]))},Le=e=>{const{log:t,cache:n}=we();if(!n)return;t("cache/api/pullFromCache",e);const r=b(e);return n.data[r]?n.data[r]:void 0},qe=(e,t,n={cachedAt:Date.now()})=>{const{log:r,cache:o}=we();if(!o)return!1;r("cache/api/pushToCache",{key:e,data:t,options:n}),!(null==n?void 0:n.hasOwnProperty("offline"))&&o.persistIf&&(n.offline=o.persistIf(e,t));const s=b(e);return o.data[s]=Object.assign({key:e,data:t},n),!0},$e=(e,t,n)=>{const{log:r,cache:o}=we();if(!o)return!1;r("cache/api/mergeInCache",{key:e,mutation:t});const s=Le(e);if(!s)return!1;const i="function"==typeof t?t(s.data):Object.assign(Object.assign({},s.data),t);return qe(e,i,n),!0},ze=(e,t,n={cachedAt:Date.now()})=>{const{log:r,cache:o}=we();if(!o)return!1;r("cache/api/upsertInCache",{key:e,data:t,options:n});return Le(e)?$e(e,t,n):qe(e,t,n)},He=(e,t=!1)=>{const{log:n,cache:r}=we();if(!r)return!1;if(n("cache/api/dropFromCache",{key:e,exact:t}),!t)return Object.keys(r.data).map((e=>w(e))).filter((t=>C(e,t))).map((e=>He(e,!0))).every((e=>e));const o=b(e);return o in r.data&&(delete r.data[o],!0)},Ve=(e,t,n)=>void 0!==n?e.filter((e=>JSON.stringify(e[t])===JSON.stringify(n))):e,We=(e,t,n)=>(null==n?void 0:n.length)?e.filter((e=>Array.isArray(e[t])&&n.some((n=>e[t].includes(n))))):e,Ke=(e,t,n)=>"all"===t?e:e.filter((e=>{var r;const o=ce("channelUsers")({channelId:e.channelId,userId:n}),s=null===(r=Le(["channelUsers","get",o]))||void 0===r?void 0:r.data;return"member"===t?s&&"none"!==s.membership:!s||"none"===s.membership})),Qe=(e,t)=>e.filter((({targetId:e,feedId:n})=>{var r;const o=null===(r=Le(["feed","get",ce("feed")({targetId:e,feedId:n})]))||void 0===r?void 0:r.data;return o&&o.feedType===t})),Je=(e,t,n)=>"all"===t?e:e.filter((e=>{var r;const o=ce("communityUsers")({communityId:e.communityId,userId:n}),s=null===(r=Le(["communityUsers","get",o]))||void 0===r?void 0:r.data;return"member"===t?s&&"member"===s.communityMembership:!s||"none"!==s.communityMembership})),Ge=(e,t)=>{const n=[];return e.forEach((e=>{var r;if("text"!==e.dataType||e.children.length)if(e.children.length){const o=null===(r=Le(["post","get",e.children[0]]))||void 0===r?void 0:r.data;o&&(null==t?void 0:t.includes(null==o?void 0:o.dataType))&&n.push(o)}else(null==t?void 0:t.includes(e.dataType))&&n.push(e)})),n},Ye=(e,t)=>{const n=new RegExp(t,"i");return e.filter((e=>{var t;return!!e.userId.match(n)||e.user&&(null===(t=e.user.displayName)||void 0===t?void 0:t.match(n))}))},Xe=({displayName:e},{displayName:t})=>e===t?0:e<t?-1:1,Ze=({name:e},{name:t})=>e.localeCompare(t),et=({createdAt:e},{createdAt:t})=>new Date(e).valueOf()-new Date(t).valueOf(),tt=({createdAt:e},{createdAt:t})=>new Date(t).valueOf()-new Date(e).valueOf(),nt=({lastActivity:e},{lastActivity:t})=>new Date(t).valueOf()-new Date(e).valueOf();let rt,ot=[];const st=e=>{clearTimeout(rt),ot.push(e),rt=setTimeout((()=>{ot.forEach((e=>e())),ot=[]}),0)},it=["disconnected","error","connect_error","reconnect_error","reconnect_failed","sessionStateChange","tokenExpired"],at=["connect","message","disconnect","error","close","end","reconnect","user.didGlobalBan"],ct=()=>{return{all:e=e||new Map,on:function(t,n){var r=e.get(t);r?r.push(n):e.set(t,[n])},off:function(t,n){var r=e.get(t);r&&(n?r.splice(r.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var r=e.get(t);r&&r.slice().map((function(e){e(n)})),(r=e.get("*"))&&r.slice().map((function(e){e(t,n)}))}};var e},lt=(e,t,n,r)=>{const{log:o,emitter:s}=e,i=Date.now();o(`${t}(tmpid: ${i}) > listen`);const a=(...e)=>{o(`${t}(tmpid: ${i}) > trigger`,e),r(...e)};return s.on(n,a),()=>{o(`${t}(tmpid: ${i}) > dispose`),s.off(n,a)}},ut=(e,t)=>{const{emitter:n}=we();st((()=>{n.emit(e,t)}))};let dt=null;const ht=()=>{if(!dt)throw new ge("Connect client first",8e5,"fatal");return dt},ft=e=>{dt={_id:e._id,userId:e.userId,path:e.path}};var pt;e.SubscriptionLevels=void 0,(pt=e.SubscriptionLevels||(e.SubscriptionLevels={})).COMMUNITY="community",pt.POST="post",pt.COMMENT="comment",pt.POST_AND_COMMENT="post_and_comment",pt.USER="user";const gt=(e,t)=>{switch(t){case"post":return`${e}/post/+`;case"comment":return`${e}/post/+/comment/+`;case"post_and_comment":return`${e}/post/#`;default:return e}},mt=e=>e.path.split("/user/")[0],yt=({path:t},n=e.SubscriptionLevels.USER)=>gt(n===e.SubscriptionLevels.USER?t:t.replace(/^(\w*)/,"$1/social"),n),vt=({channelId:e,subChannelId:t})=>{const n=ht();return`${mt(n)}/marker/channel/${e}/message/${t}`},bt=()=>mt(ht()),wt=()=>{const e=ht();return`${mt(e)}/smartfeed/${e._id}/channels`},Ct=()=>{const e=ht();return`${mt(e)}/smartfeed/${e._id}/messagefeeds`},_t=()=>{const e=ht();return`${mt(e)}/smartfeed/${e._id}/messages`};let kt,St;function At(e,t){var n;const{mqtt:r,emitter:o,token:s}=we(),i=null!==(n=null==s?void 0:s.accessToken)&&void 0!==n?n:"",a=ht();return kt===i&&St===a._id||(kt=i,St=a._id,r.connect({accessToken:kt,userId:St}),((e,t)=>{at.forEach((n=>{e.on(n,((...e)=>{t.emit(n,1===e.length?e[0]:e)}))})),e.on("message",((e,n)=>{const r=JSON.parse(n.toString());t.emit(r.eventType,r.data)}))})(r,o)),r.subscribe(e,t)}var Et,It,Ot={exports:{}};function Tt(){if(It)return Et;It=1;var e=1e3,t=60*e,n=60*t,r=24*n,o=7*r,s=365.25*r;function i(e,t,n,r){var o=t>=1.5*n;return Math.round(e/n)+" "+r+(o?"s":"")}return Et=function(a,c){c=c||{};var l=typeof a;if("string"===l&&a.length>0)return function(i){if((i=String(i)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(i);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*s;case"weeks":case"week":case"w":return c*o;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===l&&isFinite(a))return c.long?function(o){var s=Math.abs(o);if(s>=r)return i(o,s,r,"day");if(s>=n)return i(o,s,n,"hour");if(s>=t)return i(o,s,t,"minute");if(s>=e)return i(o,s,e,"second");return o+" ms"}(a):function(o){var s=Math.abs(o);if(s>=r)return Math.round(o/r)+"d";if(s>=n)return Math.round(o/n)+"h";if(s>=t)return Math.round(o/t)+"m";if(s>=e)return Math.round(o/e)+"s";return o+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))},Et}var xt=function(e){function t(e){let r,o,s,i=null;function a(...e){if(!a.enabled)return;const n=a,o=Number(new Date),s=o-(r||o);n.diff=s,n.prev=r,n.curr=o,r=o,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((r,o)=>{if("%%"===r)return"%";i++;const s=t.formatters[o];if("function"==typeof s){const t=e[i];r=s.call(n,t),e.splice(i,1),i--}return r})),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=n,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(o!==t.namespaces&&(o=t.namespaces,s=t.enabled(e)),s),set:e=>{i=e}}),"function"==typeof t.init&&t.init(a),a}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(r),...t.skips.map(r).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(n=0;n<o;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=Tt(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t};!function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,o=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))})),t.splice(o,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=xt(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(Ot,Ot.exports);var Rt,Pt=Ot.exports;const Mt="object"==typeof globalThis?globalThis:"object"==typeof global?global:window,{process:jt={}}=Mt,Ft="production"===(null===(Rt=jt.env)||void 0===Rt?void 0:Rt.NODE_ENV),Nt={EU:"eu",SG:"sg",US:"us"},Bt={http:"https://api.{region}.amity.co",mqtt:"wss://sse.{region}.amity.co:443/mqtt"};function Ut(e,t){return Bt[e].replace("{region}",t)}function Dt(e,t){return function(){return e.apply(t,arguments)}}const{toString:Lt}=Object.prototype,{getPrototypeOf:qt}=Object,$t=(zt=Object.create(null),e=>{const t=Lt.call(e);return zt[t]||(zt[t]=t.slice(8,-1).toLowerCase())});var zt;const Ht=e=>(e=e.toLowerCase(),t=>$t(t)===e),Vt=e=>t=>typeof t===e,{isArray:Wt}=Array,Kt=Vt("undefined");const Qt=Ht("ArrayBuffer");const Jt=Vt("string"),Gt=Vt("function"),Yt=Vt("number"),Xt=e=>null!==e&&"object"==typeof e,Zt=e=>{if("object"!==$t(e))return!1;const t=qt(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)},en=Ht("Date"),tn=Ht("File"),nn=Ht("Blob"),rn=Ht("FileList"),on=Ht("URLSearchParams");function sn(e,t,{allOwnKeys:n=!1}={}){if(null==e)return;let r,o;if("object"!=typeof e&&(e=[e]),Wt(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{const o=n?Object.getOwnPropertyNames(e):Object.keys(e),s=o.length;let i;for(r=0;r<s;r++)i=o[r],t.call(null,e[i],i,e)}}function an(e,t){t=t.toLowerCase();const n=Object.keys(e);let r,o=n.length;for(;o-- >0;)if(r=n[o],t===r.toLowerCase())return r;return null}const cn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,ln=e=>!Kt(e)&&e!==cn;const un=(dn="undefined"!=typeof Uint8Array&&qt(Uint8Array),e=>dn&&e instanceof dn);var dn;const hn=Ht("HTMLFormElement"),fn=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),pn=Ht("RegExp"),gn=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};sn(n,((n,o)=>{!1!==t(n,o,e)&&(r[o]=n)})),Object.defineProperties(e,r)};var mn={isArray:Wt,isArrayBuffer:Qt,isBuffer:function(e){return null!==e&&!Kt(e)&&null!==e.constructor&&!Kt(e.constructor)&&Gt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)},isFormData:e=>{const t="[object FormData]";return e&&("function"==typeof FormData&&e instanceof FormData||Lt.call(e)===t||Gt(e.toString)&&e.toString()===t)},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&Qt(e.buffer),t},isString:Jt,isNumber:Yt,isBoolean:e=>!0===e||!1===e,isObject:Xt,isPlainObject:Zt,isUndefined:Kt,isDate:en,isFile:tn,isBlob:nn,isRegExp:pn,isFunction:Gt,isStream:e=>Xt(e)&&Gt(e.pipe),isURLSearchParams:on,isTypedArray:un,isFileList:rn,forEach:sn,merge:function e(){const{caseless:t}=ln(this)&&this||{},n={},r=(r,o)=>{const s=t&&an(n,o)||o;Zt(n[s])&&Zt(r)?n[s]=e(n[s],r):Zt(r)?n[s]=e({},r):Wt(r)?n[s]=r.slice():n[s]=r};for(let e=0,t=arguments.length;e<t;e++)arguments[e]&&sn(arguments[e],r);return n},extend:(e,t,n,{allOwnKeys:r}={})=>(sn(t,((t,r)=>{n&&Gt(t)?e[r]=Dt(t,n):e[r]=t}),{allOwnKeys:r}),e),trim:e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:e=>(65279===e.charCodeAt(0)&&(e=e.slice(1)),e),inherits:(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},toFlatObject:(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},null==e)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],r&&!r(i,e,t)||a[i]||(t[i]=e[i],a[i]=!0);e=!1!==n&&qt(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:$t,kindOfTest:Ht,endsWith:(e,t,n)=>{e=String(e),(void 0===n||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return-1!==r&&r===n},toArray:e=>{if(!e)return null;if(Wt(e))return e;let t=e.length;if(!Yt(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},forEachEntry:(e,t)=>{const n=(e&&e[Symbol.iterator]).call(e);let r;for(;(r=n.next())&&!r.done;){const n=r.value;t.call(e,n[0],n[1])}},matchAll:(e,t)=>{let n;const r=[];for(;null!==(n=e.exec(t));)r.push(n);return r},isHTMLForm:hn,hasOwnProperty:fn,hasOwnProp:fn,reduceDescriptors:gn,freezeMethods:e=>{gn(e,((t,n)=>{if(Gt(e)&&-1!==["arguments","caller","callee"].indexOf(n))return!1;const r=e[n];Gt(r)&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")}))}))},toObjectSet:(e,t)=>{const n={},r=e=>{e.forEach((e=>{n[e]=!0}))};return Wt(e)?r(e):r(String(e).split(t)),n},toCamelCase:e=>e.toLowerCase().replace(/[_-\s]([a-z\d])(\w*)/g,(function(e,t,n){return t.toUpperCase()+n})),noop:()=>{},toFiniteNumber:(e,t)=>(e=+e,Number.isFinite(e)?e:t),findKey:an,global:cn,isContextDefined:ln,toJSONObject:e=>{const t=new Array(10),n=(e,r)=>{if(Xt(e)){if(t.indexOf(e)>=0)return;if(!("toJSON"in e)){t[r]=e;const o=Wt(e)?[]:{};return sn(e,((e,t)=>{const s=n(e,r+1);!Kt(s)&&(o[t]=s)})),t[r]=void 0,o}}return e};return n(e,0)}};function yn(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o)}mn.inherits(yn,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:mn.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const vn=yn.prototype,bn={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach((e=>{bn[e]={value:e}})),Object.defineProperties(yn,bn),Object.defineProperty(vn,"isAxiosError",{value:!0}),yn.from=(e,t,n,r,o,s)=>{const i=Object.create(vn);return mn.toFlatObject(e,i,(function(e){return e!==Error.prototype}),(e=>"isAxiosError"!==e)),yn.call(i,e.message,t,n,r,o),i.cause=e,i.name=e.name,s&&Object.assign(i,s),i};var wn="object"==typeof self?self.FormData:window.FormData;function Cn(e){return mn.isPlainObject(e)||mn.isArray(e)}function _n(e){return mn.endsWith(e,"[]")?e.slice(0,-2):e}function kn(e,t,n){return e?e.concat(t).map((function(e,t){return e=_n(e),!n&&t?"["+e+"]":e})).join(n?".":""):t}const Sn=mn.toFlatObject(mn,{},null,(function(e){return/^is[A-Z]/.test(e)}));function An(e,t,n){if(!mn.isObject(e))throw new TypeError("target must be an object");t=t||new(wn||FormData);const r=(n=mn.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,(function(e,t){return!mn.isUndefined(t[e])}))).metaTokens,o=n.visitor||u,s=n.dots,i=n.indexes,a=(n.Blob||"undefined"!=typeof Blob&&Blob)&&((c=t)&&mn.isFunction(c.append)&&"FormData"===c[Symbol.toStringTag]&&c[Symbol.iterator]);var c;if(!mn.isFunction(o))throw new TypeError("visitor must be a function");function l(e){if(null===e)return"";if(mn.isDate(e))return e.toISOString();if(!a&&mn.isBlob(e))throw new yn("Blob is not supported. Use a Buffer instead.");return mn.isArrayBuffer(e)||mn.isTypedArray(e)?a&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function u(e,n,o){let a=e;if(e&&!o&&"object"==typeof e)if(mn.endsWith(n,"{}"))n=r?n:n.slice(0,-2),e=JSON.stringify(e);else if(mn.isArray(e)&&function(e){return mn.isArray(e)&&!e.some(Cn)}(e)||mn.isFileList(e)||mn.endsWith(n,"[]")&&(a=mn.toArray(e)))return n=_n(n),a.forEach((function(e,r){!mn.isUndefined(e)&&null!==e&&t.append(!0===i?kn([n],r,s):null===i?n:n+"[]",l(e))})),!1;return!!Cn(e)||(t.append(kn(o,n,s),l(e)),!1)}const d=[],h=Object.assign(Sn,{defaultVisitor:u,convertValue:l,isVisitable:Cn});if(!mn.isObject(e))throw new TypeError("data must be an object");return function e(n,r){if(!mn.isUndefined(n)){if(-1!==d.indexOf(n))throw Error("Circular reference detected in "+r.join("."));d.push(n),mn.forEach(n,(function(n,s){!0===(!(mn.isUndefined(n)||null===n)&&o.call(t,n,mn.isString(s)?s.trim():s,r,h))&&e(n,r?r.concat(s):[s])})),d.pop()}}(e),t}function En(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,(function(e){return t[e]}))}function In(e,t){this._pairs=[],e&&An(e,this,t)}const On=In.prototype;function Tn(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function xn(e,t,n){if(!t)return e;const r=n&&n.encode||Tn,o=n&&n.serialize;let s;if(s=o?o(t,n):mn.isURLSearchParams(t)?t.toString():new In(t,n).toString(r),s){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+s}return e}On.append=function(e,t){this._pairs.push([e,t])},On.toString=function(e){const t=e?function(t){return e.call(this,t,En)}:En;return this._pairs.map((function(e){return t(e[0])+"="+t(e[1])}),"").join("&")};class Rn{constructor(){this.handlers=[]}use(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){mn.forEach(this.handlers,(function(t){null!==t&&e(t)}))}}var Pn={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Mn="undefined"!=typeof URLSearchParams?URLSearchParams:In,jn=FormData;const Fn=(()=>{let e;return("undefined"==typeof navigator||"ReactNative"!==(e=navigator.product)&&"NativeScript"!==e&&"NS"!==e)&&("undefined"!=typeof window&&"undefined"!=typeof document)})(),Nn="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts;var Bn={isBrowser:!0,classes:{URLSearchParams:Mn,FormData:jn,Blob:Blob},isStandardBrowserEnv:Fn,isStandardBrowserWebWorkerEnv:Nn,protocols:["http","https","file","blob","url","data"]};function Un(e){function t(e,n,r,o){let s=e[o++];const i=Number.isFinite(+s),a=o>=e.length;if(s=!s&&mn.isArray(r)?r.length:s,a)return mn.hasOwnProp(r,s)?r[s]=[r[s],n]:r[s]=n,!i;r[s]&&mn.isObject(r[s])||(r[s]=[]);return t(e,n,r[s],o)&&mn.isArray(r[s])&&(r[s]=function(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}(r[s])),!i}if(mn.isFormData(e)&&mn.isFunction(e.entries)){const n={};return mn.forEachEntry(e,((e,r)=>{t(function(e){return mn.matchAll(/\w+|\[(\w*)]/g,e).map((e=>"[]"===e[0]?"":e[1]||e[0]))}(e),r,n,0)})),n}return null}const Dn={"Content-Type":void 0};const Ln={transitional:Pn,adapter:["xhr","http"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,o=mn.isObject(e);o&&mn.isHTMLForm(e)&&(e=new FormData(e));if(mn.isFormData(e))return r&&r?JSON.stringify(Un(e)):e;if(mn.isArrayBuffer(e)||mn.isBuffer(e)||mn.isStream(e)||mn.isFile(e)||mn.isBlob(e))return e;if(mn.isArrayBufferView(e))return e.buffer;if(mn.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let s;if(o){if(n.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return An(e,new Bn.classes.URLSearchParams,Object.assign({visitor:function(e,t,n,r){return Bn.isNode&&mn.isBuffer(e)?(this.append(t,e.toString("base64")),!1):r.defaultVisitor.apply(this,arguments)}},t))}(e,this.formSerializer).toString();if((s=mn.isFileList(e))||n.indexOf("multipart/form-data")>-1){const t=this.env&&this.env.FormData;return An(s?{"files[]":e}:e,t&&new t,this.formSerializer)}}return o||r?(t.setContentType("application/json",!1),function(e,t,n){if(mn.isString(e))try{return(t||JSON.parse)(e),mn.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(n||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=this.transitional||Ln.transitional,n=t&&t.forcedJSONParsing,r="json"===this.responseType;if(e&&mn.isString(e)&&(n&&!this.responseType||r)){const n=!(t&&t.silentJSONParsing)&&r;try{return JSON.parse(e)}catch(e){if(n){if("SyntaxError"===e.name)throw yn.from(e,yn.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Bn.classes.FormData,Blob:Bn.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};mn.forEach(["delete","get","head"],(function(e){Ln.headers[e]={}})),mn.forEach(["post","put","patch"],(function(e){Ln.headers[e]=mn.merge(Dn)}));const qn=mn.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]);const $n=Symbol("internals");function zn(e){return e&&String(e).trim().toLowerCase()}function Hn(e){return!1===e||null==e?e:mn.isArray(e)?e.map(Hn):String(e)}function Vn(e,t,n,r){return mn.isFunction(r)?r.call(this,t,n):mn.isString(t)?mn.isString(r)?-1!==t.indexOf(r):mn.isRegExp(r)?r.test(t):void 0:void 0}class Wn{constructor(e){e&&this.set(e)}set(e,t,n){const r=this;function o(e,t,n){const o=zn(t);if(!o)throw new Error("header name must be a non-empty string");const s=mn.findKey(r,o);(!s||void 0===r[s]||!0===n||void 0===n&&!1!==r[s])&&(r[s||t]=Hn(e))}const s=(e,t)=>mn.forEach(e,((e,n)=>o(e,n,t)));return mn.isPlainObject(e)||e instanceof this.constructor?s(e,t):mn.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z]+$/.test(e.trim())?s((e=>{const t={};let n,r,o;return e&&e.split("\n").forEach((function(e){o=e.indexOf(":"),n=e.substring(0,o).trim().toLowerCase(),r=e.substring(o+1).trim(),!n||t[n]&&qn[n]||("set-cookie"===n?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)})),t})(e),t):null!=e&&o(t,e,n),this}get(e,t){if(e=zn(e)){const n=mn.findKey(this,e);if(n){const e=this[n];if(!t)return e;if(!0===t)return function(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}(e);if(mn.isFunction(t))return t.call(this,e,n);if(mn.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=zn(e)){const n=mn.findKey(this,e);return!(!n||t&&!Vn(0,this[n],n,t))}return!1}delete(e,t){const n=this;let r=!1;function o(e){if(e=zn(e)){const o=mn.findKey(n,e);!o||t&&!Vn(0,n[o],o,t)||(delete n[o],r=!0)}}return mn.isArray(e)?e.forEach(o):o(e),r}clear(){return Object.keys(this).forEach(this.delete.bind(this))}normalize(e){const t=this,n={};return mn.forEach(this,((r,o)=>{const s=mn.findKey(n,o);if(s)return t[s]=Hn(r),void delete t[o];const i=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,((e,t,n)=>t.toUpperCase()+n))}(o):String(o).trim();i!==o&&delete t[o],t[i]=Hn(r),n[i]=!0})),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return mn.forEach(this,((n,r)=>{null!=n&&!1!==n&&(t[r]=e&&mn.isArray(n)?n.join(", "):n)})),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map((([e,t])=>e+": "+t)).join("\n")}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const n=new this(e);return t.forEach((e=>n.set(e))),n}static accessor(e){const t=(this[$n]=this[$n]={accessors:{}}).accessors,n=this.prototype;function r(e){const r=zn(e);t[r]||(!function(e,t){const n=mn.toCamelCase(" "+t);["get","set","has"].forEach((r=>{Object.defineProperty(e,r+n,{value:function(e,n,o){return this[r].call(this,t,e,n,o)},configurable:!0})}))}(n,e),t[r]=!0)}return mn.isArray(e)?e.forEach(r):r(e),this}}function Kn(e,t){const n=this||Ln,r=t||n,o=Wn.from(r.headers);let s=r.data;return mn.forEach(e,(function(e){s=e.call(n,s,o.normalize(),t?t.status:void 0)})),o.normalize(),s}function Qn(e){return!(!e||!e.__CANCEL__)}function Jn(e,t,n){yn.call(this,null==e?"canceled":e,yn.ERR_CANCELED,t,n),this.name="CanceledError"}Wn.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent"]),mn.freezeMethods(Wn.prototype),mn.freezeMethods(Wn),mn.inherits(Jn,yn,{__CANCEL__:!0});var Gn=Bn.isStandardBrowserEnv?{write:function(e,t,n,r,o,s){const i=[];i.push(e+"="+encodeURIComponent(t)),mn.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),mn.isString(r)&&i.push("path="+r),mn.isString(o)&&i.push("domain="+o),!0===s&&i.push("secure"),document.cookie=i.join("; ")},read:function(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}};function Yn(e,t){return e&&!function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}(t)?function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}var Xn=Bn.isStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),t=document.createElement("a");let n;function r(n){let r=n;return e&&(t.setAttribute("href",r),r=t.href),t.setAttribute("href",r),{href:t.href,protocol:t.protocol?t.protocol.replace(/:$/,""):"",host:t.host,search:t.search?t.search.replace(/^\?/,""):"",hash:t.hash?t.hash.replace(/^#/,""):"",hostname:t.hostname,port:t.port,pathname:"/"===t.pathname.charAt(0)?t.pathname:"/"+t.pathname}}return n=r(window.location.href),function(e){const t=mn.isString(e)?r(e):e;return t.protocol===n.protocol&&t.host===n.host}}():function(){return!0};function Zn(e,t){let n=0;const r=function(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o,s=0,i=0;return t=void 0!==t?t:1e3,function(a){const c=Date.now(),l=r[i];o||(o=c),n[s]=a,r[s]=c;let u=i,d=0;for(;u!==s;)d+=n[u++],u%=e;if(s=(s+1)%e,s===i&&(i=(i+1)%e),c-o<t)return;const h=l&&c-l;return h?Math.round(1e3*d/h):void 0}}(50,250);return o=>{const s=o.loaded,i=o.lengthComputable?o.total:void 0,a=s-n,c=r(a);n=s;const l={loaded:s,total:i,progress:i?s/i:void 0,bytes:a,rate:c||void 0,estimated:c&&i&&s<=i?(i-s)/c:void 0,event:o};l[t?"download":"upload"]=!0,e(l)}}var er="undefined"!=typeof XMLHttpRequest&&function(e){return new Promise((function(t,n){let r=e.data;const o=Wn.from(e.headers).normalize(),s=e.responseType;let i;function a(){e.cancelToken&&e.cancelToken.unsubscribe(i),e.signal&&e.signal.removeEventListener("abort",i)}mn.isFormData(r)&&(Bn.isStandardBrowserEnv||Bn.isStandardBrowserWebWorkerEnv)&&o.setContentType(!1);let c=new XMLHttpRequest;if(e.auth){const t=e.auth.username||"",n=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.set("Authorization","Basic "+btoa(t+":"+n))}const l=Yn(e.baseURL,e.url);function u(){if(!c)return;const r=Wn.from("getAllResponseHeaders"in c&&c.getAllResponseHeaders());!function(e,t,n){const r=n.config.validateStatus;n.status&&r&&!r(n.status)?t(new yn("Request failed with status code "+n.status,[yn.ERR_BAD_REQUEST,yn.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):e(n)}((function(e){t(e),a()}),(function(e){n(e),a()}),{data:s&&"text"!==s&&"json"!==s?c.response:c.responseText,status:c.status,statusText:c.statusText,headers:r,config:e,request:c}),c=null}if(c.open(e.method.toUpperCase(),xn(l,e.params,e.paramsSerializer),!0),c.timeout=e.timeout,"onloadend"in c?c.onloadend=u:c.onreadystatechange=function(){c&&4===c.readyState&&(0!==c.status||c.responseURL&&0===c.responseURL.indexOf("file:"))&&setTimeout(u)},c.onabort=function(){c&&(n(new yn("Request aborted",yn.ECONNABORTED,e,c)),c=null)},c.onerror=function(){n(new yn("Network Error",yn.ERR_NETWORK,e,c)),c=null},c.ontimeout=function(){let t=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded";const r=e.transitional||Pn;e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),n(new yn(t,r.clarifyTimeoutError?yn.ETIMEDOUT:yn.ECONNABORTED,e,c)),c=null},Bn.isStandardBrowserEnv){const t=(e.withCredentials||Xn(l))&&e.xsrfCookieName&&Gn.read(e.xsrfCookieName);t&&o.set(e.xsrfHeaderName,t)}void 0===r&&o.setContentType(null),"setRequestHeader"in c&&mn.forEach(o.toJSON(),(function(e,t){c.setRequestHeader(t,e)})),mn.isUndefined(e.withCredentials)||(c.withCredentials=!!e.withCredentials),s&&"json"!==s&&(c.responseType=e.responseType),"function"==typeof e.onDownloadProgress&&c.addEventListener("progress",Zn(e.onDownloadProgress,!0)),"function"==typeof e.onUploadProgress&&c.upload&&c.upload.addEventListener("progress",Zn(e.onUploadProgress)),(e.cancelToken||e.signal)&&(i=t=>{c&&(n(!t||t.type?new Jn(null,e,c):t),c.abort(),c=null)},e.cancelToken&&e.cancelToken.subscribe(i),e.signal&&(e.signal.aborted?i():e.signal.addEventListener("abort",i)));const d=function(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}(l);d&&-1===Bn.protocols.indexOf(d)?n(new yn("Unsupported protocol "+d+":",yn.ERR_BAD_REQUEST,e)):c.send(r||null)}))};const tr={http:null,xhr:er};mn.forEach(tr,((e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}}));var nr=e=>{e=mn.isArray(e)?e:[e];const{length:t}=e;let n,r;for(let o=0;o<t&&(n=e[o],!(r=mn.isString(n)?tr[n.toLowerCase()]:n));o++);if(!r){if(!1===r)throw new yn(`Adapter ${n} is not supported by the environment`,"ERR_NOT_SUPPORT");throw new Error(mn.hasOwnProp(tr,n)?`Adapter '${n}' is not available in the build`:`Unknown adapter '${n}'`)}if(!mn.isFunction(r))throw new TypeError("adapter is not a function");return r};function rr(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Jn(null,e)}function or(e){rr(e),e.headers=Wn.from(e.headers),e.data=Kn.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1);return nr(e.adapter||Ln.adapter)(e).then((function(t){return rr(e),t.data=Kn.call(e,e.transformResponse,t),t.headers=Wn.from(t.headers),t}),(function(t){return Qn(t)||(rr(e),t&&t.response&&(t.response.data=Kn.call(e,e.transformResponse,t.response),t.response.headers=Wn.from(t.response.headers))),Promise.reject(t)}))}const sr=e=>e instanceof Wn?e.toJSON():e;function ir(e,t){t=t||{};const n={};function r(e,t,n){return mn.isPlainObject(e)&&mn.isPlainObject(t)?mn.merge.call({caseless:n},e,t):mn.isPlainObject(t)?mn.merge({},t):mn.isArray(t)?t.slice():t}function o(e,t,n){return mn.isUndefined(t)?mn.isUndefined(e)?void 0:r(void 0,e,n):r(e,t,n)}function s(e,t){if(!mn.isUndefined(t))return r(void 0,t)}function i(e,t){return mn.isUndefined(t)?mn.isUndefined(e)?void 0:r(void 0,e):r(void 0,t)}function a(n,o,s){return s in t?r(n,o):s in e?r(void 0,n):void 0}const c={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(e,t)=>o(sr(e),sr(t),!0)};return mn.forEach(Object.keys(e).concat(Object.keys(t)),(function(r){const s=c[r]||o,i=s(e[r],t[r],r);mn.isUndefined(i)&&s!==a||(n[r]=i)})),n}const ar="1.2.3",cr={};["object","boolean","number","function","string","symbol"].forEach(((e,t)=>{cr[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}}));const lr={};cr.transitional=function(e,t,n){function r(e,t){return"[Axios v1.2.3] Transitional option '"+e+"'"+t+(n?". "+n:"")}return(n,o,s)=>{if(!1===e)throw new yn(r(o," has been removed"+(t?" in "+t:"")),yn.ERR_DEPRECATED);return t&&!lr[o]&&(lr[o]=!0,console.warn(r(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(n,o,s)}};var ur={assertOptions:function(e,t,n){if("object"!=typeof e)throw new yn("options must be an object",yn.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const t=e[s],n=void 0===t||i(t,s,e);if(!0!==n)throw new yn("option "+s+" must be "+n,yn.ERR_BAD_OPTION_VALUE)}else if(!0!==n)throw new yn("Unknown option "+s,yn.ERR_BAD_OPTION)}},validators:cr};const dr=ur.validators;class hr{constructor(e){this.defaults=e,this.interceptors={request:new Rn,response:new Rn}}request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=ir(this.defaults,t);const{transitional:n,paramsSerializer:r,headers:o}=t;let s;void 0!==n&&ur.assertOptions(n,{silentJSONParsing:dr.transitional(dr.boolean),forcedJSONParsing:dr.transitional(dr.boolean),clarifyTimeoutError:dr.transitional(dr.boolean)},!1),void 0!==r&&ur.assertOptions(r,{encode:dr.function,serialize:dr.function},!0),t.method=(t.method||this.defaults.method||"get").toLowerCase(),s=o&&mn.merge(o.common,o[t.method]),s&&mn.forEach(["delete","get","head","post","put","patch","common"],(e=>{delete o[e]})),t.headers=Wn.concat(s,o);const i=[];let a=!0;this.interceptors.request.forEach((function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(a=a&&e.synchronous,i.unshift(e.fulfilled,e.rejected))}));const c=[];let l;this.interceptors.response.forEach((function(e){c.push(e.fulfilled,e.rejected)}));let u,d=0;if(!a){const e=[or.bind(this),void 0];for(e.unshift.apply(e,i),e.push.apply(e,c),u=e.length,l=Promise.resolve(t);d<u;)l=l.then(e[d++],e[d++]);return l}u=i.length;let h=t;for(d=0;d<u;){const e=i[d++],t=i[d++];try{h=e(h)}catch(e){t.call(this,e);break}}try{l=or.call(this,h)}catch(e){return Promise.reject(e)}for(d=0,u=c.length;d<u;)l=l.then(c[d++],c[d++]);return l}getUri(e){return xn(Yn((e=ir(this.defaults,e)).baseURL,e.url),e.params,e.paramsSerializer)}}mn.forEach(["delete","get","head","options"],(function(e){hr.prototype[e]=function(t,n){return this.request(ir(n||{},{method:e,url:t,data:(n||{}).data}))}})),mn.forEach(["post","put","patch"],(function(e){function t(t){return function(n,r,o){return this.request(ir(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}hr.prototype[e]=t(),hr.prototype[e+"Form"]=t(!0)}));class fr{constructor(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((function(e){t=e}));const n=this;this.promise.then((e=>{if(!n._listeners)return;let t=n._listeners.length;for(;t-- >0;)n._listeners[t](e);n._listeners=null})),this.promise.then=e=>{let t;const r=new Promise((e=>{n.subscribe(e),t=e})).then(e);return r.cancel=function(){n.unsubscribe(t)},r},e((function(e,r,o){n.reason||(n.reason=new Jn(e,r,o),t(n.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}static source(){let e;return{token:new fr((function(t){e=t})),cancel:e}}}const pr={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(pr).forEach((([e,t])=>{pr[t]=e}));const gr=function e(t){const n=new hr(t),r=Dt(hr.prototype.request,n);return mn.extend(r,hr.prototype,n,{allOwnKeys:!0}),mn.extend(r,n,null,{allOwnKeys:!0}),r.create=function(n){return e(ir(t,n))},r}(Ln);gr.Axios=hr,gr.CanceledError=Jn,gr.CancelToken=fr,gr.isCancel=Qn,gr.VERSION=ar,gr.toFormData=An,gr.AxiosError=yn,gr.Cancel=gr.CanceledError,gr.all=function(e){return Promise.all(e)},gr.spread=function(e){return function(t){return e.apply(null,t)}},gr.isAxiosError=function(e){return mn.isObject(e)&&!0===e.isAxiosError},gr.mergeConfig=ir,gr.AxiosHeaders=Wn,gr.formToJSON=e=>Un(mn.isHTMLForm(e)?new FormData(e):e),gr.HttpStatusCode=pr,gr.default=gr;var mr={exports:{}};mr.exports=vr;var yr=mr.exports.HttpsAgent=vr;function vr(){}const br=e=>{if("success"===e.status)return e.data;if("fail"===e.status)throw new ye(e.code);if("error"===e.status)throw new me(e.message,e.code,"error")};var wr;!function(e){e.UserDeleted="User Deleted",e.UserGlobalBanned="User Global Banned",e.TokenExpired="Token Expired"}(wr||(wr={}));const Cr=new AbortController,_r=e=>{switch(e){case wr.UserGlobalBanned:throw new ge(e,400312,"fatal");case wr.UserDeleted:throw new ge(e,400100,"fatal");case wr.TokenExpired:throw ut("tokenExpired","tokenExpired"),new ge(e,800403,"fatal");default:throw new ge("Request Aborted",8e5,"error")}},kr=e=>{const t={maxSockets:100,maxFreeSockets:10,timeout:6e4,freeSocketTimeout:3e4},n=gr.create({baseURL:e,httpAgent:new mr.exports(t),httpsAgent:new yr(t),signal:Cr.signal});return n.interceptors.request.use((e=>{if("/api/v4/sessions"===e.url)return e;if(e.metadata){const{tokenExpiry:t,isGlobalBanned:n,isUserDeleted:r}=e.metadata;n&&(Cr.abort(),_r(wr.UserGlobalBanned)),r&&(Cr.abort(),_r(wr.UserDeleted)),t&&Date.now()>=Date.parse(t)&&(Cr.abort(wr.UserDeleted),_r(wr.TokenExpired))}return e})),n.interceptors.response.use((e=>e),(e=>{var t,n;const{response:r}=e;if(400100===(null==r?void 0:r.data.code)&&ut("tokenTerminated","terminated"),(null===(t=null==r?void 0:r.data)||void 0===t?void 0:t.status)&&br(null==r?void 0:r.data),Cr.signal.aborted)throw e;throw new Error(null!==(n=null==r?void 0:r.data)&&void 0!==n?n:e)})),n};var Sr={exports:{}},Ar=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Er=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],Ir=function(e){var t=e,n=e.indexOf("["),r=e.indexOf("]");-1!=n&&-1!=r&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));for(var o=Ar.exec(e||""),s={},i=14;i--;)s[Er[i]]=o[i]||"";return-1!=n&&-1!=r&&(s.source=t,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("[","").replace("]","").replace(/;/g,":"),s.ipv6uri=!0),s},Or={exports:{}},Tr={exports:{}},xr=1e3,Rr=6e4,Pr=60*Rr,Mr=24*Pr,jr=365.25*Mr,Fr=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*jr;case"days":case"day":case"d":return n*Mr;case"hours":case"hour":case"hrs":case"hr":case"h":return n*Pr;case"minutes":case"minute":case"mins":case"min":case"m":return n*Rr;case"seconds":case"second":case"secs":case"sec":case"s":return n*xr;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(e);if("number"===n&&!1===isNaN(e))return t.long?function(e){return Nr(e,Mr,"day")||Nr(e,Pr,"hour")||Nr(e,Rr,"minute")||Nr(e,xr,"second")||e+" ms"}(e):function(e){if(e>=Mr)return Math.round(e/Mr)+"d";if(e>=Pr)return Math.round(e/Pr)+"h";if(e>=Rr)return Math.round(e/Rr)+"m";if(e>=xr)return Math.round(e/xr)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function Nr(e,t,n){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}!function(e,t){function n(e){var n;function o(){if(o.enabled){var e=o,r=+new Date,s=r-(n||r);e.diff=s,e.prev=n,e.curr=r,n=r;for(var i=new Array(arguments.length),a=0;a<i.length;a++)i[a]=arguments[a];i[0]=t.coerce(i[0]),"string"!=typeof i[0]&&i.unshift("%O");var c=0;i[0]=i[0].replace(/%([a-zA-Z%])/g,(function(n,r){if("%%"===n)return n;c++;var o=t.formatters[r];if("function"==typeof o){var s=i[c];n=o.call(e,s),i.splice(c,1),c--}return n})),t.formatArgs.call(e,i);var l=o.log||t.log||console.log.bind(console);l.apply(e,i)}}return o.namespace=e,o.enabled=t.enabled(e),o.useColors=t.useColors(),o.color=function(e){var n,r=0;for(n in e)r=(r<<5)-r+e.charCodeAt(n),r|=0;return t.colors[Math.abs(r)%t.colors.length]}(e),o.destroy=r,"function"==typeof t.init&&t.init(o),t.instances.push(o),o}function r(){var e=t.instances.indexOf(this);return-1!==e&&(t.instances.splice(e,1),!0)}(t=e.exports=n.debug=n.default=n).coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){t.enable("")},t.enable=function(e){var n;t.save(e),t.names=[],t.skips=[];var r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(n=0;n<o;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")));for(n=0;n<t.instances.length;n++){var s=t.instances[n];s.enabled=t.enabled(s.namespace)}},t.enabled=function(e){if("*"===e[e.length-1])return!0;var n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=Fr,t.instances=[],t.names=[],t.skips=[],t.formatters={}}(Tr,Tr.exports),function(e,t){function n(){var e;try{e=t.storage.debug}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e}(t=e.exports=Tr.exports).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},t.formatArgs=function(e){var n=this.useColors;if(e[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+e[0]+(n?"%c ":" ")+"+"+t.humanize(this.diff),!n)return;var r="color: "+this.color;e.splice(1,0,r,"color: inherit");var o=0,s=0;e[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(o++,"%c"===e&&(s=o))})),e.splice(s,0,r)},t.save=function(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}},t.load=n,t.useColors=function(){if("undefined"!=typeof window&&window.process&&"renderer"===window.process.type)return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(n())}(Or,Or.exports);var Br=Ir,Ur=Or.exports("socket.io-client:url"),Dr=function(e,t){var n=e;t=t||"undefined"!=typeof location&&location,null==e&&(e=t.protocol+"//"+t.host);"string"==typeof e&&("/"===e.charAt(0)&&(e="/"===e.charAt(1)?t.protocol+e:t.host+e),/^(https?|wss?):\/\//.test(e)||(Ur("protocol-less url %s",e),e=void 0!==t?t.protocol+"//"+e:"https://"+e),Ur("parse %s",e),n=Br(e));n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443"));n.path=n.path||"/";var r=-1!==n.host.indexOf(":")?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+r+":"+n.port,n.href=n.protocol+"://"+r+(t&&t.port===n.port?"":":"+n.port),n};var Lr={},qr={exports:{}},$r={exports:{}},zr=1e3,Hr=6e4,Vr=60*Hr,Wr=24*Vr,Kr=365.25*Wr,Qr=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*Kr;case"days":case"day":case"d":return n*Wr;case"hours":case"hour":case"hrs":case"hr":case"h":return n*Vr;case"minutes":case"minute":case"mins":case"min":case"m":return n*Hr;case"seconds":case"second":case"secs":case"sec":case"s":return n*zr;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(e);if("number"===n&&!1===isNaN(e))return t.long?function(e){return Jr(e,Wr,"day")||Jr(e,Vr,"hour")||Jr(e,Hr,"minute")||Jr(e,zr,"second")||e+" ms"}(e):function(e){if(e>=Wr)return Math.round(e/Wr)+"d";if(e>=Vr)return Math.round(e/Vr)+"h";if(e>=Hr)return Math.round(e/Hr)+"m";if(e>=zr)return Math.round(e/zr)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function Jr(e,t,n){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}!function(e,t){function n(e){var n;function o(){if(o.enabled){var e=o,r=+new Date,s=r-(n||r);e.diff=s,e.prev=n,e.curr=r,n=r;for(var i=new Array(arguments.length),a=0;a<i.length;a++)i[a]=arguments[a];i[0]=t.coerce(i[0]),"string"!=typeof i[0]&&i.unshift("%O");var c=0;i[0]=i[0].replace(/%([a-zA-Z%])/g,(function(n,r){if("%%"===n)return n;c++;var o=t.formatters[r];if("function"==typeof o){var s=i[c];n=o.call(e,s),i.splice(c,1),c--}return n})),t.formatArgs.call(e,i);var l=o.log||t.log||console.log.bind(console);l.apply(e,i)}}return o.namespace=e,o.enabled=t.enabled(e),o.useColors=t.useColors(),o.color=function(e){var n,r=0;for(n in e)r=(r<<5)-r+e.charCodeAt(n),r|=0;return t.colors[Math.abs(r)%t.colors.length]}(e),o.destroy=r,"function"==typeof t.init&&t.init(o),t.instances.push(o),o}function r(){var e=t.instances.indexOf(this);return-1!==e&&(t.instances.splice(e,1),!0)}(t=e.exports=n.debug=n.default=n).coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){t.enable("")},t.enable=function(e){var n;t.save(e),t.names=[],t.skips=[];var r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(n=0;n<o;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")));for(n=0;n<t.instances.length;n++){var s=t.instances[n];s.enabled=t.enabled(s.namespace)}},t.enabled=function(e){if("*"===e[e.length-1])return!0;var n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=Qr,t.instances=[],t.names=[],t.skips=[],t.formatters={}}($r,$r.exports),function(e,t){function n(){var e;try{e=t.storage.debug}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e}(t=e.exports=$r.exports).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},t.formatArgs=function(e){var n=this.useColors;if(e[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+e[0]+(n?"%c ":" ")+"+"+t.humanize(this.diff),!n)return;var r="color: "+this.color;e.splice(1,0,r,"color: inherit");var o=0,s=0;e[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(o++,"%c"===e&&(s=o))})),e.splice(s,0,r)},t.save=function(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}},t.load=n,t.useColors=function(){if("undefined"!=typeof window&&window.process&&"renderer"===window.process.type)return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(n())}(qr,qr.exports);var Gr={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;o<r.length;o++)if((n=r[o])===t||n.fn===t){r.splice(o,1);break}return 0===r.length&&delete this._callbacks["$"+e],this},t.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),n=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){r=0;for(var o=(n=n.slice(0)).length;r<o;++r)n[r].apply(this,t)}return this},t.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},t.prototype.hasListeners=function(e){return!!this.listeners(e).length}}(Gr);var Yr={},Xr={}.toString,Zr=Array.isArray||function(e){return"[object Array]"==Xr.call(e)},eo=function(e){return to&&Buffer.isBuffer(e)||no&&(e instanceof ArrayBuffer||function(e){return"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer}(e))},to="function"==typeof Buffer&&"function"==typeof Buffer.isBuffer,no="function"==typeof ArrayBuffer;var ro=Zr,oo=eo,so=Object.prototype.toString,io="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===so.call(Blob),ao="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===so.call(File);function co(e,t){if(!e)return e;if(oo(e)){var n={_placeholder:!0,num:t.length};return t.push(e),n}if(ro(e)){for(var r=new Array(e.length),o=0;o<e.length;o++)r[o]=co(e[o],t);return r}if("object"==typeof e&&!(e instanceof Date)){r={};for(var s in e)r[s]=co(e[s],t);return r}return e}function lo(e,t){if(!e)return e;if(e&&e._placeholder)return t[e.num];if(ro(e))for(var n=0;n<e.length;n++)e[n]=lo(e[n],t);else if("object"==typeof e)for(var r in e)e[r]=lo(e[r],t);return e}Yr.deconstructPacket=function(e){var t=[],n=e.data,r=e;return r.data=co(n,t),r.attachments=t.length,{packet:r,buffers:t}},Yr.reconstructPacket=function(e,t){return e.data=lo(e.data,t),e.attachments=void 0,e},Yr.removeBlobs=function(e,t){var n=0,r=e;!function e(o,s,i){if(!o)return o;if(io&&o instanceof Blob||ao&&o instanceof File){n++;var a=new FileReader;a.onload=function(){i?i[s]=this.result:r=this.result,--n||t(r)},a.readAsArrayBuffer(o)}else if(ro(o))for(var c=0;c<o.length;c++)e(o[c],c,o);else if("object"==typeof o&&!oo(o))for(var l in o)e(o[l],l,o)}(r),n||t(r)},function(e){var t=qr.exports("socket.io-parser"),n=Gr.exports,r=Yr,o=Zr,s=eo;function i(){}e.protocol=4,e.types=["CONNECT","DISCONNECT","EVENT","ACK","ERROR","BINARY_EVENT","BINARY_ACK"],e.CONNECT=0,e.DISCONNECT=1,e.EVENT=2,e.ACK=3,e.ERROR=4,e.BINARY_EVENT=5,e.BINARY_ACK=6,e.Encoder=i,e.Decoder=l;var a=e.ERROR+'"encode error"';function c(n){var r=""+n.type;if(e.BINARY_EVENT!==n.type&&e.BINARY_ACK!==n.type||(r+=n.attachments+"-"),n.nsp&&"/"!==n.nsp&&(r+=n.nsp+","),null!=n.id&&(r+=n.id),null!=n.data){var o=function(e){try{return JSON.stringify(e)}catch(e){return!1}}(n.data);if(!1===o)return a;r+=o}return t("encoded %j as %s",n,r),r}function l(){this.reconstructor=null}function u(e){this.reconPack=e,this.buffers=[]}function d(t){return{type:e.ERROR,data:"parser error: "+t}}i.prototype.encode=function(n,o){(t("encoding packet %j",n),e.BINARY_EVENT===n.type||e.BINARY_ACK===n.type)?function(e,t){function n(e){var n=r.deconstructPacket(e),o=c(n.packet),s=n.buffers;s.unshift(o),t(s)}r.removeBlobs(e,n)}(n,o):o([c(n)])},n(l.prototype),l.prototype.add=function(n){var r;if("string"==typeof n)r=function(n){var r=0,s={type:Number(n.charAt(0))};if(null==e.types[s.type])return d("unknown packet type "+s.type);if(e.BINARY_EVENT===s.type||e.BINARY_ACK===s.type){for(var i=r+1;"-"!==n.charAt(++r)&&r!=n.length;);var a=n.substring(i,r);if(a!=Number(a)||"-"!==n.charAt(r))throw new Error("Illegal attachments");s.attachments=Number(a)}if("/"===n.charAt(r+1)){for(i=r+1;++r;){if(","===(l=n.charAt(r)))break;if(r===n.length)break}s.nsp=n.substring(i,r)}else s.nsp="/";var c=n.charAt(r+1);if(""!==c&&Number(c)==c){for(i=r+1;++r;){var l;if(null==(l=n.charAt(r))||Number(l)!=l){--r;break}if(r===n.length)break}s.id=Number(n.substring(i,r+1))}if(n.charAt(++r)){var u=function(e){try{return JSON.parse(e)}catch(e){return!1}}(n.substr(r));if(!(!1!==u&&(s.type===e.ERROR||o(u))))return d("invalid payload");s.data=u}return t("decoded %s as %j",n,s),s}(n),e.BINARY_EVENT===r.type||e.BINARY_ACK===r.type?(this.reconstructor=new u(r),0===this.reconstructor.reconPack.attachments&&this.emit("decoded",r)):this.emit("decoded",r);else{if(!s(n)&&!n.base64)throw new Error("Unknown type: "+n);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");(r=this.reconstructor.takeBinaryData(n))&&(this.reconstructor=null,this.emit("decoded",r))}},l.prototype.destroy=function(){this.reconstructor&&this.reconstructor.finishedReconstruction()},u.prototype.takeBinaryData=function(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){var t=r.reconstructPacket(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null},u.prototype.finishedReconstruction=function(){this.reconPack=null,this.buffers=[]}}(Lr);var uo={exports:{}},ho={},fo={exports:{}};try{fo.exports="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(e){fo.exports=!1}var po,go,mo,yo,vo=fo.exports,bo=function(e){var t=e.xdomain,n=e.xscheme,r=e.enablesXDR;try{if("undefined"!=typeof XMLHttpRequest&&(!t||vo))return new XMLHttpRequest}catch(e){}try{if("undefined"!=typeof XDomainRequest&&!n&&r)return new XDomainRequest}catch(e){}if(!t)try{return new(self[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(e){}},wo={exports:{}},Co={},_o=Object.keys||function(e){var t=[],n=Object.prototype.hasOwnProperty;for(var r in e)n.call(e,r)&&t.push(r);return t};function ko(){if(yo)return mo;yo=1;var e=function(){if(go)return po;go=1;var e={}.toString;return po=Array.isArray||function(t){return"[object Array]"==e.call(t)}}(),t=Object.prototype.toString,n="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===t.call(Blob),r="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===t.call(File);return mo=function t(o){if(!o||"object"!=typeof o)return!1;if(e(o)){for(var s=0,i=o.length;s<i;s++)if(t(o[s]))return!0;return!1}if("function"==typeof Buffer&&Buffer.isBuffer&&Buffer.isBuffer(o)||"function"==typeof ArrayBuffer&&o instanceof ArrayBuffer||n&&o instanceof Blob||r&&o instanceof File)return!0;if(o.toJSON&&"function"==typeof o.toJSON&&1===arguments.length)return t(o.toJSON(),!0);for(var a in o)if(Object.prototype.hasOwnProperty.call(o,a)&&t(o[a]))return!0;return!1},mo}var So=function(e,t,n){var r=e.byteLength;if(t=t||0,n=n||r,e.slice)return e.slice(t,n);if(t<0&&(t+=r),n<0&&(n+=r),n>r&&(n=r),t>=r||t>=n||0===r)return new ArrayBuffer(0);for(var o=new Uint8Array(e),s=new Uint8Array(n-t),i=t,a=0;i<n;i++,a++)s[a]=o[i];return s.buffer},Ao=function(e,t,n){var r=!1;return n=n||Eo,o.count=e,0===e?t():o;function o(e,s){if(o.count<=0)throw new Error("after called too many times");--o.count,e?(r=!0,t(e),t=n):0!==o.count||r||t(null,s)}};function Eo(){}
1
+ var Amity=function(e){"use strict";const t=Object.freeze({ONLY_ADMIN_CAN_POST:"ONLY_ADMIN_CAN_POST",ADMIN_REVIEW_POST_REQUIRED:"ADMIN_REVIEW_POST_REQUIRED",ANYONE_CAN_POST:"ANYONE_CAN_POST"}),n=Object.freeze({ONLY_ADMIN_CAN_POST:{needApprovalOnPostCreation:!1,onlyAdminCanPost:!0},ADMIN_REVIEW_POST_REQUIRED:{needApprovalOnPostCreation:!0,onlyAdminCanPost:!1},ANYONE_CAN_POST:{needApprovalOnPostCreation:!1,onlyAdminCanPost:!1}}),r="ONLY_ADMIN_CAN_POST",o=Object.freeze({STORY:"story",CLIP:"clip",CHAT:"chat",POST:"post",MESSAGE:"message"}),s=Object.freeze({FILE:"file",IMAGE:"image",VIDEO:"video"}),i=Object.freeze({"1080P":"1080p","720P":"720p","480P":"480p","360P":"360p",ORIGINAL:"original"}),a=Object.freeze({UPLOADED:"uploaded",TRANSCODING:"transcoding",TRANSCODED:"transcoded",TRANSCODE_FAILED:"transcodeFailed"}),c=Object.freeze({LOW:"low",MEDIUM:"medium",HIGH:"high",ORIGINAL:"original"}),l=Object.freeze({TEXT:"text",IMAGE:"image",FILE:"file",VIDEO:"video",AUDIO:"audio",CUSTOM:"custom"}),u=Object.freeze({TEXT:"text",IMAGE:"image",FILE:"file",VIDEO:"video",LIVESTREAM:"liveStream",POLL:"poll",CUSTOM:"custom"});const d=function(){try{return"v6.3.1-umd"}catch(e){return"__dev__"}}(),h=5,f="cache_then_server",p="For using Live Collection feature you need to enable Cache!",g=6e5,m="dead",y=2e3,v=6e4,b=e=>JSON.stringify(e,((e,t)=>{return"object"==typeof t?(n=t,Object.keys(n).sort().reduce(((e,t)=>Object.assign(Object.assign({},e),{[t]:n[t]})),{})):t;var n})),w=e=>JSON.parse(e),C=(e,t)=>e===t||!(!e||!t)&&("object"==typeof e&&Object.keys(e).every((n=>C(e[n],t[n])))),_=e=>[400400,400300].includes(e),k="function"==typeof atob,S="function"==typeof btoa,A="function"==typeof Buffer,E="function"==typeof TextDecoder?new TextDecoder:void 0,I="function"==typeof TextEncoder?new TextEncoder:void 0,O=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),T=(e=>{let t={};return e.forEach(((e,n)=>t[e]=n)),t})(O),x=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,R=String.fromCharCode.bind(String),P="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):(e,t=(e=>e))=>new Uint8Array(Array.prototype.slice.call(e,0).map(t)),M=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),j=S?e=>btoa(e):A?e=>Buffer.from(e,"binary").toString("base64"):e=>{let t,n,r,o,s="";const i=e.length%3;for(let i=0;i<e.length;){if((n=e.charCodeAt(i++))>255||(r=e.charCodeAt(i++))>255||(o=e.charCodeAt(i++))>255)throw new TypeError("invalid character found");t=n<<16|r<<8|o,s+=O[t>>18&63]+O[t>>12&63]+O[t>>6&63]+O[63&t]}return i?s.slice(0,i-3)+"===".substring(i):s},F=A?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let n=0,r=e.length;n<r;n+=4096)t.push(R.apply(null,e.subarray(n,n+4096)));return j(t.join(""))},N=e=>{if(e.length<2)return(t=e.charCodeAt(0))<128?e:t<2048?R(192|t>>>6)+R(128|63&t):R(224|t>>>12&15)+R(128|t>>>6&63)+R(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return R(240|t>>>18&7)+R(128|t>>>12&63)+R(128|t>>>6&63)+R(128|63&t)},B=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,U=A?e=>Buffer.from(e,"utf8").toString("base64"):I?e=>F(I.encode(e)):e=>j(e.replace(B,N)),D=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,L=e=>{switch(e.length){case 4:var t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return R(55296+(t>>>10))+R(56320+(1023&t));case 3:return R((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return R((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},q=k?e=>atob(M(e)):A?e=>Buffer.from(e,"base64").toString("binary"):e=>{if(e=e.replace(/\s+/g,""),!x.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let t,n,r,o="";for(let s=0;s<e.length;)t=T[e.charAt(s++)]<<18|T[e.charAt(s++)]<<12|(n=T[e.charAt(s++)])<<6|(r=T[e.charAt(s++)]),o+=64===n?R(t>>16&255):64===r?R(t>>16&255,t>>8&255):R(t>>16&255,t>>8&255,255&t);return o},$=A?e=>P(Buffer.from(e,"base64")):e=>P(q(e),(e=>e.charCodeAt(0))),z=A?e=>Buffer.from(e,"base64").toString("utf8"):E?e=>E.decode($(e)):e=>q(e).replace(D,L),H=e=>z(M(e.replace(/[-_]/g,(e=>"-"==e?"+":"/")))),V=e=>["skip"].some((t=>t in e)),W=e=>["after","before","first","last","limit"].some((t=>t in e)),K=e=>"limit"in e,Q=e=>(null==e?void 0:e.hasOwnProperty("data"))&&(null==e?void 0:e.hasOwnProperty("nextPage"))&&(null==e?void 0:e.hasOwnProperty("prevPage")),J=(e,t)=>{var n;if(!e||!Object.keys(e).length)return;let r={};return"skiplimit"===t?r={skip:null!==(n=e.after)&&void 0!==n?n:0,limit:e.limit}:"afterbefore"===t&&W(e)?Number.isNaN(Number(null==e?void 0:e.before))?Number.isNaN(Number(null==e?void 0:e.after))?Number.isNaN(Number(null==e?void 0:e.limit))||(r={last:e.limit}):r={after:e.after,first:e.limit}:r={before:e.before,last:e.limit}:"afterbeforeraw"===t&&(r=e),Object.keys(r).length?((e,t=!1)=>t?(e=>e.replace(/=/g,"").replace(/[+\/]/g,(e=>"+"==e?"-":"_")))(U(e)):U(e))(JSON.stringify(r)):void 0},G=e=>{if(!e)return;const t=JSON.parse(H(e));if(V(t))return{after:t.skip,limit:t.limit};if(W(t)){if("before"in t)return{before:t.before,limit:t.last};if("after"in t)return{after:t.after,limit:t.first}}},Y=e=>{if(!e)return;const t=JSON.parse(H(e));return K(t)?t:void 0},X=e=>"locally"in e,Z=e=>"optimistically"in e,ee=e=>X(e)||Z(e),te=e=>null==e?void 0:e.hasOwnProperty("cachedAt"),ne=(e,t=6e4)=>{var n;return Date.now()-(null!==(n=null==e?void 0:e.cachedAt)&&void 0!==n?n:0)<=t},re=(e,...t)=>({func:e,args:t}),oe=(e,t=6e4)=>"cache_only"===e?{lifeSpan:1/0}:{lifeSpan:t<v?v:t},se=({func:e,args:t},n,r=oe("cache_then_server"))=>{let o;const{lifeSpan:s}=oe("cache_then_server",r.lifeSpan);if(ee(e)){try{o=Z(e)?e.optimistically(...t):e.locally(...t)}catch(e){null==n||n(ie(void 0,{origin:"local",loading:!1,error:e}))}const r=te(o)&&ne(o,s);if(null==n||n(ie(o,{origin:"local",loading:!(X(e)&&r)})),r)return}else null==n||n(ie(void 0,{origin:"local",loading:!0}));e(...t).then((e=>{null==n||n(ie(e,{origin:"server",loading:!1}))})).catch((e=>{null==n||n(ie(void 0,{origin:"server",loading:!1,error:e}))}))};function ie(e,t){return Q(e)||te(e)?Object.assign(Object.assign({},t),e):Object.assign(Object.assign({},t),{data:e})}const ae={user:({userId:e})=>e,file:({fileId:e})=>e,role:({roleId:e})=>e,channel:({channelId:e})=>e,subChannel:({subChannelId:e})=>e,channelUsers:({channelId:e,userId:t})=>`${e}#${t}`,message:({messageId:e})=>e,channelMarker:({entityId:e,userId:t})=>`${e}#${t}`,subChannelMarker:({entityId:e,feedId:t,userId:n})=>`${e}#${t}#${n}`,messageMarker:({feedId:e,contentId:t,creatorId:n})=>`${e}#${t}#${n}`,feedMarker:({feedId:e,entityId:t})=>`${e}#${t}`,userMarker:({userId:e})=>e,community:({communityId:e})=>e,category:({categoryId:e})=>e,communityUsers:({communityId:e,userId:t})=>`${e}#${t}`,post:({postId:e})=>e,comment:({commentId:e})=>e,poll:({pollId:e})=>e,reaction:({reactionId:e})=>e,stream:({streamId:e})=>e,follow:({from:e,to:t})=>`${e}#${t}`,followInfo:({userId:e})=>e,followCount:({userId:e})=>e,feed:({targetId:e,feedId:t})=>`${e}#${t}`},ce=e=>ae[e],le={file:["fileId","attributes"],user:["userId","avatarFileId"],role:["roleId"],channel:["channelId","rateLimit"],subChannel:["subChannelId"],channelUsers:["channelId","userId","membership"],message:["messageId"],community:["communityId","postSetting"],category:["categoryId"],communityUsers:["userId","communityId","communityMembership"],post:["postId","feedId"],comment:["commentId","referenceId"],poll:["pollId"],reaction:["reactionId"],stream:["streamId"],follow:["from","to"],feed:["feedId","feedType"],followInfo:["userId","status"],followCount:["userId","followerCount"]},ue=e=>{var t;return null===(t=Object.entries(le).find((([t,n])=>((e,t)=>{const n=Object.keys(e);return t.every((e=>n.includes(e)))})(e,n))))||void 0===t?void 0:t[0]},de=e=>{var t;const n=ue(e);if(n)return null===(t=le[n])||void 0===t?void 0:t[0]},he={users:"user",files:"file",roles:"role",channels:"channel",messageFeeds:"subChannel",channelUsers:"channelUsers",messages:"message",userEntityMarkers:"channelMarker",userFeedMarkers:"subChannelMarker",contentMarkers:"messageMarker",feedMarkers:"feedMarker",userMarkers:"userMarker",communities:"community",categories:"category",communityUsers:"communityUsers",posts:"post",postChildren:"post",comments:"comment",polls:"poll",reactions:"reaction",videoStreamings:"stream",follows:"follow",followCounts:"followCount",feeds:"feed"},fe=(e,t)=>new Date(e.updatedAt)<new Date(t.updatedAt);function pe(e=(new Date).toISOString()){return new Date(new Date(e).getTime()+1).toISOString()}class ge extends Error{constructor(e,t,n){super(`Amity SDK (${t}): ${e}`),this.code=t,this.level=n,this.type="ASC",this.timestamp=Date.now(),Error.captureStackTrace&&Error.captureStackTrace(this,ge)}}class me extends ge{constructor(e,t,n){super(e,t,n)}}class ye extends ge{constructor(e=8e5,t="fatal"){super("Unexpected error",e,t)}}class ve extends ge{constructor(e,t="SDK client is having connection issues"){super(`${t} (${e})`,"disconnected"===e?800211:800210,"error"),this.event=e}}let be=null;const we=()=>{if(!be)throw new ge("There is no active client",8e5,"fatal");return be},Ce=e=>{be=e};var _e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ke(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Se(e){var t=e.default;if("function"==typeof t){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}const Ae=e=>{if("[object Object]"!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype},{hasOwnProperty:Ee}=Object.prototype,{propertyIsEnumerable:Ie}=Object,Oe=(e,t,n)=>Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}),Te=_e,xe={concatArrays:!1,ignoreUndefined:!1},Re=e=>{const t=[];for(const n in e)Ee.call(e,n)&&t.push(n);if(Object.getOwnPropertySymbols){const n=Object.getOwnPropertySymbols(e);for(const r of n)Ie.call(e,r)&&t.push(r)}return t};function Pe(e){return Array.isArray(e)?function(e){const t=e.slice(0,0);return Re(e).forEach((n=>{Oe(t,n,Pe(e[n]))})),t}(e):Ae(e)?function(e){const t=null===Object.getPrototypeOf(e)?Object.create(null):{};return Re(e).forEach((n=>{Oe(t,n,Pe(e[n]))})),t}(e):e}const Me=(e,t,n,r)=>(n.forEach((n=>{void 0===t[n]&&r.ignoreUndefined||(n in e&&e[n]!==Object.getPrototypeOf(e)?Oe(e,n,je(e[n],t[n],r)):Oe(e,n,Pe(t[n])))})),e);function je(e,t,n){return n.concatArrays&&Array.isArray(e)&&Array.isArray(t)?((e,t,n)=>{let r=e.slice(0,0),o=0;return[e,t].forEach((t=>{const s=[];for(let n=0;n<t.length;n++)Ee.call(t,n)&&(s.push(String(n)),Oe(r,o++,t===e?t[n]:Pe(t[n])));r=Me(r,t,Re(t).filter((e=>!s.includes(e))),n)})),r})(e,t,n):Ae(t)&&Ae(e)?Me(e,t,Re(t),n):Pe(t)}const Fe=function(...e){const t=je(Pe(xe),this!==Te&&this||{},xe);let n={_:{}};for(const r of e)if(void 0!==r){if(!Ae(r))throw new TypeError("`"+r+"` is not an Option Object");n=je(n,{_:r},t)}return n._}.bind({concatArrays:!0,ignoreUndefined:!0});function Ne(e,t){return new Promise(((n,r)=>{try{const r=e();null==t||t(null,r),n(r)}catch(e){null==t||t(e),r(e)}}))}function Be(e,t,n){return Promise.all(e).then((e=>{var r;const o=null!==(r=null==n?void 0:n(e))&&void 0!==r?r:null;return null==t||t(null,o),Promise.resolve(o)}),(e=>(null==t||t(e),Promise.reject(e))))}const Ue={getItem:(e,t)=>Ne((()=>window.localStorage.getItem(e)),t),setItem:(e,t,n)=>Ne((()=>window.localStorage.setItem(e,t)),n),removeItem:(e,t)=>Ne((()=>window.localStorage.removeItem(e)),t),mergeItem:(e,t,n)=>Ne((()=>function(e,t){const n=window.localStorage.getItem(e);if(n){const r=JSON.parse(n),o=JSON.parse(t),s=JSON.stringify(Fe(r,o));window.localStorage.setItem(e,s)}else window.localStorage.setItem(e,t)}(e,t)),n),clear:e=>Ne((()=>window.localStorage.clear()),e),getAllKeys:e=>Ne((()=>{const e=window.localStorage.length,t=[];for(let n=0;n<e;n+=1){const e=window.localStorage.key(n)||"";t.push(e)}return t}),e),flushGetRequests:()=>{},multiGet:(e,t)=>Be(e.map((e=>Ue.getItem(e))),t,(t=>t.map(((t,n)=>[e[n],t])))),multiSet:(e,t)=>Be(e.map((e=>Ue.setItem(e[0],e[1]))),t),multiRemove:(e,t)=>Be(e.map((e=>Ue.removeItem(e))),t),multiMerge:(e,t)=>Be(e.map((e=>Ue.mergeItem(e[0],e[1]))),t)},De=e=>{const{log:t,cache:n}=we();if(n)return t("cache/api/queryCache",{key:e}),Object.keys(n.data).filter((t=>{const n=w(t);return C(e,n)})).map((e=>n.data[e]))},Le=e=>{const{log:t,cache:n}=we();if(!n)return;t("cache/api/pullFromCache",e);const r=b(e);return n.data[r]?n.data[r]:void 0},qe=(e,t,n={cachedAt:Date.now()})=>{const{log:r,cache:o}=we();if(!o)return!1;r("cache/api/pushToCache",{key:e,data:t,options:n}),!(null==n?void 0:n.hasOwnProperty("offline"))&&o.persistIf&&(n.offline=o.persistIf(e,t));const s=b(e);return o.data[s]=Object.assign({key:e,data:t},n),!0},$e=(e,t,n)=>{const{log:r,cache:o}=we();if(!o)return!1;r("cache/api/mergeInCache",{key:e,mutation:t});const s=Le(e);if(!s)return!1;const i="function"==typeof t?t(s.data):Object.assign(Object.assign({},s.data),t);return qe(e,i,n),!0},ze=(e,t,n={cachedAt:Date.now()})=>{const{log:r,cache:o}=we();if(!o)return!1;r("cache/api/upsertInCache",{key:e,data:t,options:n});return Le(e)?$e(e,t,n):qe(e,t,n)},He=(e,t=!1)=>{const{log:n,cache:r}=we();if(!r)return!1;if(n("cache/api/dropFromCache",{key:e,exact:t}),!t)return Object.keys(r.data).map((e=>w(e))).filter((t=>C(e,t))).map((e=>He(e,!0))).every((e=>e));const o=b(e);return o in r.data&&(delete r.data[o],!0)},Ve=(e,t,n)=>void 0!==n?e.filter((e=>JSON.stringify(e[t])===JSON.stringify(n))):e,We=(e,t,n)=>(null==n?void 0:n.length)?e.filter((e=>Array.isArray(e[t])&&n.some((n=>e[t].includes(n))))):e,Ke=(e,t,n)=>"all"===t?e:e.filter((e=>{var r;const o=ce("channelUsers")({channelId:e.channelId,userId:n}),s=null===(r=Le(["channelUsers","get",o]))||void 0===r?void 0:r.data;return"member"===t?s&&"none"!==s.membership:!s||"none"===s.membership})),Qe=(e,t)=>e.filter((({targetId:e,feedId:n})=>{var r;const o=null===(r=Le(["feed","get",ce("feed")({targetId:e,feedId:n})]))||void 0===r?void 0:r.data;return o&&o.feedType===t})),Je=(e,t,n)=>"all"===t?e:e.filter((e=>{var r;const o=ce("communityUsers")({communityId:e.communityId,userId:n}),s=null===(r=Le(["communityUsers","get",o]))||void 0===r?void 0:r.data;return"member"===t?s&&"member"===s.communityMembership:!s||"none"!==s.communityMembership})),Ge=(e,t)=>{const n=[];return e.forEach((e=>{var r;if("text"!==e.dataType||e.children.length)if(e.children.length){const o=null===(r=Le(["post","get",e.children[0]]))||void 0===r?void 0:r.data;o&&(null==t?void 0:t.includes(null==o?void 0:o.dataType))&&n.push(o)}else(null==t?void 0:t.includes(e.dataType))&&n.push(e)})),n},Ye=(e,t)=>{const n=new RegExp(t,"i");return e.filter((e=>{var t;return!!e.userId.match(n)||e.user&&(null===(t=e.user.displayName)||void 0===t?void 0:t.match(n))}))},Xe=({displayName:e},{displayName:t})=>e===t?0:e<t?-1:1,Ze=({name:e},{name:t})=>e.localeCompare(t),et=({createdAt:e},{createdAt:t})=>new Date(e).valueOf()-new Date(t).valueOf(),tt=({createdAt:e},{createdAt:t})=>new Date(t).valueOf()-new Date(e).valueOf(),nt=({lastActivity:e},{lastActivity:t})=>new Date(t).valueOf()-new Date(e).valueOf();let rt,ot=[];const st=e=>{clearTimeout(rt),ot.push(e),rt=setTimeout((()=>{ot.forEach((e=>e())),ot=[]}),0)},it=["disconnected","error","connect_error","reconnect_error","reconnect_failed","sessionStateChange","tokenExpired"],at=["connect","message","disconnect","error","close","end","reconnect","user.didGlobalBan"],ct=()=>{return{all:e=e||new Map,on:function(t,n){var r=e.get(t);r?r.push(n):e.set(t,[n])},off:function(t,n){var r=e.get(t);r&&(n?r.splice(r.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var r=e.get(t);r&&r.slice().map((function(e){e(n)})),(r=e.get("*"))&&r.slice().map((function(e){e(t,n)}))}};var e},lt=(e,t,n,r)=>{const{log:o,emitter:s}=e,i=Date.now();o(`${t}(tmpid: ${i}) > listen`);const a=(...e)=>{o(`${t}(tmpid: ${i}) > trigger`,e),r(...e)};return s.on(n,a),()=>{o(`${t}(tmpid: ${i}) > dispose`),s.off(n,a)}},ut=(e,t)=>{const{emitter:n}=we();st((()=>{n.emit(e,t)}))};let dt=null;const ht=()=>{if(!dt)throw new ge("Connect client first",8e5,"fatal");return dt},ft=e=>{dt={_id:e._id,userId:e.userId,path:e.path}};var pt;e.SubscriptionLevels=void 0,(pt=e.SubscriptionLevels||(e.SubscriptionLevels={})).COMMUNITY="community",pt.POST="post",pt.COMMENT="comment",pt.POST_AND_COMMENT="post_and_comment",pt.USER="user";const gt=(e,t)=>{switch(t){case"post":return`${e}/post/+`;case"comment":return`${e}/post/+/comment/+`;case"post_and_comment":return`${e}/post/#`;default:return e}},mt=e=>e.path.split("/user/")[0],yt=({path:t},n=e.SubscriptionLevels.USER)=>gt(n===e.SubscriptionLevels.USER?t:t.replace(/^(\w*)/,"$1/social"),n),vt=({channelId:e,subChannelId:t})=>{const n=ht();return`${mt(n)}/marker/channel/${e}/message/${t}`},bt=()=>mt(ht()),wt=()=>{const e=ht();return`${mt(e)}/smartfeed/${e._id}/channels`},Ct=()=>{const e=ht();return`${mt(e)}/smartfeed/${e._id}/messagefeeds`},_t=()=>{const e=ht();return`${mt(e)}/smartfeed/${e._id}/messages`};let kt,St;function At(e,t){var n;const{mqtt:r,emitter:o,token:s}=we(),i=null!==(n=null==s?void 0:s.accessToken)&&void 0!==n?n:"",a=ht();return kt===i&&St===a._id||(kt=i,St=a._id,r.connect({accessToken:kt,userId:St}),((e,t)=>{at.forEach((n=>{e.on(n,((...e)=>{t.emit(n,1===e.length?e[0]:e)}))})),e.on("message",((e,n)=>{const r=JSON.parse(n.toString());t.emit(r.eventType,r.data)}))})(r,o)),r.subscribe(e,t)}var Et,It,Ot={exports:{}};function Tt(){if(It)return Et;It=1;var e=1e3,t=60*e,n=60*t,r=24*n,o=7*r,s=365.25*r;function i(e,t,n,r){var o=t>=1.5*n;return Math.round(e/n)+" "+r+(o?"s":"")}return Et=function(a,c){c=c||{};var l=typeof a;if("string"===l&&a.length>0)return function(i){if((i=String(i)).length>100)return;var a=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(i);if(!a)return;var c=parseFloat(a[1]);switch((a[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return c*s;case"weeks":case"week":case"w":return c*o;case"days":case"day":case"d":return c*r;case"hours":case"hour":case"hrs":case"hr":case"h":return c*n;case"minutes":case"minute":case"mins":case"min":case"m":return c*t;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}(a);if("number"===l&&isFinite(a))return c.long?function(o){var s=Math.abs(o);if(s>=r)return i(o,s,r,"day");if(s>=n)return i(o,s,n,"hour");if(s>=t)return i(o,s,t,"minute");if(s>=e)return i(o,s,e,"second");return o+" ms"}(a):function(o){var s=Math.abs(o);if(s>=r)return Math.round(o/r)+"d";if(s>=n)return Math.round(o/n)+"h";if(s>=t)return Math.round(o/t)+"m";if(s>=e)return Math.round(o/e)+"s";return o+"ms"}(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))},Et}var xt=function(e){function t(e){let r,o,s,i=null;function a(...e){if(!a.enabled)return;const n=a,o=Number(new Date),s=o-(r||o);n.diff=s,n.prev=r,n.curr=o,r=o,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((r,o)=>{if("%%"===r)return"%";i++;const s=t.formatters[o];if("function"==typeof s){const t=e[i];r=s.call(n,t),e.splice(i,1),i--}return r})),t.formatArgs.call(n,e);(n.log||t.log).apply(n,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=n,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(o!==t.namespaces&&(o=t.namespaces,s=t.enabled(e)),s),set:e=>{i=e}}),"function"==typeof t.init&&t.init(a),a}function n(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},t.disable=function(){const e=[...t.names.map(r),...t.skips.map(r).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(n=0;n<o;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=Tt(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t};!function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,o=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))})),t.splice(o,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG);return e},t.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=xt(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(Ot,Ot.exports);var Rt,Pt=Ot.exports;const Mt="object"==typeof globalThis?globalThis:"object"==typeof global?global:window,{process:jt={}}=Mt,Ft="production"===(null===(Rt=jt.env)||void 0===Rt?void 0:Rt.NODE_ENV),Nt={EU:"eu",SG:"sg",US:"us"},Bt={http:"https://api.{region}.amity.co",mqtt:"wss://sse.{region}.amity.co:443/mqtt"};function Ut(e,t){return Bt[e].replace("{region}",t)}function Dt(e,t){return function(){return e.apply(t,arguments)}}const{toString:Lt}=Object.prototype,{getPrototypeOf:qt}=Object,$t=(zt=Object.create(null),e=>{const t=Lt.call(e);return zt[t]||(zt[t]=t.slice(8,-1).toLowerCase())});var zt;const Ht=e=>(e=e.toLowerCase(),t=>$t(t)===e),Vt=e=>t=>typeof t===e,{isArray:Wt}=Array,Kt=Vt("undefined");const Qt=Ht("ArrayBuffer");const Jt=Vt("string"),Gt=Vt("function"),Yt=Vt("number"),Xt=e=>null!==e&&"object"==typeof e,Zt=e=>{if("object"!==$t(e))return!1;const t=qt(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)},en=Ht("Date"),tn=Ht("File"),nn=Ht("Blob"),rn=Ht("FileList"),on=Ht("URLSearchParams");function sn(e,t,{allOwnKeys:n=!1}={}){if(null==e)return;let r,o;if("object"!=typeof e&&(e=[e]),Wt(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{const o=n?Object.getOwnPropertyNames(e):Object.keys(e),s=o.length;let i;for(r=0;r<s;r++)i=o[r],t.call(null,e[i],i,e)}}function an(e,t){t=t.toLowerCase();const n=Object.keys(e);let r,o=n.length;for(;o-- >0;)if(r=n[o],t===r.toLowerCase())return r;return null}const cn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,ln=e=>!Kt(e)&&e!==cn;const un=(dn="undefined"!=typeof Uint8Array&&qt(Uint8Array),e=>dn&&e instanceof dn);var dn;const hn=Ht("HTMLFormElement"),fn=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),pn=Ht("RegExp"),gn=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};sn(n,((n,o)=>{!1!==t(n,o,e)&&(r[o]=n)})),Object.defineProperties(e,r)};var mn={isArray:Wt,isArrayBuffer:Qt,isBuffer:function(e){return null!==e&&!Kt(e)&&null!==e.constructor&&!Kt(e.constructor)&&Gt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)},isFormData:e=>{const t="[object FormData]";return e&&("function"==typeof FormData&&e instanceof FormData||Lt.call(e)===t||Gt(e.toString)&&e.toString()===t)},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&Qt(e.buffer),t},isString:Jt,isNumber:Yt,isBoolean:e=>!0===e||!1===e,isObject:Xt,isPlainObject:Zt,isUndefined:Kt,isDate:en,isFile:tn,isBlob:nn,isRegExp:pn,isFunction:Gt,isStream:e=>Xt(e)&&Gt(e.pipe),isURLSearchParams:on,isTypedArray:un,isFileList:rn,forEach:sn,merge:function e(){const{caseless:t}=ln(this)&&this||{},n={},r=(r,o)=>{const s=t&&an(n,o)||o;Zt(n[s])&&Zt(r)?n[s]=e(n[s],r):Zt(r)?n[s]=e({},r):Wt(r)?n[s]=r.slice():n[s]=r};for(let e=0,t=arguments.length;e<t;e++)arguments[e]&&sn(arguments[e],r);return n},extend:(e,t,n,{allOwnKeys:r}={})=>(sn(t,((t,r)=>{n&&Gt(t)?e[r]=Dt(t,n):e[r]=t}),{allOwnKeys:r}),e),trim:e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:e=>(65279===e.charCodeAt(0)&&(e=e.slice(1)),e),inherits:(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},toFlatObject:(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},null==e)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],r&&!r(i,e,t)||a[i]||(t[i]=e[i],a[i]=!0);e=!1!==n&&qt(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:$t,kindOfTest:Ht,endsWith:(e,t,n)=>{e=String(e),(void 0===n||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return-1!==r&&r===n},toArray:e=>{if(!e)return null;if(Wt(e))return e;let t=e.length;if(!Yt(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},forEachEntry:(e,t)=>{const n=(e&&e[Symbol.iterator]).call(e);let r;for(;(r=n.next())&&!r.done;){const n=r.value;t.call(e,n[0],n[1])}},matchAll:(e,t)=>{let n;const r=[];for(;null!==(n=e.exec(t));)r.push(n);return r},isHTMLForm:hn,hasOwnProperty:fn,hasOwnProp:fn,reduceDescriptors:gn,freezeMethods:e=>{gn(e,((t,n)=>{if(Gt(e)&&-1!==["arguments","caller","callee"].indexOf(n))return!1;const r=e[n];Gt(r)&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")}))}))},toObjectSet:(e,t)=>{const n={},r=e=>{e.forEach((e=>{n[e]=!0}))};return Wt(e)?r(e):r(String(e).split(t)),n},toCamelCase:e=>e.toLowerCase().replace(/[_-\s]([a-z\d])(\w*)/g,(function(e,t,n){return t.toUpperCase()+n})),noop:()=>{},toFiniteNumber:(e,t)=>(e=+e,Number.isFinite(e)?e:t),findKey:an,global:cn,isContextDefined:ln,toJSONObject:e=>{const t=new Array(10),n=(e,r)=>{if(Xt(e)){if(t.indexOf(e)>=0)return;if(!("toJSON"in e)){t[r]=e;const o=Wt(e)?[]:{};return sn(e,((e,t)=>{const s=n(e,r+1);!Kt(s)&&(o[t]=s)})),t[r]=void 0,o}}return e};return n(e,0)}};function yn(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o)}mn.inherits(yn,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:mn.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const vn=yn.prototype,bn={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach((e=>{bn[e]={value:e}})),Object.defineProperties(yn,bn),Object.defineProperty(vn,"isAxiosError",{value:!0}),yn.from=(e,t,n,r,o,s)=>{const i=Object.create(vn);return mn.toFlatObject(e,i,(function(e){return e!==Error.prototype}),(e=>"isAxiosError"!==e)),yn.call(i,e.message,t,n,r,o),i.cause=e,i.name=e.name,s&&Object.assign(i,s),i};var wn="object"==typeof self?self.FormData:window.FormData;function Cn(e){return mn.isPlainObject(e)||mn.isArray(e)}function _n(e){return mn.endsWith(e,"[]")?e.slice(0,-2):e}function kn(e,t,n){return e?e.concat(t).map((function(e,t){return e=_n(e),!n&&t?"["+e+"]":e})).join(n?".":""):t}const Sn=mn.toFlatObject(mn,{},null,(function(e){return/^is[A-Z]/.test(e)}));function An(e,t,n){if(!mn.isObject(e))throw new TypeError("target must be an object");t=t||new(wn||FormData);const r=(n=mn.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,(function(e,t){return!mn.isUndefined(t[e])}))).metaTokens,o=n.visitor||u,s=n.dots,i=n.indexes,a=(n.Blob||"undefined"!=typeof Blob&&Blob)&&((c=t)&&mn.isFunction(c.append)&&"FormData"===c[Symbol.toStringTag]&&c[Symbol.iterator]);var c;if(!mn.isFunction(o))throw new TypeError("visitor must be a function");function l(e){if(null===e)return"";if(mn.isDate(e))return e.toISOString();if(!a&&mn.isBlob(e))throw new yn("Blob is not supported. Use a Buffer instead.");return mn.isArrayBuffer(e)||mn.isTypedArray(e)?a&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function u(e,n,o){let a=e;if(e&&!o&&"object"==typeof e)if(mn.endsWith(n,"{}"))n=r?n:n.slice(0,-2),e=JSON.stringify(e);else if(mn.isArray(e)&&function(e){return mn.isArray(e)&&!e.some(Cn)}(e)||mn.isFileList(e)||mn.endsWith(n,"[]")&&(a=mn.toArray(e)))return n=_n(n),a.forEach((function(e,r){!mn.isUndefined(e)&&null!==e&&t.append(!0===i?kn([n],r,s):null===i?n:n+"[]",l(e))})),!1;return!!Cn(e)||(t.append(kn(o,n,s),l(e)),!1)}const d=[],h=Object.assign(Sn,{defaultVisitor:u,convertValue:l,isVisitable:Cn});if(!mn.isObject(e))throw new TypeError("data must be an object");return function e(n,r){if(!mn.isUndefined(n)){if(-1!==d.indexOf(n))throw Error("Circular reference detected in "+r.join("."));d.push(n),mn.forEach(n,(function(n,s){!0===(!(mn.isUndefined(n)||null===n)&&o.call(t,n,mn.isString(s)?s.trim():s,r,h))&&e(n,r?r.concat(s):[s])})),d.pop()}}(e),t}function En(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,(function(e){return t[e]}))}function In(e,t){this._pairs=[],e&&An(e,this,t)}const On=In.prototype;function Tn(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function xn(e,t,n){if(!t)return e;const r=n&&n.encode||Tn,o=n&&n.serialize;let s;if(s=o?o(t,n):mn.isURLSearchParams(t)?t.toString():new In(t,n).toString(r),s){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+s}return e}On.append=function(e,t){this._pairs.push([e,t])},On.toString=function(e){const t=e?function(t){return e.call(this,t,En)}:En;return this._pairs.map((function(e){return t(e[0])+"="+t(e[1])}),"").join("&")};class Rn{constructor(){this.handlers=[]}use(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){mn.forEach(this.handlers,(function(t){null!==t&&e(t)}))}}var Pn={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Mn="undefined"!=typeof URLSearchParams?URLSearchParams:In,jn=FormData;const Fn=(()=>{let e;return("undefined"==typeof navigator||"ReactNative"!==(e=navigator.product)&&"NativeScript"!==e&&"NS"!==e)&&("undefined"!=typeof window&&"undefined"!=typeof document)})(),Nn="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts;var Bn={isBrowser:!0,classes:{URLSearchParams:Mn,FormData:jn,Blob:Blob},isStandardBrowserEnv:Fn,isStandardBrowserWebWorkerEnv:Nn,protocols:["http","https","file","blob","url","data"]};function Un(e){function t(e,n,r,o){let s=e[o++];const i=Number.isFinite(+s),a=o>=e.length;if(s=!s&&mn.isArray(r)?r.length:s,a)return mn.hasOwnProp(r,s)?r[s]=[r[s],n]:r[s]=n,!i;r[s]&&mn.isObject(r[s])||(r[s]=[]);return t(e,n,r[s],o)&&mn.isArray(r[s])&&(r[s]=function(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}(r[s])),!i}if(mn.isFormData(e)&&mn.isFunction(e.entries)){const n={};return mn.forEachEntry(e,((e,r)=>{t(function(e){return mn.matchAll(/\w+|\[(\w*)]/g,e).map((e=>"[]"===e[0]?"":e[1]||e[0]))}(e),r,n,0)})),n}return null}const Dn={"Content-Type":void 0};const Ln={transitional:Pn,adapter:["xhr","http"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,o=mn.isObject(e);o&&mn.isHTMLForm(e)&&(e=new FormData(e));if(mn.isFormData(e))return r&&r?JSON.stringify(Un(e)):e;if(mn.isArrayBuffer(e)||mn.isBuffer(e)||mn.isStream(e)||mn.isFile(e)||mn.isBlob(e))return e;if(mn.isArrayBufferView(e))return e.buffer;if(mn.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let s;if(o){if(n.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return An(e,new Bn.classes.URLSearchParams,Object.assign({visitor:function(e,t,n,r){return Bn.isNode&&mn.isBuffer(e)?(this.append(t,e.toString("base64")),!1):r.defaultVisitor.apply(this,arguments)}},t))}(e,this.formSerializer).toString();if((s=mn.isFileList(e))||n.indexOf("multipart/form-data")>-1){const t=this.env&&this.env.FormData;return An(s?{"files[]":e}:e,t&&new t,this.formSerializer)}}return o||r?(t.setContentType("application/json",!1),function(e,t,n){if(mn.isString(e))try{return(t||JSON.parse)(e),mn.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(n||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=this.transitional||Ln.transitional,n=t&&t.forcedJSONParsing,r="json"===this.responseType;if(e&&mn.isString(e)&&(n&&!this.responseType||r)){const n=!(t&&t.silentJSONParsing)&&r;try{return JSON.parse(e)}catch(e){if(n){if("SyntaxError"===e.name)throw yn.from(e,yn.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Bn.classes.FormData,Blob:Bn.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};mn.forEach(["delete","get","head"],(function(e){Ln.headers[e]={}})),mn.forEach(["post","put","patch"],(function(e){Ln.headers[e]=mn.merge(Dn)}));const qn=mn.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]);const $n=Symbol("internals");function zn(e){return e&&String(e).trim().toLowerCase()}function Hn(e){return!1===e||null==e?e:mn.isArray(e)?e.map(Hn):String(e)}function Vn(e,t,n,r){return mn.isFunction(r)?r.call(this,t,n):mn.isString(t)?mn.isString(r)?-1!==t.indexOf(r):mn.isRegExp(r)?r.test(t):void 0:void 0}class Wn{constructor(e){e&&this.set(e)}set(e,t,n){const r=this;function o(e,t,n){const o=zn(t);if(!o)throw new Error("header name must be a non-empty string");const s=mn.findKey(r,o);(!s||void 0===r[s]||!0===n||void 0===n&&!1!==r[s])&&(r[s||t]=Hn(e))}const s=(e,t)=>mn.forEach(e,((e,n)=>o(e,n,t)));return mn.isPlainObject(e)||e instanceof this.constructor?s(e,t):mn.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z]+$/.test(e.trim())?s((e=>{const t={};let n,r,o;return e&&e.split("\n").forEach((function(e){o=e.indexOf(":"),n=e.substring(0,o).trim().toLowerCase(),r=e.substring(o+1).trim(),!n||t[n]&&qn[n]||("set-cookie"===n?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)})),t})(e),t):null!=e&&o(t,e,n),this}get(e,t){if(e=zn(e)){const n=mn.findKey(this,e);if(n){const e=this[n];if(!t)return e;if(!0===t)return function(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}(e);if(mn.isFunction(t))return t.call(this,e,n);if(mn.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=zn(e)){const n=mn.findKey(this,e);return!(!n||t&&!Vn(0,this[n],n,t))}return!1}delete(e,t){const n=this;let r=!1;function o(e){if(e=zn(e)){const o=mn.findKey(n,e);!o||t&&!Vn(0,n[o],o,t)||(delete n[o],r=!0)}}return mn.isArray(e)?e.forEach(o):o(e),r}clear(){return Object.keys(this).forEach(this.delete.bind(this))}normalize(e){const t=this,n={};return mn.forEach(this,((r,o)=>{const s=mn.findKey(n,o);if(s)return t[s]=Hn(r),void delete t[o];const i=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,((e,t,n)=>t.toUpperCase()+n))}(o):String(o).trim();i!==o&&delete t[o],t[i]=Hn(r),n[i]=!0})),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return mn.forEach(this,((n,r)=>{null!=n&&!1!==n&&(t[r]=e&&mn.isArray(n)?n.join(", "):n)})),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map((([e,t])=>e+": "+t)).join("\n")}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const n=new this(e);return t.forEach((e=>n.set(e))),n}static accessor(e){const t=(this[$n]=this[$n]={accessors:{}}).accessors,n=this.prototype;function r(e){const r=zn(e);t[r]||(!function(e,t){const n=mn.toCamelCase(" "+t);["get","set","has"].forEach((r=>{Object.defineProperty(e,r+n,{value:function(e,n,o){return this[r].call(this,t,e,n,o)},configurable:!0})}))}(n,e),t[r]=!0)}return mn.isArray(e)?e.forEach(r):r(e),this}}function Kn(e,t){const n=this||Ln,r=t||n,o=Wn.from(r.headers);let s=r.data;return mn.forEach(e,(function(e){s=e.call(n,s,o.normalize(),t?t.status:void 0)})),o.normalize(),s}function Qn(e){return!(!e||!e.__CANCEL__)}function Jn(e,t,n){yn.call(this,null==e?"canceled":e,yn.ERR_CANCELED,t,n),this.name="CanceledError"}Wn.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent"]),mn.freezeMethods(Wn.prototype),mn.freezeMethods(Wn),mn.inherits(Jn,yn,{__CANCEL__:!0});var Gn=Bn.isStandardBrowserEnv?{write:function(e,t,n,r,o,s){const i=[];i.push(e+"="+encodeURIComponent(t)),mn.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),mn.isString(r)&&i.push("path="+r),mn.isString(o)&&i.push("domain="+o),!0===s&&i.push("secure"),document.cookie=i.join("; ")},read:function(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}};function Yn(e,t){return e&&!function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}(t)?function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}var Xn=Bn.isStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),t=document.createElement("a");let n;function r(n){let r=n;return e&&(t.setAttribute("href",r),r=t.href),t.setAttribute("href",r),{href:t.href,protocol:t.protocol?t.protocol.replace(/:$/,""):"",host:t.host,search:t.search?t.search.replace(/^\?/,""):"",hash:t.hash?t.hash.replace(/^#/,""):"",hostname:t.hostname,port:t.port,pathname:"/"===t.pathname.charAt(0)?t.pathname:"/"+t.pathname}}return n=r(window.location.href),function(e){const t=mn.isString(e)?r(e):e;return t.protocol===n.protocol&&t.host===n.host}}():function(){return!0};function Zn(e,t){let n=0;const r=function(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o,s=0,i=0;return t=void 0!==t?t:1e3,function(a){const c=Date.now(),l=r[i];o||(o=c),n[s]=a,r[s]=c;let u=i,d=0;for(;u!==s;)d+=n[u++],u%=e;if(s=(s+1)%e,s===i&&(i=(i+1)%e),c-o<t)return;const h=l&&c-l;return h?Math.round(1e3*d/h):void 0}}(50,250);return o=>{const s=o.loaded,i=o.lengthComputable?o.total:void 0,a=s-n,c=r(a);n=s;const l={loaded:s,total:i,progress:i?s/i:void 0,bytes:a,rate:c||void 0,estimated:c&&i&&s<=i?(i-s)/c:void 0,event:o};l[t?"download":"upload"]=!0,e(l)}}var er="undefined"!=typeof XMLHttpRequest&&function(e){return new Promise((function(t,n){let r=e.data;const o=Wn.from(e.headers).normalize(),s=e.responseType;let i;function a(){e.cancelToken&&e.cancelToken.unsubscribe(i),e.signal&&e.signal.removeEventListener("abort",i)}mn.isFormData(r)&&(Bn.isStandardBrowserEnv||Bn.isStandardBrowserWebWorkerEnv)&&o.setContentType(!1);let c=new XMLHttpRequest;if(e.auth){const t=e.auth.username||"",n=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.set("Authorization","Basic "+btoa(t+":"+n))}const l=Yn(e.baseURL,e.url);function u(){if(!c)return;const r=Wn.from("getAllResponseHeaders"in c&&c.getAllResponseHeaders());!function(e,t,n){const r=n.config.validateStatus;n.status&&r&&!r(n.status)?t(new yn("Request failed with status code "+n.status,[yn.ERR_BAD_REQUEST,yn.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):e(n)}((function(e){t(e),a()}),(function(e){n(e),a()}),{data:s&&"text"!==s&&"json"!==s?c.response:c.responseText,status:c.status,statusText:c.statusText,headers:r,config:e,request:c}),c=null}if(c.open(e.method.toUpperCase(),xn(l,e.params,e.paramsSerializer),!0),c.timeout=e.timeout,"onloadend"in c?c.onloadend=u:c.onreadystatechange=function(){c&&4===c.readyState&&(0!==c.status||c.responseURL&&0===c.responseURL.indexOf("file:"))&&setTimeout(u)},c.onabort=function(){c&&(n(new yn("Request aborted",yn.ECONNABORTED,e,c)),c=null)},c.onerror=function(){n(new yn("Network Error",yn.ERR_NETWORK,e,c)),c=null},c.ontimeout=function(){let t=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded";const r=e.transitional||Pn;e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),n(new yn(t,r.clarifyTimeoutError?yn.ETIMEDOUT:yn.ECONNABORTED,e,c)),c=null},Bn.isStandardBrowserEnv){const t=(e.withCredentials||Xn(l))&&e.xsrfCookieName&&Gn.read(e.xsrfCookieName);t&&o.set(e.xsrfHeaderName,t)}void 0===r&&o.setContentType(null),"setRequestHeader"in c&&mn.forEach(o.toJSON(),(function(e,t){c.setRequestHeader(t,e)})),mn.isUndefined(e.withCredentials)||(c.withCredentials=!!e.withCredentials),s&&"json"!==s&&(c.responseType=e.responseType),"function"==typeof e.onDownloadProgress&&c.addEventListener("progress",Zn(e.onDownloadProgress,!0)),"function"==typeof e.onUploadProgress&&c.upload&&c.upload.addEventListener("progress",Zn(e.onUploadProgress)),(e.cancelToken||e.signal)&&(i=t=>{c&&(n(!t||t.type?new Jn(null,e,c):t),c.abort(),c=null)},e.cancelToken&&e.cancelToken.subscribe(i),e.signal&&(e.signal.aborted?i():e.signal.addEventListener("abort",i)));const d=function(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}(l);d&&-1===Bn.protocols.indexOf(d)?n(new yn("Unsupported protocol "+d+":",yn.ERR_BAD_REQUEST,e)):c.send(r||null)}))};const tr={http:null,xhr:er};mn.forEach(tr,((e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}}));var nr=e=>{e=mn.isArray(e)?e:[e];const{length:t}=e;let n,r;for(let o=0;o<t&&(n=e[o],!(r=mn.isString(n)?tr[n.toLowerCase()]:n));o++);if(!r){if(!1===r)throw new yn(`Adapter ${n} is not supported by the environment`,"ERR_NOT_SUPPORT");throw new Error(mn.hasOwnProp(tr,n)?`Adapter '${n}' is not available in the build`:`Unknown adapter '${n}'`)}if(!mn.isFunction(r))throw new TypeError("adapter is not a function");return r};function rr(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Jn(null,e)}function or(e){rr(e),e.headers=Wn.from(e.headers),e.data=Kn.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1);return nr(e.adapter||Ln.adapter)(e).then((function(t){return rr(e),t.data=Kn.call(e,e.transformResponse,t),t.headers=Wn.from(t.headers),t}),(function(t){return Qn(t)||(rr(e),t&&t.response&&(t.response.data=Kn.call(e,e.transformResponse,t.response),t.response.headers=Wn.from(t.response.headers))),Promise.reject(t)}))}const sr=e=>e instanceof Wn?e.toJSON():e;function ir(e,t){t=t||{};const n={};function r(e,t,n){return mn.isPlainObject(e)&&mn.isPlainObject(t)?mn.merge.call({caseless:n},e,t):mn.isPlainObject(t)?mn.merge({},t):mn.isArray(t)?t.slice():t}function o(e,t,n){return mn.isUndefined(t)?mn.isUndefined(e)?void 0:r(void 0,e,n):r(e,t,n)}function s(e,t){if(!mn.isUndefined(t))return r(void 0,t)}function i(e,t){return mn.isUndefined(t)?mn.isUndefined(e)?void 0:r(void 0,e):r(void 0,t)}function a(n,o,s){return s in t?r(n,o):s in e?r(void 0,n):void 0}const c={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(e,t)=>o(sr(e),sr(t),!0)};return mn.forEach(Object.keys(e).concat(Object.keys(t)),(function(r){const s=c[r]||o,i=s(e[r],t[r],r);mn.isUndefined(i)&&s!==a||(n[r]=i)})),n}const ar="1.2.3",cr={};["object","boolean","number","function","string","symbol"].forEach(((e,t)=>{cr[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}}));const lr={};cr.transitional=function(e,t,n){function r(e,t){return"[Axios v1.2.3] Transitional option '"+e+"'"+t+(n?". "+n:"")}return(n,o,s)=>{if(!1===e)throw new yn(r(o," has been removed"+(t?" in "+t:"")),yn.ERR_DEPRECATED);return t&&!lr[o]&&(lr[o]=!0,console.warn(r(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(n,o,s)}};var ur={assertOptions:function(e,t,n){if("object"!=typeof e)throw new yn("options must be an object",yn.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const t=e[s],n=void 0===t||i(t,s,e);if(!0!==n)throw new yn("option "+s+" must be "+n,yn.ERR_BAD_OPTION_VALUE)}else if(!0!==n)throw new yn("Unknown option "+s,yn.ERR_BAD_OPTION)}},validators:cr};const dr=ur.validators;class hr{constructor(e){this.defaults=e,this.interceptors={request:new Rn,response:new Rn}}request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=ir(this.defaults,t);const{transitional:n,paramsSerializer:r,headers:o}=t;let s;void 0!==n&&ur.assertOptions(n,{silentJSONParsing:dr.transitional(dr.boolean),forcedJSONParsing:dr.transitional(dr.boolean),clarifyTimeoutError:dr.transitional(dr.boolean)},!1),void 0!==r&&ur.assertOptions(r,{encode:dr.function,serialize:dr.function},!0),t.method=(t.method||this.defaults.method||"get").toLowerCase(),s=o&&mn.merge(o.common,o[t.method]),s&&mn.forEach(["delete","get","head","post","put","patch","common"],(e=>{delete o[e]})),t.headers=Wn.concat(s,o);const i=[];let a=!0;this.interceptors.request.forEach((function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(a=a&&e.synchronous,i.unshift(e.fulfilled,e.rejected))}));const c=[];let l;this.interceptors.response.forEach((function(e){c.push(e.fulfilled,e.rejected)}));let u,d=0;if(!a){const e=[or.bind(this),void 0];for(e.unshift.apply(e,i),e.push.apply(e,c),u=e.length,l=Promise.resolve(t);d<u;)l=l.then(e[d++],e[d++]);return l}u=i.length;let h=t;for(d=0;d<u;){const e=i[d++],t=i[d++];try{h=e(h)}catch(e){t.call(this,e);break}}try{l=or.call(this,h)}catch(e){return Promise.reject(e)}for(d=0,u=c.length;d<u;)l=l.then(c[d++],c[d++]);return l}getUri(e){return xn(Yn((e=ir(this.defaults,e)).baseURL,e.url),e.params,e.paramsSerializer)}}mn.forEach(["delete","get","head","options"],(function(e){hr.prototype[e]=function(t,n){return this.request(ir(n||{},{method:e,url:t,data:(n||{}).data}))}})),mn.forEach(["post","put","patch"],(function(e){function t(t){return function(n,r,o){return this.request(ir(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}hr.prototype[e]=t(),hr.prototype[e+"Form"]=t(!0)}));class fr{constructor(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((function(e){t=e}));const n=this;this.promise.then((e=>{if(!n._listeners)return;let t=n._listeners.length;for(;t-- >0;)n._listeners[t](e);n._listeners=null})),this.promise.then=e=>{let t;const r=new Promise((e=>{n.subscribe(e),t=e})).then(e);return r.cancel=function(){n.unsubscribe(t)},r},e((function(e,r,o){n.reason||(n.reason=new Jn(e,r,o),t(n.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}static source(){let e;return{token:new fr((function(t){e=t})),cancel:e}}}const pr={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(pr).forEach((([e,t])=>{pr[t]=e}));const gr=function e(t){const n=new hr(t),r=Dt(hr.prototype.request,n);return mn.extend(r,hr.prototype,n,{allOwnKeys:!0}),mn.extend(r,n,null,{allOwnKeys:!0}),r.create=function(n){return e(ir(t,n))},r}(Ln);gr.Axios=hr,gr.CanceledError=Jn,gr.CancelToken=fr,gr.isCancel=Qn,gr.VERSION=ar,gr.toFormData=An,gr.AxiosError=yn,gr.Cancel=gr.CanceledError,gr.all=function(e){return Promise.all(e)},gr.spread=function(e){return function(t){return e.apply(null,t)}},gr.isAxiosError=function(e){return mn.isObject(e)&&!0===e.isAxiosError},gr.mergeConfig=ir,gr.AxiosHeaders=Wn,gr.formToJSON=e=>Un(mn.isHTMLForm(e)?new FormData(e):e),gr.HttpStatusCode=pr,gr.default=gr;var mr={exports:{}};mr.exports=vr;var yr=mr.exports.HttpsAgent=vr;function vr(){}const br=e=>{if("success"===e.status)return e.data;if("fail"===e.status)throw new ye(e.code);if("error"===e.status)throw new me(e.message,e.code,"error")};var wr;!function(e){e.UserDeleted="User Deleted",e.UserGlobalBanned="User Global Banned",e.TokenExpired="Token Expired"}(wr||(wr={}));const Cr=new AbortController,_r=e=>{switch(e){case wr.UserGlobalBanned:throw new ge(e,400312,"fatal");case wr.UserDeleted:throw new ge(e,400100,"fatal");case wr.TokenExpired:throw ut("tokenExpired","tokenExpired"),new ge(e,800403,"fatal");default:throw new ge("Request Aborted",8e5,"error")}},kr=e=>{const t={maxSockets:100,maxFreeSockets:10,timeout:6e4,freeSocketTimeout:3e4},n=gr.create({baseURL:e,httpAgent:new mr.exports(t),httpsAgent:new yr(t),signal:Cr.signal});return n.interceptors.request.use((e=>{if("/api/v4/sessions"===e.url)return e;if(e.metadata){const{tokenExpiry:t,isGlobalBanned:n,isUserDeleted:r}=e.metadata;n&&(Cr.abort(),_r(wr.UserGlobalBanned)),r&&(Cr.abort(),_r(wr.UserDeleted)),t&&Date.now()>=Date.parse(t)&&(Cr.abort(wr.UserDeleted),_r(wr.TokenExpired))}return e})),n.interceptors.response.use((e=>e),(e=>{var t,n;const{response:r}=e;if(400100===(null==r?void 0:r.data.code)&&ut("tokenTerminated","terminated"),(null===(t=null==r?void 0:r.data)||void 0===t?void 0:t.status)&&br(null==r?void 0:r.data),Cr.signal.aborted)throw e;throw new Error(null!==(n=null==r?void 0:r.data)&&void 0!==n?n:e)})),n};var Sr={exports:{}},Ar=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Er=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],Ir=function(e){var t=e,n=e.indexOf("["),r=e.indexOf("]");-1!=n&&-1!=r&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));for(var o=Ar.exec(e||""),s={},i=14;i--;)s[Er[i]]=o[i]||"";return-1!=n&&-1!=r&&(s.source=t,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("[","").replace("]","").replace(/;/g,":"),s.ipv6uri=!0),s},Or={exports:{}},Tr={exports:{}},xr=1e3,Rr=6e4,Pr=60*Rr,Mr=24*Pr,jr=365.25*Mr,Fr=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*jr;case"days":case"day":case"d":return n*Mr;case"hours":case"hour":case"hrs":case"hr":case"h":return n*Pr;case"minutes":case"minute":case"mins":case"min":case"m":return n*Rr;case"seconds":case"second":case"secs":case"sec":case"s":return n*xr;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(e);if("number"===n&&!1===isNaN(e))return t.long?function(e){return Nr(e,Mr,"day")||Nr(e,Pr,"hour")||Nr(e,Rr,"minute")||Nr(e,xr,"second")||e+" ms"}(e):function(e){if(e>=Mr)return Math.round(e/Mr)+"d";if(e>=Pr)return Math.round(e/Pr)+"h";if(e>=Rr)return Math.round(e/Rr)+"m";if(e>=xr)return Math.round(e/xr)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function Nr(e,t,n){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}!function(e,t){function n(e){var n;function o(){if(o.enabled){var e=o,r=+new Date,s=r-(n||r);e.diff=s,e.prev=n,e.curr=r,n=r;for(var i=new Array(arguments.length),a=0;a<i.length;a++)i[a]=arguments[a];i[0]=t.coerce(i[0]),"string"!=typeof i[0]&&i.unshift("%O");var c=0;i[0]=i[0].replace(/%([a-zA-Z%])/g,(function(n,r){if("%%"===n)return n;c++;var o=t.formatters[r];if("function"==typeof o){var s=i[c];n=o.call(e,s),i.splice(c,1),c--}return n})),t.formatArgs.call(e,i);var l=o.log||t.log||console.log.bind(console);l.apply(e,i)}}return o.namespace=e,o.enabled=t.enabled(e),o.useColors=t.useColors(),o.color=function(e){var n,r=0;for(n in e)r=(r<<5)-r+e.charCodeAt(n),r|=0;return t.colors[Math.abs(r)%t.colors.length]}(e),o.destroy=r,"function"==typeof t.init&&t.init(o),t.instances.push(o),o}function r(){var e=t.instances.indexOf(this);return-1!==e&&(t.instances.splice(e,1),!0)}(t=e.exports=n.debug=n.default=n).coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){t.enable("")},t.enable=function(e){var n;t.save(e),t.names=[],t.skips=[];var r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(n=0;n<o;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")));for(n=0;n<t.instances.length;n++){var s=t.instances[n];s.enabled=t.enabled(s.namespace)}},t.enabled=function(e){if("*"===e[e.length-1])return!0;var n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=Fr,t.instances=[],t.names=[],t.skips=[],t.formatters={}}(Tr,Tr.exports),function(e,t){function n(){var e;try{e=t.storage.debug}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e}(t=e.exports=Tr.exports).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},t.formatArgs=function(e){var n=this.useColors;if(e[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+e[0]+(n?"%c ":" ")+"+"+t.humanize(this.diff),!n)return;var r="color: "+this.color;e.splice(1,0,r,"color: inherit");var o=0,s=0;e[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(o++,"%c"===e&&(s=o))})),e.splice(s,0,r)},t.save=function(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}},t.load=n,t.useColors=function(){if("undefined"!=typeof window&&window.process&&"renderer"===window.process.type)return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(n())}(Or,Or.exports);var Br=Ir,Ur=Or.exports("socket.io-client:url"),Dr=function(e,t){var n=e;t=t||"undefined"!=typeof location&&location,null==e&&(e=t.protocol+"//"+t.host);"string"==typeof e&&("/"===e.charAt(0)&&(e="/"===e.charAt(1)?t.protocol+e:t.host+e),/^(https?|wss?):\/\//.test(e)||(Ur("protocol-less url %s",e),e=void 0!==t?t.protocol+"//"+e:"https://"+e),Ur("parse %s",e),n=Br(e));n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443"));n.path=n.path||"/";var r=-1!==n.host.indexOf(":")?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+r+":"+n.port,n.href=n.protocol+"://"+r+(t&&t.port===n.port?"":":"+n.port),n};var Lr={},qr={exports:{}},$r={exports:{}},zr=1e3,Hr=6e4,Vr=60*Hr,Wr=24*Vr,Kr=365.25*Wr,Qr=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*Kr;case"days":case"day":case"d":return n*Wr;case"hours":case"hour":case"hrs":case"hr":case"h":return n*Vr;case"minutes":case"minute":case"mins":case"min":case"m":return n*Hr;case"seconds":case"second":case"secs":case"sec":case"s":return n*zr;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(e);if("number"===n&&!1===isNaN(e))return t.long?function(e){return Jr(e,Wr,"day")||Jr(e,Vr,"hour")||Jr(e,Hr,"minute")||Jr(e,zr,"second")||e+" ms"}(e):function(e){if(e>=Wr)return Math.round(e/Wr)+"d";if(e>=Vr)return Math.round(e/Vr)+"h";if(e>=Hr)return Math.round(e/Hr)+"m";if(e>=zr)return Math.round(e/zr)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function Jr(e,t,n){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}!function(e,t){function n(e){var n;function o(){if(o.enabled){var e=o,r=+new Date,s=r-(n||r);e.diff=s,e.prev=n,e.curr=r,n=r;for(var i=new Array(arguments.length),a=0;a<i.length;a++)i[a]=arguments[a];i[0]=t.coerce(i[0]),"string"!=typeof i[0]&&i.unshift("%O");var c=0;i[0]=i[0].replace(/%([a-zA-Z%])/g,(function(n,r){if("%%"===n)return n;c++;var o=t.formatters[r];if("function"==typeof o){var s=i[c];n=o.call(e,s),i.splice(c,1),c--}return n})),t.formatArgs.call(e,i);var l=o.log||t.log||console.log.bind(console);l.apply(e,i)}}return o.namespace=e,o.enabled=t.enabled(e),o.useColors=t.useColors(),o.color=function(e){var n,r=0;for(n in e)r=(r<<5)-r+e.charCodeAt(n),r|=0;return t.colors[Math.abs(r)%t.colors.length]}(e),o.destroy=r,"function"==typeof t.init&&t.init(o),t.instances.push(o),o}function r(){var e=t.instances.indexOf(this);return-1!==e&&(t.instances.splice(e,1),!0)}(t=e.exports=n.debug=n.default=n).coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){t.enable("")},t.enable=function(e){var n;t.save(e),t.names=[],t.skips=[];var r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(n=0;n<o;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")));for(n=0;n<t.instances.length;n++){var s=t.instances[n];s.enabled=t.enabled(s.namespace)}},t.enabled=function(e){if("*"===e[e.length-1])return!0;var n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=Qr,t.instances=[],t.names=[],t.skips=[],t.formatters={}}($r,$r.exports),function(e,t){function n(){var e;try{e=t.storage.debug}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e}(t=e.exports=$r.exports).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},t.formatArgs=function(e){var n=this.useColors;if(e[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+e[0]+(n?"%c ":" ")+"+"+t.humanize(this.diff),!n)return;var r="color: "+this.color;e.splice(1,0,r,"color: inherit");var o=0,s=0;e[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(o++,"%c"===e&&(s=o))})),e.splice(s,0,r)},t.save=function(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}},t.load=n,t.useColors=function(){if("undefined"!=typeof window&&window.process&&"renderer"===window.process.type)return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(n())}(qr,qr.exports);var Gr={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;o<r.length;o++)if((n=r[o])===t||n.fn===t){r.splice(o,1);break}return 0===r.length&&delete this._callbacks["$"+e],this},t.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),n=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){r=0;for(var o=(n=n.slice(0)).length;r<o;++r)n[r].apply(this,t)}return this},t.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},t.prototype.hasListeners=function(e){return!!this.listeners(e).length}}(Gr);var Yr={},Xr={}.toString,Zr=Array.isArray||function(e){return"[object Array]"==Xr.call(e)},eo=function(e){return to&&Buffer.isBuffer(e)||no&&(e instanceof ArrayBuffer||function(e){return"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer}(e))},to="function"==typeof Buffer&&"function"==typeof Buffer.isBuffer,no="function"==typeof ArrayBuffer;var ro=Zr,oo=eo,so=Object.prototype.toString,io="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===so.call(Blob),ao="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===so.call(File);function co(e,t){if(!e)return e;if(oo(e)){var n={_placeholder:!0,num:t.length};return t.push(e),n}if(ro(e)){for(var r=new Array(e.length),o=0;o<e.length;o++)r[o]=co(e[o],t);return r}if("object"==typeof e&&!(e instanceof Date)){r={};for(var s in e)r[s]=co(e[s],t);return r}return e}function lo(e,t){if(!e)return e;if(e&&e._placeholder)return t[e.num];if(ro(e))for(var n=0;n<e.length;n++)e[n]=lo(e[n],t);else if("object"==typeof e)for(var r in e)e[r]=lo(e[r],t);return e}Yr.deconstructPacket=function(e){var t=[],n=e.data,r=e;return r.data=co(n,t),r.attachments=t.length,{packet:r,buffers:t}},Yr.reconstructPacket=function(e,t){return e.data=lo(e.data,t),e.attachments=void 0,e},Yr.removeBlobs=function(e,t){var n=0,r=e;!function e(o,s,i){if(!o)return o;if(io&&o instanceof Blob||ao&&o instanceof File){n++;var a=new FileReader;a.onload=function(){i?i[s]=this.result:r=this.result,--n||t(r)},a.readAsArrayBuffer(o)}else if(ro(o))for(var c=0;c<o.length;c++)e(o[c],c,o);else if("object"==typeof o&&!oo(o))for(var l in o)e(o[l],l,o)}(r),n||t(r)},function(e){var t=qr.exports("socket.io-parser"),n=Gr.exports,r=Yr,o=Zr,s=eo;function i(){}e.protocol=4,e.types=["CONNECT","DISCONNECT","EVENT","ACK","ERROR","BINARY_EVENT","BINARY_ACK"],e.CONNECT=0,e.DISCONNECT=1,e.EVENT=2,e.ACK=3,e.ERROR=4,e.BINARY_EVENT=5,e.BINARY_ACK=6,e.Encoder=i,e.Decoder=l;var a=e.ERROR+'"encode error"';function c(n){var r=""+n.type;if(e.BINARY_EVENT!==n.type&&e.BINARY_ACK!==n.type||(r+=n.attachments+"-"),n.nsp&&"/"!==n.nsp&&(r+=n.nsp+","),null!=n.id&&(r+=n.id),null!=n.data){var o=function(e){try{return JSON.stringify(e)}catch(e){return!1}}(n.data);if(!1===o)return a;r+=o}return t("encoded %j as %s",n,r),r}function l(){this.reconstructor=null}function u(e){this.reconPack=e,this.buffers=[]}function d(t){return{type:e.ERROR,data:"parser error: "+t}}i.prototype.encode=function(n,o){(t("encoding packet %j",n),e.BINARY_EVENT===n.type||e.BINARY_ACK===n.type)?function(e,t){function n(e){var n=r.deconstructPacket(e),o=c(n.packet),s=n.buffers;s.unshift(o),t(s)}r.removeBlobs(e,n)}(n,o):o([c(n)])},n(l.prototype),l.prototype.add=function(n){var r;if("string"==typeof n)r=function(n){var r=0,s={type:Number(n.charAt(0))};if(null==e.types[s.type])return d("unknown packet type "+s.type);if(e.BINARY_EVENT===s.type||e.BINARY_ACK===s.type){for(var i=r+1;"-"!==n.charAt(++r)&&r!=n.length;);var a=n.substring(i,r);if(a!=Number(a)||"-"!==n.charAt(r))throw new Error("Illegal attachments");s.attachments=Number(a)}if("/"===n.charAt(r+1)){for(i=r+1;++r;){if(","===(l=n.charAt(r)))break;if(r===n.length)break}s.nsp=n.substring(i,r)}else s.nsp="/";var c=n.charAt(r+1);if(""!==c&&Number(c)==c){for(i=r+1;++r;){var l;if(null==(l=n.charAt(r))||Number(l)!=l){--r;break}if(r===n.length)break}s.id=Number(n.substring(i,r+1))}if(n.charAt(++r)){var u=function(e){try{return JSON.parse(e)}catch(e){return!1}}(n.substr(r));if(!(!1!==u&&(s.type===e.ERROR||o(u))))return d("invalid payload");s.data=u}return t("decoded %s as %j",n,s),s}(n),e.BINARY_EVENT===r.type||e.BINARY_ACK===r.type?(this.reconstructor=new u(r),0===this.reconstructor.reconPack.attachments&&this.emit("decoded",r)):this.emit("decoded",r);else{if(!s(n)&&!n.base64)throw new Error("Unknown type: "+n);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");(r=this.reconstructor.takeBinaryData(n))&&(this.reconstructor=null,this.emit("decoded",r))}},l.prototype.destroy=function(){this.reconstructor&&this.reconstructor.finishedReconstruction()},u.prototype.takeBinaryData=function(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){var t=r.reconstructPacket(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null},u.prototype.finishedReconstruction=function(){this.reconPack=null,this.buffers=[]}}(Lr);var uo={exports:{}},ho={},fo={exports:{}};try{fo.exports="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(e){fo.exports=!1}var po,go,mo,yo,vo=fo.exports,bo=function(e){var t=e.xdomain,n=e.xscheme,r=e.enablesXDR;try{if("undefined"!=typeof XMLHttpRequest&&(!t||vo))return new XMLHttpRequest}catch(e){}try{if("undefined"!=typeof XDomainRequest&&!n&&r)return new XDomainRequest}catch(e){}if(!t)try{return new(self[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(e){}},wo={exports:{}},Co={},_o=Object.keys||function(e){var t=[],n=Object.prototype.hasOwnProperty;for(var r in e)n.call(e,r)&&t.push(r);return t};function ko(){if(yo)return mo;yo=1;var e=function(){if(go)return po;go=1;var e={}.toString;return po=Array.isArray||function(t){return"[object Array]"==e.call(t)}}(),t=Object.prototype.toString,n="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===t.call(Blob),r="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===t.call(File);return mo=function t(o){if(!o||"object"!=typeof o)return!1;if(e(o)){for(var s=0,i=o.length;s<i;s++)if(t(o[s]))return!0;return!1}if("function"==typeof Buffer&&Buffer.isBuffer&&Buffer.isBuffer(o)||"function"==typeof ArrayBuffer&&o instanceof ArrayBuffer||n&&o instanceof Blob||r&&o instanceof File)return!0;if(o.toJSON&&"function"==typeof o.toJSON&&1===arguments.length)return t(o.toJSON(),!0);for(var a in o)if(Object.prototype.hasOwnProperty.call(o,a)&&t(o[a]))return!0;return!1},mo}var So=function(e,t,n){var r=e.byteLength;if(t=t||0,n=n||r,e.slice)return e.slice(t,n);if(t<0&&(t+=r),n<0&&(n+=r),n>r&&(n=r),t>=r||t>=n||0===r)return new ArrayBuffer(0);for(var o=new Uint8Array(e),s=new Uint8Array(n-t),i=t,a=0;i<n;i++,a++)s[a]=o[i];return s.buffer},Ao=function(e,t,n){var r=!1;return n=n||Eo,o.count=e,0===e?t():o;function o(e,s){if(o.count<=0)throw new Error("after called too many times");--o.count,e?(r=!0,t(e),t=n):0!==o.count||r||t(null,s)}};function Eo(){}
2
2
  /*! https://mths.be/utf8js v2.1.2 by @mathias */var Io,Oo,To,xo=String.fromCharCode;function Ro(e){for(var t,n,r=[],o=0,s=e.length;o<s;)(t=e.charCodeAt(o++))>=55296&&t<=56319&&o<s?56320==(64512&(n=e.charCodeAt(o++)))?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),o--):r.push(t);return r}function Po(e,t){if(e>=55296&&e<=57343){if(t)throw Error("Lone surrogate U+"+e.toString(16).toUpperCase()+" is not a scalar value");return!1}return!0}function Mo(e,t){return xo(e>>t&63|128)}function jo(e,t){if(0==(4294967168&e))return xo(e);var n="";return 0==(4294965248&e)?n=xo(e>>6&31|192):0==(4294901760&e)?(Po(e,t)||(e=65533),n=xo(e>>12&15|224),n+=Mo(e,6)):0==(4292870144&e)&&(n=xo(e>>18&7|240),n+=Mo(e,12),n+=Mo(e,6)),n+=xo(63&e|128)}function Fo(){if(To>=Oo)throw Error("Invalid byte index");var e=255&Io[To];if(To++,128==(192&e))return 63&e;throw Error("Invalid continuation byte")}function No(e){var t,n;if(To>Oo)throw Error("Invalid byte index");if(To==Oo)return!1;if(t=255&Io[To],To++,0==(128&t))return t;if(192==(224&t)){if((n=(31&t)<<6|Fo())>=128)return n;throw Error("Invalid continuation byte")}if(224==(240&t)){if((n=(15&t)<<12|Fo()<<6|Fo())>=2048)return Po(n,e)?n:65533;throw Error("Invalid continuation byte")}if(240==(248&t)&&(n=(7&t)<<18|Fo()<<12|Fo()<<6|Fo())>=65536&&n<=1114111)return n;throw Error("Invalid UTF-8 detected")}var Bo,Uo,Do,Lo={version:"2.1.2",encode:function(e,t){for(var n=!1!==(t=t||{}).strict,r=Ro(e),o=r.length,s=-1,i="";++s<o;)i+=jo(r[s],n);return i},decode:function(e,t){var n=!1!==(t=t||{}).strict;Io=Ro(e),Oo=Io.length,To=0;for(var r,o=[];!1!==(r=No(n));)o.push(r);return function(e){for(var t,n=e.length,r=-1,o="";++r<n;)(t=e[r])>65535&&(o+=xo((t-=65536)>>>10&1023|55296),t=56320|1023&t),o+=xo(t);return o}(o)}},qo={};function $o(){if(Do)return Uo;Do=1;var e=void 0!==e?e:"undefined"!=typeof WebKitBlobBuilder?WebKitBlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder&&MozBlobBuilder,t=function(){try{return 2===new Blob(["hi"]).size}catch(e){return!1}}(),n=t&&function(){try{return 2===new Blob([new Uint8Array([1,2])]).size}catch(e){return!1}}(),r=e&&e.prototype.append&&e.prototype.getBlob;function o(e){return e.map((function(e){if(e.buffer instanceof ArrayBuffer){var t=e.buffer;if(e.byteLength!==t.byteLength){var n=new Uint8Array(e.byteLength);n.set(new Uint8Array(t,e.byteOffset,e.byteLength)),t=n.buffer}return t}return e}))}function s(t,n){n=n||{};var r=new e;return o(t).forEach((function(e){r.append(e)})),n.type?r.getBlob(n.type):r.getBlob()}function i(e,t){return new Blob(o(e),t||{})}return"undefined"!=typeof Blob&&(s.prototype=Blob.prototype,i.prototype=Blob.prototype),Uo=t?n?Blob:i:r?s:void 0}!function(e){var t,n=_o,r=ko(),o=So,s=Ao,i=Lo;"undefined"!=typeof ArrayBuffer&&(Bo||(Bo=1,function(){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=new Uint8Array(256),n=0;n<e.length;n++)t[e.charCodeAt(n)]=n;qo.encode=function(t){var n,r=new Uint8Array(t),o=r.length,s="";for(n=0;n<o;n+=3)s+=e[r[n]>>2],s+=e[(3&r[n])<<4|r[n+1]>>4],s+=e[(15&r[n+1])<<2|r[n+2]>>6],s+=e[63&r[n+2]];return o%3==2?s=s.substring(0,s.length-1)+"=":o%3==1&&(s=s.substring(0,s.length-2)+"=="),s},qo.decode=function(e){var n,r,o,s,i,a=.75*e.length,c=e.length,l=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var u=new ArrayBuffer(a),d=new Uint8Array(u);for(n=0;n<c;n+=4)r=t[e.charCodeAt(n)],o=t[e.charCodeAt(n+1)],s=t[e.charCodeAt(n+2)],i=t[e.charCodeAt(n+3)],d[l++]=r<<2|o>>4,d[l++]=(15&o)<<4|s>>2,d[l++]=(3&s)<<6|63&i;return u}}()),t=qo);var a="undefined"!=typeof navigator&&/Android/i.test(navigator.userAgent),c="undefined"!=typeof navigator&&/PhantomJS/i.test(navigator.userAgent),l=a||c;e.protocol=3;var u=e.packets={open:0,close:1,ping:2,pong:3,message:4,upgrade:5,noop:6},d=n(u),h={type:"error",data:"parser error"},f=$o();function p(e,t,n){for(var r=new Array(e.length),o=s(e.length,n),i=function(e,n,o){t(n,(function(t,n){r[e]=n,o(t,r)}))},a=0;a<e.length;a++)i(a,e[a],o)}e.encodePacket=function(t,n,r,o){"function"==typeof n&&(o=n,n=!1),"function"==typeof r&&(o=r,r=null);var s=void 0===t.data?void 0:t.data.buffer||t.data;if("undefined"!=typeof ArrayBuffer&&s instanceof ArrayBuffer)return function(t,n,r){if(!n)return e.encodeBase64Packet(t,r);var o=t.data,s=new Uint8Array(o),i=new Uint8Array(1+o.byteLength);i[0]=u[t.type];for(var a=0;a<s.length;a++)i[a+1]=s[a];return r(i.buffer)}(t,n,o);if(void 0!==f&&s instanceof f)return function(t,n,r){if(!n)return e.encodeBase64Packet(t,r);if(l)return function(t,n,r){if(!n)return e.encodeBase64Packet(t,r);var o=new FileReader;return o.onload=function(){e.encodePacket({type:t.type,data:o.result},n,!0,r)},o.readAsArrayBuffer(t.data)}(t,n,r);var o=new Uint8Array(1);o[0]=u[t.type];var s=new f([o.buffer,t.data]);return r(s)}(t,n,o);if(s&&s.base64)return function(t,n){var r="b"+e.packets[t.type]+t.data.data;return n(r)}(t,o);var a=u[t.type];return void 0!==t.data&&(a+=r?i.encode(String(t.data),{strict:!1}):String(t.data)),o(""+a)},e.encodeBase64Packet=function(t,n){var r,o="b"+e.packets[t.type];if(void 0!==f&&t.data instanceof f){var s=new FileReader;return s.onload=function(){var e=s.result.split(",")[1];n(o+e)},s.readAsDataURL(t.data)}try{r=String.fromCharCode.apply(null,new Uint8Array(t.data))}catch(e){for(var i=new Uint8Array(t.data),a=new Array(i.length),c=0;c<i.length;c++)a[c]=i[c];r=String.fromCharCode.apply(null,a)}return o+=btoa(r),n(o)},e.decodePacket=function(t,n,r){if(void 0===t)return h;if("string"==typeof t){if("b"===t.charAt(0))return e.decodeBase64Packet(t.substr(1),n);if(r&&!1===(t=function(e){try{e=i.decode(e,{strict:!1})}catch(e){return!1}return e}(t)))return h;var s=t.charAt(0);return Number(s)==s&&d[s]?t.length>1?{type:d[s],data:t.substring(1)}:{type:d[s]}:h}s=new Uint8Array(t)[0];var a=o(t,1);return f&&"blob"===n&&(a=new f([a])),{type:d[s],data:a}},e.decodeBase64Packet=function(e,n){var r=d[e.charAt(0)];if(!t)return{type:r,data:{base64:!0,data:e.substr(1)}};var o=t.decode(e.substr(1));return"blob"===n&&f&&(o=new f([o])),{type:r,data:o}},e.encodePayload=function(t,n,o){"function"==typeof n&&(o=n,n=null);var s=r(t);if(n&&s)return f&&!l?e.encodePayloadAsBlob(t,o):e.encodePayloadAsArrayBuffer(t,o);if(!t.length)return o("0:");p(t,(function(t,r){e.encodePacket(t,!!s&&n,!1,(function(e){r(null,function(e){return e.length+":"+e}(e))}))}),(function(e,t){return o(t.join(""))}))},e.decodePayload=function(t,n,r){if("string"!=typeof t)return e.decodePayloadAsBinary(t,n,r);var o;if("function"==typeof n&&(r=n,n=null),""===t)return r(h,0,1);for(var s,i,a="",c=0,l=t.length;c<l;c++){var u=t.charAt(c);if(":"===u){if(""===a||a!=(s=Number(a)))return r(h,0,1);if(a!=(i=t.substr(c+1,s)).length)return r(h,0,1);if(i.length){if(o=e.decodePacket(i,n,!1),h.type===o.type&&h.data===o.data)return r(h,0,1);if(!1===r(o,c+s,l))return}c+=s,a=""}else a+=u}return""!==a?r(h,0,1):void 0},e.encodePayloadAsArrayBuffer=function(t,n){if(!t.length)return n(new ArrayBuffer(0));p(t,(function(t,n){e.encodePacket(t,!0,!0,(function(e){return n(null,e)}))}),(function(e,t){var r=t.reduce((function(e,t){var n;return e+(n="string"==typeof t?t.length:t.byteLength).toString().length+n+2}),0),o=new Uint8Array(r),s=0;return t.forEach((function(e){var t="string"==typeof e,n=e;if(t){for(var r=new Uint8Array(e.length),i=0;i<e.length;i++)r[i]=e.charCodeAt(i);n=r.buffer}o[s++]=t?0:1;var a=n.byteLength.toString();for(i=0;i<a.length;i++)o[s++]=parseInt(a[i]);o[s++]=255;for(r=new Uint8Array(n),i=0;i<r.length;i++)o[s++]=r[i]})),n(o.buffer)}))},e.encodePayloadAsBlob=function(t,n){p(t,(function(t,n){e.encodePacket(t,!0,!0,(function(e){var t=new Uint8Array(1);if(t[0]=1,"string"==typeof e){for(var r=new Uint8Array(e.length),o=0;o<e.length;o++)r[o]=e.charCodeAt(o);e=r.buffer,t[0]=0}var s=(e instanceof ArrayBuffer?e.byteLength:e.size).toString(),i=new Uint8Array(s.length+1);for(o=0;o<s.length;o++)i[o]=parseInt(s[o]);if(i[s.length]=255,f){var a=new f([t.buffer,i.buffer,e]);n(null,a)}}))}),(function(e,t){return n(new f(t))}))},e.decodePayloadAsBinary=function(t,n,r){"function"==typeof n&&(r=n,n=null);for(var s=t,i=[];s.byteLength>0;){for(var a=new Uint8Array(s),c=0===a[0],l="",u=1;255!==a[u];u++){if(l.length>310)return r(h,0,1);l+=a[u]}s=o(s,2+l.length),l=parseInt(l);var d=o(s,0,l);if(c)try{d=String.fromCharCode.apply(null,new Uint8Array(d))}catch(e){var f=new Uint8Array(d);d="";for(u=0;u<f.length;u++)d+=String.fromCharCode(f[u])}i.push(d),s=o(s,l)}var p=i.length;i.forEach((function(t,o){r(e.decodePacket(t,n,!0),o,p)}))}}(Co);var zo,Ho,Vo={exports:{}};function Wo(){if(Ho)return zo;Ho=1;var e=Co;function t(e){this.path=e.path,this.hostname=e.hostname,this.port=e.port,this.secure=e.secure,this.query=e.query,this.timestampParam=e.timestampParam,this.timestampRequests=e.timestampRequests,this.readyState="",this.agent=e.agent||!1,this.socket=e.socket,this.enablesXDR=e.enablesXDR,this.pfx=e.pfx,this.key=e.key,this.passphrase=e.passphrase,this.cert=e.cert,this.ca=e.ca,this.ciphers=e.ciphers,this.rejectUnauthorized=e.rejectUnauthorized,this.forceNode=e.forceNode,this.isReactNative=e.isReactNative,this.extraHeaders=e.extraHeaders,this.localAddress=e.localAddress}return zo=t,(0,Vo.exports)(t.prototype),t.prototype.onError=function(e,t){var n=new Error(e);return n.type="TransportError",n.description=t,this.emit("error",n),this},t.prototype.open=function(){return"closed"!==this.readyState&&""!==this.readyState||(this.readyState="opening",this.doOpen()),this},t.prototype.close=function(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this},t.prototype.send=function(e){if("open"!==this.readyState)throw new Error("Transport not open");this.write(e)},t.prototype.onOpen=function(){this.readyState="open",this.writable=!0,this.emit("open")},t.prototype.onData=function(t){var n=e.decodePacket(t,this.socket.binaryType);this.onPacket(n)},t.prototype.onPacket=function(e){this.emit("packet",e)},t.prototype.onClose=function(){this.readyState="closed",this.emit("close")},zo}!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;o<r.length;o++)if((n=r[o])===t||n.fn===t){r.splice(o,1);break}return this},t.prototype.emit=function(e){this._callbacks=this._callbacks||{};var t=[].slice.call(arguments,1),n=this._callbacks["$"+e];if(n)for(var r=0,o=(n=n.slice(0)).length;r<o;++r)n[r].apply(this,t);return this},t.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},t.prototype.hasListeners=function(e){return!!this.listeners(e).length}}(Vo);var Ko,Qo={};function Jo(){return Ko||(Ko=1,Qo.encode=function(e){var t="";for(var n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t},Qo.decode=function(e){for(var t={},n=e.split("&"),r=0,o=n.length;r<o;r++){var s=n[r].split("=");t[decodeURIComponent(s[0])]=decodeURIComponent(s[1])}return t}),Qo}var Go,Yo=function(e,t){var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e},Xo="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),Zo={},es=0,ts=0;function ns(e){var t="";do{t=Xo[e%64]+t,e=Math.floor(e/64)}while(e>0);return t}function rs(){var e=ns(+new Date);return e!==Go?(es=0,Go=e):e+"."+ns(es++)}for(;ts<64;ts++)Zo[Xo[ts]]=ts;rs.encode=ns,rs.decode=function(e){var t=0;for(ts=0;ts<e.length;ts++)t=64*t+Zo[e.charAt(ts)];return t};var os=rs,ss={exports:{}},is={exports:{}},as=1e3,cs=60*as,ls=60*cs,us=24*ls,ds=365.25*us,hs=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*ds;case"days":case"day":case"d":return n*us;case"hours":case"hour":case"hrs":case"hr":case"h":return n*ls;case"minutes":case"minute":case"mins":case"min":case"m":return n*cs;case"seconds":case"second":case"secs":case"sec":case"s":return n*as;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(e);if("number"===n&&!1===isNaN(e))return t.long?function(e){return fs(e,us,"day")||fs(e,ls,"hour")||fs(e,cs,"minute")||fs(e,as,"second")||e+" ms"}(e):function(e){if(e>=us)return Math.round(e/us)+"d";if(e>=ls)return Math.round(e/ls)+"h";if(e>=cs)return Math.round(e/cs)+"m";if(e>=as)return Math.round(e/as)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function fs(e,t,n){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}!function(e,t){function n(e){var n;function o(){if(o.enabled){var e=o,r=+new Date,s=r-(n||r);e.diff=s,e.prev=n,e.curr=r,n=r;for(var i=new Array(arguments.length),a=0;a<i.length;a++)i[a]=arguments[a];i[0]=t.coerce(i[0]),"string"!=typeof i[0]&&i.unshift("%O");var c=0;i[0]=i[0].replace(/%([a-zA-Z%])/g,(function(n,r){if("%%"===n)return n;c++;var o=t.formatters[r];if("function"==typeof o){var s=i[c];n=o.call(e,s),i.splice(c,1),c--}return n})),t.formatArgs.call(e,i);var l=o.log||t.log||console.log.bind(console);l.apply(e,i)}}return o.namespace=e,o.enabled=t.enabled(e),o.useColors=t.useColors(),o.color=function(e){var n,r=0;for(n in e)r=(r<<5)-r+e.charCodeAt(n),r|=0;return t.colors[Math.abs(r)%t.colors.length]}(e),o.destroy=r,"function"==typeof t.init&&t.init(o),t.instances.push(o),o}function r(){var e=t.instances.indexOf(this);return-1!==e&&(t.instances.splice(e,1),!0)}(t=e.exports=n.debug=n.default=n).coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){t.enable("")},t.enable=function(e){var n;t.save(e),t.names=[],t.skips=[];var r=("string"==typeof e?e:"").split(/[\s,]+/),o=r.length;for(n=0;n<o;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")));for(n=0;n<t.instances.length;n++){var s=t.instances[n];s.enabled=t.enabled(s.namespace)}},t.enabled=function(e){if("*"===e[e.length-1])return!0;var n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=hs,t.instances=[],t.names=[],t.skips=[],t.formatters={}}(is,is.exports),function(e,t){function n(){var e;try{e=t.storage.debug}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e}(t=e.exports=is.exports).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},t.formatArgs=function(e){var n=this.useColors;if(e[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+e[0]+(n?"%c ":" ")+"+"+t.humanize(this.diff),!n)return;var r="color: "+this.color;e.splice(1,0,r,"color: inherit");var o=0,s=0;e[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(o++,"%c"===e&&(s=o))})),e.splice(s,0,r)},t.save=function(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}},t.load=n,t.useColors=function(){if("undefined"!=typeof window&&window.process&&"renderer"===window.process.type)return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(n())}(ss,ss.exports);var ps=Wo(),gs=Jo(),ms=Co,ys=Yo,vs=os,bs=ss.exports("engine.io-client:polling"),ws=_s,Cs=null!=new bo({xdomain:!1}).responseType;function _s(e){var t=e&&e.forceBase64;Cs&&!t||(this.supportsBinary=!1),ps.call(this,e)}ys(_s,ps),_s.prototype.name="polling",_s.prototype.doOpen=function(){this.poll()},_s.prototype.pause=function(e){var t=this;function n(){bs("paused"),t.readyState="paused",e()}if(this.readyState="pausing",this.polling||!this.writable){var r=0;this.polling&&(bs("we are currently polling - waiting to pause"),r++,this.once("pollComplete",(function(){bs("pre-pause polling complete"),--r||n()}))),this.writable||(bs("we are currently writing - waiting to pause"),r++,this.once("drain",(function(){bs("pre-pause writing complete"),--r||n()})))}else n()},_s.prototype.poll=function(){bs("polling"),this.polling=!0,this.doPoll(),this.emit("poll")},_s.prototype.onData=function(e){var t=this;bs("polling got data %s",e);ms.decodePayload(e,this.socket.binaryType,(function(e,n,r){if("opening"===t.readyState&&t.onOpen(),"close"===e.type)return t.onClose(),!1;t.onPacket(e)})),"closed"!==this.readyState&&(this.polling=!1,this.emit("pollComplete"),"open"===this.readyState?this.poll():bs('ignoring poll - transport state "%s"',this.readyState))},_s.prototype.doClose=function(){var e=this;function t(){bs("writing close packet"),e.write([{type:"close"}])}"open"===this.readyState?(bs("transport open - closing"),t()):(bs("transport not open - deferring close"),this.once("open",t))},_s.prototype.write=function(e){var t=this;this.writable=!1;var n=function(){t.writable=!0,t.emit("drain")};ms.encodePayload(e,this.supportsBinary,(function(e){t.doWrite(e,n)}))},_s.prototype.uri=function(){var e=this.query||{},t=this.secure?"https":"http",n="";return!1!==this.timestampRequests&&(e[this.timestampParam]=vs()),this.supportsBinary||e.sid||(e.b64=1),e=gs.encode(e),this.port&&("https"===t&&443!==Number(this.port)||"http"===t&&80!==Number(this.port))&&(n=":"+this.port),e.length&&(e="?"+e),t+"://"+(-1!==this.hostname.indexOf(":")?"["+this.hostname+"]":this.hostname)+n+this.path+e};var ks=bo,Ss=ws,As=Vo.exports,Es=Yo,Is=ss.exports("engine.io-client:polling-xhr");function Os(){}function Ts(e){if(Ss.call(this,e),this.requestTimeout=e.requestTimeout,this.extraHeaders=e.extraHeaders,"undefined"!=typeof location){var t="https:"===location.protocol,n=location.port;n||(n=t?443:80),this.xd="undefined"!=typeof location&&e.hostname!==location.hostname||n!==e.port,this.xs=e.secure!==t}}function xs(e){this.method=e.method||"GET",this.uri=e.uri,this.xd=!!e.xd,this.xs=!!e.xs,this.async=!1!==e.async,this.data=void 0!==e.data?e.data:null,this.agent=e.agent,this.isBinary=e.isBinary,this.supportsBinary=e.supportsBinary,this.enablesXDR=e.enablesXDR,this.requestTimeout=e.requestTimeout,this.pfx=e.pfx,this.key=e.key,this.passphrase=e.passphrase,this.cert=e.cert,this.ca=e.ca,this.ciphers=e.ciphers,this.rejectUnauthorized=e.rejectUnauthorized,this.extraHeaders=e.extraHeaders,this.create()}if(wo.exports=Ts,wo.exports.Request=xs,Es(Ts,Ss),Ts.prototype.supportsBinary=!0,Ts.prototype.request=function(e){return(e=e||{}).uri=this.uri(),e.xd=this.xd,e.xs=this.xs,e.agent=this.agent||!1,e.supportsBinary=this.supportsBinary,e.enablesXDR=this.enablesXDR,e.pfx=this.pfx,e.key=this.key,e.passphrase=this.passphrase,e.cert=this.cert,e.ca=this.ca,e.ciphers=this.ciphers,e.rejectUnauthorized=this.rejectUnauthorized,e.requestTimeout=this.requestTimeout,e.extraHeaders=this.extraHeaders,new xs(e)},Ts.prototype.doWrite=function(e,t){var n="string"!=typeof e&&void 0!==e,r=this.request({method:"POST",data:e,isBinary:n}),o=this;r.on("success",t),r.on("error",(function(e){o.onError("xhr post error",e)})),this.sendXhr=r},Ts.prototype.doPoll=function(){Is("xhr poll");var e=this.request(),t=this;e.on("data",(function(e){t.onData(e)})),e.on("error",(function(e){t.onError("xhr poll error",e)})),this.pollXhr=e},As(xs.prototype),xs.prototype.create=function(){var e={agent:this.agent,xdomain:this.xd,xscheme:this.xs,enablesXDR:this.enablesXDR};e.pfx=this.pfx,e.key=this.key,e.passphrase=this.passphrase,e.cert=this.cert,e.ca=this.ca,e.ciphers=this.ciphers,e.rejectUnauthorized=this.rejectUnauthorized;var t=this.xhr=new ks(e),n=this;try{Is("xhr open %s: %s",this.method,this.uri),t.open(this.method,this.uri,this.async);try{if(this.extraHeaders)for(var r in t.setDisableHeaderCheck&&t.setDisableHeaderCheck(!0),this.extraHeaders)this.extraHeaders.hasOwnProperty(r)&&t.setRequestHeader(r,this.extraHeaders[r])}catch(e){}if("POST"===this.method)try{this.isBinary?t.setRequestHeader("Content-type","application/octet-stream"):t.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(e){}try{t.setRequestHeader("Accept","*/*")}catch(e){}"withCredentials"in t&&(t.withCredentials=!0),this.requestTimeout&&(t.timeout=this.requestTimeout),this.hasXDR()?(t.onload=function(){n.onLoad()},t.onerror=function(){n.onError(t.responseText)}):t.onreadystatechange=function(){if(2===t.readyState)try{var e=t.getResponseHeader("Content-Type");n.supportsBinary&&"application/octet-stream"===e&&(t.responseType="arraybuffer")}catch(e){}4===t.readyState&&(200===t.status||1223===t.status?n.onLoad():setTimeout((function(){n.onError(t.status)}),0))},Is("xhr data %s",this.data),t.send(this.data)}catch(e){return void setTimeout((function(){n.onError(e)}),0)}"undefined"!=typeof document&&(this.index=xs.requestsCount++,xs.requests[this.index]=this)},xs.prototype.onSuccess=function(){this.emit("success"),this.cleanup()},xs.prototype.onData=function(e){this.emit("data",e),this.onSuccess()},xs.prototype.onError=function(e){this.emit("error",e),this.cleanup(!0)},xs.prototype.cleanup=function(e){if(void 0!==this.xhr&&null!==this.xhr){if(this.hasXDR()?this.xhr.onload=this.xhr.onerror=Os:this.xhr.onreadystatechange=Os,e)try{this.xhr.abort()}catch(e){}"undefined"!=typeof document&&delete xs.requests[this.index],this.xhr=null}},xs.prototype.onLoad=function(){var e;try{var t;try{t=this.xhr.getResponseHeader("Content-Type")}catch(e){}e="application/octet-stream"===t&&this.xhr.response||this.xhr.responseText}catch(e){this.onError(e)}null!=e&&this.onData(e)},xs.prototype.hasXDR=function(){return"undefined"!=typeof XDomainRequest&&!this.xs&&this.enablesXDR},xs.prototype.abort=function(){this.cleanup()},xs.requestsCount=0,xs.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",Ps);else if("function"==typeof addEventListener){var Rs="onpagehide"in self?"pagehide":"unload";addEventListener(Rs,Ps,!1)}function Ps(){for(var e in xs.requests)xs.requests.hasOwnProperty(e)&&xs.requests[e].abort()}var Ms,js=ws,Fs=Ls,Ns=/\n/g,Bs=/\\n/g;function Us(){}function Ds(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==_e?_e:{}}function Ls(e){if(js.call(this,e),this.query=this.query||{},!Ms){var t=Ds();Ms=t.___eio=t.___eio||[]}this.index=Ms.length;var n=this;Ms.push((function(e){n.onData(e)})),this.query.j=this.index,"function"==typeof addEventListener&&addEventListener("beforeunload",(function(){n.script&&(n.script.onerror=Us)}),!1)}Yo(Ls,js),Ls.prototype.supportsBinary=!1,Ls.prototype.doClose=function(){this.script&&(this.script.parentNode.removeChild(this.script),this.script=null),this.form&&(this.form.parentNode.removeChild(this.form),this.form=null,this.iframe=null),js.prototype.doClose.call(this)},Ls.prototype.doPoll=function(){var e=this,t=document.createElement("script");this.script&&(this.script.parentNode.removeChild(this.script),this.script=null),t.async=!0,t.src=this.uri(),t.onerror=function(t){e.onError("jsonp poll error",t)};var n=document.getElementsByTagName("script")[0];n?n.parentNode.insertBefore(t,n):(document.head||document.body).appendChild(t),this.script=t,"undefined"!=typeof navigator&&/gecko/i.test(navigator.userAgent)&&setTimeout((function(){var e=document.createElement("iframe");document.body.appendChild(e),document.body.removeChild(e)}),100)},Ls.prototype.doWrite=function(e,t){var n=this;if(!this.form){var r,o=document.createElement("form"),s=document.createElement("textarea"),i=this.iframeId="eio_iframe_"+this.index;o.className="socketio",o.style.position="absolute",o.style.top="-1000px",o.style.left="-1000px",o.target=i,o.method="POST",o.setAttribute("accept-charset","utf-8"),s.name="d",o.appendChild(s),document.body.appendChild(o),this.form=o,this.area=s}function a(){c(),t()}function c(){if(n.iframe)try{n.form.removeChild(n.iframe)}catch(e){n.onError("jsonp polling iframe removal error",e)}try{var e='<iframe src="javascript:0" name="'+n.iframeId+'">';r=document.createElement(e)}catch(e){(r=document.createElement("iframe")).name=n.iframeId,r.src="javascript:0"}r.id=n.iframeId,n.form.appendChild(r),n.iframe=r}this.form.action=this.uri(),c(),e=e.replace(Bs,"\\\n"),this.area.value=e.replace(Ns,"\\n");try{this.form.submit()}catch(e){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){"complete"===n.iframe.readyState&&a()}:this.iframe.onload=a};var qs,$s,zs=Se(Object.freeze({__proto__:null,default:{}})),Hs=Wo(),Vs=Co,Ws=Jo(),Ks=Yo,Qs=os,Js=ss.exports("engine.io-client:websocket");if("undefined"!=typeof WebSocket)qs=WebSocket;else if("undefined"!=typeof self)qs=self.WebSocket||self.MozWebSocket;else try{$s=zs}catch(e){}var Gs=qs||$s,Ys=Xs;function Xs(e){e&&e.forceBase64&&(this.supportsBinary=!1),this.perMessageDeflate=e.perMessageDeflate,this.usingBrowserWebSocket=qs&&!e.forceNode,this.protocols=e.protocols,this.usingBrowserWebSocket||(Gs=$s),Hs.call(this,e)}Ks(Xs,Hs),Xs.prototype.name="websocket",Xs.prototype.supportsBinary=!0,Xs.prototype.doOpen=function(){if(this.check()){var e=this.uri(),t=this.protocols,n={agent:this.agent,perMessageDeflate:this.perMessageDeflate};n.pfx=this.pfx,n.key=this.key,n.passphrase=this.passphrase,n.cert=this.cert,n.ca=this.ca,n.ciphers=this.ciphers,n.rejectUnauthorized=this.rejectUnauthorized,this.extraHeaders&&(n.headers=this.extraHeaders),this.localAddress&&(n.localAddress=this.localAddress);try{this.ws=this.usingBrowserWebSocket&&!this.isReactNative?t?new Gs(e,t):new Gs(e):new Gs(e,t,n)}catch(e){return this.emit("error",e)}void 0===this.ws.binaryType&&(this.supportsBinary=!1),this.ws.supports&&this.ws.supports.binary?(this.supportsBinary=!0,this.ws.binaryType="nodebuffer"):this.ws.binaryType="arraybuffer",this.addEventListeners()}},Xs.prototype.addEventListeners=function(){var e=this;this.ws.onopen=function(){e.onOpen()},this.ws.onclose=function(){e.onClose()},this.ws.onmessage=function(t){e.onData(t.data)},this.ws.onerror=function(t){e.onError("websocket error",t)}},Xs.prototype.write=function(e){var t=this;this.writable=!1;for(var n=e.length,r=0,o=n;r<o;r++)!function(e){Vs.encodePacket(e,t.supportsBinary,(function(r){if(!t.usingBrowserWebSocket){var o={};if(e.options&&(o.compress=e.options.compress),t.perMessageDeflate)("string"==typeof r?Buffer.byteLength(r):r.length)<t.perMessageDeflate.threshold&&(o.compress=!1)}try{t.usingBrowserWebSocket?t.ws.send(r):t.ws.send(r,o)}catch(e){Js("websocket closed before onclose event")}--n||s()}))}(e[r]);function s(){t.emit("flush"),setTimeout((function(){t.writable=!0,t.emit("drain")}),0)}},Xs.prototype.onClose=function(){Hs.prototype.onClose.call(this)},Xs.prototype.doClose=function(){void 0!==this.ws&&this.ws.close()},Xs.prototype.uri=function(){var e=this.query||{},t=this.secure?"wss":"ws",n="";return this.port&&("wss"===t&&443!==Number(this.port)||"ws"===t&&80!==Number(this.port))&&(n=":"+this.port),this.timestampRequests&&(e[this.timestampParam]=Qs()),this.supportsBinary||(e.b64=1),(e=Ws.encode(e)).length&&(e="?"+e),t+"://"+(-1!==this.hostname.indexOf(":")?"["+this.hostname+"]":this.hostname)+n+this.path+e},Xs.prototype.check=function(){return!(!Gs||"__initialize"in Gs&&this.name===Xs.prototype.name)};var Zs=bo,ei=wo.exports,ti=Fs,ni=Ys;ho.polling=function(e){var t=!1,n=!1,r=!1!==e.jsonp;if("undefined"!=typeof location){var o="https:"===location.protocol,s=location.port;s||(s=o?443:80),t=e.hostname!==location.hostname||s!==e.port,n=e.secure!==o}if(e.xdomain=t,e.xscheme=n,"open"in new Zs(e)&&!e.forceJSONP)return new ei(e);if(!r)throw new Error("JSONP disabled");return new ti(e)},ho.websocket=ni;var ri,oi=[].indexOf,si=function(e,t){if(oi)return e.indexOf(t);for(var n=0;n<e.length;++n)if(e[n]===t)return n;return-1},ii=ho,ai=Vo.exports,ci=ss.exports("engine.io-client:socket"),li=si,ui=Co,di=Ir,hi=Jo(),fi=pi;function pi(e,t){if(!(this instanceof pi))return new pi(e,t);t=t||{},e&&"object"==typeof e&&(t=e,e=null),e?(e=di(e),t.hostname=e.host,t.secure="https"===e.protocol||"wss"===e.protocol,t.port=e.port,e.query&&(t.query=e.query)):t.host&&(t.hostname=di(t.host).host),this.secure=null!=t.secure?t.secure:"undefined"!=typeof location&&"https:"===location.protocol,t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.agent=t.agent||!1,this.hostname=t.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=t.port||("undefined"!=typeof location&&location.port?location.port:this.secure?443:80),this.query=t.query||{},"string"==typeof this.query&&(this.query=hi.decode(this.query)),this.upgrade=!1!==t.upgrade,this.path=(t.path||"/engine.io").replace(/\/$/,"")+"/",this.forceJSONP=!!t.forceJSONP,this.jsonp=!1!==t.jsonp,this.forceBase64=!!t.forceBase64,this.enablesXDR=!!t.enablesXDR,this.timestampParam=t.timestampParam||"t",this.timestampRequests=t.timestampRequests,this.transports=t.transports||["polling","websocket"],this.transportOptions=t.transportOptions||{},this.readyState="",this.writeBuffer=[],this.prevBufferLen=0,this.policyPort=t.policyPort||843,this.rememberUpgrade=t.rememberUpgrade||!1,this.binaryType=null,this.onlyBinaryUpgrades=t.onlyBinaryUpgrades,this.perMessageDeflate=!1!==t.perMessageDeflate&&(t.perMessageDeflate||{}),!0===this.perMessageDeflate&&(this.perMessageDeflate={}),this.perMessageDeflate&&null==this.perMessageDeflate.threshold&&(this.perMessageDeflate.threshold=1024),this.pfx=t.pfx||null,this.key=t.key||null,this.passphrase=t.passphrase||null,this.cert=t.cert||null,this.ca=t.ca||null,this.ciphers=t.ciphers||null,this.rejectUnauthorized=void 0===t.rejectUnauthorized||t.rejectUnauthorized,this.forceNode=!!t.forceNode,this.isReactNative="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase(),("undefined"==typeof self||this.isReactNative)&&(t.extraHeaders&&Object.keys(t.extraHeaders).length>0&&(this.extraHeaders=t.extraHeaders),t.localAddress&&(this.localAddress=t.localAddress)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingIntervalTimer=null,this.pingTimeoutTimer=null,this.open()}pi.priorWebsocketSuccess=!1,ai(pi.prototype),pi.protocol=ui.protocol,pi.Socket=pi,pi.Transport=Wo(),pi.transports=ho,pi.parser=Co,pi.prototype.createTransport=function(e){ci('creating transport "%s"',e);var t=function(e){var t={};for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}(this.query);t.EIO=ui.protocol,t.transport=e;var n=this.transportOptions[e]||{};return this.id&&(t.sid=this.id),new ii[e]({query:t,socket:this,agent:n.agent||this.agent,hostname:n.hostname||this.hostname,port:n.port||this.port,secure:n.secure||this.secure,path:n.path||this.path,forceJSONP:n.forceJSONP||this.forceJSONP,jsonp:n.jsonp||this.jsonp,forceBase64:n.forceBase64||this.forceBase64,enablesXDR:n.enablesXDR||this.enablesXDR,timestampRequests:n.timestampRequests||this.timestampRequests,timestampParam:n.timestampParam||this.timestampParam,policyPort:n.policyPort||this.policyPort,pfx:n.pfx||this.pfx,key:n.key||this.key,passphrase:n.passphrase||this.passphrase,cert:n.cert||this.cert,ca:n.ca||this.ca,ciphers:n.ciphers||this.ciphers,rejectUnauthorized:n.rejectUnauthorized||this.rejectUnauthorized,perMessageDeflate:n.perMessageDeflate||this.perMessageDeflate,extraHeaders:n.extraHeaders||this.extraHeaders,forceNode:n.forceNode||this.forceNode,localAddress:n.localAddress||this.localAddress,requestTimeout:n.requestTimeout||this.requestTimeout,protocols:n.protocols||void 0,isReactNative:this.isReactNative})},pi.prototype.open=function(){var e;if(this.rememberUpgrade&&pi.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))e="websocket";else{if(0===this.transports.length){var t=this;return void setTimeout((function(){t.emit("error","No transports available")}),0)}e=this.transports[0]}this.readyState="opening";try{e=this.createTransport(e)}catch(e){return this.transports.shift(),void this.open()}e.open(),this.setTransport(e)},pi.prototype.setTransport=function(e){ci("setting transport %s",e.name);var t=this;this.transport&&(ci("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=e,e.on("drain",(function(){t.onDrain()})).on("packet",(function(e){t.onPacket(e)})).on("error",(function(e){t.onError(e)})).on("close",(function(){t.onClose("transport close")}))},pi.prototype.probe=function(e){ci('probing transport "%s"',e);var t=this.createTransport(e,{probe:1}),n=!1,r=this;function o(){if(r.onlyBinaryUpgrades){var o=!this.supportsBinary&&r.transport.supportsBinary;n=n||o}n||(ci('probe transport "%s" opened',e),t.send([{type:"ping",data:"probe"}]),t.once("packet",(function(o){if(!n)if("pong"===o.type&&"probe"===o.data){if(ci('probe transport "%s" pong',e),r.upgrading=!0,r.emit("upgrading",t),!t)return;pi.priorWebsocketSuccess="websocket"===t.name,ci('pausing current transport "%s"',r.transport.name),r.transport.pause((function(){n||"closed"!==r.readyState&&(ci("changing transport and sending upgrade packet"),u(),r.setTransport(t),t.send([{type:"upgrade"}]),r.emit("upgrade",t),t=null,r.upgrading=!1,r.flush())}))}else{ci('probe transport "%s" failed',e);var s=new Error("probe error");s.transport=t.name,r.emit("upgradeError",s)}})))}function s(){n||(n=!0,u(),t.close(),t=null)}function i(n){var o=new Error("probe error: "+n);o.transport=t.name,s(),ci('probe transport "%s" failed because of error: %s',e,n),r.emit("upgradeError",o)}function a(){i("transport closed")}function c(){i("socket closed")}function l(e){t&&e.name!==t.name&&(ci('"%s" works - aborting "%s"',e.name,t.name),s())}function u(){t.removeListener("open",o),t.removeListener("error",i),t.removeListener("close",a),r.removeListener("close",c),r.removeListener("upgrading",l)}pi.priorWebsocketSuccess=!1,t.once("open",o),t.once("error",i),t.once("close",a),this.once("close",c),this.once("upgrading",l),t.open()},pi.prototype.onOpen=function(){if(ci("socket open"),this.readyState="open",pi.priorWebsocketSuccess="websocket"===this.transport.name,this.emit("open"),this.flush(),"open"===this.readyState&&this.upgrade&&this.transport.pause){ci("starting upgrade probes");for(var e=0,t=this.upgrades.length;e<t;e++)this.probe(this.upgrades[e])}},pi.prototype.onPacket=function(e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(ci('socket receive: type "%s", data "%s"',e.type,e.data),this.emit("packet",e),this.emit("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"pong":this.setPing(),this.emit("pong");break;case"error":var t=new Error("server error");t.code=e.data,this.onError(t);break;case"message":this.emit("data",e.data),this.emit("message",e.data)}else ci('packet received with socket readyState "%s"',this.readyState)},pi.prototype.onHandshake=function(e){this.emit("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.onOpen(),"closed"!==this.readyState&&(this.setPing(),this.removeListener("heartbeat",this.onHeartbeat),this.on("heartbeat",this.onHeartbeat))},pi.prototype.onHeartbeat=function(e){clearTimeout(this.pingTimeoutTimer);var t=this;t.pingTimeoutTimer=setTimeout((function(){"closed"!==t.readyState&&t.onClose("ping timeout")}),e||t.pingInterval+t.pingTimeout)},pi.prototype.setPing=function(){var e=this;clearTimeout(e.pingIntervalTimer),e.pingIntervalTimer=setTimeout((function(){ci("writing ping packet - expecting pong within %sms",e.pingTimeout),e.ping(),e.onHeartbeat(e.pingTimeout)}),e.pingInterval)},pi.prototype.ping=function(){var e=this;this.sendPacket("ping",(function(){e.emit("ping")}))},pi.prototype.onDrain=function(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emit("drain"):this.flush()},pi.prototype.flush=function(){"closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length&&(ci("flushing %d packets in socket",this.writeBuffer.length),this.transport.send(this.writeBuffer),this.prevBufferLen=this.writeBuffer.length,this.emit("flush"))},pi.prototype.write=pi.prototype.send=function(e,t,n){return this.sendPacket("message",e,t,n),this},pi.prototype.sendPacket=function(e,t,n,r){if("function"==typeof t&&(r=t,t=void 0),"function"==typeof n&&(r=n,n=null),"closing"!==this.readyState&&"closed"!==this.readyState){(n=n||{}).compress=!1!==n.compress;var o={type:e,data:t,options:n};this.emit("packetCreate",o),this.writeBuffer.push(o),r&&this.once("flush",r),this.flush()}},pi.prototype.close=function(){if("opening"===this.readyState||"open"===this.readyState){this.readyState="closing";var e=this;this.writeBuffer.length?this.once("drain",(function(){this.upgrading?r():t()})):this.upgrading?r():t()}function t(){e.onClose("forced close"),ci("socket closing - telling transport to close"),e.transport.close()}function n(){e.removeListener("upgrade",n),e.removeListener("upgradeError",n),t()}function r(){e.once("upgrade",n),e.once("upgradeError",n)}return this},pi.prototype.onError=function(e){ci("socket error %j",e),pi.priorWebsocketSuccess=!1,this.emit("error",e),this.onClose("transport error",e)},pi.prototype.onClose=function(e,t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){ci('socket close with reason: "%s"',e);clearTimeout(this.pingIntervalTimer),clearTimeout(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),this.readyState="closed",this.id=null,this.emit("close",e,t),this.writeBuffer=[],this.prevBufferLen=0}},pi.prototype.filterUpgrades=function(e){for(var t=[],n=0,r=e.length;n<r;n++)~li(this.transports,e[n])&&t.push(e[n]);return t},(ri=uo).exports=fi,ri.exports.parser=Co;var gi,mi,yi={exports:{}},vi={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;o<r.length;o++)if((n=r[o])===t||n.fn===t){r.splice(o,1);break}return this},t.prototype.emit=function(e){this._callbacks=this._callbacks||{};var t=[].slice.call(arguments,1),n=this._callbacks["$"+e];if(n)for(var r=0,o=(n=n.slice(0)).length;r<o;++r)n[r].apply(this,t);return this},t.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},t.prototype.hasListeners=function(e){return!!this.listeners(e).length}}(vi);var bi=function(e,t,n){return e.on(t,n),{destroy:function(){e.removeListener(t,n)}}};var wi,Ci=[].slice,_i=function(e,t){if("string"==typeof t&&(t=e[t]),"function"!=typeof t)throw new Error("bind() requires a function");var n=Ci.call(arguments,2);return function(){return t.apply(e,n.concat(Ci.call(arguments)))}};function ki(){return wi||(wi=1,function(e,t){var n=Lr,r=vi.exports,o=(mi||(mi=1,gi=function(e,t){for(var n=[],r=(t=t||0)||0;r<e.length;r++)n[r-t]=e[r];return n}),gi),s=bi,i=_i,a=Or.exports("socket.io-client:socket"),c=Jo(),l=ko();e.exports=h;var u={connect:1,connect_error:1,connect_timeout:1,connecting:1,disconnect:1,error:1,reconnect:1,reconnect_attempt:1,reconnect_failed:1,reconnect_error:1,reconnecting:1,ping:1,pong:1},d=r.prototype.emit;function h(e,t,n){this.io=e,this.nsp=t,this.json=this,this.ids=0,this.acks={},this.receiveBuffer=[],this.sendBuffer=[],this.connected=!1,this.disconnected=!0,this.flags={},n&&n.query&&(this.query=n.query),this.io.autoConnect&&this.open()}r(h.prototype),h.prototype.subEvents=function(){if(!this.subs){var e=this.io;this.subs=[s(e,"open",i(this,"onopen")),s(e,"packet",i(this,"onpacket")),s(e,"close",i(this,"onclose"))]}},h.prototype.open=h.prototype.connect=function(){return this.connected||(this.subEvents(),this.io.open(),"open"===this.io.readyState&&this.onopen(),this.emit("connecting")),this},h.prototype.send=function(){var e=o(arguments);return e.unshift("message"),this.emit.apply(this,e),this},h.prototype.emit=function(e){if(u.hasOwnProperty(e))return d.apply(this,arguments),this;var t=o(arguments),r={type:(void 0!==this.flags.binary?this.flags.binary:l(t))?n.BINARY_EVENT:n.EVENT,data:t,options:{}};return r.options.compress=!this.flags||!1!==this.flags.compress,"function"==typeof t[t.length-1]&&(a("emitting packet with ack id %d",this.ids),this.acks[this.ids]=t.pop(),r.id=this.ids++),this.connected?this.packet(r):this.sendBuffer.push(r),this.flags={},this},h.prototype.packet=function(e){e.nsp=this.nsp,this.io.packet(e)},h.prototype.onopen=function(){if(a("transport is open - connecting"),"/"!==this.nsp)if(this.query){var e="object"==typeof this.query?c.encode(this.query):this.query;a("sending connect packet with query %s",e),this.packet({type:n.CONNECT,query:e})}else this.packet({type:n.CONNECT})},h.prototype.onclose=function(e){a("close (%s)",e),this.connected=!1,this.disconnected=!0,delete this.id,this.emit("disconnect",e)},h.prototype.onpacket=function(e){var t=e.nsp===this.nsp,r=e.type===n.ERROR&&"/"===e.nsp;if(t||r)switch(e.type){case n.CONNECT:this.onconnect();break;case n.EVENT:case n.BINARY_EVENT:this.onevent(e);break;case n.ACK:case n.BINARY_ACK:this.onack(e);break;case n.DISCONNECT:this.ondisconnect();break;case n.ERROR:this.emit("error",e.data)}},h.prototype.onevent=function(e){var t=e.data||[];a("emitting event %j",t),null!=e.id&&(a("attaching ack callback to event"),t.push(this.ack(e.id))),this.connected?d.apply(this,t):this.receiveBuffer.push(t)},h.prototype.ack=function(e){var t=this,r=!1;return function(){if(!r){r=!0;var s=o(arguments);a("sending ack %j",s),t.packet({type:l(s)?n.BINARY_ACK:n.ACK,id:e,data:s})}}},h.prototype.onack=function(e){var t=this.acks[e.id];"function"==typeof t?(a("calling ack %s with %j",e.id,e.data),t.apply(this,e.data),delete this.acks[e.id]):a("bad ack %s",e.id)},h.prototype.onconnect=function(){this.connected=!0,this.disconnected=!1,this.emit("connect"),this.emitBuffered()},h.prototype.emitBuffered=function(){var e;for(e=0;e<this.receiveBuffer.length;e++)d.apply(this,this.receiveBuffer[e]);for(this.receiveBuffer=[],e=0;e<this.sendBuffer.length;e++)this.packet(this.sendBuffer[e]);this.sendBuffer=[]},h.prototype.ondisconnect=function(){a("server disconnect (%s)",this.nsp),this.destroy(),this.onclose("io server disconnect")},h.prototype.destroy=function(){if(this.subs){for(var e=0;e<this.subs.length;e++)this.subs[e].destroy();this.subs=null}this.io.destroy(this)},h.prototype.close=h.prototype.disconnect=function(){return this.connected&&(a("performing disconnect (%s)",this.nsp),this.packet({type:n.DISCONNECT})),this.destroy(),this.connected&&this.onclose("io client disconnect"),this},h.prototype.compress=function(e){return this.flags.compress=e,this},h.prototype.binary=function(e){return this.flags.binary=e,this}}(yi)),yi.exports}var Si=Ai;function Ai(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}Ai.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=0==(1&Math.floor(10*t))?e-n:e+n}return 0|Math.min(e,this.max)},Ai.prototype.reset=function(){this.attempts=0},Ai.prototype.setMin=function(e){this.ms=e},Ai.prototype.setMax=function(e){this.max=e},Ai.prototype.setJitter=function(e){this.jitter=e};var Ei=uo.exports,Ii=ki(),Oi=vi.exports,Ti=Lr,xi=bi,Ri=_i,Pi=Or.exports("socket.io-client:manager"),Mi=si,ji=Si,Fi=Object.prototype.hasOwnProperty,Ni=Bi;function Bi(e,t){if(!(this instanceof Bi))return new Bi(e,t);e&&"object"==typeof e&&(t=e,e=void 0),(t=t||{}).path=t.path||"/socket.io",this.nsps={},this.subs=[],this.opts=t,this.reconnection(!1!==t.reconnection),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor(t.randomizationFactor||.5),this.backoff=new ji({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==t.timeout?2e4:t.timeout),this.readyState="closed",this.uri=e,this.connecting=[],this.lastPing=null,this.encoding=!1,this.packetBuffer=[];var n=t.parser||Ti;this.encoder=new n.Encoder,this.decoder=new n.Decoder,this.autoConnect=!1!==t.autoConnect,this.autoConnect&&this.open()}Bi.prototype.emitAll=function(){for(var e in this.emit.apply(this,arguments),this.nsps)Fi.call(this.nsps,e)&&this.nsps[e].emit.apply(this.nsps[e],arguments)},Bi.prototype.updateSocketIds=function(){for(var e in this.nsps)Fi.call(this.nsps,e)&&(this.nsps[e].id=this.generateId(e))},Bi.prototype.generateId=function(e){return("/"===e?"":e+"#")+this.engine.id},Oi(Bi.prototype),Bi.prototype.reconnection=function(e){return arguments.length?(this._reconnection=!!e,this):this._reconnection},Bi.prototype.reconnectionAttempts=function(e){return arguments.length?(this._reconnectionAttempts=e,this):this._reconnectionAttempts},Bi.prototype.reconnectionDelay=function(e){return arguments.length?(this._reconnectionDelay=e,this.backoff&&this.backoff.setMin(e),this):this._reconnectionDelay},Bi.prototype.randomizationFactor=function(e){return arguments.length?(this._randomizationFactor=e,this.backoff&&this.backoff.setJitter(e),this):this._randomizationFactor},Bi.prototype.reconnectionDelayMax=function(e){return arguments.length?(this._reconnectionDelayMax=e,this.backoff&&this.backoff.setMax(e),this):this._reconnectionDelayMax},Bi.prototype.timeout=function(e){return arguments.length?(this._timeout=e,this):this._timeout},Bi.prototype.maybeReconnectOnOpen=function(){!this.reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()},Bi.prototype.open=Bi.prototype.connect=function(e,t){if(Pi("readyState %s",this.readyState),~this.readyState.indexOf("open"))return this;Pi("opening %s",this.uri),this.engine=Ei(this.uri,this.opts);var n=this.engine,r=this;this.readyState="opening",this.skipReconnect=!1;var o=xi(n,"open",(function(){r.onopen(),e&&e()})),s=xi(n,"error",(function(t){if(Pi("connect_error"),r.cleanup(),r.readyState="closed",r.emitAll("connect_error",t),e){var n=new Error("Connection error");n.data=t,e(n)}else r.maybeReconnectOnOpen()}));if(!1!==this._timeout){var i=this._timeout;Pi("connect attempt will timeout after %d",i);var a=setTimeout((function(){Pi("connect attempt timed out after %d",i),o.destroy(),n.close(),n.emit("error","timeout"),r.emitAll("connect_timeout",i)}),i);this.subs.push({destroy:function(){clearTimeout(a)}})}return this.subs.push(o),this.subs.push(s),this},Bi.prototype.onopen=function(){Pi("open"),this.cleanup(),this.readyState="open",this.emit("open");var e=this.engine;this.subs.push(xi(e,"data",Ri(this,"ondata"))),this.subs.push(xi(e,"ping",Ri(this,"onping"))),this.subs.push(xi(e,"pong",Ri(this,"onpong"))),this.subs.push(xi(e,"error",Ri(this,"onerror"))),this.subs.push(xi(e,"close",Ri(this,"onclose"))),this.subs.push(xi(this.decoder,"decoded",Ri(this,"ondecoded")))},Bi.prototype.onping=function(){this.lastPing=new Date,this.emitAll("ping")},Bi.prototype.onpong=function(){this.emitAll("pong",new Date-this.lastPing)},Bi.prototype.ondata=function(e){this.decoder.add(e)},Bi.prototype.ondecoded=function(e){this.emit("packet",e)},Bi.prototype.onerror=function(e){Pi("error",e),this.emitAll("error",e)},Bi.prototype.socket=function(e,t){var n=this.nsps[e];if(!n){n=new Ii(this,e,t),this.nsps[e]=n;var r=this;n.on("connecting",o),n.on("connect",(function(){n.id=r.generateId(e)})),this.autoConnect&&o()}function o(){~Mi(r.connecting,n)||r.connecting.push(n)}return n},Bi.prototype.destroy=function(e){var t=Mi(this.connecting,e);~t&&this.connecting.splice(t,1),this.connecting.length||this.close()},Bi.prototype.packet=function(e){Pi("writing packet %j",e);var t=this;e.query&&0===e.type&&(e.nsp+="?"+e.query),t.encoding?t.packetBuffer.push(e):(t.encoding=!0,this.encoder.encode(e,(function(n){for(var r=0;r<n.length;r++)t.engine.write(n[r],e.options);t.encoding=!1,t.processPacketQueue()})))},Bi.prototype.processPacketQueue=function(){if(this.packetBuffer.length>0&&!this.encoding){var e=this.packetBuffer.shift();this.packet(e)}},Bi.prototype.cleanup=function(){Pi("cleanup");for(var e=this.subs.length,t=0;t<e;t++){this.subs.shift().destroy()}this.packetBuffer=[],this.encoding=!1,this.lastPing=null,this.decoder.destroy()},Bi.prototype.close=Bi.prototype.disconnect=function(){Pi("disconnect"),this.skipReconnect=!0,this.reconnecting=!1,"opening"===this.readyState&&this.cleanup(),this.backoff.reset(),this.readyState="closed",this.engine&&this.engine.close()},Bi.prototype.onclose=function(e){Pi("onclose"),this.cleanup(),this.backoff.reset(),this.readyState="closed",this.emit("close",e),this._reconnection&&!this.skipReconnect&&this.reconnect()},Bi.prototype.reconnect=function(){if(this.reconnecting||this.skipReconnect)return this;var e=this;if(this.backoff.attempts>=this._reconnectionAttempts)Pi("reconnect failed"),this.backoff.reset(),this.emitAll("reconnect_failed"),this.reconnecting=!1;else{var t=this.backoff.duration();Pi("will wait %dms before reconnect attempt",t),this.reconnecting=!0;var n=setTimeout((function(){e.skipReconnect||(Pi("attempting reconnect"),e.emitAll("reconnect_attempt",e.backoff.attempts),e.emitAll("reconnecting",e.backoff.attempts),e.skipReconnect||e.open((function(t){t?(Pi("reconnect attempt error"),e.reconnecting=!1,e.reconnect(),e.emitAll("reconnect_error",t.data)):(Pi("reconnect success"),e.onreconnect())})))}),t);this.subs.push({destroy:function(){clearTimeout(n)}})}},Bi.prototype.onreconnect=function(){var e=this.backoff.attempts;this.reconnecting=!1,this.backoff.reset(),this.updateSocketIds(),this.emitAll("reconnect",e)},function(e,t){var n=Dr,r=Lr,o=Ni,s=Or.exports("socket.io-client");e.exports=t=a;var i=t.managers={};function a(e,t){"object"==typeof e&&(t=e,e=void 0),t=t||{};var r,a=n(e),c=a.source,l=a.id,u=a.path,d=i[l]&&u in i[l].nsps;return t.forceNew||t["force new connection"]||!1===t.multiplex||d?(s("ignoring socket cache for %s",c),r=o(c,t)):(i[l]||(s("new io instance for %s",c),i[l]=o(c,t)),r=i[l]),a.query&&!t.query&&(t.query=a.query),r.socket(a.path,t)}t.protocol=r.protocol,t.connect=a,t.Manager=Ni,t.Socket=ki()}(Sr,Sr.exports);var Ui=Sr.exports;const Di=async(e,t,n)=>{const{ws:r}=e;return await new Promise(((e,o)=>{r.emit(t,n,(t=>{try{e(br(t))}catch(e){o(e)}}))}))};function Li(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var qi={exports:{}};!function(e,t){e.exports=function(){function e(t,n,r){function o(i,a){if(!n[i]){if(!t[i]){if(!a&&Li)return Li(i);if(s)return s(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[i]={exports:{}};t[i][0].call(l.exports,(function(e){return o(t[i][1][e]||e)}),l,l.exports,e,t,n,r)}return n[i].exports}for(var s=Li,i=0;i<r.length;i++)o(r[i]);return o}return e}()({1:[function(e,t,n){(function(n,r){(function(){const o=e("events").EventEmitter,s=e("./store"),i=e("./topic-alias-recv"),a=e("./topic-alias-send"),c=e("mqtt-packet"),l=e("./default-message-id-provider"),u=e("readable-stream").Writable,d=e("inherits"),h=e("reinterval"),f=e("rfdc/default"),p=e("./validations"),g=e("xtend"),m=e("debug")("mqttjs:client"),y=n?n.nextTick:function(e){setTimeout(e,0)},v=r.setImmediate||function(e){y(e)},b={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:3e4,clean:!0,resubscribe:!0},w=["ECONNREFUSED","EADDRINUSE","ECONNRESET","ENOTFOUND"],C={0:"",1:"Unacceptable protocol version",2:"Identifier rejected",3:"Server unavailable",4:"Bad username or password",5:"Not authorized",16:"No matching subscribers",17:"No subscription existed",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",132:"Unsupported Protocol Version",133:"Client Identifier not valid",134:"Bad User Name or Password",135:"Not authorized",136:"Server unavailable",137:"Server busy",138:"Banned",139:"Server shutting down",140:"Bad authentication method",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",145:"Packet identifier in use",146:"Packet Identifier not found",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"};function _(){return"mqttjs_"+Math.random().toString(16).substr(2,8)}function k(e,t){if(5===e.options.protocolVersion&&"publish"===t.cmd){let n;t.properties&&(n=t.properties.topicAlias);const r=t.topic.toString();if(e.topicAliasSend)if(n){if(0!==r.length&&(m("applyTopicAlias :: register topic: %s - alias: %d",r,n),!e.topicAliasSend.put(r,n)))return m("applyTopicAlias :: error out of range. topic: %s - alias: %d",r,n),new Error("Sending Topic Alias out of range")}else 0!==r.length&&(e.options.autoAssignTopicAlias?(n=e.topicAliasSend.getAliasByTopic(r),n?(t.topic="",t.properties={...t.properties,topicAlias:n},m("applyTopicAlias :: auto assign(use) topic: %s - alias: %d",r,n)):(n=e.topicAliasSend.getLruAlias(),e.topicAliasSend.put(r,n),t.properties={...t.properties,topicAlias:n},m("applyTopicAlias :: auto assign topic: %s - alias: %d",r,n))):e.options.autoUseTopicAlias&&(n=e.topicAliasSend.getAliasByTopic(r),n&&(t.topic="",t.properties={...t.properties,topicAlias:n},m("applyTopicAlias :: auto use topic: %s - alias: %d",r,n))));else if(n)return m("applyTopicAlias :: error out of range. topic: %s - alias: %d",r,n),new Error("Sending Topic Alias out of range")}}function S(e,t){let n;t.properties&&(n=t.properties.topicAlias);let r=t.topic.toString();if(0===r.length){if(void 0===n)return new Error("Unregistered Topic Alias");if(r=e.topicAliasSend.getTopicByAlias(n),void 0===r)return new Error("Unregistered Topic Alias");t.topic=r}n&&delete t.properties.topicAlias}function A(e,t,n){m("sendPacket :: packet: %O",t),m("sendPacket :: emitting `packetsend`"),e.emit("packetsend",t),m("sendPacket :: writing to stream");const r=c.writeToStream(t,e.stream,e.options);m("sendPacket :: writeToStream result %s",r),!r&&n&&n!==T?(m("sendPacket :: handle events on `drain` once through callback."),e.stream.once("drain",n)):n&&(m("sendPacket :: invoking cb"),n())}function E(e){e&&(m("flush: queue exists? %b",!!e),Object.keys(e).forEach((function(t){"function"==typeof e[t].cb&&(e[t].cb(new Error("Connection closed")),delete e[t])})))}function I(e){e&&(m("flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(e).forEach((function(t){e[t].volatile&&"function"==typeof e[t].cb&&(e[t].cb(new Error("Connection closed")),delete e[t])})))}function O(e,t,n,r){m("storeAndSend :: store packet with cmd %s to outgoingStore",t.cmd);let o,s=t;if("publish"===s.cmd&&(s=f(t),o=S(e,s),o))return n&&n(o);e.outgoingStore.put(s,(function(o){if(o)return n&&n(o);r(),A(e,t,n)}))}function T(e){m("nop ::",e)}function x(e,t){let n;const r=this;if(!(this instanceof x))return new x(e,t);for(n in this.options=t||{},b)void 0===this.options[n]?this.options[n]=b[n]:this.options[n]=t[n];m("MqttClient :: options.protocol",t.protocol),m("MqttClient :: options.protocolVersion",t.protocolVersion),m("MqttClient :: options.username",t.username),m("MqttClient :: options.keepalive",t.keepalive),m("MqttClient :: options.reconnectPeriod",t.reconnectPeriod),m("MqttClient :: options.rejectUnauthorized",t.rejectUnauthorized),m("MqttClient :: options.topicAliasMaximum",t.topicAliasMaximum),this.options.clientId="string"==typeof t.clientId?t.clientId:_(),m("MqttClient :: clientId",this.options.clientId),this.options.customHandleAcks=5===t.protocolVersion&&t.customHandleAcks?t.customHandleAcks:function(){arguments[3](0)},this.streamBuilder=e,this.messageIdProvider=void 0===this.options.messageIdProvider?new l:this.options.messageIdProvider,this.outgoingStore=t.outgoingStore||new s,this.incomingStore=t.incomingStore||new s,this.queueQoSZero=void 0===t.queueQoSZero||t.queueQoSZero,this._resubscribeTopics={},this.messageIdToTopic={},this.pingTimer=null,this.connected=!1,this.disconnecting=!1,this.queue=[],this.connackTimer=null,this.reconnectTimer=null,this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={},this._storeProcessingQueue=[],this.outgoing={},this._firstConnection=!0,t.topicAliasMaximum>0&&(t.topicAliasMaximum>65535?m("MqttClient :: options.topicAliasMaximum is out of range"):this.topicAliasRecv=new i(t.topicAliasMaximum)),this.on("connect",(function(){const e=this.queue;function t(){const n=e.shift();m("deliver :: entry %o",n);let o=null;if(!n)return void r._resubscribe();o=n.packet,m("deliver :: call _sendPacket for %o",o);let s=!0;o.messageId&&0!==o.messageId&&(r.messageIdProvider.register(o.messageId)||(s=!1)),s?r._sendPacket(o,(function(e){n.cb&&n.cb(e),t()})):(m("messageId: %d has already used. The message is skipped and removed.",o.messageId),t())}m("connect :: sending queued packets"),t()})),this.on("close",(function(){m("close :: connected set to `false`"),this.connected=!1,m("close :: clearing connackTimer"),clearTimeout(this.connackTimer),m("close :: clearing ping timer"),null!==r.pingTimer&&(r.pingTimer.clear(),r.pingTimer=null),this.topicAliasRecv&&this.topicAliasRecv.clear(),m("close :: calling _setupReconnect"),this._setupReconnect()})),o.call(this),m("MqttClient :: setting up stream"),this._setupStream()}d(x,o),x.prototype._setupStream=function(){const e=this,t=new u,n=c.parser(this.options);let r=null;const o=[];function s(){if(o.length)y(i);else{const e=r;r=null,e()}}function i(){m("work :: getting next packet in queue");const t=o.shift();if(t)m("work :: packet pulled from queue"),e._handlePacket(t,s);else{m("work :: no packets in queue");const e=r;r=null,m("work :: done flag is %s",!!e),e&&e()}}function a(t){m("streamErrorHandler :: error",t.message),w.includes(t.code)?(m("streamErrorHandler :: emitting error"),e.emit("error",t)):T(t)}m("_setupStream :: calling method to clear reconnect"),this._clearReconnect(),m("_setupStream :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),n.on("packet",(function(e){m("parser :: on packet push to packets array."),o.push(e)})),t._write=function(e,t,o){r=o,m("writable stream :: parsing buffer"),n.parse(e),i()},m("_setupStream :: pipe stream to writable stream"),this.stream.pipe(t),this.stream.on("error",a),this.stream.on("close",(function(){m("(%s)stream :: on close",e.options.clientId),I(e.outgoing),m("stream: emit close to MqttClient"),e.emit("close")})),m("_setupStream: sending packet `connect`");const l=Object.create(this.options);if(l.cmd="connect",this.topicAliasRecv&&(l.properties||(l.properties={}),this.topicAliasRecv&&(l.properties.topicAliasMaximum=this.topicAliasRecv.max)),A(this,l),n.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return e.end((()=>this.emit("error",new Error("Packet has no Authentication Method")))),this;this.options.properties.authenticationMethod&&this.options.authPacket&&"object"==typeof this.options.authPacket&&A(this,g({cmd:"auth",reasonCode:0},this.options.authPacket))}this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout((function(){m("!!connectTimeout hit!! Calling _cleanUp with force `true`"),e._cleanUp(!0)}),this.options.connectTimeout)},x.prototype._handlePacket=function(e,t){const n=this.options;if(5===n.protocolVersion&&n.properties&&n.properties.maximumPacketSize&&n.properties.maximumPacketSize<e.length)return this.emit("error",new Error("exceeding packets size "+e.cmd)),this.end({reasonCode:149,properties:{reasonString:"Maximum packet size was exceeded"}}),this;switch(m("_handlePacket :: emitting packetreceive"),this.emit("packetreceive",e),e.cmd){case"publish":this._handlePublish(e,t);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(e),t();break;case"pubrel":this._handlePubrel(e,t);break;case"connack":this._handleConnack(e),t();break;case"auth":this._handleAuth(e),t();break;case"pingresp":this._handlePingresp(e),t();break;case"disconnect":this._handleDisconnect(e),t()}},x.prototype._checkDisconnecting=function(e){return this.disconnecting&&(e&&e!==T?e(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting},x.prototype.publish=function(e,t,n,r){m("publish :: message `%s` to topic `%s`",t,e);const o=this.options;if("function"==typeof n&&(r=n,n=null),n=g({qos:0,retain:!1,dup:!1},n),this._checkDisconnecting(r))return this;const s=this,i=function(){let i=0;if((1===n.qos||2===n.qos)&&(i=s._nextId(),null===i))return m("No messageId left"),!1;const a={cmd:"publish",topic:e,payload:t,qos:n.qos,retain:n.retain,messageId:i,dup:n.dup};switch(5===o.protocolVersion&&(a.properties=n.properties),m("publish :: qos",n.qos),n.qos){case 1:case 2:s.outgoing[a.messageId]={volatile:!1,cb:r||T},m("MqttClient:publish: packet cmd: %s",a.cmd),s._sendPacket(a,void 0,n.cbStorePut);break;default:m("MqttClient:publish: packet cmd: %s",a.cmd),s._sendPacket(a,r,n.cbStorePut)}return!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!i())&&this._storeProcessingQueue.push({invoke:i,cbStorePut:n.cbStorePut,callback:r}),this},x.prototype.subscribe=function(){const e=this,t=new Array(arguments.length);for(let e=0;e<arguments.length;e++)t[e]=arguments[e];const n=[];let r=t.shift();const o=r.resubscribe;let s=t.pop()||T,i=t.pop();const a=this.options.protocolVersion;delete r.resubscribe,"string"==typeof r&&(r=[r]),"function"!=typeof s&&(i=s,s=T);const c=p.validateTopics(r);if(null!==c)return v(s,new Error("Invalid topic "+c)),this;if(this._checkDisconnecting(s))return m("subscribe: discconecting true"),this;const l={qos:0};if(5===a&&(l.nl=!1,l.rap=!1,l.rh=0),i=g(l,i),Array.isArray(r)?r.forEach((function(t){if(m("subscribe: array topic %s",t),!Object.prototype.hasOwnProperty.call(e._resubscribeTopics,t)||e._resubscribeTopics[t].qos<i.qos||o){const e={topic:t,qos:i.qos};5===a&&(e.nl=i.nl,e.rap=i.rap,e.rh=i.rh,e.properties=i.properties),m("subscribe: pushing topic `%s` and qos `%s` to subs list",e.topic,e.qos),n.push(e)}})):Object.keys(r).forEach((function(t){if(m("subscribe: object topic %s",t),!Object.prototype.hasOwnProperty.call(e._resubscribeTopics,t)||e._resubscribeTopics[t].qos<r[t].qos||o){const e={topic:t,qos:r[t].qos};5===a&&(e.nl=r[t].nl,e.rap=r[t].rap,e.rh=r[t].rh,e.properties=i.properties),m("subscribe: pushing `%s` to subs list",e),n.push(e)}})),!n.length)return s(null,[]),this;const u=function(){const t=e._nextId();if(null===t)return m("No messageId left"),!1;const r={cmd:"subscribe",subscriptions:n,qos:1,retain:!1,dup:!1,messageId:t};if(i.properties&&(r.properties=i.properties),e.options.resubscribe){m("subscribe :: resubscribe true");const t=[];n.forEach((function(n){if(e.options.reconnectPeriod>0){const r={qos:n.qos};5===a&&(r.nl=n.nl||!1,r.rap=n.rap||!1,r.rh=n.rh||0,r.properties=n.properties),e._resubscribeTopics[n.topic]=r,t.push(n.topic)}})),e.messageIdToTopic[r.messageId]=t}return e.outgoing[r.messageId]={volatile:!0,cb:function(e,t){if(!e){const e=t.granted;for(let t=0;t<e.length;t+=1)n[t].qos=e[t]}s(e,n)}},m("subscribe :: call _sendPacket"),e._sendPacket(r),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!u())&&this._storeProcessingQueue.push({invoke:u,callback:s}),this},x.prototype.unsubscribe=function(){const e=this,t=new Array(arguments.length);for(let e=0;e<arguments.length;e++)t[e]=arguments[e];let n=t.shift(),r=t.pop()||T,o=t.pop();"string"==typeof n&&(n=[n]),"function"!=typeof r&&(o=r,r=T);const s=p.validateTopics(n);if(null!==s)return v(r,new Error("Invalid topic "+s)),this;if(e._checkDisconnecting(r))return this;const i=function(){const t=e._nextId();if(null===t)return m("No messageId left"),!1;const s={cmd:"unsubscribe",qos:1,messageId:t};return"string"==typeof n?s.unsubscriptions=[n]:Array.isArray(n)&&(s.unsubscriptions=n),e.options.resubscribe&&s.unsubscriptions.forEach((function(t){delete e._resubscribeTopics[t]})),"object"==typeof o&&o.properties&&(s.properties=o.properties),e.outgoing[s.messageId]={volatile:!0,cb:r},m("unsubscribe: call _sendPacket"),e._sendPacket(s),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!i())&&this._storeProcessingQueue.push({invoke:i,callback:r}),this},x.prototype.end=function(e,t,n){const r=this;function o(){m("end :: closeStores: closing incoming and outgoing stores"),r.disconnected=!0,r.incomingStore.close((function(e){r.outgoingStore.close((function(t){if(m("end :: closeStores: emitting end"),r.emit("end"),n){const r=e||t;m("end :: closeStores: invoking callback with args"),n(r)}}))})),r._deferredReconnect&&r._deferredReconnect()}function s(){m("end :: (%s) :: finish :: calling _cleanUp with force %s",r.options.clientId,e),r._cleanUp(e,(()=>{m("end :: finish :: calling process.nextTick on closeStores"),y(o.bind(r))}),t)}return m("end :: (%s)",this.options.clientId),null!=e&&"boolean"==typeof e||(n=t||T,t=e,e=!1,"object"!=typeof t&&(n=t,t=null,"function"!=typeof n&&(n=T))),"object"!=typeof t&&(n=t,t=null),m("end :: cb? %s",!!n),n=n||T,this.disconnecting?(n(),this):(this._clearReconnect(),this.disconnecting=!0,!e&&Object.keys(this.outgoing).length>0?(m("end :: (%s) :: calling finish in 10ms once outgoing is empty",r.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,s,10))):(m("end :: (%s) :: immediately calling finish",r.options.clientId),s()),this)},x.prototype.removeOutgoingMessage=function(e){const t=this.outgoing[e]?this.outgoing[e].cb:null;return delete this.outgoing[e],this.outgoingStore.del({messageId:e},(function(){t(new Error("Message removed"))})),this},x.prototype.reconnect=function(e){m("client reconnect");const t=this,n=function(){e?(t.options.incomingStore=e.incomingStore,t.options.outgoingStore=e.outgoingStore):(t.options.incomingStore=null,t.options.outgoingStore=null),t.incomingStore=t.options.incomingStore||new s,t.outgoingStore=t.options.outgoingStore||new s,t.disconnecting=!1,t.disconnected=!1,t._deferredReconnect=null,t._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=n:n(),this},x.prototype._reconnect=function(){m("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end((()=>{this._setupStream()})),m("client already connected. disconnecting first.")):(m("_reconnect: calling _setupStream"),this._setupStream())},x.prototype._setupReconnect=function(){const e=this;!e.disconnecting&&!e.reconnectTimer&&e.options.reconnectPeriod>0?(this.reconnecting||(m("_setupReconnect :: emit `offline` state"),this.emit("offline"),m("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),m("_setupReconnect :: setting reconnectTimer for %d ms",e.options.reconnectPeriod),e.reconnectTimer=setInterval((function(){m("reconnectTimer :: reconnect triggered!"),e._reconnect()}),e.options.reconnectPeriod)):m("_setupReconnect :: doing nothing...")},x.prototype._clearReconnect=function(){m("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},x.prototype._cleanUp=function(e,t){const n=arguments[2];if(t&&(m("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",t)),m("_cleanUp :: forced? %s",e),e)0===this.options.reconnectPeriod&&this.options.clean&&E(this.outgoing),m("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{const e=g({cmd:"disconnect"},n);m("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(e,v.bind(null,this.stream.end.bind(this.stream)))}this.disconnecting||(m("_cleanUp :: client not disconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),null!==this.pingTimer&&(m("_cleanUp :: clearing pingTimer"),this.pingTimer.clear(),this.pingTimer=null),t&&!this.connected&&(m("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",t),t())},x.prototype._sendPacket=function(e,t,n){m("_sendPacket :: (%s) :: start",this.options.clientId),n=n||T,t=t||T;const r=k(this,e);if(r)t(r);else{if(!this.connected)return"auth"===e.cmd?(this._shiftPingInterval(),void A(this,e,t)):(m("_sendPacket :: client not connected. Storing packet offline."),void this._storePacket(e,t,n));switch(this._shiftPingInterval(),e.cmd){case"publish":break;case"pubrel":return void O(this,e,t,n);default:return void A(this,e,t)}switch(e.qos){case 2:case 1:O(this,e,t,n);break;default:A(this,e,t)}m("_sendPacket :: (%s) :: end",this.options.clientId)}},x.prototype._storePacket=function(e,t,n){m("_storePacket :: packet: %o",e),m("_storePacket :: cb? %s",!!t),n=n||T;let r=e;if("publish"===r.cmd){r=f(e);const n=S(this,r);if(n)return t&&t(n)}0===(r.qos||0)&&this.queueQoSZero||"publish"!==r.cmd?this.queue.push({packet:r,cb:t}):r.qos>0?(t=this.outgoing[r.messageId]?this.outgoing[r.messageId].cb:null,this.outgoingStore.put(r,(function(e){if(e)return t&&t(e);n()}))):t&&t(new Error("No connection to broker"))},x.prototype._setupPingTimer=function(){m("_setupPingTimer :: keepalive %d (seconds)",this.options.keepalive);const e=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=h((function(){e._checkPing()}),1e3*this.options.keepalive))},x.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},x.prototype._checkPing=function(){m("_checkPing :: checking ping..."),this.pingResp?(m("_checkPing :: ping response received. Clearing flag and sending `pingreq`"),this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):(m("_checkPing :: calling _cleanUp with force true"),this._cleanUp(!0))},x.prototype._handlePingresp=function(){this.pingResp=!0},x.prototype._handleConnack=function(e){m("_handleConnack");const t=this.options,n=5===t.protocolVersion?e.reasonCode:e.returnCode;if(clearTimeout(this.connackTimer),delete this.topicAliasSend,e.properties){if(e.properties.topicAliasMaximum){if(e.properties.topicAliasMaximum>65535)return void this.emit("error",new Error("topicAliasMaximum from broker is out of range"));e.properties.topicAliasMaximum>0&&(this.topicAliasSend=new a(e.properties.topicAliasMaximum))}e.properties.serverKeepAlive&&t.keepalive&&(t.keepalive=e.properties.serverKeepAlive,this._shiftPingInterval()),e.properties.maximumPacketSize&&(t.properties||(t.properties={}),t.properties.maximumPacketSize=e.properties.maximumPacketSize)}if(0===n)this.reconnecting=!1,this._onConnect(e);else if(n>0){const e=new Error("Connection refused: "+C[n]);e.code=n,this.emit("error",e)}},x.prototype._handleAuth=function(e){const t=this.options.protocolVersion,n=5===t?e.reasonCode:e.returnCode;if(5!==t){const e=new Error("Protocol error: Auth packets are only supported in MQTT 5. Your version:"+t);return e.code=n,void this.emit("error",e)}const r=this;this.handleAuth(e,(function(e,t){if(e)r.emit("error",e);else if(24===n)r.reconnecting=!1,r._sendPacket(t);else{const t=new Error("Connection refused: "+C[n]);e.code=n,r.emit("error",t)}}))},x.prototype.handleAuth=function(e,t){t()},x.prototype._handlePublish=function(e,t){m("_handlePublish: packet %o",e),t=void 0!==t?t:T;let n=e.topic.toString();const r=e.payload,o=e.qos,s=e.messageId,i=this,a=this.options,c=[0,16,128,131,135,144,145,151,153];if(5===this.options.protocolVersion){let t;if(e.properties&&(t=e.properties.topicAlias),void 0!==t)if(0===n.length){if(!(t>0&&t<=65535))return m("_handlePublish :: topic alias out of range. alias: %d",t),void this.emit("error",new Error("Received Topic Alias is out of range"));{const e=this.topicAliasRecv.getTopicByAlias(t);if(!e)return m("_handlePublish :: unregistered topic alias. alias: %d",t),void this.emit("error",new Error("Received unregistered Topic Alias"));n=e,m("_handlePublish :: topic complemented by alias. topic: %s - alias: %d",n,t)}}else{if(!this.topicAliasRecv.put(n,t))return m("_handlePublish :: topic alias out of range. alias: %d",t),void this.emit("error",new Error("Received Topic Alias is out of range"));m("_handlePublish :: registered topic: %s - alias: %d",n,t)}}switch(m("_handlePublish: qos %d",o),o){case 2:a.customHandleAcks(n,r,e,(function(n,r){return n instanceof Error||(r=n,n=null),n?i.emit("error",n):-1===c.indexOf(r)?i.emit("error",new Error("Wrong reason code for pubrec")):void(r?i._sendPacket({cmd:"pubrec",messageId:s,reasonCode:r},t):i.incomingStore.put(e,(function(){i._sendPacket({cmd:"pubrec",messageId:s},t)})))}));break;case 1:a.customHandleAcks(n,r,e,(function(o,a){return o instanceof Error||(a=o,o=null),o?i.emit("error",o):-1===c.indexOf(a)?i.emit("error",new Error("Wrong reason code for puback")):(a||i.emit("message",n,r,e),void i.handleMessage(e,(function(e){if(e)return t&&t(e);i._sendPacket({cmd:"puback",messageId:s,reasonCode:a},t)})))}));break;case 0:this.emit("message",n,r,e),this.handleMessage(e,t);break;default:m("_handlePublish: unknown QoS. Doing nothing.")}},x.prototype.handleMessage=function(e,t){t()},x.prototype._handleAck=function(e){const t=e.messageId,n=e.cmd;let r=null;const o=this.outgoing[t]?this.outgoing[t].cb:null,s=this;let i;if(o){switch(m("_handleAck :: packet type",n),n){case"pubcomp":case"puback":{const n=e.reasonCode;n&&n>0&&16!==n&&(i=new Error("Publish error: "+C[n]),i.code=n,o(i,e)),delete this.outgoing[t],this.outgoingStore.del(e,o),this.messageIdProvider.deallocate(t),this._invokeStoreProcessingQueue();break}case"pubrec":{r={cmd:"pubrel",qos:2,messageId:t};const n=e.reasonCode;n&&n>0&&16!==n?(i=new Error("Publish error: "+C[n]),i.code=n,o(i,e)):this._sendPacket(r);break}case"suback":delete this.outgoing[t],this.messageIdProvider.deallocate(t);for(let n=0;n<e.granted.length;n++)if(0!=(128&e.granted[n])){const e=this.messageIdToTopic[t];e&&e.forEach((function(e){delete s._resubscribeTopics[e]}))}this._invokeStoreProcessingQueue(),o(null,e);break;case"unsuback":delete this.outgoing[t],this.messageIdProvider.deallocate(t),this._invokeStoreProcessingQueue(),o(null);break;default:s.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&0===Object.keys(this.outgoing).length&&this.emit("outgoingEmpty")}else m("_handleAck :: Server sent an ack in error. Ignoring.")},x.prototype._handlePubrel=function(e,t){m("handling pubrel packet"),t=void 0!==t?t:T;const n=e.messageId,r=this,o={cmd:"pubcomp",messageId:n};r.incomingStore.get(e,(function(e,n){e?r._sendPacket(o,t):(r.emit("message",n.topic,n.payload,n),r.handleMessage(n,(function(e){if(e)return t(e);r.incomingStore.del(n,T),r._sendPacket(o,t)})))}))},x.prototype._handleDisconnect=function(e){this.emit("disconnect",e)},x.prototype._nextId=function(){return this.messageIdProvider.allocate()},x.prototype.getLastMessageId=function(){return this.messageIdProvider.getLastAllocated()},x.prototype._resubscribe=function(){m("_resubscribe");const e=Object.keys(this._resubscribeTopics);if(!this._firstConnection&&(this.options.clean||5===this.options.protocolVersion&&!this.connackPacket.sessionPresent)&&e.length>0)if(this.options.resubscribe)if(5===this.options.protocolVersion){m("_resubscribe: protocolVersion 5");for(let t=0;t<e.length;t++){const n={};n[e[t]]=this._resubscribeTopics[e[t]],n.resubscribe=!0,this.subscribe(n,{properties:n[e[t]].properties})}}else this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics);else this._resubscribeTopics={};this._firstConnection=!1},x.prototype._onConnect=function(e){if(this.disconnected)return void this.emit("connect",e);const t=this;function n(){let r=t.outgoingStore.createStream();function o(){t._storeProcessing=!1,t._packetIdsDuringStoreProcessing={}}function s(){r.destroy(),r=null,t._flushStoreProcessingQueue(),o()}function i(){if(!r)return;t._storeProcessing=!0;const e=r.read(1);let n;e?t._packetIdsDuringStoreProcessing[e.messageId]?i():t.disconnecting||t.reconnectTimer?r.destroy&&r.destroy():(n=t.outgoing[e.messageId]?t.outgoing[e.messageId].cb:null,t.outgoing[e.messageId]={volatile:!1,cb:function(e,t){n&&n(e,t),i()}},t._packetIdsDuringStoreProcessing[e.messageId]=!0,t.messageIdProvider.register(e.messageId)?t._sendPacket(e):m("messageId: %d has already used.",e.messageId)):r.once("readable",i)}t.once("close",s),r.on("error",(function(e){o(),t._flushStoreProcessingQueue(),t.removeListener("close",s),t.emit("error",e)})),r.on("end",(function(){let r=!0;for(const e in t._packetIdsDuringStoreProcessing)if(!t._packetIdsDuringStoreProcessing[e]){r=!1;break}r?(o(),t.removeListener("close",s),t._invokeAllStoreProcessingQueue(),t.emit("connect",e)):n()})),i()}this.connackPacket=e,this.messageIdProvider.clear(),this._setupPingTimer(),this.connected=!0,n()},x.prototype._invokeStoreProcessingQueue=function(){if(this._storeProcessingQueue.length>0){const e=this._storeProcessingQueue[0];if(e&&e.invoke())return this._storeProcessingQueue.shift(),!0}return!1},x.prototype._invokeAllStoreProcessingQueue=function(){for(;this._invokeStoreProcessingQueue(););},x.prototype._flushStoreProcessingQueue=function(){for(const e of this._storeProcessingQueue)e.cbStorePut&&e.cbStorePut(new Error("Connection closed")),e.callback&&e.callback(new Error("Connection closed"));this._storeProcessingQueue.splice(0)},t.exports=x}).call(this)}).call(this,e("_process"),void 0!==_e?_e:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./default-message-id-provider":7,"./store":8,"./topic-alias-recv":9,"./topic-alias-send":10,"./validations":11,_process:50,debug:18,events:22,inherits:24,"mqtt-packet":40,"readable-stream":69,reinterval:70,"rfdc/default":71,xtend:81}],2:[function(e,t,n){const{Buffer:r}=e("buffer"),o=e("readable-stream").Transform,s=e("duplexify");let i,a,c,l=!1;function u(){const e=new o;return e._write=function(e,t,n){i.sendSocketMessage({data:e.buffer,success:function(){n()},fail:function(){n(new Error)}})},e._flush=function(e){i.closeSocket({success:function(){e()}})},e}function d(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}function h(e,t){const n="alis"===e.protocol?"wss":"ws";let r=n+"://"+e.hostname+e.path;return e.port&&80!==e.port&&443!==e.port&&(r=n+"://"+e.hostname+":"+e.port+e.path),"function"==typeof e.transformWsUrl&&(r=e.transformWsUrl(r,e,t)),r}function f(){l||(l=!0,i.onSocketOpen((function(){c.setReadable(a),c.setWritable(a),c.emit("connect")})),i.onSocketMessage((function(e){if("string"==typeof e.data){const t=r.from(e.data,"base64");a.push(t)}else{const t=new FileReader;t.addEventListener("load",(function(){let e=t.result;e=e instanceof ArrayBuffer?r.from(e):r.from(e,"utf8"),a.push(e)})),t.readAsArrayBuffer(e.data)}})),i.onSocketClose((function(){c.end(),c.destroy()})),i.onSocketError((function(e){c.destroy(e)})))}function p(e,t){if(t.hostname=t.hostname||t.host,!t.hostname)throw new Error("Could not determine host. Specify host manually.");const n="MQIsdp"===t.protocolId&&3===t.protocolVersion?"mqttv3.1":"mqtt";d(t);const r=h(t,e);return i=t.my,i.connectSocket({url:r,protocols:n}),a=u(),c=s.obj(),f(),c}t.exports=p},{buffer:17,duplexify:20,"readable-stream":69}],3:[function(e,t,n){const r=e("net"),o=e("debug")("mqttjs:tcp");function s(e,t){t.port=t.port||1883,t.hostname=t.hostname||t.host||"localhost";const n=t.port,s=t.hostname;return o("port %d and host %s",n,s),r.createConnection(n,s)}t.exports=s},{debug:18,net:16}],4:[function(e,t,n){const r=e("tls"),o=e("net"),s=e("debug")("mqttjs:tls");function i(e,t){t.port=t.port||8883,t.host=t.hostname||t.host||"localhost",0===o.isIP(t.host)&&(t.servername=t.host),t.rejectUnauthorized=!1!==t.rejectUnauthorized,delete t.path,s("port %d host %s rejectUnauthorized %b",t.port,t.host,t.rejectUnauthorized);const n=r.connect(t);function i(r){t.rejectUnauthorized&&e.emit("error",r),n.end()}return n.on("secureConnect",(function(){t.rejectUnauthorized&&!n.authorized?n.emit("error",new Error("TLS not authorized")):n.removeListener("error",i)})),n.on("error",i),n}t.exports=i},{debug:18,net:16,tls:16}],5:[function(e,t,n){(function(n){(function(){const{Buffer:r}=e("buffer"),o=e("ws"),s=e("debug")("mqttjs:ws"),i=e("duplexify"),a=e("readable-stream").Transform,c=["rejectUnauthorized","ca","cert","key","pfx","passphrase"],l=void 0!==n&&"browser"===n.title||"function"==typeof __webpack_require__;function u(e,t){let n=e.protocol+"://"+e.hostname+":"+e.port+e.path;return"function"==typeof e.transformWsUrl&&(n=e.transformWsUrl(n,e,t)),n}function d(e){const t=e;return e.hostname||(t.hostname="localhost"),e.port||("wss"===e.protocol?t.port=443:t.port=80),e.path||(t.path="/"),e.wsOptions||(t.wsOptions={}),l||"wss"!==e.protocol||c.forEach((function(n){Object.prototype.hasOwnProperty.call(e,n)&&!Object.prototype.hasOwnProperty.call(e.wsOptions,n)&&(t.wsOptions[n]=e[n])})),t}function h(e){const t=d(e);if(t.hostname||(t.hostname=t.host),!t.hostname){if("undefined"==typeof document)throw new Error("Could not determine host. Specify host manually.");const e=new URL(document.URL);t.hostname=e.hostname,t.port||(t.port=e.port)}return void 0===t.objectMode&&(t.objectMode=!(!0===t.binary||void 0===t.binary)),t}function f(e,t,n){s("createWebSocket"),s("protocol: "+n.protocolId+" "+n.protocolVersion);const r="MQIsdp"===n.protocolId&&3===n.protocolVersion?"mqttv3.1":"mqtt";return s("creating new Websocket for url: "+t+" and protocol: "+r),new o(t,[r],n.wsOptions)}function p(e,t){const n="MQIsdp"===t.protocolId&&3===t.protocolVersion?"mqttv3.1":"mqtt",r=u(t,e),o=new WebSocket(r,[n]);return o.binaryType="arraybuffer",o}function g(e,t){s("streamBuilder");const n=d(t),r=u(n,e),i=f(e,r,n),a=o.createWebSocketStream(i,n.wsOptions);return a.url=r,i.on("close",(()=>{a.destroy()})),a}function m(e,t){let n;s("browserStreamBuilder");const o=h(t).browserBufferSize||524288,c=t.browserBufferTimeout||1e3,l=!t.objectMode,u=p(e,t),d=g(t,C,_);t.objectMode||(d._writev=w),d.on("close",(()=>{u.close()}));const f=void 0!==u.addEventListener;function g(e,t,n){const r=new a({objectModeMode:e.objectMode});return r._write=t,r._flush=n,r}function m(){n.setReadable(d),n.setWritable(d),n.emit("connect")}function y(){n.end(),n.destroy()}function v(e){n.destroy(e)}function b(e){let t=e.data;t=t instanceof ArrayBuffer?r.from(t):r.from(t,"utf8"),d.push(t)}function w(e,t){const n=new Array(e.length);for(let t=0;t<e.length;t++)"string"==typeof e[t].chunk?n[t]=r.from(e[t],"utf8"):n[t]=e[t].chunk;this._write(r.concat(n),"binary",t)}function C(e,t,n){u.bufferedAmount>o&&setTimeout(C,c,e,t,n),l&&"string"==typeof e&&(e=r.from(e,"utf8"));try{u.send(e)}catch(e){return n(e)}n()}function _(e){u.close(),e()}return u.readyState===u.OPEN?n=d:(n=n=i(void 0,void 0,t),t.objectMode||(n._writev=w),f?u.addEventListener("open",m):u.onopen=m),n.socket=u,f?(u.addEventListener("close",y),u.addEventListener("error",v),u.addEventListener("message",b)):(u.onclose=y,u.onerror=v,u.onmessage=b),n}t.exports=l?m:g}).call(this)}).call(this,e("_process"))},{_process:50,buffer:17,debug:18,duplexify:20,"readable-stream":69,ws:80}],6:[function(e,t,n){const{Buffer:r}=e("buffer"),o=e("readable-stream").Transform,s=e("duplexify");let i,a,c;function l(){const e=new o;return e._write=function(e,t,n){i.send({data:e.buffer,success:function(){n()},fail:function(e){n(new Error(e))}})},e._flush=function(e){i.close({success:function(){e()}})},e}function u(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}function d(e,t){const n="wxs"===e.protocol?"wss":"ws";let r=n+"://"+e.hostname+e.path;return e.port&&80!==e.port&&443!==e.port&&(r=n+"://"+e.hostname+":"+e.port+e.path),"function"==typeof e.transformWsUrl&&(r=e.transformWsUrl(r,e,t)),r}function h(){i.onOpen((function(){c.setReadable(a),c.setWritable(a),c.emit("connect")})),i.onMessage((function(e){let t=e.data;t=t instanceof ArrayBuffer?r.from(t):r.from(t,"utf8"),a.push(t)})),i.onClose((function(){c.end(),c.destroy()})),i.onError((function(e){c.destroy(new Error(e.errMsg))}))}function f(e,t){if(t.hostname=t.hostname||t.host,!t.hostname)throw new Error("Could not determine host. Specify host manually.");const n="MQIsdp"===t.protocolId&&3===t.protocolVersion?"mqttv3.1":"mqtt";u(t);const r=d(t,e);i=wx.connectSocket({url:r,protocols:[n]}),a=l(),c=s.obj(),c._destroy=function(e,t){i.close({success:function(){t&&t(e)}})};const o=c.destroy;return c.destroy=function(){c.destroy=o;const e=this;setTimeout((function(){i.close({fail:function(){e._destroy(new Error)}})}),0)}.bind(c),h(),c}t.exports=f},{buffer:17,duplexify:20,"readable-stream":69}],7:[function(e,t,n){function r(){if(!(this instanceof r))return new r;this.nextId=Math.max(1,Math.floor(65535*Math.random()))}r.prototype.allocate=function(){const e=this.nextId++;return 65536===this.nextId&&(this.nextId=1),e},r.prototype.getLastAllocated=function(){return 1===this.nextId?65535:this.nextId-1},r.prototype.register=function(e){return!0},r.prototype.deallocate=function(e){},r.prototype.clear=function(){},t.exports=r},{}],8:[function(e,t,n){const r=e("xtend"),o=e("readable-stream").Readable,s={objectMode:!0},i={clean:!0};function a(e){if(!(this instanceof a))return new a(e);this.options=e||{},this.options=r(i,e),this._inflights=new Map}a.prototype.put=function(e,t){return this._inflights.set(e.messageId,e),t&&t(),this},a.prototype.createStream=function(){const e=new o(s),t=[];let n=!1,r=0;return this._inflights.forEach((function(e,n){t.push(e)})),e._read=function(){!n&&r<t.length?this.push(t[r++]):this.push(null)},e.destroy=function(){if(n)return;const e=this;n=!0,setTimeout((function(){e.emit("close")}),0)},e},a.prototype.del=function(e,t){return(e=this._inflights.get(e.messageId))?(this._inflights.delete(e.messageId),t(null,e)):t&&t(new Error("missing packet")),this},a.prototype.get=function(e,t){return(e=this._inflights.get(e.messageId))?t(null,e):t&&t(new Error("missing packet")),this},a.prototype.close=function(e){this.options.clean&&(this._inflights=null),e&&e()},t.exports=a},{"readable-stream":69,xtend:81}],9:[function(e,t,n){function r(e){if(!(this instanceof r))return new r(e);this.aliasToTopic={},this.max=e}r.prototype.put=function(e,t){return!(0===t||t>this.max||(this.aliasToTopic[t]=e,this.length=Object.keys(this.aliasToTopic).length,0))},r.prototype.getTopicByAlias=function(e){return this.aliasToTopic[e]},r.prototype.clear=function(){this.aliasToTopic={}},t.exports=r},{}],10:[function(e,t,n){const r=e("lru-cache"),o=e("number-allocator").NumberAllocator;function s(e){if(!(this instanceof s))return new s(e);e>0&&(this.aliasToTopic=new r({max:e}),this.topicToAlias={},this.numberAllocator=new o(1,e),this.max=e,this.length=0)}s.prototype.put=function(e,t){if(0===t||t>this.max)return!1;const n=this.aliasToTopic.get(t);return n&&delete this.topicToAlias[n],this.aliasToTopic.set(t,e),this.topicToAlias[e]=t,this.numberAllocator.use(t),this.length=this.aliasToTopic.length,!0},s.prototype.getTopicByAlias=function(e){return this.aliasToTopic.get(e)},s.prototype.getAliasByTopic=function(e){const t=this.topicToAlias[e];return void 0!==t&&this.aliasToTopic.get(t),t},s.prototype.clear=function(){this.aliasToTopic.reset(),this.topicToAlias={},this.numberAllocator.clear(),this.length=0},s.prototype.getLruAlias=function(){const e=this.numberAllocator.firstVacant();return e||this.aliasToTopic.keys()[this.aliasToTopic.length-1]},t.exports=s},{"lru-cache":37,"number-allocator":46}],11:[function(e,t,n){function r(e){const t=e.split("/");for(let e=0;e<t.length;e++)if("+"!==t[e]){if("#"===t[e])return e===t.length-1;if(-1!==t[e].indexOf("+")||-1!==t[e].indexOf("#"))return!1}return!0}function o(e){if(0===e.length)return"empty_topic_list";for(let t=0;t<e.length;t++)if(!r(e[t]))return e[t];return null}t.exports={validateTopics:o}},{}],12:[function(e,t,n){(function(n){(function(){const r=e("../client"),o=e("../store"),s=e("url"),i=e("xtend"),a=e("debug")("mqttjs"),c={};function l(e){let t;e.auth&&(t=e.auth.match(/^(.+):(.+)$/),t?(e.username=t[1],e.password=t[2]):e.username=e.auth)}function u(e,t){if(a("connecting to an MQTT broker..."),"object"!=typeof e||t||(t=e,e=null),t=t||{},e){const n=s.parse(e,!0);if(null!=n.port&&(n.port=Number(n.port)),null===(t=i(n,t)).protocol)throw new Error("Missing protocol");t.protocol=t.protocol.replace(/:$/,"")}if(l(t),t.query&&"string"==typeof t.query.clientId&&(t.clientId=t.query.clientId),t.cert&&t.key){if(!t.protocol)throw new Error("Missing secure protocol key");if(-1===["mqtts","wss","wxs","alis"].indexOf(t.protocol))switch(t.protocol){case"mqtt":t.protocol="mqtts";break;case"ws":t.protocol="wss";break;case"wx":t.protocol="wxs";break;case"ali":t.protocol="alis";break;default:throw new Error('Unknown protocol for secure connection: "'+t.protocol+'"!')}}if(!c[t.protocol]){const e=-1!==["mqtts","wss"].indexOf(t.protocol);t.protocol=["mqtt","mqtts","ws","wss","wx","wxs","ali","alis"].filter((function(t,n){return(!e||n%2!=0)&&"function"==typeof c[t]}))[0]}if(!1===t.clean&&!t.clientId)throw new Error("Missing clientId for unclean clients");function n(e){return t.servers&&(e._reconnectCount&&e._reconnectCount!==t.servers.length||(e._reconnectCount=0),t.host=t.servers[e._reconnectCount].host,t.port=t.servers[e._reconnectCount].port,t.protocol=t.servers[e._reconnectCount].protocol?t.servers[e._reconnectCount].protocol:t.defaultProtocol,t.hostname=t.host,e._reconnectCount++),a("calling streambuilder for",t.protocol),c[t.protocol](e,t)}t.protocol&&(t.defaultProtocol=t.protocol);const o=new r(n,t);return o.on("error",(function(){})),o}void 0!==n&&"browser"!==n.title||"function"!=typeof __webpack_require__?(c.mqtt=e("./tcp"),c.tcp=e("./tcp"),c.ssl=e("./tls"),c.tls=e("./tls"),c.mqtts=e("./tls")):(c.wx=e("./wx"),c.wxs=e("./wx"),c.ali=e("./ali"),c.alis=e("./ali")),c.ws=e("./ws"),c.wss=e("./ws"),t.exports=u,t.exports.connect=u,t.exports.MqttClient=r,t.exports.Store=o}).call(this)}).call(this,e("_process"))},{"../client":1,"../store":8,"./ali":2,"./tcp":3,"./tls":4,"./ws":5,"./wx":6,_process:50,debug:18,url:76,xtend:81}],13:[function(e,t,n){n.byteLength=u,n.toByteArray=h,n.fromByteArray=g;for(var r=[],o=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=i.length;a<c;++a)r[a]=i[a],o[i.charCodeAt(a)]=a;function l(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function u(e){var t=l(e),n=t[0],r=t[1];return 3*(n+r)/4-r}function d(e,t,n){return 3*(t+n)/4-n}function h(e){var t,n,r=l(e),i=r[0],a=r[1],c=new s(d(e,i,a)),u=0,h=a>0?i-4:i;for(n=0;n<h;n+=4)t=o[e.charCodeAt(n)]<<18|o[e.charCodeAt(n+1)]<<12|o[e.charCodeAt(n+2)]<<6|o[e.charCodeAt(n+3)],c[u++]=t>>16&255,c[u++]=t>>8&255,c[u++]=255&t;return 2===a&&(t=o[e.charCodeAt(n)]<<2|o[e.charCodeAt(n+1)]>>4,c[u++]=255&t),1===a&&(t=o[e.charCodeAt(n)]<<10|o[e.charCodeAt(n+1)]<<4|o[e.charCodeAt(n+2)]>>2,c[u++]=t>>8&255,c[u++]=255&t),c}function f(e){return r[e>>18&63]+r[e>>12&63]+r[e>>6&63]+r[63&e]}function p(e,t,n){for(var r,o=[],s=t;s<n;s+=3)r=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(255&e[s+2]),o.push(f(r));return o.join("")}function g(e){for(var t,n=e.length,o=n%3,s=[],i=16383,a=0,c=n-o;a<c;a+=i)s.push(p(e,a,a+i>c?c:a+i));return 1===o?(t=e[n-1],s.push(r[t>>2]+r[t<<4&63]+"==")):2===o&&(t=(e[n-2]<<8)+e[n-1],s.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"=")),s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},{}],14:[function(e,t,n){const{Buffer:r}=e("buffer"),o=Symbol.for("BufferList");function s(e){if(!(this instanceof s))return new s(e);s._init.call(this,e)}s._init=function(e){Object.defineProperty(this,o,{value:!0}),this._bufs=[],this.length=0,e&&this.append(e)},s.prototype._new=function(e){return new s(e)},s.prototype._offset=function(e){if(0===e)return[0,0];let t=0;for(let n=0;n<this._bufs.length;n++){const r=t+this._bufs[n].length;if(e<r||n===this._bufs.length-1)return[n,e-t];t=r}},s.prototype._reverseOffset=function(e){const t=e[0];let n=e[1];for(let e=0;e<t;e++)n+=this._bufs[e].length;return n},s.prototype.get=function(e){if(e>this.length||e<0)return;const t=this._offset(e);return this._bufs[t[0]][t[1]]},s.prototype.slice=function(e,t){return"number"==typeof e&&e<0&&(e+=this.length),"number"==typeof t&&t<0&&(t+=this.length),this.copy(null,0,e,t)},s.prototype.copy=function(e,t,n,o){if(("number"!=typeof n||n<0)&&(n=0),("number"!=typeof o||o>this.length)&&(o=this.length),n>=this.length)return e||r.alloc(0);if(o<=0)return e||r.alloc(0);const s=!!e,i=this._offset(n),a=o-n;let c=a,l=s&&t||0,u=i[1];if(0===n&&o===this.length){if(!s)return 1===this._bufs.length?this._bufs[0]:r.concat(this._bufs,this.length);for(let t=0;t<this._bufs.length;t++)this._bufs[t].copy(e,l),l+=this._bufs[t].length;return e}if(c<=this._bufs[i[0]].length-u)return s?this._bufs[i[0]].copy(e,t,u,u+c):this._bufs[i[0]].slice(u,u+c);s||(e=r.allocUnsafe(a));for(let t=i[0];t<this._bufs.length;t++){const n=this._bufs[t].length-u;if(!(c>n)){this._bufs[t].copy(e,l,u,u+c),l+=n;break}this._bufs[t].copy(e,l,u),l+=n,c-=n,u&&(u=0)}return e.length>l?e.slice(0,l):e},s.prototype.shallowSlice=function(e,t){if(e=e||0,t="number"!=typeof t?this.length:t,e<0&&(e+=this.length),t<0&&(t+=this.length),e===t)return this._new();const n=this._offset(e),r=this._offset(t),o=this._bufs.slice(n[0],r[0]+1);return 0===r[1]?o.pop():o[o.length-1]=o[o.length-1].slice(0,r[1]),0!==n[1]&&(o[0]=o[0].slice(n[1])),this._new(o)},s.prototype.toString=function(e,t,n){return this.slice(t,n).toString(e)},s.prototype.consume=function(e){if(e=Math.trunc(e),Number.isNaN(e)||e<=0)return this;for(;this._bufs.length;){if(!(e>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(e),this.length-=e;break}e-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},s.prototype.duplicate=function(){const e=this._new();for(let t=0;t<this._bufs.length;t++)e.append(this._bufs[t]);return e},s.prototype.append=function(e){if(null==e)return this;if(e.buffer)this._appendBuffer(r.from(e.buffer,e.byteOffset,e.byteLength));else if(Array.isArray(e))for(let t=0;t<e.length;t++)this.append(e[t]);else if(this._isBufferList(e))for(let t=0;t<e._bufs.length;t++)this.append(e._bufs[t]);else"number"==typeof e&&(e=e.toString()),this._appendBuffer(r.from(e));return this},s.prototype._appendBuffer=function(e){this._bufs.push(e),this.length+=e.length},s.prototype.indexOf=function(e,t,n){if(void 0===n&&"string"==typeof t&&(n=t,t=void 0),"function"==typeof e||Array.isArray(e))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if("number"==typeof e?e=r.from([e]):"string"==typeof e?e=r.from(e,n):this._isBufferList(e)?e=e.slice():Array.isArray(e.buffer)?e=r.from(e.buffer,e.byteOffset,e.byteLength):r.isBuffer(e)||(e=r.from(e)),t=Number(t||0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),0===e.length)return t>this.length?this.length:t;const o=this._offset(t);let s=o[0],i=o[1];for(;s<this._bufs.length;s++){const t=this._bufs[s];for(;i<t.length;)if(t.length-i>=e.length){const n=t.indexOf(e,i);if(-1!==n)return this._reverseOffset([s,n]);i=t.length-e.length+1}else{const t=this._reverseOffset([s,i]);if(this._match(t,e))return t;i++}i=0}return-1},s.prototype._match=function(e,t){if(this.length-e<t.length)return!1;for(let n=0;n<t.length;n++)if(this.get(e+n)!==t[n])return!1;return!0},function(){const e={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1,readIntBE:null,readIntLE:null,readUIntBE:null,readUIntLE:null};for(const t in e)!function(t){null===e[t]?s.prototype[t]=function(e,n){return this.slice(e,e+n)[t](0,n)}:s.prototype[t]=function(n=0){return this.slice(n,n+e[t])[t](0)}}(t)}(),s.prototype._isBufferList=function(e){return e instanceof s||s.isBufferList(e)},s.isBufferList=function(e){return null!=e&&e[o]},t.exports=s},{buffer:17}],15:[function(e,t,n){const r=e("readable-stream").Duplex,o=e("inherits"),s=e("./BufferList");function i(e){if(!(this instanceof i))return new i(e);if("function"==typeof e){this._callback=e;const t=function(e){this._callback&&(this._callback(e),this._callback=null)}.bind(this);this.on("pipe",(function(e){e.on("error",t)})),this.on("unpipe",(function(e){e.removeListener("error",t)})),e=null}s._init.call(this,e),r.call(this)}o(i,r),Object.assign(i.prototype,s.prototype),i.prototype._new=function(e){return new i(e)},i.prototype._write=function(e,t,n){this._appendBuffer(e),"function"==typeof n&&n()},i.prototype._read=function(e){if(!this.length)return this.push(null);e=Math.min(e,this.length),this.push(this.slice(0,e)),this.consume(e)},i.prototype.end=function(e){r.prototype.end.call(this,e),this._callback&&(this._callback(null,this.slice()),this._callback=null)},i.prototype._destroy=function(e,t){this._bufs.length=0,this.length=0,t(e)},i.prototype._isBufferList=function(e){return e instanceof i||e instanceof s||i.isBufferList(e)},i.isBufferList=s.isBufferList,t.exports=i,t.exports.BufferListStream=i,t.exports.BufferList=s},{"./BufferList":14,inherits:24,"readable-stream":69}],16:[function(e,t,n){},{}],17:[function(e,t,n){(function(t){(function(){var t=e("base64-js"),r=e("ieee754");n.Buffer=a,n.SlowBuffer=y,n.INSPECT_MAX_BYTES=50;var o=2147483647;function s(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}function i(e){if(e>o)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return t.__proto__=a.prototype,t}function a(e,t,n){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return d(e)}return c(e,t,n)}function c(e,t,n){if("string"==typeof e)return h(e,t);if(ArrayBuffer.isView(e))return f(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(G(e,ArrayBuffer)||e&&G(e.buffer,ArrayBuffer))return p(e,t,n);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var r=e.valueOf&&e.valueOf();if(null!=r&&r!==e)return a.from(r,t,n);var o=g(e);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return a.from(e[Symbol.toPrimitive]("string"),t,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function l(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function u(e,t,n){return l(e),e<=0?i(e):void 0!==t?"string"==typeof n?i(e).fill(t,n):i(e).fill(t):i(e)}function d(e){return l(e),i(e<0?0:0|m(e))}function h(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!a.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var n=0|v(e,t),r=i(n),o=r.write(e,t);return o!==n&&(r=r.slice(0,o)),r}function f(e){for(var t=e.length<0?0:0|m(e.length),n=i(t),r=0;r<t;r+=1)n[r]=255&e[r];return n}function p(e,t,n){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(n||0))throw new RangeError('"length" is outside of buffer bounds');var r;return(r=void 0===t&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,t):new Uint8Array(e,t,n)).__proto__=a.prototype,r}function g(e){if(a.isBuffer(e)){var t=0|m(e.length),n=i(t);return 0===n.length||e.copy(n,0,0,t),n}return void 0!==e.length?"number"!=typeof e.length||Y(e.length)?i(0):f(e):"Buffer"===e.type&&Array.isArray(e.data)?f(e.data):void 0}function m(e){if(e>=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return 0|e}function y(e){return+e!=e&&(e=0),a.alloc(+e)}function v(e,t){if(a.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||G(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var n=e.length,r=arguments.length>2&&!0===arguments[2];if(!r&&0===n)return 0;for(var o=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return V(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return Q(e).length;default:if(o)return r?-1:V(e).length;t=(""+t).toLowerCase(),o=!0}}function b(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return F(this,t,n);case"utf8":case"utf-8":return x(this,t,n);case"ascii":return M(this,t,n);case"latin1":case"binary":return j(this,t,n);case"base64":return T(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function w(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function C(e,t,n,r,o){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),Y(n=+n)&&(n=o?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(o)return-1;n=e.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof t&&(t=a.from(t,r)),a.isBuffer(t))return 0===t.length?-1:_(e,t,n,r,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):_(e,[t],n,r,o);throw new TypeError("val must be string, number or Buffer")}function _(e,t,n,r,o){var s,i=1,a=e.length,c=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;i=2,a/=2,c/=2,n/=2}function l(e,t){return 1===i?e[t]:e.readUInt16BE(t*i)}if(o){var u=-1;for(s=n;s<a;s++)if(l(e,s)===l(t,-1===u?0:s-u)){if(-1===u&&(u=s),s-u+1===c)return u*i}else-1!==u&&(s-=s-u),u=-1}else for(n+c>a&&(n=a-c),s=n;s>=0;s--){for(var d=!0,h=0;h<c;h++)if(l(e,s+h)!==l(t,h)){d=!1;break}if(d)return s}return-1}function k(e,t,n,r){n=Number(n)||0;var o=e.length-n;r?(r=Number(r))>o&&(r=o):r=o;var s=t.length;r>s/2&&(r=s/2);for(var i=0;i<r;++i){var a=parseInt(t.substr(2*i,2),16);if(Y(a))return i;e[n+i]=a}return i}function S(e,t,n,r){return J(V(t,e.length-n),e,n,r)}function A(e,t,n,r){return J(W(t),e,n,r)}function E(e,t,n,r){return A(e,t,n,r)}function I(e,t,n,r){return J(Q(t),e,n,r)}function O(e,t,n,r){return J(K(t,e.length-n),e,n,r)}function T(e,n,r){return 0===n&&r===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(n,r))}function x(e,t,n){n=Math.min(e.length,n);for(var r=[],o=t;o<n;){var s,i,a,c,l=e[o],u=null,d=l>239?4:l>223?3:l>191?2:1;if(o+d<=n)switch(d){case 1:l<128&&(u=l);break;case 2:128==(192&(s=e[o+1]))&&(c=(31&l)<<6|63&s)>127&&(u=c);break;case 3:s=e[o+1],i=e[o+2],128==(192&s)&&128==(192&i)&&(c=(15&l)<<12|(63&s)<<6|63&i)>2047&&(c<55296||c>57343)&&(u=c);break;case 4:s=e[o+1],i=e[o+2],a=e[o+3],128==(192&s)&&128==(192&i)&&128==(192&a)&&(c=(15&l)<<18|(63&s)<<12|(63&i)<<6|63&a)>65535&&c<1114112&&(u=c)}null===u?(u=65533,d=1):u>65535&&(u-=65536,r.push(u>>>10&1023|55296),u=56320|1023&u),r.push(u),o+=d}return P(r)}n.kMaxLength=o,a.TYPED_ARRAY_SUPPORT=s(),a.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&a[Symbol.species]===a&&Object.defineProperty(a,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),a.poolSize=8192,a.from=function(e,t,n){return c(e,t,n)},a.prototype.__proto__=Uint8Array.prototype,a.__proto__=Uint8Array,a.alloc=function(e,t,n){return u(e,t,n)},a.allocUnsafe=function(e){return d(e)},a.allocUnsafeSlow=function(e){return d(e)},a.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==a.prototype},a.compare=function(e,t){if(G(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),G(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(e)||!a.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var n=e.length,r=t.length,o=0,s=Math.min(n,r);o<s;++o)if(e[o]!==t[o]){n=e[o],r=t[o];break}return n<r?-1:r<n?1:0},a.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return a.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=a.allocUnsafe(t),o=0;for(n=0;n<e.length;++n){var s=e[n];if(G(s,Uint8Array)&&(s=a.from(s)),!a.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(r,o),o+=s.length}return r},a.byteLength=v,a.prototype._isBuffer=!0,a.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)w(this,t,t+1);return this},a.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)w(this,t,t+3),w(this,t+1,t+2);return this},a.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)w(this,t,t+7),w(this,t+1,t+6),w(this,t+2,t+5),w(this,t+3,t+4);return this},a.prototype.toString=function(){var e=this.length;return 0===e?"":0===arguments.length?x(this,0,e):b.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(e){if(!a.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===a.compare(this,e)},a.prototype.inspect=function(){var e="",t=n.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},a.prototype.compare=function(e,t,n,r,o){if(G(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),t<0||n>e.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&t>=n)return 0;if(r>=o)return-1;if(t>=n)return 1;if(this===e)return 0;for(var s=(o>>>=0)-(r>>>=0),i=(n>>>=0)-(t>>>=0),c=Math.min(s,i),l=this.slice(r,o),u=e.slice(t,n),d=0;d<c;++d)if(l[d]!==u[d]){s=l[d],i=u[d];break}return s<i?-1:i<s?1:0},a.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},a.prototype.indexOf=function(e,t,n){return C(this,e,t,n,!0)},a.prototype.lastIndexOf=function(e,t,n){return C(this,e,t,n,!1)},a.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(n)?(n>>>=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-t;if((void 0===n||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var s=!1;;)switch(r){case"hex":return k(this,e,t,n);case"utf8":case"utf-8":return S(this,e,t,n);case"ascii":return A(this,e,t,n);case"latin1":case"binary":return E(this,e,t,n);case"base64":return I(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var R=4096;function P(e){var t=e.length;if(t<=R)return String.fromCharCode.apply(String,e);for(var n="",r=0;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=R));return n}function M(e,t,n){var r="";n=Math.min(e.length,n);for(var o=t;o<n;++o)r+=String.fromCharCode(127&e[o]);return r}function j(e,t,n){var r="";n=Math.min(e.length,n);for(var o=t;o<n;++o)r+=String.fromCharCode(e[o]);return r}function F(e,t,n){var r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);for(var o="",s=t;s<n;++s)o+=H(e[s]);return o}function N(e,t,n){for(var r=e.slice(t,n),o="",s=0;s<r.length;s+=2)o+=String.fromCharCode(r[s]+256*r[s+1]);return o}function B(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function U(e,t,n,r,o,s){if(!a.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<s)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function D(e,t,n,r,o,s){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function L(e,t,n,o,s){return t=+t,n>>>=0,s||D(e,t,n,4),r.write(e,t,n,o,23,4),n+4}function q(e,t,n,o,s){return t=+t,n>>>=0,s||D(e,t,n,8),r.write(e,t,n,o,52,8),n+8}a.prototype.slice=function(e,t){var n=this.length;(e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e);var r=this.subarray(e,t);return r.__proto__=a.prototype,r},a.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||B(e,t,this.length);for(var r=this[e],o=1,s=0;++s<t&&(o*=256);)r+=this[e+s]*o;return r},a.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||B(e,t,this.length);for(var r=this[e+--t],o=1;t>0&&(o*=256);)r+=this[e+--t]*o;return r},a.prototype.readUInt8=function(e,t){return e>>>=0,t||B(e,1,this.length),this[e]},a.prototype.readUInt16LE=function(e,t){return e>>>=0,t||B(e,2,this.length),this[e]|this[e+1]<<8},a.prototype.readUInt16BE=function(e,t){return e>>>=0,t||B(e,2,this.length),this[e]<<8|this[e+1]},a.prototype.readUInt32LE=function(e,t){return e>>>=0,t||B(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},a.prototype.readUInt32BE=function(e,t){return e>>>=0,t||B(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},a.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||B(e,t,this.length);for(var r=this[e],o=1,s=0;++s<t&&(o*=256);)r+=this[e+s]*o;return r>=(o*=128)&&(r-=Math.pow(2,8*t)),r},a.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||B(e,t,this.length);for(var r=t,o=1,s=this[e+--r];r>0&&(o*=256);)s+=this[e+--r]*o;return s>=(o*=128)&&(s-=Math.pow(2,8*t)),s},a.prototype.readInt8=function(e,t){return e>>>=0,t||B(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},a.prototype.readInt16LE=function(e,t){e>>>=0,t||B(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},a.prototype.readInt16BE=function(e,t){e>>>=0,t||B(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},a.prototype.readInt32LE=function(e,t){return e>>>=0,t||B(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},a.prototype.readInt32BE=function(e,t){return e>>>=0,t||B(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},a.prototype.readFloatLE=function(e,t){return e>>>=0,t||B(e,4,this.length),r.read(this,e,!0,23,4)},a.prototype.readFloatBE=function(e,t){return e>>>=0,t||B(e,4,this.length),r.read(this,e,!1,23,4)},a.prototype.readDoubleLE=function(e,t){return e>>>=0,t||B(e,8,this.length),r.read(this,e,!0,52,8)},a.prototype.readDoubleBE=function(e,t){return e>>>=0,t||B(e,8,this.length),r.read(this,e,!1,52,8)},a.prototype.writeUIntLE=function(e,t,n,r){e=+e,t>>>=0,n>>>=0,r||U(this,e,t,n,Math.pow(2,8*n)-1,0);var o=1,s=0;for(this[t]=255&e;++s<n&&(o*=256);)this[t+s]=e/o&255;return t+n},a.prototype.writeUIntBE=function(e,t,n,r){e=+e,t>>>=0,n>>>=0,r||U(this,e,t,n,Math.pow(2,8*n)-1,0);var o=n-1,s=1;for(this[t+o]=255&e;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+n},a.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||U(this,e,t,1,255,0),this[t]=255&e,t+1},a.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||U(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},a.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||U(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},a.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||U(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},a.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||U(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},a.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t>>>=0,!r){var o=Math.pow(2,8*n-1);U(this,e,t,n,o-1,-o)}var s=0,i=1,a=0;for(this[t]=255&e;++s<n&&(i*=256);)e<0&&0===a&&0!==this[t+s-1]&&(a=1),this[t+s]=(e/i>>0)-a&255;return t+n},a.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t>>>=0,!r){var o=Math.pow(2,8*n-1);U(this,e,t,n,o-1,-o)}var s=n-1,i=1,a=0;for(this[t+s]=255&e;--s>=0&&(i*=256);)e<0&&0===a&&0!==this[t+s+1]&&(a=1),this[t+s]=(e/i>>0)-a&255;return t+n},a.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||U(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},a.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||U(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},a.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||U(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},a.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||U(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},a.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||U(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},a.prototype.writeFloatLE=function(e,t,n){return L(this,e,t,!0,n)},a.prototype.writeFloatBE=function(e,t,n){return L(this,e,t,!1,n)},a.prototype.writeDoubleLE=function(e,t,n){return q(this,e,t,!0,n)},a.prototype.writeDoubleBE=function(e,t,n){return q(this,e,t,!1,n)},a.prototype.copy=function(e,t,n,r){if(!a.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var o=r-n;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(t,n,r);else if(this===e&&n<t&&t<r)for(var s=o-1;s>=0;--s)e[s+t]=this[s+n];else Uint8Array.prototype.set.call(e,this.subarray(n,r),t);return o},a.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!a.isEncoding(r))throw new TypeError("Unknown encoding: "+r);if(1===e.length){var o=e.charCodeAt(0);("utf8"===r&&o<128||"latin1"===r)&&(e=o)}}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;var s;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(s=t;s<n;++s)this[s]=e;else{var i=a.isBuffer(e)?e:a.from(e,r),c=i.length;if(0===c)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<n-t;++s)this[s+t]=i[s%c]}return this};var $=/[^+/0-9A-Za-z-_]/g;function z(e){if((e=(e=e.split("=")[0]).trim().replace($,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}function H(e){return e<16?"0"+e.toString(16):e.toString(16)}function V(e,t){var n;t=t||1/0;for(var r=e.length,o=null,s=[],i=0;i<r;++i){if((n=e.charCodeAt(i))>55295&&n<57344){if(!o){if(n>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(i+1===r){(t-=3)>-1&&s.push(239,191,189);continue}o=n;continue}if(n<56320){(t-=3)>-1&&s.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(t-=3)>-1&&s.push(239,191,189);if(o=null,n<128){if((t-=1)<0)break;s.push(n)}else if(n<2048){if((t-=2)<0)break;s.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;s.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return s}function W(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}function K(e,t){for(var n,r,o,s=[],i=0;i<e.length&&!((t-=2)<0);++i)r=(n=e.charCodeAt(i))>>8,o=n%256,s.push(o),s.push(r);return s}function Q(e){return t.toByteArray(z(e))}function J(e,t,n,r){for(var o=0;o<r&&!(o+n>=t.length||o>=e.length);++o)t[o+n]=e[o];return o}function G(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Y(e){return e!=e}}).call(this)}).call(this,e("buffer").Buffer)},{"base64-js":13,buffer:17,ieee754:23}],18:[function(e,t,n){(function(r){(function(){function o(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function s(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+t.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;e.splice(1,0,n,"color: inherit");let r=0,o=0;e[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))})),e.splice(o,0,n)}function i(e){try{e?n.storage.setItem("debug",e):n.storage.removeItem("debug")}catch(e){}}function a(){let e;try{e=n.storage.getItem("debug")}catch(e){}return!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG),e}function c(){try{return localStorage}catch(e){}}n.formatArgs=s,n.save=i,n.load=a,n.useColors=o,n.storage=c(),n.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),n.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],n.log=console.debug||console.log||(()=>{}),t.exports=e("./common")(n);const{formatters:l}=t.exports;l.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}).call(this)}).call(this,e("_process"))},{"./common":19,_process:50}],19:[function(e,t,n){function r(t){function n(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return r.colors[Math.abs(t)%r.colors.length]}function r(e){let t,n,s,i=null;function a(...e){if(!a.enabled)return;const n=a,o=Number(new Date),s=o-(t||o);n.diff=s,n.prev=t,n.curr=o,t=o,e[0]=r.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((t,o)=>{if("%%"===t)return"%";i++;const s=r.formatters[o];if("function"==typeof s){const r=e[i];t=s.call(n,r),e.splice(i,1),i--}return t})),r.formatArgs.call(n,e),(n.log||r.log).apply(n,e)}return a.namespace=e,a.useColors=r.useColors(),a.color=r.selectColor(e),a.extend=o,a.destroy=r.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==i?i:(n!==r.namespaces&&(n=r.namespaces,s=r.enabled(e)),s),set:e=>{i=e}}),"function"==typeof r.init&&r.init(a),a}function o(e,t){const n=r(this.namespace+(void 0===t?":":t)+e);return n.log=this.log,n}function s(e){let t;r.save(e),r.namespaces=e,r.names=[],r.skips=[];const n=("string"==typeof e?e:"").split(/[\s,]+/),o=n.length;for(t=0;t<o;t++)n[t]&&("-"===(e=n[t].replace(/\*/g,".*?"))[0]?r.skips.push(new RegExp("^"+e.substr(1)+"$")):r.names.push(new RegExp("^"+e+"$")))}function i(){const e=[...r.names.map(c),...r.skips.map(c).map((e=>"-"+e))].join(",");return r.enable(""),e}function a(e){if("*"===e[e.length-1])return!0;let t,n;for(t=0,n=r.skips.length;t<n;t++)if(r.skips[t].test(e))return!1;for(t=0,n=r.names.length;t<n;t++)if(r.names[t].test(e))return!0;return!1}function c(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}function l(e){return e instanceof Error?e.stack||e.message:e}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.debug=r,r.default=r,r.coerce=l,r.disable=i,r.enable=s,r.enabled=a,r.humanize=e("ms"),r.destroy=u,Object.keys(t).forEach((e=>{r[e]=t[e]})),r.names=[],r.skips=[],r.formatters={},r.selectColor=n,r.enable(r.load()),r}t.exports=r},{ms:45}],20:[function(e,t,n){(function(n,r){(function(){var o=e("readable-stream"),s=e("end-of-stream"),i=e("inherits"),a=e("stream-shift"),c=r.from&&r.from!==Uint8Array.from?r.from([0]):new r([0]),l=function(e,t){e._corked?e.once("uncork",t):t()},u=function(e,t){e._autoDestroy&&e.destroy(t)},d=function(e,t){return function(n){n?u(e,"premature close"===n.message?null:n):t&&!e._ended&&e.end()}},h=function(e,t){return e?e._writableState&&e._writableState.finished?t():e._writableState?e.end(t):(e.end(),void t()):t()},f=function(){},p=function(e){return new o.Readable({objectMode:!0,highWaterMark:16}).wrap(e)},g=function(e,t,n){if(!(this instanceof g))return new g(e,t,n);o.Duplex.call(this,n),this._writable=null,this._readable=null,this._readable2=null,this._autoDestroy=!n||!1!==n.autoDestroy,this._forwardDestroy=!n||!1!==n.destroy,this._forwardEnd=!n||!1!==n.end,this._corked=1,this._ondrain=null,this._drained=!1,this._forwarding=!1,this._unwrite=null,this._unread=null,this._ended=!1,this.destroyed=!1,e&&this.setWritable(e),t&&this.setReadable(t)};i(g,o.Duplex),g.obj=function(e,t,n){return n||(n={}),n.objectMode=!0,n.highWaterMark=16,new g(e,t,n)},g.prototype.cork=function(){1==++this._corked&&this.emit("cork")},g.prototype.uncork=function(){this._corked&&0==--this._corked&&this.emit("uncork")},g.prototype.setWritable=function(e){if(this._unwrite&&this._unwrite(),this.destroyed)e&&e.destroy&&e.destroy();else if(null!==e&&!1!==e){var t=this,r=s(e,{writable:!0,readable:!1},d(this,this._forwardEnd)),o=function(){var e=t._ondrain;t._ondrain=null,e&&e()},i=function(){t._writable.removeListener("drain",o),r()};this._unwrite&&n.nextTick(o),this._writable=e,this._writable.on("drain",o),this._unwrite=i,this.uncork()}else this.end()},g.prototype.setReadable=function(e){if(this._unread&&this._unread(),this.destroyed)e&&e.destroy&&e.destroy();else{if(null===e||!1===e)return this.push(null),void this.resume();var t=this,n=s(e,{writable:!1,readable:!0},d(this)),r=function(){t._forward()},o=function(){t.push(null)},i=function(){t._readable2.removeListener("readable",r),t._readable2.removeListener("end",o),n()};this._drained=!0,this._readable=e,this._readable2=e._readableState?e:p(e),this._readable2.on("readable",r),this._readable2.on("end",o),this._unread=i,this._forward()}},g.prototype._read=function(){this._drained=!0,this._forward()},g.prototype._forward=function(){if(!this._forwarding&&this._readable2&&this._drained){var e;for(this._forwarding=!0;this._drained&&null!==(e=a(this._readable2));)this.destroyed||(this._drained=this.push(e));this._forwarding=!1}},g.prototype.destroy=function(e,t){if(t||(t=f),this.destroyed)return t(null);this.destroyed=!0;var r=this;n.nextTick((function(){r._destroy(e),t(null)}))},g.prototype._destroy=function(e){if(e){var t=this._ondrain;this._ondrain=null,t?t(e):this.emit("error",e)}this._forwardDestroy&&(this._readable&&this._readable.destroy&&this._readable.destroy(),this._writable&&this._writable.destroy&&this._writable.destroy()),this.emit("close")},g.prototype._write=function(e,t,n){if(!this.destroyed)return this._corked?l(this,this._write.bind(this,e,t,n)):e===c?this._finish(n):this._writable?void(!1===this._writable.write(e)?this._ondrain=n:this.destroyed||n()):n()},g.prototype._finish=function(e){var t=this;this.emit("preend"),l(this,(function(){h(t._forwardEnd&&t._writable,(function(){!1===t._writableState.prefinished&&(t._writableState.prefinished=!0),t.emit("prefinish"),l(t,e)}))}))},g.prototype.end=function(e,t,n){return"function"==typeof e?this.end(null,null,e):"function"==typeof t?this.end(e,null,t):(this._ended=!0,e&&this.write(e),this._writableState.ending||this._writableState.destroyed||this.write(c),o.Writable.prototype.end.call(this,n))},t.exports=g}).call(this)}).call(this,e("_process"),e("buffer").Buffer)},{_process:50,buffer:17,"end-of-stream":21,inherits:24,"readable-stream":69,"stream-shift":74}],21:[function(e,t,n){(function(n){(function(){var r=e("once"),o=function(){},s=function(e){return e.setHeader&&"function"==typeof e.abort},i=function(e){return e.stdio&&Array.isArray(e.stdio)&&3===e.stdio.length},a=function(e,t,c){if("function"==typeof t)return a(e,null,t);t||(t={}),c=r(c||o);var l=e._writableState,u=e._readableState,d=t.readable||!1!==t.readable&&e.readable,h=t.writable||!1!==t.writable&&e.writable,f=!1,p=function(){e.writable||g()},g=function(){h=!1,d||c.call(e)},m=function(){d=!1,h||c.call(e)},y=function(t){c.call(e,t?new Error("exited with error code: "+t):null)},v=function(t){c.call(e,t)},b=function(){n.nextTick(w)},w=function(){if(!f)return(!d||u&&u.ended&&!u.destroyed)&&(!h||l&&l.ended&&!l.destroyed)?void 0:c.call(e,new Error("premature close"))},C=function(){e.req.on("finish",g)};return s(e)?(e.on("complete",g),e.on("abort",b),e.req?C():e.on("request",C)):h&&!l&&(e.on("end",p),e.on("close",p)),i(e)&&e.on("exit",y),e.on("end",m),e.on("finish",g),!1!==t.error&&e.on("error",v),e.on("close",b),function(){f=!0,e.removeListener("complete",g),e.removeListener("abort",b),e.removeListener("request",C),e.req&&e.req.removeListener("finish",g),e.removeListener("end",p),e.removeListener("close",p),e.removeListener("finish",g),e.removeListener("exit",y),e.removeListener("end",m),e.removeListener("error",v),e.removeListener("close",b)}};t.exports=a}).call(this)}).call(this,e("_process"))},{_process:50,once:48}],22:[function(e,t,n){var r=Object.create||S,o=Object.keys||A,s=Function.prototype.bind||E;function i(){this._events&&Object.prototype.hasOwnProperty.call(this,"_events")||(this._events=r(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0}t.exports=i,i.EventEmitter=i,i.prototype._events=void 0,i.prototype._maxListeners=void 0;var a,c=10;try{var l={};Object.defineProperty&&Object.defineProperty(l,"x",{value:0}),a=0===l.x}catch(e){a=!1}function u(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function d(e,t,n){if(t)e.call(n);else for(var r=e.length,o=_(e,r),s=0;s<r;++s)o[s].call(n)}function h(e,t,n,r){if(t)e.call(n,r);else for(var o=e.length,s=_(e,o),i=0;i<o;++i)s[i].call(n,r)}function f(e,t,n,r,o){if(t)e.call(n,r,o);else for(var s=e.length,i=_(e,s),a=0;a<s;++a)i[a].call(n,r,o)}function p(e,t,n,r,o,s){if(t)e.call(n,r,o,s);else for(var i=e.length,a=_(e,i),c=0;c<i;++c)a[c].call(n,r,o,s)}function g(e,t,n,r){if(t)e.apply(n,r);else for(var o=e.length,s=_(e,o),i=0;i<o;++i)s[i].apply(n,r)}function m(e,t,n,o){var s,i,a;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((i=e._events)?(i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),a=i[t]):(i=e._events=r(null),e._eventsCount=0),a){if("function"==typeof a?a=i[t]=o?[n,a]:[a,n]:o?a.unshift(n):a.push(n),!a.warned&&(s=u(e))&&s>0&&a.length>s){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=a.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",c.name,c.message)}}else a=i[t]=n,++e._eventsCount;return e}function y(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var e=new Array(arguments.length),t=0;t<e.length;++t)e[t]=arguments[t];this.listener.apply(this.target,e)}}function v(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},o=s.call(y,r);return o.listener=n,r.wrapFn=o,o}function b(e,t,n){var r=e._events;if(!r)return[];var o=r[t];return o?"function"==typeof o?n?[o.listener||o]:[o]:n?k(o):_(o,o.length):[]}function w(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 C(e,t){for(var n=t,r=n+1,o=e.length;r<o;n+=1,r+=1)e[n]=e[r];e.pop()}function _(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function k(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function S(e){var t=function(){};return t.prototype=e,new t}function A(e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t);return t}function E(e){var t=this;return function(){return t.apply(e,arguments)}}a?Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(e){if("number"!=typeof e||e<0||e!=e)throw new TypeError('"defaultMaxListeners" must be a positive number');c=e}}):i.defaultMaxListeners=c,i.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},i.prototype.getMaxListeners=function(){return u(this)},i.prototype.emit=function(e){var t,n,r,o,s,i,a="error"===e;if(i=this._events)a=a&&null==i.error;else if(!a)return!1;if(a){if(arguments.length>1&&(t=arguments[1]),t instanceof Error)throw t;var c=new Error('Unhandled "error" event. ('+t+")");throw c.context=t,c}if(!(n=i[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:d(n,l,this);break;case 2:h(n,l,this,arguments[1]);break;case 3:f(n,l,this,arguments[1],arguments[2]);break;case 4:p(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(o=new Array(r-1),s=1;s<r;s++)o[s-1]=arguments[s];g(n,l,this,o)}return!0},i.prototype.addListener=function(e,t){return m(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return m(this,e,t,!0)},i.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},i.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},i.prototype.removeListener=function(e,t){var n,o,s,i,a;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(o=this._events))return this;if(!(n=o[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=r(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(s=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){a=n[i].listener,s=i;break}if(s<0)return this;0===s?n.shift():C(n,s),1===n.length&&(o[e]=n[0]),o.removeListener&&this.emit("removeListener",e,a||t)}return this},i.prototype.removeAllListeners=function(e){var t,n,s;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=r(null),this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=r(null):delete n[e]),this;if(0===arguments.length){var i,a=o(n);for(s=0;s<a.length;++s)"removeListener"!==(i=a[s])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=r(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)for(s=t.length-1;s>=0;s--)this.removeListener(e,t[s]);return this},i.prototype.listeners=function(e){return b(this,e,!0)},i.prototype.rawListeners=function(e){return b(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):w.call(e,t)},i.prototype.listenerCount=w,i.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],23:[function(e,t,n){
3
3
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
4
4
  n.read=function(e,t,n,r,o){var s,i,a=8*o-r-1,c=(1<<a)-1,l=c>>1,u=-7,d=n?o-1:0,h=n?-1:1,f=e[t+d];for(d+=h,s=f&(1<<-u)-1,f>>=-u,u+=a;u>0;s=256*s+e[t+d],d+=h,u-=8);for(i=s&(1<<-u)-1,s>>=-u,u+=r;u>0;i=256*i+e[t+d],d+=h,u-=8);if(0===s)s=1-l;else{if(s===c)return i?NaN:1/0*(f?-1:1);i+=Math.pow(2,r),s-=l}return(f?-1:1)*i*Math.pow(2,s-r)},n.write=function(e,t,n,r,o,s){var i,a,c,l=8*s-o-1,u=(1<<l)-1,d=u>>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,f=r?0:s-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,i=u):(i=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-i))<1&&(i--,c*=2),(t+=i+d>=1?h/c:h*Math.pow(2,1-d))*c>=2&&(i++,c/=2),i+d>=u?(a=0,i=u):i+d>=1?(a=(t*c-1)*Math.pow(2,o),i+=d):(a=t*Math.pow(2,d-1)*Math.pow(2,o),i=0));o>=8;e[n+f]=255&a,f+=p,a/=256,o-=8);for(i=i<<o|a,l+=o;l>0;e[n+f]=255&i,f+=p,i/=256,l-=8);e[n+f-p]|=128*g}},{}],24:[function(e,t,n){"function"==typeof Object.create?t.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:t.exports=function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}},{}],25:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function e(e,t){this.color=!0,this.key=void 0,this.value=void 0,this.parent=void 0,this.brother=void 0,this.leftChild=void 0,this.rightChild=void 0,this.key=e,this.value=t}return e.prototype.rotateLeft=function(){var e=this.parent,t=this.brother,n=this.leftChild,r=this.rightChild;if(!r)throw new Error("unknown error");var o=r.leftChild,s=r.rightChild;return e&&(e.leftChild===this?e.leftChild=r:e.rightChild===this&&(e.rightChild=r)),r.parent=e,r.brother=t,r.leftChild=this,r.rightChild=s,t&&(t.brother=r),this.parent=r,this.brother=s,this.leftChild=n,this.rightChild=o,s&&(s.parent=r,s.brother=this),n&&(n.parent=this,n.brother=o),o&&(o.parent=this,o.brother=n),r},e.prototype.rotateRight=function(){var e=this.parent,t=this.brother,n=this.leftChild;if(!n)throw new Error("unknown error");var r=this.rightChild,o=n.leftChild,s=n.rightChild;return e&&(e.leftChild===this?e.leftChild=n:e.rightChild===this&&(e.rightChild=n)),n.parent=e,n.brother=t,n.leftChild=o,n.rightChild=this,t&&(t.brother=n),o&&(o.parent=n,o.brother=this),this.parent=n,this.brother=o,this.leftChild=s,this.rightChild=r,s&&(s.parent=this,s.brother=r),r&&(r.parent=this,r.brother=s),n},e.prototype.remove=function(){if(this.leftChild||this.rightChild)throw new Error("can only remove leaf node");this.parent&&(this===this.parent.leftChild?this.parent.leftChild=void 0:this===this.parent.rightChild&&(this.parent.rightChild=void 0)),this.brother&&(this.brother.brother=void 0),this.key=void 0,this.value=void 0,this.parent=void 0,this.brother=void 0},e.TreeNodeColorType={red:!0,black:!1},e}();Object.freeze(r),n.default=r},{}],26:[function(e,t,n){var r=this&&this.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(e){return function(t){return c([e,t])}}function c(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};function o(e){var t=this;void 0===e&&(e=[]);var n=[],s=0,i=0,a=0,c=0,l=0,u=0;this.size=function(){return u},this.empty=function(){return 0===u},this.clear=function(){s=a=i=c=l=u=0,h.call(this,o.bucketSize),u=0},this.front=function(){return n[s][i]},this.back=function(){return n[a][c]},this.forEach=function(e){if(!this.empty()){var t=0;if(s!==a){for(l=i;l<o.bucketSize;++l)e(n[s][l],t++);for(l=s+1;l<a;++l)for(var r=0;r<o.bucketSize;++r)e(n[l][r],t++);for(l=0;l<=c;++l)e(n[a][l],t++)}else for(var l=i;l<=c;++l)e(n[s][l],t++)}};var d=function(e){var t=s*o.bucketSize+i,n=t+e,r=a*o.bucketSize+c;if(n<t||n>r)throw new Error("pos should more than 0 and less than queue's size");return{curNodeBucketIndex:Math.floor(n/o.bucketSize),curNodePointerIndex:n%o.bucketSize}};this.getElementByPos=function(e){var t=d(e),r=t.curNodeBucketIndex,o=t.curNodePointerIndex;return n[r][o]},this.eraseElementByPos=function(e){var t=this;if(e<0||e>u)throw new Error("pos should more than 0 and less than queue's size");if(0===e)this.popFront();else if(e===this.size())this.popBack();else{for(var n=[],r=e+1;r<u;++r)n.push(this.getElementByPos(r));this.cut(e),this.popBack(),n.forEach((function(e){return t.pushBack(e)}))}},this.eraseElementByValue=function(e){if(!this.empty()){var t=[];this.forEach((function(n){n!==e&&t.push(n)}));for(var n=t.length,r=0;r<n;++r)this.setElementByPos(r,t[r]);this.cut(n-1)}};var h=function(e){for(var t=[],r=e*o.sigma,d=Math.max(Math.ceil(r/o.bucketSize),2),h=0;h<d;++h)t.push(new Array(o.bucketSize));var f=Math.ceil(e/o.bucketSize),p=Math.floor(d/2)-Math.floor(f/2),g=p,m=0;if(this.size())for(h=0;h<f;++h){for(var y=0;y<o.bucketSize;++y)if(t[p+h][y]=this.front(),this.popFront(),this.empty()){g=p+h,m=y;break}if(this.empty())break}n=t,s=p,i=0,a=g,c=m,l=d,u=e};this.pushBack=function(e){this.empty()||(a===l-1&&c===o.bucketSize-1&&h.call(this,this.size()),c<o.bucketSize-1?++c:a<l-1&&(++a,c=0)),++u,n[a][c]=e},this.popBack=function(){this.empty()||(1!==this.size()&&(c>0?--c:s<a&&(--a,c=o.bucketSize-1)),u>0&&--u)},this.setElementByPos=function(e,t){var r=d(e),o=r.curNodeBucketIndex,s=r.curNodePointerIndex;n[o][s]=t},this.insert=function(e,t,n){var r=this;if(void 0===n&&(n=1),0===e)for(;n--;)this.pushFront(t);else if(e===this.size())for(;n--;)this.pushBack(t);else{for(var o=[],s=e;s<u;++s)o.push(this.getElementByPos(s));for(this.cut(e-1),s=0;s<n;++s)this.pushBack(t);o.forEach((function(e){return r.pushBack(e)}))}},this.find=function(e){if(s===a){for(var t=i;t<=c;++t)if(n[s][t]===e)return!0;return!1}for(t=i;t<o.bucketSize;++t)if(n[s][t]===e)return!0;for(t=s+1;t<a;++t)for(var r=0;r<o.bucketSize;++r)if(n[t][r]===e)return!0;for(t=0;t<=c;++t)if(n[a][t]===e)return!0;return!1},this.reverse=function(){for(var e=0,t=u-1;e<t;){var n=this.getElementByPos(e);this.setElementByPos(e,this.getElementByPos(t)),this.setElementByPos(t,n),++e,--t}},this.unique=function(){if(!this.empty()){var e=[],t=this.front();this.forEach((function(n,r){0!==r&&n===t||(e.push(n),t=n)}));for(var n=0;n<u;++n)this.setElementByPos(n,e[n]);this.cut(e.length-1)}},this.sort=function(e){var t=[];this.forEach((function(e){t.push(e)})),t.sort(e);for(var n=0;n<u;++n)this.setElementByPos(n,t[n])},this.pushFront=function(e){this.empty()||(0===s&&0===i&&h.call(this,this.size()),i>0?--i:s>0&&(--s,i=o.bucketSize-1)),++u,n[s][i]=e},this.popFront=function(){this.empty()||(1!==this.size()&&(i<o.bucketSize-1?++i:s<a&&(++s,i=0)),u>0&&--u)},this.shrinkToFit=function(){var e=this,t=[];this.forEach((function(e){t.push(e)}));var r=t.length;n=[];for(var s=Math.ceil(r/o.bucketSize),i=0;i<s;++i)n.push(new Array(o.bucketSize));this.clear(),t.forEach((function(t){return e.pushBack(t)}))},this.cut=function(e){if(e<0)this.clear();else{var t=d(e),n=t.curNodeBucketIndex,r=t.curNodePointerIndex;a=n,c=r,u=e+1}},this[Symbol.iterator]=function(){return function(){var e,t;return r(this,(function(r){switch(r.label){case 0:if(0===u)return[2];if(s!==a)return[3,5];t=i,r.label=1;case 1:return t<=c?[4,n[s][t]]:[3,4];case 2:r.sent(),r.label=3;case 3:return++t,[3,1];case 4:return[2];case 5:t=i,r.label=6;case 6:return t<o.bucketSize?[4,n[s][t]]:[3,9];case 7:r.sent(),r.label=8;case 8:return++t,[3,6];case 9:t=s+1,r.label=10;case 10:if(!(t<a))return[3,15];e=0,r.label=11;case 11:return e<o.bucketSize?[4,n[t][e]]:[3,14];case 12:r.sent(),r.label=13;case 13:return++e,[3,11];case 14:return++t,[3,10];case 15:t=0,r.label=16;case 16:return t<=c?[4,n[a][t]]:[3,19];case 17:r.sent(),r.label=18;case 18:return++t,[3,16];case 19:return[2]}}))}()},function(){var r=o.bucketSize;e.size?r=e.size():e.length&&(r=e.length);var i=r*o.sigma;l=Math.ceil(i/o.bucketSize),l=Math.max(l,3);for(var c=0;c<l;++c)n.push(new Array(o.bucketSize));var u=Math.ceil(r/o.bucketSize);s=Math.floor(l/2)-Math.floor(u/2),a=s,e.forEach((function(e){return t.pushBack(e)}))}(),Object.freeze(this)}Object.defineProperty(n,"__esModule",{value:!0}),o.sigma=3,o.bucketSize=5e3,Object.freeze(o),n.default=o},{}],27:[function(e,t,n){var r=this&&this.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(e){return function(t){return c([e,t])}}function c(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},o=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(n,"__esModule",{value:!0});var s=e("../LinkList/LinkList"),i=e("../Map/Map");function a(e,t,n){var c=this;if(void 0===e&&(e=[]),void 0===t&&(t=a.initSize),n=n||function(e){var t,n,r=0,s="";if("number"==typeof e)r=((r=Math.floor(e))<<5)-r,r&=r;else{s="string"!=typeof e?JSON.stringify(e):e;try{for(var i=o(s),a=i.next();!a.done;a=i.next())r=(r<<5)-r+a.value.charCodeAt(0),r&=r}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}}return r^=r>>>16},0!=(t&t-1))throw new Error("initBucketNum must be 2 to the power of n");var l=0,u=[],d=Math.max(a.initSize,Math.min(a.maxSize,t));this.size=function(){return l},this.empty=function(){return 0===l},this.clear=function(){l=0,d=t,u=[]},this.forEach=function(e){var t=0;u.forEach((function(n){n.forEach((function(n){e(n,t++)}))}))};var h=function(e){if(!(e>=a.maxSize)){d=2*e;var t=[];u.forEach((function(r,o){if(!r.empty()){if(r instanceof s.default&&1===r.size()){var c=r.front(),l=c.key,h=c.value;t[n(l)&d-1]=new s.default([{key:l,value:h}])}else if(r instanceof i.default){var f=new s.default,p=new s.default;r.forEach((function(t){0==(n(t.key)&e)?f.pushBack(t):p.pushBack(t)})),f.size()>a.untreeifyThreshold?t[o]=new i.default(f):f.size()&&(t[o]=f),p.size()>a.untreeifyThreshold?t[o+e]=new i.default(p):p.size()&&(t[o+e]=p)}else{var g=new s.default,m=new s.default;r.forEach((function(t){0==(n(t.key)&e)?g.pushBack(t):m.pushBack(t)})),g.size()&&(t[o]=g),m.size()&&(t[o+e]=m)}u[o].clear()}})),u=t}};this.setElement=function(e,t){var r,c;if(null==e)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(null!=t){var f=n(e)&d-1;if(u[f]){var p=u[f].size();if(u[f]instanceof s.default){try{for(var g=o(u[f]),m=g.next();!m.done;m=g.next()){var y=m.value;if(y.key===e)return void(y.value=t)}}catch(e){r={error:e}}finally{try{m&&!m.done&&(c=g.return)&&c.call(g)}finally{if(r)throw r.error}}u[f].pushBack({key:e,value:t}),u[f].size()>=a.treeifyThreshold&&(u[f]=new i.default(u[f]))}else u[f].setElement(e,t);var v=u[f].size();l+=v-p}else++l,u[f]=new s.default([{key:e,value:t}]);l>d*a.sigma&&h.call(this,d)}else this.eraseElementByKey(e)},this.getElementByKey=function(e){var t,r,s=n(e)&d-1;if(u[s]){if(u[s]instanceof i.default)return u[s].getElementByKey(e);try{for(var a=o(u[s]),c=a.next();!c.done;c=a.next()){var l=c.value;if(l.key===e)return l.value}}catch(e){t={error:e}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}}},this.eraseElementByKey=function(e){var t,r,c=n(e)&d-1;if(u[c]){var h=u[c].size();if(u[c]instanceof i.default)u[c].eraseElementByKey(e),u[c].size()<=a.untreeifyThreshold&&(u[c]=new s.default(u[c]));else{var f=-1;try{for(var p=o(u[c]),g=p.next();!g.done;g=p.next()){var m=g.value;if(++f,m.key===e){u[c].eraseElementByPos(f);break}}}catch(e){t={error:e}}finally{try{g&&!g.done&&(r=p.return)&&r.call(p)}finally{if(t)throw t.error}}}var y=u[c].size();l+=y-h}},this.find=function(e){var t,r,s=n(e)&d-1;if(!u[s])return!1;if(u[s]instanceof i.default)return u[s].find(e);try{for(var a=o(u[s]),c=a.next();!c.done;c=a.next())if(c.value.key===e)return!0}catch(e){t={error:e}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return!1},this[Symbol.iterator]=function(){return function(){var e,t,n,s,i,a;return r(this,(function(r){switch(r.label){case 0:e=0,r.label=1;case 1:if(!(e<d))return[3,10];for(;e<d&&!u[e];)++e;if(e>=d)return[3,10];r.label=2;case 2:r.trys.push([2,7,8,9]),i=void 0,t=o(u[e]),n=t.next(),r.label=3;case 3:return n.done?[3,6]:[4,n.value];case 4:r.sent(),r.label=5;case 5:return n=t.next(),[3,3];case 6:return[3,9];case 7:return s=r.sent(),i={error:s},[3,9];case 8:try{n&&!n.done&&(a=t.return)&&a.call(t)}finally{if(i)throw i.error}return[7];case 9:return++e,[3,1];case 10:return[2]}}))}()},e.forEach((function(e){var t=e.key,n=e.value;return c.setElement(t,n)})),Object.freeze(this)}a.initSize=16,a.maxSize=1<<30,a.sigma=.75,a.treeifyThreshold=8,a.untreeifyThreshold=6,a.minTreeifySize=64,Object.freeze(a),n.default=a},{"../LinkList/LinkList":29,"../Map/Map":30}],28:[function(e,t,n){var r=this&&this.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(e){return function(t){return c([e,t])}}function c(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},o=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(n,"__esModule",{value:!0});var s=e("../Set/Set"),i=e("../LinkList/LinkList");function a(e,t,n){var c=this;if(void 0===e&&(e=[]),void 0===t&&(t=a.initSize),n=n||function(e){var t=0,n="";if("number"==typeof e)t=((t=Math.floor(e))<<5)-t,t&=t;else{n="string"!=typeof e?JSON.stringify(e):e;for(var r=0;r<n.length;r++)t=(t<<5)-t+n.charCodeAt(r),t&=t}return t^=t>>>16},0!=(t&t-1))throw new Error("initBucketNum must be 2 to the power of n");var l=0,u=[],d=Math.max(a.initSize,Math.min(a.maxSize,t));this.size=function(){return l},this.empty=function(){return 0===l},this.clear=function(){l=0,d=t,u=[]},this.forEach=function(e){var t=0;u.forEach((function(n){n.forEach((function(n){e(n,t++)}))}))};var h=function(e){if(!(e>=a.maxSize)){d=2*e;var t=[];u.forEach((function(r,o){if(!r.empty()){if(r instanceof i.default&&1===r.size()){var c=r.front();if(void 0===c)throw new Error("unknown error");t[n(c)&d-1]=new i.default([c])}else if(r instanceof s.default){var l=new i.default,h=new i.default;r.forEach((function(t){0==(n(t)&e)?l.pushBack(t):h.pushBack(t)})),l.size()>a.untreeifyThreshold?t[o]=new s.default(l):l.size()&&(t[o]=l),h.size()>a.untreeifyThreshold?t[o+e]=new s.default(h):h.size()&&(t[o+e]=h)}else{var f=new i.default,p=new i.default;r.forEach((function(t){0==(n(t)&e)?f.pushBack(t):p.pushBack(t)})),f.size()&&(t[o]=f),p.size()&&(t[o+e]=p)}u[o].clear()}})),u=t}};this.insert=function(e){if(null==e)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");var t=n(e)&d-1;if(u[t]){var r=u[t].size();if(u[t]instanceof i.default){if(u[t].find(e))return;u[t].pushBack(e),u[t].size()>=a.treeifyThreshold&&(u[t]=new s.default(u[t]))}else u[t].insert(e);var o=u[t].size();l+=o-r}else u[t]=new i.default([e]),++l;l>d*a.sigma&&h.call(this,d)},this.eraseElementByValue=function(e){var t=n(e)&d-1;if(u[t]){var r=u[t].size();u[t].eraseElementByValue(e),u[t]instanceof s.default&&u[t].size()<=a.untreeifyThreshold&&(u[t]=new i.default(u[t]));var o=u[t].size();l+=o-r}},this.find=function(e){var t=n(e)&d-1;return!!u[t]&&u[t].find(e)},this[Symbol.iterator]=function(){return function(){var e,t,n,s,i,a;return r(this,(function(r){switch(r.label){case 0:e=0,r.label=1;case 1:if(!(e<d))return[3,10];for(;e<d&&!u[e];)++e;if(e>=d)return[3,10];r.label=2;case 2:r.trys.push([2,7,8,9]),i=void 0,t=o(u[e]),n=t.next(),r.label=3;case 3:return n.done?[3,6]:[4,n.value];case 4:r.sent(),r.label=5;case 5:return n=t.next(),[3,3];case 6:return[3,9];case 7:return s=r.sent(),i={error:s},[3,9];case 8:try{n&&!n.done&&(a=t.return)&&a.call(t)}finally{if(i)throw i.error}return[7];case 9:return++e,[3,1];case 10:return[2]}}))}()},e.forEach((function(e){return c.insert(e)})),Object.freeze(this)}a.initSize=16,a.maxSize=1<<30,a.sigma=.75,a.treeifyThreshold=8,a.untreeifyThreshold=6,a.minTreeifySize=64,Object.freeze(a),n.default=a},{"../LinkList/LinkList":29,"../Set/Set":33}],29:[function(e,t,n){var r=this&&this.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(e){return function(t){return c([e,t])}}function c(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(n,"__esModule",{value:!0});var o=function(){function e(e){this.value=void 0,this.pre=void 0,this.next=void 0,this.value=e}return e}();function s(e){var t=this;void 0===e&&(e=[]);var n=0,s=void 0,i=void 0;this.size=function(){return n},this.empty=function(){return 0===n},this.clear=function(){s=i=void 0,n=0},this.front=function(){return null==s?void 0:s.value},this.back=function(){return null==i?void 0:i.value},this.forEach=function(e){for(var t=s,n=0;t;){if(void 0===t.value)throw new Error("unknown error");e(t.value,n++),t=t.next}},this.getElementByPos=function(e){if(e<0||e>=n)throw new Error("pos must more then 0 and less then the list length");for(var t=s;e--&&t;)t=t.next;if(!t||void 0===t.value)throw new Error("unknown error");return t.value},this.eraseElementByPos=function(e){if(e<0||e>=n)throw new Error("erase pos must more then 0 and less then the list length");if(0===e)this.popFront();else if(e===n-1)this.popBack();else{for(var t=s;e--;){if(!(null==t?void 0:t.next))throw new Error("unknown error");t=t.next}if(!t||!t.pre||!t.next)throw new Error("unknown error");var r=t.pre,o=t.next;o.pre=r,r.next=o,n>0&&--n}},this.eraseElementByValue=function(e){for(;s&&s.value===e;)this.popFront();for(;i&&i.value===e;)this.popBack();if(s)for(var t=s;t;){if(t.value===e){var r=t.pre,o=t.next;o&&(o.pre=r),r&&(r.next=o),n>0&&--n}t=t.next}},this.pushBack=function(e){if(null==e)throw new Error("you can't push null or undefined here");++n;var t=new o(e);i?(i.next=t,t.pre=i,i=t):s=i=t},this.popBack=function(){i&&(n>0&&--n,i&&(s===i?s=i=void 0:(i=i.pre)&&(i.next=void 0)))},this.setElementByPos=function(e,t){if(null==t)throw new Error("you can't set null or undefined here");if(e<0||e>=n)throw new Error("pos must more then 0 and less then the list length");for(var r=s;e--;){if(!r)throw new Error("unknown error");r=r.next}r&&(r.value=t)},this.insert=function(e,t,r){if(void 0===r&&(r=1),null==t)throw new Error("you can't insert null or undefined here");if(e<0||e>n)throw new Error("insert pos must more then 0 and less then or equal to the list length");if(r<0)throw new Error("insert size must more than 0");if(0===e)for(;r--;)this.pushFront(t);else if(e===n)for(;r--;)this.pushBack(t);else{for(var i=s,a=1;a<e;++a){if(!(null==i?void 0:i.next))throw new Error("unknown error");i=null==i?void 0:i.next}if(!i)throw new Error("unknown error");var c=i.next;for(n+=r;r--;)i.next=new o(t),i.next.pre=i,i=i.next;i.next=c,c&&(c.pre=i)}},this.find=function(e){for(var t=s;t;){if(t.value===e)return!0;t=t.next}return!1},this.reverse=function(){for(var e=s,t=i,r=0;e&&t&&2*r<n;){var o=e.value;e.value=t.value,t.value=o,e=e.next,t=t.pre,++r}},this.unique=function(){for(var e=s;e;){for(var t=e;t&&t.next&&t.value===t.next.value;)t=t.next,n>0&&--n;e.next=t.next,e.next&&(e.next.pre=e),e=e.next}},this.sort=function(e){var t=[];this.forEach((function(e){t.push(e)})),t.sort(e);var n=s;t.forEach((function(e){n&&(n.value=e,n=n.next)}))},this.pushFront=function(e){if(null==e)throw new Error("you can't push null or undefined here");++n;var t=new o(e);s?(t.next=s,s.pre=t,s=t):s=i=t},this.popFront=function(){s&&(n>0&&--n,s&&(s===i?s=i=void 0:(s=s.next)&&(s.pre=void 0)))},this.merge=function(e){var t=this,r=s;e.forEach((function(e){for(;r&&void 0!==r.value&&r.value<=e;)r=r.next;if(void 0===r)t.pushBack(e),r=i;else if(r===s)t.pushFront(e),r=s;else{++n;var a=r.pre;a&&(a.next=new o(e),a.next.pre=a,a.next.next=r,r&&(r.pre=a.next))}}))},this[Symbol.iterator]=function(){return function(){var e;return r(this,(function(t){switch(t.label){case 0:e=s,t.label=1;case 1:if(void 0===e)return[3,3];if(!e.value)throw new Error("unknown error");return[4,e.value];case 2:return t.sent(),e=e.next,[3,1];case 3:return[2]}}))}()},e.forEach((function(e){return t.pushBack(e)})),Object.freeze(this)}Object.freeze(s),n.default=s},{}],30:[function(e,t,n){var r=this&&this.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(e){return function(t){return c([e,t])}}function c(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},o=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(n,"__esModule",{value:!0});var s=e("../Base/TreeNode");function i(e,t){var n=this;void 0===e&&(e=[]),t=t||function(e,t){return e<t?-1:e>t?1:0};var i=0,a=new s.default;a.color=s.default.TreeNodeColorType.black,this.size=function(){return i},this.empty=function(){return 0===i},this.clear=function(){i=0,a.key=a.value=void 0,a.leftChild=a.rightChild=a.brother=void 0};var c=function(e){if(!e||void 0===e.key)throw new Error("unknown error");return e.leftChild?c(e.leftChild):e},l=function(e){if(!e||void 0===e.key)throw new Error("unknown error");return e.rightChild?l(e.rightChild):e};this.front=function(){if(!this.empty()){var e=c(a);if(void 0===e.key||void 0===e.value)throw new Error("unknown error");return{key:e.key,value:e.value}}},this.back=function(){if(!this.empty()){var e=l(a);if(void 0===e.key||void 0===e.value)throw new Error("unknown error");return{key:e.key,value:e.value}}},this.forEach=function(e){var t,n,r=0;try{for(var s=o(this),i=s.next();!i.done;i=s.next())e(i.value,r++)}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}},this.getElementByPos=function(e){var t,n;if(e<0||e>=this.size())throw new Error("pos must more than 0 and less than set's size");var r=0;try{for(var s=o(this),i=s.next();!i.done;i=s.next()){var a=i.value;if(r===e)return a;++r}}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}throw new Error("unknown Error")};var u=function(e,n){if(e&&void 0!==e.key&&void 0!==e.value){var r=t(e.key,n);return 0===r?{key:e.key,value:e.value}:r<0?u(e.rightChild,n):u(e.leftChild,n)||{key:e.key,value:e.value}}};this.lowerBound=function(e){return u(a,e)};var d=function(e,n){if(e&&void 0!==e.key&&void 0!==e.value)return t(e.key,n)<=0?d(e.rightChild,n):d(e.leftChild,n)||{key:e.key,value:e.value}};this.upperBound=function(e){return d(a,e)};var h=function(e,n){if(e&&void 0!==e.key&&void 0!==e.value){var r=t(e.key,n);return 0===r?{key:e.key,value:e.value}:r>0?h(e.leftChild,n):h(e.rightChild,n)||{key:e.key,value:e.value}}};this.reverseLowerBound=function(e){return h(a,e)};var f=function(e,n){if(e&&void 0!==e.key&&void 0!==e.value)return t(e.key,n)>=0?f(e.leftChild,n):f(e.rightChild,n)||{key:e.key,value:e.value}};this.reverseUpperBound=function(e){return f(a,e)};var p=function(e){var t=e.parent;if(!t){if(e===a)return;throw new Error("unknown error")}if(e.color!==s.default.TreeNodeColorType.red){var n=e.brother;if(!n)throw new Error("unknown error");if(e===t.leftChild)if(n.color===s.default.TreeNodeColorType.red){n.color=s.default.TreeNodeColorType.black,t.color=s.default.TreeNodeColorType.red;var r=t.rotateLeft();a===t&&(a=r),p(e)}else n.color===s.default.TreeNodeColorType.black&&(n.rightChild&&n.rightChild.color===s.default.TreeNodeColorType.red?(n.color=t.color,t.color=s.default.TreeNodeColorType.black,n.rightChild&&(n.rightChild.color=s.default.TreeNodeColorType.black),r=t.rotateLeft(),a===t&&(a=r),e.color=s.default.TreeNodeColorType.black):n.rightChild&&n.rightChild.color!==s.default.TreeNodeColorType.black||!n.leftChild||n.leftChild.color!==s.default.TreeNodeColorType.red?n.leftChild&&n.leftChild.color!==s.default.TreeNodeColorType.black||n.rightChild&&n.rightChild.color!==s.default.TreeNodeColorType.black||(n.color=s.default.TreeNodeColorType.red,p(t)):(n.color=s.default.TreeNodeColorType.red,n.leftChild&&(n.leftChild.color=s.default.TreeNodeColorType.black),r=n.rotateRight(),a===n&&(a=r),p(e)));else e===t.rightChild&&(n.color===s.default.TreeNodeColorType.red?(n.color=s.default.TreeNodeColorType.black,t.color=s.default.TreeNodeColorType.red,r=t.rotateRight(),a===t&&(a=r),p(e)):n.color===s.default.TreeNodeColorType.black&&(n.leftChild&&n.leftChild.color===s.default.TreeNodeColorType.red?(n.color=t.color,t.color=s.default.TreeNodeColorType.black,n.leftChild&&(n.leftChild.color=s.default.TreeNodeColorType.black),r=t.rotateRight(),a===t&&(a=r),e.color=s.default.TreeNodeColorType.black):n.leftChild&&n.leftChild.color!==s.default.TreeNodeColorType.black||!n.rightChild||n.rightChild.color!==s.default.TreeNodeColorType.red?n.leftChild&&n.leftChild.color!==s.default.TreeNodeColorType.black||n.rightChild&&n.rightChild.color!==s.default.TreeNodeColorType.black||(n.color=s.default.TreeNodeColorType.red,p(t)):(n.color=s.default.TreeNodeColorType.red,n.rightChild&&(n.rightChild.color=s.default.TreeNodeColorType.black),r=n.rotateLeft(),a===n&&(a=r),p(e))))}else e.color=s.default.TreeNodeColorType.black},g=function(e){for(var t=e;t.leftChild||t.rightChild;){if(t.rightChild){t=c(t.rightChild);var n=e.key;e.key=t.key,t.key=n;var r=e.value;e.value=t.value,t.value=r,e=t}t.leftChild&&(t=l(t.leftChild),n=e.key,e.key=t.key,t.key=n,r=e.value,e.value=t.value,t.value=r,e=t)}p(t),t&&t.remove(),--i,a.color=s.default.TreeNodeColorType.black},m=function(e,t){return!(!e||void 0===e.key)&&(!!m(e.leftChild,t)||!!t(e)||m(e.rightChild,t))};this.eraseElementByPos=function(e){if(e<0||e>=i)throw new Error("pos must more than 0 and less than set's size");var t=0;m(a,(function(n){return e===t?(g(n),!0):(++t,!1)}))},this.eraseElementByKey=function(e){if(!this.empty()){var n=b(a,e);void 0!==n&&void 0!==n.key&&0===t(n.key,e)&&g(n)}};var y=function(e,n){if(!e||void 0===e.key)throw new Error("unknown error");var r=t(n,e.key);return r<0?e.leftChild?y(e.leftChild,n):(e.leftChild=new s.default,e.leftChild.parent=e,e.leftChild.brother=e.rightChild,e.rightChild&&(e.rightChild.brother=e.leftChild),e.leftChild):r>0?e.rightChild?y(e.rightChild,n):(e.rightChild=new s.default,e.rightChild.parent=e,e.rightChild.brother=e.leftChild,e.leftChild&&(e.leftChild.brother=e.rightChild),e.rightChild):e},v=function(e){var t=e.parent;if(!t){if(e===a)return;throw new Error("unknown error")}if(t.color!==s.default.TreeNodeColorType.black&&t.color===s.default.TreeNodeColorType.red){var n=t.brother,r=t.parent;if(!r)throw new Error("unknown error");if(n&&n.color===s.default.TreeNodeColorType.red)n.color=t.color=s.default.TreeNodeColorType.black,r.color=s.default.TreeNodeColorType.red,v(r);else if(!n||n.color===s.default.TreeNodeColorType.black)if(t===r.leftChild)if(e===t.leftChild){t.color=s.default.TreeNodeColorType.black,r.color=s.default.TreeNodeColorType.red;var o=r.rotateRight();r===a&&(a=o)}else e===t.rightChild&&(o=t.rotateLeft(),r===a&&(a=o),v(t));else t===r.rightChild&&(e===t.leftChild?(o=t.rotateRight(),r===a&&(a=o),v(t)):e===t.rightChild&&(t.color=s.default.TreeNodeColorType.black,r.color=s.default.TreeNodeColorType.red,o=r.rotateLeft(),r===a&&(a=o)))}};this.setElement=function(e,n){if(null==e)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(null!=n){if(this.empty())return++i,a.key=e,a.value=n,void(a.color=s.default.TreeNodeColorType.black);var r=y(a,e);void 0===r.key||0!==t(r.key,e)?(++i,r.key=e,r.value=n,v(r),a.color=s.default.TreeNodeColorType.black):r.value=n}else this.eraseElementByKey(e)};var b=function(e,n){if(e&&void 0!==e.key){var r=t(n,e.key);return r<0?b(e.leftChild,n):r>0?b(e.rightChild,n):e}};this.find=function(e){return!!b(a,e)},this.getElementByKey=function(e){var t=b(a,e);if(void 0===(null==t?void 0:t.key)||void 0===(null==t?void 0:t.value))throw new Error("unknown error");return t.value},this.union=function(e){var t=this;e.forEach((function(e){var n=e.key,r=e.value;return t.setElement(n,r)}))},this.getHeight=function(){if(this.empty())return 0;var e=function(t){return t?Math.max(e(t.leftChild),e(t.rightChild))+1:1};return e(a)};var w=function(e){return r(this,(function(t){switch(t.label){case 0:return e&&void 0!==e.key&&void 0!==e.value?[5,o(w(e.leftChild))]:[2];case 1:return t.sent(),[4,{key:e.key,value:e.value}];case 2:return t.sent(),[5,o(w(e.rightChild))];case 3:return t.sent(),[2]}}))};this[Symbol.iterator]=function(){return w(a)},e.forEach((function(e){var t=e.key,r=e.value;return n.setElement(t,r)})),Object.freeze(this)}Object.freeze(i),n.default=i},{"../Base/TreeNode":25}],31:[function(e,t,n){function r(e,t){void 0===e&&(e=[]),t=t||function(e,t){return e>t?-1:e<t?1:0};var n=[];e.forEach((function(e){return n.push(e)}));var r=n.length,o=function(e,t){if(e<0||e>=r)throw new Error("unknown error");if(t<0||t>=r)throw new Error("unknown error");var o=n[e];n[e]=n[t],n[t]=o},s=function(e){if(e<0||e>=r)throw new Error("unknown error");var s=2*e+1,i=2*e+2;s<r&&t(n[e],n[s])>0&&o(e,s),i<r&&t(n[e],n[i])>0&&o(e,i)};!function(){for(var e=Math.floor((r-1)/2);e>=0;--e)for(var s=e,i=2*s+1;i<r;){var a=i+1,c=i;if(a<r&&t(n[i],n[a])>0&&(c=a),t(n[s],n[c])<=0)break;o(s,c),i=2*(s=c)+1}}(),this.size=function(){return r},this.empty=function(){return 0===r},this.clear=function(){r=0,n.length=0},this.push=function(e){if(n.push(e),1!=++r)for(var o=r-1;o>0;){var i=Math.floor((o-1)/2);if(t(n[i],e)<=0)break;s(i),o=i}},this.pop=function(){if(!this.empty())if(1!==this.size()){var e=n[r-1];--r;for(var o=0;o<this.size();){var s=2*o+1,i=2*o+2;if(s>=this.size())break;var a=s;if(i<this.size()&&t(n[s],n[i])>0&&(a=i),t(n[a],e)>=0)break;n[o]=n[a],o=a}n[o]=e}else--r},this.top=function(){return n[0]},Object.freeze(this)}Object.defineProperty(n,"__esModule",{value:!0}),Object.freeze(r),n.default=r},{}],32:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var r=e("../LinkList/LinkList");function o(e){void 0===e&&(e=[]);var t=new r.default(e);this.size=function(){return t.size()},this.empty=function(){return t.empty()},this.clear=function(){t.clear()},this.push=function(e){t.pushBack(e)},this.pop=function(){t.popFront()},this.front=function(){return t.front()},Object.freeze(this)}Object.freeze(o),n.default=o},{"../LinkList/LinkList":29}],33:[function(e,t,n){var r=this&&this.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(e){return function(t){return c([e,t])}}function c(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},o=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(n,"__esModule",{value:!0});var s=e("../Base/TreeNode");function i(e,t){var n=this;void 0===e&&(e=[]),t=t||function(e,t){return e<t?-1:e>t?1:0};var i=0,a=new s.default;a.color=s.default.TreeNodeColorType.black,this.size=function(){return i},this.empty=function(){return 0===i},this.clear=function(){i=0,a.key=void 0,a.leftChild=a.rightChild=a.brother=a.parent=void 0,a.color=s.default.TreeNodeColorType.black};var c=function(e){if(!e||void 0===e.key)throw new Error("unknown error");return e.leftChild?c(e.leftChild):e},l=function(e){if(!e||void 0===e.key)throw new Error("unknown error");return e.rightChild?l(e.rightChild):e};this.front=function(){if(!this.empty())return c(a).key},this.back=function(){if(!this.empty())return l(a).key},this.forEach=function(e){var t,n,r=0;try{for(var s=o(this),i=s.next();!i.done;i=s.next())e(i.value,r++)}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}},this.getElementByPos=function(e){var t,n;if(e<0||e>=this.size())throw new Error("pos must more than 0 and less than set's size");var r=0;try{for(var s=o(this),i=s.next();!i.done;i=s.next()){var a=i.value;if(r===e)return a;++r}}catch(e){t={error:e}}finally{try{i&&!i.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}throw new Error("unknown error")};var u=function(e){var t=e.parent;if(!t){if(e===a)return;throw new Error("unknown error")}if(e.color!==s.default.TreeNodeColorType.red){var n=e.brother;if(!n)throw new Error("unknown error");if(e===t.leftChild)if(n.color===s.default.TreeNodeColorType.red){n.color=s.default.TreeNodeColorType.black,t.color=s.default.TreeNodeColorType.red;var r=t.rotateLeft();a===t&&(a=r),u(e)}else n.color===s.default.TreeNodeColorType.black&&(n.rightChild&&n.rightChild.color===s.default.TreeNodeColorType.red?(n.color=t.color,t.color=s.default.TreeNodeColorType.black,n.rightChild&&(n.rightChild.color=s.default.TreeNodeColorType.black),r=t.rotateLeft(),a===t&&(a=r),e.color=s.default.TreeNodeColorType.black):n.rightChild&&n.rightChild.color!==s.default.TreeNodeColorType.black||!n.leftChild||n.leftChild.color!==s.default.TreeNodeColorType.red?n.leftChild&&n.leftChild.color!==s.default.TreeNodeColorType.black||n.rightChild&&n.rightChild.color!==s.default.TreeNodeColorType.black||(n.color=s.default.TreeNodeColorType.red,u(t)):(n.color=s.default.TreeNodeColorType.red,n.leftChild&&(n.leftChild.color=s.default.TreeNodeColorType.black),r=n.rotateRight(),a===n&&(a=r),u(e)));else e===t.rightChild&&(n.color===s.default.TreeNodeColorType.red?(n.color=s.default.TreeNodeColorType.black,t.color=s.default.TreeNodeColorType.red,r=t.rotateRight(),a===t&&(a=r),u(e)):n.color===s.default.TreeNodeColorType.black&&(n.leftChild&&n.leftChild.color===s.default.TreeNodeColorType.red?(n.color=t.color,t.color=s.default.TreeNodeColorType.black,n.leftChild&&(n.leftChild.color=s.default.TreeNodeColorType.black),r=t.rotateRight(),a===t&&(a=r),e.color=s.default.TreeNodeColorType.black):n.leftChild&&n.leftChild.color!==s.default.TreeNodeColorType.black||!n.rightChild||n.rightChild.color!==s.default.TreeNodeColorType.red?n.leftChild&&n.leftChild.color!==s.default.TreeNodeColorType.black||n.rightChild&&n.rightChild.color!==s.default.TreeNodeColorType.black||(n.color=s.default.TreeNodeColorType.red,u(t)):(n.color=s.default.TreeNodeColorType.red,n.rightChild&&(n.rightChild.color=s.default.TreeNodeColorType.black),r=n.rotateLeft(),a===n&&(a=r),u(e))))}else e.color=s.default.TreeNodeColorType.black},d=function(e){for(var t=e;t.leftChild||t.rightChild;){if(t.rightChild){t=c(t.rightChild);var n=e.key;e.key=t.key,t.key=n,e=t}t.leftChild&&(t=l(t.leftChild),n=e.key,e.key=t.key,t.key=n,e=t)}u(t),t&&t.remove(),--i,a.color=s.default.TreeNodeColorType.black},h=function(e,t){return!(!e||void 0===e.key)&&(!!h(e.leftChild,t)||!!t(e)||h(e.rightChild,t))};this.eraseElementByPos=function(e){if(e<0||e>=i)throw new Error("pos must more than 0 and less than set's size");var t=0;h(a,(function(n){return e===t?(d(n),!0):(++t,!1)}))},this.eraseElementByValue=function(e){if(!this.empty()){var n=g(a,e);void 0!==n&&void 0!==n.key&&0===t(n.key,e)&&d(n)}};var f=function(e,n){if(!e||void 0===e.key)throw new Error("unknown error");var r=t(n,e.key);return r<0?e.leftChild?f(e.leftChild,n):(e.leftChild=new s.default,e.leftChild.parent=e,e.leftChild.brother=e.rightChild,e.rightChild&&(e.rightChild.brother=e.leftChild),e.leftChild):r>0?e.rightChild?f(e.rightChild,n):(e.rightChild=new s.default,e.rightChild.parent=e,e.rightChild.brother=e.leftChild,e.leftChild&&(e.leftChild.brother=e.rightChild),e.rightChild):e},p=function(e){var t=e.parent;if(!t){if(e===a)return;throw new Error("unknown error")}if(t.color!==s.default.TreeNodeColorType.black&&t.color===s.default.TreeNodeColorType.red){var n=t.brother,r=t.parent;if(!r)throw new Error("unknown error");if(n&&n.color===s.default.TreeNodeColorType.red)n.color=t.color=s.default.TreeNodeColorType.black,r.color=s.default.TreeNodeColorType.red,p(r);else if(!n||n.color===s.default.TreeNodeColorType.black)if(t===r.leftChild)if(e===t.leftChild){t.color=s.default.TreeNodeColorType.black,r.color=s.default.TreeNodeColorType.red;var o=r.rotateRight();r===a&&(a=o)}else e===t.rightChild&&(o=t.rotateLeft(),r===a&&(a=o),p(t));else t===r.rightChild&&(e===t.leftChild?(o=t.rotateRight(),r===a&&(a=o),p(t)):e===t.rightChild&&(t.color=s.default.TreeNodeColorType.black,r.color=s.default.TreeNodeColorType.red,o=r.rotateLeft(),r===a&&(a=o)))}};this.insert=function(e){if(null==e)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(this.empty())return++i,a.key=e,void(a.color=s.default.TreeNodeColorType.black);var n=f(a,e);void 0!==n.key&&0===t(n.key,e)||(++i,n.key=e,p(n),a.color=s.default.TreeNodeColorType.black)};var g=function(e,n){if(e&&void 0!==e.key){var r=t(n,e.key);return r<0?g(e.leftChild,n):r>0?g(e.rightChild,n):e}};this.find=function(e){var n=g(a,e);return void 0!==n&&void 0!==n.key&&0===t(n.key,e)};var m=function(e,n){if(e&&void 0!==e.key){var r=t(e.key,n);if(0===r)return e.key;if(r<0)return m(e.rightChild,n);var o=m(e.leftChild,n);return void 0!==o?o:e.key}};this.lowerBound=function(e){return m(a,e)};var y=function(e,n){if(e&&void 0!==e.key){if(t(e.key,n)<=0)return y(e.rightChild,n);var r=y(e.leftChild,n);return void 0!==r?r:e.key}};this.upperBound=function(e){return y(a,e)};var v=function(e,n){if(e&&void 0!==e.key){var r=t(e.key,n);if(0===r)return e.key;if(r>0)return v(e.leftChild,n);var o=v(e.rightChild,n);return void 0!==o?o:e.key}};this.reverseLowerBound=function(e){return v(a,e)};var b=function(e,n){if(e&&void 0!==e.key){if(t(e.key,n)>=0)return b(e.leftChild,n);var r=b(e.rightChild,n);return void 0!==r?r:e.key}};this.reverseUpperBound=function(e){return b(a,e)},this.union=function(e){var t=this;e.forEach((function(e){return t.insert(e)}))},this.getHeight=function(){if(this.empty())return 0;var e=function(t){return t?Math.max(e(t.leftChild),e(t.rightChild))+1:1};return e(a)};var w=function(e){return r(this,(function(t){switch(t.label){case 0:return e&&void 0!==e.key?[5,o(w(e.leftChild))]:[2];case 1:return t.sent(),[4,e.key];case 2:return t.sent(),[5,o(w(e.rightChild))];case 3:return t.sent(),[2]}}))};this[Symbol.iterator]=function(){return w(a)},e.forEach((function(e){return n.insert(e)})),Object.freeze(this)}Object.freeze(i),n.default=i},{"../Base/TreeNode":25}],34:[function(e,t,n){function r(e){var t=this;void 0===e&&(e=[]);var n=0,r=[];this.size=function(){return n},this.empty=function(){return 0===n},this.clear=function(){n=0,r.length=0},this.push=function(e){r.push(e),++n},this.pop=function(){r.pop(),n>0&&--n},this.top=function(){return r[n-1]},e.forEach((function(e){return t.push(e)})),Object.freeze(this)}Object.defineProperty(n,"__esModule",{value:!0}),Object.freeze(r),n.default=r},{}],35:[function(e,t,n){var r=this&&this.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(e){return function(t){return c([e,t])}}function c(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}},o=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,s=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=s.next()).done;)i.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=s.return)&&n.call(s)}finally{if(o)throw o.error}}return i},s=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,o=0,s=t.length;o<s;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))},i=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};function a(e){var t=this;void 0===e&&(e=[]);var n=0,a=[];this.size=function(){return n},this.empty=function(){return 0===n},this.clear=function(){n=0,a.length=0},this.front=function(){if(!this.empty())return a[0]},this.back=function(){if(!this.empty())return a[n-1]},this.forEach=function(e){a.forEach(e)},this.getElementByPos=function(e){if(e<0||e>=n)throw new Error("pos must more than 0 and less than vector's size");return a[e]},this.eraseElementByPos=function(e){if(e<0||e>=n)throw new Error("pos must more than 0 and less than vector's size");for(var t=e;t<n-1;++t)a[t]=a[t+1];this.popBack()},this.eraseElementByValue=function(e){var t=[];this.forEach((function(n){n!==e&&t.push(n)})),t.forEach((function(e,t){a[t]=e}));for(var r=t.length;n>r;)this.popBack()},this.pushBack=function(e){a.push(e),++n},this.popBack=function(){a.pop(),n>0&&--n},this.setElementByPos=function(e,t){if(e<0||e>=n)throw new Error("pos must more than 0 and less than vector's size");a[e]=t},this.insert=function(e,t,r){if(void 0===r&&(r=1),e<0||e>n)throw new Error("pos must more than 0 and less than or equal to vector's size");a.splice.apply(a,s([e,0],o(new Array(r).fill(t)),!1)),n+=r},this.find=function(e){return a.includes(e)},this.reverse=function(){a.reverse()},this.unique=function(){var e,t=[];this.forEach((function(n,r){0!==r&&n===e||(t.push(n),e=n)})),t.forEach((function(e,t){a[t]=e}));for(var r=t.length;n>r;)this.popBack()},this.sort=function(e){a.sort(e)},this[Symbol.iterator]=function(){return function(){return r(this,(function(e){switch(e.label){case 0:return[5,i(a)];case 1:return[2,e.sent()]}}))}()},e.forEach((function(e){return t.pushBack(e)})),Object.freeze(this)}Object.defineProperty(n,"__esModule",{value:!0}),Object.freeze(a),n.default=a},{}],36:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.HashMap=n.HashSet=n.Map=n.Set=n.PriorityQueue=n.Deque=n.LinkList=n.Queue=n.Stack=n.Vector=void 0;var r=e("./Vector/Vector");n.Vector=r.default;var o=e("./Stack/Stack");n.Stack=o.default;var s=e("./Queue/Queue");n.Queue=s.default;var i=e("./LinkList/LinkList");n.LinkList=i.default;var a=e("./Deque/Deque");n.Deque=a.default;var c=e("./PriorityQueue/PriorityQueue");n.PriorityQueue=c.default;var l=e("./Set/Set");n.Set=l.default;var u=e("./Map/Map");n.Map=u.default;var d=e("./HashSet/HashSet");n.HashSet=d.default;var h=e("./HashMap/HashMap");n.HashMap=h.default},{"./Deque/Deque":26,"./HashMap/HashMap":27,"./HashSet/HashSet":28,"./LinkList/LinkList":29,"./Map/Map":30,"./PriorityQueue/PriorityQueue":31,"./Queue/Queue":32,"./Set/Set":33,"./Stack/Stack":34,"./Vector/Vector":35}],37:[function(e,t,n){const r=e("yallist"),o=Symbol("max"),s=Symbol("length"),i=Symbol("lengthCalculator"),a=Symbol("allowStale"),c=Symbol("maxAge"),l=Symbol("dispose"),u=Symbol("noDisposeOnSet"),d=Symbol("lruList"),h=Symbol("cache"),f=Symbol("updateAgeOnGet"),p=()=>1;class g{constructor(e){if("number"==typeof e&&(e={max:e}),e||(e={}),e.max&&("number"!=typeof e.max||e.max<0))throw new TypeError("max must be a non-negative number");this[o]=e.max||1/0;const t=e.length||p;if(this[i]="function"!=typeof t?p:t,this[a]=e.stale||!1,e.maxAge&&"number"!=typeof e.maxAge)throw new TypeError("maxAge must be a number");this[c]=e.maxAge||0,this[l]=e.dispose,this[u]=e.noDisposeOnSet||!1,this[f]=e.updateAgeOnGet||!1,this.reset()}set max(e){if("number"!=typeof e||e<0)throw new TypeError("max must be a non-negative number");this[o]=e||1/0,v(this)}get max(){return this[o]}set allowStale(e){this[a]=!!e}get allowStale(){return this[a]}set maxAge(e){if("number"!=typeof e)throw new TypeError("maxAge must be a non-negative number");this[c]=e,v(this)}get maxAge(){return this[c]}set lengthCalculator(e){"function"!=typeof e&&(e=p),e!==this[i]&&(this[i]=e,this[s]=0,this[d].forEach((e=>{e.length=this[i](e.value,e.key),this[s]+=e.length}))),v(this)}get lengthCalculator(){return this[i]}get length(){return this[s]}get itemCount(){return this[d].length}rforEach(e,t){t=t||this;for(let n=this[d].tail;null!==n;){const r=n.prev;C(this,e,n,t),n=r}}forEach(e,t){t=t||this;for(let n=this[d].head;null!==n;){const r=n.next;C(this,e,n,t),n=r}}keys(){return this[d].toArray().map((e=>e.key))}values(){return this[d].toArray().map((e=>e.value))}reset(){this[l]&&this[d]&&this[d].length&&this[d].forEach((e=>this[l](e.key,e.value))),this[h]=new Map,this[d]=new r,this[s]=0}dump(){return this[d].map((e=>!y(this,e)&&{k:e.key,v:e.value,e:e.now+(e.maxAge||0)})).toArray().filter((e=>e))}dumpLru(){return this[d]}set(e,t,n){if((n=n||this[c])&&"number"!=typeof n)throw new TypeError("maxAge must be a number");const r=n?Date.now():0,a=this[i](t,e);if(this[h].has(e)){if(a>this[o])return b(this,this[h].get(e)),!1;const i=this[h].get(e).value;return this[l]&&(this[u]||this[l](e,i.value)),i.now=r,i.maxAge=n,i.value=t,this[s]+=a-i.length,i.length=a,this.get(e),v(this),!0}const f=new w(e,t,a,r,n);return f.length>this[o]?(this[l]&&this[l](e,t),!1):(this[s]+=f.length,this[d].unshift(f),this[h].set(e,this[d].head),v(this),!0)}has(e){if(!this[h].has(e))return!1;const t=this[h].get(e).value;return!y(this,t)}get(e){return m(this,e,!0)}peek(e){return m(this,e,!1)}pop(){const e=this[d].tail;return e?(b(this,e),e.value):null}del(e){b(this,this[h].get(e))}load(e){this.reset();const t=Date.now();for(let n=e.length-1;n>=0;n--){const r=e[n],o=r.e||0;if(0===o)this.set(r.k,r.v);else{const e=o-t;e>0&&this.set(r.k,r.v,e)}}}prune(){this[h].forEach(((e,t)=>m(this,t,!1)))}}const m=(e,t,n)=>{const r=e[h].get(t);if(r){const t=r.value;if(y(e,t)){if(b(e,r),!e[a])return}else n&&(e[f]&&(r.value.now=Date.now()),e[d].unshiftNode(r));return t.value}},y=(e,t)=>{if(!t||!t.maxAge&&!e[c])return!1;const n=Date.now()-t.now;return t.maxAge?n>t.maxAge:e[c]&&n>e[c]},v=e=>{if(e[s]>e[o])for(let t=e[d].tail;e[s]>e[o]&&null!==t;){const n=t.prev;b(e,t),t=n}},b=(e,t)=>{if(t){const n=t.value;e[l]&&e[l](n.key,n.value),e[s]-=n.length,e[h].delete(n.key),e[d].removeNode(t)}};class w{constructor(e,t,n,r,o){this.key=e,this.value=t,this.length=n,this.now=r,this.maxAge=o||0}}const C=(e,t,n,r)=>{let o=n.value;y(e,o)&&(b(e,n),e[a]||(o=void 0)),o&&t.call(r,o.value,o.key,e)};t.exports=g},{yallist:83}],38:[function(e,t,n){(function(e){(function(){const n=t.exports;n.types={0:"reserved",1:"connect",2:"connack",3:"publish",4:"puback",5:"pubrec",6:"pubrel",7:"pubcomp",8:"subscribe",9:"suback",10:"unsubscribe",11:"unsuback",12:"pingreq",13:"pingresp",14:"disconnect",15:"auth"},n.codes={};for(const e in n.types){const t=n.types[e];n.codes[t]=e}n.CMD_SHIFT=4,n.CMD_MASK=240,n.DUP_MASK=8,n.QOS_MASK=3,n.QOS_SHIFT=1,n.RETAIN_MASK=1,n.VARBYTEINT_MASK=127,n.VARBYTEINT_FIN_MASK=128,n.VARBYTEINT_MAX=268435455,n.SESSIONPRESENT_MASK=1,n.SESSIONPRESENT_HEADER=e.from([n.SESSIONPRESENT_MASK]),n.CONNACK_HEADER=e.from([n.codes.connack<<n.CMD_SHIFT]),n.USERNAME_MASK=128,n.PASSWORD_MASK=64,n.WILL_RETAIN_MASK=32,n.WILL_QOS_MASK=24,n.WILL_QOS_SHIFT=3,n.WILL_FLAG_MASK=4,n.CLEAN_SESSION_MASK=2,n.CONNECT_HEADER=e.from([n.codes.connect<<n.CMD_SHIFT]),n.properties={sessionExpiryInterval:17,willDelayInterval:24,receiveMaximum:33,maximumPacketSize:39,topicAliasMaximum:34,requestResponseInformation:25,requestProblemInformation:23,userProperties:38,authenticationMethod:21,authenticationData:22,payloadFormatIndicator:1,messageExpiryInterval:2,contentType:3,responseTopic:8,correlationData:9,maximumQoS:36,retainAvailable:37,assignedClientIdentifier:18,reasonString:31,wildcardSubscriptionAvailable:40,subscriptionIdentifiersAvailable:41,sharedSubscriptionAvailable:42,serverKeepAlive:19,responseInformation:26,serverReference:28,topicAlias:35,subscriptionIdentifier:11},n.propertiesCodes={};for(const e in n.properties){const t=n.properties[e];n.propertiesCodes[t]=e}function r(t){return[0,1,2].map((r=>[0,1].map((o=>[0,1].map((s=>{const i=e.alloc(1);return i.writeUInt8(n.codes[t]<<n.CMD_SHIFT|(o?n.DUP_MASK:0)|r<<n.QOS_SHIFT|s,0,!0),i}))))))}n.propertiesTypes={sessionExpiryInterval:"int32",willDelayInterval:"int32",receiveMaximum:"int16",maximumPacketSize:"int32",topicAliasMaximum:"int16",requestResponseInformation:"byte",requestProblemInformation:"byte",userProperties:"pair",authenticationMethod:"string",authenticationData:"binary",payloadFormatIndicator:"byte",messageExpiryInterval:"int32",contentType:"string",responseTopic:"string",correlationData:"binary",maximumQoS:"int8",retainAvailable:"byte",assignedClientIdentifier:"string",reasonString:"string",wildcardSubscriptionAvailable:"byte",subscriptionIdentifiersAvailable:"byte",sharedSubscriptionAvailable:"byte",serverKeepAlive:"int16",responseInformation:"string",serverReference:"string",topicAlias:"int16",subscriptionIdentifier:"var"},n.PUBLISH_HEADER=r("publish"),n.SUBSCRIBE_HEADER=r("subscribe"),n.SUBSCRIBE_OPTIONS_QOS_MASK=3,n.SUBSCRIBE_OPTIONS_NL_MASK=1,n.SUBSCRIBE_OPTIONS_NL_SHIFT=2,n.SUBSCRIBE_OPTIONS_RAP_MASK=1,n.SUBSCRIBE_OPTIONS_RAP_SHIFT=3,n.SUBSCRIBE_OPTIONS_RH_MASK=3,n.SUBSCRIBE_OPTIONS_RH_SHIFT=4,n.SUBSCRIBE_OPTIONS_RH=[0,16,32],n.SUBSCRIBE_OPTIONS_NL=4,n.SUBSCRIBE_OPTIONS_RAP=8,n.SUBSCRIBE_OPTIONS_QOS=[0,1,2],n.UNSUBSCRIBE_HEADER=r("unsubscribe"),n.ACKS={unsuback:r("unsuback"),puback:r("puback"),pubcomp:r("pubcomp"),pubrel:r("pubrel"),pubrec:r("pubrec")},n.SUBACK_HEADER=e.from([n.codes.suback<<n.CMD_SHIFT]),n.VERSION3=e.from([3]),n.VERSION4=e.from([4]),n.VERSION5=e.from([5]),n.VERSION131=e.from([131]),n.VERSION132=e.from([132]),n.QOS=[0,1,2].map((t=>e.from([t]))),n.EMPTY={pingreq:e.from([n.codes.pingreq<<4,0]),pingresp:e.from([n.codes.pingresp<<4,0]),disconnect:e.from([n.codes.disconnect<<4,0])}}).call(this)}).call(this,e("buffer").Buffer)},{buffer:17}],39:[function(e,t,n){(function(n){(function(){const r=e("./writeToStream"),o=e("events");function s(e,t){const n=new i;return r(e,n,t),n.concat()}class i extends o{constructor(){super(),this._array=new Array(20),this._i=0}write(e){return this._array[this._i++]=e,!0}concat(){let e=0;const t=new Array(this._array.length),r=this._array;let o,s=0;for(o=0;o<r.length&&void 0!==r[o];o++)"string"!=typeof r[o]?t[o]=r[o].length:t[o]=n.byteLength(r[o]),e+=t[o];const i=n.allocUnsafe(e);for(o=0;o<r.length&&void 0!==r[o];o++)"string"!=typeof r[o]?(r[o].copy(i,s),s+=t[o]):(i.write(r[o],s),s+=t[o]);return i}}t.exports=s}).call(this)}).call(this,e("buffer").Buffer)},{"./writeToStream":44,buffer:17,events:22}],40:[function(e,t,n){n.parser=e("./parser").parser,n.generate=e("./generate"),n.writeToStream=e("./writeToStream")},{"./generate":39,"./parser":43,"./writeToStream":44}],41:[function(e,t,n){(function(e){(function(){const n=65536,r={},o=e.isBuffer(e.from([1,2]).subarray(0,1));function s(t){const n=e.allocUnsafe(2);return n.writeUInt8(t>>8,0),n.writeUInt8(255&t,1),n}function i(){for(let e=0;e<n;e++)r[e]=s(e)}function a(t){const n=4;let r=0,s=0;const i=e.allocUnsafe(n);do{r=t%128|0,(t=t/128|0)>0&&(r|=128),i.writeUInt8(r,s++)}while(t>0&&s<n);return t>0&&(s=0),o?i.subarray(0,s):i.slice(0,s)}function c(t){const n=e.allocUnsafe(4);return n.writeUInt32BE(t,0),n}t.exports={cache:r,generateCache:i,generateNumber:s,genBufVariableByteInt:a,generate4ByteBuffer:c}}).call(this)}).call(this,e("buffer").Buffer)},{buffer:17}],42:[function(e,t,n){class r{constructor(){this.cmd=null,this.retain=!1,this.qos=0,this.dup=!1,this.length=-1,this.topic=null,this.payload=null}}t.exports=r},{}],43:[function(e,t,n){const r=e("bl"),o=e("events"),s=e("./packet"),i=e("./constants"),a=e("debug")("mqtt-packet:parser");class c extends o{constructor(){super(),this.parser=this.constructor.parser}static parser(e){return this instanceof c?(this.settings=e||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):(new c).parser(e)}_resetState(){a("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new s,this.error=null,this._list=r(),this._stateCounter=0}parse(e){for(this.error&&this._resetState(),this._list.append(e),a("parse: current state: %s",this._states[this._stateCounter]);(-1!==this.packet.length||this._list.length>0)&&this[this._states[this._stateCounter]]()&&!this.error;)this._stateCounter++,a("parse: state complete. _stateCounter is now: %d",this._stateCounter),a("parse: packet.length: %d, buffer list length: %d",this.packet.length,this._list.length),this._stateCounter>=this._states.length&&(this._stateCounter=0);return a("parse: exited while loop. packet: %d, buffer list length: %d",this.packet.length,this._list.length),this._list.length}_parseHeader(){const e=this._list.readUInt8(0);return this.packet.cmd=i.types[e>>i.CMD_SHIFT],this.packet.retain=0!=(e&i.RETAIN_MASK),this.packet.qos=e>>i.QOS_SHIFT&i.QOS_MASK,this.packet.dup=0!=(e&i.DUP_MASK),a("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0}_parseLength(){const e=this._parseVarByteNum(!0);return e&&(this.packet.length=e.value,this._list.consume(e.bytes)),a("_parseLength %d",e.value),!!e}_parsePayload(){a("_parsePayload: payload %O",this._list);let e=!1;if(0===this.packet.length||this._list.length>=this.packet.length){switch(this._pos=0,this.packet.cmd){case"connect":this._parseConnect();break;case"connack":this._parseConnack();break;case"publish":this._parsePublish();break;case"puback":case"pubrec":case"pubrel":case"pubcomp":this._parseConfirmation();break;case"subscribe":this._parseSubscribe();break;case"suback":this._parseSuback();break;case"unsubscribe":this._parseUnsubscribe();break;case"unsuback":this._parseUnsuback();break;case"pingreq":case"pingresp":break;case"disconnect":this._parseDisconnect();break;case"auth":this._parseAuth();break;default:this._emitError(new Error("Not supported"))}e=!0}return a("_parsePayload complete result: %s",e),e}_parseConnect(){let e,t,n,r;a("_parseConnect");const o={},s=this.packet,c=this._parseString();if(null===c)return this._emitError(new Error("Cannot parse protocolId"));if("MQTT"!==c&&"MQIsdp"!==c)return this._emitError(new Error("Invalid protocolId"));if(s.protocolId=c,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(s.protocolVersion=this._list.readUInt8(this._pos),s.protocolVersion>=128&&(s.bridgeMode=!0,s.protocolVersion=s.protocolVersion-128),3!==s.protocolVersion&&4!==s.protocolVersion&&5!==s.protocolVersion)return this._emitError(new Error("Invalid protocol version"));if(this._pos++,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(o.username=this._list.readUInt8(this._pos)&i.USERNAME_MASK,o.password=this._list.readUInt8(this._pos)&i.PASSWORD_MASK,o.will=this._list.readUInt8(this._pos)&i.WILL_FLAG_MASK,o.will&&(s.will={},s.will.retain=0!=(this._list.readUInt8(this._pos)&i.WILL_RETAIN_MASK),s.will.qos=(this._list.readUInt8(this._pos)&i.WILL_QOS_MASK)>>i.WILL_QOS_SHIFT),s.clean=0!=(this._list.readUInt8(this._pos)&i.CLEAN_SESSION_MASK),this._pos++,s.keepalive=this._parseNum(),-1===s.keepalive)return this._emitError(new Error("Packet too short"));if(5===s.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(s.properties=e)}const l=this._parseString();if(null===l)return this._emitError(new Error("Packet too short"));if(s.clientId=l,a("_parseConnect: packet.clientId: %s",s.clientId),o.will){if(5===s.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(s.will.properties=e)}if(e=this._parseString(),null===e)return this._emitError(new Error("Cannot parse will topic"));if(s.will.topic=e,a("_parseConnect: packet.will.topic: %s",s.will.topic),t=this._parseBuffer(),null===t)return this._emitError(new Error("Cannot parse will payload"));s.will.payload=t,a("_parseConnect: packet.will.paylaod: %s",s.will.payload)}if(o.username){if(r=this._parseString(),null===r)return this._emitError(new Error("Cannot parse username"));s.username=r,a("_parseConnect: packet.username: %s",s.username)}if(o.password){if(n=this._parseBuffer(),null===n)return this._emitError(new Error("Cannot parse password"));s.password=n}return this.settings=s,a("_parseConnect: complete"),s}_parseConnack(){a("_parseConnack");const e=this.packet;if(this._list.length<1)return null;if(e.sessionPresent=!!(this._list.readUInt8(this._pos++)&i.SESSIONPRESENT_MASK),5===this.settings.protocolVersion)this._list.length>=2?e.reasonCode=this._list.readUInt8(this._pos++):e.reasonCode=0;else{if(this._list.length<2)return null;e.returnCode=this._list.readUInt8(this._pos++)}if(-1===e.returnCode||-1===e.reasonCode)return this._emitError(new Error("Cannot parse return code"));if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}a("_parseConnack: complete")}_parsePublish(){a("_parsePublish");const e=this.packet;if(e.topic=this._parseString(),null===e.topic)return this._emitError(new Error("Cannot parse topic"));if(!(e.qos>0)||this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}e.payload=this._list.slice(this._pos,e.length),a("_parsePublish: payload from buffer list: %o",e.payload)}}_parseSubscribe(){a("_parseSubscribe");const e=this.packet;let t,n,r,o,s,c,l;if(1!==e.qos)return this._emitError(new Error("Wrong subscribe header"));if(e.subscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<e.length;){if(t=this._parseString(),null===t)return this._emitError(new Error("Cannot parse topic"));if(this._pos>=e.length)return this._emitError(new Error("Malformed Subscribe Payload"));n=this._parseByte(),r=n&i.SUBSCRIBE_OPTIONS_QOS_MASK,c=0!=(n>>i.SUBSCRIBE_OPTIONS_NL_SHIFT&i.SUBSCRIBE_OPTIONS_NL_MASK),s=0!=(n>>i.SUBSCRIBE_OPTIONS_RAP_SHIFT&i.SUBSCRIBE_OPTIONS_RAP_MASK),o=n>>i.SUBSCRIBE_OPTIONS_RH_SHIFT&i.SUBSCRIBE_OPTIONS_RH_MASK,l={topic:t,qos:r},5===this.settings.protocolVersion?(l.nl=c,l.rap=s,l.rh=o):this.settings.bridgeMode&&(l.rh=0,l.rap=!0,l.nl=!0),a("_parseSubscribe: push subscription `%s` to subscription",l),e.subscriptions.push(l)}}}_parseSuback(){a("_parseSuback");const e=this.packet;if(this.packet.granted=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseUnsubscribe(){a("_parseUnsubscribe");const e=this.packet;if(e.unsubscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<e.length;){const t=this._parseString();if(null===t)return this._emitError(new Error("Cannot parse topic"));a("_parseUnsubscribe: push topic `%s` to unsubscriptions",t),e.unsubscriptions.push(t)}}}_parseUnsuback(){a("_parseUnsuback");const e=this.packet;if(!this._parseMessageId())return this._emitError(new Error("Cannot parse messageId"));if(5===this.settings.protocolVersion){const t=this._parseProperties();for(Object.getOwnPropertyNames(t).length&&(e.properties=t),e.granted=[];this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseConfirmation(){a("_parseConfirmation: packet.cmd: `%s`",this.packet.cmd);const e=this.packet;if(this._parseMessageId(),5===this.settings.protocolVersion&&(e.length>2?(e.reasonCode=this._parseByte(),a("_parseConfirmation: packet.reasonCode `%d`",e.reasonCode)):e.reasonCode=0,e.length>3)){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}return!0}_parseDisconnect(){const e=this.packet;if(a("_parseDisconnect"),5===this.settings.protocolVersion){this._list.length>0?e.reasonCode=this._parseByte():e.reasonCode=0;const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}return a("_parseDisconnect result: true"),!0}_parseAuth(){a("_parseAuth");const e=this.packet;if(5!==this.settings.protocolVersion)return this._emitError(new Error("Not supported auth packet for this version MQTT"));e.reasonCode=this._parseByte();const t=this._parseProperties();return Object.getOwnPropertyNames(t).length&&(e.properties=t),a("_parseAuth: result: true"),!0}_parseMessageId(){const e=this.packet;return e.messageId=this._parseNum(),null===e.messageId?(this._emitError(new Error("Cannot parse messageId")),!1):(a("_parseMessageId: packet.messageId %d",e.messageId),!0)}_parseString(e){const t=this._parseNum(),n=t+this._pos;if(-1===t||n>this._list.length||n>this.packet.length)return null;const r=this._list.toString("utf8",this._pos,n);return this._pos+=t,a("_parseString: result: %s",r),r}_parseStringPair(){return a("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){const e=this._parseNum(),t=e+this._pos;if(-1===e||t>this._list.length||t>this.packet.length)return null;const n=this._list.slice(this._pos,t);return this._pos+=e,a("_parseBuffer: result: %o",n),n}_parseNum(){if(this._list.length-this._pos<2)return-1;const e=this._list.readUInt16BE(this._pos);return this._pos+=2,a("_parseNum: result: %s",e),e}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;const e=this._list.readUInt32BE(this._pos);return this._pos+=4,a("_parse4ByteNum: result: %s",e),e}_parseVarByteNum(e){a("_parseVarByteNum");const t=4;let n,r=0,o=1,s=0,c=!1;const l=this._pos?this._pos:0;for(;r<t&&l+r<this._list.length;){if(n=this._list.readUInt8(l+r++),s+=o*(n&i.VARBYTEINT_MASK),o*=128,0==(n&i.VARBYTEINT_FIN_MASK)){c=!0;break}if(this._list.length<=r)break}return!c&&r===t&&this._list.length>=r&&this._emitError(new Error("Invalid variable byte integer")),l&&(this._pos+=r),c=!!c&&(e?{bytes:r,value:s}:s),a("_parseVarByteNum: result: %o",c),c}_parseByte(){let e;return this._pos<this._list.length&&(e=this._list.readUInt8(this._pos),this._pos++),a("_parseByte: result: %o",e),e}_parseByType(e){switch(a("_parseByType: type: %s",e),e){case"byte":return 0!==this._parseByte();case"int8":return this._parseByte();case"int16":return this._parseNum();case"int32":return this._parse4ByteNum();case"var":return this._parseVarByteNum();case"string":return this._parseString();case"pair":return this._parseStringPair();case"binary":return this._parseBuffer()}}_parseProperties(){a("_parseProperties");const e=this._parseVarByteNum(),t=this._pos+e,n={};for(;this._pos<t;){const e=this._parseByte();if(!e)return this._emitError(new Error("Cannot parse property code type")),!1;const t=i.propertiesCodes[e];if(!t)return this._emitError(new Error("Unknown property")),!1;if("userProperties"!==t)n[t]?(Array.isArray(n[t])||(n[t]=[n[t]]),n[t].push(this._parseByType(i.propertiesTypes[t]))):n[t]=this._parseByType(i.propertiesTypes[t]);else{n[t]||(n[t]=Object.create(null));const e=this._parseByType(i.propertiesTypes[t]);if(n[t][e.name])if(Array.isArray(n[t][e.name]))n[t][e.name].push(e.value);else{const r=n[t][e.name];n[t][e.name]=[r],n[t][e.name].push(e.value)}else n[t][e.name]=e.value}}return n}_newPacket(){return a("_newPacket"),this.packet&&(this._list.consume(this.packet.length),a("_newPacket: parser emit packet: packet.cmd: %s, packet.payload: %s, packet.length: %d",this.packet.cmd,this.packet.payload,this.packet.length),this.emit("packet",this.packet)),a("_newPacket: new packet"),this.packet=new s,this._pos=0,!0}_emitError(e){a("_emitError"),this.error=e,this.emit("error",e)}}t.exports=c},{"./constants":38,"./packet":42,bl:15,debug:18,events:22}],44:[function(e,t,n){(function(n){(function(){const r=e("./constants"),o=n.allocUnsafe(0),s=n.from([0]),i=e("./numbers"),a=e("process-nextick-args").nextTick,c=e("debug")("mqtt-packet:writeToStream"),l=i.cache,u=i.generateNumber,d=i.generateCache,h=i.genBufVariableByteInt,f=i.generate4ByteBuffer;let p=M,g=!0;function m(e,t,n){switch(c("generate called"),t.cork&&(t.cork(),a(y,t)),g&&(g=!1,d()),c("generate: packet.cmd: %s",e.cmd),e.cmd){case"connect":return v(e,t);case"connack":return b(e,t,n);case"publish":return w(e,t,n);case"puback":case"pubrec":case"pubrel":case"pubcomp":return C(e,t,n);case"subscribe":return _(e,t,n);case"suback":return k(e,t,n);case"unsubscribe":return S(e,t,n);case"unsuback":return A(e,t,n);case"pingreq":case"pingresp":return E(e,t);case"disconnect":return I(e,t,n);case"auth":return O(e,t,n);default:return t.emit("error",new Error("Unknown command")),!1}}function y(e){e.uncork()}function v(e,t,o){const s=e||{},i=s.protocolId||"MQTT";let a=s.protocolVersion||4;const c=s.will;let l=s.clean;const u=s.keepalive||0,d=s.clientId||"",h=s.username,f=s.password,g=s.properties;void 0===l&&(l=!0);let m=0;if(!i||"string"!=typeof i&&!n.isBuffer(i))return t.emit("error",new Error("Invalid protocolId")),!1;if(m+=i.length+2,3!==a&&4!==a&&5!==a)return t.emit("error",new Error("Invalid protocol version")),!1;if(m+=1,("string"==typeof d||n.isBuffer(d))&&(d||a>=4)&&(d||l))m+=n.byteLength(d)+2;else{if(a<4)return t.emit("error",new Error("clientId must be supplied before 3.1.1")),!1;if(1*l==0)return t.emit("error",new Error("clientId must be given if cleanSession set to 0")),!1}if("number"!=typeof u||u<0||u>65535||u%1!=0)return t.emit("error",new Error("Invalid keepalive")),!1;if(m+=2,m+=1,5===a){var y=B(t,g);if(!y)return!1;m+=y.length}if(c){if("object"!=typeof c)return t.emit("error",new Error("Invalid will")),!1;if(!c.topic||"string"!=typeof c.topic)return t.emit("error",new Error("Invalid will topic")),!1;if(m+=n.byteLength(c.topic)+2,m+=2,c.payload){if(!(c.payload.length>=0))return t.emit("error",new Error("Invalid will payload")),!1;"string"==typeof c.payload?m+=n.byteLength(c.payload):m+=c.payload.length}var v={};if(5===a){if(!(v=B(t,c.properties)))return!1;m+=v.length}}let b=!1;if(null!=h){if(!$(h))return t.emit("error",new Error("Invalid username")),!1;b=!0,m+=n.byteLength(h)+2}if(null!=f){if(!b)return t.emit("error",new Error("Username is required to use password")),!1;if(!$(f))return t.emit("error",new Error("Invalid password")),!1;m+=q(f)+2}t.write(r.CONNECT_HEADER),x(t,m),N(t,i),s.bridgeMode&&(a+=128),t.write(131===a?r.VERSION131:132===a?r.VERSION132:4===a?r.VERSION4:5===a?r.VERSION5:r.VERSION3);let w=0;return w|=null!=h?r.USERNAME_MASK:0,w|=null!=f?r.PASSWORD_MASK:0,w|=c&&c.retain?r.WILL_RETAIN_MASK:0,w|=c&&c.qos?c.qos<<r.WILL_QOS_SHIFT:0,w|=c?r.WILL_FLAG_MASK:0,w|=l?r.CLEAN_SESSION_MASK:0,t.write(n.from([w])),p(t,u),5===a&&y.write(),N(t,d),c&&(5===a&&v.write(),R(t,c.topic),N(t,c.payload)),null!=h&&N(t,h),null!=f&&N(t,f),!0}function b(e,t,o){const i=o?o.protocolVersion:4,a=e||{},c=5===i?a.reasonCode:a.returnCode,l=a.properties;let u=2;if("number"!=typeof c)return t.emit("error",new Error("Invalid return code")),!1;let d=null;if(5===i){if(d=B(t,l),!d)return!1;u+=d.length}return t.write(r.CONNACK_HEADER),x(t,u),t.write(a.sessionPresent?r.SESSIONPRESENT_HEADER:s),t.write(n.from([c])),null!=d&&d.write(),!0}function w(e,t,s){c("publish: packet: %o",e);const i=s?s.protocolVersion:4,a=e||{},l=a.qos||0,u=a.retain?r.RETAIN_MASK:0,d=a.topic,h=a.payload||o,f=a.messageId,g=a.properties;let m=0;if("string"==typeof d)m+=n.byteLength(d)+2;else{if(!n.isBuffer(d))return t.emit("error",new Error("Invalid topic")),!1;m+=d.length+2}if(n.isBuffer(h)?m+=h.length:m+=n.byteLength(h),l&&"number"!=typeof f)return t.emit("error",new Error("Invalid messageId")),!1;l&&(m+=2);let y=null;if(5===i){if(y=B(t,g),!y)return!1;m+=y.length}return t.write(r.PUBLISH_HEADER[l][a.dup?1:0][u?1:0]),x(t,m),p(t,q(d)),t.write(d),l>0&&p(t,f),null!=y&&y.write(),c("publish: payload: %o",h),t.write(h)}function C(e,t,o){const s=o?o.protocolVersion:4,i=e||{},a=i.cmd||"puback",c=i.messageId,l=i.dup&&"pubrel"===a?r.DUP_MASK:0;let u=0;const d=i.reasonCode,h=i.properties;let f=5===s?3:2;if("pubrel"===a&&(u=1),"number"!=typeof c)return t.emit("error",new Error("Invalid messageId")),!1;let g=null;if(5===s&&"object"==typeof h){if(g=U(t,h,o,f),!g)return!1;f+=g.length}return t.write(r.ACKS[a][u][l][0]),x(t,f),p(t,c),5===s&&t.write(n.from([d])),null!==g&&g.write(),!0}function _(e,t,o){c("subscribe: packet: ");const s=o?o.protocolVersion:4,i=e||{},a=i.dup?r.DUP_MASK:0,l=i.messageId,u=i.subscriptions,d=i.properties;let h=0;if("number"!=typeof l)return t.emit("error",new Error("Invalid messageId")),!1;h+=2;let f=null;if(5===s){if(f=B(t,d),!f)return!1;h+=f.length}if("object"!=typeof u||!u.length)return t.emit("error",new Error("Invalid subscriptions")),!1;for(let e=0;e<u.length;e+=1){const r=u[e].topic,o=u[e].qos;if("string"!=typeof r)return t.emit("error",new Error("Invalid subscriptions - invalid topic")),!1;if("number"!=typeof o)return t.emit("error",new Error("Invalid subscriptions - invalid qos")),!1;if(5===s){if("boolean"!=typeof(u[e].nl||!1))return t.emit("error",new Error("Invalid subscriptions - invalid No Local")),!1;if("boolean"!=typeof(u[e].rap||!1))return t.emit("error",new Error("Invalid subscriptions - invalid Retain as Published")),!1;const n=u[e].rh||0;if("number"!=typeof n||n>2)return t.emit("error",new Error("Invalid subscriptions - invalid Retain Handling")),!1}h+=n.byteLength(r)+2+1}c("subscribe: writing to stream: %o",r.SUBSCRIBE_HEADER),t.write(r.SUBSCRIBE_HEADER[1][a?1:0][0]),x(t,h),p(t,l),null!==f&&f.write();let g=!0;for(const e of u){const o=e.topic,i=e.qos,a=+e.nl,c=+e.rap,l=e.rh;let u;R(t,o),u=r.SUBSCRIBE_OPTIONS_QOS[i],5===s&&(u|=a?r.SUBSCRIBE_OPTIONS_NL:0,u|=c?r.SUBSCRIBE_OPTIONS_RAP:0,u|=l?r.SUBSCRIBE_OPTIONS_RH[l]:0),g=t.write(n.from([u]))}return g}function k(e,t,o){const s=o?o.protocolVersion:4,i=e||{},a=i.messageId,c=i.granted,l=i.properties;let u=0;if("number"!=typeof a)return t.emit("error",new Error("Invalid messageId")),!1;if(u+=2,"object"!=typeof c||!c.length)return t.emit("error",new Error("Invalid qos vector")),!1;for(let e=0;e<c.length;e+=1){if("number"!=typeof c[e])return t.emit("error",new Error("Invalid qos vector")),!1;u+=1}let d=null;if(5===s){if(d=U(t,l,o,u),!d)return!1;u+=d.length}return t.write(r.SUBACK_HEADER),x(t,u),p(t,a),null!==d&&d.write(),t.write(n.from(c))}function S(e,t,o){const s=o?o.protocolVersion:4,i=e||{},a=i.messageId,c=i.dup?r.DUP_MASK:0,l=i.unsubscriptions,u=i.properties;let d=0;if("number"!=typeof a)return t.emit("error",new Error("Invalid messageId")),!1;if(d+=2,"object"!=typeof l||!l.length)return t.emit("error",new Error("Invalid unsubscriptions")),!1;for(let e=0;e<l.length;e+=1){if("string"!=typeof l[e])return t.emit("error",new Error("Invalid unsubscriptions")),!1;d+=n.byteLength(l[e])+2}let h=null;if(5===s){if(h=B(t,u),!h)return!1;d+=h.length}t.write(r.UNSUBSCRIBE_HEADER[1][c?1:0][0]),x(t,d),p(t,a),null!==h&&h.write();let f=!0;for(let e=0;e<l.length;e++)f=R(t,l[e]);return f}function A(e,t,o){const s=o?o.protocolVersion:4,i=e||{},a=i.messageId,c=i.dup?r.DUP_MASK:0,l=i.granted,u=i.properties,d=i.cmd,h=0;let f=2;if("number"!=typeof a)return t.emit("error",new Error("Invalid messageId")),!1;if(5===s){if("object"!=typeof l||!l.length)return t.emit("error",new Error("Invalid qos vector")),!1;for(let e=0;e<l.length;e+=1){if("number"!=typeof l[e])return t.emit("error",new Error("Invalid qos vector")),!1;f+=1}}let g=null;if(5===s){if(g=U(t,u,o,f),!g)return!1;f+=g.length}return t.write(r.ACKS[d][h][c][0]),x(t,f),p(t,a),null!==g&&g.write(),5===s&&t.write(n.from(l)),!0}function E(e,t,n){return t.write(r.EMPTY[e.cmd])}function I(e,t,o){const s=o?o.protocolVersion:4,i=e||{},a=i.reasonCode,c=i.properties;let l=5===s?1:0,u=null;if(5===s){if(u=U(t,c,o,l),!u)return!1;l+=u.length}return t.write(n.from([r.codes.disconnect<<4])),x(t,l),5===s&&t.write(n.from([a])),null!==u&&u.write(),!0}function O(e,t,o){const s=o?o.protocolVersion:4,i=e||{},a=i.reasonCode,c=i.properties;let l=5===s?1:0;5!==s&&t.emit("error",new Error("Invalid mqtt version for auth packet"));const u=U(t,c,o,l);return!!u&&(l+=u.length,t.write(n.from([r.codes.auth<<4])),x(t,l),t.write(n.from([a])),null!==u&&u.write(),!0)}Object.defineProperty(m,"cacheNumbers",{get:()=>p===M,set(e){e?(l&&0!==Object.keys(l).length||(g=!0),p=M):(g=!1,p=j)}});const T={};function x(e,t){if(t>r.VARBYTEINT_MAX)return e.emit("error",new Error(`Invalid variable byte integer: ${t}`)),!1;let n=T[t];return n||(n=h(t),t<16384&&(T[t]=n)),c("writeVarByteInt: writing to stream: %o",n),e.write(n)}function R(e,t){const r=n.byteLength(t);return p(e,r),c("writeString: %s",t),e.write(t,"utf8")}function P(e,t,n){R(e,t),R(e,n)}function M(e,t){return c("writeNumberCached: number: %d",t),c("writeNumberCached: %o",l[t]),e.write(l[t])}function j(e,t){const n=u(t);return c("writeNumberGenerated: %o",n),e.write(n)}function F(e,t){const n=f(t);return c("write4ByteNumber: %o",n),e.write(n)}function N(e,t){"string"==typeof t?R(e,t):t?(p(e,t.length),e.write(t)):p(e,0)}function B(e,t){if("object"!=typeof t||null!=t.length)return{length:1,write(){L(e,{},0)}};let o=0;function s(t,o){let s=0;switch(r.propertiesTypes[t]){case"byte":if("boolean"!=typeof o)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;s+=2;break;case"int8":if("number"!=typeof o||o<0||o>255)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;s+=2;break;case"binary":if(o&&null===o)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;s+=1+n.byteLength(o)+2;break;case"int16":if("number"!=typeof o||o<0||o>65535)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;s+=3;break;case"int32":if("number"!=typeof o||o<0||o>4294967295)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;s+=5;break;case"var":if("number"!=typeof o||o<0||o>268435455)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;s+=1+n.byteLength(h(o));break;case"string":if("string"!=typeof o)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;s+=3+n.byteLength(o.toString());break;case"pair":if("object"!=typeof o)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;s+=Object.getOwnPropertyNames(o).reduce(((e,t)=>{const r=o[t];return Array.isArray(r)?e+=r.reduce(((e,r)=>e+=3+n.byteLength(t.toString())+2+n.byteLength(r.toString())),0):e+=3+n.byteLength(t.toString())+2+n.byteLength(o[t].toString()),e}),0);break;default:return e.emit("error",new Error(`Invalid property ${t}: ${o}`)),!1}return s}if(t)for(const e in t){let n=0,r=0;const i=t[e];if(Array.isArray(i))for(let t=0;t<i.length;t++){if(r=s(e,i[t]),!r)return!1;n+=r}else{if(r=s(e,i),!r)return!1;n=r}if(!n)return!1;o+=n}return{length:n.byteLength(h(o))+o,write(){L(e,t,o)}}}function U(e,t,n,r){const o=["reasonString","userProperties"],s=n&&n.properties&&n.properties.maximumPacketSize?n.properties.maximumPacketSize:0;let i=B(e,t);if(s)for(;r+i.length>s;){const n=o.shift();if(!n||!t[n])return!1;delete t[n],i=B(e,t)}return i}function D(e,t,o){switch(r.propertiesTypes[t]){case"byte":e.write(n.from([r.properties[t]])),e.write(n.from([+o]));break;case"int8":e.write(n.from([r.properties[t]])),e.write(n.from([o]));break;case"binary":e.write(n.from([r.properties[t]])),N(e,o);break;case"int16":e.write(n.from([r.properties[t]])),p(e,o);break;case"int32":e.write(n.from([r.properties[t]])),F(e,o);break;case"var":e.write(n.from([r.properties[t]])),x(e,o);break;case"string":e.write(n.from([r.properties[t]])),R(e,o);break;case"pair":Object.getOwnPropertyNames(o).forEach((s=>{const i=o[s];Array.isArray(i)?i.forEach((o=>{e.write(n.from([r.properties[t]])),P(e,s.toString(),o.toString())})):(e.write(n.from([r.properties[t]])),P(e,s.toString(),i.toString()))}));break;default:return e.emit("error",new Error(`Invalid property ${t} value: ${o}`)),!1}}function L(e,t,n){x(e,n);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&null!==t[n]){const r=t[n];if(Array.isArray(r))for(let t=0;t<r.length;t++)D(e,n,r[t]);else D(e,n,r)}}function q(e){return e?e instanceof n?e.length:n.byteLength(e):0}function $(e){return"string"==typeof e||e instanceof n}t.exports=m}).call(this)}).call(this,e("buffer").Buffer)},{"./constants":38,"./numbers":41,buffer:17,debug:18,"process-nextick-args":49}],45:[function(e,t,n){var r=1e3,o=60*r,s=60*o,i=24*s,a=7*i,c=365.25*i;function l(e){if(!((e=String(e)).length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*c;case"weeks":case"week":case"w":return n*a;case"days":case"day":case"d":return n*i;case"hours":case"hour":case"hrs":case"hr":case"h":return n*s;case"minutes":case"minute":case"mins":case"min":case"m":return n*o;case"seconds":case"second":case"secs":case"sec":case"s":return n*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}function u(e){var t=Math.abs(e);return t>=i?Math.round(e/i)+"d":t>=s?Math.round(e/s)+"h":t>=o?Math.round(e/o)+"m":t>=r?Math.round(e/r)+"s":e+"ms"}function d(e){var t=Math.abs(e);return t>=i?h(e,t,i,"day"):t>=s?h(e,t,s,"hour"):t>=o?h(e,t,o,"minute"):t>=r?h(e,t,r,"second"):e+" ms"}function h(e,t,n,r){var o=t>=1.5*n;return Math.round(e/n)+" "+r+(o?"s":"")}t.exports=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return l(e);if("number"===n&&isFinite(e))return t.long?d(e):u(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},{}],46:[function(e,t,n){const r=e("./lib/number-allocator.js");t.exports.NumberAllocator=r},{"./lib/number-allocator.js":47}],47:[function(e,t,n){const r=e("js-sdsl").Set,o=e("debug")("number-allocator:trace"),s=e("debug")("number-allocator:error");function i(e,t){this.low=e,this.high=t}function a(e,t){if(!(this instanceof a))return new a(e,t);this.min=e,this.max=t,this.ss=new r([],((e,t)=>e.compare(t))),o("Create"),this.clear()}i.prototype.equals=function(e){return this.low===e.low&&this.high===e.high},i.prototype.compare=function(e){return this.low<e.low&&this.high<e.low?-1:e.low<this.low&&e.high<this.low?1:0},a.prototype.firstVacant=function(){return 0===this.ss.size()?null:this.ss.front().low},a.prototype.alloc=function(){if(0===this.ss.size())return o("alloc():empty"),null;const e=this.ss.front(),t=e.low;return t+1<=e.high?++e.low:this.ss.eraseElementByPos(0),o("alloc():"+t),t},a.prototype.use=function(e){const t=new i(e,e),n=this.ss.lowerBound(t);if(n){if(n.equals(t))return this.ss.eraseElementByValue(n),o("use():"+e),!0;if(n.low>e)return!1;if(n.low===e)return++n.low,o("use():"+e),!0;if(n.high===e)return--n.high,o("use():"+e),!0;const r=n.low;return n.low=e+1,this.ss.insert(new i(r,e-1)),o("use():"+e),!0}return o("use():failed"),!1},a.prototype.free=function(e){if(e<this.min||e>this.max)return void s("free():"+e+" is out of range");const t=new i(e,e),n=this.ss.lowerBound(t);if(n){if(n.low<=e&&e<=n.high)return void s("free():"+e+" has already been vacant");if(n===this.ss.front())e+1===n.low?--n.low:this.ss.insert(t);else{const r=this.ss.reverseLowerBound(t);r.high+1===e?e+1===n.low?(this.ss.eraseElementByValue(r),n.low=r.low):r.high=e:e+1===n.low?n.low=e:this.ss.insert(t)}}else{if(n===this.ss.front())return void this.ss.insert(t);const r=this.ss.reverseLowerBound(t);r.high+1===e?r.high=e:this.ss.insert(t)}o("free():"+e)},a.prototype.clear=function(){o("clear()"),this.ss.clear(),this.ss.insert(new i(this.min,this.max))},a.prototype.intervalCount=function(){return this.ss.size()},a.prototype.dump=function(){console.log("length:"+this.ss.size());for(const e of this.ss)console.log(e)},t.exports=a},{debug:18,"js-sdsl":36}],48:[function(e,t,n){var r=e("wrappy");function o(e){var t=function(){return t.called?t.value:(t.called=!0,t.value=e.apply(this,arguments))};return t.called=!1,t}function s(e){var t=function(){if(t.called)throw new Error(t.onceError);return t.called=!0,t.value=e.apply(this,arguments)},n=e.name||"Function wrapped with `once`";return t.onceError=n+" shouldn't be called more than once",t.called=!1,t}t.exports=r(o),t.exports.strict=r(s),o.proto=o((function(){Object.defineProperty(Function.prototype,"once",{value:function(){return o(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return s(this)},configurable:!0})}))},{wrappy:79}],49:[function(e,t,n){(function(e){(function(){function n(t,n,r,o){if("function"!=typeof t)throw new TypeError('"callback" argument must be a function');var s,i,a=arguments.length;switch(a){case 0:case 1:return e.nextTick(t);case 2:return e.nextTick((function(){t.call(null,n)}));case 3:return e.nextTick((function(){t.call(null,n,r)}));case 4:return e.nextTick((function(){t.call(null,n,r,o)}));default:for(s=new Array(a-1),i=0;i<s.length;)s[i++]=arguments[i];return e.nextTick((function(){t.apply(null,s)}))}}void 0===e||!e.version||0===e.version.indexOf("v0.")||0===e.version.indexOf("v1.")&&0!==e.version.indexOf("v1.8.")?t.exports={nextTick:n}:t.exports=e}).call(this)}).call(this,e("_process"))},{_process:50}],50:[function(e,t,n){var r,o,s=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function c(e){if(r===setTimeout)return setTimeout(e,0);if((r===i||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}function l(e){if(o===clearTimeout)return clearTimeout(e);if((o===a||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(e);try{return o(e)}catch(t){try{return o.call(null,e)}catch(t){return o.call(this,e)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:i}catch(e){r=i}try{o="function"==typeof clearTimeout?clearTimeout:a}catch(e){o=a}}();var u,d=[],h=!1,f=-1;function p(){h&&u&&(h=!1,u.length?d=u.concat(d):f=-1,d.length&&g())}function g(){if(!h){var e=c(p);h=!0;for(var t=d.length;t;){for(u=d,d=[];++f<t;)u&&u[f].run();f=-1,t=d.length}u=null,h=!1,l(e)}}function m(e,t){this.fun=e,this.array=t}function y(){}s.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];d.push(new m(e,t)),1!==d.length||h||c(g)},m.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=y,s.addListener=y,s.once=y,s.off=y,s.removeListener=y,s.removeAllListeners=y,s.emit=y,s.prependListener=y,s.prependOnceListener=y,s.listeners=function(e){return[]},s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},{}],51:[function(e,t,n){(function(e){(function(){!function(r){var o="object"==typeof n&&n&&!n.nodeType&&n,s="object"==typeof t&&t&&!t.nodeType&&t,i="object"==typeof e&&e;i.global!==i&&i.window!==i&&i.self!==i||(r=i);var a,c,l=2147483647,u=36,d=1,h=26,f=38,p=700,g=72,m=128,y="-",v=/^xn--/,b=/[^\x20-\x7E]/,w=/[\x2E\u3002\uFF0E\uFF61]/g,C={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},_=u-d,k=Math.floor,S=String.fromCharCode;function A(e){throw new RangeError(C[e])}function E(e,t){for(var n=e.length,r=[];n--;)r[n]=t(e[n]);return r}function I(e,t){var n=e.split("@"),r="";return n.length>1&&(r=n[0]+"@",e=n[1]),r+E((e=e.replace(w,".")).split("."),t).join(".")}function O(e){for(var t,n,r=[],o=0,s=e.length;o<s;)(t=e.charCodeAt(o++))>=55296&&t<=56319&&o<s?56320==(64512&(n=e.charCodeAt(o++)))?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),o--):r.push(t);return r}function T(e){return E(e,(function(e){var t="";return e>65535&&(t+=S((e-=65536)>>>10&1023|55296),e=56320|1023&e),t+=S(e)})).join("")}function x(e){return e-48<10?e-22:e-65<26?e-65:e-97<26?e-97:u}function R(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function P(e,t,n){var r=0;for(e=n?k(e/p):e>>1,e+=k(e/t);e>_*h>>1;r+=u)e=k(e/_);return k(r+(_+1)*e/(e+f))}function M(e){var t,n,r,o,s,i,a,c,f,p,v=[],b=e.length,w=0,C=m,_=g;for((n=e.lastIndexOf(y))<0&&(n=0),r=0;r<n;++r)e.charCodeAt(r)>=128&&A("not-basic"),v.push(e.charCodeAt(r));for(o=n>0?n+1:0;o<b;){for(s=w,i=1,a=u;o>=b&&A("invalid-input"),((c=x(e.charCodeAt(o++)))>=u||c>k((l-w)/i))&&A("overflow"),w+=c*i,!(c<(f=a<=_?d:a>=_+h?h:a-_));a+=u)i>k(l/(p=u-f))&&A("overflow"),i*=p;_=P(w-s,t=v.length+1,0==s),k(w/t)>l-C&&A("overflow"),C+=k(w/t),w%=t,v.splice(w++,0,C)}return T(v)}function j(e){var t,n,r,o,s,i,a,c,f,p,v,b,w,C,_,E=[];for(b=(e=O(e)).length,t=m,n=0,s=g,i=0;i<b;++i)(v=e[i])<128&&E.push(S(v));for(r=o=E.length,o&&E.push(y);r<b;){for(a=l,i=0;i<b;++i)(v=e[i])>=t&&v<a&&(a=v);for(a-t>k((l-n)/(w=r+1))&&A("overflow"),n+=(a-t)*w,t=a,i=0;i<b;++i)if((v=e[i])<t&&++n>l&&A("overflow"),v==t){for(c=n,f=u;!(c<(p=f<=s?d:f>=s+h?h:f-s));f+=u)_=c-p,C=u-p,E.push(S(R(p+_%C,0))),c=k(_/C);E.push(S(R(c,0))),s=P(n,w,r==o),n=0,++r}++n,++t}return E.join("")}function F(e){return I(e,(function(e){return v.test(e)?M(e.slice(4).toLowerCase()):e}))}function N(e){return I(e,(function(e){return b.test(e)?"xn--"+j(e):e}))}if(a={version:"1.4.1",ucs2:{decode:O,encode:T},decode:M,encode:j,toASCII:N,toUnicode:F},o&&s)if(t.exports==o)s.exports=a;else for(c in a)a.hasOwnProperty(c)&&(o[c]=a[c]);else r.punycode=a}(this)}).call(this)}).call(this,void 0!==_e?_e:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],52:[function(e,t,n){function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.exports=function(e,t,n,s){t=t||"&",n=n||"=";var i={};if("string"!=typeof e||0===e.length)return i;var a=/\+/g;e=e.split(t);var c=1e3;s&&"number"==typeof s.maxKeys&&(c=s.maxKeys);var l=e.length;c>0&&l>c&&(l=c);for(var u=0;u<l;++u){var d,h,f,p,g=e[u].replace(a,"%20"),m=g.indexOf(n);m>=0?(d=g.substr(0,m),h=g.substr(m+1)):(d=g,h=""),f=decodeURIComponent(d),p=decodeURIComponent(h),r(i,f)?o(i[f])?i[f].push(p):i[f]=[i[f],p]:i[f]=p}return i};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},{}],53:[function(e,t,n){var r=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};t.exports=function(e,t,n,a){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?s(i(e),(function(i){var a=encodeURIComponent(r(i))+n;return o(e[i])?s(e[i],(function(e){return a+encodeURIComponent(r(e))})).join(t):a+encodeURIComponent(r(e[i]))})).join(t):a?encodeURIComponent(r(a))+n+encodeURIComponent(r(e)):""};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function s(e,t){if(e.map)return e.map(t);for(var n=[],r=0;r<e.length;r++)n.push(t(e[r],r));return n}var i=Object.keys||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t}},{}],54:[function(e,t,n){n.decode=n.parse=e("./decode"),n.encode=n.stringify=e("./encode")},{"./decode":52,"./encode":53}],55:[function(e,t,n){function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var o={};function s(e,t,n){function s(e,n,r){return"string"==typeof t?t:t(e,n,r)}n||(n=Error);var i=function(e){function t(t,n,r){return e.call(this,s(t,n,r))||this}return r(t,e),t}(n);i.prototype.name=n.name,i.prototype.code=e,o[e]=i}function i(e,t){if(Array.isArray(e)){var n=e.length;return e=e.map((function(e){return String(e)})),n>2?"one of ".concat(t," ").concat(e.slice(0,n-1).join(", "),", or ")+e[n-1]:2===n?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}return"of ".concat(t," ").concat(String(e))}function a(e,t,n){return e.substr(!n||n<0?0:+n,t.length)===t}function c(e,t,n){return(void 0===n||n>e.length)&&(n=e.length),e.substring(n-t.length,n)===t}function l(e,t,n){return"number"!=typeof n&&(n=0),!(n+t.length>e.length)&&-1!==e.indexOf(t,n)}s("ERR_INVALID_OPT_VALUE",(function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),s("ERR_INVALID_ARG_TYPE",(function(e,t,n){var r,o;if("string"==typeof t&&a(t,"not ")?(r="must not be",t=t.replace(/^not /,"")):r="must be",c(e," argument"))o="The ".concat(e," ").concat(r," ").concat(i(t,"type"));else{var s=l(e,".")?"property":"argument";o='The "'.concat(e,'" ').concat(s," ").concat(r," ").concat(i(t,"type"))}return o+=". Received type ".concat(typeof n)}),TypeError),s("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),s("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return"The "+e+" method is not implemented"})),s("ERR_STREAM_PREMATURE_CLOSE","Premature close"),s("ERR_STREAM_DESTROYED",(function(e){return"Cannot call "+e+" after a stream was destroyed"})),s("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),s("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),s("ERR_STREAM_WRITE_AFTER_END","write after end"),s("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),s("ERR_UNKNOWN_ENCODING",(function(e){return"Unknown encoding: "+e}),TypeError),s("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),t.exports.codes=o},{}],56:[function(e,t,n){(function(n){(function(){var r=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};t.exports=l;var o=e("./_stream_readable"),s=e("./_stream_writable");e("inherits")(l,o);for(var i=r(s.prototype),a=0;a<i.length;a++){var c=i[a];l.prototype[c]||(l.prototype[c]=s.prototype[c])}function l(e){if(!(this instanceof l))return new l(e);o.call(this,e),s.call(this,e),this.allowHalfOpen=!0,e&&(!1===e.readable&&(this.readable=!1),!1===e.writable&&(this.writable=!1),!1===e.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",u)))}function u(){this._writableState.ended||n.nextTick(d,this)}function d(e){e.end()}Object.defineProperty(l.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(l.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(l.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(l.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&this._readableState.destroyed&&this._writableState.destroyed},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}})}).call(this)}).call(this,e("_process"))},{"./_stream_readable":58,"./_stream_writable":60,_process:50,inherits:24}],57:[function(e,t,n){t.exports=o;var r=e("./_stream_transform");function o(e){if(!(this instanceof o))return new o(e);r.call(this,e)}e("inherits")(o,r),o.prototype._transform=function(e,t,n){n(null,e)}},{"./_stream_transform":59,inherits:24}],58:[function(e,t,n){(function(n,r){(function(){var o;t.exports=O,O.ReadableState=I,e("events").EventEmitter;var s=function(e,t){return e.listeners(t).length},i=e("./internal/streams/stream"),a=e("buffer").Buffer,c=r.Uint8Array||function(){};function l(e){return a.from(e)}function u(e){return a.isBuffer(e)||e instanceof c}var d,h=e("util");d=h&&h.debuglog?h.debuglog("stream"):function(){};var f,p,g,m=e("./internal/streams/buffer_list"),y=e("./internal/streams/destroy"),v=e("./internal/streams/state").getHighWaterMark,b=e("../errors").codes,w=b.ERR_INVALID_ARG_TYPE,C=b.ERR_STREAM_PUSH_AFTER_EOF,_=b.ERR_METHOD_NOT_IMPLEMENTED,k=b.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;e("inherits")(O,i);var S=y.errorOrDestroy,A=["error","close","destroy","pause","resume"];function E(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n)}function I(t,n,r){o=o||e("./_stream_duplex"),t=t||{},"boolean"!=typeof r&&(r=n instanceof o),this.objectMode=!!t.objectMode,r&&(this.objectMode=this.objectMode||!!t.readableObjectMode),this.highWaterMark=v(this,t,"readableHighWaterMark",r),this.buffer=new m,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=!1!==t.emitClose,this.autoDestroy=!!t.autoDestroy,this.destroyed=!1,this.defaultEncoding=t.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,t.encoding&&(f||(f=e("string_decoder/").StringDecoder),this.decoder=new f(t.encoding),this.encoding=t.encoding)}function O(t){if(o=o||e("./_stream_duplex"),!(this instanceof O))return new O(t);var n=this instanceof o;this._readableState=new I(t,this,n),this.readable=!0,t&&("function"==typeof t.read&&(this._read=t.read),"function"==typeof t.destroy&&(this._destroy=t.destroy)),i.call(this)}function T(e,t,n,r,o){d("readableAddChunk",t);var s,i=e._readableState;if(null===t)i.reading=!1,F(e,i);else if(o||(s=R(i,t)),s)S(e,s);else if(i.objectMode||t&&t.length>0)if("string"==typeof t||i.objectMode||Object.getPrototypeOf(t)===a.prototype||(t=l(t)),r)i.endEmitted?S(e,new k):x(e,i,t,!0);else if(i.ended)S(e,new C);else{if(i.destroyed)return!1;i.reading=!1,i.decoder&&!n?(t=i.decoder.write(t),i.objectMode||0!==t.length?x(e,i,t,!1):U(e,i)):x(e,i,t,!1)}else r||(i.reading=!1,U(e,i));return!i.ended&&(i.length<i.highWaterMark||0===i.length)}function x(e,t,n,r){t.flowing&&0===t.length&&!t.sync?(t.awaitDrain=0,e.emit("data",n)):(t.length+=t.objectMode?1:n.length,r?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&N(e)),U(e,t)}function R(e,t){var n;return u(t)||"string"==typeof t||void 0===t||e.objectMode||(n=new w("chunk",["string","Buffer","Uint8Array"],t)),n}Object.defineProperty(O.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),O.prototype.destroy=y.destroy,O.prototype._undestroy=y.undestroy,O.prototype._destroy=function(e,t){t(e)},O.prototype.push=function(e,t){var n,r=this._readableState;return r.objectMode?n=!0:"string"==typeof e&&((t=t||r.defaultEncoding)!==r.encoding&&(e=a.from(e,t),t=""),n=!0),T(this,e,t,!1,n)},O.prototype.unshift=function(e){return T(this,e,null,!0,!1)},O.prototype.isPaused=function(){return!1===this._readableState.flowing},O.prototype.setEncoding=function(t){f||(f=e("string_decoder/").StringDecoder);var n=new f(t);this._readableState.decoder=n,this._readableState.encoding=this._readableState.decoder.encoding;for(var r=this._readableState.buffer.head,o="";null!==r;)o+=n.write(r.data),r=r.next;return this._readableState.buffer.clear(),""!==o&&this._readableState.buffer.push(o),this._readableState.length=o.length,this};var P=1073741824;function M(e){return e>=P?e=P:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function j(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!=e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=M(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function F(e,t){if(d("onEofChunk"),!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,t.sync?N(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,B(e)))}}function N(e){var t=e._readableState;d("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(d("emitReadable",t.flowing),t.emittedReadable=!0,n.nextTick(B,e))}function B(e){var t=e._readableState;d("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,V(e)}function U(e,t){t.readingMore||(t.readingMore=!0,n.nextTick(D,e,t))}function D(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&0===t.length);){var n=t.length;if(d("maybeReadMore read 0"),e.read(0),n===t.length)break}t.readingMore=!1}function L(e){return function(){var t=e._readableState;d("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&s(e,"data")&&(t.flowing=!0,V(e))}}function q(e){var t=e._readableState;t.readableListening=e.listenerCount("readable")>0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume()}function $(e){d("readable nexttick read 0"),e.read(0)}function z(e,t){t.resumeScheduled||(t.resumeScheduled=!0,n.nextTick(H,e,t))}function H(e,t){d("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),V(e),t.flowing&&!t.reading&&e.read(0)}function V(e){var t=e._readableState;for(d("flow",t.flowing);t.flowing&&null!==e.read(););}function W(e,t){return 0===t.length?null:(t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n);var n}function K(e){var t=e._readableState;d("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,n.nextTick(Q,t,e))}function Q(e,t){if(d("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy()}}function J(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}O.prototype.read=function(e){d("read",e),e=parseInt(e,10);var t=this._readableState,n=e;if(0!==e&&(t.emittedReadable=!1),0===e&&t.needReadable&&((0!==t.highWaterMark?t.length>=t.highWaterMark:t.length>0)||t.ended))return d("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?K(this):N(this),null;if(0===(e=j(e,t))&&t.ended)return 0===t.length&&K(this),null;var r,o=t.needReadable;return d("need readable",o),(0===t.length||t.length-e<t.highWaterMark)&&d("length less than watermark",o=!0),t.ended||t.reading?d("reading or ended",o=!1):o&&(d("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=j(n,t))),null===(r=e>0?W(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&K(this)),null!==r&&this.emit("data",r),r},O.prototype._read=function(e){S(this,new _("_read()"))},O.prototype.pipe=function(e,t){var r=this,o=this._readableState;switch(o.pipesCount){case 0:o.pipes=e;break;case 1:o.pipes=[o.pipes,e];break;default:o.pipes.push(e)}o.pipesCount+=1,d("pipe count=%d opts=%j",o.pipesCount,t);var i=t&&!1===t.end||e===n.stdout||e===n.stderr?y:c;function a(e,t){d("onunpipe"),e===r&&t&&!1===t.hasUnpiped&&(t.hasUnpiped=!0,h())}function c(){d("onend"),e.end()}o.endEmitted?n.nextTick(i):r.once("end",i),e.on("unpipe",a);var l=L(r);e.on("drain",l);var u=!1;function h(){d("cleanup"),e.removeListener("close",g),e.removeListener("finish",m),e.removeListener("drain",l),e.removeListener("error",p),e.removeListener("unpipe",a),r.removeListener("end",c),r.removeListener("end",y),r.removeListener("data",f),u=!0,!o.awaitDrain||e._writableState&&!e._writableState.needDrain||l()}function f(t){d("ondata");var n=e.write(t);d("dest.write",n),!1===n&&((1===o.pipesCount&&o.pipes===e||o.pipesCount>1&&-1!==J(o.pipes,e))&&!u&&(d("false write response, pause",o.awaitDrain),o.awaitDrain++),r.pause())}function p(t){d("onerror",t),y(),e.removeListener("error",p),0===s(e,"error")&&S(e,t)}function g(){e.removeListener("finish",m),y()}function m(){d("onfinish"),e.removeListener("close",g),y()}function y(){d("unpipe"),r.unpipe(e)}return r.on("data",f),E(e,"error",p),e.once("close",g),e.once("finish",m),e.emit("pipe",r),o.flowing||(d("pipe resume"),r.resume()),e},O.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n)),this;if(!e){var r=t.pipes,o=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var s=0;s<o;s++)r[s].emit("unpipe",this,{hasUnpiped:!1});return this}var i=J(t.pipes,e);return-1===i||(t.pipes.splice(i,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,n)),this},O.prototype.on=function(e,t){var r=i.prototype.on.call(this,e,t),o=this._readableState;return"data"===e?(o.readableListening=this.listenerCount("readable")>0,!1!==o.flowing&&this.resume()):"readable"===e&&(o.endEmitted||o.readableListening||(o.readableListening=o.needReadable=!0,o.flowing=!1,o.emittedReadable=!1,d("on readable",o.length,o.reading),o.length?N(this):o.reading||n.nextTick($,this))),r},O.prototype.addListener=O.prototype.on,O.prototype.removeListener=function(e,t){var r=i.prototype.removeListener.call(this,e,t);return"readable"===e&&n.nextTick(q,this),r},O.prototype.removeAllListeners=function(e){var t=i.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||n.nextTick(q,this),t},O.prototype.resume=function(){var e=this._readableState;return e.flowing||(d("resume"),e.flowing=!e.readableListening,z(this,e)),e.paused=!1,this},O.prototype.pause=function(){return d("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(d("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},O.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var o in e.on("end",(function(){if(d("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e)}t.push(null)})),e.on("data",(function(o){d("wrapped data"),n.decoder&&(o=n.decoder.write(o)),n.objectMode&&null==o||(n.objectMode||o&&o.length)&&(t.push(o)||(r=!0,e.pause()))})),e)void 0===this[o]&&"function"==typeof e[o]&&(this[o]=function(t){return function(){return e[t].apply(e,arguments)}}(o));for(var s=0;s<A.length;s++)e.on(A[s],this.emit.bind(this,A[s]));return this._read=function(t){d("wrapped _read",t),r&&(r=!1,e.resume())},this},"function"==typeof Symbol&&(O.prototype[Symbol.asyncIterator]=function(){return void 0===p&&(p=e("./internal/streams/async_iterator")),p(this)}),Object.defineProperty(O.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(O.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(O.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),O._fromList=W,Object.defineProperty(O.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(O.from=function(t,n){return void 0===g&&(g=e("./internal/streams/from")),g(O,t,n)})}).call(this)}).call(this,e("_process"),void 0!==_e?_e:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../errors":55,"./_stream_duplex":56,"./internal/streams/async_iterator":61,"./internal/streams/buffer_list":62,"./internal/streams/destroy":63,"./internal/streams/from":65,"./internal/streams/state":67,"./internal/streams/stream":68,_process:50,buffer:17,events:22,inherits:24,"string_decoder/":75,util:16}],59:[function(e,t,n){t.exports=u;var r=e("../errors").codes,o=r.ERR_METHOD_NOT_IMPLEMENTED,s=r.ERR_MULTIPLE_CALLBACK,i=r.ERR_TRANSFORM_ALREADY_TRANSFORMING,a=r.ERR_TRANSFORM_WITH_LENGTH_0,c=e("./_stream_duplex");function l(e,t){var n=this._transformState;n.transforming=!1;var r=n.writecb;if(null===r)return this.emit("error",new s);n.writechunk=null,n.writecb=null,null!=t&&this.push(t),r(e);var o=this._readableState;o.reading=!1,(o.needReadable||o.length<o.highWaterMark)&&this._read(o.highWaterMark)}function u(e){if(!(this instanceof u))return new u(e);c.call(this,e),this._transformState={afterTransform:l.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.on("prefinish",d)}function d(){var e=this;"function"!=typeof this._flush||this._readableState.destroyed?h(this,null,null):this._flush((function(t,n){h(e,t,n)}))}function h(e,t,n){if(t)return e.emit("error",t);if(null!=n&&e.push(n),e._writableState.length)throw new a;if(e._transformState.transforming)throw new i;return e.push(null)}e("inherits")(u,c),u.prototype.push=function(e,t){return this._transformState.needTransform=!1,c.prototype.push.call(this,e,t)},u.prototype._transform=function(e,t,n){n(new o("_transform()"))},u.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var o=this._readableState;(r.needTransform||o.needReadable||o.length<o.highWaterMark)&&this._read(o.highWaterMark)}},u.prototype._read=function(e){var t=this._transformState;null===t.writechunk||t.transforming?t.needTransform=!0:(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform))},u.prototype._destroy=function(e,t){c.prototype._destroy.call(this,e,(function(e){t(e)}))}},{"../errors":55,"./_stream_duplex":56,inherits:24}],60:[function(e,t,n){(function(n,r){(function(){function o(e){var t=this;this.next=null,this.entry=null,this.finish=function(){H(t,e)}}var s;t.exports=I,I.WritableState=E;var i={deprecate:e("util-deprecate")},a=e("./internal/streams/stream"),c=e("buffer").Buffer,l=r.Uint8Array||function(){};function u(e){return c.from(e)}function d(e){return c.isBuffer(e)||e instanceof l}var h,f=e("./internal/streams/destroy"),p=e("./internal/streams/state").getHighWaterMark,g=e("../errors").codes,m=g.ERR_INVALID_ARG_TYPE,y=g.ERR_METHOD_NOT_IMPLEMENTED,v=g.ERR_MULTIPLE_CALLBACK,b=g.ERR_STREAM_CANNOT_PIPE,w=g.ERR_STREAM_DESTROYED,C=g.ERR_STREAM_NULL_VALUES,_=g.ERR_STREAM_WRITE_AFTER_END,k=g.ERR_UNKNOWN_ENCODING,S=f.errorOrDestroy;function A(){}function E(t,n,r){s=s||e("./_stream_duplex"),t=t||{},"boolean"!=typeof r&&(r=n instanceof s),this.objectMode=!!t.objectMode,r&&(this.objectMode=this.objectMode||!!t.writableObjectMode),this.highWaterMark=p(this,t,"writableHighWaterMark",r),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var i=!1===t.decodeStrings;this.decodeStrings=!i,this.defaultEncoding=t.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){F(n,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==t.emitClose,this.autoDestroy=!!t.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new o(this)}function I(t){var n=this instanceof(s=s||e("./_stream_duplex"));if(!n&&!h.call(I,this))return new I(t);this._writableState=new E(t,this,n),this.writable=!0,t&&("function"==typeof t.write&&(this._write=t.write),"function"==typeof t.writev&&(this._writev=t.writev),"function"==typeof t.destroy&&(this._destroy=t.destroy),"function"==typeof t.final&&(this._final=t.final)),a.call(this)}function O(e,t){var r=new _;S(e,r),n.nextTick(t,r)}function T(e,t,r,o){var s;return null===r?s=new C:"string"==typeof r||t.objectMode||(s=new m("chunk",["string","Buffer"],r)),!s||(S(e,s),n.nextTick(o,s),!1)}function x(e,t,n){return e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=c.from(t,n)),t}function R(e,t,n,r,o,s){if(!n){var i=x(t,r,o);r!==i&&(n=!0,o="buffer",r=i)}var a=t.objectMode?1:r.length;t.length+=a;var c=t.length<t.highWaterMark;if(c||(t.needDrain=!0),t.writing||t.corked){var l=t.lastBufferedRequest;t.lastBufferedRequest={chunk:r,encoding:o,isBuf:n,callback:s,next:null},l?l.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else P(e,t,!1,a,r,o,s);return c}function P(e,t,n,r,o,s,i){t.writelen=r,t.writecb=i,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new w("write")):n?e._writev(o,t.onwrite):e._write(o,s,t.onwrite),t.sync=!1}function M(e,t,r,o,s){--t.pendingcb,r?(n.nextTick(s,o),n.nextTick($,e,t),e._writableState.errorEmitted=!0,S(e,o)):(s(o),e._writableState.errorEmitted=!0,S(e,o),$(e,t))}function j(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function F(e,t){var r=e._writableState,o=r.sync,s=r.writecb;if("function"!=typeof s)throw new v;if(j(r),t)M(e,r,o,t,s);else{var i=D(r)||e.destroyed;i||r.corked||r.bufferProcessing||!r.bufferedRequest||U(e,r),o?n.nextTick(N,e,r,i,s):N(e,r,i,s)}}function N(e,t,n,r){n||B(e,t),t.pendingcb--,r(),$(e,t)}function B(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function U(e,t){t.bufferProcessing=!0;var n=t.bufferedRequest;if(e._writev&&n&&n.next){var r=t.bufferedRequestCount,s=new Array(r),i=t.corkedRequestsFree;i.entry=n;for(var a=0,c=!0;n;)s[a]=n,n.isBuf||(c=!1),n=n.next,a+=1;s.allBuffers=c,P(e,t,!0,t.length,s,"",i.finish),t.pendingcb++,t.lastBufferedRequest=null,i.next?(t.corkedRequestsFree=i.next,i.next=null):t.corkedRequestsFree=new o(t),t.bufferedRequestCount=0}else{for(;n;){var l=n.chunk,u=n.encoding,d=n.callback;if(P(e,t,!1,t.objectMode?1:l.length,l,u,d),n=n.next,t.bufferedRequestCount--,t.writing)break}null===n&&(t.lastBufferedRequest=null)}t.bufferedRequest=n,t.bufferProcessing=!1}function D(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function L(e,t){e._final((function(n){t.pendingcb--,n&&S(e,n),t.prefinished=!0,e.emit("prefinish"),$(e,t)}))}function q(e,t){t.prefinished||t.finalCalled||("function"!=typeof e._final||t.destroyed?(t.prefinished=!0,e.emit("prefinish")):(t.pendingcb++,t.finalCalled=!0,n.nextTick(L,e,t)))}function $(e,t){var n=D(t);if(n&&(q(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"),t.autoDestroy))){var r=e._readableState;(!r||r.autoDestroy&&r.endEmitted)&&e.destroy()}return n}function z(e,t,r){t.ending=!0,$(e,t),r&&(t.finished?n.nextTick(r):e.once("finish",r)),t.ended=!0,e.writable=!1}function H(e,t,n){var r=e.entry;for(e.entry=null;r;){var o=r.callback;t.pendingcb--,o(n),r=r.next}t.corkedRequestsFree.next=e}e("inherits")(I,a),E.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(E.prototype,"buffer",{get:i.deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(h=Function.prototype[Symbol.hasInstance],Object.defineProperty(I,Symbol.hasInstance,{value:function(e){return!!h.call(this,e)||this===I&&e&&e._writableState instanceof E}})):h=function(e){return e instanceof this},I.prototype.pipe=function(){S(this,new b)},I.prototype.write=function(e,t,n){var r=this._writableState,o=!1,s=!r.objectMode&&d(e);return s&&!c.isBuffer(e)&&(e=u(e)),"function"==typeof t&&(n=t,t=null),s?t="buffer":t||(t=r.defaultEncoding),"function"!=typeof n&&(n=A),r.ending?O(this,n):(s||T(this,r,e,n))&&(r.pendingcb++,o=R(this,r,s,e,t,n)),o},I.prototype.cork=function(){this._writableState.corked++},I.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.bufferProcessing||!e.bufferedRequest||U(this,e))},I.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new k(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(I.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(I.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),I.prototype._write=function(e,t,n){n(new y("_write()"))},I.prototype._writev=null,I.prototype.end=function(e,t,n){var r=this._writableState;return"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||z(this,r,n),this},Object.defineProperty(I.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(I.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),I.prototype.destroy=f.destroy,I.prototype._undestroy=f.undestroy,I.prototype._destroy=function(e,t){t(e)}}).call(this)}).call(this,e("_process"),void 0!==_e?_e:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../errors":55,"./_stream_duplex":56,"./internal/streams/destroy":63,"./internal/streams/state":67,"./internal/streams/stream":68,_process:50,buffer:17,inherits:24,"util-deprecate":78}],61:[function(e,t,n){(function(n){(function(){var r;function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var s=e("./end-of-stream"),i=Symbol("lastResolve"),a=Symbol("lastReject"),c=Symbol("error"),l=Symbol("ended"),u=Symbol("lastPromise"),d=Symbol("handlePromise"),h=Symbol("stream");function f(e,t){return{value:e,done:t}}function p(e){var t=e[i];if(null!==t){var n=e[h].read();null!==n&&(e[u]=null,e[i]=null,e[a]=null,t(f(n,!1)))}}function g(e){n.nextTick(p,e)}function m(e,t){return function(n,r){e.then((function(){t[l]?n(f(void 0,!0)):t[d](n,r)}),r)}}var y=Object.getPrototypeOf((function(){})),v=Object.setPrototypeOf((o(r={get stream(){return this[h]},next:function(){var e=this,t=this[c];if(null!==t)return Promise.reject(t);if(this[l])return Promise.resolve(f(void 0,!0));if(this[h].destroyed)return new Promise((function(t,r){n.nextTick((function(){e[c]?r(e[c]):t(f(void 0,!0))}))}));var r,o=this[u];if(o)r=new Promise(m(o,this));else{var s=this[h].read();if(null!==s)return Promise.resolve(f(s,!1));r=new Promise(this[d])}return this[u]=r,r}},Symbol.asyncIterator,(function(){return this})),o(r,"return",(function(){var e=this;return new Promise((function(t,n){e[h].destroy(null,(function(e){e?n(e):t(f(void 0,!0))}))}))})),r),y),b=function(e){var t,n=Object.create(v,(o(t={},h,{value:e,writable:!0}),o(t,i,{value:null,writable:!0}),o(t,a,{value:null,writable:!0}),o(t,c,{value:null,writable:!0}),o(t,l,{value:e._readableState.endEmitted,writable:!0}),o(t,d,{value:function(e,t){var r=n[h].read();r?(n[u]=null,n[i]=null,n[a]=null,e(f(r,!1))):(n[i]=e,n[a]=t)},writable:!0}),t));return n[u]=null,s(e,(function(e){if(e&&"ERR_STREAM_PREMATURE_CLOSE"!==e.code){var t=n[a];return null!==t&&(n[u]=null,n[i]=null,n[a]=null,t(e)),void(n[c]=e)}var r=n[i];null!==r&&(n[u]=null,n[i]=null,n[a]=null,r(f(void 0,!0))),n[l]=!0})),e.on("readable",g.bind(null,n)),n};t.exports=b}).call(this)}).call(this,e("_process"))},{"./end-of-stream":64,_process:50}],62:[function(e,t,n){function r(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 o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){s(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(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 c(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}var l=e("buffer").Buffer,u=e("util").inspect,d=u&&u.custom||"inspect";function h(e,t,n){l.prototype.copy.call(e,t,n)}t.exports=function(){function e(){i(this,e),this.head=null,this.tail=null,this.length=0}return c(e,[{key:"push",value:function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(e){if(0===this.length)return"";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n}},{key:"concat",value:function(e){if(0===this.length)return l.alloc(0);for(var t=l.allocUnsafe(e>>>0),n=this.head,r=0;n;)h(n.data,t,r),r+=n.data.length,n=n.next;return t}},{key:"consume",value:function(e,t){var n;return e<this.head.data.length?(n=this.head.data.slice(0,e),this.head.data=this.head.data.slice(e)):n=e===this.head.data.length?this.shift():t?this._getString(e):this._getBuffer(e),n}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(e){var t=this.head,n=1,r=t.data;for(e-=r.length;t=t.next;){var o=t.data,s=e>o.length?o.length:e;if(s===o.length?r+=o:r+=o.slice(0,e),0==(e-=s)){s===o.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=o.slice(s));break}++n}return this.length-=n,r}},{key:"_getBuffer",value:function(e){var t=l.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var o=n.data,s=e>o.length?o.length:e;if(o.copy(t,t.length-e,0,s),0==(e-=s)){s===o.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=o.slice(s));break}++r}return this.length-=r,t}},{key:d,value:function(e,t){return u(this,o({},t,{depth:0,customInspect:!1}))}}]),e}()},{buffer:17,util:16}],63:[function(e,t,n){(function(e){(function(){function n(t,n){var s=this,a=this._readableState&&this._readableState.destroyed,c=this._writableState&&this._writableState.destroyed;return a||c?(n?n(t):t&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,e.nextTick(i,this,t)):e.nextTick(i,this,t)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(t||null,(function(t){!n&&t?s._writableState?s._writableState.errorEmitted?e.nextTick(o,s):(s._writableState.errorEmitted=!0,e.nextTick(r,s,t)):e.nextTick(r,s,t):n?(e.nextTick(o,s),n(t)):e.nextTick(o,s)})),this)}function r(e,t){i(e,t),o(e)}function o(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function s(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function i(e,t){e.emit("error",t)}function a(e,t){var n=e._readableState,r=e._writableState;n&&n.autoDestroy||r&&r.autoDestroy?e.destroy(t):e.emit("error",t)}t.exports={destroy:n,undestroy:s,errorOrDestroy:a}}).call(this)}).call(this,e("_process"))},{_process:50}],64:[function(e,t,n){var r=e("../../../errors").codes.ERR_STREAM_PREMATURE_CLOSE;function o(e){var t=!1;return function(){if(!t){t=!0;for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];e.apply(this,r)}}}function s(){}function i(e){return e.setHeader&&"function"==typeof e.abort}function a(e,t,n){if("function"==typeof t)return a(e,null,t);t||(t={}),n=o(n||s);var c=t.readable||!1!==t.readable&&e.readable,l=t.writable||!1!==t.writable&&e.writable,u=function(){e.writable||h()},d=e._writableState&&e._writableState.finished,h=function(){l=!1,d=!0,c||n.call(e)},f=e._readableState&&e._readableState.endEmitted,p=function(){c=!1,f=!0,l||n.call(e)},g=function(t){n.call(e,t)},m=function(){var t;return c&&!f?(e._readableState&&e._readableState.ended||(t=new r),n.call(e,t)):l&&!d?(e._writableState&&e._writableState.ended||(t=new r),n.call(e,t)):void 0},y=function(){e.req.on("finish",h)};return i(e)?(e.on("complete",h),e.on("abort",m),e.req?y():e.on("request",y)):l&&!e._writableState&&(e.on("end",u),e.on("close",u)),e.on("end",p),e.on("finish",h),!1!==t.error&&e.on("error",g),e.on("close",m),function(){e.removeListener("complete",h),e.removeListener("abort",m),e.removeListener("request",y),e.req&&e.req.removeListener("finish",h),e.removeListener("end",u),e.removeListener("close",u),e.removeListener("finish",h),e.removeListener("end",p),e.removeListener("error",g),e.removeListener("close",m)}}t.exports=a},{"../../../errors":55}],65:[function(e,t,n){t.exports=function(){throw new Error("Readable.from is not available in the browser")}},{}],66:[function(e,t,n){var r;function o(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var s=e("../../../errors").codes,i=s.ERR_MISSING_ARGS,a=s.ERR_STREAM_DESTROYED;function c(e){if(e)throw e}function l(e){return e.setHeader&&"function"==typeof e.abort}function u(t,n,s,i){i=o(i);var c=!1;t.on("close",(function(){c=!0})),void 0===r&&(r=e("./end-of-stream")),r(t,{readable:n,writable:s},(function(e){if(e)return i(e);c=!0,i()}));var u=!1;return function(e){if(!c&&!u)return u=!0,l(t)?t.abort():"function"==typeof t.destroy?t.destroy():void i(e||new a("pipe"))}}function d(e){e()}function h(e,t){return e.pipe(t)}function f(e){return e.length?"function"!=typeof e[e.length-1]?c:e.pop():c}function p(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r,o=f(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new i("streams");var s=t.map((function(e,n){var i=n<t.length-1;return u(e,i,n>0,(function(e){r||(r=e),e&&s.forEach(d),i||(s.forEach(d),o(r))}))}));return t.reduce(h)}t.exports=p},{"../../../errors":55,"./end-of-stream":64}],67:[function(e,t,n){var r=e("../../../errors").codes.ERR_INVALID_OPT_VALUE;function o(e,t,n){return null!=e.highWaterMark?e.highWaterMark:t?e[n]:null}function s(e,t,n,s){var i=o(t,s,n);if(null!=i){if(!isFinite(i)||Math.floor(i)!==i||i<0)throw new r(s?n:"highWaterMark",i);return Math.floor(i)}return e.objectMode?16:16384}t.exports={getHighWaterMark:s}},{"../../../errors":55}],68:[function(e,t,n){t.exports=e("events").EventEmitter},{events:22}],69:[function(e,t,n){(n=t.exports=e("./lib/_stream_readable.js")).Stream=n,n.Readable=n,n.Writable=e("./lib/_stream_writable.js"),n.Duplex=e("./lib/_stream_duplex.js"),n.Transform=e("./lib/_stream_transform.js"),n.PassThrough=e("./lib/_stream_passthrough.js"),n.finished=e("./lib/internal/streams/end-of-stream.js"),n.pipeline=e("./lib/internal/streams/pipeline.js")},{"./lib/_stream_duplex.js":56,"./lib/_stream_passthrough.js":57,"./lib/_stream_readable.js":58,"./lib/_stream_transform.js":59,"./lib/_stream_writable.js":60,"./lib/internal/streams/end-of-stream.js":64,"./lib/internal/streams/pipeline.js":66}],70:[function(e,t,n){function r(e,t,n){var r=this;this._callback=e,this._args=n,this._interval=setInterval(e,t,this._args),this.reschedule=function(e){e||(e=r._interval),r._interval&&clearInterval(r._interval),r._interval=setInterval(r._callback,e,r._args)},this.clear=function(){r._interval&&(clearInterval(r._interval),r._interval=void 0)},this.destroy=function(){r._interval&&clearInterval(r._interval),r._callback=void 0,r._interval=void 0,r._args=void 0}}function o(){if("function"!=typeof arguments[0])throw new Error("callback needed");if("number"!=typeof arguments[1])throw new Error("interval needed");var e;if(arguments.length>0){e=new Array(arguments.length-2);for(var t=0;t<e.length;t++)e[t]=arguments[t+2]}return new r(arguments[0],arguments[1],e)}t.exports=o},{}],71:[function(e,t,n){t.exports=e("./index.js")()},{"./index.js":72}],72:[function(e,t,n){(function(e){(function(){function n(t){return t instanceof e?e.from(t):new t.constructor(t.buffer.slice(),t.byteOffset,t.length)}function r(e){return(e=e||{}).circles?o(e):e.proto?s:r;function t(e,t){for(var r=Object.keys(e),o=new Array(r.length),s=0;s<r.length;s++){var i=r[s],a=e[i];"object"!=typeof a||null===a?o[i]=a:a instanceof Date?o[i]=new Date(a):ArrayBuffer.isView(a)?o[i]=n(a):o[i]=t(a)}return o}function r(e){if("object"!=typeof e||null===e)return e;if(e instanceof Date)return new Date(e);if(Array.isArray(e))return t(e,r);if(e instanceof Map)return new Map(t(Array.from(e),r));if(e instanceof Set)return new Set(t(Array.from(e),r));var o={};for(var s in e)if(!1!==Object.hasOwnProperty.call(e,s)){var i=e[s];"object"!=typeof i||null===i?o[s]=i:i instanceof Date?o[s]=new Date(i):i instanceof Map?o[s]=new Map(t(Array.from(i),r)):i instanceof Set?o[s]=new Set(t(Array.from(i),r)):ArrayBuffer.isView(i)?o[s]=n(i):o[s]=r(i)}return o}function s(e){if("object"!=typeof e||null===e)return e;if(e instanceof Date)return new Date(e);if(Array.isArray(e))return t(e,s);if(e instanceof Map)return new Map(t(Array.from(e),s));if(e instanceof Set)return new Set(t(Array.from(e),s));var r={};for(var o in e){var i=e[o];"object"!=typeof i||null===i?r[o]=i:i instanceof Date?r[o]=new Date(i):i instanceof Map?r[o]=new Map(t(Array.from(i),s)):i instanceof Set?r[o]=new Set(t(Array.from(i),s)):ArrayBuffer.isView(i)?r[o]=n(i):r[o]=s(i)}return r}}function o(e){var t=[],r=[];return e.proto?i:s;function o(e,o){for(var s=Object.keys(e),i=new Array(s.length),a=0;a<s.length;a++){var c=s[a],l=e[c];if("object"!=typeof l||null===l)i[c]=l;else if(l instanceof Date)i[c]=new Date(l);else if(ArrayBuffer.isView(l))i[c]=n(l);else{var u=t.indexOf(l);i[c]=-1!==u?r[u]:o(l)}}return i}function s(e){if("object"!=typeof e||null===e)return e;if(e instanceof Date)return new Date(e);if(Array.isArray(e))return o(e,s);if(e instanceof Map)return new Map(o(Array.from(e),s));if(e instanceof Set)return new Set(o(Array.from(e),s));var i={};for(var a in t.push(e),r.push(i),e)if(!1!==Object.hasOwnProperty.call(e,a)){var c=e[a];if("object"!=typeof c||null===c)i[a]=c;else if(c instanceof Date)i[a]=new Date(c);else if(c instanceof Map)i[a]=new Map(o(Array.from(c),s));else if(c instanceof Set)i[a]=new Set(o(Array.from(c),s));else if(ArrayBuffer.isView(c))i[a]=n(c);else{var l=t.indexOf(c);i[a]=-1!==l?r[l]:s(c)}}return t.pop(),r.pop(),i}function i(e){if("object"!=typeof e||null===e)return e;if(e instanceof Date)return new Date(e);if(Array.isArray(e))return o(e,i);if(e instanceof Map)return new Map(o(Array.from(e),i));if(e instanceof Set)return new Set(o(Array.from(e),i));var s={};for(var a in t.push(e),r.push(s),e){var c=e[a];if("object"!=typeof c||null===c)s[a]=c;else if(c instanceof Date)s[a]=new Date(c);else if(c instanceof Map)s[a]=new Map(o(Array.from(c),i));else if(c instanceof Set)s[a]=new Set(o(Array.from(c),i));else if(ArrayBuffer.isView(c))s[a]=n(c);else{var l=t.indexOf(c);s[a]=-1!==l?r[l]:i(c)}}return t.pop(),r.pop(),s}}t.exports=r}).call(this)}).call(this,e("buffer").Buffer)},{buffer:17}],73:[function(e,t,n){
5
5
  /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
6
- var r=e("buffer"),o=r.Buffer;function s(e,t){for(var n in e)t[n]=e[n]}function i(e,t,n){return o(e,t,n)}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?t.exports=r:(s(r,n),n.Buffer=i),i.prototype=Object.create(o.prototype),s(o,i),i.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return o(e,t,n)},i.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var r=o(e);return void 0!==t?"string"==typeof n?r.fill(t,n):r.fill(t):r.fill(0),r},i.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o(e)},i.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}},{buffer:17}],74:[function(e,t,n){function r(e){var t=e._readableState;return t?t.objectMode||"number"==typeof e._duplexState?e.read():e.read(o(t)):null}function o(e){return e.buffer.length?e.buffer.head?e.buffer.head.data.length:e.buffer[0].length:e.length}t.exports=r},{}],75:[function(e,t,n){var r=e("safe-buffer").Buffer,o=r.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function s(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}function i(e){var t=s(e);if("string"!=typeof t&&(r.isEncoding===o||!o(e)))throw new Error("Unknown encoding: "+e);return t||e}function a(e){var t;switch(this.encoding=i(e),this.encoding){case"utf16le":this.text=p,this.end=g,t=4;break;case"utf8":this.fillLast=d,t=4;break;case"base64":this.text=m,this.end=y,t=3;break;default:return this.write=v,void(this.end=b)}this.lastNeed=0,this.lastTotal=0,this.lastChar=r.allocUnsafe(t)}function c(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function l(e,t,n){var r=t.length-1;if(r<n)return 0;var o=c(t[r]);return o>=0?(o>0&&(e.lastNeed=o-1),o):--r<n||-2===o?0:(o=c(t[r]))>=0?(o>0&&(e.lastNeed=o-2),o):--r<n||-2===o?0:(o=c(t[r]))>=0?(o>0&&(2===o?o=0:e.lastNeed=o-3),o):0}function u(e,t,n){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}function d(e){var t=this.lastTotal-this.lastNeed,n=u(this,e);return void 0!==n?n:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function h(e,t){var n=l(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=n;var r=e.length-(n-this.lastNeed);return e.copy(this.lastChar,0,r),e.toString("utf8",t,r)}function f(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function p(e,t){if((e.length-t)%2==0){var n=e.toString("utf16le",t);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function g(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,n)}return t}function m(e,t){var n=(e.length-t)%3;return 0===n?e.toString("base64",t):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-n))}function y(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function v(e){return e.toString(this.encoding)}function b(e){return e&&e.length?this.write(e):""}n.StringDecoder=a,a.prototype.write=function(e){if(0===e.length)return"";var t,n;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n<e.length?t?t+this.text(e,n):this.text(e,n):t||""},a.prototype.end=f,a.prototype.text=h,a.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}},{"safe-buffer":73}],76:[function(e,t,n){var r=e("punycode"),o=e("./util");function s(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}n.parse=w,n.resolve=_,n.resolveObject=k,n.format=C,n.Url=s;var i=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,l=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),u=["'"].concat(l),d=["%","/","?",";","#"].concat(u),h=["/","?","#"],f=255,p=/^[+a-z0-9A-Z_-]{0,63}$/,g=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,m={javascript:!0,"javascript:":!0},y={javascript:!0,"javascript:":!0},v={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},b=e("querystring");function w(e,t,n){if(e&&o.isObject(e)&&e instanceof s)return e;var r=new s;return r.parse(e,t,n),r}function C(e){return o.isString(e)&&(e=w(e)),e instanceof s?e.format():s.prototype.format.call(e)}function _(e,t){return w(e,!1,!0).resolve(t)}function k(e,t){return e?w(e,!1,!0).resolveObject(t):t}s.prototype.parse=function(e,t,n){if(!o.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var s=e.indexOf("?"),a=-1!==s&&s<e.indexOf("#")?"?":"#",l=e.split(a),w=/\\/g;l[0]=l[0].replace(w,"/");var C=e=l.join(a);if(C=C.trim(),!n&&1===e.split("#").length){var _=c.exec(C);if(_)return this.path=C,this.href=C,this.pathname=_[1],_[2]?(this.search=_[2],this.query=t?b.parse(this.search.substr(1)):this.search.substr(1)):t&&(this.search="",this.query={}),this}var k=i.exec(C);if(k){var S=(k=k[0]).toLowerCase();this.protocol=S,C=C.substr(k.length)}if(n||k||C.match(/^\/\/[^@\/]+@[^@\/]+/)){var A="//"===C.substr(0,2);!A||k&&y[k]||(C=C.substr(2),this.slashes=!0)}if(!y[k]&&(A||k&&!v[k])){for(var E,I,O=-1,T=0;T<h.length;T++)-1!==(x=C.indexOf(h[T]))&&(-1===O||x<O)&&(O=x);for(-1!==(I=-1===O?C.lastIndexOf("@"):C.lastIndexOf("@",O))&&(E=C.slice(0,I),C=C.slice(I+1),this.auth=decodeURIComponent(E)),O=-1,T=0;T<d.length;T++){var x;-1!==(x=C.indexOf(d[T]))&&(-1===O||x<O)&&(O=x)}-1===O&&(O=C.length),this.host=C.slice(0,O),C=C.slice(O),this.parseHost(),this.hostname=this.hostname||"";var R="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!R)for(var P=this.hostname.split(/\./),M=(T=0,P.length);T<M;T++){var j=P[T];if(j&&!j.match(p)){for(var F="",N=0,B=j.length;N<B;N++)j.charCodeAt(N)>127?F+="x":F+=j[N];if(!F.match(p)){var U=P.slice(0,T),D=P.slice(T+1),L=j.match(g);L&&(U.push(L[1]),D.unshift(L[2])),D.length&&(C="/"+D.join(".")+C),this.hostname=U.join(".");break}}}this.hostname.length>f?this.hostname="":this.hostname=this.hostname.toLowerCase(),R||(this.hostname=r.toASCII(this.hostname));var q=this.port?":"+this.port:"",$=this.hostname||"";this.host=$+q,this.href+=this.host,R&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==C[0]&&(C="/"+C))}if(!m[S])for(T=0,M=u.length;T<M;T++){var z=u[T];if(-1!==C.indexOf(z)){var H=encodeURIComponent(z);H===z&&(H=escape(z)),C=C.split(z).join(H)}}var V=C.indexOf("#");-1!==V&&(this.hash=C.substr(V),C=C.slice(0,V));var W=C.indexOf("?");if(-1!==W?(this.search=C.substr(W),this.query=C.substr(W+1),t&&(this.query=b.parse(this.query)),C=C.slice(0,W)):t&&(this.search="",this.query={}),C&&(this.pathname=C),v[S]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){q=this.pathname||"";var K=this.search||"";this.path=q+K}return this.href=this.format(),this},s.prototype.format=function(){var e=this.auth||"";e&&(e=(e=encodeURIComponent(e)).replace(/%3A/i,":"),e+="@");var t=this.protocol||"",n=this.pathname||"",r=this.hash||"",s=!1,i="";this.host?s=e+this.host:this.hostname&&(s=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(s+=":"+this.port)),this.query&&o.isObject(this.query)&&Object.keys(this.query).length&&(i=b.stringify(this.query));var a=this.search||i&&"?"+i||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||v[t])&&!1!==s?(s="//"+(s||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):s||(s=""),r&&"#"!==r.charAt(0)&&(r="#"+r),a&&"?"!==a.charAt(0)&&(a="?"+a),t+s+(n=n.replace(/[?#]/g,(function(e){return encodeURIComponent(e)})))+(a=a.replace("#","%23"))+r},s.prototype.resolve=function(e){return this.resolveObject(w(e,!1,!0)).format()},s.prototype.resolveObject=function(e){if(o.isString(e)){var t=new s;t.parse(e,!1,!0),e=t}for(var n=new s,r=Object.keys(this),i=0;i<r.length;i++){var a=r[i];n[a]=this[a]}if(n.hash=e.hash,""===e.href)return n.href=n.format(),n;if(e.slashes&&!e.protocol){for(var c=Object.keys(e),l=0;l<c.length;l++){var u=c[l];"protocol"!==u&&(n[u]=e[u])}return v[n.protocol]&&n.hostname&&!n.pathname&&(n.path=n.pathname="/"),n.href=n.format(),n}if(e.protocol&&e.protocol!==n.protocol){if(!v[e.protocol]){for(var d=Object.keys(e),h=0;h<d.length;h++){var f=d[h];n[f]=e[f]}return n.href=n.format(),n}if(n.protocol=e.protocol,e.host||y[e.protocol])n.pathname=e.pathname;else{for(var p=(e.pathname||"").split("/");p.length&&!(e.host=p.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==p[0]&&p.unshift(""),p.length<2&&p.unshift(""),n.pathname=p.join("/")}if(n.search=e.search,n.query=e.query,n.host=e.host||"",n.auth=e.auth,n.hostname=e.hostname||e.host,n.port=e.port,n.pathname||n.search){var g=n.pathname||"",m=n.search||"";n.path=g+m}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var b=n.pathname&&"/"===n.pathname.charAt(0),w=e.host||e.pathname&&"/"===e.pathname.charAt(0),C=w||b||n.host&&e.pathname,_=C,k=n.pathname&&n.pathname.split("/")||[],S=(p=e.pathname&&e.pathname.split("/")||[],n.protocol&&!v[n.protocol]);if(S&&(n.hostname="",n.port=null,n.host&&(""===k[0]?k[0]=n.host:k.unshift(n.host)),n.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===p[0]?p[0]=e.host:p.unshift(e.host)),e.host=null),C=C&&(""===p[0]||""===k[0])),w)n.host=e.host||""===e.host?e.host:n.host,n.hostname=e.hostname||""===e.hostname?e.hostname:n.hostname,n.search=e.search,n.query=e.query,k=p;else if(p.length)k||(k=[]),k.pop(),k=k.concat(p),n.search=e.search,n.query=e.query;else if(!o.isNullOrUndefined(e.search))return S&&(n.hostname=n.host=k.shift(),(T=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=T.shift(),n.host=n.hostname=T.shift())),n.search=e.search,n.query=e.query,o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n;if(!k.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var A=k.slice(-1)[0],E=(n.host||e.host||k.length>1)&&("."===A||".."===A)||""===A,I=0,O=k.length;O>=0;O--)"."===(A=k[O])?k.splice(O,1):".."===A?(k.splice(O,1),I++):I&&(k.splice(O,1),I--);if(!C&&!_)for(;I--;I)k.unshift("..");!C||""===k[0]||k[0]&&"/"===k[0].charAt(0)||k.unshift(""),E&&"/"!==k.join("/").substr(-1)&&k.push("");var T,x=""===k[0]||k[0]&&"/"===k[0].charAt(0);return S&&(n.hostname=n.host=x?"":k.length?k.shift():"",(T=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=T.shift(),n.host=n.hostname=T.shift())),(C=C||n.host&&k.length)&&!x&&k.unshift(""),k.length?n.pathname=k.join("/"):(n.pathname=null,n.path=null),o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},s.prototype.parseHost=function(){var e=this.host,t=a.exec(e);t&&(":"!==(t=t[0])&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},{"./util":77,punycode:51,querystring:54}],77:[function(e,t,n){t.exports={isString:function(e){return"string"==typeof e},isObject:function(e){return"object"==typeof e&&null!==e},isNull:function(e){return null===e},isNullOrUndefined:function(e){return null==e}}},{}],78:[function(e,t,n){(function(e){(function(){function n(e,t){if(r("noDeprecation"))return e;var n=!1;function o(){if(!n){if(r("throwDeprecation"))throw new Error(t);r("traceDeprecation")?console.trace(t):console.warn(t),n=!0}return e.apply(this,arguments)}return o}function r(t){try{if(!e.localStorage)return!1}catch(e){return!1}var n=e.localStorage[t];return null!=n&&"true"===String(n).toLowerCase()}t.exports=n}).call(this)}).call(this,void 0!==_e?_e:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],79:[function(e,t,n){function r(e,t){if(e&&t)return r(e)(t);if("function"!=typeof e)throw new TypeError("need wrapper function");return Object.keys(e).forEach((function(t){n[t]=e[t]})),n;function n(){for(var t=new Array(arguments.length),n=0;n<t.length;n++)t[n]=arguments[n];var r=e.apply(this,t),o=t[t.length-1];return"function"==typeof r&&r!==o&&Object.keys(o).forEach((function(e){r[e]=o[e]})),r}}t.exports=r},{}],80:[function(e,t,n){t.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},{}],81:[function(e,t,n){t.exports=o;var r=Object.prototype.hasOwnProperty;function o(){for(var e={},t=0;t<arguments.length;t++){var n=arguments[t];for(var o in n)r.call(n,o)&&(e[o]=n[o])}return e}},{}],82:[function(e,t,n){t.exports=function(e){e.prototype[Symbol.iterator]=function*(){for(let e=this.head;e;e=e.next)yield e.value}}},{}],83:[function(e,t,n){function r(e){var t=this;if(t instanceof r||(t=new r),t.tail=null,t.head=null,t.length=0,e&&"function"==typeof e.forEach)e.forEach((function(e){t.push(e)}));else if(arguments.length>0)for(var n=0,o=arguments.length;n<o;n++)t.push(arguments[n]);return t}function o(e,t,n){var r=t===e.head?new a(n,null,t,e):new a(n,t,t.next,e);return null===r.next&&(e.tail=r),null===r.prev&&(e.head=r),e.length++,r}function s(e,t){e.tail=new a(t,e.tail,null,e),e.head||(e.head=e.tail),e.length++}function i(e,t){e.head=new a(t,null,e.head,e),e.tail||(e.tail=e.head),e.length++}function a(e,t,n,r){if(!(this instanceof a))return new a(e,t,n,r);this.list=r,this.value=e,t?(t.next=this,this.prev=t):this.prev=null,n?(n.prev=this,this.next=n):this.next=null}t.exports=r,r.Node=a,r.create=r,r.prototype.removeNode=function(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");var t=e.next,n=e.prev;return t&&(t.prev=n),n&&(n.next=t),e===this.head&&(this.head=t),e===this.tail&&(this.tail=n),e.list.length--,e.next=null,e.prev=null,e.list=null,t},r.prototype.unshiftNode=function(e){if(e!==this.head){e.list&&e.list.removeNode(e);var t=this.head;e.list=this,e.next=t,t&&(t.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}},r.prototype.pushNode=function(e){if(e!==this.tail){e.list&&e.list.removeNode(e);var t=this.tail;e.list=this,e.prev=t,t&&(t.next=e),this.tail=e,this.head||(this.head=e),this.length++}},r.prototype.push=function(){for(var e=0,t=arguments.length;e<t;e++)s(this,arguments[e]);return this.length},r.prototype.unshift=function(){for(var e=0,t=arguments.length;e<t;e++)i(this,arguments[e]);return this.length},r.prototype.pop=function(){if(this.tail){var e=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,e}},r.prototype.shift=function(){if(this.head){var e=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,e}},r.prototype.forEach=function(e,t){t=t||this;for(var n=this.head,r=0;null!==n;r++)e.call(t,n.value,r,this),n=n.next},r.prototype.forEachReverse=function(e,t){t=t||this;for(var n=this.tail,r=this.length-1;null!==n;r--)e.call(t,n.value,r,this),n=n.prev},r.prototype.get=function(e){for(var t=0,n=this.head;null!==n&&t<e;t++)n=n.next;if(t===e&&null!==n)return n.value},r.prototype.getReverse=function(e){for(var t=0,n=this.tail;null!==n&&t<e;t++)n=n.prev;if(t===e&&null!==n)return n.value},r.prototype.map=function(e,t){t=t||this;for(var n=new r,o=this.head;null!==o;)n.push(e.call(t,o.value,this)),o=o.next;return n},r.prototype.mapReverse=function(e,t){t=t||this;for(var n=new r,o=this.tail;null!==o;)n.push(e.call(t,o.value,this)),o=o.prev;return n},r.prototype.reduce=function(e,t){var n,r=this.head;if(arguments.length>1)n=t;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");r=this.head.next,n=this.head.value}for(var o=0;null!==r;o++)n=e(n,r.value,o),r=r.next;return n},r.prototype.reduceReverse=function(e,t){var n,r=this.tail;if(arguments.length>1)n=t;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");r=this.tail.prev,n=this.tail.value}for(var o=this.length-1;null!==r;o--)n=e(n,r.value,o),r=r.prev;return n},r.prototype.toArray=function(){for(var e=new Array(this.length),t=0,n=this.head;null!==n;t++)e[t]=n.value,n=n.next;return e},r.prototype.toArrayReverse=function(){for(var e=new Array(this.length),t=0,n=this.tail;null!==n;t++)e[t]=n.value,n=n.prev;return e},r.prototype.slice=function(e,t){(t=t||this.length)<0&&(t+=this.length),(e=e||0)<0&&(e+=this.length);var n=new r;if(t<e||t<0)return n;e<0&&(e=0),t>this.length&&(t=this.length);for(var o=0,s=this.head;null!==s&&o<e;o++)s=s.next;for(;null!==s&&o<t;o++,s=s.next)n.push(s.value);return n},r.prototype.sliceReverse=function(e,t){(t=t||this.length)<0&&(t+=this.length),(e=e||0)<0&&(e+=this.length);var n=new r;if(t<e||t<0)return n;e<0&&(e=0),t>this.length&&(t=this.length);for(var o=this.length,s=this.tail;null!==s&&o>t;o--)s=s.prev;for(;null!==s&&o>e;o--,s=s.prev)n.push(s.value);return n},r.prototype.splice=function(e,t,...n){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);for(var r=0,s=this.head;null!==s&&r<e;r++)s=s.next;var i=[];for(r=0;s&&r<t;r++)i.push(s.value),s=this.removeNode(s);for(null===s&&(s=this.tail),s!==this.head&&s!==this.tail&&(s=s.prev),r=0;r<n.length;r++)s=o(this,s,n[r]);return i},r.prototype.reverse=function(){for(var e=this.head,t=this.tail,n=e;null!==n;n=n.prev){var r=n.prev;n.prev=n.next,n.next=r}return this.head=t,this.tail=e,this};try{e("./iterator.js")(r)}catch(e){}},{"./iterator.js":82}]},{},[12])(12)}(qi);var $i=ke(qi.exports);var zi;!function(e){e[e.IDENTIFIER_REJECTED=2]="IDENTIFIER_REJECTED",e[e.BAD_USERNAME_OR_PASSWORD=4]="BAD_USERNAME_OR_PASSWORD",e[e.NOT_AUTHORIZED=5]="NOT_AUTHORIZED"}(zi||(zi={}));const Hi=e=>{let t,n=0,r=!0;return{connect:async function(o){return t&&(t.removeAllListeners(),t.end(!0)),t=$i.connect(e,function(e){return Object.assign({clean:!1,clientId:`mqttjs_ + ${Math.random().toString(16).substring(2,10)}`,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:0,will:{topic:"WillMsg",payload:"Connection Closed abnormally..!",qos:0,retain:!1},resubscribe:!0},e)}({username:o.userId,password:o.accessToken})),t.on("connect",(()=>{n=0,r=!0})),t.on("error",(e=>{switch(e.code){case 2:case 4:case 5:r=!1}})),t.on("close",(()=>{r&&setTimeout((()=>{n+=1,t.reconnect()}),1e3*2**(n>10?10:n))})),new Promise((e=>t.once("connect",(()=>e()))))},async disconnect(){if(r=!1,this.connected)return new Promise((e=>null==t?void 0:t.end(!0,void 0,(()=>e()))))},get connected(){return!!(null==t?void 0:t.connected)},on(e,n){null==t||t.on(e,n)},once(e,n){null==t||t.once(e,n)},off(e,n){void 0!==n?null==t||t.off(e,n):null==t||t.removeAllListeners(e)},removeAllListeners(){null==t||t.removeAllListeners()},subscribe(e,n){const r=(t,r)=>{if(t||128===r[0].qos){const r=t?new ge(t.message,8e5,"error"):new ye(8e5,"error");console.warn(`Failed to subscribe to topic ${e}`,r),null==n||n(r)}else console.log(`Subscribed to topic ${r[0].topic}`),null==n||n()};return t?t.subscribe(e,{qos:0},r):r(new Error("No connection to broker"),[]),()=>null==t?void 0:t.unsubscribe(e)},unsubscribe(e){null==t||t.unsubscribe(e)}}},Vi=async()=>{const e=we(),{data:t}=await e.http.get("/api/v3/network-settings/feed-setting");return Object.fromEntries(t.feedSettings.map((({feedType:e,contentSettings:t})=>[e,t])))},Wi=()=>`ascWebSdk#${Math.random().toString(16)}`,Ki=()=>{const e=(()=>{var e,t;return(null===(e=jt.versions)||void 0===e?void 0:e.node)?jt.versions.node:navigator?`${navigator.product.toLowerCase()}#${null!==(t=navigator.userAgent)&&void 0!==t?t:"unknown_agent"}`:"unknown_model"})();return{kind:"web",model:e,sdkVersion:d}},Qi={notLoggedIn:["establishing"],terminated:["establishing"],establishing:["notLoggedIn","established"],established:["notLoggedIn","terminated","tokenExpired","establishing"],tokenExpired:["establishing"]},Ji=e=>{const t=we();t.log("client/api/setSessionState",e);const{sessionState:n}=t;if(n===e)return!1;if(!((e,t)=>Qi[e].includes(t))(n,e))throw new ge(`Session state cannot change from ${n} to ${e}`,8e5,"error");return t.sessionState=e,ut("sessionStateChange",e),!0},Gi=async e=>{const t=we();Ji("establishing");const{accessToken:n,users:r,expiresAt:o,issuedAt:s,refreshToken:i}=await(async e=>{const t=we();t.log("client/api/getToken",e);const n=Ki(),{data:r}=await t.http.post("/api/v4/sessions",Object.assign(Object.assign({},e),{deviceInfo:n}),{headers:{"X-API-Key":t.apiKey}});return r})(e);return t.http.defaults.headers.common.Authorization=`Bearer ${n}`,t.http.defaults.metadata={tokenExpiry:o,isGlobalBanned:!1,isUserDeleted:!1},t.ws.io.opts.query={token:n},t.token={accessToken:n,issuedAt:s,expiresAt:o},Ji("established"),{accessToken:n,users:r,refreshToken:i}},Yi=(e={},t)=>{Object.entries(e).forEach((([e,n])=>{const r=he[e];if(!r)return;const o=ce(r);o&&n.forEach((e=>{ze([r,"get",o(e)],e,t)}))}))};function Xi(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}const Zi=(e,t="userId",n="user")=>{var r;return null!==(r=null==e?void 0:e.map((e=>((e,t="userId",n="user")=>e[n]?e:Object.assign({get[n](){var n;if(!we().cache)return;return(null===(n=Le(["user","get",e[t]]))||void 0===n?void 0:n.data)||void 0}},e))(e,t,n))))&&void 0!==r?r:e},ea=(e,t,n="userId",r="user")=>{const o=e,s=t,i=o[s],a=Xi(o,["symbol"==typeof s?s:s+""]),c=Zi(i,n,r);return Object.assign(Object.assign({},a),{[t]:c})},ta=(e,t)=>{var n,r,o;return(null==t?void 0:t.isDeleted)?0:null!==(o=null!==(n=null==t?void 0:t.unreadCount)&&void 0!==n?n:null===(r=(e=>{var t;const n={entityId:e,userId:ht()._id};return null===(t=Le(["channelMarker","get",ce("channelMarker")(n)]))||void 0===t?void 0:t.data})(e.channelId))||void 0===r?void 0:r.unreadCount)&&void 0!==o?o:0},na=(e,t)=>{var n;return null!==(n=null!=t?t:(e=>{var t,n;const r={creatorId:e.creatorId,feedId:null!==(t=e.messageFeedId)&&void 0!==t?t:e.subChannelId,contentId:e.messageId};return null===(n=Le(["messageMarker","get",ce("messageMarker")(r)]))||void 0===n?void 0:n.data})(e))&&void 0!==n?n:{readCount:0,deliveredCount:0}};function ra(e,t,n){var r;if(n)return n.unreadCount;const o={entityId:e,feedId:t,userId:ht()._id},s=null===(r=Le(["subChannelMarker","get",ce("subChannelMarker")(o)]))||void 0===r?void 0:r.data;return s?s.unreadCount:0}const oa=(e,t)=>{t.length&&ut(e,{userMarkers:t})},sa=(e,t)=>{t.length&&ut(e,{feedMarkers:t})},ia=(e,t)=>{if(!t.length)return;ut(e,{userEntityMarkers:t});const n=function(e){var t;const n=["channel","get",e.entityId],r=null===(t=Le(n))||void 0===t?void 0:t.data;if(!r)return;const o=Object.assign(Object.assign({},r),{unreadCount:ta(r,e),updatedAt:(new Date).toISOString()});return ze(n,o),o}(t[0]);return n&&ut("local.channel.updated",{channels:[n]}),n},aa=(e,t)=>{if(!t.length)return;ut(e,{userFeedMarkers:t});const n=function(e){var t;const n=["subChannel","get",e.feedId],r=null===(t=Le(n))||void 0===t?void 0:t.data;if(!r)return;const o=Object.assign(Object.assign({},r),{unreadCount:ra(r.channelId,r.subChannelId,e),updatedAt:(new Date).toISOString()});return ze(n,o),o}(t[0]);return n&&ut("local.message-feed.updated",{messageFeeds:[n]}),n},ca=(e,t)=>{if(!t.length)return;ut(e,{contentMarkers:t});const n=function(e){var t;const n=["message","get",e.contentId],r=null===(t=Le(n))||void 0===t?void 0:t.data;if(!r)return;const{readCount:o,deliveredCount:s}=na(r,e),i=Object.assign(Object.assign({},r),{readCount:o,deliveredCount:s,updatedAt:(new Date).toISOString()});return ze(n,i),i}(t[0]);return n&&ut("local.message.updated",{messages:[n]}),n},la=async(e,t={limit:100})=>{const n=we();n.log("channel/getChannelMarkers",e,t);const{data:r}=await n.http.get("/api/v1/markers/channels",{params:{channelIds:e,options:{token:J(t,"skiplimit")}}}),{paging:o}=r,s=Xi(r,["paging"]),{userEntityMarkers:i,userMarkers:a}=s,c=n.cache&&Date.now();n.cache&&Yi(s,{cachedAt:c}),ia("local.channelMarker.fetched",i),oa("local.userMarker.fetched",a);const l=G(o.next);return{data:i,cachedAt:c,prevPage:G(o.previous),nextPage:l}},ua=["broadcast","conversation","community"],da=({type:e})=>ua.includes(e);function ha(e,t){return Object.assign(Object.assign({},e),{defaultSubChannelId:e._id,isUnreadCountSupport:da(e),unreadCount:ta(e,t)})}const fa=async e=>{let t=[];const n=e.channels.filter(da).map((({channelId:e})=>e));if(n.length>0){(e=>{Yi({channels:e.channels.map((e=>ha(e)))})})(e);try{({data:t}=await la(n))}catch(e){}}const r=e.channels.map((e=>{const n=null==t?void 0:t.find((({entityId:t})=>t===e.channelId));return ha(e,n)})),o=Zi(e.channelUsers);return Object.assign(Object.assign({},e),{channels:r,channelUsers:o})},pa=e=>{const t=we();return lt(t,"onChannelDeleted","channel.deleted",(async t=>{const n=await fa(t);Yi(n),e(n.channels[0])}))},ga=e=>{const t=we();return lt(t,"onChannelMemberBanned","channel.banned",(async t=>{const n=await fa(t),{channels:r,channelUsers:o}=n;Yi(n),e(r[0],o.find((e=>"banned"===e.membership)))}))},ma=(e,t)=>{const n=we();return lt(n,e,e,(e=>{n.cache&&Yi(e),t(e.users[0])}))},ya=e=>ma("user.deleted",e),va=async()=>{const e=we();return e.log("client/api/disconnectClient"),await new Promise((t=>{e.ws.once("disconnect",t),e.ws.disconnect(),e.mqtt.disconnect()})),e.emitter.all.clear(),e.ws.removeAllListeners(),e.mqtt.removeAllListeners(),e.userId=void 0,e.token=void 0,e.http.defaults.headers.common.Authorization="",e.ws.io.opts.query={token:""},"established"===e.sessionState&&Ji("notLoggedIn"),"tokenExpired"!==e.sessionState&&e.cache&&(e.cache={data:{}}),!e.ws.connected},ba=e=>{const t=we();Ji("terminated"),t.http.defaults.metadata&&("globalBan"===e&&(t.http.defaults.metadata.isGlobalBanned=!0),"userDeleted"===e&&(t.http.defaults.metadata.isUserDeleted=!0)),t.sessionHandler=void 0,va()},wa=["disconnected","error","connect_error","reconnect_error","reconnect_failed"],Ca=e=>{const t=we(),n=wa.map((n=>lt(t,`client/onConnectionError(${n})`,n,(t=>{const r=(null==t?void 0:t.code)?new ge(t.message,t.code,"fatal"):new ve(n);e(r)}))));return()=>{n.forEach((e=>e()))}},_a=e=>{const t=we();return lt(t,"client/onConnectionError(user.didGlobalBan)","user.didGlobalBan",e)},ka=e=>{const t=ce("channelMarker")({userId:ht()._id,entityId:e.channelId});He(["channelMarker","get",t],!0)},Sa=[],Aa=async(e,t,n)=>{var r,o,s;const i=we();let a;i.log("client/api/connectClient",Object.assign({apiKey:i.apiKey,sessionState:i.sessionState},e)),i.userId&&i.userId!==e.userId&&(await va(),Sa.forEach((e=>e()))),null!==(r=e.deviceId)&&void 0!==r||(e.deviceId=Wi());try{const{users:n}=await Gi(e);c=i.ws,l=i.emitter,it.forEach((e=>{c.on(e,(t=>{l.emit(e,t)}))})),await new Promise((e=>{i.ws.once("connect",e),i.ws.open()})),i.userId=e.userId,i.sessionHandler=t,a=i.accessTokenExpiryWatcher(null===(o=i.token)||void 0===o?void 0:o.expiresAt,null===(s=i.token)||void 0===s?void 0:s.issuedAt,t),ft(n[0])}catch(e){throw Ji("notLoggedIn"),e}var c,l;return!0!==(null==n?void 0:n.disableRTE)&&(At(bt()),At(wt()),At(Ct()),At(_t()),At(yt(ht()))),Sa.push(_a((e=>{ba("globalBan"),Sa.forEach((e=>e())),a()})),(e=>{const t=we();return lt(t,"client/onTokenTerminated","tokenTerminated",e)})((e=>{ba(),Sa.forEach((e=>e())),a()})),ya((e=>{e.userId===i.userId&&(ba("userDeleted"),Sa.forEach((e=>e())),a())})),(e=>{const t=we();return lt(t,"client/onTokenExpired","tokenExpired",e)})((e=>{Ji(e),va(),Sa.forEach((e=>e()))})),pa(ka),ga(ka)),i.ws.connected},Ea=()=>{let e,t=!1;const n=we();n.log("initiating access token renewal");const r=async r=>{const{userId:o,displayName:s}=ht(),i={userId:o,displayName:s,authToken:r,deviceId:Wi()};"tokenExpired"===n.sessionState?await Aa(i,n.sessionHandler):await Gi(i),t=!0,e&&clearTimeout(e)};return{renew:()=>{t?console.log("'renew' method can be called only once per renewal instance"):r()},renewWithAuthToken:e=>{t?console.log("'renewWithAuthToken' method can be called only once per renewal instance"):r(e)},unableToRetrieveAuthToken:()=>{e=setTimeout((()=>{var e;null===(e=n.sessionHandler)||void 0===e||e.sessionWillRenewAccessToken(Ea())}),g)}}},Ia=3e5,Oa=(e,t,n)=>{const r=setInterval((()=>{if((e=>Date.now()>Date.parse(e)-Ia)(e))return ut("tokenExpired","tokenExpired"),void st((()=>n.sessionWillRenewAccessToken(Ea())));(e=>{const{expiresAt:t,issuedAt:n}=e,r=Date.parse(t),o=Date.parse(n),s=Date.now();return s>o+.8*(r-o-Ia)&&s<r})({expiresAt:e,issuedAt:t})&&n.sessionWillRenewAccessToken(Ea())}),g);return()=>clearInterval(r)},Ta=async()=>{const e=we();e.log("channel/markerSync");const{data:t}=await e.http.post("/api/v1/markers/sync"),{userEntityMarkers:n,userFeedMarkers:r,feedMarkers:o,userMarkers:s}=t,i=e.cache&&Date.now();return e.cache&&Yi(t,{cachedAt:i}),sa("local.feedMarker.fetched",o),ia("local.channelMarker.fetched",n),aa("local.subChannelMarker.fetched",r),oa("local.userMarker.fetched",s),{hasMore:t.feedMarkers.length>0}},xa=async(e,t={limit:100})=>{const n=we();n.log("channel/getMessageMarkers",e,t);const{data:r}=await n.http.get("/api/v1/markers/messages",{params:{messageIds:e,options:{token:J(t,"skiplimit")}}}),{paging:o}=r,s=Xi(r,["paging"]),{contentMarkers:i,feedMarkers:a,userMarkers:c}=s,l=n.cache&&Date.now();n.cache&&Yi(s,{cachedAt:l}),sa("local.feedMarker.fetched",a),ca("local.messageMarker.fetched",i),oa("local.userMarker.fetched",c);const u=G(o.next);return{data:i,cachedAt:l,prevPage:G(o.previous),nextPage:u}},Ra=async(e,t={limit:100})=>{const n=we();n.log("channel/getSubChannelMarkers",e,t);const{data:r}=await n.http.get("/api/v1/markers/message-feeds",{params:{messageFeedIds:e,options:{token:J(t,"skiplimit")}}}),{paging:o}=r,s=Xi(r,["paging"]),{userEntityMarkers:i,userFeedMarkers:a,userMarkers:c}=s,l=n.cache&&Date.now();n.cache&&Yi(s,{cachedAt:l}),ia("local.channelMarker.fetched",i),aa("local.subChannelMarker.fetched",a),oa("local.userMarker.fetched",c);const u=G(o.next);return{data:a,cachedAt:l,prevPage:G(o.previous),nextPage:u}},Pa=()=>{var e,t;const n=we(),r=ht();n.log("marker/getUserMarker.locally");const{_id:o}=r;if(!o)throw new ge("The userId has not been defined in active client",8e5,"error");const s=(new Date).toISOString(),i=n.cache&&Date.now();return{data:null!==(t=null===(e=Le(["userMarker","get",ce("userMarker")({userId:o})]))||void 0===e?void 0:e.data)&&void 0!==t?t:{userId:o,unreadCount:0,lastSyncAt:s,createdAt:s,updatedAt:s},cachedAt:i}},Ma=()=>Promise.resolve(Pa());Ma.locally=Pa;const ja=e=>{const t=we();return lt(t,"feedMarker/onFeedMarkerUpdated","marker.feed-updated",(t=>{e(t.feedMarkers[0])}))},Fa=e=>{const t=we();return lt(t,"userMarker/onUserMarkerFetched","local.userMarker.fetched",(t=>{e(t.userMarkers[0])}))},Na=(e,t,n,r,o,s=(e=>e),i)=>{const{cache:a}=we();let c;a||console.log("For using Live Object feature you need to enable Cache!");let l=!1;const u=[],d=e=>{const{data:n}=e,r=Xi(e,["data"]);i&&!i(n,c)||t(Object.assign({data:s(n)},r)),c=n},h=t=>{e===t[n]&&(c&&!fe(c,t)||d({loading:!1,data:t,origin:"event"}))};return u.push(...o.map((e=>e(h)))),(()=>{const t=re(r,e,!0);se(t,(({error:e,data:t,loading:n,origin:r,cachedAt:o})=>{-5===o?(d({data:t,origin:r,loading:!1,error:new me("Observing unsynced object is not supported by Live Object.",800800,"error")}),l=!0,u.forEach((e=>e()))):l||d({loading:n,data:t,origin:r,error:e}),e&&u.forEach((e=>e()))}))})(),()=>{u.forEach((e=>e()))}},Ba=e=>!0===e&&void 0;function Ua(e,t){const{channelPublicId:n,childCount:r,creatorPublicId:o,mentionedUsers:s,messageFeedId:i,myReactions:a,reactionCount:c,reactions:l,referenceId:u,segment:d,messageId:h}=e,f=Xi(e,["channelPublicId","childCount","creatorPublicId","mentionedUsers","messageFeedId","myReactions","reactionCount","reactions","referenceId","segment","messageId"]),{readCount:p,deliveredCount:g}=na(e,t);let m;u&&(m=Le(["message","get",u])),m||(m=Le(["message","get",h]));const y=Object.assign(Object.assign({},f),{messageId:h,channelId:n,channelSegment:d,childrenNumber:r,creatorId:o,reactions:null!=l?l:{},reactionsCount:c,subChannelId:i,uniqueId:m?m.data.uniqueId:h,readCount:p,deliveredCount:g});return s&&(y.mentionees=s.map((e=>"channel"===e.type?e:{type:"user",userIds:e.userPublicIds}))),a?y.myReactions=a:(e=>{const t=we(),n=Le(["message","get",e.messageId]),r=(null==n?void 0:n.data.myReactions)||[];Object.assign(e,{myReactions:r});const o=null==e?void 0:e.latestReaction;o&&o.userId===t.userId&&("add"!==o.eventName||r.includes(o.reactionName)||Object.assign(e,{myReactions:[...r,o.reactionName]}),"remove"===o.eventName&&r.includes(o.reactionName)&&Object.assign(e,{myReactions:r.filter((e=>e!==o.reactionName))}))})(y),y}const Da=async e=>{let t=[];const n=e.messages.map((({messageId:e})=>e));if(n.length>0){Yi({messages:e.messages.map((e=>Ua(e)))});try{({data:t}=await xa(n))}catch(e){}}return Object.assign(Object.assign({},e),{messages:e.messages.map((e=>{const n=null==t?void 0:t.find((({contentId:t})=>t===e.messageId));return Ua(e,n)}))})};function La(e){var{subChannelId:t,mentionees:n}=e,r=Xi(e,["subChannelId","mentionees"]);return Object.assign({messageFeedId:t,mentionedUsers:n},r)}function qa(e){var{page:t,sortBy:n,subChannelId:r,tags:o,includeDeleted:s}=e,i=Xi(e,["page","sortBy","subChannelId","tags","includeDeleted"]);const a=Object.assign(Object.assign({},i),{messageFeedId:r,isDeleted:Ba(s),options:{token:J(t||{limit:10},"afterbeforeraw")}});return void 0!==n&&(a.options.sortBy=n),o&&(a.includeTags=o),a}const $a=(e,t=!0)=>{const n=we(),r=[lt(n,"message/onMessageCreated","message.created",(async t=>{const n=await Da(t),r=n.messages[0];Yi(n),e(r)}))];return t&&lt(n,"message/onMessageCreated","local.message.created",(t=>e(t.messages[0]))),()=>{r.forEach((e=>e()))}},za=e=>{const t=we(),n=[lt(t,"onMessageUpdated","message.updated",(async t=>{const n=await Da(t);Yi(n),e(n.messages[0])})),lt(t,"onMessageUpdated","local.message.updated",(t=>e(t.messages[0]))),lt(t,"onMessageUpdated","marker.marked-message",(async t=>{const n=function(e){var t,n,r;const o=["message","get"],s=null===(n=null===(t=De(["user","get"]))||void 0===t?void 0:t.filter((({data:t})=>t._id===e.creatorId)))||void 0===n?void 0:n[0].data;if(!s)return;const i=null===(r=De(o))||void 0===r?void 0:r.filter((({data:t})=>t.subChannelId===e.feedId&&t.creatorId===s.userId));return i?i.map((({data:t})=>{const{readCount:n,deliveredCount:r}=na(t,e),s=Object.assign(Object.assign({},t),{readCount:n,deliveredCount:r,updatedAt:(new Date).toISOString()});return ze(o,s),s})):void 0}(t.contentMarkers[0]);n&&n.forEach((t=>e(t)))}))];return()=>{n.forEach((e=>e()))}},Ha=e=>{const t=we(),n=[lt(t,"message/onMessageDeleted","message.deleted",(async t=>{const n=await Da(t);Yi(n),e(n.messages[0])})),lt(t,"message/onMessageDeleted","local.message.deleted",(t=>e(t.messages[0])))];return()=>{n.forEach((e=>e()))}},Va=e=>{const t=we();return lt(t,"onMessageFlagged","message.flagged",(async t=>{const n=await Da(t);Yi(n),e(n.messages[0])}))},Wa=e=>{const t=we();return lt(t,"onMessageUnflagged","message.unflagged",(async t=>{const n=await Da(t);Yi(n),e(n.messages[0])}))},Ka=e=>{const t=we();return lt(t,"onMessageFlagCleared","message.flagCleared",(async t=>{const n=await Da(t);Yi(n),e(n.messages[0])}))},Qa=e=>{const t=we();return lt(t,"onMessageReactionAdded","message.reactionAdded",(async t=>{const n=await Da(t);Yi(n),e(n.messages[0])}))},Ja=e=>{const t=we();return lt(t,"onMessageReactionRemoved","message.reactionRemoved",(async t=>{const n=await Da(t);Yi(n),e(n.messages[0])}))},Ga=e=>{const t=we();return lt(t,"message/onMessageFetched","local.message.fetched",(t=>{Yi(t),e(t.messages[0])}))},Ya=["broadcast","conversation","community"],Xa=({channelType:e})=>Ya.includes(e);function Za(e,t){var{channelId:n,channelPublicId:r,channelType:o,childCount:s,creatorId:i,creatorPublicId:a,lastMessageId:c,lastMessageTimestamp:l,messageFeedId:u,name:d}=e,h=Xi(e,["channelId","channelPublicId","channelType","childCount","creatorId","creatorPublicId","lastMessageId","lastMessageTimestamp","messageFeedId","name"]);return Object.assign(Object.assign({},h),{channelId:r,creatorId:a,displayName:d,lastActivity:l,latestMessageId:c,messageCount:s,subChannelId:u,isUnreadCountSupport:Xa({channelType:o}),unreadCount:ra(n,u,t)})}const ec=async e=>{let t=[];const n=e.messageFeeds.filter(Xa).map((({messageFeedId:e})=>e));if(n.length>0){(e=>{Yi({messageFeeds:e.messageFeeds.map((e=>Za(e)))})})(e);try{({data:t}=await Ra(n))}catch(e){}}const r=e.messageFeeds.map((e=>{const n=null==t?void 0:t.find((({feedId:t})=>t===e.messageFeedId));return Za(e,n)}));return Object.assign(Object.assign({},e),{messageFeeds:r})};function tc(e){var{excludeDefaultSubChannel:t}=e,n=Xi(e,["excludeDefaultSubChannel"]);const r=Object.assign({},n);return void 0!==t&&(r.excludeDefaultMessageFeed=t),r}const nc=(e,t)=>{const{log:n,cache:r}=we(),o=[e,m,t];if(!r)return;n("cache/api/isInTombstone",o);const s=Le(o),{lifeSpan:i}=oe("cache_then_server",18e4);if(s&&ne(s.data,i))throw new me("Item not found!",400400,"error")},rc=(e,t)=>{const{log:n,cache:r}=we(),o=[e,m,t],s={cachedAt:Date.now()};r&&(n("cache/api/pushToTombstone",{cacheKey:o,data:s}),He([e,"get",t],!0),qe(o,s))},oc=async e=>{const t=we();t.log("channel/getSubChannel",e),nc("subChannel",e);try{const n=await t.http.get(`/api/v5/message-feeds/${encodeURIComponent(e)}`),r=await ec(n.data),o=t.cache&&Date.now();return t.cache&&Yi(r,{cachedAt:o}),ut("local.message-feed.fetched",r),{data:r.messageFeeds[0],cachedAt:o}}catch(t){throw _(null==t?void 0:t.code)&&rc("subChannel",e),t}};oc.locally=e=>{const t=we();if(t.log("channel/getSubChannel.locally",e),!t.cache)return;const n=Le(["subChannel","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const sc=async e=>{const t=we();t.log("channel/startReadingAPI",e);const{data:n}=await t.http.post(`/api/v1/markers/message-feeds/${e}/start-reading`),{userEntityMarkers:r,userFeedMarkers:o,feedMarkers:s,userMarkers:i}=n,a=t.cache&&Date.now();return t.cache&&Yi(n,{cachedAt:a}),sa("local.feedMarker.fetched",s),ia("local.channelMarker.fetched",r),aa("local.subChannelMarker.fetched",o),oa("local.userMarker.fetched",i),!0},ic=async e=>{const t=we();t.log("channel/stopReadingAPI",e);const{data:n}=await t.http.post(`/api/v1/markers/message-feeds/${e}/stop-reading`),{userEntityMarkers:r,userFeedMarkers:o,feedMarkers:s,userMarkers:i}=n,a=t.cache&&Date.now();return t.cache&&Yi(n,{cachedAt:a}),sa("local.feedMarker.fetched",s),ia("local.channelMarker.fetched",r),aa("local.subChannelMarker.fetched",o),oa("local.userMarker.fetched",i),!0};let ac=[];const cc={},lc=e=>{var t;if(!cc[e.subChannelId])return;if(!we().cache)return;const n={entityId:e.channelId,feedId:e.subChannelId,userId:ht()._id},r=null===(t=Le(["subChannelMarker","get",ce("subChannelMarker")(n)]))||void 0===t?void 0:t.data;if(!r)return;const o=[Object.assign(Object.assign({},r),{readToSegment:e.channelSegment})];aa("local.subChannelMarker.updated",o)},uc=()=>{ac.push((()=>{const e=()=>{Object.entries(cc).forEach((([e,t])=>{t&&sc(e)}))};return window.addEventListener("online",e),()=>window.removeEventListener("online",e)})(),$a(lc))},dc=async e=>{const t=await(async e=>{const t=oc.locally(e);if(t)return t.data.channelId;const{data:n}=await oc(e);return n.channelId})(e),n=vt({channelId:t,subChannelId:e});ac.push(At(n))},hc=e=>{const t=we();return lt(t,"onSubChannelCreated","message-feed.created",(async t=>{const n=await ec(t);Yi(n),e(n.messageFeeds[0])}))},fc=e=>{const t=we(),n=[lt(t,"onSubChannelUpdated","message-feed.updated",(async t=>{const n=await ec(t);Yi(n),e(n.messageFeeds[0])})),lt(t,"onSubChannelUpdated","local.message-feed.updated",(t=>e(t.messageFeeds[0])))];return()=>{n.forEach((e=>e()))}},pc=e=>{const t=we(),n=[lt(t,"onSubChannelDeleted","message-feed.deleted",(async t=>{const n=await ec(t);Yi(n),e(n.messageFeeds[0])})),lt(t,"local.message-feed.deleted","local.message-feed.deleted",(t=>e(t.messageFeeds[0])))];return()=>{n.forEach((e=>e()))}};let gc,mc=[],yc=!1,vc=[];const bc=e=>{vc=e},wc=e=>vc.push(e),Cc=async e=>{if(yc)return;if(0===vc.length)return;yc=!0,vc=[];(await e()).hasMore&&vc.push("has_more"),yc=!1},_c=()=>{mc.push((()=>{const e=()=>vc.push("resume");return window.addEventListener("online",e),()=>window.removeEventListener("online",e)})(),$a((e=>{Xa(e)&&vc.push("new message")}),!1),hc((()=>vc.push("subchannel is created"))),pc((()=>vc.push("subchannel is deleted"))),ja((()=>vc.push("feed marker updated"))))};var kc=Object.freeze({__proto__:null,getActiveClient:we,getActiveUser:ht,setActiveUser:ft,createClient:(e,t=Nt.SG,{debugSession:n="amity",apiEndpoint:r}={})=>{var o,s;const i=(e=>{const t=`${null==e?void 0:e.trim()}`.length>0&&!Ft,n=Pt(e),r=(e,...r)=>{t&&n(e,r)};return r.__instance__=n,r})(n);i("client/api/createClient",{apiKey:e.replace(/.{5}$/g,"xxxxx"),apiRegion:t});const a=null!==(o=null==r?void 0:r.http)&&void 0!==o?o:Ut("http",t),c=null!==(s=null==r?void 0:r.mqtt)&&void 0!==s?s:Ut("mqtt",t),l=kr(a),u=(e=>{const t=Ui(e,{autoConnect:!1,reconnectionDelay:2e3,transports:["websocket"]});return t.on("disconnect",(e=>{"io server disconnect"===e&&t.connect()})),t})(a),h=Hi(c),f=ct(),p={version:`${d}`,apiKey:e,log:i,cache:{data:{}},http:l,ws:u,mqtt:h,emitter:f,sessionState:"notLoggedIn",accessTokenExpiryWatcher:Oa,sessionHandler:undefined,getFeedSettings:Vi,use:()=>Ce(p)};try{return we()}catch(e){Ce(p)}return p},login:Aa,logout:va,isConnected:()=>{var e,t;const n=we();return n.log("client/api/isConnected",n),!!(n.userId&&(null===(t=String(null===(e=n.http.defaults.headers.common)||void 0===e?void 0:e.Authorization))||void 0===t?void 0:t.length)&&n.ws.connected)},getFeedSettings:Vi,renewal:Ea,markerSync:Ta,onConnectionError:Ca,onClientDisconnected:e=>Ca((({code:t})=>{800211===t&&e()})),onClientBanned:_a,onSessionStateChange:e=>{const t=we();return lt(t,"client/onSessionStateChange","sessionStateChange",e)},getTotalUnreadCount:e=>{const{_id:t}=ht();if(!t)throw new ge("The _id has not been defined in ActiveUser",8e5,"error");return Na(t,e,"userId",Ma,[Fa],(e=>{var t;return null!==(t=null==e?void 0:e.unreadCount)&&void 0!==t?t:0}),((e,t)=>(null==e?void 0:e.unreadCount)!==(null==t?void 0:t.unreadCount)))},getMarkerSyncEvents:()=>vc,setMarkerSyncEvents:bc,pushMarkerSyncEvent:wc,markerSyncTrigger:Cc,startUnreadSync:()=>{wc("start syncing"),gc||(gc=((e,t)=>{const n=setInterval(e,t);return()=>clearInterval(n)})((()=>Cc(Ta)),2e3)),_c()},stopUnreadSyncing:()=>{null==gc||gc(),gc=void 0,bc([]),mc.forEach((e=>e())),mc=[]}});const Sc=async e=>{const t=we();let n={};if(e){const{token:t,limit:r}=e;n={limit:r,token:t}}t.log("user/queryBlockedUsers");const{data:r}=await t.http.get("/api/v4/me/user-blocks",{params:n}),{paging:o}=r,s=Xi(r,["paging"]),{users:i}=s,a=t.cache&&Date.now();if(t.cache){Yi(s,{cachedAt:a});qe(["blockedUsers","query",n],{users:i.map(ce("user")),paging:o})}const{next:c,previous:l,total:u}=o,d=Y(c);return{data:i,prevPage:Y(l),nextPage:d,total:u,cachedAt:a}};Sc.locally=(e={})=>{var t,n,r;const o=we();if(o.log("user/queryBlockedUsers.locally"),!o.cache)return;let s={};if(e){const{token:t,limit:n}=e;s={token:t,limit:n}}const i=["blockedUsers","query",s],{data:a,cachedAt:c}=null!==(t=Le(i))&&void 0!==t?t:{},l=null!==(n=null==a?void 0:a.users.map((e=>Le(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[],u=Y(null==a?void 0:a.paging.next),d=Y(null==a?void 0:a.paging.previous);return l.length>0&&l.length===(null===(r=null==a?void 0:a.users)||void 0===r?void 0:r.length)?{data:l,nextPage:u,prevPage:d,total:null==a?void 0:a.paging.total,cachedAt:c}:void 0};const Ac=(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getBlockedUsers(tmpid: ${s}) > listen`);const{limit:i,token:a}=e,c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["blockedUsers","collection",{}],g=(e=!1)=>{var n,r;const o=null===(n=Le(d))||void 0===n?void 0:n.data,s=null!==(r=null==o?void 0:o.data)&&void 0!==r?r:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(Sc,{limit:c,token:J(e||null==o?void 0:o.params.page,"afterbeforeraw")});se(i,(({data:e,loading:n,error:r,nextPage:o,total:i})=>{const a={loading:n,error:r,params:{page:o,total:i},data:s};e&&(a.data=[...new Set([...s,...e.map(ce("user"))])]),qe(d,a),(e=>{var n,r;const o=null!==(n=e.data.map((e=>Le(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[];t({onNextPage:g,data:o,hasNextPage:!!(null===(r=e.params)||void 0===r?void 0:r.page),loading:e.loading,error:e.error})})(a)}),oe(l,y))};return u.push((()=>{})),g(!0),()=>{r(`getCategories(tmpid: ${s}) > dispose`),u.forEach((e=>e())),He(d)}},Ec=(e,t)=>{const n=we();return lt(n,e,e,(e=>{var r,o;if(n.cache){Yi(e);[...null!==(r=De(["followers","query"]))&&void 0!==r?r:[],...null!==(o=De(["followings","query"]))&&void 0!==o?o:[]].filter((({key:t})=>t[2].userId===e.follows[0].from||t[2].userId===e.follows[0].to)).forEach((({key:e,data:t})=>ze(e,t,{cachedAt:-1}))),t(e.follows[0])}else t(e.follows[0])}))},Ic=e=>Ec("follow.created",e),Oc=e=>Ec("follow.unfollowed",e),Tc=e=>Ec("follow.followerDeleted",e),xc=e=>Ec("follow.requested",e),Rc=e=>Ec("follow.requestCanceled",e),Pc=e=>Ec("follow.accepted",e),Mc=e=>Ec("follow.requestDeclined",e),jc=async e=>{var t,n;const r=we();r.log("follow/getFollowInfo",e);const{data:o}=await r.http.get(r.userId===e?"/api/v4/me/followInfo":`/api/v5/users/${e}/followInfo`),s=r.cache&&Date.now(),i="follows"in o?Object.assign(Object.assign({},o.followCounts[0]),{status:null===(n=null===(t=o.follows)||void 0===t?void 0:t[0])||void 0===n?void 0:n.status}):o.followCounts[0];return r.cache&&qe(["followInfo","get",e],i,{cachedAt:s}),{data:i,cachedAt:s}};jc.locally=e=>{const t=we();if(t.log("follow/getFollowInfo.locally",e),!t.cache)return;const n=Le(["followInfo","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Fc=e=>{const t=async t=>{const[{data:n},{data:r}]=await Promise.all([jc(t.from),jc(t.to)]);e(n),e(r)},n=[Ec("follow.created",t),Ec("follow.requested",t),Ec("follow.accepted",t),Ec("follow.unfollowed",t),Ec("follow.requestCanceled",t),Ec("follow.requestDeclined",t),Ec("follow.followerDeleted",t)];return()=>{n.forEach((e=>e()))}},Nc=async(e,t)=>{const n=we();n.log(`follow/queryF${e.substring(1)}`,t);const{userId:r,page:o}=t,s=Xi(t,["userId","page"]),{data:i}=await n.http.get(n.userId===r?`/api/v4/me/${e}`:`/api/v4/users/${r}/${e}`,{params:Object.assign(Object.assign({},s),{token:J(o,"afterbeforeraw")})}),{paging:a}=i,c=Xi(i,["paging"]),{follows:l}=c,u=n.cache&&Date.now();if(n.cache){Yi(c,{cachedAt:u});const t=["follow","query",Object.assign(Object.assign({},s),{userId:r,options:Object.assign({},o),type:e})];qe(t,{follows:l.map(ce("follow")),paging:a})}const d=Y(a.next);return{data:l,cachedAt:u,prevPage:Y(a.previous),nextPage:d}};Nc.locally=(e,t)=>{var n,r;const o=we();if(o.log(`follow/queryF${e.substring(1)}.locally`,t),!o.cache)return;const{page:s}=t,i=Xi(t,["page"]),a=["follow","query",Object.assign(Object.assign({},i),{options:Object.assign({},s),type:e})],{data:c,cachedAt:l}=null!==(n=Le(a))&&void 0!==n?n:{};if(!(null==c?void 0:c.follows.length))return;const u=c.follows.map((e=>Le(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)),d=Y(null==c?void 0:c.paging.previous),h=Y(null==c?void 0:c.paging.next);return u.length===(null===(r=null==c?void 0:c.follows)||void 0===r?void 0:r.length)?{data:u,cachedAt:l,prevPage:d,nextPage:h}:void 0};const Bc=async e=>Nc("followers",e);Bc.locally=e=>Nc.locally("followers",e);const Uc=async e=>Nc("following",e);Uc.locally=e=>Nc.locally("following",e);var Dc=Object.freeze({__proto__:null,blockUser:async e=>{const t=we();t.log("user/blockUser",e);const{data:n}=await t.http.post(`/api/v4/me/user-blocks/${e}`),r=t.cache&&Date.now(),{follows:o,followCounts:s}=n,i={follows:o};return t.cache&&(Yi(i,{cachedAt:r}),ze(["followInfo","get",e],s[0],{cachedAt:r})),ut("follow.unfollowed",i),n},unBlockUser:async e=>{const t=we();t.log("user/unBlockUser",e);const{data:n}=await t.http.delete(`/api/v4/me/user-blocks/${e}`),r=t.cache&&Date.now(),{follows:o,followCounts:s}=n,i={follows:o};return t.cache&&(Yi(i,{cachedAt:r}),ze(["followInfo","get",e],s[0],{cachedAt:r})),ut("follow.created",i),n},getBlockedUsers:(e,t,n)=>(console.log("Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead."),Ac(e,t,n)),follow:async e=>{const t=we();t.log("follow/follow",e);const{data:n}=await t.http.post(`/api/v4/me/following/${e}`),r=t.cache&&Date.now();return t.cache&&Yi(n,{cachedAt:r}),ut("accepted"===n.follows[0].status?"follow.created":"follow.requested",n),{data:n.follows[0],cachedAt:r}},unfollow:async e=>{const t=we();t.log("follow/unfollow",e);const{data:n}=await t.http.delete(`/api/v4/me/following/${e}`);return t.cache&&Yi(n),ut("follow.unfollowed",n),!0},acceptFollower:async e=>{const t=we();t.log("follow/acceptFollower",e);const{data:n}=await t.http.post(`/api/v4/me/followers/${e}`);return t.cache&&Yi(n),ut("follow.accepted",n),!0},declineFollower:async e=>{const t=we();t.log("follow/declineFollower",e);const{data:n}=await t.http.delete(`/api/v4/me/followers/${e}`);return t.cache&&Yi(n),ut("follow.requestDeclined",n),!0},onUserFollowed:Ic,onUserUnfollowed:Oc,onFollowerDeleted:Tc,onFollowerRequested:xc,onFollowRequestCanceled:Rc,onFollowRequestAccepted:Pc,onFollowRequestDeclined:Mc,onFollowInfoUpdated:Fc,observeFollowInfo:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observeFollowInfo(tmpid: ${o}) > listen`);const s=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},i=[];return i.push(Fc((t=>((t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.userId)===e&&s(t,n)})({data:t,loading:!1,origin:"event"},"onUpdate")))),se(re(jc,e),(e=>(e.data||e.error)&&s(e,"onFetch")),oe(n)),()=>{r(`observeFollowInfo(tmpid: ${o}) > dispose`),i.forEach((e=>e()))}},observeFollowers:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeFollowers(tmpid: ${r}) > listen`);const o=[],s=(n,r)=>{var o,s;if(n.from===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(s=t[r])||void 0===s||s.call(t,n)}};return o.push(xc((e=>s(e,"onRequested"))),Pc((e=>s(e,"onAccepted"))),Mc((e=>s(e,"onDeclined"))),Rc((e=>s(e,"onCanceled"))),Ic((e=>s(e,"onFollowed"))),Oc((e=>s(e,"onUnfollowed"))),Tc((e=>s(e,"onDeleted")))),()=>{n(`observeFollowers(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},observeFollowings:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeFollowings(tmpid: ${r}) > listen`);const o=[],s=(n,r)=>{var o,s;if(n.to===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(s=t[r])||void 0===s||s.call(t,n)}};return o.push(xc((e=>s(e,"onRequested"))),Pc((e=>s(e,"onAccepted"))),Mc((e=>s(e,"onDeclined"))),Rc((e=>s(e,"onCanceled"))),Ic((e=>s(e,"onFollowed"))),Oc((e=>s(e,"onUnfollowed"))),Tc((e=>s(e,"onDeleted")))),()=>{n(`observeFollowings(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},getFollowers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const s=Date.now();r(`getFollowers(tmpid: ${s}) > listen`);const{limit:i}=e,a=Xi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["follow","collection",{userId:e.userId,type:"follower"}],p=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.status&&"all"!==e.status&&(s=Ve(s,"status",e.status)),t({onNextPage:m,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},g=t=>n=>{var r;const o=null===(r=Le(d))||void 0===r?void 0:r.data;e.userId===n.to&&o&&(["onDeclined","onCanceled","onUnfollowed","onDeleted"].includes(t)?o.data=o.data.filter((e=>e!==ce("follow")(n))):["onRequested","onAccepted","onFollowed"].includes(t)&&(o.data=[...new Set([ce("follow")(n),...o.data])]),qe(d,o),p(o))},m=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re(Bc,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:i};e&&(o.data=[...new Set([...i,...e.map(ce("follow"))])]),qe(d,o),p(o)}),oe(l))};return u.push(xc(g("onRequested")),Pc(g("onAccepted")),Mc(g("onDeclined")),Rc(g("onCanceled")),Ic(g("onFollowed")),Oc(g("onUnfollowed")),Tc(g("onDeleted"))),m(!0),()=>{r(`getFollowers(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},getFollowings:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const s=Date.now();r(`getFollowings(tmpid: ${s}) > listen`);const{limit:i}=e,a=Xi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["follow","collection",{userId:e.userId,type:"following"}],p=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.status&&"all"!==e.status&&(s=Ve(s,"status",e.status)),t({onNextPage:m,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},g=t=>n=>{var r;const o=null===(r=Le(d))||void 0===r?void 0:r.data;e.userId===n.from&&o&&(["onDeclined","onCanceled","onUnfollowed","onDeleted"].includes(t)?o.data=o.data.filter((e=>e!==ce("follow")(n))):["onRequested","onAccepted","onFollowed"].includes(t)&&(o.data=[...new Set([ce("follow")(n),...o.data])]),qe(d,o),p(o))},m=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re(Uc,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:i};e&&(o.data=[...new Set([...i,...e.map(ce("follow"))])]),qe(d,o),p(o)}),oe(l))};return u.push(xc(g("onRequested")),Pc(g("onAccepted")),Mc(g("onDeclined")),Rc(g("onCanceled")),Ic(g("onFollowed")),Oc(g("onUnfollowed")),Tc(g("onDeleted"))),m(!0),()=>{r(`getFollowings(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},getFollowInfo:(e,t)=>Na(e,t,"userId",jc,[Fc])});const Lc=async e=>{const t=we();t.log("user/getUsers",e);const n=e.map((e=>encodeURIComponent(e))),{data:r}=await t.http.get("/api/v3/users/list",{params:{userIds:n}}),o=t.cache&&Date.now();return t.cache&&Yi(r,{cachedAt:o}),ut("user.fetched",r),{data:r.users,cachedAt:o}};Lc.locally=e=>{var t;const n=we();if(n.log("user/getUsers.locally",e),!n.cache)return;const r=e.map((e=>Le(["user","get",e]))).filter(Boolean),o=r.map((({data:e})=>e)),s=null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0];return(null==r?void 0:r.length)<e.length?void 0:{data:o,cachedAt:s.cachedAt}};const qc=e=>ma("user.updated",e),$c=e=>ma("user.flagged",e),zc=e=>ma("user.unflagged",e),Hc=e=>ma("user.flagCleared",e),Vc=e=>ma("user.fetched",e),Wc=async e=>{const t=we();let n;t.log("user/getUser",e),nc("user",e);try{n=(await t.http.get(`/api/v3/users/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&rc("user",e),t}const r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r});const{users:o}=n;return ut("user.fetched",n),{data:o.find((t=>t.userId===e)),cachedAt:r}};Wc.locally=e=>{const t=we();return t.log("user/getUser.locally",e),t.cache&&Le(["user","get",e])};const Kc=async(e={})=>{const t=we();t.log("user/queryUsers",e);const{page:n={limit:10},displayName:r,filter:o="all",sortBy:s="displayName"}=e,i=Xi(e,["page","displayName","filter","sortBy"]),{data:a}=await t.http.get("/api/v3/users",{params:Object.assign(Object.assign({},i),{keyword:r,filter:o,sortBy:s,options:{token:J(n,"skiplimit")}})}),{paging:c}=a,l=Xi(a,["paging"]),{users:u}=l,d=t.cache&&Date.now();if(t.cache){Yi(l,{cachedAt:d});const t=["user","query",Object.assign(Object.assign({},e),{options:Object.assign({},n)})];qe(t,{users:u.map(ce("user")),paging:c})}ut("user.fetched",a);return{data:u,cachedAt:d,prevPage:G(c.previous),nextPage:G(c.next)}};Kc.locally=(e={})=>{var t,n,r;const o=we();if(o.log("user/queryUsers.locally",e),!o.cache)return;const{page:s={limit:10}}=null!=e?e:{},i=["user","query",Object.assign(Object.assign({},e),{options:Object.assign({},s)})],{data:a,cachedAt:c}=null!==(t=Le(i))&&void 0!==t?t:{},l=null!==(n=null==a?void 0:a.users.map((e=>Le(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[],u=G(null==a?void 0:a.paging.previous),d=G(null==a?void 0:a.paging.next);return l.length>0&&l.length===(null===(r=null==a?void 0:a.users)||void 0===r?void 0:r.length)?{data:l,cachedAt:c,prevPage:u,nextPage:d}:void 0};var Qc=Object.freeze({__proto__:null,Relationship:Dc,getUserByIds:Lc,updateUser:async(e,t)=>{const n=we();n.log("user/updateUser",e,t);const{data:r}=await n.http.put("/api/v3/users/",Object.assign(Object.assign({userId:e},t),{createNewUserWhenNotFound:!1})),o=n.cache&&Date.now();n.cache&&Yi(r,{cachedAt:o});const{users:s}=r;return ut("user.updated",r),{data:s.find((t=>t.userId===e)),cachedAt:o}},flagUser:async e=>{const t=we();t.log("user/flagUser",e);const{data:n}=await t.http.post(`api/v4/me/flags/${encodeURIComponent(e)}`);return t.cache&&Yi(n),ut("user.flagged",n),!!n},unflagUser:async e=>{const t=we();t.log("user/unflag",e);const{data:n}=await t.http.delete(`/api/v4/me/flags/${encodeURIComponent(e)}`);return t.cache&&Yi(n),ut("user.unflagged",n),!!n},isUserFlaggedByMe:async e=>{var t,n;const r=we();r.log("user/isUserFlaggedByMe",e);const{result:o,isFlagByMe:s}=null!==(t=await Di(r,"user.isFlagByMe",{userId:e}))&&void 0!==t?t:{};return null!==(n=null!=o?o:s)&&void 0!==n&&n},onUserUpdated:qc,onUserDeleted:ya,onUserFlagged:$c,onUserUnflagged:zc,onUserFlagCleared:Hc,getUser:(e,t)=>Na(e,t,"userId",Wc,[Vc,qc,ya,$c,zc,Hc]),getUsers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`liveUsers(tmpid: ${s}) > listen`);const{limit:i}=e,a=Xi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["user","collection",{}],g=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(s=Ve(s,"displayName",e.displayName),e.sortBy){case"firstCreated":s=s.sort(et);break;case"lastCreated":s=s.sort(tt);break;default:s=s.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Xe)}t({onNextPage:y,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},m=e=>e=>{var t;const n=null===(t=Le(d))||void 0===t?void 0:t.data;n&&(n.data=[...new Set([e.userId,...n.data])],qe(d,n),g(n))},y=(e=!1)=>{var t,n,r;const o=null===(t=Le(d))||void 0===t?void 0:t.data,s=null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(Kc,Object.assign(Object.assign({},a),{page:null!==(r=e||null==o?void 0:o.params.page)&&void 0!==r?r:{limit:c}}));se(i,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(ce("user"))])]),qe(d,o),g(o)}),oe(l))};return u.push(qc(m()),ya(m()),$c(m()),zc(m()),Hc(m())),y(!0),()=>{r(`liveUsers(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},observeUser:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeUser(tmpid: ${r}) > listen`);const o=(n,r)=>{var o,s,i;if((null===(o=n.data)||void 0===o?void 0:o.userId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(s=t.onEvent)||void 0===s||s.call(t,r,n)),null===(i=t[r])||void 0===i||i.call(t,n)}},s=[];return s.push(qc((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),ya((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),$c((e=>o({data:e,loading:!1,origin:"event"},"onFlagged"))),zc((e=>o({data:e,loading:!1,origin:"event"},"onUnflagged"))),Hc((e=>o({data:e,loading:!1,origin:"event"},"onFlagCleared")))),se(re(Wc,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeUser(tmpid: ${r}) > dispose`),s.forEach((e=>e()))}},getBlockedUsers:Ac});const Jc=async e=>{const t=we();t.log("file/getFile",e);const{data:n}=await t.http.get(`/api/v3/files/${e}`),r=t.cache&&Date.now();return t.cache&&Yi({files:[n]},{cachedAt:r}),{data:n,cachedAt:r}};Jc.locally=e=>{const t=we();if(t.log("file/getFile.locally",e),!t.cache)return;const n=Le(["file","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};var Gc=Object.freeze({__proto__:null,getFile:Jc,uploadFile:async(e,t)=>{const n=we();if(n.log("file/uploadFile",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");const r="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:o}=await n.http.post("/api/v4/files",e,{headers:r,onUploadProgress({loaded:e,total:n=100}){t&&t(Math.round(100*e/n))}}),s=n.cache&&Date.now();return n.cache&&Yi({files:o},{cachedAt:s}),{data:o,cachedAt:s}},deleteFile:async e=>{const t=we();return t.log("file/deleteFile",e),await t.http.delete(`/api/v3/files/${e}`),He(["file","get",e],!0),{success:!0}},fileUrlWithSize:(e,t)=>`${e}?size=${t}`,uploadVideo:async(e,t,n)=>{const r=we();if(r.log("file/uploadVideo",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");t&&e.append("feedType",t);const o="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:s}=await r.http.post("/api/v4/videos",e,{headers:o,onUploadProgress({loaded:e,total:t=100}){n&&n(Math.round(100*e/t))}}),i=r.cache&&Date.now();return r.cache&&Yi({files:s},{cachedAt:i}),{data:s,cachedAt:i}},uploadImage:async(e,t)=>{const n=we();if(n.log("file/uploadImage",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");const r="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:o}=await n.http.post("/api/v4/images",e,{headers:r,onUploadProgress({loaded:e,total:n=100}){t&&t(Math.round(100*e/n))}}),s=n.cache&&Date.now();return n.cache&&Yi({files:o},{cachedAt:s}),{data:o,cachedAt:s}},createImage:async(e,t)=>{const n=we();if(n.log("file/createImage",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");const r="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:o}=await n.http.post("/api/v4/images",e,{headers:r,onUploadProgress({loaded:e,total:n=100}){t&&t(Math.round(100*e/n))}}),s=n.cache&&Date.now();return n.cache&&Yi({files:o},{cachedAt:s}),{data:o,cachedAt:s}},createFile:async(e,t)=>{const n=we();if(n.log("file/createFile",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");const r="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:o}=await n.http.post("/api/v4/files",e,{headers:r,onUploadProgress({loaded:e,total:n=100}){t&&t(Math.round(100*e/n))}}),s=n.cache&&Date.now();return n.cache&&Yi({files:o},{cachedAt:s}),{data:o,cachedAt:s}},createVideo:async(e,t,n)=>{const r=we();if(r.log("file/createVideo",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");t&&e.append("feedType",t);const o="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:s}=await r.http.post("/api/v4/videos",e,{headers:o,onUploadProgress({loaded:e,total:t=100}){n&&n(Math.round(100*e/t))}}),i=r.cache&&Date.now();return r.cache&&Yi({files:s},{cachedAt:i}),{data:s,cachedAt:i}},observeFile:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeFile(tmpid: ${r}) > listen`);return se(re(Jc,e),(n=>n.data&&((n,r)=>{var o,s,i;if((null===(o=n.data)||void 0===o?void 0:o.fileId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(s=t.onEvent)||void 0===s||s.call(t,r,n)),null===(i=t[r])||void 0===i||i.call(t,n)}})(n,"onFetch"))),()=>{n(`observeFile(tmpid: ${r}) > dispose`)}}});const Yc=async e=>{const t=we();t.log("role/queryRoles",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,sortBy:s}=n,i=Xi(n,["page","displayName","sortBy"]),{data:a}=await t.http.get("/api/v3/roles",{params:Object.assign(Object.assign({},i),{keyword:o,sortBy:s,options:{token:J(r,"skiplimit")}})}),{paging:c}=a,l=Xi(a,["paging"]),{roles:u}=l,d=t.cache&&Date.now();t.cache&&Yi(l,{cachedAt:d});const h=G(c.next);return{data:u,cachedAt:d,prevPage:G(c.previous),nextPage:h}};Yc.locally=e=>{we().log("role/queryRoles.locally",e)};const Xc=async e=>{const t=we();t.log("role/getRole",e);const{data:n}=await t.http.get(`/api/v3/roles/${e}`),r=t.cache&&Date.now();return t.cache&&Yi({roles:n},{cachedAt:r}),{data:n.find((t=>t.roleId===e)),cachedAt:r}};Xc.locally=e=>{const t=we();if(t.log("role/getRole.locally",e),!t.cache)return;const n=Le(["role","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Zc=(e,t)=>{"message"===e?ut("local.message.updated",{messages:[t]}):"post"===e?ut("post.updated",{posts:[t]}):"comment"===e&&ut("comment.updated",{comments:[t]})},el=async(e,t=!1)=>{const n=we();let r;n.log("message/getMessage",e),t||console.log("getMessage will be deprecated on 15th November 2022, please use liveMessage instead."),nc("message",e);try{const{data:t}=await n.http.get(`/api/v5/messages/${encodeURIComponent(e)}`);r=await Da(t)}catch(t){throw _(null==t?void 0:t.code)&&rc("message",e),t}const o=n.cache&&Date.now();n.cache&&Yi(r,{cachedAt:o});const{messages:s}=r;return ut("local.message.fetched",{messages:s}),{data:s.find((t=>t.messageId===e)),cachedAt:o}};el.locally=e=>{const t=we();if(t.log("message/getMessage.locally",e),!t.cache)return;const n=Le(["message","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const tl=async e=>{const t=we();let n;t.log("post/getPost",e),nc("post",e);try{n=(await t.http.get(`/api/v3/posts/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&rc("post",e),t}const r=ea(n,"communityUsers"),o=t.cache&&Date.now();t.cache&&Yi(r,{cachedAt:o});const{posts:s}=r;return{data:s.find((t=>t.postId===e)),cachedAt:o}};tl.locally=e=>{const t=we();if(t.log("post/getPost.locally",e),!t.cache)return;const n=Le(["post","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const nl=async e=>{const t=we();let n;t.log("comment/getComment",e),nc("comment",e);try{n=(await t.http.get(`/api/v3/comments/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&rc("comment",e),t}const r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r});const{comments:o}=n;return{data:o.find((t=>t.commentId===e)),cachedAt:r}};nl.locally=e=>{const t=we();if(t.log("comment/getComment.locally",e),!t.cache)return;const n=Le(["comment","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const rl=(e,t)=>{var n,r;if(we().userId!==t.reactor.userId)return;let o,s;if("post.addReaction"===e||"post.removeReaction"===e){const e=t.posts[0];s=null===(n=Le(["post","get",e.postId]))||void 0===n?void 0:n.data,o=e}else{const e=t.comments[0];s=null===(r=Le(["comment","get",e.commentId]))||void 0===r?void 0:r.data,o=e}if(s&&s.myReactions)if("post.addReaction"===e||"comment.addReaction"===e){if(s.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:[...s.myReactions,t.reactor.reactionName]})}else{if(!s.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:s.myReactions.filter((e=>e!==t.reactor.reactionName))})}},ol=async(e,t,n)=>{const r=we();if(r.log("reaction/createReaction",{referenceId:t,referenceType:e,reactionName:n}),await r.http.post("/api/v2/reactions",{referenceId:t,referenceType:e,reactionName:n,referenceVersion:"message"===e?5:void 0}),r.cache){const n=Le([e,"get",t]);(null==n?void 0:n.data)&&qe([e,"get",t],n.data,{cachedAt:Date.now()})}return!0};ol.optimistically=(e,t,n)=>{var r,o,s,i,a;const c=we();if(c.log("reaction/createReaction.optimistically",{referenceId:t,referenceType:e,reactionName:n}),!c.cache)return;const l=Le([e,"get",t]);if(!(null==l?void 0:l.data)||(null===(r=l.data.myReactions)||void 0===r?void 0:r.includes(n)))return;const u=Object.assign(Object.assign({},l.data),{reactionsCount:l.data.reactionsCount+1,myReactions:[...null!==(o=l.data.myReactions)&&void 0!==o?o:[],n],reactions:Object.assign(Object.assign({},l.data.reactions),{[n]:(null!==(s=l.data.reactions[n])&&void 0!==s?s:0)+1})});return ze([e,"get",t],u,{cachedAt:-5}),Zc(e,u),null!==(a=null===(i=null==u?void 0:u.myReactions)||void 0===i?void 0:i.includes(n))&&void 0!==a&&a};const sl=async(e,t,n)=>{const r=we();if(r.log("reaction/removeReaction",{referenceId:t,referenceType:e,reactionName:n}),await r.http.delete("/api/v2/reactions",{data:{referenceId:t,referenceType:e,reactionName:n,referenceVersion:"message"===e?5:void 0}}),r.cache){const n=Le([e,"get",t]);(null==n?void 0:n.data)&&qe([e,"get",t],n.data,{cachedAt:Date.now()})}return!0};sl.optimistically=(e,t,n)=>{var r,o,s,i,a;const c=we();if(c.log("reaction/removeReaction.optimistically",{referenceId:t,referenceType:e,reactionName:n}),!c.cache)return;const l=Le([e,"get",t]);if(!(null==l?void 0:l.data)||!(null===(r=l.data.myReactions)||void 0===r?void 0:r.includes(n)))return;const u=Object.assign(Object.assign({},l.data),{reactionsCount:Math.max(0,l.data.reactionsCount-1),myReactions:(null!==(o=l.data.myReactions)&&void 0!==o?o:[]).filter((e=>e!==n)),reactions:Object.assign(Object.assign({},l.data.reactions),{[n]:Math.max(0,(null!==(s=l.data.reactions[n])&&void 0!==s?s:0)-1)})});return ze([e,"get",t],u,{cachedAt:-5}),Zc(e,u),null!==(a=!(null===(i=null==u?void 0:u.myReactions)||void 0===i?void 0:i.includes(n)))&&void 0!==a&&a};const il=(e,t)=>{const n=we();return lt(n,e,e,(r=>{var o;if(n.cache){const{communities:n}=r,s=Xi(r,["communities"]),i=ea(s,"communityUsers");Yi(i),(null==n?void 0:n[0])&&!["post.updated"].includes(e)&&ut("community.updated",{communities:n,categories:[],communityUsers:[],feeds:[],files:[],users:[]});const a=Le(["post","get",r.posts[0].postId]);if(["post.created","post.approved","post.declined"].includes(e)){let t=null===(o=De(["post","query"]))||void 0===o?void 0:o.filter((({key:e})=>{var t;return(null===(t=e[2])||void 0===t?void 0:t.targetId)===a.data.targetId}));"post.declined"===e&&(t=null==t?void 0:t.filter((({key:e})=>{var t;return"reviewing"===(null===(t=e[2])||void 0===t?void 0:t.feedType)}))),null==t||t.map((({key:e,data:t})=>ze(e,t,{cachedAt:-1})))}t(a.data)}else t(r.posts[0])}))},al=e=>il("post.created",e),cl=e=>il("post.updated",e),ll=e=>il("post.deleted",e),ul=e=>il("post.approved",e),dl=e=>il("post.declined",e),hl=e=>il("post.flagged",e),fl=e=>il("post.unflagged",e),pl=e=>{const t=we();return lt(t,"post.addReaction","post.addReaction",(n=>{if(t.cache){rl("post.addReaction",n);const t=Xi(n,["reactor"]);Yi(t);const r=Le(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},gl=e=>{const t=we();return lt(t,"post.removeReaction","post.removeReaction",(n=>{if(t.cache){rl("post.removeReaction",n);const t=Xi(n,["reactor"]);Yi(t);const r=Le(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},ml=(e,t)=>{const n=we();return lt(n,e,e,(r=>{var o;if(n.cache){Yi(r);const n=Le(["comment","get",r.comments[0].commentId]);if(["comment.created"].includes(e)){const e=null===(o=De(["comment","query"]))||void 0===o?void 0:o.filter((({key:e})=>{var t;return(null===(t=e[2])||void 0===t?void 0:t.referenceId)===n.data.referenceId}));null==e||e.map((({key:e,data:t})=>ze(e,t,{cachedAt:-1})))}t(n.data)}else t(r.comments[0])}))},yl=e=>ml("comment.created",e),vl=e=>ml("comment.updated",e),bl=e=>ml("comment.deleted",e),wl=e=>ml("comment.flagged",e),Cl=e=>ml("comment.unflagged",e),_l=e=>{const t=we();return lt(t,"comment.addReaction","comment.addReaction",(n=>{if(t.cache){rl("comment.addReaction",n);const t=Xi(n,["reactor"]);Yi(t);const r=Le(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},kl=e=>{const t=we();return lt(t,"comment.removeReaction","comment.removeReaction",(n=>{if(t.cache){rl("comment.removeReaction",n);const t=Xi(n,["reactor"]);Yi(t);const r=Le(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},Sl=(e,t,n)=>{const r=we(),o=(r,o,s)=>{r===e&&o===t&&n(s)};if("message"===e){const e=async e=>{const t=await Da(e);if(!t.messages[0].latestReaction)return;const n=t.messages[0].latestReaction,{eventName:r,referenceId:s,referenceType:i,userDisplayName:a}=n,c=Xi(n,["eventName","referenceId","referenceType","userDisplayName"]);"add"===r&&(Yi(t),Yi({reactions:[c]}),o("message",t.messages[0].messageId,c))};return lt(r,"reaction/onReactorAdded","message.updated",e)}if("post"===e){return lt(r,"post.addReaction","post.addReaction",(e=>{const{reactor:t}=e,n=Xi(e,["reactor"]);Yi(n),Yi({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return lt(r,"comment.addReaction","comment.addReaction",(e=>{const{reactor:t}=e,n=Xi(e,["reactor"]);Yi(n),Yi({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))},Al=(e,t,n)=>{const r=we(),o=(r,o,s)=>{r===e&&o===t&&n(s)};if("message"===e){const e=async e=>{const t=await Da(e);if(!t.messages[0].latestReaction)return;const n=t.messages[0].latestReaction,{eventName:r,referenceId:s,referenceType:i}=n,a=Xi(n,["eventName","referenceId","referenceType"]);"remove"===r&&(Yi(t),Yi({reactions:[a]}),o("message",t.messages[0].messageId,a))};return lt(r,"reaction/onReactorRemoved","message.updated",e)}if("post"===e){return lt(r,"post.removeReaction","post.removeReaction",(e=>{const{reactor:t}=e,n=Xi(e,["reactor"]);Yi(n),Yi({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return lt(r,"comment.removeReaction","comment.removeReaction",(e=>{const{reactor:t}=e,n=Xi(e,["reactor"]);Yi(n),Yi({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))},El=async e=>{const t=we();t.log("reaction/queryReactions",e);const n=null!=e?e:{},{page:r={limit:10}}=n,o=Xi(n,["page"]),{data:s}=await t.http.get("/api/v3/reactions",{params:Object.assign(Object.assign({},o),{options:{token:J(r,"afterbeforeraw")}})}),{paging:i}=s,a=Xi(s,["paging"]),{reactions:c}=a;Yi(Object.assign(Object.assign({},a),{reactions:c[0].reactors}));const l=Y(i.next);return{data:c,prevPage:Y(i.previous),nextPage:l}};var Il=Object.freeze({__proto__:null,addReaction:ol,removeReaction:sl,onReactionAdded:(e,t,n)=>{const r=r=>{ce(e)(r)===t&&n(r)};if("message"===e){const e=we(),t=async e=>{var t;const n=await Da(e),o=Le(["message","get",n.messages[0].messageId]),s=(null===(t=null==o?void 0:o.data)||void 0===t?void 0:t.reactionsCount)!==n.messages[0].reactionsCount;Yi(n),s&&r(n.messages[0])};return lt(e,"reaction/onReactionAdded","message.updated",t)}return"post"===e?pl(r):_l(r)},onReactionRemoved:(e,t,n)=>{const r=r=>{ce(e)(r)===t&&n(r)};if("message"===e){const e=we(),t=async e=>{var t;const n=await Da(e),o=Le(["message","get",n.messages[0].messageId]),s=(null===(t=null==o?void 0:o.data)||void 0===t?void 0:t.reactionsCount)!==n.messages[0].reactionsCount;Yi(n),s&&r(n.messages[0])};return lt(e,"reaction/onReactionRemoved","message.updated",t)}return"post"===e?gl(r):kl(r)},onReactorAdded:Sl,onReactorRemoved:Al,getReactions:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const s=Date.now();r(`liveReactions(tmpid: ${s}) > listen`);const{limit:i}=e,a=Xi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["reaction","collection",{referenceId:e.referenceId,referenceType:e.referenceType}],p=e=>{var n,r;const o=null!==(n=e.data.map((e=>Le(["reaction","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[];t({onNextPage:m,data:o,hasNextPage:!!(null===(r=e.params)||void 0===r?void 0:r.page),loading:e.loading,error:e.error})},g=e=>t=>{var n;const r=null===(n=Le(d))||void 0===n?void 0:n.data;r&&("onAdded"===e?r.data=[...new Set([t.reactionId,...r.data])]:"onRemoved"===e&&(r.data=r.data.filter((e=>e!==t.reactionId))),qe(d,r),p(r))},m=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re(El,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:i};e&&(o.data=[...new Set([...i,...e[0].reactors.map(ce("reaction"))])]),qe(d,o),p(o)}),oe(l))};return u.push(Sl(a.referenceType,a.referenceId,g("onAdded")),Al(a.referenceType,a.referenceId,g("onRemoved"))),m(!0),()=>{r(`liveReactions(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}}}),Ol={post:{domainName:"posts",eventName:"v3/post.isflagbyme",primaryKey:"postId"},comment:{domainName:"comments",eventName:"v3/comment.isflagbyme",primaryKey:"commentId"},message:{domainName:"messages",eventName:"v3/message.isFlaggedByMe",primaryKey:"messageId"},user:{domainName:"users",eventName:"user.isFlagByMe",primaryKey:"userId"}};const Tl=async e=>{const t=we();t.log("channel/getChannelByIds",e);const n=e.map((e=>encodeURIComponent(e)));let r;try{r=(await t.http.get("/api/v3/channels/list",{params:{channelIds:n}})).data}catch(t){throw e.forEach((e=>{_(null==t?void 0:t.code)&&rc("channel",e)})),t}const o=await fa(r),s=t.cache&&Date.now();return t.cache&&Yi(o,{cachedAt:s}),{data:o.channels,cachedAt:s}};Tl.locally=e=>{var t;const n=we();if(n.log("channel/getChannelByIds.locally",e),!n.cache)return;const r=e.map((e=>Le(["channel","get",e]))).filter(Boolean);if((null==r?void 0:r.length)<e.length)return;return{data:r.map((({data:e})=>e)),cachedAt:(null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0]).cachedAt}};const xl=async e=>{const t=we();let n;t.log("channel/getChannel",e),nc("channel",e);try{const{data:r}=await t.http.get(`/api/v3/channels/${encodeURIComponent(e)}`);n=await fa(r)}catch(t){throw _(null==t?void 0:t.code)&&rc("channel",e),t}const r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r});const{channels:o}=n;return{data:o.find((t=>t.channelId===e)),cachedAt:r}};xl.locally=e=>{const t=we();if(t.log("channel/getChannel.locally",e),!t.cache)return;const n=Le(["channel","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Rl=e=>{const t=we();return lt(t,"onChannelCreated","channel.created",(async t=>{const n=await fa(t);Yi(n),e(n.channels[0])}))},Pl=e=>{const t=we(),n=[lt(t,"onChannelUpdated","channel.updated",(async t=>{const n=await fa(t);Yi(n),e(n.channels[0])})),lt(t,"onChannelUpdated","local.channel.updated",(t=>e(t.channels[0])))];return()=>{n.forEach((e=>e()))}},Ml=e=>{const t=we();return lt(t,"onChannelJoined","channel.joined",(async t=>{const n=await fa(t),{channels:r,channelUsers:o}=n;Yi(n),e(r[0],o[0])}))},jl=e=>{const t=we();return lt(t,"onChannelLeft","channel.left",(async t=>{const n=await fa(t),{channels:r,channelUsers:o}=n;Yi(n),e(r[0],o[0])}))},Fl=e=>{const t=we();return lt(t,"onChannelMuted","channel.setMuted",(async t=>{const n=await fa(t);Yi(n),e(n.channels[0])}))},Nl=e=>{const t=we();return lt(t,"onChannelMemberAdded","channel.membersAdded",(async t=>{const n=await fa(t),{channels:r,channelUsers:o}=n;Yi(n),e(r[0],o.find((e=>"member"===e.membership)))}))},Bl=e=>{const t=we();return lt(t,"onChannelMemberRemoved","channel.membersRemoved",(async t=>{const n=await fa(t),{channels:r,channelUsers:o}=n;Yi(n),e(r[0],o[0])}))},Ul=e=>{const t=we();return lt(t,"onChannelMemberUnbanned","channel.unbanned",(async t=>{const n=await fa(t),{channels:r,channelUsers:o}=n;Yi(n),e(r[0],o.find((e=>"none"===e.membership)))}))},Dl=async e=>{const t=we();t.log("channel/queryChannels",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,membership:s}=n,i=Xi(n,["page","displayName","membership"]),{data:a}=await t.http.get("/api/v3/channels",{params:Object.assign(Object.assign({},i),{keyword:o,filter:s,options:{token:J(r,"skiplimit")}})}),{paging:c}=a,l=Xi(a,["paging"]),u=await fa(l),{channels:d}=u,h=t.cache&&Date.now();if(t.cache){Yi(u,{cachedAt:h});const e=["channel","query",Object.assign(Object.assign({},i),{options:Object.assign({},r)})];qe(e,{channels:d.map(ce("channel")),paging:c})}const f=G(c.next);return{data:d,cachedAt:h,prevPage:G(c.previous),nextPage:f}},Ll=async e=>{const t=we();t.log("channel/queryChannelMembers",e);const n=null!=e?e:{},{page:r}=n,o=Xi(n,["page"]),{data:s}=await t.http.get(`/api/v4/channels/${encodeURIComponent(o.channelId)}/users`,{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:i}=s,a=Xi(s,["paging"]),c=await fa(a),{channelUsers:l}=c,u=t.cache&&Date.now();if(t.cache){Yi(c);const e=["channelUsers","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];qe(e,{channelUsers:l.map((({channelId:e,userId:t})=>ce("channelUsers")({channelId:e,userId:t}))),paging:i})}return{data:l,cachedAt:u,nextPage:G(i.next),prevPage:G(i.previous)}};Ll.locally=e=>{var t,n;const r=we();if(r.log("channel/queryChannelMembers.locally",e),!r.cache)return;const{page:o}=e,s=Xi(e,["page"]),i=["channelUsers","query",Object.assign(Object.assign({},s),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Le(i))&&void 0!==t?t:{};if(!(null==a?void 0:a.channelUsers.length))return;const l=a.channelUsers.map((e=>Le(["channelUsers","get",e]))).filter(Boolean).map((({data:e})=>e)),u=G(null==a?void 0:a.paging.previous),d=G(null==a?void 0:a.paging.next);return l.length===(null===(n=null==a?void 0:a.channelUsers)||void 0===n?void 0:n.length)?{data:l,cachedAt:c,prevPage:u,nextPage:d}:void 0};const ql=(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getMembers(tmpid: ${s}) > listen`);const{limit:i}=e,a=Xi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["channelUsers","collection",{channelId:e.channelId}],g=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["channelUsers","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];s=We(s,"roles",e.roles),e.memberships&&(s=s.filter((t=>!(!e.memberships.includes("muted")||!t.isMuted)||e.memberships.includes(t.membership)))),e.search&&(s=Ye(s,e.search));const i=e.sortBy?e.sortBy:"lastCreated";s=s.sort("lastCreated"===i?tt:et),t({onNextPage:y,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},m=t=>(t,n)=>{var r;if(e.channelId!==n.channelId)return;const o=null===(r=Le(d))||void 0===r?void 0:r.data;if(!o)return;const s=ce("channelUsers")({channelId:e.channelId,userId:n.userId});"none"===n.membership?o.data=o.data.filter((e=>e!==s)):o.data.includes(s)||(o.data=[s,...o.data]),qe(d,o),g(o)},y=(e=!1)=>{var t,n,r;const o=null===(t=Le(d))||void 0===t?void 0:t.data,s=null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(Ll,Object.assign(Object.assign({},a),{page:null!==(r=e||null==o?void 0:o.params.page)&&void 0!==r?r:{limit:c}}));se(i,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(ce("channelUsers"))])]),qe(d,o),g(o)}),oe(l))};return u.push(Ml(m()),jl(m()),Nl(m()),Bl(m()),ga(m()),Ul(m())),y(!0),()=>{r(`getMembers(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}};var $l=Object.freeze({__proto__:null,addMembers:async(e,t)=>{const n=we();n.log("channel/addMembers",e,t);const{data:r}=await n.http.post(`/api/v3/channels/${encodeURIComponent(e)}/users`,{channelId:e,userIds:t});t.forEach((e=>ut("channel.membersAdded",Object.assign(Object.assign({},r),{channelUsers:r.channelUsers.filter((t=>t.userId===e))}))));const o=await fa(r);n.cache&&Yi(o);const{channelUsers:s}=o;return!!s.find((t=>t.channelId===e&&"member"===t.membership))},removeMembers:async(e,t)=>{const n=we();n.log("channel/removeMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/channels/${encodeURIComponent(e)}/users`,{data:{channelId:e,userIds:t}});t.forEach((e=>ut("channel.membersRemoved",Object.assign(Object.assign({},r),{channelUsers:r.channelUsers.filter((t=>t.userId===e))}))));const o=await fa(r);n.cache&&Yi(o);const{channelUsers:s}=o;return!!s.find((t=>t.channelId===e&&"member"!==t.membership))},getMembers:ql,searchMembers:(e,t,n)=>ql(e,t,n)});var zl=Object.freeze({__proto__:null,addRole:async(e,t,n)=>{const r=we();r.log("channel/addRole",e,t,n);const{data:o}=await r.http.post(`/api/v3/channels/${encodeURIComponent(e)}/users/roles`,{channelId:e,role:t,userIds:n}),s=await fa(o);r.cache&&Yi(s);const{channelUsers:i}=s;return!!i.find((n=>n.channelId===e&&n.roles.includes(t)))},removeRole:async(e,t,n)=>{const r=we();r.log("channel/removeRole",e,t,n);const{data:o}=await r.http.delete(`/api/v3/channels/${encodeURIComponent(e)}/users/roles`,{data:{channelId:e,role:t,userIds:n}}),s=await fa(o);r.cache&&Yi(s);const{channelUsers:i}=s;return!!i.find((n=>n.channelId===e&&!n.roles.includes(t)))},banMembers:async(e,t)=>{const n=we();n.log("channel/banMembers",{userIds:t,channelId:e});const{data:r}=await n.http.put(`/api/v3/channels/${e}/users/ban`,{userIds:t}),o=await fa(r),{channelUsers:s}=o,i=n.cache&&Date.now();return n.cache&&Yi(o,{cachedAt:i}),{data:null==s?void 0:s.filter((e=>"banned"===e.membership)),cachedAt:i}},unbanMembers:async(e,t)=>{const n=we();n.log("channel/unbanMembers",{userIds:t,channelId:e});const{data:r}=await n.http.put(`/api/v3/channels/${encodeURIComponent(e)}/users/unban`,{userIds:t}),o=await fa(r),s=n.cache&&Date.now();n.cache&&Yi(o,{cachedAt:s});const{channelUsers:i}=o;return{data:null==i?void 0:i.filter((e=>"member"===e.membership)),cachedAt:s}}}),Hl=Object.freeze({__proto__:null,Membership:$l,Moderation:zl,getChannelByIds:Tl,createChannel:async e=>{const t=we();let n;t.log("user/createChannel",e),n="conversation"===(null==e?void 0:e.type)?await t.http.post("/api/v3/channels/conversation",Object.assign(Object.assign({},e),{isDistinct:!0})):await t.http.post("/api/v3/channels",e);const r=await fa(n.data),o=t.cache&&Date.now();t.cache&&Yi(r,{cachedAt:o});const{channels:s}=r;return{data:s[0],cachedAt:o}},updateChannel:async(e,t)=>{const n=we();n.log("channel/updateChannel",e,t);const{data:r}=await n.http.put(`/api/v3/channels/${encodeURIComponent(e)}`,t),o=await fa(r),s=n.cache&&Date.now();n.cache&&Yi(o,{cachedAt:s});const{channels:i}=o;return{data:i.find((t=>t.channelId===e)),cachedAt:s}},deleteChannel:async e=>{const t=we();t.log("channel/deleteChannel",e),await t.http.delete(`/api/v3/channels/${encodeURIComponent(e)}`);return(await xl(e)).data},joinChannel:async e=>{const t=we();t.log("channel/joinChannel",e);const{data:n}=await t.http.post(`/api/v3/channels/${encodeURIComponent(e)}/join`),r=await fa(n);t.cache&&Yi(r);const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"===t.membership))},leaveChannel:async e=>{const t=we();t.log("channel/leaveChannel",e);const{data:n}=await t.http.delete(`/api/v3/channels/${encodeURIComponent(e)}/leave`),r=await fa(n);t.cache&&Yi(r);const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"!==t.membership))},muteChannel:async(e,t=-1)=>{const n=we();if(n.log("channel/muteChannel",e),-1!==t&&t<0)throw new ge("Mute Period can only be positive numbers or -1(mute forever)",800110,"error");const{data:r}=await n.http.put(`/api/v2/channel/${encodeURIComponent(e)}/mute`,{mutePeriod:t}),{success:o}=r;return o},unmuteChannel:async e=>{const t=we();t.log("channel/unmuteChannel",e);const{data:n}=await t.http.put(`/api/v2/channel/${encodeURIComponent(e)}/mute`,{mutePeriod:0}),{success:r}=n;return r},markAsRead:async e=>{const t=we();t.log("channel/markAsRead",e);const{data:n}=await t.http.put(`/api/v1/markers/channels/${e}/mark-read`),r=t.cache&&Date.now();return t.cache&&Yi(n,{cachedAt:r}),!0},onChannelCreated:Rl,onChannelUpdated:Pl,onChannelDeleted:pa,onChannelJoined:Ml,onChannelLeft:jl,onChannelMuted:Fl,onChannelMemberAdded:Nl,onChannelMemberRemoved:Bl,onChannelMemberBanned:ga,onChannelMemberUnbanned:Ul,observeChannel:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeChannel(tmpid: ${r}) > listen`);const o=(n,r)=>{var o,s,i;if((null===(o=n.data)||void 0===o?void 0:o.channelId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(s=t.onEvent)||void 0===s||s.call(t,r,n)),null===(i=t[r])||void 0===i||i.call(t,n)}},s=[];return s.push(Pl((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),pa((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),Ml((e=>o({data:e,loading:!1,origin:"event"},"onJoin"))),jl((e=>o({data:e,loading:!1,origin:"event"},"onLeft"))),Fl((e=>o({data:e,loading:!1,origin:"event"},"onMute"))),Nl((e=>o({data:e,loading:!1,origin:"event"},"onMemberAdded"))),Bl((e=>o({data:e,loading:!1,origin:"event"},"onMemberRemoved")))),se(re(xl,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeChannel(tmpid: ${r}) > dispose`),s.forEach((e=>e()))}},observeChannels:e=>{const{log:t}=we(),n=Date.now();t(`observeChannels(tmpid: ${n}) > listen`);const r=[],o=(t,n)=>{var r,o;if(e instanceof Function)return e(t);null===(r=e.onEvent)||void 0===r||r.call(e,n,t),null===(o=e[n])||void 0===o||o.call(e,t)};return r.push(Rl((e=>o(e,"onCreate"))),Pl((e=>o(e,"onUpdate"))),pa((e=>o(e,"onDelete"))),Ml((e=>o(e,"onJoin"))),jl((e=>o(e,"onLeft"))),Fl((e=>o(e,"onMute"))),Nl((e=>o(e,"onMemberAdded"))),Bl((e=>o(e,"onMemberRemoved")))),()=>{t(`observeChannels(tmpid: ${n}) > dispose`),r.forEach((e=>e()))}},getChannel:(e,t)=>Na(e,t,"channelId",xl,[Pl,pa,Ml,jl,Nl,Bl,ga,Ul,Fl,()=>$a((()=>null))]),getChannels:(e,t,n)=>{const{log:r,cache:o,userId:s}=we();o||console.log(p);const i=Date.now();r(`getChannels(tmpid: ${i}) > listen`);const{limit:a}=e,c=Xi(e,["limit"]),l=null!=a?a:h,{policy:u=f}=null!=n?n:{},d=[],g=["channel","collection",{}],m=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["channel","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(i=Ve(i,"isDeleted",e.isDeleted),i=Ve(i,"displayName",e.displayName),e.types&&(i=i.filter((t=>{var n;return null===(n=e.types)||void 0===n?void 0:n.includes(t.type)}))),e.tags&&(i=i.filter((t=>{var n;return null===(n=t.tags)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.tags)||void 0===n?void 0:n.includes(t)}))}))),e.excludeTags&&(i=i.filter((t=>{var n;return!(null===(n=t.tags)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.excludeTags)||void 0===n?void 0:n.includes(t)})))}))),e.membership&&s&&(i=Ke(i,e.membership,s)),e.sortBy){case"firstCreated":i=i.sort(et);break;case"lastCreated":i=i.sort(tt);break;case"displayName":i=i.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Xe);break;default:i=i.sort(nt)}t({onNextPage:b,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},v=e=>e=>{var t;const n=null===(t=Le(g))||void 0===t?void 0:t.data;n&&(n.data=[...new Set([e.channelId,...n.data])],qe(g,n),m(n))},b=(e=!1)=>{var t,n,r;const o=null===(t=Le(g))||void 0===t?void 0:t.data,s=null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(Dl,Object.assign(Object.assign({},c),{page:null!==(r=e||null==o?void 0:o.params.page)&&void 0!==r?r:{limit:l}}));se(i,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(ce("channel"))])]),qe(g,o),m(o)}),oe(u,y))};return d.push(Rl(v()),pa(v()),Pl(v()),Fl(v()),Ml(v()),jl(v()),Nl(v()),Bl(v()),$a((()=>null))),b(!0),He(g),()=>{r(`getChannels(tmpid: ${i}) > dispose`),d.forEach((e=>e()))}},MARKER_INCLUDED_CHANNEL_TYPE:ua,isUnreadCountSupport:da,convertFromRaw:ha,prepareChannelPayload:fa});const Vl=async e=>{const t=we();t.log("message/getMessages",e);const{data:n}=await t.http.get("/api/v5/messages/list",{params:{messageIds:e.map(encodeURIComponent)}}),r=await Da(n),o=t.cache&&Date.now();t.cache&&Yi(r,{cachedAt:o});const{messages:s}=r;return ut("local.message.fetched",{messages:s}),{data:s,cachedAt:o}};Vl.locally=e=>{var t;const n=we();if(n.log("message/getMessages.locally",e),!n.cache)return;const r=e.map((e=>Le(["message","get",e]))).filter(Boolean),o=r.map((({data:e})=>e)),s=null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0];return(null==r?void 0:r.length)<e.length?void 0:{data:o,cachedAt:s.cachedAt}};var Wl={},Kl={},Ql={};Object.defineProperty(Ql,"__esModule",{value:!0}),Ql.bytesToString=Ql.stringToBytes=Ql.NIL=Ql.X500=Ql.OID=Ql.URL=Ql.DNS=Ql.hexToByte=Ql.byteToHex=void 0;let Jl=[],Gl={};for(var Yl=0;Yl<256;Yl++)Jl[Yl]=(Yl+256).toString(16).substr(1),Gl[Jl[Yl]]=Yl;Ql.byteToHex=Jl,Ql.hexToByte=Gl,Ql.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Ql.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",Ql.OID="6ba7b812-9dad-11d1-80b4-00c04fd430c8",Ql.X500="6ba7b814-9dad-11d1-80b4-00c04fd430c8",Ql.NIL="00000000-0000-0000-0000-000000000000";Ql.stringToBytes=e=>{e=unescape(encodeURIComponent(e));const t=new Uint8Array(e.length);for(let n=0;n<e.length;++n)t[n]=e.charCodeAt(n);return t};Ql.bytesToString=e=>{const t=new Uint8Array(e,0,e.byteLength);return String.fromCharCode.apply(null,Array.from(t))},Object.defineProperty(Kl,"__esModule",{value:!0}),Kl.parse=void 0;const Xl=Ql;Kl.parse=(e,t,n)=>{let r=t&&n||0,o=0;for(t=t||[],e.toLowerCase().replace(/[0-9a-f]{2}/g,(e=>(o<16&&t&&(t[r+o++]=Xl.hexToByte[e]),"")));o<16;)t[r+o++]=0;return t};var Zl={};Object.defineProperty(Zl,"__esModule",{value:!0}),Zl.unparse=void 0;const eu=Ql;Zl.unparse=(e,t)=>{let n=t||0,r=eu.byteToHex;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++]]};var tu={},nu={};Object.defineProperty(nu,"__esModule",{value:!0});nu.default=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;var ru=_e&&_e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(tu,"__esModule",{value:!0}),tu.validate=void 0;const ou=ru(nu);tu.validate=e=>"string"==typeof e&&ou.default.test(e);var su={};Object.defineProperty(su,"__esModule",{value:!0}),su.version=void 0;const iu=tu;su.version=e=>{if(!iu.validate(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)};var au={},cu={};Object.defineProperty(cu,"__esModule",{value:!0}),cu.stringify=void 0;const lu=tu,uu=[];for(let e=0;e<256;++e)uu.push((e+256).toString(16).substr(1));cu.stringify=(e,t=0)=>{const n=(uu[e[t+0]]+uu[e[t+1]]+uu[e[t+2]]+uu[e[t+3]]+"-"+uu[e[t+4]]+uu[e[t+5]]+"-"+uu[e[t+6]]+uu[e[t+7]]+"-"+uu[e[t+8]]+uu[e[t+9]]+"-"+uu[e[t+10]]+uu[e[t+11]]+uu[e[t+12]]+uu[e[t+13]]+uu[e[t+14]]+uu[e[t+15]]).toLowerCase();if(!lu.validate(n))throw TypeError("Stringified UUID is invalid");return n};var du={};Object.defineProperty(du,"__esModule",{value:!0}),du.rng=void 0;du.rng=()=>{let e=new Array(16);for(let t=0;t<16;t++)e[t]=255&256*Math.random()+0;return e},Object.defineProperty(au,"__esModule",{value:!0}),au.v1=void 0;const hu=cu,fu=du;let pu,gu,mu=0,yu=0;au.v1=(e,t,n=0)=>{let r=t&&n||0;const o=t||new Uint8Array(16);let s=e&&e.node?e.node:pu,i=e&&e.clockseq?e.clockseq:gu;if(null==s||null==i){const t=e&&e.random?e.random:e&&e.rng?e.rng():fu.rng();null==s&&(s=pu=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==i&&(i=gu=16383&(t[6]<<8|t[7]))}let a=e&&e.msecs?e.msecs:Date.now(),c=e&&e.nsecs?e.nsecs:yu+1;const l=a-mu+(c-yu)/1e4;if(l<0&&e&&!e.clockseq&&(i=i+1&16383),(l<0||a>mu)&&e&&!e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");mu=a,yu=c,gu=i,a+=122192928e5;const u=(1e4*(268435455&a)+c)%4294967296;o[r++]=u>>>24&255,o[r++]=u>>>16&255,o[r++]=u>>>8&255,o[r++]=255&u;const d=a/4294967296*1e4&268435455;o[r++]=d>>>8&255,o[r++]=255&d,o[r++]=d>>>24&15|16,o[r++]=d>>>16&255,o[r++]=i>>>8|128,o[r++]=255&i;for(let e=0;e<6;++e)o[r+e]=s[e];return t||hu.stringify(o)};var vu={};Object.defineProperty(vu,"__esModule",{value:!0}),vu.v4=void 0;const bu=Zl,wu=du;vu.v4=(e,t,n)=>{let r=t&&n||0,o=wu.rng();if(!e||e instanceof String||(e.random&&(o=e.random),e.rng&&(o=e.rng())),o[6]=15&o[6]|64,o[8]=63&o[8]|128,t)for(var s=0;s<16;s++)t[r+s]=o[s];return t||bu.unparse(o)};var Cu={},_u={};Object.defineProperty(_u,"__esModule",{value:!0}),_u.v35=void 0;const ku=cu,Su=Kl,Au=Ql;_u.v35=(e,t,n)=>(e,r,o,s=0)=>{if("string"==typeof e&&(e=Au.stringToBytes(e)),"string"==typeof r&&(r=Su.parse(r)),r&&16!==r.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let i=new Uint8Array(16+e.length);if(i.set(r),i.set(e,r.length),i=Au.stringToBytes(n(Au.bytesToString(i))),i[6]=15&i[6]|t,i[8]=63&i[8]|128,o)for(let e=0;e<16;++e)o[s+e]=i[e];return o||ku.stringify(i)};var Eu={};!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.any_hmac_sha1=e.b64_hmac_sha1=e.hex_hmac_sha1=e.any_sha1=e.b64_sha1=e.hex_sha1=void 0;let t=0,n="";e.hex_sha1=e=>s(r(c(e))),e.default=e.hex_sha1;e.b64_sha1=e=>i(r(c(e)));e.any_sha1=(e,t)=>a(r(c(e)),t);e.hex_hmac_sha1=(e,t)=>s(o(c(e),c(t)));e.b64_hmac_sha1=(e,t)=>i(o(c(e),c(t)));e.any_hmac_sha1=(e,t,n)=>a(o(c(e),c(t)),n);const r=e=>u(d(l(e),8*e.length)),o=(e,t)=>{let n=l(e);n.length>16&&(n=d(n,8*e.length));let r=Array(16),o=Array(16);for(var s=0;s<16;s++)r[s]=909522486^n[s],o[s]=1549556828^n[s];var i=d(r.concat(l(t)),512+8*t.length);return u(d(o.concat(i),672))},s=e=>{for(var n,r=t?"0123456789ABCDEF":"0123456789abcdef",o="",s=0;s<e.length;s++)n=e.charCodeAt(s),o+=r.charAt(n>>>4&15)+r.charAt(15&n);return o},i=e=>{for(var t="",r=e.length,o=0;o<r;o+=3)for(var s=e.charCodeAt(o)<<16|(o+1<r?e.charCodeAt(o+1)<<8:0)|(o+2<r?e.charCodeAt(o+2):0),i=0;i<4;i++)8*o+6*i>8*e.length?t+=n:t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(s>>>6*(3-i)&63);return t},a=(e,t)=>{var n,r,o,s,i=t.length,a=[],c=Array(Math.ceil(e.length/2));for(n=0;n<c.length;n++)c[n]=e.charCodeAt(2*n)<<8|e.charCodeAt(2*n+1);for(;c.length>0;){for(s=[],o=0,n=0;n<c.length;n++)o=(o<<16)+c[n],o-=(r=Math.floor(o/i))*i,(s.length>0||r>0)&&(s[s.length]=r);a[a.length]=o,c=s}var l="";for(n=a.length-1;n>=0;n--)l+=t.charAt(a[n]);var u=Math.ceil(8*e.length/(Math.log(t.length)/Math.log(2)));for(n=l.length;n<u;n++)l=t[0]+l;return l},c=e=>{for(var t,n,r="",o=-1;++o<e.length;)t=e.charCodeAt(o),n=o+1<e.length?e.charCodeAt(o+1):0,t>=55296&&t<=56319&&n>=56320&&n<=57343&&(t=65536+((1023&t)<<10)+(1023&n),o++),t<=127?r+=String.fromCharCode(t):t<=2047?r+=String.fromCharCode(192|t>>>6&31,128|63&t):t<=65535?r+=String.fromCharCode(224|t>>>12&15,128|t>>>6&63,128|63&t):t<=2097151&&(r+=String.fromCharCode(240|t>>>18&7,128|t>>>12&63,128|t>>>6&63,128|63&t));return r},l=e=>{for(var t=Array(e.length>>2),n=0;n<t.length;n++)t[n]=0;for(n=0;n<8*e.length;n+=8)t[n>>5]|=(255&e.charCodeAt(n/8))<<24-n%32;return t},u=e=>{for(var t="",n=0;n<32*e.length;n+=8)t+=String.fromCharCode(e[n>>5]>>>24-n%32&255);return t},d=(e,t)=>{e[t>>5]|=128<<24-t%32,e[15+(t+64>>9<<4)]=t;for(var n=Array(80),r=1732584193,o=-271733879,s=-1732584194,i=271733878,a=-1009589776,c=0;c<e.length;c+=16){for(var l=r,u=o,d=s,m=i,y=a,v=0;v<80;v++){n[v]=v<16?e[c+v]:g(n[v-3]^n[v-8]^n[v-14]^n[v-16],1);let t=p(p(g(r,5),h(v,o,s,i)),p(p(a,n[v]),f(v)));a=i,i=s,s=g(o,30),o=r,r=t}r=p(r,l),o=p(o,u),s=p(s,d),i=p(i,m),a=p(a,y)}return[r,o,s,i,a]},h=(e,t,n,r)=>e<20?t&n|~t&r:e<40?t^n^r:e<60?t&n|t&r|n&r:t^n^r,f=e=>e<20?1518500249:e<40?1859775393:e<60?-1894007588:-899497514,p=(e,t)=>{var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n},g=(e,t)=>e<<t|e>>>32-t}(Eu);var Iu=_e&&_e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Cu,"__esModule",{value:!0}),Cu.v5=void 0;const Ou=_u,Tu=Iu(Eu);Cu.v5=Ou.v35("v5",80,Tu.default),Object.defineProperty(Wl,"__esModule",{value:!0});const xu=Kl,Ru=Zl,Pu=tu,Mu=su,ju=au,Fu=vu,Nu=Cu,Bu=Ql;var Uu=Wl.default={parse:xu.parse,unparse:Ru.unparse,validate:Pu.validate,version:Mu.version,v1:ju.v1,v4:Fu.v4,v5:Nu.v5,NIL:Bu.NIL,DNS:Bu.DNS,URL:Bu.URL,OID:Bu.OID,X500:Bu.X500};const Du=()=>`LOCAL_${Uu.v4().toString()}`;let Lu;const qu=async e=>{const t=we();t.log("message/createMessage",e);const n=e.referenceId||Lu||Du();Lu=void 0;const{data:r}=await t.http.post("/api/v5/messages",Object.assign(Object.assign({},La(e)),{referenceId:n})),o=await Da(r),{messages:s}=o,i=t.cache&&Date.now();return t.cache&&(He(["message","get",n]),Yi(o,{cachedAt:i})),ut("local.message.created",{messages:s}),{data:s[0],cachedAt:i}};qu.optimistically=e=>{var t,n,{referenceId:r}=e,o=Xi(e,["referenceId"]);const s=we();if(!s.cache)return;Lu=r||Du();const i=Object.assign({messageId:Lu,uniqueId:Lu},o);s.log("message/createMessage.optimistically",i);const a=Le(["subChannel","get",o.subChannelId]);if(a&&(ze(["subChannel","get",o.subChannelId],Object.assign(Object.assign({},a.data),{messageCount:a.data.messageCount+1})),a.data.channelId===a.data.subChannelId)){const e=Le(["channel","get",a.data.channelId]);(null==e?void 0:e.data)&&ze(["channel","get",a.data.channelId],Object.assign(Object.assign({},e.data),{messageCount:(null!==(t=e.data.messageCount)&&void 0!==t?t:0)+1}))}const c=(new Date).toISOString(),l=Object.assign({creatorId:s.userId,channelSegment:(null!==(n=null==a?void 0:a.data.messageCount)&&void 0!==n?n:0)+1,childrenNumber:0,createdAt:c,updatedAt:c},i);return qe(["message","get",l.messageId],l,{cachedAt:-5}),ut("local.message.created",{messages:[l]}),{cachedAt:-5,data:l}};const $u=async(e,t)=>{const n=we();n.log("message/updateMessage",t),console.warn("MessageRepository.updateMessage will be replaced with MessageRepository.editMessage");const{data:r}=await n.http.put(`/api/v5/messages/${encodeURIComponent(e)}`,La(t)),o=await Da(r),s=n.cache&&Date.now();n.cache&&Yi(o,{cachedAt:s});const{messages:i}=o;return ut("local.message.updated",{messages:i}),{data:i.find((t=>t.messageId===e)),cachedAt:s}};$u.optimistically=(e,t)=>{const n=we();if(n.log("message/updateMessage.optimistically",t),!n.cache)return;const r=Le(["message","get",e]);if(!r)return;const o=Object.assign(Object.assign(Object.assign({},r.data),t),{updatedAt:(new Date).toISOString()});return ze(["message","get",e],o,{cachedAt:-1}),ut("local.message.updated",{messages:[o]}),{data:o,cachedAt:-1}};const zu=async(e,t)=>{const n=we();n.log("message/editMessage",t);const{data:r}=await n.http.put(`/api/v5/messages/${encodeURIComponent(e)}`,La(t)),o=await Da(r),s=n.cache&&Date.now();n.cache&&Yi(o,{cachedAt:s});const{messages:i}=o;return ut("local.message.updated",{messages:i}),{data:i.find((t=>t.messageId===e)),cachedAt:s}};zu.optimistically=(e,t)=>{const n=we();if(n.log("message/editMessage.optimistically",t),!n.cache)return;const r=Le(["message","get",e]);if(!r)return;const o=Object.assign(Object.assign(Object.assign({},r.data),t),{updatedAt:(new Date).toISOString()});return ze(["message","get",e],o,{cachedAt:-1}),ut("local.message.updated",{messages:[o]}),{data:o,cachedAt:-1}};const Hu=async e=>{const t=we();t.log("message/deleteMessage",e),await t.http.delete(`/api/v5/messages/${encodeURIComponent(e)}`);const n=await el(e);return ut("local.message.deleted",{messages:[n.data]}),n.data};Hu.optimistically=e=>{we().log("message/deleteMessage.optimistically",e);const t=Le(["message","get",e]);if(!t)return;const n=Object.assign(Object.assign({},t.data),{isDeleted:!0,updatedAt:(new Date).toISOString()});return ze(["message","get",e],n,{cachedAt:-1}),ut("local.message.deleted",{messages:[n]}),{data:n,cachedAt:-1}};const Vu=async e=>{const t=we();t.log("message/softDeleteMessage",e),await t.http.delete(`/api/v5/messages/${encodeURIComponent(e)}`);const n=await el(e);return ut("local.message.deleted",{messages:[n.data]}),n.data};Vu.optimistically=e=>{we().log("message/softDeleteMessage.optimistically",e);const t=Le(["message","get",e]);if(!t)return;const n=Object.assign(Object.assign({},t.data),{isDeleted:!0,updatedAt:(new Date).toISOString()});return ze(["message","get",e],n,{cachedAt:-1}),ut("local.message.deleted",{messages:[n]}),{data:n,cachedAt:-1}};const Wu=async e=>{const t=we();t.log("user/getReadUsers",e);const{page:n,messageId:r}=e,o=Xi(e,["page","messageId"]),{data:s}=await t.http.get(`/api/v1/markers/messages/${r}/read-users`,{params:Object.assign(Object.assign({},o),{options:{token:J(n,"afterbeforeraw")}})}),{paging:i,publicUserIds:a}=s,c=Xi(s,["paging","publicUserIds"]),l=t.cache&&Date.now();if(t.cache){Yi(c,{cachedAt:l});const e=["read-user","query",Object.assign(Object.assign({messageId:r},o),{options:Object.assign({},n)})];qe(e,{users:a,paging:i})}let u=[];a.length>0&&({data:u}=await Lc(a));return{data:u,cachedAt:l,prevPage:G(i.previous),nextPage:G(i.next)}};Wu.locally=e=>{var t;const n=we();if(n.log("user/getReadUsers.locally",e),!n.cache)return;const{page:r}=e,o=Xi(e,["page"]),s=["read-user","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})],{data:i,cachedAt:a}=null!==(t=Le(s))&&void 0!==t?t:{},c=null==i?void 0:i.users.map((e=>{var t;return null===(t=Le(["user","get",e]))||void 0===t?void 0:t.data}));if(!c||c.some((e=>!e)))return;return{data:c,cachedAt:a,prevPage:G(null==i?void 0:i.paging.previous),nextPage:G(null==i?void 0:i.paging.next)}};const Ku=async e=>{const t=we();t.log("user/getDeliveredUsers",e);const{page:n,messageId:r}=e,o=Xi(e,["page","messageId"]),{data:s}=await t.http.get(`/api/v1/markers/messages/${r}/delivered-users`,{params:Object.assign(Object.assign({},o),{options:{token:J(n,"afterbeforeraw")}})}),{paging:i,publicUserIds:a}=s,c=Xi(s,["paging","publicUserIds"]),l=t.cache&&Date.now();if(t.cache){Yi(c,{cachedAt:l});const e=["delivered-user","query",Object.assign(Object.assign({messageId:r},o),{options:Object.assign({},n)})];qe(e,{users:a,paging:i})}let u=[];a.length>0&&({data:u}=await Lc(a));return{data:u,cachedAt:l,prevPage:G(i.previous),nextPage:G(i.next)}};Ku.locally=e=>{var t;const n=we();if(n.log("user/getDeliveredUsers.locally",e),!n.cache)return;const{page:r}=e,o=Xi(e,["page"]),s=["delivered-user","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})],{data:i,cachedAt:a}=null!==(t=Le(s))&&void 0!==t?t:{},c=null==i?void 0:i.users.map((e=>{var t;return null===(t=Le(["user","get",e]))||void 0===t?void 0:t.data}));if(!c||c.some((e=>!e)))return;return{data:c,cachedAt:a,prevPage:G(null==i?void 0:i.paging.previous),nextPage:G(null==i?void 0:i.paging.next)}};const Qu=async e=>{const t=we();t.log("message/queryMessages",e);const n=qa(e),{data:r}=await t.http.get("/api/v5/messages",{params:n}),{paging:o}=r,s=Xi(r,["paging"]),i=await Da(s),{messages:a}=i,c=t.cache&&Date.now();if(t.cache){Yi(i,{cachedAt:c});qe(["message","query",n],{messages:a.map(ce("message")),paging:o})}ut("local.message.fetched",{messages:a});const l=Y(o.next);return{data:a,cachedAt:c,prevPage:Y(o.previous),nextPage:l}};var Ju=Object.freeze({__proto__:null,getMessageByIds:Vl,createMessage:qu,updateMessage:$u,editMessage:zu,deleteMessage:Hu,softDeleteMessage:Vu,markAsDelivered:async(e,t)=>{const n=we();n.log("message/markAsDelivered",e,t);const{data:r}=await n.http.put(`/api/v1/markers/message-feeds/${e}/mark-delivering`,{messageId:t}),o=n.cache&&Date.now();return n.cache&&Yi(r,{cachedAt:o}),!0},getReadUsers:Wu,getDeliveredUsers:Ku,flagMessage:async e=>{const t=we();t.log("message/flag",e);const{data:n}=await t.http.post(`/api/v5/messages/${encodeURIComponent(e)}/flags`);if(t.cache){const e=await Da(n);Yi(e)}return ut("message.flagged",n),!!n},unflagMessage:async e=>{const t=we();t.log("message/unflag",e);const{data:n}=await t.http.delete(`/api/v5/messages/${encodeURIComponent(e)}/flags`);if(t.cache){const e=await Da(n);Yi(e)}return ut("message.unflagged",n),!!n},isMessageFlaggedByMe:async e=>{const t=we();t.log("message/isMessageFlaggedByMe",e);const{data:n}=await t.http.get(`/api/v5/messages/${encodeURIComponent(e)}/flags`);return n.result},onMessageCreated:$a,onMessageUpdated:za,onMessageDeleted:Ha,onMessageFlagged:Va,onMessageUnflagged:Wa,onMessageFlagCleared:Ka,onMessageReactionAdded:Qa,onMessageReactionRemoved:Ja,onMessageFetched:Ga,getMessage:(e,t)=>Na(e,t,"messageId",el,[Ga,za,Ha,Va,Wa,Ka,Qa,Ja]),getMessages:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getMessages(tmpid: ${s}) > listen`);const{limit:i}=e,a=Xi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["message","collection",{subChannelId:e.subChannelId}],g=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["message","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.includeDeleted||(s=Ve(s,"isDeleted",!1)),t({onNextPage:v,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},m=t=>t=>{var n;const r=null===(n=Le(d))||void 0===n?void 0:n.data;e.subChannelId===(null==t?void 0:t.subChannelId)&&r&&(r.data=[...new Set([t.messageId,...r.data])],qe(d,r),g(r))},v=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re(Qu,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:i};e&&(o.data=[...new Set([...i,...e.map(ce("message"))])]),qe(d,o),g(o)}),oe(l,y))};return u.push(Ga(m()),$a(m()),za(m()),Ha(m()),Va(m()),Wa(m()),Ka(m()),Qa(m()),Ja(m())),v(!0),u.push((()=>He(d))),()=>{r(`getMessages(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},observeMessage:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observeMessage(tmpid: ${o}) > listen`),console.log("observeMessage will be deprecated on 15th November 2022, please use liveMessage instead.");const s=(n,r)=>{var o,s,i;if((null===(o=n.data)||void 0===o?void 0:o.messageId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(s=t.onEvent)||void 0===s||s.call(t,r,n)),null===(i=t[r])||void 0===i||i.call(t,n)}},i=[];return i.push(za((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Ha((e=>s({data:e,loading:!1,origin:"event"},"onDelete")))),"no_fetch"!==n&&se(re(el,e),(e=>e.data&&s(e,"onFetch")),oe(n)),()=>{r(`observeMessages(tmpid: ${o}) > dispose`),i.forEach((e=>e()))}},observeMessages:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeMessages(tmpid: ${r}) > listen`);const o=[],s=(n,r)=>{var o,s,i;if((null===(o=n.data)||void 0===o?void 0:o.subChannelId)===e){if(t instanceof Function)return t(n);null===(s=t.onEvent)||void 0===s||s.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push($a((e=>s({data:e,loading:!1,origin:"event"},"onCreate"))),za((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Ha((e=>s({data:e,loading:!1,origin:"event"},"onDelete")))),()=>{n(`observeMessages(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},convertFromRaw:Ua,prepareMessagePayload:Da,convertParams:La,convertQueryParams:qa});const Gu=async e=>{const t=we();t.log("channel/getSubChannels",e);const n=await t.http.get("/api/v5/message-feeds/list",{params:{messageFeedIds:e.map(encodeURIComponent)}}),r=await ec(n.data),o=t.cache&&Date.now();return t.cache&&Yi(r,{cachedAt:o}),ut("local.message-feed.fetched",r),{data:r.messageFeeds,cachedAt:o}};Gu.locally=e=>{var t;const n=we();if(n.log("channel/getSubChannels.locally",e),!n.cache)return;const r=e.map((e=>Le(["subChannel","get",e]))).filter(Boolean);if((null==r?void 0:r.length)<e.length)return;return{data:r.map((({data:e})=>e)),cachedAt:(null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0]).cachedAt}};const Yu=async(e,t=!1)=>{const n=we(),r=await oc(e);await n.http.delete(`/api/v5/message-feeds/${encodeURIComponent(e)}`,{params:{permanent:t}});const o=Object.assign(Object.assign({},r.data),{isDeleted:!0,updatedAt:pe(r.data.updatedAt)});return t?setTimeout((()=>{rc("subChannel",e)}),0):ze(["subChannel","get",e],o),ut("local.message-feed.deleted",{messageFeeds:[o]}),o},Xu=e=>lt(we(),"onSubChannelFetched","local.message-feed.fetched",(t=>e(t.messageFeeds[0])));function Zu(e,t){const n=[...e,...t];if(0===n.length)return[];const r=de(n[0]),o=new Map;return n.forEach((e=>o.set(e[r],e))),Array.from(o.values())}const ed=async e=>{const t=we();t.log("channel/querySubChannels",e);const n=tc(e),{page:r={limit:10},channelId:o,includeDeleted:s}=n,i=Xi(n,["page","channelId","includeDeleted"]),a=(await t.http.get(`/api/v5/message-feeds/channel/${o}`,{params:Object.assign(Object.assign({},i),{isDeleted:Ba(s),options:{token:J(r,"skiplimit")}})})).data,{paging:c}=a,l=Xi(a,["paging"]),u=await ec(l),d=u.messageFeeds,h=t.cache&&Date.now();if(t.cache){Yi(u,{cachedAt:h});const e=["subChannel","query",Object.assign(Object.assign({channelId:o},i),{options:Object.assign({},r)})];qe(e,{subChannels:d.map(ce("subChannel")),paging:c})}ut("local.message-feed.fetched",u);const f=G(c.next);return{data:d,cachedAt:h,prevPage:G(c.previous),nextPage:f}};ed.locally=e=>{var t,n,r;we().log("channel/querySubChannels.locally",e);const o=null!==(t=tc(e))&&void 0!==t?t:{},{page:s={limit:10},channelId:i}=o,a=Xi(o,["page","channelId"]),c=["subChannel","query",Object.assign(Object.assign({channelId:i},a),{options:Object.assign({},s)})],{data:l,cachedAt:u}=null!==(n=Le(c))&&void 0!==n?n:{};if(!(null==l?void 0:l.subChannels.length))return;const d=l.subChannels.map((e=>Le(["subChannel","get",e]))).filter(Boolean).map((({data:e})=>e)),h=G(null==l?void 0:l.paging.previous),f=G(null==l?void 0:l.paging.next);return d.length===(null===(r=null==l?void 0:l.subChannels)||void 0===r?void 0:r.length)?{data:d,cachedAt:u,prevPage:h,nextPage:f}:void 0};var td=Object.freeze({__proto__:null,getSubChannelByIds:Gu,createSubChannel:async e=>{const t=we();t.log("user/createSubChannel",e);const n=await t.http.post("/api/v5/message-feeds",{channelId:e.channelId,name:e.displayName}),r=await ec(n.data),o=t.cache&&Date.now();return t.cache&&Yi(r,{cachedAt:o}),ut("message-feed.created",n.data),{data:r.messageFeeds[0],cachedAt:o}},updateSubChannel:async(e,t)=>{const n=we();n.log("channel/updateSubChannel",e,t);const r=await n.http.put(`/api/v5/message-feeds/${encodeURIComponent(e)}`,{name:t.displayName}),o=await ec(r.data),s=n.cache&&Date.now();return n.cache&&Yi(o,{cachedAt:s}),ut("message-feed.updated",r.data),{data:o.messageFeeds[0],cachedAt:s}},deleteSubChannel:Yu,hardDeleteSubChannel:async e=>{we().log("channel/hardDeleteSubChannel",e);return await Yu(e,!0)},softDeleteSubChannel:async e=>{we().log("channel/softDeleteSubChannel",e);return await Yu(e,!1)},startReadingAPI:sc,stopReadingAPI:ic,onSubChannelCreated:hc,onSubChannelUpdated:fc,onSubChannelDeleted:pc,getSubChannel:(e,t)=>Na(e,t,"subChannelId",oc,[Xu,fc,pc]),getSubChannels:(e,t,n)=>{const{log:r,cache:o}=we(),s=Date.now();r(`getSubChannels(tmpid: ${s}) > listen`),o||console.log(p);const{limit:i=h}=e,a=Xi(e,["limit"]),{policy:c=f}=null!=n?n:{};let l;const u=[],d=n=>{var r;let o=n.data;e.includeDeleted||(o=Ve(o,"isDeleted",!1)),o.sort(nt),t({onNextPage:m,data:o,hasNextPage:!!(null===(r=n.params)||void 0===r?void 0:r.page),loading:n.loading,error:n.error})},g=t=>n=>{e.channelId===n.channelId&&l&&function(e,t,n){const r=de(t),o=e.find((e=>e[r]===t[r]));return o?fe(o,t):"onCreate"===n}(l.data,n,t)&&(l.data="onCreate"===t?[n,...l.data]:l.data.map((e=>e.subChannelId===n.subChannelId?n:e)),d(l))},m=()=>{var e;const t=l?l.data:[];if(t.length>0&&!(null==l?void 0:l.params.page))return;const n=re(ed,Object.assign(Object.assign({},a),{page:null!==(e=null==l?void 0:l.params.page)&&void 0!==e?e:{limit:i}}));se(n,(({data:e,error:n,loading:r,nextPage:o})=>{l={loading:r,error:n,params:{page:o},data:e?Zu(t,e):t},d(l)}),oe(c,y))};return u.push(hc(g("onCreate")),pc(g("onDelete")),Xu(g("onFetch")),fc(g("onUpdate"))),m(),()=>{r(`getSubChannels(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},startReading:e=>(cc[e]=!0,0===ac.length&&(uc(),dc(e)),sc(e)),stopReading:e=>(cc[e]=!1,ac.forEach((e=>e())),ac=[],ic(e))});const nd=e=>{var t;return null!==(t=Object.keys(n).find((t=>e.needApprovalOnPostCreation===n[t].needApprovalOnPostCreation&&e.onlyAdminCanPost===n[t].onlyAdminCanPost)))&&void 0!==t?t:r},rd=e=>{const t=e.communities.map((e=>{var{needApprovalOnPostCreation:t,onlyAdminCanPost:n}=e,r=Xi(e,["needApprovalOnPostCreation","onlyAdminCanPost"]);return Object.assign({postSetting:nd({needApprovalOnPostCreation:t,onlyAdminCanPost:n})},r)})),n=Zi(e.communityUsers);return Object.assign(Object.assign({},e),{communities:t,communityUsers:n})},od=e=>{const{postSetting:t}=e,r=Xi(e,["postSetting"]);return Object.assign(Object.assign({},r),t?n[t]:void 0)},sd=async e=>{const t=we();t.log("community/getCommunities",e);const{data:n}=await t.http.get("/api/v3/communities/list",{params:{communityIds:e}}),r=rd(n),o=t.cache&&Date.now();return t.cache&&Yi(r,{cachedAt:o}),{data:r.communities,cachedAt:o}};sd.locally=e=>{var t;const n=we();if(n.log("community/getCommunities.locally",e),!n.cache)return;const r=e.map((e=>Le(["community","get",e]))).filter(Boolean),o=r.map((({data:e})=>e)),s=null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0];return(null==r?void 0:r.length)<e.length?void 0:{data:o,cachedAt:s.cachedAt}};const id=async e=>{const t=we();t.log("community/getCommunity",e);const{data:n}=await t.http.get(`/api/v3/communities/${e}`),r=rd(n),o=t.cache&&Date.now();t.cache&&Yi(r,{cachedAt:o});const{communities:s}=r;return{data:s.find((t=>t.communityId===e)),cachedAt:o}};id.locally=e=>{const t=we();if(t.log("community/getCommunity.locally",e),!t.cache)return;const n=Le(["community","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const ad=async e=>{const t=we();t.log("channel/getTopTrendingCommunities",e);const{limit:n=5}=null!=e?e:{},{data:r}=await t.http.get("/api/v3/communities/top-trending",{params:{options:{limit:n}}}),o=rd(r),{communities:s}=o,i=t.cache&&Date.now();if(t.cache){Yi(o,{cachedAt:i});qe(["community","top-trending",{params:{options:{limit:n}}}],{communities:s.map(ce("community"))})}return{data:s,cachedAt:i}};ad.locally=e=>{var t,n;const r=we();if(r.log("community/getTopTrendingCommunities.locally",e),!r.cache)return;const{limit:o=5}=null!=e?e:{},s=["community","top-trending",{params:{options:{limit:o}}}],{data:i,cachedAt:a}=null!==(t=Le(s))&&void 0!==t?t:{};if(!(null==i?void 0:i.communities.length))return;const c=i.communities.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e));return c.length===(null===(n=null==i?void 0:i.communities)||void 0===n?void 0:n.length)?{data:c,cachedAt:a}:void 0};const cd=async e=>{const t=we();t.log("channel/getRecommendedCommunities",e);const{limit:n=5}=null!=e?e:{},{data:r}=await t.http.get("/api/v3/communities/recommended",{params:{options:{limit:n}}}),o=rd(r),{communities:s}=o,i=t.cache&&Date.now();if(t.cache){Yi(o,{cachedAt:i});qe(["community","recommended",{params:{options:{limit:n}}}],{communities:s.map(ce("community"))})}return{data:s,cachedAt:i}};cd.locally=e=>{var t,n;const r=we();if(r.log("community/getRecommendedCommunities.locally",e),!r.cache)return;const{limit:o=5}=null!=e?e:{},s=["community","recommended",{params:{options:{limit:o}}}],{data:i,cachedAt:a}=null!==(t=Le(s))&&void 0!==t?t:{};if(!(null==i?void 0:i.communities.length))return;const c=i.communities.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e));return c.length===(null===(n=null==i?void 0:i.communities)||void 0===n?void 0:n.length)?{data:c,cachedAt:a}:void 0};const ld=(e,t)=>{const n=we();return lt(n,e,e,(e=>{const r=rd(e);if(n.cache){Yi(r);const e=Le(["community","get",r.communities[0].communityId]);t(e.data)}else t(r.communities[0])}))},ud=e=>ld("community.created",e),dd=e=>ld("community.updated",e),hd=e=>ld("community.deleted",e);function fd(e,t){return e.map((e=>{const n=t.some((t=>function(e,t){const{userId:n}=ht();return e.communityId===t.communityId&&t.userId===n}(e,t)&&"none"!==t.communityMembership));return Object.assign(Object.assign({},e),{isJoined:n})}))}function pd(e,t,n){return!!e.permissions.some((e=>e===n))||t.users.find((t=>t.userId===e.userId)).permissions.some((e=>e===n))}function gd(e,t){return"community.joined"===e||"community.left"===e?t.communityUsers[0]:"community.userRemoved"===e?t.communityUsers.filter((e=>"none"===e.communityMembership))[0]:"community.userBanned"===e?t.communityUsers.filter((e=>"banned"===e.communityMembership))[0]:"community.userUnbanned"===e?t.communityUsers.filter((e=>!pd(e,t,"BAN_COMMUNITY_USER")))[0]:t.communityUsers.filter((e=>!pd(e,t,"ADD_COMMUNITY_USER")))[0]}const md=(e,t)=>{const n=we();return lt(n,e,e,(r=>{const o=rd(r),{communities:s,communityUsers:i}=o,a=fd(s,i);if(o.communities=a,n.cache){Yi(o);const n=Le(["community","get",o.communities[0].communityId]),r=Le(["communityUsers","get",ce("communityUsers")(gd(e,o))]);t(n.data,r.data)}else t(o.communities[0],gd(e,o))}))},yd=e=>md("community.userAdded",e),vd=e=>md("community.userRemoved",e),bd=e=>md("community.userBanned",e),wd=e=>md("community.userChanged",e),Cd=e=>md("community.userUnbanned",e),_d=e=>md("community.roleAdded",e),kd=e=>md("community.roleRemoved",e),Sd=e=>md("community.joined",e),Ad=e=>md("community.left",e),Ed=async e=>{const t=we();t.log("channel/queryCommunities",e);const n=null!=e?e:{},{page:r}=n,o=Xi(n,["page"]),s=null!=o?o:{},{displayName:i,membership:a,includeDeleted:c}=s,l=Xi(s,["displayName","membership","includeDeleted"]),{data:u}=await t.http.get("/api/v3/communities",{params:Object.assign(Object.assign({},l),{isDeleted:Ba(c),keyword:i,filter:a,options:{token:J(r,"skiplimit")}})}),{paging:d}=u,h=Xi(u,["paging"]),f=rd(h),{communities:p}=f,g=t.cache&&Date.now();if(t.cache){Yi(f,{cachedAt:g});const e=["community","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];qe(e,{communities:p.map(ce("community")),paging:d})}const m=G(d.next);return{data:p,cachedAt:g,prevPage:G(d.previous),nextPage:m}};var Id=Object.freeze({__proto__:null,addRoles:async(e,t,n)=>{const r=we();r.log("community/moderation/addRoles",e,t,n);const{data:o}=await r.http.post(`/api/v4/communities/${e}/users/roles`,{communityId:e,roles:t,userIds:n}),s=ea(o,"communityUsers");r.cache&&Yi(s);const{communityUsers:i}=s;return!!i.find((n=>n.communityId===e&&t.some((e=>n.roles.includes(e)))))},removeRoles:async(e,t,n)=>{const r=we();r.log("community/moderation/removeRoles",e,t,n);const{data:o}=await r.http.delete(`/api/v4/communities/${e}/users/roles`,{data:{communityId:e,roles:t,userIds:n}}),s=ea(o,"communityUsers");r.cache&&Yi(s);const{communityUsers:i}=s;return!!i.find((n=>n.communityId===e&&!t.some((e=>n.roles.includes(e)))))},banMembers:async(e,t)=>{const n=we();n.log("community/banMembers",{userIds:t,communityId:e});const{data:r}=await n.http.put(`/api/v3/communities/${e}/users/ban`,{userIds:t}),o=ea(r,"communityUsers"),s=n.cache&&Date.now();n.cache&&Yi(o,{cachedAt:s});const{communityUsers:i}=o;return{data:i.filter((e=>t.includes(e.userId))),cachedAt:s}},unbanMembers:async(e,t)=>{const n=we();n.log("community/unbanMembers",{userIds:t,communityId:e});const{data:r}=await n.http.put(`/api/v3/communities/${e}/users/unban`,{userIds:t}),o=ea(r,"communityUsers"),s=n.cache&&Date.now();n.cache&&Yi(o,{cachedAt:s});const{communityUsers:i}=o;return{data:i.filter((e=>t.includes(e.userId))),cachedAt:s}}});const Od=async e=>{const t=we();t.log("community/queryCommunityMembers",e);const n=null!=e?e:{},{page:r}=n,o=Xi(n,["page"]),{data:s}=await t.http.get(`/api/v3/communities/${o.communityId}/users`,{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:i}=s,a=Xi(s,["paging"]),c=ea(a,"communityUsers"),{communityUsers:l}=c,u=t.cache&&Date.now();if(t.cache){Yi(c,{cachedAt:u});const e=["communityUsers","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];qe(e,{communityUsers:l.map((({communityId:e,userId:t})=>ce("communityUsers")({communityId:e,userId:t}))),paging:i})}return{data:l,cachedAt:u,nextPage:G(i.next),prevPage:G(i.previous)}};Od.locally=e=>{var t,n;const r=we();if(r.log("community/queryCommunityMembers",e),!r.cache)return;const o=null!=e?e:{},{page:s}=o,i=Xi(o,["page"]),a=["communityUsers","query",Object.assign(Object.assign({},i),{options:Object.assign({},s)})],{data:c,cachedAt:l}=null!==(t=Le(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.communityUsers.length))return;const u=c.communityUsers.map((e=>Le(["communityUsers","get",e]))).filter(Boolean).map((({data:e})=>e)),d=G(null==c?void 0:c.paging.previous),h=G(null==c?void 0:c.paging.next);return u.length===(null===(n=null==c?void 0:c.communityUsers)||void 0===n?void 0:n.length)?{data:u,cachedAt:l,prevPage:d,nextPage:h}:void 0};var Td=Object.freeze({__proto__:null,addMembers:async(e,t)=>{const n=we();n.log("community/moderation/addMembers",e,t);const{data:r}=await n.http.post(`/api/v3/communities/${e}/users`,{communityId:e,userIds:t});ut("community.userAdded",r);const o=ea(r,"communityUsers");n.cache&&Yi(o);const{communityUsers:s}=o;return!!s.find((t=>t.communityId===e&&"member"===t.communityMembership))},removeMembers:async(e,t)=>{const n=we();n.log("community/moderation/removeMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/communities/${e}/users`,{data:{communityId:e,userIds:t}});ut("community.userRemoved",r);const o=ea(r,"communityUsers");n.cache&&Yi(o);const{communityUsers:s}=o;return!!s.find((t=>t.communityId===e&&"member"!==t.communityMembership))},getMembers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getMembers(tmpid: ${s}) > listen`);const{limit:i}=e,a=Xi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["communityUsers","collection",{communityId:e.communityId}],g=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["communityUsers","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];s=We(s,"roles",e.roles),e.membership&&(s=s.filter((({communityMembership:t})=>e.membership.includes(t)))),e.search&&(s=Ye(s,e.search));const i=e.sortBy?e.sortBy:"lastCreated";s=s.sort("lastCreated"===i?tt:et),t({onNextPage:y,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},m=t=>(t,n)=>{var r;if(e.communityId!==n.communityId)return;const o=null===(r=Le(d))||void 0===r?void 0:r.data;if(!o)return;const s=ce("communityUsers")({communityId:e.communityId,userId:n.userId});o.data=[...new Set([s,...o.data])],qe(d,o),g(o)},y=(e=!1)=>{var t,n,r;const o=null===(t=Le(d))||void 0===t?void 0:t.data,s=null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(Od,Object.assign(Object.assign({},a),{page:null!==(r=e||null==o?void 0:o.params.page)&&void 0!==r?r:{limit:c}}));se(i,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(ce("communityUsers"))])]),qe(d,o),g(o)}),oe(l))};return u.push(Ad(m()),Sd(m()),bd(m()),Cd(m()),wd(m()),_d(m()),kd(m())),y(!0),()=>{r(`getMembers(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},onCommunityUserAdded:yd,onCommunityUserRemoved:vd,onCommunityUserBanned:bd,onCommunityUserChanged:wd,onCommunityUserUnbanned:Cd,onCommunityUserRoleAdded:_d,onCommunityUserRoleRemoved:kd,onCommunityJoined:Sd,onCommunityLeft:Ad}),xd=Object.freeze({__proto__:null,Moderation:Id,Membership:Td,getCommunityByIds:sd,createCommunity:async e=>{const t=we();t.log("user/createCommunity",e);const{data:n}=await t.http.post("/api/v3/communities/",od(e));ut("community.created",n);const r=rd(n),o=t.cache&&Date.now();t.cache&&Yi(r,{cachedAt:o});const{communities:s}=r;return{data:s[0],cachedAt:o}},updateCommunity:async(e,t)=>{const n=we();n.log("community/updateCommunity",e,t);const{data:r}=await n.http.put(`/api/v3/communities/${e}`,od(t));ut("community.updated",r);const o=rd(r),s=n.cache&&Date.now();n.cache&&Yi(o,{cachedAt:s});const{communities:i}=o;return{data:i.find((t=>t.communityId===e)),cachedAt:s}},deleteCommunity:async e=>{const t=we();t.log("community/deleteCommunity",e),await t.http.delete(`/api/v3/communities/${e}`);const n=await id(e);return ut("community.deleted",{communities:[n.data],categories:[],communityUsers:[],feeds:[],files:[],users:[]}),n.data},joinCommunity:async e=>{const t=we();t.log("community/joinCommunity",e);const{data:n}=await t.http.post(`/api/v3/communities/${e}/join`);ut("community.joined",n);const r=rd(n),o=t.cache&&Date.now();t.cache&&Yi(r,{cachedAt:o});const{communityUsers:s}=r;return!!s.find((t=>t.communityId===e&&"member"===t.communityMembership))},leaveCommunity:async e=>{const t=we();t.log("community/leaveCommunity",e);const{data:n}=await t.http.delete(`/api/v3/communities/${e}/leave`);ut("community.left",n);const r=rd(n),o=t.cache&&Date.now();t.cache&&Yi(r,{cachedAt:o});const{communityUsers:s}=r;return!!s.find((t=>t.communityId===e&&"member"!==t.communityMembership))},getTopTrendingCommunities:ad,getRecommendedCommunities:cd,onCommunityCreated:ud,onCommunityUpdated:dd,onCommunityDeleted:hd,observeCommunity:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeCommunity(tmpid: ${r}) > listen`);const o=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},s=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.communityId)===e&&o(t,n)},i=[];return i.push(dd((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),hd((e=>s({data:e,loading:!1,origin:"event"},"onDelete"))),Sd((e=>s({data:e,loading:!1,origin:"event"},"onJoin"))),Ad((e=>s({data:e,loading:!1,origin:"event"},"onLeft"))),yd((e=>s({data:e,loading:!1,origin:"event"},"onUserAdded"))),vd((e=>s({data:e,loading:!1,origin:"event"},"onUserRemoved"))),bd((e=>s({data:e,loading:!1,origin:"event"},"onUserBanned"))),Cd((e=>s({data:e,loading:!1,origin:"event"},"onUserUnbanned")))),se(re(id,e),(e=>(e.data||e.error)&&o(e,"onFetch"))),()=>{n(`observeCommunity(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}},getCommunities:(e,t,n)=>{const{log:r,cache:o,userId:s}=we();o||console.log(p);const i=Date.now();r(`getCommunities(tmpid: ${i}) > listen`);const{limit:a}=e,c=Xi(e,["limit"]),l=null!=a?a:h,{policy:u=f}=null!=n?n:{},d=[],g=["community","collection",{}],m=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];i=Ve(i,"displayName",e.displayName),e.includeDeleted||(i=Ve(i,"isDeleted",!1)),e.categoryId&&(i=i.filter((t=>{var n;return null===(n=t.categoryIds)||void 0===n?void 0:n.includes(e.categoryId)}))),e.tags&&(i=i.filter((t=>{var n;return null===(n=t.tags)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.tags)||void 0===n?void 0:n.includes(t)}))}))),e.membership&&s&&(i=Je(i,e.membership,s));const a=e.sortBy||"lastCreated";"lastCreated"!==a&&"firstCreated"!==a||(i=i.sort("lastCreated"===a?tt:et)),"displayName"===a&&(i=i.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Xe)),t({onNextPage:b,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},v=e=>e=>{var t;const n=null===(t=Le(g))||void 0===t?void 0:t.data;n&&(n.data=[...new Set([e.communityId,...n.data])],qe(g,n),m(n))},b=(e=!1)=>{var t,n,r;const o=null===(t=Le(g))||void 0===t?void 0:t.data,s=null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(Ed,Object.assign(Object.assign({},c),{page:null!==(r=e||null==o?void 0:o.params.page)&&void 0!==r?r:{limit:l}}));se(i,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(ce("community"))])]),qe(g,o),m(o)}),oe(u,y))};return d.push(ud(v()),hd(v()),dd(v()),Sd(v()),Ad(v()),wd(v())),b(!0),d.push((()=>He(g))),()=>{r(`getCommunities(tmpid: ${i}) > dispose`),d.forEach((e=>e()))}},getCommunity:(e,t)=>Na(e,t,"communityId",id,[dd,hd,Sd,Ad,bd,Cd,wd])});const Rd=async e=>{const t=we();t.log("category/getCategory",e);const{data:n}=await t.http.get(`/api/v3/community-categories/${encodeURIComponent(e)}`),r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r});const{categories:o}=n;return{data:o.find((t=>t.categoryId===e)),cachedAt:r}};Rd.locally=e=>{const t=we();if(t.log("category/getCategory.locally",e),!t.cache)return;const n=Le(["category","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Pd=async e=>{const t=we();t.log("category/queryCategories",e);const n=null!=e?e:{},{page:r={limit:10},includeDeleted:o}=n,s=Xi(n,["page","includeDeleted"]),{data:i}=await t.http.get("/api/v3/community-categories",{params:Object.assign(Object.assign({},s),{isDeleted:Ba(o),options:{token:J(r,"skiplimit")}})}),{paging:a}=i,c=Xi(i,["paging"]),{categories:l}=c,u=t.cache&&Date.now();if(t.cache){Yi(c,{cachedAt:u});const e=["category","query",Object.assign(Object.assign({},s),{options:Object.assign({},r)})];qe(e,{categories:l.map(ce("category")),paging:a})}const d=G(a.next);return{data:l,cachedAt:u,prevPage:G(a.previous),nextPage:d}};Pd.locally=e=>{var t,n;const r=we();if(r.log("category/queryCategories.locally",e),!r.cache)return;const o=null!=e?e:{},{page:s={limit:10}}=o,i=Xi(o,["page"]),a=["category","query",Object.assign(Object.assign({},i),{options:Object.assign({},s)})],{data:c,cachedAt:l}=null!==(t=Le(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.categories.length))return;const u=c.categories.map((e=>Le(["category","get",e]))).filter(Boolean).map((({data:e})=>e)),d=G(null==c?void 0:c.paging.previous),h=G(null==c?void 0:c.paging.next);return u.length===(null===(n=null==c?void 0:c.categories)||void 0===n?void 0:n.length)?{data:u,cachedAt:l,prevPage:d,nextPage:h}:void 0};var Md=Object.freeze({__proto__:null,getCategory:Rd,getCategories:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getCategories(tmpid: ${s}) > listen`);const{limit:i}=e,a=Xi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["category","collection",{}],g=(n=!1)=>{var r,o,s;const i=null===(r=Le(d))||void 0===r?void 0:r.data,u=null!==(o=null==i?void 0:i.data)&&void 0!==o?o:[];if(!n&&u.length>0&&!(null==i?void 0:i.params.page))return;const h=re(Pd,Object.assign(Object.assign({},a),{page:null!==(s=n||null==i?void 0:i.params.page)&&void 0!==s?s:{limit:c}}));se(h,(({data:n,error:r,loading:o,nextPage:s})=>{const i={loading:o,error:r,params:{page:s},data:u};n&&(i.data=[...new Set([...u,...n.map(ce("category"))])]),qe(d,i),(n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["category","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(e.includeDeleted||(s=Ve(s,"isDeleted",!1)),e.sortBy){case"firstCreated":s=s.sort(et);break;case"lastCreated":s=s.sort(tt);break;default:s=s.sort(Ze)}t({onNextPage:g,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})})(i)}),oe(l))};return u.push((()=>{})),g(!0),()=>{r(`getCategories(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}}});const jd=async e=>{const t=we();t.log("feed/queryGlobalFeed",e);const n=null!=e?e:{},{useCustomRanking:r,page:o}=n,s=Xi(n,["useCustomRanking","page"]);r&&console.warn('The param "useCustomRanking" has been deprecated. To get custom ranking feed use FeedRepository.getCustomRankingGlobalFeed instead');const{data:i}=await t.http.get("/api/v4/me/global-feeds",{params:Object.assign(Object.assign({},s),{options:{token:J(o,"skiplimit")}})}),{paging:a}=i,c=Xi(i,["paging"]),l=ea(c,"communityUsers"),{posts:u}=l,d=t.cache&&Date.now();if(t.cache){Yi(l);const e=["globalFeed","query",Object.assign(Object.assign({},s),{options:Object.assign({},o)})];qe(e,{posts:u.map(ce("post")),paging:a})}const h=G(a.next);return{data:u,cachedAt:d,prevPage:G(a.previous),nextPage:h}};jd.locally=e=>{var t,n;const r=we();if(r.log("post/queryGlobalFeed.locally",e),!r.cache)return;const o=null!=e?e:{},{page:s}=o,i=Xi(o,["page"]),a=["globalFeed","query",Object.assign(Object.assign({},i),{options:Object.assign({},s)})],{data:c,cachedAt:l}=null!==(t=Le(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.posts.length))return;const u=c.posts.map((e=>Le(["post","get",e]))).filter(Boolean).map((({data:e})=>e)),d=G(null==c?void 0:c.paging.previous),h=G(null==c?void 0:c.paging.next);return u.length===(null===(n=null==c?void 0:c.posts)||void 0===n?void 0:n.length)?{data:u,cachedAt:l,prevPage:d,nextPage:h}:void 0};const Fd=async e=>{const t=we();t.log("feed/getCustomRankingGlobalFeed",e);const n=null!=e?e:{},{page:r}=n,o=Xi(n,["page"]),{data:s}=await t.http.get("/api/v5/me/global-feeds",{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:i}=s,a=Xi(s,["paging"]),c=ea(a,"communityUsers"),{posts:l}=c,u=t.cache&&Date.now();if(t.cache){Yi(c);const e=["customGlobalFeed","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];qe(e,{posts:l.map(ce("post")),paging:i})}const d=G(i.next);return{data:l,cachedAt:u,prevPage:G(i.previous),nextPage:d}};Fd.locally=e=>{var t,n;const r=we();if(r.log("post/getCustomRankingGlobalFeed.locally",e),!r.cache)return;const o=null!=e?e:{},{page:s}=o,i=Xi(o,["page"]),a=["customGlobalFeed","query",Object.assign(Object.assign({},i),{options:Object.assign({},s)})],{data:c,cachedAt:l}=null!==(t=Le(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.posts.length))return;const u=c.posts.map((e=>Le(["post","get",e]))).filter(Boolean).map((({data:e})=>e)),d=G(null==c?void 0:c.paging.previous),h=G(null==c?void 0:c.paging.next);return u.length===(null===(n=null==c?void 0:c.posts)||void 0===n?void 0:n.length)?{data:u,cachedAt:l,prevPage:d,nextPage:h}:void 0};var Nd=Object.freeze({__proto__:null,queryGlobalFeed:jd,getCustomRankingGlobalFeed:Fd});const Bd=async e=>{const t=we();t.log("post/getPostByIds",e);const n=e.map((e=>encodeURIComponent(e)));let r;try{r=(await t.http.get("/api/v3/posts/list",{params:{postIds:n}})).data}catch(t){throw e.forEach((e=>{_(null==t?void 0:t.code)&&rc("post",e)})),t}const o=ea(r,"communityUsers"),s=t.cache&&Date.now();return t.cache&&Yi(o,{cachedAt:s}),{data:o.posts,cachedAt:s}};Bd.locally=e=>{var t;const n=we();if(n.log("post/getPostByIds.locally",e),!n.cache)return;const r=e.map((e=>Le(["post","get",e]))).filter(Boolean),o=r.map((({data:e})=>e)),s=null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0];return(null==r?void 0:r.length)<e.length?void 0:{data:o,cachedAt:s.cachedAt}};const Ud=async(e,t=!1)=>{const n=we(),r=await tl(e);if(await n.http.delete(`/api/v4/posts/${encodeURIComponent(e)}`,{params:{postId:e,permanent:t}}),"community"===r.data.targetType){const e=await id(r.data.targetId);ut("community.updated",{communities:[e.data],categories:[],communityUsers:[],feeds:[],files:[],users:[]})}const o=Object.assign(Object.assign({},r.data),{isDeleted:!0});return ut("post.deleted",{posts:[o],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),t?setTimeout((()=>{rc("post",e)}),0):ze(["post","get",e],{isDeleted:!0}),o},Dd=async e=>{const t=we();t.log("post/queryPosts",e);const{page:n={limit:10},includeDeleted:r}=e,o=Xi(e,["page","includeDeleted"]),{dataTypes:s,matchingOnlyParentPost:i}=o,{data:a}=await t.http.get("/api/v4/posts",{params:Object.assign(Object.assign({},o),{isDeleted:Ba(r),matchingOnlyParentPost:null!=i?i:!(null==s?void 0:s.length),options:{token:J(n,"afterbeforeraw")}})}),{paging:c}=a,l=Xi(a,["paging"]),u=ea(l,"communityUsers"),{posts:d}=l,h=t.cache&&Date.now();if(t.cache){Yi(u,{cachedAt:h});const e=["post","query",Object.assign(Object.assign({},o),{options:Object.assign({},n)})];qe(e,{posts:d.map(ce("post")),paging:c})}const f=Y(c.next);return{data:d,cachedAt:h,prevPage:Y(c.previous),nextPage:f}};var Ld=Object.freeze({__proto__:null,getPostByIds:Bd,createPost:async e=>{const t=we();t.log("post/createPost",e),e.dataType&&!["text","image","file","video"].includes(e.dataType)||delete e.dataType;const{data:n}=await t.http.post("/api/v4/posts",e);ut("post.created",n);const r=ea(n,"communityUsers"),o=t.cache&&Date.now();t.cache&&Yi(r,{cachedAt:o});const{posts:s}=r;return{data:s[0],cachedAt:o}},updatePost:async(e,t)=>{const n=we();n.log("user/updatePost",t),console.warn("Deprecation: updatePost has been renamed to editPost. Update post API will be deprecated soon.");const{data:r}=await n.http.put(`/api/v4/posts/${encodeURIComponent(e)}`,t),o=ea(r,"communityUsers"),s=n.cache&&Date.now();n.cache&&Yi(o,{cachedAt:s}),ut("post.updated",o);const{posts:i}=o;return{data:i.find((t=>t.postId===e)),cachedAt:s}},editPost:async(e,t)=>{const n=we();n.log("user/editPost",t);const{data:r}=await n.http.put(`/api/v4/posts/${encodeURIComponent(e)}`,t),o=ea(r,"communityUsers"),s=n.cache&&Date.now();n.cache&&Yi(o,{cachedAt:s}),ut("post.updated",o);const{posts:i}=o;return{data:i.find((t=>t.postId===e)),cachedAt:s}},deletePost:Ud,softDeletePost:async e=>{we().log("post/softDeletePost",e);return await Ud(e,!1)},hardDeletePost:async e=>{we().log("post/hardDeletePost",e);return await Ud(e,!0)},approvePost:async e=>{const t=we();t.log("post/approvePost",e);const{data:n}=await t.http.post(`/api/v3/posts/${encodeURIComponent(e)}/approve`);ut("post.approved",n),"community"===n.posts[0].targetType&&ut("community.updated",n);const r=ea(n,"communityUsers"),o=t.cache&&Date.now();return t.cache&&Yi(r,{cachedAt:o}),{data:r.posts.find((t=>t.postId===e)),cachedAt:o}},declinePost:async e=>{const t=we();t.log("post/declinePost",e);const{data:n}=await t.http.post(`/api/v3/posts/${encodeURIComponent(e)}/decline`);"community"===n.posts[0].targetType&&ut("community.updated",n),ut("post.declined",n);const r=ea(n,"communityUsers"),o=t.cache&&Date.now();return t.cache&&Yi(r,{cachedAt:o}),{data:n.posts.find((t=>t.postId===e)),cachedAt:o}},flagPost:async e=>{const t=we();t.log("post/flagPost",e);const{data:n}=await t.http.post(`/api/v3/posts/${encodeURIComponent(e)}/flag`);return t.cache&&Yi(ea(n,"communityUsers")),ut("post.flagged",n),!!n},unflagPost:async e=>{const t=we();t.log("post/unflagPost",e);const{data:n}=await t.http.delete(`/api/v3/posts/${encodeURIComponent(e)}/unflag`);return t.cache&&Yi(ea(n,"communityUsers")),ut("post.unflagged",n),!!n},isPostFlaggedByMe:async e=>{var t,n;const r=we();r.log("post/isPostFlaggedByMe",e);const{result:o,isFlagByMe:s}=null!==(t=await Di(r,"v3/post.isflagbyme",{postId:e}))&&void 0!==t?t:{};return null!==(n=null!=o?o:s)&&void 0!==n&&n},onPostCreated:al,onPostUpdated:cl,onPostDeleted:ll,onPostApproved:ul,onPostDeclined:dl,onPostFlagged:hl,onPostUnflagged:fl,onPostReactionAdded:pl,onPostReactionRemoved:gl,observePosts:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observePosts(tmpid: ${r}) > listen`);const o=[],s=(n,r)=>{var o,s;if(e.targetId===n.targetId&&e.targetType===n.targetType){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(s=t[r])||void 0===s||s.call(t,n)}};return o.push(al((e=>s(e,"onCreate"))),cl((e=>s(e,"onUpdate"))),ll((e=>s(e,"onDelete"))),ul((e=>s(e,"onApproved"))),dl((e=>s(e,"onDeclined"))),hl((e=>s(e,"onFlagged"))),fl((e=>s(e,"onUnflagged"))),pl((e=>s(e,"onReactionAdded"))),gl((e=>s(e,"onReactionRemoved")))),()=>{n(`observePosts(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},observePost:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observePost(tmpid: ${o}) > listen`);const s=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},i=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.postId)===e&&s(t,n)},a=[];return a.push(cl((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),ll((e=>i({data:e,loading:!1,origin:"event"},"onDelete"))),ul((e=>i({data:e,loading:!1,origin:"event"},"onApproved"))),dl((e=>i({data:e,loading:!1,origin:"event"},"onDeclined"))),hl((e=>i({data:e,loading:!1,origin:"event"},"onFlagged"))),fl((e=>i({data:e,loading:!1,origin:"event"},"onUnflagged"))),pl((e=>i({data:e,loading:!1,origin:"event"},"onReactionAdded"))),gl((e=>i({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),se(re(tl,e),(e=>(e.data||e.error)&&s(e,"onFetch")),oe(n)),()=>{r(`observePosts(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},getPost:(e,t)=>Na(e,t,"postId",tl,[ul,dl,ll,hl,pl,gl,fl,cl]),getPosts:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getPosts(tmpid: ${s}) > listen`);const{limit:i}=e,a=Xi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["post","collection",{targetId:e.targetId,targetType:e.targetType}],g=n=>{var r,o,s;let i=null!==(r=n.data.map((e=>Le(["post","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];const a=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===a?tt:et),e.includeDeleted||(i=Ve(i,"isDeleted",!1)),e.tags&&(i=i.filter((t=>{var n;return null===(n=t.tags)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.tags)||void 0===n?void 0:n.includes(t)}))}))),"community"===e.targetType&&e.feedType&&(i=Qe(i,e.feedType)),(null===(o=e.dataTypes)||void 0===o?void 0:o.length)&&(i=Ge(i,e.dataTypes)),t({onNextPage:v,data:i,hasNextPage:!!(null===(s=n.params)||void 0===s?void 0:s.page),loading:n.loading,error:n.error})},m=t=>n=>{var r;const o=null===(r=Le(d))||void 0===r?void 0:r.data;e.targetId===n.targetId&&e.targetType===n.targetType&&o&&(o.data="onDeclined"===t?o.data.filter((e=>e!==n.postId)):[...new Set([n.postId,...o.data])],qe(d,o),g(o))},v=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re(Dd,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:i};e&&(o.data=[...new Set([...i,...e.map(ce("post"))])]),qe(d,o),g(o)}),oe(l,y))};return u.push(al(m("onCreate")),ul(m("onApproved")),dl(m("onDeclined")),ll(m("onDelete")),cl(m("onUpdate")),hl(m("onFlagged")),fl(m("onUnflagged")),pl(m("onReactionAdded")),gl(m("onReactionRemoved"))),v(!0),u.push((()=>He(d))),()=>{r(`getPosts(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}}});const qd=async e=>{const t=we();t.log("comment/getCommentByIds",e);const n=e.map((e=>encodeURIComponent(e)));let r;try{r=(await t.http.get("/api/v3/comments/list",{params:{commentIds:n}})).data}catch(t){throw e.forEach((e=>{_(null==t?void 0:t.code)&&rc("comment",e)})),t}const o=t.cache&&Date.now();return t.cache&&Yi(r,{cachedAt:o}),{data:r.comments,cachedAt:o}};qd.locally=e=>{var t;const n=we();if(n.log("comment/getCommentByIds.locally",e),!n.cache)return;const r=e.map((e=>Le(["comment","get",e]))).filter(Boolean),o=r.map((({data:e})=>e)),s=null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0];return(null==r?void 0:r.length)<e.length?void 0:{data:o,cachedAt:s.cachedAt}};const $d=async e=>{const t=we();t.log("comment/queryComments",e);const{page:n={limit:10},includeDeleted:r}=e,o=Xi(e,["page","includeDeleted"]),s={type:o.sortBy?"pagination":void 0,token:J(n,o.sortBy?"skiplimit":"afterbefore")},{data:i}=await t.http.get("/api/v3/comments",{params:Object.assign(Object.assign({},o),{isDeleted:Ba(r),options:s})}),{paging:a}=i,c=Xi(i,["paging"]),{comments:l}=c,u=t.cache&&Date.now();if(t.cache){Yi(c,{cachedAt:u});const e=["comment","query",Object.assign(Object.assign({},o),{options:Object.assign({},n)})];qe(e,{comments:l.map(ce("comment")),paging:a})}const d=G(a.next);return{data:l,cachedAt:u,prevPage:G(a.previous),nextPage:d}};var zd=Object.freeze({__proto__:null,getCommentByIds:qd,createComment:async e=>{const t=we();t.log("comment/createComment",e);const{data:n}=await t.http.post("/api/v3/comments",e),r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r});const o=await tl(e.referenceId);ut("post.updated",{posts:[o.data],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),ut("comment.created",n);const{comments:s}=n;return{data:s[0],cachedAt:r}},updateComment:async(e,t)=>{const n=we();n.log("user/updateComment",t);const{data:r}=await n.http.put(`/api/v3/comments/${encodeURIComponent(e)}`,t),o=n.cache&&Date.now();n.cache&&Yi(r,{cachedAt:o}),ut("comment.updated",r);const{comments:s}=r;return{data:s.find((t=>t.commentId===e)),cachedAt:o}},deleteComment:async(e,t=!1)=>{const n=we();n.log("comment/deleteComment",e);const r=await nl(e);await n.http.delete(`/api/v4/comments/${encodeURIComponent(e)}`,{params:{commentId:e,permanent:t}});const o=Object.assign(Object.assign({},r.data),{isDeleted:!0}),s=await tl(r.data.referenceId);return ut("post.updated",{posts:[s.data],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),ut("comment.deleted",{comments:[o],commentChildren:[],files:[],users:[]}),t?st((()=>rc("comment",e))):ze(["comment","get",e],{isDeleted:!0}),o},onCommentCreated:yl,onCommentUpdated:vl,onCommentDeleted:bl,onCommentFlagged:wl,onCommentUnflagged:Cl,onCommentReactionAdded:_l,onCommentReactionRemoved:kl,observeComments:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeComments(tmpid: ${r}) > listen`);const o=[],s=(n,r)=>{var o,s;if(n.referenceId===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(s=t[r])||void 0===s||s.call(t,n)}};return o.push(yl((e=>s(e,"onCreate"))),vl((e=>s(e,"onUpdate"))),bl((e=>s(e,"onDelete"))),wl((e=>s(e,"onFlagged"))),Cl((e=>s(e,"onUnflagged"))),_l((e=>s(e,"onReactionAdded"))),kl((e=>s(e,"onReactionRemoved")))),()=>{n(`observeComments(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},observeComment:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observeComment(tmpid: ${o}) > listen`);const s=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},i=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.commentId)===e&&s(t,n)},a=[];return a.push(vl((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),bl((e=>i({data:e,loading:!1,origin:"event"},"onDelete"))),wl((e=>i({data:e,loading:!1,origin:"event"},"onFlagged"))),Cl((e=>i({data:e,loading:!1,origin:"event"},"onUnflagged"))),_l((e=>i({data:e,loading:!1,origin:"event"},"onReactionAdded"))),kl((e=>i({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),se(re(nl,e),(e=>(e.data||e.error)&&s(e,"onFetch")),oe(n)),()=>{r(`observeComment(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},getComment:(e,t)=>Na(e,t,"commentId",nl,[bl,wl,_l,kl,Cl,vl]),getComments:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const s=Date.now();r(`getComments(tmpid: ${s}) > listen`);const{limit:i}=e,a=Xi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["comment","collection",{referenceId:e.referenceType,referenceType:e.referenceId}],p=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["comment","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.includeDeleted||(s=Ve(s,"isDeleted",!1));const i=e.sortBy?e.sortBy:"lastCreated";s=s.sort("lastCreated"===i?tt:et),t({onNextPage:m,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},g=t=>n=>{var r;const o=null===(r=Le(d))||void 0===r?void 0:r.data;e.referenceId===n.referenceId&&e.referenceType===n.referenceType&&o&&("onCreate"===t?o.data=[...new Set([n.commentId,...o.data])]:"onDelete"===t&&(o.data=o.data.filter((e=>e!==n.commentId))),qe(d,o),p(o))},m=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re($d,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,prevPage:r,nextPage:o})=>{const s={loading:n,error:t,params:{page:a.sortBy?o:r},data:i};e&&(s.data=[...new Set([...i,...e.map(ce("comment"))])]),qe(d,s),p(s)}),oe(l,y))};return u.push(yl(g("onCreate")),vl(g("onUpdate")),bl(g("onDelete")),wl(g("onFlagged")),Cl(g("onUnflagged")),_l(g("onReactionAdded")),kl(g("onReactionRemoved"))),m(!0),u.push((()=>He(d))),()=>{r(`getComments(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}}});const Hd=async e=>{const t=we();t.log("stream/getStream",e);const{data:n}=await t.http.get(`/api/v3/video-streaming/${e}`),r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}};Hd.locally=e=>{const t=we();if(t.log("stream/getStream",e),!t.cache)return;const n=Le(["stream","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Vd=async e=>{const t=we();t.log("stream/getStreams",e);const n=null!=e?e:{},{page:r}=n,o=Xi(n,["page"]),{data:s}=await t.http.get("/api/v3/video-streaming",{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:i,results:a}=s,{videoStreamings:c}=a,l=t.cache&&Date.now();t.cache&&Yi(a,{cachedAt:l});const u=G(i.next);return{data:c,cachedAt:l,prevPage:G(i.previous),nextPage:u}};Vd.locally=e=>{we().log("stream/getStreams.locally",e)};var Wd=Object.freeze({__proto__:null,getStream:Hd,getStreams:Vd,createStream:async e=>{const t=we();t.log("stream/createStream",e);const{data:n}=await t.http.post("/api/v3/video-streaming",e),r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o[0],cachedAt:r}},updateStream:async(e,t)=>{const n=we();n.log("stream/updateStream",e,t);const{data:r}=await n.http.put(`/api/v3/video-streaming/${e}`,t),o=n.cache&&Date.now();n.cache&&Yi(r,{cachedAt:o});const{videoStreamings:s}=r;return{data:s.find((t=>t.streamId===e)),cachedAt:o}},deleteStream:async e=>{const t=we();t.log("stream/deleteStream",e);const n=await Hd(e),{data:r}=await t.http.delete(`/api/v3/video-streaming/${e}`),{success:o}=r,s=Object.assign(Object.assign({},n.data),{isDeleted:!0});return ze(["stream","get",e],s),o},disposeStream:async e=>{const t=we();t.log("stream/disposeStream",e);const{data:n}=await t.http.delete(`/api/v3/video-streaming/${e}/streaming-url`),r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}},onStreamStarted:e=>{const t=we();return lt(t,"stream/onStreamStarted","video-streaming.didStart",(t=>{Yi(t),e(t.videoStreamings[0])}))},onStreamStopped:e=>{const t=we();return lt(t,"stream/onStreamStarted","video-streaming.didStop",(t=>{Yi(t),e(t.videoStreamings[0])}))},onStreamRecorded:e=>{const t=we();return lt(t,"stream/onStreamRecorded","video-streaming.didRecord",(t=>{Yi(t),e(t.videoStreamings[0])}))}});const Kd=async e=>{const t=we();t.log("poll/getPoll",e);const{data:n}=await t.http.get(`/api/v3/polls/${e}`),r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r});const{polls:o}=n;return{data:o.find((t=>t.pollId===e)),cachedAt:r}};Kd.locally=e=>{const t=we();if(t.log("poll/getPoll",e),!t.cache)return;const n=Le(["poll","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Qd=e=>{const t=we();return lt(t,"poll/onPollUpdated","poll.updated",(n=>{t.cache&&Yi(n),e(n.polls[0])}))},Jd=e=>{const t=we();return lt(t,"poll/onPollDeleted","poll.deleted",(n=>{t.cache&&Yi(n),e(n.polls[0])}))};var Gd=Object.freeze({__proto__:null,getPoll:Kd,createPoll:async e=>{const t=we();t.log("post/createPoll",e);const{data:n}=await t.http.post("/api/v3/polls",e),r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r});const{polls:o}=n;return{data:o[0],cachedAt:r}},closePoll:async e=>{const t=we();t.log("user/closePoll",e);const{data:n}=await t.http.put(`/api/v3/polls/${encodeURIComponent(e)}`,{status:"closed"}),r=t.cache&&Date.now();t.cache&&Yi(n,{cachedAt:r}),ut("poll.updated",n);const{polls:o}=n;return{data:o.find((t=>t.pollId===e)),cachedAt:r}},deletePoll:async e=>{const t=we();t.log("poll/deletePoll",e);const n=await Kd(e),{data:r}=await t.http.delete(`/api/v3/polls/${e}`),{success:o}=r,s=Object.assign(Object.assign({},n.data),{isDeleted:!0});return ze(["poll","get",e],s),ut("poll.deleted",{polls:[s],users:[]}),o},votePoll:async(e,t)=>{const n=we();n.log("user/votePoll",e);const{data:r}=await n.http.post(`/api/v3/polls/${encodeURIComponent(e)}/votes`,{pollId:e,answerIds:t}),o=n.cache&&Date.now();n.cache&&Yi(r,{cachedAt:o});const{polls:s}=r;return ut("poll.updated",r),{data:s.find((t=>t.pollId===e)),cachedAt:o}},onPollUpdated:Qd,onPollDeleted:Jd,observePoll:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observePoll(tmpid: ${o}) > listen`);const s=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},i=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.pollId)===e&&s(t,n)},a=[];return a.push(Qd((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),Jd((e=>i({data:e,loading:!1,origin:"event"},"onDelete")))),se(re(Kd,e),(e=>(e.data||e.error)&&s(e,"onFetch")),oe(n)),()=>{r(`observePoll(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}}});return e.API_REGIONS=Nt,e.CategoryRepository=Md,e.ChannelRepository=Hl,e.Client=kc,e.CommentRepository=zd,e.CommunityPostSettingMaps=n,e.CommunityPostSettings=t,e.CommunityRepository=xd,e.ContentFeedType=o,e.DefaultCommunityPostSetting=r,e.FeedRepository=Nd,e.FileRepository=Gc,e.FileType=s,e.MessageContentType=l,e.MessageRepository=Ju,e.PollRepository=Gd,e.PostContentType=u,e.PostRepository=Ld,e.ReactionRepository=Il,e.StreamRepository=Wd,e.SubChannelRepository=td,e.UserRepository=Qc,e.VERSION=d,e.VideoResolution=i,e.VideoSize=c,e.VideoTranscodingStatus=a,e.backupCache=async(e="amitySdk",t=(e=>e.offline))=>{const{log:n,cache:r,userId:o}=we();if(!r)return!1;n("cache/api/backupCache",{storageKey:e});const s=Object.fromEntries(Object.entries(r.data).filter((([e,n])=>t(n))));return!!Object.keys(s).length&&(await Ue.setItem(`${e}#${o}`,JSON.stringify(s)),!0)},e.createQuery=re,e.createReport=async(e,t)=>{const n=we();n.log("report/createReport",{referenceType:e,referenceId:t});const{data:r}=await n.http.post((()=>{if("user"===e)return`/api/v4/me/flags/${encodeURIComponent(t)}`;if("message"===e)return`/api/v5/messages/${encodeURIComponent(t)}/flags`;const{domainName:n}=Ol[e];return`/api/v3/${n}/${encodeURIComponent(t)}/flag`})());if(n.cache)if("message"===e){const e=await Da(r);Yi(e)}else Yi("post"===e?ea(r,"communityUsers"):r);return ut(`${e}.flagged`,r),!!r},e.createUserToken=async(e,t,n)=>{const r=Wi(),o=Ki(),s=kr(Ut("http",t)),{data:i}=await s.post("/api/v4/sessions",Object.assign(Object.assign({},n),{deviceId:r,deviceInfo:Object.assign(Object.assign({},o),{model:"token management API on TS-SDK"})}),{headers:{"X-API-Key":e}});return{accessToken:i.accessToken}},e.deleteReport=async(e,t)=>{const n=we();n.log("report/deleteReport",{referenceType:e,referenceId:t});const{data:r}=await n.http.delete((()=>{if("user"===e)return`/api/v4/me/flags/${encodeURIComponent(t)}`;if("message"===e)return`/api/v5/messages/${encodeURIComponent(t)}/flags`;const{domainName:n}=Ol[e];return`/api/v3/${n}/${encodeURIComponent(t)}/unflag`})());if(n.cache)if("message"===e){const e=await Da(r);Yi(e)}else Yi("post"===e?ea(r,"communityUsers"):r);return ut(`${e}.unflagged`,r),!!r},e.disableCache=()=>{const e=we();e.cache&&(e.log("cache/api/disableCache"),delete e.cache)},e.dropFromCache=He,e.enableCache=(e={},t)=>{const n=we();n.cache||(n.log("cache/api/enableCache"),n.cache={data:e,persistIf:t})},e.filterByChannelMembership=Ke,e.filterByCommunityMembership=Je,e.filterByFeedType=Qe,e.filterByPostDataTypes=Ge,e.filterByPropEquality=Ve,e.filterByPropInclusion=(e,t,n)=>void 0!==n?e.filter((e=>n.includes(e[t]))):e,e.filterByPropIntersection=We,e.filterBySearchTerm=Ye,e.getChannelMarkers=la,e.getChannelTopic=e=>`${e.path}/#`,e.getCommentTopic=({path:e})=>e,e.getCommunityTopic=({path:t},n=e.SubscriptionLevels.COMMUNITY)=>gt(t,n),e.getMarkedMessageTopic=vt,e.getMessageMarkers=xa,e.getMessageTopic=e=>e.path,e.getMyFollowersTopic=()=>{const e=ht();return`${mt(e)}/membership/${e._id}/+/+`},e.getMyFollowingsTopic=()=>{const e=ht();return`${mt(e)}/membership/+/${e._id}/+`},e.getNetworkTopic=bt,e.getPostTopic=({path:t},n=e.SubscriptionLevels.POST)=>"comment"===n?`${t}/comment/+`:t,e.getRole=Xc,e.getSmartFeedChannelTopic=wt,e.getSmartFeedMessageTopic=_t,e.getSmartFeedSubChannelTopic=Ct,e.getSubChannelMarkers=Ra,e.getSubChannelTopic=e=>`${e.path}/#`,e.getUserMarker=Ma,e.getUserTopic=yt,e.isAfterBefore=W,e.isAfterBeforeRaw=K,e.isCachable=te,e.isFetcher=X,e.isFresh=ne,e.isLocal=e=>te(e)&&-1===(null==e?void 0:e.cachedAt),e.isMutator=Z,e.isOffline=ee,e.isPaged=Q,e.isReportedByMe=async(e,t)=>{var n,r;const o=we();o.log("report/isReportedByMe",{referenceType:e,referenceId:t});const{eventName:s,primaryKey:i}=Ol[e];if("message"===e){const{data:e}=await o.http.get(`/api/v5/messages/${encodeURIComponent(t)}/flags`);return e.result}const{result:a,isFlagByMe:c}=null!==(n=await Di(o,s,{[i]:t}))&&void 0!==n?n:{};return null!==(r=null!=a?a:c)&&void 0!==r&&r},e.isSkip=V,e.mergeInCache=$e,e.onChannelMarkerFetched=e=>{const t=we();return lt(t,"channelMarker/onChannelMarkerFetched","local.channelMarker.fetched",(t=>{e(t.userEntityMarkers[0])}))},e.onFeedMarkerFetched=e=>{const t=we();return lt(t,"feedMarker/onFeedMarkerFetched","local.feedMarker.fetched",(t=>{e(t.feedMarkers[0])}))},e.onFeedMarkerUpdated=ja,e.onMessageMarked=e=>{const t=we();return lt(t,"messageMarker/onMessageMarked","marker.marked-message",(t=>{e(t.contentMarkers[0])}))},e.onMessageMarkerFetched=e=>{const t=we();return lt(t,"messageMarker/onMessageMarkerFetched","local.messageMarker.fetched",(t=>{e(t.contentMarkers[0])}))},e.onSubChannelMarkerFetched=e=>{const t=we();return lt(t,"subChannelMarker/onSubChannelMarkerFetched","local.subChannelMarker.fetched",(t=>{e(t.userFeedMarkers[0])}))},e.onSubChannelMarkerUpdated=e=>{const t=we();return lt(t,"subChannelMarker/onSubChannelMarkerUpdated","local.subChannelMarker.updated",(t=>{e(t.userFeedMarkers[0])}))},e.onUserMarkerFetched=Fa,e.pullFromCache=Le,e.pushToCache=qe,e.queryCache=De,e.queryOptions=oe,e.queryRoles=Yc,e.restoreCache=async(e="amitySdk")=>{var t;const n=we();if(!n.cache)return!1;n.log("cache/api/restoreCache",{storageKey:e});const r=null!==(t=await Ue.getItem(`${e}#${n.userId}`))&&void 0!==t?t:"{}";let o={};try{o=JSON.parse(r)}catch(e){}return n.cache.data=Object.assign(Object.assign({},o),n.cache.data),!0},e.runQuery=se,e.sortByChannelSegment=({channelSegment:e},{channelSegment:t})=>e-t,e.sortByDisplayName=Xe,e.sortByFirstCreated=et,e.sortByLastActivity=nt,e.sortByLastCreated=tt,e.sortByName=Ze,e.sortBySegmentNumber=({segmentNumber:e},{segmentNumber:t})=>e-t,e.subscribeTopic=At,e.toPage=G,e.toPageRaw=Y,e.toToken=J,e.upsertInCache=ze,e.wipeCache=async(e="amitySdk")=>{const{log:t,cache:n,userId:r}=we();return!!n&&(t("cache/api/wipeCache",{storageKey:e}),n.data={},await Ue.setItem(`${e}#${r}`,"{}"),!0)},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
6
+ var r=e("buffer"),o=r.Buffer;function s(e,t){for(var n in e)t[n]=e[n]}function i(e,t,n){return o(e,t,n)}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?t.exports=r:(s(r,n),n.Buffer=i),i.prototype=Object.create(o.prototype),s(o,i),i.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return o(e,t,n)},i.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var r=o(e);return void 0!==t?"string"==typeof n?r.fill(t,n):r.fill(t):r.fill(0),r},i.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o(e)},i.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}},{buffer:17}],74:[function(e,t,n){function r(e){var t=e._readableState;return t?t.objectMode||"number"==typeof e._duplexState?e.read():e.read(o(t)):null}function o(e){return e.buffer.length?e.buffer.head?e.buffer.head.data.length:e.buffer[0].length:e.length}t.exports=r},{}],75:[function(e,t,n){var r=e("safe-buffer").Buffer,o=r.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function s(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}function i(e){var t=s(e);if("string"!=typeof t&&(r.isEncoding===o||!o(e)))throw new Error("Unknown encoding: "+e);return t||e}function a(e){var t;switch(this.encoding=i(e),this.encoding){case"utf16le":this.text=p,this.end=g,t=4;break;case"utf8":this.fillLast=d,t=4;break;case"base64":this.text=m,this.end=y,t=3;break;default:return this.write=v,void(this.end=b)}this.lastNeed=0,this.lastTotal=0,this.lastChar=r.allocUnsafe(t)}function c(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function l(e,t,n){var r=t.length-1;if(r<n)return 0;var o=c(t[r]);return o>=0?(o>0&&(e.lastNeed=o-1),o):--r<n||-2===o?0:(o=c(t[r]))>=0?(o>0&&(e.lastNeed=o-2),o):--r<n||-2===o?0:(o=c(t[r]))>=0?(o>0&&(2===o?o=0:e.lastNeed=o-3),o):0}function u(e,t,n){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}function d(e){var t=this.lastTotal-this.lastNeed,n=u(this,e);return void 0!==n?n:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function h(e,t){var n=l(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=n;var r=e.length-(n-this.lastNeed);return e.copy(this.lastChar,0,r),e.toString("utf8",t,r)}function f(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function p(e,t){if((e.length-t)%2==0){var n=e.toString("utf16le",t);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function g(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,n)}return t}function m(e,t){var n=(e.length-t)%3;return 0===n?e.toString("base64",t):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-n))}function y(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function v(e){return e.toString(this.encoding)}function b(e){return e&&e.length?this.write(e):""}n.StringDecoder=a,a.prototype.write=function(e){if(0===e.length)return"";var t,n;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n<e.length?t?t+this.text(e,n):this.text(e,n):t||""},a.prototype.end=f,a.prototype.text=h,a.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}},{"safe-buffer":73}],76:[function(e,t,n){var r=e("punycode"),o=e("./util");function s(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}n.parse=w,n.resolve=_,n.resolveObject=k,n.format=C,n.Url=s;var i=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,l=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),u=["'"].concat(l),d=["%","/","?",";","#"].concat(u),h=["/","?","#"],f=255,p=/^[+a-z0-9A-Z_-]{0,63}$/,g=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,m={javascript:!0,"javascript:":!0},y={javascript:!0,"javascript:":!0},v={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},b=e("querystring");function w(e,t,n){if(e&&o.isObject(e)&&e instanceof s)return e;var r=new s;return r.parse(e,t,n),r}function C(e){return o.isString(e)&&(e=w(e)),e instanceof s?e.format():s.prototype.format.call(e)}function _(e,t){return w(e,!1,!0).resolve(t)}function k(e,t){return e?w(e,!1,!0).resolveObject(t):t}s.prototype.parse=function(e,t,n){if(!o.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var s=e.indexOf("?"),a=-1!==s&&s<e.indexOf("#")?"?":"#",l=e.split(a),w=/\\/g;l[0]=l[0].replace(w,"/");var C=e=l.join(a);if(C=C.trim(),!n&&1===e.split("#").length){var _=c.exec(C);if(_)return this.path=C,this.href=C,this.pathname=_[1],_[2]?(this.search=_[2],this.query=t?b.parse(this.search.substr(1)):this.search.substr(1)):t&&(this.search="",this.query={}),this}var k=i.exec(C);if(k){var S=(k=k[0]).toLowerCase();this.protocol=S,C=C.substr(k.length)}if(n||k||C.match(/^\/\/[^@\/]+@[^@\/]+/)){var A="//"===C.substr(0,2);!A||k&&y[k]||(C=C.substr(2),this.slashes=!0)}if(!y[k]&&(A||k&&!v[k])){for(var E,I,O=-1,T=0;T<h.length;T++)-1!==(x=C.indexOf(h[T]))&&(-1===O||x<O)&&(O=x);for(-1!==(I=-1===O?C.lastIndexOf("@"):C.lastIndexOf("@",O))&&(E=C.slice(0,I),C=C.slice(I+1),this.auth=decodeURIComponent(E)),O=-1,T=0;T<d.length;T++){var x;-1!==(x=C.indexOf(d[T]))&&(-1===O||x<O)&&(O=x)}-1===O&&(O=C.length),this.host=C.slice(0,O),C=C.slice(O),this.parseHost(),this.hostname=this.hostname||"";var R="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!R)for(var P=this.hostname.split(/\./),M=(T=0,P.length);T<M;T++){var j=P[T];if(j&&!j.match(p)){for(var F="",N=0,B=j.length;N<B;N++)j.charCodeAt(N)>127?F+="x":F+=j[N];if(!F.match(p)){var U=P.slice(0,T),D=P.slice(T+1),L=j.match(g);L&&(U.push(L[1]),D.unshift(L[2])),D.length&&(C="/"+D.join(".")+C),this.hostname=U.join(".");break}}}this.hostname.length>f?this.hostname="":this.hostname=this.hostname.toLowerCase(),R||(this.hostname=r.toASCII(this.hostname));var q=this.port?":"+this.port:"",$=this.hostname||"";this.host=$+q,this.href+=this.host,R&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==C[0]&&(C="/"+C))}if(!m[S])for(T=0,M=u.length;T<M;T++){var z=u[T];if(-1!==C.indexOf(z)){var H=encodeURIComponent(z);H===z&&(H=escape(z)),C=C.split(z).join(H)}}var V=C.indexOf("#");-1!==V&&(this.hash=C.substr(V),C=C.slice(0,V));var W=C.indexOf("?");if(-1!==W?(this.search=C.substr(W),this.query=C.substr(W+1),t&&(this.query=b.parse(this.query)),C=C.slice(0,W)):t&&(this.search="",this.query={}),C&&(this.pathname=C),v[S]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){q=this.pathname||"";var K=this.search||"";this.path=q+K}return this.href=this.format(),this},s.prototype.format=function(){var e=this.auth||"";e&&(e=(e=encodeURIComponent(e)).replace(/%3A/i,":"),e+="@");var t=this.protocol||"",n=this.pathname||"",r=this.hash||"",s=!1,i="";this.host?s=e+this.host:this.hostname&&(s=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(s+=":"+this.port)),this.query&&o.isObject(this.query)&&Object.keys(this.query).length&&(i=b.stringify(this.query));var a=this.search||i&&"?"+i||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||v[t])&&!1!==s?(s="//"+(s||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):s||(s=""),r&&"#"!==r.charAt(0)&&(r="#"+r),a&&"?"!==a.charAt(0)&&(a="?"+a),t+s+(n=n.replace(/[?#]/g,(function(e){return encodeURIComponent(e)})))+(a=a.replace("#","%23"))+r},s.prototype.resolve=function(e){return this.resolveObject(w(e,!1,!0)).format()},s.prototype.resolveObject=function(e){if(o.isString(e)){var t=new s;t.parse(e,!1,!0),e=t}for(var n=new s,r=Object.keys(this),i=0;i<r.length;i++){var a=r[i];n[a]=this[a]}if(n.hash=e.hash,""===e.href)return n.href=n.format(),n;if(e.slashes&&!e.protocol){for(var c=Object.keys(e),l=0;l<c.length;l++){var u=c[l];"protocol"!==u&&(n[u]=e[u])}return v[n.protocol]&&n.hostname&&!n.pathname&&(n.path=n.pathname="/"),n.href=n.format(),n}if(e.protocol&&e.protocol!==n.protocol){if(!v[e.protocol]){for(var d=Object.keys(e),h=0;h<d.length;h++){var f=d[h];n[f]=e[f]}return n.href=n.format(),n}if(n.protocol=e.protocol,e.host||y[e.protocol])n.pathname=e.pathname;else{for(var p=(e.pathname||"").split("/");p.length&&!(e.host=p.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==p[0]&&p.unshift(""),p.length<2&&p.unshift(""),n.pathname=p.join("/")}if(n.search=e.search,n.query=e.query,n.host=e.host||"",n.auth=e.auth,n.hostname=e.hostname||e.host,n.port=e.port,n.pathname||n.search){var g=n.pathname||"",m=n.search||"";n.path=g+m}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var b=n.pathname&&"/"===n.pathname.charAt(0),w=e.host||e.pathname&&"/"===e.pathname.charAt(0),C=w||b||n.host&&e.pathname,_=C,k=n.pathname&&n.pathname.split("/")||[],S=(p=e.pathname&&e.pathname.split("/")||[],n.protocol&&!v[n.protocol]);if(S&&(n.hostname="",n.port=null,n.host&&(""===k[0]?k[0]=n.host:k.unshift(n.host)),n.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===p[0]?p[0]=e.host:p.unshift(e.host)),e.host=null),C=C&&(""===p[0]||""===k[0])),w)n.host=e.host||""===e.host?e.host:n.host,n.hostname=e.hostname||""===e.hostname?e.hostname:n.hostname,n.search=e.search,n.query=e.query,k=p;else if(p.length)k||(k=[]),k.pop(),k=k.concat(p),n.search=e.search,n.query=e.query;else if(!o.isNullOrUndefined(e.search))return S&&(n.hostname=n.host=k.shift(),(T=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=T.shift(),n.host=n.hostname=T.shift())),n.search=e.search,n.query=e.query,o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n;if(!k.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var A=k.slice(-1)[0],E=(n.host||e.host||k.length>1)&&("."===A||".."===A)||""===A,I=0,O=k.length;O>=0;O--)"."===(A=k[O])?k.splice(O,1):".."===A?(k.splice(O,1),I++):I&&(k.splice(O,1),I--);if(!C&&!_)for(;I--;I)k.unshift("..");!C||""===k[0]||k[0]&&"/"===k[0].charAt(0)||k.unshift(""),E&&"/"!==k.join("/").substr(-1)&&k.push("");var T,x=""===k[0]||k[0]&&"/"===k[0].charAt(0);return S&&(n.hostname=n.host=x?"":k.length?k.shift():"",(T=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=T.shift(),n.host=n.hostname=T.shift())),(C=C||n.host&&k.length)&&!x&&k.unshift(""),k.length?n.pathname=k.join("/"):(n.pathname=null,n.path=null),o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},s.prototype.parseHost=function(){var e=this.host,t=a.exec(e);t&&(":"!==(t=t[0])&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},{"./util":77,punycode:51,querystring:54}],77:[function(e,t,n){t.exports={isString:function(e){return"string"==typeof e},isObject:function(e){return"object"==typeof e&&null!==e},isNull:function(e){return null===e},isNullOrUndefined:function(e){return null==e}}},{}],78:[function(e,t,n){(function(e){(function(){function n(e,t){if(r("noDeprecation"))return e;var n=!1;function o(){if(!n){if(r("throwDeprecation"))throw new Error(t);r("traceDeprecation")?console.trace(t):console.warn(t),n=!0}return e.apply(this,arguments)}return o}function r(t){try{if(!e.localStorage)return!1}catch(e){return!1}var n=e.localStorage[t];return null!=n&&"true"===String(n).toLowerCase()}t.exports=n}).call(this)}).call(this,void 0!==_e?_e:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],79:[function(e,t,n){function r(e,t){if(e&&t)return r(e)(t);if("function"!=typeof e)throw new TypeError("need wrapper function");return Object.keys(e).forEach((function(t){n[t]=e[t]})),n;function n(){for(var t=new Array(arguments.length),n=0;n<t.length;n++)t[n]=arguments[n];var r=e.apply(this,t),o=t[t.length-1];return"function"==typeof r&&r!==o&&Object.keys(o).forEach((function(e){r[e]=o[e]})),r}}t.exports=r},{}],80:[function(e,t,n){t.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},{}],81:[function(e,t,n){t.exports=o;var r=Object.prototype.hasOwnProperty;function o(){for(var e={},t=0;t<arguments.length;t++){var n=arguments[t];for(var o in n)r.call(n,o)&&(e[o]=n[o])}return e}},{}],82:[function(e,t,n){t.exports=function(e){e.prototype[Symbol.iterator]=function*(){for(let e=this.head;e;e=e.next)yield e.value}}},{}],83:[function(e,t,n){function r(e){var t=this;if(t instanceof r||(t=new r),t.tail=null,t.head=null,t.length=0,e&&"function"==typeof e.forEach)e.forEach((function(e){t.push(e)}));else if(arguments.length>0)for(var n=0,o=arguments.length;n<o;n++)t.push(arguments[n]);return t}function o(e,t,n){var r=t===e.head?new a(n,null,t,e):new a(n,t,t.next,e);return null===r.next&&(e.tail=r),null===r.prev&&(e.head=r),e.length++,r}function s(e,t){e.tail=new a(t,e.tail,null,e),e.head||(e.head=e.tail),e.length++}function i(e,t){e.head=new a(t,null,e.head,e),e.tail||(e.tail=e.head),e.length++}function a(e,t,n,r){if(!(this instanceof a))return new a(e,t,n,r);this.list=r,this.value=e,t?(t.next=this,this.prev=t):this.prev=null,n?(n.prev=this,this.next=n):this.next=null}t.exports=r,r.Node=a,r.create=r,r.prototype.removeNode=function(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");var t=e.next,n=e.prev;return t&&(t.prev=n),n&&(n.next=t),e===this.head&&(this.head=t),e===this.tail&&(this.tail=n),e.list.length--,e.next=null,e.prev=null,e.list=null,t},r.prototype.unshiftNode=function(e){if(e!==this.head){e.list&&e.list.removeNode(e);var t=this.head;e.list=this,e.next=t,t&&(t.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}},r.prototype.pushNode=function(e){if(e!==this.tail){e.list&&e.list.removeNode(e);var t=this.tail;e.list=this,e.prev=t,t&&(t.next=e),this.tail=e,this.head||(this.head=e),this.length++}},r.prototype.push=function(){for(var e=0,t=arguments.length;e<t;e++)s(this,arguments[e]);return this.length},r.prototype.unshift=function(){for(var e=0,t=arguments.length;e<t;e++)i(this,arguments[e]);return this.length},r.prototype.pop=function(){if(this.tail){var e=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,e}},r.prototype.shift=function(){if(this.head){var e=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,e}},r.prototype.forEach=function(e,t){t=t||this;for(var n=this.head,r=0;null!==n;r++)e.call(t,n.value,r,this),n=n.next},r.prototype.forEachReverse=function(e,t){t=t||this;for(var n=this.tail,r=this.length-1;null!==n;r--)e.call(t,n.value,r,this),n=n.prev},r.prototype.get=function(e){for(var t=0,n=this.head;null!==n&&t<e;t++)n=n.next;if(t===e&&null!==n)return n.value},r.prototype.getReverse=function(e){for(var t=0,n=this.tail;null!==n&&t<e;t++)n=n.prev;if(t===e&&null!==n)return n.value},r.prototype.map=function(e,t){t=t||this;for(var n=new r,o=this.head;null!==o;)n.push(e.call(t,o.value,this)),o=o.next;return n},r.prototype.mapReverse=function(e,t){t=t||this;for(var n=new r,o=this.tail;null!==o;)n.push(e.call(t,o.value,this)),o=o.prev;return n},r.prototype.reduce=function(e,t){var n,r=this.head;if(arguments.length>1)n=t;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");r=this.head.next,n=this.head.value}for(var o=0;null!==r;o++)n=e(n,r.value,o),r=r.next;return n},r.prototype.reduceReverse=function(e,t){var n,r=this.tail;if(arguments.length>1)n=t;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");r=this.tail.prev,n=this.tail.value}for(var o=this.length-1;null!==r;o--)n=e(n,r.value,o),r=r.prev;return n},r.prototype.toArray=function(){for(var e=new Array(this.length),t=0,n=this.head;null!==n;t++)e[t]=n.value,n=n.next;return e},r.prototype.toArrayReverse=function(){for(var e=new Array(this.length),t=0,n=this.tail;null!==n;t++)e[t]=n.value,n=n.prev;return e},r.prototype.slice=function(e,t){(t=t||this.length)<0&&(t+=this.length),(e=e||0)<0&&(e+=this.length);var n=new r;if(t<e||t<0)return n;e<0&&(e=0),t>this.length&&(t=this.length);for(var o=0,s=this.head;null!==s&&o<e;o++)s=s.next;for(;null!==s&&o<t;o++,s=s.next)n.push(s.value);return n},r.prototype.sliceReverse=function(e,t){(t=t||this.length)<0&&(t+=this.length),(e=e||0)<0&&(e+=this.length);var n=new r;if(t<e||t<0)return n;e<0&&(e=0),t>this.length&&(t=this.length);for(var o=this.length,s=this.tail;null!==s&&o>t;o--)s=s.prev;for(;null!==s&&o>e;o--,s=s.prev)n.push(s.value);return n},r.prototype.splice=function(e,t,...n){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);for(var r=0,s=this.head;null!==s&&r<e;r++)s=s.next;var i=[];for(r=0;s&&r<t;r++)i.push(s.value),s=this.removeNode(s);for(null===s&&(s=this.tail),s!==this.head&&s!==this.tail&&(s=s.prev),r=0;r<n.length;r++)s=o(this,s,n[r]);return i},r.prototype.reverse=function(){for(var e=this.head,t=this.tail,n=e;null!==n;n=n.prev){var r=n.prev;n.prev=n.next,n.next=r}return this.head=t,this.tail=e,this};try{e("./iterator.js")(r)}catch(e){}},{"./iterator.js":82}]},{},[12])(12)}(qi);var $i=ke(qi.exports);const zi=1e3;var Hi;!function(e){e[e.IDENTIFIER_REJECTED=2]="IDENTIFIER_REJECTED",e[e.BAD_USERNAME_OR_PASSWORD=134]="BAD_USERNAME_OR_PASSWORD",e[e.NOT_AUTHORIZED=135]="NOT_AUTHORIZED"}(Hi||(Hi={}));const Vi=e=>{let t;return{connect:async function(n){return t&&(t.removeAllListeners(),t.end(!0)),t=$i.connect(e,function(e){return Object.assign({clean:!1,clientId:`mqttjs_ + ${Math.random().toString(16).substring(2,10)}`,protocolId:"MQTT",protocolVersion:5,reconnectPeriod:zi,will:{topic:"WillMsg",payload:"Connection Closed abnormally..!",qos:0,retain:!1},resubscribe:!0},e)}({username:n.userId,password:n.accessToken})),t.on("connect",(()=>{t.options.reconnectPeriod=zi})),t.on("error",(e=>{switch(e.code){case 2:case 134:case 135:t.end()}})),t.on("reconnect",(()=>{t.options.reconnectPeriod=Math.min(2*(t.options.reconnectPeriod||zi),8e3)})),new Promise((e=>t.once("connect",(()=>e()))))},async disconnect(){if(this.connected)return new Promise((e=>null==t?void 0:t.end(!0,void 0,(()=>e()))))},get connected(){return!!(null==t?void 0:t.connected)},on(e,n){null==t||t.on(e,n)},once(e,n){null==t||t.once(e,n)},off(e,n){void 0!==n?null==t||t.off(e,n):null==t||t.removeAllListeners(e)},removeAllListeners(){null==t||t.removeAllListeners()},subscribe(e,n){const r=(t,r)=>{if(t||128===r[0].qos){const r=t?new ge(t.message,8e5,"error"):new ye(8e5,"error");console.warn(`Failed to subscribe to topic ${e}`,r),null==n||n(r)}else console.log(`Subscribed to topic ${r[0].topic}`),null==n||n()};return t?t.subscribe(e,{qos:0},r):r(new Error("No connection to broker"),[]),()=>null==t?void 0:t.unsubscribe(e)},unsubscribe(e){null==t||t.unsubscribe(e)}}},Wi=async()=>{const e=we(),{data:t}=await e.http.get("/api/v3/network-settings/feed-setting");return Object.fromEntries(t.feedSettings.map((({feedType:e,contentSettings:t})=>[e,t])))},Ki=()=>`ascWebSdk#${Math.random().toString(16)}`,Qi=()=>{const e=(()=>{var e,t;return(null===(e=jt.versions)||void 0===e?void 0:e.node)?jt.versions.node:navigator?`${navigator.product.toLowerCase()}#${null!==(t=navigator.userAgent)&&void 0!==t?t:"unknown_agent"}`:"unknown_model"})();return{kind:"web",model:e,sdkVersion:d}},Ji={notLoggedIn:["establishing"],terminated:["establishing"],establishing:["notLoggedIn","established"],established:["notLoggedIn","terminated","tokenExpired","establishing"],tokenExpired:["establishing"]},Gi=e=>{const t=we();t.log("client/api/setSessionState",e);const{sessionState:n}=t;if(n===e)return!1;if(!((e,t)=>Ji[e].includes(t))(n,e))throw new ge(`Session state cannot change from ${n} to ${e}`,8e5,"error");return t.sessionState=e,t.emitter.emit("sessionStateChange",e),!0},Yi=async e=>{const t=we();Gi("establishing");const{accessToken:n,users:r,expiresAt:o,issuedAt:s,refreshToken:i}=await(async e=>{const t=we();t.log("client/api/getToken",e);const n=Qi(),{data:r}=await t.http.post("/api/v4/sessions",Object.assign(Object.assign({},e),{deviceInfo:n}),{headers:{"X-API-Key":t.apiKey}});return r})(e);return t.http.defaults.headers.common.Authorization=`Bearer ${n}`,t.http.defaults.metadata={tokenExpiry:o,isGlobalBanned:!1,isUserDeleted:!1},t.ws.io.opts.query={token:n},t.token={accessToken:n,issuedAt:s,expiresAt:o},Gi("established"),{accessToken:n,users:r,refreshToken:i}},Xi=(e={},t)=>{Object.entries(e).forEach((([e,n])=>{const r=he[e];if(!r)return;const o=ce(r);o&&n.forEach((e=>{ze([r,"get",o(e)],e,t)}))}))};function Zi(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}const ea=(e,t="userId",n="user")=>{var r;return null!==(r=null==e?void 0:e.map((e=>((e,t="userId",n="user")=>e[n]?e:Object.assign({get[n](){var n;if(!we().cache)return;return(null===(n=Le(["user","get",e[t]]))||void 0===n?void 0:n.data)||void 0}},e))(e,t,n))))&&void 0!==r?r:e},ta=(e,t,n="userId",r="user")=>{const o=e,s=t,i=o[s],a=Zi(o,["symbol"==typeof s?s:s+""]),c=ea(i,n,r);return Object.assign(Object.assign({},a),{[t]:c})},na=(e,t)=>{var n,r,o;return(null==t?void 0:t.isDeleted)?0:null!==(o=null!==(n=null==t?void 0:t.unreadCount)&&void 0!==n?n:null===(r=(e=>{var t;const n={entityId:e,userId:ht()._id};return null===(t=Le(["channelMarker","get",ce("channelMarker")(n)]))||void 0===t?void 0:t.data})(e.channelId))||void 0===r?void 0:r.unreadCount)&&void 0!==o?o:0},ra=(e,t)=>{var n;return null!==(n=null!=t?t:(e=>{var t,n;const r={creatorId:e.creatorId,feedId:null!==(t=e.messageFeedId)&&void 0!==t?t:e.subChannelId,contentId:e.messageId};return null===(n=Le(["messageMarker","get",ce("messageMarker")(r)]))||void 0===n?void 0:n.data})(e))&&void 0!==n?n:{readCount:0,deliveredCount:0}};function oa(e,t,n){var r;if(n)return n.unreadCount;const o={entityId:e,feedId:t,userId:ht()._id},s=null===(r=Le(["subChannelMarker","get",ce("subChannelMarker")(o)]))||void 0===r?void 0:r.data;return s?s.unreadCount:0}const sa=(e,t)=>{t.length&&ut(e,{userMarkers:t})},ia=(e,t)=>{t.length&&ut(e,{feedMarkers:t})},aa=(e,t)=>{if(!t.length)return;ut(e,{userEntityMarkers:t});const n=function(e){var t;const n=["channel","get",e.entityId],r=null===(t=Le(n))||void 0===t?void 0:t.data;if(!r)return;const o=Object.assign(Object.assign({},r),{unreadCount:na(r,e),updatedAt:(new Date).toISOString()});return ze(n,o),o}(t[0]);return n&&ut("local.channel.updated",{channels:[n]}),n},ca=(e,t)=>{if(!t.length)return;ut(e,{userFeedMarkers:t});const n=function(e){var t;const n=["subChannel","get",e.feedId],r=null===(t=Le(n))||void 0===t?void 0:t.data;if(!r)return;const o=Object.assign(Object.assign({},r),{unreadCount:oa(r.channelId,r.subChannelId,e),updatedAt:(new Date).toISOString()});return ze(n,o),o}(t[0]);return n&&ut("local.message-feed.updated",{messageFeeds:[n]}),n},la=(e,t)=>{if(!t.length)return;ut(e,{contentMarkers:t});const n=function(e){var t;const n=["message","get",e.contentId],r=null===(t=Le(n))||void 0===t?void 0:t.data;if(!r)return;const{readCount:o,deliveredCount:s}=ra(r,e),i=Object.assign(Object.assign({},r),{readCount:o,deliveredCount:s,updatedAt:(new Date).toISOString()});return ze(n,i),i}(t[0]);return n&&ut("local.message.updated",{messages:[n]}),n},ua=async(e,t={limit:100})=>{const n=we();n.log("channel/getChannelMarkers",e,t);const{data:r}=await n.http.get("/api/v1/markers/channels",{params:{channelIds:e,options:{token:J(t,"skiplimit")}}}),{paging:o}=r,s=Zi(r,["paging"]),{userEntityMarkers:i,userMarkers:a}=s,c=n.cache&&Date.now();n.cache&&Xi(s,{cachedAt:c}),aa("local.channelMarker.fetched",i),sa("local.userMarker.fetched",a);const l=G(o.next);return{data:i,cachedAt:c,prevPage:G(o.previous),nextPage:l}},da=["broadcast","conversation","community"],ha=({type:e})=>da.includes(e);function fa(e,t){return Object.assign(Object.assign({},e),{defaultSubChannelId:e._id,isUnreadCountSupport:ha(e),unreadCount:na(e,t)})}const pa=async e=>{let t=[];const n=e.channels.filter(ha).map((({channelId:e})=>e));if(n.length>0){(e=>{Xi({channels:e.channels.map((e=>fa(e)))})})(e);try{({data:t}=await ua(n))}catch(e){}}const r=e.channels.map((e=>{const n=null==t?void 0:t.find((({entityId:t})=>t===e.channelId));return fa(e,n)})),o=ea(e.channelUsers);return Object.assign(Object.assign({},e),{channels:r,channelUsers:o})},ga=e=>{const t=we();return lt(t,"onChannelDeleted","channel.deleted",(async t=>{const n=await pa(t);Xi(n),e(n.channels[0])}))},ma=e=>{const t=we();return lt(t,"onChannelMemberBanned","channel.banned",(async t=>{const n=await pa(t),{channels:r,channelUsers:o}=n;Xi(n),e(r[0],o.find((e=>"banned"===e.membership)))}))},ya=(e,t)=>{const n=we();return lt(n,e,e,(e=>{n.cache&&Xi(e),t(e.users[0])}))},va=e=>ya("user.deleted",e),ba=async()=>{const e=we();return e.log("client/api/disconnectClient"),await new Promise((t=>{e.ws.once("disconnect",t),e.ws.disconnect(),e.mqtt.disconnect()})),"established"===e.sessionState&&Gi("notLoggedIn"),e.emitter.all.clear(),e.ws.removeAllListeners(),e.mqtt.removeAllListeners(),e.userId=void 0,e.token=void 0,e.http.defaults.headers.common.Authorization="",e.ws.io.opts.query={token:""},"tokenExpired"!==e.sessionState&&e.cache&&(e.cache={data:{}}),!e.ws.connected},wa=e=>{const t=we();Gi("terminated"),t.http.defaults.metadata&&("globalBan"===e&&(t.http.defaults.metadata.isGlobalBanned=!0),"userDeleted"===e&&(t.http.defaults.metadata.isUserDeleted=!0)),t.sessionHandler=void 0,ba()},Ca=["disconnected","error","connect_error","reconnect_error","reconnect_failed"],_a=e=>{const t=we(),n=Ca.map((n=>lt(t,`client/onConnectionError(${n})`,n,(t=>{const r=(null==t?void 0:t.code)?new ge(t.message,t.code,"fatal"):new ve(n);e(r)}))));return()=>{n.forEach((e=>e()))}},ka=e=>{const t=we();return lt(t,"client/onConnectionError(user.didGlobalBan)","user.didGlobalBan",e)},Sa=e=>{const t=ce("channelMarker")({userId:ht()._id,entityId:e.channelId});He(["channelMarker","get",t],!0)},Aa=[],Ea=async(e,t,n)=>{var r,o,s;const i=we();let a;i.log("client/api/connectClient",Object.assign({apiKey:i.apiKey,sessionState:i.sessionState},e)),i.userId&&i.userId!==e.userId&&(await ba(),Aa.forEach((e=>e()))),null!==(r=e.deviceId)&&void 0!==r||(e.deviceId=Ki());try{const{users:n}=await Yi(e);c=i.ws,l=i.emitter,it.forEach((e=>{c.on(e,(t=>{l.emit(e,t)}))})),await new Promise((e=>{i.ws.once("connect",e),i.ws.open()})),i.userId=e.userId,i.sessionHandler=t,a=i.accessTokenExpiryWatcher(null===(o=i.token)||void 0===o?void 0:o.expiresAt,null===(s=i.token)||void 0===s?void 0:s.issuedAt,t),ft(n[0])}catch(e){throw Gi("notLoggedIn"),e}var c,l;return!0!==(null==n?void 0:n.disableRTE)&&(At(bt()),At(wt()),At(Ct()),At(_t()),At(yt(ht()))),Aa.push(ka((e=>{wa("globalBan"),Aa.forEach((e=>e())),a()})),(e=>{const t=we();return lt(t,"client/onTokenTerminated","tokenTerminated",e)})((e=>{wa(),Aa.forEach((e=>e())),a()})),va((e=>{e.userId===i.userId&&(wa("userDeleted"),Aa.forEach((e=>e())),a())})),(e=>{const t=we();return lt(t,"client/onTokenExpired","tokenExpired",e)})((e=>{Gi(e),ba(),Aa.forEach((e=>e()))})),ga(Sa),ma(Sa)),i.ws.connected},Ia=()=>{let e,t=!1;const n=we();n.log("initiating access token renewal");const r=async r=>{const{userId:o,displayName:s}=ht(),i={userId:o,displayName:s,authToken:r,deviceId:Ki()};"tokenExpired"===n.sessionState?await Ea(i,n.sessionHandler):await Yi(i),t=!0,e&&clearTimeout(e)};return{renew:()=>{t?console.log("'renew' method can be called only once per renewal instance"):r()},renewWithAuthToken:e=>{t?console.log("'renewWithAuthToken' method can be called only once per renewal instance"):r(e)},unableToRetrieveAuthToken:()=>{e=setTimeout((()=>{var e;null===(e=n.sessionHandler)||void 0===e||e.sessionWillRenewAccessToken(Ia())}),g)}}},Oa=3e5,Ta=(e,t,n)=>{const r=setInterval((()=>{if((e=>Date.now()>Date.parse(e)-Oa)(e))return ut("tokenExpired","tokenExpired"),void st((()=>n.sessionWillRenewAccessToken(Ia())));(e=>{const{expiresAt:t,issuedAt:n}=e,r=Date.parse(t),o=Date.parse(n),s=Date.now();return s>o+.8*(r-o-Oa)&&s<r})({expiresAt:e,issuedAt:t})&&n.sessionWillRenewAccessToken(Ia())}),g);return()=>clearInterval(r)},xa=async()=>{const e=we();e.log("channel/markerSync");const{data:t}=await e.http.post("/api/v1/markers/sync"),{userEntityMarkers:n,userFeedMarkers:r,feedMarkers:o,userMarkers:s}=t,i=e.cache&&Date.now();return e.cache&&Xi(t,{cachedAt:i}),ia("local.feedMarker.fetched",o),aa("local.channelMarker.fetched",n),ca("local.subChannelMarker.fetched",r),sa("local.userMarker.fetched",s),{hasMore:t.feedMarkers.length>0}},Ra=async(e,t={limit:100})=>{const n=we();n.log("channel/getMessageMarkers",e,t);const{data:r}=await n.http.get("/api/v1/markers/messages",{params:{messageIds:e,options:{token:J(t,"skiplimit")}}}),{paging:o}=r,s=Zi(r,["paging"]),{contentMarkers:i,feedMarkers:a,userMarkers:c}=s,l=n.cache&&Date.now();n.cache&&Xi(s,{cachedAt:l}),ia("local.feedMarker.fetched",a),la("local.messageMarker.fetched",i),sa("local.userMarker.fetched",c);const u=G(o.next);return{data:i,cachedAt:l,prevPage:G(o.previous),nextPage:u}},Pa=async(e,t={limit:100})=>{const n=we();n.log("channel/getSubChannelMarkers",e,t);const{data:r}=await n.http.get("/api/v1/markers/message-feeds",{params:{messageFeedIds:e,options:{token:J(t,"skiplimit")}}}),{paging:o}=r,s=Zi(r,["paging"]),{userEntityMarkers:i,userFeedMarkers:a,userMarkers:c}=s,l=n.cache&&Date.now();n.cache&&Xi(s,{cachedAt:l}),aa("local.channelMarker.fetched",i),ca("local.subChannelMarker.fetched",a),sa("local.userMarker.fetched",c);const u=G(o.next);return{data:a,cachedAt:l,prevPage:G(o.previous),nextPage:u}},Ma=()=>{var e,t;const n=we(),r=ht();n.log("marker/getUserMarker.locally");const{_id:o}=r;if(!o)throw new ge("The userId has not been defined in active client",8e5,"error");const s=(new Date).toISOString(),i=n.cache&&Date.now();return{data:null!==(t=null===(e=Le(["userMarker","get",ce("userMarker")({userId:o})]))||void 0===e?void 0:e.data)&&void 0!==t?t:{userId:o,unreadCount:0,lastSyncAt:s,createdAt:s,updatedAt:s},cachedAt:i}},ja=()=>Promise.resolve(Ma());ja.locally=Ma;const Fa=e=>{const t=we();return lt(t,"feedMarker/onFeedMarkerUpdated","marker.feed-updated",(t=>{e(t.feedMarkers[0])}))},Na=e=>{const t=we();return lt(t,"userMarker/onUserMarkerFetched","local.userMarker.fetched",(t=>{e(t.userMarkers[0])}))};function Ba(e,t){if(null==e||null==t)return e===t;if(e.constructor!==t.constructor)return!1;if(e instanceof Function)return e===t;if(e instanceof RegExp)return e===t;if(e===t||e.valueOf()===t.valueOf())return!0;if(Array.isArray(e)&&e.length!==t.length)return!1;if(e instanceof Date)return!1;if(!(e instanceof Object))return!1;if(!(t instanceof Object))return!1;const n=Object.keys(e);return Object.keys(t).every((e=>-1!==n.indexOf(e)))&&n.every((n=>Ba(e[n],t[n])))}const Ua=(e,t,n,r,o,s=(e=>e),i)=>{const{cache:a}=we();let c;a||console.log("For using Live Object feature you need to enable Cache!");let l=!1;const u=[],d=e=>{const{data:n}=e,r=Zi(e,["data"]);i&&!i(n,c)||t(Object.assign({data:s(n)},r)),c=n},h=t=>{e===t[n]&&(c&&"updatedAt"in c&&"updatedAt"in t&&(!fe(c,t)||Ba(c,t))||d({loading:!1,data:t,origin:"event"}))};return u.push(...o.map((e=>e(h)))),(()=>{const t=re(r,e,!0);se(t,(({error:e,data:t,loading:n,origin:r,cachedAt:o})=>{-5===o?(d({data:t,origin:r,loading:!1,error:new me("Observing unsynced object is not supported by Live Object.",800800,"error")}),l=!0,u.forEach((e=>e()))):l||d({loading:n,data:t,origin:r,error:e}),e&&u.forEach((e=>e()))}))})(),()=>{u.forEach((e=>e()))}},Da=e=>!0===e&&void 0;function La(e,t){const{channelPublicId:n,childCount:r,creatorPublicId:o,mentionedUsers:s,messageFeedId:i,myReactions:a,reactionCount:c,reactions:l,referenceId:u,segment:d,messageId:h}=e,f=Zi(e,["channelPublicId","childCount","creatorPublicId","mentionedUsers","messageFeedId","myReactions","reactionCount","reactions","referenceId","segment","messageId"]),{readCount:p,deliveredCount:g}=ra(e,t);let m;u&&(m=Le(["message","get",u])),m||(m=Le(["message","get",h]));const y=Object.assign(Object.assign({},f),{messageId:h,channelId:n,channelSegment:d,childrenNumber:r,creatorId:o,reactions:null!=l?l:{},reactionsCount:c,subChannelId:i,uniqueId:m?m.data.uniqueId:h,readCount:p,deliveredCount:g});return s&&(y.mentionees=s.map((e=>"channel"===e.type?e:{type:"user",userIds:e.userPublicIds}))),a?y.myReactions=a:(e=>{const t=we(),n=Le(["message","get",e.messageId]),r=(null==n?void 0:n.data.myReactions)||[];Object.assign(e,{myReactions:r});const o=null==e?void 0:e.latestReaction;o&&o.userId===t.userId&&("add"!==o.eventName||r.includes(o.reactionName)||Object.assign(e,{myReactions:[...r,o.reactionName]}),"remove"===o.eventName&&r.includes(o.reactionName)&&Object.assign(e,{myReactions:r.filter((e=>e!==o.reactionName))}))})(y),y}const qa=async e=>{let t=[];const n=e.messages.map((({messageId:e})=>e));if(n.length>0){Xi({messages:e.messages.map((e=>La(e)))});try{({data:t}=await Ra(n))}catch(e){}}return Object.assign(Object.assign({},e),{messages:e.messages.map((e=>{const n=null==t?void 0:t.find((({contentId:t})=>t===e.messageId));return La(e,n)}))})};function $a(e){var{subChannelId:t,mentionees:n}=e,r=Zi(e,["subChannelId","mentionees"]);return Object.assign({messageFeedId:t,mentionedUsers:n},r)}function za(e){var{page:t,sortBy:n,subChannelId:r,tags:o,includeDeleted:s}=e,i=Zi(e,["page","sortBy","subChannelId","tags","includeDeleted"]);const a=Object.assign(Object.assign({},i),{messageFeedId:r,isDeleted:Da(s),options:{token:J(t||{limit:10},"afterbeforeraw")}});return void 0!==n&&(a.options.sortBy=n),o&&(a.includeTags=o),a}const Ha=(e,t=!0)=>{const n=we(),r=[lt(n,"message/onMessageCreated","message.created",(async t=>{const n=await qa(t),r=n.messages[0];Xi(n),e(r)}))];return t&&lt(n,"message/onMessageCreated","local.message.created",(t=>e(t.messages[0]))),()=>{r.forEach((e=>e()))}},Va=e=>{const t=we(),n=[lt(t,"onMessageUpdated","message.updated",(async t=>{const n=await qa(t);Xi(n),e(n.messages[0])})),lt(t,"onMessageUpdated","local.message.updated",(t=>e(t.messages[0]))),lt(t,"onMessageUpdated","marker.marked-message",(async t=>{const n=function(e){var t,n,r;const o=["message","get"],s=null===(n=null===(t=De(["user","get"]))||void 0===t?void 0:t.filter((({data:t})=>t._id===e.creatorId)))||void 0===n?void 0:n[0].data;if(!s)return;const i=null===(r=De(o))||void 0===r?void 0:r.filter((({data:t})=>t.subChannelId===e.feedId&&t.creatorId===s.userId));return i?i.map((({data:t})=>{const{readCount:n,deliveredCount:r}=ra(t,e),s=Object.assign(Object.assign({},t),{readCount:n,deliveredCount:r,updatedAt:(new Date).toISOString()});return ze(o,s),s})):void 0}(t.contentMarkers[0]);n&&n.forEach((t=>e(t)))}))];return()=>{n.forEach((e=>e()))}},Wa=e=>{const t=we(),n=[lt(t,"message/onMessageDeleted","message.deleted",(async t=>{const n=await qa(t);Xi(n),e(n.messages[0])})),lt(t,"message/onMessageDeleted","local.message.deleted",(t=>e(t.messages[0])))];return()=>{n.forEach((e=>e()))}},Ka=e=>{const t=we();return lt(t,"onMessageFlagged","message.flagged",(async t=>{const n=await qa(t);Xi(n),e(n.messages[0])}))},Qa=e=>{const t=we();return lt(t,"onMessageUnflagged","message.unflagged",(async t=>{const n=await qa(t);Xi(n),e(n.messages[0])}))},Ja=e=>{const t=we();return lt(t,"onMessageFlagCleared","message.flagCleared",(async t=>{const n=await qa(t);Xi(n),e(n.messages[0])}))},Ga=e=>{const t=we();return lt(t,"onMessageReactionAdded","message.reactionAdded",(async t=>{const n=await qa(t);Xi(n),e(n.messages[0])}))},Ya=e=>{const t=we();return lt(t,"onMessageReactionRemoved","message.reactionRemoved",(async t=>{const n=await qa(t);Xi(n),e(n.messages[0])}))},Xa=e=>{const t=we();return lt(t,"message/onMessageFetched","local.message.fetched",(t=>{Xi(t),e(t.messages[0])}))},Za=["broadcast","conversation","community"],ec=({channelType:e})=>Za.includes(e);function tc(e,t){var{channelId:n,channelPublicId:r,channelType:o,childCount:s,creatorId:i,creatorPublicId:a,lastMessageId:c,lastMessageTimestamp:l,messageFeedId:u,name:d}=e,h=Zi(e,["channelId","channelPublicId","channelType","childCount","creatorId","creatorPublicId","lastMessageId","lastMessageTimestamp","messageFeedId","name"]);return Object.assign(Object.assign({},h),{channelId:r,creatorId:a,displayName:d,lastActivity:l,latestMessageId:c,messageCount:s,subChannelId:u,isUnreadCountSupport:ec({channelType:o}),unreadCount:oa(n,u,t)})}const nc=async e=>{let t=[];const n=e.messageFeeds.filter(ec).map((({messageFeedId:e})=>e));if(n.length>0){(e=>{Xi({messageFeeds:e.messageFeeds.map((e=>tc(e)))})})(e);try{({data:t}=await Pa(n))}catch(e){}}const r=e.messageFeeds.map((e=>{const n=null==t?void 0:t.find((({feedId:t})=>t===e.messageFeedId));return tc(e,n)}));return Object.assign(Object.assign({},e),{messageFeeds:r})};function rc(e){var{excludeDefaultSubChannel:t}=e,n=Zi(e,["excludeDefaultSubChannel"]);const r=Object.assign({},n);return void 0!==t&&(r.excludeDefaultMessageFeed=t),r}const oc=(e,t)=>{const{log:n,cache:r}=we(),o=[e,m,t];if(!r)return;n("cache/api/isInTombstone",o);const s=Le(o),{lifeSpan:i}=oe("cache_then_server",18e4);if(s&&ne(s.data,i))throw new me("Item not found!",400400,"error")},sc=(e,t)=>{const{log:n,cache:r}=we(),o=[e,m,t],s={cachedAt:Date.now()};r&&(n("cache/api/pushToTombstone",{cacheKey:o,data:s}),He([e,"get",t],!0),qe(o,s))},ic=async e=>{const t=we();t.log("channel/getSubChannel",e),oc("subChannel",e);try{const n=await t.http.get(`/api/v5/message-feeds/${encodeURIComponent(e)}`),r=await nc(n.data),o=t.cache&&Date.now();return t.cache&&Xi(r,{cachedAt:o}),ut("local.message-feed.fetched",r),{data:r.messageFeeds[0],cachedAt:o}}catch(t){throw _(null==t?void 0:t.code)&&sc("subChannel",e),t}};ic.locally=e=>{const t=we();if(t.log("channel/getSubChannel.locally",e),!t.cache)return;const n=Le(["subChannel","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const ac=async e=>{const t=we();t.log("channel/startReadingAPI",e);const{data:n}=await t.http.post(`/api/v1/markers/message-feeds/${e}/start-reading`),{userEntityMarkers:r,userFeedMarkers:o,feedMarkers:s,userMarkers:i}=n,a=t.cache&&Date.now();return t.cache&&Xi(n,{cachedAt:a}),ia("local.feedMarker.fetched",s),aa("local.channelMarker.fetched",r),ca("local.subChannelMarker.fetched",o),sa("local.userMarker.fetched",i),!0},cc=async e=>{const t=we();t.log("channel/stopReadingAPI",e);const{data:n}=await t.http.post(`/api/v1/markers/message-feeds/${e}/stop-reading`),{userEntityMarkers:r,userFeedMarkers:o,feedMarkers:s,userMarkers:i}=n,a=t.cache&&Date.now();return t.cache&&Xi(n,{cachedAt:a}),ia("local.feedMarker.fetched",s),aa("local.channelMarker.fetched",r),ca("local.subChannelMarker.fetched",o),sa("local.userMarker.fetched",i),!0};let lc=[];const uc={},dc=e=>{var t;if(!uc[e.subChannelId])return;if(!we().cache)return;const n={entityId:e.channelId,feedId:e.subChannelId,userId:ht()._id},r=null===(t=Le(["subChannelMarker","get",ce("subChannelMarker")(n)]))||void 0===t?void 0:t.data;if(!r)return;const o=[Object.assign(Object.assign({},r),{readToSegment:e.channelSegment})];ca("local.subChannelMarker.updated",o)},hc=()=>{lc.push((()=>{const e=()=>{Object.entries(uc).forEach((([e,t])=>{t&&ac(e)}))};return window.addEventListener("online",e),()=>window.removeEventListener("online",e)})(),Ha(dc))},fc=async e=>{const t=await(async e=>{const t=ic.locally(e);if(t)return t.data.channelId;const{data:n}=await ic(e);return n.channelId})(e),n=vt({channelId:t,subChannelId:e});lc.push(At(n))},pc=e=>{const t=we();return lt(t,"onSubChannelCreated","message-feed.created",(async t=>{const n=await nc(t);Xi(n),e(n.messageFeeds[0])}))},gc=e=>{const t=we(),n=[lt(t,"onSubChannelUpdated","message-feed.updated",(async t=>{const n=await nc(t);Xi(n),e(n.messageFeeds[0])})),lt(t,"onSubChannelUpdated","local.message-feed.updated",(t=>e(t.messageFeeds[0])))];return()=>{n.forEach((e=>e()))}},mc=e=>{const t=we(),n=[lt(t,"onSubChannelDeleted","message-feed.deleted",(async t=>{const n=await nc(t);Xi(n),e(n.messageFeeds[0])})),lt(t,"local.message-feed.deleted","local.message-feed.deleted",(t=>e(t.messageFeeds[0])))];return()=>{n.forEach((e=>e()))}};let yc,vc=[],bc=!1,wc=[];const Cc=e=>{wc=e},_c=e=>wc.push(e),kc=async e=>{if(bc)return;if(0===wc.length)return;bc=!0,wc=[];(await e()).hasMore&&wc.push("has_more"),bc=!1},Sc=()=>{vc.push((()=>{const e=()=>wc.push("resume");return window.addEventListener("online",e),()=>window.removeEventListener("online",e)})(),Ha((e=>{ec(e)&&wc.push("new message")}),!1),pc((()=>wc.push("subchannel is created"))),mc((()=>wc.push("subchannel is deleted"))),Fa((()=>wc.push("feed marker updated"))))};var Ac=Object.freeze({__proto__:null,getActiveClient:we,getActiveUser:ht,setActiveUser:ft,createClient:(e,t=Nt.SG,{debugSession:n="amity",apiEndpoint:r}={})=>{var o,s;const i=(e=>{const t=`${null==e?void 0:e.trim()}`.length>0&&!Ft,n=Pt(e),r=(e,...r)=>{t&&n(e,r)};return r.__instance__=n,r})(n);i("client/api/createClient",{apiKey:e.replace(/.{5}$/g,"xxxxx"),apiRegion:t});const a=null!==(o=null==r?void 0:r.http)&&void 0!==o?o:Ut("http",t),c=null!==(s=null==r?void 0:r.mqtt)&&void 0!==s?s:Ut("mqtt",t),l=kr(a),u=(e=>{const t=Ui(e,{autoConnect:!1,reconnectionDelay:2e3,transports:["websocket"]});return t.on("disconnect",(e=>{"io server disconnect"===e&&t.connect()})),t})(a),h=Vi(c),f=ct(),p={version:`${d}`,apiKey:e,log:i,cache:{data:{}},http:l,ws:u,mqtt:h,emitter:f,sessionState:"notLoggedIn",accessTokenExpiryWatcher:Ta,sessionHandler:undefined,getFeedSettings:Wi,use:()=>Ce(p)};try{return we()}catch(e){Ce(p)}return p},login:Ea,logout:ba,isConnected:()=>{var e,t;const n=we();return n.log("client/api/isConnected",n),!!(n.userId&&(null===(t=String(null===(e=n.http.defaults.headers.common)||void 0===e?void 0:e.Authorization))||void 0===t?void 0:t.length)&&n.ws.connected)},getFeedSettings:Wi,renewal:Ia,markerSync:xa,onConnectionError:_a,onClientDisconnected:e=>_a((({code:t})=>{800211===t&&e()})),onClientBanned:ka,onSessionStateChange:e=>{const t=we();return lt(t,"client/onSessionStateChange","sessionStateChange",e)},getTotalUnreadCount:e=>{const{_id:t}=ht();if(!t)throw new ge("The _id has not been defined in ActiveUser",8e5,"error");return Ua(t,e,"userId",ja,[Na],(e=>{var t;return null!==(t=null==e?void 0:e.unreadCount)&&void 0!==t?t:0}),((e,t)=>(null==e?void 0:e.unreadCount)!==(null==t?void 0:t.unreadCount)))},getMarkerSyncEvents:()=>wc,setMarkerSyncEvents:Cc,pushMarkerSyncEvent:_c,markerSyncTrigger:kc,startUnreadSync:()=>{_c("start syncing"),yc||(yc=((e,t)=>{const n=setInterval(e,t);return()=>clearInterval(n)})((()=>kc(xa)),2e3)),Sc()},stopUnreadSyncing:()=>{null==yc||yc(),yc=void 0,Cc([]),vc.forEach((e=>e())),vc=[]}});const Ec=async e=>{const t=we();let n={};if(e){const{token:t,limit:r}=e;n={limit:r,token:t}}t.log("user/queryBlockedUsers");const{data:r}=await t.http.get("/api/v4/me/user-blocks",{params:n}),{paging:o}=r,s=Zi(r,["paging"]),{users:i}=s,a=t.cache&&Date.now();if(t.cache){Xi(s,{cachedAt:a});qe(["blockedUsers","query",n],{users:i.map(ce("user")),paging:o})}const{next:c,previous:l,total:u}=o,d=Y(c);return{data:i,prevPage:Y(l),nextPage:d,total:u,cachedAt:a}};Ec.locally=(e={})=>{var t,n,r;const o=we();if(o.log("user/queryBlockedUsers.locally"),!o.cache)return;let s={};if(e){const{token:t,limit:n}=e;s={token:t,limit:n}}const i=["blockedUsers","query",s],{data:a,cachedAt:c}=null!==(t=Le(i))&&void 0!==t?t:{},l=null!==(n=null==a?void 0:a.users.map((e=>Le(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[],u=Y(null==a?void 0:a.paging.next),d=Y(null==a?void 0:a.paging.previous);return l.length>0&&l.length===(null===(r=null==a?void 0:a.users)||void 0===r?void 0:r.length)?{data:l,nextPage:u,prevPage:d,total:null==a?void 0:a.paging.total,cachedAt:c}:void 0};const Ic=(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getBlockedUsers(tmpid: ${s}) > listen`);const{limit:i,token:a}=e,c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["blockedUsers","collection",{}],g=(e=!1)=>{var n,r;const o=null===(n=Le(d))||void 0===n?void 0:n.data,s=null!==(r=null==o?void 0:o.data)&&void 0!==r?r:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(Ec,{limit:c,token:J(e||null==o?void 0:o.params.page,"afterbeforeraw")});se(i,(({data:e,loading:n,error:r,nextPage:o,total:i})=>{const a={loading:n,error:r,params:{page:o,total:i},data:s};e&&(a.data=[...new Set([...s,...e.map(ce("user"))])]),qe(d,a),(e=>{var n,r;const o=null!==(n=e.data.map((e=>Le(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[];t({onNextPage:g,data:o,hasNextPage:!!(null===(r=e.params)||void 0===r?void 0:r.page),loading:e.loading,error:e.error})})(a)}),oe(l,y))};return u.push((()=>{})),g(!0),()=>{r(`getCategories(tmpid: ${s}) > dispose`),u.forEach((e=>e())),He(d)}},Oc=(e,t)=>{const n=we();return lt(n,e,e,(e=>{var r,o;if(n.cache){Xi(e);[...null!==(r=De(["followers","query"]))&&void 0!==r?r:[],...null!==(o=De(["followings","query"]))&&void 0!==o?o:[]].filter((({key:t})=>t[2].userId===e.follows[0].from||t[2].userId===e.follows[0].to)).forEach((({key:e,data:t})=>ze(e,t,{cachedAt:-1}))),t(e.follows[0])}else t(e.follows[0])}))},Tc=e=>Oc("follow.created",e),xc=e=>Oc("follow.unfollowed",e),Rc=e=>Oc("follow.followerDeleted",e),Pc=e=>Oc("follow.requested",e),Mc=e=>Oc("follow.requestCanceled",e),jc=e=>Oc("follow.accepted",e),Fc=e=>Oc("follow.requestDeclined",e),Nc=async e=>{var t,n;const r=we();r.log("follow/getFollowInfo",e);const{data:o}=await r.http.get(r.userId===e?"/api/v4/me/followInfo":`/api/v5/users/${e}/followInfo`),s=r.cache&&Date.now(),i="follows"in o?Object.assign(Object.assign({},o.followCounts[0]),{status:null===(n=null===(t=o.follows)||void 0===t?void 0:t[0])||void 0===n?void 0:n.status}):o.followCounts[0];return r.cache&&qe(["followInfo","get",e],i,{cachedAt:s}),{data:i,cachedAt:s}};Nc.locally=e=>{const t=we();if(t.log("follow/getFollowInfo.locally",e),!t.cache)return;const n=Le(["followInfo","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Bc=e=>{const t=async t=>{const[{data:n},{data:r}]=await Promise.all([Nc(t.from),Nc(t.to)]);e(n),e(r)},n=[Oc("follow.created",t),Oc("follow.requested",t),Oc("follow.accepted",t),Oc("follow.unfollowed",t),Oc("follow.requestCanceled",t),Oc("follow.requestDeclined",t),Oc("follow.followerDeleted",t)];return()=>{n.forEach((e=>e()))}},Uc=async(e,t)=>{const n=we();n.log(`follow/queryF${e.substring(1)}`,t);const{userId:r,page:o}=t,s=Zi(t,["userId","page"]),{data:i}=await n.http.get(n.userId===r?`/api/v4/me/${e}`:`/api/v4/users/${r}/${e}`,{params:Object.assign(Object.assign({},s),{token:J(o,"afterbeforeraw")})}),{paging:a}=i,c=Zi(i,["paging"]),{follows:l}=c,u=n.cache&&Date.now();if(n.cache){Xi(c,{cachedAt:u});const t=["follow","query",Object.assign(Object.assign({},s),{userId:r,options:Object.assign({},o),type:e})];qe(t,{follows:l.map(ce("follow")),paging:a})}const d=Y(a.next);return{data:l,cachedAt:u,prevPage:Y(a.previous),nextPage:d}};Uc.locally=(e,t)=>{var n,r;const o=we();if(o.log(`follow/queryF${e.substring(1)}.locally`,t),!o.cache)return;const{page:s}=t,i=Zi(t,["page"]),a=["follow","query",Object.assign(Object.assign({},i),{options:Object.assign({},s),type:e})],{data:c,cachedAt:l}=null!==(n=Le(a))&&void 0!==n?n:{};if(!(null==c?void 0:c.follows.length))return;const u=c.follows.map((e=>Le(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)),d=Y(null==c?void 0:c.paging.previous),h=Y(null==c?void 0:c.paging.next);return u.length===(null===(r=null==c?void 0:c.follows)||void 0===r?void 0:r.length)?{data:u,cachedAt:l,prevPage:d,nextPage:h}:void 0};const Dc=async e=>Uc("followers",e);Dc.locally=e=>Uc.locally("followers",e);const Lc=async e=>Uc("following",e);Lc.locally=e=>Uc.locally("following",e);var qc=Object.freeze({__proto__:null,blockUser:async e=>{const t=we();t.log("user/blockUser",e);const{data:n}=await t.http.post(`/api/v4/me/user-blocks/${e}`),r=t.cache&&Date.now(),{follows:o,followCounts:s}=n,i={follows:o};return t.cache&&(Xi(i,{cachedAt:r}),ze(["followInfo","get",e],s[0],{cachedAt:r})),ut("follow.unfollowed",i),n},unBlockUser:async e=>{const t=we();t.log("user/unBlockUser",e);const{data:n}=await t.http.delete(`/api/v4/me/user-blocks/${e}`),r=t.cache&&Date.now(),{follows:o,followCounts:s}=n,i={follows:o};return t.cache&&(Xi(i,{cachedAt:r}),ze(["followInfo","get",e],s[0],{cachedAt:r})),ut("follow.created",i),n},getBlockedUsers:(e,t,n)=>(console.log("Deprecation Notice: UserRepository.Relationship.getBlockedUsers will be deprecated on 9th June 2023, please use UserRepository.getBlockedUsers instead."),Ic(e,t,n)),follow:async e=>{const t=we();t.log("follow/follow",e);const{data:n}=await t.http.post(`/api/v4/me/following/${e}`),r=t.cache&&Date.now();return t.cache&&Xi(n,{cachedAt:r}),ut("accepted"===n.follows[0].status?"follow.created":"follow.requested",n),{data:n.follows[0],cachedAt:r}},unfollow:async e=>{const t=we();t.log("follow/unfollow",e);const{data:n}=await t.http.delete(`/api/v4/me/following/${e}`);return t.cache&&Xi(n),ut("follow.unfollowed",n),!0},acceptFollower:async e=>{const t=we();t.log("follow/acceptFollower",e);const{data:n}=await t.http.post(`/api/v4/me/followers/${e}`);return t.cache&&Xi(n),ut("follow.accepted",n),!0},declineFollower:async e=>{const t=we();t.log("follow/declineFollower",e);const{data:n}=await t.http.delete(`/api/v4/me/followers/${e}`);return t.cache&&Xi(n),ut("follow.requestDeclined",n),!0},onUserFollowed:Tc,onUserUnfollowed:xc,onFollowerDeleted:Rc,onFollowerRequested:Pc,onFollowRequestCanceled:Mc,onFollowRequestAccepted:jc,onFollowRequestDeclined:Fc,onFollowInfoUpdated:Bc,observeFollowInfo:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observeFollowInfo(tmpid: ${o}) > listen`);const s=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},i=[];return i.push(Bc((t=>((t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.userId)===e&&s(t,n)})({data:t,loading:!1,origin:"event"},"onUpdate")))),se(re(Nc,e),(e=>(e.data||e.error)&&s(e,"onFetch")),oe(n)),()=>{r(`observeFollowInfo(tmpid: ${o}) > dispose`),i.forEach((e=>e()))}},observeFollowers:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeFollowers(tmpid: ${r}) > listen`);const o=[],s=(n,r)=>{var o,s;if(n.from===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(s=t[r])||void 0===s||s.call(t,n)}};return o.push(Pc((e=>s(e,"onRequested"))),jc((e=>s(e,"onAccepted"))),Fc((e=>s(e,"onDeclined"))),Mc((e=>s(e,"onCanceled"))),Tc((e=>s(e,"onFollowed"))),xc((e=>s(e,"onUnfollowed"))),Rc((e=>s(e,"onDeleted")))),()=>{n(`observeFollowers(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},observeFollowings:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeFollowings(tmpid: ${r}) > listen`);const o=[],s=(n,r)=>{var o,s;if(n.to===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(s=t[r])||void 0===s||s.call(t,n)}};return o.push(Pc((e=>s(e,"onRequested"))),jc((e=>s(e,"onAccepted"))),Fc((e=>s(e,"onDeclined"))),Mc((e=>s(e,"onCanceled"))),Tc((e=>s(e,"onFollowed"))),xc((e=>s(e,"onUnfollowed"))),Rc((e=>s(e,"onDeleted")))),()=>{n(`observeFollowings(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},getFollowers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const s=Date.now();r(`getFollowers(tmpid: ${s}) > listen`);const{limit:i}=e,a=Zi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["follow","collection",{userId:e.userId,type:"follower"}],p=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.status&&"all"!==e.status&&(s=Ve(s,"status",e.status)),t({onNextPage:m,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},g=t=>n=>{var r;const o=null===(r=Le(d))||void 0===r?void 0:r.data;e.userId===n.to&&o&&(["onDeclined","onCanceled","onUnfollowed","onDeleted"].includes(t)?o.data=o.data.filter((e=>e!==ce("follow")(n))):["onRequested","onAccepted","onFollowed"].includes(t)&&(o.data=[...new Set([ce("follow")(n),...o.data])]),qe(d,o),p(o))},m=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re(Dc,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:i};e&&(o.data=[...new Set([...i,...e.map(ce("follow"))])]),qe(d,o),p(o)}),oe(l))};return u.push(Pc(g("onRequested")),jc(g("onAccepted")),Fc(g("onDeclined")),Mc(g("onCanceled")),Tc(g("onFollowed")),xc(g("onUnfollowed")),Rc(g("onDeleted"))),m(!0),()=>{r(`getFollowers(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},getFollowings:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const s=Date.now();r(`getFollowings(tmpid: ${s}) > listen`);const{limit:i}=e,a=Zi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["follow","collection",{userId:e.userId,type:"following"}],p=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.status&&"all"!==e.status&&(s=Ve(s,"status",e.status)),t({onNextPage:m,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},g=t=>n=>{var r;const o=null===(r=Le(d))||void 0===r?void 0:r.data;e.userId===n.from&&o&&(["onDeclined","onCanceled","onUnfollowed","onDeleted"].includes(t)?o.data=o.data.filter((e=>e!==ce("follow")(n))):["onRequested","onAccepted","onFollowed"].includes(t)&&(o.data=[...new Set([ce("follow")(n),...o.data])]),qe(d,o),p(o))},m=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re(Lc,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:i};e&&(o.data=[...new Set([...i,...e.map(ce("follow"))])]),qe(d,o),p(o)}),oe(l))};return u.push(Pc(g("onRequested")),jc(g("onAccepted")),Fc(g("onDeclined")),Mc(g("onCanceled")),Tc(g("onFollowed")),xc(g("onUnfollowed")),Rc(g("onDeleted"))),m(!0),()=>{r(`getFollowings(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},getFollowInfo:(e,t)=>Ua(e,t,"userId",Nc,[Bc])});const $c=async e=>{const t=we();t.log("user/getUsers",e);const n=e.map((e=>encodeURIComponent(e))),{data:r}=await t.http.get("/api/v3/users/list",{params:{userIds:n}}),o=t.cache&&Date.now();return t.cache&&Xi(r,{cachedAt:o}),ut("user.fetched",r),{data:r.users,cachedAt:o}};$c.locally=e=>{var t;const n=we();if(n.log("user/getUsers.locally",e),!n.cache)return;const r=e.map((e=>Le(["user","get",e]))).filter(Boolean),o=r.map((({data:e})=>e)),s=null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0];return(null==r?void 0:r.length)<e.length?void 0:{data:o,cachedAt:s.cachedAt}};const zc=e=>ya("user.updated",e),Hc=e=>ya("user.flagged",e),Vc=e=>ya("user.unflagged",e),Wc=e=>ya("user.flagCleared",e),Kc=e=>ya("user.fetched",e),Qc=async e=>{const t=we();let n;t.log("user/getUser",e),oc("user",e);try{n=(await t.http.get(`/api/v3/users/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&sc("user",e),t}const r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r});const{users:o}=n;return ut("user.fetched",n),{data:o.find((t=>t.userId===e)),cachedAt:r}};Qc.locally=e=>{const t=we();return t.log("user/getUser.locally",e),t.cache&&Le(["user","get",e])};const Jc=async(e={})=>{const t=we();t.log("user/queryUsers",e);const{page:n={limit:10},displayName:r,filter:o="all",sortBy:s="displayName"}=e,i=Zi(e,["page","displayName","filter","sortBy"]),{data:a}=await t.http.get("/api/v3/users",{params:Object.assign(Object.assign({},i),{keyword:r,filter:o,sortBy:s,options:{token:J(n,"skiplimit")}})}),{paging:c}=a,l=Zi(a,["paging"]),{users:u}=l,d=t.cache&&Date.now();if(t.cache){Xi(l,{cachedAt:d});const t=["user","query",Object.assign(Object.assign({},e),{options:Object.assign({},n)})];qe(t,{users:u.map(ce("user")),paging:c})}ut("user.fetched",a);return{data:u,cachedAt:d,prevPage:G(c.previous),nextPage:G(c.next)}};Jc.locally=(e={})=>{var t,n,r;const o=we();if(o.log("user/queryUsers.locally",e),!o.cache)return;const{page:s={limit:10}}=null!=e?e:{},i=["user","query",Object.assign(Object.assign({},e),{options:Object.assign({},s)})],{data:a,cachedAt:c}=null!==(t=Le(i))&&void 0!==t?t:{},l=null!==(n=null==a?void 0:a.users.map((e=>Le(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[],u=G(null==a?void 0:a.paging.previous),d=G(null==a?void 0:a.paging.next);return l.length>0&&l.length===(null===(r=null==a?void 0:a.users)||void 0===r?void 0:r.length)?{data:l,cachedAt:c,prevPage:u,nextPage:d}:void 0};const Gc=(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`liveUsers(tmpid: ${s}) > listen`);const{limit:i}=e,a=Zi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["user","collection",{}],g=t=>{let n=Ve(t,"displayName",e.displayName);switch(e.sortBy){case"firstCreated":n=n.sort(et);break;case"lastCreated":n=n.sort(tt);break;default:n=n.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Xe)}return n},m=(e,n=!1)=>{var r,o;const s=null!==(r=e.data.map((e=>Le(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];t({onNextPage:v,data:n?g(s):s,hasNextPage:!!(null===(o=e.params)||void 0===o?void 0:o.page),loading:e.loading,error:e.error})},y=e=>e=>{var t;const n=null===(t=Le(d))||void 0===t?void 0:t.data;n&&(n.data=[...new Set([e.userId,...n.data])],qe(d,n),m(n,!0))},v=(e=!1)=>{var t,n,r;const o=null===(t=Le(d))||void 0===t?void 0:t.data,s=null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(Jc,Object.assign(Object.assign({},a),{page:null!==(r=e||null==o?void 0:o.params.page)&&void 0!==r?r:{limit:c}}));se(i,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(ce("user"))])]),qe(d,o),m(o)}),oe(l))};return u.push(zc(y()),va(y()),Hc(y()),Vc(y()),Wc(y())),v(!0),()=>{r(`liveUsers(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}};var Yc=Object.freeze({__proto__:null,Relationship:qc,getUserByIds:$c,updateUser:async(e,t)=>{const n=we();n.log("user/updateUser",e,t);const{data:r}=await n.http.put("/api/v3/users/",Object.assign(Object.assign({userId:e},t),{createNewUserWhenNotFound:!1})),o=n.cache&&Date.now();n.cache&&Xi(r,{cachedAt:o});const{users:s}=r;return ut("user.updated",r),{data:s.find((t=>t.userId===e)),cachedAt:o}},flagUser:async e=>{const t=we();t.log("user/flagUser",e);const{data:n}=await t.http.post(`api/v4/me/flags/${encodeURIComponent(e)}`);return t.cache&&Xi(n),ut("user.flagged",n),!!n},unflagUser:async e=>{const t=we();t.log("user/unflag",e);const{data:n}=await t.http.delete(`/api/v4/me/flags/${encodeURIComponent(e)}`);return t.cache&&Xi(n),ut("user.unflagged",n),!!n},isUserFlaggedByMe:async e=>{var t,n;const r=we();r.log("user/isUserFlaggedByMe",e);const{result:o,isFlagByMe:s}=null!==(t=await Di(r,"user.isFlagByMe",{userId:e}))&&void 0!==t?t:{};return null!==(n=null!=o?o:s)&&void 0!==n&&n},onUserUpdated:zc,onUserDeleted:va,onUserFlagged:Hc,onUserUnflagged:Vc,onUserFlagCleared:Wc,getUser:(e,t)=>Ua(e,t,"userId",Qc,[Kc,zc,va,Hc,Vc,Wc]),getUsers:Gc,observeUser:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeUser(tmpid: ${r}) > listen`);const o=(n,r)=>{var o,s,i;if((null===(o=n.data)||void 0===o?void 0:o.userId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(s=t.onEvent)||void 0===s||s.call(t,r,n)),null===(i=t[r])||void 0===i||i.call(t,n)}},s=[];return s.push(zc((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),va((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),Hc((e=>o({data:e,loading:!1,origin:"event"},"onFlagged"))),Vc((e=>o({data:e,loading:!1,origin:"event"},"onUnflagged"))),Wc((e=>o({data:e,loading:!1,origin:"event"},"onFlagCleared")))),se(re(Qc,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeUser(tmpid: ${r}) > dispose`),s.forEach((e=>e()))}},getBlockedUsers:Ic,searchUserByDisplayName:(e,t,n)=>Gc(Object.assign(Object.assign({},e),{filter:"all"}),t,n)});const Xc=async e=>{const t=we();t.log("file/getFile",e);const{data:n}=await t.http.get(`/api/v3/files/${e}`),r=t.cache&&Date.now();return t.cache&&Xi({files:[n]},{cachedAt:r}),{data:n,cachedAt:r}};Xc.locally=e=>{const t=we();if(t.log("file/getFile.locally",e),!t.cache)return;const n=Le(["file","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};var Zc=Object.freeze({__proto__:null,getFile:Xc,uploadFile:async(e,t)=>{const n=we();if(n.log("file/uploadFile",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");const r="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:o}=await n.http.post("/api/v4/files",e,{headers:r,onUploadProgress({loaded:e,total:n=100}){t&&t(Math.round(100*e/n))}}),s=n.cache&&Date.now();return n.cache&&Xi({files:o},{cachedAt:s}),{data:o,cachedAt:s}},deleteFile:async e=>{const t=we();return t.log("file/deleteFile",e),await t.http.delete(`/api/v3/files/${e}`),He(["file","get",e],!0),{success:!0}},fileUrlWithSize:(e,t)=>`${e}?size=${t}`,uploadVideo:async(e,t,n)=>{const r=we();if(r.log("file/uploadVideo",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");t&&e.append("feedType",t);const o="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:s}=await r.http.post("/api/v4/videos",e,{headers:o,onUploadProgress({loaded:e,total:t=100}){n&&n(Math.round(100*e/t))}}),i=r.cache&&Date.now();return r.cache&&Xi({files:s},{cachedAt:i}),{data:s,cachedAt:i}},uploadImage:async(e,t)=>{const n=we();if(n.log("file/uploadImage",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");const r="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:o}=await n.http.post("/api/v4/images",e,{headers:r,onUploadProgress({loaded:e,total:n=100}){t&&t(Math.round(100*e/n))}}),s=n.cache&&Date.now();return n.cache&&Xi({files:o},{cachedAt:s}),{data:o,cachedAt:s}},createImage:async(e,t)=>{const n=we();if(n.log("file/createImage",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");const r="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:o}=await n.http.post("/api/v4/images",e,{headers:r,onUploadProgress({loaded:e,total:n=100}){t&&t(Math.round(100*e/n))}}),s=n.cache&&Date.now();return n.cache&&Xi({files:o},{cachedAt:s}),{data:o,cachedAt:s}},createFile:async(e,t)=>{const n=we();if(n.log("file/createFile",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");const r="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:o}=await n.http.post("/api/v4/files",e,{headers:r,onUploadProgress({loaded:e,total:n=100}){t&&t(Math.round(100*e/n))}}),s=n.cache&&Date.now();return n.cache&&Xi({files:o},{cachedAt:s}),{data:o,cachedAt:s}},createVideo:async(e,t,n)=>{const r=we();if(r.log("file/createVideo",e),!e.getAll("files").length)throw new Error("The formData object must have a `files` key.");t&&e.append("feedType",t);const o="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:s}=await r.http.post("/api/v4/videos",e,{headers:o,onUploadProgress({loaded:e,total:t=100}){n&&n(Math.round(100*e/t))}}),i=r.cache&&Date.now();return r.cache&&Xi({files:s},{cachedAt:i}),{data:s,cachedAt:i}},observeFile:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeFile(tmpid: ${r}) > listen`);return se(re(Xc,e),(n=>n.data&&((n,r)=>{var o,s,i;if((null===(o=n.data)||void 0===o?void 0:o.fileId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(s=t.onEvent)||void 0===s||s.call(t,r,n)),null===(i=t[r])||void 0===i||i.call(t,n)}})(n,"onFetch"))),()=>{n(`observeFile(tmpid: ${r}) > dispose`)}}});const el=async e=>{const t=we();t.log("role/queryRoles",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,sortBy:s}=n,i=Zi(n,["page","displayName","sortBy"]),{data:a}=await t.http.get("/api/v3/roles",{params:Object.assign(Object.assign({},i),{keyword:o,sortBy:s,options:{token:J(r,"skiplimit")}})}),{paging:c}=a,l=Zi(a,["paging"]),{roles:u}=l,d=t.cache&&Date.now();t.cache&&Xi(l,{cachedAt:d});const h=G(c.next);return{data:u,cachedAt:d,prevPage:G(c.previous),nextPage:h}};el.locally=e=>{we().log("role/queryRoles.locally",e)};const tl=async e=>{const t=we();t.log("role/getRole",e);const{data:n}=await t.http.get(`/api/v3/roles/${e}`),r=t.cache&&Date.now();return t.cache&&Xi({roles:n},{cachedAt:r}),{data:n.find((t=>t.roleId===e)),cachedAt:r}};tl.locally=e=>{const t=we();if(t.log("role/getRole.locally",e),!t.cache)return;const n=Le(["role","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const nl=(e,t)=>{"message"===e?ut("local.message.updated",{messages:[t]}):"post"===e?ut("post.updated",{posts:[t]}):"comment"===e&&ut("comment.updated",{comments:[t]})},rl=async(e,t=!1)=>{const n=we();let r;n.log("message/getMessage",e),t||console.log("getMessage will be deprecated on 15th November 2022, please use liveMessage instead."),oc("message",e);try{const{data:t}=await n.http.get(`/api/v5/messages/${encodeURIComponent(e)}`);r=await qa(t)}catch(t){throw _(null==t?void 0:t.code)&&sc("message",e),t}const o=n.cache&&Date.now();n.cache&&Xi(r,{cachedAt:o});const{messages:s}=r;return ut("local.message.fetched",{messages:s}),{data:s.find((t=>t.messageId===e)),cachedAt:o}};rl.locally=e=>{const t=we();if(t.log("message/getMessage.locally",e),!t.cache)return;const n=Le(["message","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const ol=async e=>{const t=we();let n;t.log("post/getPost",e),oc("post",e);try{n=(await t.http.get(`/api/v3/posts/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&sc("post",e),t}const r=ta(n,"communityUsers"),o=t.cache&&Date.now();t.cache&&Xi(r,{cachedAt:o});const{posts:s}=r;return{data:s.find((t=>t.postId===e)),cachedAt:o}};ol.locally=e=>{const t=we();if(t.log("post/getPost.locally",e),!t.cache)return;const n=Le(["post","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const sl=async e=>{const t=we();let n;t.log("comment/getComment",e),oc("comment",e);try{n=(await t.http.get(`/api/v3/comments/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&sc("comment",e),t}const r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r});const{comments:o}=n;return{data:o.find((t=>t.commentId===e)),cachedAt:r}};sl.locally=e=>{const t=we();if(t.log("comment/getComment.locally",e),!t.cache)return;const n=Le(["comment","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const il=(e,t)=>{var n,r;if(we().userId!==t.reactor.userId)return;let o,s;if("post.addReaction"===e||"post.removeReaction"===e){const e=t.posts[0];s=null===(n=Le(["post","get",e.postId]))||void 0===n?void 0:n.data,o=e}else{const e=t.comments[0];s=null===(r=Le(["comment","get",e.commentId]))||void 0===r?void 0:r.data,o=e}if(s&&s.myReactions)if("post.addReaction"===e||"comment.addReaction"===e){if(s.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:[...s.myReactions,t.reactor.reactionName]})}else{if(!s.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:s.myReactions.filter((e=>e!==t.reactor.reactionName))})}},al=async(e,t,n)=>{const r=we();if(r.log("reaction/createReaction",{referenceId:t,referenceType:e,reactionName:n}),await r.http.post("/api/v2/reactions",{referenceId:t,referenceType:e,reactionName:n,referenceVersion:"message"===e?5:void 0}),r.cache){const n=Le([e,"get",t]);(null==n?void 0:n.data)&&qe([e,"get",t],n.data,{cachedAt:Date.now()})}return!0};al.optimistically=(e,t,n)=>{var r,o,s,i,a;const c=we();if(c.log("reaction/createReaction.optimistically",{referenceId:t,referenceType:e,reactionName:n}),!c.cache)return;const l=Le([e,"get",t]);if(!(null==l?void 0:l.data)||(null===(r=l.data.myReactions)||void 0===r?void 0:r.includes(n)))return;const u=Object.assign(Object.assign({},l.data),{reactionsCount:l.data.reactionsCount+1,myReactions:[...null!==(o=l.data.myReactions)&&void 0!==o?o:[],n],reactions:Object.assign(Object.assign({},l.data.reactions),{[n]:(null!==(s=l.data.reactions[n])&&void 0!==s?s:0)+1})});return ze([e,"get",t],u,{cachedAt:-5}),nl(e,u),null!==(a=null===(i=null==u?void 0:u.myReactions)||void 0===i?void 0:i.includes(n))&&void 0!==a&&a};const cl=async(e,t,n)=>{const r=we();if(r.log("reaction/removeReaction",{referenceId:t,referenceType:e,reactionName:n}),await r.http.delete("/api/v2/reactions",{data:{referenceId:t,referenceType:e,reactionName:n,referenceVersion:"message"===e?5:void 0}}),r.cache){const n=Le([e,"get",t]);(null==n?void 0:n.data)&&qe([e,"get",t],n.data,{cachedAt:Date.now()})}return!0};cl.optimistically=(e,t,n)=>{var r,o,s,i,a;const c=we();if(c.log("reaction/removeReaction.optimistically",{referenceId:t,referenceType:e,reactionName:n}),!c.cache)return;const l=Le([e,"get",t]);if(!(null==l?void 0:l.data)||!(null===(r=l.data.myReactions)||void 0===r?void 0:r.includes(n)))return;const u=Object.assign(Object.assign({},l.data),{reactionsCount:Math.max(0,l.data.reactionsCount-1),myReactions:(null!==(o=l.data.myReactions)&&void 0!==o?o:[]).filter((e=>e!==n)),reactions:Object.assign(Object.assign({},l.data.reactions),{[n]:Math.max(0,(null!==(s=l.data.reactions[n])&&void 0!==s?s:0)-1)})});return ze([e,"get",t],u,{cachedAt:-5}),nl(e,u),null!==(a=!(null===(i=null==u?void 0:u.myReactions)||void 0===i?void 0:i.includes(n)))&&void 0!==a&&a};const ll=(e,t)=>{const n=we();return lt(n,e,e,(r=>{var o;if(n.cache){const{communities:n}=r,s=Zi(r,["communities"]),i=ta(s,"communityUsers");Xi(i),(null==n?void 0:n[0])&&!["post.updated"].includes(e)&&ut("community.updated",{communities:n,categories:[],communityUsers:[],feeds:[],files:[],users:[]});const a=Le(["post","get",r.posts[0].postId]);if(["post.created","post.approved","post.declined"].includes(e)){let t=null===(o=De(["post","query"]))||void 0===o?void 0:o.filter((({key:e})=>{var t;return(null===(t=e[2])||void 0===t?void 0:t.targetId)===a.data.targetId}));"post.declined"===e&&(t=null==t?void 0:t.filter((({key:e})=>{var t;return"reviewing"===(null===(t=e[2])||void 0===t?void 0:t.feedType)}))),null==t||t.map((({key:e,data:t})=>ze(e,t,{cachedAt:-1})))}t(a.data)}else t(r.posts[0])}))},ul=e=>ll("post.created",e),dl=e=>ll("post.updated",e),hl=e=>ll("post.deleted",e),fl=e=>ll("post.approved",e),pl=e=>ll("post.declined",e),gl=e=>ll("post.flagged",e),ml=e=>ll("post.unflagged",e),yl=e=>{const t=we();return lt(t,"post.addReaction","post.addReaction",(n=>{if(t.cache){il("post.addReaction",n);const t=Zi(n,["reactor"]);Xi(t);const r=Le(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},vl=e=>{const t=we();return lt(t,"post.removeReaction","post.removeReaction",(n=>{if(t.cache){il("post.removeReaction",n);const t=Zi(n,["reactor"]);Xi(t);const r=Le(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},bl=(e,t)=>{const n=we();return lt(n,e,e,(r=>{var o;if(n.cache){Xi(r);const n=Le(["comment","get",r.comments[0].commentId]);if(["comment.created"].includes(e)){const e=null===(o=De(["comment","query"]))||void 0===o?void 0:o.filter((({key:e})=>{var t;return(null===(t=e[2])||void 0===t?void 0:t.referenceId)===n.data.referenceId}));null==e||e.map((({key:e,data:t})=>ze(e,t,{cachedAt:-1})))}t(n.data)}else t(r.comments[0])}))},wl=e=>bl("comment.created",e),Cl=e=>bl("comment.updated",e),_l=e=>bl("comment.deleted",e),kl=e=>bl("comment.flagged",e),Sl=e=>bl("comment.unflagged",e),Al=e=>{const t=we();return lt(t,"comment.addReaction","comment.addReaction",(n=>{if(t.cache){il("comment.addReaction",n);const t=Zi(n,["reactor"]);Xi(t);const r=Le(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},El=e=>{const t=we();return lt(t,"comment.removeReaction","comment.removeReaction",(n=>{if(t.cache){il("comment.removeReaction",n);const t=Zi(n,["reactor"]);Xi(t);const r=Le(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},Il=(e,t,n)=>{const r=we(),o=(r,o,s)=>{r===e&&o===t&&n(s)};if("message"===e){const e=async e=>{const t=await qa(e);if(!t.messages[0].latestReaction)return;const n=t.messages[0].latestReaction,{eventName:r,referenceId:s,referenceType:i,userDisplayName:a}=n,c=Zi(n,["eventName","referenceId","referenceType","userDisplayName"]);"add"===r&&(Xi(t),Xi({reactions:[c]}),o("message",t.messages[0].messageId,c))};return lt(r,"reaction/onReactorAdded","message.updated",e)}if("post"===e){return lt(r,"post.addReaction","post.addReaction",(e=>{const{reactor:t}=e,n=Zi(e,["reactor"]);Xi(n),Xi({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return lt(r,"comment.addReaction","comment.addReaction",(e=>{const{reactor:t}=e,n=Zi(e,["reactor"]);Xi(n),Xi({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))},Ol=(e,t,n)=>{const r=we(),o=(r,o,s)=>{r===e&&o===t&&n(s)};if("message"===e){const e=async e=>{const t=await qa(e);if(!t.messages[0].latestReaction)return;const n=t.messages[0].latestReaction,{eventName:r,referenceId:s,referenceType:i}=n,a=Zi(n,["eventName","referenceId","referenceType"]);"remove"===r&&(Xi(t),Xi({reactions:[a]}),o("message",t.messages[0].messageId,a))};return lt(r,"reaction/onReactorRemoved","message.updated",e)}if("post"===e){return lt(r,"post.removeReaction","post.removeReaction",(e=>{const{reactor:t}=e,n=Zi(e,["reactor"]);Xi(n),Xi({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return lt(r,"comment.removeReaction","comment.removeReaction",(e=>{const{reactor:t}=e,n=Zi(e,["reactor"]);Xi(n),Xi({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))},Tl=async e=>{const t=we();t.log("reaction/queryReactions",e);const n=null!=e?e:{},{page:r={limit:10}}=n,o=Zi(n,["page"]),{data:s}=await t.http.get("/api/v3/reactions",{params:Object.assign(Object.assign({},o),{options:{token:J(r,"afterbeforeraw")}})}),{paging:i}=s,a=Zi(s,["paging"]),{reactions:c}=a;Xi(Object.assign(Object.assign({},a),{reactions:c[0].reactors}));const l=Y(i.next);return{data:c,prevPage:Y(i.previous),nextPage:l}};var xl=Object.freeze({__proto__:null,addReaction:al,removeReaction:cl,onReactionAdded:(e,t,n)=>{const r=r=>{ce(e)(r)===t&&n(r)};if("message"===e){const e=we(),t=async e=>{var t;const n=await qa(e),o=Le(["message","get",n.messages[0].messageId]),s=(null===(t=null==o?void 0:o.data)||void 0===t?void 0:t.reactionsCount)!==n.messages[0].reactionsCount;Xi(n),s&&r(n.messages[0])};return lt(e,"reaction/onReactionAdded","message.updated",t)}return"post"===e?yl(r):Al(r)},onReactionRemoved:(e,t,n)=>{const r=r=>{ce(e)(r)===t&&n(r)};if("message"===e){const e=we(),t=async e=>{var t;const n=await qa(e),o=Le(["message","get",n.messages[0].messageId]),s=(null===(t=null==o?void 0:o.data)||void 0===t?void 0:t.reactionsCount)!==n.messages[0].reactionsCount;Xi(n),s&&r(n.messages[0])};return lt(e,"reaction/onReactionRemoved","message.updated",t)}return"post"===e?vl(r):El(r)},onReactorAdded:Il,onReactorRemoved:Ol,getReactions:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const s=Date.now();r(`liveReactions(tmpid: ${s}) > listen`);const{limit:i}=e,a=Zi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["reaction","collection",{referenceId:e.referenceId,referenceType:e.referenceType}],p=e=>{var n,r;const o=null!==(n=e.data.map((e=>Le(["reaction","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[];t({onNextPage:m,data:o,hasNextPage:!!(null===(r=e.params)||void 0===r?void 0:r.page),loading:e.loading,error:e.error})},g=e=>t=>{var n;const r=null===(n=Le(d))||void 0===n?void 0:n.data;r&&("onAdded"===e?r.data=[...new Set([t.reactionId,...r.data])]:"onRemoved"===e&&(r.data=r.data.filter((e=>e!==t.reactionId))),qe(d,r),p(r))},m=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re(Tl,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:i};e&&(o.data=[...new Set([...i,...e[0].reactors.map(ce("reaction"))])]),qe(d,o),p(o)}),oe(l))};return u.push(Il(a.referenceType,a.referenceId,g("onAdded")),Ol(a.referenceType,a.referenceId,g("onRemoved"))),m(!0),()=>{r(`liveReactions(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}}}),Rl={post:{domainName:"posts",eventName:"v3/post.isflagbyme",primaryKey:"postId"},comment:{domainName:"comments",eventName:"v3/comment.isflagbyme",primaryKey:"commentId"},message:{domainName:"messages",eventName:"v3/message.isFlaggedByMe",primaryKey:"messageId"},user:{domainName:"users",eventName:"user.isFlagByMe",primaryKey:"userId"}};const Pl=async e=>{const t=we();t.log("channel/getChannelByIds",e);const n=e.map((e=>encodeURIComponent(e)));let r;try{r=(await t.http.get("/api/v3/channels/list",{params:{channelIds:n}})).data}catch(t){throw e.forEach((e=>{_(null==t?void 0:t.code)&&sc("channel",e)})),t}const o=await pa(r),s=t.cache&&Date.now();return t.cache&&Xi(o,{cachedAt:s}),{data:o.channels,cachedAt:s}};Pl.locally=e=>{var t;const n=we();if(n.log("channel/getChannelByIds.locally",e),!n.cache)return;const r=e.map((e=>Le(["channel","get",e]))).filter(Boolean);if((null==r?void 0:r.length)<e.length)return;return{data:r.map((({data:e})=>e)),cachedAt:(null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0]).cachedAt}};const Ml=async e=>{const t=we();let n;t.log("channel/getChannel",e),oc("channel",e);try{const{data:r}=await t.http.get(`/api/v3/channels/${encodeURIComponent(e)}`);n=await pa(r)}catch(t){throw _(null==t?void 0:t.code)&&sc("channel",e),t}const r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r});const{channels:o}=n;return{data:o.find((t=>t.channelId===e)),cachedAt:r}};Ml.locally=e=>{const t=we();if(t.log("channel/getChannel.locally",e),!t.cache)return;const n=Le(["channel","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const jl=e=>{const t=we();return lt(t,"onChannelCreated","channel.created",(async t=>{const n=await pa(t);Xi(n),e(n.channels[0])}))},Fl=e=>{const t=we(),n=[lt(t,"onChannelUpdated","channel.updated",(async t=>{const n=await pa(t);Xi(n),e(n.channels[0])})),lt(t,"onChannelUpdated","local.channel.updated",(t=>e(t.channels[0])))];return()=>{n.forEach((e=>e()))}},Nl=e=>{const t=we();return lt(t,"onChannelJoined","channel.joined",(async t=>{const n=await pa(t),{channels:r,channelUsers:o}=n;Xi(n),e(r[0],o[0])}))},Bl=e=>{const t=we();return lt(t,"onChannelLeft","channel.left",(async t=>{const n=await pa(t),{channels:r,channelUsers:o}=n;Xi(n),e(r[0],o[0])}))},Ul=e=>{const t=we();return lt(t,"onChannelMuted","channel.setMuted",(async t=>{const n=await pa(t);Xi(n),e(n.channels[0])}))},Dl=e=>{const t=we();return lt(t,"onChannelMemberAdded","channel.membersAdded",(async t=>{const n=await pa(t),{channels:r,channelUsers:o}=n;Xi(n),e(r[0],o.find((e=>"member"===e.membership)))}))},Ll=e=>{const t=we();return lt(t,"onChannelMemberRemoved","channel.membersRemoved",(async t=>{const n=await pa(t),{channels:r,channelUsers:o}=n;Xi(n),e(r[0],o[0])}))},ql=e=>{const t=we();return lt(t,"onChannelMemberUnbanned","channel.unbanned",(async t=>{const n=await pa(t),{channels:r,channelUsers:o}=n;Xi(n),e(r[0],o.find((e=>"none"===e.membership)))}))},$l=async e=>{const t=we();t.log("channel/queryChannels",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,membership:s}=n,i=Zi(n,["page","displayName","membership"]),{data:a}=await t.http.get("/api/v3/channels",{params:Object.assign(Object.assign({},i),{keyword:o,filter:s,options:{token:J(r,"skiplimit")}})}),{paging:c}=a,l=Zi(a,["paging"]),u=await pa(l),{channels:d}=u,h=t.cache&&Date.now();if(t.cache){Xi(u,{cachedAt:h});const e=["channel","query",Object.assign(Object.assign({},i),{options:Object.assign({},r)})];qe(e,{channels:d.map(ce("channel")),paging:c})}const f=G(c.next);return{data:d,cachedAt:h,prevPage:G(c.previous),nextPage:f}},zl=async e=>{const t=we();t.log("channel/queryChannelMembers",e);const n=null!=e?e:{},{page:r}=n,o=Zi(n,["page"]),{data:s}=await t.http.get(`/api/v4/channels/${encodeURIComponent(o.channelId)}/users`,{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:i}=s,a=Zi(s,["paging"]),c=await pa(a),{channelUsers:l}=c,u=t.cache&&Date.now();if(t.cache){Xi(c);const e=["channelUsers","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];qe(e,{channelUsers:l.map((({channelId:e,userId:t})=>ce("channelUsers")({channelId:e,userId:t}))),paging:i})}return{data:l,cachedAt:u,nextPage:G(i.next),prevPage:G(i.previous)}};zl.locally=e=>{var t,n;const r=we();if(r.log("channel/queryChannelMembers.locally",e),!r.cache)return;const{page:o}=e,s=Zi(e,["page"]),i=["channelUsers","query",Object.assign(Object.assign({},s),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Le(i))&&void 0!==t?t:{};if(!(null==a?void 0:a.channelUsers.length))return;const l=a.channelUsers.map((e=>Le(["channelUsers","get",e]))).filter(Boolean).map((({data:e})=>e)),u=G(null==a?void 0:a.paging.previous),d=G(null==a?void 0:a.paging.next);return l.length===(null===(n=null==a?void 0:a.channelUsers)||void 0===n?void 0:n.length)?{data:l,cachedAt:c,prevPage:u,nextPage:d}:void 0};const Hl=(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getMembers(tmpid: ${s}) > listen`);const{limit:i}=e,a=Zi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["channelUsers","collection",{channelId:e.channelId}],g=t=>{let n=We(t,"roles",e.roles);e.memberships&&(n=n.filter((t=>!(!e.memberships.includes("muted")||!t.isMuted)||e.memberships.includes(t.membership))));const r=e.sortBy?e.sortBy:"lastCreated";return n=n.sort("lastCreated"===r?tt:et),n},m=(e,n=!1)=>{var r,o;const s=null!==(r=e.data.map((e=>Le(["channelUsers","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];t({onNextPage:v,data:n?g(s):s,hasNextPage:!!(null===(o=e.params)||void 0===o?void 0:o.page),loading:e.loading,error:e.error})},y=t=>(t,n)=>{var r;if(e.channelId!==n.channelId)return;const o=null===(r=Le(d))||void 0===r?void 0:r.data;if(!o)return;const s=ce("channelUsers")({channelId:e.channelId,userId:n.userId});"none"===n.membership?o.data=o.data.filter((e=>e!==s)):o.data.includes(s)||(o.data=[s,...o.data]),qe(d,o),m(o,!0)},v=(e=!1)=>{var t,n,r;const o=null===(t=Le(d))||void 0===t?void 0:t.data,s=null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(zl,Object.assign(Object.assign({},a),{page:null!==(r=e||null==o?void 0:o.params.page)&&void 0!==r?r:{limit:c}}));se(i,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(ce("channelUsers"))])]),qe(d,o),m(o)}),oe(l))};return u.push(Nl(y()),Bl(y()),Dl(y()),Ll(y()),ma(y()),ql(y())),v(!0),()=>{r(`getMembers(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}};var Vl=Object.freeze({__proto__:null,addMembers:async(e,t)=>{const n=we();n.log("channel/addMembers",e,t);const{data:r}=await n.http.post(`/api/v3/channels/${encodeURIComponent(e)}/users`,{channelId:e,userIds:t});t.forEach((e=>ut("channel.membersAdded",Object.assign(Object.assign({},r),{channelUsers:r.channelUsers.filter((t=>t.userId===e))}))));const o=await pa(r);n.cache&&Xi(o);const{channelUsers:s}=o;return!!s.find((t=>t.channelId===e&&"member"===t.membership))},removeMembers:async(e,t)=>{const n=we();n.log("channel/removeMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/channels/${encodeURIComponent(e)}/users`,{data:{channelId:e,userIds:t}});t.forEach((e=>ut("channel.membersRemoved",Object.assign(Object.assign({},r),{channelUsers:r.channelUsers.filter((t=>t.userId===e))}))));const o=await pa(r);n.cache&&Xi(o);const{channelUsers:s}=o;return!!s.find((t=>t.channelId===e&&"member"!==t.membership))},getMembers:Hl,searchMembers:(e,t,n)=>Hl(e,t,n)});var Wl=Object.freeze({__proto__:null,addRole:async(e,t,n)=>{const r=we();r.log("channel/addRole",e,t,n);const{data:o}=await r.http.post(`/api/v3/channels/${encodeURIComponent(e)}/users/roles`,{channelId:e,role:t,userIds:n}),s=await pa(o);r.cache&&Xi(s);const{channelUsers:i}=s;return!!i.find((n=>n.channelId===e&&n.roles.includes(t)))},removeRole:async(e,t,n)=>{const r=we();r.log("channel/removeRole",e,t,n);const{data:o}=await r.http.delete(`/api/v3/channels/${encodeURIComponent(e)}/users/roles`,{data:{channelId:e,role:t,userIds:n}}),s=await pa(o);r.cache&&Xi(s);const{channelUsers:i}=s;return!!i.find((n=>n.channelId===e&&!n.roles.includes(t)))},banMembers:async(e,t)=>{const n=we();n.log("channel/banMembers",{userIds:t,channelId:e});const{data:r}=await n.http.put(`/api/v3/channels/${e}/users/ban`,{userIds:t}),o=await pa(r),{channelUsers:s}=o,i=n.cache&&Date.now();return n.cache&&Xi(o,{cachedAt:i}),{data:null==s?void 0:s.filter((e=>"banned"===e.membership)),cachedAt:i}},unbanMembers:async(e,t)=>{const n=we();n.log("channel/unbanMembers",{userIds:t,channelId:e});const{data:r}=await n.http.put(`/api/v3/channels/${encodeURIComponent(e)}/users/unban`,{userIds:t}),o=await pa(r),s=n.cache&&Date.now();n.cache&&Xi(o,{cachedAt:s});const{channelUsers:i}=o;return{data:null==i?void 0:i.filter((e=>"member"===e.membership)),cachedAt:s}}}),Kl=Object.freeze({__proto__:null,Membership:Vl,Moderation:Wl,getChannelByIds:Pl,createChannel:async e=>{const t=we();let n;t.log("user/createChannel",e),n="conversation"===(null==e?void 0:e.type)?await t.http.post("/api/v3/channels/conversation",Object.assign(Object.assign({},e),{isDistinct:!0})):await t.http.post("/api/v3/channels",e);const r=await pa(n.data),o=t.cache&&Date.now();t.cache&&Xi(r,{cachedAt:o});const{channels:s}=r;return{data:s[0],cachedAt:o}},updateChannel:async(e,t)=>{const n=we();n.log("channel/updateChannel",e,t);const{data:r}=await n.http.put(`/api/v3/channels/${encodeURIComponent(e)}`,t),o=await pa(r),s=n.cache&&Date.now();n.cache&&Xi(o,{cachedAt:s});const{channels:i}=o;return{data:i.find((t=>t.channelId===e)),cachedAt:s}},deleteChannel:async e=>{const t=we();t.log("channel/deleteChannel",e),await t.http.delete(`/api/v3/channels/${encodeURIComponent(e)}`);return(await Ml(e)).data},joinChannel:async e=>{const t=we();t.log("channel/joinChannel",e);const{data:n}=await t.http.post(`/api/v3/channels/${encodeURIComponent(e)}/join`),r=await pa(n);t.cache&&Xi(r);const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"===t.membership))},leaveChannel:async e=>{const t=we();t.log("channel/leaveChannel",e);const{data:n}=await t.http.delete(`/api/v3/channels/${encodeURIComponent(e)}/leave`),r=await pa(n);t.cache&&Xi(r);const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"!==t.membership))},muteChannel:async(e,t=-1)=>{const n=we();if(n.log("channel/muteChannel",e),-1!==t&&t<0)throw new ge("Mute Period can only be positive numbers or -1(mute forever)",800110,"error");const{data:r}=await n.http.put(`/api/v2/channel/${encodeURIComponent(e)}/mute`,{mutePeriod:t}),{success:o}=r;return o},unmuteChannel:async e=>{const t=we();t.log("channel/unmuteChannel",e);const{data:n}=await t.http.put(`/api/v2/channel/${encodeURIComponent(e)}/mute`,{mutePeriod:0}),{success:r}=n;return r},markAsRead:async e=>{const t=we();t.log("channel/markAsRead",e);const{data:n}=await t.http.put(`/api/v1/markers/channels/${e}/mark-read`),r=t.cache&&Date.now();return t.cache&&Xi(n,{cachedAt:r}),!0},onChannelCreated:jl,onChannelUpdated:Fl,onChannelDeleted:ga,onChannelJoined:Nl,onChannelLeft:Bl,onChannelMuted:Ul,onChannelMemberAdded:Dl,onChannelMemberRemoved:Ll,onChannelMemberBanned:ma,onChannelMemberUnbanned:ql,observeChannel:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeChannel(tmpid: ${r}) > listen`);const o=(n,r)=>{var o,s,i;if((null===(o=n.data)||void 0===o?void 0:o.channelId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(s=t.onEvent)||void 0===s||s.call(t,r,n)),null===(i=t[r])||void 0===i||i.call(t,n)}},s=[];return s.push(Fl((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),ga((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),Nl((e=>o({data:e,loading:!1,origin:"event"},"onJoin"))),Bl((e=>o({data:e,loading:!1,origin:"event"},"onLeft"))),Ul((e=>o({data:e,loading:!1,origin:"event"},"onMute"))),Dl((e=>o({data:e,loading:!1,origin:"event"},"onMemberAdded"))),Ll((e=>o({data:e,loading:!1,origin:"event"},"onMemberRemoved")))),se(re(Ml,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeChannel(tmpid: ${r}) > dispose`),s.forEach((e=>e()))}},observeChannels:e=>{const{log:t}=we(),n=Date.now();t(`observeChannels(tmpid: ${n}) > listen`);const r=[],o=(t,n)=>{var r,o;if(e instanceof Function)return e(t);null===(r=e.onEvent)||void 0===r||r.call(e,n,t),null===(o=e[n])||void 0===o||o.call(e,t)};return r.push(jl((e=>o(e,"onCreate"))),Fl((e=>o(e,"onUpdate"))),ga((e=>o(e,"onDelete"))),Nl((e=>o(e,"onJoin"))),Bl((e=>o(e,"onLeft"))),Ul((e=>o(e,"onMute"))),Dl((e=>o(e,"onMemberAdded"))),Ll((e=>o(e,"onMemberRemoved")))),()=>{t(`observeChannels(tmpid: ${n}) > dispose`),r.forEach((e=>e()))}},getChannel:(e,t)=>Ua(e,t,"channelId",Ml,[Fl,ga,Nl,Bl,Dl,Ll,ma,ql,Ul,()=>Ha((()=>null))]),getChannels:(e,t,n)=>{const{log:r,cache:o,userId:s}=we();o||console.log(p);const i=Date.now();r(`getChannels(tmpid: ${i}) > listen`);const{limit:a}=e,c=Zi(e,["limit"]),l=null!=a?a:h,{policy:u=f}=null!=n?n:{},d=[],g=["channel","collection",{}],m=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["channel","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(i=Ve(i,"isDeleted",e.isDeleted),i=Ve(i,"displayName",e.displayName),e.types&&(i=i.filter((t=>{var n;return null===(n=e.types)||void 0===n?void 0:n.includes(t.type)}))),e.tags&&(i=i.filter((t=>{var n;return null===(n=t.tags)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.tags)||void 0===n?void 0:n.includes(t)}))}))),e.excludeTags&&(i=i.filter((t=>{var n;return!(null===(n=t.tags)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.excludeTags)||void 0===n?void 0:n.includes(t)})))}))),e.membership&&s&&(i=Ke(i,e.membership,s)),e.sortBy){case"firstCreated":i=i.sort(et);break;case"lastCreated":i=i.sort(tt);break;case"displayName":i=i.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Xe);break;default:i=i.sort(nt)}t({onNextPage:b,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},v=e=>e=>{var t;const n=null===(t=Le(g))||void 0===t?void 0:t.data;n&&(n.data=[...new Set([e.channelId,...n.data])],qe(g,n),m(n))},b=(e=!1)=>{var t,n,r;const o=null===(t=Le(g))||void 0===t?void 0:t.data,s=null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re($l,Object.assign(Object.assign({},c),{page:null!==(r=e||null==o?void 0:o.params.page)&&void 0!==r?r:{limit:l}}));se(i,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(ce("channel"))])]),qe(g,o),m(o)}),oe(u,y))};return d.push(jl(v()),ga(v()),Fl(v()),Ul(v()),Nl(v()),Bl(v()),Dl(v()),Ll(v()),Ha((()=>null))),b(!0),He(g),()=>{r(`getChannels(tmpid: ${i}) > dispose`),d.forEach((e=>e()))}},MARKER_INCLUDED_CHANNEL_TYPE:da,isUnreadCountSupport:ha,convertFromRaw:fa,prepareChannelPayload:pa});const Ql=async e=>{const t=we();t.log("message/getMessages",e);const{data:n}=await t.http.get("/api/v5/messages/list",{params:{messageIds:e.map(encodeURIComponent)}}),r=await qa(n),o=t.cache&&Date.now();t.cache&&Xi(r,{cachedAt:o});const{messages:s}=r;return ut("local.message.fetched",{messages:s}),{data:s,cachedAt:o}};Ql.locally=e=>{var t;const n=we();if(n.log("message/getMessages.locally",e),!n.cache)return;const r=e.map((e=>Le(["message","get",e]))).filter(Boolean),o=r.map((({data:e})=>e)),s=null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0];return(null==r?void 0:r.length)<e.length?void 0:{data:o,cachedAt:s.cachedAt}};var Jl={},Gl={},Yl={};Object.defineProperty(Yl,"__esModule",{value:!0}),Yl.bytesToString=Yl.stringToBytes=Yl.NIL=Yl.X500=Yl.OID=Yl.URL=Yl.DNS=Yl.hexToByte=Yl.byteToHex=void 0;let Xl=[],Zl={};for(var eu=0;eu<256;eu++)Xl[eu]=(eu+256).toString(16).substr(1),Zl[Xl[eu]]=eu;Yl.byteToHex=Xl,Yl.hexToByte=Zl,Yl.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Yl.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",Yl.OID="6ba7b812-9dad-11d1-80b4-00c04fd430c8",Yl.X500="6ba7b814-9dad-11d1-80b4-00c04fd430c8",Yl.NIL="00000000-0000-0000-0000-000000000000";Yl.stringToBytes=e=>{e=unescape(encodeURIComponent(e));const t=new Uint8Array(e.length);for(let n=0;n<e.length;++n)t[n]=e.charCodeAt(n);return t};Yl.bytesToString=e=>{const t=new Uint8Array(e,0,e.byteLength);return String.fromCharCode.apply(null,Array.from(t))},Object.defineProperty(Gl,"__esModule",{value:!0}),Gl.parse=void 0;const tu=Yl;Gl.parse=(e,t,n)=>{let r=t&&n||0,o=0;for(t=t||[],e.toLowerCase().replace(/[0-9a-f]{2}/g,(e=>(o<16&&t&&(t[r+o++]=tu.hexToByte[e]),"")));o<16;)t[r+o++]=0;return t};var nu={};Object.defineProperty(nu,"__esModule",{value:!0}),nu.unparse=void 0;const ru=Yl;nu.unparse=(e,t)=>{let n=t||0,r=ru.byteToHex;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++]]};var ou={},su={};Object.defineProperty(su,"__esModule",{value:!0});su.default=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;var iu=_e&&_e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(ou,"__esModule",{value:!0}),ou.validate=void 0;const au=iu(su);ou.validate=e=>"string"==typeof e&&au.default.test(e);var cu={};Object.defineProperty(cu,"__esModule",{value:!0}),cu.version=void 0;const lu=ou;cu.version=e=>{if(!lu.validate(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)};var uu={},du={};Object.defineProperty(du,"__esModule",{value:!0}),du.stringify=void 0;const hu=ou,fu=[];for(let e=0;e<256;++e)fu.push((e+256).toString(16).substr(1));du.stringify=(e,t=0)=>{const n=(fu[e[t+0]]+fu[e[t+1]]+fu[e[t+2]]+fu[e[t+3]]+"-"+fu[e[t+4]]+fu[e[t+5]]+"-"+fu[e[t+6]]+fu[e[t+7]]+"-"+fu[e[t+8]]+fu[e[t+9]]+"-"+fu[e[t+10]]+fu[e[t+11]]+fu[e[t+12]]+fu[e[t+13]]+fu[e[t+14]]+fu[e[t+15]]).toLowerCase();if(!hu.validate(n))throw TypeError("Stringified UUID is invalid");return n};var pu={};Object.defineProperty(pu,"__esModule",{value:!0}),pu.rng=void 0;pu.rng=()=>{let e=new Array(16);for(let t=0;t<16;t++)e[t]=255&256*Math.random()+0;return e},Object.defineProperty(uu,"__esModule",{value:!0}),uu.v1=void 0;const gu=du,mu=pu;let yu,vu,bu=0,wu=0;uu.v1=(e,t,n=0)=>{let r=t&&n||0;const o=t||new Uint8Array(16);let s=e&&e.node?e.node:yu,i=e&&e.clockseq?e.clockseq:vu;if(null==s||null==i){const t=e&&e.random?e.random:e&&e.rng?e.rng():mu.rng();null==s&&(s=yu=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==i&&(i=vu=16383&(t[6]<<8|t[7]))}let a=e&&e.msecs?e.msecs:Date.now(),c=e&&e.nsecs?e.nsecs:wu+1;const l=a-bu+(c-wu)/1e4;if(l<0&&e&&!e.clockseq&&(i=i+1&16383),(l<0||a>bu)&&e&&!e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");bu=a,wu=c,vu=i,a+=122192928e5;const u=(1e4*(268435455&a)+c)%4294967296;o[r++]=u>>>24&255,o[r++]=u>>>16&255,o[r++]=u>>>8&255,o[r++]=255&u;const d=a/4294967296*1e4&268435455;o[r++]=d>>>8&255,o[r++]=255&d,o[r++]=d>>>24&15|16,o[r++]=d>>>16&255,o[r++]=i>>>8|128,o[r++]=255&i;for(let e=0;e<6;++e)o[r+e]=s[e];return t||gu.stringify(o)};var Cu={};Object.defineProperty(Cu,"__esModule",{value:!0}),Cu.v4=void 0;const _u=nu,ku=pu;Cu.v4=(e,t,n)=>{let r=t&&n||0,o=ku.rng();if(!e||e instanceof String||(e.random&&(o=e.random),e.rng&&(o=e.rng())),o[6]=15&o[6]|64,o[8]=63&o[8]|128,t)for(var s=0;s<16;s++)t[r+s]=o[s];return t||_u.unparse(o)};var Su={},Au={};Object.defineProperty(Au,"__esModule",{value:!0}),Au.v35=void 0;const Eu=du,Iu=Gl,Ou=Yl;Au.v35=(e,t,n)=>(e,r,o,s=0)=>{if("string"==typeof e&&(e=Ou.stringToBytes(e)),"string"==typeof r&&(r=Iu.parse(r)),r&&16!==r.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let i=new Uint8Array(16+e.length);if(i.set(r),i.set(e,r.length),i=Ou.stringToBytes(n(Ou.bytesToString(i))),i[6]=15&i[6]|t,i[8]=63&i[8]|128,o)for(let e=0;e<16;++e)o[s+e]=i[e];return o||Eu.stringify(i)};var Tu={};!function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.any_hmac_sha1=e.b64_hmac_sha1=e.hex_hmac_sha1=e.any_sha1=e.b64_sha1=e.hex_sha1=void 0;let t=0,n="";e.hex_sha1=e=>s(r(c(e))),e.default=e.hex_sha1;e.b64_sha1=e=>i(r(c(e)));e.any_sha1=(e,t)=>a(r(c(e)),t);e.hex_hmac_sha1=(e,t)=>s(o(c(e),c(t)));e.b64_hmac_sha1=(e,t)=>i(o(c(e),c(t)));e.any_hmac_sha1=(e,t,n)=>a(o(c(e),c(t)),n);const r=e=>u(d(l(e),8*e.length)),o=(e,t)=>{let n=l(e);n.length>16&&(n=d(n,8*e.length));let r=Array(16),o=Array(16);for(var s=0;s<16;s++)r[s]=909522486^n[s],o[s]=1549556828^n[s];var i=d(r.concat(l(t)),512+8*t.length);return u(d(o.concat(i),672))},s=e=>{for(var n,r=t?"0123456789ABCDEF":"0123456789abcdef",o="",s=0;s<e.length;s++)n=e.charCodeAt(s),o+=r.charAt(n>>>4&15)+r.charAt(15&n);return o},i=e=>{for(var t="",r=e.length,o=0;o<r;o+=3)for(var s=e.charCodeAt(o)<<16|(o+1<r?e.charCodeAt(o+1)<<8:0)|(o+2<r?e.charCodeAt(o+2):0),i=0;i<4;i++)8*o+6*i>8*e.length?t+=n:t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(s>>>6*(3-i)&63);return t},a=(e,t)=>{var n,r,o,s,i=t.length,a=[],c=Array(Math.ceil(e.length/2));for(n=0;n<c.length;n++)c[n]=e.charCodeAt(2*n)<<8|e.charCodeAt(2*n+1);for(;c.length>0;){for(s=[],o=0,n=0;n<c.length;n++)o=(o<<16)+c[n],o-=(r=Math.floor(o/i))*i,(s.length>0||r>0)&&(s[s.length]=r);a[a.length]=o,c=s}var l="";for(n=a.length-1;n>=0;n--)l+=t.charAt(a[n]);var u=Math.ceil(8*e.length/(Math.log(t.length)/Math.log(2)));for(n=l.length;n<u;n++)l=t[0]+l;return l},c=e=>{for(var t,n,r="",o=-1;++o<e.length;)t=e.charCodeAt(o),n=o+1<e.length?e.charCodeAt(o+1):0,t>=55296&&t<=56319&&n>=56320&&n<=57343&&(t=65536+((1023&t)<<10)+(1023&n),o++),t<=127?r+=String.fromCharCode(t):t<=2047?r+=String.fromCharCode(192|t>>>6&31,128|63&t):t<=65535?r+=String.fromCharCode(224|t>>>12&15,128|t>>>6&63,128|63&t):t<=2097151&&(r+=String.fromCharCode(240|t>>>18&7,128|t>>>12&63,128|t>>>6&63,128|63&t));return r},l=e=>{for(var t=Array(e.length>>2),n=0;n<t.length;n++)t[n]=0;for(n=0;n<8*e.length;n+=8)t[n>>5]|=(255&e.charCodeAt(n/8))<<24-n%32;return t},u=e=>{for(var t="",n=0;n<32*e.length;n+=8)t+=String.fromCharCode(e[n>>5]>>>24-n%32&255);return t},d=(e,t)=>{e[t>>5]|=128<<24-t%32,e[15+(t+64>>9<<4)]=t;for(var n=Array(80),r=1732584193,o=-271733879,s=-1732584194,i=271733878,a=-1009589776,c=0;c<e.length;c+=16){for(var l=r,u=o,d=s,m=i,y=a,v=0;v<80;v++){n[v]=v<16?e[c+v]:g(n[v-3]^n[v-8]^n[v-14]^n[v-16],1);let t=p(p(g(r,5),h(v,o,s,i)),p(p(a,n[v]),f(v)));a=i,i=s,s=g(o,30),o=r,r=t}r=p(r,l),o=p(o,u),s=p(s,d),i=p(i,m),a=p(a,y)}return[r,o,s,i,a]},h=(e,t,n,r)=>e<20?t&n|~t&r:e<40?t^n^r:e<60?t&n|t&r|n&r:t^n^r,f=e=>e<20?1518500249:e<40?1859775393:e<60?-1894007588:-899497514,p=(e,t)=>{var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n},g=(e,t)=>e<<t|e>>>32-t}(Tu);var xu=_e&&_e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Su,"__esModule",{value:!0}),Su.v5=void 0;const Ru=Au,Pu=xu(Tu);Su.v5=Ru.v35("v5",80,Pu.default),Object.defineProperty(Jl,"__esModule",{value:!0});const Mu=Gl,ju=nu,Fu=ou,Nu=cu,Bu=uu,Uu=Cu,Du=Su,Lu=Yl;var qu=Jl.default={parse:Mu.parse,unparse:ju.unparse,validate:Fu.validate,version:Nu.version,v1:Bu.v1,v4:Uu.v4,v5:Du.v5,NIL:Lu.NIL,DNS:Lu.DNS,URL:Lu.URL,OID:Lu.OID,X500:Lu.X500};const $u=()=>`LOCAL_${qu.v4().toString()}`;let zu;const Hu=async e=>{const t=we();t.log("message/createMessage",e);const n=e.referenceId||zu||$u();zu=void 0;const{data:r}=await t.http.post("/api/v5/messages",Object.assign(Object.assign({},$a(e)),{referenceId:n})),o=await qa(r),{messages:s}=o,i=t.cache&&Date.now();return t.cache&&(He(["message","get",n]),Xi(o,{cachedAt:i})),ut("local.message.created",{messages:s}),{data:s[0],cachedAt:i}};Hu.optimistically=e=>{var t,n,{referenceId:r}=e,o=Zi(e,["referenceId"]);const s=we();if(!s.cache)return;zu=r||$u();const i=Object.assign({messageId:zu,uniqueId:zu},o);s.log("message/createMessage.optimistically",i);const a=Le(["subChannel","get",o.subChannelId]);if(a&&(ze(["subChannel","get",o.subChannelId],Object.assign(Object.assign({},a.data),{messageCount:a.data.messageCount+1})),a.data.channelId===a.data.subChannelId)){const e=Le(["channel","get",a.data.channelId]);(null==e?void 0:e.data)&&ze(["channel","get",a.data.channelId],Object.assign(Object.assign({},e.data),{messageCount:(null!==(t=e.data.messageCount)&&void 0!==t?t:0)+1}))}const c=(new Date).toISOString(),l=Object.assign({creatorId:s.userId,channelSegment:(null!==(n=null==a?void 0:a.data.messageCount)&&void 0!==n?n:0)+1,childrenNumber:0,createdAt:c,updatedAt:c},i);return qe(["message","get",l.messageId],l,{cachedAt:-5}),ut("local.message.created",{messages:[l]}),{cachedAt:-5,data:l}};const Vu=async(e,t)=>{const n=we();n.log("message/updateMessage",t),console.warn("MessageRepository.updateMessage will be replaced with MessageRepository.editMessage");const{data:r}=await n.http.put(`/api/v5/messages/${encodeURIComponent(e)}`,$a(t)),o=await qa(r),s=n.cache&&Date.now();n.cache&&Xi(o,{cachedAt:s});const{messages:i}=o;return ut("local.message.updated",{messages:i}),{data:i.find((t=>t.messageId===e)),cachedAt:s}};Vu.optimistically=(e,t)=>{const n=we();if(n.log("message/updateMessage.optimistically",t),!n.cache)return;const r=Le(["message","get",e]);if(!r)return;const o=Object.assign(Object.assign(Object.assign({},r.data),t),{updatedAt:(new Date).toISOString()});return ze(["message","get",e],o,{cachedAt:-1}),ut("local.message.updated",{messages:[o]}),{data:o,cachedAt:-1}};const Wu=async(e,t)=>{const n=we();n.log("message/editMessage",t);const{data:r}=await n.http.put(`/api/v5/messages/${encodeURIComponent(e)}`,$a(t)),o=await qa(r),s=n.cache&&Date.now();n.cache&&Xi(o,{cachedAt:s});const{messages:i}=o;return ut("local.message.updated",{messages:i}),{data:i.find((t=>t.messageId===e)),cachedAt:s}};Wu.optimistically=(e,t)=>{const n=we();if(n.log("message/editMessage.optimistically",t),!n.cache)return;const r=Le(["message","get",e]);if(!r)return;const o=Object.assign(Object.assign(Object.assign({},r.data),t),{updatedAt:(new Date).toISOString()});return ze(["message","get",e],o,{cachedAt:-1}),ut("local.message.updated",{messages:[o]}),{data:o,cachedAt:-1}};const Ku=async e=>{const t=we();t.log("message/deleteMessage",e),await t.http.delete(`/api/v5/messages/${encodeURIComponent(e)}`);const n=await rl(e);return ut("local.message.deleted",{messages:[n.data]}),n.data};Ku.optimistically=e=>{we().log("message/deleteMessage.optimistically",e);const t=Le(["message","get",e]);if(!t)return;const n=Object.assign(Object.assign({},t.data),{isDeleted:!0,updatedAt:(new Date).toISOString()});return ze(["message","get",e],n,{cachedAt:-1}),ut("local.message.deleted",{messages:[n]}),{data:n,cachedAt:-1}};const Qu=async e=>{const t=we();t.log("message/softDeleteMessage",e),await t.http.delete(`/api/v5/messages/${encodeURIComponent(e)}`);const n=await rl(e);return ut("local.message.deleted",{messages:[n.data]}),n.data};Qu.optimistically=e=>{we().log("message/softDeleteMessage.optimistically",e);const t=Le(["message","get",e]);if(!t)return;const n=Object.assign(Object.assign({},t.data),{isDeleted:!0,updatedAt:(new Date).toISOString()});return ze(["message","get",e],n,{cachedAt:-1}),ut("local.message.deleted",{messages:[n]}),{data:n,cachedAt:-1}};const Ju=async e=>{const t=we();t.log("user/getReadUsers",e);const{page:n,messageId:r}=e,o=Zi(e,["page","messageId"]),{data:s}=await t.http.get(`/api/v1/markers/messages/${r}/read-users`,{params:Object.assign(Object.assign({},o),{options:{token:J(n,"afterbeforeraw")}})}),{paging:i,publicUserIds:a}=s,c=Zi(s,["paging","publicUserIds"]),l=t.cache&&Date.now();if(t.cache){Xi(c,{cachedAt:l});const e=["read-user","query",Object.assign(Object.assign({messageId:r},o),{options:Object.assign({},n)})];qe(e,{users:a,paging:i})}let u=[];a.length>0&&({data:u}=await $c(a));return{data:u,cachedAt:l,prevPage:G(i.previous),nextPage:G(i.next)}};Ju.locally=e=>{var t;const n=we();if(n.log("user/getReadUsers.locally",e),!n.cache)return;const{page:r}=e,o=Zi(e,["page"]),s=["read-user","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})],{data:i,cachedAt:a}=null!==(t=Le(s))&&void 0!==t?t:{},c=null==i?void 0:i.users.map((e=>{var t;return null===(t=Le(["user","get",e]))||void 0===t?void 0:t.data}));if(!c||c.some((e=>!e)))return;return{data:c,cachedAt:a,prevPage:G(null==i?void 0:i.paging.previous),nextPage:G(null==i?void 0:i.paging.next)}};const Gu=async e=>{const t=we();t.log("user/getDeliveredUsers",e);const{page:n,messageId:r}=e,o=Zi(e,["page","messageId"]),{data:s}=await t.http.get(`/api/v1/markers/messages/${r}/delivered-users`,{params:Object.assign(Object.assign({},o),{options:{token:J(n,"afterbeforeraw")}})}),{paging:i,publicUserIds:a}=s,c=Zi(s,["paging","publicUserIds"]),l=t.cache&&Date.now();if(t.cache){Xi(c,{cachedAt:l});const e=["delivered-user","query",Object.assign(Object.assign({messageId:r},o),{options:Object.assign({},n)})];qe(e,{users:a,paging:i})}let u=[];a.length>0&&({data:u}=await $c(a));return{data:u,cachedAt:l,prevPage:G(i.previous),nextPage:G(i.next)}};Gu.locally=e=>{var t;const n=we();if(n.log("user/getDeliveredUsers.locally",e),!n.cache)return;const{page:r}=e,o=Zi(e,["page"]),s=["delivered-user","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})],{data:i,cachedAt:a}=null!==(t=Le(s))&&void 0!==t?t:{},c=null==i?void 0:i.users.map((e=>{var t;return null===(t=Le(["user","get",e]))||void 0===t?void 0:t.data}));if(!c||c.some((e=>!e)))return;return{data:c,cachedAt:a,prevPage:G(null==i?void 0:i.paging.previous),nextPage:G(null==i?void 0:i.paging.next)}};const Yu=async e=>{const t=we();t.log("message/queryMessages",e);const n=za(e),{data:r}=await t.http.get("/api/v5/messages",{params:n}),{paging:o}=r,s=Zi(r,["paging"]),i=await qa(s),{messages:a}=i,c=t.cache&&Date.now();if(t.cache){Xi(i,{cachedAt:c});qe(["message","query",n],{messages:a.map(ce("message")),paging:o})}ut("local.message.fetched",{messages:a});const l=Y(o.next);return{data:a,cachedAt:c,prevPage:Y(o.previous),nextPage:l}};var Xu=Object.freeze({__proto__:null,getMessageByIds:Ql,createMessage:Hu,updateMessage:Vu,editMessage:Wu,deleteMessage:Ku,softDeleteMessage:Qu,markAsDelivered:async(e,t)=>{const n=we();n.log("message/markAsDelivered",e,t);const{data:r}=await n.http.put(`/api/v1/markers/message-feeds/${e}/mark-delivering`,{messageId:t}),o=n.cache&&Date.now();return n.cache&&Xi(r,{cachedAt:o}),!0},getReadUsers:Ju,getDeliveredUsers:Gu,flagMessage:async e=>{const t=we();t.log("message/flag",e);const{data:n}=await t.http.post(`/api/v5/messages/${encodeURIComponent(e)}/flags`);if(t.cache){const e=await qa(n);Xi(e)}return ut("message.flagged",n),!!n},unflagMessage:async e=>{const t=we();t.log("message/unflag",e);const{data:n}=await t.http.delete(`/api/v5/messages/${encodeURIComponent(e)}/flags`);if(t.cache){const e=await qa(n);Xi(e)}return ut("message.unflagged",n),!!n},isMessageFlaggedByMe:async e=>{const t=we();t.log("message/isMessageFlaggedByMe",e);const{data:n}=await t.http.get(`/api/v5/messages/${encodeURIComponent(e)}/flags`);return n.result},onMessageCreated:Ha,onMessageUpdated:Va,onMessageDeleted:Wa,onMessageFlagged:Ka,onMessageUnflagged:Qa,onMessageFlagCleared:Ja,onMessageReactionAdded:Ga,onMessageReactionRemoved:Ya,onMessageFetched:Xa,getMessage:(e,t)=>Ua(e,t,"messageId",rl,[Xa,Va,Wa,Ka,Qa,Ja,Ga,Ya]),getMessages:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getMessages(tmpid: ${s}) > listen`);const{limit:i}=e,a=Zi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["message","collection",e],g=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["message","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.includeDeleted||(s=Ve(s,"isDeleted",!1)),t({onNextPage:v,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},m=t=>t=>{var n;const r=null===(n=Le(d))||void 0===n?void 0:n.data;e.subChannelId===(null==t?void 0:t.subChannelId)&&r&&(r.data=[...new Set([t.messageId,...r.data])],qe(d,r),g(r))},v=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re(Yu,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:i};e&&(o.data=[...new Set([...i,...e.map(ce("message"))])]),qe(d,o),g(o)}),oe(l,y))};return u.push(Xa(m()),Ha(m()),Va(m()),Wa(m()),Ka(m()),Qa(m()),Ja(m()),Ga(m()),Ya(m())),v(!0),u.push((()=>He(d))),()=>{r(`getMessages(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},observeMessage:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observeMessage(tmpid: ${o}) > listen`),console.log("observeMessage will be deprecated on 15th November 2022, please use liveMessage instead.");const s=(n,r)=>{var o,s,i;if((null===(o=n.data)||void 0===o?void 0:o.messageId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(s=t.onEvent)||void 0===s||s.call(t,r,n)),null===(i=t[r])||void 0===i||i.call(t,n)}},i=[];return i.push(Va((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Wa((e=>s({data:e,loading:!1,origin:"event"},"onDelete")))),"no_fetch"!==n&&se(re(rl,e),(e=>e.data&&s(e,"onFetch")),oe(n)),()=>{r(`observeMessages(tmpid: ${o}) > dispose`),i.forEach((e=>e()))}},observeMessages:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeMessages(tmpid: ${r}) > listen`);const o=[],s=(n,r)=>{var o,s,i;if((null===(o=n.data)||void 0===o?void 0:o.subChannelId)===e){if(t instanceof Function)return t(n);null===(s=t.onEvent)||void 0===s||s.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(Ha((e=>s({data:e,loading:!1,origin:"event"},"onCreate"))),Va((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Wa((e=>s({data:e,loading:!1,origin:"event"},"onDelete")))),()=>{n(`observeMessages(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},convertFromRaw:La,prepareMessagePayload:qa,convertParams:$a,convertQueryParams:za});const Zu=async e=>{const t=we();t.log("channel/getSubChannels",e);const n=await t.http.get("/api/v5/message-feeds/list",{params:{messageFeedIds:e.map(encodeURIComponent)}}),r=await nc(n.data),o=t.cache&&Date.now();return t.cache&&Xi(r,{cachedAt:o}),ut("local.message-feed.fetched",r),{data:r.messageFeeds,cachedAt:o}};Zu.locally=e=>{var t;const n=we();if(n.log("channel/getSubChannels.locally",e),!n.cache)return;const r=e.map((e=>Le(["subChannel","get",e]))).filter(Boolean);if((null==r?void 0:r.length)<e.length)return;return{data:r.map((({data:e})=>e)),cachedAt:(null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0]).cachedAt}};const ed=async(e,t=!1)=>{const n=we(),r=await ic(e);await n.http.delete(`/api/v5/message-feeds/${encodeURIComponent(e)}`,{params:{permanent:t}});const o=Object.assign(Object.assign({},r.data),{isDeleted:!0,updatedAt:pe(r.data.updatedAt)});return t?setTimeout((()=>{sc("subChannel",e)}),0):ze(["subChannel","get",e],o),ut("local.message-feed.deleted",{messageFeeds:[o]}),o},td=e=>lt(we(),"onSubChannelFetched","local.message-feed.fetched",(t=>e(t.messageFeeds[0])));function nd(e,t){const n=[...e,...t];if(0===n.length)return[];const r=de(n[0]),o=new Map;return n.forEach((e=>o.set(e[r],e))),Array.from(o.values())}const rd=async e=>{const t=we();t.log("channel/querySubChannels",e);const n=rc(e),{page:r={limit:10},channelId:o,includeDeleted:s}=n,i=Zi(n,["page","channelId","includeDeleted"]),a=(await t.http.get(`/api/v5/message-feeds/channel/${o}`,{params:Object.assign(Object.assign({},i),{isDeleted:Da(s),options:{token:J(r,"skiplimit")}})})).data,{paging:c}=a,l=Zi(a,["paging"]),u=await nc(l),d=u.messageFeeds,h=t.cache&&Date.now();if(t.cache){Xi(u,{cachedAt:h});const e=["subChannel","query",Object.assign(Object.assign({channelId:o},i),{options:Object.assign({},r)})];qe(e,{subChannels:d.map(ce("subChannel")),paging:c})}ut("local.message-feed.fetched",u);const f=G(c.next);return{data:d,cachedAt:h,prevPage:G(c.previous),nextPage:f}};rd.locally=e=>{var t,n,r;we().log("channel/querySubChannels.locally",e);const o=null!==(t=rc(e))&&void 0!==t?t:{},{page:s={limit:10},channelId:i}=o,a=Zi(o,["page","channelId"]),c=["subChannel","query",Object.assign(Object.assign({channelId:i},a),{options:Object.assign({},s)})],{data:l,cachedAt:u}=null!==(n=Le(c))&&void 0!==n?n:{};if(!(null==l?void 0:l.subChannels.length))return;const d=l.subChannels.map((e=>Le(["subChannel","get",e]))).filter(Boolean).map((({data:e})=>e)),h=G(null==l?void 0:l.paging.previous),f=G(null==l?void 0:l.paging.next);return d.length===(null===(r=null==l?void 0:l.subChannels)||void 0===r?void 0:r.length)?{data:d,cachedAt:u,prevPage:h,nextPage:f}:void 0};var od=Object.freeze({__proto__:null,getSubChannelByIds:Zu,createSubChannel:async e=>{const t=we();t.log("user/createSubChannel",e);const n=await t.http.post("/api/v5/message-feeds",{channelId:e.channelId,name:e.displayName}),r=await nc(n.data),o=t.cache&&Date.now();return t.cache&&Xi(r,{cachedAt:o}),ut("message-feed.created",n.data),{data:r.messageFeeds[0],cachedAt:o}},updateSubChannel:async(e,t)=>{const n=we();n.log("channel/updateSubChannel",e,t);const r=await n.http.put(`/api/v5/message-feeds/${encodeURIComponent(e)}`,{name:t.displayName}),o=await nc(r.data),s=n.cache&&Date.now();return n.cache&&Xi(o,{cachedAt:s}),ut("message-feed.updated",r.data),{data:o.messageFeeds[0],cachedAt:s}},deleteSubChannel:ed,hardDeleteSubChannel:async e=>{we().log("channel/hardDeleteSubChannel",e);return await ed(e,!0)},softDeleteSubChannel:async e=>{we().log("channel/softDeleteSubChannel",e);return await ed(e,!1)},startReadingAPI:ac,stopReadingAPI:cc,onSubChannelCreated:pc,onSubChannelUpdated:gc,onSubChannelDeleted:mc,getSubChannel:(e,t)=>Ua(e,t,"subChannelId",ic,[td,gc,mc]),getSubChannels:(e,t,n)=>{const{log:r,cache:o}=we(),s=Date.now();r(`getSubChannels(tmpid: ${s}) > listen`),o||console.log(p);const{limit:i=h}=e,a=Zi(e,["limit"]),{policy:c=f}=null!=n?n:{};let l;const u=[],d=n=>{var r;let o=n.data;e.includeDeleted||(o=Ve(o,"isDeleted",!1)),o.sort(nt),t({onNextPage:m,data:o,hasNextPage:!!(null===(r=n.params)||void 0===r?void 0:r.page),loading:n.loading,error:n.error})},g=t=>n=>{e.channelId===n.channelId&&l&&function(e,t,n){const r=de(t),o=e.find((e=>e[r]===t[r]));return o?fe(o,t):"onCreate"===n}(l.data,n,t)&&(l.data="onCreate"===t?[n,...l.data]:l.data.map((e=>e.subChannelId===n.subChannelId?n:e)),d(l))},m=()=>{var e;const t=l?l.data:[];if(t.length>0&&!(null==l?void 0:l.params.page))return;const n=re(rd,Object.assign(Object.assign({},a),{page:null!==(e=null==l?void 0:l.params.page)&&void 0!==e?e:{limit:i}}));se(n,(({data:e,error:n,loading:r,nextPage:o})=>{l={loading:r,error:n,params:{page:o},data:e?nd(t,e):t},d(l)}),oe(c,y))};return u.push(pc(g("onCreate")),mc(g("onDelete")),td(g("onFetch")),gc(g("onUpdate"))),m(),()=>{r(`getSubChannels(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},startReading:e=>(uc[e]=!0,0===lc.length&&(hc(),fc(e)),ac(e)),stopReading:e=>(uc[e]=!1,lc.forEach((e=>e())),lc=[],cc(e))});const sd=e=>{var t;return null!==(t=Object.keys(n).find((t=>e.needApprovalOnPostCreation===n[t].needApprovalOnPostCreation&&e.onlyAdminCanPost===n[t].onlyAdminCanPost)))&&void 0!==t?t:r},id=e=>{const t=e.communities.map((e=>{var{needApprovalOnPostCreation:t,onlyAdminCanPost:n}=e,r=Zi(e,["needApprovalOnPostCreation","onlyAdminCanPost"]);return Object.assign({postSetting:sd({needApprovalOnPostCreation:t,onlyAdminCanPost:n})},r)})),n=ea(e.communityUsers);return Object.assign(Object.assign({},e),{communities:t,communityUsers:n})},ad=e=>{const{postSetting:t}=e,r=Zi(e,["postSetting"]);return Object.assign(Object.assign({},r),t?n[t]:void 0)},cd=async e=>{const t=we();t.log("community/getCommunities",e);const{data:n}=await t.http.get("/api/v3/communities/list",{params:{communityIds:e}}),r=id(n),o=t.cache&&Date.now();return t.cache&&Xi(r,{cachedAt:o}),{data:r.communities,cachedAt:o}};cd.locally=e=>{var t;const n=we();if(n.log("community/getCommunities.locally",e),!n.cache)return;const r=e.map((e=>Le(["community","get",e]))).filter(Boolean),o=r.map((({data:e})=>e)),s=null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0];return(null==r?void 0:r.length)<e.length?void 0:{data:o,cachedAt:s.cachedAt}};const ld=async e=>{const t=we();t.log("community/getCommunity",e);const{data:n}=await t.http.get(`/api/v3/communities/${e}`),r=id(n),o=t.cache&&Date.now();t.cache&&Xi(r,{cachedAt:o});const{communities:s}=r;return{data:s.find((t=>t.communityId===e)),cachedAt:o}};ld.locally=e=>{const t=we();if(t.log("community/getCommunity.locally",e),!t.cache)return;const n=Le(["community","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const ud=async e=>{const t=we();t.log("channel/getTopTrendingCommunities",e);const{limit:n=5}=null!=e?e:{},{data:r}=await t.http.get("/api/v3/communities/top-trending",{params:{options:{limit:n}}}),o=id(r),{communities:s}=o,i=t.cache&&Date.now();if(t.cache){Xi(o,{cachedAt:i});qe(["community","top-trending",{params:{options:{limit:n}}}],{communities:s.map(ce("community"))})}return{data:s,cachedAt:i}};ud.locally=e=>{var t,n;const r=we();if(r.log("community/getTopTrendingCommunities.locally",e),!r.cache)return;const{limit:o=5}=null!=e?e:{},s=["community","top-trending",{params:{options:{limit:o}}}],{data:i,cachedAt:a}=null!==(t=Le(s))&&void 0!==t?t:{};if(!(null==i?void 0:i.communities.length))return;const c=i.communities.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e));return c.length===(null===(n=null==i?void 0:i.communities)||void 0===n?void 0:n.length)?{data:c,cachedAt:a}:void 0};const dd=async e=>{const t=we();t.log("channel/getRecommendedCommunities",e);const{limit:n=5}=null!=e?e:{},{data:r}=await t.http.get("/api/v3/communities/recommended",{params:{options:{limit:n}}}),o=id(r),{communities:s}=o,i=t.cache&&Date.now();if(t.cache){Xi(o,{cachedAt:i});qe(["community","recommended",{params:{options:{limit:n}}}],{communities:s.map(ce("community"))})}return{data:s,cachedAt:i}};dd.locally=e=>{var t,n;const r=we();if(r.log("community/getRecommendedCommunities.locally",e),!r.cache)return;const{limit:o=5}=null!=e?e:{},s=["community","recommended",{params:{options:{limit:o}}}],{data:i,cachedAt:a}=null!==(t=Le(s))&&void 0!==t?t:{};if(!(null==i?void 0:i.communities.length))return;const c=i.communities.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e));return c.length===(null===(n=null==i?void 0:i.communities)||void 0===n?void 0:n.length)?{data:c,cachedAt:a}:void 0};const hd=(e,t)=>{const n=we();return lt(n,e,e,(e=>{const r=id(e);if(n.cache){Xi(r);const e=Le(["community","get",r.communities[0].communityId]);t(e.data)}else t(r.communities[0])}))},fd=e=>hd("community.created",e),pd=e=>hd("community.updated",e),gd=e=>hd("community.deleted",e);function md(e,t){return e.map((e=>{const n=t.some((t=>function(e,t){const{userId:n}=ht();return e.communityId===t.communityId&&t.userId===n}(e,t)&&"none"!==t.communityMembership));return Object.assign(Object.assign({},e),{isJoined:n})}))}function yd(e,t,n){return!!e.permissions.some((e=>e===n))||t.users.find((t=>t.userId===e.userId)).permissions.some((e=>e===n))}function vd(e,t){return"community.joined"===e||"community.left"===e?t.communityUsers[0]:"community.userRemoved"===e?t.communityUsers.filter((e=>"none"===e.communityMembership))[0]:"community.userBanned"===e?t.communityUsers.filter((e=>"banned"===e.communityMembership))[0]:"community.userUnbanned"===e?t.communityUsers.filter((e=>!yd(e,t,"BAN_COMMUNITY_USER")))[0]:t.communityUsers.filter((e=>!yd(e,t,"ADD_COMMUNITY_USER")))[0]}const bd=(e,t)=>{const n=we();return lt(n,e,e,(r=>{const o=id(r),{communities:s,communityUsers:i}=o,a=md(s,i);if(o.communities=a,n.cache){Xi(o);const n=Le(["community","get",o.communities[0].communityId]),r=Le(["communityUsers","get",ce("communityUsers")(vd(e,o))]);t(n.data,r.data)}else t(o.communities[0],vd(e,o))}))},wd=e=>bd("community.userAdded",e),Cd=e=>bd("community.userRemoved",e),_d=e=>bd("community.userBanned",e),kd=e=>bd("community.userChanged",e),Sd=e=>bd("community.userUnbanned",e),Ad=e=>bd("community.roleAdded",e),Ed=e=>bd("community.roleRemoved",e),Id=e=>bd("community.joined",e),Od=e=>bd("community.left",e),Td=async e=>{const t=we();t.log("channel/queryCommunities",e);const n=null!=e?e:{},{page:r}=n,o=Zi(n,["page"]),s=null!=o?o:{},{displayName:i,membership:a,includeDeleted:c}=s,l=Zi(s,["displayName","membership","includeDeleted"]),{data:u}=await t.http.get("/api/v3/communities",{params:Object.assign(Object.assign({},l),{isDeleted:Da(c),keyword:i,filter:a,options:{token:J(r,"skiplimit")}})}),{paging:d}=u,h=Zi(u,["paging"]),f=id(h),{communities:p}=f,g=t.cache&&Date.now();if(t.cache){Xi(f,{cachedAt:g});const e=["community","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];qe(e,{communities:p.map(ce("community")),paging:d})}const m=G(d.next);return{data:p,cachedAt:g,prevPage:G(d.previous),nextPage:m}};var xd=Object.freeze({__proto__:null,addRoles:async(e,t,n)=>{const r=we();r.log("community/moderation/addRoles",e,t,n);const{data:o}=await r.http.post(`/api/v4/communities/${e}/users/roles`,{communityId:e,roles:t,userIds:n}),s=ta(o,"communityUsers");r.cache&&Xi(s);const{communityUsers:i}=s;return!!i.find((n=>n.communityId===e&&t.some((e=>n.roles.includes(e)))))},removeRoles:async(e,t,n)=>{const r=we();r.log("community/moderation/removeRoles",e,t,n);const{data:o}=await r.http.delete(`/api/v4/communities/${e}/users/roles`,{data:{communityId:e,roles:t,userIds:n}}),s=ta(o,"communityUsers");r.cache&&Xi(s);const{communityUsers:i}=s;return!!i.find((n=>n.communityId===e&&!t.some((e=>n.roles.includes(e)))))},banMembers:async(e,t)=>{const n=we();n.log("community/banMembers",{userIds:t,communityId:e});const{data:r}=await n.http.put(`/api/v3/communities/${e}/users/ban`,{userIds:t}),o=ta(r,"communityUsers"),s=n.cache&&Date.now();n.cache&&Xi(o,{cachedAt:s});const{communityUsers:i}=o;return{data:i.filter((e=>t.includes(e.userId))),cachedAt:s}},unbanMembers:async(e,t)=>{const n=we();n.log("community/unbanMembers",{userIds:t,communityId:e});const{data:r}=await n.http.put(`/api/v3/communities/${e}/users/unban`,{userIds:t}),o=ta(r,"communityUsers"),s=n.cache&&Date.now();n.cache&&Xi(o,{cachedAt:s});const{communityUsers:i}=o;return{data:i.filter((e=>t.includes(e.userId))),cachedAt:s}}});const Rd=async e=>{const t=we();t.log("community/queryCommunityMembers",e);const n=null!=e?e:{},{page:r}=n,o=Zi(n,["page"]),{data:s}=await t.http.get(`/api/v3/communities/${o.communityId}/users`,{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:i}=s,a=Zi(s,["paging"]),c=ta(a,"communityUsers"),{communityUsers:l}=c,u=t.cache&&Date.now();if(t.cache){Xi(c,{cachedAt:u});const e=["communityUsers","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];qe(e,{communityUsers:l.map((({communityId:e,userId:t})=>ce("communityUsers")({communityId:e,userId:t}))),paging:i})}return{data:l,cachedAt:u,nextPage:G(i.next),prevPage:G(i.previous)}};Rd.locally=e=>{var t,n;const r=we();if(r.log("community/queryCommunityMembers",e),!r.cache)return;const o=null!=e?e:{},{page:s}=o,i=Zi(o,["page"]),a=["communityUsers","query",Object.assign(Object.assign({},i),{options:Object.assign({},s)})],{data:c,cachedAt:l}=null!==(t=Le(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.communityUsers.length))return;const u=c.communityUsers.map((e=>Le(["communityUsers","get",e]))).filter(Boolean).map((({data:e})=>e)),d=G(null==c?void 0:c.paging.previous),h=G(null==c?void 0:c.paging.next);return u.length===(null===(n=null==c?void 0:c.communityUsers)||void 0===n?void 0:n.length)?{data:u,cachedAt:l,prevPage:d,nextPage:h}:void 0};var Pd=Object.freeze({__proto__:null,addMembers:async(e,t)=>{const n=we();n.log("community/moderation/addMembers",e,t);const{data:r}=await n.http.post(`/api/v3/communities/${e}/users`,{communityId:e,userIds:t});ut("community.userAdded",r);const o=ta(r,"communityUsers");n.cache&&Xi(o);const{communityUsers:s}=o;return!!s.find((t=>t.communityId===e&&"member"===t.communityMembership))},removeMembers:async(e,t)=>{const n=we();n.log("community/moderation/removeMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/communities/${e}/users`,{data:{communityId:e,userIds:t}});ut("community.userRemoved",r);const o=ta(r,"communityUsers");n.cache&&Xi(o);const{communityUsers:s}=o;return!!s.find((t=>t.communityId===e&&"member"!==t.communityMembership))},getMembers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getMembers(tmpid: ${s}) > listen`);const{limit:i}=e,a=Zi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["communityUsers","collection",{communityId:e.communityId}],g=t=>{let n=We(t,"roles",e.roles);e.membership&&(n=n.filter((({communityMembership:t})=>e.membership.includes(t)))),e.search&&(n=Ye(n,e.search));const r=e.sortBy?e.sortBy:"lastCreated";return n=n.sort("lastCreated"===r?tt:et),n},m=(e,n=!1)=>{var r,o;const s=null!==(r=e.data.map((e=>Le(["communityUsers","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];t({onNextPage:v,data:n?g(s):s,hasNextPage:!!(null===(o=e.params)||void 0===o?void 0:o.page),loading:e.loading,error:e.error})},y=t=>(t,n)=>{var r;if(e.communityId!==n.communityId)return;const o=null===(r=Le(d))||void 0===r?void 0:r.data;if(!o)return;const s=ce("communityUsers")({communityId:e.communityId,userId:n.userId});o.data=[...new Set([s,...o.data])],qe(d,o),m(o,!0)},v=(e=!1)=>{var t,n,r;const o=null===(t=Le(d))||void 0===t?void 0:t.data,s=null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(Rd,Object.assign(Object.assign({},a),{page:null!==(r=e||null==o?void 0:o.params.page)&&void 0!==r?r:{limit:c}}));se(i,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(ce("communityUsers"))])]),qe(d,o),m(o)}),oe(l))};return u.push(Od(y()),Id(y()),_d(y()),Sd(y()),kd(y()),Ad(y()),Ed(y())),v(!0),()=>{r(`getMembers(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}},onCommunityUserAdded:wd,onCommunityUserRemoved:Cd,onCommunityUserBanned:_d,onCommunityUserChanged:kd,onCommunityUserUnbanned:Sd,onCommunityUserRoleAdded:Ad,onCommunityUserRoleRemoved:Ed,onCommunityJoined:Id,onCommunityLeft:Od}),Md=Object.freeze({__proto__:null,Moderation:xd,Membership:Pd,getCommunityByIds:cd,createCommunity:async e=>{const t=we();t.log("user/createCommunity",e);const{data:n}=await t.http.post("/api/v3/communities/",ad(e));ut("community.created",n);const r=id(n),o=t.cache&&Date.now();t.cache&&Xi(r,{cachedAt:o});const{communities:s}=r;return{data:s[0],cachedAt:o}},updateCommunity:async(e,t)=>{const n=we();n.log("community/updateCommunity",e,t);const{data:r}=await n.http.put(`/api/v3/communities/${e}`,ad(t));ut("community.updated",r);const o=id(r),s=n.cache&&Date.now();n.cache&&Xi(o,{cachedAt:s});const{communities:i}=o;return{data:i.find((t=>t.communityId===e)),cachedAt:s}},deleteCommunity:async e=>{const t=we();t.log("community/deleteCommunity",e),await t.http.delete(`/api/v3/communities/${e}`);const n=await ld(e);return ut("community.deleted",{communities:[n.data],categories:[],communityUsers:[],feeds:[],files:[],users:[]}),n.data},joinCommunity:async e=>{const t=we();t.log("community/joinCommunity",e);const{data:n}=await t.http.post(`/api/v3/communities/${e}/join`);ut("community.joined",n);const r=id(n),o=t.cache&&Date.now();t.cache&&Xi(r,{cachedAt:o});const{communityUsers:s}=r;return!!s.find((t=>t.communityId===e&&"member"===t.communityMembership))},leaveCommunity:async e=>{const t=we();t.log("community/leaveCommunity",e);const{data:n}=await t.http.delete(`/api/v3/communities/${e}/leave`);ut("community.left",n);const r=id(n),o=t.cache&&Date.now();t.cache&&Xi(r,{cachedAt:o});const{communityUsers:s}=r;return!!s.find((t=>t.communityId===e&&"member"!==t.communityMembership))},getTopTrendingCommunities:ud,getRecommendedCommunities:dd,onCommunityCreated:fd,onCommunityUpdated:pd,onCommunityDeleted:gd,observeCommunity:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeCommunity(tmpid: ${r}) > listen`);const o=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},s=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.communityId)===e&&o(t,n)},i=[];return i.push(pd((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),gd((e=>s({data:e,loading:!1,origin:"event"},"onDelete"))),Id((e=>s({data:e,loading:!1,origin:"event"},"onJoin"))),Od((e=>s({data:e,loading:!1,origin:"event"},"onLeft"))),wd((e=>s({data:e,loading:!1,origin:"event"},"onUserAdded"))),Cd((e=>s({data:e,loading:!1,origin:"event"},"onUserRemoved"))),_d((e=>s({data:e,loading:!1,origin:"event"},"onUserBanned"))),Sd((e=>s({data:e,loading:!1,origin:"event"},"onUserUnbanned")))),se(re(ld,e),(e=>(e.data||e.error)&&o(e,"onFetch"))),()=>{n(`observeCommunity(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}},getCommunities:(e,t,n)=>{const{log:r,cache:o,userId:s}=we();o||console.log(p);const i=Date.now();r(`getCommunities(tmpid: ${i}) > listen`);const{limit:a}=e,c=Zi(e,["limit"]),l=null!=a?a:h,{policy:u=f}=null!=n?n:{},d=[],g=["community","collection",{}],m=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];i=Ve(i,"displayName",e.displayName),e.includeDeleted||(i=Ve(i,"isDeleted",!1)),e.categoryId&&(i=i.filter((t=>{var n;return null===(n=t.categoryIds)||void 0===n?void 0:n.includes(e.categoryId)}))),e.tags&&(i=i.filter((t=>{var n;return null===(n=t.tags)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.tags)||void 0===n?void 0:n.includes(t)}))}))),e.membership&&s&&(i=Je(i,e.membership,s));const a=e.sortBy||"lastCreated";"lastCreated"!==a&&"firstCreated"!==a||(i=i.sort("lastCreated"===a?tt:et)),"displayName"===a&&(i=i.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Xe)),t({onNextPage:b,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},v=e=>e=>{var t;const n=null===(t=Le(g))||void 0===t?void 0:t.data;n&&(n.data=[...new Set([e.communityId,...n.data])],qe(g,n),m(n))},b=(e=!1)=>{var t,n,r;const o=null===(t=Le(g))||void 0===t?void 0:t.data,s=null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[];if(!e&&s.length>0&&!(null==o?void 0:o.params.page))return;const i=re(Td,Object.assign(Object.assign({},c),{page:null!==(r=e||null==o?void 0:o.params.page)&&void 0!==r?r:{limit:l}}));se(i,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(ce("community"))])]),qe(g,o),m(o)}),oe(u,y))};return d.push(fd(v()),gd(v()),pd(v()),Id(v()),Od(v()),kd(v())),b(!0),d.push((()=>He(g))),()=>{r(`getCommunities(tmpid: ${i}) > dispose`),d.forEach((e=>e()))}},getCommunity:(e,t)=>Ua(e,t,"communityId",ld,[pd,gd,Id,Od,_d,Sd,kd])});const jd=async e=>{const t=we();t.log("category/getCategory",e);const{data:n}=await t.http.get(`/api/v3/community-categories/${encodeURIComponent(e)}`),r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r});const{categories:o}=n;return{data:o.find((t=>t.categoryId===e)),cachedAt:r}};jd.locally=e=>{const t=we();if(t.log("category/getCategory.locally",e),!t.cache)return;const n=Le(["category","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Fd=async e=>{const t=we();t.log("category/queryCategories",e);const n=null!=e?e:{},{page:r={limit:10},includeDeleted:o}=n,s=Zi(n,["page","includeDeleted"]),{data:i}=await t.http.get("/api/v3/community-categories",{params:Object.assign(Object.assign({},s),{isDeleted:Da(o),options:{token:J(r,"skiplimit")}})}),{paging:a}=i,c=Zi(i,["paging"]),{categories:l}=c,u=t.cache&&Date.now();if(t.cache){Xi(c,{cachedAt:u});const e=["category","query",Object.assign(Object.assign({},s),{options:Object.assign({},r)})];qe(e,{categories:l.map(ce("category")),paging:a})}const d=G(a.next);return{data:l,cachedAt:u,prevPage:G(a.previous),nextPage:d}};Fd.locally=e=>{var t,n;const r=we();if(r.log("category/queryCategories.locally",e),!r.cache)return;const o=null!=e?e:{},{page:s={limit:10}}=o,i=Zi(o,["page"]),a=["category","query",Object.assign(Object.assign({},i),{options:Object.assign({},s)})],{data:c,cachedAt:l}=null!==(t=Le(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.categories.length))return;const u=c.categories.map((e=>Le(["category","get",e]))).filter(Boolean).map((({data:e})=>e)),d=G(null==c?void 0:c.paging.previous),h=G(null==c?void 0:c.paging.next);return u.length===(null===(n=null==c?void 0:c.categories)||void 0===n?void 0:n.length)?{data:u,cachedAt:l,prevPage:d,nextPage:h}:void 0};var Nd=Object.freeze({__proto__:null,getCategory:jd,getCategories:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getCategories(tmpid: ${s}) > listen`);const{limit:i}=e,a=Zi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["category","collection",{}],g=(n=!1)=>{var r,o,s;const i=null===(r=Le(d))||void 0===r?void 0:r.data,u=null!==(o=null==i?void 0:i.data)&&void 0!==o?o:[];if(!n&&u.length>0&&!(null==i?void 0:i.params.page))return;const h=re(Fd,Object.assign(Object.assign({},a),{page:null!==(s=n||null==i?void 0:i.params.page)&&void 0!==s?s:{limit:c}}));se(h,(({data:n,error:r,loading:o,nextPage:s})=>{const i={loading:o,error:r,params:{page:s},data:u};n&&(i.data=[...new Set([...u,...n.map(ce("category"))])]),qe(d,i),(n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["category","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(e.includeDeleted||(s=Ve(s,"isDeleted",!1)),e.sortBy){case"firstCreated":s=s.sort(et);break;case"lastCreated":s=s.sort(tt);break;default:s=s.sort(Ze)}t({onNextPage:g,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})})(i)}),oe(l))};return u.push((()=>{})),g(!0),()=>{r(`getCategories(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}}});const Bd=async e=>{const t=we();t.log("feed/queryGlobalFeed",e);const n=null!=e?e:{},{useCustomRanking:r,page:o}=n,s=Zi(n,["useCustomRanking","page"]);r&&console.warn('The param "useCustomRanking" has been deprecated. To get custom ranking feed use FeedRepository.getCustomRankingGlobalFeed instead');const{data:i}=await t.http.get("/api/v4/me/global-feeds",{params:Object.assign(Object.assign({},s),{options:{token:J(o,"skiplimit")}})}),{paging:a}=i,c=Zi(i,["paging"]),l=ta(c,"communityUsers"),{posts:u}=l,d=t.cache&&Date.now();if(t.cache){Xi(l);const e=["globalFeed","query",Object.assign(Object.assign({},s),{options:Object.assign({},o)})];qe(e,{posts:u.map(ce("post")),paging:a})}const h=G(a.next);return{data:u,cachedAt:d,prevPage:G(a.previous),nextPage:h}};Bd.locally=e=>{var t,n;const r=we();if(r.log("post/queryGlobalFeed.locally",e),!r.cache)return;const o=null!=e?e:{},{page:s}=o,i=Zi(o,["page"]),a=["globalFeed","query",Object.assign(Object.assign({},i),{options:Object.assign({},s)})],{data:c,cachedAt:l}=null!==(t=Le(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.posts.length))return;const u=c.posts.map((e=>Le(["post","get",e]))).filter(Boolean).map((({data:e})=>e)),d=G(null==c?void 0:c.paging.previous),h=G(null==c?void 0:c.paging.next);return u.length===(null===(n=null==c?void 0:c.posts)||void 0===n?void 0:n.length)?{data:u,cachedAt:l,prevPage:d,nextPage:h}:void 0};const Ud=async e=>{const t=we();t.log("feed/getCustomRankingGlobalFeed",e);const n=null!=e?e:{},{page:r}=n,o=Zi(n,["page"]),{data:s}=await t.http.get("/api/v5/me/global-feeds",{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:i}=s,a=Zi(s,["paging"]),c=ta(a,"communityUsers"),{posts:l}=c,u=t.cache&&Date.now();if(t.cache){Xi(c);const e=["customGlobalFeed","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];qe(e,{posts:l.map(ce("post")),paging:i})}const d=G(i.next);return{data:l,cachedAt:u,prevPage:G(i.previous),nextPage:d}};Ud.locally=e=>{var t,n;const r=we();if(r.log("post/getCustomRankingGlobalFeed.locally",e),!r.cache)return;const o=null!=e?e:{},{page:s}=o,i=Zi(o,["page"]),a=["customGlobalFeed","query",Object.assign(Object.assign({},i),{options:Object.assign({},s)})],{data:c,cachedAt:l}=null!==(t=Le(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.posts.length))return;const u=c.posts.map((e=>Le(["post","get",e]))).filter(Boolean).map((({data:e})=>e)),d=G(null==c?void 0:c.paging.previous),h=G(null==c?void 0:c.paging.next);return u.length===(null===(n=null==c?void 0:c.posts)||void 0===n?void 0:n.length)?{data:u,cachedAt:l,prevPage:d,nextPage:h}:void 0};var Dd=Object.freeze({__proto__:null,queryGlobalFeed:Bd,getCustomRankingGlobalFeed:Ud});const Ld=async e=>{const t=we();t.log("post/getPostByIds",e);const n=e.map((e=>encodeURIComponent(e)));let r;try{r=(await t.http.get("/api/v3/posts/list",{params:{postIds:n}})).data}catch(t){throw e.forEach((e=>{_(null==t?void 0:t.code)&&sc("post",e)})),t}const o=ta(r,"communityUsers"),s=t.cache&&Date.now();return t.cache&&Xi(o,{cachedAt:s}),{data:o.posts,cachedAt:s}};Ld.locally=e=>{var t;const n=we();if(n.log("post/getPostByIds.locally",e),!n.cache)return;const r=e.map((e=>Le(["post","get",e]))).filter(Boolean),o=r.map((({data:e})=>e)),s=null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0];return(null==r?void 0:r.length)<e.length?void 0:{data:o,cachedAt:s.cachedAt}};const qd=async(e,t=!1)=>{const n=we(),r=await ol(e);if(await n.http.delete(`/api/v4/posts/${encodeURIComponent(e)}`,{params:{postId:e,permanent:t}}),"community"===r.data.targetType){const e=await ld(r.data.targetId);ut("community.updated",{communities:[e.data],categories:[],communityUsers:[],feeds:[],files:[],users:[]})}const o=Object.assign(Object.assign({},r.data),{isDeleted:!0});return ut("post.deleted",{posts:[o],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),t?setTimeout((()=>{sc("post",e)}),0):ze(["post","get",e],{isDeleted:!0}),o},$d=async e=>{const t=we();t.log("post/queryPosts",e);const{page:n={limit:10},includeDeleted:r}=e,o=Zi(e,["page","includeDeleted"]),{dataTypes:s,matchingOnlyParentPost:i}=o,{data:a}=await t.http.get("/api/v4/posts",{params:Object.assign(Object.assign({},o),{isDeleted:Da(r),matchingOnlyParentPost:null!=i?i:!(null==s?void 0:s.length),options:{token:J(n,"afterbeforeraw")}})}),{paging:c}=a,l=Zi(a,["paging"]),u=ta(l,"communityUsers"),{posts:d}=l,h=t.cache&&Date.now();if(t.cache){Xi(u,{cachedAt:h});const e=["post","query",Object.assign(Object.assign({},o),{options:Object.assign({},n)})];qe(e,{posts:d.map(ce("post")),paging:c})}const f=Y(c.next);return{data:d,cachedAt:h,prevPage:Y(c.previous),nextPage:f}};var zd=Object.freeze({__proto__:null,getPostByIds:Ld,createPost:async e=>{const t=we();t.log("post/createPost",e),e.dataType&&!["text","image","file","video"].includes(e.dataType)||delete e.dataType;const{data:n}=await t.http.post("/api/v4/posts",e);ut("post.created",n);const r=ta(n,"communityUsers"),o=t.cache&&Date.now();t.cache&&Xi(r,{cachedAt:o});const{posts:s}=r;return{data:s[0],cachedAt:o}},updatePost:async(e,t)=>{const n=we();n.log("user/updatePost",t),console.warn("Deprecation: updatePost has been renamed to editPost. Update post API will be deprecated soon.");const{data:r}=await n.http.put(`/api/v4/posts/${encodeURIComponent(e)}`,t),o=ta(r,"communityUsers"),s=n.cache&&Date.now();n.cache&&Xi(o,{cachedAt:s}),ut("post.updated",o);const{posts:i}=o;return{data:i.find((t=>t.postId===e)),cachedAt:s}},editPost:async(e,t)=>{const n=we();n.log("user/editPost",t);const{data:r}=await n.http.put(`/api/v4/posts/${encodeURIComponent(e)}`,t),o=ta(r,"communityUsers"),s=n.cache&&Date.now();n.cache&&Xi(o,{cachedAt:s}),ut("post.updated",o);const{posts:i}=o;return{data:i.find((t=>t.postId===e)),cachedAt:s}},deletePost:qd,softDeletePost:async e=>{we().log("post/softDeletePost",e);return await qd(e,!1)},hardDeletePost:async e=>{we().log("post/hardDeletePost",e);return await qd(e,!0)},approvePost:async e=>{const t=we();t.log("post/approvePost",e);const{data:n}=await t.http.post(`/api/v3/posts/${encodeURIComponent(e)}/approve`);ut("post.approved",n),"community"===n.posts[0].targetType&&ut("community.updated",n);const r=ta(n,"communityUsers"),o=t.cache&&Date.now();return t.cache&&Xi(r,{cachedAt:o}),{data:r.posts.find((t=>t.postId===e)),cachedAt:o}},declinePost:async e=>{const t=we();t.log("post/declinePost",e);const{data:n}=await t.http.post(`/api/v3/posts/${encodeURIComponent(e)}/decline`);"community"===n.posts[0].targetType&&ut("community.updated",n),ut("post.declined",n);const r=ta(n,"communityUsers"),o=t.cache&&Date.now();return t.cache&&Xi(r,{cachedAt:o}),{data:n.posts.find((t=>t.postId===e)),cachedAt:o}},flagPost:async e=>{const t=we();t.log("post/flagPost",e);const{data:n}=await t.http.post(`/api/v3/posts/${encodeURIComponent(e)}/flag`);return t.cache&&Xi(ta(n,"communityUsers")),ut("post.flagged",n),!!n},unflagPost:async e=>{const t=we();t.log("post/unflagPost",e);const{data:n}=await t.http.delete(`/api/v3/posts/${encodeURIComponent(e)}/unflag`);return t.cache&&Xi(ta(n,"communityUsers")),ut("post.unflagged",n),!!n},isPostFlaggedByMe:async e=>{var t,n;const r=we();r.log("post/isPostFlaggedByMe",e);const{result:o,isFlagByMe:s}=null!==(t=await Di(r,"v3/post.isflagbyme",{postId:e}))&&void 0!==t?t:{};return null!==(n=null!=o?o:s)&&void 0!==n&&n},onPostCreated:ul,onPostUpdated:dl,onPostDeleted:hl,onPostApproved:fl,onPostDeclined:pl,onPostFlagged:gl,onPostUnflagged:ml,onPostReactionAdded:yl,onPostReactionRemoved:vl,observePosts:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observePosts(tmpid: ${r}) > listen`);const o=[],s=(n,r)=>{var o,s;if(e.targetId===n.targetId&&e.targetType===n.targetType){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(s=t[r])||void 0===s||s.call(t,n)}};return o.push(ul((e=>s(e,"onCreate"))),dl((e=>s(e,"onUpdate"))),hl((e=>s(e,"onDelete"))),fl((e=>s(e,"onApproved"))),pl((e=>s(e,"onDeclined"))),gl((e=>s(e,"onFlagged"))),ml((e=>s(e,"onUnflagged"))),yl((e=>s(e,"onReactionAdded"))),vl((e=>s(e,"onReactionRemoved")))),()=>{n(`observePosts(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},observePost:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observePost(tmpid: ${o}) > listen`);const s=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},i=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.postId)===e&&s(t,n)},a=[];return a.push(dl((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),hl((e=>i({data:e,loading:!1,origin:"event"},"onDelete"))),fl((e=>i({data:e,loading:!1,origin:"event"},"onApproved"))),pl((e=>i({data:e,loading:!1,origin:"event"},"onDeclined"))),gl((e=>i({data:e,loading:!1,origin:"event"},"onFlagged"))),ml((e=>i({data:e,loading:!1,origin:"event"},"onUnflagged"))),yl((e=>i({data:e,loading:!1,origin:"event"},"onReactionAdded"))),vl((e=>i({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),se(re(ol,e),(e=>(e.data||e.error)&&s(e,"onFetch")),oe(n)),()=>{r(`observePosts(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},getPost:(e,t)=>Ua(e,t,"postId",ol,[fl,pl,hl,gl,yl,vl,ml,dl]),getPosts:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const s=Date.now();r(`getPosts(tmpid: ${s}) > listen`);const{limit:i}=e,a=Zi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["post","collection",{targetId:e.targetId,targetType:e.targetType}],g=n=>{var r,o,s;let i=null!==(r=n.data.map((e=>Le(["post","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];const a=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===a?tt:et),e.includeDeleted||(i=Ve(i,"isDeleted",!1)),e.tags&&(i=i.filter((t=>{var n;return null===(n=t.tags)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.tags)||void 0===n?void 0:n.includes(t)}))}))),"community"===e.targetType&&e.feedType&&(i=Qe(i,e.feedType)),(null===(o=e.dataTypes)||void 0===o?void 0:o.length)&&(i=Ge(i,e.dataTypes)),t({onNextPage:v,data:i,hasNextPage:!!(null===(s=n.params)||void 0===s?void 0:s.page),loading:n.loading,error:n.error})},m=t=>n=>{var r;const o=null===(r=Le(d))||void 0===r?void 0:r.data;e.targetId===n.targetId&&e.targetType===n.targetType&&o&&(o.data="onDeclined"===t?o.data.filter((e=>e!==n.postId)):[...new Set([n.postId,...o.data])],qe(d,o),g(o))},v=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re($d,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,nextPage:r})=>{const o={loading:n,error:t,params:{page:r},data:i};e&&(o.data=[...new Set([...i,...e.map(ce("post"))])]),qe(d,o),g(o)}),oe(l,y))};return u.push(ul(m("onCreate")),fl(m("onApproved")),pl(m("onDeclined")),hl(m("onDelete")),dl(m("onUpdate")),gl(m("onFlagged")),ml(m("onUnflagged")),yl(m("onReactionAdded")),vl(m("onReactionRemoved"))),v(!0),u.push((()=>He(d))),()=>{r(`getPosts(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}}});const Hd=async e=>{const t=we();t.log("comment/getCommentByIds",e);const n=e.map((e=>encodeURIComponent(e)));let r;try{r=(await t.http.get("/api/v3/comments/list",{params:{commentIds:n}})).data}catch(t){throw e.forEach((e=>{_(null==t?void 0:t.code)&&sc("comment",e)})),t}const o=t.cache&&Date.now();return t.cache&&Xi(r,{cachedAt:o}),{data:r.comments,cachedAt:o}};Hd.locally=e=>{var t;const n=we();if(n.log("comment/getCommentByIds.locally",e),!n.cache)return;const r=e.map((e=>Le(["comment","get",e]))).filter(Boolean),o=r.map((({data:e})=>e)),s=null===(t=r.sort(((e,t)=>e.cachedAt<t.cachedAt?-1:1)))||void 0===t?void 0:t[0];return(null==r?void 0:r.length)<e.length?void 0:{data:o,cachedAt:s.cachedAt}};const Vd=async e=>{const t=we();t.log("comment/queryComments",e);const{page:n={limit:10},includeDeleted:r}=e,o=Zi(e,["page","includeDeleted"]),s={type:o.sortBy?"pagination":void 0,token:J(n,o.sortBy?"skiplimit":"afterbefore")},{data:i}=await t.http.get("/api/v3/comments",{params:Object.assign(Object.assign({},o),{isDeleted:Da(r),options:s})}),{paging:a}=i,c=Zi(i,["paging"]),{comments:l}=c,u=t.cache&&Date.now();if(t.cache){Xi(c,{cachedAt:u});const e=["comment","query",Object.assign(Object.assign({},o),{options:Object.assign({},n)})];qe(e,{comments:l.map(ce("comment")),paging:a})}const d=G(a.next);return{data:l,cachedAt:u,prevPage:G(a.previous),nextPage:d}};var Wd=Object.freeze({__proto__:null,getCommentByIds:Hd,createComment:async e=>{const t=we();t.log("comment/createComment",e);const{data:n}=await t.http.post("/api/v3/comments",e),r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r});const o=await ol(e.referenceId);ut("post.updated",{posts:[o.data],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),ut("comment.created",n);const{comments:s}=n;return{data:s[0],cachedAt:r}},updateComment:async(e,t)=>{const n=we();n.log("user/updateComment",t);const{data:r}=await n.http.put(`/api/v3/comments/${encodeURIComponent(e)}`,t),o=n.cache&&Date.now();n.cache&&Xi(r,{cachedAt:o}),ut("comment.updated",r);const{comments:s}=r;return{data:s.find((t=>t.commentId===e)),cachedAt:o}},deleteComment:async(e,t=!1)=>{const n=we();n.log("comment/deleteComment",e);const r=await sl(e);await n.http.delete(`/api/v4/comments/${encodeURIComponent(e)}`,{params:{commentId:e,permanent:t}});const o=Object.assign(Object.assign({},r.data),{isDeleted:!0}),s=await ol(r.data.referenceId);return ut("post.updated",{posts:[s.data],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),ut("comment.deleted",{comments:[o],commentChildren:[],files:[],users:[]}),t?st((()=>sc("comment",e))):ze(["comment","get",e],{isDeleted:!0}),o},onCommentCreated:wl,onCommentUpdated:Cl,onCommentDeleted:_l,onCommentFlagged:kl,onCommentUnflagged:Sl,onCommentReactionAdded:Al,onCommentReactionRemoved:El,observeComments:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeComments(tmpid: ${r}) > listen`);const o=[],s=(n,r)=>{var o,s;if(n.referenceId===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(s=t[r])||void 0===s||s.call(t,n)}};return o.push(wl((e=>s(e,"onCreate"))),Cl((e=>s(e,"onUpdate"))),_l((e=>s(e,"onDelete"))),kl((e=>s(e,"onFlagged"))),Sl((e=>s(e,"onUnflagged"))),Al((e=>s(e,"onReactionAdded"))),El((e=>s(e,"onReactionRemoved")))),()=>{n(`observeComments(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},observeComment:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observeComment(tmpid: ${o}) > listen`);const s=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},i=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.commentId)===e&&s(t,n)},a=[];return a.push(Cl((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),_l((e=>i({data:e,loading:!1,origin:"event"},"onDelete"))),kl((e=>i({data:e,loading:!1,origin:"event"},"onFlagged"))),Sl((e=>i({data:e,loading:!1,origin:"event"},"onUnflagged"))),Al((e=>i({data:e,loading:!1,origin:"event"},"onReactionAdded"))),El((e=>i({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),se(re(sl,e),(e=>(e.data||e.error)&&s(e,"onFetch")),oe(n)),()=>{r(`observeComment(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},getComment:(e,t)=>Ua(e,t,"commentId",sl,[_l,kl,Al,El,Sl,Cl]),getComments:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const s=Date.now();r(`getComments(tmpid: ${s}) > listen`);const{limit:i}=e,a=Zi(e,["limit"]),c=null!=i?i:h,{policy:l=f}=null!=n?n:{},u=[],d=["comment","collection",{referenceId:e.referenceType,referenceType:e.referenceId}],p=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["comment","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.includeDeleted||(s=Ve(s,"isDeleted",!1));const i=e.sortBy?e.sortBy:"lastCreated";s=s.sort("lastCreated"===i?tt:et),t({onNextPage:m,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},g=t=>n=>{var r;const o=null===(r=Le(d))||void 0===r?void 0:r.data;e.referenceId===n.referenceId&&e.referenceType===n.referenceType&&o&&("onCreate"===t?o.data=[...new Set([n.commentId,...o.data])]:"onDelete"===t&&(o.data=o.data.filter((e=>e!==n.commentId))),qe(d,o),p(o))},m=(e=!1)=>{var t,n,r,o;const s=null===(t=Le(d))||void 0===t?void 0:t.data,i=null!==(n=null==s?void 0:s.data)&&void 0!==n?n:[];if(!e&&i.length>0&&!(null===(r=null==s?void 0:s.params)||void 0===r?void 0:r.page))return;const u=re(Vd,Object.assign(Object.assign({},a),{page:null!==(o=e||null==s?void 0:s.params.page)&&void 0!==o?o:{limit:c}}));se(u,(({data:e,error:t,loading:n,prevPage:r,nextPage:o})=>{const s={loading:n,error:t,params:{page:a.sortBy?o:r},data:i};e&&(s.data=[...new Set([...i,...e.map(ce("comment"))])]),qe(d,s),p(s)}),oe(l,y))};return u.push(wl(g("onCreate")),Cl(g("onUpdate")),_l(g("onDelete")),kl(g("onFlagged")),Sl(g("onUnflagged")),Al(g("onReactionAdded")),El(g("onReactionRemoved"))),m(!0),u.push((()=>He(d))),()=>{r(`getComments(tmpid: ${s}) > dispose`),u.forEach((e=>e()))}}});const Kd=async e=>{const t=we();t.log("stream/getStream",e);const{data:n}=await t.http.get(`/api/v3/video-streaming/${e}`),r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}};Kd.locally=e=>{const t=we();if(t.log("stream/getStream",e),!t.cache)return;const n=Le(["stream","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Qd=async e=>{const t=we();t.log("stream/getStreams",e);const n=null!=e?e:{},{page:r}=n,o=Zi(n,["page"]),{data:s}=await t.http.get("/api/v3/video-streaming",{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:i,results:a}=s,{videoStreamings:c}=a,l=t.cache&&Date.now();t.cache&&Xi(a,{cachedAt:l});const u=G(i.next);return{data:c,cachedAt:l,prevPage:G(i.previous),nextPage:u}};Qd.locally=e=>{we().log("stream/getStreams.locally",e)};var Jd=Object.freeze({__proto__:null,getStream:Kd,getStreams:Qd,createStream:async e=>{const t=we();t.log("stream/createStream",e);const{data:n}=await t.http.post("/api/v3/video-streaming",e),r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o[0],cachedAt:r}},updateStream:async(e,t)=>{const n=we();n.log("stream/updateStream",e,t);const{data:r}=await n.http.put(`/api/v3/video-streaming/${e}`,t),o=n.cache&&Date.now();n.cache&&Xi(r,{cachedAt:o});const{videoStreamings:s}=r;return{data:s.find((t=>t.streamId===e)),cachedAt:o}},deleteStream:async e=>{const t=we();t.log("stream/deleteStream",e);const n=await Kd(e),{data:r}=await t.http.delete(`/api/v3/video-streaming/${e}`),{success:o}=r,s=Object.assign(Object.assign({},n.data),{isDeleted:!0});return ze(["stream","get",e],s),o},disposeStream:async e=>{const t=we();t.log("stream/disposeStream",e);const{data:n}=await t.http.delete(`/api/v3/video-streaming/${e}/streaming-url`),r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}},onStreamStarted:e=>{const t=we();return lt(t,"stream/onStreamStarted","video-streaming.didStart",(t=>{Xi(t),e(t.videoStreamings[0])}))},onStreamStopped:e=>{const t=we();return lt(t,"stream/onStreamStarted","video-streaming.didStop",(t=>{Xi(t),e(t.videoStreamings[0])}))},onStreamRecorded:e=>{const t=we();return lt(t,"stream/onStreamRecorded","video-streaming.didRecord",(t=>{Xi(t),e(t.videoStreamings[0])}))}});const Gd=async e=>{const t=we();t.log("poll/getPoll",e);const{data:n}=await t.http.get(`/api/v3/polls/${e}`),r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r});const{polls:o}=n;return{data:o.find((t=>t.pollId===e)),cachedAt:r}};Gd.locally=e=>{const t=we();if(t.log("poll/getPoll",e),!t.cache)return;const n=Le(["poll","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Yd=e=>{const t=we();return lt(t,"poll/onPollUpdated","poll.updated",(n=>{t.cache&&Xi(n),e(n.polls[0])}))},Xd=e=>{const t=we();return lt(t,"poll/onPollDeleted","poll.deleted",(n=>{t.cache&&Xi(n),e(n.polls[0])}))};var Zd=Object.freeze({__proto__:null,getPoll:Gd,createPoll:async e=>{const t=we();t.log("post/createPoll",e);const{data:n}=await t.http.post("/api/v3/polls",e),r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r});const{polls:o}=n;return{data:o[0],cachedAt:r}},closePoll:async e=>{const t=we();t.log("user/closePoll",e);const{data:n}=await t.http.put(`/api/v3/polls/${encodeURIComponent(e)}`,{status:"closed"}),r=t.cache&&Date.now();t.cache&&Xi(n,{cachedAt:r}),ut("poll.updated",n);const{polls:o}=n;return{data:o.find((t=>t.pollId===e)),cachedAt:r}},deletePoll:async e=>{const t=we();t.log("poll/deletePoll",e);const n=await Gd(e),{data:r}=await t.http.delete(`/api/v3/polls/${e}`),{success:o}=r,s=Object.assign(Object.assign({},n.data),{isDeleted:!0});return ze(["poll","get",e],s),ut("poll.deleted",{polls:[s],users:[]}),o},votePoll:async(e,t)=>{const n=we();n.log("user/votePoll",e);const{data:r}=await n.http.post(`/api/v3/polls/${encodeURIComponent(e)}/votes`,{pollId:e,answerIds:t}),o=n.cache&&Date.now();n.cache&&Xi(r,{cachedAt:o});const{polls:s}=r;return ut("poll.updated",r),{data:s.find((t=>t.pollId===e)),cachedAt:o}},onPollUpdated:Yd,onPollDeleted:Xd,observePoll:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observePoll(tmpid: ${o}) > listen`);const s=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},i=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.pollId)===e&&s(t,n)},a=[];return a.push(Yd((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),Xd((e=>i({data:e,loading:!1,origin:"event"},"onDelete")))),se(re(Gd,e),(e=>(e.data||e.error)&&s(e,"onFetch")),oe(n)),()=>{r(`observePoll(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}}});return e.API_REGIONS=Nt,e.CategoryRepository=Nd,e.ChannelRepository=Kl,e.Client=Ac,e.CommentRepository=Wd,e.CommunityPostSettingMaps=n,e.CommunityPostSettings=t,e.CommunityRepository=Md,e.ContentFeedType=o,e.DefaultCommunityPostSetting=r,e.FeedRepository=Dd,e.FileRepository=Zc,e.FileType=s,e.MessageContentType=l,e.MessageRepository=Xu,e.PollRepository=Zd,e.PostContentType=u,e.PostRepository=zd,e.ReactionRepository=xl,e.StreamRepository=Jd,e.SubChannelRepository=od,e.UserRepository=Yc,e.VERSION=d,e.VideoResolution=i,e.VideoSize=c,e.VideoTranscodingStatus=a,e.backupCache=async(e="amitySdk",t=(e=>e.offline))=>{const{log:n,cache:r,userId:o}=we();if(!r)return!1;n("cache/api/backupCache",{storageKey:e});const s=Object.fromEntries(Object.entries(r.data).filter((([e,n])=>t(n))));return!!Object.keys(s).length&&(await Ue.setItem(`${e}#${o}`,JSON.stringify(s)),!0)},e.createQuery=re,e.createReport=async(e,t)=>{const n=we();n.log("report/createReport",{referenceType:e,referenceId:t});const{data:r}=await n.http.post((()=>{if("user"===e)return`/api/v4/me/flags/${encodeURIComponent(t)}`;if("message"===e)return`/api/v5/messages/${encodeURIComponent(t)}/flags`;const{domainName:n}=Rl[e];return`/api/v3/${n}/${encodeURIComponent(t)}/flag`})());if(n.cache)if("message"===e){const e=await qa(r);Xi(e)}else Xi("post"===e?ta(r,"communityUsers"):r);return ut(`${e}.flagged`,r),!!r},e.createUserToken=async(e,t,n)=>{const r=Ki(),o=Qi(),s=kr(Ut("http",t)),{data:i}=await s.post("/api/v4/sessions",Object.assign(Object.assign({},n),{deviceId:r,deviceInfo:Object.assign(Object.assign({},o),{model:"token management API on TS-SDK"})}),{headers:{"X-API-Key":e}});return{accessToken:i.accessToken}},e.deleteReport=async(e,t)=>{const n=we();n.log("report/deleteReport",{referenceType:e,referenceId:t});const{data:r}=await n.http.delete((()=>{if("user"===e)return`/api/v4/me/flags/${encodeURIComponent(t)}`;if("message"===e)return`/api/v5/messages/${encodeURIComponent(t)}/flags`;const{domainName:n}=Rl[e];return`/api/v3/${n}/${encodeURIComponent(t)}/unflag`})());if(n.cache)if("message"===e){const e=await qa(r);Xi(e)}else Xi("post"===e?ta(r,"communityUsers"):r);return ut(`${e}.unflagged`,r),!!r},e.disableCache=()=>{const e=we();e.cache&&(e.log("cache/api/disableCache"),delete e.cache)},e.dropFromCache=He,e.enableCache=(e={},t)=>{const n=we();n.cache||(n.log("cache/api/enableCache"),n.cache={data:e,persistIf:t})},e.filterByChannelMembership=Ke,e.filterByCommunityMembership=Je,e.filterByFeedType=Qe,e.filterByPostDataTypes=Ge,e.filterByPropEquality=Ve,e.filterByPropInclusion=(e,t,n)=>void 0!==n?e.filter((e=>n.includes(e[t]))):e,e.filterByPropIntersection=We,e.filterBySearchTerm=Ye,e.getChannelMarkers=ua,e.getChannelTopic=e=>`${e.path}/#`,e.getCommentTopic=({path:e})=>e,e.getCommunityTopic=({path:t},n=e.SubscriptionLevels.COMMUNITY)=>gt(t,n),e.getMarkedMessageTopic=vt,e.getMessageMarkers=Ra,e.getMessageTopic=e=>e.path,e.getMyFollowersTopic=()=>{const e=ht();return`${mt(e)}/membership/${e._id}/+/+`},e.getMyFollowingsTopic=()=>{const e=ht();return`${mt(e)}/membership/+/${e._id}/+`},e.getNetworkTopic=bt,e.getPostTopic=({path:t},n=e.SubscriptionLevels.POST)=>"comment"===n?`${t}/comment/+`:t,e.getRole=tl,e.getSmartFeedChannelTopic=wt,e.getSmartFeedMessageTopic=_t,e.getSmartFeedSubChannelTopic=Ct,e.getSubChannelMarkers=Pa,e.getSubChannelTopic=e=>`${e.path}/#`,e.getUserMarker=ja,e.getUserTopic=yt,e.isAfterBefore=W,e.isAfterBeforeRaw=K,e.isCachable=te,e.isFetcher=X,e.isFresh=ne,e.isLocal=e=>te(e)&&-1===(null==e?void 0:e.cachedAt),e.isMutator=Z,e.isOffline=ee,e.isPaged=Q,e.isReportedByMe=async(e,t)=>{var n,r;const o=we();o.log("report/isReportedByMe",{referenceType:e,referenceId:t});const{eventName:s,primaryKey:i}=Rl[e];if("message"===e){const{data:e}=await o.http.get(`/api/v5/messages/${encodeURIComponent(t)}/flags`);return e.result}const{result:a,isFlagByMe:c}=null!==(n=await Di(o,s,{[i]:t}))&&void 0!==n?n:{};return null!==(r=null!=a?a:c)&&void 0!==r&&r},e.isSkip=V,e.mergeInCache=$e,e.onChannelMarkerFetched=e=>{const t=we();return lt(t,"channelMarker/onChannelMarkerFetched","local.channelMarker.fetched",(t=>{e(t.userEntityMarkers[0])}))},e.onFeedMarkerFetched=e=>{const t=we();return lt(t,"feedMarker/onFeedMarkerFetched","local.feedMarker.fetched",(t=>{e(t.feedMarkers[0])}))},e.onFeedMarkerUpdated=Fa,e.onMessageMarked=e=>{const t=we();return lt(t,"messageMarker/onMessageMarked","marker.marked-message",(t=>{e(t.contentMarkers[0])}))},e.onMessageMarkerFetched=e=>{const t=we();return lt(t,"messageMarker/onMessageMarkerFetched","local.messageMarker.fetched",(t=>{e(t.contentMarkers[0])}))},e.onSubChannelMarkerFetched=e=>{const t=we();return lt(t,"subChannelMarker/onSubChannelMarkerFetched","local.subChannelMarker.fetched",(t=>{e(t.userFeedMarkers[0])}))},e.onSubChannelMarkerUpdated=e=>{const t=we();return lt(t,"subChannelMarker/onSubChannelMarkerUpdated","local.subChannelMarker.updated",(t=>{e(t.userFeedMarkers[0])}))},e.onUserMarkerFetched=Na,e.pullFromCache=Le,e.pushToCache=qe,e.queryCache=De,e.queryOptions=oe,e.queryRoles=el,e.restoreCache=async(e="amitySdk")=>{var t;const n=we();if(!n.cache)return!1;n.log("cache/api/restoreCache",{storageKey:e});const r=null!==(t=await Ue.getItem(`${e}#${n.userId}`))&&void 0!==t?t:"{}";let o={};try{o=JSON.parse(r)}catch(e){}return n.cache.data=Object.assign(Object.assign({},o),n.cache.data),!0},e.runQuery=se,e.sortByChannelSegment=({channelSegment:e},{channelSegment:t})=>e-t,e.sortByDisplayName=Xe,e.sortByFirstCreated=et,e.sortByLastActivity=nt,e.sortByLastCreated=tt,e.sortByName=Ze,e.sortBySegmentNumber=({segmentNumber:e},{segmentNumber:t})=>e-t,e.subscribeTopic=At,e.toPage=G,e.toPageRaw=Y,e.toToken=J,e.upsertInCache=ze,e.wipeCache=async(e="amitySdk")=>{const{log:t,cache:n,userId:r}=we();return!!n&&(t("cache/api/wipeCache",{storageKey:e}),n.data={},await Ue.setItem(`${e}#${r}`,"{}"),!0)},Object.defineProperty(e,"__esModule",{value:!0}),e}({});