@amityco/ts-sdk 0.0.1-ce7eebc.0 → 0.0.1-ce96c83.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/cache/api/tests/enableCache.test.d.ts +2 -0
  2. package/dist/cache/api/tests/enableCache.test.d.ts.map +1 -0
  3. package/dist/channel/events/tests/onChannelCreated.test.d.ts +2 -0
  4. package/dist/channel/events/tests/onChannelCreated.test.d.ts.map +1 -0
  5. package/dist/channel/events/tests/onChannelJoined.test.d.ts +2 -0
  6. package/dist/channel/events/tests/onChannelJoined.test.d.ts.map +1 -0
  7. package/dist/channel/events/tests/onChannelMemberAdded.test.d.ts +2 -0
  8. package/dist/channel/events/tests/onChannelMemberAdded.test.d.ts.map +1 -0
  9. package/dist/channel/events/tests/onChannelMemberRemoved.test.d.ts +2 -0
  10. package/dist/channel/events/tests/onChannelMemberRemoved.test.d.ts.map +1 -0
  11. package/dist/channel/events/tests/onChannelUpdated.test.d.ts +2 -0
  12. package/dist/channel/events/tests/onChannelUpdated.test.d.ts.map +1 -0
  13. package/dist/client/api/tests/createClient.test.d.ts +2 -0
  14. package/dist/client/api/tests/createClient.test.d.ts.map +1 -0
  15. package/dist/community/api/queryCommunities.d.ts.map +1 -1
  16. package/dist/community/api/test/addCommunityMember.test.d.ts +2 -0
  17. package/dist/community/api/test/addCommunityMember.test.d.ts.map +1 -0
  18. package/dist/community/api/test/addCommunityMemberRole.test.d.ts +2 -0
  19. package/dist/community/api/test/addCommunityMemberRole.test.d.ts.map +1 -0
  20. package/dist/community/api/test/createCommunity.test.d.ts +2 -0
  21. package/dist/community/api/test/createCommunity.test.d.ts.map +1 -0
  22. package/dist/community/api/test/deleteCommunity.test.d.ts +2 -0
  23. package/dist/community/api/test/deleteCommunity.test.d.ts.map +1 -0
  24. package/dist/community/api/test/getCommunities.test.d.ts +2 -0
  25. package/dist/community/api/test/getCommunities.test.d.ts.map +1 -0
  26. package/dist/community/api/test/getCommunity.test.d.ts +2 -0
  27. package/dist/community/api/test/getCommunity.test.d.ts.map +1 -0
  28. package/dist/community/api/test/getRecommendedCommunities.test.d.ts +2 -0
  29. package/dist/community/api/test/getRecommendedCommunities.test.d.ts.map +1 -0
  30. package/dist/community/api/test/getTopTrendingCommunities.test.d.ts +2 -0
  31. package/dist/community/api/test/getTopTrendingCommunities.test.d.ts.map +1 -0
  32. package/dist/community/api/test/joinCommunity.test.d.ts +2 -0
  33. package/dist/community/api/test/joinCommunity.test.d.ts.map +1 -0
  34. package/dist/community/api/test/leaveCommunity.test.d.ts +2 -0
  35. package/dist/community/api/test/leaveCommunity.test.d.ts.map +1 -0
  36. package/dist/community/api/test/queryCommunity.test.d.ts +2 -0
  37. package/dist/community/api/test/queryCommunity.test.d.ts.map +1 -0
  38. package/dist/community/api/test/removeCommunityMemberRole.test.d.ts +2 -0
  39. package/dist/community/api/test/removeCommunityMemberRole.test.d.ts.map +1 -0
  40. package/dist/community/api/test/removeCommunityMembers.test.d.ts +2 -0
  41. package/dist/community/api/test/removeCommunityMembers.test.d.ts.map +1 -0
  42. package/dist/community/api/test/updateCommunity.test.d.ts +2 -0
  43. package/dist/community/api/test/updateCommunity.test.d.ts.map +1 -0
  44. package/dist/community/events/test/onCommunityCreated.test.d.ts +2 -0
  45. package/dist/community/events/test/onCommunityCreated.test.d.ts.map +1 -0
  46. package/dist/community/events/test/onCommunityDeleted.test.d.ts +2 -0
  47. package/dist/community/events/test/onCommunityDeleted.test.d.ts.map +1 -0
  48. package/dist/community/events/test/onCommunityJoined.test.d.ts +2 -0
  49. package/dist/community/events/test/onCommunityJoined.test.d.ts.map +1 -0
  50. package/dist/community/events/test/onCommunityLeft.test.d.ts +2 -0
  51. package/dist/community/events/test/onCommunityLeft.test.d.ts.map +1 -0
  52. package/dist/community/events/test/onCommunityUpdated.test.d.ts +2 -0
  53. package/dist/community/events/test/onCommunityUpdated.test.d.ts.map +1 -0
  54. package/dist/community/events/test/onCommunityUserAdded.test.d.ts +2 -0
  55. package/dist/community/events/test/onCommunityUserAdded.test.d.ts.map +1 -0
  56. package/dist/community/events/test/onCommunityUserBanned.test.d.ts +2 -0
  57. package/dist/community/events/test/onCommunityUserBanned.test.d.ts.map +1 -0
  58. package/dist/community/events/test/onCommunityUserRemoved.test.d.ts +2 -0
  59. package/dist/community/events/test/onCommunityUserRemoved.test.d.ts.map +1 -0
  60. package/dist/community/events/test/onCommunityUserUnbaned.test.d.ts +2 -0
  61. package/dist/community/events/test/onCommunityUserUnbaned.test.d.ts.map +1 -0
  62. package/dist/community/events/test/utils.test.d.ts +2 -0
  63. package/dist/community/events/test/utils.test.d.ts.map +1 -0
  64. package/dist/index.cjs.js +6 -3
  65. package/dist/index.esm.js +6 -3
  66. package/dist/index.umd.js +1 -1
  67. package/dist/post/events/tests/onPostFlagged.test.d.ts +2 -0
  68. package/dist/post/events/tests/onPostFlagged.test.d.ts.map +1 -0
  69. package/dist/post/events/tests/onPostReactionAdded.test.d.ts +2 -0
  70. package/dist/post/events/tests/onPostReactionAdded.test.d.ts.map +1 -0
  71. package/dist/post/events/tests/onPostReactionRemoved.test.d.ts +2 -0
  72. package/dist/post/events/tests/onPostReactionRemoved.test.d.ts.map +1 -0
  73. package/dist/post/events/tests/onPostUnflagged.test.d.ts +2 -0
  74. package/dist/post/events/tests/onPostUnflagged.test.d.ts.map +1 -0
  75. package/dist/post/events/tests/onPostUpdated.test.d.ts +2 -0
  76. package/dist/post/events/tests/onPostUpdated.test.d.ts.map +1 -0
  77. package/dist/post/observers/livePosts.d.ts.map +1 -1
  78. package/dist/utils/tests/dummy/community.d.ts +2 -0
  79. package/dist/utils/tests/dummy/community.d.ts.map +1 -1
  80. package/package.json +1 -1
  81. package/src/cache/api/tests/enableCache.test.ts +15 -0
  82. package/src/channel/events/tests/onChannelCreated.test.ts +60 -0
  83. package/src/channel/events/tests/onChannelJoined.test.ts +60 -0
  84. package/src/channel/events/tests/onChannelMemberAdded.test.ts +59 -0
  85. package/src/channel/events/tests/onChannelMemberRemoved.test.ts +59 -0
  86. package/src/channel/events/tests/onChannelUpdated.test.ts +58 -0
  87. package/src/client/api/createClient.ts +1 -1
  88. package/src/client/api/tests/createClient.test.ts +40 -0
  89. package/src/community/api/queryCommunities.ts +3 -2
  90. package/src/community/api/test/addCommunityMember.test.ts +71 -0
  91. package/src/community/api/test/addCommunityMemberRole.test.ts +67 -0
  92. package/src/community/api/test/createCommunity.test.ts +61 -0
  93. package/src/community/api/test/deleteCommunity.test.ts +74 -0
  94. package/src/community/api/test/getCommunities.test.ts +73 -0
  95. package/src/community/api/test/getCommunity.test.ts +69 -0
  96. package/src/community/api/test/getRecommendedCommunities.test.ts +102 -0
  97. package/src/community/api/test/getTopTrendingCommunities.test.ts +102 -0
  98. package/src/community/api/test/joinCommunity.test.ts +70 -0
  99. package/src/community/api/test/leaveCommunity.test.ts +78 -0
  100. package/src/community/api/test/queryCommunity.test.ts +108 -0
  101. package/src/community/api/test/removeCommunityMemberRole.test.ts +67 -0
  102. package/src/community/api/test/removeCommunityMembers.test.ts +75 -0
  103. package/src/community/api/test/updateCommunity.test.ts +65 -0
  104. package/src/community/events/test/onCommunityCreated.test.ts +46 -0
  105. package/src/community/events/test/onCommunityDeleted.test.ts +35 -0
  106. package/src/community/events/test/onCommunityJoined.test.ts +50 -0
  107. package/src/community/events/test/onCommunityLeft.test.ts +50 -0
  108. package/src/community/events/test/onCommunityUpdated.test.ts +49 -0
  109. package/src/community/events/test/onCommunityUserAdded.test.ts +50 -0
  110. package/src/community/events/test/onCommunityUserBanned.test.ts +50 -0
  111. package/src/community/events/test/onCommunityUserRemoved.test.ts +50 -0
  112. package/src/community/events/test/onCommunityUserUnbaned.test.ts +50 -0
  113. package/src/community/events/test/utils.test.ts +158 -0
  114. package/src/post/events/tests/onPostFlagged.test.ts +33 -0
  115. package/src/post/events/tests/onPostReactionAdded.test.ts +40 -0
  116. package/src/post/events/tests/onPostReactionRemoved.test.ts +40 -0
  117. package/src/post/events/tests/onPostUnflagged.test.ts +33 -0
  118. package/src/post/events/tests/onPostUpdated.test.ts +33 -0
  119. package/src/post/observers/livePosts.ts +3 -0
  120. package/src/post/observers/tests/livePosts.test.ts +24 -0
  121. package/src/utils/tests/dummy/community.ts +17 -1
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,f=n?o-1:0,h=n?-1:1,d=e[t+f];for(f+=h,i=d&(1<<-u)-1,d>>=-u,u+=a;u>0;i=256*i+e[t+f],f+=h,u-=8);for(s=i&(1<<-u)-1,i>>=-u,u+=r;u>0;s=256*s+e[t+f],f+=h,u-=8);if(0===i)i=1-l;else{if(i===c)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,r),i-=l}return(d?-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,f=u>>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,d=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+f>=1?h/c:h*Math.pow(2,1-f))*c>=2&&(s++,c/=2),s+f>=u?(a=0,s=u):s+f>=1?(a=(t*c-1)*Math.pow(2,o),s+=f):(a=t*Math.pow(2,f-1)*Math.pow(2,o),s=0));o>=8;e[n+d]=255&a,d+=p,a/=256,o-=8);for(s=s<<o|a,l+=o;l>0;e[n+d]=255&s,d+=p,s/=256,l-=8);e[n+d-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 f=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=f(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,f=Math.max(Math.ceil(r/o.bucketSize),2),h=0;h<f;++h)t.push(new Array(o.bucketSize));var d=Math.ceil(e/o.bucketSize),p=Math.floor(f/2)-Math.floor(d/2),g=p,m=0;if(this.size())for(h=0;h<d;++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=f,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=f(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=f(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=[],f=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,f=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)){f=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)&f-1]=new i.default([{key:l,value:h}])}else if(r instanceof s.default){var d=new i.default,p=new i.default;r.forEach((function(t){0==(n(t.key)&e)?d.pushBack(t):p.pushBack(t)})),d.size()>a.untreeifyThreshold?t[o]=new s.default(d):d.size()&&(t[o]=d),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 d=n(e)&f-1;if(u[d]){var p=u[d].size();if(u[d]instanceof i.default){try{for(var g=o(u[d]),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[d].pushBack({key:e,value:t}),u[d].size()>=a.treeifyThreshold&&(u[d]=new s.default(u[d]))}else u[d].setElement(e,t);var v=u[d].size();l+=v-p}else++l,u[d]=new i.default([{key:e,value:t}]);l>f*a.sigma&&h.call(this,f)}else this.eraseElementByKey(e)},this.getElementByKey=function(e){var t,r,i=n(e)&f-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)&f-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 d=-1;try{for(var p=o(u[c]),g=p.next();!g.done;g=p.next()){var m=g.value;if(++d,m.key===e){u[c].eraseElementByPos(d);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)&f-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<f))return[3,10];for(;e<f&&!u[e];)++e;if(e>=f)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=[],f=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,f=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)){f=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)&f-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 d=new s.default,p=new s.default;r.forEach((function(t){0==(n(t)&e)?d.pushBack(t):p.pushBack(t)})),d.size()&&(t[o]=d),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)&f-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>f*a.sigma&&h.call(this,f)},this.eraseElementByValue=function(e){var t=n(e)&f-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)&f-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<f))return[3,10];for(;e<f&&!u[e];)++e;if(e>=f)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 f=function(e,n){if(e&&void 0!==e.key&&void 0!==e.value)return t(e.key,n)<=0?f(e.rightChild,n):f(e.leftChild,n)||{key:e.key,value:e.value}};this.upperBound=function(e){return f(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 d=function(e,n){if(e&&void 0!==e.key&&void 0!==e.value)return t(e.key,n)>=0?d(e.leftChild,n):d(e.rightChild,n)||{key:e.key,value:e.value}};this.reverseUpperBound=function(e){return d(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},f=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?(f(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)&&f(n)}};var d=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?d(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?d(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=d(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 f=e("./HashSet/HashSet");n.HashSet=f.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"),f=Symbol("lruList"),h=Symbol("cache"),d=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[d]=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[f].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[f].length}rforEach(e,t){t=t||this;for(let n=this[f].tail;null!==n;){const r=n.prev;C(this,e,n,t),n=r}}forEach(e,t){t=t||this;for(let n=this[f].head;null!==n;){const r=n.next;C(this,e,n,t),n=r}}keys(){return this[f].toArray().map((e=>e.key))}values(){return this[f].toArray().map((e=>e.value))}reset(){this[l]&&this[f]&&this[f].length&&this[f].forEach((e=>this[l](e.key,e.value))),this[h]=new Map,this[f]=new r,this[i]=0}dump(){return this[f].map((e=>!y(this,e)&&{k:e.key,v:e.value,e:e.now+(e.maxAge||0)})).toArray().filter((e=>e))}dumpLru(){return this[f]}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 d=new w(e,t,a,r,n);return d.length>this[o]?(this[l]&&this[l](e,t),!1):(this[i]+=d.length,this[f].unshift(d),this[h].set(e,this[f].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[f].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[d]&&(r.value.now=Date.now()),e[f].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[f].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[f].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,f=s.generateCache,h=s.genBufVariableByteInt,d=s.generate4ByteBuffer;let p=j,g=!0;function m(e,t,n){switch(c("generate called"),t.cork&&(t.cork(),a(y,t)),g&&(g=!1,f()),c("generate: packet.cmd: %s",e.cmd),e.cmd){case"connect":return v(e,t);case"connack":return b(e,t,n);case"publish":return w(e,t,n);case"puback":case"pubrec":case"pubrel":case"pubcomp":return C(e,t,n);case"subscribe":return _(e,t,n);case"suback":return k(e,t,n);case"unsubscribe":return S(e,t,n);case"unsuback":return A(e,t,n);case"pingreq":case"pingresp":return E(e,t);case"disconnect":return O(e,t,n);case"auth":return I(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,f=i.clientId||"",h=i.username,d=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 f||n.isBuffer(f))&&(f||a>=4)&&(f||l))m+=n.byteLength(f)+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=M(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=M(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!=d){if(!b)return t.emit("error",new Error("Username is required to use password")),!1;if(!z(d))return t.emit("error",new Error("Invalid password")),!1;m+=q(d)+2}t.write(r.CONNECT_HEADER),x(t,m),B(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!=d?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(),B(t,f),c&&(5===a&&v.write(),P(t,c.topic),B(t,c.payload)),null!=h&&B(t,h),null!=d&&B(t,d),!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 f=null;if(5===s){if(f=M(t,l),!f)return!1;u+=f.length}return t.write(r.CONNACK_HEADER),x(t,u),t.write(a.sessionPresent?r.SESSIONPRESENT_HEADER:i),t.write(n.from([c])),null!=f&&f.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,f=a.topic,h=a.payload||o,d=a.messageId,g=a.properties;let m=0;if("string"==typeof f)m+=n.byteLength(f)+2;else{if(!n.isBuffer(f))return t.emit("error",new Error("Invalid topic")),!1;m+=f.length+2}if(n.isBuffer(h)?m+=h.length:m+=n.byteLength(h),l&&"number"!=typeof d)return t.emit("error",new Error("Invalid messageId")),!1;l&&(m+=2);let y=null;if(5===s){if(y=M(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(f)),t.write(f),l>0&&p(t,d),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 f=s.reasonCode,h=s.properties;let d=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,d),!g)return!1;d+=g.length}return t.write(r.ACKS[a][u][l][0]),x(t,d),p(t,c),5===i&&t.write(n.from([f])),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,f=s.properties;let h=0;if("number"!=typeof l)return t.emit("error",new Error("Invalid messageId")),!1;h+=2;let d=null;if(5===i){if(d=M(t,f),!d)return!1;h+=d.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!==d&&d.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;P(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 f=null;if(5===i){if(f=U(t,l,o,u),!f)return!1;u+=f.length}return t.write(r.SUBACK_HEADER),x(t,u),p(t,a),null!==f&&f.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 f=0;if("number"!=typeof a)return t.emit("error",new Error("Invalid messageId")),!1;if(f+=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;f+=n.byteLength(l[e])+2}let h=null;if(5===i){if(h=M(t,u),!h)return!1;f+=h.length}t.write(r.UNSUBSCRIBE_HEADER[1][c?1:0][0]),x(t,f),p(t,a),null!==h&&h.write();let d=!0;for(let e=0;e<l.length;e++)d=P(t,l[e]);return d}function A(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,f=s.cmd,h=0;let d=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;d+=1}}let g=null;if(5===i){if(g=U(t,u,o,d),!g)return!1;d+=g.length}return t.write(r.ACKS[f][h][c][0]),x(t,d),p(t,a),null!==g&&g.write(),5===i&&t.write(n.from(l)),!0}function E(e,t,n){return t.write(r.EMPTY[e.cmd])}function O(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 I(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===j,set(e){e?(l&&0!==Object.keys(l).length||(g=!0),p=j):(g=!1,p=N)}});const T={};function x(e,t){if(t>r.VARBYTEINT_MAX)return e.emit("error",new Error(`Invalid variable byte integer: ${t}`)),!1;let n=T[t];return n||(n=h(t),t<16384&&(T[t]=n)),c("writeVarByteInt: writing to stream: %o",n),e.write(n)}function P(e,t){const r=n.byteLength(t);return p(e,r),c("writeString: %s",t),e.write(t,"utf8")}function R(e,t,n){P(e,t),P(e,n)}function j(e,t){return c("writeNumberCached: number: %d",t),c("writeNumberCached: %o",l[t]),e.write(l[t])}function N(e,t){const n=u(t);return c("writeNumberGenerated: %o",n),e.write(n)}function F(e,t){const n=d(t);return c("write4ByteNumber: %o",n),e.write(n)}function B(e,t){"string"==typeof t?P(e,t):t?(p(e,t.length),e.write(t)):p(e,0)}function M(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=M(e,t);if(i)for(;r+s.length>i;){const n=o.shift();if(!n||!t[n])return!1;delete t[n],s=M(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]])),B(e,o);break;case"int16":e.write(n.from([r.properties[t]])),p(e,o);break;case"int32":e.write(n.from([r.properties[t]])),F(e,o);break;case"var":e.write(n.from([r.properties[t]])),x(e,o);break;case"string":e.write(n.from([r.properties[t]])),P(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]])),R(e,i.toString(),o.toString())})):(e.write(n.from([r.properties[t]])),R(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 f(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?f(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,f=[],h=!1,d=-1;function p(){h&&u&&(h=!1,u.length?f=u.concat(f):d=-1,f.length&&g())}function g(){if(!h){var e=c(p);h=!0;for(var t=f.length;t;){for(u=f,f=[];++d<t;)u&&u[d].run();d=-1,t=f.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];f.push(new m(e,t)),1!==f.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,f=1,h=26,d=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-f,k=Math.floor,S=String.fromCharCode;function A(e){throw new RangeError(C[e])}function E(e,t){for(var n=e.length,r=[];n--;)r[n]=t(e[n]);return r}function O(e,t){var n=e.split("@"),r="";return n.length>1&&(r=n[0]+"@",e=n[1]),r+E((e=e.replace(w,".")).split("."),t).join(".")}function I(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 T(e){return E(e,(function(e){var t="";return e>65535&&(t+=S((e-=65536)>>>10&1023|55296),e=56320|1023&e),t+=S(e)})).join("")}function x(e){return e-48<10?e-22:e-65<26?e-65:e-97<26?e-97:u}function P(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function R(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+d))}function j(e){var t,n,r,o,i,s,a,c,d,p,v=[],b=e.length,w=0,C=m,_=g;for((n=e.lastIndexOf(y))<0&&(n=0),r=0;r<n;++r)e.charCodeAt(r)>=128&&A("not-basic"),v.push(e.charCodeAt(r));for(o=n>0?n+1:0;o<b;){for(i=w,s=1,a=u;o>=b&&A("invalid-input"),((c=x(e.charCodeAt(o++)))>=u||c>k((l-w)/s))&&A("overflow"),w+=c*s,!(c<(d=a<=_?f:a>=_+h?h:a-_));a+=u)s>k(l/(p=u-d))&&A("overflow"),s*=p;_=R(w-i,t=v.length+1,0==i),k(w/t)>l-C&&A("overflow"),C+=k(w/t),w%=t,v.splice(w++,0,C)}return T(v)}function N(e){var t,n,r,o,i,s,a,c,d,p,v,b,w,C,_,E=[];for(b=(e=I(e)).length,t=m,n=0,i=g,s=0;s<b;++s)(v=e[s])<128&&E.push(S(v));for(r=o=E.length,o&&E.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))&&A("overflow"),n+=(a-t)*w,t=a,s=0;s<b;++s)if((v=e[s])<t&&++n>l&&A("overflow"),v==t){for(c=n,d=u;!(c<(p=d<=i?f:d>=i+h?h:d-i));d+=u)_=c-p,C=u-p,E.push(S(P(p+_%C,0))),c=k(_/C);E.push(S(P(c,0))),i=R(n,w,r==o),n=0,++r}++n,++t}return E.join("")}function F(e){return O(e,(function(e){return v.test(e)?j(e.slice(4).toLowerCase()):e}))}function B(e){return O(e,(function(e){return b.test(e)?"xn--"+N(e):e}))}if(a={version:"1.4.1",ucs2:{decode:I,encode:T},decode:j,encode:N,toASCII:B,toUnicode:F},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!==we?we:"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 f,h,d,p,g=e[u].replace(a,"%20"),m=g.indexOf(n);m>=0?(f=g.substr(0,m),h=g.substr(m+1)):(f=g,h=""),d=decodeURIComponent(f),p=decodeURIComponent(h),r(s,d)?o(s[d])?s[d].push(p):s[d]=[s[d],p]:s[d]=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(f,this)}function f(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=I,I.ReadableState=O,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 f,h=e("util");f=h&&h.debuglog?h.debuglog("stream"):function(){};var d,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")(I,s);var S=y.errorOrDestroy,A=["error","close","destroy","pause","resume"];function E(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n)}function O(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&&(d||(d=e("string_decoder/").StringDecoder),this.decoder=new d(t.encoding),this.encoding=t.encoding)}function I(t){if(o=o||e("./_stream_duplex"),!(this instanceof I))return new I(t);var n=this instanceof o;this._readableState=new O(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 T(e,t,n,r,o){f("readableAddChunk",t);var i,s=e._readableState;if(null===t)s.reading=!1,F(e,s);else if(o||(i=P(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&&B(e)),U(e,t)}function P(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(I.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),I.prototype.destroy=y.destroy,I.prototype._undestroy=y.undestroy,I.prototype._destroy=function(e,t){t(e)},I.prototype.push=function(e,t){var n,r=this._readableState;return r.objectMode?n=!0:"string"==typeof e&&((t=t||r.defaultEncoding)!==r.encoding&&(e=a.from(e,t),t=""),n=!0),T(this,e,t,!1,n)},I.prototype.unshift=function(e){return T(this,e,null,!0,!1)},I.prototype.isPaused=function(){return!1===this._readableState.flowing},I.prototype.setEncoding=function(t){d||(d=e("string_decoder/").StringDecoder);var n=new d(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 R=1073741824;function j(e){return e>=R?e=R:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function N(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=j(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function F(e,t){if(f("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?B(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,M(e)))}}function B(e){var t=e._readableState;f("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(f("emitReadable",t.flowing),t.emittedReadable=!0,n.nextTick(M,e))}function M(e){var t=e._readableState;f("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(f("maybeReadMore read 0"),e.read(0),n===t.length)break}t.readingMore=!1}function L(e){return function(){var t=e._readableState;f("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){f("readable nexttick read 0"),e.read(0)}function $(e,t){t.resumeScheduled||(t.resumeScheduled=!0,n.nextTick(H,e,t))}function H(e,t){f("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(f("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;f("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,n.nextTick(Q,t,e))}function Q(e,t){if(f("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}I.prototype.read=function(e){f("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 f("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?K(this):B(this),null;if(0===(e=N(e,t))&&t.ended)return 0===t.length&&K(this),null;var r,o=t.needReadable;return f("need readable",o),(0===t.length||t.length-e<t.highWaterMark)&&f("length less than watermark",o=!0),t.ended||t.reading?f("reading or ended",o=!1):o&&(f("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=N(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},I.prototype._read=function(e){S(this,new _("_read()"))},I.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,f("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){f("onunpipe"),e===r&&t&&!1===t.hasUnpiped&&(t.hasUnpiped=!0,h())}function c(){f("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(){f("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",d),u=!0,!o.awaitDrain||e._writableState&&!e._writableState.needDrain||l()}function d(t){f("ondata");var n=e.write(t);f("dest.write",n),!1===n&&((1===o.pipesCount&&o.pipes===e||o.pipesCount>1&&-1!==J(o.pipes,e))&&!u&&(f("false write response, pause",o.awaitDrain),o.awaitDrain++),r.pause())}function p(t){f("onerror",t),y(),e.removeListener("error",p),0===i(e,"error")&&S(e,t)}function g(){e.removeListener("finish",m),y()}function m(){f("onfinish"),e.removeListener("close",g),y()}function y(){f("unpipe"),r.unpipe(e)}return r.on("data",d),E(e,"error",p),e.once("close",g),e.once("finish",m),e.emit("pipe",r),o.flowing||(f("pipe resume"),r.resume()),e},I.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},I.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,f("on readable",o.length,o.reading),o.length?B(this):o.reading||n.nextTick(z,this))),r},I.prototype.addListener=I.prototype.on,I.prototype.removeListener=function(e,t){var r=s.prototype.removeListener.call(this,e,t);return"readable"===e&&n.nextTick(q,this),r},I.prototype.removeAllListeners=function(e){var t=s.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||n.nextTick(q,this),t},I.prototype.resume=function(){var e=this._readableState;return e.flowing||(f("resume"),e.flowing=!e.readableListening,$(this,e)),e.paused=!1,this},I.prototype.pause=function(){return f("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(f("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},I.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var o in e.on("end",(function(){if(f("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){f("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<A.length;i++)e.on(A[i],this.emit.bind(this,A[i]));return this._read=function(t){f("wrapped _read",t),r&&(r=!1,e.resume())},this},"function"==typeof Symbol&&(I.prototype[Symbol.asyncIterator]=function(){return void 0===p&&(p=e("./internal/streams/async_iterator")),p(this)}),Object.defineProperty(I.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(I.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(I.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),I._fromList=W,Object.defineProperty(I.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(I.from=function(t,n){return void 0===g&&(g=e("./internal/streams/from")),g(I,t,n)})}).call(this)}).call(this,e("_process"),void 0!==we?we:"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",f)}function f(){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=O,O.WritableState=E;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 f(e){return c.isBuffer(e)||e instanceof l}var h,d=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=d.errorOrDestroy;function A(){}function E(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){F(n,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==t.emitClose,this.autoDestroy=!!t.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new o(this)}function O(t){var n=this instanceof(i=i||e("./_stream_duplex"));if(!n&&!h.call(O,this))return new O(t);this._writableState=new E(t,this,n),this.writable=!0,t&&("function"==typeof t.write&&(this._write=t.write),"function"==typeof t.writev&&(this._writev=t.writev),"function"==typeof t.destroy&&(this._destroy=t.destroy),"function"==typeof t.final&&(this._final=t.final)),a.call(this)}function I(e,t){var r=new _;S(e,r),n.nextTick(t,r)}function T(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 P(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 R(e,t,!1,a,r,o,i);return c}function R(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 j(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 N(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function F(e,t){var r=e._writableState,o=r.sync,i=r.writecb;if("function"!=typeof i)throw new v;if(N(r),t)j(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(B,e,r,s,i):B(e,r,s,i)}}function B(e,t,n,r){n||M(e,t),t.pendingcb--,r(),z(e,t)}function M(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,R(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,f=n.callback;if(R(e,t,!1,t.objectMode?1:l.length,l,u,f),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")(O,a),E.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(E.prototype,"buffer",{get: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(O,Symbol.hasInstance,{value:function(e){return!!h.call(this,e)||this===O&&e&&e._writableState instanceof E}})):h=function(e){return e instanceof this},O.prototype.pipe=function(){S(this,new b)},O.prototype.write=function(e,t,n){var r=this._writableState,o=!1,i=!r.objectMode&&f(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=A),r.ending?I(this,n):(i||T(this,r,e,n))&&(r.pendingcb++,o=P(this,r,i,e,t,n)),o},O.prototype.cork=function(){this._writableState.corked++},O.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.bufferProcessing||!e.bufferedRequest||U(this,e))},O.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(O.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(O.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),O.prototype._write=function(e,t,n){n(new y("_write()"))},O.prototype._writev=null,O.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(O.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(O.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),O.prototype.destroy=d.destroy,O.prototype._undestroy=d.undestroy,O.prototype._destroy=function(e,t){t(e)}}).call(this)}).call(this,e("_process"),void 0!==we?we:"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"),f=Symbol("handlePromise"),h=Symbol("stream");function d(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(d(n,!1)))}}function g(e){n.nextTick(p,e)}function m(e,t){return function(n,r){e.then((function(){t[l]?n(d(void 0,!0)):t[f](n,r)}),r)}}var y=Object.getPrototypeOf((function(){})),v=Object.setPrototypeOf((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(d(void 0,!0));if(this[h].destroyed)return new Promise((function(t,r){n.nextTick((function(){e[c]?r(e[c]):t(d(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(d(i,!1));r=new Promise(this[f])}return this[u]=r,r}},o(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(d(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,f,{value:function(e,t){var r=n[h].read();r?(n[u]=null,n[s]=null,n[a]=null,e(d(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(d(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,f=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:f,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()},f=e._writableState&&e._writableState.finished,h=function(){l=!1,f=!0,c||n.call(e)},d=e._readableState&&e._readableState.endEmitted,p=function(){c=!1,d=!0,l||n.call(e)},g=function(t){n.call(e,t)},m=function(){var t;return c&&!d?(e._readableState&&e._readableState.ended||(t=new r),n.call(e,t)):l&&!f?(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 f(e){e()}function h(e,t){return e.pipe(t)}function d(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=d(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(f),s||(i.forEach(f),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=f,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 f(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 d(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=d,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),f=["%","/","?",";","#"].concat(u),h=["/","?","#"],d=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 A="//"===C.substr(0,2);!A||k&&y[k]||(C=C.substr(2),this.slashes=!0)}if(!y[k]&&(A||k&&!v[k])){for(var E,O,I=-1,T=0;T<h.length;T++)-1!==(x=C.indexOf(h[T]))&&(-1===I||x<I)&&(I=x);for(-1!==(O=-1===I?C.lastIndexOf("@"):C.lastIndexOf("@",I))&&(E=C.slice(0,O),C=C.slice(O+1),this.auth=decodeURIComponent(E)),I=-1,T=0;T<f.length;T++){var x;-1!==(x=C.indexOf(f[T]))&&(-1===I||x<I)&&(I=x)}-1===I&&(I=C.length),this.host=C.slice(0,I),C=C.slice(I),this.parseHost(),this.hostname=this.hostname||"";var P="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!P)for(var R=this.hostname.split(/\./),j=(T=0,R.length);T<j;T++){var N=R[T];if(N&&!N.match(p)){for(var F="",B=0,M=N.length;B<M;B++)N.charCodeAt(B)>127?F+="x":F+=N[B];if(!F.match(p)){var U=R.slice(0,T),D=R.slice(T+1),L=N.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>d?this.hostname="":this.hostname=this.hostname.toLowerCase(),P||(this.hostname=r.toASCII(this.hostname));var q=this.port?":"+this.port:"",z=this.hostname||"";this.host=z+q,this.href+=this.host,P&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==C[0]&&(C="/"+C))}if(!m[S])for(T=0,j=u.length;T<j;T++){var $=u[T];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 f=Object.keys(e),h=0;h<f.length;h++){var d=f[h];n[d]=e[d]}return n.href=n.format(),n}if(n.protocol=e.protocol,e.host||y[e.protocol])n.pathname=e.pathname;else{for(var p=(e.pathname||"").split("/");p.length&&!(e.host=p.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==p[0]&&p.unshift(""),p.length<2&&p.unshift(""),n.pathname=p.join("/")}if(n.search=e.search,n.query=e.query,n.host=e.host||"",n.auth=e.auth,n.hostname=e.hostname||e.host,n.port=e.port,n.pathname||n.search){var g=n.pathname||"",m=n.search||"";n.path=g+m}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var b=n.pathname&&"/"===n.pathname.charAt(0),w=e.host||e.pathname&&"/"===e.pathname.charAt(0),C=w||b||n.host&&e.pathname,_=C,k=n.pathname&&n.pathname.split("/")||[],S=(p=e.pathname&&e.pathname.split("/")||[],n.protocol&&!v[n.protocol]);if(S&&(n.hostname="",n.port=null,n.host&&(""===k[0]?k[0]=n.host:k.unshift(n.host)),n.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===p[0]?p[0]=e.host:p.unshift(e.host)),e.host=null),C=C&&(""===p[0]||""===k[0])),w)n.host=e.host||""===e.host?e.host:n.host,n.hostname=e.hostname||""===e.hostname?e.hostname:n.hostname,n.search=e.search,n.query=e.query,k=p;else if(p.length)k||(k=[]),k.pop(),k=k.concat(p),n.search=e.search,n.query=e.query;else if(!o.isNullOrUndefined(e.search))return S&&(n.hostname=n.host=k.shift(),(T=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=T.shift(),n.host=n.hostname=T.shift())),n.search=e.search,n.query=e.query,o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n;if(!k.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var A=k.slice(-1)[0],E=(n.host||e.host||k.length>1)&&("."===A||".."===A)||""===A,O=0,I=k.length;I>=0;I--)"."===(A=k[I])?k.splice(I,1):".."===A?(k.splice(I,1),O++):O&&(k.splice(I,1),O--);if(!C&&!_)for(;O--;O)k.unshift("..");!C||""===k[0]||k[0]&&"/"===k[0].charAt(0)||k.unshift(""),E&&"/"!==k.join("/").substr(-1)&&k.push("");var T,x=""===k[0]||k[0]&&"/"===k[0].charAt(0);return S&&(n.hostname=n.host=x?"":k.length?k.shift():"",(T=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=T.shift(),n.host=n.hostname=T.shift())),(C=C||n.host&&k.length)&&!x&&k.unshift(""),k.length?n.pathname=k.join("/"):(n.pathname=null,n.path=null),o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},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!==we?we:"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)}(Sl);var Al=Ce(Sl.exports);var El;!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"}(El||(El={}));const Ol=e=>{let t,n=0,r=!0;return{connect:async function(o){return t&&(t.removeAllListeners(),t.end(!0)),t=Al.connect(e,function(e){return Object.assign({clean:!1,clientId:`mqttjs_ + ${Math.random().toString(16).substr(2,8)}`,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 de(t.message,8e5,"error"):new ge(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)}}},Il=async()=>{const e=ve(),{data:t}=await e.http.get("/api/v3/network-settings/feed-setting");return Object.fromEntries(t.feedSettings.map((({feedType:e,contentSettings:t})=>[e,t])))},Tl=async()=>{const e=ve();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.accessToken=void 0,!e.ws.connected},xl=()=>`ascWebSdk#${Math.random().toString(16)}`,Pl=()=>{const e=(()=>{var e,t;return(null===(e=d.versions)||void 0===e?void 0:e.node)?d.versions.node:navigator?`${navigator.product.toLowerCase()}#${null!==(t=navigator.userAgent)&&void 0!==t?t:"unknown_agent"}`:"unknown_model"})();return{version:"11.0.0",kind:"web",model:e}},Rl=(e={},t)=>{Object.entries(e).forEach((([e,n])=>{const r=Y[e];if(!r)return;const o=Q(r);n.forEach((e=>{qe([r,"get",o(e)],e,t)}))}))},jl=(e,t)=>{const n=ve();return et(n,e,e,(e=>{n.cache&&Rl(e),t(e.users[0])}))},Nl=e=>jl("user.deleted",e),Fl=["disconnected","error","connect_error","reconnect_error","reconnect_failed"],Bl=e=>{const t=ve(),n=Fl.map((n=>et(t,`client/onConnectionError(${n})`,n,(t=>{const r=(null==t?void 0:t.code)?new de(t.message,t.code,"fatal"):new me(n);e(r)}))));return()=>{n.forEach((e=>e()))}},Ml=e=>Bl((({code:t})=>{400312===t&&e()})),Ul=(e,t)=>{const{log:n,cache:r}=ve(),o=[e,X,t];if(!r)return;n("cache/api/isInTombstone",o);const i=Ue(o),{lifeSpan:s}=ue("cache_then_server",18e4);if(i&&ce(i.data,s))throw new pe("Item not found!",400400,"error")},Dl=(e,t)=>{const{log:n,cache:r}=ve(),o=[e,X,t],i={cachedAt:Date.now()};r&&(n("cache/api/pushToTombstone",{cacheKey:o,data:i}),ze([e,"get",t],!0),De(o,i))},Ll=async(e,t=!1)=>{const n=ve();let r;n.log("user/getUser",e),t||console.log("getUser will be deprecated on 25th November 2022, please use liveUser instead."),Ul("user",e);try{r=(await n.http.get(`/api/v3/users/${encodeURIComponent(e)}`)).data}catch(t){throw re(null==t?void 0:t.code)&&Dl("user",e),t}const o=n.cache&&Date.now();n.cache&&Rl(r,{cachedAt:o});const{users:i}=r;return tt("user.fetched",r),{data:i.find((t=>t.userId===e)),cachedAt:o}};Ll.locally=e=>{const t=ve();return t.log("user/getUser.locally",e),t.cache&&Ue(["user","get",e])};const ql=async e=>{const t=ve();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&&Rl(r,{cachedAt:o}),tt("user.fetched",r),{data:r.users,cachedAt:o}};function zl(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}ql.locally=e=>{var t;const n=ve();if(n.log("user/getUsers.locally",e),!n.cache)return;const r=e.map((e=>Ue(["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 $l=async(e={})=>{const t=ve();t.log("user/queryUsers",e);const{page:n={limit:10},displayName:r,filter:o="all",sortBy:i="displayName"}=e,s=zl(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:H(n,"skiplimit")}})}),{paging:c}=a,l=zl(a,["paging"]),{users:u}=l,f=t.cache&&Date.now();if(t.cache){Rl(l,{cachedAt:f});const t=["user","query",Object.assign(Object.assign({},e),{options:Object.assign({},n)})];De(t,{users:u.map(Q("user")),paging:c})}tt("user.fetched",a);return{data:u,cachedAt:f,prevPage:V(c.previous),nextPage:V(c.next)}};$l.locally=(e={})=>{var t,n,r;const o=ve();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=Ue(s))&&void 0!==t?t:{},l=null!==(n=null==a?void 0:a.users.map((e=>Ue(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[],u=V(null==a?void 0:a.paging.previous),f=V(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:f}:void 0};const Hl=e=>jl("user.fetched",e),Vl=e=>jl("user.updated",e),Wl=e=>jl("user.flagged",e),Kl=e=>jl("user.unflagged",e),Ql=e=>jl("user.flagCleared",e),Jl="cache_then_server",Gl="For using Live Collection feature you need to enable Cache!",Yl="For using Live Object feature you need to enable Cache!",Xl=async e=>{const t=ve();t.log("file/getFile",e);const{data:n}=await t.http.get(`/api/v3/files/${e}`),r=t.cache&&Date.now();return t.cache&&Rl({files:[n]},{cachedAt:r}),{data:n,cachedAt:r}};Xl.locally=e=>{const t=ve();if(t.log("file/getFile.locally",e),!t.cache)return;const n=Ue(["file","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Zl=async e=>{const t=ve();t.log("role/queryRoles",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,sortBy:i}=n,s=zl(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:H(r,"skiplimit")}})}),{paging:c}=a,l=zl(a,["paging"]),{roles:u}=l,f=t.cache&&Date.now();t.cache&&Rl(l,{cachedAt:f});const h=V(c.next);return{data:u,cachedAt:f,prevPage:V(c.previous),nextPage:h}};Zl.locally=e=>{ve().log("role/queryRoles.locally",e)};const eu=async e=>{const t=ve();t.log("role/getRole",e);const{data:n}=await t.http.get(`/api/v3/roles/${e}`),r=t.cache&&Date.now();return t.cache&&Rl({roles:n},{cachedAt:r}),{data:n.find((t=>t.roleId===e)),cachedAt:r}};eu.locally=e=>{const t=ve();if(t.log("role/getRole.locally",e),!t.cache)return;const n=Ue(["role","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const tu=(e,t)=>{"message"===e?tt("v3.message.didUpdate",{messages:[t]}):"post"===e?tt("post.updated",{posts:[t]}):"comment"===e&&tt("comment.updated",{comments:[t]})},nu=async(e,t=!1)=>{const n=ve();let r;n.log("message/getMessage",e),t||console.log("getMessage will be deprecated on 15th November 2022, please use liveMessage instead."),Ul("message",e);try{r=(await n.http.get(`/api/v3/messages/${encodeURIComponent(e)}`)).data}catch(t){throw re(null==t?void 0:t.code)&&Dl("message",e),t}const o=n.cache&&Date.now();n.cache&&Rl(r,{cachedAt:o});const{messages:i}=r;return tt("v3.message.didFetch",{messages:i}),{data:i.find((t=>t.messageId===e)),cachedAt:o}};nu.locally=e=>{const t=ve();if(t.log("message/getMessage.locally",e),!t.cache)return;const n=Ue(["message","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const ru=async e=>{const t=ve();t.log("message/getMessages",e);const{data:n}=await t.http.get("/api/v3/messages/list",{params:{messageIds:e}}),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{messages:o}=n;return tt("v3.message.didFetch",{messages:o}),{data:o,cachedAt:r}};ru.locally=e=>{var t;const n=ve();if(n.log("message/getMessages.locally",e),!n.cache)return;const r=e.map((e=>Ue(["message","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 ou=async e=>{const t=ve();t.log("message/queryMessages",e);const{page:n={limit:10}}=e,r=zl(e,["page"]),{data:o}=await t.http.get("/api/v3/messages",{params:Object.assign(Object.assign({},r),{options:{token:H(n,"afterbefore")}})}),{paging:i}=o,s=zl(o,["paging"]),{messages:a}=s,c=t.cache&&Date.now();if(t.cache){Rl(s,{cachedAt:c});const e=["message","query",Object.assign(Object.assign({},r),{options:Object.assign({},n)})];De(e,{messages:a.map(Q("message")),paging:i})}tt("v3.message.didFetch",{messages:a});const l=V(i.next);return{data:a,cachedAt:c,prevPage:V(i.previous),nextPage:l}};ou.locally=e=>{var t,n;const r=ve();if(r.log("message/queryMessages.locally",e),!r.cache)return;const{page:o={limit:10}}=e,i=zl(e,["page"]),s=["message","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Ue(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.messages.length))return;const l=a.messages.map((e=>Ue(["message","get",e]))).filter(Boolean).map((({data:e})=>e)),u=V(null==a?void 0:a.paging.previous),f=V(null==a?void 0:a.paging.next);return l.length===(null===(n=null==a?void 0:a.messages)||void 0===n?void 0:n.length)?{data:l,cachedAt:c,prevPage:u,nextPage:f}:void 0};var iu={},su={},au={};Object.defineProperty(au,"__esModule",{value:!0}),au.bytesToString=au.stringToBytes=au.NIL=au.X500=au.OID=au.URL=au.DNS=au.hexToByte=au.byteToHex=void 0;let cu=[],lu={};for(var uu=0;uu<256;uu++)cu[uu]=(uu+256).toString(16).substr(1),lu[cu[uu]]=uu;au.byteToHex=cu,au.hexToByte=lu,au.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",au.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",au.OID="6ba7b812-9dad-11d1-80b4-00c04fd430c8",au.X500="6ba7b814-9dad-11d1-80b4-00c04fd430c8",au.NIL="00000000-0000-0000-0000-000000000000";au.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};au.bytesToString=e=>{const t=new Uint8Array(e,0,e.byteLength);return String.fromCharCode.apply(null,Array.from(t))},Object.defineProperty(su,"__esModule",{value:!0}),su.parse=void 0;const fu=au;su.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++]=fu.hexToByte[e]),"")));o<16;)t[r+o++]=0;return t};var hu={};Object.defineProperty(hu,"__esModule",{value:!0}),hu.unparse=void 0;const du=au;hu.unparse=(e,t)=>{let n=t||0,r=du.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 pu={},gu={};Object.defineProperty(gu,"__esModule",{value:!0});gu.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 mu=we&&we.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(pu,"__esModule",{value:!0}),pu.validate=void 0;const yu=mu(gu);pu.validate=e=>"string"==typeof e&&yu.default.test(e);var vu={};Object.defineProperty(vu,"__esModule",{value:!0}),vu.version=void 0;const bu=pu;vu.version=e=>{if(!bu.validate(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)};var wu={},Cu={};Object.defineProperty(Cu,"__esModule",{value:!0}),Cu.stringify=void 0;const _u=pu,ku=[];for(let e=0;e<256;++e)ku.push((e+256).toString(16).substr(1));Cu.stringify=(e,t=0)=>{const n=(ku[e[t+0]]+ku[e[t+1]]+ku[e[t+2]]+ku[e[t+3]]+"-"+ku[e[t+4]]+ku[e[t+5]]+"-"+ku[e[t+6]]+ku[e[t+7]]+"-"+ku[e[t+8]]+ku[e[t+9]]+"-"+ku[e[t+10]]+ku[e[t+11]]+ku[e[t+12]]+ku[e[t+13]]+ku[e[t+14]]+ku[e[t+15]]).toLowerCase();if(!_u.validate(n))throw TypeError("Stringified UUID is invalid");return n};var Su={};Object.defineProperty(Su,"__esModule",{value:!0}),Su.rng=void 0;Su.rng=()=>{let e=new Array(16);for(let t=0;t<16;t++)e[t]=255&256*Math.random()+0;return e},Object.defineProperty(wu,"__esModule",{value:!0}),wu.v1=void 0;const Au=Cu,Eu=Su;let Ou,Iu,Tu=0,xu=0;wu.v1=(e,t,n=0)=>{let r=t&&n||0;const o=t||new Uint8Array(16);let i=e&&e.node?e.node:Ou,s=e&&e.clockseq?e.clockseq:Iu;if(null==i||null==s){const t=e&&e.random?e.random:e&&e.rng?e.rng():Eu.rng();null==i&&(i=Ou=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==s&&(s=Iu=16383&(t[6]<<8|t[7]))}let a=e&&e.msecs?e.msecs:Date.now(),c=e&&e.nsecs?e.nsecs:xu+1;const l=a-Tu+(c-xu)/1e4;if(l<0&&e&&!e.clockseq&&(s=s+1&16383),(l<0||a>Tu)&&e&&!e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Tu=a,xu=c,Iu=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 f=a/4294967296*1e4&268435455;o[r++]=f>>>8&255,o[r++]=255&f,o[r++]=f>>>24&15|16,o[r++]=f>>>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||Au.stringify(o)};var Pu={};Object.defineProperty(Pu,"__esModule",{value:!0}),Pu.v4=void 0;const Ru=hu,ju=Su;Pu.v4=(e,t,n)=>{let r=t&&n||0,o=ju.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||Ru.unparse(o)};var Nu={},Fu={};Object.defineProperty(Fu,"__esModule",{value:!0}),Fu.v35=void 0;const Bu=Cu,Mu=su,Uu=au;Fu.v35=(e,t,n)=>(e,r,o,i=0)=>{if("string"==typeof e&&(e=Uu.stringToBytes(e)),"string"==typeof r&&(r=Mu.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=Uu.stringToBytes(n(Uu.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||Bu.stringify(s)};var Du={};!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(f(l(e),8*e.length)),o=(e,t)=>{let n=l(e);n.length>16&&(n=f(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=f(r.concat(l(t)),512+8*t.length);return u(f(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},f=(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,f=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]),d(v)));a=s,s=i,i=g(o,30),o=r,r=t}r=p(r,l),o=p(o,u),i=p(i,f),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,d=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}(Du);var Lu=we&&we.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Nu,"__esModule",{value:!0}),Nu.v5=void 0;const qu=Fu,zu=Lu(Du);Nu.v5=qu.v35("v5",80,zu.default),Object.defineProperty(iu,"__esModule",{value:!0});const $u=su,Hu=hu,Vu=pu,Wu=vu,Ku=wu,Qu=Pu,Ju=Nu,Gu=au;var Yu=iu.default={parse:$u.parse,unparse:Hu.unparse,validate:Vu.validate,version:Wu.version,v1:Ku.v1,v4:Qu.v4,v5:Ju.v5,NIL:Gu.NIL,DNS:Gu.DNS,URL:Gu.URL,OID:Gu.OID,X500:Gu.X500};const Xu=async e=>{const t=ve();t.log("user/createMessage",e);const{data:n}=await t.http.post("/api/v3/messages",e),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{messages:o}=n;return tt("v3.message.didCreate",{messages:o}),{data:o[0],cachedAt:r}};Xu.optimistically=e=>{var t,n;const r=ve();if(!r.cache)return;const o=Object.assign({messageId:Yu.v4().toString()},e);r.log("user/createMessage.locally",o);const i=Ue(["channel","get",o.channelId]);qe(["channel","get",o.channelId],Object.assign(Object.assign({},null==i?void 0:i.data),{messageCount:(null!==(t=null==i?void 0:i.data.messageCount)&&void 0!==t?t:0)+1}));const s=(new Date).toISOString(),a=Object.assign({userId:r.userId,channelSegment:(null!==(n=null==i?void 0:i.data.messageCount)&&void 0!==n?n:0)+1,createdAt:s,updatedAt:s},o);return De(["message","get",a.messageId],a,{cachedAt:-5}),tt("v3.message.didCreate",{messages:[a]}),{cachedAt:-5,data:a}};const Zu=async(e,t)=>{const n=ve();n.log("user/updateMessage",t);const{data:r}=await n.http.put(`/api/v3/messages/${encodeURIComponent(e)}`,t),o=n.cache&&Date.now();n.cache&&Rl(r,{cachedAt:o});const{messages:i}=r;return tt("v3.message.didUpdate",{messages:i}),{data:i.find((t=>t.messageId===e)),cachedAt:o}};Zu.optimistically=(e,t)=>{const n=ve();if(n.log("user/updateMessage",t),!n.cache)return;const r=Ue(["message","get",e]);if(!r)return;const o=Object.assign(Object.assign(Object.assign({},r.data),t),{updatedAt:(new Date).toISOString()});return qe(["message","get",e],o,{cachedAt:-1}),tt("v3.message.didUpdate",{messages:[o]}),{data:o,cachedAt:-1}};const ef=async e=>{const t=ve();t.log("message/deleteMessage",e),await t.http.delete(`/api/v3/messages/${encodeURIComponent(e)}`);const n=await nu(e);return tt("v3.message.didDelete",{messages:[n.data]}),n.data};ef.optimistically=e=>{ve().log("message/deleteMessage",e);const t=Ue(["message","get",e]);if(!t)return;const n=Object.assign(Object.assign({},t.data),{isDeleted:!0,updatedAt:(new Date).toISOString()});return qe(["message","get",e],n,{cachedAt:-1}),tt("v3.message.didDelete",{messages:[n]}),{data:n,cachedAt:-1}};const tf=async e=>{const t=ve();t.log("post/queryPosts",e);const{page:n={limit:10}}=e,r=zl(e,["page"]),{dataTypes:o,matchingOnlyParentPost:i}=r,{data:s}=await t.http.get("/api/v4/posts",{params:Object.assign(Object.assign({},r),{matchingOnlyParentPost:null!=i?i:!(null==o?void 0:o.length),options:{token:H(n,"afterbeforeraw")}})}),{paging:a}=s,c=zl(s,["paging"]),{posts:l}=c,u=t.cache&&Date.now();if(t.cache){Rl(c,{cachedAt:u});const e=["post","query",Object.assign(Object.assign({},r),{options:Object.assign({},n)})];De(e,{posts:l.map(Q("post")),paging:a})}const f=W(a.next);return{data:l,cachedAt:u,prevPage:W(a.previous),nextPage:f}};tf.locally=e=>{var t,n;const r=ve();if(r.log("post/queryPosts.locally",e),!r.cache)return;const{page:o={limit:10}}=e,i=zl(e,["page"]),s=["post","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Ue(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.posts.length))return;const l=a.posts.map((e=>Ue(["post","get",e]))).filter(Boolean).map((({data:e})=>e)),u=W(null==a?void 0:a.paging.previous),f=W(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:f}:void 0};const nf=async e=>{const t=ve();t.log("post/getPosts",e);const n=e.map((e=>encodeURIComponent(e))),{data:r}=await t.http.get("/api/v3/posts/list",{params:{postIds:n}}),o=t.cache&&Date.now();return t.cache&&Rl(r,{cachedAt:o}),{data:r.posts,cachedAt:o}};nf.locally=e=>{var t;const n=ve();if(n.log("post/getPosts.locally",e),!n.cache)return;const r=e.map((e=>Ue(["post","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 rf=async e=>{const t=ve();let n;t.log("post/getPost",e),Ul("post",e);try{n=(await t.http.get(`/api/v3/posts/${encodeURIComponent(e)}`)).data}catch(t){throw re(null==t?void 0:t.code)&&Dl("post",e),t}const r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{posts:o}=n;return{data:o.find((t=>t.postId===e)),cachedAt:r}};rf.locally=e=>{const t=ve();if(t.log("post/getPost.locally",e),!t.cache)return;const n=Ue(["post","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const of=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},sf=e=>{var{communities:t}=e,n=zl(e,["communities"]);return Object.assign({communities:t.map((e=>{var{needApprovalOnPostCreation:t,onlyAdminCanPost:n}=e,r=zl(e,["needApprovalOnPostCreation","onlyAdminCanPost"]);return Object.assign({postSetting:of({needApprovalOnPostCreation:t,onlyAdminCanPost:n})},r)}))},n)},af=e=>{var{postSetting:t}=e,r=zl(e,["postSetting"]);return Object.assign(Object.assign({},r),t?n[t]:void 0)},cf=async e=>{const t=ve();t.log("channel/queryCommunities",e);const n=null!=e?e:{},{page:r,displayName:o,membership:i}=n,s=zl(n,["page","displayName","membership"]),{data:a}=await t.http.get("/api/v3/communities",{params:Object.assign(Object.assign({},s),{keyword:o,filter:i,options:{token:H(r,"skiplimit")}})}),{paging:c}=a,l=zl(a,["paging"]),u=sf(l),{communities:f}=u,h=t.cache&&Date.now();if(t.cache){Rl(u,{cachedAt:h});const e=["community","query",Object.assign(Object.assign({},s),{options:Object.assign({},r)})];De(e,{communities:f.map(Q("community")),paging:c})}const d=V(c.next);return{data:f,cachedAt:h,prevPage:V(c.previous),nextPage:d}};cf.locally=e=>{ve().log("community/queryCommunities.locally",e)};const lf=async e=>{const t=ve();t.log("community/getCommunities",e);const{data:n}=await t.http.get("/api/v3/communities/list",{params:{communityIds:e}}),r=sf(n),o=t.cache&&Date.now();return t.cache&&Rl(r,{cachedAt:o}),{data:r.communities,cachedAt:o}};lf.locally=e=>{var t;const n=ve();if(n.log("community/getCommunities.locally",e),!n.cache)return;const r=e.map((e=>Ue(["community","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 uf=async e=>{const t=ve();t.log("community/getCommunity",e);const{data:n}=await t.http.get(`/api/v3/communities/${e}`),r=sf(n),o=t.cache&&Date.now();t.cache&&Rl(r,{cachedAt:o});const{communities:i}=r;return{data:i.find((t=>t.communityId===e)),cachedAt:o}};uf.locally=e=>{const t=ve();if(t.log("community/getCommunity.locally",e),!t.cache)return;const n=Ue(["community","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const ff=(e,t="userId",n="user")=>e.map((e=>((e,t="userId",n="user")=>Object.assign({get[n](){var n;if(!ve().cache)return;return(null===(n=Ue(["user","get",e[t]]))||void 0===n?void 0:n.data)||void 0}},e))(e,t,n))),hf=(e,t,n="userId",r="user")=>{const o=e,i=t,s=o[i],a=zl(o,["symbol"==typeof i?i:i+""]),c=ff(s,n,r);return Object.assign(Object.assign({},a),{[t]:c})},df=async e=>{const t=ve();t.log("community/queryCommunityMembers",e);const n=null!=e?e:{},{page:r}=n,o=zl(n,["page"]),{data:i}=await t.http.get(`/api/v3/communities/${o.communityId}/users`,{params:Object.assign(Object.assign({},o),{options:{token:H(r,"skiplimit")}})}),{paging:s}=i,a=zl(i,["paging"]),c=hf(a,"communityUsers"),{communityUsers:l}=c,u=t.cache&&Date.now();if(t.cache){Rl(c,{cachedAt:u});const e=["communityUsers","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];De(e,{communityUsers:l.map((({communityId:e,userId:t})=>Q("communityUsers")({communityId:e,userId:t}))),paging:s})}return{data:l,cachedAt:u,nextPage:V(s.next),prevPage:V(s.previous)}};df.locally=e=>{var t,n;const r=ve();if(r.log("community/queryCommunityMembers",e),!r.cache)return;const o=null!=e?e:{},{page:i}=o,s=zl(o,["page"]),a=["communityUsers","query",Object.assign(Object.assign({},s),{options:Object.assign({},i)})],{data:c,cachedAt:l}=null!==(t=Ue(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.communityUsers.length))return;const u=c.communityUsers.map((e=>Ue(["communityUsers","get",e]))).filter(Boolean).map((({data:e})=>e)),f=V(null==c?void 0:c.paging.previous),h=V(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:f,nextPage:h}:void 0};const pf=async e=>{const t=ve();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=sf(r),{communities:i}=o,s=t.cache&&Date.now();if(t.cache){Rl(o,{cachedAt:s});De(["community","top-trending",{params:{options:{limit:n}}}],{communities:i.map(Q("community"))})}return{data:i,cachedAt:s}};pf.locally=e=>{var t,n;const r=ve();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=Ue(i))&&void 0!==t?t:{};if(!(null==s?void 0:s.communities.length))return;const c=s.communities.map((e=>Ue(["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 gf=async e=>{const t=ve();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=sf(r),{communities:i}=o,s=t.cache&&Date.now();if(t.cache){Rl(o,{cachedAt:s});De(["community","recommended",{params:{options:{limit:n}}}],{communities:i.map(Q("community"))})}return{data:i,cachedAt:s}};gf.locally=e=>{var t,n;const r=ve();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=Ue(i))&&void 0!==t?t:{};if(!(null==s?void 0:s.communities.length))return;const c=s.communities.map((e=>Ue(["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 mf=async e=>{const t=ve();t.log("comment/queryComments",e);const{page:n={limit:10}}=e,r=zl(e,["page"]),o={type:r.sortBy?"pagination":void 0,token:H(n,r.sortBy?"skiplimit":"afterbefore")},{data:i}=await t.http.get("/api/v3/comments",{params:Object.assign(Object.assign({},r),{options:o})}),{paging:s}=i,a=zl(i,["paging"]),{comments:c}=a,l=t.cache&&Date.now();if(t.cache){Rl(a,{cachedAt:l});const e=["comment","query",Object.assign(Object.assign({},r),{options:Object.assign({},n)})];De(e,{comments:c.map(Q("comment")),paging:s})}const u=V(s.next);return{data:c,cachedAt:l,prevPage:V(s.previous),nextPage:u}};mf.locally=e=>{var t,n;const r=ve();if(r.log("comment/queryComments.locally",e),!r.cache)return;const{page:o={limit:10}}=e,i=zl(e,["page"]),s=["comment","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Ue(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.comments.length))return;const l=a.comments.map((e=>Ue(["comment","get",e]))).filter(Boolean).map((({data:e})=>e)),u=V(null==a?void 0:a.paging.previous),f=V(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:f}:void 0};const yf=async e=>{const t=ve();t.log("comment/getComments",e);const n=e.map((e=>encodeURIComponent(e))),{data:r}=await t.http.get("/api/v3/comments/list",{params:{commentIds:n}}),o=t.cache&&Date.now();return t.cache&&Rl(r,{cachedAt:o}),{data:r.comments,cachedAt:o}};yf.locally=e=>{var t;const n=ve();if(n.log("comment/getComments.locally",e),!n.cache)return;const r=e.map((e=>Ue(["comment","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 vf=async e=>{const t=ve();let n;t.log("comment/getComment",e);try{n=(await t.http.get(`/api/v3/comments/${encodeURIComponent(e)}`)).data}catch(t){throw 400400===(null==t?void 0:t.code)&&ze(["comment","get",e],!0),t}const r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{comments:o}=n;return{data:o.find((t=>t.commentId===e)),cachedAt:r}};vf.locally=e=>{const t=ve();if(t.log("comment/getComment.locally",e),!t.cache)return;const n=Ue(["comment","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const bf=(e,t)=>{var n,r;if(ve().userId!==t.reactor.userId)return;let o,i;if("post.addReaction"===e||"post.removeReaction"===e){const e=t.posts[0];i=null===(n=Ue(["post","get",e.postId]))||void 0===n?void 0:n.data,o=e}else{const e=t.comments[0];i=null===(r=Ue(["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))})}},wf=async(e,t,n)=>{const r=ve();if(r.log("reaction/createReaction",{referenceId:t,referenceType:e,reactionName:n}),await r.http.post("/api/v2/reactions",{referenceId:t,referenceType:e,reactionName:n}),r.cache){const n=Ue([e,"get",t]);(null==n?void 0:n.data)&&De([e,"get",t],n.data,{cachedAt:Date.now()})}return!0};wf.optimistically=(e,t,n)=>{var r,o,i,s,a;const c=ve();if(c.log("reaction/createReaction.optimistically",{referenceId:t,referenceType:e,reactionName:n}),!c.cache)return;const l=Ue([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 qe([e,"get",t],u,{cachedAt:-5}),tu(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 Cf=async(e,t,n)=>{const r=ve();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}}),r.cache){const n=Ue([e,"get",t]);(null==n?void 0:n.data)&&De([e,"get",t],n.data,{cachedAt:Date.now()})}return!0};Cf.optimistically=(e,t,n)=>{var r,o,i,s,a;const c=ve();if(c.log("reaction/removeReaction.optimistically",{referenceId:t,referenceType:e,reactionName:n}),!c.cache)return;const l=Ue([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 qe([e,"get",t],u,{cachedAt:-5}),tu(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 _f=async e=>{const t=ve();t.log("reaction/queryReactions",e);const n=null!=e?e:{},{page:r={limit:10}}=n,o=zl(n,["page"]),{data:i}=await t.http.get("/api/v3/reactions",{params:Object.assign(Object.assign({},o),{options:{token:H(r,"afterbeforeraw")}})}),{paging:s}=i,a=zl(i,["paging"]),{reactions:c}=a;Rl(Object.assign(Object.assign({},a),{reactions:c[0].reactors}));const l=W(s.next);return{data:c,prevPage:W(s.previous),nextPage:l}},kf=(e,t)=>{const n=ve();return et(n,e,e,(r=>{var o;if(n.cache){const{communities:n}=r,i=zl(r,["communities"]);Rl(i),(null==n?void 0:n[0])&&!["post.updated"].includes(e)&&tt("community.updated",{communities:n});const s=Ue(["post","get",r.posts[0].postId]);if(["post.created","post.approved","post.declined"].includes(e)){let t=null===(o=Me(["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)===s.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})=>qe(e,t,{cachedAt:-1})))}t(s.data)}else t(r.posts[0])}))},Sf=e=>kf("post.created",e),Af=e=>kf("post.updated",e),Ef=e=>kf("post.deleted",e),Of=e=>kf("post.approved",e),If=e=>kf("post.declined",e),Tf=e=>kf("post.flagged",e),xf=e=>kf("post.unflagged",e),Pf=e=>{const t=ve();return et(t,"post.addReaction","post.addReaction",(n=>{if(t.cache){bf("post.addReaction",n);const t=zl(n,["reactor"]);Rl(t);const r=Ue(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},Rf=e=>{const t=ve();return et(t,"post.removeReaction","post.removeReaction",(n=>{if(t.cache){bf("post.removeReaction",n);const t=zl(n,["reactor"]);Rl(t);const r=Ue(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},jf=(e,t)=>{const n=ve();return et(n,e,e,(r=>{var o;if(n.cache){Rl(r);const n=Ue(["comment","get",r.comments[0].commentId]);if(["comment.created"].includes(e)){const e=null===(o=Me(["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})=>qe(e,t,{cachedAt:-1})))}t(n.data)}else t(r.comments[0])}))},Nf=e=>jf("comment.created",e),Ff=e=>jf("comment.updated",e),Bf=e=>jf("comment.deleted",e),Mf=e=>jf("comment.flagged",e),Uf=e=>jf("comment.unflagged",e),Df=e=>{const t=ve();return et(t,"comment.addReaction","comment.addReaction",(n=>{if(t.cache){bf("comment.addReaction",n);const t=zl(n,["reactor"]);Rl(t);const r=Ue(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},Lf=e=>{const t=ve();return et(t,"comment.removeReaction","comment.removeReaction",(n=>{if(t.cache){bf("comment.removeReaction",n);const t=zl(n,["reactor"]);Rl(t);const r=Ue(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},qf=(e,t,n)=>{const r=ve(),o=(r,o,i)=>{r===e&&o===t&&n(i)};if("message"===e){const e=e=>{if(!e.messages[0].latestReaction)return;const t=e.messages[0].latestReaction,{eventName:n,referenceId:r,referenceType:i,userDisplayName:s}=t,a=zl(t,["eventName","referenceId","referenceType","userDisplayName"]);"add"===n&&(Rl(e),Rl({reactions:[a]}),o("message",e.messages[0].messageId,a))};return et(r,"reaction/onReactorAdded","v3.message.didUpdate",e)}if("post"===e){return et(r,"post.addReaction","post.addReaction",(e=>{const{reactor:t}=e,n=zl(e,["reactor"]);Rl(n),Rl({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return et(r,"comment.addReaction","comment.addReaction",(e=>{const{reactor:t}=e,n=zl(e,["reactor"]);Rl(n),Rl({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))},zf=(e,t,n)=>{const r=ve(),o=(r,o,i)=>{r===e&&o===t&&n(i)};if("message"===e){const e=e=>{if(!e.messages[0].latestReaction)return;const t=e.messages[0].latestReaction,{eventName:n,referenceId:r,referenceType:i}=t,s=zl(t,["eventName","referenceId","referenceType"]);"remove"===n&&(Rl(e),Rl({reactions:[s]}),o("message",e.messages[0].messageId,s))};return et(r,"reaction/onReactorRemoved","v3.message.didUpdate",e)}if("post"===e){return et(r,"post.removeReaction","post.removeReaction",(e=>{const{reactor:t}=e,n=zl(e,["reactor"]);Rl(n),Rl({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return et(r,"comment.removeReaction","comment.removeReaction",(e=>{const{reactor:t}=e,n=zl(e,["reactor"]);Rl(n),Rl({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))};var $f={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 Hf=e=>{const t=ve(),n=e.channels.map((n=>{const r=e.channelUsers.find((e=>e.userId===t.userId&&n.channelId===e.channelId)),o=!!r&&r.readToSegment<r.lastMentionedSegment,i=r&&"member"===r.membership&&n.messageCount?Math.max(0,n.messageCount-r.readToSegment):0;return Object.assign(Object.assign({},n),{hasMention:o,unreadCount:i})}));return Object.assign(Object.assign({},e),{channels:n})},Vf=async e=>{const t=ve();t.log("channel/queryChannels",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,membership:i}=n,s=zl(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:H(r,"skiplimit")}})}),{paging:c}=a,l=zl(a,["paging"]),u=Hf(l),{channels:f}=u,h=t.cache&&Date.now();if(t.cache){Rl(u,{cachedAt:h});const e=["channel","query",Object.assign(Object.assign({},s),{options:Object.assign({},r)})];De(e,{channels:f.map(Q("channel")),paging:c})}const d=V(c.next);return{data:f,cachedAt:h,prevPage:V(c.previous),nextPage:d}};Vf.locally=e=>{var t,n;ve().log("channel/queryChannels.locally",e);const r=null!=e?e:{},{page:o={limit:10}}=r,i=zl(r,["page"]),s=["channel","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Ue(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.channels.length))return;const l=a.channels.map((e=>Ue(["channel","get",e]))).filter(Boolean).map((({data:e})=>e)),u=V(null==a?void 0:a.paging.previous),f=V(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:f}:void 0};const Wf=async e=>{const t=ve();t.log("channel/getChannels",e);const n=e.map((e=>encodeURIComponent(e))),{data:r}=await t.http.get("/api/v3/channels/list",{params:{channelIds:n}}),o=Hf(r),i=t.cache&&Date.now();return t.cache&&Rl(o,{cachedAt:i}),{data:o.channels,cachedAt:i}};Wf.locally=e=>{var t;const n=ve();if(n.log("channel/getChannels.locally",e),!n.cache)return;const r=e.map((e=>Ue(["channel","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 Kf=async e=>{const t=ve();let n;t.log("channel/getChannel",e),Ul("channel",e);try{const{data:r}=await t.http.get(`/api/v3/channels/${encodeURIComponent(e)}`);n=Hf(r)}catch(t){throw re(null==t?void 0:t.code)&&Dl("channel",e),t}const r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{channels:o}=n;return{data:o.find((t=>t.channelId===e)),cachedAt:r}};Kf.locally=e=>{const t=ve();if(t.log("channel/getChannel.locally",e),!t.cache)return;const n=Ue(["channel","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Qf=async e=>{const t=ve();t.log("channel/queryChannelMembers",e);const n=null!=e?e:{},{page:r}=n,o=zl(n,["page"]),{data:i}=await t.http.get(`/api/v4/channels/${encodeURIComponent(o.channelId)}/users`,{params:Object.assign(Object.assign({},o),{options:{token:H(r,"skiplimit")}})}),{paging:s}=i,a=zl(i,["paging"]),c=Hf(a),l=hf(c,"channelUsers"),{channelUsers:u}=l,f=t.cache&&Date.now();if(t.cache){Rl(l);const e=["channelUsers","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];De(e,{channelUsers:u.map((({channelId:e,userId:t})=>Q("channelUsers")({channelId:e,userId:t}))),paging:s})}return{data:u,cachedAt:f,nextPage:V(s.next),prevPage:V(s.previous)}};Qf.locally=e=>{var t,n;const r=ve();if(r.log("channel/queryChannelMembers.locally",e),!r.cache)return;const{page:o}=e,i=zl(e,["page"]),s=["channelUsers","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Ue(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.channelUsers.length))return;const l=a.channelUsers.map((e=>Ue(["channelUsers","get",e]))).filter(Boolean).map((({data:e})=>e)),u=V(null==a?void 0:a.paging.previous),f=V(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:f}:void 0};const Jf=e=>{const t=ve();return et(t,"onChannelCreated","v3.channel.didCreate",(t=>{const n=Hf(t);Rl(n),e(n.channels[0])}))},Gf=e=>{const t=ve();return et(t,"onChannelUpdated","v3.channel.didUpdate",(t=>{const n=Hf(t);Rl(n),e(n.channels[0])}))},Yf=e=>{const t=ve();return et(t,"onChannelDeleted","v3.channel.didDelete",(t=>{const n=Hf(t);Rl(n),e(n.channels[0])}))},Xf=e=>{const t=ve();return et(t,"onChannelJoined","v3.channel.didJoin",(t=>{const n=Hf(t);Rl(n),e(n.channels[0])}))},Zf=e=>{const t=ve();return et(t,"onChannelLeft","v3.channel.didLeave",(t=>{const n=Hf(t);Rl(n),e(n.channels[0])}))},eh=e=>{const t=ve();return et(t,"onChannelMemberAdded","v3.channel.didAddUsers",(t=>{const n=Hf(t),r=hf(n,"channelUsers"),{channels:o,channelUsers:i}=r;Rl(r),e(o[0],i.find((e=>"member"===e.membership)))}))},th=e=>{const t=ve();return et(t,"onChannelMemberRemoved","v3.channel.didRemoveUsers",(t=>{const n=Hf(t),r=hf(n,"channelUsers"),{channels:o,channelUsers:i}=r;Rl(r),e(o[0],i[0])}))},nh=e=>{const t=ve();return et(t,"onChannelMemberBanned","v3.channel.didBan",(t=>{const n=Hf(t),r=hf(n,"channelUsers"),{channels:o,channelUsers:i}=r;Rl(r),e(o[0],i.find((e=>"banned"===e.membership)))}))},rh=e=>{const t=ve();return et(t,"onChannelMemberUnbanned","v3.channel.didUnban",(t=>{const n=Hf(t),r=hf(n,"channelUsers"),{channels:o,channelUsers:i}=r;Rl(r),e(o[0],i.find((e=>"none"===e.membership)))}))},oh=e=>{const t=ve();return et(t,"onChannelMemberRead","v3.channel.didMarkSeen",(t=>{const n=Hf(t),r=hf(n,"channelUsers");Rl(r),e(r.channels[0],r.channelUsers[0])}))},ih=e=>{const t=ve();return et(t,"message/onMessageCreated","v3.message.didCreate",(t=>{Rl(t),e(t.messages[0])}))},sh=e=>{const t=ve();return et(t,"message/onMessageUpdated","v3.message.didUpdate",(t=>{Rl(t);const n=t.messages[0];(null==n?void 0:n.myReactions)||(e=>{const t=ve(),n=Ue(["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))}))})(n),e(n)}))},ah=e=>{const t=ve();return et(t,"message/onMessageDeleted","v3.message.didDelete",(t=>{Rl(t),e(t.messages[0])}))},ch=e=>{const t=ve();return et(t,"message/onMessageFetched","v3.message.didFetch",(t=>{Rl(t),e(t.messages[0])}))},lh=(e,t)=>{const n=ve();return et(n,e,e,(e=>{const r=sf(e);if(n.cache){Rl(r);const e=Ue(["community","get",r.communities[0].communityId]);t(e.data)}else t(r.communities[0])}))};function uh(e,t,n){return!!e.permissions.some((e=>e===n))||t.users.find((t=>t.userId===e.userId)).permissions.some((e=>e===n))}function fh(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=>!uh(e,t,"BAN_COMMUNITY_USER")))[0]:t.communityUsers.filter((e=>!uh(e,t,"ADD_COMMUNITY_USER")))[0]}const hh=(e,t)=>{const n=ve();return et(n,e,e,(r=>{const o=sf(r),i=hf(o,"communityUsers");if(n.cache){Rl(i);const n=Ue(["community","get",i.communities[0].communityId]),r=Ue(["communityUsers","get",Q("communityUsers")(fh(e,i))]);t(n.data,r.data)}else t(i.communities[0],fh(e,i))}))},dh=e=>lh("community.updated",e),ph=e=>lh("community.deleted",e),gh=e=>hh("community.joined",e),mh=e=>hh("community.left",e),yh=e=>hh("community.userAdded",e),vh=e=>hh("community.userRemoved",e),bh=e=>hh("community.userBanned",e),wh=e=>hh("community.userUnbanned",e),Ch=async e=>{const t=ve();t.log("category/queryCategories",e);const n=null!=e?e:{},{page:r={limit:10}}=n,o=zl(n,["page"]),{data:i}=await t.http.get("/api/v3/community-categories",{params:Object.assign(Object.assign({},o),{options:{token:H(r,"skiplimit")}})}),{paging:s}=i,a=zl(i,["paging"]),{categories:c}=a,l=t.cache&&Date.now();if(t.cache){Rl(a,{cachedAt:l});const e=["category","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];De(e,{categories:c.map(Q("category")),paging:s})}const u=V(s.next);return{data:c,cachedAt:l,prevPage:V(s.previous),nextPage:u}};Ch.locally=e=>{var t,n;const r=ve();if(r.log("category/queryCategories.locally",e),!r.cache)return;const o=null!=e?e:{},{page:i={limit:10}}=o,s=zl(o,["page"]),a=["category","query",Object.assign(Object.assign({},s),{options:Object.assign({},i)})],{data:c,cachedAt:l}=null!==(t=Ue(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.categories.length))return;const u=c.categories.map((e=>Ue(["category","get",e]))).filter(Boolean).map((({data:e})=>e)),f=V(null==c?void 0:c.paging.previous),h=V(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:f,nextPage:h}:void 0};const _h=async e=>{const t=ve();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&&Rl(n,{cachedAt:r});const{categories:o}=n;return{data:o.find((t=>t.categoryId===e)),cachedAt:r}};_h.locally=e=>{const t=ve();if(t.log("category/getCategory.locally",e),!t.cache)return;const n=Ue(["category","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const kh=async e=>{const t=ve();t.log("feed/queryGlobalFeed",e);const n=null!=e?e:{},{useCustomRanking:r,page:o}=n,i=zl(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:H(o,"skiplimit")}})}),{paging:a}=s,c=zl(s,["paging"]),{posts:l}=c,u=t.cache&&Date.now();if(t.cache){Rl(c);const e=["globalFeed","query",Object.assign(Object.assign({},i),{useCustomRanking:r,options:Object.assign({},o)})];De(e,{posts:l.map(Q("post")),paging:a})}const f=V(a.next);return{data:l,cachedAt:u,prevPage:V(a.previous),nextPage:f}};kh.locally=e=>{var t,n;const r=ve();if(r.log("post/queryGlobalFeed.locally",e),!r.cache)return;const o=null!=e?e:{},{useCustomRanking:i,page:s}=o,a=zl(o,["useCustomRanking","page"]),c=["globalFeed","query",Object.assign(Object.assign({},a),{useCustomRanking:i,options:Object.assign({},s)})],{data:l,cachedAt:u}=null!==(t=Ue(c))&&void 0!==t?t:{};if(!(null==l?void 0:l.posts.length))return;const f=l.posts.map((e=>Ue(["post","get",e]))).filter(Boolean).map((({data:e})=>e)),h=V(null==l?void 0:l.paging.previous),d=V(null==l?void 0:l.paging.next);return f.length===(null===(n=null==l?void 0:l.posts)||void 0===n?void 0:n.length)?{data:f,cachedAt:u,prevPage:h,nextPage:d}:void 0};const Sh=async(e,t)=>{const n=ve();n.log(`follow/queryF${e.substring(1)}`,t);const{userId:r,page:o}=t,i=zl(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:H(o,"afterbeforeraw")})}),{paging:a}=s,c=zl(s,["paging"]),{follows:l}=c,u=n.cache&&Date.now();if(n.cache){Rl(c,{cachedAt:u});const t=["follow","query",Object.assign(Object.assign({},i),{userId:r,options:Object.assign({},o),type:e})];De(t,{follows:l.map(Q("follow")),paging:a})}const f=W(a.next);return{data:l,cachedAt:u,prevPage:W(a.previous),nextPage:f}};Sh.locally=(e,t)=>{var n,r;const o=ve();if(o.log(`follow/queryF${e.substring(1)}.locally`,t),!o.cache)return;const{page:i}=t,s=zl(t,["page"]),a=["follow","query",Object.assign(Object.assign({},s),{options:Object.assign({},i),type:e})],{data:c,cachedAt:l}=null!==(n=Ue(a))&&void 0!==n?n:{};if(!(null==c?void 0:c.follows.length))return;const u=c.follows.map((e=>Ue(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)),f=W(null==c?void 0:c.paging.previous),h=W(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:f,nextPage:h}:void 0};const Ah=async e=>Sh("followers",e);Ah.locally=e=>Sh.locally("followers",e);const Eh=async e=>Sh("following",e);Eh.locally=e=>Sh.locally("following",e);const Oh=e=>["followInfo","get",`${ve().userId}#${e}`],Ih=async e=>{var t,n;const r=ve();r.log("follow/getFollowInfo",e);const{data:o}=await r.http.get(r.userId===e?"/api/v4/me/followInfo":`/api/v4/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&&De(Oh(e),s,{cachedAt:i}),{data:s,cachedAt:i}};Ih.locally=e=>{const t=ve();if(t.log("follow/getFollowInfo.locally",e),!t.cache)return;const n=Ue(Oh(e));return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Th=(e,t)=>{const n=ve();return et(n,e,e,(e=>{var r,o;if(n.cache){Rl(e);[...null!==(r=Me(["followers","query"]))&&void 0!==r?r:[],...null!==(o=Me(["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})=>qe(e,t,{cachedAt:-1}))),t(e.follows[0])}else t(e.follows[0])}))},xh=e=>Th("follow.created",e),Ph=e=>Th("follow.unfollowed",e),Rh=e=>Th("follow.followerDeleted",e),jh=e=>Th("follow.requested",e),Nh=e=>Th("follow.requestCanceled",e),Fh=e=>Th("follow.accepted",e),Bh=e=>Th("follow.requestDeclined",e),Mh=e=>{const t=async t=>{const[{data:n},{data:r}]=await Promise.all([Ih(t.from),Ih(t.to)]);e(n),e(r)},n=[Th("follow.created",t),Th("follow.requested",t),Th("follow.accepted",t),Th("follow.unfollowed",t),Th("follow.requestCanceled",t),Th("follow.requestDeclined",t),Th("follow.followerDeleted",t)];return()=>{n.forEach((e=>e()))}},Uh=async e=>{const t=ve();t.log("poll/getPoll",e);const{data:n}=await t.http.get(`/api/v3/polls/${e}`),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{polls:o}=n;return{data:o.find((t=>t.pollId===e)),cachedAt:r}};Uh.locally=e=>{const t=ve();if(t.log("poll/getPoll",e),!t.cache)return;const n=Ue(["poll","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Dh=e=>{const t=ve();return et(t,"poll/onPollUpdated","poll.updated",(n=>{t.cache&&Rl(n),e(n.polls[0])}))},Lh=e=>{const t=ve();return et(t,"poll/onPollDeleted","poll.deleted",(n=>{t.cache&&Rl(n),e(n.polls[0])}))},qh=async e=>{const t=ve();t.log("stream/getStream",e);const{data:n}=await t.http.get(`/api/v3/video-streaming/${e}`),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}};qh.locally=e=>{const t=ve();if(t.log("stream/getStream",e),!t.cache)return;const n=Ue(["stream","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const zh=async e=>{const t=ve();t.log("stream/queryStreams",e);const n=null!=e?e:{},{page:r}=n,o=zl(n,["page"]),{data:i}=await t.http.get("/api/v3/video-streaming",{params:Object.assign(Object.assign({},o),{options:{token:H(r,"skiplimit")}})}),{paging:s,results:a}=i,{videoStreamings:c}=a,l=t.cache&&Date.now();t.cache&&Rl(a,{cachedAt:l});const u=V(s.next);return{data:c,cachedAt:l,prevPage:V(s.previous),nextPage:u}};zh.locally=e=>{ve().log("stream/queryStreams.locally",e)};return e.API_REGIONS=mt,e.CommunityPostSettingMaps=n,e.CommunityPostSettings=t,e.ContentFeedType=o,e.DefaultCommunityPostSetting=r,e.FileType=i,e.MessageContentType=l,e.PostContentType=u,e.VERSION=y,e.VideoResolution=s,e.VideoSize=c,e.VideoTranscodingStatus=a,e.acceptFollower=async e=>{const t=ve();t.log("follow/acceptFollower",e);const{data:n}=await t.http.post(`/api/v4/me/followers/${e}`);return t.cache&&Rl(n),tt("follow.accepted",n),!0},e.addChannelMembers=async(e,t)=>{const n=ve();n.log("channel/addChannelMembers",e,t);const{data:r}=await n.http.post(`/api/v3/channels/${encodeURIComponent(e)}/users`,{channelId:e,userIds:t}),o=Hf(r);n.cache&&Rl(o),t.forEach((e=>tt("v3.channel.didAddUsers",Object.assign(Object.assign({},o),{channelUsers:o.channelUsers.filter((t=>t.userId===e))}))));const{channelUsers:i}=o;return!!i.find((t=>t.channelId===e&&"member"===t.membership))},e.addChannelMembersRole=async(e,t,n)=>{const r=ve();r.log("channel/addChannelMembersRole",e,t,n);const{data:o}=await r.http.post(`/api/v3/channels/${encodeURIComponent(e)}/users/roles`,{channelId:e,role:t,userIds:n}),i=Hf(o);r.cache&&Rl(i);const{channelUsers:s}=i;return!!s.find((n=>n.channelId===e&&n.roles.includes(t)))},e.addCommunityMembers=async(e,t)=>{const n=ve();n.log("community/addCommunityMembers",e,t);const{data:r}=await n.http.post(`/api/v3/communities/${e}/users`,{communityId:e,userIds:t});n.cache&&Rl(r),tt("community.userAdded",r);const{communityUsers:o}=r;return!!o.find((t=>t.communityId===e&&"member"===t.communityMembership))},e.addCommunityMembersRoles=async(e,t,n)=>{const r=ve();r.log("community/addCommunityMembersRoles",e,t,n);const{data:o}=await r.http.post(`/api/v4/communities/${e}/users/roles`,{communityId:e,roles:t,userIds:n});r.cache&&Rl(o);const{communityUsers:i}=o;return!!i.find((n=>n.communityId===e&&t.some((e=>n.roles.includes(e)))))},e.addReaction=wf,e.approvePost=async e=>{var t;const n=ve();n.log("post/approvePost",e);const{data:r}=await n.http.post(`/api/v3/posts/${encodeURIComponent(e)}/approve`),o=n.cache&&Date.now();if(n.cache&&Rl(r,{cachedAt:o}),"community"===r.posts[0].targetType){const e=null===(t=r.communities)||void 0===t?void 0:t[0];tt("community.updated",{communities:[e]})}return tt("post.approved",{posts:[r.posts[0]]}),{data:r.posts.find((t=>t.postId===e)),cachedAt:o}},e.backupCache=async(e="amitySdk",t=(e=>e.offline))=>{const{log:n,cache:r,userId:o}=ve();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 Be.setItem(`${e}#${o}`,JSON.stringify(i)),!0)},e.banChannelMembers=async(e,t)=>{const n=ve();n.log("channel/banChannelMembers",{userIds:t,channelId:e});const{data:r}=await n.http.put(`/api/v3/channels/${e}/users/ban`,{userIds:t}),o=Hf(r),i=hf(o,"channelUsers"),{channelUsers:s}=i,a=n.cache&&Date.now();return n.cache&&Rl(i,{cachedAt:a}),{data:null==s?void 0:s.filter((e=>"banned"===e.membership)),cachedAt:a}},e.closePoll=async e=>{const t=ve();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&&Rl(n,{cachedAt:r}),tt("poll.updated",n);const{polls:o}=n;return{data:o.find((t=>t.pollId===e)),cachedAt:r}},e.connectClient=async(e,t)=>{var n;const r=ve();r.log("client/api/connectClient",Object.assign({apiKey:r.apiKey},e)),null!==(n=e.deviceId)&&void 0!==n||(e.deviceId=xl());const{accessToken:o,users:i}=await(async e=>{const t=ve();t.log("client/api/getToken",e);const n=await Pl(),{data:r}=await t.http.post("/v1/device",Object.assign(Object.assign({},e),{deviceInfo:n}),{headers:{"X-API-Key":t.apiKey}});return r})(e);var s,a,c;r.http.defaults.headers.common.Authorization=`Bearer ${o}`,r.ws.io.opts.query={token:o},s=r.ws,a=r.emitter,Ye.forEach((e=>{s.on(e,(t=>a.emit(e,t)))})),await new Promise((e=>{r.ws.once("connect",e),r.ws.open()})),r.userId=e.userId,r.accessToken=o,c=i[0],nt={_id:c._id,userId:c.userId,path:c.path},!0!==(null==t?void 0:t.disableRTE)&&lt(st());const l=[Ml((()=>{Tl(),l.forEach((e=>e()))})),Nl((()=>null))];return r.ws.connected},e.createChannel=async e=>{const t=ve();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=Hf(n.data),o=t.cache&&Date.now();t.cache&&Rl(r,{cachedAt:o});const{channels:i}=r;return{data:i[0],cachedAt:o}},e.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&&!p,n=gt(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:vt("http",t),c=null!==(i=null==r?void 0:r.mqtt)&&void 0!==i?i:vt("mqtt",t),l=ls(a),u=(e=>{const t=Cl(e,{autoConnect:!1,reconnectionDelay:2e3,transports:["websocket"]});return t.on("disconnect",(e=>{"io server disconnect"===e&&t.connect()})),t})(a),f=Ol(c),h=Ze(),d={version:`${y}`,apiKey:e,log:s,http:l,ws:u,mqtt:f,emitter:h,use:()=>be(d),getFeedSettings:Il};try{ve()}catch(e){be(d)}return d},e.createComment=async e=>{const t=ve();t.log("comment/createComment",e);const{data:n}=await t.http.post("/api/v3/comments",e),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const o=await rf(e.referenceId);tt("post.updated",{posts:[o.data]}),tt("comment.created",n);const{comments:i}=n;return{data:i[0],cachedAt:r}},e.createCommunity=async e=>{const t=ve();t.log("user/createCommunity",e);const{data:n}=await t.http.post("/api/v3/communities/",af(e)),r=sf(n),o=t.cache&&Date.now();t.cache&&Rl(r,{cachedAt:o}),tt("community.created",r);const{communities:i}=r;return{data:i[0],cachedAt:o}},e.createFile=async(e,t)=>{const n=ve();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}){t&&t(Math.round(100*e/n))}}),i=n.cache&&Date.now();return n.cache&&Rl({files:o},{cachedAt:i}),{data:o,cachedAt:i}},e.createImage=async(e,t)=>{const n=ve();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}){t&&t(Math.round(100*e/n))}}),i=n.cache&&Date.now();return n.cache&&Rl({files:o},{cachedAt:i}),{data:o,cachedAt:i}},e.createMessage=Xu,e.createPoll=async e=>{const t=ve();t.log("post/createPoll",e);const{data:n}=await t.http.post("/api/v3/polls",e),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{polls:o}=n;return{data:o[0],cachedAt:r}},e.createPost=async e=>{const t=ve();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),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r}),tt("post.created",n);const{posts:o}=n;return{data:o[0],cachedAt:r}},e.createQuery=le,e.createReport=async(e,t)=>{const n=ve();n.log("report/createReport",{referenceType:e,referenceId:t});const{domainName:r}=$f[e],{data:o}=await n.http.post("/api/"+("user"===e?`v4/me/flags/${encodeURIComponent(t)}`:`v3/${r}/${encodeURIComponent(t)}/flag`));n.cache&&Rl(o);return tt("message"===e?"v3.message.didUpdate":`${e}.flagged`,o),!!o},e.createStream=async e=>{const t=ve();t.log("stream/createStream",e);const{data:n}=await t.http.post("/api/v3/video-streaming",e),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o[0],cachedAt:r}},e.createUserToken=async(e,t,n)=>{const r=xl(),o=await Pl(),i=ls(vt("http",t)),{data:s}=await i.post("/api/v3/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.createVideo=async(e,t,n)=>{const r=ve();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}){n&&n(Math.round(100*e/t))}}),s=r.cache&&Date.now();return r.cache&&Rl({files:i},{cachedAt:s}),{data:i,cachedAt:s}},e.declineFollower=async e=>{const t=ve();t.log("follow/declineFollower",e);const{data:n}=await t.http.delete(`/api/v4/me/followers/${e}`);return t.cache&&Rl(n),tt("follow.requestDeclined",n),!0},e.declinePost=async e=>{var t;const n=ve();n.log("post/declinePost",e);const{data:r}=await n.http.post(`/api/v3/posts/${encodeURIComponent(e)}/decline`),o=n.cache&&Date.now();if(n.cache&&Rl(r,{cachedAt:o}),"community"===r.posts[0].targetType){const e=null===(t=r.communities)||void 0===t?void 0:t[0];tt("community.updated",{communities:[e]})}return tt("post.declined",{posts:[r.posts[0]]}),{data:r.posts.find((t=>t.postId===e)),cachedAt:o}},e.deleteChannel=async e=>{const t=ve();t.log("channel/deleteChannel",e),await t.http.delete(`/api/v3/channels/${encodeURIComponent(e)}`);return(await Kf(e)).data},e.deleteComment=async(e,t=!1)=>{const n=ve();n.log("comment/deleteComment",e);const r=await vf(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 rf(r.data.referenceId);return tt("post.updated",{posts:[i.data]}),tt("comment.deleted",{comments:[o]}),t?setTimeout((()=>{ze(["comment","get",e],!0)}),0):qe(["comment","get",e],{isDeleted:!0}),o},e.deleteCommunity=async e=>{const t=ve();t.log("community/deleteCommunity",e),await t.http.delete(`/api/v3/communities/${e}`);const n=await uf(e);return tt("community.deleted",{communities:[n.data]}),n.data},e.deleteFile=async e=>{const t=ve();return t.log("file/deleteFile",e),await t.http.delete(`/api/v3/files/${e}`),ze(["file","get",e],!0),{success:!0}},e.deleteMessage=ef,e.deletePoll=async e=>{const t=ve();t.log("poll/deletePoll",e);const n=await Uh(e),{data:r}=await t.http.delete(`/api/v3/polls/${e}`),{success:o}=r,i=Object.assign(Object.assign({},n.data),{isDeleted:!0});return qe(["poll","get",e],i),tt("poll.deleted",{polls:[i],users:[]}),o},e.deletePost=async(e,t=!1)=>{const n=ve();n.log("post/deletePost",e);const r=await rf(e);if(await n.http.delete(`/api/v4/posts/${encodeURIComponent(e)}`,{params:{postId:e,permanent:t}}),"community"===r.data.targetType){const e=await uf(r.data.targetId);tt("community.updated",{communities:[e.data]})}const o=Object.assign(Object.assign({},r.data),{isDeleted:!0});return tt("post.deleted",{posts:[o]}),t?setTimeout((()=>{Dl("post",e)}),0):qe(["post","get",e],{isDeleted:!0}),o},e.deleteReport=async(e,t)=>{const n=ve();n.log("report/deleteReport",{referenceType:e,referenceId:t});const{domainName:r}=$f[e],{data:o}=await n.http.delete("/api/"+("user"===e?`v4/me/flags/${encodeURIComponent(t)}`:`v3/${r}/${encodeURIComponent(t)}/unflag`));n.cache&&Rl(o);return tt("message"===e?"v3.message.didUpdate":`${e}.unflagged`,o),!!o},e.deleteStream=async e=>{const t=ve();t.log("stream/deleteStream",e);const n=await qh(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 qe(["stream","get",e],i),o},e.disableCache=()=>{const e=ve();e.cache&&(e.log("cache/api/disableCache"),delete e.cache)},e.disconnectClient=Tl,e.disposeStream=async e=>{const t=ve();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&&Rl(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}},e.dropFromCache=ze,e.enableCache=(e={},t)=>{const n=ve();n.cache||(n.log("cache/api/enableCache"),n.cache={data:e,persistIf:t})},e.fileUrlWithSize=(e,t)=>`${e}?size=${t}`,e.filterByChannelMembership=Ve,e.filterByPropEquality=$e,e.filterByPropInclusion=He,e.follow=async e=>{const t=ve();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&&Rl(n,{cachedAt:r}),tt("accepted"===n.follows[0].status?"follow.created":"follow.requested",n),{data:n.follows[0],cachedAt:r}},e.getActiveClient=ve,e.getCategory=_h,e.getChannel=Kf,e.getChannels=Wf,e.getComment=vf,e.getCommentTopic=({path:e})=>e,e.getComments=yf,e.getCommunities=lf,e.getCommunity=uf,e.getCommunityTopic=({path:t},n=e.SubscriptionLevels.COMMUNITY)=>it(t,n),e.getFeedSettings=Il,e.getFile=Xl,e.getFollowInfo=Ih,e.getMessage=nu,e.getMessages=ru,e.getMyFollowersTopic=()=>{const e=rt(),[t]=e.path.split("/user/");return`${t}/membership/${e._id}/+/+`},e.getMyFollowingsTopic=()=>{const e=rt(),[t]=e.path.split("/user/");return`${t}/membership/+/${e._id}/+`},e.getNetworkTopic=st,e.getPoll=Uh,e.getPost=rf,e.getPostTopic=({path:t},n=e.SubscriptionLevels.POST)=>"comment"===n?`${t}/comment/+`:t,e.getPosts=nf,e.getRecommendedCommunities=gf,e.getRole=eu,e.getStream=qh,e.getTopTrendingCommunities=pf,e.getUser=Ll,e.getUserTopic=({path:t},n=e.SubscriptionLevels.USER)=>it(n===e.SubscriptionLevels.USER?t:t.replace(/^(\w*)/,"$1/social"),n),e.getUsers=ql,e.isAfterBefore=q,e.isAfterBeforeRaw=z,e.isCachable=ae,e.isConnected=()=>{var e,t;const n=ve();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)},e.isFetcher=oe,e.isFresh=ce,e.isLocal=e=>ae(e)&&-1===(null==e?void 0:e.cachedAt),e.isMutator=ie,e.isOffline=se,e.isPaged=$,e.isReportedByMe=async(e,t)=>{var n,r;const o=ve();o.log("report/isReportedByMe",{referenceType:e,referenceId:t});const{eventName:i,primaryKey:s}=$f[e],{result:a,isFlagByMe:c}=null!==(n=await _l(o,i,{[s]:t}))&&void 0!==n?n:{};return null!==(r=null!=a?a:c)&&void 0!==r&&r},e.isSkipLimit=L,e.joinChannel=async e=>{const t=ve();t.log("channel/joinChannel",e);const{data:n}=await t.http.post(`/api/v3/channels/${encodeURIComponent(e)}/join`),r=Hf(n);t.cache&&Rl(r);const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"===t.membership))},e.joinCommunity=async e=>{const t=ve();t.log("community/joinCommunity",e);const{data:n}=await t.http.post(`/api/v3/communities/${e}/join`),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r}),tt("community.joined",n);const{communityUsers:o}=n;return!!o.find((t=>t.communityId===e&&"member"===t.communityMembership))},e.leaveChannel=async e=>{const t=ve();t.log("channel/leaveChannel",e);const{data:n}=await t.http.delete(`/api/v3/channels/${encodeURIComponent(e)}/leave`),r=Hf(n);t.cache&&Rl(r);const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"!==t.membership))},e.leaveCommunity=async e=>{const t=ve();t.log("community/leaveCommunity",e);const{data:n}=await t.http.delete(`/api/v3/communities/${e}/leave`),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r}),tt("community.left",n);const{communityUsers:o}=n;return!!o.find((t=>t.communityId===e&&"member"!==t.communityMembership))},e.liveChannelMembers=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log(Gl);const i=Date.now();r(`liveChannelMembers(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["channelUsers","collection",{channelId:e.channelId}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["channelUsers","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];if(i=$e(i,"roles",e.roles),e.memberships&&(e.memberships.some((e=>["member","banned"].includes(e)))&&(i=He(i,"membership",e.memberships)),e.memberships.includes("muted")&&(i=$e(i,"isMuted",!0))),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?Qe:Ke),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;if(!o)return;const i=Q("channelUsers")({channelId:e.channelId,userId:t.userId});"onMemberAdded"===n&&(o.data=[...new Set([i,...o.data])]),"onMemberRemoved"===n&&(o.data=o.data.filter((e=>e!==i))),De(f,o),h(o)},p=()=>{var e,t,n;const r=null===(e=Ue(f))||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=le(Qf,Object.assign(Object.assign({},a),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:c}}));fe(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(Q("channelUsers"))])]),De(f,i),h(i)}),ue(l))};return u.push(eh(((e,t)=>d(t,"onMemberAdded"))),th(((e,t)=>d(t,"onMemberRemoved"))),nh(((e,t)=>d(t,"onChannelMemberBanned"))),rh(((e,t)=>d(t,"onChannelMemberUnbanned"))),oh(((e,t)=>d(t,"onMemberRead")))),p(),()=>{r(`liveChannelMembers(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveChannels=(e,t,n)=>{const{log:r,cache:o,userId:i}=ve();o||console.log(Gl);const s=Date.now();r(`liveChannels(tmpid: ${s}) > listen`);const{limit:a}=e,c=zl(e,["limit"]),l=null!=a?a:5,{policy:u=Jl}=null!=n?n:{},f=[],h=["channel","collection",{}],d=n=>{var r,o;let s=null!==(r=n.data.map((e=>Ue(["channel","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];s=$e(s,"isDeleted",e.isDeleted),s=$e(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=Ve(s,e.membership,i));const a=e.sortBy||"lastCreated";"lastCreated"!==a&&"firstCreated"!==a||(s=s.sort("lastCreated"===a?Qe:Ke)),"displayName"===a&&(s=s.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(We)),t({onNextPage:g,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},p=(t,n)=>{var r;const o=null===(r=Ue(h))||void 0===r?void 0:r.data;o&&("onCreate"===n?o.data=[...new Set([t.channelId,...o.data])]:"onDelete"!==n||e.isDeleted||(o.data=o.data.filter((e=>e!==t.channelId))),De(h,o),d(o))},g=()=>{var e,t,n;const r=null===(e=Ue(h))||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=le(Vf,Object.assign(Object.assign({},c),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:l}}));fe(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(Q("channel"))])]),De(h,i),d(i)}),ue(u))};return f.push(Jf((e=>p(e,"onCreate"))),Yf((e=>p(e,"onDelete"))),Gf((e=>p(e,"onUpdate"))),oh((e=>p(e,"onRead")))),g(),()=>{r(`liveChannels(tmpid: ${s}) > dispose`),f.forEach((e=>e()))}},e.liveComments=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log("For using Live Collection feature you need to enable Cache!");const i=Date.now();r(`liveComments(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["comment","collection",{referenceId:e.referenceType,referenceType:e.referenceId}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["comment","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];i=$e(i,"isDeleted",e.isDeleted);const s=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===s?Qe:Ke),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;e.referenceId===t.referenceId&&e.referenceType===t.referenceType&&o&&("onCreate"===n?o.data=[...new Set([t.commentId,...o.data])]:"onDelete"===n&&(o.data=o.data.filter((e=>e!==t.commentId))),De(f,o),h(o))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(mf,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}}));fe(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(Q("comment"))])]),De(f,i),h(i)}),ue(l))};return u.push(Nf((e=>d(e,"onCreate"))),Ff((e=>d(e,"onUpdate"))),Bf((e=>d(e,"onDelete"))),Mf((e=>d(e,"onFlagged"))),Uf((e=>d(e,"onUnflagged"))),Df((e=>d(e,"onReactionAdded"))),Lf((e=>d(e,"onReactionRemoved")))),p(),()=>{r(`liveComments(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveFollowers=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log("For using Live Collection feature you need to enable Cache!");const i=Date.now();r(`liveFollowers(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["follow","collection",{userId:e.userId,type:"follower"}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.status&&"all"!==e.status&&(i=$e(i,"status",e.status)),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;e.userId===t.to&&o&&(["onDeclined","onCanceled","onUnfollowed","onDeleted"].includes(n)?o.data=o.data.filter((e=>e!==Q("follow")(t))):["onRequested","onAccepted","onFollowed"].includes(n)&&(o.data=[...new Set([Q("follow")(t),...o.data])]),De(f,o),h(o))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(Ah,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}}));fe(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(Q("follow"))])]),De(f,o),h(o)}),ue(l))};return u.push(jh((e=>d(e,"onRequested"))),Fh((e=>d(e,"onAccepted"))),Bh((e=>d(e,"onDeclined"))),Nh((e=>d(e,"onCanceled"))),xh((e=>d(e,"onFollowed"))),Ph((e=>d(e,"onUnfollowed"))),Rh((e=>d(e,"onDeleted")))),p(),()=>{r(`liveFollowers(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveFollowings=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log("For using Live Collection feature you need to enable Cache!");const i=Date.now();r(`liveFollowings(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["follow","collection",{userId:e.userId,type:"following"}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.status&&"all"!==e.status&&(i=$e(i,"status",e.status)),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;e.userId===t.from&&o&&(["onDeclined","onCanceled","onUnfollowed","onDeleted"].includes(n)?o.data=o.data.filter((e=>e!==Q("follow")(t))):["onRequested","onAccepted","onFollowed"].includes(n)&&(o.data=[...new Set([Q("follow")(t),...o.data])]),De(f,o),h(o))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(Eh,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}}));fe(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(Q("follow"))])]),De(f,o),h(o)}),ue(l))};return u.push(jh((e=>d(e,"onRequested"))),Fh((e=>d(e,"onAccepted"))),Bh((e=>d(e,"onDeclined"))),Nh((e=>d(e,"onCanceled"))),xh((e=>d(e,"onFollowed"))),Ph((e=>d(e,"onUnfollowed"))),Rh((e=>d(e,"onDeleted")))),p(),()=>{r(`liveFollowings(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveMessage=(e,t)=>{const{log:n,cache:r}=ve();let o,i=!1;r||console.log(Yl);const s=Date.now();n(`liveMessage(tmpid: ${s}) > listen`);const a=[],c=e=>{var n;o&&(null===(n=e.data)||void 0===n?void 0:n.updatedAt)===(null==o?void 0:o.updatedAt)&&"server"!==e.origin||(t(e),o=e.data)},l=(e,t)=>{c({loading:!1,data:e,origin:"event"})};return a.push(ch((e=>l(e))),sh((e=>l(e))),ah((e=>l(e)))),(()=>{const t=le(nu,e,!0);fe(t,(({loading:e,data:t,error:n,origin:r,cachedAt:o})=>{-5===o?(c({data:t,origin:r,loading:!1,error:new pe("Observing unsynced object is not supported by Live Object.",800800,"error")}),i=!0,a.forEach((e=>e()))):i||c({loading:e,data:t,origin:r,error:n}),n&&a.forEach((e=>e()))}))})(),()=>{n(`liveMessage(tmpid: ${s}) > dispose`),a.forEach((e=>e()))}},e.liveMessages=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log(Gl);const i=Date.now();r(`liveMessages(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["message","collection",{channelId:e.channelId}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["message","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];i=$e(i,"isDeleted",e.isDeleted),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;e.channelId===t.channelId&&o&&("onCreate"===n?o.data=[...new Set([t.messageId,...o.data])]:["onDelete"].includes(n)&&(o.data=o.data.filter((e=>e!==t.messageId))),De(f,o),h(o))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(ou,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}}));fe(u,(({data:e,error:t,loading:n,prevPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(Q("message"))])]),De(f,o),h(o)}),ue(l))};return u.push(ch((e=>d(e,"onFetch"))),ih((e=>d(e,"onCreate"))),ah((e=>d(e,"onDelete"))),sh((e=>d(e,"onUpdate")))),p(),()=>{r(`liveMessages(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.livePosts=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log(Gl);const i=Date.now();r(`livePosts(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["post","collection",{targetId:e.targetId,targetType:e.targetType}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["post","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];i=$e(i,"isDeleted",e.isDeleted);const s=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===s?Qe:Ke),e.tags&&(i=i.filter((t=>{var n;return null===(n=t.tags)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.tags)||void 0===n?void 0:n.includes(t)}))}))),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;e.targetId===t.targetId&&e.targetType===t.targetType&&o&&("onCreate"===n?o.data=[...new Set([t.postId,...o.data])]:["onDelete","onDeclined"].includes(n)&&(o.data=o.data.filter((e=>e!==t.postId)),e.isDeleted&&o.data.unshift(t.postId)),De(f,o),h(o))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(tf,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}}));fe(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(Q("post"))])]),De(f,o),h(o)}),ue(l))};return u.push(Sf((e=>d(e,"onCreate"))),Of((e=>d(e,"onApproved"))),If((e=>d(e,"onDeclined"))),Ef((e=>d(e,"onDelete"))),Af((e=>d(e,"onUpdate"))),Tf((e=>d(e,"onFlagged"))),xf((e=>d(e,"onUnflagged"))),Pf((e=>d(e,"onReactionAdded"))),Rf((e=>d(e,"onReactionRemoved")))),p(),()=>{r(`livePosts(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveReactions=(e,t,n)=>{const{log:r,cache:o}=ve();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=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["reaction","collection",{referenceId:e.referenceId,referenceType:e.referenceType}],h=e=>{var n,r;const o=null!==(n=e.data.map((e=>Ue(["reaction","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[];t({onNextPage:p,data:o,hasNextPage:!!(null===(r=e.params)||void 0===r?void 0:r.page),loading:e.loading,error:e.error})},d=(e,t)=>{var n;const r=null===(n=Ue(f))||void 0===n?void 0:n.data;r&&("onAdded"===t?r.data=[...new Set([e.reactionId,...r.data])]:"onRemoved"===t&&(r.data=r.data.filter((t=>t!==e.reactionId))),De(f,r),h(r))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(_f,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}}));fe(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(Q("reaction"))])]),De(f,o),h(o)}),ue(l))};return u.push(qf(a.referenceType,a.referenceId,(e=>d(e,"onAdded"))),zf(a.referenceType,a.referenceId,(e=>d(e,"onRemoved")))),p(),()=>{r(`liveReactions(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveUser=(e,t)=>{const{log:n,cache:r}=ve();let o;r||console.log(Yl);const i=Date.now();n(`liveUser(tmpid: ${i}) > listen`);const s=[],a=e=>{var n;o&&(null===(n=e.data)||void 0===n?void 0:n.updatedAt)===(null==o?void 0:o.updatedAt)&&"server"!==e.origin||(t(e),o=e.data)},c=(e,t)=>{a({loading:!1,data:e,origin:"event"})};return s.push(Hl((e=>c(e))),Vl((e=>c(e))),Nl((e=>c(e))),Wl((e=>c(e))),Kl((e=>c(e))),Ql((e=>c(e)))),(()=>{const t=le(Ll,e,!0);fe(t,(({loading:e,data:t,error:n,origin:r})=>{a({loading:e,data:t,origin:r,error:n}),n&&s.forEach((e=>e()))}))})(),()=>{n(`liveUser(tmpid: ${i}) > dispose`),s.forEach((e=>e()))}},e.mergeInCache=Le,e.observeChannel=(e,t)=>{const{log:n}=ve(),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(Gf((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),Yf((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),Xf((e=>o({data:e,loading:!1,origin:"event"},"onJoin"))),Zf((e=>o({data:e,loading:!1,origin:"event"},"onLeft"))),eh((e=>o({data:e,loading:!1,origin:"event"},"onMemberAdded"))),th((e=>o({data:e,loading:!1,origin:"event"},"onMemberRemoved"))),oh((e=>o({data:e,loading:!1,origin:"event"},"onRead")))),fe(le(Kf,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeChannel(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}},e.observeChannels=e=>{const{log:t}=ve(),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(Jf((e=>o(e,"onCreate"))),Gf((e=>o(e,"onUpdate"))),Yf((e=>o(e,"onDelete"))),Xf((e=>o(e,"onJoin"))),Zf((e=>o(e,"onLeft"))),eh((e=>o(e,"onMemberAdded"))),th((e=>o(e,"onMemberRemoved"))),oh((e=>o(e,"onRead")))),()=>{t(`observeChannels(tmpid: ${n}) > dispose`),r.forEach((e=>e()))}},e.observeComment=(e,t,n="cache_then_server")=>{const{log:r}=ve(),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(Ff((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Bf((e=>s({data:e,loading:!1,origin:"event"},"onDelete"))),Mf((e=>s({data:e,loading:!1,origin:"event"},"onFlagged"))),Uf((e=>s({data:e,loading:!1,origin:"event"},"onUnflagged"))),Df((e=>s({data:e,loading:!1,origin:"event"},"onReactionAdded"))),Lf((e=>s({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),fe(le(vf,e),(e=>(e.data||e.error)&&i(e,"onFetch")),ue(n)),()=>{r(`observeComment(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},e.observeComments=(e,t)=>{const{log:n}=ve(),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(Nf((e=>i(e,"onCreate"))),Ff((e=>i(e,"onUpdate"))),Bf((e=>i(e,"onDelete"))),Mf((e=>i(e,"onFlagged"))),Uf((e=>i(e,"onUnflagged"))),Df((e=>i(e,"onReactionAdded"))),Lf((e=>i(e,"onReactionRemoved")))),()=>{n(`observeComments(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeCommunity=(e,t)=>{const{log:n}=ve(),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(dh((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),ph((e=>i({data:e,loading:!1,origin:"event"},"onDelete"))),gh((e=>i({data:e,loading:!1,origin:"event"},"onJoin"))),mh((e=>i({data:e,loading:!1,origin:"event"},"onLeft"))),yh((e=>i({data:e,loading:!1,origin:"event"},"onUserAdded"))),vh((e=>i({data:e,loading:!1,origin:"event"},"onUserRemoved"))),bh((e=>i({data:e,loading:!1,origin:"event"},"onUserBanned"))),wh((e=>i({data:e,loading:!1,origin:"event"},"onUserUnbanned")))),fe(le(uf,e),(e=>(e.data||e.error)&&o(e,"onFetch"))),()=>{n(`observeCommunity(tmpid: ${r}) > dispose`),s.forEach((e=>e()))}},e.observeFile=(e,t)=>{const{log:n}=ve(),r=Date.now();n(`observeFile(tmpid: ${r}) > listen`);return fe(le(Xl,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`)}},e.observeFollowInfo=(e,t,n="cache_then_server")=>{const{log:r}=ve(),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(Mh((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")))),fe(le(Ih,e),(e=>(e.data||e.error)&&i(e,"onFetch")),ue(n)),()=>{r(`observeFollowInfo(tmpid: ${o}) > dispose`),s.forEach((e=>e()))}},e.observeFollowers=(e,t)=>{const{log:n}=ve(),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(jh((e=>i(e,"onRequested"))),Fh((e=>i(e,"onAccepted"))),Bh((e=>i(e,"onDeclined"))),Nh((e=>i(e,"onCanceled"))),xh((e=>i(e,"onFollowed"))),Ph((e=>i(e,"onUnfollowed"))),Rh((e=>i(e,"onDeleted")))),()=>{n(`observeFollowers(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeFollowings=(e,t)=>{const{log:n}=ve(),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(jh((e=>i(e,"onRequested"))),Fh((e=>i(e,"onAccepted"))),Bh((e=>i(e,"onDeclined"))),Nh((e=>i(e,"onCanceled"))),xh((e=>i(e,"onFollowed"))),Ph((e=>i(e,"onUnfollowed"))),Rh((e=>i(e,"onDeleted")))),()=>{n(`observeFollowings(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeMessage=(e,t,n="cache_then_server")=>{const{log:r}=ve(),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(sh((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),ah((e=>i({data:e,loading:!1,origin:"event"},"onDelete")))),"no_fetch"!==n&&fe(le(nu,e),(e=>e.data&&i(e,"onFetch")),ue(n)),()=>{r(`observeMessages(tmpid: ${o}) > dispose`),s.forEach((e=>e()))}},e.observeMessages=(e,t)=>{const{log:n}=ve(),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.channelId)===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(ih((e=>i({data:e,loading:!1,origin:"event"},"onCreate"))),sh((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),ah((e=>i({data:e,loading:!1,origin:"event"},"onDelete")))),()=>{n(`observeMessages(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observePoll=(e,t,n="cache_then_server")=>{const{log:r}=ve(),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(Dh((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Lh((e=>s({data:e,loading:!1,origin:"event"},"onDelete")))),fe(le(Uh,e),(e=>(e.data||e.error)&&i(e,"onFetch")),ue(n)),()=>{r(`observePoll(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},e.observePost=(e,t,n="cache_then_server")=>{const{log:r}=ve(),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(Af((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Ef((e=>s({data:e,loading:!1,origin:"event"},"onDelete"))),Of((e=>s({data:e,loading:!1,origin:"event"},"onApproved"))),If((e=>s({data:e,loading:!1,origin:"event"},"onDeclined"))),Tf((e=>s({data:e,loading:!1,origin:"event"},"onFlagged"))),xf((e=>s({data:e,loading:!1,origin:"event"},"onUnflagged"))),Pf((e=>s({data:e,loading:!1,origin:"event"},"onReactionAdded"))),Rf((e=>s({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),fe(le(rf,e),(e=>(e.data||e.error)&&i(e,"onFetch")),ue(n)),()=>{r(`observePosts(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},e.observePosts=(e,t)=>{const{log:n}=ve(),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(Sf((e=>i(e,"onCreate"))),Af((e=>i(e,"onUpdate"))),Ef((e=>i(e,"onDelete"))),Of((e=>i(e,"onApproved"))),If((e=>i(e,"onDeclined"))),Tf((e=>i(e,"onFlagged"))),xf((e=>i(e,"onUnflagged"))),Pf((e=>i(e,"onReactionAdded"))),Rf((e=>i(e,"onReactionRemoved")))),()=>{n(`observePosts(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeUser=(e,t)=>{const{log:n}=ve(),r=Date.now();n(`observeUser(tmpid: ${r}) > listen`),console.log("observeUser will be deprecated on 25th November 2022, please use liveUser instead.");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(Vl((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),Nl((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),Wl((e=>o({data:e,loading:!1,origin:"event"},"onFlagged"))),Kl((e=>o({data:e,loading:!1,origin:"event"},"onUnflagged"))),Ql((e=>o({data:e,loading:!1,origin:"event"},"onFlagCleared")))),fe(le(Ll,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeUser(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}},e.onChannelCreated=Jf,e.onChannelDeleted=Yf,e.onChannelJoined=Xf,e.onChannelLeft=Zf,e.onChannelMemberAdded=eh,e.onChannelMemberBanned=nh,e.onChannelMemberRead=oh,e.onChannelMemberRemoved=th,e.onChannelMemberUnbanned=rh,e.onChannelUpdated=Gf,e.onClientBanned=Ml,e.onClientDisconnected=e=>Bl((({code:t})=>{800211===t&&e()})),e.onCommentCreated=Nf,e.onCommentDeleted=Bf,e.onCommentFlagged=Mf,e.onCommentReactionAdded=Df,e.onCommentReactionRemoved=Lf,e.onCommentUnflagged=Uf,e.onCommentUpdated=Ff,e.onCommunityCreated=e=>lh("community.created",e),e.onCommunityDeleted=ph,e.onCommunityJoined=gh,e.onCommunityLeft=mh,e.onCommunityUpdated=dh,e.onCommunityUserAdded=yh,e.onCommunityUserBanned=bh,e.onCommunityUserRemoved=vh,e.onCommunityUserUnbanned=wh,e.onConnectionError=Bl,e.onFollowInfoUpdated=Mh,e.onFollowRequestAccepted=Fh,e.onFollowRequestCanceled=Nh,e.onFollowRequestDeclined=Bh,e.onFollowerDeleted=Rh,e.onFollowerRequested=jh,e.onMessageCreated=ih,e.onMessageDeleted=ah,e.onMessageFetched=ch,e.onMessageUpdated=sh,e.onPollDeleted=Lh,e.onPollUpdated=Dh,e.onPostApproved=Of,e.onPostCreated=Sf,e.onPostDeclined=If,e.onPostDeleted=Ef,e.onPostFlagged=Tf,e.onPostReactionAdded=Pf,e.onPostReactionRemoved=Rf,e.onPostUnflagged=xf,e.onPostUpdated=Af,e.onReactionAdded=(e,t,n)=>{const r=r=>{Q(e)(r)===t&&n(r)};if("message"===e){const e=ve(),t=e=>{var t;const n=Ue(["message","get",e.messages[0].messageId]),o=(null===(t=null==n?void 0:n.data)||void 0===t?void 0:t.reactionsCount)!==e.messages[0].reactionsCount;Rl(e),o&&r(e.messages[0])};return et(e,"reaction/onReactionAdded","v3.message.didUpdate",t)}return"post"===e?Pf(r):Df(r)},e.onReactionRemoved=(e,t,n)=>{const r=r=>{Q(e)(r)===t&&n(r)};if("message"===e){const e=ve(),t=e=>{var t;const n=Ue(["message","get",e.messages[0].messageId]),o=(null===(t=null==n?void 0:n.data)||void 0===t?void 0:t.reactionsCount)!==e.messages[0].reactionsCount;Rl(e),o&&r(e.messages[0])};return et(e,"reaction/onReactionRemoved","v3.message.didUpdate",t)}return"post"===e?Rf(r):Lf(r)},e.onReactorAdded=qf,e.onReactorRemoved=zf,e.onStreamRecorded=e=>{const t=ve();return et(t,"stream/onStreamRecorded","video-streaming.didRecord",(t=>{Rl(t),e(t.videoStreamings[0])}))},e.onStreamStarted=e=>{const t=ve();return et(t,"stream/onStreamStarted","video-streaming.didStart",(t=>{Rl(t),e(t.videoStreamings[0])}))},e.onStreamStopped=e=>{const t=ve();return et(t,"stream/onStreamStarted","video-streaming.didStop",(t=>{Rl(t),e(t.videoStreamings[0])}))},e.onUserDeleted=Nl,e.onUserFetched=Hl,e.onUserFlagCleared=Ql,e.onUserFlagged=Wl,e.onUserFollowed=xh,e.onUserUnflagged=Kl,e.onUserUnfollowed=Ph,e.onUserUpdated=Vl,e.pullFromCache=Ue,e.pushToCache=De,e.queryCache=Me,e.queryCategories=Ch,e.queryChannelMembers=Qf,e.queryChannels=Vf,e.queryComments=mf,e.queryCommunities=cf,e.queryCommunityMembers=df,e.queryFollowers=Ah,e.queryFollowings=Eh,e.queryGlobalFeed=kh,e.queryMessages=ou,e.queryOptions=ue,e.queryPosts=tf,e.queryReactions=_f,e.queryRoles=Zl,e.queryStreams=zh,e.queryUsers=$l,e.removeChannelMembers=async(e,t)=>{const n=ve();n.log("channel/removeChannelMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/channels/${encodeURIComponent(e)}/users`,{data:{channelId:e,userIds:t}}),o=Hf(r);n.cache&&Rl(o),t.forEach((e=>tt("v3.channel.didRemoveUsers",Object.assign(Object.assign({},o),{channelUsers:o.channelUsers.filter((t=>t.userId===e))}))));const{channelUsers:i}=o;return!!i.find((t=>t.channelId===e&&"member"!==t.membership))},e.removeChannelMembersRole=async(e,t,n)=>{const r=ve();r.log("channel/removeChannelMembersRole",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=Hf(o);r.cache&&Rl(i);const{channelUsers:s}=i;return!!s.find((n=>n.channelId===e&&!n.roles.includes(t)))},e.removeCommunityMembers=async(e,t)=>{const n=ve();n.log("community/removeCommunityMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/communities/${e}/users`,{data:{communityId:e,userIds:t}});n.cache&&Rl(r),tt("community.userRemoved",r);const{communityUsers:o}=r;return!!o.find((t=>t.communityId===e&&"member"!==t.communityMembership))},e.removeCommunityMembersRoles=async(e,t,n)=>{const r=ve();r.log("community/removeCommunityMembersRoles",e,t,n);const{data:o}=await r.http.delete(`/api/v4/communities/${e}/users/roles`,{data:{communityId:e,roles:t,userIds:n}});r.cache&&Rl(o);const{communityUsers:i}=o;return!!i.find((n=>n.communityId===e&&!t.some((e=>n.roles.includes(e)))))},e.removeReaction=Cf,e.restoreCache=async(e="amitySdk")=>{var t;const n=ve();if(!n.cache)return!1;n.log("cache/api/restoreCache",{storageKey:e});const r=null!==(t=await Be.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=fe,e.sortByChannelSegment=({channelSegment:e},{channelSegment:t})=>e-t,e.sortByDisplayName=We,e.sortByFirstCreated=Ke,e.sortByLastActivity=({lastActivity:e},{lastActivity:t})=>new Date(t).valueOf()-new Date(e).valueOf(),e.sortByLastCreated=Qe,e.sortBySegmentNumber=({segmentNumber:e},{segmentNumber:t})=>e-t,e.startReading=async(e,t=ve().userId)=>{const n=ve();n.log("message/startReading",{channelId:e});return!!await _l(n,"channel.startReading",{channelId:e})},e.stopReading=async e=>{const t=ve();t.log("message/stopReading",{channelId:e});return!!await _l(t,"channel.stopReading",{channelId:e})},e.subscribeTopic=lt,e.toPage=V,e.toPageRaw=W,e.toToken=H,e.unbanChannelMembers=async(e,t)=>{const n=ve();n.log("channel/unbanChannelMembers",{userIds:t,channelId:e});const{data:r}=await n.http.put(`/api/v3/channels/${encodeURIComponent(e)}/users/unban`,{userIds:t}),o=Hf(r),i=hf(o,"channelUsers"),s=n.cache&&Date.now();n.cache&&Rl(i,{cachedAt:s});const{channelUsers:a}=i;return{data:null==a?void 0:a.filter((e=>"member"===e.membership)),cachedAt:s}},e.unfollow=async e=>{const t=ve();t.log("follow/unfollow",e);const{data:n}=await t.http.delete(`/api/v4/me/following/${e}`);return t.cache&&Rl(n),tt("follow.unfollowed",n),!0},e.updateChannel=async(e,t)=>{const n=ve();n.log("channel/updateChannel",e,t);const{data:r}=await n.http.put(`/api/v3/channels/${encodeURIComponent(e)}`,t),o=Hf(r),i=n.cache&&Date.now();n.cache&&Rl(o,{cachedAt:i});const{channels:s}=o;return{data:s.find((t=>t.channelId===e)),cachedAt:i}},e.updateComment=async(e,t)=>{const n=ve();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&&Rl(r,{cachedAt:o}),tt("comment.updated",r);const{comments:i}=r;return{data:i.find((t=>t.commentId===e)),cachedAt:o}},e.updateCommunity=async(e,t)=>{const n=ve();n.log("community/updateCommunity",e,t);const{data:r}=await n.http.put(`/api/v3/communities/${e}`,af(t)),o=sf(r),i=n.cache&&Date.now();n.cache&&Rl(o,{cachedAt:i}),tt("community.updated",o);const{communities:s}=o;return{data:s.find((t=>t.communityId===e)),cachedAt:i}},e.updateMessage=Zu,e.updatePost=async(e,t)=>{const n=ve();n.log("user/updatePost",t);const{data:r}=await n.http.put(`/api/v4/posts/${encodeURIComponent(e)}`,t),o=n.cache&&Date.now();n.cache&&Rl(r,{cachedAt:o}),tt("post.updated",r);const{posts:i}=r;return{data:i.find((t=>t.postId===e)),cachedAt:o}},e.updateStream=async(e,t)=>{const n=ve();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&&Rl(r,{cachedAt:o});const{videoStreamings:i}=r;return{data:i.find((t=>t.streamId===e)),cachedAt:o}},e.updateUser=async(e,t)=>{const n=ve();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&&Rl(r,{cachedAt:o});const{users:i}=r;return tt("user.updated",r),{data:i.find((t=>t.userId===e)),cachedAt:o}},e.upsertInCache=qe,e.votePoll=async(e,t)=>{const n=ve();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&&Rl(r,{cachedAt:o});const{polls:i}=r;return tt("poll.updated",r),{data:i.find((t=>t.pollId===e)),cachedAt:o}},e.wipeCache=async(e="amitySdk")=>{const{log:t,cache:n,userId:r}=ve();return!!n&&(t("cache/api/wipeCache",{storageKey:e}),n.data={},await Be.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=f,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 f(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 d(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=d,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),f=["%","/","?",";","#"].concat(u),h=["/","?","#"],d=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 A="//"===C.substr(0,2);!A||k&&y[k]||(C=C.substr(2),this.slashes=!0)}if(!y[k]&&(A||k&&!v[k])){for(var E,O,I=-1,T=0;T<h.length;T++)-1!==(x=C.indexOf(h[T]))&&(-1===I||x<I)&&(I=x);for(-1!==(O=-1===I?C.lastIndexOf("@"):C.lastIndexOf("@",I))&&(E=C.slice(0,O),C=C.slice(O+1),this.auth=decodeURIComponent(E)),I=-1,T=0;T<f.length;T++){var x;-1!==(x=C.indexOf(f[T]))&&(-1===I||x<I)&&(I=x)}-1===I&&(I=C.length),this.host=C.slice(0,I),C=C.slice(I),this.parseHost(),this.hostname=this.hostname||"";var P="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!P)for(var R=this.hostname.split(/\./),j=(T=0,R.length);T<j;T++){var N=R[T];if(N&&!N.match(p)){for(var F="",B=0,M=N.length;B<M;B++)N.charCodeAt(B)>127?F+="x":F+=N[B];if(!F.match(p)){var U=R.slice(0,T),D=R.slice(T+1),L=N.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>d?this.hostname="":this.hostname=this.hostname.toLowerCase(),P||(this.hostname=r.toASCII(this.hostname));var q=this.port?":"+this.port:"",z=this.hostname||"";this.host=z+q,this.href+=this.host,P&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==C[0]&&(C="/"+C))}if(!m[S])for(T=0,j=u.length;T<j;T++){var $=u[T];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 f=Object.keys(e),h=0;h<f.length;h++){var d=f[h];n[d]=e[d]}return n.href=n.format(),n}if(n.protocol=e.protocol,e.host||y[e.protocol])n.pathname=e.pathname;else{for(var p=(e.pathname||"").split("/");p.length&&!(e.host=p.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==p[0]&&p.unshift(""),p.length<2&&p.unshift(""),n.pathname=p.join("/")}if(n.search=e.search,n.query=e.query,n.host=e.host||"",n.auth=e.auth,n.hostname=e.hostname||e.host,n.port=e.port,n.pathname||n.search){var g=n.pathname||"",m=n.search||"";n.path=g+m}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var b=n.pathname&&"/"===n.pathname.charAt(0),w=e.host||e.pathname&&"/"===e.pathname.charAt(0),C=w||b||n.host&&e.pathname,_=C,k=n.pathname&&n.pathname.split("/")||[],S=(p=e.pathname&&e.pathname.split("/")||[],n.protocol&&!v[n.protocol]);if(S&&(n.hostname="",n.port=null,n.host&&(""===k[0]?k[0]=n.host:k.unshift(n.host)),n.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===p[0]?p[0]=e.host:p.unshift(e.host)),e.host=null),C=C&&(""===p[0]||""===k[0])),w)n.host=e.host||""===e.host?e.host:n.host,n.hostname=e.hostname||""===e.hostname?e.hostname:n.hostname,n.search=e.search,n.query=e.query,k=p;else if(p.length)k||(k=[]),k.pop(),k=k.concat(p),n.search=e.search,n.query=e.query;else if(!o.isNullOrUndefined(e.search))return S&&(n.hostname=n.host=k.shift(),(T=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=T.shift(),n.host=n.hostname=T.shift())),n.search=e.search,n.query=e.query,o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n;if(!k.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var A=k.slice(-1)[0],E=(n.host||e.host||k.length>1)&&("."===A||".."===A)||""===A,O=0,I=k.length;I>=0;I--)"."===(A=k[I])?k.splice(I,1):".."===A?(k.splice(I,1),O++):O&&(k.splice(I,1),O--);if(!C&&!_)for(;O--;O)k.unshift("..");!C||""===k[0]||k[0]&&"/"===k[0].charAt(0)||k.unshift(""),E&&"/"!==k.join("/").substr(-1)&&k.push("");var T,x=""===k[0]||k[0]&&"/"===k[0].charAt(0);return S&&(n.hostname=n.host=x?"":k.length?k.shift():"",(T=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=T.shift(),n.host=n.hostname=T.shift())),(C=C||n.host&&k.length)&&!x&&k.unshift(""),k.length?n.pathname=k.join("/"):(n.pathname=null,n.path=null),o.isNull(n.pathname)&&o.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},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!==we?we:"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)}(Sl);var Al=Ce(Sl.exports);var El;!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"}(El||(El={}));const Ol=e=>{let t,n=0,r=!0;return{connect:async function(o){return t&&(t.removeAllListeners(),t.end(!0)),t=Al.connect(e,function(e){return Object.assign({clean:!1,clientId:`mqttjs_ + ${Math.random().toString(16).substr(2,8)}`,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 de(t.message,8e5,"error"):new ge(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)}}},Il=async()=>{const e=ve(),{data:t}=await e.http.get("/api/v3/network-settings/feed-setting");return Object.fromEntries(t.feedSettings.map((({feedType:e,contentSettings:t})=>[e,t])))},Tl=async()=>{const e=ve();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.accessToken=void 0,!e.ws.connected},xl=()=>`ascWebSdk#${Math.random().toString(16)}`,Pl=()=>{const e=(()=>{var e,t;return(null===(e=d.versions)||void 0===e?void 0:e.node)?d.versions.node:navigator?`${navigator.product.toLowerCase()}#${null!==(t=navigator.userAgent)&&void 0!==t?t:"unknown_agent"}`:"unknown_model"})();return{version:"11.0.0",kind:"web",model:e}},Rl=(e={},t)=>{Object.entries(e).forEach((([e,n])=>{const r=Y[e];if(!r)return;const o=Q(r);n.forEach((e=>{qe([r,"get",o(e)],e,t)}))}))},jl=(e,t)=>{const n=ve();return et(n,e,e,(e=>{n.cache&&Rl(e),t(e.users[0])}))},Nl=e=>jl("user.deleted",e),Fl=["disconnected","error","connect_error","reconnect_error","reconnect_failed"],Bl=e=>{const t=ve(),n=Fl.map((n=>et(t,`client/onConnectionError(${n})`,n,(t=>{const r=(null==t?void 0:t.code)?new de(t.message,t.code,"fatal"):new me(n);e(r)}))));return()=>{n.forEach((e=>e()))}},Ml=e=>Bl((({code:t})=>{400312===t&&e()})),Ul=(e,t)=>{const{log:n,cache:r}=ve(),o=[e,X,t];if(!r)return;n("cache/api/isInTombstone",o);const i=Ue(o),{lifeSpan:s}=ue("cache_then_server",18e4);if(i&&ce(i.data,s))throw new pe("Item not found!",400400,"error")},Dl=(e,t)=>{const{log:n,cache:r}=ve(),o=[e,X,t],i={cachedAt:Date.now()};r&&(n("cache/api/pushToTombstone",{cacheKey:o,data:i}),ze([e,"get",t],!0),De(o,i))},Ll=async(e,t=!1)=>{const n=ve();let r;n.log("user/getUser",e),t||console.log("getUser will be deprecated on 25th November 2022, please use liveUser instead."),Ul("user",e);try{r=(await n.http.get(`/api/v3/users/${encodeURIComponent(e)}`)).data}catch(t){throw re(null==t?void 0:t.code)&&Dl("user",e),t}const o=n.cache&&Date.now();n.cache&&Rl(r,{cachedAt:o});const{users:i}=r;return tt("user.fetched",r),{data:i.find((t=>t.userId===e)),cachedAt:o}};Ll.locally=e=>{const t=ve();return t.log("user/getUser.locally",e),t.cache&&Ue(["user","get",e])};const ql=async e=>{const t=ve();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&&Rl(r,{cachedAt:o}),tt("user.fetched",r),{data:r.users,cachedAt:o}};function zl(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}ql.locally=e=>{var t;const n=ve();if(n.log("user/getUsers.locally",e),!n.cache)return;const r=e.map((e=>Ue(["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 $l=async(e={})=>{const t=ve();t.log("user/queryUsers",e);const{page:n={limit:10},displayName:r,filter:o="all",sortBy:i="displayName"}=e,s=zl(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:H(n,"skiplimit")}})}),{paging:c}=a,l=zl(a,["paging"]),{users:u}=l,f=t.cache&&Date.now();if(t.cache){Rl(l,{cachedAt:f});const t=["user","query",Object.assign(Object.assign({},e),{options:Object.assign({},n)})];De(t,{users:u.map(Q("user")),paging:c})}tt("user.fetched",a);return{data:u,cachedAt:f,prevPage:V(c.previous),nextPage:V(c.next)}};$l.locally=(e={})=>{var t,n,r;const o=ve();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=Ue(s))&&void 0!==t?t:{},l=null!==(n=null==a?void 0:a.users.map((e=>Ue(["user","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[],u=V(null==a?void 0:a.paging.previous),f=V(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:f}:void 0};const Hl=e=>jl("user.fetched",e),Vl=e=>jl("user.updated",e),Wl=e=>jl("user.flagged",e),Kl=e=>jl("user.unflagged",e),Ql=e=>jl("user.flagCleared",e),Jl="cache_then_server",Gl="For using Live Collection feature you need to enable Cache!",Yl="For using Live Object feature you need to enable Cache!",Xl=async e=>{const t=ve();t.log("file/getFile",e);const{data:n}=await t.http.get(`/api/v3/files/${e}`),r=t.cache&&Date.now();return t.cache&&Rl({files:[n]},{cachedAt:r}),{data:n,cachedAt:r}};Xl.locally=e=>{const t=ve();if(t.log("file/getFile.locally",e),!t.cache)return;const n=Ue(["file","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Zl=async e=>{const t=ve();t.log("role/queryRoles",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,sortBy:i}=n,s=zl(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:H(r,"skiplimit")}})}),{paging:c}=a,l=zl(a,["paging"]),{roles:u}=l,f=t.cache&&Date.now();t.cache&&Rl(l,{cachedAt:f});const h=V(c.next);return{data:u,cachedAt:f,prevPage:V(c.previous),nextPage:h}};Zl.locally=e=>{ve().log("role/queryRoles.locally",e)};const eu=async e=>{const t=ve();t.log("role/getRole",e);const{data:n}=await t.http.get(`/api/v3/roles/${e}`),r=t.cache&&Date.now();return t.cache&&Rl({roles:n},{cachedAt:r}),{data:n.find((t=>t.roleId===e)),cachedAt:r}};eu.locally=e=>{const t=ve();if(t.log("role/getRole.locally",e),!t.cache)return;const n=Ue(["role","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const tu=(e,t)=>{"message"===e?tt("v3.message.didUpdate",{messages:[t]}):"post"===e?tt("post.updated",{posts:[t]}):"comment"===e&&tt("comment.updated",{comments:[t]})},nu=async(e,t=!1)=>{const n=ve();let r;n.log("message/getMessage",e),t||console.log("getMessage will be deprecated on 15th November 2022, please use liveMessage instead."),Ul("message",e);try{r=(await n.http.get(`/api/v3/messages/${encodeURIComponent(e)}`)).data}catch(t){throw re(null==t?void 0:t.code)&&Dl("message",e),t}const o=n.cache&&Date.now();n.cache&&Rl(r,{cachedAt:o});const{messages:i}=r;return tt("v3.message.didFetch",{messages:i}),{data:i.find((t=>t.messageId===e)),cachedAt:o}};nu.locally=e=>{const t=ve();if(t.log("message/getMessage.locally",e),!t.cache)return;const n=Ue(["message","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const ru=async e=>{const t=ve();t.log("message/getMessages",e);const{data:n}=await t.http.get("/api/v3/messages/list",{params:{messageIds:e}}),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{messages:o}=n;return tt("v3.message.didFetch",{messages:o}),{data:o,cachedAt:r}};ru.locally=e=>{var t;const n=ve();if(n.log("message/getMessages.locally",e),!n.cache)return;const r=e.map((e=>Ue(["message","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 ou=async e=>{const t=ve();t.log("message/queryMessages",e);const{page:n={limit:10}}=e,r=zl(e,["page"]),{data:o}=await t.http.get("/api/v3/messages",{params:Object.assign(Object.assign({},r),{options:{token:H(n,"afterbefore")}})}),{paging:i}=o,s=zl(o,["paging"]),{messages:a}=s,c=t.cache&&Date.now();if(t.cache){Rl(s,{cachedAt:c});const e=["message","query",Object.assign(Object.assign({},r),{options:Object.assign({},n)})];De(e,{messages:a.map(Q("message")),paging:i})}tt("v3.message.didFetch",{messages:a});const l=V(i.next);return{data:a,cachedAt:c,prevPage:V(i.previous),nextPage:l}};ou.locally=e=>{var t,n;const r=ve();if(r.log("message/queryMessages.locally",e),!r.cache)return;const{page:o={limit:10}}=e,i=zl(e,["page"]),s=["message","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Ue(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.messages.length))return;const l=a.messages.map((e=>Ue(["message","get",e]))).filter(Boolean).map((({data:e})=>e)),u=V(null==a?void 0:a.paging.previous),f=V(null==a?void 0:a.paging.next);return l.length===(null===(n=null==a?void 0:a.messages)||void 0===n?void 0:n.length)?{data:l,cachedAt:c,prevPage:u,nextPage:f}:void 0};var iu={},su={},au={};Object.defineProperty(au,"__esModule",{value:!0}),au.bytesToString=au.stringToBytes=au.NIL=au.X500=au.OID=au.URL=au.DNS=au.hexToByte=au.byteToHex=void 0;let cu=[],lu={};for(var uu=0;uu<256;uu++)cu[uu]=(uu+256).toString(16).substr(1),lu[cu[uu]]=uu;au.byteToHex=cu,au.hexToByte=lu,au.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",au.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",au.OID="6ba7b812-9dad-11d1-80b4-00c04fd430c8",au.X500="6ba7b814-9dad-11d1-80b4-00c04fd430c8",au.NIL="00000000-0000-0000-0000-000000000000";au.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};au.bytesToString=e=>{const t=new Uint8Array(e,0,e.byteLength);return String.fromCharCode.apply(null,Array.from(t))},Object.defineProperty(su,"__esModule",{value:!0}),su.parse=void 0;const fu=au;su.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++]=fu.hexToByte[e]),"")));o<16;)t[r+o++]=0;return t};var hu={};Object.defineProperty(hu,"__esModule",{value:!0}),hu.unparse=void 0;const du=au;hu.unparse=(e,t)=>{let n=t||0,r=du.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 pu={},gu={};Object.defineProperty(gu,"__esModule",{value:!0});gu.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 mu=we&&we.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(pu,"__esModule",{value:!0}),pu.validate=void 0;const yu=mu(gu);pu.validate=e=>"string"==typeof e&&yu.default.test(e);var vu={};Object.defineProperty(vu,"__esModule",{value:!0}),vu.version=void 0;const bu=pu;vu.version=e=>{if(!bu.validate(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)};var wu={},Cu={};Object.defineProperty(Cu,"__esModule",{value:!0}),Cu.stringify=void 0;const _u=pu,ku=[];for(let e=0;e<256;++e)ku.push((e+256).toString(16).substr(1));Cu.stringify=(e,t=0)=>{const n=(ku[e[t+0]]+ku[e[t+1]]+ku[e[t+2]]+ku[e[t+3]]+"-"+ku[e[t+4]]+ku[e[t+5]]+"-"+ku[e[t+6]]+ku[e[t+7]]+"-"+ku[e[t+8]]+ku[e[t+9]]+"-"+ku[e[t+10]]+ku[e[t+11]]+ku[e[t+12]]+ku[e[t+13]]+ku[e[t+14]]+ku[e[t+15]]).toLowerCase();if(!_u.validate(n))throw TypeError("Stringified UUID is invalid");return n};var Su={};Object.defineProperty(Su,"__esModule",{value:!0}),Su.rng=void 0;Su.rng=()=>{let e=new Array(16);for(let t=0;t<16;t++)e[t]=255&256*Math.random()+0;return e},Object.defineProperty(wu,"__esModule",{value:!0}),wu.v1=void 0;const Au=Cu,Eu=Su;let Ou,Iu,Tu=0,xu=0;wu.v1=(e,t,n=0)=>{let r=t&&n||0;const o=t||new Uint8Array(16);let i=e&&e.node?e.node:Ou,s=e&&e.clockseq?e.clockseq:Iu;if(null==i||null==s){const t=e&&e.random?e.random:e&&e.rng?e.rng():Eu.rng();null==i&&(i=Ou=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==s&&(s=Iu=16383&(t[6]<<8|t[7]))}let a=e&&e.msecs?e.msecs:Date.now(),c=e&&e.nsecs?e.nsecs:xu+1;const l=a-Tu+(c-xu)/1e4;if(l<0&&e&&!e.clockseq&&(s=s+1&16383),(l<0||a>Tu)&&e&&!e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");Tu=a,xu=c,Iu=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 f=a/4294967296*1e4&268435455;o[r++]=f>>>8&255,o[r++]=255&f,o[r++]=f>>>24&15|16,o[r++]=f>>>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||Au.stringify(o)};var Pu={};Object.defineProperty(Pu,"__esModule",{value:!0}),Pu.v4=void 0;const Ru=hu,ju=Su;Pu.v4=(e,t,n)=>{let r=t&&n||0,o=ju.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||Ru.unparse(o)};var Nu={},Fu={};Object.defineProperty(Fu,"__esModule",{value:!0}),Fu.v35=void 0;const Bu=Cu,Mu=su,Uu=au;Fu.v35=(e,t,n)=>(e,r,o,i=0)=>{if("string"==typeof e&&(e=Uu.stringToBytes(e)),"string"==typeof r&&(r=Mu.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=Uu.stringToBytes(n(Uu.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||Bu.stringify(s)};var Du={};!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(f(l(e),8*e.length)),o=(e,t)=>{let n=l(e);n.length>16&&(n=f(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=f(r.concat(l(t)),512+8*t.length);return u(f(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},f=(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,f=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]),d(v)));a=s,s=i,i=g(o,30),o=r,r=t}r=p(r,l),o=p(o,u),i=p(i,f),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,d=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}(Du);var Lu=we&&we.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Nu,"__esModule",{value:!0}),Nu.v5=void 0;const qu=Fu,zu=Lu(Du);Nu.v5=qu.v35("v5",80,zu.default),Object.defineProperty(iu,"__esModule",{value:!0});const $u=su,Hu=hu,Vu=pu,Wu=vu,Ku=wu,Qu=Pu,Ju=Nu,Gu=au;var Yu=iu.default={parse:$u.parse,unparse:Hu.unparse,validate:Vu.validate,version:Wu.version,v1:Ku.v1,v4:Qu.v4,v5:Ju.v5,NIL:Gu.NIL,DNS:Gu.DNS,URL:Gu.URL,OID:Gu.OID,X500:Gu.X500};const Xu=async e=>{const t=ve();t.log("user/createMessage",e);const{data:n}=await t.http.post("/api/v3/messages",e),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{messages:o}=n;return tt("v3.message.didCreate",{messages:o}),{data:o[0],cachedAt:r}};Xu.optimistically=e=>{var t,n;const r=ve();if(!r.cache)return;const o=Object.assign({messageId:Yu.v4().toString()},e);r.log("user/createMessage.locally",o);const i=Ue(["channel","get",o.channelId]);qe(["channel","get",o.channelId],Object.assign(Object.assign({},null==i?void 0:i.data),{messageCount:(null!==(t=null==i?void 0:i.data.messageCount)&&void 0!==t?t:0)+1}));const s=(new Date).toISOString(),a=Object.assign({userId:r.userId,channelSegment:(null!==(n=null==i?void 0:i.data.messageCount)&&void 0!==n?n:0)+1,createdAt:s,updatedAt:s},o);return De(["message","get",a.messageId],a,{cachedAt:-5}),tt("v3.message.didCreate",{messages:[a]}),{cachedAt:-5,data:a}};const Zu=async(e,t)=>{const n=ve();n.log("user/updateMessage",t);const{data:r}=await n.http.put(`/api/v3/messages/${encodeURIComponent(e)}`,t),o=n.cache&&Date.now();n.cache&&Rl(r,{cachedAt:o});const{messages:i}=r;return tt("v3.message.didUpdate",{messages:i}),{data:i.find((t=>t.messageId===e)),cachedAt:o}};Zu.optimistically=(e,t)=>{const n=ve();if(n.log("user/updateMessage",t),!n.cache)return;const r=Ue(["message","get",e]);if(!r)return;const o=Object.assign(Object.assign(Object.assign({},r.data),t),{updatedAt:(new Date).toISOString()});return qe(["message","get",e],o,{cachedAt:-1}),tt("v3.message.didUpdate",{messages:[o]}),{data:o,cachedAt:-1}};const ef=async e=>{const t=ve();t.log("message/deleteMessage",e),await t.http.delete(`/api/v3/messages/${encodeURIComponent(e)}`);const n=await nu(e);return tt("v3.message.didDelete",{messages:[n.data]}),n.data};ef.optimistically=e=>{ve().log("message/deleteMessage",e);const t=Ue(["message","get",e]);if(!t)return;const n=Object.assign(Object.assign({},t.data),{isDeleted:!0,updatedAt:(new Date).toISOString()});return qe(["message","get",e],n,{cachedAt:-1}),tt("v3.message.didDelete",{messages:[n]}),{data:n,cachedAt:-1}};const tf=async e=>{const t=ve();t.log("post/queryPosts",e);const{page:n={limit:10}}=e,r=zl(e,["page"]),{dataTypes:o,matchingOnlyParentPost:i}=r,{data:s}=await t.http.get("/api/v4/posts",{params:Object.assign(Object.assign({},r),{matchingOnlyParentPost:null!=i?i:!(null==o?void 0:o.length),options:{token:H(n,"afterbeforeraw")}})}),{paging:a}=s,c=zl(s,["paging"]),{posts:l}=c,u=t.cache&&Date.now();if(t.cache){Rl(c,{cachedAt:u});const e=["post","query",Object.assign(Object.assign({},r),{options:Object.assign({},n)})];De(e,{posts:l.map(Q("post")),paging:a})}const f=W(a.next);return{data:l,cachedAt:u,prevPage:W(a.previous),nextPage:f}};tf.locally=e=>{var t,n;const r=ve();if(r.log("post/queryPosts.locally",e),!r.cache)return;const{page:o={limit:10}}=e,i=zl(e,["page"]),s=["post","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Ue(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.posts.length))return;const l=a.posts.map((e=>Ue(["post","get",e]))).filter(Boolean).map((({data:e})=>e)),u=W(null==a?void 0:a.paging.previous),f=W(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:f}:void 0};const nf=async e=>{const t=ve();t.log("post/getPosts",e);const n=e.map((e=>encodeURIComponent(e))),{data:r}=await t.http.get("/api/v3/posts/list",{params:{postIds:n}}),o=t.cache&&Date.now();return t.cache&&Rl(r,{cachedAt:o}),{data:r.posts,cachedAt:o}};nf.locally=e=>{var t;const n=ve();if(n.log("post/getPosts.locally",e),!n.cache)return;const r=e.map((e=>Ue(["post","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 rf=async e=>{const t=ve();let n;t.log("post/getPost",e),Ul("post",e);try{n=(await t.http.get(`/api/v3/posts/${encodeURIComponent(e)}`)).data}catch(t){throw re(null==t?void 0:t.code)&&Dl("post",e),t}const r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{posts:o}=n;return{data:o.find((t=>t.postId===e)),cachedAt:r}};rf.locally=e=>{const t=ve();if(t.log("post/getPost.locally",e),!t.cache)return;const n=Ue(["post","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const of=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},sf=e=>{var{communities:t}=e,n=zl(e,["communities"]);return Object.assign({communities:t.map((e=>{var{needApprovalOnPostCreation:t,onlyAdminCanPost:n}=e,r=zl(e,["needApprovalOnPostCreation","onlyAdminCanPost"]);return Object.assign({postSetting:of({needApprovalOnPostCreation:t,onlyAdminCanPost:n})},r)}))},n)},af=e=>{var{postSetting:t}=e,r=zl(e,["postSetting"]);return Object.assign(Object.assign({},r),t?n[t]:void 0)},cf=async e=>{const t=ve();t.log("channel/queryCommunities",e);const n=null!=e?e:{},{page:r}=n,o=zl(n,["page"]),i=null!=o?o:{},{displayName:s,membership:a}=i,c=zl(i,["displayName","membership"]),{data:l}=await t.http.get("/api/v3/communities",{params:Object.assign(Object.assign({},c),{keyword:s,filter:a,options:{token:H(r,"skiplimit")}})}),{paging:u}=l,f=zl(l,["paging"]),h=sf(f),{communities:d}=h,p=t.cache&&Date.now();if(t.cache){Rl(h,{cachedAt:p});const e=["community","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];De(e,{communities:d.map(Q("community")),paging:u})}const g=V(u.next);return{data:d,cachedAt:p,prevPage:V(u.previous),nextPage:g}};cf.locally=e=>{ve().log("community/queryCommunities.locally",e)};const lf=async e=>{const t=ve();t.log("community/getCommunities",e);const{data:n}=await t.http.get("/api/v3/communities/list",{params:{communityIds:e}}),r=sf(n),o=t.cache&&Date.now();return t.cache&&Rl(r,{cachedAt:o}),{data:r.communities,cachedAt:o}};lf.locally=e=>{var t;const n=ve();if(n.log("community/getCommunities.locally",e),!n.cache)return;const r=e.map((e=>Ue(["community","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 uf=async e=>{const t=ve();t.log("community/getCommunity",e);const{data:n}=await t.http.get(`/api/v3/communities/${e}`),r=sf(n),o=t.cache&&Date.now();t.cache&&Rl(r,{cachedAt:o});const{communities:i}=r;return{data:i.find((t=>t.communityId===e)),cachedAt:o}};uf.locally=e=>{const t=ve();if(t.log("community/getCommunity.locally",e),!t.cache)return;const n=Ue(["community","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const ff=(e,t="userId",n="user")=>e.map((e=>((e,t="userId",n="user")=>Object.assign({get[n](){var n;if(!ve().cache)return;return(null===(n=Ue(["user","get",e[t]]))||void 0===n?void 0:n.data)||void 0}},e))(e,t,n))),hf=(e,t,n="userId",r="user")=>{const o=e,i=t,s=o[i],a=zl(o,["symbol"==typeof i?i:i+""]),c=ff(s,n,r);return Object.assign(Object.assign({},a),{[t]:c})},df=async e=>{const t=ve();t.log("community/queryCommunityMembers",e);const n=null!=e?e:{},{page:r}=n,o=zl(n,["page"]),{data:i}=await t.http.get(`/api/v3/communities/${o.communityId}/users`,{params:Object.assign(Object.assign({},o),{options:{token:H(r,"skiplimit")}})}),{paging:s}=i,a=zl(i,["paging"]),c=hf(a,"communityUsers"),{communityUsers:l}=c,u=t.cache&&Date.now();if(t.cache){Rl(c,{cachedAt:u});const e=["communityUsers","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];De(e,{communityUsers:l.map((({communityId:e,userId:t})=>Q("communityUsers")({communityId:e,userId:t}))),paging:s})}return{data:l,cachedAt:u,nextPage:V(s.next),prevPage:V(s.previous)}};df.locally=e=>{var t,n;const r=ve();if(r.log("community/queryCommunityMembers",e),!r.cache)return;const o=null!=e?e:{},{page:i}=o,s=zl(o,["page"]),a=["communityUsers","query",Object.assign(Object.assign({},s),{options:Object.assign({},i)})],{data:c,cachedAt:l}=null!==(t=Ue(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.communityUsers.length))return;const u=c.communityUsers.map((e=>Ue(["communityUsers","get",e]))).filter(Boolean).map((({data:e})=>e)),f=V(null==c?void 0:c.paging.previous),h=V(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:f,nextPage:h}:void 0};const pf=async e=>{const t=ve();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=sf(r),{communities:i}=o,s=t.cache&&Date.now();if(t.cache){Rl(o,{cachedAt:s});De(["community","top-trending",{params:{options:{limit:n}}}],{communities:i.map(Q("community"))})}return{data:i,cachedAt:s}};pf.locally=e=>{var t,n;const r=ve();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=Ue(i))&&void 0!==t?t:{};if(!(null==s?void 0:s.communities.length))return;const c=s.communities.map((e=>Ue(["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 gf=async e=>{const t=ve();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=sf(r),{communities:i}=o,s=t.cache&&Date.now();if(t.cache){Rl(o,{cachedAt:s});De(["community","recommended",{params:{options:{limit:n}}}],{communities:i.map(Q("community"))})}return{data:i,cachedAt:s}};gf.locally=e=>{var t,n;const r=ve();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=Ue(i))&&void 0!==t?t:{};if(!(null==s?void 0:s.communities.length))return;const c=s.communities.map((e=>Ue(["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 mf=async e=>{const t=ve();t.log("comment/queryComments",e);const{page:n={limit:10}}=e,r=zl(e,["page"]),o={type:r.sortBy?"pagination":void 0,token:H(n,r.sortBy?"skiplimit":"afterbefore")},{data:i}=await t.http.get("/api/v3/comments",{params:Object.assign(Object.assign({},r),{options:o})}),{paging:s}=i,a=zl(i,["paging"]),{comments:c}=a,l=t.cache&&Date.now();if(t.cache){Rl(a,{cachedAt:l});const e=["comment","query",Object.assign(Object.assign({},r),{options:Object.assign({},n)})];De(e,{comments:c.map(Q("comment")),paging:s})}const u=V(s.next);return{data:c,cachedAt:l,prevPage:V(s.previous),nextPage:u}};mf.locally=e=>{var t,n;const r=ve();if(r.log("comment/queryComments.locally",e),!r.cache)return;const{page:o={limit:10}}=e,i=zl(e,["page"]),s=["comment","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Ue(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.comments.length))return;const l=a.comments.map((e=>Ue(["comment","get",e]))).filter(Boolean).map((({data:e})=>e)),u=V(null==a?void 0:a.paging.previous),f=V(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:f}:void 0};const yf=async e=>{const t=ve();t.log("comment/getComments",e);const n=e.map((e=>encodeURIComponent(e))),{data:r}=await t.http.get("/api/v3/comments/list",{params:{commentIds:n}}),o=t.cache&&Date.now();return t.cache&&Rl(r,{cachedAt:o}),{data:r.comments,cachedAt:o}};yf.locally=e=>{var t;const n=ve();if(n.log("comment/getComments.locally",e),!n.cache)return;const r=e.map((e=>Ue(["comment","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 vf=async e=>{const t=ve();let n;t.log("comment/getComment",e);try{n=(await t.http.get(`/api/v3/comments/${encodeURIComponent(e)}`)).data}catch(t){throw 400400===(null==t?void 0:t.code)&&ze(["comment","get",e],!0),t}const r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{comments:o}=n;return{data:o.find((t=>t.commentId===e)),cachedAt:r}};vf.locally=e=>{const t=ve();if(t.log("comment/getComment.locally",e),!t.cache)return;const n=Ue(["comment","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const bf=(e,t)=>{var n,r;if(ve().userId!==t.reactor.userId)return;let o,i;if("post.addReaction"===e||"post.removeReaction"===e){const e=t.posts[0];i=null===(n=Ue(["post","get",e.postId]))||void 0===n?void 0:n.data,o=e}else{const e=t.comments[0];i=null===(r=Ue(["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))})}},wf=async(e,t,n)=>{const r=ve();if(r.log("reaction/createReaction",{referenceId:t,referenceType:e,reactionName:n}),await r.http.post("/api/v2/reactions",{referenceId:t,referenceType:e,reactionName:n}),r.cache){const n=Ue([e,"get",t]);(null==n?void 0:n.data)&&De([e,"get",t],n.data,{cachedAt:Date.now()})}return!0};wf.optimistically=(e,t,n)=>{var r,o,i,s,a;const c=ve();if(c.log("reaction/createReaction.optimistically",{referenceId:t,referenceType:e,reactionName:n}),!c.cache)return;const l=Ue([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 qe([e,"get",t],u,{cachedAt:-5}),tu(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 Cf=async(e,t,n)=>{const r=ve();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}}),r.cache){const n=Ue([e,"get",t]);(null==n?void 0:n.data)&&De([e,"get",t],n.data,{cachedAt:Date.now()})}return!0};Cf.optimistically=(e,t,n)=>{var r,o,i,s,a;const c=ve();if(c.log("reaction/removeReaction.optimistically",{referenceId:t,referenceType:e,reactionName:n}),!c.cache)return;const l=Ue([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 qe([e,"get",t],u,{cachedAt:-5}),tu(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 _f=async e=>{const t=ve();t.log("reaction/queryReactions",e);const n=null!=e?e:{},{page:r={limit:10}}=n,o=zl(n,["page"]),{data:i}=await t.http.get("/api/v3/reactions",{params:Object.assign(Object.assign({},o),{options:{token:H(r,"afterbeforeraw")}})}),{paging:s}=i,a=zl(i,["paging"]),{reactions:c}=a;Rl(Object.assign(Object.assign({},a),{reactions:c[0].reactors}));const l=W(s.next);return{data:c,prevPage:W(s.previous),nextPage:l}},kf=(e,t)=>{const n=ve();return et(n,e,e,(r=>{var o;if(n.cache){const{communities:n}=r,i=zl(r,["communities"]);Rl(i),(null==n?void 0:n[0])&&!["post.updated"].includes(e)&&tt("community.updated",{communities:n});const s=Ue(["post","get",r.posts[0].postId]);if(["post.created","post.approved","post.declined"].includes(e)){let t=null===(o=Me(["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)===s.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})=>qe(e,t,{cachedAt:-1})))}t(s.data)}else t(r.posts[0])}))},Sf=e=>kf("post.created",e),Af=e=>kf("post.updated",e),Ef=e=>kf("post.deleted",e),Of=e=>kf("post.approved",e),If=e=>kf("post.declined",e),Tf=e=>kf("post.flagged",e),xf=e=>kf("post.unflagged",e),Pf=e=>{const t=ve();return et(t,"post.addReaction","post.addReaction",(n=>{if(t.cache){bf("post.addReaction",n);const t=zl(n,["reactor"]);Rl(t);const r=Ue(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},Rf=e=>{const t=ve();return et(t,"post.removeReaction","post.removeReaction",(n=>{if(t.cache){bf("post.removeReaction",n);const t=zl(n,["reactor"]);Rl(t);const r=Ue(["post","get",n.posts[0].postId]);e(r.data)}else e(n.posts[0])}))},jf=(e,t)=>{const n=ve();return et(n,e,e,(r=>{var o;if(n.cache){Rl(r);const n=Ue(["comment","get",r.comments[0].commentId]);if(["comment.created"].includes(e)){const e=null===(o=Me(["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})=>qe(e,t,{cachedAt:-1})))}t(n.data)}else t(r.comments[0])}))},Nf=e=>jf("comment.created",e),Ff=e=>jf("comment.updated",e),Bf=e=>jf("comment.deleted",e),Mf=e=>jf("comment.flagged",e),Uf=e=>jf("comment.unflagged",e),Df=e=>{const t=ve();return et(t,"comment.addReaction","comment.addReaction",(n=>{if(t.cache){bf("comment.addReaction",n);const t=zl(n,["reactor"]);Rl(t);const r=Ue(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},Lf=e=>{const t=ve();return et(t,"comment.removeReaction","comment.removeReaction",(n=>{if(t.cache){bf("comment.removeReaction",n);const t=zl(n,["reactor"]);Rl(t);const r=Ue(["comment","get",n.comments[0].commentId]);e(r.data)}else e(n.comments[0])}))},qf=(e,t,n)=>{const r=ve(),o=(r,o,i)=>{r===e&&o===t&&n(i)};if("message"===e){const e=e=>{if(!e.messages[0].latestReaction)return;const t=e.messages[0].latestReaction,{eventName:n,referenceId:r,referenceType:i,userDisplayName:s}=t,a=zl(t,["eventName","referenceId","referenceType","userDisplayName"]);"add"===n&&(Rl(e),Rl({reactions:[a]}),o("message",e.messages[0].messageId,a))};return et(r,"reaction/onReactorAdded","v3.message.didUpdate",e)}if("post"===e){return et(r,"post.addReaction","post.addReaction",(e=>{const{reactor:t}=e,n=zl(e,["reactor"]);Rl(n),Rl({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return et(r,"comment.addReaction","comment.addReaction",(e=>{const{reactor:t}=e,n=zl(e,["reactor"]);Rl(n),Rl({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))},zf=(e,t,n)=>{const r=ve(),o=(r,o,i)=>{r===e&&o===t&&n(i)};if("message"===e){const e=e=>{if(!e.messages[0].latestReaction)return;const t=e.messages[0].latestReaction,{eventName:n,referenceId:r,referenceType:i}=t,s=zl(t,["eventName","referenceId","referenceType"]);"remove"===n&&(Rl(e),Rl({reactions:[s]}),o("message",e.messages[0].messageId,s))};return et(r,"reaction/onReactorRemoved","v3.message.didUpdate",e)}if("post"===e){return et(r,"post.removeReaction","post.removeReaction",(e=>{const{reactor:t}=e,n=zl(e,["reactor"]);Rl(n),Rl({reactions:[t]}),o("post",e.posts[0].postId,t)}))}return et(r,"comment.removeReaction","comment.removeReaction",(e=>{const{reactor:t}=e,n=zl(e,["reactor"]);Rl(n),Rl({reactions:[t]}),o("comment",e.comments[0].commentId,t)}))};var $f={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 Hf=e=>{const t=ve(),n=e.channels.map((n=>{const r=e.channelUsers.find((e=>e.userId===t.userId&&n.channelId===e.channelId)),o=!!r&&r.readToSegment<r.lastMentionedSegment,i=r&&"member"===r.membership&&n.messageCount?Math.max(0,n.messageCount-r.readToSegment):0;return Object.assign(Object.assign({},n),{hasMention:o,unreadCount:i})}));return Object.assign(Object.assign({},e),{channels:n})},Vf=async e=>{const t=ve();t.log("channel/queryChannels",e);const n=null!=e?e:{},{page:r={limit:10},displayName:o,membership:i}=n,s=zl(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:H(r,"skiplimit")}})}),{paging:c}=a,l=zl(a,["paging"]),u=Hf(l),{channels:f}=u,h=t.cache&&Date.now();if(t.cache){Rl(u,{cachedAt:h});const e=["channel","query",Object.assign(Object.assign({},s),{options:Object.assign({},r)})];De(e,{channels:f.map(Q("channel")),paging:c})}const d=V(c.next);return{data:f,cachedAt:h,prevPage:V(c.previous),nextPage:d}};Vf.locally=e=>{var t,n;ve().log("channel/queryChannels.locally",e);const r=null!=e?e:{},{page:o={limit:10}}=r,i=zl(r,["page"]),s=["channel","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Ue(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.channels.length))return;const l=a.channels.map((e=>Ue(["channel","get",e]))).filter(Boolean).map((({data:e})=>e)),u=V(null==a?void 0:a.paging.previous),f=V(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:f}:void 0};const Wf=async e=>{const t=ve();t.log("channel/getChannels",e);const n=e.map((e=>encodeURIComponent(e))),{data:r}=await t.http.get("/api/v3/channels/list",{params:{channelIds:n}}),o=Hf(r),i=t.cache&&Date.now();return t.cache&&Rl(o,{cachedAt:i}),{data:o.channels,cachedAt:i}};Wf.locally=e=>{var t;const n=ve();if(n.log("channel/getChannels.locally",e),!n.cache)return;const r=e.map((e=>Ue(["channel","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 Kf=async e=>{const t=ve();let n;t.log("channel/getChannel",e),Ul("channel",e);try{const{data:r}=await t.http.get(`/api/v3/channels/${encodeURIComponent(e)}`);n=Hf(r)}catch(t){throw re(null==t?void 0:t.code)&&Dl("channel",e),t}const r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{channels:o}=n;return{data:o.find((t=>t.channelId===e)),cachedAt:r}};Kf.locally=e=>{const t=ve();if(t.log("channel/getChannel.locally",e),!t.cache)return;const n=Ue(["channel","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Qf=async e=>{const t=ve();t.log("channel/queryChannelMembers",e);const n=null!=e?e:{},{page:r}=n,o=zl(n,["page"]),{data:i}=await t.http.get(`/api/v4/channels/${encodeURIComponent(o.channelId)}/users`,{params:Object.assign(Object.assign({},o),{options:{token:H(r,"skiplimit")}})}),{paging:s}=i,a=zl(i,["paging"]),c=Hf(a),l=hf(c,"channelUsers"),{channelUsers:u}=l,f=t.cache&&Date.now();if(t.cache){Rl(l);const e=["channelUsers","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];De(e,{channelUsers:u.map((({channelId:e,userId:t})=>Q("channelUsers")({channelId:e,userId:t}))),paging:s})}return{data:u,cachedAt:f,nextPage:V(s.next),prevPage:V(s.previous)}};Qf.locally=e=>{var t,n;const r=ve();if(r.log("channel/queryChannelMembers.locally",e),!r.cache)return;const{page:o}=e,i=zl(e,["page"]),s=["channelUsers","query",Object.assign(Object.assign({},i),{options:Object.assign({},o)})],{data:a,cachedAt:c}=null!==(t=Ue(s))&&void 0!==t?t:{};if(!(null==a?void 0:a.channelUsers.length))return;const l=a.channelUsers.map((e=>Ue(["channelUsers","get",e]))).filter(Boolean).map((({data:e})=>e)),u=V(null==a?void 0:a.paging.previous),f=V(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:f}:void 0};const Jf=e=>{const t=ve();return et(t,"onChannelCreated","v3.channel.didCreate",(t=>{const n=Hf(t);Rl(n),e(n.channels[0])}))},Gf=e=>{const t=ve();return et(t,"onChannelUpdated","v3.channel.didUpdate",(t=>{const n=Hf(t);Rl(n),e(n.channels[0])}))},Yf=e=>{const t=ve();return et(t,"onChannelDeleted","v3.channel.didDelete",(t=>{const n=Hf(t);Rl(n),e(n.channels[0])}))},Xf=e=>{const t=ve();return et(t,"onChannelJoined","v3.channel.didJoin",(t=>{const n=Hf(t);Rl(n),e(n.channels[0])}))},Zf=e=>{const t=ve();return et(t,"onChannelLeft","v3.channel.didLeave",(t=>{const n=Hf(t);Rl(n),e(n.channels[0])}))},eh=e=>{const t=ve();return et(t,"onChannelMemberAdded","v3.channel.didAddUsers",(t=>{const n=Hf(t),r=hf(n,"channelUsers"),{channels:o,channelUsers:i}=r;Rl(r),e(o[0],i.find((e=>"member"===e.membership)))}))},th=e=>{const t=ve();return et(t,"onChannelMemberRemoved","v3.channel.didRemoveUsers",(t=>{const n=Hf(t),r=hf(n,"channelUsers"),{channels:o,channelUsers:i}=r;Rl(r),e(o[0],i[0])}))},nh=e=>{const t=ve();return et(t,"onChannelMemberBanned","v3.channel.didBan",(t=>{const n=Hf(t),r=hf(n,"channelUsers"),{channels:o,channelUsers:i}=r;Rl(r),e(o[0],i.find((e=>"banned"===e.membership)))}))},rh=e=>{const t=ve();return et(t,"onChannelMemberUnbanned","v3.channel.didUnban",(t=>{const n=Hf(t),r=hf(n,"channelUsers"),{channels:o,channelUsers:i}=r;Rl(r),e(o[0],i.find((e=>"none"===e.membership)))}))},oh=e=>{const t=ve();return et(t,"onChannelMemberRead","v3.channel.didMarkSeen",(t=>{const n=Hf(t),r=hf(n,"channelUsers");Rl(r),e(r.channels[0],r.channelUsers[0])}))},ih=e=>{const t=ve();return et(t,"message/onMessageCreated","v3.message.didCreate",(t=>{Rl(t),e(t.messages[0])}))},sh=e=>{const t=ve();return et(t,"message/onMessageUpdated","v3.message.didUpdate",(t=>{Rl(t);const n=t.messages[0];(null==n?void 0:n.myReactions)||(e=>{const t=ve(),n=Ue(["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))}))})(n),e(n)}))},ah=e=>{const t=ve();return et(t,"message/onMessageDeleted","v3.message.didDelete",(t=>{Rl(t),e(t.messages[0])}))},ch=e=>{const t=ve();return et(t,"message/onMessageFetched","v3.message.didFetch",(t=>{Rl(t),e(t.messages[0])}))},lh=(e,t)=>{const n=ve();return et(n,e,e,(e=>{const r=sf(e);if(n.cache){Rl(r);const e=Ue(["community","get",r.communities[0].communityId]);t(e.data)}else t(r.communities[0])}))};function uh(e,t,n){return!!e.permissions.some((e=>e===n))||t.users.find((t=>t.userId===e.userId)).permissions.some((e=>e===n))}function fh(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=>!uh(e,t,"BAN_COMMUNITY_USER")))[0]:t.communityUsers.filter((e=>!uh(e,t,"ADD_COMMUNITY_USER")))[0]}const hh=(e,t)=>{const n=ve();return et(n,e,e,(r=>{const o=sf(r),i=hf(o,"communityUsers");if(n.cache){Rl(i);const n=Ue(["community","get",i.communities[0].communityId]),r=Ue(["communityUsers","get",Q("communityUsers")(fh(e,i))]);t(n.data,r.data)}else t(i.communities[0],fh(e,i))}))},dh=e=>lh("community.updated",e),ph=e=>lh("community.deleted",e),gh=e=>hh("community.joined",e),mh=e=>hh("community.left",e),yh=e=>hh("community.userAdded",e),vh=e=>hh("community.userRemoved",e),bh=e=>hh("community.userBanned",e),wh=e=>hh("community.userUnbanned",e),Ch=async e=>{const t=ve();t.log("category/queryCategories",e);const n=null!=e?e:{},{page:r={limit:10}}=n,o=zl(n,["page"]),{data:i}=await t.http.get("/api/v3/community-categories",{params:Object.assign(Object.assign({},o),{options:{token:H(r,"skiplimit")}})}),{paging:s}=i,a=zl(i,["paging"]),{categories:c}=a,l=t.cache&&Date.now();if(t.cache){Rl(a,{cachedAt:l});const e=["category","query",Object.assign(Object.assign({},o),{options:Object.assign({},r)})];De(e,{categories:c.map(Q("category")),paging:s})}const u=V(s.next);return{data:c,cachedAt:l,prevPage:V(s.previous),nextPage:u}};Ch.locally=e=>{var t,n;const r=ve();if(r.log("category/queryCategories.locally",e),!r.cache)return;const o=null!=e?e:{},{page:i={limit:10}}=o,s=zl(o,["page"]),a=["category","query",Object.assign(Object.assign({},s),{options:Object.assign({},i)})],{data:c,cachedAt:l}=null!==(t=Ue(a))&&void 0!==t?t:{};if(!(null==c?void 0:c.categories.length))return;const u=c.categories.map((e=>Ue(["category","get",e]))).filter(Boolean).map((({data:e})=>e)),f=V(null==c?void 0:c.paging.previous),h=V(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:f,nextPage:h}:void 0};const _h=async e=>{const t=ve();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&&Rl(n,{cachedAt:r});const{categories:o}=n;return{data:o.find((t=>t.categoryId===e)),cachedAt:r}};_h.locally=e=>{const t=ve();if(t.log("category/getCategory.locally",e),!t.cache)return;const n=Ue(["category","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const kh=async e=>{const t=ve();t.log("feed/queryGlobalFeed",e);const n=null!=e?e:{},{useCustomRanking:r,page:o}=n,i=zl(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:H(o,"skiplimit")}})}),{paging:a}=s,c=zl(s,["paging"]),{posts:l}=c,u=t.cache&&Date.now();if(t.cache){Rl(c);const e=["globalFeed","query",Object.assign(Object.assign({},i),{useCustomRanking:r,options:Object.assign({},o)})];De(e,{posts:l.map(Q("post")),paging:a})}const f=V(a.next);return{data:l,cachedAt:u,prevPage:V(a.previous),nextPage:f}};kh.locally=e=>{var t,n;const r=ve();if(r.log("post/queryGlobalFeed.locally",e),!r.cache)return;const o=null!=e?e:{},{useCustomRanking:i,page:s}=o,a=zl(o,["useCustomRanking","page"]),c=["globalFeed","query",Object.assign(Object.assign({},a),{useCustomRanking:i,options:Object.assign({},s)})],{data:l,cachedAt:u}=null!==(t=Ue(c))&&void 0!==t?t:{};if(!(null==l?void 0:l.posts.length))return;const f=l.posts.map((e=>Ue(["post","get",e]))).filter(Boolean).map((({data:e})=>e)),h=V(null==l?void 0:l.paging.previous),d=V(null==l?void 0:l.paging.next);return f.length===(null===(n=null==l?void 0:l.posts)||void 0===n?void 0:n.length)?{data:f,cachedAt:u,prevPage:h,nextPage:d}:void 0};const Sh=async(e,t)=>{const n=ve();n.log(`follow/queryF${e.substring(1)}`,t);const{userId:r,page:o}=t,i=zl(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:H(o,"afterbeforeraw")})}),{paging:a}=s,c=zl(s,["paging"]),{follows:l}=c,u=n.cache&&Date.now();if(n.cache){Rl(c,{cachedAt:u});const t=["follow","query",Object.assign(Object.assign({},i),{userId:r,options:Object.assign({},o),type:e})];De(t,{follows:l.map(Q("follow")),paging:a})}const f=W(a.next);return{data:l,cachedAt:u,prevPage:W(a.previous),nextPage:f}};Sh.locally=(e,t)=>{var n,r;const o=ve();if(o.log(`follow/queryF${e.substring(1)}.locally`,t),!o.cache)return;const{page:i}=t,s=zl(t,["page"]),a=["follow","query",Object.assign(Object.assign({},s),{options:Object.assign({},i),type:e})],{data:c,cachedAt:l}=null!==(n=Ue(a))&&void 0!==n?n:{};if(!(null==c?void 0:c.follows.length))return;const u=c.follows.map((e=>Ue(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)),f=W(null==c?void 0:c.paging.previous),h=W(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:f,nextPage:h}:void 0};const Ah=async e=>Sh("followers",e);Ah.locally=e=>Sh.locally("followers",e);const Eh=async e=>Sh("following",e);Eh.locally=e=>Sh.locally("following",e);const Oh=e=>["followInfo","get",`${ve().userId}#${e}`],Ih=async e=>{var t,n;const r=ve();r.log("follow/getFollowInfo",e);const{data:o}=await r.http.get(r.userId===e?"/api/v4/me/followInfo":`/api/v4/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&&De(Oh(e),s,{cachedAt:i}),{data:s,cachedAt:i}};Ih.locally=e=>{const t=ve();if(t.log("follow/getFollowInfo.locally",e),!t.cache)return;const n=Ue(Oh(e));return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Th=(e,t)=>{const n=ve();return et(n,e,e,(e=>{var r,o;if(n.cache){Rl(e);[...null!==(r=Me(["followers","query"]))&&void 0!==r?r:[],...null!==(o=Me(["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})=>qe(e,t,{cachedAt:-1}))),t(e.follows[0])}else t(e.follows[0])}))},xh=e=>Th("follow.created",e),Ph=e=>Th("follow.unfollowed",e),Rh=e=>Th("follow.followerDeleted",e),jh=e=>Th("follow.requested",e),Nh=e=>Th("follow.requestCanceled",e),Fh=e=>Th("follow.accepted",e),Bh=e=>Th("follow.requestDeclined",e),Mh=e=>{const t=async t=>{const[{data:n},{data:r}]=await Promise.all([Ih(t.from),Ih(t.to)]);e(n),e(r)},n=[Th("follow.created",t),Th("follow.requested",t),Th("follow.accepted",t),Th("follow.unfollowed",t),Th("follow.requestCanceled",t),Th("follow.requestDeclined",t),Th("follow.followerDeleted",t)];return()=>{n.forEach((e=>e()))}},Uh=async e=>{const t=ve();t.log("poll/getPoll",e);const{data:n}=await t.http.get(`/api/v3/polls/${e}`),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{polls:o}=n;return{data:o.find((t=>t.pollId===e)),cachedAt:r}};Uh.locally=e=>{const t=ve();if(t.log("poll/getPoll",e),!t.cache)return;const n=Ue(["poll","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const Dh=e=>{const t=ve();return et(t,"poll/onPollUpdated","poll.updated",(n=>{t.cache&&Rl(n),e(n.polls[0])}))},Lh=e=>{const t=ve();return et(t,"poll/onPollDeleted","poll.deleted",(n=>{t.cache&&Rl(n),e(n.polls[0])}))},qh=async e=>{const t=ve();t.log("stream/getStream",e);const{data:n}=await t.http.get(`/api/v3/video-streaming/${e}`),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}};qh.locally=e=>{const t=ve();if(t.log("stream/getStream",e),!t.cache)return;const n=Ue(["stream","get",e]);return n?{data:n.data,cachedAt:n.cachedAt}:void 0};const zh=async e=>{const t=ve();t.log("stream/queryStreams",e);const n=null!=e?e:{},{page:r}=n,o=zl(n,["page"]),{data:i}=await t.http.get("/api/v3/video-streaming",{params:Object.assign(Object.assign({},o),{options:{token:H(r,"skiplimit")}})}),{paging:s,results:a}=i,{videoStreamings:c}=a,l=t.cache&&Date.now();t.cache&&Rl(a,{cachedAt:l});const u=V(s.next);return{data:c,cachedAt:l,prevPage:V(s.previous),nextPage:u}};zh.locally=e=>{ve().log("stream/queryStreams.locally",e)};return e.API_REGIONS=mt,e.CommunityPostSettingMaps=n,e.CommunityPostSettings=t,e.ContentFeedType=o,e.DefaultCommunityPostSetting=r,e.FileType=i,e.MessageContentType=l,e.PostContentType=u,e.VERSION=y,e.VideoResolution=s,e.VideoSize=c,e.VideoTranscodingStatus=a,e.acceptFollower=async e=>{const t=ve();t.log("follow/acceptFollower",e);const{data:n}=await t.http.post(`/api/v4/me/followers/${e}`);return t.cache&&Rl(n),tt("follow.accepted",n),!0},e.addChannelMembers=async(e,t)=>{const n=ve();n.log("channel/addChannelMembers",e,t);const{data:r}=await n.http.post(`/api/v3/channels/${encodeURIComponent(e)}/users`,{channelId:e,userIds:t}),o=Hf(r);n.cache&&Rl(o),t.forEach((e=>tt("v3.channel.didAddUsers",Object.assign(Object.assign({},o),{channelUsers:o.channelUsers.filter((t=>t.userId===e))}))));const{channelUsers:i}=o;return!!i.find((t=>t.channelId===e&&"member"===t.membership))},e.addChannelMembersRole=async(e,t,n)=>{const r=ve();r.log("channel/addChannelMembersRole",e,t,n);const{data:o}=await r.http.post(`/api/v3/channels/${encodeURIComponent(e)}/users/roles`,{channelId:e,role:t,userIds:n}),i=Hf(o);r.cache&&Rl(i);const{channelUsers:s}=i;return!!s.find((n=>n.channelId===e&&n.roles.includes(t)))},e.addCommunityMembers=async(e,t)=>{const n=ve();n.log("community/addCommunityMembers",e,t);const{data:r}=await n.http.post(`/api/v3/communities/${e}/users`,{communityId:e,userIds:t});n.cache&&Rl(r),tt("community.userAdded",r);const{communityUsers:o}=r;return!!o.find((t=>t.communityId===e&&"member"===t.communityMembership))},e.addCommunityMembersRoles=async(e,t,n)=>{const r=ve();r.log("community/addCommunityMembersRoles",e,t,n);const{data:o}=await r.http.post(`/api/v4/communities/${e}/users/roles`,{communityId:e,roles:t,userIds:n});r.cache&&Rl(o);const{communityUsers:i}=o;return!!i.find((n=>n.communityId===e&&t.some((e=>n.roles.includes(e)))))},e.addReaction=wf,e.approvePost=async e=>{var t;const n=ve();n.log("post/approvePost",e);const{data:r}=await n.http.post(`/api/v3/posts/${encodeURIComponent(e)}/approve`),o=n.cache&&Date.now();if(n.cache&&Rl(r,{cachedAt:o}),"community"===r.posts[0].targetType){const e=null===(t=r.communities)||void 0===t?void 0:t[0];tt("community.updated",{communities:[e]})}return tt("post.approved",{posts:[r.posts[0]]}),{data:r.posts.find((t=>t.postId===e)),cachedAt:o}},e.backupCache=async(e="amitySdk",t=(e=>e.offline))=>{const{log:n,cache:r,userId:o}=ve();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 Be.setItem(`${e}#${o}`,JSON.stringify(i)),!0)},e.banChannelMembers=async(e,t)=>{const n=ve();n.log("channel/banChannelMembers",{userIds:t,channelId:e});const{data:r}=await n.http.put(`/api/v3/channels/${e}/users/ban`,{userIds:t}),o=Hf(r),i=hf(o,"channelUsers"),{channelUsers:s}=i,a=n.cache&&Date.now();return n.cache&&Rl(i,{cachedAt:a}),{data:null==s?void 0:s.filter((e=>"banned"===e.membership)),cachedAt:a}},e.closePoll=async e=>{const t=ve();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&&Rl(n,{cachedAt:r}),tt("poll.updated",n);const{polls:o}=n;return{data:o.find((t=>t.pollId===e)),cachedAt:r}},e.connectClient=async(e,t)=>{var n;const r=ve();r.log("client/api/connectClient",Object.assign({apiKey:r.apiKey},e)),null!==(n=e.deviceId)&&void 0!==n||(e.deviceId=xl());const{accessToken:o,users:i}=await(async e=>{const t=ve();t.log("client/api/getToken",e);const n=await Pl(),{data:r}=await t.http.post("/v1/device",Object.assign(Object.assign({},e),{deviceInfo:n}),{headers:{"X-API-Key":t.apiKey}});return r})(e);var s,a,c;r.http.defaults.headers.common.Authorization=`Bearer ${o}`,r.ws.io.opts.query={token:o},s=r.ws,a=r.emitter,Ye.forEach((e=>{s.on(e,(t=>a.emit(e,t)))})),await new Promise((e=>{r.ws.once("connect",e),r.ws.open()})),r.userId=e.userId,r.accessToken=o,c=i[0],nt={_id:c._id,userId:c.userId,path:c.path},!0!==(null==t?void 0:t.disableRTE)&&lt(st());const l=[Ml((()=>{Tl(),l.forEach((e=>e()))})),Nl((()=>null))];return r.ws.connected},e.createChannel=async e=>{const t=ve();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=Hf(n.data),o=t.cache&&Date.now();t.cache&&Rl(r,{cachedAt:o});const{channels:i}=r;return{data:i[0],cachedAt:o}},e.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&&!p,n=gt(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:vt("http",t),c=null!==(i=null==r?void 0:r.mqtt)&&void 0!==i?i:vt("mqtt",t),l=ls(a),u=(e=>{const t=Cl(e,{autoConnect:!1,reconnectionDelay:2e3,transports:["websocket"]});return t.on("disconnect",(e=>{"io server disconnect"===e&&t.connect()})),t})(a),f=Ol(c),h=Ze(),d={version:`${y}`,apiKey:e,log:s,http:l,ws:u,mqtt:f,emitter:h,use:()=>be(d),getFeedSettings:Il};try{return ve()}catch(e){be(d)}return d},e.createComment=async e=>{const t=ve();t.log("comment/createComment",e);const{data:n}=await t.http.post("/api/v3/comments",e),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const o=await rf(e.referenceId);tt("post.updated",{posts:[o.data]}),tt("comment.created",n);const{comments:i}=n;return{data:i[0],cachedAt:r}},e.createCommunity=async e=>{const t=ve();t.log("user/createCommunity",e);const{data:n}=await t.http.post("/api/v3/communities/",af(e)),r=sf(n),o=t.cache&&Date.now();t.cache&&Rl(r,{cachedAt:o}),tt("community.created",r);const{communities:i}=r;return{data:i[0],cachedAt:o}},e.createFile=async(e,t)=>{const n=ve();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}){t&&t(Math.round(100*e/n))}}),i=n.cache&&Date.now();return n.cache&&Rl({files:o},{cachedAt:i}),{data:o,cachedAt:i}},e.createImage=async(e,t)=>{const n=ve();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}){t&&t(Math.round(100*e/n))}}),i=n.cache&&Date.now();return n.cache&&Rl({files:o},{cachedAt:i}),{data:o,cachedAt:i}},e.createMessage=Xu,e.createPoll=async e=>{const t=ve();t.log("post/createPoll",e);const{data:n}=await t.http.post("/api/v3/polls",e),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{polls:o}=n;return{data:o[0],cachedAt:r}},e.createPost=async e=>{const t=ve();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),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r}),tt("post.created",n);const{posts:o}=n;return{data:o[0],cachedAt:r}},e.createQuery=le,e.createReport=async(e,t)=>{const n=ve();n.log("report/createReport",{referenceType:e,referenceId:t});const{domainName:r}=$f[e],{data:o}=await n.http.post("/api/"+("user"===e?`v4/me/flags/${encodeURIComponent(t)}`:`v3/${r}/${encodeURIComponent(t)}/flag`));n.cache&&Rl(o);return tt("message"===e?"v3.message.didUpdate":`${e}.flagged`,o),!!o},e.createStream=async e=>{const t=ve();t.log("stream/createStream",e);const{data:n}=await t.http.post("/api/v3/video-streaming",e),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o[0],cachedAt:r}},e.createUserToken=async(e,t,n)=>{const r=xl(),o=await Pl(),i=ls(vt("http",t)),{data:s}=await i.post("/api/v3/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.createVideo=async(e,t,n)=>{const r=ve();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}){n&&n(Math.round(100*e/t))}}),s=r.cache&&Date.now();return r.cache&&Rl({files:i},{cachedAt:s}),{data:i,cachedAt:s}},e.declineFollower=async e=>{const t=ve();t.log("follow/declineFollower",e);const{data:n}=await t.http.delete(`/api/v4/me/followers/${e}`);return t.cache&&Rl(n),tt("follow.requestDeclined",n),!0},e.declinePost=async e=>{var t;const n=ve();n.log("post/declinePost",e);const{data:r}=await n.http.post(`/api/v3/posts/${encodeURIComponent(e)}/decline`),o=n.cache&&Date.now();if(n.cache&&Rl(r,{cachedAt:o}),"community"===r.posts[0].targetType){const e=null===(t=r.communities)||void 0===t?void 0:t[0];tt("community.updated",{communities:[e]})}return tt("post.declined",{posts:[r.posts[0]]}),{data:r.posts.find((t=>t.postId===e)),cachedAt:o}},e.deleteChannel=async e=>{const t=ve();t.log("channel/deleteChannel",e),await t.http.delete(`/api/v3/channels/${encodeURIComponent(e)}`);return(await Kf(e)).data},e.deleteComment=async(e,t=!1)=>{const n=ve();n.log("comment/deleteComment",e);const r=await vf(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 rf(r.data.referenceId);return tt("post.updated",{posts:[i.data]}),tt("comment.deleted",{comments:[o]}),t?setTimeout((()=>{ze(["comment","get",e],!0)}),0):qe(["comment","get",e],{isDeleted:!0}),o},e.deleteCommunity=async e=>{const t=ve();t.log("community/deleteCommunity",e),await t.http.delete(`/api/v3/communities/${e}`);const n=await uf(e);return tt("community.deleted",{communities:[n.data]}),n.data},e.deleteFile=async e=>{const t=ve();return t.log("file/deleteFile",e),await t.http.delete(`/api/v3/files/${e}`),ze(["file","get",e],!0),{success:!0}},e.deleteMessage=ef,e.deletePoll=async e=>{const t=ve();t.log("poll/deletePoll",e);const n=await Uh(e),{data:r}=await t.http.delete(`/api/v3/polls/${e}`),{success:o}=r,i=Object.assign(Object.assign({},n.data),{isDeleted:!0});return qe(["poll","get",e],i),tt("poll.deleted",{polls:[i],users:[]}),o},e.deletePost=async(e,t=!1)=>{const n=ve();n.log("post/deletePost",e);const r=await rf(e);if(await n.http.delete(`/api/v4/posts/${encodeURIComponent(e)}`,{params:{postId:e,permanent:t}}),"community"===r.data.targetType){const e=await uf(r.data.targetId);tt("community.updated",{communities:[e.data]})}const o=Object.assign(Object.assign({},r.data),{isDeleted:!0});return tt("post.deleted",{posts:[o]}),t?setTimeout((()=>{Dl("post",e)}),0):qe(["post","get",e],{isDeleted:!0}),o},e.deleteReport=async(e,t)=>{const n=ve();n.log("report/deleteReport",{referenceType:e,referenceId:t});const{domainName:r}=$f[e],{data:o}=await n.http.delete("/api/"+("user"===e?`v4/me/flags/${encodeURIComponent(t)}`:`v3/${r}/${encodeURIComponent(t)}/unflag`));n.cache&&Rl(o);return tt("message"===e?"v3.message.didUpdate":`${e}.unflagged`,o),!!o},e.deleteStream=async e=>{const t=ve();t.log("stream/deleteStream",e);const n=await qh(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 qe(["stream","get",e],i),o},e.disableCache=()=>{const e=ve();e.cache&&(e.log("cache/api/disableCache"),delete e.cache)},e.disconnectClient=Tl,e.disposeStream=async e=>{const t=ve();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&&Rl(n,{cachedAt:r});const{videoStreamings:o}=n;return{data:o.find((t=>t.streamId===e)),cachedAt:r}},e.dropFromCache=ze,e.enableCache=(e={},t)=>{const n=ve();n.cache||(n.log("cache/api/enableCache"),n.cache={data:e,persistIf:t})},e.fileUrlWithSize=(e,t)=>`${e}?size=${t}`,e.filterByChannelMembership=Ve,e.filterByPropEquality=$e,e.filterByPropInclusion=He,e.follow=async e=>{const t=ve();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&&Rl(n,{cachedAt:r}),tt("accepted"===n.follows[0].status?"follow.created":"follow.requested",n),{data:n.follows[0],cachedAt:r}},e.getActiveClient=ve,e.getCategory=_h,e.getChannel=Kf,e.getChannels=Wf,e.getComment=vf,e.getCommentTopic=({path:e})=>e,e.getComments=yf,e.getCommunities=lf,e.getCommunity=uf,e.getCommunityTopic=({path:t},n=e.SubscriptionLevels.COMMUNITY)=>it(t,n),e.getFeedSettings=Il,e.getFile=Xl,e.getFollowInfo=Ih,e.getMessage=nu,e.getMessages=ru,e.getMyFollowersTopic=()=>{const e=rt(),[t]=e.path.split("/user/");return`${t}/membership/${e._id}/+/+`},e.getMyFollowingsTopic=()=>{const e=rt(),[t]=e.path.split("/user/");return`${t}/membership/+/${e._id}/+`},e.getNetworkTopic=st,e.getPoll=Uh,e.getPost=rf,e.getPostTopic=({path:t},n=e.SubscriptionLevels.POST)=>"comment"===n?`${t}/comment/+`:t,e.getPosts=nf,e.getRecommendedCommunities=gf,e.getRole=eu,e.getStream=qh,e.getTopTrendingCommunities=pf,e.getUser=Ll,e.getUserTopic=({path:t},n=e.SubscriptionLevels.USER)=>it(n===e.SubscriptionLevels.USER?t:t.replace(/^(\w*)/,"$1/social"),n),e.getUsers=ql,e.isAfterBefore=q,e.isAfterBeforeRaw=z,e.isCachable=ae,e.isConnected=()=>{var e,t;const n=ve();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)},e.isFetcher=oe,e.isFresh=ce,e.isLocal=e=>ae(e)&&-1===(null==e?void 0:e.cachedAt),e.isMutator=ie,e.isOffline=se,e.isPaged=$,e.isReportedByMe=async(e,t)=>{var n,r;const o=ve();o.log("report/isReportedByMe",{referenceType:e,referenceId:t});const{eventName:i,primaryKey:s}=$f[e],{result:a,isFlagByMe:c}=null!==(n=await _l(o,i,{[s]:t}))&&void 0!==n?n:{};return null!==(r=null!=a?a:c)&&void 0!==r&&r},e.isSkipLimit=L,e.joinChannel=async e=>{const t=ve();t.log("channel/joinChannel",e);const{data:n}=await t.http.post(`/api/v3/channels/${encodeURIComponent(e)}/join`),r=Hf(n);t.cache&&Rl(r);const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"===t.membership))},e.joinCommunity=async e=>{const t=ve();t.log("community/joinCommunity",e);const{data:n}=await t.http.post(`/api/v3/communities/${e}/join`),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r}),tt("community.joined",n);const{communityUsers:o}=n;return!!o.find((t=>t.communityId===e&&"member"===t.communityMembership))},e.leaveChannel=async e=>{const t=ve();t.log("channel/leaveChannel",e);const{data:n}=await t.http.delete(`/api/v3/channels/${encodeURIComponent(e)}/leave`),r=Hf(n);t.cache&&Rl(r);const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"!==t.membership))},e.leaveCommunity=async e=>{const t=ve();t.log("community/leaveCommunity",e);const{data:n}=await t.http.delete(`/api/v3/communities/${e}/leave`),r=t.cache&&Date.now();t.cache&&Rl(n,{cachedAt:r}),tt("community.left",n);const{communityUsers:o}=n;return!!o.find((t=>t.communityId===e&&"member"!==t.communityMembership))},e.liveChannelMembers=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log(Gl);const i=Date.now();r(`liveChannelMembers(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["channelUsers","collection",{channelId:e.channelId}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["channelUsers","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];if(i=$e(i,"roles",e.roles),e.memberships&&(e.memberships.some((e=>["member","banned"].includes(e)))&&(i=He(i,"membership",e.memberships)),e.memberships.includes("muted")&&(i=$e(i,"isMuted",!0))),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?Qe:Ke),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;if(!o)return;const i=Q("channelUsers")({channelId:e.channelId,userId:t.userId});"onMemberAdded"===n&&(o.data=[...new Set([i,...o.data])]),"onMemberRemoved"===n&&(o.data=o.data.filter((e=>e!==i))),De(f,o),h(o)},p=()=>{var e,t,n;const r=null===(e=Ue(f))||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=le(Qf,Object.assign(Object.assign({},a),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:c}}));fe(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(Q("channelUsers"))])]),De(f,i),h(i)}),ue(l))};return u.push(eh(((e,t)=>d(t,"onMemberAdded"))),th(((e,t)=>d(t,"onMemberRemoved"))),nh(((e,t)=>d(t,"onChannelMemberBanned"))),rh(((e,t)=>d(t,"onChannelMemberUnbanned"))),oh(((e,t)=>d(t,"onMemberRead")))),p(),()=>{r(`liveChannelMembers(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveChannels=(e,t,n)=>{const{log:r,cache:o,userId:i}=ve();o||console.log(Gl);const s=Date.now();r(`liveChannels(tmpid: ${s}) > listen`);const{limit:a}=e,c=zl(e,["limit"]),l=null!=a?a:5,{policy:u=Jl}=null!=n?n:{},f=[],h=["channel","collection",{}],d=n=>{var r,o;let s=null!==(r=n.data.map((e=>Ue(["channel","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];s=$e(s,"isDeleted",e.isDeleted),s=$e(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=Ve(s,e.membership,i));const a=e.sortBy||"lastCreated";"lastCreated"!==a&&"firstCreated"!==a||(s=s.sort("lastCreated"===a?Qe:Ke)),"displayName"===a&&(s=s.map((e=>e.displayName?e:Object.assign(Object.assign({},e),{displayName:""}))).sort(We)),t({onNextPage:g,data:s,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},p=(t,n)=>{var r;const o=null===(r=Ue(h))||void 0===r?void 0:r.data;o&&("onCreate"===n?o.data=[...new Set([t.channelId,...o.data])]:"onDelete"!==n||e.isDeleted||(o.data=o.data.filter((e=>e!==t.channelId))),De(h,o),d(o))},g=()=>{var e,t,n;const r=null===(e=Ue(h))||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=le(Vf,Object.assign(Object.assign({},c),{page:null!==(n=null==r?void 0:r.params.page)&&void 0!==n?n:{limit:l}}));fe(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(Q("channel"))])]),De(h,i),d(i)}),ue(u))};return f.push(Jf((e=>p(e,"onCreate"))),Yf((e=>p(e,"onDelete"))),Gf((e=>p(e,"onUpdate"))),oh((e=>p(e,"onRead")))),g(),()=>{r(`liveChannels(tmpid: ${s}) > dispose`),f.forEach((e=>e()))}},e.liveComments=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log("For using Live Collection feature you need to enable Cache!");const i=Date.now();r(`liveComments(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["comment","collection",{referenceId:e.referenceType,referenceType:e.referenceId}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["comment","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];i=$e(i,"isDeleted",e.isDeleted);const s=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===s?Qe:Ke),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;e.referenceId===t.referenceId&&e.referenceType===t.referenceType&&o&&("onCreate"===n?o.data=[...new Set([t.commentId,...o.data])]:"onDelete"===n&&(o.data=o.data.filter((e=>e!==t.commentId))),De(f,o),h(o))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(mf,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}}));fe(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(Q("comment"))])]),De(f,i),h(i)}),ue(l))};return u.push(Nf((e=>d(e,"onCreate"))),Ff((e=>d(e,"onUpdate"))),Bf((e=>d(e,"onDelete"))),Mf((e=>d(e,"onFlagged"))),Uf((e=>d(e,"onUnflagged"))),Df((e=>d(e,"onReactionAdded"))),Lf((e=>d(e,"onReactionRemoved")))),p(),()=>{r(`liveComments(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveFollowers=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log("For using Live Collection feature you need to enable Cache!");const i=Date.now();r(`liveFollowers(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["follow","collection",{userId:e.userId,type:"follower"}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.status&&"all"!==e.status&&(i=$e(i,"status",e.status)),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;e.userId===t.to&&o&&(["onDeclined","onCanceled","onUnfollowed","onDeleted"].includes(n)?o.data=o.data.filter((e=>e!==Q("follow")(t))):["onRequested","onAccepted","onFollowed"].includes(n)&&(o.data=[...new Set([Q("follow")(t),...o.data])]),De(f,o),h(o))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(Ah,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}}));fe(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(Q("follow"))])]),De(f,o),h(o)}),ue(l))};return u.push(jh((e=>d(e,"onRequested"))),Fh((e=>d(e,"onAccepted"))),Bh((e=>d(e,"onDeclined"))),Nh((e=>d(e,"onCanceled"))),xh((e=>d(e,"onFollowed"))),Ph((e=>d(e,"onUnfollowed"))),Rh((e=>d(e,"onDeleted")))),p(),()=>{r(`liveFollowers(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveFollowings=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log("For using Live Collection feature you need to enable Cache!");const i=Date.now();r(`liveFollowings(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["follow","collection",{userId:e.userId,type:"following"}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["follow","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];e.status&&"all"!==e.status&&(i=$e(i,"status",e.status)),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;e.userId===t.from&&o&&(["onDeclined","onCanceled","onUnfollowed","onDeleted"].includes(n)?o.data=o.data.filter((e=>e!==Q("follow")(t))):["onRequested","onAccepted","onFollowed"].includes(n)&&(o.data=[...new Set([Q("follow")(t),...o.data])]),De(f,o),h(o))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(Eh,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}}));fe(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(Q("follow"))])]),De(f,o),h(o)}),ue(l))};return u.push(jh((e=>d(e,"onRequested"))),Fh((e=>d(e,"onAccepted"))),Bh((e=>d(e,"onDeclined"))),Nh((e=>d(e,"onCanceled"))),xh((e=>d(e,"onFollowed"))),Ph((e=>d(e,"onUnfollowed"))),Rh((e=>d(e,"onDeleted")))),p(),()=>{r(`liveFollowings(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveMessage=(e,t)=>{const{log:n,cache:r}=ve();let o,i=!1;r||console.log(Yl);const s=Date.now();n(`liveMessage(tmpid: ${s}) > listen`);const a=[],c=e=>{var n;o&&(null===(n=e.data)||void 0===n?void 0:n.updatedAt)===(null==o?void 0:o.updatedAt)&&"server"!==e.origin||(t(e),o=e.data)},l=(e,t)=>{c({loading:!1,data:e,origin:"event"})};return a.push(ch((e=>l(e))),sh((e=>l(e))),ah((e=>l(e)))),(()=>{const t=le(nu,e,!0);fe(t,(({loading:e,data:t,error:n,origin:r,cachedAt:o})=>{-5===o?(c({data:t,origin:r,loading:!1,error:new pe("Observing unsynced object is not supported by Live Object.",800800,"error")}),i=!0,a.forEach((e=>e()))):i||c({loading:e,data:t,origin:r,error:n}),n&&a.forEach((e=>e()))}))})(),()=>{n(`liveMessage(tmpid: ${s}) > dispose`),a.forEach((e=>e()))}},e.liveMessages=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log(Gl);const i=Date.now();r(`liveMessages(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["message","collection",{channelId:e.channelId}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["message","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];i=$e(i,"isDeleted",e.isDeleted),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;e.channelId===t.channelId&&o&&("onCreate"===n?o.data=[...new Set([t.messageId,...o.data])]:["onDelete"].includes(n)&&(o.data=o.data.filter((e=>e!==t.messageId))),De(f,o),h(o))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(ou,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}}));fe(u,(({data:e,error:t,loading:n,prevPage:r})=>{const o={loading:n,error:t,params:{page:r},data:s};e&&(o.data=[...new Set([...s,...e.map(Q("message"))])]),De(f,o),h(o)}),ue(l))};return u.push(ch((e=>d(e,"onFetch"))),ih((e=>d(e,"onCreate"))),ah((e=>d(e,"onDelete"))),sh((e=>d(e,"onUpdate")))),p(),()=>{r(`liveMessages(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.livePosts=(e,t,n)=>{const{log:r,cache:o}=ve();o||console.log(Gl);const i=Date.now();r(`livePosts(tmpid: ${i}) > listen`);const{limit:s}=e,a=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["post","collection",{targetId:e.targetId,targetType:e.targetType}],h=n=>{var r,o;let i=null!==(r=n.data.map((e=>Ue(["post","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==r?r:[];i=$e(i,"isDeleted",e.isDeleted);const s=e.sortBy?e.sortBy:"lastCreated";i=i.sort("lastCreated"===s?Qe:Ke),e.tags&&(i=i.filter((t=>{var n;return null===(n=t.tags)||void 0===n?void 0:n.some((t=>{var n;return null===(n=e.tags)||void 0===n?void 0:n.includes(t)}))}))),t({onNextPage:p,data:i,hasNextPage:!!(null===(o=n.params)||void 0===o?void 0:o.page),loading:n.loading,error:n.error})},d=(t,n)=>{var r;const o=null===(r=Ue(f))||void 0===r?void 0:r.data;e.targetId===t.targetId&&e.targetType===t.targetType&&o&&("onCreate"===n?o.data=[...new Set([t.postId,...o.data])]:["onDelete","onDeclined"].includes(n)&&(o.data=o.data.filter((e=>e!==t.postId)),e.isDeleted&&o.data.unshift(t.postId)),"reviewing"===e.feedType&&"onApproved"===n&&(o.data=o.data.filter((e=>e!==t.postId))),De(f,o),h(o))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(tf,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}}));fe(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(Q("post"))])]),De(f,o),h(o)}),ue(l))};return u.push(Sf((e=>d(e,"onCreate"))),Of((e=>d(e,"onApproved"))),If((e=>d(e,"onDeclined"))),Ef((e=>d(e,"onDelete"))),Af((e=>d(e,"onUpdate"))),Tf((e=>d(e,"onFlagged"))),xf((e=>d(e,"onUnflagged"))),Pf((e=>d(e,"onReactionAdded"))),Rf((e=>d(e,"onReactionRemoved")))),p(),()=>{r(`livePosts(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveReactions=(e,t,n)=>{const{log:r,cache:o}=ve();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=zl(e,["limit"]),c=null!=s?s:5,{policy:l=Jl}=null!=n?n:{},u=[],f=["reaction","collection",{referenceId:e.referenceId,referenceType:e.referenceType}],h=e=>{var n,r;const o=null!==(n=e.data.map((e=>Ue(["reaction","get",e]))).filter(Boolean).map((({data:e})=>e)))&&void 0!==n?n:[];t({onNextPage:p,data:o,hasNextPage:!!(null===(r=e.params)||void 0===r?void 0:r.page),loading:e.loading,error:e.error})},d=(e,t)=>{var n;const r=null===(n=Ue(f))||void 0===n?void 0:n.data;r&&("onAdded"===t?r.data=[...new Set([e.reactionId,...r.data])]:"onRemoved"===t&&(r.data=r.data.filter((t=>t!==e.reactionId))),De(f,r),h(r))},p=()=>{var e,t,n,r,o;const i=null===(e=Ue(f))||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=le(_f,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}}));fe(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(Q("reaction"))])]),De(f,o),h(o)}),ue(l))};return u.push(qf(a.referenceType,a.referenceId,(e=>d(e,"onAdded"))),zf(a.referenceType,a.referenceId,(e=>d(e,"onRemoved")))),p(),()=>{r(`liveReactions(tmpid: ${i}) > dispose`),u.forEach((e=>e()))}},e.liveUser=(e,t)=>{const{log:n,cache:r}=ve();let o;r||console.log(Yl);const i=Date.now();n(`liveUser(tmpid: ${i}) > listen`);const s=[],a=e=>{var n;o&&(null===(n=e.data)||void 0===n?void 0:n.updatedAt)===(null==o?void 0:o.updatedAt)&&"server"!==e.origin||(t(e),o=e.data)},c=(e,t)=>{a({loading:!1,data:e,origin:"event"})};return s.push(Hl((e=>c(e))),Vl((e=>c(e))),Nl((e=>c(e))),Wl((e=>c(e))),Kl((e=>c(e))),Ql((e=>c(e)))),(()=>{const t=le(Ll,e,!0);fe(t,(({loading:e,data:t,error:n,origin:r})=>{a({loading:e,data:t,origin:r,error:n}),n&&s.forEach((e=>e()))}))})(),()=>{n(`liveUser(tmpid: ${i}) > dispose`),s.forEach((e=>e()))}},e.mergeInCache=Le,e.observeChannel=(e,t)=>{const{log:n}=ve(),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(Gf((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),Yf((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),Xf((e=>o({data:e,loading:!1,origin:"event"},"onJoin"))),Zf((e=>o({data:e,loading:!1,origin:"event"},"onLeft"))),eh((e=>o({data:e,loading:!1,origin:"event"},"onMemberAdded"))),th((e=>o({data:e,loading:!1,origin:"event"},"onMemberRemoved"))),oh((e=>o({data:e,loading:!1,origin:"event"},"onRead")))),fe(le(Kf,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeChannel(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}},e.observeChannels=e=>{const{log:t}=ve(),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(Jf((e=>o(e,"onCreate"))),Gf((e=>o(e,"onUpdate"))),Yf((e=>o(e,"onDelete"))),Xf((e=>o(e,"onJoin"))),Zf((e=>o(e,"onLeft"))),eh((e=>o(e,"onMemberAdded"))),th((e=>o(e,"onMemberRemoved"))),oh((e=>o(e,"onRead")))),()=>{t(`observeChannels(tmpid: ${n}) > dispose`),r.forEach((e=>e()))}},e.observeComment=(e,t,n="cache_then_server")=>{const{log:r}=ve(),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(Ff((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Bf((e=>s({data:e,loading:!1,origin:"event"},"onDelete"))),Mf((e=>s({data:e,loading:!1,origin:"event"},"onFlagged"))),Uf((e=>s({data:e,loading:!1,origin:"event"},"onUnflagged"))),Df((e=>s({data:e,loading:!1,origin:"event"},"onReactionAdded"))),Lf((e=>s({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),fe(le(vf,e),(e=>(e.data||e.error)&&i(e,"onFetch")),ue(n)),()=>{r(`observeComment(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},e.observeComments=(e,t)=>{const{log:n}=ve(),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(Nf((e=>i(e,"onCreate"))),Ff((e=>i(e,"onUpdate"))),Bf((e=>i(e,"onDelete"))),Mf((e=>i(e,"onFlagged"))),Uf((e=>i(e,"onUnflagged"))),Df((e=>i(e,"onReactionAdded"))),Lf((e=>i(e,"onReactionRemoved")))),()=>{n(`observeComments(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeCommunity=(e,t)=>{const{log:n}=ve(),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(dh((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),ph((e=>i({data:e,loading:!1,origin:"event"},"onDelete"))),gh((e=>i({data:e,loading:!1,origin:"event"},"onJoin"))),mh((e=>i({data:e,loading:!1,origin:"event"},"onLeft"))),yh((e=>i({data:e,loading:!1,origin:"event"},"onUserAdded"))),vh((e=>i({data:e,loading:!1,origin:"event"},"onUserRemoved"))),bh((e=>i({data:e,loading:!1,origin:"event"},"onUserBanned"))),wh((e=>i({data:e,loading:!1,origin:"event"},"onUserUnbanned")))),fe(le(uf,e),(e=>(e.data||e.error)&&o(e,"onFetch"))),()=>{n(`observeCommunity(tmpid: ${r}) > dispose`),s.forEach((e=>e()))}},e.observeFile=(e,t)=>{const{log:n}=ve(),r=Date.now();n(`observeFile(tmpid: ${r}) > listen`);return fe(le(Xl,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`)}},e.observeFollowInfo=(e,t,n="cache_then_server")=>{const{log:r}=ve(),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(Mh((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")))),fe(le(Ih,e),(e=>(e.data||e.error)&&i(e,"onFetch")),ue(n)),()=>{r(`observeFollowInfo(tmpid: ${o}) > dispose`),s.forEach((e=>e()))}},e.observeFollowers=(e,t)=>{const{log:n}=ve(),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(jh((e=>i(e,"onRequested"))),Fh((e=>i(e,"onAccepted"))),Bh((e=>i(e,"onDeclined"))),Nh((e=>i(e,"onCanceled"))),xh((e=>i(e,"onFollowed"))),Ph((e=>i(e,"onUnfollowed"))),Rh((e=>i(e,"onDeleted")))),()=>{n(`observeFollowers(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeFollowings=(e,t)=>{const{log:n}=ve(),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(jh((e=>i(e,"onRequested"))),Fh((e=>i(e,"onAccepted"))),Bh((e=>i(e,"onDeclined"))),Nh((e=>i(e,"onCanceled"))),xh((e=>i(e,"onFollowed"))),Ph((e=>i(e,"onUnfollowed"))),Rh((e=>i(e,"onDeleted")))),()=>{n(`observeFollowings(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeMessage=(e,t,n="cache_then_server")=>{const{log:r}=ve(),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(sh((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),ah((e=>i({data:e,loading:!1,origin:"event"},"onDelete")))),"no_fetch"!==n&&fe(le(nu,e),(e=>e.data&&i(e,"onFetch")),ue(n)),()=>{r(`observeMessages(tmpid: ${o}) > dispose`),s.forEach((e=>e()))}},e.observeMessages=(e,t)=>{const{log:n}=ve(),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.channelId)===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(ih((e=>i({data:e,loading:!1,origin:"event"},"onCreate"))),sh((e=>i({data:e,loading:!1,origin:"event"},"onUpdate"))),ah((e=>i({data:e,loading:!1,origin:"event"},"onDelete")))),()=>{n(`observeMessages(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observePoll=(e,t,n="cache_then_server")=>{const{log:r}=ve(),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(Dh((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Lh((e=>s({data:e,loading:!1,origin:"event"},"onDelete")))),fe(le(Uh,e),(e=>(e.data||e.error)&&i(e,"onFetch")),ue(n)),()=>{r(`observePoll(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},e.observePost=(e,t,n="cache_then_server")=>{const{log:r}=ve(),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(Af((e=>s({data:e,loading:!1,origin:"event"},"onUpdate"))),Ef((e=>s({data:e,loading:!1,origin:"event"},"onDelete"))),Of((e=>s({data:e,loading:!1,origin:"event"},"onApproved"))),If((e=>s({data:e,loading:!1,origin:"event"},"onDeclined"))),Tf((e=>s({data:e,loading:!1,origin:"event"},"onFlagged"))),xf((e=>s({data:e,loading:!1,origin:"event"},"onUnflagged"))),Pf((e=>s({data:e,loading:!1,origin:"event"},"onReactionAdded"))),Rf((e=>s({data:e,loading:!1,origin:"event"},"onReactionRemoved")))),fe(le(rf,e),(e=>(e.data||e.error)&&i(e,"onFetch")),ue(n)),()=>{r(`observePosts(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},e.observePosts=(e,t)=>{const{log:n}=ve(),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(Sf((e=>i(e,"onCreate"))),Af((e=>i(e,"onUpdate"))),Ef((e=>i(e,"onDelete"))),Of((e=>i(e,"onApproved"))),If((e=>i(e,"onDeclined"))),Tf((e=>i(e,"onFlagged"))),xf((e=>i(e,"onUnflagged"))),Pf((e=>i(e,"onReactionAdded"))),Rf((e=>i(e,"onReactionRemoved")))),()=>{n(`observePosts(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeUser=(e,t)=>{const{log:n}=ve(),r=Date.now();n(`observeUser(tmpid: ${r}) > listen`),console.log("observeUser will be deprecated on 25th November 2022, please use liveUser instead.");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(Vl((e=>o({data:e,loading:!1,origin:"event"},"onUpdate"))),Nl((e=>o({data:e,loading:!1,origin:"event"},"onDelete"))),Wl((e=>o({data:e,loading:!1,origin:"event"},"onFlagged"))),Kl((e=>o({data:e,loading:!1,origin:"event"},"onUnflagged"))),Ql((e=>o({data:e,loading:!1,origin:"event"},"onFlagCleared")))),fe(le(Ll,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeUser(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}},e.onChannelCreated=Jf,e.onChannelDeleted=Yf,e.onChannelJoined=Xf,e.onChannelLeft=Zf,e.onChannelMemberAdded=eh,e.onChannelMemberBanned=nh,e.onChannelMemberRead=oh,e.onChannelMemberRemoved=th,e.onChannelMemberUnbanned=rh,e.onChannelUpdated=Gf,e.onClientBanned=Ml,e.onClientDisconnected=e=>Bl((({code:t})=>{800211===t&&e()})),e.onCommentCreated=Nf,e.onCommentDeleted=Bf,e.onCommentFlagged=Mf,e.onCommentReactionAdded=Df,e.onCommentReactionRemoved=Lf,e.onCommentUnflagged=Uf,e.onCommentUpdated=Ff,e.onCommunityCreated=e=>lh("community.created",e),e.onCommunityDeleted=ph,e.onCommunityJoined=gh,e.onCommunityLeft=mh,e.onCommunityUpdated=dh,e.onCommunityUserAdded=yh,e.onCommunityUserBanned=bh,e.onCommunityUserRemoved=vh,e.onCommunityUserUnbanned=wh,e.onConnectionError=Bl,e.onFollowInfoUpdated=Mh,e.onFollowRequestAccepted=Fh,e.onFollowRequestCanceled=Nh,e.onFollowRequestDeclined=Bh,e.onFollowerDeleted=Rh,e.onFollowerRequested=jh,e.onMessageCreated=ih,e.onMessageDeleted=ah,e.onMessageFetched=ch,e.onMessageUpdated=sh,e.onPollDeleted=Lh,e.onPollUpdated=Dh,e.onPostApproved=Of,e.onPostCreated=Sf,e.onPostDeclined=If,e.onPostDeleted=Ef,e.onPostFlagged=Tf,e.onPostReactionAdded=Pf,e.onPostReactionRemoved=Rf,e.onPostUnflagged=xf,e.onPostUpdated=Af,e.onReactionAdded=(e,t,n)=>{const r=r=>{Q(e)(r)===t&&n(r)};if("message"===e){const e=ve(),t=e=>{var t;const n=Ue(["message","get",e.messages[0].messageId]),o=(null===(t=null==n?void 0:n.data)||void 0===t?void 0:t.reactionsCount)!==e.messages[0].reactionsCount;Rl(e),o&&r(e.messages[0])};return et(e,"reaction/onReactionAdded","v3.message.didUpdate",t)}return"post"===e?Pf(r):Df(r)},e.onReactionRemoved=(e,t,n)=>{const r=r=>{Q(e)(r)===t&&n(r)};if("message"===e){const e=ve(),t=e=>{var t;const n=Ue(["message","get",e.messages[0].messageId]),o=(null===(t=null==n?void 0:n.data)||void 0===t?void 0:t.reactionsCount)!==e.messages[0].reactionsCount;Rl(e),o&&r(e.messages[0])};return et(e,"reaction/onReactionRemoved","v3.message.didUpdate",t)}return"post"===e?Rf(r):Lf(r)},e.onReactorAdded=qf,e.onReactorRemoved=zf,e.onStreamRecorded=e=>{const t=ve();return et(t,"stream/onStreamRecorded","video-streaming.didRecord",(t=>{Rl(t),e(t.videoStreamings[0])}))},e.onStreamStarted=e=>{const t=ve();return et(t,"stream/onStreamStarted","video-streaming.didStart",(t=>{Rl(t),e(t.videoStreamings[0])}))},e.onStreamStopped=e=>{const t=ve();return et(t,"stream/onStreamStarted","video-streaming.didStop",(t=>{Rl(t),e(t.videoStreamings[0])}))},e.onUserDeleted=Nl,e.onUserFetched=Hl,e.onUserFlagCleared=Ql,e.onUserFlagged=Wl,e.onUserFollowed=xh,e.onUserUnflagged=Kl,e.onUserUnfollowed=Ph,e.onUserUpdated=Vl,e.pullFromCache=Ue,e.pushToCache=De,e.queryCache=Me,e.queryCategories=Ch,e.queryChannelMembers=Qf,e.queryChannels=Vf,e.queryComments=mf,e.queryCommunities=cf,e.queryCommunityMembers=df,e.queryFollowers=Ah,e.queryFollowings=Eh,e.queryGlobalFeed=kh,e.queryMessages=ou,e.queryOptions=ue,e.queryPosts=tf,e.queryReactions=_f,e.queryRoles=Zl,e.queryStreams=zh,e.queryUsers=$l,e.removeChannelMembers=async(e,t)=>{const n=ve();n.log("channel/removeChannelMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/channels/${encodeURIComponent(e)}/users`,{data:{channelId:e,userIds:t}}),o=Hf(r);n.cache&&Rl(o),t.forEach((e=>tt("v3.channel.didRemoveUsers",Object.assign(Object.assign({},o),{channelUsers:o.channelUsers.filter((t=>t.userId===e))}))));const{channelUsers:i}=o;return!!i.find((t=>t.channelId===e&&"member"!==t.membership))},e.removeChannelMembersRole=async(e,t,n)=>{const r=ve();r.log("channel/removeChannelMembersRole",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=Hf(o);r.cache&&Rl(i);const{channelUsers:s}=i;return!!s.find((n=>n.channelId===e&&!n.roles.includes(t)))},e.removeCommunityMembers=async(e,t)=>{const n=ve();n.log("community/removeCommunityMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/communities/${e}/users`,{data:{communityId:e,userIds:t}});n.cache&&Rl(r),tt("community.userRemoved",r);const{communityUsers:o}=r;return!!o.find((t=>t.communityId===e&&"member"!==t.communityMembership))},e.removeCommunityMembersRoles=async(e,t,n)=>{const r=ve();r.log("community/removeCommunityMembersRoles",e,t,n);const{data:o}=await r.http.delete(`/api/v4/communities/${e}/users/roles`,{data:{communityId:e,roles:t,userIds:n}});r.cache&&Rl(o);const{communityUsers:i}=o;return!!i.find((n=>n.communityId===e&&!t.some((e=>n.roles.includes(e)))))},e.removeReaction=Cf,e.restoreCache=async(e="amitySdk")=>{var t;const n=ve();if(!n.cache)return!1;n.log("cache/api/restoreCache",{storageKey:e});const r=null!==(t=await Be.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=fe,e.sortByChannelSegment=({channelSegment:e},{channelSegment:t})=>e-t,e.sortByDisplayName=We,e.sortByFirstCreated=Ke,e.sortByLastActivity=({lastActivity:e},{lastActivity:t})=>new Date(t).valueOf()-new Date(e).valueOf(),e.sortByLastCreated=Qe,e.sortBySegmentNumber=({segmentNumber:e},{segmentNumber:t})=>e-t,e.startReading=async(e,t=ve().userId)=>{const n=ve();n.log("message/startReading",{channelId:e});return!!await _l(n,"channel.startReading",{channelId:e})},e.stopReading=async e=>{const t=ve();t.log("message/stopReading",{channelId:e});return!!await _l(t,"channel.stopReading",{channelId:e})},e.subscribeTopic=lt,e.toPage=V,e.toPageRaw=W,e.toToken=H,e.unbanChannelMembers=async(e,t)=>{const n=ve();n.log("channel/unbanChannelMembers",{userIds:t,channelId:e});const{data:r}=await n.http.put(`/api/v3/channels/${encodeURIComponent(e)}/users/unban`,{userIds:t}),o=Hf(r),i=hf(o,"channelUsers"),s=n.cache&&Date.now();n.cache&&Rl(i,{cachedAt:s});const{channelUsers:a}=i;return{data:null==a?void 0:a.filter((e=>"member"===e.membership)),cachedAt:s}},e.unfollow=async e=>{const t=ve();t.log("follow/unfollow",e);const{data:n}=await t.http.delete(`/api/v4/me/following/${e}`);return t.cache&&Rl(n),tt("follow.unfollowed",n),!0},e.updateChannel=async(e,t)=>{const n=ve();n.log("channel/updateChannel",e,t);const{data:r}=await n.http.put(`/api/v3/channels/${encodeURIComponent(e)}`,t),o=Hf(r),i=n.cache&&Date.now();n.cache&&Rl(o,{cachedAt:i});const{channels:s}=o;return{data:s.find((t=>t.channelId===e)),cachedAt:i}},e.updateComment=async(e,t)=>{const n=ve();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&&Rl(r,{cachedAt:o}),tt("comment.updated",r);const{comments:i}=r;return{data:i.find((t=>t.commentId===e)),cachedAt:o}},e.updateCommunity=async(e,t)=>{const n=ve();n.log("community/updateCommunity",e,t);const{data:r}=await n.http.put(`/api/v3/communities/${e}`,af(t)),o=sf(r),i=n.cache&&Date.now();n.cache&&Rl(o,{cachedAt:i}),tt("community.updated",o);const{communities:s}=o;return{data:s.find((t=>t.communityId===e)),cachedAt:i}},e.updateMessage=Zu,e.updatePost=async(e,t)=>{const n=ve();n.log("user/updatePost",t);const{data:r}=await n.http.put(`/api/v4/posts/${encodeURIComponent(e)}`,t),o=n.cache&&Date.now();n.cache&&Rl(r,{cachedAt:o}),tt("post.updated",r);const{posts:i}=r;return{data:i.find((t=>t.postId===e)),cachedAt:o}},e.updateStream=async(e,t)=>{const n=ve();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&&Rl(r,{cachedAt:o});const{videoStreamings:i}=r;return{data:i.find((t=>t.streamId===e)),cachedAt:o}},e.updateUser=async(e,t)=>{const n=ve();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&&Rl(r,{cachedAt:o});const{users:i}=r;return tt("user.updated",r),{data:i.find((t=>t.userId===e)),cachedAt:o}},e.upsertInCache=qe,e.votePoll=async(e,t)=>{const n=ve();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&&Rl(r,{cachedAt:o});const{polls:i}=r;return tt("poll.updated",r),{data:i.find((t=>t.pollId===e)),cachedAt:o}},e.wipeCache=async(e="amitySdk")=>{const{log:t,cache:n,userId:r}=ve();return!!n&&(t("cache/api/wipeCache",{storageKey:e}),n.data={},await Be.setItem(`${e}#${r}`,"{}"),!0)},Object.defineProperty(e,"__esModule",{value:!0}),e}({});