@amityco/ts-sdk 6.0.0 → 6.0.1-4e89646.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.
- package/dist/@types/domains/channel.d.ts +1 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/channel/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/domains/channel.ts +1 -0
- package/src/channel/utils/prepareChannelPayload.ts +1 -0
- package/src/channel/utils/tests/prepareChannelPayload.test.ts +18 -3
- package/src/utils/tests/dummy/channel.ts +2 -0
package/dist/index.umd.js
CHANGED
|
@@ -3,4 +3,4 @@ var Amity=function(e){"use strict";const t=Object.freeze({ONLY_ADMIN_CAN_POST:"O
|
|
|
3
3
|
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
4
4
|
n.read=function(e,t,n,r,o){var i,s,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,i=f&(1<<-u)-1,f>>=-u,u+=a;u>0;i=256*i+e[t+d],d+=h,u-=8);for(s=i&(1<<-u)-1,i>>=-u,u+=r;u>0;s=256*s+e[t+d],d+=h,u-=8);if(0===i)i=1-l;else{if(i===c)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,r),i-=l}return(f?-1:1)*s*Math.pow(2,i-r)},n.write=function(e,t,n,r,o,i){var s,a,c,l=8*i-o-1,u=(1<<l)-1,d=u>>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,f=r?0:i-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,s=u):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+d>=1?h/c:h*Math.pow(2,1-d))*c>=2&&(s++,c/=2),s+d>=u?(a=0,s=u):s+d>=1?(a=(t*c-1)*Math.pow(2,o),s+=d):(a=t*Math.pow(2,d-1)*Math.pow(2,o),s=0));o>=8;e[n+f]=255&a,f+=p,a/=256,o-=8);for(s=s<<o|a,l+=o;l>0;e[n+f]=255&s,f+=p,s/=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,i=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=i,t&&(t.brother=r),this.parent=r,this.brother=i,this.leftChild=n,this.rightChild=o,i&&(i.parent=r,i.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,i=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=i,this.rightChild=r,i&&(i.parent=this,i.brother=r),r&&(r.parent=this,r.brother=i),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,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(e){return function(t){return c([e,t])}}function c(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}};function o(e){var t=this;void 0===e&&(e=[]);var n=[],i=0,s=0,a=0,c=0,l=0,u=0;this.size=function(){return u},this.empty=function(){return 0===u},this.clear=function(){i=a=s=c=l=u=0,h.call(this,o.bucketSize),u=0},this.front=function(){return n[i][s]},this.back=function(){return n[a][c]},this.forEach=function(e){if(!this.empty()){var t=0;if(i!==a){for(l=s;l<o.bucketSize;++l)e(n[i][l],t++);for(l=i+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=s;l<=c;++l)e(n[i][l],t++)}};var d=function(e){var t=i*o.bucketSize+s,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,i=p,s=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:i<a&&(--a,c=o.bucketSize-1)),u>0&&--u)},this.setElementByPos=function(e,t){var r=d(e),o=r.curNodeBucketIndex,i=r.curNodePointerIndex;n[o][i]=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=[],i=e;i<u;++i)o.push(this.getElementByPos(i));for(this.cut(e-1),i=0;i<n;++i)this.pushBack(t);o.forEach((function(e){return r.pushBack(e)}))}},this.find=function(e){if(i===a){for(var t=s;t<=c;++t)if(n[i][t]===e)return!0;return!1}for(t=s;t<o.bucketSize;++t)if(n[i][t]===e)return!0;for(t=i+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===i&&0===s&&h.call(this,this.size()),s>0?--s:i>0&&(--i,s=o.bucketSize-1)),++u,n[i][s]=e},this.popFront=function(){this.empty()||(1!==this.size()&&(s<o.bucketSize-1?++s:i<a&&(++i,s=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 i=Math.ceil(r/o.bucketSize),s=0;s<i;++s)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(i!==a)return[3,5];t=s,r.label=1;case 1:return t<=c?[4,n[i][t]]:[3,4];case 2:r.sent(),r.label=3;case 3:return++t,[3,1];case 4:return[2];case 5:t=s,r.label=6;case 6:return t<o.bucketSize?[4,n[i][t]]:[3,9];case 7:r.sent(),r.label=8;case 8:return++t,[3,6];case 9:t=i+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 s=r*o.sigma;l=Math.ceil(s/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);i=Math.floor(l/2)-Math.floor(u/2),a=i,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,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(e){return function(t){return c([e,t])}}function c(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[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 i=e("../LinkList/LinkList"),s=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,i="";if("number"==typeof e)r=((r=Math.floor(e))<<5)-r,r&=r;else{i="string"!=typeof e?JSON.stringify(e):e;try{for(var s=o(i),a=s.next();!a.done;a=s.next())r=(r<<5)-r+a.value.charCodeAt(0),r&=r}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}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 i.default&&1===r.size()){var c=r.front(),l=c.key,h=c.value;t[n(l)&d-1]=new i.default([{key:l,value:h}])}else if(r instanceof s.default){var f=new i.default,p=new i.default;r.forEach((function(t){0==(n(t.key)&e)?f.pushBack(t):p.pushBack(t)})),f.size()>a.untreeifyThreshold?t[o]=new s.default(f):f.size()&&(t[o]=f),p.size()>a.untreeifyThreshold?t[o+e]=new s.default(p):p.size()&&(t[o+e]=p)}else{var g=new i.default,m=new i.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 i.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 s.default(u[f]))}else u[f].setElement(e,t);var v=u[f].size();l+=v-p}else++l,u[f]=new i.default([{key:e,value:t}]);l>d*a.sigma&&h.call(this,d)}else this.eraseElementByKey(e)},this.getElementByKey=function(e){var t,r,i=n(e)&d-1;if(u[i]){if(u[i]instanceof s.default)return u[i].getElementByKey(e);try{for(var a=o(u[i]),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 s.default)u[c].eraseElementByKey(e),u[c].size()<=a.untreeifyThreshold&&(u[c]=new i.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,i=n(e)&d-1;if(!u[i])return!1;if(u[i]instanceof s.default)return u[i].find(e);try{for(var a=o(u[i]),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,i,s,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]),s=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 i=r.sent(),s={error:i},[3,9];case 8:try{n&&!n.done&&(a=t.return)&&a.call(t)}finally{if(s)throw s.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,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(e){return function(t){return c([e,t])}}function c(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[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 i=e("../Set/Set"),s=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 s.default&&1===r.size()){var c=r.front();if(void 0===c)throw new Error("unknown error");t[n(c)&d-1]=new s.default([c])}else if(r instanceof i.default){var l=new s.default,h=new s.default;r.forEach((function(t){0==(n(t)&e)?l.pushBack(t):h.pushBack(t)})),l.size()>a.untreeifyThreshold?t[o]=new i.default(l):l.size()&&(t[o]=l),h.size()>a.untreeifyThreshold?t[o+e]=new i.default(h):h.size()&&(t[o+e]=h)}else{var f=new s.default,p=new s.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 s.default){if(u[t].find(e))return;u[t].pushBack(e),u[t].size()>=a.treeifyThreshold&&(u[t]=new i.default(u[t]))}else u[t].insert(e);var o=u[t].size();l+=o-r}else u[t]=new s.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 i.default&&u[t].size()<=a.untreeifyThreshold&&(u[t]=new s.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,i,s,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]),s=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 i=r.sent(),s={error:i},[3,9];case 8:try{n&&!n.done&&(a=t.return)&&a.call(t)}finally{if(s)throw s.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,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(e){return function(t){return c([e,t])}}function c(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[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 i(e){var t=this;void 0===e&&(e=[]);var n=0,i=void 0,s=void 0;this.size=function(){return n},this.empty=function(){return 0===n},this.clear=function(){i=s=void 0,n=0},this.front=function(){return null==i?void 0:i.value},this.back=function(){return null==s?void 0:s.value},this.forEach=function(e){for(var t=i,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=i;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=i;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(;i&&i.value===e;)this.popFront();for(;s&&s.value===e;)this.popBack();if(i)for(var t=i;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);s?(s.next=t,t.pre=s,s=t):i=s=t},this.popBack=function(){s&&(n>0&&--n,s&&(i===s?i=s=void 0:(s=s.pre)&&(s.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=i;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 s=i,a=1;a<e;++a){if(!(null==s?void 0:s.next))throw new Error("unknown error");s=null==s?void 0:s.next}if(!s)throw new Error("unknown error");var c=s.next;for(n+=r;r--;)s.next=new o(t),s.next.pre=s,s=s.next;s.next=c,c&&(c.pre=s)}},this.find=function(e){for(var t=i;t;){if(t.value===e)return!0;t=t.next}return!1},this.reverse=function(){for(var e=i,t=s,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=i;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=i;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);i?(t.next=i,i.pre=t,i=t):i=s=t},this.popFront=function(){i&&(n>0&&--n,i&&(i===s?i=s=void 0:(i=i.next)&&(i.pre=void 0)))},this.merge=function(e){var t=this,r=i;e.forEach((function(e){for(;r&&void 0!==r.value&&r.value<=e;)r=r.next;if(void 0===r)t.pushBack(e),r=s;else if(r===i)t.pushFront(e),r=i;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=i,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(i),n.default=i},{}],30:[function(e,t,n){var r=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(e){return function(t){return c([e,t])}}function c(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[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 i=e("../Base/TreeNode");function s(e,t){var n=this;void 0===e&&(e=[]),t=t||function(e,t){return e<t?-1:e>t?1:0};var s=0,a=new i.default;a.color=i.default.TreeNodeColorType.black,this.size=function(){return s},this.empty=function(){return 0===s},this.clear=function(){s=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 i=o(this),s=i.next();!s.done;s=i.next())e(s.value,r++)}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}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 i=o(this),s=i.next();!s.done;s=i.next()){var a=s.value;if(r===e)return a;++r}}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}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!==i.default.TreeNodeColorType.red){var n=e.brother;if(!n)throw new Error("unknown error");if(e===t.leftChild)if(n.color===i.default.TreeNodeColorType.red){n.color=i.default.TreeNodeColorType.black,t.color=i.default.TreeNodeColorType.red;var r=t.rotateLeft();a===t&&(a=r),p(e)}else n.color===i.default.TreeNodeColorType.black&&(n.rightChild&&n.rightChild.color===i.default.TreeNodeColorType.red?(n.color=t.color,t.color=i.default.TreeNodeColorType.black,n.rightChild&&(n.rightChild.color=i.default.TreeNodeColorType.black),r=t.rotateLeft(),a===t&&(a=r),e.color=i.default.TreeNodeColorType.black):n.rightChild&&n.rightChild.color!==i.default.TreeNodeColorType.black||!n.leftChild||n.leftChild.color!==i.default.TreeNodeColorType.red?n.leftChild&&n.leftChild.color!==i.default.TreeNodeColorType.black||n.rightChild&&n.rightChild.color!==i.default.TreeNodeColorType.black||(n.color=i.default.TreeNodeColorType.red,p(t)):(n.color=i.default.TreeNodeColorType.red,n.leftChild&&(n.leftChild.color=i.default.TreeNodeColorType.black),r=n.rotateRight(),a===n&&(a=r),p(e)));else e===t.rightChild&&(n.color===i.default.TreeNodeColorType.red?(n.color=i.default.TreeNodeColorType.black,t.color=i.default.TreeNodeColorType.red,r=t.rotateRight(),a===t&&(a=r),p(e)):n.color===i.default.TreeNodeColorType.black&&(n.leftChild&&n.leftChild.color===i.default.TreeNodeColorType.red?(n.color=t.color,t.color=i.default.TreeNodeColorType.black,n.leftChild&&(n.leftChild.color=i.default.TreeNodeColorType.black),r=t.rotateRight(),a===t&&(a=r),e.color=i.default.TreeNodeColorType.black):n.leftChild&&n.leftChild.color!==i.default.TreeNodeColorType.black||!n.rightChild||n.rightChild.color!==i.default.TreeNodeColorType.red?n.leftChild&&n.leftChild.color!==i.default.TreeNodeColorType.black||n.rightChild&&n.rightChild.color!==i.default.TreeNodeColorType.black||(n.color=i.default.TreeNodeColorType.red,p(t)):(n.color=i.default.TreeNodeColorType.red,n.rightChild&&(n.rightChild.color=i.default.TreeNodeColorType.black),r=n.rotateLeft(),a===n&&(a=r),p(e))))}else e.color=i.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(),--s,a.color=i.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>=s)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 i.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 i.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!==i.default.TreeNodeColorType.black&&t.color===i.default.TreeNodeColorType.red){var n=t.brother,r=t.parent;if(!r)throw new Error("unknown error");if(n&&n.color===i.default.TreeNodeColorType.red)n.color=t.color=i.default.TreeNodeColorType.black,r.color=i.default.TreeNodeColorType.red,v(r);else if(!n||n.color===i.default.TreeNodeColorType.black)if(t===r.leftChild)if(e===t.leftChild){t.color=i.default.TreeNodeColorType.black,r.color=i.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=i.default.TreeNodeColorType.black,r.color=i.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++s,a.key=e,a.value=n,void(a.color=i.default.TreeNodeColorType.black);var r=y(a,e);void 0===r.key||0!==t(r.key,e)?(++s,r.key=e,r.value=n,v(r),a.color=i.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(s),n.default=s},{"../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},i=function(e){if(e<0||e>=r)throw new Error("unknown error");var i=2*e+1,s=2*e+2;i<r&&t(n[e],n[i])>0&&o(e,i),s<r&&t(n[e],n[s])>0&&o(e,s)};!function(){for(var e=Math.floor((r-1)/2);e>=0;--e)for(var i=e,s=2*i+1;s<r;){var a=s+1,c=s;if(a<r&&t(n[s],n[a])>0&&(c=a),t(n[i],n[c])<=0)break;o(i,c),s=2*(i=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 s=Math.floor((o-1)/2);if(t(n[s],e)<=0)break;i(s),o=s}},this.pop=function(){if(!this.empty())if(1!==this.size()){var e=n[r-1];--r;for(var o=0;o<this.size();){var i=2*o+1,s=2*o+2;if(i>=this.size())break;var a=i;if(s<this.size()&&t(n[i],n[s])>0&&(a=s),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,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(e){return function(t){return c([e,t])}}function c(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[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 i=e("../Base/TreeNode");function s(e,t){var n=this;void 0===e&&(e=[]),t=t||function(e,t){return e<t?-1:e>t?1:0};var s=0,a=new i.default;a.color=i.default.TreeNodeColorType.black,this.size=function(){return s},this.empty=function(){return 0===s},this.clear=function(){s=0,a.key=void 0,a.leftChild=a.rightChild=a.brother=a.parent=void 0,a.color=i.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 i=o(this),s=i.next();!s.done;s=i.next())e(s.value,r++)}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}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 i=o(this),s=i.next();!s.done;s=i.next()){var a=s.value;if(r===e)return a;++r}}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}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!==i.default.TreeNodeColorType.red){var n=e.brother;if(!n)throw new Error("unknown error");if(e===t.leftChild)if(n.color===i.default.TreeNodeColorType.red){n.color=i.default.TreeNodeColorType.black,t.color=i.default.TreeNodeColorType.red;var r=t.rotateLeft();a===t&&(a=r),u(e)}else n.color===i.default.TreeNodeColorType.black&&(n.rightChild&&n.rightChild.color===i.default.TreeNodeColorType.red?(n.color=t.color,t.color=i.default.TreeNodeColorType.black,n.rightChild&&(n.rightChild.color=i.default.TreeNodeColorType.black),r=t.rotateLeft(),a===t&&(a=r),e.color=i.default.TreeNodeColorType.black):n.rightChild&&n.rightChild.color!==i.default.TreeNodeColorType.black||!n.leftChild||n.leftChild.color!==i.default.TreeNodeColorType.red?n.leftChild&&n.leftChild.color!==i.default.TreeNodeColorType.black||n.rightChild&&n.rightChild.color!==i.default.TreeNodeColorType.black||(n.color=i.default.TreeNodeColorType.red,u(t)):(n.color=i.default.TreeNodeColorType.red,n.leftChild&&(n.leftChild.color=i.default.TreeNodeColorType.black),r=n.rotateRight(),a===n&&(a=r),u(e)));else e===t.rightChild&&(n.color===i.default.TreeNodeColorType.red?(n.color=i.default.TreeNodeColorType.black,t.color=i.default.TreeNodeColorType.red,r=t.rotateRight(),a===t&&(a=r),u(e)):n.color===i.default.TreeNodeColorType.black&&(n.leftChild&&n.leftChild.color===i.default.TreeNodeColorType.red?(n.color=t.color,t.color=i.default.TreeNodeColorType.black,n.leftChild&&(n.leftChild.color=i.default.TreeNodeColorType.black),r=t.rotateRight(),a===t&&(a=r),e.color=i.default.TreeNodeColorType.black):n.leftChild&&n.leftChild.color!==i.default.TreeNodeColorType.black||!n.rightChild||n.rightChild.color!==i.default.TreeNodeColorType.red?n.leftChild&&n.leftChild.color!==i.default.TreeNodeColorType.black||n.rightChild&&n.rightChild.color!==i.default.TreeNodeColorType.black||(n.color=i.default.TreeNodeColorType.red,u(t)):(n.color=i.default.TreeNodeColorType.red,n.rightChild&&(n.rightChild.color=i.default.TreeNodeColorType.black),r=n.rotateLeft(),a===n&&(a=r),u(e))))}else e.color=i.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(),--s,a.color=i.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>=s)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 i.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 i.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!==i.default.TreeNodeColorType.black&&t.color===i.default.TreeNodeColorType.red){var n=t.brother,r=t.parent;if(!r)throw new Error("unknown error");if(n&&n.color===i.default.TreeNodeColorType.red)n.color=t.color=i.default.TreeNodeColorType.black,r.color=i.default.TreeNodeColorType.red,p(r);else if(!n||n.color===i.default.TreeNodeColorType.black)if(t===r.leftChild)if(e===t.leftChild){t.color=i.default.TreeNodeColorType.black,r.color=i.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=i.default.TreeNodeColorType.black,r.color=i.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++s,a.key=e,void(a.color=i.default.TreeNodeColorType.black);var n=f(a,e);void 0!==n.key&&0===t(n.key,e)||(++s,n.key=e,p(n),a.color=i.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(s),n.default=s},{"../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,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(e){return function(t){return c([e,t])}}function c(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[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,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},i=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;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))},s=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,i([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,s(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 i=e("./Queue/Queue");n.Queue=i.default;var s=e("./LinkList/LinkList");n.LinkList=s.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"),i=Symbol("length"),s=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[s]="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[s]&&(this[s]=e,this[i]=0,this[d].forEach((e=>{e.length=this[s](e.value,e.key),this[i]+=e.length}))),v(this)}get lengthCalculator(){return this[s]}get length(){return this[i]}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[i]=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[s](t,e);if(this[h].has(e)){if(a>this[o])return b(this,this[h].get(e)),!1;const s=this[h].get(e).value;return this[l]&&(this[u]||this[l](e,s.value)),s.now=r,s.maxAge=n,s.value=t,this[i]+=a-s.length,s.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[i]+=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[i]>e[o])for(let t=e[d].tail;e[i]>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[i]-=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((i=>{const s=e.alloc(1);return s.writeUInt8(n.codes[t]<<n.CMD_SHIFT|(o?n.DUP_MASK:0)|r<<n.QOS_SHIFT|i,0,!0),s}))))))}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 i(e,t){const n=new s;return r(e,n,t),n.concat()}class s 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,i=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 s=n.allocUnsafe(e);for(o=0;o<r.length&&void 0!==r[o];o++)"string"!=typeof r[o]?(r[o].copy(s,i),i+=t[o]):(s.write(r[o],i),i+=t[o]);return s}}t.exports=i}).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 i(t){const n=e.allocUnsafe(2);return n.writeUInt8(t>>8,0),n.writeUInt8(255&t,1),n}function s(){for(let e=0;e<n;e++)r[e]=i(e)}function a(t){const n=4;let r=0,i=0;const s=e.allocUnsafe(n);do{r=t%128|0,(t=t/128|0)>0&&(r|=128),s.writeUInt8(r,i++)}while(t>0&&i<n);return t>0&&(i=0),o?s.subarray(0,i):s.slice(0,i)}function c(t){const n=e.allocUnsafe(4);return n.writeUInt32BE(t,0),n}t.exports={cache:r,generateCache:s,generateNumber:i,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"),i=e("./packet"),s=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 i,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=s.types[e>>s.CMD_SHIFT],this.packet.retain=0!=(e&s.RETAIN_MASK),this.packet.qos=e>>s.QOS_SHIFT&s.QOS_MASK,this.packet.dup=0!=(e&s.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={},i=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(i.protocolId=c,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(i.protocolVersion=this._list.readUInt8(this._pos),i.protocolVersion>=128&&(i.bridgeMode=!0,i.protocolVersion=i.protocolVersion-128),3!==i.protocolVersion&&4!==i.protocolVersion&&5!==i.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)&s.USERNAME_MASK,o.password=this._list.readUInt8(this._pos)&s.PASSWORD_MASK,o.will=this._list.readUInt8(this._pos)&s.WILL_FLAG_MASK,o.will&&(i.will={},i.will.retain=0!=(this._list.readUInt8(this._pos)&s.WILL_RETAIN_MASK),i.will.qos=(this._list.readUInt8(this._pos)&s.WILL_QOS_MASK)>>s.WILL_QOS_SHIFT),i.clean=0!=(this._list.readUInt8(this._pos)&s.CLEAN_SESSION_MASK),this._pos++,i.keepalive=this._parseNum(),-1===i.keepalive)return this._emitError(new Error("Packet too short"));if(5===i.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(i.properties=e)}const l=this._parseString();if(null===l)return this._emitError(new Error("Packet too short"));if(i.clientId=l,a("_parseConnect: packet.clientId: %s",i.clientId),o.will){if(5===i.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(i.will.properties=e)}if(e=this._parseString(),null===e)return this._emitError(new Error("Cannot parse will topic"));if(i.will.topic=e,a("_parseConnect: packet.will.topic: %s",i.will.topic),t=this._parseBuffer(),null===t)return this._emitError(new Error("Cannot parse will payload"));i.will.payload=t,a("_parseConnect: packet.will.paylaod: %s",i.will.payload)}if(o.username){if(r=this._parseString(),null===r)return this._emitError(new Error("Cannot parse username"));i.username=r,a("_parseConnect: packet.username: %s",i.username)}if(o.password){if(n=this._parseBuffer(),null===n)return this._emitError(new Error("Cannot parse password"));i.password=n}return this.settings=i,a("_parseConnect: complete"),i}_parseConnack(){a("_parseConnack");const e=this.packet;if(this._list.length<1)return null;if(e.sessionPresent=!!(this._list.readUInt8(this._pos++)&s.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,i,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&s.SUBSCRIBE_OPTIONS_QOS_MASK,c=0!=(n>>s.SUBSCRIBE_OPTIONS_NL_SHIFT&s.SUBSCRIBE_OPTIONS_NL_MASK),i=0!=(n>>s.SUBSCRIBE_OPTIONS_RAP_SHIFT&s.SUBSCRIBE_OPTIONS_RAP_MASK),o=n>>s.SUBSCRIBE_OPTIONS_RH_SHIFT&s.SUBSCRIBE_OPTIONS_RH_MASK,l={topic:t,qos:r},5===this.settings.protocolVersion?(l.nl=c,l.rap=i,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,i=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++),i+=o*(n&s.VARBYTEINT_MASK),o*=128,0==(n&s.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:i}:i),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=s.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(s.propertiesTypes[t]))):n[t]=this._parseByType(s.propertiesTypes[t]);else{n[t]||(n[t]=Object.create(null));const e=this._parseByType(s.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 i,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),i=n.from([0]),s=e("./numbers"),a=e("process-nextick-args").nextTick,c=e("debug")("mqtt-packet:writeToStream"),l=s.cache,u=s.generateNumber,d=s.generateCache,h=s.genBufVariableByteInt,f=s.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 E(e,t,n);case"pingreq":case"pingresp":return A(e,t);case"disconnect":return I(e,t,n);case"auth":return T(e,t,n);default:return t.emit("error",new Error("Unknown command")),!1}}function y(e){e.uncork()}function v(e,t,o){const i=e||{},s=i.protocolId||"MQTT";let a=i.protocolVersion||4;const c=i.will;let l=i.clean;const u=i.keepalive||0,d=i.clientId||"",h=i.username,f=i.password,g=i.properties;void 0===l&&(l=!0);let m=0;if(!s||"string"!=typeof s&&!n.isBuffer(s))return t.emit("error",new Error("Invalid protocolId")),!1;if(m+=s.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(!z(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(!z(f))return t.emit("error",new Error("Invalid password")),!1;m+=q(f)+2}t.write(r.CONNECT_HEADER),x(t,m),F(t,s),i.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(),F(t,d),c&&(5===a&&v.write(),R(t,c.topic),F(t,c.payload)),null!=h&&F(t,h),null!=f&&F(t,f),!0}function b(e,t,o){const s=o?o.protocolVersion:4,a=e||{},c=5===s?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===s){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:i),t.write(n.from([c])),null!=d&&d.write(),!0}function w(e,t,i){c("publish: packet: %o",e);const s=i?i.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===s){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 i=o?o.protocolVersion:4,s=e||{},a=s.cmd||"puback",c=s.messageId,l=s.dup&&"pubrel"===a?r.DUP_MASK:0;let u=0;const d=s.reasonCode,h=s.properties;let f=5===i?3:2;if("pubrel"===a&&(u=1),"number"!=typeof c)return t.emit("error",new Error("Invalid messageId")),!1;let g=null;if(5===i&&"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===i&&t.write(n.from([d])),null!==g&&g.write(),!0}function _(e,t,o){c("subscribe: packet: ");const i=o?o.protocolVersion:4,s=e||{},a=s.dup?r.DUP_MASK:0,l=s.messageId,u=s.subscriptions,d=s.properties;let h=0;if("number"!=typeof l)return t.emit("error",new Error("Invalid messageId")),!1;h+=2;let f=null;if(5===i){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===i){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,s=e.qos,a=+e.nl,c=+e.rap,l=e.rh;let u;R(t,o),u=r.SUBSCRIBE_OPTIONS_QOS[s],5===i&&(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 i=o?o.protocolVersion:4,s=e||{},a=s.messageId,c=s.granted,l=s.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===i){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 i=o?o.protocolVersion:4,s=e||{},a=s.messageId,c=s.dup?r.DUP_MASK:0,l=s.unsubscriptions,u=s.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===i){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 E(e,t,o){const i=o?o.protocolVersion:4,s=e||{},a=s.messageId,c=s.dup?r.DUP_MASK:0,l=s.granted,u=s.properties,d=s.cmd,h=0;let f=2;if("number"!=typeof a)return t.emit("error",new Error("Invalid messageId")),!1;if(5===i){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===i){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===i&&t.write(n.from(l)),!0}function A(e,t,n){return t.write(r.EMPTY[e.cmd])}function I(e,t,o){const i=o?o.protocolVersion:4,s=e||{},a=s.reasonCode,c=s.properties;let l=5===i?1:0,u=null;if(5===i){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===i&&t.write(n.from([a])),null!==u&&u.write(),!0}function T(e,t,o){const i=o?o.protocolVersion:4,s=e||{},a=s.reasonCode,c=s.properties;let l=5===i?1:0;5!==i&&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 O={};function x(e,t){if(t>r.VARBYTEINT_MAX)return e.emit("error",new Error(`Invalid variable byte integer: ${t}`)),!1;let n=O[t];return n||(n=h(t),t<16384&&(O[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 N(e,t){const n=f(t);return c("write4ByteNumber: %o",n),e.write(n)}function F(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 i(t,o){let i=0;switch(r.propertiesTypes[t]){case"byte":if("boolean"!=typeof o)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;i+=2;break;case"int8":if("number"!=typeof o||o<0||o>255)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;i+=2;break;case"binary":if(o&&null===o)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;i+=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;i+=3;break;case"int32":if("number"!=typeof o||o<0||o>4294967295)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;i+=5;break;case"var":if("number"!=typeof o||o<0||o>268435455)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;i+=1+n.byteLength(h(o));break;case"string":if("string"!=typeof o)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;i+=3+n.byteLength(o.toString());break;case"pair":if("object"!=typeof o)return e.emit("error",new Error(`Invalid ${t}: ${o}`)),!1;i+=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 i}if(t)for(const e in t){let n=0,r=0;const s=t[e];if(Array.isArray(s))for(let t=0;t<s.length;t++){if(r=i(e,s[t]),!r)return!1;n+=r}else{if(r=i(e,s),!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"],i=n&&n.properties&&n.properties.maximumPacketSize?n.properties.maximumPacketSize:0;let s=B(e,t);if(i)for(;r+s.length>i;){const n=o.shift();if(!n||!t[n])return!1;delete t[n],s=B(e,t)}return s}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]])),F(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]])),N(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((i=>{const s=o[i];Array.isArray(s)?s.forEach((o=>{e.write(n.from([r.properties[t]])),P(e,i.toString(),o.toString())})):(e.write(n.from([r.properties[t]])),P(e,i.toString(),s.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 z(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,i=60*o,s=24*i,a=7*s,c=365.25*s;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*s;case"hours":case"hour":case"hrs":case"hr":case"h":return n*i;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>=s?Math.round(e/s)+"d":t>=i?Math.round(e/i)+"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>=s?h(e,t,s,"day"):t>=i?h(e,t,i,"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"),i=e("debug")("number-allocator:error");function s(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()}s.prototype.equals=function(e){return this.low===e.low&&this.high===e.high},s.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 s(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 s(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 i("free():"+e+" is out of range");const t=new s(e,e),n=this.ss.lowerBound(t);if(n){if(n.low<=e&&e<=n.high)return void i("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 s(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 i(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(i),o.proto=o((function(){Object.defineProperty(Function.prototype,"once",{value:function(){return o(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return i(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 i,s,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(i=new Array(a-1),s=0;s<i.length;)i[s++]=arguments[s];return e.nextTick((function(){t.apply(null,i)}))}}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,i=t.exports={};function s(){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===s||!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:s}catch(e){r=s}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(){}i.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)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=y,i.addListener=y,i.once=y,i.off=y,i.removeListener=y,i.removeAllListeners=y,i.emit=y,i.prependListener=y,i.prependOnceListener=y,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],51:[function(e,t,n){(function(e){(function(){!function(r){var o="object"==typeof n&&n&&!n.nodeType&&n,i="object"==typeof t&&t&&!t.nodeType&&t,s="object"==typeof e&&e;s.global!==s&&s.window!==s&&s.self!==s||(r=s);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 E(e){throw new RangeError(C[e])}function A(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+A((e=e.replace(w,".")).split("."),t).join(".")}function T(e){for(var t,n,r=[],o=0,i=e.length;o<i;)(t=e.charCodeAt(o++))>=55296&&t<=56319&&o<i?56320==(64512&(n=e.charCodeAt(o++)))?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),o--):r.push(t);return r}function O(e){return A(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,i,s,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&&E("not-basic"),v.push(e.charCodeAt(r));for(o=n>0?n+1:0;o<b;){for(i=w,s=1,a=u;o>=b&&E("invalid-input"),((c=x(e.charCodeAt(o++)))>=u||c>k((l-w)/s))&&E("overflow"),w+=c*s,!(c<(f=a<=_?d:a>=_+h?h:a-_));a+=u)s>k(l/(p=u-f))&&E("overflow"),s*=p;_=P(w-i,t=v.length+1,0==i),k(w/t)>l-C&&E("overflow"),C+=k(w/t),w%=t,v.splice(w++,0,C)}return O(v)}function j(e){var t,n,r,o,i,s,a,c,f,p,v,b,w,C,_,A=[];for(b=(e=T(e)).length,t=m,n=0,i=g,s=0;s<b;++s)(v=e[s])<128&&A.push(S(v));for(r=o=A.length,o&&A.push(y);r<b;){for(a=l,s=0;s<b;++s)(v=e[s])>=t&&v<a&&(a=v);for(a-t>k((l-n)/(w=r+1))&&E("overflow"),n+=(a-t)*w,t=a,s=0;s<b;++s)if((v=e[s])<t&&++n>l&&E("overflow"),v==t){for(c=n,f=u;!(c<(p=f<=i?d:f>=i+h?h:f-i));f+=u)_=c-p,C=u-p,A.push(S(R(p+_%C,0))),c=k(_/C);A.push(S(R(c,0))),i=P(n,w,r==o),n=0,++r}++n,++t}return A.join("")}function N(e){return I(e,(function(e){return v.test(e)?M(e.slice(4).toLowerCase()):e}))}function F(e){return I(e,(function(e){return b.test(e)?"xn--"+j(e):e}))}if(a={version:"1.4.1",ucs2:{decode:T,encode:O},decode:M,encode:j,toASCII:F,toUnicode:N},o&&i)if(t.exports==o)i.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,i){t=t||"&",n=n||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var c=1e3;i&&"number"==typeof i.maxKeys&&(c=i.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(s,f)?o(s[f])?s[f].push(p):s[f]=[s[f],p]:s[f]=p}return s};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?i(s(e),(function(s){var a=encodeURIComponent(r(s))+n;return o(e[s])?i(e[s],(function(e){return a+encodeURIComponent(r(e))})).join(t):a+encodeURIComponent(r(e[s]))})).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 i(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 s=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 i(e,t,n){function i(e,n,r){return"string"==typeof t?t:t(e,n,r)}n||(n=Error);var s=function(e){function t(t,n,r){return e.call(this,i(t,n,r))||this}return r(t,e),t}(n);s.prototype.name=n.name,s.prototype.code=e,o[e]=s}function s(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)}i("ERR_INVALID_OPT_VALUE",(function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),i("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(s(t,"type"));else{var i=l(e,".")?"property":"argument";o='The "'.concat(e,'" ').concat(i," ").concat(r," ").concat(s(t,"type"))}return o+=". Received type ".concat(typeof n)}),TypeError),i("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),i("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return"The "+e+" method is not implemented"})),i("ERR_STREAM_PREMATURE_CLOSE","Premature close"),i("ERR_STREAM_DESTROYED",(function(e){return"Cannot call "+e+" after a stream was destroyed"})),i("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),i("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),i("ERR_STREAM_WRITE_AFTER_END","write after end"),i("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),i("ERR_UNKNOWN_ENCODING",(function(e){return"Unknown encoding: "+e}),TypeError),i("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"),i=e("./_stream_writable");e("inherits")(l,o);for(var s=r(i.prototype),a=0;a<s.length;a++){var c=s[a];l.prototype[c]||(l.prototype[c]=i.prototype[c])}function l(e){if(!(this instanceof l))return new l(e);o.call(this,e),i.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=T,T.ReadableState=I,e("events").EventEmitter;var i=function(e,t){return e.listeners(t).length},s=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")(T,s);var S=y.errorOrDestroy,E=["error","close","destroy","pause","resume"];function A(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 T(t){if(o=o||e("./_stream_duplex"),!(this instanceof T))return new T(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)),s.call(this)}function O(e,t,n,r,o){d("readableAddChunk",t);var i,s=e._readableState;if(null===t)s.reading=!1,N(e,s);else if(o||(i=R(s,t)),i)S(e,i);else if(s.objectMode||t&&t.length>0)if("string"==typeof t||s.objectMode||Object.getPrototypeOf(t)===a.prototype||(t=l(t)),r)s.endEmitted?S(e,new k):x(e,s,t,!0);else if(s.ended)S(e,new C);else{if(s.destroyed)return!1;s.reading=!1,s.decoder&&!n?(t=s.decoder.write(t),s.objectMode||0!==t.length?x(e,s,t,!1):U(e,s)):x(e,s,t,!1)}else r||(s.reading=!1,U(e,s));return!s.ended&&(s.length<s.highWaterMark||0===s.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&&F(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(T.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),T.prototype.destroy=y.destroy,T.prototype._undestroy=y.undestroy,T.prototype._destroy=function(e,t){t(e)},T.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),O(this,e,t,!1,n)},T.prototype.unshift=function(e){return O(this,e,null,!0,!1)},T.prototype.isPaused=function(){return!1===this._readableState.flowing},T.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 N(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?F(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,B(e)))}}function F(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&&i(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 z(e){d("readable nexttick read 0"),e.read(0)}function $(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}T.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):F(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},T.prototype._read=function(e){S(this,new _("_read()"))},T.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 s=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(s):r.once("end",s),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===i(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),A(e,"error",p),e.once("close",g),e.once("finish",m),e.emit("pipe",r),o.flowing||(d("pipe resume"),r.resume()),e},T.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 i=0;i<o;i++)r[i].emit("unpipe",this,{hasUnpiped:!1});return this}var s=J(t.pipes,e);return-1===s||(t.pipes.splice(s,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,n)),this},T.prototype.on=function(e,t){var r=s.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?F(this):o.reading||n.nextTick(z,this))),r},T.prototype.addListener=T.prototype.on,T.prototype.removeListener=function(e,t){var r=s.prototype.removeListener.call(this,e,t);return"readable"===e&&n.nextTick(q,this),r},T.prototype.removeAllListeners=function(e){var t=s.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||n.nextTick(q,this),t},T.prototype.resume=function(){var e=this._readableState;return e.flowing||(d("resume"),e.flowing=!e.readableListening,$(this,e)),e.paused=!1,this},T.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},T.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 i=0;i<E.length;i++)e.on(E[i],this.emit.bind(this,E[i]));return this._read=function(t){d("wrapped _read",t),r&&(r=!1,e.resume())},this},"function"==typeof Symbol&&(T.prototype[Symbol.asyncIterator]=function(){return void 0===p&&(p=e("./internal/streams/async_iterator")),p(this)}),Object.defineProperty(T.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(T.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(T.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),T._fromList=W,Object.defineProperty(T.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(T.from=function(t,n){return void 0===g&&(g=e("./internal/streams/from")),g(T,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,i=r.ERR_MULTIPLE_CALLBACK,s=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 i);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 s;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 i;t.exports=I,I.WritableState=A;var s={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 E(){}function A(t,n,r){i=i||e("./_stream_duplex"),t=t||{},"boolean"!=typeof r&&(r=n instanceof i),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 s=!1===t.decodeStrings;this.decodeStrings=!s,this.defaultEncoding=t.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){N(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(i=i||e("./_stream_duplex"));if(!n&&!h.call(I,this))return new I(t);this._writableState=new A(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 T(e,t){var r=new _;S(e,r),n.nextTick(t,r)}function O(e,t,r,o){var i;return null===r?i=new C:"string"==typeof r||t.objectMode||(i=new m("chunk",["string","Buffer"],r)),!i||(S(e,i),n.nextTick(o,i),!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,i){if(!n){var s=x(t,r,o);r!==s&&(n=!0,o="buffer",r=s)}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:i,next:null},l?l.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else P(e,t,!1,a,r,o,i);return c}function P(e,t,n,r,o,i,s){t.writelen=r,t.writecb=s,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new w("write")):n?e._writev(o,t.onwrite):e._write(o,i,t.onwrite),t.sync=!1}function M(e,t,r,o,i){--t.pendingcb,r?(n.nextTick(i,o),n.nextTick(z,e,t),e._writableState.errorEmitted=!0,S(e,o)):(i(o),e._writableState.errorEmitted=!0,S(e,o),z(e,t))}function j(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function N(e,t){var r=e._writableState,o=r.sync,i=r.writecb;if("function"!=typeof i)throw new v;if(j(r),t)M(e,r,o,t,i);else{var s=D(r)||e.destroyed;s||r.corked||r.bufferProcessing||!r.bufferedRequest||U(e,r),o?n.nextTick(F,e,r,s,i):F(e,r,s,i)}}function F(e,t,n,r){n||B(e,t),t.pendingcb--,r(),z(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,i=new Array(r),s=t.corkedRequestsFree;s.entry=n;for(var a=0,c=!0;n;)i[a]=n,n.isBuf||(c=!1),n=n.next,a+=1;i.allBuffers=c,P(e,t,!0,t.length,i,"",s.finish),t.pendingcb++,t.lastBufferedRequest=null,s.next?(t.corkedRequestsFree=s.next,s.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"),z(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 z(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 $(e,t,r){t.ending=!0,z(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),A.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(A.prototype,"buffer",{get:s.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 A}})):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,i=!r.objectMode&&d(e);return i&&!c.isBuffer(e)&&(e=u(e)),"function"==typeof t&&(n=t,t=null),i?t="buffer":t||(t=r.defaultEncoding),"function"!=typeof n&&(n=E),r.ending?T(this,n):(i||O(this,r,e,n))&&(r.pendingcb++,o=R(this,r,i,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||$(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 i=e("./end-of-stream"),s=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[s];if(null!==t){var n=e[h].read();null!==n&&(e[u]=null,e[s]=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 i=this[h].read();if(null!==i)return Promise.resolve(f(i,!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,s,{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[s]=null,n[a]=null,e(f(r,!1))):(n[s]=e,n[a]=t)},writable:!0}),t));return n[u]=null,i(e,(function(e){if(e&&"ERR_STREAM_PREMATURE_CLOSE"!==e.code){var t=n[a];return null!==t&&(n[u]=null,n[s]=null,n[a]=null,t(e)),void(n[c]=e)}var r=n[s];null!==r&&(n[u]=null,n[s]=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){i(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 i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(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(){s(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,i=e>o.length?o.length:e;if(i===o.length?r+=o:r+=o.slice(0,e),0==(e-=i)){i===o.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=o.slice(i));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,i=e>o.length?o.length:e;if(o.copy(t,t.length-e,0,i),0==(e-=i)){i===o.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=o.slice(i));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 i=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(s,this,t)):e.nextTick(s,this,t)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(t||null,(function(t){!n&&t?i._writableState?i._writableState.errorEmitted?e.nextTick(o,i):(i._writableState.errorEmitted=!0,e.nextTick(r,i,t)):e.nextTick(r,i,t):n?(e.nextTick(o,i),n(t)):e.nextTick(o,i)})),this)}function r(e,t){s(e,t),o(e)}function o(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function i(){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 s(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:i,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 i(){}function s(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||i);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 s(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 i=e("../../../errors").codes,s=i.ERR_MISSING_ARGS,a=i.ERR_STREAM_DESTROYED;function c(e){if(e)throw e}function l(e){return e.setHeader&&"function"==typeof e.abort}function u(t,n,i,s){s=o(s);var c=!1;t.on("close",(function(){c=!0})),void 0===r&&(r=e("./end-of-stream")),r(t,{readable:n,writable:i},(function(e){if(e)return s(e);c=!0,s()}));var u=!1;return function(e){if(!c&&!u)return u=!0,l(t)?t.abort():"function"==typeof t.destroy?t.destroy():void s(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 s("streams");var i=t.map((function(e,n){var s=n<t.length-1;return u(e,s,n>0,(function(e){r||(r=e),e&&i.forEach(d),s||(i.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 i(e,t,n,i){var s=o(t,i,n);if(null!=s){if(!isFinite(s)||Math.floor(s)!==s||s<0)throw new r(i?n:"highWaterMark",s);return Math.floor(s)}return e.objectMode?16:16384}t.exports={getHighWaterMark:i}},{"../../../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?i:r;function t(e,t){for(var r=Object.keys(e),o=new Array(r.length),i=0;i<r.length;i++){var s=r[i],a=e[s];"object"!=typeof a||null===a?o[s]=a:a instanceof Date?o[s]=new Date(a):ArrayBuffer.isView(a)?o[s]=n(a):o[s]=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 i in e)if(!1!==Object.hasOwnProperty.call(e,i)){var s=e[i];"object"!=typeof s||null===s?o[i]=s:s instanceof Date?o[i]=new Date(s):s instanceof Map?o[i]=new Map(t(Array.from(s),r)):s instanceof Set?o[i]=new Set(t(Array.from(s),r)):ArrayBuffer.isView(s)?o[i]=n(s):o[i]=r(s)}return o}function i(e){if("object"!=typeof e||null===e)return e;if(e instanceof Date)return new Date(e);if(Array.isArray(e))return t(e,i);if(e instanceof Map)return new Map(t(Array.from(e),i));if(e instanceof Set)return new Set(t(Array.from(e),i));var r={};for(var o in e){var s=e[o];"object"!=typeof s||null===s?r[o]=s:s instanceof Date?r[o]=new Date(s):s instanceof Map?r[o]=new Map(t(Array.from(s),i)):s instanceof Set?r[o]=new Set(t(Array.from(s),i)):ArrayBuffer.isView(s)?r[o]=n(s):r[o]=i(s)}return r}}function o(e){var t=[],r=[];return e.proto?s:i;function o(e,o){for(var i=Object.keys(e),s=new Array(i.length),a=0;a<i.length;a++){var c=i[a],l=e[c];if("object"!=typeof l||null===l)s[c]=l;else if(l instanceof Date)s[c]=new Date(l);else if(ArrayBuffer.isView(l))s[c]=n(l);else{var u=t.indexOf(l);s[c]=-1!==u?r[u]:o(l)}}return s}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)if(!1!==Object.hasOwnProperty.call(e,a)){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}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){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}}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 i(e,t){for(var n in e)t[n]=e[n]}function s(e,t,n){return o(e,t,n)}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?t.exports=r:(i(r,n),n.Buffer=s),s.prototype=Object.create(o.prototype),i(o,s),s.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return o(e,t,n)},s.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},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o(e)},s.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 i(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 s(e){var t=i(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=s(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 i(){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=i;var s=/^([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 i)return e;var r=new i;return r.parse(e,t,n),r}function C(e){return o.isString(e)&&(e=w(e)),e instanceof i?e.format():i.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}i.prototype.parse=function(e,t,n){if(!o.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var i=e.indexOf("?"),a=-1!==i&&i<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=s.exec(C);if(k){var S=(k=k[0]).toLowerCase();this.protocol=S,C=C.substr(k.length)}if(n||k||C.match(/^\/\/[^@\/]+@[^@\/]+/)){var E="//"===C.substr(0,2);!E||k&&y[k]||(C=C.substr(2),this.slashes=!0)}if(!y[k]&&(E||k&&!v[k])){for(var A,I,T=-1,O=0;O<h.length;O++)-1!==(x=C.indexOf(h[O]))&&(-1===T||x<T)&&(T=x);for(-1!==(I=-1===T?C.lastIndexOf("@"):C.lastIndexOf("@",T))&&(A=C.slice(0,I),C=C.slice(I+1),this.auth=decodeURIComponent(A)),T=-1,O=0;O<d.length;O++){var x;-1!==(x=C.indexOf(d[O]))&&(-1===T||x<T)&&(T=x)}-1===T&&(T=C.length),this.host=C.slice(0,T),C=C.slice(T),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=(O=0,P.length);O<M;O++){var j=P[O];if(j&&!j.match(p)){for(var N="",F=0,B=j.length;F<B;F++)j.charCodeAt(F)>127?N+="x":N+=j[F];if(!N.match(p)){var U=P.slice(0,O),D=P.slice(O+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:"",z=this.hostname||"";this.host=z+q,this.href+=this.host,R&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==C[0]&&(C="/"+C))}if(!m[S])for(O=0,M=u.length;O<M;O++){var $=u[O];if(-1!==C.indexOf($)){var H=encodeURIComponent($);H===$&&(H=escape($)),C=C.split($).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},i.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||"",i=!1,s="";this.host?i=e+this.host:this.hostname&&(i=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&o.isObject(this.query)&&Object.keys(this.query).length&&(s=b.stringify(this.query));var a=this.search||s&&"?"+s||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||v[t])&&!1!==i?(i="//"+(i||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):i||(i=""),r&&"#"!==r.charAt(0)&&(r="#"+r),a&&"?"!==a.charAt(0)&&(a="?"+a),t+i+(n=n.replace(/[?#]/g,(function(e){return encodeURIComponent(e)})))+(a=a.replace("#","%23"))+r},i.prototype.resolve=function(e){return this.resolveObject(w(e,!1,!0)).format()},i.prototype.resolveObject=function(e){if(o.isString(e)){var t=new i;t.parse(e,!1,!0),e=t}for(var n=new i,r=Object.keys(this),s=0;s<r.length;s++){var a=r[s];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(),(O=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=O.shift(),n.host=n.hostname=O.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 E=k.slice(-1)[0],A=(n.host||e.host||k.length>1)&&("."===E||".."===E)||""===E,I=0,T=k.length;T>=0;T--)"."===(E=k[T])?k.splice(T,1):".."===E?(k.splice(T,1),I++):I&&(k.splice(T,1),I--);if(!C&&!_)for(;I--;I)k.unshift("..");!C||""===k[0]||k[0]&&"/"===k[0].charAt(0)||k.unshift(""),A&&"/"!==k.join("/").substr(-1)&&k.push("");var O,x=""===k[0]||k[0]&&"/"===k[0].charAt(0);return S&&(n.hostname=n.host=x?"":k.length?k.shift():"",(O=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=O.shift(),n.host=n.hostname=O.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},i.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 i(e,t){e.tail=new a(t,e.tail,null,e),e.head||(e.head=e.tail),e.length++}function s(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++)i(this,arguments[e]);return this.length},r.prototype.unshift=function(){for(var e=0,t=arguments.length;e<t;e++)s(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,i=this.head;null!==i&&o<e;o++)i=i.next;for(;null!==i&&o<t;o++,i=i.next)n.push(i.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,i=this.tail;null!==i&&o>t;o--)i=i.prev;for(;null!==i&&o>e;o--,i=i.prev)n.push(i.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,i=this.head;null!==i&&r<e;r++)i=i.next;var s=[];for(r=0;i&&r<t;r++)s.push(i.value),i=this.removeNode(i);for(null===i&&(i=this.tail),i!==this.head&&i!==this.tail&&(i=i.prev),r=0;r<n.length;r++)i=o(this,i,n[r]);return s},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)}(js);var Ns=ke(js.exports);var Fs;!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"}(Fs||(Fs={}));const Bs=e=>{let t,n=0,r=!0;return{connect:async function(o){return t&&(t.removeAllListeners(),t.end(!0)),t=Ns.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}},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.error(`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)}}},Us=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])))},Ds=()=>`ascWebSdk#${Math.random().toString(16)}`,Ls=()=>{const e=(()=>{var e,t;return(null===(e=Rt.versions)||void 0===e?void 0:e.node)?Rt.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}},qs={notLoggedIn:["establishing"],terminated:["establishing"],establishing:["notLoggedIn","established"],established:["notLoggedIn","terminated","tokenExpired","establishing"],tokenExpired:["establishing"]},zs=e=>{const t=we();t.log("client/api/setSessionState",e);const{sessionState:n}=t;if(n===e)return!1;if(!((e,t)=>qs[e].includes(t))(n,e))throw new ge(`Session state cannot change from ${n} to ${e}`,8e5,"error");return t.sessionState=e,ct("sessionStateChange",e),!0},$s=async e=>{const t=we();zs("establishing");const{accessToken:n,users:r,expiresAt:o,issuedAt:i,refreshToken:s}=await(async e=>{const t=we();t.log("client/api/getToken",e);const n=Ls(),{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},t.ws.io.opts.query={token:n},t.token={accessToken:n,issuedAt:i,expiresAt:o},zs("established"),{accessToken:n,users:r,refreshToken:s}},Hs=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&&zs("notLoggedIn"),"tokenExpired"!==e.sessionState&&e.cache&&(e.cache={data:{}}),!e.ws.connected},Vs=(e={},t)=>{Object.entries(e).forEach((([e,n])=>{const r=he[e];if(!r)return;const o=ce(r);o&&n.forEach((e=>{$e([r,"get",o(e)],e,t)}))}))},Ws=(e,t)=>{const n=we();return at(n,e,e,(e=>{n.cache&&Vs(e),t(e.users[0])}))},Ks=e=>Ws("user.deleted",e),Qs=()=>{const e=we();zs("terminated"),e.sessionHandler=void 0,Hs()},Js=["disconnected","error","connect_error","reconnect_error","reconnect_failed"],Gs=e=>{const t=we(),n=Js.map((n=>at(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()))}},Ys=e=>{const t=we();return at(t,"client/onConnectionError(user.didGlobalBan)","user.didGlobalBan",e)},Xs=[],Zs=async(e,t,n)=>{var r,o,i;const s=we();let a;s.log("client/api/connectClient",Object.assign({apiKey:s.apiKey,sessionState:s.sessionState},e)),s.userId&&s.userId!==e.userId&&(await Hs(),Xs.forEach((e=>e()))),null!==(r=e.deviceId)&&void 0!==r||(e.deviceId=Ds());try{const{users:n}=await $s(e);c=s.ws,l=s.emitter,ot.forEach((e=>{c.on(e,(t=>{l.emit(e,t)}))})),await new Promise((e=>{s.ws.once("connect",e),s.ws.open()})),s.userId=e.userId,s.sessionHandler=t,a=s.accessTokenExpiryWatcher(null===(o=s.token)||void 0===o?void 0:o.expiresAt,null===(i=s.token)||void 0===i?void 0:i.issuedAt,t),dt(n[0])}catch(e){throw zs("notLoggedIn"),e}var c,l;return!0!==(null==n?void 0:n.disableRTE)&&(_t(mt()),_t(yt()),_t(vt()),_t(bt()),_t(gt(ut()))),Xs.push(Ys((e=>{Qs(),Xs.forEach((e=>e())),a()})),(e=>{const t=we();return at(t,"client/onTokenTerminated","tokenTerminated",e)})((e=>{Qs(),Xs.forEach((e=>e())),a()})),Ks((e=>{e.userId===s.userId&&(Qs(),Xs.forEach((e=>e())),a())})),(e=>{const t=we();return at(t,"client/onTokenExpired","tokenExpired",e)})((e=>{zs(e),Hs(),Xs.forEach((e=>e()))}))),s.ws.connected},ea=()=>{let e,t=!1;const n=we();n.log("initiating access token renewal");const r=async r=>{const{userId:o,displayName:i}=ut(),s={userId:o,displayName:i,authToken:r,deviceId:Ds()};"tokenExpired"===n.sessionState?await Zs(s,n.sessionHandler):await $s(s),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)}}},ta=3e5,na=(e,t,n)=>{const r=setInterval((()=>{if((e=>Date.now()>Date.parse(e)-ta)(e))return ct("tokenExpired","tokenExpired"),void rt((()=>n.sessionWillRenewAccessToken(ea())));(e=>{const{expiresAt:t,issuedAt:n}=e,r=Date.parse(t),o=Date.parse(n),i=Date.now();return i>o+.8*(r-o-ta)&&i<r})({expiresAt:e,issuedAt:t})&&n.sessionWillRenewAccessToken(ea())}),g);return()=>clearInterval(r)},ra=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:i}=t,s=e.cache&&Date.now();return e.cache&&Vs(t,{cachedAt:s}),o.length&&ct("local.feedMarker.fetched",{feedMarkers:o}),n.length&&ct("local.channelMarker.fetched",{userEntityMarkers:n}),r.length&&ct("local.subChannelMarker.fetched",{userFeedMarkers:r}),i.length&&ct("local.userMarker.fetched",{userMarkers:i}),{hasMore:t.feedMarkers.length>0}};function oa(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 ia=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,i=oa(r,["paging"]),{userEntityMarkers:s,userMarkers:a}=i,c=n.cache&&Date.now();n.cache&&Vs(i,{cachedAt:c}),s.length&&ct("local.channelMarker.fetched",{userEntityMarkers:s}),a.length&&ct("local.userMarker.fetched",{userMarkers:a});const l=G(o.next);return{data:s,cachedAt:c,prevPage:G(o.previous),nextPage:l}},sa=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,i=oa(r,["paging"]),{contentMarkers:s,feedMarkers:a,userMarkers:c}=i,l=n.cache&&Date.now();n.cache&&Vs(i,{cachedAt:l}),a.length&&ct("local.feedMarker.fetched",{feedMarkers:a}),s.length&&ct("local.messageMarker.fetched",{contentMarkers:s}),c.length&&ct("local.userMarker.fetched",{userMarkers:c});const u=G(o.next);return{data:s,cachedAt:l,prevPage:G(o.previous),nextPage:u}},aa=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,i=oa(r,["paging"]),{userEntityMarkers:s,userFeedMarkers:a,userMarkers:c}=i,l=n.cache&&Date.now();n.cache&&Vs(i,{cachedAt:l}),s.length&&ct("local.channelMarker.fetched",{userEntityMarkers:s}),a.length&&ct("local.subChannelMarker.fetched",{userFeedMarkers:a}),c.length&&ct("local.userMarker.fetched",{userMarkers:c});const u=G(o.next);return{data:a,cachedAt:l,prevPage:G(o.previous),nextPage:u}},ca=()=>{var e,t;const n=we(),r=ut();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 i=(new Date).toISOString(),s=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:i,createdAt:i,updatedAt:i},cachedAt:s}},la=()=>Promise.resolve(ca());la.locally=ca;const ua=e=>{const t=we();return at(t,"userMarker/onUserMarkerFetched","local.userMarker.fetched",(t=>{e(t.userMarkers[0])}))},da=(e,t,n,r,o,i=(e=>e),s)=>{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=oa(e,["data"]);s&&!s(n,c)||t(Object.assign({data:i(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);ie(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()))}},ha=e=>!0===e&&void 0,fa=(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 pa(e,t){const{channelPublicId:n,childCount:r,creatorPublicId:o,mentionedUsers:i,messageFeedId:s,myReactions:a,reactionCount:c,reactions:l,referenceId:u,segment:d,messageId:h}=e,f=oa(e,["channelPublicId","childCount","creatorPublicId","mentionedUsers","messageFeedId","myReactions","reactionCount","reactions","referenceId","segment","messageId"]),{readCount:p,deliveredCount:g}=fa(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:s,uniqueId:m?m.data.uniqueId:h,readCount:p,deliveredCount:g});return i&&(y.mentionees=i.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}function ga(e,t){const{readCount:n,deliveredCount:r}=fa(e,t);return Object.assign(Object.assign({},e),{readCount:n,deliveredCount:r,updatedAt:(new Date).toISOString()})}const ma=async e=>{let t=[];const n=e.messages.map((({messageId:e})=>e));if(n.length>0)try{({data:t}=await sa(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 pa(e,n)}))})};function ya(e){var{subChannelId:t,mentionees:n}=e,r=oa(e,["subChannelId","mentionees"]);return Object.assign({messageFeedId:t,mentionedUsers:n},r)}function va(e){var{page:t,sortBy:n,subChannelId:r,tags:o,includeDeleted:i}=e,s=oa(e,["page","sortBy","subChannelId","tags","includeDeleted"]);const a=Object.assign(Object.assign({},s),{messageFeedId:r,isDeleted:ha(i),options:{token:J(t||{limit:10},"afterbeforeraw")}});return void 0!==n&&(a.options.sortBy=n),o&&(a.includeTags=o),a}const ba=(e,t=!0)=>{const n=we(),r=[at(n,"message/onMessageCreated","message.created",(async t=>{const n=await ma(t),r=n.messages[0];Vs(n),e(r)}))];return t&&at(n,"message/onMessageCreated","local.message.created",(t=>e(t.messages[0]))),()=>{r.forEach((e=>e()))}},wa=e=>{const t=we(),n=[at(t,"onMessageUpdated","message.updated",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])})),at(t,"onMessageUpdated","local.message.updated",(t=>e(t.messages[0]))),at(t,"onMessageUpdated","local.messageMarker.fetched",(async t=>{var n;const r=t.contentMarkers[0],o=["message","get",r.contentId],i=null===(n=Le(o))||void 0===n?void 0:n.data;if(!i)return;const s=ga(i,r);$e(o,s),e(s)}))];return()=>{n.forEach((e=>e()))}},Ca=e=>{const t=we(),n=[at(t,"message/onMessageDeleted","message.deleted",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])})),at(t,"local.message.deleted","local.message.deleted",(t=>e(t.messages[0])))];return()=>{n.forEach((e=>e()))}},_a=e=>{const t=we();return at(t,"onMessageFlagged","message.flagged",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])}))},ka=e=>{const t=we();return at(t,"onMessageUnflagged","message.unflagged",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])}))},Sa=e=>{const t=we();return at(t,"onMessageFlagCleared","message.flagCleared",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])}))},Ea=e=>{const t=we();return at(t,"onMessageReactionAdded","message.reactionAdded",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])}))},Aa=e=>{const t=we();return at(t,"onMessageReactionRemoved","message.reactionRemoved",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])}))},Ia=e=>{const t=we();return at(t,"message/onMessageFetched","local.message.fetched",(t=>{Vs(t),e(t.messages[0])}))},Ta=["broadcast","conversation","community"],Oa=({channelType:e})=>Ta.includes(e);function xa(e,t,n){var r;if(n)return n.unreadCount;const o={entityId:e,feedId:t,userId:ut()._id},i=null===(r=Le(["subChannelMarker","get",ce("subChannelMarker")(o)]))||void 0===r?void 0:r.data;return i?i.unreadCount:0}const Ra=async e=>{let t=[];const n=e.messageFeeds.filter(Oa).map((({messageFeedId:e})=>e));if(n.length>0)try{({data:t}=await aa(n))}catch(e){}const r=e.messageFeeds.map((e=>{const n=null==t?void 0:t.find((({feedId:t})=>t===e.messageFeedId));return function(e,t){var{channelId:n,channelPublicId:r,channelType:o,childCount:i,creatorId:s,creatorPublicId:a,lastMessageId:c,lastMessageTimestamp:l,messageFeedId:u,name:d}=e,h=oa(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:i,subChannelId:u,isUnreadCountSupport:Oa({channelType:o}),unreadCount:xa(n,u,t)})}(e,n)}));return Object.assign(Object.assign({},e),{messageFeeds:r})};function Pa(e){var{excludeDefaultSubChannel:t}=e,n=oa(e,["excludeDefaultSubChannel"]);const r=Object.assign({},n);return void 0!==t&&(r.excludeDefaultMessageFeed=t),r}const Ma=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`),r=t.cache&&Date.now();return t.cache&&Vs(n,{cachedAt:r}),!0},ja=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`),r=t.cache&&Date.now();return t.cache&&Vs(n,{cachedAt:r}),!0};let Na=[];const Fa={},Ba=e=>{var t;if(!Fa[e.subChannelId])return;if(!we().cache)return;const n={entityId:e.channelId,feedId:e.subChannelId,userId:ut()._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})];ct("local.subChannelMarker.updated",{userFeedMarkers:o})},Ua=()=>{Na.push((()=>{const e=()=>{Object.entries(Fa).forEach((([e,t])=>{t&&Ma(e)}))};return window.addEventListener("online",e),()=>window.removeEventListener("online",e)})(),ba(Ba))},Da=e=>{const t=we();return at(t,"onSubChannelCreated","message-feed.created",(async t=>{const n=await Ra(t);Vs(n),e(n.messageFeeds[0])}))},La=e=>{const t=we(),n=async t=>{var n;const r=t.userFeedMarkers[0],o=["subChannel","get",r.feedId],i=null===(n=Le(o))||void 0===n?void 0:n.data;if(!i)return;const s=function(e,t){return Object.assign(Object.assign({},e),{unreadCount:xa(e.channelId,e.subChannelId,t),updatedAt:(new Date).toISOString()})}(i,r);$e(o,s),e(s)},r=[at(t,"onSubChannelUpdated","message-feed.updated",(async t=>{const n=await Ra(t);Vs(n),e(n.messageFeeds[0])})),at(t,"onSubChannelUpdated","local.subChannelMarker.fetched",n),at(t,"onSubChannelUpdated","local.subChannelMarker.updated",n)];return()=>{r.forEach((e=>e()))}},qa=e=>{const t=we(),n=[at(t,"onSubChannelDeleted","message-feed.deleted",(async t=>{const n=await Ra(t);Vs(n),e(n.messageFeeds[0])})),at(t,"local.message-feed.deleted","local.message-feed.deleted",(t=>e(t.messageFeeds[0])))];return()=>{n.forEach((e=>e()))}};let za,$a=[],Ha=!1,Va=[];const Wa=e=>{Va=e},Ka=e=>Va.push(e),Qa=async e=>{if(Ha)return;if(0===Va.length)return;Ha=!0,Va=[];(await e()).hasMore&&Va.push("has_more"),Ha=!1},Ja=(e,t)=>{const n=setInterval(e,t);return()=>clearInterval(n)},Ga=()=>{$a.push((()=>{const e=()=>Va.push("resume");return window.addEventListener("online",e),()=>window.removeEventListener("online",e)})(),ba((e=>{Oa(e)&&Va.push("new message")}),!1),Da((()=>Va.push("subchannel is created"))),qa((()=>Va.push("subchannel is deleted"))),Ja((()=>Va.push("force sync")),8e3))};var Ya=Object.freeze({__proto__:null,getActiveClient:we,getActiveUser:ut,setActiveUser:dt,createClient:(e,t=Mt.SG,{debugSession:n="amity",apiEndpoint:r}={})=>{var o,i;const s=(e=>{const t=`${null==e?void 0:e.trim()}`.length>0&&!Pt,n=Ot(e),r=(e,...r)=>{t&&n(e,r)};return r.__instance__=n,r})(n);s("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:Nt("http",t),c=null!==(i=null==r?void 0:r.mqtt)&&void 0!==i?i:Nt("mqtt",t),l=yr(a),u=(e=>{const t=Ps(e,{autoConnect:!1,reconnectionDelay:2e3,transports:["websocket"]});return t.on("disconnect",(e=>{"io server disconnect"===e&&t.connect()})),t})(a),h=Bs(c),f=st(),p={version:`${d}`,apiKey:e,log:s,http:l,ws:u,mqtt:h,emitter:f,accessTokenExpiryWatcher:na,use:()=>Ce(p),sessionState:"notLoggedIn",sessionHandler:undefined,getFeedSettings:Us};try{return we()}catch(e){Ce(p)}return p},login:Zs,logout:Hs,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:Us,renewal:ea,markerSync:ra,onConnectionError:Gs,onClientDisconnected:e=>Gs((({code:t})=>{800211===t&&e()})),onClientBanned:Ys,onSessionStateChange:e=>{const t=we();return at(t,"client/onSessionStateChange","sessionStateChange",e)},getTotalUnreadCount:e=>{const{_id:t}=ut();if(!t)throw new ge("The _id has not been defined in ActiveUser",8e5,"error");return da(t,e,"userId",la,[ua],(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:()=>Va,setMarkerSyncEvents:Wa,pushMarkerSyncEvent:Ka,markerSyncTrigger:Qa,startUnreadSync:()=>{Ka("start syncing"),za||(za=Ja((()=>Qa(ra)),2e3)),Ga()},stopUnreadSyncing:()=>{null==za||za(),za=void 0,Wa([]),$a.forEach((e=>e())),$a=[]}});const Xa=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,i=oa(r,["paging"]),{users:s}=i,a=t.cache&&Date.now();if(t.cache){Vs(i,{cachedAt:a});qe(["blockedUsers","query",n],{users:s.map(ce("user")),paging:o})}const{next:c,previous:l,total:u}=o,d=Y(c);return{data:s,prevPage:Y(l),nextPage:d,total:u,cachedAt:a}};Xa.locally=(e={})=>{var t,n,r;const o=we();if(o.log("user/queryBlockedUsers.locally"),!o.cache)return;let i={};if(e){const{token:t,limit:n}=e;i={token:t,limit:n}}const s=["blockedUsers","query",i],{data:a,cachedAt:c}=null!==(t=Le(s))&&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 Za=(e,t)=>{const n=we();return at(n,e,e,(e=>{var r,o;if(n.cache){Vs(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})=>$e(e,t,{cachedAt:-1}))),t(e.follows[0])}else t(e.follows[0])}))},ec=e=>Za("follow.created",e),tc=e=>Za("follow.unfollowed",e),nc=e=>Za("follow.followerDeleted",e),rc=e=>Za("follow.requested",e),oc=e=>Za("follow.requestCanceled",e),ic=e=>Za("follow.accepted",e),sc=e=>Za("follow.requestDeclined",e),ac=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`),i=r.cache&&Date.now(),s="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],s,{cachedAt:i}),{data:s,cachedAt:i}};ac.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 cc=e=>{const t=async t=>{const[{data:n},{data:r}]=await Promise.all([ac(t.from),ac(t.to)]);e(n),e(r)},n=[Za("follow.created",t),Za("follow.requested",t),Za("follow.accepted",t),Za("follow.unfollowed",t),Za("follow.requestCanceled",t),Za("follow.requestDeclined",t),Za("follow.followerDeleted",t)];return()=>{n.forEach((e=>e()))}},lc=async(e,t)=>{const n=we();n.log(`follow/queryF${e.substring(1)}`,t);const{userId:r,page:o}=t,i=oa(t,["userId","page"]),{data:s}=await n.http.get(n.userId===r?`/api/v4/me/${e}`:`/api/v4/users/${r}/${e}`,{params:Object.assign(Object.assign({},i),{token:J(o,"afterbeforeraw")})}),{paging:a}=s,c=oa(s,["paging"]),{follows:l}=c,u=n.cache&&Date.now();if(n.cache){Vs(c,{cachedAt:u});const t=["follow","query",Object.assign(Object.assign({},i),{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}};lc.locally=(e,t)=>{var n,r;const o=we();if(o.log(`follow/queryF${e.substring(1)}.locally`,t),!o.cache)return;const{page:i}=t,s=oa(t,["page"]),a=["follow","query",Object.assign(Object.assign({},s),{options:Object.assign({},i),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 uc=async e=>lc("followers",e);uc.locally=e=>lc.locally("followers",e);const dc=async e=>lc("following",e);dc.locally=e=>lc.locally("following",e);var hc=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:i}=n,s={follows:o};return t.cache&&(Vs(s,{cachedAt:r}),$e(["followInfo","get",e],i[0],{cachedAt:r})),ct("follow.unfollowed",s),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:i}=n,s={follows:o};return t.cache&&(Vs(s,{cachedAt:r}),$e(["followInfo","get",e],i[0],{cachedAt:r})),ct("follow.created",s),n},getBlockedUsers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getBlockedUsers(tmpid: ${i}) > listen`);const{limit:s,token:a}=e,c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["blockedUsers","collection",{}],g=()=>{var e,n;const r=null===(e=Le(d))||void 0===e?void 0:e.data,o=null!==(n=null==r?void 0:r.data)&&void 0!==n?n:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(Xa,{limit:c,token:J(null==r?void 0:r.params.page,"afterbeforeraw")});ie(i,(({data:e,loading:n,error:r,nextPage:i,total:s})=>{const a={loading:n,error:r,params:{page:i,total:s},data:o};e&&(a.data=[...new Set([...o,...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(),()=>{r(`getCategories(tmpid: ${i}) > dispose`),u.forEach((e=>e())),He(d)}},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&&Vs(n,{cachedAt:r}),ct("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&&Vs(n),ct("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&&Vs(n),ct("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&&Vs(n),ct("follow.requestDeclined",n),!0},onUserFollowed:ec,onUserUnfollowed:tc,onFollowerDeleted:nc,onFollowerRequested:rc,onFollowRequestCanceled:oc,onFollowRequestAccepted:ic,onFollowRequestDeclined:sc,onFollowInfoUpdated:cc,observeFollowInfo:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observeFollowInfo(tmpid: ${o}) > listen`);const i=(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=[];return s.push(cc((t=>((t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.userId)===e&&i(t,n)})({data:t,loading:!1,origin:"event"},"onUpdate")))),ie(re(ac,e),(e=>(e.data||e.error)&&i(e,"onFetch")),oe(n)),()=>{r(`observeFollowInfo(tmpid: ${o}) > dispose`),s.forEach((e=>e()))}},observeFollowers:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeFollowers(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;if(n.from===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(rc((e=>i(e,"onRequested"))),ic((e=>i(e,"onAccepted"))),sc((e=>i(e,"onDeclined"))),oc((e=>i(e,"onCanceled"))),ec((e=>i(e,"onFollowed"))),tc((e=>i(e,"onUnfollowed"))),nc((e=>i(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=[],i=(n,r)=>{var o,i;if(n.to===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(rc((e=>i(e,"onRequested"))),ic((e=>i(e,"onAccepted"))),sc((e=>i(e,"onDeclined"))),oc((e=>i(e,"onCanceled"))),ec((e=>i(e,"onFollowed"))),tc((e=>i(e,"onUnfollowed"))),nc((e=>i(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 i=Date.now();r(`getFollowers(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["follow","collection",{userId:e.userId,type:"follower"}],p=n=>{var r,o;let i=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&&(i=Ve(i,"status",e.status)),t({onNextPage:m,data:i,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=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(uc,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({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("follow"))])]),qe(d,o),p(o)}),oe(l))};return u.push(rc(g("onRequested")),ic(g("onAccepted")),sc(g("onDeclined")),oc(g("onCanceled")),ec(g("onFollowed")),tc(g("onUnfollowed")),nc(g("onDeleted"))),m(),()=>{r(`getFollowers(tmpid: ${i}) > 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 i=Date.now();r(`getFollowings(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["follow","collection",{userId:e.userId,type:"following"}],p=n=>{var r,o;let i=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&&(i=Ve(i,"status",e.status)),t({onNextPage:m,data:i,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=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(dc,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({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("follow"))])]),qe(d,o),p(o)}),oe(l))};return u.push(rc(g("onRequested")),ic(g("onAccepted")),sc(g("onDeclined")),oc(g("onCanceled")),ec(g("onFollowed")),tc(g("onUnfollowed")),nc(g("onDeleted"))),m(),()=>{r(`getFollowings(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},getFollowInfo:(e,t)=>da(e,t,"userId",ac,[cc])});const fc=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&&Vs(r,{cachedAt:o}),ct("user.fetched",r),{data:r.users,cachedAt:o}};fc.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)),i=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:i.cachedAt}};const pc=e=>Ws("user.updated",e),gc=e=>Ws("user.flagged",e),mc=e=>Ws("user.unflagged",e),yc=e=>Ws("user.flagCleared",e),vc=e=>Ws("user.fetched",e),bc=(e,t)=>{const{log:n,cache:r}=we(),o=[e,m,t];if(!r)return;n("cache/api/isInTombstone",o);const i=Le(o),{lifeSpan:s}=oe("cache_then_server",18e4);if(i&&ne(i.data,s))throw new me("Item not found!",400400,"error")},wc=(e,t)=>{const{log:n,cache:r}=we(),o=[e,m,t],i={cachedAt:Date.now()};r&&(n("cache/api/pushToTombstone",{cacheKey:o,data:i}),He([e,"get",t],!0),qe(o,i))},Cc=async e=>{const t=we();let n;t.log("user/getUser",e),bc("user",e);try{n=(await t.http.get(`/api/v3/users/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&wc("user",e),t}const r=t.cache&&Date.now();t.cache&&Vs(n,{cachedAt:r});const{users:o}=n;return ct("user.fetched",n),{data:o.find((t=>t.userId===e)),cachedAt:r}};Cc.locally=e=>{const t=we();return t.log("user/getUser.locally",e),t.cache&&Le(["user","get",e])};const _c=async(e={})=>{const t=we();t.log("user/queryUsers",e);const{page:n={limit:10},displayName:r,filter:o="all",sortBy:i="displayName"}=e,s=oa(e,["page","displayName","filter","sortBy"]),{data:a}=await t.http.get("/api/v3/users",{params:Object.assign(Object.assign({},s),{keyword:r,filter:o,sortBy:i,options:{token:J(n,"skiplimit")}})}),{paging:c}=a,l=oa(a,["paging"]),{users:u}=l,d=t.cache&&Date.now();if(t.cache){Vs(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})}ct("user.fetched",a);return{data:u,cachedAt:d,prevPage:G(c.previous),nextPage:G(c.next)}};_c.locally=(e={})=>{var t,n,r;const o=we();if(o.log("user/queryUsers.locally",e),!o.cache)return;const{page:i={limit:10}}=null!=e?e:{},s=["user","query",Object.assign(Object.assign({},e),{options:Object.assign({},i)})],{data:a,cachedAt:c}=null!==(t=Le(s))&&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 kc=Object.freeze({__proto__:null,Relationship:hc,getUserByIds:fc,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&&Vs(r,{cachedAt:o});const{users:i}=r;return ct("user.updated",r),{data:i.find((t=>t.userId===e)),cachedAt:o}},onUserUpdated:pc,onUserDeleted:Ks,onUserFlagged:gc,onUserUnflagged:mc,onUserFlagCleared:yc,getUser:(e,t)=>da(e,t,"userId",Cc,[vc,pc,Ks,gc,mc,yc]),getUsers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`liveUsers(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["user","collection",{}],g=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(i=Ve(i,"displayName",e.displayName),e.sortBy){case"firstCreated":i=i.sort(Xe);break;case"lastCreated":i=i.sort(Ze);break;default:i=i.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Ge)}t({onNextPage:y,data:i,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=()=>{var e,t,n;const r=null===(e=Le(d))||void 0===e?void 0:e.data,o=null!==(t=null==r?void 0:r.data)&&void 0!==t?t:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(_c,Object.assign(Object.assign({},a),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:c}}));ie(i,(({data:e,error:t,loading:n,nextPage:r})=>{const i={loading:n,error:t,params:{page:r},data:o};e&&(i.data=[...new Set([...o,...e.map(ce("user"))])]),qe(d,i),g(i)}),oe(l))};return u.push(pc(m()),Ks(m()),gc(m()),mc(m()),yc(m())),y(),()=>{r(`liveUsers(tmpid: ${i}) > 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,i,s;if((null===(o=n.data)||void 0===o?void 0:o.userId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},i=[];return i.push(pc((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),Ks((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),gc((e=>o({data:e,loading:!1,origin:"event"},"onFlagged"))),mc((e=>o({data:e,loading:!1,origin:"event"},"onUnflagged"))),yc((e=>o({data:e,loading:!1,origin:"event"},"onFlagCleared")))),ie(re(Cc,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeUser(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}}});const Sc=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&&Vs({files:[n]},{cachedAt:r}),{data:n,cachedAt:r}};Sc.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 Ec=Object.freeze({__proto__:null,getFile:Sc,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))}}),i=n.cache&&Date.now();return n.cache&&Vs({files:o},{cachedAt:i}),{data:o,cachedAt:i}},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}`,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:i}=await r.http.post("/api/v4/videos",e,{headers:o,onUploadProgress({loaded:e,total:t=100}){n&&n(Math.round(100*e/t))}}),s=r.cache&&Date.now();return r.cache&&Vs({files:i},{cachedAt:s}),{data:i,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))}}),i=n.cache&&Date.now();return n.cache&&Vs({files:o},{cachedAt:i}),{data:o,cachedAt:i}},observeFile:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeFile(tmpid: ${r}) > listen`);return ie(re(Sc,e),(n=>n.data&&((n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.fileId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}})(n,"onFetch"))),()=>{n(`observeFile(tmpid: ${r}) > dispose`)}}});const Ac=async e=>{const t=we();t.log("role/queryRoles",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,sortBy:i}=n,s=oa(n,["page","displayName","sortBy"]),{data:a}=await t.http.get("/api/v3/roles",{params:Object.assign(Object.assign({},s),{keyword:o,sortBy:i,options:{token:J(r,"skiplimit")}})}),{paging:c}=a,l=oa(a,["paging"]),{roles:u}=l,d=t.cache&&Date.now();t.cache&&Vs(l,{cachedAt:d});const h=G(c.next);return{data:u,cachedAt:d,prevPage:G(c.previous),nextPage:h}};Ac.locally=e=>{we().log("role/queryRoles.locally",e)};const Ic=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&&Vs({roles:n},{cachedAt:r}),{data:n.find((t=>t.roleId===e)),cachedAt:r}};Ic.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 Tc=(e,t)=>{"message"===e?ct("local.message.updated",{messages:[t]}):"post"===e?ct("post.updated",{posts:[t]}):"comment"===e&&ct("comment.updated",{comments:[t]})},Oc=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."),bc("message",e);try{const{data:t}=await n.http.get(`/api/v5/messages/${encodeURIComponent(e)}`);r=await ma(t)}catch(t){throw _(null==t?void 0:t.code)&&wc("message",e),t}const o=n.cache&&Date.now();n.cache&&Vs(r,{cachedAt:o});const{messages:i}=r;return ct("local.message.fetched",{messages:i}),{data:i.find((t=>t.messageId===e)),cachedAt:o}};Oc.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 xc=(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},Rc=(e,t,n="userId",r="user")=>{const o=e,i=t,s=o[i],a=oa(o,["symbol"==typeof i?i:i+""]),c=xc(s,n,r);return Object.assign(Object.assign({},a),{[t]:c})},Pc=async e=>{const t=we();let n;t.log("post/getPost",e),bc("post",e);try{n=(await t.http.get(`/api/v3/posts/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&wc("post",e),t}const r=Rc(n,"communityUsers"),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{posts:i}=r;return{data:i.find((t=>t.postId===e)),cachedAt:o}};Pc.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 Mc=async e=>{const t=we();let n;t.log("comment/getComment",e),bc("comment",e);try{n=(await t.http.get(`/api/v3/comments/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&wc("comment",e),t}const r=t.cache&&Date.now();t.cache&&Vs(n,{cachedAt:r});const{comments:o}=n;return{data:o.find((t=>t.commentId===e)),cachedAt:r}};Mc.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 jc=(e,t)=>{var n,r;if(we().userId!==t.reactor.userId)return;let o,i;if("post.addReaction"===e||"post.removeReaction"===e){const e=t.posts[0];i=null===(n=Le(["post","get",e.postId]))||void 0===n?void 0:n.data,o=e}else{const e=t.comments[0];i=null===(r=Le(["comment","get",e.commentId]))||void 0===r?void 0:r.data,o=e}if(i&&i.myReactions)if("post.addReaction"===e||"comment.addReaction"===e){if(i.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:[...i.myReactions,t.reactor.reactionName]})}else{if(!i.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:i.myReactions.filter((e=>e!==t.reactor.reactionName))})}},Nc=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};Nc.optimistically=(e,t,n)=>{var r,o,i,s,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!==(i=l.data.reactions[n])&&void 0!==i?i:0)+1})});return $e([e,"get",t],u,{cachedAt:-5}),Tc(e,u),null!==(a=null===(s=null==u?void 0:u.myReactions)||void 0===s?void 0:s.includes(n))&&void 0!==a&&a};const Fc=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};Fc.optimistically=(e,t,n)=>{var r,o,i,s,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!==(i=l.data.reactions[n])&&void 0!==i?i:0)-1)})});return $e([e,"get",t],u,{cachedAt:-5}),Tc(e,u),null!==(a=!(null===(s=null==u?void 0:u.myReactions)||void 0===s?void 0:s.includes(n)))&&void 0!==a&&a};const Bc=(e,t)=>{const n=we();return at(n,e,e,(r=>{var o;if(n.cache){const{communities:n}=r,i=oa(r,["communities"]),s=Rc(i,"communityUsers");Vs(s),(null==n?void 0:n[0])&&!["post.updated"].includes(e)&&ct("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})=>$e(e,t,{cachedAt:-1})))}t(a.data)}else t(r.posts[0])}))},Uc=e=>Bc("post.created",e),Dc=e=>Bc("post.updated",e),Lc=e=>Bc("post.deleted",e),qc=e=>Bc("post.approved",e),zc=e=>Bc("post.declined",e),$c=e=>Bc("post.flagged",e),Hc=e=>Bc("post.unflagged",e),Vc=e=>{const t=we();return at(t,"post.addReaction","post.addReaction",(n=>{if(t.cache){jc("post.addReaction",n);const t=oa(n,["reactor"]);Vs(t);const r=Le(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},Wc=e=>{const t=we();return at(t,"post.removeReaction","post.removeReaction",(n=>{if(t.cache){jc("post.removeReaction",n);const t=oa(n,["reactor"]);Vs(t);const r=Le(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},Kc=(e,t)=>{const n=we();return at(n,e,e,(r=>{var o;if(n.cache){Vs(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})=>$e(e,t,{cachedAt:-1})))}t(n.data)}else t(r.comments[0])}))},Qc=e=>Kc("comment.created",e),Jc=e=>Kc("comment.updated",e),Gc=e=>Kc("comment.deleted",e),Yc=e=>Kc("comment.flagged",e),Xc=e=>Kc("comment.unflagged",e),Zc=e=>{const t=we();return at(t,"comment.addReaction","comment.addReaction",(n=>{if(t.cache){jc("comment.addReaction",n);const t=oa(n,["reactor"]);Vs(t);const r=Le(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},el=e=>{const t=we();return at(t,"comment.removeReaction","comment.removeReaction",(n=>{if(t.cache){jc("comment.removeReaction",n);const t=oa(n,["reactor"]);Vs(t);const r=Le(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},tl=(e,t,n)=>{const r=we(),o=(r,o,i)=>{r===e&&o===t&&n(i)};if("message"===e){const e=async e=>{const t=await ma(e);if(!t.messages[0].latestReaction)return;const n=t.messages[0].latestReaction,{eventName:r,referenceId:i,referenceType:s,userDisplayName:a}=n,c=oa(n,["eventName","referenceId","referenceType","userDisplayName"]);"add"===r&&(Vs(t),Vs({reactions:[c]}),o("message",t.messages[0].messageId,c))};return at(r,"reaction/onReactorAdded","message.updated",e)}if("post"===e){return at(r,"post.addReaction","post.addReaction",(e=>{const{reactor:t}=e,n=oa(e,["reactor"]);Vs(n),Vs({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return at(r,"comment.addReaction","comment.addReaction",(e=>{const{reactor:t}=e,n=oa(e,["reactor"]);Vs(n),Vs({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))},nl=(e,t,n)=>{const r=we(),o=(r,o,i)=>{r===e&&o===t&&n(i)};if("message"===e){const e=async e=>{const t=await ma(e);if(!t.messages[0].latestReaction)return;const n=t.messages[0].latestReaction,{eventName:r,referenceId:i,referenceType:s}=n,a=oa(n,["eventName","referenceId","referenceType"]);"remove"===r&&(Vs(t),Vs({reactions:[a]}),o("message",t.messages[0].messageId,a))};return at(r,"reaction/onReactorRemoved","message.updated",e)}if("post"===e){return at(r,"post.removeReaction","post.removeReaction",(e=>{const{reactor:t}=e,n=oa(e,["reactor"]);Vs(n),Vs({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return at(r,"comment.removeReaction","comment.removeReaction",(e=>{const{reactor:t}=e,n=oa(e,["reactor"]);Vs(n),Vs({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))},rl=async e=>{const t=we();t.log("reaction/queryReactions",e);const n=null!=e?e:{},{page:r={limit:10}}=n,o=oa(n,["page"]),{data:i}=await t.http.get("/api/v3/reactions",{params:Object.assign(Object.assign({},o),{options:{token:J(r,"afterbeforeraw")}})}),{paging:s}=i,a=oa(i,["paging"]),{reactions:c}=a;Vs(Object.assign(Object.assign({},a),{reactions:c[0].reactors}));const l=Y(s.next);return{data:c,prevPage:Y(s.previous),nextPage:l}};var ol=Object.freeze({__proto__:null,addReaction:Nc,removeReaction:Fc,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 ma(e),o=Le(["message","get",n.messages[0].messageId]),i=(null===(t=null==o?void 0:o.data)||void 0===t?void 0:t.reactionsCount)!==n.messages[0].reactionsCount;Vs(n),i&&r(n.messages[0])};return at(e,"reaction/onReactionAdded","message.updated",t)}return"post"===e?Vc(r):Zc(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 ma(e),o=Le(["message","get",n.messages[0].messageId]),i=(null===(t=null==o?void 0:o.data)||void 0===t?void 0:t.reactionsCount)!==n.messages[0].reactionsCount;Vs(n),i&&r(n.messages[0])};return at(e,"reaction/onReactionRemoved","message.updated",t)}return"post"===e?Wc(r):el(r)},onReactorAdded:tl,onReactorRemoved:nl,getReactions:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const i=Date.now();r(`liveReactions(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s: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=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(rl,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({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[0].reactors.map(ce("reaction"))])]),qe(d,o),p(o)}),oe(l))};return u.push(tl(a.referenceType,a.referenceId,g("onAdded")),nl(a.referenceType,a.referenceId,g("onRemoved"))),m(),()=>{r(`liveReactions(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}}}),il={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 sl=["broadcast","conversation","community"],al=({type:e})=>sl.includes(e),cl=(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:ut()._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};function ll(e,t){return Object.assign(Object.assign({},e),{isUnreadCountSupport:al(e),unreadCount:cl(e,t)})}function ul(e,t){return Object.assign(Object.assign({},e),{unreadCount:cl(e,t),updatedAt:(new Date).toISOString()})}const dl=async e=>{let t=[];const n=e.channels.filter(al).map((({channelId:e})=>e));if(n.length>0)try{({data:t}=await ia(n))}catch(e){}const r=e.channels.map((e=>{const n=null==t?void 0:t.find((({entityId:t})=>t===e.channelId));return ll(e,n)})),o=xc(e.channelUsers);return Object.assign(Object.assign({},e),{channels:r,channelUsers:o})},hl=async e=>{const t=we();let n;t.log("channel/getChannel",e),bc("channel",e);try{const{data:r}=await t.http.get(`/api/v3/channels/${encodeURIComponent(e)}`);n=await dl(r)}catch(t){throw _(null==t?void 0:t.code)&&wc("channel",e),t}const r=t.cache&&Date.now();t.cache&&Vs(n,{cachedAt:r});const{channels:o}=n;return{data:o.find((t=>t.channelId===e)),cachedAt:r}};hl.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 fl=e=>{const t=we();return at(t,"onChannelCreated","channel.created",(async t=>{const n=await dl(t);Vs(n),e(n.channels[0])}))},pl=e=>{const t=we(),n=[at(t,"onChannelUpdated","channel.updated",(async t=>{const n=await dl(t);Vs(n),e(n.channels[0])})),at(t,"onChannelUpdated","local.channel.updated",(t=>e(t.channels[0]))),at(t,"onChannelUpdated","local.channelMarker.fetched",(async t=>{var n;const r=t.userEntityMarkers[0],o=["channel","get",r.entityId],i=null===(n=Le(o))||void 0===n?void 0:n.data;if(!i)return;const s=ul(i,r);$e(o,s),e(s)}))];return()=>{n.forEach((e=>e()))}},gl=e=>{const t=we();return at(t,"onChannelDeleted","channel.deleted",(async t=>{const n=await dl(t);Vs(n),e(n.channels[0])}))},ml=e=>{const t=we();return at(t,"onChannelJoined","channel.joined",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o[0])}))},yl=e=>{const t=we();return at(t,"onChannelLeft","channel.left",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o[0])}))},vl=e=>{const t=we();return at(t,"onChannelMuted","channel.setMuted",(async t=>{const n=await dl(t);Vs(n),e(n.channels[0])}))},bl=e=>{const t=we();return at(t,"onChannelMemberAdded","channel.membersAdded",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o.find((e=>"member"===e.membership)))}))},wl=e=>{const t=we();return at(t,"onChannelMemberRemoved","channel.membersRemoved",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o[0])}))},Cl=e=>{const t=we();return at(t,"onChannelMemberBanned","channel.banned",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o.find((e=>"banned"===e.membership)))}))},_l=e=>{const t=we();return at(t,"onChannelMemberUnbanned","channel.unbanned",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o.find((e=>"none"===e.membership)))}))},kl=async e=>{const t=we();t.log("channel/queryChannels",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,membership:i}=n,s=oa(n,["page","displayName","membership"]),{data:a}=await t.http.get("/api/v3/channels",{params:Object.assign(Object.assign({},s),{keyword:o,filter:i,options:{token:J(r,"skiplimit")}})}),{paging:c}=a,l=oa(a,["paging"]),u=await dl(l),{channels:d}=u,h=t.cache&&Date.now();if(t.cache){Vs(u,{cachedAt:h});const e=["channel","query",Object.assign(Object.assign({},s),{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}};kl.locally=e=>{var t,n;we().log("channel/queryChannels.locally",e);const r=null!=e?e:{},{page:o={limit:10}}=r,i=oa(r,["page"]),s=["channel","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Le(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.channels.length))return;const l=a.channels.map((e=>Le(["channel","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.channels)||void 0===n?void 0:n.length)?{data:l,cachedAt:c,prevPage:u,nextPage:d}:void 0};const Sl=async e=>{const t=we();t.log("channel/queryChannelMembers",e);const n=null!=e?e:{},{page:r}=n,o=oa(n,["page"]),{data:i}=await t.http.get(`/api/v4/channels/${encodeURIComponent(o.channelId)}/users`,{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:s}=i,a=oa(i,["paging"]),c=await dl(a),{channelUsers:l}=c,u=t.cache&&Date.now();if(t.cache){Vs(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:s})}return{data:l,cachedAt:u,nextPage:G(s.next),prevPage:G(s.previous)}};Sl.locally=e=>{var t,n;const r=we();if(r.log("channel/queryChannelMembers.locally",e),!r.cache)return;const{page:o}=e,i=oa(e,["page"]),s=["channelUsers","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Le(s))&&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};var El=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=>ct("channel.membersAdded",Object.assign(Object.assign({},r),{channelUsers:r.channelUsers.filter((t=>t.userId===e))}))));const o=await dl(r);n.cache&&Vs(o);const{channelUsers:i}=o;return!!i.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=>ct("channel.membersRemoved",Object.assign(Object.assign({},r),{channelUsers:r.channelUsers.filter((t=>t.userId===e))}))));const o=await dl(r);n.cache&&Vs(o);const{channelUsers:i}=o;return!!i.find((t=>t.channelId===e&&"member"!==t.membership))},getMembers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getMembers(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["channelUsers","collection",{channelId:e.channelId}],g=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["channelUsers","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];if(i=Ve(i,"roles",e.roles),e.memberships&&(i=i.filter((t=>!(!e.memberships.includes("muted")||!t.isMuted)||e.memberships.includes(t.membership)))),e.search){const t=new RegExp(e.search);i=i.filter((e=>e.userId.match(t)))}const s=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===s?Ze:Xe),t({onNextPage:y,data:i,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 i=ce("channelUsers")({channelId:e.channelId,userId:n.userId});"none"===n.membership?o.data=o.data.filter((e=>e!==i)):o.data.includes(i)||(o.data=[i,...o.data]),qe(d,o),g(o)},y=()=>{var e,t,n;const r=null===(e=Le(d))||void 0===e?void 0:e.data,o=null!==(t=null==r?void 0:r.data)&&void 0!==t?t:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(Sl,Object.assign(Object.assign({},a),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:c}}));ie(i,(({data:e,error:t,loading:n,nextPage:r})=>{const i={loading:n,error:t,params:{page:r},data:o};e&&(i.data=[...new Set([...o,...e.map(ce("channelUsers"))])]),qe(d,i),g(i)}),oe(l))};return u.push(ml(m()),yl(m()),bl(m()),wl(m()),Cl(m()),_l(m())),y(),()=>{r(`getMembers(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}}});var Al=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}),i=await dl(o);r.cache&&Vs(i);const{channelUsers:s}=i;return!!s.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}}),i=await dl(o);r.cache&&Vs(i);const{channelUsers:s}=i;return!!s.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 dl(r),{channelUsers:i}=o,s=n.cache&&Date.now();return n.cache&&Vs(o,{cachedAt:s}),{data:null==i?void 0:i.filter((e=>"banned"===e.membership)),cachedAt:s}},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 dl(r),i=n.cache&&Date.now();n.cache&&Vs(o,{cachedAt:i});const{channelUsers:s}=o;return{data:null==s?void 0:s.filter((e=>"member"===e.membership)),cachedAt:i}}}),Il=Object.freeze({__proto__:null,Membership:El,Moderation:Al,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 dl(n.data),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{channels:i}=r;return{data:i[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 dl(r),i=n.cache&&Date.now();n.cache&&Vs(o,{cachedAt:i});const{channels:s}=o;return{data:s.find((t=>t.channelId===e)),cachedAt:i}},deleteChannel:async e=>{const t=we();t.log("channel/deleteChannel",e),await t.http.delete(`/api/v3/channels/${encodeURIComponent(e)}`);return(await hl(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 dl(n);t.cache&&Vs(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 dl(n);t.cache&&Vs(r);const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"!==t.membership))},onChannelCreated:fl,onChannelUpdated:pl,onChannelDeleted:gl,onChannelJoined:ml,onChannelLeft:yl,onChannelMuted:vl,onChannelMemberAdded:bl,onChannelMemberRemoved:wl,onChannelMemberBanned:Cl,onChannelMemberUnbanned:_l,observeChannel:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeChannel(tmpid: ${r}) > listen`);const o=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.channelId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},i=[];return i.push(pl((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),gl((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),ml((e=>o({data:e,loading:!1,origin:"event"},"onJoin"))),yl((e=>o({data:e,loading:!1,origin:"event"},"onLeft"))),vl((e=>o({data:e,loading:!1,origin:"event"},"onMute"))),bl((e=>o({data:e,loading:!1,origin:"event"},"onMemberAdded"))),wl((e=>o({data:e,loading:!1,origin:"event"},"onMemberRemoved")))),ie(re(hl,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeChannel(tmpid: ${r}) > dispose`),i.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(fl((e=>o(e,"onCreate"))),pl((e=>o(e,"onUpdate"))),gl((e=>o(e,"onDelete"))),ml((e=>o(e,"onJoin"))),yl((e=>o(e,"onLeft"))),vl((e=>o(e,"onMute"))),bl((e=>o(e,"onMemberAdded"))),wl((e=>o(e,"onMemberRemoved")))),()=>{t(`observeChannels(tmpid: ${n}) > dispose`),r.forEach((e=>e()))}},getChannel:(e,t)=>da(e,t,"channelId",hl,[pl,gl,ml,yl,bl,wl,Cl,_l,vl,()=>ba((()=>null))]),getChannels:(e,t,n)=>{const{log:r,cache:o,userId:i}=we();o||console.log(p);const s=Date.now();r(`getChannels(tmpid: ${s}) > listen`);const{limit:a}=e,c=oa(e,["limit"]),l=null!=a?a:h,{policy:u=f}=null!=n?n:{},d=[],g=["channel","collection",{}],m=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["channel","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(s=Ve(s,"isDeleted",e.isDeleted),s=Ve(s,"displayName",e.displayName),e.types&&(s=s.filter((t=>{var n;return null===(n=e.types)||void 0===n?void 0:n.includes(t.type)}))),e.tags&&(s=s.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&&(s=s.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&&i&&(s=We(s,e.membership,i)),e.sortBy){case"firstCreated":s=s.sort(Xe);break;case"lastCreated":s=s.sort(Ze);break;case"displayName":s=s.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Ge);break;default:s=s.sort(et)}t({onNextPage:b,data:s,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=()=>{var e,t,n;const r=null===(e=Le(g))||void 0===e?void 0:e.data,o=null!==(t=null==r?void 0:r.data)&&void 0!==t?t:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(kl,Object.assign(Object.assign({},c),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:l}}));ie(i,(({data:e,error:t,loading:n,nextPage:r})=>{const i={loading:n,error:t,params:{page:r},data:o};e&&(i.data=[...new Set([...o,...e.map(ce("channel"))])]),qe(g,i),m(i)}),oe(u,y))};return d.push(fl(v()),gl(v()),pl(v()),vl(v()),ml(v()),yl(v()),bl(v()),wl(v()),ba((()=>null))),b(),()=>{r(`getChannels(tmpid: ${s}) > dispose`),d.forEach((e=>e())),He(g)}},MARKER_INCLUDED_CHANNEL_TYPE:sl,isUnreadCountSupport:al,convertFromRaw:ll,updateChannelMarker:ul,prepareChannelPayload:dl}),Tl={},Ol={},xl={};Object.defineProperty(xl,"__esModule",{value:!0}),xl.bytesToString=xl.stringToBytes=xl.NIL=xl.X500=xl.OID=xl.URL=xl.DNS=xl.hexToByte=xl.byteToHex=void 0;let Rl=[],Pl={};for(var Ml=0;Ml<256;Ml++)Rl[Ml]=(Ml+256).toString(16).substr(1),Pl[Rl[Ml]]=Ml;xl.byteToHex=Rl,xl.hexToByte=Pl,xl.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",xl.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",xl.OID="6ba7b812-9dad-11d1-80b4-00c04fd430c8",xl.X500="6ba7b814-9dad-11d1-80b4-00c04fd430c8",xl.NIL="00000000-0000-0000-0000-000000000000";xl.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};xl.bytesToString=e=>{const t=new Uint8Array(e,0,e.byteLength);return String.fromCharCode.apply(null,Array.from(t))},Object.defineProperty(Ol,"__esModule",{value:!0}),Ol.parse=void 0;const jl=xl;Ol.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++]=jl.hexToByte[e]),"")));o<16;)t[r+o++]=0;return t};var Nl={};Object.defineProperty(Nl,"__esModule",{value:!0}),Nl.unparse=void 0;const Fl=xl;Nl.unparse=(e,t)=>{let n=t||0,r=Fl.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 Bl={},Ul={};Object.defineProperty(Ul,"__esModule",{value:!0});Ul.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 Dl=_e&&_e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Bl,"__esModule",{value:!0}),Bl.validate=void 0;const Ll=Dl(Ul);Bl.validate=e=>"string"==typeof e&&Ll.default.test(e);var ql={};Object.defineProperty(ql,"__esModule",{value:!0}),ql.version=void 0;const zl=Bl;ql.version=e=>{if(!zl.validate(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)};var $l={},Hl={};Object.defineProperty(Hl,"__esModule",{value:!0}),Hl.stringify=void 0;const Vl=Bl,Wl=[];for(let e=0;e<256;++e)Wl.push((e+256).toString(16).substr(1));Hl.stringify=(e,t=0)=>{const n=(Wl[e[t+0]]+Wl[e[t+1]]+Wl[e[t+2]]+Wl[e[t+3]]+"-"+Wl[e[t+4]]+Wl[e[t+5]]+"-"+Wl[e[t+6]]+Wl[e[t+7]]+"-"+Wl[e[t+8]]+Wl[e[t+9]]+"-"+Wl[e[t+10]]+Wl[e[t+11]]+Wl[e[t+12]]+Wl[e[t+13]]+Wl[e[t+14]]+Wl[e[t+15]]).toLowerCase();if(!Vl.validate(n))throw TypeError("Stringified UUID is invalid");return n};var Kl={};Object.defineProperty(Kl,"__esModule",{value:!0}),Kl.rng=void 0;Kl.rng=()=>{let e=new Array(16);for(let t=0;t<16;t++)e[t]=255&256*Math.random()+0;return e},Object.defineProperty($l,"__esModule",{value:!0}),$l.v1=void 0;const Ql=Hl,Jl=Kl;let Gl,Yl,Xl=0,Zl=0;$l.v1=(e,t,n=0)=>{let r=t&&n||0;const o=t||new Uint8Array(16);let i=e&&e.node?e.node:Gl,s=e&&e.clockseq?e.clockseq:Yl;if(null==i||null==s){const t=e&&e.random?e.random:e&&e.rng?e.rng():Jl.rng();null==i&&(i=Gl=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==s&&(s=Yl=16383&(t[6]<<8|t[7]))}let a=e&&e.msecs?e.msecs:Date.now(),c=e&&e.nsecs?e.nsecs:Zl+1;const l=a-Xl+(c-Zl)/1e4;if(l<0&&e&&!e.clockseq&&(s=s+1&16383),(l<0||a>Xl)&&e&&!e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Xl=a,Zl=c,Yl=s,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++]=s>>>8|128,o[r++]=255&s;for(let e=0;e<6;++e)o[r+e]=i[e];return t||Ql.stringify(o)};var eu={};Object.defineProperty(eu,"__esModule",{value:!0}),eu.v4=void 0;const tu=Nl,nu=Kl;eu.v4=(e,t,n)=>{let r=t&&n||0,o=nu.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 i=0;i<16;i++)t[r+i]=o[i];return t||tu.unparse(o)};var ru={},ou={};Object.defineProperty(ou,"__esModule",{value:!0}),ou.v35=void 0;const iu=Hl,su=Ol,au=xl;ou.v35=(e,t,n)=>(e,r,o,i=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 s=new Uint8Array(16+e.length);if(s.set(r),s.set(e,r.length),s=au.stringToBytes(n(au.bytesToString(s))),s[6]=15&s[6]|t,s[8]=63&s[8]|128,o)for(let e=0;e<16;++e)o[i+e]=s[e];return o||iu.stringify(s)};var cu={};!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=>i(r(c(e))),e.default=e.hex_sha1;e.b64_sha1=e=>s(r(c(e)));e.any_sha1=(e,t)=>a(r(c(e)),t);e.hex_hmac_sha1=(e,t)=>i(o(c(e),c(t)));e.b64_hmac_sha1=(e,t)=>s(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 i=0;i<16;i++)r[i]=909522486^n[i],o[i]=1549556828^n[i];var s=d(r.concat(l(t)),512+8*t.length);return u(d(o.concat(s),672))},i=e=>{for(var n,r=t?"0123456789ABCDEF":"0123456789abcdef",o="",i=0;i<e.length;i++)n=e.charCodeAt(i),o+=r.charAt(n>>>4&15)+r.charAt(15&n);return o},s=e=>{for(var t="",r=e.length,o=0;o<r;o+=3)for(var i=e.charCodeAt(o)<<16|(o+1<r?e.charCodeAt(o+1)<<8:0)|(o+2<r?e.charCodeAt(o+2):0),s=0;s<4;s++)8*o+6*s>8*e.length?t+=n:t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>>6*(3-s)&63);return t},a=(e,t)=>{var n,r,o,i,s=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(i=[],o=0,n=0;n<c.length;n++)o=(o<<16)+c[n],o-=(r=Math.floor(o/s))*s,(i.length>0||r>0)&&(i[i.length]=r);a[a.length]=o,c=i}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,i=-1732584194,s=271733878,a=-1009589776,c=0;c<e.length;c+=16){for(var l=r,u=o,d=i,m=s,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,i,s)),p(p(a,n[v]),f(v)));a=s,s=i,i=g(o,30),o=r,r=t}r=p(r,l),o=p(o,u),i=p(i,d),s=p(s,m),a=p(a,y)}return[r,o,i,s,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}(cu);var lu=_e&&_e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(ru,"__esModule",{value:!0}),ru.v5=void 0;const uu=ou,du=lu(cu);ru.v5=uu.v35("v5",80,du.default),Object.defineProperty(Tl,"__esModule",{value:!0});const hu=Ol,fu=Nl,pu=Bl,gu=ql,mu=$l,yu=eu,vu=ru,bu=xl;var wu=Tl.default={parse:hu.parse,unparse:fu.unparse,validate:pu.validate,version:gu.version,v1:mu.v1,v4:yu.v4,v5:vu.v5,NIL:bu.NIL,DNS:bu.DNS,URL:bu.URL,OID:bu.OID,X500:bu.X500};const Cu=()=>`LOCAL_${wu.v4().toString()}`;let _u;const ku=async e=>{const t=we();t.log("message/createMessage",e);const n=e.referenceId||_u||Cu();_u=void 0;const{data:r}=await t.http.post("/api/v5/messages",Object.assign(Object.assign({},ya(e)),{referenceId:n})),o=await ma(r),{messages:i}=o,s=t.cache&&Date.now();return t.cache&&(He(["message","get",n]),Vs(o,{cachedAt:s})),ct("local.message.created",{messages:i}),{data:i[0],cachedAt:s}};ku.optimistically=e=>{var t,n,{referenceId:r}=e,o=oa(e,["referenceId"]);const i=we();if(!i.cache)return;_u=r||Cu();const s=Object.assign({messageId:_u,uniqueId:_u},o);i.log("message/createMessage.optimistically",s);const a=Le(["subChannel","get",o.subChannelId]);if(a&&($e(["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)&&$e(["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:i.userId,channelSegment:(null!==(n=null==a?void 0:a.data.messageCount)&&void 0!==n?n:0)+1,childrenNumber:0,createdAt:c,updatedAt:c},s);return qe(["message","get",l.messageId],l,{cachedAt:-5}),ct("local.message.created",{messages:[l]}),{cachedAt:-5,data:l}};const Su=async(e,t)=>{const n=we();n.log("message/updateMessage",t);const{data:r}=await n.http.put(`/api/v5/messages/${encodeURIComponent(e)}`,ya(t)),o=await ma(r),i=n.cache&&Date.now();n.cache&&Vs(o,{cachedAt:i});const{messages:s}=o;return ct("local.message.updated",{messages:s}),{data:s.find((t=>t.messageId===e)),cachedAt:i}};Su.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 $e(["message","get",e],o,{cachedAt:-1}),ct("local.message.updated",{messages:[o]}),{data:o,cachedAt:-1}};const Eu=async e=>{const t=we();t.log("message/deleteMessage",e),await t.http.delete(`/api/v5/messages/${encodeURIComponent(e)}`);const n=await Oc(e);return ct("local.message.deleted",{messages:[n.data]}),n.data};Eu.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 $e(["message","get",e],n,{cachedAt:-1}),ct("local.message.deleted",{messages:[n]}),{data:n,cachedAt:-1}};const Au=async e=>{const t=we();t.log("message/queryMessages",e);const n=va(e),{data:r}=await t.http.get("/api/v5/messages",{params:n}),{paging:o}=r,i=oa(r,["paging"]),s=await ma(i),{messages:a}=s,c=t.cache&&Date.now();if(t.cache){Vs(s,{cachedAt:c});qe(["message","query",n],{messages:a.map(ce("message")),paging:o})}ct("local.message.fetched",{messages:a});const l=Y(o.next);return{data:a,cachedAt:c,prevPage:Y(o.previous),nextPage:l}};var Iu=Object.freeze({__proto__:null,createMessage:ku,updateMessage:Su,deleteMessage:Eu,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&&Vs(r,{cachedAt:o}),!0},onMessageCreated:ba,onMessageUpdated:wa,onMessageDeleted:Ca,onMessageFlagged:_a,onMessageUnflagged:ka,onMessageFlagCleared:Sa,onMessageReactionAdded:Ea,onMessageReactionRemoved:Aa,onMessageFetched:Ia,getMessage:(e,t)=>da(e,t,"messageId",Oc,[Ia,wa,Ca,_a,ka,Sa,Ea,Aa]),getMessages:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getMessages(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["message","collection",{subChannelId:e.subChannelId}],g=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["message","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.includeDeleted||(i=Ve(i,"isDeleted",!1)),t({onNextPage:v,data:i,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),u.push((()=>He(d))),g(r))},v=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(Au,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({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("message"))])]),qe(d,o),g(o)}),oe(l,y))};return u.push(Ia(m()),ba(m()),wa(m()),Ca(m()),_a(m()),ka(m()),Sa(m()),Ea(m()),Aa(m())),v(),()=>{r(`getMessages(tmpid: ${i}) > 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 i=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.messageId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},s=[];return s.push(wa((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),Ca((e=>i({data:e,loading:!1,origin:"event"},"onDelete")))),"no_fetch"!==n&&ie(re(Oc,e),(e=>e.data&&i(e,"onFetch")),oe(n)),()=>{r(`observeMessages(tmpid: ${o}) > dispose`),s.forEach((e=>e()))}},observeMessages:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeMessages(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.subChannelId)===e){if(t instanceof Function)return t(n);null===(i=t.onEvent)||void 0===i||i.call(t,r,n),null===(s=t[r])||void 0===s||s.call(t,n)}};return o.push(ba((e=>i({data:e,loading:!1,origin:"event"},"onCreate"))),wa((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),Ca((e=>i({data:e,loading:!1,origin:"event"},"onDelete")))),()=>{n(`observeMessages(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},convertFromRaw:pa,updateMessageMarker:ga,prepareMessagePayload:ma,convertParams:ya,convertQueryParams:va});const Tu=async e=>{const t=we();t.log("channel/getSubChannel",e),bc("subChannel",e);try{const n=await t.http.get(`/api/v5/message-feeds/${encodeURIComponent(e)}`),r=await Ra(n.data),o=t.cache&&Date.now();return t.cache&&Vs(r,{cachedAt:o}),ct("local.message-feed.fetched",r),{data:r.messageFeeds[0],cachedAt:o}}catch(t){throw _(null==t?void 0:t.code)&&wc("subChannel",e),t}};Tu.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 Ou=e=>at(we(),"onSubChannelFetched","local.message-feed.fetched",(t=>e(t.messageFeeds[0])));function xu(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 Ru=async e=>{const t=we();t.log("channel/querySubChannels",e);const n=Pa(e),{page:r={limit:10},channelId:o,includeDeleted:i}=n,s=oa(n,["page","channelId","includeDeleted"]),a=(await t.http.get(`/api/v5/message-feeds/channel/${o}`,{params:Object.assign(Object.assign({},s),{isDeleted:ha(i),options:{token:J(r,"skiplimit")}})})).data,{paging:c}=a,l=oa(a,["paging"]),u=await Ra(l),d=u.messageFeeds,h=t.cache&&Date.now();if(t.cache){Vs(u,{cachedAt:h});const e=["subChannel","query",Object.assign(Object.assign({channelId:o},s),{options:Object.assign({},r)})];qe(e,{subChannels:d.map(ce("subChannel")),paging:c})}ct("local.message-feed.fetched",u);const f=G(c.next);return{data:d,cachedAt:h,prevPage:G(c.previous),nextPage:f}};Ru.locally=e=>{var t,n,r;we().log("channel/querySubChannels.locally",e);const o=null!==(t=Pa(e))&&void 0!==t?t:{},{page:i={limit:10},channelId:s}=o,a=oa(o,["page","channelId"]),c=["subChannel","query",Object.assign(Object.assign({channelId:s},a),{options:Object.assign({},i)})],{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 Pu=Object.freeze({__proto__:null,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 Ra(n.data),o=t.cache&&Date.now();return t.cache&&Vs(r,{cachedAt:o}),ct("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 Ra(r.data),i=n.cache&&Date.now();return n.cache&&Vs(o,{cachedAt:i}),ct("message-feed.updated",r.data),{data:o.messageFeeds[0],cachedAt:i}},deleteSubChannel:async(e,t=!1)=>{const n=we();n.log("channel/deleteSubChannel",e);const r=await Tu(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((()=>{wc("subChannel",e)}),0):$e(["subChannel","get",e],o),ct("local.message-feed.deleted",{messageFeeds:[o]}),o},startReadingAPI:Ma,stopReadingAPI:ja,onSubChannelCreated:Da,onSubChannelUpdated:La,onSubChannelDeleted:qa,getSubChannel:(e,t)=>da(e,t,"subChannelId",Tu,[Ou,La,qa]),getSubChannels:(e,t,n)=>{const{log:r,cache:o}=we(),i=Date.now();r(`getSubChannels(tmpid: ${i}) > listen`),o||console.log(p);const{limit:s=h}=e,a=oa(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(et),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(Ru,Object.assign(Object.assign({},a),{page:null!==(e=null==l?void 0:l.params.page)&&void 0!==e?e:{limit:s}}));ie(n,(({data:e,error:n,loading:r,nextPage:o})=>{l={loading:r,error:n,params:{page:o},data:e?xu(t,e):t},d(l)}),oe(c,y))};return u.push(Da(g("onCreate")),qa(g("onDelete")),Ou(g("onFetch")),La(g("onUpdate"))),m(),()=>{r(`getSubChannels(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},startReading:e=>(Fa[e]=!0,0===Na.length&&Ua(),Ma(e)),stopReading:e=>(Fa[e]=!1,Na.forEach((e=>e())),Na=[],ja(e))});const Mu=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},ju=e=>{const t=e.communities.map((e=>{var{needApprovalOnPostCreation:t,onlyAdminCanPost:n}=e,r=oa(e,["needApprovalOnPostCreation","onlyAdminCanPost"]);return Object.assign({postSetting:Mu({needApprovalOnPostCreation:t,onlyAdminCanPost:n})},r)})),n=xc(e.communityUsers);return Object.assign(Object.assign({},e),{communities:t,communityUsers:n})},Nu=e=>{const{postSetting:t}=e,r=oa(e,["postSetting"]);return Object.assign(Object.assign({},r),t?n[t]:void 0)},Fu=async e=>{const t=we();t.log("community/getCommunity",e);const{data:n}=await t.http.get(`/api/v3/communities/${e}`),r=ju(n),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{communities:i}=r;return{data:i.find((t=>t.communityId===e)),cachedAt:o}};Fu.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 Bu=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=ju(r),{communities:i}=o,s=t.cache&&Date.now();if(t.cache){Vs(o,{cachedAt:s});qe(["community","top-trending",{params:{options:{limit:n}}}],{communities:i.map(ce("community"))})}return{data:i,cachedAt:s}};Bu.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:{},i=["community","top-trending",{params:{options:{limit:o}}}],{data:s,cachedAt:a}=null!==(t=Le(i))&&void 0!==t?t:{};if(!(null==s?void 0:s.communities.length))return;const c=s.communities.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e));return c.length===(null===(n=null==s?void 0:s.communities)||void 0===n?void 0:n.length)?{data:c,cachedAt:a}:void 0};const Uu=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=ju(r),{communities:i}=o,s=t.cache&&Date.now();if(t.cache){Vs(o,{cachedAt:s});qe(["community","recommended",{params:{options:{limit:n}}}],{communities:i.map(ce("community"))})}return{data:i,cachedAt:s}};Uu.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:{},i=["community","recommended",{params:{options:{limit:o}}}],{data:s,cachedAt:a}=null!==(t=Le(i))&&void 0!==t?t:{};if(!(null==s?void 0:s.communities.length))return;const c=s.communities.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e));return c.length===(null===(n=null==s?void 0:s.communities)||void 0===n?void 0:n.length)?{data:c,cachedAt:a}:void 0};const Du=(e,t)=>{const n=we();return at(n,e,e,(e=>{const r=ju(e);if(n.cache){Vs(r);const e=Le(["community","get",r.communities[0].communityId]);t(e.data)}else t(r.communities[0])}))},Lu=e=>Du("community.created",e),qu=e=>Du("community.updated",e),zu=e=>Du("community.deleted",e);function $u(e,t){return e.map((e=>{const n=t.some((t=>function(e,t){const{userId:n}=ut();return e.communityId===t.communityId&&t.userId===n}(e,t)&&"none"!==t.communityMembership));return Object.assign(Object.assign({},e),{isJoined:n})}))}function Hu(e,t,n){return!!e.permissions.some((e=>e===n))||t.users.find((t=>t.userId===e.userId)).permissions.some((e=>e===n))}function Vu(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=>!Hu(e,t,"BAN_COMMUNITY_USER")))[0]:t.communityUsers.filter((e=>!Hu(e,t,"ADD_COMMUNITY_USER")))[0]}const Wu=(e,t)=>{const n=we();return at(n,e,e,(r=>{const o=ju(r),{communities:i,communityUsers:s}=o,a=$u(i,s);if(o.communities=a,n.cache){Vs(o);const n=Le(["community","get",o.communities[0].communityId]),r=Le(["communityUsers","get",ce("communityUsers")(Vu(e,o))]);t(n.data,r.data)}else t(o.communities[0],Vu(e,o))}))},Ku=e=>Wu("community.userAdded",e),Qu=e=>Wu("community.userRemoved",e),Ju=e=>Wu("community.userBanned",e),Gu=e=>Wu("community.userChanged",e),Yu=e=>Wu("community.userUnbanned",e),Xu=e=>Wu("community.roleAdded",e),Zu=e=>Wu("community.roleRemoved",e),ed=e=>Wu("community.joined",e),td=e=>Wu("community.left",e),nd=async e=>{const t=we();t.log("channel/queryCommunities",e);const n=null!=e?e:{},{page:r}=n,o=oa(n,["page"]),i=null!=o?o:{},{displayName:s,membership:a,includeDeleted:c}=i,l=oa(i,["displayName","membership","includeDeleted"]),{data:u}=await t.http.get("/api/v3/communities",{params:Object.assign(Object.assign({},l),{isDeleted:ha(c),keyword:s,filter:a,options:{token:J(r,"skiplimit")}})}),{paging:d}=u,h=oa(u,["paging"]),f=ju(h),{communities:p}=f,g=t.cache&&Date.now();if(t.cache){Vs(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}};nd.locally=e=>{we().log("community/queryCommunities.locally",e)};var rd=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});ct("community.userAdded",r);const o=Rc(r,"communityUsers");n.cache&&Vs(o);const{communityUsers:i}=o;return!!i.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}});ct("community.userRemoved",r);const o=Rc(r,"communityUsers");n.cache&&Vs(o);const{communityUsers:i}=o;return!!i.find((t=>t.communityId===e&&"member"!==t.communityMembership))},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}),i=Rc(o,"communityUsers");r.cache&&Vs(i);const{communityUsers:s}=i;return!!s.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}}),i=Rc(o,"communityUsers");r.cache&&Vs(i);const{communityUsers:s}=i;return!!s.find((n=>n.communityId===e&&!t.some((e=>n.roles.includes(e)))))}});const od=async e=>{const t=we();t.log("community/queryCommunityMembers",e);const n=null!=e?e:{},{page:r}=n,o=oa(n,["page"]),{data:i}=await t.http.get(`/api/v3/communities/${o.communityId}/users`,{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:s}=i,a=oa(i,["paging"]),c=Rc(a,"communityUsers"),{communityUsers:l}=c,u=t.cache&&Date.now();if(t.cache){Vs(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:s})}return{data:l,cachedAt:u,nextPage:G(s.next),prevPage:G(s.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:i}=o,s=oa(o,["page"]),a=["communityUsers","query",Object.assign(Object.assign({},s),{options:Object.assign({},i)})],{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 id=Object.freeze({__proto__:null,getMembers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getMembers(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["communityUsers","collection",{communityId:e.communityId}],g=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["communityUsers","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];if(e.roles&&(i=i.filter((t=>{var n;return null===(n=t.roles)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.roles)||void 0===n?void 0:n.includes(t)}))}))),e.membership&&(i=i.filter((({communityMembership:t})=>e.membership.includes(t)))),e.search){const t=new RegExp(e.search);i=i.filter((e=>{var n;return!!e.userId.match(t)||e.user&&(null===(n=e.user.displayName)||void 0===n?void 0:n.match(t))}))}const s=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===s?Ze:Xe),t({onNextPage:y,data:i,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 i=ce("communityUsers")({communityId:e.communityId,userId:n.userId});o.data=[...new Set([i,...o.data])],qe(d,o),g(o)},y=()=>{var e,t,n;const r=null===(e=Le(d))||void 0===e?void 0:e.data,o=null!==(t=null==r?void 0:r.data)&&void 0!==t?t:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(od,Object.assign(Object.assign({},a),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:c}}));ie(i,(({data:e,error:t,loading:n,nextPage:r})=>{const i={loading:n,error:t,params:{page:r},data:o};e&&(i.data=[...new Set([...o,...e.map(ce("communityUsers"))])]),qe(d,i),g(i)}),oe(l))};return u.push(td(m()),ed(m()),Ju(m()),Yu(m()),Gu(m()),Xu(m()),Zu(m())),y(),()=>{r(`getMembers(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},onCommunityUserAdded:Ku,onCommunityUserRemoved:Qu,onCommunityUserBanned:Ju,onCommunityUserChanged:Gu,onCommunityUserUnbanned:Yu,onCommunityUserRoleAdded:Xu,onCommunityUserRoleRemoved:Zu,onCommunityJoined:ed,onCommunityLeft:td}),sd=Object.freeze({__proto__:null,Moderation:rd,Membership:id,createCommunity:async e=>{const t=we();t.log("user/createCommunity",e);const{data:n}=await t.http.post("/api/v3/communities/",Nu(e));ct("community.created",n);const r=ju(n),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{communities:i}=r;return{data:i[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}`,Nu(t));ct("community.updated",r);const o=ju(r),i=n.cache&&Date.now();n.cache&&Vs(o,{cachedAt:i});const{communities:s}=o;return{data:s.find((t=>t.communityId===e)),cachedAt:i}},deleteCommunity:async e=>{const t=we();t.log("community/deleteCommunity",e),await t.http.delete(`/api/v3/communities/${e}`);const n=await Fu(e);return ct("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`);ct("community.joined",n);const r=ju(n),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{communityUsers:i}=r;return!!i.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`);ct("community.left",n);const r=ju(n),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{communityUsers:i}=r;return!!i.find((t=>t.communityId===e&&"member"!==t.communityMembership))},getTopTrendingCommunities:Bu,getRecommendedCommunities:Uu,onCommunityCreated:Lu,onCommunityUpdated:qu,onCommunityDeleted:zu,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)},i=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.communityId)===e&&o(t,n)},s=[];return s.push(qu((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),zu((e=>i({data:e,loading:!1,origin:"event"},"onDelete"))),ed((e=>i({data:e,loading:!1,origin:"event"},"onJoin"))),td((e=>i({data:e,loading:!1,origin:"event"},"onLeft"))),Ku((e=>i({data:e,loading:!1,origin:"event"},"onUserAdded"))),Qu((e=>i({data:e,loading:!1,origin:"event"},"onUserRemoved"))),Ju((e=>i({data:e,loading:!1,origin:"event"},"onUserBanned"))),Yu((e=>i({data:e,loading:!1,origin:"event"},"onUserUnbanned")))),ie(re(Fu,e),(e=>(e.data||e.error)&&o(e,"onFetch"))),()=>{n(`observeCommunity(tmpid: ${r}) > dispose`),s.forEach((e=>e()))}},getCommunities:(e,t,n)=>{const{log:r,cache:o,userId:i}=we();o||console.log(p);const s=Date.now();r(`getCommunities(tmpid: ${s}) > listen`);const{limit:a}=e,c=oa(e,["limit"]),l=null!=a?a:h,{policy:u=f}=null!=n?n:{},d=[],g=["community","collection",{}],m=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];s=Ve(s,"displayName",e.displayName),e.includeDeleted||(s=Ve(s,"isDeleted",!1)),e.categoryId&&(s=s.filter((t=>{var n;return null===(n=t.categoryIds)||void 0===n?void 0:n.includes(e.categoryId)}))),e.tags&&(s=s.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&&i&&(s=Qe(s,e.membership,i));const a=e.sortBy||"lastCreated";"lastCreated"!==a&&"firstCreated"!==a||(s=s.sort("lastCreated"===a?Ze:Xe)),"displayName"===a&&(s=s.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Ge)),t({onNextPage:b,data:s,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=()=>{var e,t,n;const r=null===(e=Le(g))||void 0===e?void 0:e.data,o=null!==(t=null==r?void 0:r.data)&&void 0!==t?t:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(nd,Object.assign(Object.assign({},c),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:l}}));ie(i,(({data:e,error:t,loading:n,nextPage:r})=>{const i={loading:n,error:t,params:{page:r},data:o};e&&(i.data=[...new Set([...o,...e.map(ce("community"))])]),qe(g,i),m(i)}),oe(u,y))};return d.push(Lu(v()),zu(v()),qu(v()),ed(v()),td(v()),Gu(v())),b(),()=>{r(`getCommunities(tmpid: ${s}) > dispose`),d.forEach((e=>e())),He(g)}},getCommunity:(e,t)=>da(e,t,"communityId",Fu,[qu,zu,ed,td,Ju,Yu,Gu])});const ad=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&&Vs(n,{cachedAt:r});const{categories:o}=n;return{data:o.find((t=>t.categoryId===e)),cachedAt:r}};ad.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 cd=async e=>{const t=we();t.log("category/queryCategories",e);const n=null!=e?e:{},{page:r={limit:10},includeDeleted:o}=n,i=oa(n,["page","includeDeleted"]),{data:s}=await t.http.get("/api/v3/community-categories",{params:Object.assign(Object.assign({},i),{isDeleted:ha(o),options:{token:J(r,"skiplimit")}})}),{paging:a}=s,c=oa(s,["paging"]),{categories:l}=c,u=t.cache&&Date.now();if(t.cache){Vs(c,{cachedAt:u});const e=["category","query",Object.assign(Object.assign({},i),{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}};cd.locally=e=>{var t,n;const r=we();if(r.log("category/queryCategories.locally",e),!r.cache)return;const o=null!=e?e:{},{page:i={limit:10}}=o,s=oa(o,["page"]),a=["category","query",Object.assign(Object.assign({},s),{options:Object.assign({},i)})],{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 ld=Object.freeze({__proto__:null,getCategory:ad,getCategories:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getCategories(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["category","collection",{}],g=()=>{var n,r,o;const i=null===(n=Le(d))||void 0===n?void 0:n.data,s=null!==(r=null==i?void 0:i.data)&&void 0!==r?r:[];if(s.length>0&&!(null==i?void 0:i.params.page))return;const u=re(cd,Object.assign(Object.assign({},a),{page:null!==(o=null==i?void 0:i.params.page)&&void 0!==o?o:{limit:c}}));ie(u,(({data:n,error:r,loading:o,nextPage:i})=>{const a={loading:o,error:r,params:{page:i},data:s};n&&(a.data=[...new Set([...s,...n.map(ce("category"))])]),qe(d,a),(n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["category","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(e.includeDeleted||(i=Ve(i,"isDeleted",!1)),e.sortBy){case"firstCreated":i=i.sort(Xe);break;case"lastCreated":i=i.sort(Ze);break;default:i=i.sort(Ye)}t({onNextPage:g,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})})(a)}),oe(l))};return u.push((()=>{})),g(),()=>{r(`getCategories(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}}});const ud=async e=>{const t=we();t.log("feed/queryGlobalFeed",e);const n=null!=e?e:{},{useCustomRanking:r,page:o}=n,i=oa(n,["useCustomRanking","page"]),{data:s}=await t.http.get(r?"/api/v5/me/global-feeds":"/api/v4/me/global-feeds",{params:Object.assign(Object.assign({},i),{options:{token:J(o,"skiplimit")}})}),{paging:a}=s,c=oa(s,["paging"]),l=Rc(c,"communityUsers"),{posts:u}=l,d=t.cache&&Date.now();if(t.cache){Vs(l);const e=["globalFeed","query",Object.assign(Object.assign({},i),{useCustomRanking:r,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}};ud.locally=e=>{var t,n;const r=we();if(r.log("post/queryGlobalFeed.locally",e),!r.cache)return;const o=null!=e?e:{},{useCustomRanking:i,page:s}=o,a=oa(o,["useCustomRanking","page"]),c=["globalFeed","query",Object.assign(Object.assign({},a),{useCustomRanking:i,options:Object.assign({},s)})],{data:l,cachedAt:u}=null!==(t=Le(c))&&void 0!==t?t:{};if(!(null==l?void 0:l.posts.length))return;const d=l.posts.map((e=>Le(["post","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===(n=null==l?void 0:l.posts)||void 0===n?void 0:n.length)?{data:d,cachedAt:u,prevPage:h,nextPage:f}:void 0};var dd=Object.freeze({__proto__:null,queryGlobalFeed:ud});const hd=async e=>{const t=we();t.log("post/queryPosts",e);const{page:n={limit:10},includeDeleted:r}=e,o=oa(e,["page","includeDeleted"]),{dataTypes:i,matchingOnlyParentPost:s}=o,{data:a}=await t.http.get("/api/v4/posts",{params:Object.assign(Object.assign({},o),{isDeleted:ha(r),matchingOnlyParentPost:null!=s?s:!(null==i?void 0:i.length),options:{token:J(n,"afterbeforeraw")}})}),{paging:c}=a,l=oa(a,["paging"]),u=Rc(l,"communityUsers"),{posts:d}=l,h=t.cache&&Date.now();if(t.cache){Vs(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}};hd.locally=e=>{var t,n;const r=we();if(r.log("post/queryPosts.locally",e),!r.cache)return;const{page:o={limit:10}}=e,i=oa(e,["page"]),s=["post","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Le(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.posts.length))return;const l=a.posts.map((e=>Le(["post","get",e]))).filter(Boolean).map((({data:e})=>e)),u=Y(null==a?void 0:a.paging.previous),d=Y(null==a?void 0:a.paging.next);return l.length===(null===(n=null==a?void 0:a.posts)||void 0===n?void 0:n.length)?{data:l,cachedAt:c,prevPage:u,nextPage:d}:void 0};var fd=Object.freeze({__proto__:null,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);ct("post.created",n);const r=Rc(n,"communityUsers"),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{posts:i}=r;return{data:i[0],cachedAt:o}},updatePost:async(e,t)=>{const n=we();n.log("user/updatePost",t);const{data:r}=await n.http.put(`/api/v4/posts/${encodeURIComponent(e)}`,t),o=Rc(r,"communityUsers"),i=n.cache&&Date.now();n.cache&&Vs(o,{cachedAt:i}),ct("post.updated",o);const{posts:s}=o;return{data:s.find((t=>t.postId===e)),cachedAt:i}},deletePost:async(e,t=!1)=>{const n=we();n.log("post/deletePost",e);const r=await Pc(e);if(await n.http.delete(`/api/v4/posts/${encodeURIComponent(e)}`,{params:{postId:e,permanent:t}}),"community"===r.data.targetType){const e=await Fu(r.data.targetId);ct("community.updated",{communities:[e.data],categories:[],communityUsers:[],feeds:[],files:[],users:[]})}const o=Object.assign(Object.assign({},r.data),{isDeleted:!0});return ct("post.deleted",{posts:[o],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),t?setTimeout((()=>{wc("post",e)}),0):$e(["post","get",e],{isDeleted:!0}),o},approvePost:async e=>{const t=we();t.log("post/approvePost",e);const{data:n}=await t.http.post(`/api/v3/posts/${encodeURIComponent(e)}/approve`);ct("post.approved",n),"community"===n.posts[0].targetType&&ct("community.updated",n);const r=Rc(n,"communityUsers"),o=t.cache&&Date.now();return t.cache&&Vs(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&&ct("community.updated",n),ct("post.declined",n);const r=Rc(n,"communityUsers"),o=t.cache&&Date.now();return t.cache&&Vs(r,{cachedAt:o}),{data:n.posts.find((t=>t.postId===e)),cachedAt:o}},onPostCreated:Uc,onPostUpdated:Dc,onPostDeleted:Lc,onPostApproved:qc,onPostDeclined:zc,onPostFlagged:$c,onPostUnflagged:Hc,onPostReactionAdded:Vc,onPostReactionRemoved:Wc,observePosts:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observePosts(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;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===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(Uc((e=>i(e,"onCreate"))),Dc((e=>i(e,"onUpdate"))),Lc((e=>i(e,"onDelete"))),qc((e=>i(e,"onApproved"))),zc((e=>i(e,"onDeclined"))),$c((e=>i(e,"onFlagged"))),Hc((e=>i(e,"onUnflagged"))),Vc((e=>i(e,"onReactionAdded"))),Wc((e=>i(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 i=(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.postId)===e&&i(t,n)},a=[];return a.push(Dc((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Lc((e=>s({data:e,loading:!1,origin:"event"},"onDelete"))),qc((e=>s({data:e,loading:!1,origin:"event"},"onApproved"))),zc((e=>s({data:e,loading:!1,origin:"event"},"onDeclined"))),$c((e=>s({data:e,loading:!1,origin:"event"},"onFlagged"))),Hc((e=>s({data:e,loading:!1,origin:"event"},"onUnflagged"))),Vc((e=>s({data:e,loading:!1,origin:"event"},"onReactionAdded"))),Wc((e=>s({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),ie(re(Pc,e),(e=>(e.data||e.error)&&i(e,"onFetch")),oe(n)),()=>{r(`observePosts(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},getPost:(e,t)=>da(e,t,"postId",Pc,[qc,zc,Lc,$c,Vc,Wc,Hc,Dc]),getPosts:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getPosts(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["post","collection",{targetId:e.targetId,targetType:e.targetType}],g=n=>{var r,o,i;let s=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";s=s.sort("lastCreated"===a?Ze:Xe),e.includeDeleted||(s=Ve(s,"isDeleted",!1)),e.tags&&(s=s.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&&(s=Ke(s,e.feedType)),(null===(o=e.dataTypes)||void 0===o?void 0:o.length)&&(s=Je(s,e.dataTypes)),t({onNextPage:v,data:s,hasNextPage:!!(null===(i=n.params)||void 0===i?void 0:i.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),u.push((()=>He(d))),g(o))},v=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(hd,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({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("post"))])]),qe(d,o),g(o)}),oe(l,y))};return u.push(Uc(m("onCreate")),qc(m("onApproved")),zc(m("onDeclined")),Lc(m("onDelete")),Dc(m("onUpdate")),$c(m("onFlagged")),Hc(m("onUnflagged")),Vc(m("onReactionAdded")),Wc(m("onReactionRemoved"))),v(),()=>{r(`getPosts(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}}});const pd=async e=>{const t=we();t.log("comment/queryComments",e);const{page:n={limit:10},includeDeleted:r}=e,o=oa(e,["page","includeDeleted"]),i={type:o.sortBy?"pagination":void 0,token:J(n,o.sortBy?"skiplimit":"afterbefore")},{data:s}=await t.http.get("/api/v3/comments",{params:Object.assign(Object.assign({},o),{isDeleted:ha(r),options:i})}),{paging:a}=s,c=oa(s,["paging"]),{comments:l}=c,u=t.cache&&Date.now();if(t.cache){Vs(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}};pd.locally=e=>{var t,n;const r=we();if(r.log("comment/queryComments.locally",e),!r.cache)return;const{page:o={limit:10}}=e,i=oa(e,["page"]),s=["comment","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Le(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.comments.length))return;const l=a.comments.map((e=>Le(["comment","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.comments)||void 0===n?void 0:n.length)?{data:l,cachedAt:c,prevPage:u,nextPage:d}:void 0};var gd=Object.freeze({__proto__:null,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&&Vs(n,{cachedAt:r});const o=await Pc(e.referenceId);ct("post.updated",{posts:[o.data],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),ct("comment.created",n);const{comments:i}=n;return{data:i[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&&Vs(r,{cachedAt:o}),ct("comment.updated",r);const{comments:i}=r;return{data:i.find((t=>t.commentId===e)),cachedAt:o}},deleteComment:async(e,t=!1)=>{const n=we();n.log("comment/deleteComment",e);const r=await Mc(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}),i=await Pc(r.data.referenceId);return ct("post.updated",{posts:[i.data],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),ct("comment.deleted",{comments:[o],commentChildren:[],files:[],users:[]}),t?rt((()=>wc("comment",e))):$e(["comment","get",e],{isDeleted:!0}),o},onCommentCreated:Qc,onCommentUpdated:Jc,onCommentDeleted:Gc,onCommentFlagged:Yc,onCommentUnflagged:Xc,onCommentReactionAdded:Zc,onCommentReactionRemoved:el,observeComments:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeComments(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;if(n.referenceId===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(Qc((e=>i(e,"onCreate"))),Jc((e=>i(e,"onUpdate"))),Gc((e=>i(e,"onDelete"))),Yc((e=>i(e,"onFlagged"))),Xc((e=>i(e,"onUnflagged"))),Zc((e=>i(e,"onReactionAdded"))),el((e=>i(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 i=(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.commentId)===e&&i(t,n)},a=[];return a.push(Jc((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Gc((e=>s({data:e,loading:!1,origin:"event"},"onDelete"))),Yc((e=>s({data:e,loading:!1,origin:"event"},"onFlagged"))),Xc((e=>s({data:e,loading:!1,origin:"event"},"onUnflagged"))),Zc((e=>s({data:e,loading:!1,origin:"event"},"onReactionAdded"))),el((e=>s({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),ie(re(Mc,e),(e=>(e.data||e.error)&&i(e,"onFetch")),oe(n)),()=>{r(`observeComment(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},getComment:(e,t)=>da(e,t,"commentId",Mc,[Gc,Yc,Zc,el,Xc,Jc]),getComments:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const i=Date.now();r(`getComments(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["comment","collection",{referenceId:e.referenceType,referenceType:e.referenceId}],p=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["comment","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.includeDeleted||(i=Ve(i,"isDeleted",!1));const s=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===s?Ze:Xe),t({onNextPage:m,data:i,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=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(pd,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({data:e,error:t,loading:n,prevPage:r,nextPage:o})=>{const i={loading:n,error:t,params:{page:a.sortBy?o:r},data:s};e&&(i.data=[...new Set([...s,...e.map(ce("comment"))])]),qe(d,i),p(i)}),oe(l,y))};return u.push(Qc(g("onCreate")),Jc(g("onUpdate")),Gc(g("onDelete")),Yc(g("onFlagged")),Xc(g("onUnflagged")),Zc(g("onReactionAdded")),el(g("onReactionRemoved"))),m(),()=>{r(`getComments(tmpid: ${i}) > dispose`),u.forEach((e=>e())),He(d)}}});const md=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&&Vs(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}};md.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 yd=async e=>{const t=we();t.log("stream/getStreams",e);const n=null!=e?e:{},{page:r}=n,o=oa(n,["page"]),{data:i}=await t.http.get("/api/v3/video-streaming",{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:s,results:a}=i,{videoStreamings:c}=a,l=t.cache&&Date.now();t.cache&&Vs(a,{cachedAt:l});const u=G(s.next);return{data:c,cachedAt:l,prevPage:G(s.previous),nextPage:u}};yd.locally=e=>{we().log("stream/getStreams.locally",e)};var vd=Object.freeze({__proto__:null,getStream:md,getStreams:yd,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&&Vs(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&&Vs(r,{cachedAt:o});const{videoStreamings:i}=r;return{data:i.find((t=>t.streamId===e)),cachedAt:o}},deleteStream:async e=>{const t=we();t.log("stream/deleteStream",e);const n=await md(e),{data:r}=await t.http.delete(`/api/v3/video-streaming/${e}`),{success:o}=r,i=Object.assign(Object.assign({},n.data),{isDeleted:!0});return $e(["stream","get",e],i),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&&Vs(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}},onStreamStarted:e=>{const t=we();return at(t,"stream/onStreamStarted","video-streaming.didStart",(t=>{Vs(t),e(t.videoStreamings[0])}))},onStreamStopped:e=>{const t=we();return at(t,"stream/onStreamStarted","video-streaming.didStop",(t=>{Vs(t),e(t.videoStreamings[0])}))},onStreamRecorded:e=>{const t=we();return at(t,"stream/onStreamRecorded","video-streaming.didRecord",(t=>{Vs(t),e(t.videoStreamings[0])}))}});const bd=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&&Vs(n,{cachedAt:r});const{polls:o}=n;return{data:o.find((t=>t.pollId===e)),cachedAt:r}};bd.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 wd=e=>{const t=we();return at(t,"poll/onPollUpdated","poll.updated",(n=>{t.cache&&Vs(n),e(n.polls[0])}))},Cd=e=>{const t=we();return at(t,"poll/onPollDeleted","poll.deleted",(n=>{t.cache&&Vs(n),e(n.polls[0])}))};var _d=Object.freeze({__proto__:null,getPoll:bd,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&&Vs(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&&Vs(n,{cachedAt:r}),ct("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 bd(e),{data:r}=await t.http.delete(`/api/v3/polls/${e}`),{success:o}=r,i=Object.assign(Object.assign({},n.data),{isDeleted:!0});return $e(["poll","get",e],i),ct("poll.deleted",{polls:[i],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&&Vs(r,{cachedAt:o});const{polls:i}=r;return ct("poll.updated",r),{data:i.find((t=>t.pollId===e)),cachedAt:o}},onPollUpdated:wd,onPollDeleted:Cd,observePoll:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observePoll(tmpid: ${o}) > listen`);const i=(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.pollId)===e&&i(t,n)},a=[];return a.push(wd((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Cd((e=>s({data:e,loading:!1,origin:"event"},"onDelete")))),ie(re(bd,e),(e=>(e.data||e.error)&&i(e,"onFetch")),oe(n)),()=>{r(`observePoll(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}}});return e.API_REGIONS=Mt,e.CategoryRepository=ld,e.ChannelRepository=Il,e.Client=Ya,e.CommentRepository=gd,e.CommunityPostSettingMaps=n,e.CommunityPostSettings=t,e.CommunityRepository=sd,e.ContentFeedType=o,e.DefaultCommunityPostSetting=r,e.FeedRepository=dd,e.FileRepository=Ec,e.FileType=i,e.MessageContentType=l,e.MessageRepository=Iu,e.PollRepository=_d,e.PostContentType=u,e.PostRepository=fd,e.ReactionRepository=ol,e.StreamRepository=vd,e.SubChannelRepository=Pu,e.UserRepository=kc,e.VERSION=d,e.VideoResolution=s,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 i=Object.fromEntries(Object.entries(r.data).filter((([e,n])=>t(n))));return!!Object.keys(i).length&&(await Ue.setItem(`${e}#${o}`,JSON.stringify(i)),!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}=il[e];return`/api/v3/${n}/${encodeURIComponent(t)}/flag`})());if(n.cache)if("message"===e){const e=await ma(r);Vs(e)}else Vs("post"===e?Rc(r,"communityUsers"):r);return ct(`${e}.flagged`,r),!!r},e.createUserToken=async(e,t,n)=>{const r=Ds(),o=Ls(),i=yr(Nt("http",t)),{data:s}=await i.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:s.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}=il[e];return`/api/v3/${n}/${encodeURIComponent(t)}/unflag`})());if(n.cache)if("message"===e){const e=await ma(r);Vs(e)}else Vs("post"===e?Rc(r,"communityUsers"):r);return ct(`${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=We,e.filterByCommunityMembership=Qe,e.filterByFeedType=Ke,e.filterByPostDataTypes=Je,e.filterByPropEquality=Ve,e.filterByPropInclusion=(e,t,n)=>void 0!==n?e.filter((e=>n.includes(e[t]))):e,e.getChannelMarkers=ia,e.getChannelTopic=e=>`${e.path}/#`,e.getCommentTopic=({path:e})=>e,e.getCommunityTopic=({path:t},n=e.SubscriptionLevels.COMMUNITY)=>ft(t,n),e.getMessageMarkers=sa,e.getMessageTopic=e=>e.path,e.getMyFollowersTopic=()=>{const e=ut();return`${pt(e)}/membership/${e._id}/+/+`},e.getMyFollowingsTopic=()=>{const e=ut();return`${pt(e)}/membership/+/${e._id}/+`},e.getNetworkTopic=mt,e.getPostTopic=({path:t},n=e.SubscriptionLevels.POST)=>"comment"===n?`${t}/comment/+`:t,e.getRole=Ic,e.getSmartFeedChannelTopic=yt,e.getSmartFeedMessageTopic=bt,e.getSmartFeedSubChannelTopic=vt,e.getSubChannelMarkers=aa,e.getSubChannelTopic=e=>`${e.path}/#`,e.getUserMarker=la,e.getUserTopic=gt,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:i,primaryKey:s}=il[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(async(e,t,n)=>{const{ws:r}=e;return await new Promise(((e,o)=>{r.emit(t,n,(t=>{try{e(mr(t))}catch(e){o(e)}}))}))})(o,i,{[s]:t}))&&void 0!==n?n:{};return null!==(r=null!=a?a:c)&&void 0!==r&&r},e.isSkip=V,e.mergeInCache=ze,e.onChannelMarkerFetched=e=>{const t=we();return at(t,"channelMarker/onChannelMarkerFetched","local.channelMarker.fetched",(t=>{e(t.userEntityMarkers[0])}))},e.onFeedMarkerFetched=e=>{const t=we();return at(t,"feedMarker/onFeedMarkerFetched","local.feedMarker.fetched",(t=>{e(t.feedMarkers[0])}))},e.onMessageMarkerFetched=e=>{const t=we();return at(t,"messageMarker/onMessageMarkerFetched","local.messageMarker.fetched",(t=>{e(t.contentMarkers[0])}))},e.onSubChannelMarkerFetched=e=>{const t=we();return at(t,"subChannelMarker/onSubChannelMarkerFetched","local.subChannelMarker.fetched",(t=>{e(t.userFeedMarkers[0])}))},e.onSubChannelMarkerUpdated=e=>{const t=we();return at(t,"subChannelMarker/onSubChannelMarkerUpdated","local.subChannelMarker.updated",(t=>{e(t.userFeedMarkers[0])}))},e.onUserMarkerFetched=ua,e.pullFromCache=Le,e.pushToCache=qe,e.queryCache=De,e.queryOptions=oe,e.queryRoles=Ac,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=ie,e.sortByChannelSegment=({channelSegment:e},{channelSegment:t})=>e-t,e.sortByDisplayName=Ge,e.sortByFirstCreated=Xe,e.sortByLastActivity=et,e.sortByLastCreated=Ze,e.sortByName=Ye,e.sortBySegmentNumber=({segmentNumber:e},{segmentNumber:t})=>e-t,e.subscribeTopic=_t,e.toPage=G,e.toPageRaw=Y,e.toToken=J,e.upsertInCache=$e,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 i(e,t){for(var n in e)t[n]=e[n]}function s(e,t,n){return o(e,t,n)}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?t.exports=r:(i(r,n),n.Buffer=s),s.prototype=Object.create(o.prototype),i(o,s),s.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return o(e,t,n)},s.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},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o(e)},s.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 i(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 s(e){var t=i(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=s(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 i(){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=i;var s=/^([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 i)return e;var r=new i;return r.parse(e,t,n),r}function C(e){return o.isString(e)&&(e=w(e)),e instanceof i?e.format():i.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}i.prototype.parse=function(e,t,n){if(!o.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var i=e.indexOf("?"),a=-1!==i&&i<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=s.exec(C);if(k){var S=(k=k[0]).toLowerCase();this.protocol=S,C=C.substr(k.length)}if(n||k||C.match(/^\/\/[^@\/]+@[^@\/]+/)){var E="//"===C.substr(0,2);!E||k&&y[k]||(C=C.substr(2),this.slashes=!0)}if(!y[k]&&(E||k&&!v[k])){for(var A,I,T=-1,O=0;O<h.length;O++)-1!==(x=C.indexOf(h[O]))&&(-1===T||x<T)&&(T=x);for(-1!==(I=-1===T?C.lastIndexOf("@"):C.lastIndexOf("@",T))&&(A=C.slice(0,I),C=C.slice(I+1),this.auth=decodeURIComponent(A)),T=-1,O=0;O<d.length;O++){var x;-1!==(x=C.indexOf(d[O]))&&(-1===T||x<T)&&(T=x)}-1===T&&(T=C.length),this.host=C.slice(0,T),C=C.slice(T),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=(O=0,P.length);O<M;O++){var j=P[O];if(j&&!j.match(p)){for(var N="",F=0,B=j.length;F<B;F++)j.charCodeAt(F)>127?N+="x":N+=j[F];if(!N.match(p)){var U=P.slice(0,O),D=P.slice(O+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:"",z=this.hostname||"";this.host=z+q,this.href+=this.host,R&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==C[0]&&(C="/"+C))}if(!m[S])for(O=0,M=u.length;O<M;O++){var $=u[O];if(-1!==C.indexOf($)){var H=encodeURIComponent($);H===$&&(H=escape($)),C=C.split($).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},i.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||"",i=!1,s="";this.host?i=e+this.host:this.hostname&&(i=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&o.isObject(this.query)&&Object.keys(this.query).length&&(s=b.stringify(this.query));var a=this.search||s&&"?"+s||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||v[t])&&!1!==i?(i="//"+(i||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):i||(i=""),r&&"#"!==r.charAt(0)&&(r="#"+r),a&&"?"!==a.charAt(0)&&(a="?"+a),t+i+(n=n.replace(/[?#]/g,(function(e){return encodeURIComponent(e)})))+(a=a.replace("#","%23"))+r},i.prototype.resolve=function(e){return this.resolveObject(w(e,!1,!0)).format()},i.prototype.resolveObject=function(e){if(o.isString(e)){var t=new i;t.parse(e,!1,!0),e=t}for(var n=new i,r=Object.keys(this),s=0;s<r.length;s++){var a=r[s];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(),(O=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=O.shift(),n.host=n.hostname=O.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 E=k.slice(-1)[0],A=(n.host||e.host||k.length>1)&&("."===E||".."===E)||""===E,I=0,T=k.length;T>=0;T--)"."===(E=k[T])?k.splice(T,1):".."===E?(k.splice(T,1),I++):I&&(k.splice(T,1),I--);if(!C&&!_)for(;I--;I)k.unshift("..");!C||""===k[0]||k[0]&&"/"===k[0].charAt(0)||k.unshift(""),A&&"/"!==k.join("/").substr(-1)&&k.push("");var O,x=""===k[0]||k[0]&&"/"===k[0].charAt(0);return S&&(n.hostname=n.host=x?"":k.length?k.shift():"",(O=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=O.shift(),n.host=n.hostname=O.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},i.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 i(e,t){e.tail=new a(t,e.tail,null,e),e.head||(e.head=e.tail),e.length++}function s(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++)i(this,arguments[e]);return this.length},r.prototype.unshift=function(){for(var e=0,t=arguments.length;e<t;e++)s(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,i=this.head;null!==i&&o<e;o++)i=i.next;for(;null!==i&&o<t;o++,i=i.next)n.push(i.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,i=this.tail;null!==i&&o>t;o--)i=i.prev;for(;null!==i&&o>e;o--,i=i.prev)n.push(i.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,i=this.head;null!==i&&r<e;r++)i=i.next;var s=[];for(r=0;i&&r<t;r++)s.push(i.value),i=this.removeNode(i);for(null===i&&(i=this.tail),i!==this.head&&i!==this.tail&&(i=i.prev),r=0;r<n.length;r++)i=o(this,i,n[r]);return s},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)}(js);var Ns=ke(js.exports);var Fs;!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"}(Fs||(Fs={}));const Bs=e=>{let t,n=0,r=!0;return{connect:async function(o){return t&&(t.removeAllListeners(),t.end(!0)),t=Ns.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}},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.error(`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)}}},Us=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])))},Ds=()=>`ascWebSdk#${Math.random().toString(16)}`,Ls=()=>{const e=(()=>{var e,t;return(null===(e=Rt.versions)||void 0===e?void 0:e.node)?Rt.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}},qs={notLoggedIn:["establishing"],terminated:["establishing"],establishing:["notLoggedIn","established"],established:["notLoggedIn","terminated","tokenExpired","establishing"],tokenExpired:["establishing"]},zs=e=>{const t=we();t.log("client/api/setSessionState",e);const{sessionState:n}=t;if(n===e)return!1;if(!((e,t)=>qs[e].includes(t))(n,e))throw new ge(`Session state cannot change from ${n} to ${e}`,8e5,"error");return t.sessionState=e,ct("sessionStateChange",e),!0},$s=async e=>{const t=we();zs("establishing");const{accessToken:n,users:r,expiresAt:o,issuedAt:i,refreshToken:s}=await(async e=>{const t=we();t.log("client/api/getToken",e);const n=Ls(),{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},t.ws.io.opts.query={token:n},t.token={accessToken:n,issuedAt:i,expiresAt:o},zs("established"),{accessToken:n,users:r,refreshToken:s}},Hs=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&&zs("notLoggedIn"),"tokenExpired"!==e.sessionState&&e.cache&&(e.cache={data:{}}),!e.ws.connected},Vs=(e={},t)=>{Object.entries(e).forEach((([e,n])=>{const r=he[e];if(!r)return;const o=ce(r);o&&n.forEach((e=>{$e([r,"get",o(e)],e,t)}))}))},Ws=(e,t)=>{const n=we();return at(n,e,e,(e=>{n.cache&&Vs(e),t(e.users[0])}))},Ks=e=>Ws("user.deleted",e),Qs=()=>{const e=we();zs("terminated"),e.sessionHandler=void 0,Hs()},Js=["disconnected","error","connect_error","reconnect_error","reconnect_failed"],Gs=e=>{const t=we(),n=Js.map((n=>at(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()))}},Ys=e=>{const t=we();return at(t,"client/onConnectionError(user.didGlobalBan)","user.didGlobalBan",e)},Xs=[],Zs=async(e,t,n)=>{var r,o,i;const s=we();let a;s.log("client/api/connectClient",Object.assign({apiKey:s.apiKey,sessionState:s.sessionState},e)),s.userId&&s.userId!==e.userId&&(await Hs(),Xs.forEach((e=>e()))),null!==(r=e.deviceId)&&void 0!==r||(e.deviceId=Ds());try{const{users:n}=await $s(e);c=s.ws,l=s.emitter,ot.forEach((e=>{c.on(e,(t=>{l.emit(e,t)}))})),await new Promise((e=>{s.ws.once("connect",e),s.ws.open()})),s.userId=e.userId,s.sessionHandler=t,a=s.accessTokenExpiryWatcher(null===(o=s.token)||void 0===o?void 0:o.expiresAt,null===(i=s.token)||void 0===i?void 0:i.issuedAt,t),dt(n[0])}catch(e){throw zs("notLoggedIn"),e}var c,l;return!0!==(null==n?void 0:n.disableRTE)&&(_t(mt()),_t(yt()),_t(vt()),_t(bt()),_t(gt(ut()))),Xs.push(Ys((e=>{Qs(),Xs.forEach((e=>e())),a()})),(e=>{const t=we();return at(t,"client/onTokenTerminated","tokenTerminated",e)})((e=>{Qs(),Xs.forEach((e=>e())),a()})),Ks((e=>{e.userId===s.userId&&(Qs(),Xs.forEach((e=>e())),a())})),(e=>{const t=we();return at(t,"client/onTokenExpired","tokenExpired",e)})((e=>{zs(e),Hs(),Xs.forEach((e=>e()))}))),s.ws.connected},ea=()=>{let e,t=!1;const n=we();n.log("initiating access token renewal");const r=async r=>{const{userId:o,displayName:i}=ut(),s={userId:o,displayName:i,authToken:r,deviceId:Ds()};"tokenExpired"===n.sessionState?await Zs(s,n.sessionHandler):await $s(s),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)}}},ta=3e5,na=(e,t,n)=>{const r=setInterval((()=>{if((e=>Date.now()>Date.parse(e)-ta)(e))return ct("tokenExpired","tokenExpired"),void rt((()=>n.sessionWillRenewAccessToken(ea())));(e=>{const{expiresAt:t,issuedAt:n}=e,r=Date.parse(t),o=Date.parse(n),i=Date.now();return i>o+.8*(r-o-ta)&&i<r})({expiresAt:e,issuedAt:t})&&n.sessionWillRenewAccessToken(ea())}),g);return()=>clearInterval(r)},ra=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:i}=t,s=e.cache&&Date.now();return e.cache&&Vs(t,{cachedAt:s}),o.length&&ct("local.feedMarker.fetched",{feedMarkers:o}),n.length&&ct("local.channelMarker.fetched",{userEntityMarkers:n}),r.length&&ct("local.subChannelMarker.fetched",{userFeedMarkers:r}),i.length&&ct("local.userMarker.fetched",{userMarkers:i}),{hasMore:t.feedMarkers.length>0}};function oa(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 ia=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,i=oa(r,["paging"]),{userEntityMarkers:s,userMarkers:a}=i,c=n.cache&&Date.now();n.cache&&Vs(i,{cachedAt:c}),s.length&&ct("local.channelMarker.fetched",{userEntityMarkers:s}),a.length&&ct("local.userMarker.fetched",{userMarkers:a});const l=G(o.next);return{data:s,cachedAt:c,prevPage:G(o.previous),nextPage:l}},sa=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,i=oa(r,["paging"]),{contentMarkers:s,feedMarkers:a,userMarkers:c}=i,l=n.cache&&Date.now();n.cache&&Vs(i,{cachedAt:l}),a.length&&ct("local.feedMarker.fetched",{feedMarkers:a}),s.length&&ct("local.messageMarker.fetched",{contentMarkers:s}),c.length&&ct("local.userMarker.fetched",{userMarkers:c});const u=G(o.next);return{data:s,cachedAt:l,prevPage:G(o.previous),nextPage:u}},aa=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,i=oa(r,["paging"]),{userEntityMarkers:s,userFeedMarkers:a,userMarkers:c}=i,l=n.cache&&Date.now();n.cache&&Vs(i,{cachedAt:l}),s.length&&ct("local.channelMarker.fetched",{userEntityMarkers:s}),a.length&&ct("local.subChannelMarker.fetched",{userFeedMarkers:a}),c.length&&ct("local.userMarker.fetched",{userMarkers:c});const u=G(o.next);return{data:a,cachedAt:l,prevPage:G(o.previous),nextPage:u}},ca=()=>{var e,t;const n=we(),r=ut();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 i=(new Date).toISOString(),s=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:i,createdAt:i,updatedAt:i},cachedAt:s}},la=()=>Promise.resolve(ca());la.locally=ca;const ua=e=>{const t=we();return at(t,"userMarker/onUserMarkerFetched","local.userMarker.fetched",(t=>{e(t.userMarkers[0])}))},da=(e,t,n,r,o,i=(e=>e),s)=>{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=oa(e,["data"]);s&&!s(n,c)||t(Object.assign({data:i(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);ie(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()))}},ha=e=>!0===e&&void 0,fa=(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 pa(e,t){const{channelPublicId:n,childCount:r,creatorPublicId:o,mentionedUsers:i,messageFeedId:s,myReactions:a,reactionCount:c,reactions:l,referenceId:u,segment:d,messageId:h}=e,f=oa(e,["channelPublicId","childCount","creatorPublicId","mentionedUsers","messageFeedId","myReactions","reactionCount","reactions","referenceId","segment","messageId"]),{readCount:p,deliveredCount:g}=fa(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:s,uniqueId:m?m.data.uniqueId:h,readCount:p,deliveredCount:g});return i&&(y.mentionees=i.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}function ga(e,t){const{readCount:n,deliveredCount:r}=fa(e,t);return Object.assign(Object.assign({},e),{readCount:n,deliveredCount:r,updatedAt:(new Date).toISOString()})}const ma=async e=>{let t=[];const n=e.messages.map((({messageId:e})=>e));if(n.length>0)try{({data:t}=await sa(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 pa(e,n)}))})};function ya(e){var{subChannelId:t,mentionees:n}=e,r=oa(e,["subChannelId","mentionees"]);return Object.assign({messageFeedId:t,mentionedUsers:n},r)}function va(e){var{page:t,sortBy:n,subChannelId:r,tags:o,includeDeleted:i}=e,s=oa(e,["page","sortBy","subChannelId","tags","includeDeleted"]);const a=Object.assign(Object.assign({},s),{messageFeedId:r,isDeleted:ha(i),options:{token:J(t||{limit:10},"afterbeforeraw")}});return void 0!==n&&(a.options.sortBy=n),o&&(a.includeTags=o),a}const ba=(e,t=!0)=>{const n=we(),r=[at(n,"message/onMessageCreated","message.created",(async t=>{const n=await ma(t),r=n.messages[0];Vs(n),e(r)}))];return t&&at(n,"message/onMessageCreated","local.message.created",(t=>e(t.messages[0]))),()=>{r.forEach((e=>e()))}},wa=e=>{const t=we(),n=[at(t,"onMessageUpdated","message.updated",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])})),at(t,"onMessageUpdated","local.message.updated",(t=>e(t.messages[0]))),at(t,"onMessageUpdated","local.messageMarker.fetched",(async t=>{var n;const r=t.contentMarkers[0],o=["message","get",r.contentId],i=null===(n=Le(o))||void 0===n?void 0:n.data;if(!i)return;const s=ga(i,r);$e(o,s),e(s)}))];return()=>{n.forEach((e=>e()))}},Ca=e=>{const t=we(),n=[at(t,"message/onMessageDeleted","message.deleted",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])})),at(t,"local.message.deleted","local.message.deleted",(t=>e(t.messages[0])))];return()=>{n.forEach((e=>e()))}},_a=e=>{const t=we();return at(t,"onMessageFlagged","message.flagged",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])}))},ka=e=>{const t=we();return at(t,"onMessageUnflagged","message.unflagged",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])}))},Sa=e=>{const t=we();return at(t,"onMessageFlagCleared","message.flagCleared",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])}))},Ea=e=>{const t=we();return at(t,"onMessageReactionAdded","message.reactionAdded",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])}))},Aa=e=>{const t=we();return at(t,"onMessageReactionRemoved","message.reactionRemoved",(async t=>{const n=await ma(t);Vs(n),e(n.messages[0])}))},Ia=e=>{const t=we();return at(t,"message/onMessageFetched","local.message.fetched",(t=>{Vs(t),e(t.messages[0])}))},Ta=["broadcast","conversation","community"],Oa=({channelType:e})=>Ta.includes(e);function xa(e,t,n){var r;if(n)return n.unreadCount;const o={entityId:e,feedId:t,userId:ut()._id},i=null===(r=Le(["subChannelMarker","get",ce("subChannelMarker")(o)]))||void 0===r?void 0:r.data;return i?i.unreadCount:0}const Ra=async e=>{let t=[];const n=e.messageFeeds.filter(Oa).map((({messageFeedId:e})=>e));if(n.length>0)try{({data:t}=await aa(n))}catch(e){}const r=e.messageFeeds.map((e=>{const n=null==t?void 0:t.find((({feedId:t})=>t===e.messageFeedId));return function(e,t){var{channelId:n,channelPublicId:r,channelType:o,childCount:i,creatorId:s,creatorPublicId:a,lastMessageId:c,lastMessageTimestamp:l,messageFeedId:u,name:d}=e,h=oa(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:i,subChannelId:u,isUnreadCountSupport:Oa({channelType:o}),unreadCount:xa(n,u,t)})}(e,n)}));return Object.assign(Object.assign({},e),{messageFeeds:r})};function Pa(e){var{excludeDefaultSubChannel:t}=e,n=oa(e,["excludeDefaultSubChannel"]);const r=Object.assign({},n);return void 0!==t&&(r.excludeDefaultMessageFeed=t),r}const Ma=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`),r=t.cache&&Date.now();return t.cache&&Vs(n,{cachedAt:r}),!0},ja=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`),r=t.cache&&Date.now();return t.cache&&Vs(n,{cachedAt:r}),!0};let Na=[];const Fa={},Ba=e=>{var t;if(!Fa[e.subChannelId])return;if(!we().cache)return;const n={entityId:e.channelId,feedId:e.subChannelId,userId:ut()._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})];ct("local.subChannelMarker.updated",{userFeedMarkers:o})},Ua=()=>{Na.push((()=>{const e=()=>{Object.entries(Fa).forEach((([e,t])=>{t&&Ma(e)}))};return window.addEventListener("online",e),()=>window.removeEventListener("online",e)})(),ba(Ba))},Da=e=>{const t=we();return at(t,"onSubChannelCreated","message-feed.created",(async t=>{const n=await Ra(t);Vs(n),e(n.messageFeeds[0])}))},La=e=>{const t=we(),n=async t=>{var n;const r=t.userFeedMarkers[0],o=["subChannel","get",r.feedId],i=null===(n=Le(o))||void 0===n?void 0:n.data;if(!i)return;const s=function(e,t){return Object.assign(Object.assign({},e),{unreadCount:xa(e.channelId,e.subChannelId,t),updatedAt:(new Date).toISOString()})}(i,r);$e(o,s),e(s)},r=[at(t,"onSubChannelUpdated","message-feed.updated",(async t=>{const n=await Ra(t);Vs(n),e(n.messageFeeds[0])})),at(t,"onSubChannelUpdated","local.subChannelMarker.fetched",n),at(t,"onSubChannelUpdated","local.subChannelMarker.updated",n)];return()=>{r.forEach((e=>e()))}},qa=e=>{const t=we(),n=[at(t,"onSubChannelDeleted","message-feed.deleted",(async t=>{const n=await Ra(t);Vs(n),e(n.messageFeeds[0])})),at(t,"local.message-feed.deleted","local.message-feed.deleted",(t=>e(t.messageFeeds[0])))];return()=>{n.forEach((e=>e()))}};let za,$a=[],Ha=!1,Va=[];const Wa=e=>{Va=e},Ka=e=>Va.push(e),Qa=async e=>{if(Ha)return;if(0===Va.length)return;Ha=!0,Va=[];(await e()).hasMore&&Va.push("has_more"),Ha=!1},Ja=(e,t)=>{const n=setInterval(e,t);return()=>clearInterval(n)},Ga=()=>{$a.push((()=>{const e=()=>Va.push("resume");return window.addEventListener("online",e),()=>window.removeEventListener("online",e)})(),ba((e=>{Oa(e)&&Va.push("new message")}),!1),Da((()=>Va.push("subchannel is created"))),qa((()=>Va.push("subchannel is deleted"))),Ja((()=>Va.push("force sync")),8e3))};var Ya=Object.freeze({__proto__:null,getActiveClient:we,getActiveUser:ut,setActiveUser:dt,createClient:(e,t=Mt.SG,{debugSession:n="amity",apiEndpoint:r}={})=>{var o,i;const s=(e=>{const t=`${null==e?void 0:e.trim()}`.length>0&&!Pt,n=Ot(e),r=(e,...r)=>{t&&n(e,r)};return r.__instance__=n,r})(n);s("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:Nt("http",t),c=null!==(i=null==r?void 0:r.mqtt)&&void 0!==i?i:Nt("mqtt",t),l=yr(a),u=(e=>{const t=Ps(e,{autoConnect:!1,reconnectionDelay:2e3,transports:["websocket"]});return t.on("disconnect",(e=>{"io server disconnect"===e&&t.connect()})),t})(a),h=Bs(c),f=st(),p={version:`${d}`,apiKey:e,log:s,http:l,ws:u,mqtt:h,emitter:f,accessTokenExpiryWatcher:na,use:()=>Ce(p),sessionState:"notLoggedIn",sessionHandler:undefined,getFeedSettings:Us};try{return we()}catch(e){Ce(p)}return p},login:Zs,logout:Hs,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:Us,renewal:ea,markerSync:ra,onConnectionError:Gs,onClientDisconnected:e=>Gs((({code:t})=>{800211===t&&e()})),onClientBanned:Ys,onSessionStateChange:e=>{const t=we();return at(t,"client/onSessionStateChange","sessionStateChange",e)},getTotalUnreadCount:e=>{const{_id:t}=ut();if(!t)throw new ge("The _id has not been defined in ActiveUser",8e5,"error");return da(t,e,"userId",la,[ua],(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:()=>Va,setMarkerSyncEvents:Wa,pushMarkerSyncEvent:Ka,markerSyncTrigger:Qa,startUnreadSync:()=>{Ka("start syncing"),za||(za=Ja((()=>Qa(ra)),2e3)),Ga()},stopUnreadSyncing:()=>{null==za||za(),za=void 0,Wa([]),$a.forEach((e=>e())),$a=[]}});const Xa=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,i=oa(r,["paging"]),{users:s}=i,a=t.cache&&Date.now();if(t.cache){Vs(i,{cachedAt:a});qe(["blockedUsers","query",n],{users:s.map(ce("user")),paging:o})}const{next:c,previous:l,total:u}=o,d=Y(c);return{data:s,prevPage:Y(l),nextPage:d,total:u,cachedAt:a}};Xa.locally=(e={})=>{var t,n,r;const o=we();if(o.log("user/queryBlockedUsers.locally"),!o.cache)return;let i={};if(e){const{token:t,limit:n}=e;i={token:t,limit:n}}const s=["blockedUsers","query",i],{data:a,cachedAt:c}=null!==(t=Le(s))&&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 Za=(e,t)=>{const n=we();return at(n,e,e,(e=>{var r,o;if(n.cache){Vs(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})=>$e(e,t,{cachedAt:-1}))),t(e.follows[0])}else t(e.follows[0])}))},ec=e=>Za("follow.created",e),tc=e=>Za("follow.unfollowed",e),nc=e=>Za("follow.followerDeleted",e),rc=e=>Za("follow.requested",e),oc=e=>Za("follow.requestCanceled",e),ic=e=>Za("follow.accepted",e),sc=e=>Za("follow.requestDeclined",e),ac=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`),i=r.cache&&Date.now(),s="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],s,{cachedAt:i}),{data:s,cachedAt:i}};ac.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 cc=e=>{const t=async t=>{const[{data:n},{data:r}]=await Promise.all([ac(t.from),ac(t.to)]);e(n),e(r)},n=[Za("follow.created",t),Za("follow.requested",t),Za("follow.accepted",t),Za("follow.unfollowed",t),Za("follow.requestCanceled",t),Za("follow.requestDeclined",t),Za("follow.followerDeleted",t)];return()=>{n.forEach((e=>e()))}},lc=async(e,t)=>{const n=we();n.log(`follow/queryF${e.substring(1)}`,t);const{userId:r,page:o}=t,i=oa(t,["userId","page"]),{data:s}=await n.http.get(n.userId===r?`/api/v4/me/${e}`:`/api/v4/users/${r}/${e}`,{params:Object.assign(Object.assign({},i),{token:J(o,"afterbeforeraw")})}),{paging:a}=s,c=oa(s,["paging"]),{follows:l}=c,u=n.cache&&Date.now();if(n.cache){Vs(c,{cachedAt:u});const t=["follow","query",Object.assign(Object.assign({},i),{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}};lc.locally=(e,t)=>{var n,r;const o=we();if(o.log(`follow/queryF${e.substring(1)}.locally`,t),!o.cache)return;const{page:i}=t,s=oa(t,["page"]),a=["follow","query",Object.assign(Object.assign({},s),{options:Object.assign({},i),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 uc=async e=>lc("followers",e);uc.locally=e=>lc.locally("followers",e);const dc=async e=>lc("following",e);dc.locally=e=>lc.locally("following",e);var hc=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:i}=n,s={follows:o};return t.cache&&(Vs(s,{cachedAt:r}),$e(["followInfo","get",e],i[0],{cachedAt:r})),ct("follow.unfollowed",s),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:i}=n,s={follows:o};return t.cache&&(Vs(s,{cachedAt:r}),$e(["followInfo","get",e],i[0],{cachedAt:r})),ct("follow.created",s),n},getBlockedUsers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getBlockedUsers(tmpid: ${i}) > listen`);const{limit:s,token:a}=e,c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["blockedUsers","collection",{}],g=()=>{var e,n;const r=null===(e=Le(d))||void 0===e?void 0:e.data,o=null!==(n=null==r?void 0:r.data)&&void 0!==n?n:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(Xa,{limit:c,token:J(null==r?void 0:r.params.page,"afterbeforeraw")});ie(i,(({data:e,loading:n,error:r,nextPage:i,total:s})=>{const a={loading:n,error:r,params:{page:i,total:s},data:o};e&&(a.data=[...new Set([...o,...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(),()=>{r(`getCategories(tmpid: ${i}) > dispose`),u.forEach((e=>e())),He(d)}},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&&Vs(n,{cachedAt:r}),ct("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&&Vs(n),ct("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&&Vs(n),ct("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&&Vs(n),ct("follow.requestDeclined",n),!0},onUserFollowed:ec,onUserUnfollowed:tc,onFollowerDeleted:nc,onFollowerRequested:rc,onFollowRequestCanceled:oc,onFollowRequestAccepted:ic,onFollowRequestDeclined:sc,onFollowInfoUpdated:cc,observeFollowInfo:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observeFollowInfo(tmpid: ${o}) > listen`);const i=(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=[];return s.push(cc((t=>((t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.userId)===e&&i(t,n)})({data:t,loading:!1,origin:"event"},"onUpdate")))),ie(re(ac,e),(e=>(e.data||e.error)&&i(e,"onFetch")),oe(n)),()=>{r(`observeFollowInfo(tmpid: ${o}) > dispose`),s.forEach((e=>e()))}},observeFollowers:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeFollowers(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;if(n.from===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(rc((e=>i(e,"onRequested"))),ic((e=>i(e,"onAccepted"))),sc((e=>i(e,"onDeclined"))),oc((e=>i(e,"onCanceled"))),ec((e=>i(e,"onFollowed"))),tc((e=>i(e,"onUnfollowed"))),nc((e=>i(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=[],i=(n,r)=>{var o,i;if(n.to===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(rc((e=>i(e,"onRequested"))),ic((e=>i(e,"onAccepted"))),sc((e=>i(e,"onDeclined"))),oc((e=>i(e,"onCanceled"))),ec((e=>i(e,"onFollowed"))),tc((e=>i(e,"onUnfollowed"))),nc((e=>i(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 i=Date.now();r(`getFollowers(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["follow","collection",{userId:e.userId,type:"follower"}],p=n=>{var r,o;let i=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&&(i=Ve(i,"status",e.status)),t({onNextPage:m,data:i,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=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(uc,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({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("follow"))])]),qe(d,o),p(o)}),oe(l))};return u.push(rc(g("onRequested")),ic(g("onAccepted")),sc(g("onDeclined")),oc(g("onCanceled")),ec(g("onFollowed")),tc(g("onUnfollowed")),nc(g("onDeleted"))),m(),()=>{r(`getFollowers(tmpid: ${i}) > 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 i=Date.now();r(`getFollowings(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["follow","collection",{userId:e.userId,type:"following"}],p=n=>{var r,o;let i=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&&(i=Ve(i,"status",e.status)),t({onNextPage:m,data:i,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=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(dc,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({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("follow"))])]),qe(d,o),p(o)}),oe(l))};return u.push(rc(g("onRequested")),ic(g("onAccepted")),sc(g("onDeclined")),oc(g("onCanceled")),ec(g("onFollowed")),tc(g("onUnfollowed")),nc(g("onDeleted"))),m(),()=>{r(`getFollowings(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},getFollowInfo:(e,t)=>da(e,t,"userId",ac,[cc])});const fc=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&&Vs(r,{cachedAt:o}),ct("user.fetched",r),{data:r.users,cachedAt:o}};fc.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)),i=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:i.cachedAt}};const pc=e=>Ws("user.updated",e),gc=e=>Ws("user.flagged",e),mc=e=>Ws("user.unflagged",e),yc=e=>Ws("user.flagCleared",e),vc=e=>Ws("user.fetched",e),bc=(e,t)=>{const{log:n,cache:r}=we(),o=[e,m,t];if(!r)return;n("cache/api/isInTombstone",o);const i=Le(o),{lifeSpan:s}=oe("cache_then_server",18e4);if(i&&ne(i.data,s))throw new me("Item not found!",400400,"error")},wc=(e,t)=>{const{log:n,cache:r}=we(),o=[e,m,t],i={cachedAt:Date.now()};r&&(n("cache/api/pushToTombstone",{cacheKey:o,data:i}),He([e,"get",t],!0),qe(o,i))},Cc=async e=>{const t=we();let n;t.log("user/getUser",e),bc("user",e);try{n=(await t.http.get(`/api/v3/users/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&wc("user",e),t}const r=t.cache&&Date.now();t.cache&&Vs(n,{cachedAt:r});const{users:o}=n;return ct("user.fetched",n),{data:o.find((t=>t.userId===e)),cachedAt:r}};Cc.locally=e=>{const t=we();return t.log("user/getUser.locally",e),t.cache&&Le(["user","get",e])};const _c=async(e={})=>{const t=we();t.log("user/queryUsers",e);const{page:n={limit:10},displayName:r,filter:o="all",sortBy:i="displayName"}=e,s=oa(e,["page","displayName","filter","sortBy"]),{data:a}=await t.http.get("/api/v3/users",{params:Object.assign(Object.assign({},s),{keyword:r,filter:o,sortBy:i,options:{token:J(n,"skiplimit")}})}),{paging:c}=a,l=oa(a,["paging"]),{users:u}=l,d=t.cache&&Date.now();if(t.cache){Vs(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})}ct("user.fetched",a);return{data:u,cachedAt:d,prevPage:G(c.previous),nextPage:G(c.next)}};_c.locally=(e={})=>{var t,n,r;const o=we();if(o.log("user/queryUsers.locally",e),!o.cache)return;const{page:i={limit:10}}=null!=e?e:{},s=["user","query",Object.assign(Object.assign({},e),{options:Object.assign({},i)})],{data:a,cachedAt:c}=null!==(t=Le(s))&&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 kc=Object.freeze({__proto__:null,Relationship:hc,getUserByIds:fc,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&&Vs(r,{cachedAt:o});const{users:i}=r;return ct("user.updated",r),{data:i.find((t=>t.userId===e)),cachedAt:o}},onUserUpdated:pc,onUserDeleted:Ks,onUserFlagged:gc,onUserUnflagged:mc,onUserFlagCleared:yc,getUser:(e,t)=>da(e,t,"userId",Cc,[vc,pc,Ks,gc,mc,yc]),getUsers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`liveUsers(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["user","collection",{}],g=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(i=Ve(i,"displayName",e.displayName),e.sortBy){case"firstCreated":i=i.sort(Xe);break;case"lastCreated":i=i.sort(Ze);break;default:i=i.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Ge)}t({onNextPage:y,data:i,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=()=>{var e,t,n;const r=null===(e=Le(d))||void 0===e?void 0:e.data,o=null!==(t=null==r?void 0:r.data)&&void 0!==t?t:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(_c,Object.assign(Object.assign({},a),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:c}}));ie(i,(({data:e,error:t,loading:n,nextPage:r})=>{const i={loading:n,error:t,params:{page:r},data:o};e&&(i.data=[...new Set([...o,...e.map(ce("user"))])]),qe(d,i),g(i)}),oe(l))};return u.push(pc(m()),Ks(m()),gc(m()),mc(m()),yc(m())),y(),()=>{r(`liveUsers(tmpid: ${i}) > 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,i,s;if((null===(o=n.data)||void 0===o?void 0:o.userId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},i=[];return i.push(pc((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),Ks((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),gc((e=>o({data:e,loading:!1,origin:"event"},"onFlagged"))),mc((e=>o({data:e,loading:!1,origin:"event"},"onUnflagged"))),yc((e=>o({data:e,loading:!1,origin:"event"},"onFlagCleared")))),ie(re(Cc,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeUser(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}}});const Sc=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&&Vs({files:[n]},{cachedAt:r}),{data:n,cachedAt:r}};Sc.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 Ec=Object.freeze({__proto__:null,getFile:Sc,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))}}),i=n.cache&&Date.now();return n.cache&&Vs({files:o},{cachedAt:i}),{data:o,cachedAt:i}},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}`,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:i}=await r.http.post("/api/v4/videos",e,{headers:o,onUploadProgress({loaded:e,total:t=100}){n&&n(Math.round(100*e/t))}}),s=r.cache&&Date.now();return r.cache&&Vs({files:i},{cachedAt:s}),{data:i,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))}}),i=n.cache&&Date.now();return n.cache&&Vs({files:o},{cachedAt:i}),{data:o,cachedAt:i}},observeFile:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeFile(tmpid: ${r}) > listen`);return ie(re(Sc,e),(n=>n.data&&((n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.fileId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}})(n,"onFetch"))),()=>{n(`observeFile(tmpid: ${r}) > dispose`)}}});const Ac=async e=>{const t=we();t.log("role/queryRoles",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,sortBy:i}=n,s=oa(n,["page","displayName","sortBy"]),{data:a}=await t.http.get("/api/v3/roles",{params:Object.assign(Object.assign({},s),{keyword:o,sortBy:i,options:{token:J(r,"skiplimit")}})}),{paging:c}=a,l=oa(a,["paging"]),{roles:u}=l,d=t.cache&&Date.now();t.cache&&Vs(l,{cachedAt:d});const h=G(c.next);return{data:u,cachedAt:d,prevPage:G(c.previous),nextPage:h}};Ac.locally=e=>{we().log("role/queryRoles.locally",e)};const Ic=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&&Vs({roles:n},{cachedAt:r}),{data:n.find((t=>t.roleId===e)),cachedAt:r}};Ic.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 Tc=(e,t)=>{"message"===e?ct("local.message.updated",{messages:[t]}):"post"===e?ct("post.updated",{posts:[t]}):"comment"===e&&ct("comment.updated",{comments:[t]})},Oc=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."),bc("message",e);try{const{data:t}=await n.http.get(`/api/v5/messages/${encodeURIComponent(e)}`);r=await ma(t)}catch(t){throw _(null==t?void 0:t.code)&&wc("message",e),t}const o=n.cache&&Date.now();n.cache&&Vs(r,{cachedAt:o});const{messages:i}=r;return ct("local.message.fetched",{messages:i}),{data:i.find((t=>t.messageId===e)),cachedAt:o}};Oc.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 xc=(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},Rc=(e,t,n="userId",r="user")=>{const o=e,i=t,s=o[i],a=oa(o,["symbol"==typeof i?i:i+""]),c=xc(s,n,r);return Object.assign(Object.assign({},a),{[t]:c})},Pc=async e=>{const t=we();let n;t.log("post/getPost",e),bc("post",e);try{n=(await t.http.get(`/api/v3/posts/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&wc("post",e),t}const r=Rc(n,"communityUsers"),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{posts:i}=r;return{data:i.find((t=>t.postId===e)),cachedAt:o}};Pc.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 Mc=async e=>{const t=we();let n;t.log("comment/getComment",e),bc("comment",e);try{n=(await t.http.get(`/api/v3/comments/${encodeURIComponent(e)}`)).data}catch(t){throw _(null==t?void 0:t.code)&&wc("comment",e),t}const r=t.cache&&Date.now();t.cache&&Vs(n,{cachedAt:r});const{comments:o}=n;return{data:o.find((t=>t.commentId===e)),cachedAt:r}};Mc.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 jc=(e,t)=>{var n,r;if(we().userId!==t.reactor.userId)return;let o,i;if("post.addReaction"===e||"post.removeReaction"===e){const e=t.posts[0];i=null===(n=Le(["post","get",e.postId]))||void 0===n?void 0:n.data,o=e}else{const e=t.comments[0];i=null===(r=Le(["comment","get",e.commentId]))||void 0===r?void 0:r.data,o=e}if(i&&i.myReactions)if("post.addReaction"===e||"comment.addReaction"===e){if(i.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:[...i.myReactions,t.reactor.reactionName]})}else{if(!i.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:i.myReactions.filter((e=>e!==t.reactor.reactionName))})}},Nc=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};Nc.optimistically=(e,t,n)=>{var r,o,i,s,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!==(i=l.data.reactions[n])&&void 0!==i?i:0)+1})});return $e([e,"get",t],u,{cachedAt:-5}),Tc(e,u),null!==(a=null===(s=null==u?void 0:u.myReactions)||void 0===s?void 0:s.includes(n))&&void 0!==a&&a};const Fc=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};Fc.optimistically=(e,t,n)=>{var r,o,i,s,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!==(i=l.data.reactions[n])&&void 0!==i?i:0)-1)})});return $e([e,"get",t],u,{cachedAt:-5}),Tc(e,u),null!==(a=!(null===(s=null==u?void 0:u.myReactions)||void 0===s?void 0:s.includes(n)))&&void 0!==a&&a};const Bc=(e,t)=>{const n=we();return at(n,e,e,(r=>{var o;if(n.cache){const{communities:n}=r,i=oa(r,["communities"]),s=Rc(i,"communityUsers");Vs(s),(null==n?void 0:n[0])&&!["post.updated"].includes(e)&&ct("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})=>$e(e,t,{cachedAt:-1})))}t(a.data)}else t(r.posts[0])}))},Uc=e=>Bc("post.created",e),Dc=e=>Bc("post.updated",e),Lc=e=>Bc("post.deleted",e),qc=e=>Bc("post.approved",e),zc=e=>Bc("post.declined",e),$c=e=>Bc("post.flagged",e),Hc=e=>Bc("post.unflagged",e),Vc=e=>{const t=we();return at(t,"post.addReaction","post.addReaction",(n=>{if(t.cache){jc("post.addReaction",n);const t=oa(n,["reactor"]);Vs(t);const r=Le(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},Wc=e=>{const t=we();return at(t,"post.removeReaction","post.removeReaction",(n=>{if(t.cache){jc("post.removeReaction",n);const t=oa(n,["reactor"]);Vs(t);const r=Le(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},Kc=(e,t)=>{const n=we();return at(n,e,e,(r=>{var o;if(n.cache){Vs(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})=>$e(e,t,{cachedAt:-1})))}t(n.data)}else t(r.comments[0])}))},Qc=e=>Kc("comment.created",e),Jc=e=>Kc("comment.updated",e),Gc=e=>Kc("comment.deleted",e),Yc=e=>Kc("comment.flagged",e),Xc=e=>Kc("comment.unflagged",e),Zc=e=>{const t=we();return at(t,"comment.addReaction","comment.addReaction",(n=>{if(t.cache){jc("comment.addReaction",n);const t=oa(n,["reactor"]);Vs(t);const r=Le(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},el=e=>{const t=we();return at(t,"comment.removeReaction","comment.removeReaction",(n=>{if(t.cache){jc("comment.removeReaction",n);const t=oa(n,["reactor"]);Vs(t);const r=Le(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},tl=(e,t,n)=>{const r=we(),o=(r,o,i)=>{r===e&&o===t&&n(i)};if("message"===e){const e=async e=>{const t=await ma(e);if(!t.messages[0].latestReaction)return;const n=t.messages[0].latestReaction,{eventName:r,referenceId:i,referenceType:s,userDisplayName:a}=n,c=oa(n,["eventName","referenceId","referenceType","userDisplayName"]);"add"===r&&(Vs(t),Vs({reactions:[c]}),o("message",t.messages[0].messageId,c))};return at(r,"reaction/onReactorAdded","message.updated",e)}if("post"===e){return at(r,"post.addReaction","post.addReaction",(e=>{const{reactor:t}=e,n=oa(e,["reactor"]);Vs(n),Vs({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return at(r,"comment.addReaction","comment.addReaction",(e=>{const{reactor:t}=e,n=oa(e,["reactor"]);Vs(n),Vs({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))},nl=(e,t,n)=>{const r=we(),o=(r,o,i)=>{r===e&&o===t&&n(i)};if("message"===e){const e=async e=>{const t=await ma(e);if(!t.messages[0].latestReaction)return;const n=t.messages[0].latestReaction,{eventName:r,referenceId:i,referenceType:s}=n,a=oa(n,["eventName","referenceId","referenceType"]);"remove"===r&&(Vs(t),Vs({reactions:[a]}),o("message",t.messages[0].messageId,a))};return at(r,"reaction/onReactorRemoved","message.updated",e)}if("post"===e){return at(r,"post.removeReaction","post.removeReaction",(e=>{const{reactor:t}=e,n=oa(e,["reactor"]);Vs(n),Vs({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return at(r,"comment.removeReaction","comment.removeReaction",(e=>{const{reactor:t}=e,n=oa(e,["reactor"]);Vs(n),Vs({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))},rl=async e=>{const t=we();t.log("reaction/queryReactions",e);const n=null!=e?e:{},{page:r={limit:10}}=n,o=oa(n,["page"]),{data:i}=await t.http.get("/api/v3/reactions",{params:Object.assign(Object.assign({},o),{options:{token:J(r,"afterbeforeraw")}})}),{paging:s}=i,a=oa(i,["paging"]),{reactions:c}=a;Vs(Object.assign(Object.assign({},a),{reactions:c[0].reactors}));const l=Y(s.next);return{data:c,prevPage:Y(s.previous),nextPage:l}};var ol=Object.freeze({__proto__:null,addReaction:Nc,removeReaction:Fc,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 ma(e),o=Le(["message","get",n.messages[0].messageId]),i=(null===(t=null==o?void 0:o.data)||void 0===t?void 0:t.reactionsCount)!==n.messages[0].reactionsCount;Vs(n),i&&r(n.messages[0])};return at(e,"reaction/onReactionAdded","message.updated",t)}return"post"===e?Vc(r):Zc(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 ma(e),o=Le(["message","get",n.messages[0].messageId]),i=(null===(t=null==o?void 0:o.data)||void 0===t?void 0:t.reactionsCount)!==n.messages[0].reactionsCount;Vs(n),i&&r(n.messages[0])};return at(e,"reaction/onReactionRemoved","message.updated",t)}return"post"===e?Wc(r):el(r)},onReactorAdded:tl,onReactorRemoved:nl,getReactions:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const i=Date.now();r(`liveReactions(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s: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=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(rl,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({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[0].reactors.map(ce("reaction"))])]),qe(d,o),p(o)}),oe(l))};return u.push(tl(a.referenceType,a.referenceId,g("onAdded")),nl(a.referenceType,a.referenceId,g("onRemoved"))),m(),()=>{r(`liveReactions(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}}}),il={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 sl=["broadcast","conversation","community"],al=({type:e})=>sl.includes(e),cl=(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:ut()._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};function ll(e,t){return Object.assign(Object.assign({},e),{defaultSubChannelId:e._id,isUnreadCountSupport:al(e),unreadCount:cl(e,t)})}function ul(e,t){return Object.assign(Object.assign({},e),{unreadCount:cl(e,t),updatedAt:(new Date).toISOString()})}const dl=async e=>{let t=[];const n=e.channels.filter(al).map((({channelId:e})=>e));if(n.length>0)try{({data:t}=await ia(n))}catch(e){}const r=e.channels.map((e=>{const n=null==t?void 0:t.find((({entityId:t})=>t===e.channelId));return ll(e,n)})),o=xc(e.channelUsers);return Object.assign(Object.assign({},e),{channels:r,channelUsers:o})},hl=async e=>{const t=we();let n;t.log("channel/getChannel",e),bc("channel",e);try{const{data:r}=await t.http.get(`/api/v3/channels/${encodeURIComponent(e)}`);n=await dl(r)}catch(t){throw _(null==t?void 0:t.code)&&wc("channel",e),t}const r=t.cache&&Date.now();t.cache&&Vs(n,{cachedAt:r});const{channels:o}=n;return{data:o.find((t=>t.channelId===e)),cachedAt:r}};hl.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 fl=e=>{const t=we();return at(t,"onChannelCreated","channel.created",(async t=>{const n=await dl(t);Vs(n),e(n.channels[0])}))},pl=e=>{const t=we(),n=[at(t,"onChannelUpdated","channel.updated",(async t=>{const n=await dl(t);Vs(n),e(n.channels[0])})),at(t,"onChannelUpdated","local.channel.updated",(t=>e(t.channels[0]))),at(t,"onChannelUpdated","local.channelMarker.fetched",(async t=>{var n;const r=t.userEntityMarkers[0],o=["channel","get",r.entityId],i=null===(n=Le(o))||void 0===n?void 0:n.data;if(!i)return;const s=ul(i,r);$e(o,s),e(s)}))];return()=>{n.forEach((e=>e()))}},gl=e=>{const t=we();return at(t,"onChannelDeleted","channel.deleted",(async t=>{const n=await dl(t);Vs(n),e(n.channels[0])}))},ml=e=>{const t=we();return at(t,"onChannelJoined","channel.joined",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o[0])}))},yl=e=>{const t=we();return at(t,"onChannelLeft","channel.left",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o[0])}))},vl=e=>{const t=we();return at(t,"onChannelMuted","channel.setMuted",(async t=>{const n=await dl(t);Vs(n),e(n.channels[0])}))},bl=e=>{const t=we();return at(t,"onChannelMemberAdded","channel.membersAdded",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o.find((e=>"member"===e.membership)))}))},wl=e=>{const t=we();return at(t,"onChannelMemberRemoved","channel.membersRemoved",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o[0])}))},Cl=e=>{const t=we();return at(t,"onChannelMemberBanned","channel.banned",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o.find((e=>"banned"===e.membership)))}))},_l=e=>{const t=we();return at(t,"onChannelMemberUnbanned","channel.unbanned",(async t=>{const n=await dl(t),{channels:r,channelUsers:o}=n;Vs(n),e(r[0],o.find((e=>"none"===e.membership)))}))},kl=async e=>{const t=we();t.log("channel/queryChannels",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,membership:i}=n,s=oa(n,["page","displayName","membership"]),{data:a}=await t.http.get("/api/v3/channels",{params:Object.assign(Object.assign({},s),{keyword:o,filter:i,options:{token:J(r,"skiplimit")}})}),{paging:c}=a,l=oa(a,["paging"]),u=await dl(l),{channels:d}=u,h=t.cache&&Date.now();if(t.cache){Vs(u,{cachedAt:h});const e=["channel","query",Object.assign(Object.assign({},s),{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}};kl.locally=e=>{var t,n;we().log("channel/queryChannels.locally",e);const r=null!=e?e:{},{page:o={limit:10}}=r,i=oa(r,["page"]),s=["channel","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Le(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.channels.length))return;const l=a.channels.map((e=>Le(["channel","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.channels)||void 0===n?void 0:n.length)?{data:l,cachedAt:c,prevPage:u,nextPage:d}:void 0};const Sl=async e=>{const t=we();t.log("channel/queryChannelMembers",e);const n=null!=e?e:{},{page:r}=n,o=oa(n,["page"]),{data:i}=await t.http.get(`/api/v4/channels/${encodeURIComponent(o.channelId)}/users`,{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:s}=i,a=oa(i,["paging"]),c=await dl(a),{channelUsers:l}=c,u=t.cache&&Date.now();if(t.cache){Vs(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:s})}return{data:l,cachedAt:u,nextPage:G(s.next),prevPage:G(s.previous)}};Sl.locally=e=>{var t,n;const r=we();if(r.log("channel/queryChannelMembers.locally",e),!r.cache)return;const{page:o}=e,i=oa(e,["page"]),s=["channelUsers","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Le(s))&&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};var El=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=>ct("channel.membersAdded",Object.assign(Object.assign({},r),{channelUsers:r.channelUsers.filter((t=>t.userId===e))}))));const o=await dl(r);n.cache&&Vs(o);const{channelUsers:i}=o;return!!i.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=>ct("channel.membersRemoved",Object.assign(Object.assign({},r),{channelUsers:r.channelUsers.filter((t=>t.userId===e))}))));const o=await dl(r);n.cache&&Vs(o);const{channelUsers:i}=o;return!!i.find((t=>t.channelId===e&&"member"!==t.membership))},getMembers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getMembers(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["channelUsers","collection",{channelId:e.channelId}],g=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["channelUsers","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];if(i=Ve(i,"roles",e.roles),e.memberships&&(i=i.filter((t=>!(!e.memberships.includes("muted")||!t.isMuted)||e.memberships.includes(t.membership)))),e.search){const t=new RegExp(e.search);i=i.filter((e=>e.userId.match(t)))}const s=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===s?Ze:Xe),t({onNextPage:y,data:i,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 i=ce("channelUsers")({channelId:e.channelId,userId:n.userId});"none"===n.membership?o.data=o.data.filter((e=>e!==i)):o.data.includes(i)||(o.data=[i,...o.data]),qe(d,o),g(o)},y=()=>{var e,t,n;const r=null===(e=Le(d))||void 0===e?void 0:e.data,o=null!==(t=null==r?void 0:r.data)&&void 0!==t?t:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(Sl,Object.assign(Object.assign({},a),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:c}}));ie(i,(({data:e,error:t,loading:n,nextPage:r})=>{const i={loading:n,error:t,params:{page:r},data:o};e&&(i.data=[...new Set([...o,...e.map(ce("channelUsers"))])]),qe(d,i),g(i)}),oe(l))};return u.push(ml(m()),yl(m()),bl(m()),wl(m()),Cl(m()),_l(m())),y(),()=>{r(`getMembers(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}}});var Al=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}),i=await dl(o);r.cache&&Vs(i);const{channelUsers:s}=i;return!!s.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}}),i=await dl(o);r.cache&&Vs(i);const{channelUsers:s}=i;return!!s.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 dl(r),{channelUsers:i}=o,s=n.cache&&Date.now();return n.cache&&Vs(o,{cachedAt:s}),{data:null==i?void 0:i.filter((e=>"banned"===e.membership)),cachedAt:s}},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 dl(r),i=n.cache&&Date.now();n.cache&&Vs(o,{cachedAt:i});const{channelUsers:s}=o;return{data:null==s?void 0:s.filter((e=>"member"===e.membership)),cachedAt:i}}}),Il=Object.freeze({__proto__:null,Membership:El,Moderation:Al,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 dl(n.data),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{channels:i}=r;return{data:i[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 dl(r),i=n.cache&&Date.now();n.cache&&Vs(o,{cachedAt:i});const{channels:s}=o;return{data:s.find((t=>t.channelId===e)),cachedAt:i}},deleteChannel:async e=>{const t=we();t.log("channel/deleteChannel",e),await t.http.delete(`/api/v3/channels/${encodeURIComponent(e)}`);return(await hl(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 dl(n);t.cache&&Vs(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 dl(n);t.cache&&Vs(r);const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"!==t.membership))},onChannelCreated:fl,onChannelUpdated:pl,onChannelDeleted:gl,onChannelJoined:ml,onChannelLeft:yl,onChannelMuted:vl,onChannelMemberAdded:bl,onChannelMemberRemoved:wl,onChannelMemberBanned:Cl,onChannelMemberUnbanned:_l,observeChannel:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeChannel(tmpid: ${r}) > listen`);const o=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.channelId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},i=[];return i.push(pl((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),gl((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),ml((e=>o({data:e,loading:!1,origin:"event"},"onJoin"))),yl((e=>o({data:e,loading:!1,origin:"event"},"onLeft"))),vl((e=>o({data:e,loading:!1,origin:"event"},"onMute"))),bl((e=>o({data:e,loading:!1,origin:"event"},"onMemberAdded"))),wl((e=>o({data:e,loading:!1,origin:"event"},"onMemberRemoved")))),ie(re(hl,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeChannel(tmpid: ${r}) > dispose`),i.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(fl((e=>o(e,"onCreate"))),pl((e=>o(e,"onUpdate"))),gl((e=>o(e,"onDelete"))),ml((e=>o(e,"onJoin"))),yl((e=>o(e,"onLeft"))),vl((e=>o(e,"onMute"))),bl((e=>o(e,"onMemberAdded"))),wl((e=>o(e,"onMemberRemoved")))),()=>{t(`observeChannels(tmpid: ${n}) > dispose`),r.forEach((e=>e()))}},getChannel:(e,t)=>da(e,t,"channelId",hl,[pl,gl,ml,yl,bl,wl,Cl,_l,vl,()=>ba((()=>null))]),getChannels:(e,t,n)=>{const{log:r,cache:o,userId:i}=we();o||console.log(p);const s=Date.now();r(`getChannels(tmpid: ${s}) > listen`);const{limit:a}=e,c=oa(e,["limit"]),l=null!=a?a:h,{policy:u=f}=null!=n?n:{},d=[],g=["channel","collection",{}],m=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["channel","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(s=Ve(s,"isDeleted",e.isDeleted),s=Ve(s,"displayName",e.displayName),e.types&&(s=s.filter((t=>{var n;return null===(n=e.types)||void 0===n?void 0:n.includes(t.type)}))),e.tags&&(s=s.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&&(s=s.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&&i&&(s=We(s,e.membership,i)),e.sortBy){case"firstCreated":s=s.sort(Xe);break;case"lastCreated":s=s.sort(Ze);break;case"displayName":s=s.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Ge);break;default:s=s.sort(et)}t({onNextPage:b,data:s,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=()=>{var e,t,n;const r=null===(e=Le(g))||void 0===e?void 0:e.data,o=null!==(t=null==r?void 0:r.data)&&void 0!==t?t:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(kl,Object.assign(Object.assign({},c),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:l}}));ie(i,(({data:e,error:t,loading:n,nextPage:r})=>{const i={loading:n,error:t,params:{page:r},data:o};e&&(i.data=[...new Set([...o,...e.map(ce("channel"))])]),qe(g,i),m(i)}),oe(u,y))};return d.push(fl(v()),gl(v()),pl(v()),vl(v()),ml(v()),yl(v()),bl(v()),wl(v()),ba((()=>null))),b(),()=>{r(`getChannels(tmpid: ${s}) > dispose`),d.forEach((e=>e())),He(g)}},MARKER_INCLUDED_CHANNEL_TYPE:sl,isUnreadCountSupport:al,convertFromRaw:ll,updateChannelMarker:ul,prepareChannelPayload:dl}),Tl={},Ol={},xl={};Object.defineProperty(xl,"__esModule",{value:!0}),xl.bytesToString=xl.stringToBytes=xl.NIL=xl.X500=xl.OID=xl.URL=xl.DNS=xl.hexToByte=xl.byteToHex=void 0;let Rl=[],Pl={};for(var Ml=0;Ml<256;Ml++)Rl[Ml]=(Ml+256).toString(16).substr(1),Pl[Rl[Ml]]=Ml;xl.byteToHex=Rl,xl.hexToByte=Pl,xl.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",xl.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",xl.OID="6ba7b812-9dad-11d1-80b4-00c04fd430c8",xl.X500="6ba7b814-9dad-11d1-80b4-00c04fd430c8",xl.NIL="00000000-0000-0000-0000-000000000000";xl.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};xl.bytesToString=e=>{const t=new Uint8Array(e,0,e.byteLength);return String.fromCharCode.apply(null,Array.from(t))},Object.defineProperty(Ol,"__esModule",{value:!0}),Ol.parse=void 0;const jl=xl;Ol.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++]=jl.hexToByte[e]),"")));o<16;)t[r+o++]=0;return t};var Nl={};Object.defineProperty(Nl,"__esModule",{value:!0}),Nl.unparse=void 0;const Fl=xl;Nl.unparse=(e,t)=>{let n=t||0,r=Fl.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 Bl={},Ul={};Object.defineProperty(Ul,"__esModule",{value:!0});Ul.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 Dl=_e&&_e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Bl,"__esModule",{value:!0}),Bl.validate=void 0;const Ll=Dl(Ul);Bl.validate=e=>"string"==typeof e&&Ll.default.test(e);var ql={};Object.defineProperty(ql,"__esModule",{value:!0}),ql.version=void 0;const zl=Bl;ql.version=e=>{if(!zl.validate(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)};var $l={},Hl={};Object.defineProperty(Hl,"__esModule",{value:!0}),Hl.stringify=void 0;const Vl=Bl,Wl=[];for(let e=0;e<256;++e)Wl.push((e+256).toString(16).substr(1));Hl.stringify=(e,t=0)=>{const n=(Wl[e[t+0]]+Wl[e[t+1]]+Wl[e[t+2]]+Wl[e[t+3]]+"-"+Wl[e[t+4]]+Wl[e[t+5]]+"-"+Wl[e[t+6]]+Wl[e[t+7]]+"-"+Wl[e[t+8]]+Wl[e[t+9]]+"-"+Wl[e[t+10]]+Wl[e[t+11]]+Wl[e[t+12]]+Wl[e[t+13]]+Wl[e[t+14]]+Wl[e[t+15]]).toLowerCase();if(!Vl.validate(n))throw TypeError("Stringified UUID is invalid");return n};var Kl={};Object.defineProperty(Kl,"__esModule",{value:!0}),Kl.rng=void 0;Kl.rng=()=>{let e=new Array(16);for(let t=0;t<16;t++)e[t]=255&256*Math.random()+0;return e},Object.defineProperty($l,"__esModule",{value:!0}),$l.v1=void 0;const Ql=Hl,Jl=Kl;let Gl,Yl,Xl=0,Zl=0;$l.v1=(e,t,n=0)=>{let r=t&&n||0;const o=t||new Uint8Array(16);let i=e&&e.node?e.node:Gl,s=e&&e.clockseq?e.clockseq:Yl;if(null==i||null==s){const t=e&&e.random?e.random:e&&e.rng?e.rng():Jl.rng();null==i&&(i=Gl=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==s&&(s=Yl=16383&(t[6]<<8|t[7]))}let a=e&&e.msecs?e.msecs:Date.now(),c=e&&e.nsecs?e.nsecs:Zl+1;const l=a-Xl+(c-Zl)/1e4;if(l<0&&e&&!e.clockseq&&(s=s+1&16383),(l<0||a>Xl)&&e&&!e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Xl=a,Zl=c,Yl=s,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++]=s>>>8|128,o[r++]=255&s;for(let e=0;e<6;++e)o[r+e]=i[e];return t||Ql.stringify(o)};var eu={};Object.defineProperty(eu,"__esModule",{value:!0}),eu.v4=void 0;const tu=Nl,nu=Kl;eu.v4=(e,t,n)=>{let r=t&&n||0,o=nu.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 i=0;i<16;i++)t[r+i]=o[i];return t||tu.unparse(o)};var ru={},ou={};Object.defineProperty(ou,"__esModule",{value:!0}),ou.v35=void 0;const iu=Hl,su=Ol,au=xl;ou.v35=(e,t,n)=>(e,r,o,i=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 s=new Uint8Array(16+e.length);if(s.set(r),s.set(e,r.length),s=au.stringToBytes(n(au.bytesToString(s))),s[6]=15&s[6]|t,s[8]=63&s[8]|128,o)for(let e=0;e<16;++e)o[i+e]=s[e];return o||iu.stringify(s)};var cu={};!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=>i(r(c(e))),e.default=e.hex_sha1;e.b64_sha1=e=>s(r(c(e)));e.any_sha1=(e,t)=>a(r(c(e)),t);e.hex_hmac_sha1=(e,t)=>i(o(c(e),c(t)));e.b64_hmac_sha1=(e,t)=>s(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 i=0;i<16;i++)r[i]=909522486^n[i],o[i]=1549556828^n[i];var s=d(r.concat(l(t)),512+8*t.length);return u(d(o.concat(s),672))},i=e=>{for(var n,r=t?"0123456789ABCDEF":"0123456789abcdef",o="",i=0;i<e.length;i++)n=e.charCodeAt(i),o+=r.charAt(n>>>4&15)+r.charAt(15&n);return o},s=e=>{for(var t="",r=e.length,o=0;o<r;o+=3)for(var i=e.charCodeAt(o)<<16|(o+1<r?e.charCodeAt(o+1)<<8:0)|(o+2<r?e.charCodeAt(o+2):0),s=0;s<4;s++)8*o+6*s>8*e.length?t+=n:t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(i>>>6*(3-s)&63);return t},a=(e,t)=>{var n,r,o,i,s=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(i=[],o=0,n=0;n<c.length;n++)o=(o<<16)+c[n],o-=(r=Math.floor(o/s))*s,(i.length>0||r>0)&&(i[i.length]=r);a[a.length]=o,c=i}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,i=-1732584194,s=271733878,a=-1009589776,c=0;c<e.length;c+=16){for(var l=r,u=o,d=i,m=s,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,i,s)),p(p(a,n[v]),f(v)));a=s,s=i,i=g(o,30),o=r,r=t}r=p(r,l),o=p(o,u),i=p(i,d),s=p(s,m),a=p(a,y)}return[r,o,i,s,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}(cu);var lu=_e&&_e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(ru,"__esModule",{value:!0}),ru.v5=void 0;const uu=ou,du=lu(cu);ru.v5=uu.v35("v5",80,du.default),Object.defineProperty(Tl,"__esModule",{value:!0});const hu=Ol,fu=Nl,pu=Bl,gu=ql,mu=$l,yu=eu,vu=ru,bu=xl;var wu=Tl.default={parse:hu.parse,unparse:fu.unparse,validate:pu.validate,version:gu.version,v1:mu.v1,v4:yu.v4,v5:vu.v5,NIL:bu.NIL,DNS:bu.DNS,URL:bu.URL,OID:bu.OID,X500:bu.X500};const Cu=()=>`LOCAL_${wu.v4().toString()}`;let _u;const ku=async e=>{const t=we();t.log("message/createMessage",e);const n=e.referenceId||_u||Cu();_u=void 0;const{data:r}=await t.http.post("/api/v5/messages",Object.assign(Object.assign({},ya(e)),{referenceId:n})),o=await ma(r),{messages:i}=o,s=t.cache&&Date.now();return t.cache&&(He(["message","get",n]),Vs(o,{cachedAt:s})),ct("local.message.created",{messages:i}),{data:i[0],cachedAt:s}};ku.optimistically=e=>{var t,n,{referenceId:r}=e,o=oa(e,["referenceId"]);const i=we();if(!i.cache)return;_u=r||Cu();const s=Object.assign({messageId:_u,uniqueId:_u},o);i.log("message/createMessage.optimistically",s);const a=Le(["subChannel","get",o.subChannelId]);if(a&&($e(["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)&&$e(["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:i.userId,channelSegment:(null!==(n=null==a?void 0:a.data.messageCount)&&void 0!==n?n:0)+1,childrenNumber:0,createdAt:c,updatedAt:c},s);return qe(["message","get",l.messageId],l,{cachedAt:-5}),ct("local.message.created",{messages:[l]}),{cachedAt:-5,data:l}};const Su=async(e,t)=>{const n=we();n.log("message/updateMessage",t);const{data:r}=await n.http.put(`/api/v5/messages/${encodeURIComponent(e)}`,ya(t)),o=await ma(r),i=n.cache&&Date.now();n.cache&&Vs(o,{cachedAt:i});const{messages:s}=o;return ct("local.message.updated",{messages:s}),{data:s.find((t=>t.messageId===e)),cachedAt:i}};Su.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 $e(["message","get",e],o,{cachedAt:-1}),ct("local.message.updated",{messages:[o]}),{data:o,cachedAt:-1}};const Eu=async e=>{const t=we();t.log("message/deleteMessage",e),await t.http.delete(`/api/v5/messages/${encodeURIComponent(e)}`);const n=await Oc(e);return ct("local.message.deleted",{messages:[n.data]}),n.data};Eu.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 $e(["message","get",e],n,{cachedAt:-1}),ct("local.message.deleted",{messages:[n]}),{data:n,cachedAt:-1}};const Au=async e=>{const t=we();t.log("message/queryMessages",e);const n=va(e),{data:r}=await t.http.get("/api/v5/messages",{params:n}),{paging:o}=r,i=oa(r,["paging"]),s=await ma(i),{messages:a}=s,c=t.cache&&Date.now();if(t.cache){Vs(s,{cachedAt:c});qe(["message","query",n],{messages:a.map(ce("message")),paging:o})}ct("local.message.fetched",{messages:a});const l=Y(o.next);return{data:a,cachedAt:c,prevPage:Y(o.previous),nextPage:l}};var Iu=Object.freeze({__proto__:null,createMessage:ku,updateMessage:Su,deleteMessage:Eu,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&&Vs(r,{cachedAt:o}),!0},onMessageCreated:ba,onMessageUpdated:wa,onMessageDeleted:Ca,onMessageFlagged:_a,onMessageUnflagged:ka,onMessageFlagCleared:Sa,onMessageReactionAdded:Ea,onMessageReactionRemoved:Aa,onMessageFetched:Ia,getMessage:(e,t)=>da(e,t,"messageId",Oc,[Ia,wa,Ca,_a,ka,Sa,Ea,Aa]),getMessages:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getMessages(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["message","collection",{subChannelId:e.subChannelId}],g=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["message","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.includeDeleted||(i=Ve(i,"isDeleted",!1)),t({onNextPage:v,data:i,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),u.push((()=>He(d))),g(r))},v=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(Au,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({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("message"))])]),qe(d,o),g(o)}),oe(l,y))};return u.push(Ia(m()),ba(m()),wa(m()),Ca(m()),_a(m()),ka(m()),Sa(m()),Ea(m()),Aa(m())),v(),()=>{r(`getMessages(tmpid: ${i}) > 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 i=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.messageId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},s=[];return s.push(wa((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),Ca((e=>i({data:e,loading:!1,origin:"event"},"onDelete")))),"no_fetch"!==n&&ie(re(Oc,e),(e=>e.data&&i(e,"onFetch")),oe(n)),()=>{r(`observeMessages(tmpid: ${o}) > dispose`),s.forEach((e=>e()))}},observeMessages:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeMessages(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.subChannelId)===e){if(t instanceof Function)return t(n);null===(i=t.onEvent)||void 0===i||i.call(t,r,n),null===(s=t[r])||void 0===s||s.call(t,n)}};return o.push(ba((e=>i({data:e,loading:!1,origin:"event"},"onCreate"))),wa((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),Ca((e=>i({data:e,loading:!1,origin:"event"},"onDelete")))),()=>{n(`observeMessages(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},convertFromRaw:pa,updateMessageMarker:ga,prepareMessagePayload:ma,convertParams:ya,convertQueryParams:va});const Tu=async e=>{const t=we();t.log("channel/getSubChannel",e),bc("subChannel",e);try{const n=await t.http.get(`/api/v5/message-feeds/${encodeURIComponent(e)}`),r=await Ra(n.data),o=t.cache&&Date.now();return t.cache&&Vs(r,{cachedAt:o}),ct("local.message-feed.fetched",r),{data:r.messageFeeds[0],cachedAt:o}}catch(t){throw _(null==t?void 0:t.code)&&wc("subChannel",e),t}};Tu.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 Ou=e=>at(we(),"onSubChannelFetched","local.message-feed.fetched",(t=>e(t.messageFeeds[0])));function xu(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 Ru=async e=>{const t=we();t.log("channel/querySubChannels",e);const n=Pa(e),{page:r={limit:10},channelId:o,includeDeleted:i}=n,s=oa(n,["page","channelId","includeDeleted"]),a=(await t.http.get(`/api/v5/message-feeds/channel/${o}`,{params:Object.assign(Object.assign({},s),{isDeleted:ha(i),options:{token:J(r,"skiplimit")}})})).data,{paging:c}=a,l=oa(a,["paging"]),u=await Ra(l),d=u.messageFeeds,h=t.cache&&Date.now();if(t.cache){Vs(u,{cachedAt:h});const e=["subChannel","query",Object.assign(Object.assign({channelId:o},s),{options:Object.assign({},r)})];qe(e,{subChannels:d.map(ce("subChannel")),paging:c})}ct("local.message-feed.fetched",u);const f=G(c.next);return{data:d,cachedAt:h,prevPage:G(c.previous),nextPage:f}};Ru.locally=e=>{var t,n,r;we().log("channel/querySubChannels.locally",e);const o=null!==(t=Pa(e))&&void 0!==t?t:{},{page:i={limit:10},channelId:s}=o,a=oa(o,["page","channelId"]),c=["subChannel","query",Object.assign(Object.assign({channelId:s},a),{options:Object.assign({},i)})],{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 Pu=Object.freeze({__proto__:null,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 Ra(n.data),o=t.cache&&Date.now();return t.cache&&Vs(r,{cachedAt:o}),ct("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 Ra(r.data),i=n.cache&&Date.now();return n.cache&&Vs(o,{cachedAt:i}),ct("message-feed.updated",r.data),{data:o.messageFeeds[0],cachedAt:i}},deleteSubChannel:async(e,t=!1)=>{const n=we();n.log("channel/deleteSubChannel",e);const r=await Tu(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((()=>{wc("subChannel",e)}),0):$e(["subChannel","get",e],o),ct("local.message-feed.deleted",{messageFeeds:[o]}),o},startReadingAPI:Ma,stopReadingAPI:ja,onSubChannelCreated:Da,onSubChannelUpdated:La,onSubChannelDeleted:qa,getSubChannel:(e,t)=>da(e,t,"subChannelId",Tu,[Ou,La,qa]),getSubChannels:(e,t,n)=>{const{log:r,cache:o}=we(),i=Date.now();r(`getSubChannels(tmpid: ${i}) > listen`),o||console.log(p);const{limit:s=h}=e,a=oa(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(et),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(Ru,Object.assign(Object.assign({},a),{page:null!==(e=null==l?void 0:l.params.page)&&void 0!==e?e:{limit:s}}));ie(n,(({data:e,error:n,loading:r,nextPage:o})=>{l={loading:r,error:n,params:{page:o},data:e?xu(t,e):t},d(l)}),oe(c,y))};return u.push(Da(g("onCreate")),qa(g("onDelete")),Ou(g("onFetch")),La(g("onUpdate"))),m(),()=>{r(`getSubChannels(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},startReading:e=>(Fa[e]=!0,0===Na.length&&Ua(),Ma(e)),stopReading:e=>(Fa[e]=!1,Na.forEach((e=>e())),Na=[],ja(e))});const Mu=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},ju=e=>{const t=e.communities.map((e=>{var{needApprovalOnPostCreation:t,onlyAdminCanPost:n}=e,r=oa(e,["needApprovalOnPostCreation","onlyAdminCanPost"]);return Object.assign({postSetting:Mu({needApprovalOnPostCreation:t,onlyAdminCanPost:n})},r)})),n=xc(e.communityUsers);return Object.assign(Object.assign({},e),{communities:t,communityUsers:n})},Nu=e=>{const{postSetting:t}=e,r=oa(e,["postSetting"]);return Object.assign(Object.assign({},r),t?n[t]:void 0)},Fu=async e=>{const t=we();t.log("community/getCommunity",e);const{data:n}=await t.http.get(`/api/v3/communities/${e}`),r=ju(n),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{communities:i}=r;return{data:i.find((t=>t.communityId===e)),cachedAt:o}};Fu.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 Bu=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=ju(r),{communities:i}=o,s=t.cache&&Date.now();if(t.cache){Vs(o,{cachedAt:s});qe(["community","top-trending",{params:{options:{limit:n}}}],{communities:i.map(ce("community"))})}return{data:i,cachedAt:s}};Bu.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:{},i=["community","top-trending",{params:{options:{limit:o}}}],{data:s,cachedAt:a}=null!==(t=Le(i))&&void 0!==t?t:{};if(!(null==s?void 0:s.communities.length))return;const c=s.communities.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e));return c.length===(null===(n=null==s?void 0:s.communities)||void 0===n?void 0:n.length)?{data:c,cachedAt:a}:void 0};const Uu=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=ju(r),{communities:i}=o,s=t.cache&&Date.now();if(t.cache){Vs(o,{cachedAt:s});qe(["community","recommended",{params:{options:{limit:n}}}],{communities:i.map(ce("community"))})}return{data:i,cachedAt:s}};Uu.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:{},i=["community","recommended",{params:{options:{limit:o}}}],{data:s,cachedAt:a}=null!==(t=Le(i))&&void 0!==t?t:{};if(!(null==s?void 0:s.communities.length))return;const c=s.communities.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e));return c.length===(null===(n=null==s?void 0:s.communities)||void 0===n?void 0:n.length)?{data:c,cachedAt:a}:void 0};const Du=(e,t)=>{const n=we();return at(n,e,e,(e=>{const r=ju(e);if(n.cache){Vs(r);const e=Le(["community","get",r.communities[0].communityId]);t(e.data)}else t(r.communities[0])}))},Lu=e=>Du("community.created",e),qu=e=>Du("community.updated",e),zu=e=>Du("community.deleted",e);function $u(e,t){return e.map((e=>{const n=t.some((t=>function(e,t){const{userId:n}=ut();return e.communityId===t.communityId&&t.userId===n}(e,t)&&"none"!==t.communityMembership));return Object.assign(Object.assign({},e),{isJoined:n})}))}function Hu(e,t,n){return!!e.permissions.some((e=>e===n))||t.users.find((t=>t.userId===e.userId)).permissions.some((e=>e===n))}function Vu(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=>!Hu(e,t,"BAN_COMMUNITY_USER")))[0]:t.communityUsers.filter((e=>!Hu(e,t,"ADD_COMMUNITY_USER")))[0]}const Wu=(e,t)=>{const n=we();return at(n,e,e,(r=>{const o=ju(r),{communities:i,communityUsers:s}=o,a=$u(i,s);if(o.communities=a,n.cache){Vs(o);const n=Le(["community","get",o.communities[0].communityId]),r=Le(["communityUsers","get",ce("communityUsers")(Vu(e,o))]);t(n.data,r.data)}else t(o.communities[0],Vu(e,o))}))},Ku=e=>Wu("community.userAdded",e),Qu=e=>Wu("community.userRemoved",e),Ju=e=>Wu("community.userBanned",e),Gu=e=>Wu("community.userChanged",e),Yu=e=>Wu("community.userUnbanned",e),Xu=e=>Wu("community.roleAdded",e),Zu=e=>Wu("community.roleRemoved",e),ed=e=>Wu("community.joined",e),td=e=>Wu("community.left",e),nd=async e=>{const t=we();t.log("channel/queryCommunities",e);const n=null!=e?e:{},{page:r}=n,o=oa(n,["page"]),i=null!=o?o:{},{displayName:s,membership:a,includeDeleted:c}=i,l=oa(i,["displayName","membership","includeDeleted"]),{data:u}=await t.http.get("/api/v3/communities",{params:Object.assign(Object.assign({},l),{isDeleted:ha(c),keyword:s,filter:a,options:{token:J(r,"skiplimit")}})}),{paging:d}=u,h=oa(u,["paging"]),f=ju(h),{communities:p}=f,g=t.cache&&Date.now();if(t.cache){Vs(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}};nd.locally=e=>{we().log("community/queryCommunities.locally",e)};var rd=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});ct("community.userAdded",r);const o=Rc(r,"communityUsers");n.cache&&Vs(o);const{communityUsers:i}=o;return!!i.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}});ct("community.userRemoved",r);const o=Rc(r,"communityUsers");n.cache&&Vs(o);const{communityUsers:i}=o;return!!i.find((t=>t.communityId===e&&"member"!==t.communityMembership))},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}),i=Rc(o,"communityUsers");r.cache&&Vs(i);const{communityUsers:s}=i;return!!s.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}}),i=Rc(o,"communityUsers");r.cache&&Vs(i);const{communityUsers:s}=i;return!!s.find((n=>n.communityId===e&&!t.some((e=>n.roles.includes(e)))))}});const od=async e=>{const t=we();t.log("community/queryCommunityMembers",e);const n=null!=e?e:{},{page:r}=n,o=oa(n,["page"]),{data:i}=await t.http.get(`/api/v3/communities/${o.communityId}/users`,{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:s}=i,a=oa(i,["paging"]),c=Rc(a,"communityUsers"),{communityUsers:l}=c,u=t.cache&&Date.now();if(t.cache){Vs(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:s})}return{data:l,cachedAt:u,nextPage:G(s.next),prevPage:G(s.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:i}=o,s=oa(o,["page"]),a=["communityUsers","query",Object.assign(Object.assign({},s),{options:Object.assign({},i)})],{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 id=Object.freeze({__proto__:null,getMembers:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getMembers(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["communityUsers","collection",{communityId:e.communityId}],g=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["communityUsers","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];if(e.roles&&(i=i.filter((t=>{var n;return null===(n=t.roles)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.roles)||void 0===n?void 0:n.includes(t)}))}))),e.membership&&(i=i.filter((({communityMembership:t})=>e.membership.includes(t)))),e.search){const t=new RegExp(e.search);i=i.filter((e=>{var n;return!!e.userId.match(t)||e.user&&(null===(n=e.user.displayName)||void 0===n?void 0:n.match(t))}))}const s=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===s?Ze:Xe),t({onNextPage:y,data:i,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 i=ce("communityUsers")({communityId:e.communityId,userId:n.userId});o.data=[...new Set([i,...o.data])],qe(d,o),g(o)},y=()=>{var e,t,n;const r=null===(e=Le(d))||void 0===e?void 0:e.data,o=null!==(t=null==r?void 0:r.data)&&void 0!==t?t:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(od,Object.assign(Object.assign({},a),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:c}}));ie(i,(({data:e,error:t,loading:n,nextPage:r})=>{const i={loading:n,error:t,params:{page:r},data:o};e&&(i.data=[...new Set([...o,...e.map(ce("communityUsers"))])]),qe(d,i),g(i)}),oe(l))};return u.push(td(m()),ed(m()),Ju(m()),Yu(m()),Gu(m()),Xu(m()),Zu(m())),y(),()=>{r(`getMembers(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},onCommunityUserAdded:Ku,onCommunityUserRemoved:Qu,onCommunityUserBanned:Ju,onCommunityUserChanged:Gu,onCommunityUserUnbanned:Yu,onCommunityUserRoleAdded:Xu,onCommunityUserRoleRemoved:Zu,onCommunityJoined:ed,onCommunityLeft:td}),sd=Object.freeze({__proto__:null,Moderation:rd,Membership:id,createCommunity:async e=>{const t=we();t.log("user/createCommunity",e);const{data:n}=await t.http.post("/api/v3/communities/",Nu(e));ct("community.created",n);const r=ju(n),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{communities:i}=r;return{data:i[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}`,Nu(t));ct("community.updated",r);const o=ju(r),i=n.cache&&Date.now();n.cache&&Vs(o,{cachedAt:i});const{communities:s}=o;return{data:s.find((t=>t.communityId===e)),cachedAt:i}},deleteCommunity:async e=>{const t=we();t.log("community/deleteCommunity",e),await t.http.delete(`/api/v3/communities/${e}`);const n=await Fu(e);return ct("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`);ct("community.joined",n);const r=ju(n),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{communityUsers:i}=r;return!!i.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`);ct("community.left",n);const r=ju(n),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{communityUsers:i}=r;return!!i.find((t=>t.communityId===e&&"member"!==t.communityMembership))},getTopTrendingCommunities:Bu,getRecommendedCommunities:Uu,onCommunityCreated:Lu,onCommunityUpdated:qu,onCommunityDeleted:zu,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)},i=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.communityId)===e&&o(t,n)},s=[];return s.push(qu((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),zu((e=>i({data:e,loading:!1,origin:"event"},"onDelete"))),ed((e=>i({data:e,loading:!1,origin:"event"},"onJoin"))),td((e=>i({data:e,loading:!1,origin:"event"},"onLeft"))),Ku((e=>i({data:e,loading:!1,origin:"event"},"onUserAdded"))),Qu((e=>i({data:e,loading:!1,origin:"event"},"onUserRemoved"))),Ju((e=>i({data:e,loading:!1,origin:"event"},"onUserBanned"))),Yu((e=>i({data:e,loading:!1,origin:"event"},"onUserUnbanned")))),ie(re(Fu,e),(e=>(e.data||e.error)&&o(e,"onFetch"))),()=>{n(`observeCommunity(tmpid: ${r}) > dispose`),s.forEach((e=>e()))}},getCommunities:(e,t,n)=>{const{log:r,cache:o,userId:i}=we();o||console.log(p);const s=Date.now();r(`getCommunities(tmpid: ${s}) > listen`);const{limit:a}=e,c=oa(e,["limit"]),l=null!=a?a:h,{policy:u=f}=null!=n?n:{},d=[],g=["community","collection",{}],m=n=>{var r,o;let s=null!==(r=n.data.map((e=>Le(["community","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];s=Ve(s,"displayName",e.displayName),e.includeDeleted||(s=Ve(s,"isDeleted",!1)),e.categoryId&&(s=s.filter((t=>{var n;return null===(n=t.categoryIds)||void 0===n?void 0:n.includes(e.categoryId)}))),e.tags&&(s=s.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&&i&&(s=Qe(s,e.membership,i));const a=e.sortBy||"lastCreated";"lastCreated"!==a&&"firstCreated"!==a||(s=s.sort("lastCreated"===a?Ze:Xe)),"displayName"===a&&(s=s.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(Ge)),t({onNextPage:b,data:s,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=()=>{var e,t,n;const r=null===(e=Le(g))||void 0===e?void 0:e.data,o=null!==(t=null==r?void 0:r.data)&&void 0!==t?t:[];if(o.length>0&&!(null==r?void 0:r.params.page))return;const i=re(nd,Object.assign(Object.assign({},c),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:l}}));ie(i,(({data:e,error:t,loading:n,nextPage:r})=>{const i={loading:n,error:t,params:{page:r},data:o};e&&(i.data=[...new Set([...o,...e.map(ce("community"))])]),qe(g,i),m(i)}),oe(u,y))};return d.push(Lu(v()),zu(v()),qu(v()),ed(v()),td(v()),Gu(v())),b(),()=>{r(`getCommunities(tmpid: ${s}) > dispose`),d.forEach((e=>e())),He(g)}},getCommunity:(e,t)=>da(e,t,"communityId",Fu,[qu,zu,ed,td,Ju,Yu,Gu])});const ad=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&&Vs(n,{cachedAt:r});const{categories:o}=n;return{data:o.find((t=>t.categoryId===e)),cachedAt:r}};ad.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 cd=async e=>{const t=we();t.log("category/queryCategories",e);const n=null!=e?e:{},{page:r={limit:10},includeDeleted:o}=n,i=oa(n,["page","includeDeleted"]),{data:s}=await t.http.get("/api/v3/community-categories",{params:Object.assign(Object.assign({},i),{isDeleted:ha(o),options:{token:J(r,"skiplimit")}})}),{paging:a}=s,c=oa(s,["paging"]),{categories:l}=c,u=t.cache&&Date.now();if(t.cache){Vs(c,{cachedAt:u});const e=["category","query",Object.assign(Object.assign({},i),{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}};cd.locally=e=>{var t,n;const r=we();if(r.log("category/queryCategories.locally",e),!r.cache)return;const o=null!=e?e:{},{page:i={limit:10}}=o,s=oa(o,["page"]),a=["category","query",Object.assign(Object.assign({},s),{options:Object.assign({},i)})],{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 ld=Object.freeze({__proto__:null,getCategory:ad,getCategories:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getCategories(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["category","collection",{}],g=()=>{var n,r,o;const i=null===(n=Le(d))||void 0===n?void 0:n.data,s=null!==(r=null==i?void 0:i.data)&&void 0!==r?r:[];if(s.length>0&&!(null==i?void 0:i.params.page))return;const u=re(cd,Object.assign(Object.assign({},a),{page:null!==(o=null==i?void 0:i.params.page)&&void 0!==o?o:{limit:c}}));ie(u,(({data:n,error:r,loading:o,nextPage:i})=>{const a={loading:o,error:r,params:{page:i},data:s};n&&(a.data=[...new Set([...s,...n.map(ce("category"))])]),qe(d,a),(n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["category","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];switch(e.includeDeleted||(i=Ve(i,"isDeleted",!1)),e.sortBy){case"firstCreated":i=i.sort(Xe);break;case"lastCreated":i=i.sort(Ze);break;default:i=i.sort(Ye)}t({onNextPage:g,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})})(a)}),oe(l))};return u.push((()=>{})),g(),()=>{r(`getCategories(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}}});const ud=async e=>{const t=we();t.log("feed/queryGlobalFeed",e);const n=null!=e?e:{},{useCustomRanking:r,page:o}=n,i=oa(n,["useCustomRanking","page"]),{data:s}=await t.http.get(r?"/api/v5/me/global-feeds":"/api/v4/me/global-feeds",{params:Object.assign(Object.assign({},i),{options:{token:J(o,"skiplimit")}})}),{paging:a}=s,c=oa(s,["paging"]),l=Rc(c,"communityUsers"),{posts:u}=l,d=t.cache&&Date.now();if(t.cache){Vs(l);const e=["globalFeed","query",Object.assign(Object.assign({},i),{useCustomRanking:r,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}};ud.locally=e=>{var t,n;const r=we();if(r.log("post/queryGlobalFeed.locally",e),!r.cache)return;const o=null!=e?e:{},{useCustomRanking:i,page:s}=o,a=oa(o,["useCustomRanking","page"]),c=["globalFeed","query",Object.assign(Object.assign({},a),{useCustomRanking:i,options:Object.assign({},s)})],{data:l,cachedAt:u}=null!==(t=Le(c))&&void 0!==t?t:{};if(!(null==l?void 0:l.posts.length))return;const d=l.posts.map((e=>Le(["post","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===(n=null==l?void 0:l.posts)||void 0===n?void 0:n.length)?{data:d,cachedAt:u,prevPage:h,nextPage:f}:void 0};var dd=Object.freeze({__proto__:null,queryGlobalFeed:ud});const hd=async e=>{const t=we();t.log("post/queryPosts",e);const{page:n={limit:10},includeDeleted:r}=e,o=oa(e,["page","includeDeleted"]),{dataTypes:i,matchingOnlyParentPost:s}=o,{data:a}=await t.http.get("/api/v4/posts",{params:Object.assign(Object.assign({},o),{isDeleted:ha(r),matchingOnlyParentPost:null!=s?s:!(null==i?void 0:i.length),options:{token:J(n,"afterbeforeraw")}})}),{paging:c}=a,l=oa(a,["paging"]),u=Rc(l,"communityUsers"),{posts:d}=l,h=t.cache&&Date.now();if(t.cache){Vs(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}};hd.locally=e=>{var t,n;const r=we();if(r.log("post/queryPosts.locally",e),!r.cache)return;const{page:o={limit:10}}=e,i=oa(e,["page"]),s=["post","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Le(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.posts.length))return;const l=a.posts.map((e=>Le(["post","get",e]))).filter(Boolean).map((({data:e})=>e)),u=Y(null==a?void 0:a.paging.previous),d=Y(null==a?void 0:a.paging.next);return l.length===(null===(n=null==a?void 0:a.posts)||void 0===n?void 0:n.length)?{data:l,cachedAt:c,prevPage:u,nextPage:d}:void 0};var fd=Object.freeze({__proto__:null,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);ct("post.created",n);const r=Rc(n,"communityUsers"),o=t.cache&&Date.now();t.cache&&Vs(r,{cachedAt:o});const{posts:i}=r;return{data:i[0],cachedAt:o}},updatePost:async(e,t)=>{const n=we();n.log("user/updatePost",t);const{data:r}=await n.http.put(`/api/v4/posts/${encodeURIComponent(e)}`,t),o=Rc(r,"communityUsers"),i=n.cache&&Date.now();n.cache&&Vs(o,{cachedAt:i}),ct("post.updated",o);const{posts:s}=o;return{data:s.find((t=>t.postId===e)),cachedAt:i}},deletePost:async(e,t=!1)=>{const n=we();n.log("post/deletePost",e);const r=await Pc(e);if(await n.http.delete(`/api/v4/posts/${encodeURIComponent(e)}`,{params:{postId:e,permanent:t}}),"community"===r.data.targetType){const e=await Fu(r.data.targetId);ct("community.updated",{communities:[e.data],categories:[],communityUsers:[],feeds:[],files:[],users:[]})}const o=Object.assign(Object.assign({},r.data),{isDeleted:!0});return ct("post.deleted",{posts:[o],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),t?setTimeout((()=>{wc("post",e)}),0):$e(["post","get",e],{isDeleted:!0}),o},approvePost:async e=>{const t=we();t.log("post/approvePost",e);const{data:n}=await t.http.post(`/api/v3/posts/${encodeURIComponent(e)}/approve`);ct("post.approved",n),"community"===n.posts[0].targetType&&ct("community.updated",n);const r=Rc(n,"communityUsers"),o=t.cache&&Date.now();return t.cache&&Vs(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&&ct("community.updated",n),ct("post.declined",n);const r=Rc(n,"communityUsers"),o=t.cache&&Date.now();return t.cache&&Vs(r,{cachedAt:o}),{data:n.posts.find((t=>t.postId===e)),cachedAt:o}},onPostCreated:Uc,onPostUpdated:Dc,onPostDeleted:Lc,onPostApproved:qc,onPostDeclined:zc,onPostFlagged:$c,onPostUnflagged:Hc,onPostReactionAdded:Vc,onPostReactionRemoved:Wc,observePosts:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observePosts(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;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===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(Uc((e=>i(e,"onCreate"))),Dc((e=>i(e,"onUpdate"))),Lc((e=>i(e,"onDelete"))),qc((e=>i(e,"onApproved"))),zc((e=>i(e,"onDeclined"))),$c((e=>i(e,"onFlagged"))),Hc((e=>i(e,"onUnflagged"))),Vc((e=>i(e,"onReactionAdded"))),Wc((e=>i(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 i=(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.postId)===e&&i(t,n)},a=[];return a.push(Dc((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Lc((e=>s({data:e,loading:!1,origin:"event"},"onDelete"))),qc((e=>s({data:e,loading:!1,origin:"event"},"onApproved"))),zc((e=>s({data:e,loading:!1,origin:"event"},"onDeclined"))),$c((e=>s({data:e,loading:!1,origin:"event"},"onFlagged"))),Hc((e=>s({data:e,loading:!1,origin:"event"},"onUnflagged"))),Vc((e=>s({data:e,loading:!1,origin:"event"},"onReactionAdded"))),Wc((e=>s({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),ie(re(Pc,e),(e=>(e.data||e.error)&&i(e,"onFetch")),oe(n)),()=>{r(`observePosts(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},getPost:(e,t)=>da(e,t,"postId",Pc,[qc,zc,Lc,$c,Vc,Wc,Hc,Dc]),getPosts:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log(p);const i=Date.now();r(`getPosts(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["post","collection",{targetId:e.targetId,targetType:e.targetType}],g=n=>{var r,o,i;let s=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";s=s.sort("lastCreated"===a?Ze:Xe),e.includeDeleted||(s=Ve(s,"isDeleted",!1)),e.tags&&(s=s.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&&(s=Ke(s,e.feedType)),(null===(o=e.dataTypes)||void 0===o?void 0:o.length)&&(s=Je(s,e.dataTypes)),t({onNextPage:v,data:s,hasNextPage:!!(null===(i=n.params)||void 0===i?void 0:i.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),u.push((()=>He(d))),g(o))},v=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(hd,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({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("post"))])]),qe(d,o),g(o)}),oe(l,y))};return u.push(Uc(m("onCreate")),qc(m("onApproved")),zc(m("onDeclined")),Lc(m("onDelete")),Dc(m("onUpdate")),$c(m("onFlagged")),Hc(m("onUnflagged")),Vc(m("onReactionAdded")),Wc(m("onReactionRemoved"))),v(),()=>{r(`getPosts(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}}});const pd=async e=>{const t=we();t.log("comment/queryComments",e);const{page:n={limit:10},includeDeleted:r}=e,o=oa(e,["page","includeDeleted"]),i={type:o.sortBy?"pagination":void 0,token:J(n,o.sortBy?"skiplimit":"afterbefore")},{data:s}=await t.http.get("/api/v3/comments",{params:Object.assign(Object.assign({},o),{isDeleted:ha(r),options:i})}),{paging:a}=s,c=oa(s,["paging"]),{comments:l}=c,u=t.cache&&Date.now();if(t.cache){Vs(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}};pd.locally=e=>{var t,n;const r=we();if(r.log("comment/queryComments.locally",e),!r.cache)return;const{page:o={limit:10}}=e,i=oa(e,["page"]),s=["comment","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Le(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.comments.length))return;const l=a.comments.map((e=>Le(["comment","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.comments)||void 0===n?void 0:n.length)?{data:l,cachedAt:c,prevPage:u,nextPage:d}:void 0};var gd=Object.freeze({__proto__:null,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&&Vs(n,{cachedAt:r});const o=await Pc(e.referenceId);ct("post.updated",{posts:[o.data],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),ct("comment.created",n);const{comments:i}=n;return{data:i[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&&Vs(r,{cachedAt:o}),ct("comment.updated",r);const{comments:i}=r;return{data:i.find((t=>t.commentId===e)),cachedAt:o}},deleteComment:async(e,t=!1)=>{const n=we();n.log("comment/deleteComment",e);const r=await Mc(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}),i=await Pc(r.data.referenceId);return ct("post.updated",{posts:[i.data],categories:[],comments:[],communities:[],communityUsers:[],feeds:[],files:[],postChildren:[],users:[]}),ct("comment.deleted",{comments:[o],commentChildren:[],files:[],users:[]}),t?rt((()=>wc("comment",e))):$e(["comment","get",e],{isDeleted:!0}),o},onCommentCreated:Qc,onCommentUpdated:Jc,onCommentDeleted:Gc,onCommentFlagged:Yc,onCommentUnflagged:Xc,onCommentReactionAdded:Zc,onCommentReactionRemoved:el,observeComments:(e,t)=>{const{log:n}=we(),r=Date.now();n(`observeComments(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;if(n.referenceId===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(Qc((e=>i(e,"onCreate"))),Jc((e=>i(e,"onUpdate"))),Gc((e=>i(e,"onDelete"))),Yc((e=>i(e,"onFlagged"))),Xc((e=>i(e,"onUnflagged"))),Zc((e=>i(e,"onReactionAdded"))),el((e=>i(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 i=(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.commentId)===e&&i(t,n)},a=[];return a.push(Jc((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Gc((e=>s({data:e,loading:!1,origin:"event"},"onDelete"))),Yc((e=>s({data:e,loading:!1,origin:"event"},"onFlagged"))),Xc((e=>s({data:e,loading:!1,origin:"event"},"onUnflagged"))),Zc((e=>s({data:e,loading:!1,origin:"event"},"onReactionAdded"))),el((e=>s({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),ie(re(Mc,e),(e=>(e.data||e.error)&&i(e,"onFetch")),oe(n)),()=>{r(`observeComment(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},getComment:(e,t)=>da(e,t,"commentId",Mc,[Gc,Yc,Zc,el,Xc,Jc]),getComments:(e,t,n)=>{const{log:r,cache:o}=we();o||console.log("For using Live Collection feature you need to enable Cache!");const i=Date.now();r(`getComments(tmpid: ${i}) > listen`);const{limit:s}=e,a=oa(e,["limit"]),c=null!=s?s:h,{policy:l=f}=null!=n?n:{},u=[],d=["comment","collection",{referenceId:e.referenceType,referenceType:e.referenceId}],p=n=>{var r,o;let i=null!==(r=n.data.map((e=>Le(["comment","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.includeDeleted||(i=Ve(i,"isDeleted",!1));const s=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===s?Ze:Xe),t({onNextPage:m,data:i,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=()=>{var e,t,n,r,o;const i=null===(e=Le(d))||void 0===e?void 0:e.data,s=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:[];if(s.length>0&&!(null===(n=null==i?void 0:i.params)||void 0===n?void 0:n.page))return;const u=re(pd,Object.assign(Object.assign({},a),{page:null!==(o=null===(r=null==i?void 0:i.params)||void 0===r?void 0:r.page)&&void 0!==o?o:{limit:c}}));ie(u,(({data:e,error:t,loading:n,prevPage:r,nextPage:o})=>{const i={loading:n,error:t,params:{page:a.sortBy?o:r},data:s};e&&(i.data=[...new Set([...s,...e.map(ce("comment"))])]),qe(d,i),p(i)}),oe(l,y))};return u.push(Qc(g("onCreate")),Jc(g("onUpdate")),Gc(g("onDelete")),Yc(g("onFlagged")),Xc(g("onUnflagged")),Zc(g("onReactionAdded")),el(g("onReactionRemoved"))),m(),()=>{r(`getComments(tmpid: ${i}) > dispose`),u.forEach((e=>e())),He(d)}}});const md=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&&Vs(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}};md.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 yd=async e=>{const t=we();t.log("stream/getStreams",e);const n=null!=e?e:{},{page:r}=n,o=oa(n,["page"]),{data:i}=await t.http.get("/api/v3/video-streaming",{params:Object.assign(Object.assign({},o),{options:{token:J(r,"skiplimit")}})}),{paging:s,results:a}=i,{videoStreamings:c}=a,l=t.cache&&Date.now();t.cache&&Vs(a,{cachedAt:l});const u=G(s.next);return{data:c,cachedAt:l,prevPage:G(s.previous),nextPage:u}};yd.locally=e=>{we().log("stream/getStreams.locally",e)};var vd=Object.freeze({__proto__:null,getStream:md,getStreams:yd,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&&Vs(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&&Vs(r,{cachedAt:o});const{videoStreamings:i}=r;return{data:i.find((t=>t.streamId===e)),cachedAt:o}},deleteStream:async e=>{const t=we();t.log("stream/deleteStream",e);const n=await md(e),{data:r}=await t.http.delete(`/api/v3/video-streaming/${e}`),{success:o}=r,i=Object.assign(Object.assign({},n.data),{isDeleted:!0});return $e(["stream","get",e],i),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&&Vs(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}},onStreamStarted:e=>{const t=we();return at(t,"stream/onStreamStarted","video-streaming.didStart",(t=>{Vs(t),e(t.videoStreamings[0])}))},onStreamStopped:e=>{const t=we();return at(t,"stream/onStreamStarted","video-streaming.didStop",(t=>{Vs(t),e(t.videoStreamings[0])}))},onStreamRecorded:e=>{const t=we();return at(t,"stream/onStreamRecorded","video-streaming.didRecord",(t=>{Vs(t),e(t.videoStreamings[0])}))}});const bd=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&&Vs(n,{cachedAt:r});const{polls:o}=n;return{data:o.find((t=>t.pollId===e)),cachedAt:r}};bd.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 wd=e=>{const t=we();return at(t,"poll/onPollUpdated","poll.updated",(n=>{t.cache&&Vs(n),e(n.polls[0])}))},Cd=e=>{const t=we();return at(t,"poll/onPollDeleted","poll.deleted",(n=>{t.cache&&Vs(n),e(n.polls[0])}))};var _d=Object.freeze({__proto__:null,getPoll:bd,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&&Vs(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&&Vs(n,{cachedAt:r}),ct("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 bd(e),{data:r}=await t.http.delete(`/api/v3/polls/${e}`),{success:o}=r,i=Object.assign(Object.assign({},n.data),{isDeleted:!0});return $e(["poll","get",e],i),ct("poll.deleted",{polls:[i],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&&Vs(r,{cachedAt:o});const{polls:i}=r;return ct("poll.updated",r),{data:i.find((t=>t.pollId===e)),cachedAt:o}},onPollUpdated:wd,onPollDeleted:Cd,observePoll:(e,t,n="cache_then_server")=>{const{log:r}=we(),o=Date.now();r(`observePoll(tmpid: ${o}) > listen`);const i=(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.pollId)===e&&i(t,n)},a=[];return a.push(wd((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Cd((e=>s({data:e,loading:!1,origin:"event"},"onDelete")))),ie(re(bd,e),(e=>(e.data||e.error)&&i(e,"onFetch")),oe(n)),()=>{r(`observePoll(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}}});return e.API_REGIONS=Mt,e.CategoryRepository=ld,e.ChannelRepository=Il,e.Client=Ya,e.CommentRepository=gd,e.CommunityPostSettingMaps=n,e.CommunityPostSettings=t,e.CommunityRepository=sd,e.ContentFeedType=o,e.DefaultCommunityPostSetting=r,e.FeedRepository=dd,e.FileRepository=Ec,e.FileType=i,e.MessageContentType=l,e.MessageRepository=Iu,e.PollRepository=_d,e.PostContentType=u,e.PostRepository=fd,e.ReactionRepository=ol,e.StreamRepository=vd,e.SubChannelRepository=Pu,e.UserRepository=kc,e.VERSION=d,e.VideoResolution=s,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 i=Object.fromEntries(Object.entries(r.data).filter((([e,n])=>t(n))));return!!Object.keys(i).length&&(await Ue.setItem(`${e}#${o}`,JSON.stringify(i)),!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}=il[e];return`/api/v3/${n}/${encodeURIComponent(t)}/flag`})());if(n.cache)if("message"===e){const e=await ma(r);Vs(e)}else Vs("post"===e?Rc(r,"communityUsers"):r);return ct(`${e}.flagged`,r),!!r},e.createUserToken=async(e,t,n)=>{const r=Ds(),o=Ls(),i=yr(Nt("http",t)),{data:s}=await i.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:s.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}=il[e];return`/api/v3/${n}/${encodeURIComponent(t)}/unflag`})());if(n.cache)if("message"===e){const e=await ma(r);Vs(e)}else Vs("post"===e?Rc(r,"communityUsers"):r);return ct(`${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=We,e.filterByCommunityMembership=Qe,e.filterByFeedType=Ke,e.filterByPostDataTypes=Je,e.filterByPropEquality=Ve,e.filterByPropInclusion=(e,t,n)=>void 0!==n?e.filter((e=>n.includes(e[t]))):e,e.getChannelMarkers=ia,e.getChannelTopic=e=>`${e.path}/#`,e.getCommentTopic=({path:e})=>e,e.getCommunityTopic=({path:t},n=e.SubscriptionLevels.COMMUNITY)=>ft(t,n),e.getMessageMarkers=sa,e.getMessageTopic=e=>e.path,e.getMyFollowersTopic=()=>{const e=ut();return`${pt(e)}/membership/${e._id}/+/+`},e.getMyFollowingsTopic=()=>{const e=ut();return`${pt(e)}/membership/+/${e._id}/+`},e.getNetworkTopic=mt,e.getPostTopic=({path:t},n=e.SubscriptionLevels.POST)=>"comment"===n?`${t}/comment/+`:t,e.getRole=Ic,e.getSmartFeedChannelTopic=yt,e.getSmartFeedMessageTopic=bt,e.getSmartFeedSubChannelTopic=vt,e.getSubChannelMarkers=aa,e.getSubChannelTopic=e=>`${e.path}/#`,e.getUserMarker=la,e.getUserTopic=gt,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:i,primaryKey:s}=il[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(async(e,t,n)=>{const{ws:r}=e;return await new Promise(((e,o)=>{r.emit(t,n,(t=>{try{e(mr(t))}catch(e){o(e)}}))}))})(o,i,{[s]:t}))&&void 0!==n?n:{};return null!==(r=null!=a?a:c)&&void 0!==r&&r},e.isSkip=V,e.mergeInCache=ze,e.onChannelMarkerFetched=e=>{const t=we();return at(t,"channelMarker/onChannelMarkerFetched","local.channelMarker.fetched",(t=>{e(t.userEntityMarkers[0])}))},e.onFeedMarkerFetched=e=>{const t=we();return at(t,"feedMarker/onFeedMarkerFetched","local.feedMarker.fetched",(t=>{e(t.feedMarkers[0])}))},e.onMessageMarkerFetched=e=>{const t=we();return at(t,"messageMarker/onMessageMarkerFetched","local.messageMarker.fetched",(t=>{e(t.contentMarkers[0])}))},e.onSubChannelMarkerFetched=e=>{const t=we();return at(t,"subChannelMarker/onSubChannelMarkerFetched","local.subChannelMarker.fetched",(t=>{e(t.userFeedMarkers[0])}))},e.onSubChannelMarkerUpdated=e=>{const t=we();return at(t,"subChannelMarker/onSubChannelMarkerUpdated","local.subChannelMarker.updated",(t=>{e(t.userFeedMarkers[0])}))},e.onUserMarkerFetched=ua,e.pullFromCache=Le,e.pushToCache=qe,e.queryCache=De,e.queryOptions=oe,e.queryRoles=Ac,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=ie,e.sortByChannelSegment=({channelSegment:e},{channelSegment:t})=>e-t,e.sortByDisplayName=Ge,e.sortByFirstCreated=Xe,e.sortByLastActivity=et,e.sortByLastCreated=Ze,e.sortByName=Ye,e.sortBySegmentNumber=({segmentNumber:e},{segmentNumber:t})=>e-t,e.subscribeTopic=_t,e.toPage=G,e.toPageRaw=Y,e.toToken=J,e.upsertInCache=$e,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}({});
|