@cloudbase/js-sdk 3.10.4-beta.0 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see index.esm.js.LICENSE.txt */
2
- import*as t from"@cloudbase/adapter-interface";import*as e from"jwt-decode";import*as n from"@cloudbase/adapter-wx_mp";import*as r from"@cloudbase/wx-cloud-client-sdk";import*as o from"web-streams-polyfill";import*as i from"@mattiasbuelens/web-streams-adapter";import*as s from"text-encoding-shim";import*as a from"bson";var c={3171:(t,e,n)=>{var r;if(n.r(e),n.d(e,{getEncryptInfo:()=>q}),!globalThis.IS_MP_BUILD){var o="undefined"!=typeof globalThis?globalThis.navigator:window.globalThis;function M(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}function B(t,e){return t&e}function W(t,e){return t|e}function F(t,e){return t^e}function H(t,e){return t&~e}function V(t){if(0==t)return-1;var e=0;return 65535&t||(t>>=16,e+=16),255&t||(t>>=8,e+=8),15&t||(t>>=4,e+=4),3&t||(t>>=2,e+=2),1&t||++e,e}function G(t){for(var e=0;0!=t;)t&=t-1,++e;return e}var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function K(t){var e,n,r="";for(e=0;e+3<=t.length;e+=3)n=parseInt(t.substring(e,e+3),16),r+=i.charAt(n>>6)+i.charAt(63&n);for(e+1==t.length?(n=parseInt(t.substring(e,e+1),16),r+=i.charAt(n<<2)):e+2==t.length&&(n=parseInt(t.substring(e,e+2),16),r+=i.charAt(n>>2)+i.charAt((3&n)<<4));(3&r.length)>0;)r+="=";return r}function J(t){var e,n="",r=0,o=0;for(e=0;e<t.length&&"="!=t.charAt(e);++e){var s=i.indexOf(t.charAt(e));s<0||(0==r?(n+=M(s>>2),o=3&s,r=1):1==r?(n+=M(o<<2|s>>4),o=15&s,r=2):2==r?(n+=M(o),n+=M(s>>2),o=3&s,r=3):(n+=M(o<<2|s>>4),n+=M(15&s),r=0))}return 1==r&&(n+=M(o<<2)),n}var s,a,c={decode:function(t){var e;if(void 0===s){var n="0123456789ABCDEF";for(s={},e=0;e<16;++e)s[n.charAt(e)]=e;for(n=n.toLowerCase(),e=10;e<16;++e)s[n.charAt(e)]=e;for(e=0;e<8;++e)s[" \f\n\r\t \u2028\u2029".charAt(e)]=-1}var r=[],o=0,i=0;for(e=0;e<t.length;++e){var a=t.charAt(e);if("="==a)break;if(-1!=(a=s[a])){if(void 0===a)throw new Error("Illegal character at offset "+e);o|=a,++i>=2?(r[r.length]=o,o=0,i=0):o<<=4}}if(i)throw new Error("Hex encoding incomplete: 4 bits missing");return r}},u={decode:function(t){var e;if(void 0===a){for(a=Object.create(null),e=0;e<64;++e)a["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;for(e=0;e<9;++e)a["= \f\n\r\t \u2028\u2029".charAt(e)]=-1}var n=[],r=0,o=0;for(e=0;e<t.length;++e){var i=t.charAt(e);if("="==i)break;if(-1!=(i=a[i])){if(void 0===i)throw new Error("Illegal character at offset "+e);r|=i,++o>=4?(n[n.length]=r>>16,n[n.length]=r>>8&255,n[n.length]=255&r,r=0,o=0):r<<=6}}switch(o){case 1:throw new Error("Base64 encoding incomplete: at least 2 bits missing");case 2:n[n.length]=r>>10;break;case 3:n[n.length]=r>>16,n[n.length]=r>>8&255}return n},re:/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,unarmor:function(t){var e=u.re.exec(t);if(e)if(e[1])t=e[1];else{if(!e[2])throw new Error("RegExp out of sync");t=e[2]}return u.decode(t)}},l=1e13;class z{constructor(t){this.buf=[+t||0]}mulAdd(t,e){var n,r,o=this.buf,i=o.length;for(n=0;n<i;++n)(r=o[n]*t+e)<l?e=0:r-=(e=0|r/l)*l,o[n]=r;e>0&&(o[n]=e)}sub(t){var e,n,r=this.buf,o=r.length;for(e=0;e<o;++e)(n=r[e]-t)<0?(n+=l,t=1):t=0,r[e]=n;for(;0===r[r.length-1];)r.pop()}toString(t){if(10!=(t||10))throw new Error("only base 10 is supported");for(var e=this.buf,n=e[e.length-1].toString(),r=e.length-2;r>=0;--r)n+=(l+e[r]).toString().substring(1);return n}valueOf(){for(var t=this.buf,e=0,n=t.length-1;n>=0;--n)e=e*l+t[n];return e}simplify(){var t=this.buf;return 1==t.length?t[0]:this}}var h,d=/^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/,f=/^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;function $(t,e){return t.length>e&&(t=t.substring(0,e)+"…"),t}class Y{constructor(t,e){this.hexDigits="0123456789ABCDEF",t instanceof Y?(this.enc=t.enc,this.pos=t.pos):(this.enc=t,this.pos=e)}get(t){if(void 0===t&&(t=this.pos++),t>=this.enc.length)throw new Error("Requesting byte offset "+t+" on a stream of length "+this.enc.length);return"string"==typeof this.enc?this.enc.charCodeAt(t):this.enc[t]}hexByte(t){return this.hexDigits.charAt(t>>4&15)+this.hexDigits.charAt(15&t)}hexDump(t,e,n){for(var r="",o=t;o<e;++o)if(r+=this.hexByte(this.get(o)),!0!==n)switch(15&o){case 7:r+=" ";break;case 15:r+="\n";break;default:r+=" "}return r}isASCII(t,e){for(var n=t;n<e;++n){var r=this.get(n);if(r<32||r>176)return!1}return!0}parseStringISO(t,e){for(var n="",r=t;r<e;++r)n+=String.fromCharCode(this.get(r));return n}parseStringUTF(t,e){for(var n="",r=t;r<e;){var o=this.get(r++);n+=o<128?String.fromCharCode(o):o>191&&o<224?String.fromCharCode((31&o)<<6|63&this.get(r++)):String.fromCharCode((15&o)<<12|(63&this.get(r++))<<6|63&this.get(r++))}return n}parseStringBMP(t,e){for(var n,r,o="",i=t;i<e;)n=this.get(i++),r=this.get(i++),o+=String.fromCharCode(n<<8|r);return o}parseTime(t,e,n){var r=this.parseStringISO(t,e),o=(n?d:f).exec(r);return o?(n&&(o[1]=+o[1],o[1]+=+o[1]<70?2e3:1900),r=o[1]+"-"+o[2]+"-"+o[3]+" "+o[4],o[5]&&(r+=":"+o[5],o[6]&&(r+=":"+o[6],o[7]&&(r+="."+o[7]))),o[8]&&(r+=" UTC","Z"!=o[8]&&(r+=o[8],o[9]&&(r+=":"+o[9]))),r):"Unrecognized time: "+r}parseInteger(t,e){for(var n,r=this.get(t),o=r>127,i=o?255:0,s="";r==i&&++t<e;)r=this.get(t);if(0===(n=e-t))return o?-1:0;if(n>4){for(s=r,n<<=3;!(128&(+s^i));)s=+s<<1,--n;s="("+n+" bit)\n"}o&&(r-=256);for(var a=new z(r),c=t+1;c<e;++c)a.mulAdd(256,this.get(c));return s+a.toString()}parseBitString(t,e,n){for(var r=this.get(t),o="("+((e-t-1<<3)-r)+" bit)\n",i="",s=t+1;s<e;++s){for(var a=this.get(s),c=s==e-1?r:0,u=7;u>=c;--u)i+=a>>u&1?"1":"0";if(i.length>n)return o+$(i,n)}return o+i}parseOctetString(t,e,n){if(this.isASCII(t,e))return $(this.parseStringISO(t,e),n);var r=e-t,o="("+r+" byte)\n";r>(n/=2)&&(e=t+n);for(var i=t;i<e;++i)o+=this.hexByte(this.get(i));return r>n&&(o+="…"),o}parseOID(t,e,n){for(var r="",o=new z,i=0,s=t;s<e;++s){var a=this.get(s);if(o.mulAdd(128,127&a),i+=7,!(128&a)){if(""===r)if((o=o.simplify())instanceof z)o.sub(80),r="2."+o.toString();else{var c=o<80?o<40?0:1:2;r=c+"."+(o-40*c)}else r+="."+o.toString();if(r.length>n)return $(r,n);o=new z,i=0}}return i>0&&(r+=".incomplete"),r}}class Q{constructor(t,e,n,r,o){if(!(r instanceof X))throw new Error("Invalid tag value.");this.stream=t,this.header=e,this.length=n,this.tag=r,this.sub=o}typeName(){switch(this.tag.tagClass){case 0:switch(this.tag.tagNumber){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString"}return"Universal_"+this.tag.tagNumber.toString();case 1:return"Application_"+this.tag.tagNumber.toString();case 2:return"["+this.tag.tagNumber.toString()+"]";case 3:return"Private_"+this.tag.tagNumber.toString()}}content(t){if(void 0===this.tag)return null;void 0===t&&(t=1/0);var e=this.posContent(),n=Math.abs(this.length);if(!this.tag.isUniversal())return null!==this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+n,t);switch(this.tag.tagNumber){case 1:return 0===this.stream.get(e)?"false":"true";case 2:return this.stream.parseInteger(e,e+n);case 3:return this.sub?"("+this.sub.length+" elem)":this.stream.parseBitString(e,e+n,t);case 4:return this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+n,t);case 6:return this.stream.parseOID(e,e+n,t);case 16:case 17:return null!==this.sub?"("+this.sub.length+" elem)":"(no elem)";case 12:return $(this.stream.parseStringUTF(e,e+n),t);case 18:case 19:case 20:case 21:case 22:case 26:return $(this.stream.parseStringISO(e,e+n),t);case 30:return $(this.stream.parseStringBMP(e,e+n),t);case 23:case 24:return this.stream.parseTime(e,e+n,23==this.tag.tagNumber)}return null}toString(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+(null===this.sub?"null":this.sub.length)+"]"}toPrettyString(t){void 0===t&&(t="");var e=t+this.typeName()+" @"+this.stream.pos;if(this.length>=0&&(e+="+"),e+=this.length,this.tag.tagConstructed?e+=" (constructed)":!this.tag.isUniversal()||3!=this.tag.tagNumber&&4!=this.tag.tagNumber||null===this.sub||(e+=" (encapsulates)"),e+="\n",null!==this.sub){t+=" ";for(var n=0,r=this.sub.length;n<r;++n)e+=this.sub[n].toPrettyString(t)}return e}posStart(){return this.stream.pos}posContent(){return this.stream.pos+this.header}posEnd(){return this.stream.pos+this.header+Math.abs(this.length)}toHexString(){return this.stream.hexDump(this.posStart(),this.posEnd(),!0)}static decodeLength(t){var e=t.get(),n=127&e;if(n==e)return n;if(n>6)throw new Error("Length over 48 bits not supported at position "+(t.pos-1));if(0===n)return null;e=0;for(var r=0;r<n;++r)e=256*e+t.get();return e}getHexStringValue(){var t=this.toHexString(),e=2*this.header,n=2*this.length;return t.substr(e,n)}static decode(t){var e;e=t instanceof Y?t:new Y(t,0);var n=new Y(e),r=new X(e),o=Q.decodeLength(e),i=e.pos,s=i-n.pos,a=null,c=function(){var t=[];if(null!==o){for(var n=i+o;e.pos<n;)t[t.length]=Q.decode(e);if(e.pos!=n)throw new Error("Content size is not correct for container starting at offset "+i)}else try{for(;;){var r=Q.decode(e);if(r.tag.isEOC())break;t[t.length]=r}o=i-e.pos}catch(t){throw new Error("Exception while decoding undefined length content: "+t)}return t};if(r.tagConstructed)a=c();else if(r.isUniversal()&&(3==r.tagNumber||4==r.tagNumber))try{if(3==r.tagNumber&&0!=e.get())throw new Error("BIT STRINGs with unused bits cannot encapsulate.");a=c();for(var u=0;u<a.length;++u)if(a[u].tag.isEOC())throw new Error("EOC is not supposed to be actual content.")}catch(t){a=null}if(null===a){if(null===o)throw new Error("We can't skip over an invalid tag with undefined length at offset "+i);e.pos=i+Math.abs(o)}return new Q(n,s,o,r,a)}}class X{constructor(t){var e=t.get();if(this.tagClass=e>>6,this.tagConstructed=!!(32&e),this.tagNumber=31&e,31==this.tagNumber){var n=new z;do{e=t.get(),n.mulAdd(128,127&e)}while(128&e);this.tagNumber=n.simplify()}}isUniversal(){return 0===this.tagClass}isEOC(){return 0===this.tagClass&&0===this.tagNumber}}var p=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],v=(1<<26)/p[p.length-1];class Z{constructor(t,e,n){null!=t&&("number"==typeof t?this.fromNumber(t,e,n):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}toString(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var n,r=(1<<e)-1,o=!1,i="",s=this.t,a=this.DB-s*this.DB%e;if(s-- >0)for(a<this.DB&&(n=this[s]>>a)>0&&(o=!0,i=M(n));s>=0;)a<e?(n=(this[s]&(1<<a)-1)<<e-a,n|=this[--s]>>(a+=this.DB-e)):(n=this[s]>>(a-=e)&r,a<=0&&(a+=this.DB,--s)),n>0&&(o=!0),o&&(i+=M(n));return o?i:"0"}negate(){var t=tt();return Z.ZERO.subTo(this,t),t}abs(){return this.s<0?this.negate():this}compareTo(t){var e=this.s-t.s;if(0!=e)return e;var n=this.t;if(0!=(e=n-t.t))return this.s<0?-e:e;for(;--n>=0;)if(0!=(e=this[n]-t[n]))return e;return 0}bitLength(){return this.t<=0?0:this.DB*(this.t-1)+at(this[this.t-1]^this.s&this.DM)}mod(t){var e=tt();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(Z.ZERO)>0&&t.subTo(e,e),e}modPowInt(t,e){var n;return n=t<256||e.isEven()?new g(e):new m(e),this.exp(t,n)}clone(){var t=tt();return this.copyTo(t),t}intValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}byteValue(){return 0==this.t?this.s:this[0]<<24>>24}shortValue(){return 0==this.t?this.s:this[0]<<16>>16}signum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}toByteArray(){var t=this.t,e=[];e[0]=this.s;var n,r=this.DB-t*this.DB%8,o=0;if(t-- >0)for(r<this.DB&&(n=this[t]>>r)!=(this.s&this.DM)>>r&&(e[o++]=n|this.s<<this.DB-r);t>=0;)r<8?(n=(this[t]&(1<<r)-1)<<8-r,n|=this[--t]>>(r+=this.DB-8)):(n=this[t]>>(r-=8)&255,r<=0&&(r+=this.DB,--t)),128&n&&(n|=-256),0==o&&(128&this.s)!=(128&n)&&++o,(o>0||n!=this.s)&&(e[o++]=n);return e}equals(t){return 0==this.compareTo(t)}min(t){return this.compareTo(t)<0?this:t}max(t){return this.compareTo(t)>0?this:t}and(t){var e=tt();return this.bitwiseTo(t,B,e),e}or(t){var e=tt();return this.bitwiseTo(t,W,e),e}xor(t){var e=tt();return this.bitwiseTo(t,F,e),e}andNot(t){var e=tt();return this.bitwiseTo(t,H,e),e}not(){for(var t=tt(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t}shiftLeft(t){var e=tt();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}shiftRight(t){var e=tt();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}getLowestSetBit(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+V(this[t]);return this.s<0?this.t*this.DB:-1}bitCount(){for(var t=0,e=this.s&this.DM,n=0;n<this.t;++n)t+=G(this[n]^e);return t}testBit(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:!!(this[e]&1<<t%this.DB)}setBit(t){return this.changeBit(t,W)}clearBit(t){return this.changeBit(t,H)}flipBit(t){return this.changeBit(t,F)}add(t){var e=tt();return this.addTo(t,e),e}subtract(t){var e=tt();return this.subTo(t,e),e}multiply(t){var e=tt();return this.multiplyTo(t,e),e}divide(t){var e=tt();return this.divRemTo(t,e,null),e}remainder(t){var e=tt();return this.divRemTo(t,null,e),e}divideAndRemainder(t){var e=tt(),n=tt();return this.divRemTo(t,e,n),[e,n]}modPow(t,e){var n,r,o=t.bitLength(),i=st(1);if(o<=0)return i;n=o<18?1:o<48?3:o<144?4:o<768?5:6,r=o<8?new g(e):e.isEven()?new b(e):new m(e);var s=[],a=3,c=n-1,u=(1<<n)-1;if(s[1]=r.convert(this),n>1){var l=tt();for(r.sqrTo(s[1],l);a<=u;)s[a]=tt(),r.mulTo(l,s[a-2],s[a]),a+=2}var h,d,f=t.t-1,p=!0,v=tt();for(o=at(t[f])-1;f>=0;){for(o>=c?h=t[f]>>o-c&u:(h=(t[f]&(1<<o+1)-1)<<c-o,f>0&&(h|=t[f-1]>>this.DB+o-c)),a=n;!(1&h);)h>>=1,--a;if((o-=a)<0&&(o+=this.DB,--f),p)s[h].copyTo(i),p=!1;else{for(;a>1;)r.sqrTo(i,v),r.sqrTo(v,i),a-=2;a>0?r.sqrTo(i,v):(d=i,i=v,v=d),r.mulTo(v,s[h],i)}for(;f>=0&&!(t[f]&1<<o);)r.sqrTo(i,v),d=i,i=v,v=d,--o<0&&(o=this.DB-1,--f)}return r.revert(i)}modInverse(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return Z.ZERO;for(var n=t.clone(),r=this.clone(),o=st(1),i=st(0),s=st(0),a=st(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),e?(o.isEven()&&i.isEven()||(o.addTo(this,o),i.subTo(t,i)),o.rShiftTo(1,o)):i.isEven()||i.subTo(t,i),i.rShiftTo(1,i);for(;r.isEven();)r.rShiftTo(1,r),e?(s.isEven()&&a.isEven()||(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);n.compareTo(r)>=0?(n.subTo(r,n),e&&o.subTo(s,o),i.subTo(a,i)):(r.subTo(n,r),e&&s.subTo(o,s),a.subTo(i,a))}return 0!=r.compareTo(Z.ONE)?Z.ZERO:a.compareTo(t)>=0?a.subtract(t):a.signum()<0?(a.addTo(t,a),a.signum()<0?a.add(t):a):a}pow(t){return this.exp(t,new y)}gcd(t){var e=this.s<0?this.negate():this.clone(),n=t.s<0?t.negate():t.clone();if(e.compareTo(n)<0){var r=e;e=n,n=r}var o=e.getLowestSetBit(),i=n.getLowestSetBit();if(i<0)return e;for(o<i&&(i=o),i>0&&(e.rShiftTo(i,e),n.rShiftTo(i,n));e.signum()>0;)(o=e.getLowestSetBit())>0&&e.rShiftTo(o,e),(o=n.getLowestSetBit())>0&&n.rShiftTo(o,n),e.compareTo(n)>=0?(e.subTo(n,e),e.rShiftTo(1,e)):(n.subTo(e,n),n.rShiftTo(1,n));return i>0&&n.lShiftTo(i,n),n}isProbablePrime(t){var e,n=this.abs();if(1==n.t&&n[0]<=p[p.length-1]){for(e=0;e<p.length;++e)if(n[0]==p[e])return!0;return!1}if(n.isEven())return!1;for(e=1;e<p.length;){for(var r=p[e],o=e+1;o<p.length&&r<v;)r*=p[o++];for(r=n.modInt(r);e<o;)if(r%p[e++]==0)return!1}return n.millerRabin(t)}copyTo(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}fromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}fromString(t,e){var n;if(16==e)n=4;else if(8==e)n=3;else if(256==e)n=8;else if(2==e)n=1;else if(32==e)n=5;else{if(4!=e)return void this.fromRadix(t,e);n=2}this.t=0,this.s=0;for(var r=t.length,o=!1,i=0;--r>=0;){var s=8==n?255&+t[r]:it(t,r);s<0?"-"==t.charAt(r)&&(o=!0):(o=!1,0==i?this[this.t++]=s:i+n>this.DB?(this[this.t-1]|=(s&(1<<this.DB-i)-1)<<i,this[this.t++]=s>>this.DB-i):this[this.t-1]|=s<<i,(i+=n)>=this.DB&&(i-=this.DB))}8==n&&128&+t[0]&&(this.s=-1,i>0&&(this[this.t-1]|=(1<<this.DB-i)-1<<i)),this.clamp(),o&&Z.ZERO.subTo(this,this)}clamp(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}dlShiftTo(t,e){var n;for(n=this.t-1;n>=0;--n)e[n+t]=this[n];for(n=t-1;n>=0;--n)e[n]=0;e.t=this.t+t,e.s=this.s}drShiftTo(t,e){for(var n=t;n<this.t;++n)e[n-t]=this[n];e.t=Math.max(this.t-t,0),e.s=this.s}lShiftTo(t,e){for(var n=t%this.DB,r=this.DB-n,o=(1<<r)-1,i=Math.floor(t/this.DB),s=this.s<<n&this.DM,a=this.t-1;a>=0;--a)e[a+i+1]=this[a]>>r|s,s=(this[a]&o)<<n;for(a=i-1;a>=0;--a)e[a]=0;e[i]=s,e.t=this.t+i+1,e.s=this.s,e.clamp()}rShiftTo(t,e){e.s=this.s;var n=Math.floor(t/this.DB);if(n>=this.t)e.t=0;else{var r=t%this.DB,o=this.DB-r,i=(1<<r)-1;e[0]=this[n]>>r;for(var s=n+1;s<this.t;++s)e[s-n-1]|=(this[s]&i)<<o,e[s-n]=this[s]>>r;r>0&&(e[this.t-n-1]|=(this.s&i)<<o),e.t=this.t-n,e.clamp()}}subTo(t,e){for(var n=0,r=0,o=Math.min(t.t,this.t);n<o;)r+=this[n]-t[n],e[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r-=t.s;n<this.t;)r+=this[n],e[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r-=t[n],e[n++]=r&this.DM,r>>=this.DB;r-=t.s}e.s=r<0?-1:0,r<-1?e[n++]=this.DV+r:r>0&&(e[n++]=r),e.t=n,e.clamp()}multiplyTo(t,e){var n=this.abs(),r=t.abs(),o=n.t;for(e.t=o+r.t;--o>=0;)e[o]=0;for(o=0;o<r.t;++o)e[o+n.t]=n.am(0,r[o],e,o,0,n.t);e.s=0,e.clamp(),this.s!=t.s&&Z.ZERO.subTo(e,e)}squareTo(t){for(var e=this.abs(),n=t.t=2*e.t;--n>=0;)t[n]=0;for(n=0;n<e.t-1;++n){var r=e.am(n,e[n],t,2*n,0,1);(t[n+e.t]+=e.am(n+1,2*e[n],t,2*n+1,r,e.t-n-1))>=e.DV&&(t[n+e.t]-=e.DV,t[n+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(n,e[n],t,2*n,0,1)),t.s=0,t.clamp()}divRemTo(t,e,n){var r=t.abs();if(!(r.t<=0)){var o=this.abs();if(o.t<r.t)return null!=e&&e.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=tt());var i=tt(),s=this.s,a=t.s,c=this.DB-at(r[r.t-1]);c>0?(r.lShiftTo(c,i),o.lShiftTo(c,n)):(r.copyTo(i),o.copyTo(n));var u=i.t,l=i[u-1];if(0!=l){var h=l*(1<<this.F1)+(u>1?i[u-2]>>this.F2:0),d=this.FV/h,f=(1<<this.F1)/h,p=1<<this.F2,v=n.t,y=v-u,g=e??tt();for(i.dlShiftTo(y,g),n.compareTo(g)>=0&&(n[n.t++]=1,n.subTo(g,n)),Z.ONE.dlShiftTo(u,g),g.subTo(i,i);i.t<u;)i[i.t++]=0;for(;--y>=0;){var m=n[--v]==l?this.DM:Math.floor(n[v]*d+(n[v-1]+p)*f);if((n[v]+=i.am(0,m,n,y,0,u))<m)for(i.dlShiftTo(y,g),n.subTo(g,n);n[v]<--m;)n.subTo(g,n)}null!=e&&(n.drShiftTo(u,e),s!=a&&Z.ZERO.subTo(e,e)),n.t=u,n.clamp(),c>0&&n.rShiftTo(c,n),s<0&&Z.ZERO.subTo(n,n)}}}invDigit(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e}isEven(){return 0==(this.t>0?1&this[0]:this.s)}exp(t,e){if(t>4294967295||t<1)return Z.ONE;var n=tt(),r=tt(),o=e.convert(this),i=at(t)-1;for(o.copyTo(n);--i>=0;)if(e.sqrTo(n,r),(t&1<<i)>0)e.mulTo(r,o,n);else{var s=n;n=r,r=s}return e.revert(n)}chunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}toRadix(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),n=Math.pow(t,e),r=st(n),o=tt(),i=tt(),s="";for(this.divRemTo(r,o,i);o.signum()>0;)s=(n+i.intValue()).toString(t).substr(1)+s,o.divRemTo(r,o,i);return i.intValue().toString(t)+s}fromRadix(t,e){this.fromInt(0),null==e&&(e=10);for(var n=this.chunkSize(e),r=Math.pow(e,n),o=!1,i=0,s=0,a=0;a<t.length;++a){var c=it(t,a);c<0?"-"==t.charAt(a)&&0==this.signum()&&(o=!0):(s=e*s+c,++i>=n&&(this.dMultiply(r),this.dAddOffset(s,0),i=0,s=0))}i>0&&(this.dMultiply(Math.pow(e,i)),this.dAddOffset(s,0)),o&&Z.ZERO.subTo(this,this)}fromNumber(t,e,n){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,n),this.testBit(t-1)||this.bitwiseTo(Z.ONE.shiftLeft(t-1),W,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(Z.ONE.shiftLeft(t-1),this);else{var r=[],o=7&t;r.length=1+(t>>3),e.nextBytes(r),o>0?r[0]&=(1<<o)-1:r[0]=0,this.fromString(r,256)}}bitwiseTo(t,e,n){var r,o,i=Math.min(t.t,this.t);for(r=0;r<i;++r)n[r]=e(this[r],t[r]);if(t.t<this.t){for(o=t.s&this.DM,r=i;r<this.t;++r)n[r]=e(this[r],o);n.t=this.t}else{for(o=this.s&this.DM,r=i;r<t.t;++r)n[r]=e(o,t[r]);n.t=t.t}n.s=e(this.s,t.s),n.clamp()}changeBit(t,e){var n=Z.ONE.shiftLeft(t);return this.bitwiseTo(n,e,n),n}addTo(t,e){for(var n=0,r=0,o=Math.min(t.t,this.t);n<o;)r+=this[n]+t[n],e[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r+=t.s;n<this.t;)r+=this[n],e[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r+=t[n],e[n++]=r&this.DM,r>>=this.DB;r+=t.s}e.s=r<0?-1:0,r>0?e[n++]=r:r<-1&&(e[n++]=this.DV+r),e.t=n,e.clamp()}dMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}dAddOffset(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}}multiplyLowerTo(t,e,n){var r=Math.min(this.t+t.t,e);for(n.s=0,n.t=r;r>0;)n[--r]=0;for(var o=n.t-this.t;r<o;++r)n[r+this.t]=this.am(0,t[r],n,r,0,this.t);for(o=Math.min(t.t,e);r<o;++r)this.am(0,t[r],n,r,0,e-r);n.clamp()}multiplyUpperTo(t,e,n){--e;var r=n.t=this.t+t.t-e;for(n.s=0;--r>=0;)n[r]=0;for(r=Math.max(e-this.t,0);r<t.t;++r)n[this.t+r-e]=this.am(e-r,t[r],n,0,0,this.t+r-e);n.clamp(),n.drShiftTo(1,n)}modInt(t){if(t<=0)return 0;var e=this.DV%t,n=this.s<0?t-1:0;if(this.t>0)if(0==e)n=this[0]%t;else for(var r=this.t-1;r>=0;--r)n=(e*n+this[r])%t;return n}millerRabin(t){var e=this.subtract(Z.ONE),n=e.getLowestSetBit();if(n<=0)return!1;var r=e.shiftRight(n);(t=t+1>>1)>p.length&&(t=p.length);for(var o=tt(),i=0;i<t;++i){o.fromInt(p[Math.floor(Math.random()*p.length)]);var s=o.modPow(r,this);if(0!=s.compareTo(Z.ONE)&&0!=s.compareTo(e)){for(var a=1;a++<n&&0!=s.compareTo(e);)if(0==(s=s.modPowInt(2,this)).compareTo(Z.ONE))return!1;if(0!=s.compareTo(e))return!1}}return!0}square(){var t=tt();return this.squareTo(t),t}gcda(t,e){var n=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(n.compareTo(r)<0){var o=n;n=r,r=o}var i=n.getLowestSetBit(),s=r.getLowestSetBit();if(s<0)e(n);else{i<s&&(s=i),s>0&&(n.rShiftTo(s,n),r.rShiftTo(s,r));var a=()=>{(i=n.getLowestSetBit())>0&&n.rShiftTo(i,n),(i=r.getLowestSetBit())>0&&r.rShiftTo(i,r),n.compareTo(r)>=0?(n.subTo(r,n),n.rShiftTo(1,n)):(r.subTo(n,r),r.rShiftTo(1,r)),n.signum()>0?setTimeout(a,0):(s>0&&r.lShiftTo(s,r),setTimeout(function(){e(r)},0))};setTimeout(a,10)}}fromNumberAsync(t,e,n,r){if("number"==typeof e)if(t<2)this.fromInt(1);else{this.fromNumber(t,n),this.testBit(t-1)||this.bitwiseTo(Z.ONE.shiftLeft(t-1),W,this),this.isEven()&&this.dAddOffset(1,0);var o=this,i=function(){o.dAddOffset(2,0),o.bitLength()>t&&o.subTo(Z.ONE.shiftLeft(t-1),o),o.isProbablePrime(e)?setTimeout(function(){r()},0):setTimeout(i,0)};setTimeout(i,0)}else{var s=[],a=7&t;s.length=1+(t>>3),e.nextBytes(s),a>0?s[0]&=(1<<a)-1:s[0]=0,this.fromString(s,256)}}}var y=function(){function t(){}return t.prototype.convert=function(t){return t},t.prototype.revert=function(t){return t},t.prototype.mulTo=function(t,e,n){t.multiplyTo(e,n)},t.prototype.sqrTo=function(t,e){t.squareTo(e)},t}(),g=function(){function t(t){this.m=t}return t.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},t.prototype.mulTo=function(t,e,n){t.multiplyTo(e,n),this.reduce(n)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}(),m=function(){function t(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}return t.prototype.convert=function(t){var e=tt();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(Z.ZERO)>0&&this.m.subTo(e,e),e},t.prototype.revert=function(t){var e=tt();return t.copyTo(e),this.reduce(e),e},t.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var n=32767&t[e],r=n*this.mpl+((n*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[n=e+this.m.t]+=this.m.am(0,r,t,e,0,this.m.t);t[n]>=t.DV;)t[n]-=t.DV,t[++n]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},t.prototype.mulTo=function(t,e,n){t.multiplyTo(e,n),this.reduce(n)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}(),b=function(){function t(t){this.m=t,this.r2=tt(),this.q3=tt(),Z.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t)}return t.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=tt();return t.copyTo(e),this.reduce(e),e},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},t.prototype.mulTo=function(t,e,n){t.multiplyTo(e,n),this.reduce(n)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}();function tt(){return new Z(null)}function et(t,e){return new Z(t,e)}function nt(t,e,n,r,o,i){for(;--i>=0;){var s=e*this[t++]+n[r]+o;o=Math.floor(s/67108864),n[r++]=67108863&s}return o}function rt(t,e,n,r,o,i){for(var s=32767&e,a=e>>15;--i>=0;){var c=32767&this[t],u=this[t++]>>15,l=a*c+u*s;o=((c=s*c+((32767&l)<<15)+n[r]+(1073741823&o))>>>30)+(l>>>15)+a*u+(o>>>30),n[r++]=1073741823&c}return o}function ot(t,e,n,r,o,i){for(var s=16383&e,a=e>>14;--i>=0;){var c=16383&this[t],u=this[t++]>>14,l=a*c+u*s;o=((c=s*c+((16383&l)<<14)+n[r]+o)>>28)+(l>>14)+a*u,n[r++]=268435455&c}return o}void 0!==o&&"Microsoft Internet Explorer"==(null==o?void 0:o.appName)?(Z.prototype.am=rt,h=30):"Netscape"!=(null==o?void 0:o.appName)?(Z.prototype.am=nt,h=26):(Z.prototype.am=ot,h=28),Z.prototype.DB=h,Z.prototype.DM=(1<<h)-1,Z.prototype.DV=1<<h,Z.prototype.FV=Math.pow(2,52),Z.prototype.F1=52-h,Z.prototype.F2=2*h-52;var w,_,E=[];for(w="0".charCodeAt(0),_=0;_<=9;++_)E[w++]=_;for(w="a".charCodeAt(0),_=10;_<36;++_)E[w++]=_;for(w="A".charCodeAt(0),_=10;_<36;++_)E[w++]=_;function it(t,e){return E[t.charCodeAt(e)]??-1}function st(t){var e=tt();return e.fromInt(t),e}function at(t){var e,n=1;return 0!=(e=t>>>16)&&(t=e,n+=16),0!=(e=t>>8)&&(t=e,n+=8),0!=(e=t>>4)&&(t=e,n+=4),0!=(e=t>>2)&&(t=e,n+=2),0!=(e=t>>1)&&(t=e,n+=1),n}Z.ZERO=st(0),Z.ONE=st(1);class ct{constructor(){this.i=0,this.j=0,this.S=[]}init(t){var e,n,r;for(e=0;e<256;++e)this.S[e]=e;for(n=0,e=0;e<256;++e)n=n+this.S[e]+t[e%t.length]&255,r=this.S[e],this.S[e]=this.S[n],this.S[n]=r;this.i=0,this.j=0}next(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]}}var I,S,O=null;if(null==O){O=[],S=0;var T,A,P=void 0;if("undefined"!=typeof window&&null!==(T=window)&&void 0!==T&&T.crypto&&null!==(A=window)&&void 0!==A&&A.crypto.getRandomValues){var R,C=new Uint32Array(256);for(null===(R=window)||void 0===R||R.crypto.getRandomValues(C),P=0;P<C.length;++P)O[S++]=255&C[P]}var k,N,x,U=function(t){var e,n,r;if(this.count=this.count||0,this.count>=256||S>=256){if("undefined"!=typeof window)if(null!==(e=window)&&void 0!==e&&e.removeEventListener)null===(r=window)||void 0===r||r.removeEventListener("mousemove",U,!1);else if(null!==(n=window)&&void 0!==n&&n.detachEvent){var o;null===(o=window)||void 0===o||o.detachEvent("onmousemove",U)}}else try{var i=t.x+t.y;O[S++]=255&i,this.count+=1}catch(t){}};if("undefined"!=typeof window)if(null!==(k=window)&&void 0!==k&&k.addEventListener)null===(x=window)||void 0===x||x.addEventListener("mousemove",U,!1);else if(null!==(N=window)&&void 0!==N&&N.attachEvent){var L;null===(L=window)||void 0===L||L.attachEvent("onmousemove",U)}}function ut(){if(null==I){for(I=new ct;S<256;){var t=Math.floor(65536*Math.random());O[S++]=255&t}for(I.init(O),S=0;S<O.length;++S)O[S]=0;S=0}return I.next()}class lt{constructor(){}nextBytes(t){for(var e=0;e<t.length;++e)t[e]=ut()}}function ht(t,e){if(e<t.length+11)return console.error("Message too long for RSA"),null;for(var n=[],r=t.length-1;r>=0&&e>0;){var o=t.charCodeAt(r--);o<128?n[--e]=o:o>127&&o<2048?(n[--e]=63&o|128,n[--e]=o>>6|192):(n[--e]=63&o|128,n[--e]=o>>6&63|128,n[--e]=o>>12|224)}n[--e]=0;for(var i=new lt,s=[];e>2;){for(s[0]=0;0==s[0];)i.nextBytes(s);n[--e]=s[0]}return n[--e]=2,n[--e]=0,new Z(n)}class dt{constructor(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}doPublic(t){return t.modPowInt(this.e,this.n)}doPrivate(t){if(null==this.p||null==this.q)return t.modPow(this.d,this.n);for(var e=t.mod(this.p).modPow(this.dmp1,this.p),n=t.mod(this.q).modPow(this.dmq1,this.q);e.compareTo(n)<0;)e=e.add(this.p);return e.subtract(n).multiply(this.coeff).mod(this.p).multiply(this.q).add(n)}setPublic(t,e){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=et(t,16),this.e=parseInt(e,16)):console.error("Invalid RSA public key")}encrypt(t){var e=ht(t,this.n.bitLength()+7>>3);if(null==e)return null;var n=this.doPublic(e);if(null==n)return null;var r=n.toString(16);return 1&r.length?"0"+r:r}encryptLong(t){var e=this,n=(this.n.bitLength()+7>>3)-11;try{var r="";return t.length>n?(t.match(/.{1,117}/g).forEach(function(t){var n=e.encrypt(t);r+=n}),K(r)):K(this.encrypt(t))}catch(t){return!1}}decryptLong(t){var e=this,n=this.n.bitLength()+7>>3;t=J(t);try{if(t.length>n){var r="";return t.match(/.{1,256}/g).forEach(function(t){var n=e.decrypt(t);r+=n}),r}return this.decrypt(t)}catch(t){return!1}}setPrivate(t,e,n){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=et(t,16),this.e=parseInt(e,16),this.d=et(n,16)):console.error("Invalid RSA private key")}setPrivateEx(t,e,n,r,o,i,s,a){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=et(t,16),this.e=parseInt(e,16),this.d=et(n,16),this.p=et(r,16),this.q=et(o,16),this.dmp1=et(i,16),this.dmq1=et(s,16),this.coeff=et(a,16)):console.error("Invalid RSA private key")}generate(t,e){var n=new lt,r=t>>1;this.e=parseInt(e,16);for(var o=new Z(e,16);;){for(;this.p=new Z(t-r,1,n),0!=this.p.subtract(Z.ONE).gcd(o).compareTo(Z.ONE)||!this.p.isProbablePrime(10););for(;this.q=new Z(r,1,n),0!=this.q.subtract(Z.ONE).gcd(o).compareTo(Z.ONE)||!this.q.isProbablePrime(10););if(this.p.compareTo(this.q)<=0){var i=this.p;this.p=this.q,this.q=i}var s=this.p.subtract(Z.ONE),a=this.q.subtract(Z.ONE),c=s.multiply(a);if(0==c.gcd(o).compareTo(Z.ONE)){this.n=this.p.multiply(this.q),this.d=o.modInverse(c),this.dmp1=this.d.mod(s),this.dmq1=this.d.mod(a),this.coeff=this.q.modInverse(this.p);break}}}decrypt(t){var e=et(t,16),n=this.doPrivate(e);return null==n?null:ft(n,this.n.bitLength()+7>>3)}generateAsync(t,e,n){var r=new lt,o=t>>1;this.e=parseInt(e,16);var i=new Z(e,16),s=this,a=()=>{var e=()=>{if(s.p.compareTo(s.q)<=0){var t=s.p;s.p=s.q,s.q=t}var e=s.p.subtract(Z.ONE),r=s.q.subtract(Z.ONE),o=e.multiply(r);0==o.gcd(i).compareTo(Z.ONE)?(s.n=s.p.multiply(s.q),s.d=i.modInverse(o),s.dmp1=s.d.mod(e),s.dmq1=s.d.mod(r),s.coeff=s.q.modInverse(s.p),setTimeout(function(){n()},0)):setTimeout(a,0)},c=()=>{s.q=tt(),s.q.fromNumberAsync(o,1,r,function(){s.q.subtract(Z.ONE).gcda(i,function(t){0==t.compareTo(Z.ONE)&&s.q.isProbablePrime(10)?setTimeout(e,0):setTimeout(c,0)})})},u=()=>{s.p=tt(),s.p.fromNumberAsync(t-o,1,r,function(){s.p.subtract(Z.ONE).gcda(i,function(t){0==t.compareTo(Z.ONE)&&s.p.isProbablePrime(10)?setTimeout(c,0):setTimeout(u,0)})})};setTimeout(u,0)};setTimeout(a,0)}}function ft(t,e){for(var n=t.toByteArray(),r=0;r<n.length&&0==n[r];)++r;if(n.length-r!=e-1||2!=n[r])return null;for(++r;0!=n[r];)if(++r>=n.length)return null;for(var o="";++r<n.length;){var i=255&n[r];i<128?o+=String.fromCharCode(i):i>191&&i<224?(o+=String.fromCharCode((31&i)<<6|63&n[r+1]),++r):(o+=String.fromCharCode((15&i)<<12|(63&n[r+1])<<6|63&n[r+2]),r+=2)}return o}class pt extends dt{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";super(),t&&("string"==typeof t?this.parseKey(t):(this.hasPrivateKeyProperty(t)||this.hasPublicKeyProperty(t))&&this.parsePropertiesFrom(t))}parseKey(t){try{var e=0,n=0,r=/^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/.test(t)?c.decode(t):u.unarmor(t),o=Q.decode(r);if(3===o.sub.length&&(o=o.sub[2].sub[0]),9===o.sub.length){e=o.sub[1].getHexStringValue(),this.n=et(e,16),n=o.sub[2].getHexStringValue(),this.e=parseInt(n,16);var i=o.sub[3].getHexStringValue();this.d=et(i,16);var s=o.sub[4].getHexStringValue();this.p=et(s,16);var a=o.sub[5].getHexStringValue();this.q=et(a,16);var l=o.sub[6].getHexStringValue();this.dmp1=et(l,16);var h=o.sub[7].getHexStringValue();this.dmq1=et(h,16);var d=o.sub[8].getHexStringValue();this.coeff=et(d,16)}else{if(2!==o.sub.length)return!1;var f=o.sub[1].sub[0];e=f.sub[0].getHexStringValue(),this.n=et(e,16),n=f.sub[1].getHexStringValue(),this.e=parseInt(n,16)}return!0}catch(t){return!1}}hasPublicKeyProperty(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")}hasPrivateKeyProperty(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")&&t.hasOwnProperty("d")&&t.hasOwnProperty("p")&&t.hasOwnProperty("q")&&t.hasOwnProperty("dmp1")&&t.hasOwnProperty("dmq1")&&t.hasOwnProperty("coeff")}parsePropertiesFrom(t){this.n=t.n,this.e=t.e,t.hasOwnProperty("d")&&(this.d=t.d,this.p=t.p,this.q=t.q,this.dmp1=t.dmp1,this.dmq1=t.dmq1,this.coeff=t.coeff)}}(r=function(t){t=t||{},this.default_key_size=parseInt(t.default_key_size,10)||1024,this.default_public_exponent=t.default_public_exponent||"010001",this.log=t.log||!1,this.key=null}).prototype.setKey=function(t){this.log&&this.key&&console.warn("A key was already set, overriding existing."),this.key=new pt(t)},r.prototype.setPrivateKey=function(t){this.setKey(t)},r.prototype.setPublicKey=function(t){this.setKey(t)},r.prototype.decrypt=function(t){try{return this.getKey().decrypt(J(t))}catch(t){return!1}},r.prototype.encrypt=function(t){try{return K(this.getKey().encrypt(t))}catch(t){return!1}},r.prototype.encryptLong=function(t){try{for(var e=this.getKey().encryptLong(t)||"",n=this.getKey().decryptLong(e)||"",r=0,o=/null$/g;o.test(n)&&(r++,e=this.getKey().encryptLong(t)||"",n=this.getKey().decryptLong(e)||"",!(r>10)););return e}catch(t){return!1}},r.prototype.getKey=function(t){if(!this.key){if(this.key=new pt,t&&"[object Function]"==={}.toString.call(t))return void this.key.generateAsync(this.default_key_size,this.default_public_exponent,t);this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},r.version="3.1.4"}const D=r;var j=n(2631),q=function(t){var e=void 0===t?{}:t,n=e.publicKey,r=void 0===n?"":n,o=e.payload,i=void 0===o?{}:o;if(!r)return"";try{var s=(0,j.I)(i),a=new D;return a.setPublicKey(r),a.encryptLong("object"==typeof s?JSON.stringify(s):s)}catch(t){console.error("encrypt error:",t)}return""}},2631:(t,e,n)=>{n.d(e,{I:()=>r,y:()=>o});var r=function(t){var e=function(e){for(var n in t)t.hasOwnProperty(n)&&(e[n]=r(t[n]));return e},n=null==t?"NullOrUndefined":Object.prototype.toString.call(t).slice(8,-1);if(["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(n))return t.slice();switch(n){case"Object":return e(Object.create(Object.getPrototypeOf(t)));case"Array":return e([]);case"Date":return new Date(t.valueOf());case"RegExp":return new RegExp(t.source,(t.global?"g":"")+(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.sticky?"y":"")+(t.unicode?"u":""));default:return t}},o=function(t){var e=t.match(/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/);return e&&e[2]||""}},3388:t=>{t.exports={}},8182:function(t,e,n){var r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)},o=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&o(e,t,n);return i(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.useDefaultAdapter=e.useAdapters=e.RUNTIME=void 0;var a,c=s(n(4274)),u=n(3616);!function(t){t.WEB="web",t.WX_MP="wx_mp"}(a=e.RUNTIME||(e.RUNTIME={})),e.useAdapters=function(t,e){for(var n=0,o=(0,u.isArray)(t)?t:[t];n<o.length;n++){var i=o[n],s=i.isMatch,a=i.genAdapter,c=i.runtime;if(s())return{adapter:r({isMatch:s},a(e)),runtime:c}}},e.useDefaultAdapter=function(){return{adapter:r({},c.genAdapter()),runtime:a.WEB}}},4274:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},a=this&&this.__generator||function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.WebRequest=e.genAdapter=void 0;var c=n(7149),u=n(3616),l=n(2946);function h(t){try{return JSON.parse(t)}catch(e){return t}}var d=function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}return o(e,t),e.prototype.get=function(t){return this.request(i(i({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(i(i({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(i(i({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t,n=e.data,r=e.file,o=e.fileContent,s=e.name,a=e.method,c=e.headers,u=void 0===c?{}:c,l=null!=r?r:o,h={post:"post",put:"put"}[null==a?void 0:a.toLowerCase()]||"put",d=new FormData;return"post"===h?(Object.keys(n).forEach(function(t){d.append(t,n[t])}),d.append("key",s),d.append("file",l instanceof Blob?l:new Blob([l])),this.request(i(i({},t),{data:d,method:h}),this.restrictedMethods.includes("upload"))):this.request(i(i({},t),{method:"put",headers:u,body:l}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return s(this,void 0,void 0,function(){var e,n,r,o;return a(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this.get(i(i({},t),{headers:{},responseType:"blob"}))];case 1:return e=s.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return s.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return s(this,void 0,void 0,function(){var n,r,o,c,u,l,d,f,p,v,y,g,m,b,w,_=this;return a(this,function(E){switch(E.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,c=void 0!==o&&o,u=t.stream,l=void 0!==u&&u,d=t.signal,f=t.timeout,p=t.shouldThrowOnError,v=void 0===p||p,y=null!=f?f:this.timeout,d&&(d.aborted&&n.abort(),d.addEventListener("abort",function(){return n.abort()})),g=null,c&&y&&(g=setTimeout(function(){console.warn(_.timeoutMsg),n.abort(new Error(_.timeoutMsg))},y)),[4,fetch(r,i(i({},t),{signal:n.signal})).then(function(t){return s(_,void 0,void 0,function(){var e,n,r;return a(this,function(o){switch(o.label){case 0:return clearTimeout(g),v?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(g),Promise.reject(t)})];case 1:return m=E.sent(),l?(b=m.body,[3,5]):[3,2];case 2:return(null===(e=m.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?(w=h,[4,m.text()]):[3,4];case 3:return b=w.apply(void 0,[E.sent()]),[3,5];case 4:b=m.text(),E.label=5;case 5:return[2,{data:b,statusCode:m.status,header:m.headers,response:m}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var i=t.url,s=t.headers,a=void 0===s?{}:s,c=t.data,h=t.responseType,d=t.withCredentials,f=t.body,p=t.onUploadProgress,v=(0,u.formatUrl)((0,l.getProtocol)(),i,"get"===r?c:{}),y=new XMLHttpRequest;y.open(r,v),h&&(y.responseType=h);var g,m,b=t.signal;b&&(b.aborted?y.abort():b.addEventListener("abort",function(){return y.abort()},{once:!0})),Object.keys(a).forEach(function(t){y.setRequestHeader(t,a[t])}),p&&y.upload.addEventListener("progress",p),y.onreadystatechange=function(){var t={};if(4===y.readyState){var e=y.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=y.status;try{t.data="blob"===h?y.response:JSON.parse(y.responseText)}catch(e){t.data="blob"===h?y.response:y.responseText}clearTimeout(g),o(t)}},e&&n.timeout&&(g=setTimeout(function(){console.warn(n.timeoutMsg),y.abort()},n.timeout)),m=(0,u.isFormData)(c)?c:"application/x-www-form-urlencoded"===a["content-type"]?(0,u.toQueryString)(c):f||(c?JSON.stringify(c):void 0),d&&(y.withCredentials=!0),y.send(m)})},e}(c.AbstractSDKRequest);e.WebRequest=d,e.genAdapter=function(){return{type:"default",root:window,reqClass:d,wsClass:WebSocket,localStorage}}},2946:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.COMMUNITY_SITE_URL=e.IS_DEBUG_MODE=e.getProtocol=e.setProtocol=e.getSdkName=e.setSdkName=void 0;var n="@cloudbase/js-sdk";e.setSdkName=function(t){n=t},e.getSdkName=function(){return n};var r="https:";e.setProtocol=function(t){r=t},e.getProtocol=function(){return r},e.IS_DEBUG_MODE=!1,e.COMMUNITY_SITE_URL="https://support.qq.com/products/148793"},6205:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ERRORS=void 0,e.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}},794:function(t,e,n){var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.OATUH_LOGINTYPE=void 0,o(n(2946),e),o(n(6205),e),e.OATUH_LOGINTYPE="constants"},7718:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},o=this&&this.__generator||function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.catchErrorsDecorator=void 0;var i=n(3616),s=n(794),a=!1;"undefined"!=typeof navigator&&navigator.userAgent&&(a=-1!==navigator.userAgent.indexOf("Firefox"));var c=a?/(\.js\/)?__decorate(\$\d+)?<@.*\d$/:/(\/\w+\.js\.)?__decorate(\$\d+)?\s*\(.*\)$/,u=/https?:\/\/.+:\d*\/.*\.js:\d+:\d+/;function l(t){var e=t.err,n=t.className,r=t.methodName,o=t.sourceLink;if(!o)return null;var i,s=e.stack.split("\n"),c=a?/^catchErrorsDecorator\/<\/descriptor.value@.*\d$/:new RegExp("".concat(n,"\\.descriptor.value\\s*\\[as\\s").concat(r,"\\]\\s*\\(.*\\)$")),l=a?/^catchErrorsDecorator\/<\/descriptor.value/:new RegExp("".concat(n,"\\.descriptor.value\\s*\\[as\\s").concat(r,"\\]")),h=s.findIndex(function(t){return c.test(t)});if(-1!==h){var d=s.filter(function(t,e){return e>h});d.unshift(s[h].replace(l,"".concat(n,".").concat(r)).replace(u,o)),(i=new Error).stack="".concat(a?"@debugger":"Error","\n").concat(d.join("\n"))}return i}e.catchErrorsDecorator=function(t){var e=t.mode,n=void 0===e?"async":e,a=t.customInfo,h=void 0===a?{}:a,d=t.title,f=t.messages,p=void 0===f?[]:f;return function(t,e,a){if(s.IS_DEBUG_MODE){var f=h.className||t.constructor.name,v=h.methodName||e,y=a.value,g=function(){var t="",e=(new Error).stack.split("\n"),n=e.findIndex(function(t){return c.test(t)});if(-1!==n){var r=u.exec(e[n+1]||"");t=r?r[0]:""}return t}();a.value="sync"===n?function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=l({err:new Error,className:f,methodName:v,sourceLink:g});try{return y.apply(this,t)}catch(t){var r=t,o=t.message,s=t.error,a=t.error_description,c={title:d||"".concat(f,".").concat(v," failed"),content:[{type:"error",body:t}]};if(o&&/^\{.*\}$/.test(o)){var u=JSON.parse(o);c.subtitle=o,u.code&&(n?(n.code=u.code,n.msg=u.msg):(t.code=u.code,t.message=u.msg),r=n||t,c.content=p.map(function(t){return{type:"info",body:t}}))}throw s&&a&&(c.subtitle=a,n?(n.code=s,n.msg=a):(t.code=s,t.message=a),r=n||t,c.content=p.map(function(t){return{type:"info",body:t}})),(0,i.printGroupLog)(c),r}}:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return r(this,void 0,void 0,function(){var e,n,r,s,a,c,u,h;return o(this,function(o){switch(o.label){case 0:e=l({err:new Error,className:f,methodName:v,sourceLink:g}),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,y.apply(this,t)];case 2:return[2,o.sent()];case 3:throw n=o.sent(),r=n,s=n.message,a=n.error,c=n.error_description,u={title:d||"".concat(f,".").concat(v," failed"),content:[{type:"error",body:n}]},s&&/^\{.*\}$/.test(s)&&(h=JSON.parse(s),u.subtitle=h,h.code&&(e?(e.code=h.code,e.message=h.msg):(n.code=h.code,n.message=h.msg),r=e||n,u.content=p.map(function(t){return{type:"info",body:t}}))),a&&c&&(u.subtitle=c,e?(e.code=a,e.msg=c):(n.code=a,n.message=c),r=e||n,u.content=p.map(function(t){return{type:"info",body:t}})),(0,i.printGroupLog)(u),r;case 4:return[2]}})})}}}}},141:function(t,e,n){var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),o(n(7718),e)},6197:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},s=this&&this.__generator||function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.CloudbaseCache=void 0;var a=n(7149),c=n(3616),u=n(794),l=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return o(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(a.AbstractStorage),h=function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:((0,c.printWarn)(u.ERRORS.INVALID_PARAMS,"localStorage is not supported on current platform"),new l(e.root));case"none":return new l(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}return Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:u.ERRORS.OPERATION_FAIL,msg:"[".concat((0,u.getSdkName)(),"][").concat(u.ERRORS.OPERATION_FAIL,"]setStore failed"),info:t}))}}else(0,c.printWarn)(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return i(this,void 0,void 0,function(){var r;return s(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}(0,c.printWarn)(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return i(this,void 0,void 0,function(){var r;return s(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):(0,c.printWarn)(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return i(this,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})},t}();e.CloudbaseCache=h},9689:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0}),e.removeEventListener=e.activateEvent=e.addEventListener=e.CloudbaseEventEmitter=e.IErrorEvent=e.CloudbaseEvent=void 0;var s=n(3616),a=function(t,e){this.data=e||null,this.name=t};e.CloudbaseEvent=a;var c=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return o(e,t),e}(a);e.IErrorEvent=c;var u=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if((0,s.isInstanceOf)(t,c))return console.error(t.error),this;var n=(0,s.isString)(t)?new a(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,u=this.listeners[r]?i([],this.listeners[r],!0):[];o<u.length;o++)u[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();e.CloudbaseEventEmitter=u;var l=new u;e.addEventListener=function(t,e){l.on(t,e)},e.activateEvent=function(t,e){void 0===e&&(e={}),l.fire(t,e)},e.removeEventListener=function(t,e){l.off(t,e)}},3616:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__rest||function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n};Object.defineProperty(e,"__esModule",{value:!0}),e.parseCaptcha=e.parseQueryString=e.transformPhone=e.sleep=e.printGroupLog=e.errorToResult=e.promoteGatewayError=e.maybeThrow=e.resolveThrow=e.createCloudbaseError=e.CloudbaseError=e.throwError=e.printInfo=e.printError=e.printWarn=e.execCallback=e.createPromiseCallback=e.removeParam=e.getHash=e.getQuery=e.toQueryString=e.formatUrl=e.generateRequestId=e.genSeqId=e.isFormData=e.isInstanceOf=e.isNull=e.isPalinObject=e.isUndefined=e.isString=e.isArray=void 0;var a=n(794);e.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},e.isString=function(t){return"string"==typeof t},e.isUndefined=function(t){return void 0===t},e.isPalinObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)},e.isNull=function(t){return"[object Null]"===Object.prototype.toString.call(t)},e.isInstanceOf=function(t,e){return t instanceof e},e.isFormData=function(t){return"[object FormData]"===Object.prototype.toString.call(t)},e.genSeqId=function(){return Math.random().toString(16).slice(2)},e.generateRequestId=function(){var t=(new Date).getTime(),e=(null===Date||void 0===Date?void 0:Date.now)&&1e3*Date.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){var r=16*Math.random();return t>0?(r=(t+r)%16|0,t=Math.floor(t/16)):(r=(e+r)%16|0,e=Math.floor(e/16)),("x"===n?r:7&r|8).toString(16)})},e.formatUrl=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)},e.toQueryString=function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")},e.getQuery=function(t,e){if("undefined"==typeof window)return!1;var n=e||decodeURIComponent(window.location.search),r=new RegExp("(^|&)".concat(t,"=([^&]*)(&|$)")),o=n.substr(n.indexOf("?")+1).match(r);return null!=o?o[2]:""},e.getHash=function(t){if("undefined"==typeof window)return"";var e=window.location.hash.match(new RegExp("[#?&/]".concat(t,"=([^&#]*)")));return e?e[1]:""},e.removeParam=function(t,e){var n=e.split("?")[0],r=[],o=-1!==e.indexOf("?")?e.split("?")[1]:"";if(""!==o){for(var i=(r=o.split("&")).length-1;i>=0;i-=1)r[i].split("=")[0]===t&&r.splice(i,1);n="".concat(n,"?").concat(r.join("&"))}return n},e.createPromiseCallback=function(){var t={};if(!Promise){(t=function(){}).promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var n=new Promise(function(e,n){t=function(t,r){return t?n(t):e(r)}});return t.promise=n,t},e.execCallback=function(t,e,n){if(void 0===n&&(n=null),t&&"function"==typeof t)return t(e,n);if(e)throw e;return n},e.printWarn=function(t,e){console.warn("[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e))},e.printError=function(t,e){console.error({code:t,msg:"[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e)})},e.printInfo=function(t,e){console.log("[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e))},e.throwError=function(t,e){var n=new Error(JSON.stringify({code:t,msg:"[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e)}));throw n.code=t,n};var c=function(t){function e(e){var n=t.call(this,e.msg||e.message||"")||this;return n.code=e.code||"",n.requestId=e.requestId||"",Object.defineProperty(n,"message",{value:e.msg||e.message||"",enumerable:!0,writable:!0,configurable:!0}),n}return o(e,t),e}(Error);e.CloudbaseError=c;var u=function(t){return new c(t)};function l(t,e){return(e||u)(t)}function h(t){return!t||"boolean"!=typeof t.throw||t.throw}e.createCloudbaseError=l,e.resolveThrow=h,e.maybeThrow=function(t,e){if(h(t))throw l(i(i({},e),{msg:e.message}),null==t?void 0:t.errorFactory);return i({code:e.code,message:e.message},e.requestId?{requestId:e.requestId}:{})},e.promoteGatewayError=function(t){if(t&&"object"==typeof t&&t.data&&"object"==typeof t.data){var e=t.data,n=e.code,r=e.message;if(!t.code&&n||!t.message&&r)return i(i(i({},t),!t.code&&n?{code:n}:{}),!t.message&&r?{message:r}:{})}return t},e.errorToResult=function(t){if(t instanceof Error&&"string"==typeof t.message)try{var e=JSON.parse(t.message);if(e&&"string"==typeof e.code)return{code:e.code,message:e.msg||e.message||"",requestId:e.requestId}}catch(t){}return t&&"string"==typeof t.code?{code:t.code,message:t.message||"",requestId:t.requestId}:{code:"UNKNOWN_ERROR",message:String((null==t?void 0:t.message)||t||"")}},e.printGroupLog=function(t){var e,n=t.title,r=t.subtitle,o=void 0===r?"":r,i=t.content,s=void 0===i?[]:i,a=t.printTrace,c=void 0!==a&&a,u=t.collapsed;void 0!==u&&u?(console.groupCollapsed||console.error)(n,o):(console.group||console.error)(n,o);for(var l=0,h=s;l<h.length;l++){var d=h[l],f=d.type,p=d.body;switch(f){case"info":console.log(p);break;case"warn":console.warn(p);break;case"error":console.error(p)}}c&&(console.trace||console.log)("stack trace:"),null===(e=console.groupEnd)||void 0===e||e.call(console)},e.sleep=function(t){return void 0===t&&(t=0),new Promise(function(e){return setTimeout(e,t)})},e.transformPhone=function(t){return"+86".concat(t)},e.parseQueryString=function(t){t=t.replace(/^\?/,"");var e={};return t.split("&").forEach(function(t){var n=t.split("="),r=n[0],o=n[1];r=decodeURIComponent(r),o=decodeURIComponent(o),r&&(e[r]?Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]:e[r]=o)}),e},e.parseCaptcha=function(t){var n={},r=t.match(/^(data:.*?)(\?[^#\s]*)?$/);if(r){t=r[1];var o=r[2];o&&(n=(0,e.parseQueryString)(o))}var i=n.token,a=s(n,["token"]);return/^data:/.test(t)&&!i?{error:"invalid_argument",error_description:"invalid captcha data: ".concat(t)}:i?{state:a.state,token:i,captchaData:t}:{error:"unimplemented",error_description:"need to impl captcha data"}}},9515:(t,e,n)=>{var r=n(8761)(n(7772),"DataView");t.exports=r},9612:(t,e,n)=>{var r=n(2118),o=n(6909),i=n(8138),s=n(4174),a=n(7942);function c(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}c.prototype.clear=r,c.prototype.delete=o,c.prototype.get=i,c.prototype.has=s,c.prototype.set=a,t.exports=c},235:(t,e,n)=>{var r=n(3945),o=n(1846),i=n(8028),s=n(2344),a=n(4769);function c(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}c.prototype.clear=r,c.prototype.delete=o,c.prototype.get=i,c.prototype.has=s,c.prototype.set=a,t.exports=c},326:(t,e,n)=>{var r=n(8761)(n(7772),"Map");t.exports=r},6738:(t,e,n)=>{var r=n(2411),o=n(6417),i=n(6928),s=n(9493),a=n(4150);function c(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}c.prototype.clear=r,c.prototype.delete=o,c.prototype.get=i,c.prototype.has=s,c.prototype.set=a,t.exports=c},2760:(t,e,n)=>{var r=n(8761)(n(7772),"Promise");t.exports=r},2143:(t,e,n)=>{var r=n(8761)(n(7772),"Set");t.exports=r},6571:(t,e,n)=>{var r=n(235),o=n(5243),i=n(2858),s=n(4417),a=n(8605),c=n(1418);function u(t){var e=this.__data__=new r(t);this.size=e.size}u.prototype.clear=o,u.prototype.delete=i,u.prototype.get=s,u.prototype.has=a,u.prototype.set=c,t.exports=u},857:(t,e,n)=>{var r=n(7772).Symbol;t.exports=r},9162:(t,e,n)=>{var r=n(7772).Uint8Array;t.exports=r},3215:(t,e,n)=>{var r=n(8761)(n(7772),"WeakMap");t.exports=r},2517:t=>{t.exports=function(t,e){for(var n=-1,r=null==t?0:t.length;++n<r&&!1!==e(t[n],n,t););return t}},7552:t=>{t.exports=function(t,e){for(var n=-1,r=null==t?0:t.length,o=0,i=[];++n<r;){var s=t[n];e(s,n,t)&&(i[o++]=s)}return i}},1634:(t,e,n)=>{var r=n(6473),o=n(9631),i=n(6152),s=n(3226),a=n(9045),c=n(7598),u=Object.prototype.hasOwnProperty;t.exports=function(t,e){var n=i(t),l=!n&&o(t),h=!n&&!l&&s(t),d=!n&&!l&&!h&&c(t),f=n||l||h||d,p=f?r(t.length,String):[],v=p.length;for(var y in t)!e&&!u.call(t,y)||f&&("length"==y||h&&("offset"==y||"parent"==y)||d&&("buffer"==y||"byteLength"==y||"byteOffset"==y)||a(y,v))||p.push(y);return p}},343:t=>{t.exports=function(t,e){for(var n=-1,r=null==t?0:t.length,o=Array(r);++n<r;)o[n]=e(t[n],n,t);return o}},5067:t=>{t.exports=function(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}},91:(t,e,n)=>{var r=n(3940),o=n(1225),i=Object.prototype.hasOwnProperty;t.exports=function(t,e,n){var s=t[e];i.call(t,e)&&o(s,n)&&(void 0!==n||e in t)||r(t,e,n)}},2218:(t,e,n)=>{var r=n(1225);t.exports=function(t,e){for(var n=t.length;n--;)if(r(t[n][0],e))return n;return-1}},7993:(t,e,n)=>{var r=n(752),o=n(249);t.exports=function(t,e){return t&&r(e,o(e),t)}},5906:(t,e,n)=>{var r=n(752),o=n(8582);t.exports=function(t,e){return t&&r(e,o(e),t)}},3940:(t,e,n)=>{var r=n(3043);t.exports=function(t,e,n){"__proto__"==e&&r?r(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}},8874:(t,e,n)=>{var r=n(6571),o=n(2517),i=n(91),s=n(7993),a=n(5906),c=n(2175),u=n(1522),l=n(7680),h=n(9987),d=n(3483),f=n(6939),p=n(940),v=n(9917),y=n(8222),g=n(8725),m=n(6152),b=n(3226),w=n(4714),_=n(9259),E=n(3679),I=n(249),S=n(8582),O="[object Arguments]",T="[object Function]",A="[object Object]",P={};P[O]=P["[object Array]"]=P["[object ArrayBuffer]"]=P["[object DataView]"]=P["[object Boolean]"]=P["[object Date]"]=P["[object Float32Array]"]=P["[object Float64Array]"]=P["[object Int8Array]"]=P["[object Int16Array]"]=P["[object Int32Array]"]=P["[object Map]"]=P["[object Number]"]=P[A]=P["[object RegExp]"]=P["[object Set]"]=P["[object String]"]=P["[object Symbol]"]=P["[object Uint8Array]"]=P["[object Uint8ClampedArray]"]=P["[object Uint16Array]"]=P["[object Uint32Array]"]=!0,P["[object Error]"]=P[T]=P["[object WeakMap]"]=!1,t.exports=function t(e,n,R,C,k,N){var x,U=1&n,L=2&n,D=4&n;if(R&&(x=k?R(e,C,k,N):R(e)),void 0!==x)return x;if(!_(e))return e;var j=m(e);if(j){if(x=v(e),!U)return u(e,x)}else{var q=p(e),M=q==T||"[object GeneratorFunction]"==q;if(b(e))return c(e,U);if(q==A||q==O||M&&!k){if(x=L||M?{}:g(e),!U)return L?h(e,a(x,e)):l(e,s(x,e))}else{if(!P[q])return k?e:{};x=y(e,q,U)}}N||(N=new r);var B=N.get(e);if(B)return B;N.set(e,x),E(e)?e.forEach(function(r){x.add(t(r,n,R,r,e,N))}):w(e)&&e.forEach(function(r,o){x.set(o,t(r,n,R,o,e,N))});var W=j?void 0:(D?L?f:d:L?S:I)(e);return o(W||e,function(r,o){W&&(r=e[o=r]),i(x,o,t(r,n,R,o,e,N))}),x}},9413:(t,e,n)=>{var r=n(9259),o=Object.create,i=function(){function t(){}return function(e){if(!r(e))return{};if(o)return o(e);t.prototype=e;var n=new t;return t.prototype=void 0,n}}();t.exports=i},3324:(t,e,n)=>{var r=n(7297),o=n(3812);t.exports=function(t,e){for(var n=0,i=(e=r(e,t)).length;null!=t&&n<i;)t=t[o(e[n++])];return n&&n==i?t:void 0}},1897:(t,e,n)=>{var r=n(5067),o=n(6152);t.exports=function(t,e,n){var i=e(t);return o(t)?i:r(i,n(t))}},3366:(t,e,n)=>{var r=n(857),o=n(2107),i=n(7157),s=r?r.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":s&&s in Object(t)?o(t):i(t)}},5183:(t,e,n)=>{var r=n(3366),o=n(5125);t.exports=function(t){return o(t)&&"[object Arguments]"==r(t)}},4511:(t,e,n)=>{var r=n(940),o=n(5125);t.exports=function(t){return o(t)&&"[object Map]"==r(t)}},6840:(t,e,n)=>{var r=n(1049),o=n(7394),i=n(9259),s=n(7035),a=/^\[object .+?Constructor\]$/,c=Function.prototype,u=Object.prototype,l=c.toString,h=u.hasOwnProperty,d=RegExp("^"+l.call(h).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=function(t){return!(!i(t)||o(t))&&(r(t)?d:a).test(s(t))}},8436:(t,e,n)=>{var r=n(940),o=n(5125);t.exports=function(t){return o(t)&&"[object Set]"==r(t)}},5522:(t,e,n)=>{var r=n(3366),o=n(1158),i=n(5125),s={};s["[object Float32Array]"]=s["[object Float64Array]"]=s["[object Int8Array]"]=s["[object Int16Array]"]=s["[object Int32Array]"]=s["[object Uint8Array]"]=s["[object Uint8ClampedArray]"]=s["[object Uint16Array]"]=s["[object Uint32Array]"]=!0,s["[object Arguments]"]=s["[object Array]"]=s["[object ArrayBuffer]"]=s["[object Boolean]"]=s["[object DataView]"]=s["[object Date]"]=s["[object Error]"]=s["[object Function]"]=s["[object Map]"]=s["[object Number]"]=s["[object Object]"]=s["[object RegExp]"]=s["[object Set]"]=s["[object String]"]=s["[object WeakMap]"]=!1,t.exports=function(t){return i(t)&&o(t.length)&&!!s[r(t)]}},6411:(t,e,n)=>{var r=n(6001),o=n(4248),i=Object.prototype.hasOwnProperty;t.exports=function(t){if(!r(t))return o(t);var e=[];for(var n in Object(t))i.call(t,n)&&"constructor"!=n&&e.push(n);return e}},8390:(t,e,n)=>{var r=n(9259),o=n(6001),i=n(2966),s=Object.prototype.hasOwnProperty;t.exports=function(t){if(!r(t))return i(t);var e=o(t),n=[];for(var a in t)("constructor"!=a||!e&&s.call(t,a))&&n.push(a);return n}},2857:(t,e,n)=>{var r=n(91),o=n(7297),i=n(9045),s=n(9259),a=n(3812);t.exports=function(t,e,n,c){if(!s(t))return t;for(var u=-1,l=(e=o(e,t)).length,h=l-1,d=t;null!=d&&++u<l;){var f=a(e[u]),p=n;if("__proto__"===f||"constructor"===f||"prototype"===f)return t;if(u!=h){var v=d[f];void 0===(p=c?c(v,f,d):void 0)&&(p=s(v)?v:i(e[u+1])?[]:{})}r(d,f,p),d=d[f]}return t}},9872:t=>{t.exports=function(t,e,n){var r=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(n=n>o?o:n)<0&&(n+=o),o=e>n?0:n-e>>>0,e>>>=0;for(var i=Array(o);++r<o;)i[r]=t[r+e];return i}},6473:t=>{t.exports=function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}},1054:(t,e,n)=>{var r=n(857),o=n(343),i=n(6152),s=n(4795),a=r?r.prototype:void 0,c=a?a.toString:void 0;t.exports=function t(e){if("string"==typeof e)return e;if(i(e))return o(e,t)+"";if(s(e))return c?c.call(e):"";var n=e+"";return"0"==n&&1/e==-1/0?"-0":n}},7826:t=>{t.exports=function(t){return function(e){return t(e)}}},9078:(t,e,n)=>{var r=n(7297),o=n(6974),i=n(2721),s=n(3812),a=Object.prototype.hasOwnProperty;t.exports=function(t,e){var n=-1,c=(e=r(e,t)).length;if(!c)return!0;for(;++n<c;){var u=s(e[n]);if("__proto__"===u&&!a.call(t,"__proto__"))return!1;if(("constructor"===u||"prototype"===u)&&n<c-1)return!1}var l=i(t,e);return null==l||delete l[s(o(e))]}},7297:(t,e,n)=>{var r=n(6152),o=n(1401),i=n(4452),s=n(6188);t.exports=function(t,e){return r(t)?t:o(t,e)?[t]:i(s(t))}},9882:(t,e,n)=>{var r=n(9162);t.exports=function(t){var e=new t.constructor(t.byteLength);return new r(e).set(new r(t)),e}},2175:(t,e,n)=>{t=n.nmd(t);var r=n(7772),o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,s=i&&i.exports===o?r.Buffer:void 0,a=s?s.allocUnsafe:void 0;t.exports=function(t,e){if(e)return t.slice();var n=t.length,r=a?a(n):new t.constructor(n);return t.copy(r),r}},4727:(t,e,n)=>{var r=n(9882);t.exports=function(t,e){var n=e?r(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}},6058:t=>{var e=/\w*$/;t.exports=function(t){var n=new t.constructor(t.source,e.exec(t));return n.lastIndex=t.lastIndex,n}},169:(t,e,n)=>{var r=n(857),o=r?r.prototype:void 0,i=o?o.valueOf:void 0;t.exports=function(t){return i?Object(i.call(t)):{}}},6190:(t,e,n)=>{var r=n(9882);t.exports=function(t,e){var n=e?r(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}},1522:t=>{t.exports=function(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}},752:(t,e,n)=>{var r=n(91),o=n(3940);t.exports=function(t,e,n,i){var s=!n;n||(n={});for(var a=-1,c=e.length;++a<c;){var u=e[a],l=i?i(n[u],t[u],u,n,t):void 0;void 0===l&&(l=t[u]),s?o(n,u,l):r(n,u,l)}return n}},7680:(t,e,n)=>{var r=n(752),o=n(633);t.exports=function(t,e){return r(t,o(t),e)}},9987:(t,e,n)=>{var r=n(752),o=n(2680);t.exports=function(t,e){return r(t,o(t),e)}},4019:(t,e,n)=>{var r=n(7772)["__core-js_shared__"];t.exports=r},3043:(t,e,n)=>{var r=n(8761),o=function(){try{var t=r(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();t.exports=o},1242:(t,e,n)=>{var r="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g;t.exports=r},3483:(t,e,n)=>{var r=n(1897),o=n(633),i=n(249);t.exports=function(t){return r(t,i,o)}},6939:(t,e,n)=>{var r=n(1897),o=n(2680),i=n(8582);t.exports=function(t){return r(t,i,o)}},7937:(t,e,n)=>{var r=n(8304);t.exports=function(t,e){var n=t.__data__;return r(e)?n["string"==typeof e?"string":"hash"]:n.map}},8761:(t,e,n)=>{var r=n(6840),o=n(8109);t.exports=function(t,e){var n=o(t,e);return r(n)?n:void 0}},7353:(t,e,n)=>{var r=n(241)(Object.getPrototypeOf,Object);t.exports=r},2107:(t,e,n)=>{var r=n(857),o=Object.prototype,i=o.hasOwnProperty,s=o.toString,a=r?r.toStringTag:void 0;t.exports=function(t){var e=i.call(t,a),n=t[a];try{t[a]=void 0;var r=!0}catch(t){}var o=s.call(t);return r&&(e?t[a]=n:delete t[a]),o}},633:(t,e,n)=>{var r=n(7552),o=n(981),i=Object.prototype.propertyIsEnumerable,s=Object.getOwnPropertySymbols,a=s?function(t){return null==t?[]:(t=Object(t),r(s(t),function(e){return i.call(t,e)}))}:o;t.exports=a},2680:(t,e,n)=>{var r=n(5067),o=n(7353),i=n(633),s=n(981),a=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)r(e,i(t)),t=o(t);return e}:s;t.exports=a},940:(t,e,n)=>{var r=n(9515),o=n(326),i=n(2760),s=n(2143),a=n(3215),c=n(3366),u=n(7035),l="[object Map]",h="[object Promise]",d="[object Set]",f="[object WeakMap]",p="[object DataView]",v=u(r),y=u(o),g=u(i),m=u(s),b=u(a),w=c;(r&&w(new r(new ArrayBuffer(1)))!=p||o&&w(new o)!=l||i&&w(i.resolve())!=h||s&&w(new s)!=d||a&&w(new a)!=f)&&(w=function(t){var e=c(t),n="[object Object]"==e?t.constructor:void 0,r=n?u(n):"";if(r)switch(r){case v:return p;case y:return l;case g:return h;case m:return d;case b:return f}return e}),t.exports=w},8109:t=>{t.exports=function(t,e){return null==t?void 0:t[e]}},2118:(t,e,n)=>{var r=n(9191);t.exports=function(){this.__data__=r?r(null):{},this.size=0}},6909:t=>{t.exports=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}},8138:(t,e,n)=>{var r=n(9191),o=Object.prototype.hasOwnProperty;t.exports=function(t){var e=this.__data__;if(r){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return o.call(e,t)?e[t]:void 0}},4174:(t,e,n)=>{var r=n(9191),o=Object.prototype.hasOwnProperty;t.exports=function(t){var e=this.__data__;return r?void 0!==e[t]:o.call(e,t)}},7942:(t,e,n)=>{var r=n(9191);t.exports=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=r&&void 0===e?"__lodash_hash_undefined__":e,this}},9917:t=>{var e=Object.prototype.hasOwnProperty;t.exports=function(t){var n=t.length,r=new t.constructor(n);return n&&"string"==typeof t[0]&&e.call(t,"index")&&(r.index=t.index,r.input=t.input),r}},8222:(t,e,n)=>{var r=n(9882),o=n(4727),i=n(6058),s=n(169),a=n(6190);t.exports=function(t,e,n){var c=t.constructor;switch(e){case"[object ArrayBuffer]":return r(t);case"[object Boolean]":case"[object Date]":return new c(+t);case"[object DataView]":return o(t,n);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return a(t,n);case"[object Map]":case"[object Set]":return new c;case"[object Number]":case"[object String]":return new c(t);case"[object RegExp]":return i(t);case"[object Symbol]":return s(t)}}},8725:(t,e,n)=>{var r=n(9413),o=n(7353),i=n(6001);t.exports=function(t){return"function"!=typeof t.constructor||i(t)?{}:r(o(t))}},9045:t=>{var e=/^(?:0|[1-9]\d*)$/;t.exports=function(t,n){var r=typeof t;return!!(n=n??9007199254740991)&&("number"==r||"symbol"!=r&&e.test(t))&&t>-1&&t%1==0&&t<n}},1401:(t,e,n)=>{var r=n(6152),o=n(4795),i=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,s=/^\w*$/;t.exports=function(t,e){if(r(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!o(t))||s.test(t)||!i.test(t)||null!=e&&t in Object(e)}},8304:t=>{t.exports=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}},7394:(t,e,n)=>{var r,o=n(4019),i=(r=/[^.]+$/.exec(o&&o.keys&&o.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"";t.exports=function(t){return!!i&&i in t}},6001:t=>{var e=Object.prototype;t.exports=function(t){var n=t&&t.constructor;return t===("function"==typeof n&&n.prototype||e)}},3945:t=>{t.exports=function(){this.__data__=[],this.size=0}},1846:(t,e,n)=>{var r=n(2218),o=Array.prototype.splice;t.exports=function(t){var e=this.__data__,n=r(e,t);return!(n<0||(n==e.length-1?e.pop():o.call(e,n,1),--this.size,0))}},8028:(t,e,n)=>{var r=n(2218);t.exports=function(t){var e=this.__data__,n=r(e,t);return n<0?void 0:e[n][1]}},2344:(t,e,n)=>{var r=n(2218);t.exports=function(t){return r(this.__data__,t)>-1}},4769:(t,e,n)=>{var r=n(2218);t.exports=function(t,e){var n=this.__data__,o=r(n,t);return o<0?(++this.size,n.push([t,e])):n[o][1]=e,this}},2411:(t,e,n)=>{var r=n(9612),o=n(235),i=n(326);t.exports=function(){this.size=0,this.__data__={hash:new r,map:new(i||o),string:new r}}},6417:(t,e,n)=>{var r=n(7937);t.exports=function(t){var e=r(this,t).delete(t);return this.size-=e?1:0,e}},6928:(t,e,n)=>{var r=n(7937);t.exports=function(t){return r(this,t).get(t)}},9493:(t,e,n)=>{var r=n(7937);t.exports=function(t){return r(this,t).has(t)}},4150:(t,e,n)=>{var r=n(7937);t.exports=function(t,e){var n=r(this,t),o=n.size;return n.set(t,e),this.size+=n.size==o?0:1,this}},7777:(t,e,n)=>{var r=n(733);t.exports=function(t){var e=r(t,function(t){return 500===n.size&&n.clear(),t}),n=e.cache;return e}},9191:(t,e,n)=>{var r=n(8761)(Object,"create");t.exports=r},4248:(t,e,n)=>{var r=n(241)(Object.keys,Object);t.exports=r},2966:t=>{t.exports=function(t){var e=[];if(null!=t)for(var n in Object(t))e.push(n);return e}},4146:(t,e,n)=>{t=n.nmd(t);var r=n(1242),o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,s=i&&i.exports===o&&r.process,a=function(){try{return i&&i.require&&i.require("util").types||s&&s.binding&&s.binding("util")}catch(t){}}();t.exports=a},7157:t=>{var e=Object.prototype.toString;t.exports=function(t){return e.call(t)}},241:t=>{t.exports=function(t,e){return function(n){return t(e(n))}}},2721:(t,e,n)=>{var r=n(3324),o=n(9872);t.exports=function(t,e){return e.length<2?t:r(t,o(e,0,-1))}},7772:(t,e,n)=>{var r=n(1242),o="object"==typeof self&&self&&self.Object===Object&&self,i=r||o||Function("return this")();t.exports=i},5243:(t,e,n)=>{var r=n(235);t.exports=function(){this.__data__=new r,this.size=0}},2858:t=>{t.exports=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n}},4417:t=>{t.exports=function(t){return this.__data__.get(t)}},8605:t=>{t.exports=function(t){return this.__data__.has(t)}},1418:(t,e,n)=>{var r=n(235),o=n(326),i=n(6738);t.exports=function(t,e){var n=this.__data__;if(n instanceof r){var s=n.__data__;if(!o||s.length<199)return s.push([t,e]),this.size=++n.size,this;n=this.__data__=new i(s)}return n.set(t,e),this.size=n.size,this}},4452:(t,e,n)=>{var r=n(7777),o=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,i=/\\(\\)?/g,s=r(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(o,function(t,n,r,o){e.push(r?o.replace(i,"$1"):n||t)}),e});t.exports=s},3812:(t,e,n)=>{var r=n(4795);t.exports=function(t){if("string"==typeof t||r(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}},7035:t=>{var e=Function.prototype.toString;t.exports=function(t){if(null!=t){try{return e.call(t)}catch(t){}try{return t+""}catch(t){}}return""}},9850:(t,e,n)=>{var r=n(8874);t.exports=function(t){return r(t,5)}},1225:t=>{t.exports=function(t,e){return t===e||t!=t&&e!=e}},9631:(t,e,n)=>{var r=n(5183),o=n(5125),i=Object.prototype,s=i.hasOwnProperty,a=i.propertyIsEnumerable,c=r(function(){return arguments}())?r:function(t){return o(t)&&s.call(t,"callee")&&!a.call(t,"callee")};t.exports=c},6152:t=>{var e=Array.isArray;t.exports=e},7878:(t,e,n)=>{var r=n(1049),o=n(1158);t.exports=function(t){return null!=t&&o(t.length)&&!r(t)}},3226:(t,e,n)=>{t=n.nmd(t);var r=n(7772),o=n(6330),i=e&&!e.nodeType&&e,s=i&&t&&!t.nodeType&&t,a=s&&s.exports===i?r.Buffer:void 0,c=(a?a.isBuffer:void 0)||o;t.exports=c},1049:(t,e,n)=>{var r=n(3366),o=n(9259);t.exports=function(t){if(!o(t))return!1;var e=r(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}},1158:t=>{t.exports=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}},4714:(t,e,n)=>{var r=n(4511),o=n(7826),i=n(4146),s=i&&i.isMap,a=s?o(s):r;t.exports=a},9259:t=>{t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},5125:t=>{t.exports=function(t){return null!=t&&"object"==typeof t}},3679:(t,e,n)=>{var r=n(8436),o=n(7826),i=n(4146),s=i&&i.isSet,a=s?o(s):r;t.exports=a},4795:(t,e,n)=>{var r=n(3366),o=n(5125);t.exports=function(t){return"symbol"==typeof t||o(t)&&"[object Symbol]"==r(t)}},7598:(t,e,n)=>{var r=n(5522),o=n(7826),i=n(4146),s=i&&i.isTypedArray,a=s?o(s):r;t.exports=a},249:(t,e,n)=>{var r=n(1634),o=n(6411),i=n(7878);t.exports=function(t){return i(t)?r(t):o(t)}},8582:(t,e,n)=>{var r=n(1634),o=n(8390),i=n(7878);t.exports=function(t){return i(t)?r(t,!0):o(t)}},6974:t=>{t.exports=function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0}},733:(t,e,n)=>{var r=n(6738);function o(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=t.apply(this,r);return n.cache=i.set(o,s)||i,s};return n.cache=new(o.Cache||r),n}o.Cache=r,t.exports=o},6765:(t,e,n)=>{var r=n(2857);t.exports=function(t,e,n){return null==t?t:r(t,e,n)}},981:t=>{t.exports=function(){return[]}},6330:t=>{t.exports=function(){return!1}},6188:(t,e,n)=>{var r=n(1054);t.exports=function(t){return null==t?"":r(t)}},7195:(t,e,n)=>{var r=n(9078);t.exports=function(t,e){return null==t||r(t,e)}},7149:e=>{e.exports=t}},u={};function l(t){var e=u[t];if(void 0!==e)return e.exports;var n=u[t]={id:t,loaded:!1,exports:{}};return c[t].call(n.exports,n,n.exports,l),n.loaded=!0,n.exports}l.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return l.d(e,{a:e}),e},l.d=(t,e)=>{for(var n in e)l.o(e,n)&&!l.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},l.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),l.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),l.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},l.nmd=t=>(t.paths=[],t.children||(t.children=[]),t);var h={};(()=>{l.d(h,{Z:()=>wd});var t={};l.r(t);var c={};l.r(c),l.d(c,{ArkSimpleModel:()=>Tc,DSSimpleModel:()=>kc,DefaultImageModel:()=>su,DefaultSimpleModel:()=>ru,HunYuanBetaSimpleModel:()=>gc,HunYuanExpSimpleModel:()=>Gc,HunYuanOpenSimpleModel:()=>$c,HunYuanSimpleModel:()=>_c,MODELS:()=>bu,MoonshotSimpleModel:()=>Wc,ReactModel:()=>du,YiSimpleModel:()=>Dc,ZhiPuSimpleModel:()=>lc,toolMap:()=>vu});var u={};l.r(u),l.d(u,{LineString:()=>Nl,MultiLineString:()=>jl,MultiPoint:()=>Ll,MultiPolygon:()=>Ml,Point:()=>uh,Polygon:()=>Ul});var d="@cloudbase/js-sdk";function f(){return d}var p,v="https:",y="https://support.qq.com/products/148793",g={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"},m=l(7149),b=(p=function(t,e){return p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},p(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}p(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),w=function(){return w=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},w.apply(this,arguments)};function _(t){return"[object Array]"===Object.prototype.toString.call(t)}function E(t){return"string"==typeof t}function I(t){return"[object FormData]"===Object.prototype.toString.call(t)}function S(){var t=(new Date).getTime(),e=(null===Date||void 0===Date?void 0:Date.now)&&1e3*Date.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){var r=16*Math.random();return t>0?(r=(t+r)%16|0,t=Math.floor(t/16)):(r=(e+r)%16|0,e=Math.floor(e/16)),("x"===n?r:7&r|8).toString(16)})}function O(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}function T(t,e){if("undefined"==typeof window)return!1;var n=e||decodeURIComponent(window.location.search),r=new RegExp("(^|&)".concat(t,"=([^&]*)(&|$)")),o=n.substr(n.indexOf("?")+1).match(r);return null!=o?o[2]:""}function A(t,e,n){if(void 0===n&&(n=null),t&&"function"==typeof t)return t(e,n);if(e)throw e;return n}function P(t,e){console.warn("[".concat(f(),"][").concat(t,"]:").concat(e))}var R=function(t){function e(e){var n=t.call(this,e.msg||e.message||"")||this;return n.code=e.code||"",n.requestId=e.requestId||"",Object.defineProperty(n,"message",{value:e.msg||e.message||"",enumerable:!0,writable:!0,configurable:!0}),n}return b(e,t),e}(Error),C=function(t){return new R(t)};function k(t,e){return(e||C)(t)}function N(t){return!t||"boolean"!=typeof t.throw||t.throw}function x(t,e){if(N(t))throw k(w(w({},e),{msg:e.message}),null==t?void 0:t.errorFactory);return w({code:e.code,message:e.message},e.requestId?{requestId:e.requestId}:{})}function U(t){if(t&&"object"==typeof t&&t.data&&"object"==typeof t.data){var e=t.data,n=e.code,r=e.message;if(!t.code&&n||!t.message&&r)return w(w(w({},t),!t.code&&n?{code:n}:{}),!t.message&&r?{message:r}:{})}return t}function L(t){var e={},n=t.match(/^(data:.*?)(\?[^#\s]*)?$/);if(n){t=n[1];var r=n[2];r&&(e=function(t){t=t.replace(/^\?/,"");var e={};return t.split("&").forEach(function(t){var n=t.split("="),r=n[0],o=n[1];r=decodeURIComponent(r),o=decodeURIComponent(o),r&&(e[r]?Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]:e[r]=o)}),e}(r))}var o=e.token,i=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(e,["token"]);return/^data:/.test(t)&&!o?{error:"invalid_argument",error_description:"invalid captcha data: ".concat(t)}:o?{state:i.state,token:o,captchaData:t}:{error:"unimplemented",error_description:"need to impl captcha data"}}var D=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),j=function(){return j=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},j.apply(this,arguments)},q=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},M=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function B(t){try{return JSON.parse(t)}catch(e){return t}}var W,F=function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}return D(e,t),e.prototype.get=function(t){return this.request(j(j({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(j(j({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(j(j({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t,n=e.data,r=e.file,o=e.fileContent,i=e.name,s=e.method,a=e.headers,c=void 0===a?{}:a,u=null!=r?r:o,l={post:"post",put:"put"}[null==s?void 0:s.toLowerCase()]||"put",h=new FormData;return"post"===l?(Object.keys(n).forEach(function(t){h.append(t,n[t])}),h.append("key",i),h.append("file",u instanceof Blob?u:new Blob([u])),this.request(j(j({},t),{data:h,method:l}),this.restrictedMethods.includes("upload"))):this.request(j(j({},t),{method:"put",headers:c,body:u}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return q(this,void 0,Promise,function(){var e,n,r,o;return M(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(j(j({},t),{headers:{},responseType:"blob"}))];case 1:return e=i.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return q(this,void 0,Promise,function(){var n,r,o,i,s,a,c,u,l,h,d,f,p,v,y,g=this;return M(this,function(m){switch(m.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,i=void 0!==o&&o,s=t.stream,a=void 0!==s&&s,c=t.signal,u=t.timeout,l=t.shouldThrowOnError,h=void 0===l||l,d=null!=u?u:this.timeout,c&&(c.aborted&&n.abort(),c.addEventListener("abort",function(){return n.abort()})),f=null,i&&d&&(f=setTimeout(function(){console.warn(g.timeoutMsg),n.abort(new Error(g.timeoutMsg))},d)),[4,fetch(r,j(j({},t),{signal:n.signal})).then(function(t){return q(g,void 0,void 0,function(){var e,n,r;return M(this,function(o){switch(o.label){case 0:return clearTimeout(f),h?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(f),Promise.reject(t)})];case 1:return p=m.sent(),a?(v=p.body,[3,5]):[3,2];case 2:return(null===(e=p.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?(y=B,[4,p.text()]):[3,4];case 3:return v=y.apply(void 0,[m.sent()]),[3,5];case 4:v=p.text(),m.label=5;case 5:return[2,{data:v,statusCode:p.status,header:p.headers,response:p}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var i=t.url,s=t.headers,a=void 0===s?{}:s,c=t.data,u=t.responseType,l=t.withCredentials,h=t.body,d=t.onUploadProgress,f=O(v,i,"get"===r?c:{}),p=new XMLHttpRequest;p.open(r,f),u&&(p.responseType=u);var y,g,m=t.signal;m&&(m.aborted?p.abort():m.addEventListener("abort",function(){return p.abort()},{once:!0})),Object.keys(a).forEach(function(t){p.setRequestHeader(t,a[t])}),d&&p.upload.addEventListener("progress",d),p.onreadystatechange=function(){var t={};if(4===p.readyState){var e=p.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=p.status;try{t.data="blob"===u?p.response:JSON.parse(p.responseText)}catch(e){t.data="blob"===u?p.response:p.responseText}clearTimeout(y),o(t)}},e&&n.timeout&&(y=setTimeout(function(){console.warn(n.timeoutMsg),p.abort()},n.timeout)),g=I(c)?c:"application/x-www-form-urlencoded"===a["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")}(c):h||(c?JSON.stringify(c):void 0),l&&(p.withCredentials=!0),p.send(g)})},e}(m.AbstractSDKRequest),H=function(){return H=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},H.apply(this,arguments)};!function(t){t.WEB="web",t.WX_MP="wx_mp"}(W||(W={}));var V=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),G=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},K=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},J=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return V(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(m.AbstractStorage),z=function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(P(g.INVALID_PARAMS,"localStorage is not supported on current platform"),new J(e.root));case"none":return new J(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}return Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:g.OPERATION_FAIL,msg:"[".concat(f(),"][").concat(g.OPERATION_FAIL,"]setStore failed"),info:t}))}}else P(g.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return G(this,void 0,void 0,function(){var r;return K(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}P(g.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return G(this,void 0,void 0,function(){var r;return K(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):P(g.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return G(this,void 0,void 0,function(){return K(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})},t}(),$=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Y=function(t,e){this.data=e||null,this.name=t},Q=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return $(e,t),e}(Y),X=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof Q)return console.error(t.error),this;var n=E(t)?new Y(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,i=this.listeners[r]?function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],this.listeners[r],!0):[];o<i.length;o++)i[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new X;var Z=new X,tt="lang_change";function et(t){return t.mode,t.customInfo,t.title,t.messages,function(t,e,n){}}"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");nt={default:()=>e.default},rt={},l.d(rt,nt);var nt,rt,ot=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},it=g,st={};function at(t,e){var n=e.name,r=e.namespace,o=e.entity,i=e.injectEvents,s=e.IIFE,a=void 0!==s&&s;if(st[n]||r&&t[r])throw new Error(JSON.stringify({code:it.INVALID_OPERATION,msg:"Duplicate component ".concat(n)}));if(a){if(!o||"function"!=typeof o)throw new Error(JSON.stringify({code:it.INVALID_PARAMS,msg:"IIFE component's entity must be a function"}));o.call(t)}if(st[n]=e,r?t.prototype[r]=o:ct(t.prototype,o),i){var c=i.bus,u=i.events;if(!c||!u||0===u.length)return;var l=t.prototype.fire||function(){};t.prototype.events||(t.prototype.events={}),(t.prototype.events||{})[n]?t.prototype.events[n].events=ot(ot([],t.prototype.events[n].events,!0),u,!0):t.prototype.events[n]={bus:c,events:u},t.prototype.fire=function(t,e){l(t,e);for(var n=0,r=Object.keys(this.events);n<r.length;n++){var o=r[n],i=this.events[o],s=i.bus;if(i.events.includes(t)){s.fire(t,e);break}}}}}function ct(t,e){if(!(e instanceof Object))return e;switch(e.constructor){case Date:return new Date(e.getTime());case Object:void 0===t&&(t={});break;case Array:t=[];break;default:return e}for(var n=0,r=Object.keys(e);n<r.length;n++){var o=r[n];Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=ct(t[o],e[o]))}return t}const ut=(t=>{var e={};return l.d(e,t),e})({WxMpWebSocket:()=>n.WxMpWebSocket,WxRequest:()=>n.WxRequest,default:()=>n.default,parseQueryString:()=>n.parseQueryString,wxMpStorage:()=>n.wxMpStorage});var lt=function(){return lt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},lt.apply(this,arguments)},ht={},dt=function(){return dt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},dt.apply(this,arguments)},ft=z,pt={},vt={};function yt(t){var e=t.env,n=t.platformInfo,r={userInfoKey:"".concat("user_info","_").concat(e)};pt[e]=pt[e]||new ft(dt(dt({},t),{keys:r,platformInfo:n})),vt[e]=vt[e]||new ft(dt(dt({},t),{keys:r,platformInfo:n,persistence:"local"}))}function gt(t){return vt[t]}var mt=function(){return mt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},mt.apply(this,arguments)},bt="",wt="@cloudbase/js-sdk";function _t(){return bt}var Et,It=[],St=["env","endPointKey","region"],Ot="https:";function Tt(t){return It.find(function(e){return St.filter(function(e){return null!=t[e]}).every(function(n){return e[n]===t[n]})})}function At(t){var e,n;t.protocol&&!/:$/.test(t.protocol)&&(t.protocol="".concat(t.protocol,":"));var r,o=Tt(t);o?(null!=t.baseUrl&&(o.baseUrl=t.baseUrl),null!=t.protocol&&(o.protocol=t.protocol)):It.push(mt(mt({},t),{protocol:null!==(e=t.protocol)&&void 0!==e?e:Ot})),"CLOUD_API"===t.endPointKey&&(r=null!==(n=t.protocol)&&void 0!==n?n:Ot,v=r)}function Pt(t,e,n){return Tt({env:t,endPointKey:e,region:n})}function Rt(t,e){void 0===e&&(e="CLOUD_API");var n=Pt(t,e||"CLOUD_API"),r=n.protocol,o=n.baseUrl;return"".concat(r).concat(o).match(/(http(s)?:)?\/\/([^/?#]*)/)[0]}!function(t){t.NULL="NULL",t.ANONYMOUS="ANONYMOUS",t.WECHAT="WECHAT",t.WECHAT_PUBLIC="WECHAT-PUBLIC",t.WECHAT_OPEN="WECHAT-OPEN",t.CUSTOM="CUSTOM",t.EMAIL="EMAIL",t.USERNAME="USERNAME",t.PHONE="PHONE"}(Et||(Et={}));var Ct=function(){return Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ct.apply(this,arguments)},kt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Nt=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},xt=g,Ut=I,Lt=O,Dt=["auth.getJwt","auth.logout","auth.signInWithTicket","auth.signInAnonymously","auth.signIn","auth.fetchAccessTokenWithRefreshToken","auth.signUpWithEmailAndPassword","auth.activateEndUserMail","auth.sendPasswordResetEmail","auth.resetPasswordWithToken","auth.isUsernameRegistered"];function jt(t,e,n){var r=t[e];t[e]=function(e){var o={},i={};n.forEach(function(n){var r=n.call(t,e),s=r.data,a=r.headers;Object.assign(o,s),Object.assign(i,a)});var s=e.data;return s&&(Ut(s)?Object.keys(o).forEach(function(t){s.append(t,o[t])}):e.data=Ct(Ct({},s),o)),e.headers=Ct(Ct({},e.headers||{}),i),r.call(t,e)}}function qt(){var t=Math.random().toString(16).slice(2);return{data:{seqId:t},headers:{"X-SDK-Version":"@cloudbase/js-sdk/".concat(_t()),"x-seqid":t}}}var Mt,Bt,Wt=function(){function t(t){var e=this;this.config=t;var n={env:this.config.env,region:this.config.region,accessKey:this.config.accessKey,context:this.config.context,auth:this.config.auth,timeout:this.config.timeout,timeoutMsg:"[@cloudbase/js-sdk] 请求在".concat(this.config.timeout/1e3,"s内未完成,已中断"),restrictedMethods:["post","put"]};this.reqClass=new ht.adapter.reqClass(n),this.localCache=gt(this.config.env),"GATEWAY"!==this.config.endPointMode&&(jt(this.reqClass,"post",[qt]),jt(this.reqClass,"upload",[qt]),jt(this.reqClass,"download",[qt])),Z.on(tt,function(t){var n;e.config.i18n=(null===(n=t.data)||void 0===n?void 0:n.i18n)||e.config.i18n})}return Object.defineProperty(t.prototype,"throwWhenRequestFail",{get:function(){var t,e,n,r,o=null===(n=null===(e=null===(t=this.config)||void 0===t?void 0:t._fromApp)||void 0===e?void 0:e.config)||void 0===n?void 0:n.throw;return"boolean"==typeof o?o:!1!==(null===(r=this.config)||void 0===r?void 0:r.throw)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"errorFactory",{get:function(){var t,e,n,r=this.config;return null!==(t=null==r?void 0:r.errorFactory)&&void 0!==t?t:null===(n=null===(e=null==r?void 0:r._fromApp)||void 0===e?void 0:e.config)||void 0===n?void 0:n.errorFactory},enumerable:!1,configurable:!0}),t.prototype.getAccessToken=function(t){return void 0===t&&(t=null),kt(this,void 0,void 0,function(){var e,n,r;return Nt(this,function(o){switch(o.label){case 0:if(null!=t)return[2,t];if(!(e=this.config._fromApp).oauthInstance)throw new Error("you can't request without auth");return n=e.oauthInstance,r=n.oauth2client,[4,this.getOauthAccessTokenV2(r)];case 1:return[2,o.sent().accessToken]}})})},t.prototype.getDefaultHeaders=function(){var t,e,n;return(t={})[null===(e=this.config.i18n)||void 0===e?void 0:e.LANG_HEADER_KEY]=null===(n=this.config.i18n)||void 0===n?void 0:n.lang,t["X-SDK-Version"]="@cloudbase/js-sdk/".concat(_t()),t},Object.defineProperty(t.prototype,"requestDebug",{get:function(){var t,e,n;return!0===(null===(n=null===(e=null===(t=this.config)||void 0===t?void 0:t._fromApp)||void 0===e?void 0:e.config)||void 0===n?void 0:n.debug)},enumerable:!1,configurable:!0}),t.prototype.post=function(t,e){return kt(this,void 0,Promise,function(){return Nt(this,function(n){switch(n.label){case 0:return[4,this.reqClass.post(Ct(Ct({},t),{headers:Ct(Ct({},t.headers),this.getDefaultHeaders()),customReqOpts:e,debug:this.requestDebug}))];case 1:return[2,n.sent()]}})})},t.prototype.upload=function(t){var e;return kt(this,void 0,Promise,function(){var n,r,o;return Nt(this,function(i){switch(i.label){case 0:return r=null!==(e=(n=t).file)&&void 0!==e?e:n.fileContent,delete(o=Ct(Ct({},n),{file:r,headers:Ct(Ct({},n.headers),this.getDefaultHeaders()),debug:this.requestDebug})).fileContent,[4,this.reqClass.upload(o)];case 1:return[2,i.sent()]}})})},t.prototype.download=function(t){return kt(this,void 0,Promise,function(){return Nt(this,function(e){switch(e.label){case 0:return[4,this.reqClass.download(Ct(Ct({},t),{headers:Ct(Ct({},t.headers),this.getDefaultHeaders()),debug:this.requestDebug}))];case 1:return[2,e.sent()]}})})},t.prototype.getUploadByteLength=function(t){var e,n;return null===(n=(e=this.reqClass).getUploadByteLength)||void 0===n?void 0:n.call(e,t)},t.prototype.getBaseEndPoint=function(t){return void 0===t&&(t="CLOUD_API"),Rt(this.config.env,t)},t.prototype.getOauthAccessTokenV2=function(t){return kt(this,void 0,Promise,function(){var e,n;return Nt(this,function(r){switch(r.label){case 0:return[4,t.getAccessToken()];case 1:return e=r.sent(),[4,t.getCredentials()];case 2:return n=r.sent(),[2,{accessToken:e,accessTokenExpire:new Date(n.expires_at).getTime()}]}})})},t.prototype.request=function(t,e,n,r){var o,i;return kt(this,void 0,Promise,function(){var s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I,S,O,T,A,P;return Nt(this,function(R){switch(R.label){case 0:if(R.trys.push([0,4,,5]),s="x-tcb-trace_".concat(this.config.env),a="application/x-www-form-urlencoded",c=Ct({action:t,dataVersion:"2020-01-10",env:this.config.env},e),-1!==Dt.indexOf(t))return[3,2];if(!(u=this.config._fromApp).oauthInstance)throw new Error("you can't request without auth");return l=u.oauthInstance,h=l.oauth2client,d=c,[4,this.getOauthAccessTokenV2(h)];case 1:d.access_token=R.sent().accessToken,R.label=2;case 2:return"storage.uploadFile"===t?(f=new FormData,Object.keys(f).forEach(function(t){Object.prototype.hasOwnProperty.call(f,t)&&void 0!==f[t]&&f.append(t,c[t])}),a="multipart/form-data"):(a="application/json;charset=UTF-8",f={},Object.keys(c).forEach(function(t){void 0!==c[t]&&(f[t]=c[t])})),p={headers:Ct(Ct({"content-type":a},this.getDefaultHeaders()),null==n?void 0:n.headers)},(null==n?void 0:n.onUploadProgress)&&(p.onUploadProgress=n.onUploadProgress),this.config.region&&(p.headers["X-TCB-Region"]=this.config.region),(v=this.localCache.getStore(s))&&(p.headers["X-TCB-Trace"]=v),y=void 0!==(null==n?void 0:n.parse)?n.parse:e.parse,g=void 0!==(null==n?void 0:n.inQuery)?n.inQuery:e.inQuery,m=void 0!==(null==n?void 0:n.search)?n.search:e.search,b=Ct(Ct({},(null==n?void 0:n.defaultQuery)||{}),{env:this.config.env}),y&&(b.parse=!0),g&&(b=Ct(Ct({},g),b)),w=(null==n?void 0:n.endPointMode)||this.config.endPointMode||"CLOUD_API",_=Pt(this.config.env,w),E=_.baseUrl,I=_.protocol,"GATEWAY"===w&&/^((database)\.)|(auth\.wsWebSign)/.test(t)&&(S=Pt(this.config.env,"CLOUD_API"),E="".concat(S.baseUrl.match(/\/\/([^/?#]*)/)[0],"/web")),O=void 0,O=n.pathname?Lt(I,"".concat(null===(o=Rt(this.config.env,w))||void 0===o?void 0:o.replace(/^https?:/,""),"/").concat(n.pathname),b):Lt(I,E,b),m&&(O+=m),[4,this.post(Ct({url:O,data:f},p),r)];case 3:if(T=R.sent(),(A=null===(i=T.header)||void 0===i?void 0:i["x-tcb-trace"])&&this.localCache.setStore(s,A),200!==Number(T.status)&&200!==Number(T.statusCode)||!T.data)throw new Error("network request error");return[2,T];case 4:P=R.sent();try{P.requestId=P.requestId||(null==n?void 0:n.headers["x-request-id"])||(null==n?void 0:n.headers["X-Request-Id"])||""}catch(t){}throw P;case 5:return[2]}})})},t.prototype.fetch=function(t){var e,n,r,o,i,s,a,c;return kt(this,void 0,Promise,function(){var u,l,h,d,f,p,v,y,g=this;return Nt(this,function(m){switch(m.label){case 0:u=t.token,l=t.headers,h=void 0===l?{}:l,d=t.withCredentials,f=void 0===d||d,p=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(t,["token","headers","withCredentials"]),v=function(){return kt(g,void 0,void 0,function(){var t,e,n,r;return Nt(this,function(o){switch(o.label){case 0:if(t={},!f)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.getAccessToken(u)];case 2:return(e=o.sent())&&(t.Authorization="Bearer ".concat(e)),[3,4];case 3:if(n=o.sent(),"undefined"==typeof process||null==process.versions||null==process.versions.node)throw n;return[3,4];case 4:return r=Ct({headers:Ct(Ct(Ct({"X-SDK-Version":"@cloudbase/js-sdk/".concat(_t())},t),this.getDefaultHeaders()),h),withCredentials:f},p),[2,this.reqClass.fetch(r)]}})})},m.label=1;case 1:return m.trys.push([1,3,,6]),[4,v()];case 2:return[2,m.sent()];case 3:y=m.sent();try{y.requestId=y.requestId||h["x-request-id"]||h["X-Request-Id"]||""}catch(t){}if("ACCESS_TOKEN_EXPIRED"!==(null==y?void 0:y.code))return[3,5];if("function"!=typeof(null===(o=null===(r=null===(n=null===(e=this.config)||void 0===e?void 0:e._fromApp)||void 0===n?void 0:n.oauthInstance)||void 0===r?void 0:r.authApi)||void 0===o?void 0:o.refreshTokenForce))throw y;return[4,null===(c=null===(a=null===(s=null===(i=this.config)||void 0===i?void 0:i._fromApp)||void 0===s?void 0:s.oauthInstance)||void 0===a?void 0:a.authApi)||void 0===c?void 0:c.refreshTokenForce()];case 4:return m.sent(),[2,v()];case 5:throw y;case 6:return[2]}})})},t.prototype.send=function(t,e,n,r){return void 0===e&&(e={}),void 0===n&&(n={}),kt(this,void 0,Promise,function(){var o;return Nt(this,function(i){switch(i.label){case 0:return[4,this.request(t,e,Ct(Ct({},n),{onUploadProgress:e.onUploadProgress}),r)];case 1:if((o=i.sent()).data.code&&this.throwWhenRequestFail)throw k({code:o.data.code,msg:o.data.message||"",requestId:o.requestId},this.errorFactory);return[2,o.data]}})})},t.prototype.gateWay=function(t,e){var n,r;return kt(this,void 0,void 0,function(){var o,i,s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E;return Nt(this,function(I){switch(I.label){case 0:if(o=t.url,i=t.name,s=t.data,a=t.path,c=void 0===a?"":a,u=t.method,l=t.header,h=void 0===l?{}:l,!(i&&c||o))throw k({code:xt.INVALID_PARAMS,msg:"[gateWay] invalid function name or path or url"},this.errorFactory);try{d=s?JSON.stringify(s):""}catch(t){throw k({code:xt.INVALID_PARAMS,msg:"[gateWay] invalid data"},this.errorFactory)}if(f=S(),p=Pt(this.config.env,"GATEWAY"),v=p.baseUrl,y=p.protocol,g="".concat(y).concat(v).concat(o||"/".concat(c,"/").concat(i)),m=["GET","HEAD"].includes(null===(n=null==u?void 0:u.toUpperCase)||void 0===n?void 0:n.call(u)))try{b={};try{b=JSON.parse(s)}catch(t){b=s||{}}g="".concat(g).concat(g.includes("?")?"&":"?").concat(Object.keys(b).map(function(t){return"".concat(t,"=").concat(b[t])}).join("&"))}catch(t){}return[4,this.fetch(Ct(Ct({method:u||"POST",headers:Ct({"Content-Type":"application/json; charset=utf-8","X-Request-Id":f},h)},m?{}:{body:d}),{url:g,customReqOpts:e,shouldThrowOnError:null!==(r=t.shouldThrowOnError)&&void 0!==r?r:this.throwWhenRequestFail}))];case 1:return w=I.sent(),_=[Ct({requestId:f},w)],E={},[4,w.data];case 2:return[2,Ct.apply(void 0,_.concat([(E.data=I.sent(),E)]))]}})})},t}(),Ft={};!function(t){t.ZH="zh-CN",t.EN="en-US"}(Bt||(Bt={}));var Ht=((Mt={})[Bt.EN]={"请检查调用方式,或前往云开发 AI+ 首页查看文档":"Please check the calling method or visit the AI+ homepage to view the documentation","AI+ 请求出错,错误码":"AI+ request error, error code",错误信息:"error message",未实现:"not implemented","小程序不支持 wasm 加载":"wasm loading is not supported in mini programs","小程序不支持动态 js 加载":"dynamic js loading is not supported in mini programs",请求超时:"request timeout","缺少 privatelink sdk 地址":"missing privatelink sdk address"},Mt),Vt=function(t,e){var n;return(null===(n=Ht[e])||void 0===n?void 0:n[t])||t},Gt=function(t,e){var n,r,o=function(t){return"lang_".concat(t.clientId||t.env)}(e),i=(t.adapter||{}).localStorage,s=e.lang||(null===(n=null==i?void 0:i.getItem)||void 0===n?void 0:n.call(i,o))||Bt.ZH;return null===(r=null==i?void 0:i.setItem)||void 0===r||r.call(i,o,s),new Proxy({t:function(t){return Vt(t,s)},LANG_HEADER_KEY:"Accept-Language",lang:s},{get:function(t,e){var n;return"lang"===e&&(null===(n=null==i?void 0:i.getItem)||void 0===n?void 0:n.call(i,o))||t[e]},set:function(t,e,n){var r;return"lang"===e&&n!==t[e]&&(t[e]=n,t.t=function(t){return Vt(t,n)},null===(r=null==i?void 0:i.setItem)||void 0===r||r.call(i,o,n),Z.fire(tt,{i18n:t})),t[e]=n,!0}})},Kt=new Set,Jt=function(){return Jt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Jt.apply(this,arguments)},zt=function(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s},$t=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},Yt=function(){return{adapter:H({},{type:"default",root:window,reqClass:F,wsClass:WebSocket,localStorage}),runtime:W.WEB}},Qt=g,Xt=y,Zt=P,te=et,ee={persistence:"local"},ne=6e5,re={},oe=function(){function t(t){this.cloudbaseConfig=t||this.cloudbaseConfig,this.authInstance=null,this.oauthInstance=null,this.requestInstance=null,this.version=_t()}return Object.defineProperty(t.prototype,"config",{get:function(){return this.cloudbaseConfig},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"platform",{get:function(){return ht},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"cache",{get:function(){return t=this.cloudbaseConfig.env,pt[t];var t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"localCache",{get:function(){return gt(this.cloudbaseConfig.env)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"request",{get:function(){return this.requestInstance||(t=this.cloudbaseConfig.env,Ft[t]);var t},enumerable:!1,configurable:!0}),t.prototype.init=function(e){var n,r,o,i,s;if(void 0===e&&(e={env:""}),e.endPointMode=e.endPointMode||"GATEWAY",ht.adapter||this.useDefaultAdapter(),(e=this.dealNodeAdapterConfig(e)).throw=null===(r=null!==(n=e.throw)&&void 0!==n?n:e.throwOnCode)||void 0===r||r,delete e.throwOnCode,!e.env)throw new Error(JSON.stringify({code:Qt.INVALID_PARAMS,msg:"env must not be specified"}));this.isInitialized(e);var a=this.isNodeEnv()?void 0:15e3,c=e.timeout||a,u={env:e.env,region:e.region,accessKey:e.accessKey,context:e.context,auth:e.auth,timeout:c,timeoutMsg:c?"[".concat(wt,"][REQUEST TIMEOUT] request had been abort since didn't finished within").concat(c/1e3,"s"):void 0};this.requestClient=new ht.adapter.reqClass(u),this.cloudbaseConfig=Jt(Jt(Jt({},ee),e),{timeout:c,i18n:Gt(ht,e)}),function(t){t&&"object"==typeof t&&Kt.add(t)}(this.cloudbaseConfig),delete this.cloudbaseConfig.lang,this.cloudbaseConfig.timeout=this.formatTimeout(this.cloudbaseConfig.timeout);var l=this.cloudbaseConfig,h=l.env,d=l.persistence,f=l.debug,p=l.timeout,v=l.oauthClient,y=l.i18n;yt({env:h,persistence:d,debug:f,platformInfo:this.platform}),function(t,e){At({env:t,region:e,baseUrl:"//".concat(t,".").concat(e||"ap-shanghai",".tcb-api.tencentcloudapi.com/web"),protocol:void 0,endPointKey:"CLOUD_API"})}(h,e.region||""),function(t,e,n){var r="//".concat(t,".api.tcloudbasegateway.com/v1");n&&(r="//".concat(t,".api.intl.tcloudbasegateway.com/v1")),At({endPointKey:"GATEWAY",env:t,baseUrl:r,protocol:e})}(h,Ot,e.intl);var g=new t(this.cloudbaseConfig);return g.requestInstance=function(t){var e=new Wt(Ct(Ct({},t),{throw:t.throw}));return Ft[t.env]=e,e}({env:h,region:e.region||"",timeout:p,oauthClient:v,_fromApp:g,i18n:y,endPointMode:e.endPointMode,auth:e.auth,context:e.context,accessKey:e.accessKey,throw:e.throw}),g.requestClient=this.requestClient,null===(o=null==this?void 0:this.fire)||void 0===o||o.call(this,"cloudbase_init",g),this.try2InitAuth(g),(null===(i=ht.adapter)||void 0===i?void 0:i.nodeTool)&&(null===(s=ht.adapter)||void 0===s||s.nodeTool(g,this.cloudbaseConfig)),g},t.prototype.updateConfig=function(t){var e=t.persistence,n=t.debug;this.cloudbaseConfig.persistence=e,this.cloudbaseConfig.debug=n,yt({env:this.cloudbaseConfig.env,persistence:e,debug:n,platformInfo:this.platform})},t.prototype.setThrowOnCode=function(t){this.cloudbaseConfig.throw=t},t.prototype.updateLang=function(t){var e;t&&t!==(null===(e=this.cloudbaseConfig.i18n)||void 0===e?void 0:e.lang)&&(this.cloudbaseConfig.i18n.lang=t)},t.prototype.registerExtension=function(t){re[t.name]=t},t.prototype.invokeExtension=function(t,e){return n=this,r=void 0,i=function(){var n;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(r){switch(r.label){case 0:if(!(n=re[t]))throw new Error(JSON.stringify({code:Qt.INVALID_PARAMS,msg:"extension:".concat(t," must be registered before invoke")}));return[4,n.invoke(e,this)];case 1:return[2,r.sent()]}})},new((o=void 0)||(o=Promise))(function(t,e){function s(t){try{c(i.next(t))}catch(t){e(t)}}function a(t){try{c(i.throw(t))}catch(t){e(t)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof o?n:new o(function(t){t(n)})).then(s,a)}c((i=i.apply(n,r||[])).next())});var n,r,o,i},t.prototype.useAdapters=function(t,e){var n=function(t,e){for(var n=0,r=_(t)?t:[t];n<r.length;n++){var o=r[n],i=o.isMatch,s=o.genAdapter,a=o.runtime;if(i())return{adapter:H({isMatch:i},s(e)),runtime:a}}}(t,e)||{},r=n.adapter,o=n.runtime;r&&(ht.adapter=r),o&&(ht.runtime=o)},t.prototype.registerHook=function(e){!function(t,e){var n=e.entity,r=e.target;if(Object.prototype.hasOwnProperty.call(t,r))throw new Error(JSON.stringify({code:it.INVALID_OPERATION,msg:"target:".concat(r," is not exist")}));var o=t.prototype[r];if("function"!=typeof o)throw new Error(JSON.stringify({code:it.INVALID_OPERATION,msg:"target:".concat(r," is not a function which is the only type supports hook")}));t.prototype[r]=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return n.call.apply(n,ot([this],t,!1)),o.call.apply(o,ot([this],t,!1))}}(t,e)},t.prototype.registerComponent=function(e){at(t,e)},t.prototype.registerVersion=function(t){!function(t){bt=t}(t),this.version=t},t.prototype.registerSdkName=function(t){!function(t){wt=t,function(t){d=t}(t)}(t)},t.prototype.isInitialized=function(t){return void 0===t&&(t=this.cloudbaseConfig),"string"==typeof t.env&&["your-env-id","your-envid","your_env_id","xxx-yyy","xxxx-yyy","envId","env-id","your-environment-id","REPLACE_ME"].some(function(e){return t.env.toLowerCase()===e.toLowerCase()})&&Zt(Qt.INVALID_PARAMS,'[CloudBase] 检测到环境 ID "'.concat(t.env,'" 可能是占位符,请替换为真实的环境 ID。\n')+" 获取方式:登录腾讯云开发平台 → 环境管理 → 环境设置 → 环境 ID\n 建议通过环境变量配置:process.env.CLOUDBASE_ENV 或 import.meta.env.VITE_CLOUDBASE_ENV"),!!(null==t?void 0:t.env)},t.prototype.registerEndPoint=function(t,e){At({baseUrl:t,protocol:e,env:this.config.env,endPointKey:"CLOUD_API"})},t.prototype.registerEndPointWithKey=function(t){At({env:this.config.env,endPointKey:t.key,baseUrl:t.url,protocol:t.protocol})},t.prototype.registerHost=function(t,e){void 0===e&&(e="http");var n=t.replace(/^(https?:)?\/\//,""),r="//".concat(n);At({baseUrl:"".concat(r,"/web"),protocol:e,env:this.config.env,endPointKey:"CLOUD_API"}),At({baseUrl:"".concat(r,"/v1"),protocol:e,env:this.config.env,endPointKey:"GATEWAY"})},t.prototype.getEndPointWithKey=function(t){var e=Pt(this.config.env,t);return{BASE_URL:e.baseUrl,PROTOCOL:e.protocol}},t.prototype.parseCaptcha=function(t){return L(t)},t.prototype.useDefaultAdapter=function(){var t=Yt.bind(this)(),e=t.adapter,n=t.runtime;ht.adapter=e,ht.runtime=n},t.prototype.isNodeEnv=function(){var t;return"undefined"!=typeof process&&!!(null===(t=ht.adapter)||void 0===t?void 0:t.getSecretInfo)},t.prototype.formatTimeout=function(t){if(null==t)return t;switch(!0){case t>ne:return Zt(Qt.INVALID_PARAMS,"timeout is greater than maximum value[10min]"),ne;case t<100:return Zt(Qt.INVALID_PARAMS,"timeout is less than maximum value[100ms]"),100;default:return t}},t.prototype.try2InitAuth=function(t){try{t.auth()}catch(t){console.log("try2InitAuth error:",t)}},t.prototype.dealNodeAdapterConfig=function(t){var e,n,r,o,i;if(this.isNodeEnv()){var s=null===(e=ht.adapter)||void 0===e?void 0:e.getSecretInfo(t);t.env&&"symbol"!=typeof t.env||(t.env=s.env),s.credentials&&(t.auth=Jt(Jt({},t.auth),{credentials:s.credentials}));var a=t,c=a.secretId||(null===(n=t.auth)||void 0===n?void 0:n.secretId),u=a.secretKey||(null===(r=t.auth)||void 0===r?void 0:r.secretKey);if(c&&u){var l=a.sessionToken||(null===(o=t.auth)||void 0===o?void 0:o.sessionToken)||"";t.auth=Jt(Jt({},t.auth),{secretId:c,secretKey:u,sessionToken:l,secretType:(null===(i=t.auth)||void 0===i?void 0:i.secretType)||(l?"SESSION_SECRET":"SECRET")})}}return t},zt([te({mode:"sync",title:"Cloudbase 初始化失败",messages:["请确认以下各项:"," 1 - 调用 cloudbase.init() 的语法或参数是否正确"," 2 - 如果是非浏览器环境,是否配置了安全应用来源(https://docs.cloudbase.net/api-reference/webv3/adapter#%E7%AC%AC-2-%E6%AD%A5%E9%85%8D%E7%BD%AE%E5%AE%89%E5%85%A8%E5%BA%94%E7%94%A8%E6%9D%A5%E6%BA%90)","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Xt)]}),$t("design:type",Function),$t("design:paramtypes",[Object]),$t("design:returntype",t)],t.prototype,"init",null),zt([te({title:"调用扩展能力失败",messages:["请确认以下各项:"," 1 - 调用 invokeExtension() 的语法或参数是否正确"," 2 - 被调用的扩展能力是否已经安装并通过 registerExtension() 注册","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Xt)]}),$t("design:type",Function),$t("design:paramtypes",[String,Object]),$t("design:returntype",Promise)],t.prototype,"invokeExtension",null),t}(),ie=new oe,se=void 0===ut.WxRequest?null:(ut.default.genAdapter=function(t){return{root:{globalThis:{}},reqClass:ut.WxRequest,wsClass:ut.WxMpWebSocket,captchaOptions:{openURIWithCallback:function(e){var n=t.EventBus,r={},o=e;console.log("openURIWithCallback",e);var i=e.match(/^(data:.*?)(\?[^#\s]*)?$/);if(i){o=i[1],console.log("openURIWithCallback url",o);var s=i[2];s&&(r=(0,ut.parseQueryString)(s))}console.log("openURIWithCallback queryObj",r);var a=r.token,c=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(r,["token"]);return/^data:/.test(o)&&!a?Promise.reject({error:"invalid_argument",error_description:"invalie captcha data: ".concat(e)}):a?new Promise(function(t){console.log("wait for captcha..."),n.$emit("CAPTCHA_DATA_CHANGE",lt(lt({},c),{token:a,url:o})),n.$once("RESOLVE_CAPTCHA_DATA",function(e){t(e)})}):Promise.reject({error:"unimplemented",error_description:"need to impl captcha data"})}},localStorage:ut.wxMpStorage,primaryStorage:m.StorageType.local,getAppSign:function(){var t=wx.getAccountInfoSync();return"undefined"!=typeof App||"undefined"!=typeof getApp||wx.onAppHide||wx.offAppHide||wx.onAppShow||wx.offAppShow?t&&t.miniProgram?t.miniProgram.appId:"":t&&t.plugin?t.plugin.appId:""}}},ut.default);se&&ie.useAdapters(se);const ae=ie;var ce,ue,le,he,de,fe,pe="/auth";!function(t){t.AUTH_SIGN_UP_URL="/v1/signup",t.AUTH_TOKEN_URL="/v1/token",t.AUTH_REVOKE_URL="/v1/revoke",t.WEDA_USER_URL="/v1/plugin/weda/userinfo",t.AUTH_RESET_PASSWORD="/v1/reset",t.AUTH_GET_DEVICE_CODE="/v1/device/code",t.CHECK_USERNAME="/v1/checkUsername",t.CHECK_IF_USER_EXIST="/v1/checkIfUserExist",t.GET_PROVIDER_TYPE="/v1/mgr/provider/providerSubType",t.AUTH_SIGN_IN_URL="/v1/signin",t.AUTH_SIGN_IN_ANONYMOUSLY_URL="/v1/signin/anonymously",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v1/signin/with/provider",t.AUTH_SIGN_IN_WITH_WECHAT_URL="/v1/signin/wechat/noauth",t.AUTH_SIGN_IN_CUSTOM="/v1/signin/custom",t.PROVIDER_TOKEN_URL="/v1/provider/token",t.PROVIDER_URI_URL="/v1/provider/uri",t.USER_ME_URL="/v1/user/me",t.AUTH_SIGNOUT_URL="/v1/user/signout",t.USER_QUERY_URL="/v1/user/query",t.USER_PRIFILE_URL="/v1/user/profile",t.USER_BASIC_EDIT_URL="/v1/user/basic/edit",t.USER_TRANS_BY_PROVIDER_URL="/v1/user/trans/by/provider",t.PROVIDER_LIST="/v1/user/provider",t.PROVIDER_BIND_URL="/v1/user/provider/bind",t.PROVIDER_UNBIND_URL="/v1/user/provider",t.CHECK_PWD_URL="/v1/user/sudo",t.SUDO_URL="/v1/user/sudo",t.BIND_CONTACT_URL="/v1/user/contact",t.AUTH_SET_PASSWORD="/v1/user/password",t.AUTHORIZE_DEVICE_URL="/v1/user/device/authorize",t.AUTHORIZE_URL="/v1/user/authorize",t.AUTHORIZE_INFO_URL="/v1/user/authorize/info",t.AUTHORIZED_DEVICES_DELETE_URL="/v1/user/authorized/devices/",t.AUTH_REVOKE_ALL_URL="/v1/user/revoke/all",t.GET_USER_BEHAVIOR_LOG="/v1/user/security/history",t.VERIFICATION_URL="/v1/verification",t.VERIFY_URL="/v1/verification/verify",t.CAPTCHA_DATA_URL="/v1/captcha/data",t.VERIFY_CAPTCHA_DATA_URL="/v1/captcha/data/verify",t.GET_CAPTCHA_URL="/v1/captcha/init",t.GET_MINIPROGRAM_QRCODE="/v1/qrcode/generate",t.GET_MINIPROGRAM_QRCODE_STATUS="/v1/qrcode/get/status"}(ce||(ce={})),function(t){t.AUTH_SIGN_IN_URL="/v2/signin/username",t.AUTH_TOKEN_URL="/v2/token",t.USER_ME_URL="/v2/user/me",t.VERIFY_URL="/v2/signin/verificationcode",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",t.AUTH_PUBLIC_KEY="/v2/signin/publichkey",t.AUTH_RESET_PASSWORD="/v2/signin/password/update"}(ue||(ue={})),function(t){t.REGISTER="REGISTER",t.SIGN_IN="SIGN_IN",t.PASSWORD_RESET="PASSWORD_RESET",t.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",t.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"}(le||(le={})),(fe=he||(he={})).UNREACHABLE="unreachable",fe.LOCAL="local",fe.CANCELLED="cancelled",fe.UNKNOWN="unknown",fe.UNAUTHENTICATED="unauthenticated",fe.RESOURCE_EXHAUSTED="resource_exhausted",fe.FAILED_PRECONDITION="failed_precondition",fe.INVALID_ARGUMENT="invalid_argument",fe.DEADLINE_EXCEEDED="deadline_exceeded",fe.NOT_FOUND="not_found",fe.ALREADY_EXISTS="already_exists",fe.PERMISSION_DENIED="permission_denied",fe.ABORTED="aborted",fe.OUT_OF_RANGE="out_of_range",fe.UNIMPLEMENTED="unimplemented",fe.INTERNAL="internal",fe.UNAVAILABLE="unavailable",fe.DATA_LOSS="data_loss",fe.INVALID_PASSWORD="invalid_password",fe.PASSWORD_NOT_SET="password_not_set",fe.INVALID_STATUS="invalid_status",fe.USER_PENDING="user_pending",fe.USER_BLOCKED="user_blocked",fe.INVALID_VERIFICATION_CODE="invalid_verification_code",fe.TWO_FACTOR_REQUIRED="two_factor_required",fe.INVALID_TWO_FACTOR="invalid_two_factor",fe.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",fe.UNDER_REVIEW="under_review",fe.INVALID_REQUEST="invalid_request",fe.UNAUTHORIZED_CLIENT="unauthorized_client",fe.ACCESS_DENIED="access_denied",fe.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",fe.INVALID_SCOPE="invalid_scope",fe.INVALID_GRANT="invalid_grant",fe.SERVER_ERROR="server_error",fe.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",fe.INTERACTION_REQUIRED="interaction_required",fe.LOGIN_REQUIRED="login_required",fe.ACCOUNT_SELECTION_REQUIRED="account_selection_required",fe.CONSENT_REQUIRED="consent_required",fe.INVALID_REQUEST_URI="invalid_request_uri",fe.INVALID_REQUEST_OBJECT="invalid_request_object",fe.REQUEST_NOT_SUPPORTED="request_not_supported",fe.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",fe.REGISTRATION_NOT_SUPPORTED="registration_not_supported",fe.CAPTCHA_REQUIRED="captcha_required",fe.CAPTCHA_INVALID="captcha_invalid",fe.PROVIDER_NOT_ENABLED="provider_not_enabled",fe.LOGIN_METHOD_DISABLED="login_method_disabled",fe.INVALID_USERNAME_OR_PASSWORD="invalid_username_or_password",fe.INVALID_CREDENTIALS="invalid_credentials",fe.WRONG_PASSWORD="wrong_password",fe.USER_NOT_FOUND="user_not_found",fe.MFA_PHONE_REQUIRED="mfa_phone_required",fe.LOGIN_TYPE_DISABLED="login_type_disabled",fe.PROVIDER_ERROR="provider_error",fe.MISSING_REQUIRED_PARAM="missing_required_param",function(t){t[t.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",t[t.NOT_FOUND=5]="NOT_FOUND",t[t.PERMISSION_DENIED=7]="PERMISSION_DENIED",t[t.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",t[t.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",t[t.ABORTED=10]="ABORTED",t[t.UNIMPLEMENTED=12]="UNIMPLEMENTED",t[t.INTERNAL=13]="INTERNAL",t[t.UNAVAILABLE=14]="UNAVAILABLE",t[t.UNAUTHENTICATED=16]="UNAUTHENTICATED",t[t.MISSING_REQUIRED_PARAM=4e3]="MISSING_REQUIRED_PARAM",t[t.CAPTCHA_REQUIRED=4001]="CAPTCHA_REQUIRED",t[t.CAPTCHA_INVALID=4002]="CAPTCHA_INVALID",t[t.PROVIDER_ERROR=4019]="PROVIDER_ERROR",t[t.UNAUTHORIZED_CLIENT=4022]="UNAUTHORIZED_CLIENT",t[t.MFA_PHONE_REQUIRED=4042]="MFA_PHONE_REQUIRED",t[t.LOGIN_TYPE_DISABLED=4045]="LOGIN_TYPE_DISABLED"}(de||(de={}));var ve,ye,ge="credentials_error",me="SIGNED_OUT",be="SIGNED_IN",we="INITIAL_SESSION",_e="TOKEN_REFRESHED",Ee="USER_UPDATED",Ie="BIND_IDENTITY",Se="loginStateChanged",Oe="authStateChanged",Te="sign_in",Ae="bind_identity",Pe="node-sdk-scope";function Re(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})}!function(t){t.EMAIL="email",t.RECOVERY="recovery",t.REAUTHENTICATION="reauthentication"}(ve||(ve={})),function(t){t.CLIENT_ID="client_id",t.CLIENT_SECRET="client_secret",t.RESPONSE_TYPE="response_type",t.SCOPE="scope",t.STATE="state",t.REDIRECT_URI="redirect_uri",t.ERROR="error",t.ERROR_DESCRIPTION="error_description",t.ERROR_URI="error_uri",t.GRANT_TYPE="grant_type",t.CODE="code",t.ACCESS_TOKEN="access_token",t.TOKEN_TYPE="token_type",t.EXPIRES_IN="expires_in",t.USERNAME="username",t.PASSWORD="password",t.REFRESH_TOKEN="refresh_token"}(ye||(ye={}));var Ce=l(2631),ke=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Ne=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},xe=new Map,Ue=function(){function t(t){this.clientId=(null==t?void 0:t.clientId)||"",this.getScope=null==t?void 0:t.getScope,xe=xe||new Map}return t.prototype.run=function(t,e){return ke(this,void 0,Promise,function(){var n,r,o=this;return Ne(this,function(i){return n=this.getScope?this.getScope():this.clientId,t="".concat(n,"_").concat(t),(r=xe.get(t))||(r=new Promise(function(n,r){ke(o,void 0,void 0,function(){var o,i,s;return Ne(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,4,5]),[4,this.runIdlePromise()];case 1:return a.sent(),o=e(),i=n,[4,o];case 2:return i.apply(void 0,[a.sent()]),[3,5];case 3:return s=a.sent(),r(s),[3,5];case 4:return xe.delete(t),[7];case 5:return[2]}})})}),xe.set(t,r)),[2,r]})})},t.prototype.runIdlePromise=function(){return Promise.resolve()},t}(),Le="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",De=/^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/,je=function(t){if(t=String(t).replace(/[\t\n\f\r ]+/g,""),!De.test(t))throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");var e;t+="==".slice(2-(3&t.length));for(var n,r,o="",i=0;i<t.length;)e=Le.indexOf(t.charAt(i++))<<18|Le.indexOf(t.charAt(i++))<<12|(n=Le.indexOf(t.charAt(i++)))<<6|(r=Le.indexOf(t.charAt(i++))),o+=64===n?String.fromCharCode(e>>16&255):64===r?String.fromCharCode(e>>16&255,e>>8&255):String.fromCharCode(e>>16&255,e>>8&255,255&e);return o};function qe(){if("undefined"==typeof globalThis)return!1;var t=globalThis.wx;if(void 0===t)return!1;if(void 0===globalThis.Page)return!1;if(!t.getDeviceInfo)return!1;if(!t.getStorageSync)return!1;if(!t.setStorageSync)return!1;if(!t.connectSocket)return!1;if(!t.request)return!1;try{if(!t.getDeviceInfo())return!1;if("qq"===t.getDeviceInfo().platform)return!1}catch(t){return!1}return!0}var Me=!1;function Be(){Me=Me||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{qe()||(Me=Me||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?Be():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",Be,!1))}catch(t){}var We=function(){return We=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},We.apply(this,arguments)},Fe=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},He=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Ve=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},Ge="x-request-id",Ke="x-device-id",Je="device_id",ze=function(t,e){return Fe(this,void 0,Promise,function(){var n,r,o,i,s;return He(this,function(a){switch(a.label){case 0:n=null,r=null,a.label=1;case 1:return a.trys.push([1,4,,5]),(o=Object.assign({},e)).method||(o.method="GET"),o.body&&"string"!=typeof o.body&&(o.body=JSON.stringify(o.body)),[4,fetch(t,o)];case 2:return[4,a.sent().json()];case 3:return(null==(i=a.sent())?void 0:i.error)?(r=i).error_uri=new URL(t).pathname:n=i,[3,5];case 4:return s=a.sent(),r={error:he.UNREACHABLE,error_description:s.message,error_uri:new URL(t).pathname},[3,5];case 5:if(r)throw r;return[2,n]}})})},$e=function(){function t(t){this._env=(null==t?void 0:t.env)||""}return t.prototype.getItem=function(t){return Fe(this,void 0,Promise,function(){return He(this,function(e){return[2,window.localStorage.getItem("".concat(t).concat(this._env))]})})},t.prototype.removeItem=function(t){return Fe(this,void 0,Promise,function(){return He(this,function(e){return window.localStorage.removeItem("".concat(t).concat(this._env)),[2]})})},t.prototype.setItem=function(t,e){return Fe(this,void 0,Promise,function(){return He(this,function(n){return window.localStorage.setItem("".concat(t).concat(this._env),e),[2]})})},t.prototype.getItemSync=function(t){return window.localStorage.getItem("".concat(t).concat(this._env))},t.prototype.removeItemSync=function(t){window.localStorage.removeItem("".concat(t).concat(this._env))},t.prototype.setItemSync=function(t,e){window.localStorage.setItem("".concat(t).concat(this._env),e)},t}(),Ye=new $e,Qe=function(){function t(t){var e=this;this.credentials=null,this.accessKeyCredentials=null,this.singlePromise=null,this.tokenSectionName=t.tokenSectionName,this.storage=t.storage,this.clientId=t.clientId,this.singlePromise=new Ue({clientId:this.clientId,getScope:function(){var t;return(null===(t=e.accessKeyCredentials)||void 0===t?void 0:t.access_token)?"".concat(e.clientId,"_").concat(e.accessKeyCredentials.access_token):e.clientId}}),this.credentials=t.credentials||null,this.onCredentialsChange=t.onCredentialsChange}return t.prototype.syncMemoryCredentials=function(t){this.credentials=t},t.prototype.getMemoryCredentials=function(){return this.credentials},t.prototype.getStorageCredentialsSync=function(){var t=null,e=this.storage.getItemSync(this.tokenSectionName);if(null!=e)try{(null==(t=JSON.parse(e))?void 0:t.expires_at)&&(t.expires_at=new Date(t.expires_at))}catch(e){this.storage.removeItem(this.tokenSectionName),t=null}return t},t.prototype.setCredentials=function(t,e){var n;return Fe(this,void 0,Promise,function(){var r,o;return He(this,function(i){switch(i.label){case 0:return r=!(!this.credentials||!this.credentials.access_token),(null==t?void 0:t.expires_in)?((null==t?void 0:t.expires_at)||(t.expires_at=new Date(Date.now()+1e3*(t.expires_in-30))),this.storage?(o=JSON.stringify(t),[4,this.storage.setItem(this.tokenSectionName,o)]):[3,2]):[3,3];case 1:i.sent(),i.label=2;case 2:return this.credentials=t,[3,6];case 3:return this.storage?[4,this.storage.removeItem(this.tokenSectionName)]:[3,5];case 4:i.sent(),i.label=5;case 5:this.credentials=null,i.label=6;case 6:return this.onCredentialsChange&&this.onCredentialsChange(t||null,{isInit:null!==(n=null==e?void 0:e.isInit)&&void 0!==n&&n,hadCredentials:r}),[2]}})})},t.prototype.setAccessKeyCredentials=function(t){this.accessKeyCredentials=t,t.scope===Pe&&(this.credentials=t)},t.prototype.getCredentials=function(){return Fe(this,void 0,Promise,function(){var t=this;return He(this,function(e){return[2,this.singlePromise.run("getCredentials",function(){return Fe(t,void 0,void 0,function(){var t,e;return He(this,function(n){switch(n.label){case 0:return[4,this.getStorageCredentials()];case 1:return t=n.sent(),e=t.credentials,t.isAccessKeyCredentials?[2,e]:(this.credentials=e,[2,this.credentials])}})})})]})})},t.prototype.getStorageCredentials=function(){return Fe(this,void 0,Promise,function(){var t=this;return He(this,function(e){return[2,this.singlePromise.run("_getStorageCredentials",function(){return Fe(t,void 0,void 0,function(){var t,e,n;return He(this,function(r){switch(r.label){case 0:return t=null,e=!1,[4,this.storage.getItem(this.tokenSectionName)];case 1:if(!(n=r.sent()))return[3,6];r.label=2;case 2:return r.trys.push([2,3,,5]),(null==(t=JSON.parse(n))?void 0:t.expires_at)&&(t.expires_at=new Date(t.expires_at)),[3,5];case 3:return r.sent(),[4,this.storage.removeItem(this.tokenSectionName)];case 4:return r.sent(),t=null,[3,5];case 5:return[3,7];case 6:t=this.accessKeyCredentials||null,e=!0,r.label=7;case 7:return[2,{credentials:t,isAccessKeyCredentials:e}]}})})})]})})},t}(),Xe=function(){function t(e){var n,r=this;this.initializePromise=null,this.lockAcquired=!1,this.pendingInLock=[],this.singlePromise=null,this._initSessionEmitted=!1,e.clientSecret||(e.clientSecret=""),!e.clientId&&e.env&&(e.clientId=e.env),this.apiOrigin=e.apiOrigin,this.getApiOriginFunc=e.getApiOrigin,this.apiPath=e.apiPath||pe,this.clientId=e.clientId,this.i18n=e.i18n,this.eventBus=e.eventBus,this.singlePromise=new Ue({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,t.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=ze,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||Ye,this.localCredentials=new Qe({tokenSectionName:"credentials_".concat(e.clientId),storage:this.storage,clientId:e.clientId,onCredentialsChange:this._handleCredentialsChange.bind(this)}),this.clientSecret=e.clientSecret,e.clientId&&(this.basicAuth="Basic ".concat(function(t){for(var e,n,r,o,i="",s=0,a=(t=String(t)).length%3;s<t.length;){if((n=t.charCodeAt(s++))>255||(r=t.charCodeAt(s++))>255||(o=t.charCodeAt(s++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");i+=Le.charAt((e=n<<16|r<<8|o)>>18&63)+Le.charAt(e>>12&63)+Le.charAt(e>>6&63)+Le.charAt(63&e)}return a?i.slice(0,a-3)+"===".substring(a):i}("".concat(e.clientId,":").concat(this.clientSecret)))),this.wxCloud=e.wxCloud;try{qe()&&(this.useWxCloud=e.useWxCloud,void 0===this.wxCloud&&e.env&&(wx.cloud.init({env:e.env}),this.wxCloud=wx.cloud))}catch(t){}this.refreshTokenFunc=e.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=e.anonymousSignInFunc,this.onCredentialsError=e.onCredentialsError,this.getInitialSession=e.getInitialSession,this.onInitialSessionObtained=e.onInitialSessionObtained,this.logDebugMessages=null!==(n=e.debug)&&void 0!==n&&n,Z.on(tt,function(t){var e;r.i18n=(null===(e=t.data)||void 0===e?void 0:e.i18n)||r.i18n}),this._initBroadcastChannel(),this._initVisibilityListener()}return t.prototype.setGetInitialSession=function(t){this.getInitialSession=t},t.prototype.setOnInitialSessionObtained=function(t){this.onInitialSessionObtained=t},t.prototype.initialize=function(t){return Fe(this,void 0,Promise,function(){var e=this;return He(this,function(n){switch(n.label){case 0:return this.initializePromise?[4,this.initializePromise]:[3,2];case 1:case 3:case 5:return[2,n.sent()];case 2:return void 0===t?[3,4]:(this.initializePromise=t,[4,this.initializePromise]);case 4:return this.initializePromise=Fe(e,void 0,void 0,function(){var t=this;return He(this,function(e){switch(e.label){case 0:return[4,this._acquireLock(-1,function(){return Fe(t,void 0,void 0,function(){return He(this,function(t){switch(t.label){case 0:return[4,this._initialize()];case 1:return[2,t.sent()]}})})})];case 1:return[2,e.sent()]}})}),[4,this.initializePromise]}})})},t.prototype.setCredentials=function(t){return Fe(this,void 0,Promise,function(){var e=this;return He(this,function(n){switch(n.label){case 0:return[4,this.initializePromise];case 1:return n.sent(),[2,this._acquireLock(-1,function(){return Fe(e,void 0,void 0,function(){return He(this,function(e){return[2,this.localCredentials.setCredentials(t)]})})})]}})})},Object.defineProperty(t.prototype,"initSessionEmitted",{get:function(){return this._initSessionEmitted},enumerable:!1,configurable:!0}),t.prototype.destroy=function(){try{this.broadcastChannel&&"function"==typeof this.broadcastChannel.close&&this.broadcastChannel.close()}catch(t){this._debug("#destroy","close BroadcastChannel error",t)}finally{this.broadcastChannel=null}try{var t=this.visibilityEventHandler;this.visibilityEventHandler=void 0,t&&"undefined"!=typeof window&&"undefined"!=typeof document&&"function"==typeof window.removeEventListener&&window.removeEventListener("visibilitychange",t)}catch(t){this._debug("#destroy","remove visibility listener error",t)}},t.prototype.setAccessKeyCredentials=function(t){return this.localCredentials.setAccessKeyCredentials(t)},t.prototype.getAccessToken=function(){return Fe(this,void 0,Promise,function(){var t,e;return He(this,function(n){switch(n.label){case 0:return[4,this.initializePromise];case 1:return n.sent(),[4,this.getCredentials()];case 2:return(null==(t=n.sent())?void 0:t.scope)===Pe||(null==t?void 0:t.access_token)?[2,Promise.resolve(t.access_token)]:(e={error:he.UNAUTHENTICATED},[2,Promise.reject(e)])}})})},t.prototype.request=function(e,n){var r,o;return Fe(this,void 0,Promise,function(){var i,s,a,c,u,l,h,d,f,p;return He(this,function(v){switch(v.label){case 0:return n||(n={}),i=this.formatRetry(n.retry,this.retry),n.headers=We(We({},n.headers),((p={})[null===(r=this.i18n)||void 0===r?void 0:r.LANG_HEADER_KEY]=null===(o=this.i18n)||void 0===o?void 0:o.lang,p)),this.headers&&(n.headers=We(We({},this.headers),n.headers)),n.headers[Ge]||(n.headers[Ge]=Re()),n.headers[Ke]?[3,2]:[4,this.getDeviceId()];case 1:s=v.sent(),n.headers[Ke]=s,v.label=2;case 2:return(null==n?void 0:n.withBasicAuth)&&this.basicAuth&&(n.headers.Authorization=this.basicAuth),(null==n?void 0:n.withCredentials)?n.getCredentials?[4,n.getCredentials()]:[3,4]:[3,7];case 3:return c=v.sent(),[3,6];case 4:return[4,this.getCredentials()];case 5:c=v.sent(),v.label=6;case 6:return(a=c)&&(this.tokenInURL?(e.indexOf("?")<0&&(e+="?"),e+="access_token=".concat(a.access_token)):n.headers.Authorization="".concat(a.token_type," ").concat(a.access_token)),[3,8];case 7:this.clientId&&e.indexOf("client_id")<0&&(e+=e.indexOf("?")<0?"?":"&",e+="client_id=".concat(this.clientId)),v.label=8;case 8:e.startsWith("/")&&(u=this.getApiOriginFunc?this.getApiOriginFunc():this.apiOrigin,e="".concat(u).concat(this.apiPath).concat(e)),l=null,h=i+1,d=0,v.label=9;case 9:if(!(d<h))return[3,21];v.label=10;case 10:return v.trys.push([10,15,,18]),n.useWxCloud||this.useWxCloud?[4,this.wxCloudCallFunction(e,n)]:[3,12];case 11:return l=v.sent(),[3,14];case 12:return[4,this.baseRequest(e,n)];case 13:l=v.sent(),v.label=14;case 14:if(null==l?void 0:l.code)throw{error:l.code,error_description:l.message,error_uri:new URL(e).pathname};return[3,21];case 15:f=v.sent();try{f.requestId=f.requestId||n.headers[Ge]||""}catch(t){}return n.withCredentials&&f&&f.error===he.UNAUTHENTICATED?[4,this.setCredentials(null)]:[3,17];case 16:return v.sent(),[2,Promise.reject(f)];case 17:return d!==i&&f&&"unreachable"===f.error?[3,18]:[2,Promise.reject(f)];case 18:return[4,this.sleep(t.retryInterval)];case 19:v.sent(),v.label=20;case 20:return d++,[3,9];case 21:return[2,l]}})})},t.prototype.wxCloudCallFunction=function(t,e){var n;return Fe(this,void 0,Promise,function(){var r,o,i,s,a;return He(this,function(c){switch(c.label){case 0:r=null,o=null,c.label=1;case 1:c.trys.push([1,7,,8]),i="",c.label=2;case 2:return c.trys.push([2,4,,5]),[4,wx.getRendererUserAgent()];case 3:return i=c.sent(),[3,5];case 4:return c.sent(),[3,5];case 5:return[4,this.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:t,method:e.method,headers:We({origin:"https://servicewechat.com","User-Agent":i},e.headers),body:e.body}})];case 6:return s=c.sent().result,(null===(n=null==s?void 0:s.body)||void 0===n?void 0:n.error_code)?(o=null==s?void 0:s.body).error_uri=(0,Ce.y)(t):r=null==s?void 0:s.body,[3,8];case 7:return a=c.sent(),o={error:he.UNREACHABLE,error_description:a.message,error_uri:(0,Ce.y)(t)},[3,8];case 8:if(o)throw o;return[2,r]}})})},t.prototype.getCredentials=function(){return Fe(this,void 0,Promise,function(){var t=this;return He(this,function(e){switch(e.label){case 0:return[4,this.initializePromise];case 1:return e.sent(),[2,this._acquireLock(-1,function(){return Fe(t,void 0,void 0,function(){return He(this,function(t){return[2,this._getCredentials()]})})})]}})})},t.prototype.getCredentialsSync=function(){return this.localCredentials.getStorageCredentialsSync()},t.prototype.getCredentialsAsync=function(){return this.getCredentials()},t.prototype.getScope=function(){var t;return Fe(this,void 0,Promise,function(){var e,n;return He(this,function(r){switch(r.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return(e=r.sent())?[2,e.scope]:(n="credentials not found",null===(t=this.onCredentialsError)||void 0===t||t.call(this,{msg:n}),[2,this.unAuthenticatedError(n)])}})})},t.prototype.getGroups=function(){var t;return Fe(this,void 0,Promise,function(){var e,n;return He(this,function(r){switch(r.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return(e=r.sent())?[2,e.groups]:(n="credentials not found",null===(t=this.onCredentialsError)||void 0===t||t.call(this,{msg:n}),[2,this.unAuthenticatedError(n)])}})})},t.prototype.refreshToken=function(t,e){return Fe(this,void 0,Promise,function(){var n=this;return He(this,function(r){switch(r.label){case 0:return[4,this.initializePromise];case 1:return r.sent(),[2,this._acquireLock(-1,function(){return Fe(n,void 0,void 0,function(){return He(this,function(n){return[2,this._refreshToken(t,e)]})})})]}})})},t.prototype._refreshToken=function(t,e){return Fe(this,void 0,Promise,function(){var n=this;return He(this,function(r){return[2,this.singlePromise.run("_refreshToken",function(){return Fe(n,void 0,void 0,function(){var n,r,o,i,s,a;return He(this,function(c){switch(c.label){case 0:if((null==t?void 0:t.scope)===Pe)return[2,t];if(!t||!t.refresh_token)return o="no refresh token found in credentials",null===(i=this.onCredentialsError)||void 0===i||i.call(this,{msg:o}),[2,this.unAuthenticatedError(o)];c.label=1;case 1:return c.trys.push([1,4,,7]),[4,this.refreshTokenFunc(t.refresh_token,t)];case 2:return n=c.sent(),[4,this.localCredentials.setCredentials(n)];case 3:return c.sent(),[2,n];case 4:if(r=c.sent(),null==e?void 0:e.throwError)throw r;return r.error!==he.INVALID_GRANT?[3,6]:[4,this.localCredentials.setCredentials(null)];case 5:return c.sent(),o=r.error_description,null===(s=this.onCredentialsError)||void 0===s||s.call(this,{msg:o}),[2,this.unAuthenticatedError(o)];case 6:return null===(a=this.onCredentialsError)||void 0===a||a.call(this,{msg:r.error_description}),[2,Promise.reject(r)];case 7:return[2]}})})})]})})},t.prototype.anonymousLogin=function(t){return Fe(this,void 0,void 0,function(){var e=this;return He(this,function(n){return[2,this.singlePromise.run("_anonymousLogin",function(){return Fe(e,void 0,void 0,function(){var e,n;return He(this,function(r){switch(r.label){case 0:return this.anonymousSignInFunc?[4,this.anonymousSignInFunc(t)]:[3,4];case 1:return e=r.sent(),(n=e)?[3,3]:[4,this.localCredentials.getCredentials()];case 2:n=r.sent(),r.label=3;case 3:return t=n,[3,6];case 4:return[4,this.anonymousSignIn(t)];case 5:t=r.sent(),r.label=6;case 6:return[2,t]}})})})]})})},t.prototype.checkRetry=function(e){var n=null;if(("number"!=typeof e||e<t.minRetry||e>t.maxRetry)&&(n={error:he.UNREACHABLE,error_description:"wrong options param: retry"}),n)throw n;return e},t.prototype.formatRetry=function(t,e){return void 0===t?e:this.checkRetry(t)},t.prototype.sleep=function(t){return Fe(this,void 0,Promise,function(){return He(this,function(e){return[2,new Promise(function(e){setTimeout(function(){e()},t)})]})})},t.prototype.anonymousSignIn=function(t){return Fe(this,void 0,Promise,function(){var e=this;return He(this,function(n){return[2,this.singlePromise.run("_anonymous",function(){return Fe(e,void 0,void 0,function(){var e,n;return He(this,function(r){switch(r.label){case 0:if(!t||"anonymous"!==t.scope)return[2,this.unAuthenticatedError("no anonymous in credentials")];r.label=1;case 1:return r.trys.push([1,4,,7]),[4,this.request(ce.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}})];case 2:return e=r.sent(),[4,this.localCredentials.setCredentials(e)];case 3:return r.sent(),[2,e];case 4:return(n=r.sent()).error!==he.INVALID_GRANT?[3,6]:[4,this.localCredentials.setCredentials(null)];case 5:return r.sent(),[2,this.unAuthenticatedError(n.error_description)];case 6:return[2,Promise.reject(n)];case 7:return[2]}})})})]})})},t.prototype.defaultRefreshTokenFunc=function(t,e){var n;return Fe(this,void 0,Promise,function(){var r,o,i;return He(this,function(s){switch(s.label){case 0:return void 0===t||""===t?(r="refresh token not found",null===(n=this.onCredentialsError)||void 0===n||n.call(this,{msg:r}),[2,this.unAuthenticatedError(r)]):(o=ce.AUTH_TOKEN_URL,"v2"===(null==e?void 0:e.version)&&(o=ue.AUTH_TOKEN_URL),[4,this.request(o,{method:"POST",body:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"refresh_token",refresh_token:t}})]);case 1:return i=s.sent(),[2,We(We({},i),{version:(null==e?void 0:e.version)||"v1"})]}})})},t.prototype.getDeviceId=function(){return Fe(this,void 0,Promise,function(){var t;return He(this,function(e){switch(e.label){case 0:return this.deviceID?[2,this.deviceID]:[4,this.storage.getItem(Je)];case 1:return"string"==typeof(t=e.sent())&&t.length>=16&&t.length<=48?[3,3]:(t=Re(),[4,this.storage.setItem(Je,t)]);case 2:e.sent(),e.label=3;case 3:return this.deviceID=t,[2,t]}})})},t.prototype.unAuthenticatedError=function(t){var e={error:he.UNAUTHENTICATED,error_description:t};return Promise.reject(e)},t.prototype._debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.logDebugMessages&&console.log.apply(console,Ve(["[OAuth2Client]"],t,!1))},t.prototype._initialize=function(){return Fe(this,void 0,Promise,function(){var t,e,n,r,o,i;return He(this,function(s){switch(s.label){case 0:if(s.trys.push([0,11,12,13]),!this.getInitialSession)return this._debug("#_initialize()","no getInitialSession callback set, skipping"),[2,{error:null}];this._debug("#_initialize()","calling getInitialSession callback"),s.label=1;case 1:return s.trys.push([1,9,,10]),[4,this.getInitialSession()];case 2:return i=s.sent(),t=i.data,e=i.error,(null==t?void 0:t.session)?(this._debug("#_initialize()","session obtained from getInitialSession",t.session),this._initSessionEmitted=!0,[4,this.localCredentials.setCredentials(null==t?void 0:t.session,{isInit:!0})]):[3,4];case 3:s.sent(),s.label=4;case 4:if(!this.onInitialSessionObtained)return[3,8];this._debug("#_initialize()","calling onInitialSessionObtained callback"),s.label=5;case 5:return s.trys.push([5,7,,8]),[4,this.onInitialSessionObtained(t,e)];case 6:return s.sent(),[3,8];case 7:return n=s.sent(),this._debug("#_initialize()","error in onInitialSessionObtained",n),[3,8];case 8:return e?(this._debug("#_initialize()","error from getInitialSession",e),[2,{error:e}]):[2,{error:null}];case 9:return r=s.sent(),this._debug("#_initialize()","exception during getInitialSession",r),[2,{error:r instanceof Error?r:new Error(String(r))}];case 10:return[3,13];case 11:return o=s.sent(),this._debug("#_initialize()","unexpected error",o),[2,{error:o instanceof Error?o:new Error(String(o))}];case 12:return this._debug("#_initialize()","end"),[7];case 13:return[2]}})})},t.prototype._acquireLock=function(t,e){return Fe(this,void 0,Promise,function(){var n,r,o,i,s=this;return He(this,function(a){switch(a.label){case 0:this._debug("#_acquireLock","begin",t),a.label=1;case 1:if(a.trys.push([1,,10,11]),this.lockAcquired)return n=this.pendingInLock.length?this.pendingInLock[this.pendingInLock.length-1]:Promise.resolve(),r=Fe(s,void 0,void 0,function(){return He(this,function(t){switch(t.label){case 0:return[4,n];case 1:return t.sent(),[4,e()];case 2:return[2,t.sent()]}})}),this.pendingInLock.push(Fe(s,void 0,void 0,function(){return He(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,r];case 1:case 2:return t.sent(),[3,3];case 3:return[2]}})})),[2,r];this._debug("#_acquireLock","acquiring lock for client",this.clientId),a.label=2;case 2:return a.trys.push([2,,8,9]),this.lockAcquired=!0,o=e(),this.pendingInLock.push(Fe(s,void 0,void 0,function(){return He(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,o];case 1:case 2:return t.sent(),[3,3];case 3:return[2]}})})),[4,o];case 3:a.sent(),a.label=4;case 4:return this.pendingInLock.length?(i=Ve([],this.pendingInLock,!0),[4,Promise.all(i)]):[3,6];case 5:return a.sent(),this.pendingInLock.splice(0,i.length),[3,4];case 6:return[4,o];case 7:return[2,a.sent()];case 8:return this._debug("#_acquireLock","releasing lock for client",this.clientId),this.lockAcquired=!1,[7];case 9:return[3,11];case 10:return this._debug("#_acquireLock","end"),[7];case 11:return[2]}})})},t.prototype._getCredentials=function(){var t,e,n;return Fe(this,void 0,Promise,function(){var r,o,i;return He(this,function(s){switch(s.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:if((null==(r=s.sent())?void 0:r.scope)===Pe)return[2,r];if(!r)return i="credentials not found",null===(t=this.onCredentialsError)||void 0===t||t.call(this,{msg:i}),[2,this.unAuthenticatedError(i)];if(!function(t){var e=!0;return(null==t?void 0:t.expires_at)&&(null==t?void 0:t.access_token)&&(e=t.expires_at<new Date),e}(r))return[3,12];if(!r.refresh_token)return[3,9];s.label=2;case 2:return s.trys.push([2,4,,8]),[4,this._refreshToken(r)];case 3:return r=s.sent(),[3,8];case 4:return o=s.sent(),"anonymous"!==r.scope?[3,6]:[4,this.anonymousLogin(r)];case 5:return r=s.sent(),[3,7];case 6:return null===(e=this.onCredentialsError)||void 0===e||e.call(this,{msg:o.error_description}),[2,Promise.reject(o)];case 7:return[3,8];case 8:return[3,12];case 9:return"anonymous"!==r.scope?[3,11]:[4,this.anonymousLogin(r)];case 10:return r=s.sent(),[3,12];case 11:return i="no refresh token found in credentials",null===(n=this.onCredentialsError)||void 0===n||n.call(this,{msg:i}),[2,this.unAuthenticatedError(i)];case 12:return[2,r]}})})},t.prototype._isUserCredentials=function(t){return!!(null==t?void 0:t.access_token)&&"accessKey"!==t.scope&&t.scope!==Pe},t.prototype._fireCredentialsEvents=function(t,e,n){var r,o,i,s,a,c;this._isUserCredentials(t)?e?null===(i=this.eventBus)||void 0===i||i.fire(Oe,{event:we}):n?null===(s=this.eventBus)||void 0===s||s.fire(Oe,{event:_e}):(null===(a=this.eventBus)||void 0===a||a.fire(Oe,{event:be}),null===(c=this.eventBus)||void 0===c||c.fire(Se,{eventType:"sign_in"})):n&&(null===(r=this.eventBus)||void 0===r||r.fire(Oe,{event:me}),null===(o=this.eventBus)||void 0===o||o.fire(Se,{eventType:"sign_out"}))},t.prototype._handleCredentialsChange=function(t,e){this._fireCredentialsEvents(t,e.isInit,e.hadCredentials),this._broadcastCredentials(t,e)},t.prototype._initBroadcastChannel=function(){var t=this;if(void 0===this.broadcastChannel)try{"undefined"!=typeof BroadcastChannel&&(this.broadcastChannelName="credentials_".concat(this.clientId),this.broadcastChannel=new BroadcastChannel(this.broadcastChannelName),this.broadcastChannel.addEventListener("message",function(e){t._handleBroadcastMessage(e.data)}),this._debug("#_initBroadcastChannel","channel created: ".concat(this.broadcastChannelName)))}catch(t){this.broadcastChannel=null,this._debug("#_initBroadcastChannel","BroadcastChannel not available, skip",t)}},t.prototype._broadcastCredentials=function(t,e){if(this.broadcastChannel)try{this.broadcastChannel.postMessage({type:"credentials_changed",credentials:t,context:e})}catch(t){this._debug("#_broadcastCredentials","postMessage error",t)}},t.prototype._handleBroadcastMessage=function(t){var e,n;try{if(!t||"credentials_changed"!==t.type)return;var r=t.context,o=t.credentials;if((null==o?void 0:o.expires_at)&&"string"==typeof o.expires_at&&(o=We(We({},o),{expires_at:new Date(o.expires_at)})),(null==o?void 0:o.access_token)===(null===(e=this.localCredentials.getMemoryCredentials())||void 0===e?void 0:e.access_token))return;var i=!!(null===(n=this.localCredentials.getMemoryCredentials())||void 0===n?void 0:n.access_token);this.localCredentials.syncMemoryCredentials(o),this._fireCredentialsEvents(o,r.isInit,i)}catch(t){this._debug("#_handleBroadcastMessage","error",t)}},t.prototype._initVisibilityListener=function(){var t=this;try{if("undefined"==typeof window||"undefined"==typeof document||"function"!=typeof window.addEventListener)return;this.visibilityEventHandler=function(){return Fe(t,void 0,void 0,function(){var t;return He(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this._onVisibilityChanged()];case 1:return e.sent(),[3,3];case 2:return t=e.sent(),this._debug("#visibilityChangedCallback","error",t),[3,3];case 3:return[2]}})})},window.addEventListener("visibilitychange",this.visibilityEventHandler)}catch(t){this._debug("#_initVisibilityListener",t)}},t.prototype._onVisibilityChanged=function(){return Fe(this,void 0,Promise,function(){var t=this;return He(this,function(e){return"visible"!==document.visibilityState||this._acquireLock(-1,function(){return Fe(t,void 0,void 0,function(){var t,e,n,r,o,i;return He(this,function(s){switch(s.label){case 0:if("visible"!==document.visibilityState)return[2];s.label=1;case 1:return s.trys.push([1,3,,4]),t=this.localCredentials.getMemoryCredentials(),[4,this.localCredentials.getCredentials()];case 2:return e=s.sent(),n=null==t?void 0:t.access_token,r=null==e?void 0:e.access_token,n===r?[2]:(o=!!n,this._fireCredentialsEvents(e,!1,o),[3,4]);case 3:return i=s.sent(),this._debug("#_onVisibilityChanged","reload credentials error",i),[3,4];case 4:return[2]}})})}),[2]})})},t.defaultRetry=2,t.minRetry=0,t.maxRetry=5,t.retryInterval=1e3,t}(),Ze=l(9689),tn=l(3616),en=function(){return en=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},en.apply(this,arguments)},nn=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},rn=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},on=function(t,e){var n;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];clearTimeout(n),n=setTimeout(function(){return t.apply(null,r)},e)}},sn=new Ze.CloudbaseEventEmitter,an="resolveCaptchaData",cn="padding:10px 8px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer;flex:1;white-space:nowrap;margin-left:10px",un="width:100%;padding:10px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer",ln="background:#6c757d;cursor:not-allowed",hn=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},dn=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},fn=function(){function t(t){t.openURIWithCallback||(t.openURIWithCallback=this.getDefaultOpenURIWithCallback()),t.storage||(t.storage=Ye),this.config=t,this.tokenSectionName="captcha_".concat(t.clientId||t.env)}return t.prototype.isMatch=function(){var t,e,n;return(null===(n=null===(e=null===(t=this.config)||void 0===t?void 0:t.adapter)||void 0===e?void 0:e.isMatch)||void 0===n?void 0:n.call(e))||qe()},t.prototype.request=function(t,e){return hn(this,void 0,Promise,function(){var n,r,o,i;return dn(this,function(s){switch(s.label){case 0:return e||(e={}),e.method||(e.method="GET"),n="".concat(e.method,":").concat(t),r=t,e.withCaptcha?[4,this.appendCaptchaTokenToURL(t,n,!1)]:[3,2];case 1:r=s.sent(),s.label=2;case 2:return s.trys.push([2,4,,7]),[4,this.config.request(r,e)];case 3:return o=s.sent(),[3,7];case 4:return(i=s.sent()).error!==he.CAPTCHA_REQUIRED&&i.error!==he.CAPTCHA_INVALID?[3,6]:[4,this.appendCaptchaTokenToURL(t,n,i.error===he.CAPTCHA_INVALID)];case 5:return t=s.sent(),[2,this.config.request(t,e)];case 6:return[2,Promise.reject(i)];case 7:return[2,o]}})})},t.prototype.getDefaultOpenURIWithCallback=function(){var t=this;return function(e){return function(t,e){return nn(void 0,void 0,Promise,function(){var n,r,o,i;return rn(this,function(s){return n=(0,tn.parseCaptcha)(t),r=n.captchaData,o=n.state,i=n.token,function(t){var e=t.oauthInstance,n=t.captchaState,r="captcha-image",o=function(){return nn(void 0,void 0,void 0,function(){var t,o;return rn(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,e.createCaptchaData({state:n.state})];case 1:return t=i.sent(),n=en(en({},n),{captchaData:t.data,token:t.token}),document.getElementById(r).src=t.data,[3,3];case 2:return o=i.sent(),console.error("刷新图形验证码失败",o),[3,3];case 3:return[2]}})})},i=function(t,e,n){var r=document.createElement(t);return e&&(r.style.cssText=e),n&&(r.textContent=n),r},s=i("div","position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:999"),a=i("div","position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:320px;padding:20px;background:#fff;border-radius:8px;box-shadow:0 0 10px rgba(0,0,0,0.2);z-index:1000");a.appendChild(i("p","margin-bottom:15px","请输入你看到的字符:"));var c=i("div","display:flex;align-items:center;justify-content:space-between;margin-bottom:15px"),u=i("img","width:100%;height:auto;border:1px solid #eee");u.id=r,u.src=n.captchaData,c.appendChild(u);var l=i("button",cn,"刷新");l.onclick=on(function(){return nn(void 0,void 0,void 0,function(){return rn(this,function(t){switch(t.label){case 0:l.textContent="加载中...",l.disabled=!0,l.style.cssText="".concat(cn,";").concat(ln),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,o()];case 2:return t.sent(),[3,4];case 3:return l.textContent="刷新",l.disabled=!1,l.style.cssText=cn,[7];case 4:return[2]}})})},500),c.appendChild(l),a.appendChild(c);var h=i("input","width:100%;padding:14px 16px;margin-bottom:15px;box-sizing:border-box;border:2px solid #e8ecf4;border-radius:10px;font-size:15px");h.type="text",h.placeholder="输入字符",h.maxLength=4,a.appendChild(h);var d=i("div","color:#dc3545;font-size:12px;margin-bottom:10px;display:none;padding:8px;background:#f8d7da;border:1px solid #f5c6cb;border-radius:4px");a.appendChild(d);var f=function(t){d.textContent=t,d.style.display="block"},p=i("button",un,"确定");p.onclick=on(function(){return nn(void 0,void 0,void 0,function(){var t,r,i,c;return rn(this,function(u){switch(u.label){case 0:if(!(t=h.value.trim()))return f("请输入字符"),[2];d.style.display="none",p.textContent="验证中...",p.disabled=!0,p.style.cssText="".concat(un,";").concat(ln),u.label=1;case 1:return u.trys.push([1,3,5,6]),[4,e.verifyCaptchaData({token:n.token,key:t})];case 2:return r=u.sent(),sn.fire(an,r),console.log("图形验证码校验成功"),document.body.removeChild(s),document.body.removeChild(a),[3,6];case 3:return i=u.sent(),console.error("图形验证码校验失败",i),c=i.error_description||"图形验证码校验失败",f(c),h.value="",h.focus(),[4,o()];case 4:return u.sent(),[3,6];case 5:return p.textContent="确定",p.disabled=!1,p.style.cssText=un,[7];case 6:return[2]}})})},500),a.appendChild(p),document.body.appendChild(s),document.body.appendChild(a)}({oauthInstance:e,captchaState:{captchaData:r,state:o,token:i}}),[2,new Promise(function(t){console.log("等待图形验证码校验结果..."),sn.on(an,function(e){t(null==e?void 0:e.data)})})]})})}(e,t.config.oauthInstance)}},t.prototype.getCaptchaToken=function(t,e){return hn(this,void 0,Promise,function(){var n,r,o,i;return dn(this,function(s){switch(s.label){case 0:return t?[3,2]:[4,this.findCaptchaToken()];case 1:if(n=s.sent())return[2,n];s.label=2;case 2:return[4,this.config.request(ce.CAPTCHA_DATA_URL,{method:"POST",body:{state:e,redirect_uri:""},withCredentials:!1})];case 3:return r=s.sent(),o="".concat(r.data,"?state=").concat(encodeURIComponent(e),"&token=").concat(encodeURIComponent(r.token)),[4,this.config.openURIWithCallback(o)];case 4:return i=s.sent(),this.saveCaptchaToken(i),[2,i.captcha_token]}})})},t.prototype.appendCaptchaTokenToURL=function(t,e,n){return hn(this,void 0,Promise,function(){var r;return dn(this,function(o){switch(o.label){case 0:return[4,this.getCaptchaToken(n,e)];case 1:return r=o.sent(),t.indexOf("?")>0?t+="&captcha_token=".concat(r):t+="?captcha_token=".concat(r),[2,t]}})})},t.prototype.saveCaptchaToken=function(t){return hn(this,void 0,void 0,function(){var e;return dn(this,function(n){switch(n.label){case 0:return t.expires_at=new Date(Date.now()+1e3*(t.expires_in-10)),e=JSON.stringify(t),[4,this.config.storage.setItem(this.tokenSectionName,e)];case 1:return n.sent(),[2]}})})},t.prototype.findCaptchaToken=function(){return hn(this,void 0,Promise,function(){var t,e;return dn(this,function(n){switch(n.label){case 0:return[4,this.config.storage.getItem(this.tokenSectionName)];case 1:if(null==(t=n.sent()))return[3,5];n.label=2;case 2:return n.trys.push([2,3,,5]),(null==(e=JSON.parse(t))?void 0:e.expires_at)&&(e.expires_at=new Date(e.expires_at)),e.expires_at<new Date?[2,null]:[2,e.captcha_token];case 3:return n.sent(),[4,this.config.storage.removeItem(this.tokenSectionName)];case 4:return n.sent(),[2,null];case 5:return[2,null]}})})},t}(),pn=function(){function t(t){if(this.params={},"string"==typeof t)this.parse(t);else if(t&&"object"==typeof t)for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&this.append(e,t[e])}return t.prototype.parse=function(t){var e=this;t.split("&").forEach(function(t){var n=t.split("=").map(decodeURIComponent),r=n[0],o=n[1];e.append(r,o)})},t.prototype.append=function(t,e){this.params[t]?this.params[t]=this.params[t].concat([e]):this.params[t]=[e]},t.prototype.get=function(t){return this.params[t]?this.params[t][0]:null},t.prototype.getAll=function(t){return this.params[t]||[]},t.prototype.delete=function(t){delete this.params[t]},t.prototype.has=function(t){return Object.prototype.hasOwnProperty.call(this.params,t)},t.prototype.set=function(t,e){this.params[t]=[e]},t.prototype.toString=function(){var t=[],e=function(e){Object.prototype.hasOwnProperty.call(n.params,e)&&n.params[e].forEach(function(n){t.push("".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(n)))})},n=this;for(var r in this.params)e(r);return t.join("&")},t}();const vn=pn;var yn,gn=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();!function(t){t.PROVIDER_NOT_ENABLED="PROVIDER_NOT_ENABLED",t.INVALID_CREDENTIALS="INVALID_CREDENTIALS",t.USER_NOT_FOUND="USER_NOT_FOUND",t.USER_STATUS_ABNORMAL="USER_STATUS_ABNORMAL",t.SERVICE_ERROR="SERVICE_ERROR",t.INVALID_PARAMS="INVALID_PARAMS",t.AUTH_METHOD_MISMATCH="AUTH_METHOD_MISMATCH",t.RATE_LIMITED="RATE_LIMITED",t.CAPTCHA_REQUIRED="CAPTCHA_REQUIRED",t.CAPTCHA_INVALID="CAPTCHA_INVALID",t.MFA_REQUIRED="MFA_REQUIRED",t.PRECONDITION_FAILED="PRECONDITION_FAILED",t.VERIFICATION_FAILED="VERIFICATION_FAILED",t.UNKNOWN="UNKNOWN"}(yn||(yn={}));var mn="https://tcb.cloud.tencent.com/dev?envId=#/identity/login-manage",bn="https://docs.cloudbase.net/api-reference/webv3/initialization";function wn(t,e){var n=(null==e?void 0:e.method)||"signIn",r={signInWithPassword:"「用户名密码登录」",signInAnonymously:"「匿名登录」",signInWithOtp:"「短信验证码登录」或「邮箱验证码登录」",signUp:"「短信验证码登录」或「邮箱验证码登录」",signInWithOAuth:"对应的第三方身份源",signInWithIdToken:"对应的第三方身份源",signInWithOpenId:"「微信小程序 OpenID 登录」",signInWithPhoneAuth:"「微信小程序手机号授权登录」",signInWithCustomTicket:"「自定义登录」",getVerification:"「短信验证码登录」或「邮箱验证码登录」",verify:"「短信验证码登录」或「邮箱验证码登录」",verifyOtp:"「短信验证码登录」或「邮箱验证码登录」",resetPasswordForEmail:"「邮箱验证码登录」",reauthenticate:"「短信验证码登录」或「邮箱验证码登录」"}[n]||"对应的登录方式";switch(t){case yn.PROVIDER_NOT_ENABLED:return"[CloudBase Auth] 登录方式未开启\n\n"+" 当前调用的 ".concat(n,"() 所需的登录方式尚未在云开发控制台启用。\n")+" 需要开启的登录方式:".concat(r,"\n")+"\n 请按以下步骤开启:\n"+" 1. 打开云开发控制台:".concat(mn,"\n")+" 2. 选择对应的云开发环境\n 3. 进入「登录授权」页面,在「登录方式」或「身份源列表」中开启所需的登录方式\n\n 各登录方法与所需登录方式的对应关系:\n - signInWithPassword → 「用户名密码登录」\n - signInAnonymously → 「匿名登录」\n - signInWithOtp/signUp → 「短信验证码登录」或「邮箱验证码登录」\n - signInWithOAuth/signInWithIdToken → 对应的第三方身份源\n\n 如使用 CLI/MCP 工具,可通过 auth 工具查询和配置身份源状态。\n"+" 更多帮助请参考文档:".concat(bn);case yn.INVALID_CREDENTIALS:return"[CloudBase Auth] 凭据验证失败\n\n"+" 调用 ".concat(n,"() 时凭据校验未通过。\n")+"\n 请按优先级逐项排查:\n 1. 确认用户名/邮箱/手机号是否拼写正确、格式完整\n 2. 确认密码是否正确(注意大小写、特殊字符、前后空格)\n 3. 确认用户账号确实存在(可通过 auth.isUsernameRegistered() 检查)\n 4. 确认凭据参数来源可靠(环境变量、配置文件中的值是否已正确设置)\n 5. 如使用加密登录(is_encrypt: true),请确认公钥版本正确\n\n 如忘记密码,可通过 auth.resetPasswordForEmail() 重置密码。\n\n 提示:如果是 AI agent / 自动化测试场景,请确认 ENV_ID、USERNAME、PASSWORD\n 等环境变量已正确传入,且对应用户已在目标环境中注册。";case yn.USER_NOT_FOUND:return"[CloudBase Auth] 用户不存在\n\n 请检查以下项目:\n 1. 确认用户名/邮箱/手机号是否正确\n 2. 确认是在正确的云开发环境(envId)下操作\n 3. 如果是新用户,请先通过 auth.signUp() 注册\n"+" 4. 也可在云开发控制台手动创建用户:".concat(mn,"\n")+"\n 提示:不同环境(开发/测试/生产)的用户库是隔离的,请确认 envId 正确。";case yn.USER_STATUS_ABNORMAL:return"[CloudBase Auth] 用户状态异常\n\n 当前用户账号可能处于以下状态之一:\n - 账号已被封禁\n - 账号正在审核中\n - 账号已被锁定(多次密码错误)\n\n"+" 请联系管理员在云开发控制台检查用户状态:".concat(mn);case yn.SERVICE_ERROR:return"[CloudBase Auth] 服务异常\n\n 请检查以下项目:\n 1. 网络连接是否正常\n 2. 云开发环境是否正常运行\n 3. 稍后重试,如持续失败请联系技术支持\n\n 提示:如果是超时错误,请检查网络环境和请求频率。\n 常见服务端错误:smtp 未配置、短信服务未配置、wedaapis 未设置等。";case yn.INVALID_PARAMS:if((null==e?void 0:e.errorCode)===de.MISSING_REQUIRED_PARAM||(null==e?void 0:e.code)===he.MISSING_REQUIRED_PARAM){var o=["verifyOtp","signInWithOtp","signUp"].includes(n)?"\n 若在校验验证码阶段缺参:\n - 独立调用 auth.verifyOtp() 时 messageId 为必填,请补上 params.messageId。\n - 推荐改用发码接口返回的回调(SDK 会自动携带 messageId):\n const { data } = await auth.signInWithOtp({ phone })\n await data.verifyOtp({ token })\n // 或 auth.signUp({ phone }) 返回的 data.verifyOtp\n":"";return"[CloudBase Auth] 缺少必填参数\n\n"+" 调用 auth.".concat(n,"() 时缺少必填参数。\n")+" 这是客户端入参问题,不是控制台通道配置问题。\n\n 修复方式:\n"+" 1. 查看 error.message 中的参数路径,补上缺失字段。\n".concat(o,"\n 参考 API 文档确认各参数的格式和约束:").concat(bn)}return"[CloudBase Auth] 参数错误\n\n 请检查传入的参数是否符合要求:\n - 不能同时输入手机号和邮箱\n - 手机号格式需正确(如 +86 开头)\n - 必须提供手机号或邮箱\n\n"+" 参考 API 文档确认各参数的格式和约束:".concat(bn);case yn.AUTH_METHOD_MISMATCH:return"[CloudBase Auth] 登录方式不匹配\n\n"+" 调用 ".concat(n,"() 时遇到错误,可能原因:\n")+" - 匿名登录失败后尝试了用户名密码登录,但凭据不正确或用户不存在\n - 应使用匿名登录但传入了密码参数\n - 应使用密码登录但未传入正确的凭据\n\n 建议:\n 1. 明确当前场景需要的登录方式:\n - 无需用户注册 → auth.signInAnonymously()\n - 有用户名和密码 → auth.signInWithPassword({ username, password })\n - 第三方平台 → auth.signInWithOAuth({ provider })\n 2. 不要在同一流程中混合使用不同的登录方式\n 3. 每种登录方式需要在控制台开启对应的身份源\n"+" 4. 控制台地址:".concat(mn);case yn.RATE_LIMITED:return"[CloudBase Auth] 发送频率受限\n\n 验证码发送过于频繁,已触发频率限制。\n\n 限制规则:\n - 手机号:每分钟最多 1 条,每天有上限\n - 邮箱:每分钟有上限,每天有上限(默认 50 条)\n\n 建议:\n 1. 检查 error.retryAfter 获取建议等待时间\n 2. 在 UI 中显示倒计时,防止用户重复点击\n 3. 如业务需要更高频率,请联系技术支持调整限额";case yn.CAPTCHA_REQUIRED:return"[CloudBase Auth] 需要滑块验证码\n\n 当前操作触发了风控策略,需要完成滑块验证。\n\n 处理方式:\n 1. 调用滑块验证码 SDK 展示验证组件\n 2. 用户完成验证后,将 captcha_token 附带到请求中重新发送\n 3. 可通过 getVerification 的 options.withCaptcha 参数自动携带验证码";case yn.CAPTCHA_INVALID:return"[CloudBase Auth] 滑块验证码校验失败\n\n 提交的验证码 token 校验未通过(可能已过期或 client_id 不匹配)。\n\n 处理方式:\n 1. 刷新滑块验证码,让用户重新验证\n 2. 确认 captcha 组件初始化的 client_id 与认证配置一致";case yn.MFA_REQUIRED:return"[CloudBase Auth] 需要 MFA 验证\n\n 当前操作要求用户绑定手机号进行多因素认证 (MFA)。\n\n 处理方式:\n 1. 引导用户进入手机号绑定流程\n 2. 绑定完成后重新执行原操作\n 3. error 中可能包含 MFA 详情信息";case yn.PRECONDITION_FAILED:return"[CloudBase Auth] 前置条件不满足\n\n 当前操作的前置条件不满足,常见原因:\n - 该手机号/邮箱已被其他账号绑定\n - 目标用户不存在或已存在(与 target 参数冲突)\n - 当前邮箱/手机号未注册用户\n\n 请根据 error.message 中的具体描述处理。";case yn.VERIFICATION_FAILED:return'[CloudBase Auth] 验证码校验失败\n\n 验证码验证未通过,常见原因:\n - 验证码已过期(通常有效期为几分钟)\n - 验证码输入不正确\n - verification_id 无效或已被使用\n - 验证码不属于当前项目(project id does not match)\n\n 处理方式:\n 1. 提示用户"验证码已过期或不正确,请重新获取"\n 2. 调用 getVerification() 重新发送验证码\n 3. 确保 verification_id 与最新发送的验证码对应\n\n 注意:每次重新发送验证码后,之前的 verification_id 即失效。';default:return"[CloudBase Auth] 操作失败\n\n 如果问题持续存在,建议:\n"+" 1. 检查云开发控制台的认证配置:".concat(mn,"\n")+" 2. 到官方问答社区提问:https://cnb.cool/tencent/cloud/cloudbase/community/-/issues\n"+" 3. 查阅文档:".concat(bn)}}function _n(t){return t&&{signInWithPassword:"当前使用「用户名密码登录」,需确保:\n ✓ 控制台已开启「用户名密码登录」\n ✓ 用户已注册且凭据正确\n 如果不需要用户系统,建议改用 auth.signInAnonymously()",signInAnonymously:"当前使用「匿名登录」,需确保:\n ✓ 控制台已开启「匿名登录」\n 注意:匿名用户无需用户名密码,适用于快速体验或临时访问场景",signInWithOtp:"当前使用「OTP 验证码登录」,需确保:\n ✓ 控制台已开启「短信验证码登录」或「邮箱验证码登录」",signInWithOAuth:"当前使用「第三方 OAuth 登录」,需确保:\n ✓ 控制台已配置并开启对应的第三方身份源"}[t]||""}var En=function(t){function e(e,n){var r=this,o=function(t){return"object"==typeof t&&null!==t&&"__isAuthError"in t}(e);return(r=t.call(this,o?e.message:e.error_description||e.message)||this).__isAuthError=!0,r.name="AuthError",o?(r.status=e.status,r.code=e.code,r.errorCode=e.errorCode,r.requestId=e.requestId,r.category=e.category,r.retryAfter=e.retryAfter,r.helpMessage=wn(r.category,{method:null==n?void 0:n.method,errorCode:r.errorCode,code:r.code}),r.loginMethodHint=_n(null==n?void 0:n.method),r):(r.status=e.error,r.code=String(e.error||e.error_code||"unknown").toLowerCase(),r.errorCode="number"==typeof e.error_code?e.error_code:"string"==typeof e.error_code&&parseInt(e.error_code,10)||void 0,r.requestId=e.requestId,r.category=function(t,e,n){if(!t&&!e&&!n)return yn.UNKNOWN;try{var r=(t||"").toLowerCase(),o="string"==typeof n?parseInt(n,10):n;return o===de.MISSING_REQUIRED_PARAM||e===he.MISSING_REQUIRED_PARAM?yn.INVALID_PARAMS:o===de.CAPTCHA_REQUIRED||e===he.CAPTCHA_REQUIRED?yn.CAPTCHA_REQUIRED:o===de.CAPTCHA_INVALID||e===he.CAPTCHA_INVALID?yn.CAPTCHA_INVALID:o===de.MFA_PHONE_REQUIRED||e===he.MFA_PHONE_REQUIRED?yn.MFA_REQUIRED:o===de.LOGIN_TYPE_DISABLED||e===he.LOGIN_TYPE_DISABLED?yn.PROVIDER_NOT_ENABLED:o===de.RESOURCE_EXHAUSTED||e===he.RESOURCE_EXHAUSTED?yn.RATE_LIMITED:o===de.INTERNAL||o===de.UNAVAILABLE||o===de.UNIMPLEMENTED||o===de.ABORTED?yn.SERVICE_ERROR:o===de.NOT_FOUND?yn.USER_NOT_FOUND:o===de.UNAUTHENTICATED?yn.INVALID_CREDENTIALS:o===de.INVALID_ARGUMENT&&(r.includes("验证码")||r.includes("verification")||r.includes("verification_code")||r.includes("verification_id")||r.includes("does not match")||r.includes("token expired")||r.includes("token error")||r.includes("过期"))?yn.VERIFICATION_FAILED:e===he.PROVIDER_NOT_ENABLED||e===he.LOGIN_METHOD_DISABLED||r.includes("身份源")||r.includes("开启")||r.includes("identity provider")||r.includes("provider not enabled")||r.includes("login method")||r.includes("登录方式")||r.includes("not enabled")||r.includes("未开启")||r.includes("未启用")||r.includes("请联系开发者")||r.includes("anonymous login is not enabled")||r.includes("匿名登录未开启")?yn.PROVIDER_NOT_ENABLED:e===he.FAILED_PRECONDITION||o===de.FAILED_PRECONDITION&&!r.includes("请联系开发者")?r.includes("不存在")||r.includes("not found")||r.includes("未注册")?yn.USER_NOT_FOUND:yn.PRECONDITION_FAILED:e===he.INVALID_PASSWORD||e===he.INVALID_GRANT||e===he.INVALID_VERIFICATION_CODE||e===he.INVALID_USERNAME_OR_PASSWORD||e===he.INVALID_CREDENTIALS||e===he.WRONG_PASSWORD||e===he.UNAUTHENTICATED||e===he.INVALID_TWO_FACTOR||e===he.INVALID_TWO_FACTOR_RECOVERY||e===he.PASSWORD_NOT_SET||r.includes("密码不正确")||r.includes("password")||r.includes("invalid_password")||r.includes("凭据")||r.includes("credentials")||r.includes("验证码")||r.includes("verification")||r.includes("invalid_verification_code")||r.includes("invalid_username_or_password")||r.includes("username or password")||r.includes("用户名或密码")||r.includes("wrong password")||r.includes("incorrect password")?yn.INVALID_CREDENTIALS:e===he.NOT_FOUND||e===he.USER_NOT_FOUND||r.includes("用户不存在")||r.includes("not found")||r.includes("user not found")||r.includes("no such user")||r.includes("user does not exist")?yn.USER_NOT_FOUND:e===he.USER_BLOCKED||e===he.USER_PENDING||e===he.UNDER_REVIEW||e===he.INVALID_STATUS||r.includes("被封禁")||r.includes("blocked")||r.includes("pending")||r.includes("审核")||r.includes("review")||r.includes("locked")||r.includes("已锁定")?yn.USER_STATUS_ABNORMAL:e===he.SERVER_ERROR||e===he.UNAVAILABLE||e===he.TEMPORARILY_UNAVAILABLE||e===he.INTERNAL||e===he.UNREACHABLE||e===he.DEADLINE_EXCEEDED||e===he.DATA_LOSS||e===he.ABORTED||r.includes("network")||r.includes("timeout")||r.includes("timed out")||r.includes("超时")||r.includes("smtp is not set")||r.includes("sms sender does not config")?yn.SERVICE_ERROR:e===he.INVALID_ARGUMENT||e===he.INVALID_REQUEST||e===he.INVALID_SCOPE||e===he.INVALID_REQUEST_URI||e===he.INVALID_REQUEST_OBJECT||o===de.INVALID_ARGUMENT?yn.INVALID_PARAMS:e===he.PERMISSION_DENIED||e===he.ACCESS_DENIED||e===he.UNAUTHORIZED_CLIENT?yn.PROVIDER_NOT_ENABLED:yn.UNKNOWN}catch(t){return e}}(r.message,r.status,r.errorCode),r.helpMessage=wn(r.category,{method:null==n?void 0:n.method,errorCode:r.errorCode,code:r.code}),r.loginMethodHint=_n(null==n?void 0:n.method),r.category===yn.RATE_LIMITED&&(r.retryAfter=e.retry_after||e.retryAfter||void 0),r)}return gn(e,t),e.prototype.toJSON=function(){return{name:this.name,message:this.message,code:this.code,errorCode:this.errorCode,status:this.status,requestId:this.requestId,category:this.category,retryAfter:this.retryAfter}},e}(Error),In=function(){return In=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},In.apply(this,arguments)},Sn=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},On=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Tn(t,e){var n;return Sn(this,void 0,void 0,function(){var r,o=this;return On(this,function(i){r=function(){return Sn(o,void 0,void 0,function(){return On(this,function(t){switch(t.label){case 0:return t.trys.push([0,1,,6]),[2,l(3171)];case 1:t.sent(),t.label=2;case 2:return t.trys.push([2,4,,5]),[4,Promise.resolve().then(l.bind(l,3171))];case 3:return[2,t.sent()];case 4:return t.sent(),[2];case 5:return[3,6];case 6:return[2]}})})};try{if(((null===(n=null==e?void 0:e.root)||void 0===n?void 0:n.globalThis)||globalThis).IS_MP_BUILD)return[2];if(t)return[2,r()]}catch(e){if(t)return[2,r()]}return[2]})})}var An=function(){function t(t){var e=t.request,n=t.credentialsClient;if(!n){var r={apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,storage:t.storage,env:t.env,baseRequest:t.baseRequest,anonymousSignInFunc:t.anonymousSignInFunc,wxCloud:t.wxCloud,onCredentialsError:t.onCredentialsError,headers:t.headers||{},i18n:t.i18n,debug:t.debug};n=new Xe(r)}if(!e){var o=n.request.bind(n),i=new fn(In({env:t.env,clientId:t.clientId,request:o,storage:t.storage,adapter:t.adapter,oauthInstance:this},t.captchaOptions));e=i.request.bind(i)}this.config={env:t.env,apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,request:e,credentialsClient:n,storage:t.storage||Ye,adapter:t.adapter}}return t.parseParamsToSearch=function(t){return Object.keys(t).forEach(function(e){t[e]||delete t[e]}),new vn(t).toString()},t.prototype.getParamsByVersion=function(t,e){var n,r=(0,Ce.I)(t),o=(null===(n={v2:ue}[null==r?void 0:r.version])||void 0===n?void 0:n[e])||ce[e];return r&&delete r.version,{params:r,url:o}},t.prototype.signIn=function(t){return Sn(this,void 0,Promise,function(){var e,n,r,o;return On(this,function(i){switch(i.label){case 0:return e=t.version||"v1",(n=this.getParamsByVersion(t,"AUTH_SIGN_IN_URL")).params.query&&delete n.params.query,[4,this.getEncryptParams(n.params)];case 1:return r=i.sent(),[4,this.config.request(n.url,{method:"POST",body:r})];case 2:return o=i.sent(),[4,this.config.credentialsClient.setCredentials(In(In({},o),{version:e}))];case 3:return i.sent(),[2,Promise.resolve(o)]}})})},t.prototype.signInAnonymously=function(t,e){return void 0===t&&(t={}),void 0===e&&(e=!1),Sn(this,void 0,Promise,function(){var n;return On(this,function(r){switch(r.label){case 0:return[4,this.config.request(ce.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:t,useWxCloud:e})];case 1:return n=r.sent(),[4,this.config.credentialsClient.setCredentials(n)];case 2:return r.sent(),[2,Promise.resolve(n)]}})})},t.prototype.signUp=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){switch(n.label){case 0:return[4,this.config.request(ce.AUTH_SIGN_UP_URL,{method:"POST",body:t})];case 1:return e=n.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return n.sent(),[2,Promise.resolve(e)]}})})},t.prototype.signOut=function(t){return Sn(this,void 0,Promise,function(){var e,n,r,o;return On(this,function(i){switch(i.label){case 0:if(e={},!t)return[3,6];i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.config.request(ce.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:t})];case 2:return e=i.sent(),[3,4];case 3:return(n=i.sent()).error!==he.UNAUTHENTICATED&&console.log("sign_out_error",n),[3,4];case 4:return[4,this.config.credentialsClient.setCredentials()];case 5:return i.sent(),[2,e];case 6:return[4,this.config.credentialsClient.getAccessToken()];case 7:return r=i.sent(),[4,this.config.request(ce.AUTH_REVOKE_URL,{method:"POST",body:{token:r}})];case 8:return o=i.sent(),[4,this.config.credentialsClient.setCredentials()];case 9:return i.sent(),[2,Promise.resolve(o)]}})})},t.prototype.revokeAllDevices=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){switch(t.label){case 0:return[4,this.config.request(ce.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})];case 1:return t.sent(),[2]}})})},t.prototype.revokeDevice=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){switch(e.label){case 0:return[4,this.config.request(ce.AUTHORIZED_DEVICES_DELETE_URL+t.device_id,{method:"DELETE",withCredentials:!0})];case 1:return e.sent(),[2]}})})},t.prototype.getVerification=function(t,e){return Sn(this,void 0,Promise,function(){var n,r;return On(this,function(o){switch(o.label){case 0:return n=!1,"CUR_USER"!==t.target?[3,1]:(n=!0,[3,3]);case 1:return[4,this.hasLoginState()];case 2:o.sent()&&(n=!0),o.label=3;case 3:return(r=(0,Ce.I)(t)).phone_number&&!/^\+\d{1,3}\s+\d+/.test(r.phone_number)&&(r.phone_number="+86 ".concat(r.phone_number)),[2,this.config.request(ce.VERIFICATION_URL,{method:"POST",body:r,withCaptcha:(null==e?void 0:e.withCaptcha)||!1,withCredentials:n})]}})})},t.prototype.verify=function(t){return Sn(this,void 0,Promise,function(){var e,n;return On(this,function(r){switch(r.label){case 0:return e=this.getParamsByVersion(t,"VERIFY_URL"),[4,this.config.request(e.url,{method:"POST",body:e.params})];case 1:return n=r.sent(),"v2"!==(null==t?void 0:t.version)?[3,3]:[4,this.config.credentialsClient.setCredentials(In(In({},n),{version:"v2"}))];case 2:r.sent(),r.label=3;case 3:return[2,n]}})})},t.prototype.genProviderRedirectUri=function(e){return Sn(this,void 0,Promise,function(){var n,r,o,i,s;return On(this,function(a){return n=e.provider_redirect_uri,r=e.other_params,o=void 0===r?{}:r,i=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(e,["provider_redirect_uri","other_params"]),n&&!i.redirect_uri&&(i.redirect_uri=n),s="".concat(ce.PROVIDER_URI_URL,"?").concat(t.parseParamsToSearch(i)),Object.keys(o).forEach(function(t){var e=o[t];("sign_out_uri"!==t||(null==e?void 0:e.length)>0)&&(s+="&other_params[".concat(t,"]=").concat(encodeURIComponent(e)))}),[2,this.config.request(s,{method:"GET"})]})})},t.prototype.grantProviderToken=function(t,e){return void 0===e&&(e=!1),Sn(this,void 0,Promise,function(){return On(this,function(n){return[2,this.config.request(ce.PROVIDER_TOKEN_URL,{method:"POST",body:t,useWxCloud:e})]})})},t.prototype.patchProviderToken=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.PROVIDER_TOKEN_URL,{method:"PATCH",body:t})]})})},t.prototype.signInWithProvider=function(t,e){return void 0===e&&(e=!1),Sn(this,void 0,Promise,function(){var n,r;return On(this,function(o){switch(o.label){case 0:return n=this.getParamsByVersion(t,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),[4,this.config.request(n.url,{method:"POST",body:n.params,useWxCloud:e})];case 1:return r=o.sent(),[4,this.config.credentialsClient.setCredentials(In(In({},r),{version:(null==t?void 0:t.version)||"v1"}))];case 2:return o.sent(),[2,Promise.resolve(r)]}})})},t.prototype.toBindIdentity=function(t){var e,n;return Sn(this,void 0,void 0,function(){var r,o,i,s;return On(this,function(a){switch(a.label){case 0:return(o=t.credentials)?[3,2]:[4,this.config.credentialsClient.localCredentials.getCredentials()];case 1:o=a.sent(),a.label=2;case 2:r=o,a.label=3;case 3:return a.trys.push([3,5,,6]),[4,this.bindWithProvider({provider_token:t.provider_token},r)];case 4:return a.sent(),i={data:{type:Ae,provider:t.provider},error:null},[3,6];case 5:return s=a.sent(),i={data:{type:Ae},error:new En(s)},[3,6];case 6:return t.fireEvent&&(null===(n=null===(e=this.config.eventBus)||void 0===e?void 0:e.fire)||void 0===n||n.call(e,Oe,{event:Ie,info:i})),[2,i]}})})},t.prototype.getInitialSession=function(){return Sn(this,void 0,Promise,function(){var t,e,n,r,o,i,s,a,c,u,l,h,d,f,p;return On(this,function(v){switch(v.label){case 0:t={},v.label=1;case 1:if(v.trys.push([1,12,,13]),"undefined"==typeof window||"undefined"==typeof document)return[2,{data:null,error:null}];if(e=new URLSearchParams(null===location||void 0===location?void 0:location.search),n=e.get("code"),r=e.get("state"),!n||!r)return[2,{data:null,error:null}];o=null;try{o=JSON.parse(sessionStorage.getItem(r)||"null")}catch(t){}return t={type:null==o?void 0:o.type},i=e.get("error"),s=e.get("error_description"),i||s?[2,{data:t,error:new En({message:s||i||"Unknown error from OAuth provider"})}]:(a=(null==o?void 0:o.provider)||e.get("provider"))?(c=location.origin+location.pathname,[4,this.grantProviderToken({provider_id:a,provider_redirect_uri:c,provider_code:n})]):[2,{data:t,error:new En({message:"Provider is required for OAuth verification"})}];case 2:return u=v.sent().provider_token,l=void 0,h=null,d=void 0,o.type!==Ae?[3,5]:[4,this.config.credentialsClient.localCredentials.getCredentials()];case 3:return l=v.sent(),[4,this.toBindIdentity({provider:a,provider_token:u,credentials:l})];case 4:return d=v.sent(),[3,11];case 5:return o.type!==Te?[3,11]:(d=this.getParamsByVersion({provider:a},"AUTH_SIGN_IN_WITH_PROVIDER_URL"),[4,this.config.request(d.url,{method:"POST",body:{provider_token:u}})]);case 6:l=v.sent(),v.label=7;case 7:return v.trys.push([7,9,,10]),[4,this.getUserInfo({credentials:l})];case 8:return h=v.sent(),[3,10];case 9:return f=v.sent(),console.error("get user info error",f),[3,10];case 10:d={data:In(In({},t),{session:l,user:h}),error:null},v.label=11;case 11:e.delete("code"),e.delete("state"),e.delete("provider"),this.restoreUrlState(void 0===(null==o?void 0:o.search)?"?".concat(e.toString()):o.search,(null==o?void 0:o.hash)||location.hash);try{sessionStorage.removeItem(r)}catch(t){}return[2,d];case 12:return p=v.sent(),[2,{data:t,error:new En(p)}];case 13:return[2]}})})},t.prototype.signInCustom=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){switch(n.label){case 0:return[4,this.config.request(ce.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:t})];case 1:return e=n.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return n.sent(),[2,Promise.resolve(e)]}})})},t.prototype.signInWithWechat=function(t){return void 0===t&&(t={}),Sn(this,void 0,Promise,function(){var e;return On(this,function(n){switch(n.label){case 0:return[4,this.config.request(ce.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:t})];case 1:return e=n.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return n.sent(),[2,Promise.resolve(e)]}})})},t.prototype.bindWithProvider=function(t,e){return Sn(this,void 0,Promise,function(){return On(this,function(n){return[2,this.config.request(ce.PROVIDER_BIND_URL,{method:"POST",body:t,withCredentials:!0,getCredentials:e?function(){return e}:void 0})]})})},t.prototype.getUserProfile=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.getUserInfo(t)]})})},t.prototype.getUserInfo=function(t){var e,n,r;return void 0===t&&(t={}),Sn(this,void 0,Promise,function(){var o,i,s,a,c;return On(this,function(u){switch(u.label){case 0:return o=this.getParamsByVersion(t,"USER_ME_URL"),(null===(e=o.params)||void 0===e?void 0:e.query)&&(i=new vn(o.params.query),o.url+="?".concat(i.toString())),[4,this.config.request(o.url,{method:"GET",withCredentials:!0,getCredentials:t.credentials?function(){return t.credentials}:void 0})];case 1:if((s=u.sent()).sub&&(s.uid=s.sub),null===(n=s.providers)||void 0===n?void 0:n.length)try{"undefined"!=typeof wx&&wx.getAccountInfoSync&&(a=null===(r=wx.getAccountInfoSync().miniProgram)||void 0===r?void 0:r.appId,(null==(c=s.providers.find(function(t){return t.id===a}))?void 0:c.provider_user_id)&&(s.open_id=c.provider_user_id))}catch(t){}return[2,s]}})})},t.prototype.getWedaUserInfo=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){switch(t.label){case 0:return[4,this.config.request(ce.WEDA_USER_URL,{method:"GET",withCredentials:!0})];case 1:return[2,t.sent()]}})})},t.prototype.deleteMe=function(e){return Sn(this,void 0,Promise,function(){var n,r;return On(this,function(o){return n=this.getParamsByVersion(e,"USER_ME_URL"),r="".concat(n.url,"?").concat(t.parseParamsToSearch(n.params)),[2,this.config.request(r,{method:"DELETE",withCredentials:!0})]})})},t.prototype.hasLoginState=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.config.credentialsClient.getAccessToken()];case 1:return t.sent(),[2,!0];case 2:return t.sent(),[2,!1];case 3:return[2]}})})},t.prototype.hasLoginStateSync=function(){return this.config.credentialsClient.getCredentialsSync()},t.prototype.getLoginState=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.credentialsClient.getCredentialsAsync()]})})},t.prototype.transByProvider=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:t,withCredentials:!0})]})})},t.prototype.grantToken=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){return e=this.getParamsByVersion(t,"AUTH_TOKEN_URL"),[2,this.config.request(e.url,{method:"POST",body:e.params})]})})},t.prototype.getProviders=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.request(ce.PROVIDER_LIST,{method:"GET",withCredentials:!0})]})})},t.prototype.unbindProvider=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.PROVIDER_UNBIND_URL,"/").concat(t.provider_id),{method:"DELETE",withCredentials:!0})]})})},t.prototype.checkPassword=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.editContact=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:t})]})})},t.prototype.setPassword=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:t})]})})},t.prototype.updatePasswordByOld=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){switch(n.label){case 0:return[4,this.sudo({password:t.old_password})];case 1:return e=n.sent(),[2,this.setPassword({sudo_token:e.sudo_token,new_password:t.new_password})]}})})},t.prototype.sudo=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.SUDO_URL),{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.sendVerificationCodeToCurrentUser=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return t.target="CUR_USER",[2,this.config.request(ce.VERIFICATION_URL,{method:"POST",body:t,withCredentials:!0,withCaptcha:!0})]})})},t.prototype.changeBoundProvider=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.PROVIDER_LIST,"/").concat(t.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:t.trans_token},withCredentials:!0})]})})},t.prototype.setUserProfile=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.USER_PRIFILE_URL,{method:"PATCH",body:t,withCredentials:!0})]})})},t.prototype.updateUserBasicInfo=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.queryUserProfile=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){return e=new vn(t),[2,this.config.request("".concat(ce.USER_QUERY_URL,"?").concat(e.toString()),{method:"GET",withCredentials:!0})]})})},t.prototype.setCustomSignFunc=function(t){this.getCustomSignTicketFn=t},t.prototype.signInWithCustomTicket=function(){return Sn(this,void 0,Promise,function(){var t,e;return On(this,function(n){switch(n.label){case 0:return(t=this.getCustomSignTicketFn)?[4,t()]:[2,Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"})];case 1:return e=n.sent(),[2,this.signInCustom({provider_id:"custom",ticket:e})]}})})},t.prototype.resetPassword=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.AUTH_RESET_PASSWORD,{method:"POST",body:t})]})})},t.prototype.authorize=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.authorizeDevice=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.deviceAuthorize=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.AUTH_GET_DEVICE_CODE,{method:"POST",body:t})]})})},t.prototype.authorizeInfo=function(e){return Sn(this,void 0,Promise,function(){var n,r,o;return On(this,function(i){switch(i.label){case 0:return n="".concat(ce.AUTHORIZE_INFO_URL,"?").concat(t.parseParamsToSearch(e)),r=!0,o=!1,[4,this.hasLoginState()];case 1:return i.sent()&&(o=!0,r=!1),[2,this.config.request(n,{method:"GET",withBasicAuth:r,withCredentials:o})]}})})},t.prototype.checkUsername=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.CHECK_USERNAME,{method:"GET",body:t,withCredentials:!0})]})})},t.prototype.checkIfUserExist=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){return e=new vn(t),[2,this.config.request("".concat(ce.CHECK_IF_USER_EXIST,"?").concat(e.toString()),{method:"GET"})]})})},t.prototype.loginScope=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.credentialsClient.getScope()]})})},t.prototype.loginGroups=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.credentialsClient.getGroups()]})})},t.prototype.refreshTokenForce=function(t){return Sn(this,void 0,void 0,function(){var e;return On(this,function(n){switch(n.label){case 0:return[4,this.config.credentialsClient.getCredentials()];case 1:return e=n.sent(),[4,this.config.credentialsClient.refreshToken(In(In({},e),{version:(null==t?void 0:t.version)||"v1"}))];case 2:return[2,n.sent()]}})})},t.prototype.getCredentials=function(){return Sn(this,void 0,void 0,function(){return On(this,function(t){return[2,this.config.credentialsClient.getCredentials()]})})},t.prototype.getPublicKey=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.request(ue.AUTH_PUBLIC_KEY,{method:"POST",body:{}})]})})},t.prototype.getEncryptParams=function(t){return Sn(this,void 0,Promise,function(){var e,n,r,o,i,s;return On(this,function(a){switch(a.label){case 0:return e=t.isEncrypt,delete t.isEncrypt,n=(0,Ce.I)(t),[4,Tn(e,this.config.adapter)];case 1:if(!(r=a.sent()))return[2,t];o="",i="",a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.getPublicKey()];case 3:if(s=a.sent(),o=s.public_key,i=s.public_key_thumbprint,!o||!i)throw s;return[3,5];case 4:throw a.sent();case 5:return[2,{params:r.getEncryptInfo({publicKey:o,payload:n}),public_key_thumbprint:i}]}})})},t.prototype.getProviderSubType=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.request(ce.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})]})})},t.prototype.verifyCaptchaData=function(t){var e=t.token,n=t.key;return Sn(this,void 0,void 0,function(){return On(this,function(t){return[2,this.config.request(ce.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:e,key:n},withCredentials:!1})]})})},t.prototype.createCaptchaData=function(t){var e=t.state,n=t.redirect_uri,r=void 0===n?void 0:n;return Sn(this,void 0,void 0,function(){return On(this,function(t){return[2,this.config.request(ce.CAPTCHA_DATA_URL,{method:"POST",body:{state:e,redirect_uri:r},withCredentials:!1})]})})},t.prototype.getMiniProgramCode=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.GET_MINIPROGRAM_QRCODE,{method:"POST",body:t})]})})},t.prototype.getMiniProgramQrCodeStatus=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:t})]})})},t.prototype.getUserBehaviorLog=function(t){return Sn(this,void 0,Promise,function(){var e,n;return On(this,function(r){return e={LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"},n="".concat(ce.GET_USER_BEHAVIOR_LOG,"?").concat(e[t.type],"&limit=").concat(t.limit).concat(t.page_token?"&page_token=".concat(t.page_token):""),[2,this.config.request(n,{method:"GET",withCredentials:!0})]})})},t.prototype.modifyPassword=function(t){return Sn(this,void 0,Promise,function(){var e,n,r,o,i,s;return On(this,function(a){switch(a.label){case 0:return e="",n="",[4,Tn(!0,this.config.adapter)];case 1:if(!(r=a.sent()))throw new Error("do not support encrypt, a encrypt util required.");a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.getPublicKey()];case 3:if(o=a.sent(),e=o.public_key,n=o.public_key_thumbprint,!e||!n)throw o;return[3,5];case 4:throw a.sent();case 5:return i=t.password?r.getEncryptInfo({publicKey:e,payload:t.password}):"",s=r.getEncryptInfo({publicKey:e,payload:t.new_password}),[2,this.config.request(ce.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:t.user_id,encrypt_password:i,encrypt_new_password:s,public_key_thumbprint:n}})]}})})},t.prototype.modifyPasswordWithoutLogin=function(t){return Sn(this,void 0,Promise,function(){var e,n,r,o,i,s;return On(this,function(a){switch(a.label){case 0:return e="",n="",[4,Tn(!0,this.config.adapter)];case 1:if(!(r=a.sent()))throw new Error("do not support encrypt, a encrypt util required.");a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.getPublicKey()];case 3:if(o=a.sent(),e=o.public_key,n=o.public_key_thumbprint,!e||!n)throw o;return[3,5];case 4:throw a.sent();case 5:return i=t.password?r.getEncryptInfo({publicKey:e,payload:t.password}):"",s=r.getEncryptInfo({publicKey:e,payload:t.new_password}),[2,this.config.request(ue.AUTH_RESET_PASSWORD,{method:"POST",body:{username:t.username,password:i,new_password:s,public_key_thumbprint:n}})]}})})},t.prototype.restoreUrlState=function(t,e){if(void 0!==t)try{var n=new URL(window.location.href);n.search=t,n.hash=e||"",window.history.replaceState(null,"",n.toString()),window.location.replace(n.toString())}catch(t){}},t}(),Pn=function(){return Pn=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Pn.apply(this,arguments)},Rn=function(){function t(t){var e=t.apiOrigin,n=t.getApiOrigin,r=t.apiPath,o=void 0===r?pe:r,i=t.clientId,s=t.env,a=t.storage,c=t.request,u=t.baseRequest,l=t.anonymousSignInFunc,h=t.wxCloud,d=t.adapter,f=t.onCredentialsError,p=t.headers,v=t.i18n,y=t.useWxCloud,g=t.eventBus,m=t.detectSessionInUrl,b=t.debug;if(this.detectSessionInUrl=null!=m&&m,this.oauth2client=new Xe({apiOrigin:e,getApiOrigin:n,apiPath:o,clientId:i,env:s,storage:a,baseRequest:u||c,anonymousSignInFunc:l,wxCloud:h,onCredentialsError:f,headers:p||{},i18n:v,useWxCloud:y,eventBus:g,debug:b}),this.authApi=new An(Pn(Pn({credentialsClient:this.oauth2client},t),{request:c?this.oauth2client.request.bind(this.oauth2client):void 0,adapter:d})),m)this.oauth2client.setGetInitialSession(this.authApi.getInitialSession.bind(this.authApi));else try{var w=new URL(window.location.href),_=w.searchParams.get("code"),E=w.searchParams.get("state"),I=JSON.parse(sessionStorage.getItem(E)||"null");_&&E&&(null==I?void 0:I.hash)&&(w.hash=I.hash,window.history.replaceState(null,"",w.toString()),window.location.replace(w.toString()))}catch(t){}}return t.prototype.initializeSession=function(t){this.detectSessionInUrl?(this.oauth2client.setOnInitialSessionObtained(t),this.oauth2client.initialize()):this.oauth2client.initialize(Promise.resolve({error:null}))},t}(),Cn=l(794),kn=l(141),Nn=l(6197),xn=l(8182),Un=function(){return Un=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Un.apply(this,arguments)},Ln=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Dn=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},jn=function(){function t(t){var e,n;try{this.localStorage=(null==t?void 0:t.localStorage)||((null===(n=null===(e=null==t?void 0:t.adapter)||void 0===e?void 0:e.root)||void 0===n?void 0:n.globalThis)||globalThis).localStorage}catch(e){this.localStorage=(null==t?void 0:t.localStorage)||{}}}return t.prototype.getItem=function(t){return Ln(this,void 0,Promise,function(){return Dn(this,function(e){return[2,this.localStorage.getItem(t)]})})},t.prototype.removeItem=function(t){return Ln(this,void 0,void 0,function(){return Dn(this,function(e){return this.localStorage.removeItem(t),[2]})})},t.prototype.setItem=function(t,e){return Ln(this,void 0,Promise,function(){return Dn(this,function(n){return this.localStorage.setItem(t,e),[2]})})},t.prototype.getItemSync=function(t){return this.localStorage.getItem(t)},t.prototype.setItemSync=function(t,e){this.localStorage.setItem(t,e)},t.prototype.removeItemSync=function(t){this.localStorage.removeItem(t)},t}(),qn=/^[^:]+:\/\/[^/]+(\/[^?#]+)/,Mn=function(t,e){var n,r,o,i,s=null===(n=null==e?void 0:e.headers)||void 0===n?void 0:n["x-request-id"];return t||(t={}),((null==t?void 0:t.code)||(null===(r=null==t?void 0:t.data)||void 0===r?void 0:r.error_code))&&(t={error:t.code||t.data.error,error_description:t.data.error_description||t.message||t.code||t.data.error_code,request_id:t.requestId,error_code:null===(o=t.data)||void 0===o?void 0:o.error_code}),(null==t?void 0:t.request_id)||(t.request_id=t.request_id||s),(null==t?void 0:t.error)?(t.error_uri=(i=null==e?void 0:e.url,qn.test(i)?RegExp.$1:i),t):(null==t?void 0:t.data)||{}},Bn=function(t){return t.adapter&&"default"!==t.adapter.type?function(t,e){var n=Un({},t);try{if(!(null==t?void 0:t.storage)&&(null==e?void 0:e.localStorage)&&(n.storage=new jn({localStorage:e.localStorage,adapter:e})),!t.captchaOptions&&(null==e?void 0:e.captchaOptions)&&(n.captchaOptions=e.captchaOptions),!t.baseRequest&&!t.request&&(null==e?void 0:e.reqClass)){var r={timeout:1e4,restrictedMethods:["get","post","upload","download","request"],auth:t.auth},o=new e.reqClass(r);n.baseRequest=function(t,e){var n,r,i,s,a;return Ln(this,void 0,void 0,function(){var c,u,l,h;return Dn(this,function(d){switch(d.label){case 0:if(c={},u=(null===(n=e.method)||void 0===n?void 0:n.toLocaleLowerCase())||"post","function"!=typeof(l=null===(i=null===(r=null==o?void 0:o[u])||void 0===r?void 0:r.bind)||void 0===i?void 0:i.call(r,o)))throw new Error("invalid 【".concat(u,"】 request method"));d.label=1;case 1:return d.trys.push([1,3,,4]),(null===(s=e.headers)||void 0===s?void 0:s["content-type"])&&!(null===(a=e.headers)||void 0===a?void 0:a["content-type"].includes("application/json"))||["string","undefined"].includes(typeof e.body)||(e.data=e.data||e.body,e.body=JSON.stringify(e.body)),[4,l(Un({url:t},e))];case 2:return c=d.sent(),c=Mn(c,Un(Un({},e),{url:t})),[3,4];case 3:throw h=d.sent(),c=Un(Un({},null==h?void 0:h.data),h);case 4:if(null==c?void 0:c.error)throw c;return[2,c]}})})}}}catch(t){console.error("user adapter generate fail:",t)}return n}(t,t.adapter):function(t,e){var n=Un({},t),r={};if((null==e?void 0:e.captchaOptions)&&(n.captchaOptions=e.captchaOptions),!ut.default.isMatch()||t.storage&&t.baseRequest)return n;try{var o=ut.default.genAdapter({}),i=o.localStorage,s=o.reqClass;if(i&&(r.storage=new jn({localStorage:i,adapter:e})),s){var a=new s({timeout:1e4,restrictedMethods:["get","post","upload","download","request"]});r.request=function(t){return function(e,n){return Ln(this,void 0,void 0,function(){return Dn(this,function(r){return[2,new Promise(function(r,o){var i=Object.assign({},n);i.body&&"string"!=typeof i.body&&(i.body=JSON.stringify(i.body));var s=wx.request({url:e,data:i.body,timeout:t._timeout,method:i.method||"GET",header:i.headers,success:function(t){(t=Mn(t,Un(Un({},n),{url:e}))).error&&o(t),r(t)},fail:function(t){o({error:"unreachable",error_description:t.message})},complete:function(e){if(e&&e.errMsg&&t._timeout&&-1!==t._restrictedMethods.indexOf("request")&&"request:fail timeout"===e.errMsg){console.warn(t._timeoutMsg);try{s.abort()}catch(t){}}}})})]})})}}(a)}return n.captchaOptions&&(r.baseRequest=r.request,r.request=void 0),Un(Un({},n),r)}catch(t){console.error("adapter generate fail:",t)}return n}(t,t.adapter)},Wn=function(){return Wn=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Wn.apply(this,arguments)},Fn=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Hn=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Vn=function(){function t(t){}return t.prototype.signInWithRedirect=function(){throw new Error("[v1 兼容] WeixinAuthProvider.signInWithRedirect() 在当前版本中无法实现。 建议使用 auth.signInWithOAuth({ provider: 'providerId' }) 替代。")},t.prototype.getRedirectResult=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] WeixinAuthProvider.getRedirectResult() 在当前版本中无法实现。 建议使用 auth.verifyOAuth({ code, state, provider }) 替代。")})})},t.prototype.getLinkRedirectResult=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] WeixinAuthProvider.getLinkRedirectResult() 在当前版本中无法实现。 建议使用 auth.linkIdentity({ provider: 'providerId' }) 替代。")})})},t}(),Gn=function(){function t(t){this.authInstance=t.authInstance}return t.prototype.signIn=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(e){switch(e.label){case 0:return[4,this.authInstance.signInWithCustomTicket(function(){return Promise.resolve(t)})];case 1:return e.sent(),[2]}})})},t}(),Kn=function(){function t(t){this.authInstance=t.authInstance}return t.prototype.signIn=function(){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){switch(t.label){case 0:return[4,this.authInstance.signInAnonymously({})];case 1:return t.sent(),[2]}})})},t}(),Jn=function(){function t(){}return t.prototype.weixinAuthProvider=function(t){return new Vn({authInstance:this,appid:t.appid,scope:t.scope})},t.prototype.customAuthProvider=function(){return new Gn({authInstance:this})},t.prototype.anonymousAuthProvider=function(){return new Kn({authInstance:this})},t.prototype.signUpWithEmailAndPassword=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(n){switch(n.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"email must be a string"),"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"password must be a string"),[4,this.signUp({email:t,password:e})];case 1:return[2,n.sent()]}})})},t.prototype.signInWithEmailAndPassword=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(n){switch(n.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"email must be a string"),"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"password must be a string"),[4,this.signIn({username:t,password:e})];case 1:return n.sent(),[2,this.createLoginState()]}})})},t.prototype.sendPasswordResetEmail=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(e){switch(e.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"email must be a string"),[4,this.getVerification({email:t})];case 1:return e.sent(),[2]}})})},t.prototype.signInWithUsernameAndPassword=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(n){switch(n.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"username must be a string"),"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"password must be a string"),[4,this.signIn({username:t,password:e})];case 1:return n.sent(),[2,this.createLoginState()]}})})},t.prototype.sendPhoneCode=function(t){return Fn(this,void 0,Promise,function(){var e;return Hn(this,function(n){switch(n.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneNumber must be a string"),e=this.formatPhone(t),[4,this.getVerification({phone_number:e})];case 1:return n.sent(),[2,!0]}})})},t.prototype.signUpWithPhoneCode=function(t,e,n){return Fn(this,void 0,Promise,function(){var r;return Hn(this,function(o){switch(o.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneNumber must be a string"),"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneCode must be a string"),r=this.formatPhone(t),[4,this.signUp(Wn({phone_number:r,verification_code:e},n?{password:n}:{}))];case 1:return o.sent(),[2,this.createLoginState()]}})})},t.prototype.signInWithPhoneCodeOrPassword=function(t){return Fn(this,void 0,Promise,function(){var e,n,r,o;return Hn(this,function(i){switch(i.label){case 0:return e=t.phoneNumber,n=t.phoneCode,r=t.password,"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneNumber must be a string"),o=this.formatPhone(e),r?[4,this.signIn({username:o,password:r})]:[3,2];case 1:return i.sent(),[3,5];case 2:return n?[4,this.signIn({username:o,verification_token:n})]:[3,4];case 3:return i.sent(),[3,5];case 4:(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneCode or password must be provided"),i.label=5;case 5:return[2,this.createLoginState()]}})})},t.prototype.forceResetPwdByPhoneCode=function(t){return Fn(this,void 0,Promise,function(){var e,n,r,o;return Hn(this,function(i){switch(i.label){case 0:return e=t.phoneNumber,n=t.phoneCode,r=t.password,"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneNumber must be a string"),"string"!=typeof n&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneCode must be a string"),"string"!=typeof r&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"password must be a string"),o=this.formatPhone(e),[4,this.resetPassword({phone_number:o,new_password:r,verification_token:n})];case 1:return i.sent(),[4,this.signIn({username:o,password:r})];case 2:return i.sent(),[2,this.createLoginState()]}})})},t.prototype.shouldRefreshAccessToken=function(t){throw new Error("[v1 兼容] shouldRefreshAccessToken() 在当前版本中无法实现。 建议使用 auth.onAuthStateChange(callback) 来监听 TOKEN_REFRESHED 事件替代。")},t.prototype.onLoginStateExpired=function(t){var e=this;this.onLoginStateChanged(function(n){(null==n?void 0:n.eventType)===ge&&t.call(e)})},t.prototype.onAccessTokenRefreshed=function(t){var e=this;this.onAuthStateChange(function(n){n===_e&&t.call(e)})},t.prototype.onAnonymousConverted=function(t){var e=this;this.onAuthStateChange(function(n){n===be&&t.call(e)})},t.prototype.onLoginTypeChanged=function(t){var e=this;this.onAuthStateChange(function(n){n!==be&&n!==me||t.call(e)})},t}(),zn=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),$n=function(){return $n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},$n.apply(this,arguments)},Yn=function(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s},Qn=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},Xn=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Zn=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},tr=function(){return"undefined"!=typeof window&&"undefined"!=typeof document},er=function(t){return function(e){t.fire(Se,$n($n({},e),{eventType:ge}))}},nr=["avatar_url","avatarUrl"];function rr(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).length:t.length}function or(t,e){if(t)for(var n=0,r=nr;n<r.length;n++){var o=r[n],i=t[o];if(null!=i&&""!==i){var s=rr(String(i));if(s>204800)throw new En({error:"invalid_argument",error_code:de.INVALID_ARGUMENT,error_description:"auth.".concat(e,'(params): "').concat(o,'" 超过 200KB 限制(当前 ').concat(s," 字节),请传入图片 URL 而非文件内容")},{method:e})}}}var ir,sr=function(){function e(t){var e=t.cache,n=t.oauthInstance;this.cache=e,this.oauthInstance=n,this.setUserInfo()}var n,r,o;return e.prototype.checkLocalInfo=function(){return Xn(this,void 0,void 0,function(){return Zn(this,function(t){return this.uid=this.getLocalUserInfo("uid"),this.gender=this.getLocalUserInfo("gender"),this.picture=this.getLocalUserInfo("picture"),this.email=this.getLocalUserInfo("email"),this.emailVerified=this.getLocalUserInfo("email_verified"),this.phoneNumber=this.getLocalUserInfo("phone_number"),this.username=this.getLocalUserInfo("username"),this.name=this.getLocalUserInfo("name"),this.birthdate=this.getLocalUserInfo("birthdate"),this.zoneinfo=this.getLocalUserInfo("zoneinfo"),this.locale=this.getLocalUserInfo("locale"),this.sub=this.getLocalUserInfo("sub"),this.createdFrom=this.getLocalUserInfo("created_from"),this.providers=this.getLocalUserInfo("providers"),[2]})})},e.prototype.checkLocalInfoAsync=function(){return Xn(this,void 0,void 0,function(){var t,e,n,r;return Zn(this,function(o){switch(o.label){case 0:return t=this,[4,this.getLocalUserInfoAsync("uid")];case 1:return t.uid=o.sent(),e=this,[4,this.getLocalUserInfoAsync("gender")];case 2:return e.gender=o.sent(),this.picture=this.getLocalUserInfo("picture"),n=this,[4,this.getLocalUserInfoAsync("email")];case 3:return n.email=o.sent(),this.emailVerified=this.getLocalUserInfo("email_verified"),this.phoneNumber=this.getLocalUserInfo("phone_number"),r=this,[4,this.getLocalUserInfoAsync("username")];case 4:return r.username=o.sent(),this.name=this.getLocalUserInfo("name"),this.birthdate=this.getLocalUserInfo("birthdate"),this.zoneinfo=this.getLocalUserInfo("zoneinfo"),this.locale=this.getLocalUserInfo("locale"),this.sub=this.getLocalUserInfo("sub"),this.createdFrom=this.getLocalUserInfo("created_from"),this.providers=this.getLocalUserInfo("providers"),[2]}})})},e.prototype.update=function(t){return Xn(this,void 0,Promise,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return or(t,"update"),[4,this.oauthInstance.authApi.setUserProfile($n({},t))];case 1:return e=n.sent(),this.setLocalUserInfo(e),[2]}})})},e.prototype.updateUserBasicInfo=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return or(t,"updateUserBasicInfo"),[4,this.oauthInstance.authApi.updateUserBasicInfo($n({},t))];case 1:return e.sent(),[4,this.refresh()];case 2:return e.sent(),[2]}})})},e.prototype.updatePassword=function(t,e){return this.oauthInstance.authApi.updatePasswordByOld({old_password:e,new_password:t})},e.prototype.updateUsername=function(t){return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"username must be a string"),this.update({username:t})},e.prototype.refresh=function(t){return Xn(this,void 0,Promise,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return[4,this.oauthInstance.authApi.getUserInfo(t)];case 1:if("INVALID_ACCESS_TOKEN"===(e=n.sent()).code)throw this.setLocalUserInfo({}),e;return this.setLocalUserInfo(e),[2,e]}})})},e.prototype.getLocalUserInfo=function(t){var e=this.cache.keys.userInfoKey,n=this.cache.getStore(e);return t?n[t]:n||{}},e.prototype.setLocalUserInfo=function(t){var e=this.cache.keys.userInfoKey;this.cache.setStore(e,t),this.setUserInfo()},e.prototype.getLocalUserInfoAsync=function(t){return Xn(this,void 0,Promise,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return e=this.cache.keys.userInfoKey,[4,this.cache.getStoreAsync(e)];case 1:return[2,n.sent()[t]]}})})},e.prototype.setUserInfo=function(){var t=this,e=this.cache.keys.userInfoKey,n=this.cache.getStore(e);["uid","email","name","gender","picture","email_verified","phone_number","birthdate","zoneinfo","locale","sub","created_from","providers","username","created_at","open_id"].forEach(function(e){t[e]=n[e]})},Yn([(0,kn.catchErrorsDecorator)({title:"更新用户信息失败",messages:["请确认以下各项:"," 1 - 调用 User.update() 的语法或参数是否正确"," 2 - 用户信息中是否包含非法值","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(n=t.UserProfile)?n:Object]),Qn("design:returntype","function"==typeof(r="undefined"!=typeof Promise&&Promise)?r:Object)],e.prototype,"update",null),Yn([(0,kn.catchErrorsDecorator)({title:"更新密码失败",messages:["请确认以下各项:"," 1 - 调用 User.updatePassword() 的语法或参数是否正确"," 3 - 新密码中是否包含非法字符","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[String,String]),Qn("design:returntype",void 0)],e.prototype,"updatePassword",null),Yn([(0,kn.catchErrorsDecorator)({title:"更新用户名失败",messages:["请确认以下各项:"," 1 - 调用 User.updateUsername() 的语法或参数是否正确"," 2 - 当前环境是否开通了用户名密码登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[String]),Qn("design:returntype",void 0)],e.prototype,"updateUsername",null),Yn([(0,kn.catchErrorsDecorator)({title:"刷新本地用户信息失败",messages:["请确认以下各项:"," 1 - 调用 User.refresh() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[Object]),Qn("design:returntype","function"==typeof(o="undefined"!=typeof Promise&&Promise)?o:Object)],e.prototype,"refresh",null),e}();(ir=sr).prototype.linkWithTicket=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] User.linkWithTicket() 在当前版本中无法实现。 建议使用 auth.signInWithCustomTicket(() => Promise.resolve(ticket)) 替代。")})})},ir.prototype.linkWithRedirect=function(t){throw new Error("[v1 兼容] User.linkWithRedirect() 在当前版本中无法实现。 建议使用 auth.linkIdentity({ provider: 'providerId' }) 替代。")},ir.prototype.updateEmail=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(e){switch(e.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"newEmail must be a string"),[4,this.updateUserBasicInfo({email:t})];case 1:return e.sent(),[2]}})})},ir.prototype.linkWithPhoneNumber=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] User.linkWithPhoneNumber() 在当前版本中无法实现。 建议使用 auth.bindPhoneNumber({ phone_number, verification_token, sudo_token }) 替代。")})})},ir.prototype.updatePhoneNumber=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] User.updatePhoneNumber() 在当前版本中无法实现。 建议使用 auth.updateUser({ phone: newPhoneNumber }) 替代。")})})},ir.prototype.unlink=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] User.unlink() 在当前版本中无法实现。 建议使用 auth.unlinkIdentity({ provider: loginType }) 替代。")})})};var ar=function(){function t(t){var e=t.envId,n=t.cache,r=t.oauthInstance;e||(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"envId is not defined"),this.cache=n,this.oauthInstance=r,this.user=new sr({cache:this.cache,oauthInstance:r})}return t.prototype.checkLocalState=function(){var t;this.oauthLoginState=null===(t=this.oauthInstance)||void 0===t?void 0:t.authApi.hasLoginStateSync(),this.user.checkLocalInfo()},t.prototype.checkLocalStateAsync=function(){var t;return Xn(this,void 0,void 0,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,null===(t=this.oauthInstance)||void 0===t?void 0:t.authApi.getLoginState()];case 1:return e.sent(),[4,this.user.checkLocalInfoAsync()];case 2:return e.sent(),[2]}})})},t}(),cr=function(e){function n(t){var n=e.call(this)||this;return n.listeners=new Map,n.hasListenerSetUp=!1,n.config=t,n.oauthInstance=t.oauthInstance,n.cache=t.cache,n.init(),n.setAccessKey(),n}var r,o,i,s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I;return zn(n,e),n.prototype.signInAnonymously=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o,i;return Zn(this,function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),[4,this.oauthInstance.authApi.signInAnonymously(t)];case 1:return s.sent(),[4,this.createLoginState()];case 2:return e=s.sent(),[4,this.getSession()];case 3:return n=s.sent().data,r=(void 0===n?{}:n).session,[2,$n($n({},e),{data:{user:r.user,session:r},error:null})];case 4:return o=s.sent(),(i=new En(o,{method:"signInAnonymously"})).category===yn.PROVIDER_NOT_ENABLED?(console.error(i.helpMessage),console.error("[CloudBase Auth] 提示:匿名登录需要在控制台开启「匿名登录」。\n 如果您需要使用用户名密码登录,请改用 auth.signInWithPassword({ username, password })。\n 不要在匿名登录失败后自动回退到密码登录,这两种方式的使用场景不同。")):(console.warn("[CloudBase Auth] signInAnonymously 失败 [".concat(i.category,"]: ").concat(i.message)),i.loginMethodHint&&console.warn(i.loginMethodHint)),[2,{data:{user:null,session:null},error:i}];case 5:return[2]}})})},n.prototype.signUp=function(t){return Xn(this,void 0,Promise,function(){var e,n,r=this;return Zn(this,function(o){switch(o.label){case 0:return t.phone_number||t.verification_code||t.verification_token||t.provider_token?(t.phone_number&&(t.phone_number=this.formatPhone(t.phone_number)),[4,this.oauthInstance.authApi.signUp(t)]):[3,2];case 1:return o.sent(),[2,this.createLoginState()];case 2:return o.trys.push([2,4,,5]),this.validateAtLeastOne(t,[["email"],["phone"]],"signUp"),[4,this.getVerification(t.email?{email:t.email,usage:ve.EMAIL}:{phone_number:this.formatPhone(t.phone)})];case 3:return e=o.sent(),[2,{data:{verifyOtp:function(n){var o=n.token,i=n.messageId,s=void 0===i?e.verification_id:i;return Xn(r,void 0,Promise,function(){var n,r,i,a,c;return Zn(this,function(u){switch(u.label){case 0:return u.trys.push([0,8,,9]),[4,this.verify({verification_id:s||e.verification_id,verification_code:String(o)})];case 1:return n=u.sent(),e.is_user?[4,this.signIn({username:t.email||this.formatPhone(t.phone),verification_token:n.verification_token})]:[3,3];case 2:return u.sent(),[3,6];case 3:return delete(r=JSON.parse(JSON.stringify(t))).email,delete r.phone,[4,this.oauthInstance.authApi.signUp($n($n($n({},r),t.email?{email:t.email}:{phone_number:this.formatPhone(t.phone)}),{verification_token:n.verification_token,verification_code:o}))];case 4:return u.sent(),[4,this.createLoginState()];case 5:u.sent(),u.label=6;case 6:return[4,this.getSession()];case 7:return i=u.sent().data,[2,{data:{user:(a=(void 0===i?{}:i).session).user,session:a},error:null}];case 8:return c=u.sent(),[2,{data:{user:null,session:null},error:new En(c,{method:"signUp"})}];case 9:return[2]}})})}},error:null}];case 4:return n=o.sent(),[2,{data:{user:null,session:null},error:new En(n,{method:"signUp"})}];case 5:return[2]}})})},n.prototype.signOut=function(t){return Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),e=this.cache.keys.userInfoKey,[4,this.oauthInstance.authApi.signOut(t)];case 1:return n=o.sent(),[4,this.cache.removeStoreAsync(e)];case 2:return o.sent(),this.setAccessKey(),[2,$n($n({},n),{data:{},error:null})];case 3:return r=o.sent(),[2,{data:{},error:new En(r,{method:"signOut"})}];case 4:return[2]}})})},n.prototype.onAuthStateChange=function(t){var e=this;this.hasListenerSetUp||(this.setupListeners(),this.hasListenerSetUp=!0);var n=Math.random().toString(36);return this.listeners.has(n)||this.listeners.set(n,new Set),this.listeners.get(n).add(t),{data:{subscription:{id:n,callback:t,unsubscribe:function(){var r=e.listeners.get(n);r&&(r.delete(t),0===r.size&&e.listeners.delete(n))}}}}},n.prototype.signInWithPassword=function(t){var e,n;return Xn(this,void 0,Promise,function(){var r,o,i,s,a,c,u,l;return Zn(this,function(h){switch(h.label){case 0:return h.trys.push([0,3,,4]),this.validateAtLeastOne(t,[["username"],["email"],["phone"]],"signInWithPassword"),this.validateParams(t,{password:{required:!0,message:"Password is required"}},"signInWithPassword"),r="username"in t?t.username:void 0,o="email"in t?t.email:void 0,i="phone"in t?t.phone:void 0,s=null!==(n=null===(e=t.options)||void 0===e?void 0:e.is_encrypt)&&void 0!==n?n:t.is_encrypt,[4,this.signIn($n({username:r||o||this.formatPhone(i),password:t.password},s?{isEncrypt:!0,version:"v2"}:{}))];case 1:return h.sent(),[4,this.getSession()];case 2:return a=h.sent().data,[2,{data:{user:(c=(void 0===a?{}:a).session).user,session:c},error:null}];case 3:return u=h.sent(),(l=new En(u,{method:"signInWithPassword"})).category===yn.PROVIDER_NOT_ENABLED?console.error(l.helpMessage):l.category===yn.INVALID_CREDENTIALS||l.category===yn.USER_NOT_FOUND?console.warn(l.helpMessage):console.warn("[CloudBase Auth] signInWithPassword 失败 [".concat(l.category,"]: ").concat(l.message)),l.loginMethodHint&&console.info(l.loginMethodHint),[2,{data:{user:null,session:null},error:l}];case 4:return[2]}})})},n.prototype.signInWithIdToken=function(t){return Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),this.validateParams(t,{token:{required:!0,message:"Token is required"}},"signInWithIdToken"),[4,this.signInWithProvider({provider_id:t.provider,provider_id_token:t.token})];case 1:return o.sent(),[4,this.getSession()];case 2:return e=o.sent().data,[2,{data:{user:(n=(void 0===e?{}:e).session).user,session:n},error:null}];case 3:return r=o.sent(),[2,{data:{user:null,session:null},error:new En(r,{method:"signInWithIdToken"})}];case 4:return[2]}})})},n.prototype.signInWithOtp=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o,i,s=this;return Zn(this,function(a){switch(a.label){case 0:if(e=t.options,n="email"in t?t.email:void 0,r="phone"in t?t.phone:void 0,!(null==e?void 0:e.emailRedirectTo)&&(void 0===(null==e?void 0:e.shouldCreateUser)||(null==e?void 0:e.shouldCreateUser)))return[2,this.signUp(n?{email:n}:{phone:r})];a.label=1;case 1:return a.trys.push([1,3,,4]),this.validateAtLeastOne(t,[["email"],["phone"]],"signInWithOtp"),[4,this.getVerification($n($n({email_redirect_to:null==e?void 0:e.emailRedirectTo},n?{email:n,usage:ve.EMAIL}:{phone_number:this.formatPhone(r)}),{target:(null==e?void 0:e.emailRedirectTo)&&(null==e?void 0:e.shouldCreateUser)?"ANY":"USER"}))];case 2:return o=a.sent(),[2,{data:{user:null,session:null,verifyOtp:function(t){var e=t.token,i=t.messageId,a=void 0===i?o.verification_id:i;return Xn(s,void 0,Promise,function(){return Zn(this,function(t){return[2,this.verifyOtp(n?{email:n,token:String(e),messageId:a||""}:{phone:r,token:String(e),messageId:a||""})]})})}},error:null}];case 3:return i=a.sent(),[2,{data:{user:null,session:null},error:new En(i,{method:"signInWithOtp"})}];case 4:return[2]}})})},n.prototype.verifyOAuth=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o,i,s,a,c,u;return Zn(this,function(l){switch(l.label){case 0:e={},l.label=1;case 1:return l.trys.push([1,7,,8]),n=(null==t?void 0:t.code)||T("code"),r=(null==t?void 0:t.state)||T("state"),n?r?(o=function(t){try{return JSON.parse(sessionStorage.getItem(t))}catch(t){return console.error("Failed to get browser session:",t),null}}(r),e.type=null==o?void 0:o.type,(i=(null==t?void 0:t.provider)||(null==o?void 0:o.provider)||T("provider"))?[4,this.grantProviderToken({provider_id:i,provider_redirect_uri:location.origin+location.pathname,provider_code:n})]:[2,{data:$n($n({},e),{user:null,session:null,redirectUrl:null}),error:this.missingRequiredParam("verifyOAuth","provider")}]):[2,{data:{user:null,session:null,redirectUrl:null},error:this.missingRequiredParam("verifyOAuth","state")}]:[2,{data:{user:null,session:null,redirectUrl:null},error:this.missingRequiredParam("verifyOAuth","code")}];case 2:return s=l.sent().provider_token,a=void 0,o.type!==Ae?[3,4]:[4,this.oauthInstance.authApi.toBindIdentity({provider_token:s,provider:i,fireEvent:!0})];case 3:return a=l.sent(),[3,6];case 4:return[4,this.signInWithIdToken({token:s})];case 5:(a=l.sent()).data=$n($n({},e),a.data),l.label=6;case 6:return(c=new URLSearchParams(null===location||void 0===location?void 0:location.search)).delete("code"),c.delete("state"),a.data.redirectUrl=function(t,e){if(void 0!==t){var n=new URL(window.location.href);return n.search=t,n.hash=e||n.hash,window.history.replaceState({},"",n.href),n.href}}(void 0===(null==o?void 0:o.search)?"?".concat(c.toString()):null==o?void 0:o.search,(null==o?void 0:o.hash)||location.hash),function(t){try{return sessionStorage.removeItem(t),!0}catch(t){return console.error("Failed to remove browser session:",t),null}}(r),[2,a];case 7:return u=l.sent(),[2,{data:$n($n({},e),{user:null,session:null,redirectUrl:null}),error:new En(u,{method:"verifyOAuth"})}];case 8:return[2]}})})},n.prototype.signInWithOAuth=function(t){var e,n,r,o,i;return Xn(this,void 0,Promise,function(){var s,a,c,u,l,h,d,f,p;return Zn(this,function(v){switch(v.label){case 0:return v.trys.push([0,2,,3]),this.validateParams(t,{provider:{required:!0,message:"Provider is required"}},"signInWithOAuth"),s=(null===(e=t.options)||void 0===e?void 0:e.redirectTo)||location.href,a=new URL(s),c=a.origin+a.pathname,u=(null===(n=t.options)||void 0===n?void 0:n.state)||"prd-".concat(t.provider,"-").concat(Math.random().toString(36).slice(2)),[4,this.genProviderRedirectUri({provider_id:t.provider,provider_redirect_uri:c,state:u})];case 1:return l=v.sent().uri,h=decodeURIComponent(l),d=h,(null===(r=t.options)||void 0===r?void 0:r.queryParams)&&(f=new URL(h),Object.entries(t.options.queryParams).forEach(function(t){var e=t[0],n=t[1];f.searchParams.set(e,n)}),d=f.toString()),function(t,e){try{sessionStorage.setItem(t,JSON.stringify(e))}catch(t){console.error("Failed to save to browser session:",t)}}(u,{provider:t.provider,search:a.search,hash:a.hash,type:(null===(o=t.options)||void 0===o?void 0:o.type)||Te}),tr()&&!(null===(i=t.options)||void 0===i?void 0:i.skipBrowserRedirect)&&window.location.assign(d),[2,{data:{url:d,provider:t.provider},error:null}];case 2:return p=v.sent(),[2,{data:{url:null,provider:null},error:new En(p,{method:"signInWithOAuth"})}];case 3:return[2]}})})},n.prototype.getClaims=function(){return Xn(this,void 0,Promise,function(){var t;return Zn(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.getAccessToken()];case 1:return[2,{data:function(t){if("string"!=typeof t)throw new Error("Invalid token specified");try{var e=t.split(".").map(function(t,e){return 2===e?t:JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("Illegal base64url string!")}try{return function(t){return decodeURIComponent(je(t).replace(/(.)/g,function(t){var e=t.charCodeAt(0).toString(16).toUpperCase();return e.length<2&&(e="0".concat(e)),"%".concat(e)}))}(e)}catch(t){return je(e)}}(t))});return{claims:e[1],header:e[0],signature:e[2]}}catch(t){throw new Error("Invalid token specified: ".concat(t)?t.message:0)}}(e.sent().accessToken),error:null}];case 2:return t=e.sent(),[2,{data:{claims:null,header:null,signature:null},error:new En(t,{method:"getClaims"})}];case 3:return[2]}})})},n.prototype.resetPasswordForEmail=function(t,e){return Xn(this,void 0,Promise,function(){var n,r,o,i,s,a,c=this;return Zn(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),this.validateParams({emailOrPhone:t},{emailOrPhone:{required:!0,message:"Email or phone is required"}},"resetPasswordForEmail"),n=(e||{}).redirectTo,r=t.includes("@"),o=void 0,r?o={email:t,usage:ve.RECOVERY}:(i=this.formatPhone(t),o={phone_number:i}),[4,this.getVerification($n($n({},o),{target:"USER"}))];case 1:return s=u.sent(),[2,{data:{updateUser:function(e){return Xn(c,void 0,Promise,function(){var o,i,a,c;return Zn(this,function(u){switch(u.label){case 0:this.validateParams(e,{nonce:{required:!0,message:"Nonce is required"},password:{required:!0,message:"Password is required"}},"resetPasswordForEmail"),u.label=1;case 1:return u.trys.push([1,5,,6]),[4,this.verify({verification_id:s.verification_id,verification_code:e.nonce})];case 2:return o=u.sent(),[4,this.oauthInstance.authApi.resetPassword({email:r?t:void 0,phone_number:r?void 0:t,new_password:e.password,verification_token:o.verification_token})];case 3:return u.sent(),null===(c=this.config.eventBus)||void 0===c||c.fire(Oe,{event:"PASSWORD_RECOVERY"}),[4,this.signInWithPassword({email:r?t:void 0,phone:r?void 0:t,password:e.password})];case 4:return i=u.sent(),n&&tr()&&window.location.assign(n),[2,i];case 5:return a=u.sent(),[2,{data:{user:null,session:null},error:new En(a,{method:"resetPasswordForEmail"})}];case 6:return[2]}})})}},error:null}];case 2:return a=u.sent(),[2,{data:{updateUser:null},error:new En(a,{method:"resetPasswordForEmail"})}];case 3:return[2]}})})},n.prototype.resetPasswordForOld=function(t){return Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,this.oauthInstance.authApi.updatePasswordByOld({old_password:t.old_password,new_password:t.new_password})];case 1:return o.sent(),[4,this.getSession()];case 2:return e=o.sent().data,[2,{data:{user:(n=(void 0===e?{}:e).session).user,session:n},error:null}];case 3:return r=o.sent(),[2,{data:{user:null,session:null},error:new En(r,{method:"resetPasswordForOld"})}];case 4:return[2]}})})},n.prototype.verifyOtp=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o,i,s,a;return Zn(this,function(c){switch(c.label){case 0:return c.trys.push([0,6,,7]),e=t.type,n=String(t.token),r="email"in t?t.email:void 0,o="phone"in t?t.phone:void 0,this.validateParams(t,{token:{required:!0,message:"Token is required"},messageId:{required:!0,message:"messageId is required"}},"verifyOtp"),["phone_change","email_change"].includes(e)?[4,this.verify({verification_id:t.messageId,verification_code:n})]:[3,2];case 1:return c.sent(),[3,4];case 2:return[4,this.signInWithUsername({verificationInfo:{verification_id:t.messageId,is_user:!0},verificationCode:n,username:r||this.formatPhone(o)||"",loginType:r?"email":"phone"})];case 3:c.sent(),c.label=4;case 4:return[4,this.getSession()];case 5:return i=c.sent().data,[2,{data:{user:(s=(void 0===i?{}:i).session).user,session:s},error:null}];case 6:return a=c.sent(),[2,{data:{user:null,session:null},error:new En(a,{method:"verifyOtp"})}];case 7:return[2]}})})},n.prototype.getSession=function(){return Xn(this,void 0,Promise,function(){var t,e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,this.oauthInstance.oauth2client.getCredentials()];case 1:return(t=o.sent())&&"accessKey"!==t.scope?[4,this.getUser(!1)]:[2,{data:{session:null,user:null},error:null}];case 2:return e=o.sent().data,n=(void 0===e?{}:e).user,[2,{data:{session:$n($n({},t),{user:n}),user:n},error:null}];case 3:return r=o.sent(),[2,{data:{session:null,user:null},error:new En(r,{method:"getSession"})}];case 4:return[2]}})})},n.prototype.refreshSession=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o,i;return Zn(this,function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),[4,this.oauthInstance.oauth2client.localCredentials.getCredentials()];case 1:return(e=s.sent()).refresh_token=t||e.refresh_token,[4,this.oauthInstance.oauth2client.refreshToken(e)];case 2:return n=s.sent(),[4,this.getUser(!1)];case 3:return r=s.sent().data,[2,{data:{user:o=(void 0===r?{}:r).user,session:$n($n({},n),{user:o})},error:null}];case 4:return i=s.sent(),[2,{data:{user:null,session:null},error:new En(i,{method:"refreshSession"})}];case 5:return[2]}})})},n.prototype.getUser=function(t){return void 0===t&&(t=!0),Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,this.oauthInstance.oauth2client.getCredentials()];case 1:return(e=o.sent())&&"accessKey"!==e.scope?(n=this.convertToUser,[4,this.getCurrentUser(t)]):[2,{data:{user:null},error:null}];case 2:return[2,{data:{user:n.apply(this,[o.sent()])},error:null}];case 3:return r=o.sent(),[2,{data:{user:null},error:new En(r,{method:"getUser"})}];case 4:return[2]}})})},n.prototype.refreshUser=function(){return Xn(this,void 0,Promise,function(){var t,e,n;return Zn(this,function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),[4,this.currentUser.refresh()];case 1:return r.sent(),[4,this.getSession()];case 2:return t=r.sent().data,[2,{data:{user:(e=(void 0===t?{}:t).session).user,session:e},error:null}];case 3:return n=r.sent(),[2,{data:{user:null,session:null},error:new En(n,{method:"refreshUser"})}];case 4:return[2]}})})},n.prototype.updateUser=function(t){var e;return Xn(this,void 0,Promise,function(){var n,r,o,i,s,a,c,u,l,h,d,f,p,v,y=this;return Zn(this,function(g){switch(g.label){case 0:if(g.trys.push([0,8,,9]),or(t,"updateUser"),n=["password","new_password"].find(function(e){var n=t[e];return null!=n&&""!==n}),n)throw new En({message:'updateUser 不支持更新密码,检测到传入了 "'.concat(n,'" 参数。如需修改密码请使用 resetPasswordForOld(旧密码修改)、resetPasswordForEmail(验证码重置)或 reauthenticate(重新认证后改密)')});if(r=Object.keys(t).some(function(e){return void 0!==t[e]&&null!==t[e]&&""!==t[e]}),!r)throw this.missingRequiredParam("updateUser","(at least one field)");return o=t.email,i=t.phone,s=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(t,["email","phone"]),c=void 0!==i,u={},(a=void 0!==o)||c?(l=void 0,a?(l={email:t.email,usage:ve.REAUTHENTICATION},h="email_change"):(d=this.formatPhone(t.phone),l={phone_number:d},h="phone_change"),[4,this.getVerification($n({},l))]):[3,4];case 1:return f=g.sent(),Object.keys(s).length>0?[4,this.updateUserBasicInfo(s)]:[3,3];case 2:g.sent(),g.label=3;case 3:return u={messageId:f.verification_id,verifyOtp:function(e){return Xn(y,void 0,Promise,function(){var n,r,o,i;return Zn(this,function(s){switch(s.label){case 0:return s.trys.push([0,11,,12]),e.email&&t.email===e.email?[4,this.verifyOtp({type:"email_change",email:t.email,token:e.token,messageId:f.verification_id||""})]:[3,3];case 1:return(n=s.sent()).error?[2,n]:[4,this.updateUserBasicInfo({email:t.email})];case 2:return s.sent(),[3,9];case 3:return e.phone&&t.phone===e.phone?[4,this.verifyOtp({type:"phone_change",phone:t.phone,token:e.token,messageId:f.verification_id||""})]:[3,6];case 4:return(n=s.sent()).error?[2,n]:[4,this.updateUserBasicInfo({phone:this.formatPhone(t.phone)})];case 5:return s.sent(),[3,9];case 6:return[4,this.verifyOtp(a?{type:h,email:t.email,token:e.token,messageId:f.verification_id||""}:{type:h,phone:t.phone,token:e.token,messageId:f.verification_id||""})];case 7:return(n=s.sent()).error?[2,n]:[4,this.updateUserBasicInfo(t)];case 8:s.sent(),s.label=9;case 9:return[4,this.getUser(!1)];case 10:return r=s.sent().data.user,null===(i=this.config.eventBus)||void 0===i||i.fire(Oe,{event:Ee}),[2,{data:{user:r},error:null}];case 11:return o=s.sent(),[2,{data:{user:null},error:new En(o,{method:"updateUser"})}];case 12:return[2]}})})}},[3,6];case 4:return[4,this.updateUserBasicInfo(t)];case 5:g.sent(),g.label=6;case 6:return[4,this.getUser(!1)];case 7:return p=g.sent().data.user,Object.keys(s).length>0&&(null===(e=this.config.eventBus)||void 0===e||e.fire(Oe,{event:Ee})),[2,{data:$n({user:p},u),error:null}];case 8:return v=g.sent(),[2,{data:{user:null},error:new En(v,{method:"updateUser"})}];case 9:return[2]}})})},n.prototype.getUserIdentities=function(){var t;return Xn(this,void 0,Promise,function(){var e,n;return Zn(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.oauthInstance.authApi.getProviders()];case 1:return e=r.sent(),[2,{data:{identities:null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.filter(function(t){return!!t.bind})},error:null}];case 2:return n=r.sent(),[2,{data:{identities:null},error:new En(n,{method:"getUserIdentities"})}];case 3:return[2]}})})},n.prototype.linkIdentity=function(t){return Xn(this,void 0,Promise,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.validateParams(t,{provider:{required:!0,message:"Provider is required"}},"linkIdentity"),[4,this.signInWithOAuth({provider:t.provider,options:{type:Ae}})];case 1:return n.sent(),[2,{data:{provider:t.provider},error:null}];case 2:return e=n.sent(),[2,{data:{provider:null},error:new En(e,{method:"linkIdentity"})}];case 3:return[2]}})})},n.prototype.unlinkIdentity=function(t){return Xn(this,void 0,Promise,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.validateParams(t,{provider:{required:!0,message:"Provider is required"}},"unlinkIdentity"),[4,this.oauthInstance.authApi.unbindProvider({provider_id:t.provider})];case 1:return n.sent(),[2,{data:{},error:null}];case 2:return e=n.sent(),[2,{data:{},error:new En(e,{method:"unlinkIdentity"})}];case 3:return[2]}})})},n.prototype.reauthenticate=function(){return Xn(this,void 0,Promise,function(){var t,e,n,r,o=this;return Zn(this,function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),[4,this.getUser(!1)];case 1:return t=i.sent().data.user,this.validateAtLeastOne(t,[["email","phone"]],"reauthenticate"),e=t.email?{email:t.email,usage:ve.REAUTHENTICATION}:{phone_number:this.formatPhone(t.phone)},[4,this.getVerification(e)];case 2:return n=i.sent(),[2,{data:{updateUser:function(t){return Xn(o,void 0,Promise,function(){var r,o,i,s,a;return Zn(this,function(c){switch(c.label){case 0:this.validateParams(t,{nonce:{required:!0,message:"Nonce is required"}},"reauthenticate"),c.label=1;case 1:return c.trys.push([1,9,,10]),t.password?[4,this.verify({verification_id:n.verification_id,verification_code:t.nonce})]:[3,5];case 2:return r=c.sent(),[4,this.oauthInstance.authApi.sudo({verification_token:r.verification_token})];case 3:return o=c.sent(),[4,this.oauthInstance.authApi.setPassword({new_password:t.password,sudo_token:o.sudo_token})];case 4:return c.sent(),[3,7];case 5:return[4,this.signInWithUsername($n($n({verificationInfo:n,verificationCode:t.nonce},e),{loginType:e.email?"email":"phone"}))];case 6:c.sent(),c.label=7;case 7:return[4,this.getSession()];case 8:return i=c.sent().data,[2,{data:{user:(s=(void 0===i?{}:i).session).user,session:s},error:null}];case 9:return a=c.sent(),[2,{data:{user:null,session:null},error:new En(a,{method:"reauthenticate"})}];case 10:return[2]}})})}},error:null}];case 3:return r=i.sent(),[2,{data:{updateUser:null},error:new En(r,{method:"reauthenticate"})}];case 4:return[2]}})})},n.prototype.resend=function(t){return Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),this.validateAtLeastOne(t,[["email"],["phone"]],"resend"),e="signup"===t.type?"ANY":"USER",n={target:e},"email"in t&&(n.email=t.email,n.usage=ve.EMAIL),"phone"in t&&(n.phone_number=this.formatPhone(t.phone)),[4,this.oauthInstance.authApi.getVerification(n)];case 1:return[2,{data:{messageId:o.sent().verification_id},error:null}];case 2:return r=o.sent(),[2,{data:{messageId:null},error:new En(r,{method:"resend"})}];case 3:return[2]}})})},n.prototype.setSession=function(t){return Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),this.validateParams(t,{access_token:{required:!0,message:"Access token is required"},refresh_token:{required:!0,message:"Refresh token is required"}},"setSession"),[4,this.oauthInstance.oauth2client.refreshToken(t,{throwError:!0})];case 1:return o.sent(),[4,this.getSession()];case 2:return e=o.sent().data,[2,{data:{user:(n=(void 0===e?{}:e).session).user,session:n},error:null}];case 3:return r=o.sent(),[2,{data:{user:null,session:null},error:new En(r,{method:"setSession"})}];case 4:return[2]}})})},n.prototype.exchangeCodeForSession=function(){return Xn(this,void 0,void 0,function(){return Zn(this,function(t){return[2]})})},n.prototype.deleteUser=function(t){return Xn(this,void 0,Promise,function(){var e,n;return Zn(this,function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),this.validateParams(t,{password:{required:!0,message:"Password is required"}},"deleteUser"),[4,this.oauthInstance.authApi.sudo(t)];case 1:return e=r.sent().sudo_token,[4,this.oauthInstance.authApi.deleteMe({sudo_token:e})];case 2:return r.sent(),[2,{data:{},error:null}];case 3:return n=r.sent(),[2,{data:{},error:new En(n,{method:"deleteUser"})}];case 4:return[2]}})})},n.prototype.toDefaultLoginPage=function(t){return void 0===t&&(t={}),Xn(this,void 0,Promise,function(){var e,n,r,o,i;return Zn(this,function(s){try{return e=t.config_version||"env",n=Object.keys(t.query||{}).map(function(e){return"".concat(e,"=").concat(t.query[e])}).join("&"),ut.default.isMatch()?wx.navigateTo({url:"/packages/$wd_system/pages/login/index".concat(n?"?".concat(n):"")}):(r=t.redirect_uri||window.location.href,o=new URL(r),i="".concat(o.origin,"/__auth/?app_id=").concat(t.app_id||"","&env_id=").concat(this.config.env,"&client_id=").concat(this.config.clientId||this.config.env,"&config_version=").concat(e,"&redirect_uri=").concat(encodeURIComponent(r)).concat(n?"&".concat(n):""),window.location.href=i),[2,{data:{},error:null}]}catch(t){return[2,{data:{},error:new En(t,{method:"toDefaultLoginPage"})}]}return[2]})})},n.prototype.signInWithCustomTicket=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o;return Zn(this,function(i){switch(i.label){case 0:t&&this.setCustomSignFunc(t),i.label=1;case 1:return i.trys.push([1,5,,6]),[4,this.oauthInstance.authApi.signInWithCustomTicket()];case 2:return i.sent(),[4,this.createLoginState()];case 3:return e=i.sent(),[4,this.getSession()];case 4:return n=i.sent().data,r=(void 0===n?{}:n).session,[2,$n($n({},e),{data:{user:r.user,session:r},error:null})];case 5:return o=i.sent(),[2,{data:{user:null,session:null},error:new En(o,{method:"signInWithCustomTicket"})}];case 6:return[2]}})})},n.prototype.signInWithOpenId=function(t){var e=(void 0===t?{}:t).useWxCloud,n=void 0===e||e;return Xn(this,void 0,Promise,function(){var t,e,r,o,i,s,a=this;return Zn(this,function(c){switch(c.label){case 0:if(!ut.default.isMatch())throw Error("wx api undefined");t=wx.getAccountInfoSync().miniProgram,e=function(e){return Xn(a,void 0,void 0,function(){var r,o;return Zn(this,function(i){switch(i.label){case 0:r=void 0,o=void 0,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:null==t?void 0:t.appId,provider_code:e,provider_params:{provider_code_type:"open_id",appid:null==t?void 0:t.appId}},n)];case 2:if((null==(r=i.sent())?void 0:r.error_code)||!r.provider_token)throw r;return[4,this.oauthInstance.authApi.signInWithProvider({provider_token:r.provider_token},n)];case 3:if(null==(o=i.sent())?void 0:o.error_code)throw o;return[3,5];case 4:throw i.sent();case 5:return[4,this.oauthInstance.oauth2client.setCredentials(o)];case 6:return i.sent(),[2]}})})},c.label=1;case 1:return c.trys.push([1,5,,6]),[4,new Promise(function(t,n){wx.login({success:function(r){return Xn(a,void 0,void 0,function(){var o;return Zn(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,e(r.code)];case 1:return i.sent(),t(!0),[3,3];case 2:return o=i.sent(),n(o),[3,3];case 3:return[2]}})})},fail:function(t){var e=new Error(null==t?void 0:t.errMsg);e.code=null==t?void 0:t.errno,n(e)}})})];case 2:return c.sent(),[4,this.createLoginState()];case 3:return r=c.sent(),[4,this.getSession()];case 4:return o=c.sent().data,i=(void 0===o?{}:o).session,[2,$n($n({},r),{data:{user:i.user,session:i},error:null})];case 5:return s=c.sent(),[2,{data:{user:null,session:null},error:new En(s,{method:"signInWithOpenId"})}];case 6:return[2]}})})},n.prototype.signInWithPhoneAuth=function(t){var e=t.phoneCode,n=void 0===e?"":e,r=t.useWxCloud,o=void 0!==r&&r;return Xn(this,void 0,Promise,function(){var t,e,r,i,s,a,c,u,l;return Zn(this,function(h){switch(h.label){case 0:return ut.default.isMatch()?(t=wx.getAccountInfoSync().miniProgram,e={provider_params:{provider_code_type:"phone",code:n,appid:t.appId},provider_id:t.appId},[4,wx.login()]):[2,{data:{user:null,session:null},error:new En({message:"wx api undefined"})}];case 1:r=h.sent().code,e.provider_code=r,h.label=2;case 2:return h.trys.push([2,5,,6]),[4,this.oauthInstance.authApi.grantProviderToken(e,o)];case 3:if((i=h.sent()).error_code)throw i;return[4,this.oauthInstance.authApi.signInWithProvider({provider_token:i.provider_token},o)];case 4:if(null==(s=h.sent())?void 0:s.error_code)throw s;return[3,6];case 5:return a=h.sent(),[2,{data:{user:null,session:null},error:new En(a,{method:"signInWithPhoneAuth"})}];case 6:return[4,this.createLoginState()];case 7:return c=h.sent(),[4,this.getSession()];case 8:return u=h.sent().data,l=(void 0===u?{}:u).session,[2,$n($n({},c),{data:{user:l.user,session:l},error:null})]}})})},n.prototype.bindPhoneNumber=function(t){return Xn(this,void 0,void 0,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.editContact(t)]})})},n.prototype.unbindProvider=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.unbindProvider(t)]})})},n.prototype.bindEmail=function(t){return this.oauthInstance.authApi.editContact(t)},n.prototype.verify=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.verify(t)]})})},n.prototype.getVerification=function(t,e){return Xn(this,void 0,Promise,function(){return Zn(this,function(n){return t.phone_number&&(t.phone_number=this.formatPhone(t.phone_number)),[2,this.oauthInstance.authApi.getVerification(t,e)]})})},Object.defineProperty(n.prototype,"currentUser",{get:function(){if("async"!==this.cache.mode){var t=this.hasLoginState();return t&&t.user||null}(0,tn.printWarn)(Cn.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getCurrentUser instead")},enumerable:!1,configurable:!0}),n.prototype.getCurrentUser=function(t){return void 0===t&&(t=!0),Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),t?[4,this.getLoginState()]:[3,3];case 1:return(e=o.sent())?[4,e.user.refresh()]:[3,3];case 2:o.sent(),o.label=3;case 3:return[3,5];case 4:return o.sent(),[3,5];case 5:return[4,this.getLoginState()];case 6:return(n=o.sent())?(r=n.user.getLocalUserInfo(),[4,n.user.checkLocalInfoAsync()]):[3,8];case 7:return o.sent(),[2,$n($n({},n.user),r)];case 8:return[2,null]}})})},n.prototype.signInAnonymouslyInWx=function(t){var e=(void 0===t?{}:t).useWxCloud;return Xn(this,void 0,Promise,function(){var t,n,r=this;return Zn(this,function(o){switch(o.label){case 0:if(!ut.default.isMatch())throw Error("wx api undefined");return t=wx.getAccountInfoSync().miniProgram,n=function(n){return Xn(r,void 0,void 0,function(){var r,o;return Zn(this,function(i){switch(i.label){case 0:r=void 0,o=void 0,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:null==t?void 0:t.appId,provider_code:n,provider_params:{provider_code_type:"open_id",appid:null==t?void 0:t.appId}},e)];case 2:if((null==(r=i.sent())?void 0:r.error_code)||!r.provider_token)throw r;return[4,this.oauthInstance.authApi.signInAnonymously({provider_token:r.provider_token},e)];case 3:if(null==(o=i.sent())?void 0:o.error_code)throw o;return[3,5];case 4:throw i.sent();case 5:return[2]}})})},[4,new Promise(function(t,e){wx.login({success:function(o){return Xn(r,void 0,void 0,function(){var r;return Zn(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,n(o.code)];case 1:return i.sent(),t(!0),[3,3];case 2:return r=i.sent(),e(r),[3,3];case 3:return[2]}})})},fail:function(t){var n=new Error(null==t?void 0:t.errMsg);n.code=null==t?void 0:t.errno,e(n)}})})];case 1:return o.sent(),[2,this.createLoginState(void 0,{asyncRefreshUser:!0})]}})})},n.prototype.bindOpenId=function(){return Xn(this,void 0,Promise,function(){var t,e,n=this;return Zn(this,function(r){switch(r.label){case 0:if(!ut.default.isMatch())throw Error("wx api undefined");return t=wx.getAccountInfoSync().miniProgram,e=function(e){return Xn(n,void 0,void 0,function(){var n;return Zn(this,function(r){switch(r.label){case 0:n=void 0,r.label=1;case 1:return r.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:null==t?void 0:t.appId,provider_code:e,provider_params:{provider_code_type:"open_id",appid:null==t?void 0:t.appId}})];case 2:if((null==(n=r.sent())?void 0:n.error_code)||!n.provider_token)throw n;return[4,this.oauthInstance.authApi.bindWithProvider({provider_token:n.provider_token})];case 3:return r.sent(),[3,5];case 4:throw r.sent();case 5:return[2]}})})},[4,new Promise(function(t,r){wx.login({success:function(o){return Xn(n,void 0,void 0,function(){var n;return Zn(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,e(o.code)];case 1:return i.sent(),t(!0),[3,3];case 2:return n=i.sent(),r(n),[3,3];case 3:return[2]}})})},fail:function(t){var e=new Error(null==t?void 0:t.errMsg);e.code=null==t?void 0:t.errno,r(e)}})})];case 1:return r.sent(),[2]}})})},n.prototype.signInWithUnionId=function(){return Xn(this,void 0,Promise,function(){var t=this;return Zn(this,function(e){switch(e.label){case 0:if(!ut.default.isMatch())throw Error("wx api undefined");e.label=1;case 1:return e.trys.push([1,3,,4]),[4,new Promise(function(e,n){var r=wx.getAccountInfoSync().miniProgram;wx.login({success:function(o){return Xn(t,void 0,void 0,function(){var t,i,s,a,c;return Zn(this,function(u){switch(u.label){case 0:t=null==r?void 0:r.appId,u.label=1;case 1:return u.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_code:o.code,provider_id:t,provider_params:{provider_code_type:"union_id",appid:null==r?void 0:r.appId}})];case 2:return i=u.sent(),(s=i.provider_token)?[4,this.oauthInstance.authApi.signInWithProvider({provider_id:t,provider_token:s})]:(n(i),[2]);case 3:return(null==(a=u.sent())?void 0:a.error_code)?(n(a),[2]):(e(!0),[3,5]);case 4:return c=u.sent(),n(c),[3,5];case 5:return[2]}})})},fail:function(t){var e=new Error(null==t?void 0:t.errMsg);e.code=null==t?void 0:t.errno,n(e)}})})];case 2:return e.sent(),[3,4];case 3:throw e.sent();case 4:return[2,this.createLoginState()]}})})},n.prototype.signInWithSms=function(t){var e=t.verificationInfo,n=void 0===e?{verification_id:"",is_user:!1}:e,r=t.verificationCode,o=void 0===r?"":r,i=t.phoneNum,s=void 0===i?"":i,a=t.bindInfo,c=void 0===a?void 0:a;return Xn(this,void 0,Promise,function(){return Zn(this,function(t){try{return[2,this.signInWithUsername({verificationInfo:n,verificationCode:o,bindInfo:c,username:s,loginType:"sms"})]}catch(t){throw t}return[2]})})},n.prototype.signInWithEmail=function(t){var e=t.verificationInfo,n=void 0===e?{verification_id:"",is_user:!1}:e,r=t.verificationCode,o=void 0===r?"":r,i=t.bindInfo,s=void 0===i?void 0:i,a=t.email,c=void 0===a?"":a;return Xn(this,void 0,Promise,function(){return Zn(this,function(t){try{return[2,this.signInWithUsername({verificationInfo:n,verificationCode:o,bindInfo:s,username:c,loginType:"email"})]}catch(t){throw t}return[2]})})},n.prototype.setCustomSignFunc=function(t){this.oauthInstance.authApi.setCustomSignFunc(t)},n.prototype.signIn=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.authApi.signIn(t)];case 1:return e.sent(),[2,this.createLoginState(t)]}})})},n.prototype.setPassword=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.setPassword(t)]})})},n.prototype.isUsernameRegistered=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"username must be a string"),[4,this.oauthInstance.authApi.checkIfUserExist({username:t})];case 1:return[2,e.sent().exist]}})})},n.prototype.hasLoginState=function(){var t;if("async"!==this.cache.mode)return(null===(t=this.oauthInstance)||void 0===t?void 0:t.authApi.hasLoginStateSync())?new ar({envId:this.config.env,cache:this.cache,oauthInstance:this.oauthInstance}):null;(0,tn.printWarn)(Cn.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getLoginState instead")},n.prototype.getLoginState=function(){return Xn(this,void 0,Promise,function(){var t;return Zn(this,function(e){switch(e.label){case 0:t=null,e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.oauthInstance.authApi.getLoginState()];case 2:return t=e.sent(),[3,4];case 3:return e.sent(),[2,null];case 4:return t?[2,new ar({envId:this.config.env,cache:this.cache,oauthInstance:this.oauthInstance})]:[2,null]}})})},n.prototype.getUserInfo=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.getCurrentUser()]})})},n.prototype.getWedaUserInfo=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.getWedaUserInfo()]})})},n.prototype.updateUserBasicInfo=function(t){return Xn(this,void 0,void 0,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return[4,this.getLoginState()];case 1:return(e=n.sent())?[4,e.user.updateUserBasicInfo(t)]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}})})},n.prototype.getAuthHeader=function(){return console.error("Auth.getAuthHeader API 已废弃"),{}},n.prototype.bindWithProvider=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.bindWithProvider(t)]})})},n.prototype.queryUser=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.queryUserProfile(t)]})})},n.prototype.getAccessToken=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.oauth2client.getAccessToken()];case 1:return[2,{accessToken:t.sent(),env:this.config.env}]}})})},n.prototype.grantProviderToken=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.grantProviderToken(t)]})})},n.prototype.patchProviderToken=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.patchProviderToken(t)]})})},n.prototype.signInWithProvider=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.authApi.signInWithProvider(t)];case 1:return e.sent(),[2,this.createLoginState(t)]}})})},n.prototype.signInWithWechat=function(t){return void 0===t&&(t={}),Xn(this,void 0,void 0,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.authApi.signInWithWechat(t)];case 1:return e.sent(),[2,this.createLoginState(t)]}})})},n.prototype.grantToken=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.authApi.grantToken(t)];case 1:return e.sent(),[2,this.createLoginState()]}})})},n.prototype.genProviderRedirectUri=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.genProviderRedirectUri(t)]})})},n.prototype.resetPassword=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.resetPassword(t)]})})},n.prototype.deviceAuthorize=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.deviceAuthorize(t)]})})},n.prototype.sudo=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.sudo(t)]})})},n.prototype.deleteMe=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.deleteMe(t)]})})},n.prototype.getProviders=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.getProviders()]})})},n.prototype.loginScope=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.loginScope()]})})},n.prototype.loginGroups=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.loginGroups()]})})},n.prototype.onLoginStateChanged=function(t){var e;return Xn(this,void 0,void 0,function(){var n,r=this;return Zn(this,function(o){switch(o.label){case 0:return null===(e=this.config.eventBus)||void 0===e||e.on(Se,function(e){return Xn(r,void 0,void 0,function(){var n,r,o;return Zn(this,function(i){switch(i.label){case 0:return(null===(o=null==e?void 0:e.data)||void 0===o?void 0:o.eventType)===ge?[3,2]:[4,this.getLoginState()];case 1:return r=i.sent(),[3,3];case 2:r={},i.label=3;case 3:return n=r,t.call(this,$n($n({},e),n)),[2]}})})}),[4,this.getLoginState()];case 1:return n=o.sent(),t.call(this,n),[2]}})})},n.prototype.refreshTokenForce=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.refreshTokenForce(t)]})})},n.prototype.getCredentials=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.getCredentials()]})})},n.prototype.setCredentials=function(t){return Xn(this,void 0,void 0,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.oauth2client.setCredentials(t)];case 1:return e.sent(),[2]}})})},n.prototype.getProviderSubType=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.getProviderSubType()]})})},n.prototype.createCaptchaData=function(t){return Xn(this,void 0,void 0,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.createCaptchaData(t)]})})},n.prototype.verifyCaptchaData=function(t){return Xn(this,void 0,void 0,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.verifyCaptchaData(t)]})})},n.prototype.getMiniProgramQrCode=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.getMiniProgramCode(t)]})})},n.prototype.getMiniProgramQrCodeStatus=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.getMiniProgramQrCodeStatus(t)]})})},n.prototype.modifyPassword=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.modifyPassword(t)]})})},n.prototype.modifyPasswordWithoutLogin=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.modifyPasswordWithoutLogin(t)]})})},n.prototype.getUserBehaviorLog=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.getUserBehaviorLog(t)]})})},n.prototype.signInWithUsername=function(t){var e=t.verificationInfo,n=void 0===e?{verification_id:"",is_user:!1}:e,r=t.verificationCode,o=void 0===r?"":r,i=t.username,s=void 0===i?"":i,a=t.bindInfo,c=void 0===a?void 0:a,u=t.loginType,l=void 0===u?"":u;return Xn(this,void 0,Promise,function(){var t,e,r,i,a,u,h;return Zn(this,function(d){switch(d.label){case 0:return d.trys.push([0,8,,9]),[4,this.oauthInstance.authApi.verify({verification_id:n.verification_id,verification_code:o})];case 1:if(null==(t=d.sent())?void 0:t.error_code)throw t;return e=t.verification_token,r=this.formatPhone(s),i={phone_number:r},"email"===l&&(i={email:r=s}),n.is_user?[4,this.oauthInstance.authApi.signIn({username:r,verification_token:e})]:[3,5];case 2:if(null==(a=d.sent())?void 0:a.error_code)throw a;return c?[4,this.oauthInstance.authApi.bindWithProvider({provider_token:null==c?void 0:c.providerToken})]:[3,4];case 3:if(null==(u=d.sent())?void 0:u.error_code)throw u;d.label=4;case 4:return[3,7];case 5:return[4,this.oauthInstance.authApi.signUp($n($n({},i),{verification_token:e,provider_token:null==c?void 0:c.providerId}))];case 6:if(null==(h=d.sent())?void 0:h.error_code)throw h;d.label=7;case 7:return[2,this.createLoginState()];case 8:throw d.sent();case 9:return[2]}})})},n.prototype.createLoginState=function(t,e){return Xn(this,void 0,Promise,function(){var n;return Zn(this,function(r){switch(r.label){case 0:return[4,(n=new ar({envId:this.config.env,cache:this.cache,oauthInstance:this.oauthInstance})).checkLocalStateAsync()];case 1:return r.sent(),(null==e?void 0:e.userInfo)?(n.user.setLocalUserInfo(e.userInfo),[3,5]):[3,2];case 2:return(null==e?void 0:e.asyncRefreshUser)?(n.user.refresh(t),[3,5]):[3,3];case 3:return[4,n.user.refresh(t)];case 4:r.sent(),r.label=5;case 5:return[2,n]}})})},n.prototype.setAccessKey=function(){var t,e;return Xn(this,void 0,void 0,function(){var n,r;return Zn(this,function(o){if(n="",r="",this.config.accessKey?(n=this.config.accessKey,r="accessKey"):(null===(t=this.config.auth)||void 0===t?void 0:t.secretId)&&(null===(e=this.config.auth)||void 0===e?void 0:e.secretKey)&&(n="",r=Pe),!r)return[2];try{this.oauthInstance.oauth2client.setAccessKeyCredentials({access_token:n,token_type:"Bearer",scope:r,expires_at:new Date(+new Date+ +new Date),expires_in:+new Date+ +new Date})}catch(t){console.warn("accessKey error: ",t)}return[2]})})},n.prototype.formatPhone=function(t){return!/\s+/.test(t)&&/^\+\d{1,3}\d+/.test(t)?t.replace(/^(\+\d{1,2})(\d+)$/,"$1 $2"):/^\+\d{1,3}\s+/.test(t)?t:"+86 ".concat(t)},n.prototype.notifyListeners=function(t,e,n){this.listeners.forEach(function(r){r.forEach(function(r){try{r(t,e,n)}catch(t){console.error("Error in auth state change callback:",t)}})})},n.prototype.setupListeners=function(){var t,e=this;null===(t=this.config.eventBus)||void 0===t||t.on(Oe,function(t){return Xn(e,void 0,void 0,function(){var e,n,r,o,i,s,a;return Zn(this,function(c){switch(c.label){case 0:return e=null===(s=null==t?void 0:t.data)||void 0===s?void 0:s.event,n=null===(a=null==t?void 0:t.data)||void 0===a?void 0:a.info,e!==be||n?[3,2]:[4,this.getUser(!0)];case 1:r=c.sent().data,(o=(void 0===r?{}:r).user)&&(n={user:o}),c.label=2;case 2:return[4,this.getSession()];case 3:return i=c.sent().data.session,this.notifyListeners(e,i,n),[2]}})})})},n.prototype.convertToUser=function(t){var e,n,r,o,i,s;if(!t)return null;var a=(null==t?void 0:t.email)||"",c=(null==t?void 0:t.phone_number)||"",u=(null==t?void 0:t.sub)||(null==t?void 0:t.uid)||"";return{id:u,aud:"authenticated",role:null===(n=null===(e=t.groups)||void 0===e?void 0:e.map)||void 0===n?void 0:n.call(e,function(t){return"string"==typeof t?t:t.id}),email:a||"",email_confirmed_at:(null==t||t.email_verified,t.created_at),phone:c,phone_confirmed_at:c?t.created_at:void 0,confirmed_at:t.created_at,last_sign_in_at:t.last_sign_in_at,app_metadata:{provider:(null===(r=t.loginType)||void 0===r?void 0:r.toLowerCase())||"cloudbase",providers:[(null===(o=t.loginType)||void 0===o?void 0:o.toLowerCase())||"cloudbase"]},user_metadata:{name:null==t?void 0:t.name,picture:null==t?void 0:t.picture,username:null==t?void 0:t.username,gender:null==t?void 0:t.gender,locale:null==t?void 0:t.locale,uid:t.uid,nickName:t.nickName||(null==t?void 0:t.name),avatarUrl:t.avatarUrl||t.picture,location:t.location,hasPassword:null!==(i=t.hasPassword)&&void 0!==i?i:"SET"===t.password,open_id:null==t?void 0:t.open_id},identities:(null===(s=null==t?void 0:t.providers)||void 0===s?void 0:s.map(function(e){return{id:e.id||"",identity_id:e.id||"",user_id:u,identity_data:{provider_id:e.id,provider_user_id:e.provider_user_id,name:e.name},provider:e.id||"cloudbase",created_at:t.created_at,updated_at:t.updated_at,last_sign_in_at:t.last_sign_in_at}}))||[],created_at:t.created_at,updated_at:t.updated_at,is_anonymous:"anonymous"===t.name}},n.prototype.missingRequiredParam=function(t,e){return new En({error:"missing_required_param",error_code:4e3,error_description:"auth.".concat(t,"(params): missing required param '").concat(e,"'")},{method:t})},n.prototype.validateParams=function(t,e,n){for(var r=0,o=Object.entries(e);r<o.length;r++){var i=o[r],s=i[0];if(i[1].required&&(void 0===(null==t?void 0:t[s])||null===(null==t?void 0:t[s])||""===(null==t?void 0:t[s])))throw this.missingRequiredParam(n,s)}},n.prototype.validateAtLeastOne=function(t,e,n){if(!e.some(function(e){return e.some(function(e){return void 0!==(null==t?void 0:t[e])&&null!==(null==t?void 0:t[e])&&""!==(null==t?void 0:t[e])})}))throw this.missingRequiredParam(n,e.map(function(t){return t.join("|")}).join("|"))},n.prototype.init=function(){var t;return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.oauthInstance.oauth2client.localCredentials.getCredentials()];case 1:return e.sent()&&!this.oauthInstance.oauth2client.initSessionEmitted&&(null===(t=this.config.eventBus)||void 0===t||t.fire(Oe,{event:we})),[3,3];case 2:return e.sent(),[3,3];case 3:return[2,{error:null}]}})})},Yn([(0,kn.catchErrorsDecorator)({title:"绑定手机号失败",messages:["请确认以下各项:"," 1 - 调用 auth().bindPhoneNumber() 的语法或参数是否正确"," 2 - 当前环境是否开通了短信验证码登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(r=t.BindPhoneRequest)?r:Object]),Qn("design:returntype",Promise)],n.prototype,"bindPhoneNumber",null),Yn([(0,kn.catchErrorsDecorator)({title:"解除三方绑定失败",messages:["请确认以下各项:"," 1 - 调用 auth().unbindProvider() 的语法或参数是否正确"," 2 - 当前账户是否已经与此登录方式解绑","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(o=t.UnbindProviderRequest)?o:Object]),Qn("design:returntype","function"==typeof(i="undefined"!=typeof Promise&&Promise)?i:Object)],n.prototype,"unbindProvider",null),Yn([(0,kn.catchErrorsDecorator)({title:"绑定邮箱地址失败",messages:["请确认以下各项:"," 1 - 调用 auth().bindEmail() 的语法或参数是否正确"," 2 - 当前环境是否开通了邮箱密码登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(s=t.BindEmailRequest)?s:Object]),Qn("design:returntype",void 0)],n.prototype,"bindEmail",null),Yn([(0,kn.catchErrorsDecorator)({title:"验证码验证失败",messages:["请确认以下各项:"," 1 - 调用 auth().verify() 的语法或参数是否正确"," 2 - 当前环境是否开通了手机验证码/邮箱登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(a=t.VerifyRequest)?a:Object]),Qn("design:returntype","function"==typeof(c="undefined"!=typeof Promise&&Promise)?c:Object)],n.prototype,"verify",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取验证码失败",messages:["请确认以下各项:"," 1 - 调用 auth().getVerification() 的语法或参数是否正确"," 2 - 当前环境是否开通了手机验证码/邮箱登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(u=t.GetVerificationRequest)?u:Object,Object]),Qn("design:returntype","function"==typeof(l="undefined"!=typeof Promise&&Promise)?l:Object)],n.prototype,"getVerification",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取用户信息失败",messages:["请确认以下各项:"," 1 - 调用 auth().getCurrentUser() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[Object]),Qn("design:returntype","function"==typeof(h="undefined"!=typeof Promise&&Promise)?h:Object)],n.prototype,"getCurrentUser",null),Yn([(0,kn.catchErrorsDecorator)({title:"小程序匿名登录失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了匿名登录"," 2 - 调用 auth().signInAnonymouslyInWx() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[Object]),Qn("design:returntype","function"==typeof(d="undefined"!=typeof Promise&&Promise)?d:Object)],n.prototype,"signInAnonymouslyInWx",null),Yn([(0,kn.catchErrorsDecorator)({title:"小程序绑定OpenID失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序openId静默登录"," 2 - 调用 auth().bindOpenId() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(f="undefined"!=typeof Promise&&Promise)?f:Object)],n.prototype,"bindOpenId",null),Yn([(0,kn.catchErrorsDecorator)({title:"小程序unionId静默登录失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序unionId静默登录"," 2 - 调用 auth().signInWithUnionId() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(p="undefined"!=typeof Promise&&Promise)?p:Object)],n.prototype,"signInWithUnionId",null),Yn([(0,kn.catchErrorsDecorator)({title:"短信验证码登陆",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序短信验证码登陆"," 2 - 调用 auth().signInWithSms() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[Object]),Qn("design:returntype","function"==typeof(v="undefined"!=typeof Promise&&Promise)?v:Object)],n.prototype,"signInWithSms",null),Yn([(0,kn.catchErrorsDecorator)({title:"邮箱验证码登陆",messages:["请确认以下各项:"," 1 - 当前环境是否开启了邮箱登陆"," 2 - 调用 auth().signInWithEmail() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[Object]),Qn("design:returntype","function"==typeof(y="undefined"!=typeof Promise&&Promise)?y:Object)],n.prototype,"signInWithEmail",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取用户是否被占用失败",messages:["请确认以下各项:"," 1 - 调用 auth().isUsernameRegistered() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[String]),Qn("design:returntype","function"==typeof(g="undefined"!=typeof Promise&&Promise)?g:Object)],n.prototype,"isUsernameRegistered",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取本地登录态失败",messages:["请确认以下各项:"," 1 - 调用 auth().getLoginState() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(m="undefined"!=typeof Promise&&Promise)?m:Object)],n.prototype,"getLoginState",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取用户信息失败",messages:["请确认以下各项:"," 1 - 是否已登录"," 2 - 调用 auth().getUserInfo() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(b="undefined"!=typeof Promise&&Promise)?b:Object)],n.prototype,"getUserInfo",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取微搭插件用户信息失败",messages:["请确认以下各项:"," 1 - 是否已登录"," 2 - 调用 auth().getWedaUserInfo() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(w="undefined"!=typeof Promise&&Promise)?w:Object)],n.prototype,"getWedaUserInfo",null),Yn([(0,kn.catchErrorsDecorator)({title:"绑定第三方登录方式失败",messages:["请确认以下各项:"," 1 - 调用 auth().bindWithProvider() 的语法或参数是否正确"," 2 - 此账户是否已经绑定此第三方","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(_=t.BindWithProviderRequest)?_:Object]),Qn("design:returntype","function"==typeof(E="undefined"!=typeof Promise&&Promise)?E:Object)],n.prototype,"bindWithProvider",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取身份源类型",messages:["请确认以下各项:"," 1 - 调用 auth().getProviderSubType() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(I="undefined"!=typeof Promise&&Promise)?I:Object)],n.prototype,"getProviderSubType",null),n}(Jn),ur="auth";function lr(t,e){for(var n=[],r=0;r<=t.length;r++)n[r]=[r];for(var o=0;o<=e.length;o++)n[0][o]=o;for(r=1;r<=t.length;r++)for(o=1;o<=e.length;o++){var i=t[r-1].toLowerCase()===e[o-1].toLowerCase()?0:1;n[r][o]=Math.min(n[r-1][o]+1,n[r][o-1]+1,n[r-1][o-1]+i)}return n[t.length][e.length]}var hr={name:"auth",namespace:ur,entity:function(t){var e=function(t){var e,n=this;if(this.authInstance&&!t)return this.authInstance;t=t||{region:"",persistence:"local",apiPath:pe};var r=this.platform.adapter,o=t.persistence||r.primaryStorage;o&&o!==this.config.persistence&&this.updateConfig({persistence:o});var i=function(t,e){var n,r,o,i,s=this,a=t.region,c=void 0===a?"ap-shanghai":a,u=t.i18n,l=t.accessKey,h=t.useWxCloud,d=(null==e?void 0:e.platform)||xn.useDefaultAdapter.bind(e)(),f=d.runtime,p=d.adapter,v=e||{},y=v.env,g=v.clientId,m=v.debug,b=v.cache,w=v.app,_=v.getApiOrigin,E=(e||{}).apiOrigin;E||(E="https://".concat(y,".").concat(c,".tcb-api.tencentcloudapi.com"));var I={env:y,clientId:g,i18n:u,accessKey:l,useWxCloud:h,eventBus:new Ze.CloudbaseEventEmitter},S=new Rn(Bn($n($n({},I),{apiOrigin:E,getApiOrigin:_,apiPath:(null==t?void 0:t.apiPath)||pe,storage:null==t?void 0:t.storage,baseRequest:null==t?void 0:t.baseRequest,request:null==t?void 0:t.request,anonymousSignInFunc:null==t?void 0:t.anonymousSignInFunc,captchaOptions:null==t?void 0:t.captchaOptions,wxCloud:null==t?void 0:t.wxCloud,adapter:p,onCredentialsError:er(I.eventBus),headers:$n({"X-SDK-Version":"@cloudbase/js-sdk/".concat(t.sdkVersion)},t.headers||{}),detectSessionInUrl:t.detectSessionInUrl,debug:m,auth:null===(r=null===(n=e.app)||void 0===n?void 0:n.config)||void 0===r?void 0:r.auth}))),O=new cr($n($n({},I),{region:c,persistence:t.persistence,debug:m,cache:b||new Nn.CloudbaseCache({persistence:t.persistence,keys:{userInfoKey:"user_info_".concat(y)},platformInfo:d}),runtime:f||"web",_fromApp:w,oauthInstance:S,auth:null===(i=null===(o=e.app)||void 0===o?void 0:o.config)||void 0===i?void 0:i.auth}));return S.initializeSession(function(t,e){return Xn(s,void 0,void 0,function(){return Zn(this,function(n){return t?(t.type===Te?e?I.eventBus.fire(Oe,{event:be,info:$n($n({},t),{error:e})}):t.user&&O.createLoginState({},{userInfo:t.user}):t.type===Ae&&I.eventBus.fire(Oe,{event:Ie,info:$n($n({},t),{error:e})}),[2]):[2]})})}),{authInstance:O,oauthInstance:S}}($n($n({wxCloud:this.config.wxCloud,storage:this.config.storage},t),{persistence:this.config.persistence,i18n:this.config.i18n,accessKey:this.config.accessKey,useWxCloud:this.config.useWxCloud,sdkVersion:this.version,detectSessionInUrl:null===(e=this.config.auth)||void 0===e?void 0:e.detectSessionInUrl}),{env:this.config.env,clientId:this.config.clientId,getApiOrigin:function(){return n.request.getBaseEndPoint(n.config.endPointMode||"CLOUD_API")},platform:this.platform,cache:this.cache,app:this,debug:this.config.debug}),s=i.authInstance,a=i.oauthInstance;return this.oauthInstance=a,this.authInstance=s,this.authInstance},n=e.call(this,t);Object.assign(e,n),Object.setPrototypeOf(e,Object.getPrototypeOf(n));var r="undefined"!=typeof Proxy?new Proxy(e,{get:function(t,e,n){var r=Reflect.get(t,e,n);if(void 0!==r||"string"!=typeof e)return r;var o=function(t,e){for(var n=null,r=1/0,o=0,i=e;o<i.length;o++){var s=i[o];if(!s.startsWith("_")&&"constructor"!==s){var a=lr(t,s);a<r&&(r=a,n=s)}}return n}(e,Object.getOwnPropertyNames(Object.getPrototypeOf(t)).concat(Object.keys(t)).filter(function(e){return"function"==typeof t[e]}));return o&&console.warn("[CloudBase Auth] auth.".concat(e," is not a function. Did you mean: auth.").concat(o,"() ?")),r}}):e;return this[ur]=r,r}};try{cloudbase.registerComponent(hr)}catch(t){}var dr=l(3388),fr=function(){return fr=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},fr.apply(this,arguments)},pr=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},vr=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},yr=g,gr="cloudrun",mr=function(){function t(){}return t.prototype.callContainer=function(t,e){return pr(this,void 0,void 0,function(){var n,r,o;return vr(this,function(i){switch(i.label){case 0:if(n=t.name,r=t.data,!n)throw new Error(JSON.stringify({code:yr.INVALID_PARAMS,msg:"[".concat(gr,".callContainer] invalid name")}));try{o=r?JSON.stringify(r):""}catch(t){throw new Error(JSON.stringify({code:yr.INVALID_PARAMS,msg:"[".concat(gr,".callContainer] invalid data")}))}return[4,br.call(this,fr(fr({},t),{data:o}),e)];case 1:return[2,i.sent()]}})})},t}();function br(t,e){var n;return pr(this,void 0,void 0,function(){var r,o,i,s,a,c,u,l,h,d,f,p,v,y,g;return vr(this,function(m){switch(m.label){case 0:if(r=t.name,o=t.data,i=t.path,s=void 0===i?"":i,a=t.method,c=t.header,u=void 0===c?{}:c,l=this.getEndPointWithKey("GATEWAY"),h=l.BASE_URL,d=l.PROTOCOL,f="".concat(d).concat(h,"/cloudrun/").concat(r),p=s.startsWith("/")?s:"/".concat(s),v=["GET","HEAD"].includes(null===(n=null==a?void 0:a.toUpperCase)||void 0===n?void 0:n.call(a)))try{y={};try{y=JSON.parse(o)}catch(t){y=o||{}}p="".concat(p).concat(p.includes("?")?"&":"?").concat(Object.keys(y).map(function(t){return"".concat(t,"=").concat(y[t])}).join("&"))}catch(t){}return[4,this.request.fetch(fr(fr({method:a||"POST",headers:Object.assign({},{"Content-Type":"application/json; charset=utf-8"},u)},v?{}:{body:o}),{url:"".concat(f).concat(p),customReqOpts:e}))];case 1:return g=m.sent(),"node-sdk"===(null==e?void 0:e.from)?[2,g]:[4,g.data];case 2:return[2,m.sent()]}})})}var wr=new mr,_r={name:gr,entity:{callContainer:wr.callContainer}};try{cloudbase.registerComponent(_r)}catch(t){}function Er(t){try{t.registerComponent(_r)}catch(t){console.warn(t)}}try{window.registerCloudrun=Er}catch(t){}var Ir=function(){return Ir=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ir.apply(this,arguments)},Sr=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},Or=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Tr=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Ar=f,Pr=g,Rr=y,Cr=A,kr=x,Nr=et,xr="functions";function Ur(t){return t.length<=1024?t:"".concat(t.slice(0,1024),"…")}function Lr(t,e){return{code:(null==t?void 0:t.code)||Pr.NETWORK_ERROR,message:(null==t?void 0:t.message)||(null==t?void 0:t.msg)||"",requestId:e}}function Dr(t,e){if(t&&"object"==typeof t&&!Array.isArray(t))return Lr(t,e);if("string"==typeof t){try{var n=JSON.parse(t);if(n&&"object"==typeof n&&!Array.isArray(n))return Lr(n,e)}catch(t){}return{code:Pr.NETWORK_ERROR,message:Ur(t),requestId:e}}return{code:Pr.NETWORK_ERROR,message:Ur(null==t?"":String(t)),requestId:e}}var jr=function(){function t(){}var e,n,r;return t.invokeCloudrun=function(t,e,n){return Or(this,void 0,void 0,function(){var r,o,i,s,a,c,u;return Tr(this,function(l){switch(l.label){case 0:return r=e.name,o=e.path,i=void 0===o?"":o,s=e.method,a=e.header,c=void 0===a?{}:a,u=S(),[4,br.call(t,{name:r,data:n,path:i,method:s,header:Ir(Ir({},c),{"X-Request-Id":u})})];case 1:return[2,{result:l.sent(),requestId:u}]}})})},t.invokeGateway=function(t,e,n,r){return Or(this,void 0,void 0,function(){var o,i,s,a,c;return Tr(this,function(u){switch(u.label){case 0:o=t.request,i=t.config,u.label=1;case 1:return u.trys.push([1,3,,4]),[4,o.gateWay(Ir(Ir({},e),{path:"functions",shouldThrowOnError:!1}),r)];case 2:return s=u.sent(),[3,4];case 3:return a=u.sent(),function(t){if(!t)return!1;if(t instanceof SyntaxError||"SyntaxError"===t.name)return!0;var e=String(t.message||"");return/not valid JSON|Unexpected token|JSON\.parse|Failed to execute 'json'/i.test(e)}(c=a)?[2,kr(i,Dr(c.message,c.requestId))]:[2,Cr(n,c)];case 4:return Number(null==s?void 0:s.statusCode)>=400?[2,kr(i,Dr(null==s?void 0:s.data,null==s?void 0:s.requestId))]:[2,Cr(n,null,{requestId:null==s?void 0:s.requestId,result:null==s?void 0:s.data})]}})})},t.invokeCloudApi=function(t,e,n,r,o){var i,s,a;return Or(this,void 0,void 0,function(){var c,u,l,h,d,f,p;return Tr(this,function(v){switch(v.label){case 0:return c=e.name,u=e.data,l=e.query,h=e.parse,d=e.search,[4,t.request.send("functions.invokeFunction",{inQuery:l,parse:h,search:d,function_name:c,request_data:n},{endPointMode:"CLOUD_API",defaultQuery:(null===(i=null==u?void 0:u.params)||void 0===i?void 0:i.action)?{action:null===(s=null==u?void 0:u.params)||void 0===s?void 0:s.action}:{}},o)];case 1:if(f=v.sent(),void 0===(p=null===(a=f.data)||void 0===a?void 0:a.response_data))return[2,Cr(r,null,f)];if(h)return[2,Cr(r,null,{result:p,requestId:f.requestId})];try{return p=JSON.parse(p),[2,Cr(r,null,{result:p,requestId:f.requestId})]}catch(t){return[2,Cr(r,new Error("[".concat(Ar(),"][").concat(Pr.INVALID_PARAMS,"][").concat(xr,".callFunction] response data must be json")))]}return[2]}})})},t.prototype.callFunction=function(e,n,r){return Or(this,void 0,void 0,function(){var o,i,s,a,c,u;return Tr(this,function(l){switch(l.label){case 0:if(o=e.name,i=e.data,s=e.type,a=this.config,!o)return[2,kr(a,{code:Pr.INVALID_PARAMS,message:"[".concat(xr,".callFunction] invalid function name")})];try{c=i?JSON.stringify(i):""}catch(t){return[2,kr(a,{code:Pr.INVALID_PARAMS,message:"[".concat(xr,".callFunction] invalid data")})]}if("cloudrun"===s)return[2,t.invokeCloudrun(this,e,c)];l.label=1;case 1:return l.trys.push([1,5,,6]),function(t,e){return"GATEWAY"===t.endPointMode&&!function(t){return"lcap-common-service"===t||"lcap-datasource-test"===t||t.startsWith("lcap-data")||t.startsWith("lowcode-datasource")||"cloudbase_module"===t}(e)&&!function(t){return"lowcode-wx-datasource"===t}(e)}(a,o)?[4,t.invokeGateway(this,e,n,r)]:[3,3];case 2:return[2,l.sent()];case 3:return[4,t.invokeCloudApi(this,e,c,n,r)];case 4:return[2,l.sent()];case 5:return u=l.sent(),Cr(n,u),[3,6];case 6:return[2]}})})},function(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);i>3&&s&&Object.defineProperty(e,n,s)}([Nr({customInfo:{className:"Cloudbase",methodName:"callFunction"},title:"函数调用失败",messages:["请确认以下各项:"," 1 - 调用 callFunction() 的语法或参数是否正确"," 2 - 当前环境下是否存在此函数"," 3 - 函数安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Rr)]}),Sr("design:type",Function),Sr("design:paramtypes",["function"==typeof(e=void 0!==dr.ICallFunctionOptions&&dr.ICallFunctionOptions)?e:Object,"function"==typeof(n="undefined"!=typeof Function&&Function)?n:Object,"function"==typeof(r=void 0!==dr.ICustomReqOpts&&dr.ICustomReqOpts)?r:Object]),Sr("design:returntype",Promise)],t.prototype,"callFunction",null),t}(),qr=new jr,Mr={name:xr,entity:{callFunction:qr.callFunction}};try{cloudbase.registerComponent(Mr)}catch(t){}var Br=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Wr=function(t){function e(e){var n=t.call(this,e)||this;return n.__isStorageError=!0,n.name="StorageError",n}return Br(e,t),e}(Error);function Fr(t){return"object"==typeof t&&null!==t&&"__isStorageError"in t}var Hr,Vr=function(t){function e(e,n,r){var o=t.call(this,e)||this;return o.name="StorageApiError",o.status=n,o.statusCode=r,o}return Br(e,t),e.prototype.toJSON=function(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}},e}(Wr);function Gr(){return globalThis.Buffer}function Kr(t){var e=Gr();return e?e.from(t).toString("base64"):btoa(t)}function Jr(t){return t.split("/").map(function(t){return encodeURIComponent(t)}).join("/")}Br(function(t,e){var n=Hr.call(this,t)||this;return n.name="StorageUnknownError",n.originalError=e,n},Hr=Wr);var zr=function(){return zr=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},zr.apply(this,arguments)},$r=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Yr=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Qr="/v1/storages";function Xr(t,e){return $r(this,void 0,Promise,function(){var n;return Yr(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,t()];case 1:return[2,{data:r.sent(),error:null}];case 2:if(n=r.sent(),e)throw n;return Fr(n)?[2,{data:null,error:n}]:[2,{data:null,error:new Wr((null==n?void 0:n.message)||String(n))}];case 3:return[2]}})})}var Zr=function(){function t(t){this.ctx=t}return Object.defineProperty(t.prototype,"request",{get:function(){return this.ctx.request},enumerable:!1,configurable:!0}),t.prototype.gatewayOrigin=function(){return this.request.getBaseEndPoint("GATEWAY")},t.prototype.buildUrl=function(t,e){var n="".concat(this.gatewayOrigin()).concat(Qr).concat(t),r=function(t){if(!t)return"";var e=[];return Object.keys(t).forEach(function(n){var r=t[n];null!=r&&e.push("".concat(encodeURIComponent(n),"=").concat(encodeURIComponent(String(r))))}),e.join("&")}(e);return r&&(n+=(n.includes("?")?"&":"?")+r),n},t.prototype.toFullUrl=function(t){return t?/^https?:\/\//.test(t)||t.startsWith("//")?t:"".concat(this.gatewayOrigin()).concat(Qr).concat(t.startsWith("/")?"":"/").concat(t):t},t.prototype.send=function(t){return $r(this,void 0,Promise,function(){var e,n,r,o,i,s;return Yr(this,function(a){switch(a.label){case 0:return e=this.buildUrl(t.path,t.query),n=t.method.toUpperCase(),r=["GET","HEAD"].includes(n),o=zr({},t.headers||{}),r||(void 0!==t.rawBody?i=t.rawBody:void 0!==t.json&&(o["Content-Type"]=o["Content-Type"]||"application/json",i=JSON.stringify(t.json))),[4,this.request.fetch(zr(zr(zr(zr({url:e,method:n,headers:o},void 0!==i?{body:i}:{}),{withCredentials:!1!==t.withCredentials,shouldThrowOnError:!1}),t.signal?{signal:t.signal}:{}),t.cache?{cache:t.cache}:{}))];case 1:return s=a.sent(),[2,this.unwrap(s,e)]}})})},t.prototype.download=function(t){var e,n;return $r(this,void 0,Promise,function(){var r,o,i,s;return Yr(this,function(a){switch(a.label){case 0:return r=this.buildUrl(t.path,t.query),[4,this.request.fetch(zr(zr({url:r,method:"GET",headers:zr({},t.headers||{}),stream:!0,withCredentials:!1!==t.withCredentials,shouldThrowOnError:!1},t.signal?{signal:t.signal}:{}),t.cache?{cache:t.cache}:{}))];case 1:if(o=a.sent(),null===(e=t.signal)||void 0===e?void 0:e.aborted)throw new Vr("The download was aborted",0,"STORAGE_PG_ABORTED");if(304===(i=Number(null!==(n=null==o?void 0:o.statusCode)&&void 0!==n?n:200)))throw new Vr("Not Modified",i,"STORAGE_PG_NOT_MODIFIED");if(i>=400)throw new Vr("Download failed with status ".concat(i),i,"STORAGE_PG_REQUEST_FAIL");if(!(s=null==o?void 0:o.response))throw new Vr("Underlying adapter did not expose the raw Response",i,"STORAGE_PG_NO_RESPONSE");return[2,{response:s,status:i,header:null==o?void 0:o.header}]}})})},t.prototype.unwrap=function(t,e){var n,r;return $r(this,void 0,Promise,function(){var o,i,s,a;return Yr(this,function(c){switch(c.label){case 0:o=Number(null!==(r=null!==(n=null==t?void 0:t.statusCode)&&void 0!==n?n:null==t?void 0:t.status)&&void 0!==r?r:200),i=null==t?void 0:t.data,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,i];case 2:return i=c.sent(),[3,4];case 3:return c.sent(),i=void 0,[3,4];case 4:if(o>=200&&o<300)return[2,i];throw s=(null==i?void 0:i.code)||(null==i?void 0:i.error)||"STORAGE_PG_REQUEST_FAIL",a=(null==i?void 0:i.message)||"Storage request failed with status ".concat(o,": ").concat(e),new Vr(a,o,s)}})})},t}(),to=function(){return to=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},to.apply(this,arguments)},eo=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},no=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function ro(t){return Fr(t)?t:new Wr((null==t?void 0:t.message)||String(t))}function oo(t){var e={};return void 0!==(null==t?void 0:t.download)&&(e.download=!0===t.download?"":t.download),void 0!==(null==t?void 0:t.cacheNonce)&&(e.cacheNonce=String(t.cacheNonce)),{headers:{},query:e}}var io=function(){function t(t){this.ctx=t}return t.prototype.then=function(t,e){return this.execute().then(t,e)},t.prototype.execute=function(){var t,e;return eo(this,void 0,Promise,function(){var n,r,o,i,s;return no(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),n=oo(this.ctx.options),r=n.headers,o=n.query,[4,this.ctx.http.download({path:"/object/".concat(this.ctx.bucketId,"/").concat(Jr(this.ctx.cleanName)),headers:to(to({},this.ctx.headers),r),query:o,signal:null===(t=this.ctx.parameters)||void 0===t?void 0:t.signal,cache:null===(e=this.ctx.parameters)||void 0===e?void 0:e.cache})];case 1:if(!(i=a.sent().response).body)throw new Vr("Response body is empty",i.status,"STORAGE_PG_EMPTY_BODY");return[2,{data:i.body,error:null}];case 2:if(s=a.sent(),this.ctx.shouldThrowOnError)throw s;return[2,{data:null,error:ro(s)}];case 3:return[2]}})})},t}(),so=function(){function t(t){this.ctx=t}return t.prototype.asStream=function(){return new io(this.ctx)},t.prototype.then=function(t,e){return this.execute().then(t,e)},t.prototype.execute=function(){var t,e;return eo(this,void 0,Promise,function(){var n,r,o,i,s,a;return no(this,function(c){switch(c.label){case 0:return c.trys.push([0,3,,4]),n=oo(this.ctx.options),r=n.headers,o=n.query,[4,this.ctx.http.download({path:"/object/".concat(this.ctx.bucketId,"/").concat(Jr(this.ctx.cleanName)),headers:to(to({},this.ctx.headers),r),query:o,signal:null===(t=this.ctx.parameters)||void 0===t?void 0:t.signal,cache:null===(e=this.ctx.parameters)||void 0===e?void 0:e.cache})];case 1:return i=c.sent().response,a={},[4,i.blob()];case 2:return[2,(a.data=c.sent(),a.error=null,a)];case 3:if(s=c.sent(),this.ctx.shouldThrowOnError)throw s;return[2,{data:null,error:ro(s)}];case 4:return[2]}})})},t}(),ao=function(){return ao=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ao.apply(this,arguments)},co=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},uo=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},lo="3600",ho=function(){function t(t,e,n){void 0===n&&(n=!1),this.headers={},this.http=t,this.bucketId=e,this.shouldThrowOnError=n}return t.prototype.throwOnError=function(){return this.shouldThrowOnError=!0,this},t.prototype.setHeader=function(t,e){var n;if("string"!=typeof t||""===t.trim())throw new Wr("setHeader requires a non-empty header name");if(/[\r\n]/.test(t)||"string"==typeof e&&/[\r\n]/.test(e))throw new Wr("setHeader does not allow CR/LF characters in header name or value");return this.headers=ao(ao({},this.headers),((n={})[t]=String(e),n)),this},t.prototype.upload=function(t,e,n){return co(this,void 0,Promise,function(){return uo(this,function(r){return[2,this.uploadOrUpdate("POST",t,e,n)]})})},t.prototype.update=function(t,e,n){return co(this,void 0,Promise,function(){return uo(this,function(r){return[2,this.uploadOrUpdate("PUT",t,e,n)]})})},t.prototype.download=function(t,e,n){return new so({http:this.http,bucketId:this.bucketId,cleanName:this.cleanPath(t),options:e,parameters:n,headers:this.headers,shouldThrowOnError:this.shouldThrowOnError})},t.prototype.list=function(t,e,n){return co(this,void 0,Promise,function(){var r=this;return uo(this,function(o){return[2,Xr(function(){return co(r,void 0,void 0,function(){var r;return uo(this,function(o){return r={prefix:t||""},void 0!==(null==e?void 0:e.limit)&&(r.limit=e.limit),void 0!==(null==e?void 0:e.cursor)&&(r.cursor=e.cursor),void 0!==(null==e?void 0:e.withDelimiter)&&(r.with_delimiter=e.withDelimiter),void 0!==(null==e?void 0:e.sortBy)&&(r.sortBy=e.sortBy),[2,this.send({method:"POST",path:"/object/list/".concat(this.bucketId),json:r,signal:null==n?void 0:n.signal,cache:null==n?void 0:n.cache})]})})},this.shouldThrowOnError)]})})},t.prototype.remove=function(t){return co(this,void 0,Promise,function(){var e=this;return uo(this,function(n){return[2,Xr(function(){return co(e,void 0,void 0,function(){var e,n,r,o,i,s=this;return uo(this,function(a){switch(a.label){case 0:e=t.map(function(t){return s.cleanPath(t)}),n=[],r=0,a.label=1;case 1:return r<e.length?(o=e.slice(r,r+100),[4,this.send({method:"DELETE",path:"/object/".concat(this.bucketId),json:{prefixes:o}})]):[3,4];case 2:i=a.sent(),Array.isArray(i)&&n.push.apply(n,i),a.label=3;case 3:return r+=100,[3,1];case 4:return[2,n]}})})},this.shouldThrowOnError)]})})},t.prototype.copy=function(t,e,n){return co(this,void 0,Promise,function(){var r=this;return uo(this,function(o){return[2,Xr(function(){return co(r,void 0,void 0,function(){var r;return uo(this,function(o){switch(o.label){case 0:return r=this.buildCopyMoveHeaders(n),[4,this.send({method:"POST",path:"/object/copy",json:{bucketId:this.bucketId,sourceKey:this.cleanPath(t),destinationKey:this.cleanPath(e),destinationBucket:null==n?void 0:n.destinationBucket,copyMetadata:null==n?void 0:n.copyMetadata,metadata:null==n?void 0:n.metadata},headers:r})];case 1:return[2,{path:o.sent().Key}]}})})},this.shouldThrowOnError)]})})},t.prototype.move=function(t,e,n){return co(this,void 0,Promise,function(){var r=this;return uo(this,function(o){return[2,Xr(function(){return co(r,void 0,void 0,function(){return uo(this,function(r){switch(r.label){case 0:return[4,this.send({method:"POST",path:"/object/move",json:{bucketId:this.bucketId,sourceKey:this.cleanPath(t),destinationKey:this.cleanPath(e),destinationBucket:null==n?void 0:n.destinationBucket}})];case 1:return[2,{message:r.sent().message||"Successfully moved"}]}})})},this.shouldThrowOnError)]})})},t.prototype.info=function(t){return co(this,void 0,Promise,function(){var e=this;return uo(this,function(n){return[2,Xr(function(){return co(e,void 0,void 0,function(){var e,n;return uo(this,function(r){switch(r.label){case 0:return e=this.cleanPath(t),[4,this.send({method:"GET",path:"/object/info/".concat(this.bucketId,"/").concat(this.encodePath(e))})];case 1:return[2,{id:(n=r.sent()).id,name:n.name,version:n.version,bucketId:n.bucket_id,size:n.size,contentType:n.content_type,cacheControl:n.cache_control,etag:n.etag,metadata:n.metadata,lastModified:n.last_modified,createdAt:n.created_at}]}})})},this.shouldThrowOnError)]})})},t.prototype.exists=function(t){return co(this,void 0,Promise,function(){var e,n,r;return uo(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),e=this.cleanPath(t),[4,this.send({method:"GET",path:"/object/info/".concat(this.bucketId,"/").concat(this.encodePath(e))})];case 1:return o.sent(),[2,{data:!0,error:null}];case 2:if(n=o.sent(),void 0!==(r=null==n?void 0:n.status)&&[400,404].includes(Number(r)))return[2,{data:!1,error:null}];if(this.shouldThrowOnError)throw n;return[2,{data:null,error:n instanceof Wr?n:new Wr((null==n?void 0:n.message)||String(n))}];case 3:return[2]}})})},t.prototype.createSignedUrl=function(t,e,n){return co(this,void 0,Promise,function(){var r=this;return uo(this,function(o){return[2,Xr(function(){return co(r,void 0,void 0,function(){var r,o,i;return uo(this,function(s){switch(s.label){case 0:return r=this.cleanPath(t),[4,this.send({method:"POST",path:"/object/sign/".concat(this.bucketId,"/").concat(this.encodePath(r)),json:{expiresIn:e}})];case 1:return o=s.sent(),i=o.fullSignedURL||this.http.toFullUrl(o.signedURL||""),[2,{fullSignedURL:this.appendUrlOptions(i,n)}]}})})},this.shouldThrowOnError)]})})},t.prototype.createSignedUrls=function(t,e,n){return co(this,void 0,Promise,function(){var r=this;return uo(this,function(o){return[2,Xr(function(){return co(r,void 0,void 0,function(){var r,o,i,s,a=this;return uo(this,function(c){switch(c.label){case 0:r=t.map(function(t){return a.cleanPath(t)}),o=[],i=0,c.label=1;case 1:return i<r.length?(s=r.slice(i,i+500),[4,this.send({method:"POST",path:"/object/sign/".concat(this.bucketId),json:{expiresIn:e,paths:s}})]):[3,4];case 2:c.sent().forEach(function(t){var e,r=t.fullSignedURL||(t.signedURL?a.http.toFullUrl(t.signedURL):null);o.push({path:t.path,fullSignedURL:r?a.appendUrlOptions(r,n):null,error:null!==(e=t.error)&&void 0!==e?e:null})}),c.label=3;case 3:return i+=500,[3,1];case 4:return[2,o]}})})},this.shouldThrowOnError)]})})},t.prototype.createSignedUploadUrl=function(t,e){return co(this,void 0,Promise,function(){var n=this;return uo(this,function(r){return[2,Xr(function(){return co(n,void 0,void 0,function(){var n,r,o;return uo(this,function(i){switch(i.label){case 0:return n=this.cleanPath(t),r={},(null==e?void 0:e.upsert)&&(r["x-upsert"]="true"),[4,this.send({method:"POST",path:"/object/upload/sign/".concat(this.bucketId,"/").concat(this.encodePath(n)),headers:r})];case 1:return[2,{fullSignedURL:(o=i.sent()).fullURL||this.http.toFullUrl(o.url||""),path:n,token:o.token}]}})})},this.shouldThrowOnError)]})})},t.prototype.uploadToSignedUrl=function(t,e,n,r){return co(this,void 0,Promise,function(){var o=this;return uo(this,function(i){return[2,Xr(function(){return co(o,void 0,void 0,function(){var o,i,s,a,c;return uo(this,function(u){switch(u.label){case 0:return o=this.cleanPath(t),i=this.buildUploadBody(n,r),s=i.body,a=i.headers,[4,this.send({method:"PUT",path:"/object/upload/sign/".concat(this.bucketId,"/").concat(this.encodePath(o)),query:{token:e},rawBody:s,headers:a,withCredentials:!1})];case 1:return c=u.sent(),[2,{path:o,fullPath:c.Key}]}})})},this.shouldThrowOnError)]})})},t.prototype.getPublicUrl=function(t,e){var n=this.cleanPath(t),r=this.http.buildUrl("/object/public/".concat(this.bucketId,"/").concat(this.encodePath(n)));return{data:{publicUrl:this.appendUrlOptions(r,e)}}},t.prototype.send=function(t){return this.http.send(ao(ao({},t),{headers:ao(ao({},this.headers),t.headers||{})}))},t.prototype.uploadOrUpdate=function(t,e,n,r){return co(this,void 0,Promise,function(){var o=this;return uo(this,function(i){return[2,Xr(function(){return co(o,void 0,void 0,function(){var o,i,s,a,c;return uo(this,function(u){switch(u.label){case 0:return o=this.cleanPath(e),i=this.buildUploadBody(n,r),s=i.body,a=i.headers,"POST"===t&&(a["x-upsert"]=String(Boolean(null==r?void 0:r.upsert))),[4,this.send({method:t,path:"/object/".concat(this.bucketId,"/").concat(this.encodePath(o)),rawBody:s,headers:a})];case 1:return[2,{id:(c=u.sent()).Id,path:o,fullPath:c.Key}]}})})},this.shouldThrowOnError)]})})},t.prototype.cleanPath=function(t){var e=t.replace(/^\/+|\/+$/g,"").replace(/\/+/g,"/");if(e.split("/").some(function(t){return".."===t}))throw new Wr('invalid path: ".." segment is not allowed');return e},t.prototype.encodePath=function(t){return Jr(t)},t.prototype.buildUploadBody=function(t,e){var n,r,o,i,s,a=ao({},(null==e?void 0:e.headers)||{}),c=t,u="undefined"!=typeof FormData&&t instanceof FormData;if("undefined"!=typeof Blob&&t instanceof Blob||u){var l=void 0,h={};if(u){var d=this.extractFromFormData(t);l=d.file,h=d.fields}else l=t;var f=null!==(r=null!==(n=null==e?void 0:e.cacheControl)&&void 0!==n?n:h.cacheControl)&&void 0!==r?r:lo,p=null!==(o=null==e?void 0:e.contentType)&&void 0!==o?o:h.contentType,v=void 0!==(null==e?void 0:e.metadata)?JSON.stringify(e.metadata):h.metadata,y=new FormData;void 0!==f&&y.append("cacheControl",String(f)),void 0!==p&&y.append("contentType",p),void 0!==v&&y.append("metadata",v),y.append("",l),c=y}else c=t,f=null!==(i=null==e?void 0:e.cacheControl)&&void 0!==i?i:lo,p=null!==(s=null==e?void 0:e.contentType)&&void 0!==s?s:"text/plain;charset=UTF-8",a["cache-control"]="max-age=".concat(f),p&&(a["content-type"]=p),(null==e?void 0:e.metadata)&&(a["x-metadata"]=this.toBase64(JSON.stringify(e.metadata)));return{body:c,headers:a}},t.prototype.extractFromFormData=function(t){var e,n={},r=0,o=[];if(t.forEach(function(t,i){if("undefined"!=typeof Blob&&t instanceof Blob)return e=t,void(r+=1);"cacheControl"!==i&&"contentType"!==i&&"metadata"!==i?o.push(i):n[i]=String(t)}),o.length>0&&console.warn("Ignored unsupported FormData field(s): [".concat(o.join(", "),"]. Only file, cacheControl, contentType and metadata are supported")),0===r||!e)throw new Wr("FormData must contain a file");if(r>1)throw new Wr("FormData must contain exactly one file");return{file:e,fields:n}},t.prototype.buildCopyMoveHeaders=function(t){var e={};return(null==t?void 0:t.upsert)&&(e["x-upsert"]="true"),!1===(null==t?void 0:t.copyMetadata)&&(null==t?void 0:t.metadata)&&(e["x-metadata"]=this.toBase64(JSON.stringify(t.metadata))),e},t.prototype.appendUrlOptions=function(t,e){var n=[];if(void 0!==(null==e?void 0:e.download)){var r=!0===e.download?"":String(e.download);n.push("download=".concat(encodeURIComponent(r)))}if(void 0!==(null==e?void 0:e.cacheNonce)&&n.push("cacheNonce=".concat(encodeURIComponent(String(e.cacheNonce)))),0===n.length)return t;var o=t.includes("?")?"&":"?";return"".concat(t).concat(o).concat(n.join("&"))},t.prototype.toBase64=function(t){return Kr(t)},t}(),fo=/[\x00-\x20\x7f/\\?#%]/;function po(t,e){if("string"!=typeof t||0===t.length)throw new Wr("[storage.".concat(e,"] bucketId is required"));if(t.length>256)throw new Wr("[storage.".concat(e,"] invalid bucketId: length must be 1-").concat(256));var n=fo.exec(t);if(n){var r="[storage.".concat(e,'] invalid bucketId "').concat(t,'": ')+"contains forbidden character ".concat(JSON.stringify(n[0]),"; ")+'must not contain whitespace, control chars, "/", "\\", "?", "#" or "%"';throw new Wr(r)}}var vo,yo=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},go=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},mo=function(){function t(t,e){void 0===e&&(e=!1),this.http=new Zr(t),this.shouldThrowOnError=e}return t.prototype.throwOnError=function(){return this.shouldThrowOnError=!0,this},t.prototype.listBuckets=function(t){return yo(this,void 0,Promise,function(){var e=this;return go(this,function(n){return[2,Xr(function(){var n={};return void 0!==(null==t?void 0:t.limit)&&(n.limit=t.limit),void 0!==(null==t?void 0:t.offset)&&(n.offset=t.offset),(null==t?void 0:t.sortColumn)&&(n.sortColumn=t.sortColumn),(null==t?void 0:t.sortOrder)&&(n.sortOrder=t.sortOrder),(null==t?void 0:t.search)&&(n.search=t.search),e.http.send({method:"GET",path:"/bucket/",query:n})},this.shouldThrowOnError)]})})},t.prototype.getBucket=function(t){return yo(this,void 0,Promise,function(){var e=this;return go(this,function(n){return[2,Xr(function(){return po(t,"getBucket"),e.http.send({method:"GET",path:"/bucket/".concat(t)})},this.shouldThrowOnError)]})})},t.prototype.createBucket=function(t,e){return yo(this,void 0,Promise,function(){var n=this;return go(this,function(r){return[2,Xr(function(){var r;return po(t,"createBucket"),n.http.send({method:"POST",path:"/bucket/",json:{id:t,name:t,public:null!==(r=null==e?void 0:e.public)&&void 0!==r&&r,type:null==e?void 0:e.type,file_size_limit:null==e?void 0:e.fileSizeLimit,allowed_mime_types:null==e?void 0:e.allowedMimeTypes}})},this.shouldThrowOnError)]})})},t.prototype.updateBucket=function(t,e){return yo(this,void 0,Promise,function(){var n=this;return go(this,function(r){return[2,Xr(function(){return po(t,"updateBucket"),n.http.send({method:"PUT",path:"/bucket/".concat(t),json:{public:e.public,file_size_limit:e.fileSizeLimit,allowed_mime_types:e.allowedMimeTypes}})},this.shouldThrowOnError)]})})},t.prototype.deleteBucket=function(t){return yo(this,void 0,Promise,function(){var e=this;return go(this,function(n){return[2,Xr(function(){return po(t,"deleteBucket"),e.http.send({method:"DELETE",path:"/bucket/".concat(t)})},this.shouldThrowOnError)]})})},t}(),bo=function(){return bo=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},bo.apply(this,arguments)},wo=function(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s},_o=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},Eo=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Io=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(t){t.put="put",t.post="post"}(vo||(vo={}));var So=f,Oo=g,To=y,Ao=_,Po=E,Ro=function(t){return"[object Object]"===Object.prototype.toString.call(t)},Co=A,ko=x,No=P,xo=et,Uo="storage";function Lo(t,e){return e&&"function"!=typeof e?[bo(bo({},t),{customReqOpts:e}),void 0]:[t,e]}var Do=function(t,e,n){return Eo(void 0,void 0,void 0,function(){var r,o,i;return Io(this,function(s){switch(s.label){case 0:return[4,t.gateWay({path:"storages",name:"get-objects-upload-info",data:[bo({objectId:e.path},e.signedHeader?{signedHeader:e.signedHeader}:{})]},n)];case 1:return r=U(r=s.sent()),o=(null===(i=r.data)||void 0===i?void 0:i[0])||{},[2,bo(bo({},r),{data:bo(bo({},o.code?bo({},o):{}),{authorization:o.authorization,token:o.token,url:o.uploadUrl,fileId:o.cloudObjectId,cosFileId:o.cloudObjectMeta,download_url:o.downloadUrl})})]}})})},jo=function(t,e,n){return Eo(void 0,void 0,void 0,function(){var r;return Io(this,function(o){switch(o.label){case 0:return[4,t.gateWay({path:"storages",name:"get-objects-download-info",data:e.convertedFileList.map(function(t){return bo({cloudObjectId:t.fileid},null!=t.max_age?{maxAge:t.max_age}:{})})},n)];case 1:return r=U(r=o.sent()),[2,bo(bo({},r),{data:{download_list:Array.isArray(r.data)?r.data.map(function(t){return{code:t.code||"SUCCESS",message:t.message,fileid:t.cloudObjectId,download_url:t.downloadUrl,fileID:t.cloudObjectId,tempFileURL:t.downloadUrl,mime_type:t.contentType||Wo(null,t.cloudObjectId||"")}}):[]}})]}})})},qo=function(t,e,n){return Eo(void 0,void 0,void 0,function(){var r;return Io(this,function(o){switch(o.label){case 0:return[4,t.gateWay({path:"storages",name:"delete-objects",data:e.fileList.map(function(t){return{cloudObjectId:t}})},n)];case 1:return r=U(r=o.sent()),[2,bo(bo({},r),{data:{delete_list:Array.isArray(r.data)?r.data.map(function(t){return{code:t.code||"SUCCESS",fileID:t.cloudObjectId,message:t.message}}):[]}})]}})})},Mo=function(t,e,n){return Eo(void 0,void 0,void 0,function(){var r;return Io(this,function(o){switch(o.label){case 0:return[4,t.gateWay({path:"storages",name:"copy-objects",data:e.convertedFileList.map(function(t){return{srcPath:t.src_path,dstPath:t.dst_path,overwrite:t.overwrite,removeOriginal:t.remove_original}})},n)];case 1:return r=U(r=o.sent()),[2,bo(bo({},r),{data:{copy_list:Array.isArray(r.data)?r.data.map(function(t){return{code:t.code||"SUCCESS",fileID:t.cloudObjectId,fileId:t.cloudObjectId,message:t.message}}):[]}})]}})})},Bo={txt:"text/plain",json:"application/json",html:"text/html",htm:"text/html",css:"text/css",js:"application/javascript",csv:"text/csv",xml:"application/xml",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",ico:"image/x-icon",pdf:"application/pdf",zip:"application/zip",gz:"application/gzip",mp4:"video/mp4",webm:"video/webm",mp3:"audio/mpeg",wav:"audio/wav"};function Wo(t,e){if("undefined"!=typeof Blob&&t instanceof Blob&&t.type)return t.type;var n=/\.([a-zA-Z0-9]+)$/.exec(e||""),r=n?n[1].toLowerCase():"";return Bo[r]||"application/octet-stream"}function Fo(){var t=globalThis.wx;return"function"==typeof(null==t?void 0:t.getFileSystemManager)}function Ho(t,e){var n=e.toLowerCase();return Object.keys(t).some(function(t){return t.toLowerCase()===n})}function Vo(t){return Object.keys(t).reduce(function(e,n){var r;return bo(bo({},e),((r={})[n]=[t[n]],r))},{})}function Go(t){return"number"==typeof t&&Number.isInteger(t)&&t>=1}var Ko=function(){function t(t){this.context=t}var e,n,r,o,i,s,a,c,u,l,h,d,f,p,v,y,g;return Object.defineProperty(t.prototype,"config",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.config},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"request",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.request},enumerable:!1,configurable:!0}),t.prototype.isGateWay=function(){return"GATEWAY"===(this.config.endPointMode||"CLOUD_API")},t.prototype.uploadFile=function(t,e){var n,r;return Eo(this,void 0,Promise,function(){var o,i,s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I,S,O,T,A,P,R,C,k,N,x,U,L,D,j;return Io(this,function(q){switch(q.label){case 0:if(U=Lo(t,e),t=U[0],e=U[1],o=t.cloudPath,i=t.filePath,s=t.onUploadProgress,L=t.method,a=void 0===L?"put":L,D=t.headers,c=void 0===D?{}:D,u=t.fileContent,!Po(o)||!i&&!u)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".uploadFile] invalid params")})];if(i&&u&&console.warn("[".concat(So(),"][").concat(Uo,".uploadFile] fileContent 是兼容字段,与 filePath 同时传入时忽略,实际使用 filePath")),l=null!=i?i:u,(h={put:vo.put,post:vo.post}[a.toLocaleLowerCase()]||vo.put)===vo.post&&console.warn("[".concat(So(),"][").concat(Uo,".uploadFile] method: 'post' 已废弃,请改用 'put'")),d=this.isGateWay(),f=bo({},c),p=Object.keys(c).reduce(function(t,e){return"content-length"!==e.toLowerCase()&&(t[e]=c[e]),t},{}),h===vo.put&&d){if(!Ho(f,"content-length")){if(v=null===(r=null===(n=this.request)||void 0===n?void 0:n.getUploadByteLength)||void 0===r?void 0:r.call(n,l),"number"!=typeof(y="number"==typeof v?v:function(t){if((!Fo()||"string"!=typeof t)&&null!==t){if("undefined"!=typeof Blob&&t instanceof Blob)return t.size;if("undefined"!=typeof ArrayBuffer){if(t instanceof ArrayBuffer)return t.byteLength;if("function"==typeof ArrayBuffer.isView&&ArrayBuffer.isView(t))return t.byteLength}if("string"==typeof t){if("undefined"!=typeof Blob)return new Blob([t]).size;var e=function(t){var e;return null===(e=Gr())||void 0===e?void 0:e.byteLength(t)}(t);return"number"==typeof e?e:t.length}return"object"==typeof t&&"number"==typeof t.size?t.size:void 0}}(l)))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:Fo()?"[".concat(Uo,".uploadFile] 无法计算 content-length,请确认上传内容为有效的本地临时路径,或传入 ArrayBuffer"):"[".concat(Uo,".uploadFile] 无法计算 content-length,请传入 File/Blob/Buffer/ArrayBuffer,或在 headers 中提供 content-length")})];f["content-length"]=String(y)}Ho(f,"content-type")||(f["content-type"]=Wo(l,o)),Ho(p,"content-type")||(p["content-type"]=Wo(l,o))}return[4,this.getUploadMetadata({cloudPath:o,method:h,headers:h!==vo.put||d?void 0:p,signedHeader:h===vo.put&&d?Vo(f):void 0,customReqOpts:t.customReqOpts})];case 1:return g=q.sent(),m=g.data,b=g.requestId,(null==(w=m)?void 0:w.code)||!(null==w?void 0:w.url)?(_=(null==w?void 0:w.code)||Oo.OPERATION_FAIL,E=(null==w?void 0:w.message)||"get upload info failed",[2,Co(e,new Error("[".concat(So(),"][").concat(_,"][").concat(Uo,"]:").concat(E)))]):(I=m.url,S=m.authorization,O=m.token,T=m.fileId,A=m.cosFileId,P=m.download_url,C=bo(bo({},R={url:I,file:l,name:o,onUploadProgress:s,fileId:T,requestId:b}),{method:vo.put,headers:bo(bo({},p),{authorization:S,"x-cos-meta-fileid":A,"x-cos-security-token":O})}),k=bo(bo({},R),{method:vo.post,data:{key:o,signature:S,"x-cos-meta-fileid":A,success_action_status:"201","x-cos-security-token":O}}),(j={})[vo.put]={params:C,isSuccess:function(t){return t>=200&&t<300}},j[vo.post]={params:k,isSuccess:function(t){return 201===t}},N=j,[4,this.request.upload(N[h].params)]);case 2:return x=q.sent(),N[h].isSuccess(x.statusCode)?[2,Co(e,null,{fileID:T,download_url:P,requestId:b})]:[2,Co(e,new Error("[".concat(So(),"][").concat(Oo.OPERATION_FAIL,"][").concat(Uo,"]:").concat(x.data)))]}})})},t.prototype.getUploadMetadata=function(t,e){return Eo(this,void 0,Promise,function(){var n,r,o,i,s,a,c,u,l,h;return Io(this,function(d){switch(d.label){case 0:if(n=t.cloudPath,r=t.method,o=t.headers,i=t.signedHeader,!Po(n))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getUploadMetadata] invalid cloudPath")})];s=this.request,a="storage.getUploadMetadata",d.label=1;case 1:return d.trys.push([1,6,,7]),c=void 0,u={path:n},l=this.isGateWay(),r&&(u.method=r),r===vo.put&&(l&&i?u.signedHeader=i:!l&&o&&(u.headers=o)),r!==vo.post&&l?[3,3]:[4,s.send(a,u,{endPointMode:"CLOUD_API"},t.customReqOpts)];case 2:return c=d.sent(),[3,5];case 3:return[4,Do(s,u,t.customReqOpts)];case 4:c=d.sent(),d.label=5;case 5:return[2,Co(e,null,c)];case 6:return h=d.sent(),[2,Co(e,h)];case 7:return[2]}})})},t.prototype.deleteFile=function(t,e){return Eo(this,void 0,Promise,function(){var n,r,o,i,s,a,c,u,l;return Io(this,function(h){switch(h.label){case 0:if(l=Lo(t,e),t=l[0],e=l[1],!(n=t.fileList)||!Ao(n)||0===n.length)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".deleteFile] fileList must not be empty")})];for(r=0,o=n;r<o.length;r++)if(!(i=o[r])||!Po(i))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".deleteFile] fileID must be string")})];return s="storage.batchDeleteFile",a=this.request,c={},this.isGateWay()?[4,qo(a,{fileList:n},t.customReqOpts)]:[3,2];case 1:return c=h.sent(),[3,4];case 2:return[4,a.send(s,{fileid_list:n},t.customReqOpts)];case 3:c=h.sent(),h.label=4;case 4:return c.code?[2,Co(e,null,c)]:(u={fileList:c.data.delete_list,requestId:c.requestId},[2,Co(e,null,u)])}})})},t.prototype.getTempFileURL=function(t,e){var n;return Eo(this,void 0,Promise,function(){var r,o,i,s,a,c,u,l,h,d,f,p;return Io(this,function(v){switch(v.label){case 0:if(p=Lo(t,e),t=p[0],e=p[1],!(r=t.fileList)||!Ao(r)||0===r.length)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getTempFileURL] fileList must not be empty")})];for(o=[],i=!1,s=0,a=r;s<a.length;s++)if(c=a[s],Ro(c)){if(!Object.prototype.hasOwnProperty.call(c,"fileID"))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getTempFileURL] file info must include fileID")})];if(u={fileid:c.fileID},Object.prototype.hasOwnProperty.call(c,"maxAge")){if(!Go(l=c.maxAge))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getTempFileURL] maxAge must be an integer greater than or equal to ").concat(1)})];l>3600&&!i&&(No(Oo.INVALID_PARAMS,"[".concat(Uo,".getTempFileURL] maxAge ").concat(l," 大于 ").concat(3600,",仍按原值下发")),i=!0),u.max_age=l}o.push(u)}else{if(!Po(c))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getTempFileURL] invalid fileList")})];o.push({fileid:c})}return h="storage.batchGetDownloadUrl",d=this.request,f={},this.isGateWay()?[4,jo(d,{convertedFileList:o},t.customReqOpts)]:[3,2];case 1:return f=v.sent(),[3,4];case 2:return[4,d.send(h,{file_list:o},t.customReqOpts)];case 3:f=v.sent(),v.label=4;case 4:return f.code?[2,Co(e,null,f)]:[2,Co(e,null,{fileList:Array.isArray(null===(n=f.data)||void 0===n?void 0:n.download_list)?f.data.download_list:[],requestId:f.requestId})]}})})},t.prototype.downloadFile=function(t,e){return Eo(this,void 0,Promise,function(){var n,r,o,i,s,a,c;return Io(this,function(u){switch(u.label){case 0:return c=Lo(t,e),t=c[0],e=c[1],n=t.fileID,Po(n)?[4,this.getTempFileURL.call(this,{fileList:[{fileID:n,maxAge:600}],customReqOpts:t.customReqOpts})]:[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getTempFileURL] fileID must be string")})];case 1:return r=u.sent(),"SUCCESS"!==(o=r.fileList[0]).code?[2,Co(e,o)]:(i=this.request,s=encodeURI(o.download_url),[4,i.download({url:s,tempFilePath:t.tempFilePath})]);case 2:return a=u.sent(),[2,Co(e,null,a)]}})})},t.prototype.copyFile=function(t,e){return Eo(this,void 0,Promise,function(){var n,r,o,i,s,a,c,u,l,h;return Io(this,function(d){switch(d.label){case 0:if(h=Lo(t,e),t=h[0],e=h[1],!(n=t.fileList)||!Ao(n)||0===n.length)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".copyFile] fileList must not be empty")})];for(r=[],o=0,i=n;o<i.length;o++){if(s=i[o],a=s.srcPath,c=s.dstPath,!a||!c||"string"!=typeof a||"string"!=typeof c)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".copyFile] srcPath and dstPath may not be empty")})];if(a===c)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".copyFile] srcPath and dstPath can not be the same")})];r.push({src_path:a,dst_path:c,overwrite:s.overwrite,remove_original:s.removeOriginal})}return u=this.request,l={},this.isGateWay()?[4,Mo(u,{convertedFileList:r},t.customReqOpts)]:[3,2];case 1:return l=d.sent(),[3,4];case 2:return[4,u.send("storage.batchCopyFile",{file_list:r},t.customReqOpts)];case 3:l=d.sent(),d.label=4;case 4:return l.code?[2,Co(e,null,l)]:[2,Co(e,null,{fileList:l.data.copy_list,requestId:l.requestId})]}})})},t.prototype.getFileInfo=function(t){var e;return Eo(this,void 0,Promise,function(){var n,r=this;return Io(this,function(o){switch(o.label){case 0:return[4,this.getTempFileURL(t)];case 1:return(null==(n=o.sent())?void 0:n.fileList)&&(null===(e=null==n?void 0:n.fileList)||void 0===e?void 0:e.length)>0?[4,Promise.all(n.fileList.map(function(t){return Eo(r,void 0,void 0,function(){var e,n,r,o,i,s,a;return Io(this,function(c){switch(c.label){case 0:if("SUCCESS"!==t.code)return[2,{code:t.code,fileID:t.fileID,tempFileURL:t.tempFileURL,message:t.message}];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,this.request.fetch({url:t.tempFileURL,method:"HEAD"})];case 2:return e=c.sent(),n=e.header,"undefined"!=typeof Headers&&n instanceof Headers&&(r={},n.forEach(function(t,e){r[e]=t}),n=r),o=parseInt(n["content-length"])||0,i=n["content-type"]||"",[400,404].includes(Number(e.statusCode))?[2,{code:"FILE_NOT_FOUND",fileID:t.fileID,tempFileURL:t.tempFileURL,message:"file not found"}]:[2,{code:t.code,fileID:t.fileID,tempFileURL:t.tempFileURL,cloudId:t.fileID,fileName:t.fileID.split("/").pop(),contentType:i,mime:i.split(";")[0].trim(),size:o,etag:n.etag||"",lastModified:n["last-modified"]||"",cacheControl:n["cache-control"]||""}];case 3:return s=c.sent(),a="object"==typeof s&&null!==s&&"message"in s?String(s.message):void 0,[2,{code:"FETCH_FILE_INFO_ERROR",fileID:t.fileID,tempFileURL:t.tempFileURL,message:a}];case 4:return[2]}})})}))]:[3,3];case 2:return[2,{fileList:o.sent(),requestId:n.requestId}];case 3:return[2,{fileList:[],requestId:n.requestId}]}})})},wo([xo({customInfo:{className:"Cloudbase",methodName:"uploadFile"},title:"上传文件失败",messages:["请确认以下各项:"," 1 - 调用 uploadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",["function"==typeof(e=void 0!==dr.ICloudbaseUploadFileParams&&dr.ICloudbaseUploadFileParams)?e:Object,"function"==typeof(n="undefined"!=typeof Function&&Function)?n:Object]),_o("design:returntype","function"==typeof(r="undefined"!=typeof Promise&&Promise)?r:Object)],t.prototype,"uploadFile",null),wo([xo({customInfo:{className:"Cloudbase",methodName:"getUploadMetadata"},title:"获取上传元信息失败",messages:["请确认以下各项:"," 1 - 调用 getUploadMetadata() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",[Object,"function"==typeof(o="undefined"!=typeof Function&&Function)?o:Object]),_o("design:returntype","function"==typeof(i="undefined"!=typeof Promise&&Promise)?i:Object)],t.prototype,"getUploadMetadata",null),wo([xo({customInfo:{className:"Cloudbase",methodName:"deleteFile"},title:"删除文件失败",messages:["请确认以下各项:"," 1 - 调用 deleteFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",["function"==typeof(s=void 0!==dr.ICloudbaseDeleteFileParams&&dr.ICloudbaseDeleteFileParams)?s:Object,"function"==typeof(a="undefined"!=typeof Function&&Function)?a:Object]),_o("design:returntype","function"==typeof(c="undefined"!=typeof Promise&&Promise)?c:Object)],t.prototype,"deleteFile",null),wo([xo({customInfo:{className:"Cloudbase",methodName:"getTempFileURL"},title:"获取文件下载链接",messages:["请确认以下各项:"," 1 - 调用 getTempFileURL() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",["function"==typeof(u=void 0!==dr.ICloudbaseGetTempFileURLParams&&dr.ICloudbaseGetTempFileURLParams)?u:Object,"function"==typeof(l="undefined"!=typeof Function&&Function)?l:Object]),_o("design:returntype","function"==typeof(h="undefined"!=typeof Promise&&Promise)?h:Object)],t.prototype,"getTempFileURL",null),wo([xo({customInfo:{className:"Cloudbase",methodName:"downloadFile"},title:"下载文件失败",messages:["请确认以下各项:"," 1 - 调用 downloadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",["function"==typeof(d=void 0!==dr.ICloudbaseDownloadFileParams&&dr.ICloudbaseDownloadFileParams)?d:Object,"function"==typeof(f="undefined"!=typeof Function&&Function)?f:Object]),_o("design:returntype","function"==typeof(p="undefined"!=typeof Promise&&Promise)?p:Object)],t.prototype,"downloadFile",null),wo([xo({customInfo:{className:"Cloudbase",methodName:"copyFile"},title:"批量复制文件",messages:["请确认以下各项:"," 1 - 调用 copyFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",["function"==typeof(v=void 0!==dr.ICloudbaseCopyFileParams&&dr.ICloudbaseCopyFileParams)?v:Object,"function"==typeof(y="undefined"!=typeof Function&&Function)?y:Object]),_o("design:returntype","function"==typeof(g="undefined"!=typeof Promise&&Promise)?g:Object)],t.prototype,"copyFile",null),t}(),Jo=function(){return Jo=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Jo.apply(this,arguments)},zo=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},$o=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Yo=g,Qo=function(){function t(t,e){void 0===e&&(e=!1),this.shouldThrowOnError=!1,this.bucketId="",this.context=t,this.shouldThrowOnError=e,this.storage=new Ko(t)}return Object.defineProperty(t.prototype,"config",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.config},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"request",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.request},enumerable:!1,configurable:!0}),t.prototype.throwOnError=function(){return this.shouldThrowOnError=!0,this},t.prototype.upload=function(t,e,n){return zo(this,void 0,Promise,function(){var r,o,i,s,a,c,u,l,h;return $o(this,function(d){switch(d.label){case 0:r=Jo({upsert:!0},n),o=r.cacheControl,i=r.contentType,s=r.metadata,d.label=1;case 1:return d.trys.push([1,3,,4]),a=this.getCloudPath(t),c={cloudPath:a,filePath:e},(o||i||s)&&(u={},o&&(u["cache-control"]=o),i&&(u["content-type"]=i),s&&(u["x-cos-metadata-metadata"]=this.toBase64(JSON.stringify(s))),c.headers=u),[4,this.storage.uploadFile(c)];case 2:if(!(l=d.sent()).fileID)throw new Error(JSON.stringify({code:Yo.OPERATION_FAIL,msg:"[".concat(Uo,".update] no fileID returned")}));return[2,{data:{id:l.fileID,path:t,fullPath:t},error:null}];case 3:if(h=d.sent(),this.shouldThrowOnError)throw h;if(Fr(h))return[2,{data:null,error:h}];throw h;case 4:return[2]}})})},t.prototype.uploadToSignedUrl=function(t,e,n,r){return zo(this,void 0,Promise,function(){return $o(this,function(e){return[2,this.upload(t,n,r)]})})},t.prototype.createSignedUploadUrl=function(t){return zo(this,void 0,Promise,function(){var e,n,r;return $o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),e=this.getCloudPath(t),[4,this.storage.getUploadMetadata({cloudPath:e})];case 1:return[2,{data:{signedUrl:(n=o.sent().data).url,token:n.token,path:t,authorization:n.authorization,id:n.fileId,cosFileId:n.cosFileId,downloadUrl:n.download_url},error:null}];case 2:if(r=o.sent(),this.shouldThrowOnError)throw r;return[2,{data:null,error:r instanceof Wr?r:new Wr(r.message)}];case 3:return[2]}})})},t.prototype.update=function(t,e,n){return zo(this,void 0,Promise,function(){return $o(this,function(r){return[2,this.upload(t,e,Jo(Jo({},n),{upsert:!0}))]})})},t.prototype.move=function(t,e){return zo(this,void 0,Promise,function(){var n,r;return $o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.storage.copyFile({fileList:[{srcPath:this.getCloudPath(t),dstPath:this.getCloudPath(e),overwrite:!0,removeOriginal:!0}]})];case 1:if((n=o.sent()).fileList[0].code&&"SUCCESS"!==n.fileList[0].code)throw new Wr(n.fileList[0].message||"Move failed");return[2,{data:{message:"File moved from ".concat(t," to ").concat(e)},error:null}];case 2:if(r=o.sent(),this.shouldThrowOnError)throw r;if(Fr(r))return[2,{data:null,error:r}];throw r;case 3:return[2]}})})},t.prototype.copy=function(t,e){return zo(this,void 0,Promise,function(){var n,r;return $o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.storage.copyFile({fileList:[{srcPath:this.getCloudPath(t),dstPath:this.getCloudPath(e),overwrite:!0,removeOriginal:!1}]})];case 1:if((n=o.sent()).fileList[0].code&&"SUCCESS"!==n.fileList[0].code)throw new Wr(n.fileList[0].message||"Copy failed");return[2,{data:{path:this.getCloudPath(e)},error:null}];case 2:if(r=o.sent(),this.shouldThrowOnError)throw r;if(Fr(r))return[2,{data:null,error:r}];throw r;case 3:return[2]}})})},t.prototype.createSignedUrl=function(t,e,n){return zo(this,void 0,Promise,function(){var r,o,i,s,a,c,u;return $o(this,function(l){switch(l.label){case 0:if(l.trys.push([0,2,,3]),!Go(e))throw new Wr("[".concat(Uo,".createSignedUrl] expiresIn must be an integer greater than or equal to ").concat(1));return r=this.normalizeCloudId(t),[4,this.storage.getTempFileURL({fileList:[{fileID:r,maxAge:e}]})];case 1:if("SUCCESS"!==(o=l.sent()).fileList[0].code)throw new Wr("Failed to create signed URL: [".concat(o.fileList[0].code,"] ").concat(o.fileList[0].fileID));return i=o.fileList[0].download_url,s=[],void 0!==(null==n?void 0:n.download)&&("string"==typeof n.download?s.push("download=".concat(encodeURIComponent(n.download))):!0===n.download&&s.push("download=true")),(null==n?void 0:n.transform)&&(a=this.transformOptsToQueryString(n.transform))&&s.push(a),s.length>0&&(c=i.includes("?")?"&":"?",i="".concat(i).concat(c).concat(s.join("&"))),[2,{data:{signedUrl:i},error:null}];case 2:if(u=l.sent(),this.shouldThrowOnError)throw u;if(Fr(u))return[2,{data:null,error:u}];throw u;case 3:return[2]}})})},t.prototype.createSignedUrls=function(t,e){return zo(this,void 0,Promise,function(){var n,r,o=this;return $o(this,function(i){switch(i.label){case 0:if(i.trys.push([0,2,,3]),!Go(e))throw new Wr("[".concat(Uo,".createSignedUrls] expiresIn must be an integer greater than or equal to ").concat(1));return n=t.map(function(t){return{fileID:o.normalizeCloudId(t),maxAge:e}}),[4,this.storage.getTempFileURL({fileList:n})];case 1:return[2,{data:i.sent().fileList.map(function(e,n){return{path:t[n],signedUrl:e.tempFileURL||"",error:"SUCCESS"===e.code?null:e.message}}),error:null}];case 2:if(r=i.sent(),this.shouldThrowOnError)throw r;if(Fr(r))return[2,{data:null,error:r}];throw r;case 3:return[2]}})})},t.prototype.download=function(t,e){return zo(this,void 0,Promise,function(){var n,r,o=this;return $o(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),r={},[4,zo(o,void 0,void 0,function(){var n,r,o,i;return $o(this,function(s){switch(s.label){case 0:return[4,this.createSignedUrl(t,600,{transform:e})];case 1:if((n=s.sent()).error)throw n.error;return r=encodeURI(null===(i=n.data)||void 0===i?void 0:i.signedUrl),[4,this.request.reqClass.get({url:r,headers:{},responseType:"blob"})];case 2:if(!(o=s.sent().data))throw new Wr("Download failed: no file content");return[2,new Blob([o])]}})})];case 1:return[2,(r.data=i.sent(),r.error=null,r)];case 2:if(n=i.sent(),this.shouldThrowOnError)throw n;if(Fr(n))return[2,{data:null,error:n}];throw n;case 3:return[2]}})})},t.prototype.info=function(t){return zo(this,void 0,Promise,function(){var e,n,r,o,i,s,a,c;return $o(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),e=t.startsWith("cloud://"),n=e?this.extractPathFromFileId(t):t,r=e?this.extractBucketFromFileId(t):this.bucketId,[4,this.storage.getFileInfo({fileList:[this.normalizeCloudId(t)]})];case 1:if(o=u.sent(),"SUCCESS"!==(i=o.fileList[0]).code)throw new Wr(i.message);return s=(new Date).toISOString(),a=(i.lastModified?new Date(i.lastModified):new Date).toISOString(),[2,{data:{id:i.fileID,version:"1",name:n,bucketId:r,updatedAt:a,createdAt:a,lastAccessedAt:s,size:i.size,cacheControl:i.cacheControl,contentType:i.contentType,etag:i.etag,lastModified:a,metadata:{}},error:null}];case 2:if(c=u.sent(),this.shouldThrowOnError)throw c;return[2,{data:null,error:c instanceof Wr?c:new Wr(c.message)}];case 3:return[2]}})})},t.prototype.exists=function(t){return zo(this,void 0,Promise,function(){var e,n,r;return $o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.storage.getFileInfo({fileList:[this.normalizeCloudId(t)]})];case 1:if(e=o.sent(),"FILE_NOT_FOUND"===(n=e.fileList[0]).code)return[2,{data:!1,error:null}];if("SUCCESS"!==n.code)throw new Wr(n.message);return[2,{data:!0,error:null}];case 2:if(r=o.sent(),this.shouldThrowOnError)throw r;if(Fr(r))return[2,{data:null,error:r}];throw r;case 3:return[2]}})})},t.prototype.getPublicUrl=function(t,e){return zo(this,void 0,Promise,function(){var n;return $o(this,function(r){switch(r.label){case 0:return[4,this.createSignedUrl(t,600,e)];case 1:return(n=r.sent()).data?[2,{data:{publicUrl:n.data.signedUrl}}]:[2,{data:null,error:n.error}]}})})},t.prototype.remove=function(t){return zo(this,void 0,Promise,function(){var e,n,r,o,i,s,a,c,u,l,h=this;return $o(this,function(d){switch(d.label){case 0:for(d.trys.push([0,3,,4]),e=10,n=[],r=0;r<t.length;r+=e)n.push(t.slice(r,r+e));return[4,Promise.all(n.map(function(t){return Promise.all(t.map(function(t){return h.info(t)}))}))];case 1:return o=d.sent(),i=new Map,o.forEach(function(n,r){n.forEach(function(n,o){n.data&&i.set(t[r*e+o],n.data)})}),s=t.map(function(t){return h.normalizeCloudId(t)}),[4,this.storage.deleteFile({fileList:s})];case 2:if(a=d.sent(),(c=a.fileList.filter(function(t){return"SUCCESS"!==t.code})).length>0)throw new Wr("Delete failed for ".concat(c.length," file(s)"));return u=(new Date).toISOString(),[2,{data:t.map(function(t){var e=i.get(t);return{name:null==e?void 0:e.name,id:null==e?void 0:e.id,bucket_id:null==e?void 0:e.bucketId,owner:void 0,updated_at:(null==e?void 0:e.updatedAt)||u,created_at:null==e?void 0:e.createdAt,last_accessed_at:(null==e?void 0:e.lastAccessedAt)||u,metadata:(null==e?void 0:e.metadata)||{},buckets:{id:null==e?void 0:e.bucketId,name:null==e?void 0:e.bucketId,owner:void 0,public:!1,created_at:"",updated_at:u}}}),error:null}];case 3:if(l=d.sent(),this.shouldThrowOnError)throw l;if(Fr(l))return[2,{data:null,error:l}];throw l;case 4:return[2]}})})},t.prototype.list=function(){return zo(this,void 0,void 0,function(){return $o(this,function(t){throw new Wr("Not implemented")})})},t.prototype.getCloudPath=function(t){return t.replace(/^\/|\/$/g,"").replace(/\/+/g,"/")},t.prototype.normalizeCloudId=function(t){var e;if(/^cloud:\/\//.test(t))return t;var n=this.getCloudPath(t);if(!this.bucketId)throw new Wr("bucketId is not set");var r=(null===(e=this.config)||void 0===e?void 0:e.env)||"";return r?"cloud://".concat(r,".").concat(this.bucketId,"/").concat(n):void 0},t.prototype.toBase64=function(t){return Kr(t)},t.prototype.transformOptsToQueryString=function(t){var e=["imageMogr2"];if(t.width||t.height){var n=t.width||"",r=t.height||"";"fill"===t.resize?e.push("thumbnail/".concat(n,"x").concat(r,"!")):"contain"===t.resize?e.push("thumbnail/".concat(n,"x").concat(r)):e.push("thumbnail/".concat(n,"x").concat(r,"^"))}if(t.format&&"origin"!==t.format&&e.push("format/".concat(t.format)),void 0!==t.quality){var o=Math.max(1,Math.min(100,t.quality));e.push("quality/".concat(o))}return e.join("/")},t.prototype.extractPathFromFileId=function(t){var e=t.replace(/^cloud:\/\//,"").split("/");return e.length<2?t:e.slice(1).join("/")},t.prototype.extractBucketFromFileId=function(t){var e=t.replace(/^cloud:\/\//,"").split("/");if(e.length<1)return"";var n=e[0],r=n.indexOf(".");return-1===r?n:n.substring(r+1)},t}(),Xo=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Zo=new Ko,ti={name:Uo,entity:{uploadFile:Zo.uploadFile,deleteFile:Zo.deleteFile,getTempFileURL:Zo.getTempFileURL,downloadFile:Zo.downloadFile,getUploadMetadata:Zo.getUploadMetadata,copyFile:Zo.copyFile,getFileInfo:Zo.getFileInfo,isGateWay:Zo.isGateWay}},ei=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Xo(e,t),e.prototype.from=function(t){return t?(po(t,"from"),new ho(this.http,t,this.shouldThrowOnError)):new Qo(this.http.ctx,this.shouldThrowOnError)},e}(mo),ni={name:"".concat(Uo,"/supabase"),IIFE:!0,entity:function(){var t=new WeakMap;Object.defineProperty(this.prototype,"storage",{get:function(){if(t.has(this))return t.get(this);var e=this,n=new Proxy({},{get:function(t,n){return"config"===n?e.config:"request"===n?e.request:void 0}}),r=new ei(n);return t.set(this,r),r},configurable:!0,enumerable:!0})}};try{cloudbase.registerComponent(ti),cloudbase.registerComponent(ni)}catch(t){}function ri(t){try{t.registerComponent(ti),t.registerComponent(ni)}catch(t){console.warn(t)}}try{window.registerStorage=ri}catch(t){}var oi=l(6765),ii=l.n(oi),si=l(7195),ai=l.n(si),ci=l(9850),ui=l.n(ci);function li(t){return void 0===t&&(t=""),"".concat(t?"".concat(t,"_"):"").concat(+new Date,"_").concat(Math.random())}var hi,di=function(t){this.close=t.close,this.onChange=t.onChange,this.onError=t.onError,t.debug&&Object.defineProperty(this,"virtualClient",{get:function(){return t.virtualClient}})},fi=function(t){var e,n,r=t.id,o=t.docChanges,i=t.docs,s=t.msgType,a=t.type;Object.defineProperties(this,{id:{get:function(){return r},enumerable:!0},docChanges:{get:function(){return e||(e=JSON.parse(JSON.stringify(o))),e},enumerable:!0},docs:{get:function(){return n||(n=JSON.parse(JSON.stringify(i))),n},enumerable:!0},msgType:{get:function(){return s},enumerable:!0},type:{get:function(){return a},enumerable:!0}})},pi=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),vi=function(t){function e(e){var n=t.call(this,"Watch Error ".concat(JSON.stringify(e.msgData)," (requestid: ").concat(e.requestId,")"))||this;return n.isRealtimeErrorMessageError=!0,n.payload=e,n}return pi(e,t),e}(Error),yi=function(t){return null==t?void 0:t.isRealtimeErrorMessageError},gi=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="timeout",e.payload=null,e.generic=!0,e}return pi(e,t),e}(Error),mi=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="cancelled",e.payload=null,e.generic=!0,e}return pi(e,t),e}(Error),bi=function(t){function e(e){var n=t.call(this,e.errMsg)||this;return n.errCode="UNKNOWN_ERROR",Object.defineProperties(n,{message:{get:function(){return"errCode: ".concat(this.errCode," ").concat(wi[this.errCode]||""," | errMsg: ").concat(this.errMsg)},set:function(t){this.errMsg=t}}}),n.errCode=e.errCode||"UNKNOWN_ERROR",n.errMsg=e.errMsg,n}return pi(e,t),Object.defineProperty(e.prototype,"message",{get:function(){return"errCode: ".concat(this.errCode," | errMsg: ").concat(this.errMsg)},set:function(t){this.errMsg=t},enumerable:!1,configurable:!0}),e}(Error),wi={UNKNOWN_ERROR:"UNKNOWN_ERROR",SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG:"SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG",SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA:"SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED",SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL",SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR:"SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR"},_i=function(t){return void 0===t&&(t=0),new Promise(function(e){return setTimeout(e,t)})},Ei=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Ii=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Si=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};!function(t){t.LOGGINGIN="LOGGINGIN",t.INITING="INITING",t.REBUILDING="REBUILDING",t.ACTIVE="ACTIVE",t.ERRORED="ERRORED",t.CLOSING="CLOSING",t.CLOSED="CLOSED",t.PAUSED="PAUSED",t.RESUMING="RESUMING"}(hi||(hi={}));var Oi=function(){function t(t){var e=this;this.watchStatus=hi.INITING,this.wsLogin=function(t,n){return Ei(e,void 0,Promise,function(){var e;return Ii(this,function(r){switch(r.label){case 0:return this.watchStatus=hi.LOGGINGIN,[4,this.login(t,n)];case 1:return e=r.sent(),this.envId||(this.envId=e.envId),[2,e]}})})},this.initWatch=function(t){return Ei(e,void 0,Promise,function(){var e,n=this;return Ii(this,function(r){switch(r.label){case 0:if(null!==this.initWatchPromise&&void 0!==this.initWatchPromise)return[2,this.initWatchPromise];this.initWatchPromise=new Promise(function(e,r){Ei(n,void 0,void 0,function(){var n,o,i,s,a,c,u,l,h,d;return Ii(this,function(f){switch(f.label){case 0:return f.trys.push([0,3,,4]),this.watchStatus===hi.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,e()]):[4,this.wsLogin(this.envId,t)];case 1:return n=f.sent().envId,this.watchStatus===hi.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,e()]):(this.watchStatus=hi.INITING,o={watchId:this.watchId,requestId:li(),msgType:"INIT_WATCH",msgData:{envId:n,collName:this.collectionName,query:this.query,limit:this.limit,orderBy:this.orderBy}},[4,this.send({msg:o,waitResponse:!0,skipOnMessage:!0,timeout:1e4})]);case 2:if(i=f.sent(),s=i.msgData,a=s.events,c=s.currEvent,this.sessionInfo={queryID:i.msgData.queryID,currentEventId:c-1,currentDocs:[]},a.length>0){for(u=0,l=a;u<l.length;u++)l[u].ID=c;this.handleServerEvents(i)}else this.sessionInfo.currentEventId=c,h=new fi({id:c,docChanges:[],docs:[],type:"init"}),this.listener.onChange(h),this.scheduleSendACK();return this.onWatchStart(this,this.sessionInfo.queryID),this.watchStatus=hi.ACTIVE,this.availableRetries.INIT_WATCH=2,e(),[3,4];case 3:return d=f.sent(),this.handleWatchEstablishmentError(d,{operationName:"INIT_WATCH",resolve:e,reject:r}),[3,4];case 4:return[2]}})})}),e=!1,r.label=1;case 1:return r.trys.push([1,,3,4]),[4,this.initWatchPromise];case 2:return r.sent(),e=!0,[3,4];case 3:return this.initWatchPromise=void 0,[7];case 4:return console.log("[realtime] initWatch ".concat(e?"success":"fail")),[2]}})})},this.rebuildWatch=function(t){return Ei(e,void 0,Promise,function(){var e,n=this;return Ii(this,function(r){switch(r.label){case 0:if(null!==this.rebuildWatchPromise&&void 0!==this.rebuildWatchPromise)return[2,this.rebuildWatchPromise];this.rebuildWatchPromise=new Promise(function(e,r){Ei(n,void 0,void 0,function(){var n,o,i,s;return Ii(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),this.watchStatus===hi.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,e()]):[4,this.wsLogin(this.envId,t)];case 1:if(n=a.sent().envId,!this.sessionInfo)throw new Error("can not rebuildWatch without a successful initWatch (lack of sessionInfo)");return this.watchStatus===hi.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,e()]):(this.watchStatus=hi.REBUILDING,o={watchId:this.watchId,requestId:li(),msgType:"REBUILD_WATCH",msgData:{envId:n,collName:this.collectionName,queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:o,waitResponse:!0,skipOnMessage:!1,timeout:1e4})]);case 2:return i=a.sent(),this.handleServerEvents(i),this.watchStatus=hi.ACTIVE,this.availableRetries.REBUILD_WATCH=2,e(),[3,4];case 3:return s=a.sent(),this.handleWatchEstablishmentError(s,{operationName:"REBUILD_WATCH",resolve:e,reject:r}),[3,4];case 4:return[2]}})})}),e=!1,r.label=1;case 1:return r.trys.push([1,,3,4]),[4,this.rebuildWatchPromise];case 2:return r.sent(),e=!0,[3,4];case 3:return this.rebuildWatchPromise=void 0,[7];case 4:return console.log("[realtime] rebuildWatch ".concat(e?"success":"fail")),[2]}})})},this.handleWatchEstablishmentError=function(t,n){return Ei(e,void 0,void 0,function(){var e,r,o,i=this;return Ii(this,function(s){return e="INIT_WATCH"===n.operationName,r=function(){i.closeWithError(new bi({errCode:e?wi.SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:wi.SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL,errMsg:t})),n.reject(t)},o=function(t){i.useRetryTicket(n.operationName)?e?(i.initWatchPromise=void 0,n.resolve(i.initWatch(t))):(i.rebuildWatchPromise=void 0,n.resolve(i.rebuildWatch(t))):r()},this.handleCommonError(t,{onSignError:function(){return o(!0)},onTimeoutError:function(){return o(!1)},onNotRetryableError:r,onCancelledError:n.reject,onUnknownError:function(){Ei(i,void 0,void 0,function(){var t,e=this;return Ii(this,function(r){switch(r.label){case 0:return r.trys.push([0,8,,9]),t=function(){return Ei(e,void 0,void 0,function(){return Ii(this,function(t){switch(t.label){case 0:return this.pause(),[4,this.onceWSConnected()];case 1:return t.sent(),o(!0),[2]}})})},this.isWSConnected()?[3,2]:[4,t()];case 1:return r.sent(),[3,7];case 2:return[4,_i(100)];case 3:return r.sent(),this.watchStatus!==hi.PAUSED?[3,4]:(n.reject(new mi("".concat(n.operationName," cancelled due to pause after unknownError"))),[3,7]);case 4:return this.isWSConnected()?[3,6]:[4,t()];case 5:return r.sent(),[3,7];case 6:o(!1),r.label=7;case 7:return[3,9];case 8:return r.sent(),o(!0),[3,9];case 9:return[2]}})})}}),[2]})})},this.closeWatch=function(){return Ei(e,void 0,void 0,function(){var t,e,n;return Ii(this,function(r){switch(r.label){case 0:if(t=this.sessionInfo?this.sessionInfo.queryID:"",this.watchStatus!==hi.ACTIVE)return this.watchStatus=hi.CLOSED,this.onWatchClose(this,t),[2];r.label=1;case 1:return r.trys.push([1,3,4,5]),this.watchStatus=hi.CLOSING,e={watchId:this.watchId,requestId:li(),msgType:"CLOSE_WATCH",msgData:null},[4,this.send({msg:e})];case 2:return r.sent(),this.sessionInfo=void 0,this.watchStatus=hi.CLOSED,[3,5];case 3:return n=r.sent(),this.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL,errMsg:n})),[3,5];case 4:return this.onWatchClose(this,t),[7];case 5:return[2]}})})},this.scheduleSendACK=function(){e.clearACKSchedule(),e.ackTimeoutId=setTimeout(function(){e.waitExpectedTimeoutId?e.scheduleSendACK():e.sendACK()},1e4)},this.clearACKSchedule=function(){e.ackTimeoutId&&clearTimeout(e.ackTimeoutId)},this.sendACK=function(){return Ei(e,void 0,Promise,function(){var t,e,n;return Ii(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.watchStatus!==hi.ACTIVE?(this.scheduleSendACK(),[2]):this.sessionInfo?(t={watchId:this.watchId,requestId:li(),msgType:"CHECK_LAST",msgData:{queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:t})]):(console.warn("[realtime listener] can not send ack without a successful initWatch (lack of sessionInfo)"),[2]);case 1:return r.sent(),this.scheduleSendACK(),[3,3];case 2:if(e=r.sent(),yi(e))switch((n=e.payload).msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return this.rebuildWatch(),[2];case"QUERYID_INVALID_ERROR":case"SYS_ERR":case"INVALIID_ENV":case"COLLECTION_PERMISSION_DENIED":return this.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:n.msgData.code})),[2]}return this.availableRetries.CHECK_LAST&&this.availableRetries.CHECK_LAST>0?(this.availableRetries.CHECK_LAST-=1,this.scheduleSendACK()):this.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:e})),[3,3];case 3:return[2]}})})},this.handleCommonError=function(t,e){if(yi(t))switch(t.payload.msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return void e.onSignError(t);default:return void e.onNotRetryableError(t)}else{if(function(t){return"timeout"===t.type}(t))return void e.onTimeoutError(t);if(function(t){return"cancelled"===t.type}(t))return void e.onCancelledError(t)}e.onUnknownError(t)},this.watchId="watchid_".concat(+new Date,"_").concat(Math.random()),this.envId=t.envId,this.collectionName=t.collectionName,this.query=t.query,this.limit=t.limit,this.orderBy=t.orderBy,this.send=t.send,this.login=t.login,this.isWSConnected=t.isWSConnected,this.onceWSConnected=t.onceWSConnected,this.getWaitExpectedTimeoutLength=t.getWaitExpectedTimeoutLength,this.onWatchStart=t.onWatchStart,this.onWatchClose=t.onWatchClose,this.debug=t.debug,this.availableRetries={INIT_WATCH:2,REBUILD_WATCH:2,CHECK_LAST:2},this.listener=new di({close:function(){e.closeWatch()},onChange:t.onChange,onError:t.onError,debug:this.debug,virtualClient:this}),this.initWatch()}return t.prototype.onMessage=function(t){var e=this;switch(this.watchStatus){case hi.PAUSED:if("ERROR"!==t.msgType)return;break;case hi.LOGGINGIN:case hi.INITING:case hi.REBUILDING:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received while ".concat(this.watchStatus));case hi.CLOSED:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has closed");case hi.ERRORED:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has ended with error")}if(this.sessionInfo)switch(this.scheduleSendACK(),t.msgType){case"NEXT_EVENT":console.warn("nextevent ".concat(t.msgData.currEvent," ignored"),t),this.handleServerEvents(t);break;case"CHECK_EVENT":this.sessionInfo.currentEventId<t.msgData.currEvent&&(this.sessionInfo.expectEventId=t.msgData.currEvent,this.clearWaitExpectedEvent(),this.waitExpectedTimeoutId=setTimeout(function(){e.rebuildWatch()},this.getWaitExpectedTimeoutLength()),console.log("[realtime] waitExpectedTimeoutLength ".concat(this.getWaitExpectedTimeoutLength())));break;case"ERROR":this.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG,errMsg:"".concat(t.msgData.code," - ").concat(t.msgData.message)}));break;default:console.warn("[realtime listener] virtual client receive unexpected msg ".concat(t.msgType,": "),t)}else console.warn("[realtime listener] internal non-fatal error: sessionInfo not found while message is received.")},t.prototype.closeWithError=function(t){var e;this.watchStatus=hi.ERRORED,this.clearACKSchedule(),this.listener.onError(t),this.onWatchClose(this,(null===(e=this.sessionInfo)||void 0===e?void 0:e.queryID)||""),console.log("[realtime] client closed (".concat(this.collectionName," ").concat(this.query,") (watchId ").concat(this.watchId,")"))},t.prototype.pause=function(){this.watchStatus=hi.PAUSED,console.log("[realtime] client paused (".concat(this.collectionName," ").concat(this.query,") (watchId ").concat(this.watchId,")"))},t.prototype.resume=function(){return Ei(this,void 0,Promise,function(){var t;return Ii(this,function(e){switch(e.label){case 0:this.watchStatus=hi.RESUMING,console.log("[realtime] client resuming with ".concat(this.sessionInfo?"REBUILD_WATCH":"INIT_WATCH"," (").concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")")),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.sessionInfo?this.rebuildWatch():this.initWatch()];case 2:return e.sent(),console.log("[realtime] client successfully resumed (".concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")")),[3,4];case 3:return t=e.sent(),console.error("[realtime] client resume failed (".concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")"),t),[3,4];case 4:return[2]}})})},t.prototype.useRetryTicket=function(t){return!!(this.availableRetries[t]&&this.availableRetries[t]>0)&&(this.availableRetries[t]-=1,console.log("[realtime] ".concat(t," use a retry ticket, now only ").concat(this.availableRetries[t]," retry left")),!0)},t.prototype.handleServerEvents=function(t){return Ei(this,void 0,void 0,function(){var e;return Ii(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.scheduleSendACK(),[4,this.handleServerEventsInternel(t)];case 1:return n.sent(),this.postHandleServerEventsValidityCheck(t),[3,3];case 2:throw e=n.sent(),console.error("[realtime listener] internal non-fatal error: handle server events failed with error: ",e),e;case 3:return[2]}})})},t.prototype.handleServerEventsInternel=function(t){return Ei(this,void 0,void 0,function(){var e,n,r,o,i,s,a,c,u,l,h,d;return Ii(this,function(f){switch(f.label){case 0:if(e=t.requestId,n=t.msgData.events,r=t.msgType,!n.length||!this.sessionInfo)return[2];o=this.sessionInfo;try{i=n.map(Ti)}catch(t){return this.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA,errMsg:t})),[2]}s=Si([],o.currentDocs,!0),a=!1,c=function(n,c){var l,h,d,f,p,v,y,g,m,b,w,_;return Ii(this,function(E){switch(E.label){case 0:return l=i[n],o.currentEventId>=l.id?(!i[n-1]||l.id>i[n-1].id?console.warn("[realtime] duplicate event received, cur ".concat(o.currentEventId," but got ").concat(l.id)):console.error("[realtime listener] server non-fatal error: events out of order (the latter event's id is smaller than that of the former) (requestId ".concat(e,")")),[2,"continue"]):[3,1];case 1:if(o.currentEventId!==l.id-1)return[3,2];switch(l.dataType){case"update":if(!l.doc)switch(l.queueType){case"update":case"dequeue":if(h=s.find(function(t){return t._id===l.docId}),h){if(d=ui()(h),l.updatedFields&&Object.keys(l.updatedFields).forEach(function(t){ii()(d,t,l.updatedFields[t])}),l.removedFields)for(f=0,p=l.removedFields;f<p.length;f++)v=p[f],ai()(d,v);l.doc=d}else console.error("[realtime listener] internal non-fatal server error: unexpected update dataType event where no doc is associated.");break;case"enqueue":throw g=new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="update" and queueType="enqueue" (requestId '.concat(t.requestId,")")}),u.closeWithError(g),g}break;case"replace":if(!l.doc)throw g=new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="replace" (requestId '.concat(t.requestId,")")}),u.closeWithError(g),g;break;case"remove":(y=s.find(function(t){return t._id===l.docId}))?l.doc=y:console.error("[realtime listener] internal non-fatal server error: unexpected remove event where no doc is associated.");break;case"limit":if(!l.doc)switch(l.queueType){case"dequeue":(y=s.find(function(t){return t._id===l.docId}))?l.doc=y:console.error("[realtime listener] internal non-fatal server error: unexpected limit dataType event where no doc is associated.");break;case"enqueue":throw g=new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="limit" and queueType="enqueue" (requestId '.concat(t.requestId,")")}),u.closeWithError(g),g}}switch(l.queueType){case"init":a?s.push(l.doc):(a=!0,s=[l.doc]);break;case"enqueue":s.push(l.doc);break;case"dequeue":m=s.findIndex(function(t){return t._id===l.docId}),m>-1?s.splice(m,1):console.error("[realtime listener] internal non-fatal server error: unexpected dequeue event where no doc is associated.");break;case"update":m=s.findIndex(function(t){return t._id===l.docId}),m>-1?s[m]=l.doc:console.error("[realtime listener] internal non-fatal server error: unexpected queueType update event where no doc is associated.")}return(n===c-1||i[n+1]&&i[n+1].id!==l.id)&&(b=Si([],s,!0),w=i.slice(0,n+1).filter(function(t){return t.id===l.id}),u.sessionInfo.currentEventId=l.id,u.sessionInfo.currentDocs=s,_=new fi({id:l.id,docChanges:w,docs:b,msgType:r}),u.listener.onChange(_)),[3,4];case 2:return console.warn("[realtime listener] event received is out of order, cur ".concat(u.sessionInfo.currentEventId," but got ").concat(l.id)),[4,u.rebuildWatch()];case 3:return E.sent(),[2,{value:void 0}];case 4:return[2]}})},u=this,l=0,h=i.length,f.label=1;case 1:return l<h?[5,c(l,h)]:[3,4];case 2:if("object"==typeof(d=f.sent()))return[2,d.value];f.label=3;case 3:return l++,[3,1];case 4:return[2]}})})},t.prototype.postHandleServerEventsValidityCheck=function(t){this.sessionInfo?(this.sessionInfo.expectEventId&&this.sessionInfo.currentEventId>=this.sessionInfo.expectEventId&&this.clearWaitExpectedEvent(),this.sessionInfo.currentEventId<t.msgData.currEvent&&console.warn("[realtime listener] internal non-fatal error: client eventId does not match with server event id after server event handling")):console.error("[realtime listener] internal non-fatal error: sessionInfo lost after server event handling, this should never occur")},t.prototype.clearWaitExpectedEvent=function(){this.waitExpectedTimeoutId&&(clearTimeout(this.waitExpectedTimeoutId),this.waitExpectedTimeoutId=void 0)},t}();function Ti(t){var e={id:t.ID,dataType:t.DataType,queueType:t.QueueType,docId:t.DocID,doc:t.Doc&&"{}"!==t.Doc?JSON.parse(t.Doc):void 0};return"update"===t.DataType&&(t.UpdatedFields&&(e.updatedFields=JSON.parse(t.UpdatedFields)),(t.removedFields||t.RemovedFields)&&(e.removedFields=JSON.parse(t.removedFields))),e}var Ai,Pi={1e3:{code:1e3,name:"Normal Closure",description:"Normal closure; the connection successfully completed whatever purpose for which it was created."},1001:{code:1001,name:"Going Away",description:"The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection."},1002:{code:1002,name:"Protocol Error",description:"The endpoint is terminating the connection due to a protocol error."},1003:{code:1003,name:"Unsupported Data",description:"The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data)."},1005:{code:1005,name:"No Status Received",description:"Indicates that no status code was provided even though one was expected."},1006:{code:1006,name:"Abnormal Closure",description:"Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected."},1007:{code:1007,name:"Invalid frame payload data",description:"The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message)."},1008:{code:1008,name:"Policy Violation",description:"The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable."},1009:{code:1009,name:"Message too big",description:"The endpoint is terminating the connection because a data frame was received that is too large."},1010:{code:1010,name:"Missing Extension",description:"The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't."},1011:{code:1011,name:"Internal Error",description:"The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request."},1012:{code:1012,name:"Service Restart",description:"The server is terminating the connection because it is restarting."},1013:{code:1013,name:"Try Again Later",description:"The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients."},1014:{code:1014,name:"Bad Gateway",description:"The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code."},1015:{code:1015,name:"TLS Handshake",description:"Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified)."},3e3:{code:3e3,name:"Reconnect WebSocket",description:"The client is terminating the connection because it wants to reconnect"},3001:{code:3001,name:"No Realtime Listeners",description:"The client is terminating the connection because no more realtime listeners exist"},3002:{code:3002,name:"Heartbeat Ping Error",description:"The client is terminating the connection due to its failure in sending heartbeat messages"},3003:{code:3003,name:"Heartbeat Pong Timeout Error",description:"The client is terminating the connection because no heartbeat response is received from the server"},3050:{code:3050,name:"Server Close",description:"The client is terminating the connection because no heartbeat response is received from the server"}};!function(t){t[t.NormalClosure=1e3]="NormalClosure",t[t.GoingAway=1001]="GoingAway",t[t.ProtocolError=1002]="ProtocolError",t[t.UnsupportedData=1003]="UnsupportedData",t[t.NoStatusReceived=1005]="NoStatusReceived",t[t.AbnormalClosure=1006]="AbnormalClosure",t[t.InvalidFramePayloadData=1007]="InvalidFramePayloadData",t[t.PolicyViolation=1008]="PolicyViolation",t[t.MessageTooBig=1009]="MessageTooBig",t[t.MissingExtension=1010]="MissingExtension",t[t.InternalError=1011]="InternalError",t[t.ServiceRestart=1012]="ServiceRestart",t[t.TryAgainLater=1013]="TryAgainLater",t[t.BadGateway=1014]="BadGateway",t[t.TLSHandshake=1015]="TLSHandshake",t[t.ReconnectWebSocket=3e3]="ReconnectWebSocket",t[t.NoRealtimeListeners=3001]="NoRealtimeListeners",t[t.HeartbeatPingError=3002]="HeartbeatPingError",t[t.HeartbeatPongTimeoutError=3003]="HeartbeatPongTimeoutError",t[t.NoAuthentication=3050]="NoAuthentication"}(Ai||(Ai={}));var Ri=function(t,e){var n=Pi[t],r=n?"".concat(n.name,", code ").concat(t,", reason ").concat(e||n.description):"code ".concat(t);return new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED,errMsg:r})},Ci=null,ki="web";function Ni(){return Ci}function xi(){return ki}function Ui(t){ki=t}var Li=function(){return Li=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Li.apply(this,arguments)},Di=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},ji=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},qi=function(){function t(t){var e=this;this.virtualWSClient=new Set,this.queryIdClientMap=new Map,this.watchIdClientMap=new Map,this.pingFailed=0,this.pongMissed=0,this.logins=new Map,this.wsReadySubsribers=[],this.wsResponseWait=new Map,this.rttObserved=[],this.send=function(t){return Di(e,void 0,Promise,function(){var e=this;return ji(this,function(n){return[2,new Promise(function(n,r){Di(e,void 0,void 0,function(){var e,o,i,s,a,c,u,l,h=this;return ji(this,function(d){switch(d.label){case 0:o=!1,i=!1,s=function(t){o=!0,e&&clearTimeout(e),n(t)},a=function(t){i=!0,e&&clearTimeout(e),r(t)},t.timeout&&(e=setTimeout(function(){Di(h,void 0,void 0,function(){return ji(this,function(t){switch(t.label){case 0:return o&&i?[3,2]:[4,_i(0)];case 1:t.sent(),o&&i||a(new gi("wsclient.send timedout")),t.label=2;case 2:return[2]}})})},t.timeout)),d.label=1;case 1:return d.trys.push([1,8,,9]),void 0===this.wsInitPromise&&null===this.wsInitPromise?[3,3]:[4,this.wsInitPromise];case 2:d.sent(),d.label=3;case 3:if(!this.ws)return a(new Error("invalid state: ws connection not exists, can not send message")),[2];if(1!==this.ws.readyState)return a(new Error("ws readyState invalid: ".concat(this.ws.readyState,", can not send message"))),[2];t.waitResponse&&(c={resolve:s,reject:a,skipOnMessage:t.skipOnMessage},this.wsResponseWait.set(t.msg.requestId,c)),d.label=4;case 4:return d.trys.push([4,6,,7]),[4,this.ws.send(JSON.stringify(t.msg))];case 5:return d.sent(),t.waitResponse||s(void 0),[3,7];case 6:return(u=d.sent())&&(a(u),t.waitResponse&&this.wsResponseWait.delete(t.msg.requestId)),[3,7];case 7:return[3,9];case 8:return l=d.sent(),a(l),[3,9];case 9:return[2]}})})})]})})},this.closeAllClients=function(t){e.virtualWSClient.forEach(function(e){e.closeWithError(t)})},this.pauseClients=function(t){(t||e.virtualWSClient).forEach(function(t){t.pause()})},this.resumeClients=function(t){(t||e.virtualWSClient).forEach(function(t){t.resume()})},this.initWebSocketConnection=function(t,n){return void 0===n&&(n=e.maxReconnect),Di(e,void 0,Promise,function(){var e=this;return ji(this,function(r){switch(r.label){case 0:if(t&&this.reconnectState)return[2];if(t&&(this.reconnectState=!0),void 0!==this.wsInitPromise&&null!==this.wsInitPromise)return[2,this.wsInitPromise];t&&this.pauseClients(),this.close(Ai.ReconnectWebSocket),this.wsInitPromise=new Promise(function(r,o){Di(e,void 0,void 0,function(){var e,i,s=this;return ji(this,function(a){switch(a.label){case 0:return a.trys.push([0,6,,11]),[4,this.getWsSign()];case 1:return e=a.sent(),[4,new Promise(function(t){var n=e.wsUrl||"wss://tcb-ws.tencentcloudapi.com",r=Ni();s.ws=r?new r(n):new WebSocket(n),t(void 0)})];case 2:return a.sent(),this.ws.connect?[4,this.ws.connect()]:[3,4];case 3:a.sent(),a.label=4;case 4:return[4,this.initWebSocketEvent()];case 5:return a.sent(),r(),t&&(this.resumeClients(),this.reconnectState=!1),[3,11];case 6:return i=a.sent(),console.error("[realtime] initWebSocketConnection connect fail",i),n>0?(this.wsInitPromise=void 0,[4,_i(this.reconnectInterval)]):[3,9];case 7:a.sent(),t&&(this.reconnectState=!1),a.label=8;case 8:return r(this.initWebSocketConnection(t,n-1)),[3,10];case 9:o(i),t&&this.closeAllClients(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL,errMsg:i})),a.label=10;case 10:return[3,11];case 11:return[2]}})})}),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,this.wsInitPromise];case 2:return r.sent(),this.wsReadySubsribers.forEach(function(t){return(0,t.resolve)()}),[3,5];case 3:return r.sent(),this.wsReadySubsribers.forEach(function(t){return(0,t.reject)()}),[3,5];case 4:return this.wsInitPromise=void 0,this.wsReadySubsribers=[],[7];case 5:return[2]}})})},this.initWebSocketEvent=function(){return new Promise(function(t,n){if(!e.ws)throw new Error("can not initWebSocketEvent, ws not exists");var r=!1;e.ws.onopen=function(e){console.warn("[realtime] ws event: open",e),r=!0,t()},e.ws.onerror=function(t){e.logins=new Map,r?(console.error("[realtime] ws event: error",t),e.clearHeartbeat(),e.virtualWSClient.forEach(function(e){return e.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR,errMsg:t}))})):(console.error("[realtime] ws open failed with ws event: error",t),n(t))},e.ws.onclose=function(t){switch(console.warn("[realtime] ws event: close",t),e.logins=new Map,e.clearHeartbeat(),t.code){case Ai.ReconnectWebSocket:case Ai.NoRealtimeListeners:break;case Ai.HeartbeatPingError:case Ai.HeartbeatPongTimeoutError:case Ai.NormalClosure:case Ai.AbnormalClosure:e.maxReconnect>0?e.initWebSocketConnection(!0,e.maxReconnect):e.closeAllClients(Ri(t.code));break;case Ai.NoAuthentication:e.closeAllClients(Ri(t.code,t.reason));break;default:e.maxReconnect>0?e.initWebSocketConnection(!0,e.maxReconnect):e.closeAllClients(Ri(t.code))}},e.ws.onmessage=function(t){var n,r,o=(null===(n=t.data)||void 0===n?void 0:n.data)||t.data;e.heartbeat();try{r="string"==typeof o?JSON.parse(o):o}catch(t){throw new Error("[realtime] onMessage parse res.data error: ".concat(t))}if("ERROR"===r.msgType){var i=null;e.virtualWSClient.forEach(function(t){t.watchId===r.watchId&&(i=t)}),i&&i.listener.onError(r)}var s=e.wsResponseWait.get(r.requestId);if(s){try{"ERROR"===r.msgType?s.reject(new vi(r)):s.resolve(r)}catch(t){console.error("ws onMessage responseWaitSpec.resolve(msg) errored:",t)}finally{e.wsResponseWait.delete(r.requestId)}if(s.skipOnMessage)return}if("PONG"!==r.msgType){var a=r.watchId&&e.watchIdClientMap.get(r.watchId);if(a)a.onMessage(r);else switch(console.error("[realtime] no realtime listener found responsible for watchId ".concat(r.watchId,": "),r),r.msgType){case"INIT_EVENT":case"NEXT_EVENT":case"CHECK_EVENT":(a=e.queryIdClientMap.get(r.msgData.queryID))&&a.onMessage(r);break;default:for(var c=0,u=Array.from(e.watchIdClientMap.entries());c<u.length;c++){u[c][1].onMessage(r);break}}}else if(e.lastPingSendTS){var l=Date.now()-e.lastPingSendTS;if(l>1e4)return void console.warn("[realtime] untrusted rtt observed: ".concat(l));e.rttObserved.length>=3&&e.rttObserved.splice(0,e.rttObserved.length-3+1),e.rttObserved.push(l)}},e.heartbeat()})},this.isWSConnected=function(){return Boolean(e.ws&&1===e.ws.readyState)},this.onceWSConnected=function(){return Di(e,void 0,Promise,function(){var t=this;return ji(this,function(e){return this.isWSConnected()?[2]:null!==this.wsInitPromise&&void 0!==this.wsInitPromise?[2,this.wsInitPromise]:[2,new Promise(function(e,n){t.wsReadySubsribers.push({resolve:e,reject:n})})]})})},this.webLogin=function(t,n){return Di(e,void 0,Promise,function(){var e,r,o,i,s,a,c,u,l=this;return ji(this,function(h){switch(h.label){case 0:if(!n)if(t){if(e=this.logins.get(t)){if(e.loggedIn&&e.loginResult)return[2,e.loginResult];if(null!==e.loggingInPromise&&void 0!==e.loggingInPromise)return[2,e.loggingInPromise]}}else if(null!==(null==(r=this.logins.get(""))?void 0:r.loggingInPromise)&&void 0!==(null==r?void 0:r.loggingInPromise))return[2,r.loggingInPromise];o=new Promise(function(t,e){Di(l,void 0,void 0,function(){var n,r,o,i,s;return ji(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,this.getWsSign()];case 1:return n=a.sent(),r={envId:n.envId||"",accessToken:"",referrer:"web",sdkVersion:"",dataVersion:""},o={watchId:void 0,requestId:li(),msgType:"LOGIN",msgData:r,exMsgData:{runtime:xi(),signStr:n.signStr,secretVersion:n.secretVersion}},[4,this.send({msg:o,waitResponse:!0,skipOnMessage:!0,timeout:5e3})];case 2:return(i=a.sent()).msgData.code?e(new Error("".concat(i.msgData.code," ").concat(i.msgData.message))):t({envId:n.envId}),[3,4];case 3:return s=a.sent(),e(s),[3,4];case 4:return[2]}})})}),i=t&&this.logins.get(t),s=Date.now(),i?(i.loggedIn=!1,i.loggingInPromise=o,i.loginStartTS=s):(i={loggedIn:!1,loggingInPromise:o,loginStartTS:s},this.logins.set(t||"",i)),h.label=1;case 1:return h.trys.push([1,3,,4]),[4,o];case 2:if(a=h.sent(),(c=t&&this.logins.get(t))&&c===i&&c.loginStartTS===s)return i.loggedIn=!0,i.loggingInPromise=void 0,i.loginStartTS=void 0,i.loginResult=a,[2,a];if(c){if(c.loggedIn&&c.loginResult)return[2,c.loginResult];if(null!==c.loggingInPromise&&void 0!==c.loggingInPromise)return[2,c.loggingInPromise];throw new Error("ws unexpected login info")}throw new Error("ws login info reset");case 3:throw u=h.sent(),i.loggedIn=!1,i.loggingInPromise=void 0,i.loginStartTS=void 0,i.loginResult=void 0,u;case 4:return[2]}})})},this.getWsSign=function(){return Di(e,void 0,Promise,function(){var t,e,n,r,o,i,s;return ji(this,function(a){switch(a.label){case 0:return this.wsSign&&this.wsSign.expiredTs>Date.now()?[2,this.wsSign]:(t=Date.now()+6e4,[4,this.context.appConfig.request.send("auth.wsWebSign",{runtime:xi()})]);case 1:if((e=a.sent()).code)throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败: ".concat(e.code));if(e.data)return n=e.data,r=n.signStr,o=n.wsUrl,i=n.secretVersion,s=n.envId,[2,{signStr:r,wsUrl:o,secretVersion:i,envId:s,expiredTs:t}];throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败")}})})},this.getWaitExpectedTimeoutLength=function(){return e.rttObserved.length?e.rttObserved.reduce(function(t,e){return t+e})/e.rttObserved.length*1.5:5e3},this.ping=function(){return Di(e,void 0,void 0,function(){var t;return ji(this,function(e){switch(e.label){case 0:return t={watchId:void 0,requestId:li(),msgType:"PING",msgData:null},[4,this.send({msg:t})];case 1:return e.sent(),[2]}})})},this.onWatchStart=function(t,n){e.queryIdClientMap.set(n,t)},this.onWatchClose=function(t,n){n&&e.queryIdClientMap.delete(n),e.watchIdClientMap.delete(t.watchId),e.virtualWSClient.delete(t),e.virtualWSClient.size||e.close(Ai.NoRealtimeListeners)},this.maxReconnect=t.maxReconnect||5,this.reconnectInterval=t.reconnectInterval||1e4,this.context=t.context}return t.prototype.clearHeartbeat=function(){this.pingTimeoutId&&clearTimeout(this.pingTimeoutId),this.pongTimeoutId&&clearTimeout(this.pongTimeoutId)},t.prototype.close=function(t){this.clearHeartbeat(),this.ws&&(this.ws.close(t,Pi[t].name),this.ws=void 0)},t.prototype.watch=function(t){this.ws||void 0!==this.wsInitPromise&&null!==this.wsInitPromise||this.initWebSocketConnection(!1);var e=new Oi(Li(Li({},t),{send:this.send,login:this.webLogin,isWSConnected:this.isWSConnected,onceWSConnected:this.onceWSConnected,getWaitExpectedTimeoutLength:this.getWaitExpectedTimeoutLength,onWatchStart:this.onWatchStart,onWatchClose:this.onWatchClose,debug:!0}));return this.virtualWSClient.add(e),this.watchIdClientMap.set(e.watchId,e),e.listener},t.prototype.heartbeat=function(t){var e=this;this.clearHeartbeat(),this.pingTimeoutId=setTimeout(function(){Di(e,void 0,void 0,function(){var t=this;return ji(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),this.ws&&1===this.ws.readyState?(this.lastPingSendTS=Date.now(),[4,this.ping()]):[2];case 1:return e.sent(),this.pingFailed=0,this.pongTimeoutId=setTimeout(function(){console.error("pong timed out"),t.pongMissed<2?(t.pongMissed+=1,t.heartbeat(!0)):t.initWebSocketConnection(!0)},this.context.appConfig.realtimePongWaitTimeout),[3,3];case 2:return e.sent(),this.pingFailed<2?(this.pingFailed+=1,this.heartbeat()):this.close(Ai.HeartbeatPingError),[3,3];case 3:return[2]}})})},t?0:this.context.appConfig.realtimePingInterval)},t}(),Mi={target:"database",entity:function(){var t,e=this.platform,n=e.adapter,r=e.runtime;t=n.wsClass,Ci=t,Ui(r)}},Bi={name:"realtime",IIFE:!0,entity:function(){this.prototype.wsClientClass=qi}};try{cloudbase.registerComponent(Bi),cloudbase.registerHook(Mi)}catch(t){}var Wi=function(){function t(){}return t.detectEnvironment=function(){var t;if("undefined"!=typeof WebSocket)return{type:"native",wsConstructor:WebSocket};var e=globalThis;if("undefined"!=typeof globalThis&&void 0!==e.WebSocket)return{type:"native",wsConstructor:e.WebSocket};var n=void 0!==l.g?l.g:void 0;if(n&&void 0!==n.WebSocket)return{type:"native",wsConstructor:n.WebSocket};if("undefined"!=typeof globalThis&&void 0!==e.WebSocketPair&&void 0===globalThis.WebSocket)return{type:"cloudflare",error:"Cloudflare Workers detected. WebSocket clients are not supported in Cloudflare Workers.",workaround:"Use Cloudflare Workers WebSocket API for server-side WebSocket handling, or deploy to a different runtime."};if("undefined"!=typeof globalThis&&e.EdgeRuntime||"undefined"!=typeof navigator&&(null===(t=navigator.userAgent)||void 0===t?void 0:t.includes("Vercel-Edge")))return{type:"unsupported",error:"Edge runtime detected (Vercel Edge/Netlify Edge). WebSockets are not supported in edge functions.",workaround:"Use serverless functions or a different deployment target for WebSocket functionality."};var r=globalThis.process;if(r){var o=r.versions;if(o&&o.node)return{type:"unsupported",error:"Node.js detected but native WebSocket not found.",workaround:"Ensure you are running Node.js 22+ or provide a WebSocket implementation via the transport option."}}return{type:"unsupported",error:"Unknown JavaScript runtime without WebSocket support.",workaround:"Ensure you're running in a supported environment (browser, Node.js, Deno) or provide a custom WebSocket implementation."}},t.getWebSocketConstructor=function(){var t=this.detectEnvironment();if(t.wsConstructor)return t.wsConstructor;var e=t.error||"WebSocket not supported in this environment.";throw t.workaround&&(e+="\n\nSuggested solution: ".concat(t.workaround)),new Error(e)},t.isWebSocketSupported=function(){try{return"native"===this.detectEnvironment().type}catch(t){return!1}},t}();const Fi=Wi;"realtime-js/".concat("1.0.0-alpha.0");var Hi="1.0.0",Vi="2.0.0",Gi=Vi,Ki="errored",Ji="joined",zi="phx_close",$i="phx_error",Yi="phx_join",Qi="phx_leave",Xi=function(){function t(t){this.HEADER_LENGTH=1,this.USER_BROADCAST_PUSH_META_LENGTH=6,this.KINDS={userBroadcastPush:3,userBroadcast:4},this.BINARY_ENCODING=0,this.JSON_ENCODING=1,this.BROADCAST_EVENT="broadcast",this.allowedMetadataKeys=[],this.allowedMetadataKeys=null!=t?t:[]}return t.prototype.encode=function(t,e){if(t.event===this.BROADCAST_EVENT&&!(t.payload instanceof ArrayBuffer)&&"string"==typeof t.payload.event)return e(this._binaryEncodeUserBroadcastPush(t));var n=[t.join_ref,t.ref,t.topic,t.event,t.payload];return e(JSON.stringify(n))},t.prototype._binaryEncodeUserBroadcastPush=function(t){var e;return this._isArrayBuffer(null===(e=t.payload)||void 0===e?void 0:e.payload)?this._encodeBinaryUserBroadcastPush(t):this._encodeJsonUserBroadcastPush(t)},t.prototype._encodeBinaryUserBroadcastPush=function(t){var e,n,r=null!==(n=null===(e=t.payload)||void 0===e?void 0:e.payload)&&void 0!==n?n:new ArrayBuffer(0);return this._encodeUserBroadcastPush(t,this.BINARY_ENCODING,r)},t.prototype._encodeJsonUserBroadcastPush=function(t){var e,n,r=null!==(n=null===(e=t.payload)||void 0===e?void 0:e.payload)&&void 0!==n?n:{},o=(new TextEncoder).encode(JSON.stringify(r)).buffer;return this._encodeUserBroadcastPush(t,this.JSON_ENCODING,o)},t.prototype._encodeUserBroadcastPush=function(t,e,n){var r,o,i=new TextEncoder,s=i.encode(t.topic),a=i.encode(null!==(r=t.ref)&&void 0!==r?r:""),c=i.encode(null!==(o=t.join_ref)&&void 0!==o?o:""),u=i.encode(t.payload.event),l=this.allowedMetadataKeys?this._pick(t.payload,this.allowedMetadataKeys):{},h=i.encode(0===Object.keys(l).length?"":JSON.stringify(l));if(c.length>255)throw new Error("joinRef length ".concat(c.length," exceeds maximum of 255"));if(a.length>255)throw new Error("ref length ".concat(a.length," exceeds maximum of 255"));if(s.length>255)throw new Error("topic length ".concat(s.length," exceeds maximum of 255"));if(u.length>255)throw new Error("userEvent length ".concat(u.length," exceeds maximum of 255"));if(h.length>255)throw new Error("metadata length ".concat(h.length," exceeds maximum of 255"));var d=this.USER_BROADCAST_PUSH_META_LENGTH+c.length+a.length+s.length+u.length+h.length,f=new ArrayBuffer(this.HEADER_LENGTH+d),p=new DataView(f),v=new Uint8Array(f),y=0;p.setUint8(y++,this.KINDS.userBroadcastPush),p.setUint8(y++,c.length),p.setUint8(y++,a.length),p.setUint8(y++,s.length),p.setUint8(y++,u.length),p.setUint8(y++,h.length),p.setUint8(y++,e),v.set(c,y),y+=c.length,v.set(a,y),y+=a.length,v.set(s,y),y+=s.length,v.set(u,y),y+=u.length,v.set(h,y),y+=h.length;var g=new Uint8Array(f.byteLength+n.byteLength);return g.set(new Uint8Array(f),0),g.set(new Uint8Array(n),f.byteLength),g.buffer},t.prototype.decode=function(t,e){if(this._isArrayBuffer(t))return e(this._binaryDecode(t));if("string"==typeof t){var n=JSON.parse(t);return e({join_ref:n[0],ref:n[1],topic:n[2],event:n[3],payload:n[4]})}return e({})},t.prototype._binaryDecode=function(t){var e=new DataView(t),n=e.getUint8(0),r=new TextDecoder;if(n===this.KINDS.userBroadcast)return this._decodeUserBroadcast(t,e,r)},t.prototype._decodeUserBroadcast=function(t,e,n){var r=e.getUint8(1),o=e.getUint8(2),i=e.getUint8(3),s=e.getUint8(4),a=this.HEADER_LENGTH+4,c=n.decode(t.slice(a,a+r));a+=r;var u=n.decode(t.slice(a,a+o));a+=o;var l=n.decode(t.slice(a,a+i));a+=i;var h=t.slice(a,t.byteLength),d=s===this.JSON_ENCODING?JSON.parse(n.decode(h)):h,f={type:this.BROADCAST_EVENT,event:u,payload:d};return i>0&&(f.meta=JSON.parse(l)),{join_ref:null,ref:null,topic:c,event:this.BROADCAST_EVENT,payload:f}},t.prototype._isArrayBuffer=function(t){var e;return t instanceof ArrayBuffer||"ArrayBuffer"===(null===(e=null==t?void 0:t.constructor)||void 0===e?void 0:e.name)},t.prototype._pick=function(t,e){return t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(function(t){var n=t[0];return e.includes(n)})):{}},t}();const Zi=Xi;var ts;!function(t){t.abstime="abstime",t.bool="bool",t.date="date",t.daterange="daterange",t.float4="float4",t.float8="float8",t.int2="int2",t.int4="int4",t.int4range="int4range",t.int8="int8",t.int8range="int8range",t.json="json",t.jsonb="jsonb",t.money="money",t.numeric="numeric",t.oid="oid",t.reltime="reltime",t.text="text",t.time="time",t.timestamp="timestamp",t.timestamptz="timestamptz",t.timetz="timetz",t.tsrange="tsrange",t.tstzrange="tstzrange"}(ts||(ts={}));var es=function(t,e,n){var r;void 0===n&&(n={});var o=null!==(r=n.skipTypes)&&void 0!==r?r:[];return e?Object.keys(e).reduce(function(n,r){return n[r]=ns(r,t,e,o),n},{}):{}},ns=function(t,e,n,r){var o=e.find(function(e){return e.name===t}),i=null==o?void 0:o.type,s=n[t];return i&&!r.includes(i)?rs(i,s):os(s)},rs=function(t,e){if("_"===t.charAt(0)){var n=t.slice(1,t.length);return cs(e,n)}switch(t){case ts.bool:return is(e);case ts.float4:case ts.float8:case ts.int2:case ts.int4:case ts.int8:case ts.numeric:case ts.oid:return ss(e);case ts.json:case ts.jsonb:return as(e);case ts.timestamp:return us(e);case ts.abstime:case ts.date:case ts.daterange:case ts.int4range:case ts.int8range:case ts.money:case ts.reltime:case ts.text:case ts.time:case ts.timestamptz:case ts.timetz:case ts.tsrange:case ts.tstzrange:default:return os(e)}},os=function(t){return t},is=function(t){switch(t){case"t":return!0;case"f":return!1;default:return t}},ss=function(t){if("string"==typeof t){var e=parseFloat(t);if(!Number.isNaN(e))return e}return t},as=function(t){if("string"==typeof t)try{return JSON.parse(t)}catch(e){return t}return t},cs=function(t,e){if("string"!=typeof t)return t;var n=t.length-1,r=t[n];if("{"===t[0]&&"}"===r){var o=void 0,i=t.slice(1,n);try{o=JSON.parse("["+i+"]")}catch(t){o=i?i.split(","):[]}return o.map(function(t){return rs(e,t)})}return t},us=function(t){return"string"==typeof t?t.replace(" ","T"):t};function ls(t){var e=t.indexOf("#"),n=-1===e?t:t.slice(0,e),r=-1===e?"":t.slice(e),o=n.indexOf("?");return{base:-1===o?n:n.slice(0,o),query:-1===o?"":n.slice(o),hash:r}}var hs=function(t){var e=ls(t),n=e.base,r=e.query,o=e.hash,i=n.replace(/^ws/i,"http").replace(/\/+$/,"");return(i=(i=i.replace(/\/socket\/websocket$/i,"").replace(/\/socket$/i,"").replace(/\/websocket$/i,"")).replace(/\/+$/,"")+"/api/broadcast")+r+o},ds=t=>"function"==typeof t?t:function(){return t},fs="undefined"!=typeof self?self:null,ps="undefined"!=typeof window?window:null,vs=fs||ps||globalThis,ys="closed",gs="errored",ms="joined",bs="joining",ws="leaving",_s="phx_close",Es="phx_error",Is="phx_reply",Ss="phx_leave",Os="websocket",Ts="base64url.bearer.phx.",As=class{constructor(t,e,n,r){this.channel=t,this.event=e,this.payload=n||function(){return{}},this.receivedResp=null,this.timeout=r,this.timeoutTimer=null,this.recHooks=[],this.sent=!1,this.ref=void 0}resend(t){this.timeout=t,this.reset(),this.send()}send(){this.hasReceived("timeout")||(this.startTimeout(),this.sent=!0,this.channel.socket.push({topic:this.channel.topic,event:this.event,payload:this.payload(),ref:this.ref,join_ref:this.channel.joinRef()}))}receive(t,e){return this.hasReceived(t)&&e(this.receivedResp.response),this.recHooks.push({status:t,callback:e}),this}reset(){this.cancelRefEvent(),this.ref=null,this.refEvent=null,this.receivedResp=null,this.sent=!1}destroy(){this.cancelRefEvent(),this.cancelTimeout()}matchReceive({status:t,response:e,_ref:n}){this.recHooks.filter(e=>e.status===t).forEach(t=>t.callback(e))}cancelRefEvent(){this.refEvent&&this.channel.off(this.refEvent)}cancelTimeout(){clearTimeout(this.timeoutTimer),this.timeoutTimer=null}startTimeout(){this.timeoutTimer&&this.cancelTimeout(),this.ref=this.channel.socket.makeRef(),this.refEvent=this.channel.replyEventName(this.ref),this.channel.on(this.refEvent,t=>{this.cancelRefEvent(),this.cancelTimeout(),this.receivedResp=t,this.matchReceive(t)}),this.timeoutTimer=setTimeout(()=>{this.trigger("timeout",{})},this.timeout)}hasReceived(t){return this.receivedResp&&this.receivedResp.status===t}trigger(t,e){this.channel.trigger(this.refEvent,{status:t,response:e})}},Ps=class{constructor(t,e){this.callback=t,this.timerCalc=e,this.timer=void 0,this.tries=0}reset(){this.tries=0,clearTimeout(this.timer)}scheduleTimeout(){clearTimeout(this.timer),this.timer=setTimeout(()=>{this.tries=this.tries+1,this.callback()},this.timerCalc(this.tries+1))}},Rs=class{constructor(t,e,n){this.state=ys,this.topic=t,this.params=ds(e||{}),this.socket=n,this.bindings=[],this.bindingRef=0,this.timeout=this.socket.timeout,this.joinedOnce=!1,this.joinPush=new As(this,"phx_join",this.params,this.timeout),this.pushBuffer=[],this.stateChangeRefs=[],this.rejoinTimer=new Ps(()=>{this.socket.isConnected()&&this.rejoin()},this.socket.rejoinAfterMs),this.stateChangeRefs.push(this.socket.onError(()=>this.rejoinTimer.reset())),this.stateChangeRefs.push(this.socket.onOpen(()=>{this.rejoinTimer.reset(),this.isErrored()&&this.rejoin()})),this.joinPush.receive("ok",()=>{this.state=ms,this.rejoinTimer.reset(),this.pushBuffer.forEach(t=>t.send()),this.pushBuffer=[]}),this.joinPush.receive("error",t=>{this.state=gs,this.socket.hasLogger()&&this.socket.log("channel",`error ${this.topic}`,t),this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.onClose(()=>{this.rejoinTimer.reset(),this.socket.hasLogger()&&this.socket.log("channel",`close ${this.topic}`),this.state=ys,this.socket.remove(this)}),this.onError(t=>{this.socket.hasLogger()&&this.socket.log("channel",`error ${this.topic}`,t),this.isJoining()&&this.joinPush.reset(),this.state=gs,this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.joinPush.receive("timeout",()=>{this.socket.hasLogger()&&this.socket.log("channel",`timeout ${this.topic}`,this.joinPush.timeout),new As(this,Ss,ds({}),this.timeout).send(),this.state=gs,this.joinPush.reset(),this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.on(Is,(t,e)=>{this.trigger(this.replyEventName(e),t)})}join(t=this.timeout){if(this.joinedOnce)throw new Error("tried to join multiple times. 'join' can only be called a single time per channel instance");return this.timeout=t,this.joinedOnce=!0,this.rejoin(),this.joinPush}teardown(){this.pushBuffer.forEach(t=>t.destroy()),this.pushBuffer=[],this.rejoinTimer.reset(),this.joinPush.destroy(),this.state=ys,this.bindings=[]}onClose(t){this.on(_s,t)}onError(t){return this.on(Es,e=>t(e))}on(t,e){let n=this.bindingRef++;return this.bindings.push({event:t,ref:n,callback:e}),n}off(t,e){this.bindings=this.bindings.filter(n=>!(n.event===t&&(void 0===e||e===n.ref)))}canPush(){return this.socket.isConnected()&&this.isJoined()}push(t,e,n=this.timeout){if(e=e||{},!this.joinedOnce)throw new Error(`tried to push '${t}' to '${this.topic}' before joining. Use channel.join() before pushing events`);let r=new As(this,t,function(){return e},n);return this.canPush()?r.send():(r.startTimeout(),this.pushBuffer.push(r)),r}leave(t=this.timeout){this.rejoinTimer.reset(),this.joinPush.cancelTimeout(),this.state=ws;let e=()=>{this.socket.hasLogger()&&this.socket.log("channel",`leave ${this.topic}`),this.trigger(_s,"leave")},n=new As(this,Ss,ds({}),t);return n.receive("ok",()=>e()).receive("timeout",()=>e()),n.send(),this.canPush()||n.trigger("ok",{}),n}onMessage(t,e,n){return e}filterBindings(t,e,n){return!0}isMember(t,e,n,r){return!(this.topic!==t||r&&r!==this.joinRef()&&(this.socket.hasLogger()&&this.socket.log("channel","dropping outdated message",{topic:t,event:e,payload:n,joinRef:r}),1))}joinRef(){return this.joinPush.ref}rejoin(t=this.timeout){this.isLeaving()||(this.socket.leaveOpenTopic(this.topic),this.state=bs,this.joinPush.resend(t))}trigger(t,e,n,r){let o=this.onMessage(t,e,n,r);if(e&&!o)throw new Error("channel onMessage callbacks must return the payload, modified or unmodified");let i=this.bindings.filter(r=>r.event===t&&this.filterBindings(r,e,n));for(let t=0;t<i.length;t++)i[t].callback(o,n,r||this.joinRef())}replyEventName(t){return`chan_reply_${t}`}isClosed(){return this.state===ys}isErrored(){return this.state===gs}isJoined(){return this.state===ms}isJoining(){return this.state===bs}isLeaving(){return this.state===ws}},Cs=class{static request(t,e,n,r,o,i,s){if(vs.XDomainRequest){let n=new vs.XDomainRequest;return this.xdomainRequest(n,t,e,r,o,i,s)}if(vs.XMLHttpRequest){let a=new vs.XMLHttpRequest;return this.xhrRequest(a,t,e,n,r,o,i,s)}if(vs.fetch&&vs.AbortController)return this.fetchRequest(t,e,n,r,o,i,s);throw new Error("No suitable XMLHttpRequest implementation found")}static fetchRequest(t,e,n,r,o,i,s){let a={method:t,headers:n,body:r},c=null;return o&&(c=new AbortController,setTimeout(()=>c.abort(),o),a.signal=c.signal),vs.fetch(e,a).then(t=>t.text()).then(t=>this.parseJSON(t)).then(t=>s&&s(t)).catch(t=>{"AbortError"===t.name&&i?i():s&&s(null)}),c}static xdomainRequest(t,e,n,r,o,i,s){return t.timeout=o,t.open(e,n),t.onload=()=>{let e=this.parseJSON(t.responseText);s&&s(e)},i&&(t.ontimeout=i),t.onprogress=()=>{},t.send(r),t}static xhrRequest(t,e,n,r,o,i,s,a){t.open(e,n,!0),t.timeout=i;for(let[e,n]of Object.entries(r))t.setRequestHeader(e,n);return t.onerror=()=>a&&a(null),t.onreadystatechange=()=>{if(4===t.readyState&&a){let e=this.parseJSON(t.responseText);a(e)}},s&&(t.ontimeout=s),t.send(o),t}static parseJSON(t){if(!t||""===t)return null;try{return JSON.parse(t)}catch{return console&&console.log("failed to parse JSON response",t),null}}static serialize(t,e){let n=[];for(var r in t){if(!Object.prototype.hasOwnProperty.call(t,r))continue;let o=e?`${e}[${r}]`:r,i=t[r];"object"==typeof i?n.push(this.serialize(i,o)):n.push(encodeURIComponent(o)+"="+encodeURIComponent(i))}return n.join("&")}static appendParams(t,e){if(0===Object.keys(e).length)return t;let n=t.match(/\?/)?"&":"?";return`${t}${n}${this.serialize(e)}`}},ks=class{constructor(t,e){e&&2===e.length&&e[1].startsWith(Ts)&&(this.authToken=atob(e[1].slice(21))),this.endPoint=null,this.token=null,this.skipHeartbeat=!0,this.reqs=new Set,this.awaitingBatchAck=!1,this.currentBatch=null,this.currentBatchTimer=null,this.batchBuffer=[],this.onopen=function(){},this.onerror=function(){},this.onmessage=function(){},this.onclose=function(){},this.pollEndpoint=this.normalizeEndpoint(t),this.readyState=0,setTimeout(()=>this.poll(),0)}normalizeEndpoint(t){return t.replace("ws://","http://").replace("wss://","https://").replace(new RegExp("(.*)/"+Os),"$1/longpoll")}endpointURL(){return Cs.appendParams(this.pollEndpoint,{token:this.token})}closeAndRetry(t,e,n){this.close(t,e,n),this.readyState=0}ontimeout(){this.onerror("timeout"),this.closeAndRetry(1005,"timeout",!1)}isActive(){return 1===this.readyState||0===this.readyState}poll(){const t={Accept:"application/json"};this.authToken&&(t["X-Phoenix-AuthToken"]=this.authToken),this.ajax("GET",t,null,()=>this.ontimeout(),t=>{if(t){var{status:e,token:n,messages:r}=t;if(410===e&&null!==this.token)return this.onerror(410),void this.closeAndRetry(3410,"session_gone",!1);this.token=n}else e=0;switch(e){case 200:r.forEach(t=>{setTimeout(()=>this.onmessage({data:t}),0)}),this.poll();break;case 204:this.poll();break;case 410:this.readyState=1,this.onopen({}),this.poll();break;case 403:this.onerror(403),this.close(1008,"forbidden",!1);break;case 0:case 500:this.onerror(500),this.closeAndRetry(1011,"internal server error",500);break;default:throw new Error(`unhandled poll status ${e}`)}})}send(t){"string"!=typeof t&&(t=(t=>{let e="",n=new Uint8Array(t),r=n.byteLength;for(let t=0;t<r;t++)e+=String.fromCharCode(n[t]);return btoa(e)})(t)),this.currentBatch?this.currentBatch.push(t):this.awaitingBatchAck?this.batchBuffer.push(t):(this.currentBatch=[t],this.currentBatchTimer=setTimeout(()=>{this.batchSend(this.currentBatch),this.currentBatch=null},0))}batchSend(t,e=0){this.awaitingBatchAck=!0;const n=e+100,r=t.slice(e,n);this.ajax("POST",{"Content-Type":"application/x-ndjson"},r.join("\n"),()=>this.onerror("timeout"),e=>{e&&200===e.status?n<t.length?this.batchSend(t,n):this.batchBuffer.length>0?(this.batchSend(this.batchBuffer),this.batchBuffer=[]):this.awaitingBatchAck=!1:(this.awaitingBatchAck=!1,this.onerror(e&&e.status),this.closeAndRetry(1011,"internal server error",!1))})}close(t,e,n){for(let t of this.reqs)t.abort();this.readyState=3;let r=Object.assign({code:1e3,reason:void 0,wasClean:!0},{code:t,reason:e,wasClean:n});this.batchBuffer=[],clearTimeout(this.currentBatchTimer),this.currentBatchTimer=null,"undefined"!=typeof CloseEvent?this.onclose(new CloseEvent("close",r)):this.onclose(r)}ajax(t,e,n,r,o){let i;i=Cs.request(t,this.endpointURL(),e,n,this.timeout,()=>{this.reqs.delete(i),r()},t=>{this.reqs.delete(i),this.isActive()&&o(t)}),this.reqs.add(i)}},Ns=class t{constructor(e,n={}){let r=n.events||{state:"presence_state",diff:"presence_diff"};this.state=Object.create(null),this.pendingDiffs=[],this.channel=e,this.joinRef=null,this.caller={onJoin:function(){},onLeave:function(){},onSync:function(){}},this.channel.on(r.state,e=>{let{onJoin:n,onLeave:r,onSync:o}=this.caller;this.joinRef=this.channel.joinRef(),this.state=t.syncState(this.state,e,n,r),this.pendingDiffs.forEach(e=>{this.state=t.syncDiff(this.state,e,n,r)}),this.pendingDiffs=[],o()}),this.channel.on(r.diff,e=>{let{onJoin:n,onLeave:r,onSync:o}=this.caller;this.inPendingSyncState()?this.pendingDiffs.push(e):(this.state=t.syncDiff(this.state,e,n,r),o())})}onJoin(t){this.caller.onJoin=t}onLeave(t){this.caller.onLeave=t}onSync(t){this.caller.onSync=t}list(e){return t.list(this.state,e)}inPendingSyncState(){return!this.joinRef||this.joinRef!==this.channel.joinRef()}static syncState(t,e,n,r){let o=this.toNullProtoObj(this.clone(t));e=this.toNullProtoObj(e);let i=Object.create(null),s=Object.create(null);return this.map(o,(t,n)=>{e[t]||(s[t]=n)}),this.map(e,(t,e)=>{let n=o[t];if(n){let r=e.metas.map(t=>t.phx_ref),o=n.metas.map(t=>t.phx_ref),a=e.metas.filter(t=>o.indexOf(t.phx_ref)<0),c=n.metas.filter(t=>r.indexOf(t.phx_ref)<0);a.length>0&&(i[t]=e,i[t].metas=a),c.length>0&&(s[t]=this.clone(n),s[t].metas=c)}else i[t]=e}),this.syncDiff(o,{joins:i,leaves:s},n,r)}static syncDiff(t,e,n,r){t=this.toNullProtoObj(t);let{joins:o,leaves:i}=this.clone(e);return n||(n=function(){}),r||(r=function(){}),this.map(o,(e,r)=>{let o=t[e];if(t[e]=this.clone(r),o){let n=t[e].metas.map(t=>t.phx_ref),r=o.metas.filter(t=>n.indexOf(t.phx_ref)<0);t[e].metas.unshift(...r)}n(e,o,r)}),this.map(i,(e,n)=>{let o=t[e];if(!o)return;let i=n.metas.map(t=>t.phx_ref);o.metas=o.metas.filter(t=>i.indexOf(t.phx_ref)<0),r(e,o,n),0===o.metas.length&&delete t[e]}),t}static list(t,e){return e||(e=function(t,e){return e}),this.map(t,(t,n)=>e(t,n))}static map(t,e){return Object.getOwnPropertyNames(t).map(n=>e(n,t[n]))}static toNullProtoObj(t){if(null===Object.getPrototypeOf(t))return t;let e=Object.create(null);return Object.getOwnPropertyNames(t).forEach(n=>{e[n]=t[n]}),e}static clone(t){return JSON.parse(JSON.stringify(t))}},xs={HEADER_LENGTH:1,META_LENGTH:4,KINDS:{push:0,reply:1,broadcast:2},encode(t,e){if(t.payload.constructor===ArrayBuffer)return e(this.binaryEncode(t));{let n=[t.join_ref,t.ref,t.topic,t.event,t.payload];return e(JSON.stringify(n))}},decode(t,e){if(t.constructor===ArrayBuffer)return e(this.binaryDecode(t));{let[n,r,o,i,s]=JSON.parse(t);return e({join_ref:n,ref:r,topic:o,event:i,payload:s})}},binaryEncode(t){let{join_ref:e,ref:n,event:r,topic:o,payload:i}=t,s=new TextEncoder,a=s.encode(e),c=s.encode(n),u=s.encode(o),l=s.encode(r);this.assertFieldSize(a.byteLength,"join_ref"),this.assertFieldSize(c.byteLength,"ref"),this.assertFieldSize(u.byteLength,"topic"),this.assertFieldSize(l.byteLength,"event");let h=this.META_LENGTH+a.byteLength+c.byteLength+u.byteLength+l.byteLength,d=new ArrayBuffer(this.HEADER_LENGTH+h),f=new Uint8Array(d),p=new DataView(d),v=0;p.setUint8(v++,this.KINDS.push),p.setUint8(v++,a.byteLength),p.setUint8(v++,c.byteLength),p.setUint8(v++,u.byteLength),p.setUint8(v++,l.byteLength),f.set(a,v),v+=a.byteLength,f.set(c,v),v+=c.byteLength,f.set(u,v),v+=u.byteLength,f.set(l,v),v+=l.byteLength;var y=new Uint8Array(d.byteLength+i.byteLength);return y.set(f,0),y.set(new Uint8Array(i),d.byteLength),y.buffer},assertFieldSize(t,e){if(t>255)throw new Error(`unable to convert ${e} to binary: must be less than or equal to 255 bytes, but is ${t} bytes`)},binaryDecode(t){let e=new DataView(t),n=e.getUint8(0),r=new TextDecoder;switch(n){case this.KINDS.push:return this.decodePush(t,e,r);case this.KINDS.reply:return this.decodeReply(t,e,r);case this.KINDS.broadcast:return this.decodeBroadcast(t,e,r)}},decodePush(t,e,n){let r=e.getUint8(1),o=e.getUint8(2),i=e.getUint8(3),s=this.HEADER_LENGTH+this.META_LENGTH-1,a=n.decode(t.slice(s,s+r));s+=r;let c=n.decode(t.slice(s,s+o));s+=o;let u=n.decode(t.slice(s,s+i));return s+=i,{join_ref:a,ref:null,topic:c,event:u,payload:t.slice(s,t.byteLength)}},decodeReply(t,e,n){let r=e.getUint8(1),o=e.getUint8(2),i=e.getUint8(3),s=e.getUint8(4),a=this.HEADER_LENGTH+this.META_LENGTH,c=n.decode(t.slice(a,a+r));a+=r;let u=n.decode(t.slice(a,a+o));a+=o;let l=n.decode(t.slice(a,a+i));a+=i;let h=n.decode(t.slice(a,a+s));a+=s;let d=t.slice(a,t.byteLength);return{join_ref:c,ref:u,topic:l,event:Is,payload:{status:h,response:d}}},decodeBroadcast(t,e,n){let r=e.getUint8(1),o=e.getUint8(2),i=this.HEADER_LENGTH+2,s=n.decode(t.slice(i,i+r));i+=r;let a=n.decode(t.slice(i,i+o));return i+=o,{join_ref:null,ref:null,topic:s,event:a,payload:t.slice(i,t.byteLength)}}},Us=class{constructor(t,e={}){this.stateChangeCallbacks={open:[],close:[],error:[],message:[]},this.channels=[],this.sendBuffer=[],this.ref=0,this.fallbackRef=null,this.timeout=e.timeout||1e4,this.transport=e.transport||vs.WebSocket||ks,this.conn=void 0,this.primaryPassedHealthCheck=!1,this.longPollFallbackMs=e.longPollFallbackMs,this.fallbackTimer=null;let n=null;try{n=vs&&vs.sessionStorage}catch{}this.sessionStore=e.sessionStorage||n,this.establishedConnections=0,this.defaultEncoder=xs.encode.bind(xs),this.defaultDecoder=xs.decode.bind(xs),this.closeWasClean=!0,this.disconnecting=!1,this.binaryType=e.binaryType||"arraybuffer",this.connectClock=1,this.pageHidden=!1,this.encode=void 0,this.decode=void 0,this.transport!==ks?(this.encode=e.encode||this.defaultEncoder,this.decode=e.decode||this.defaultDecoder):(this.encode=this.defaultEncoder,this.decode=this.defaultDecoder);let r=null;ps&&ps.addEventListener&&(ps.addEventListener("pagehide",t=>{this.conn&&(this.disconnect(),r=this.connectClock)}),ps.addEventListener("pageshow",t=>{r===this.connectClock&&(r=null,this.connect())}),ps.addEventListener("visibilitychange",()=>{"hidden"===document.visibilityState?this.pageHidden=!0:(this.pageHidden=!1,this.isConnected()||this.closeWasClean||this.teardown(()=>this.connect()))})),this.heartbeatIntervalMs=e.heartbeatIntervalMs||3e4,this.autoSendHeartbeat=e.autoSendHeartbeat??!0,this.heartbeatCallback=e.heartbeatCallback??(()=>{}),this.rejoinAfterMs=t=>e.rejoinAfterMs?e.rejoinAfterMs(t):[1e3,2e3,5e3][t-1]||1e4,this.reconnectAfterMs=t=>e.reconnectAfterMs?e.reconnectAfterMs(t):[10,50,100,150,200,250,500,1e3,2e3][t-1]||5e3,this.logger=e.logger||null,!this.logger&&e.debug&&(this.logger=(t,e,n)=>{console.log(`${t}: ${e}`,n)}),this.longpollerTimeout=e.longpollerTimeout||2e4,this.params=ds(e.params||{}),this.endPoint=`${t}/${Os}`,this.vsn=e.vsn||"2.0.0",this.heartbeatTimeoutTimer=null,this.heartbeatTimer=null,this.heartbeatSentAt=null,this.pendingHeartbeatRef=null,this.reconnectTimer=new Ps(()=>{if(this.pageHidden)return this.log("Not reconnecting as page is hidden!"),void this.teardown();this.teardown(async()=>{e.beforeReconnect&&await e.beforeReconnect(),this.connect()})},this.reconnectAfterMs),this.authToken=e.authToken&&ds(e.authToken)}getLongPollTransport(){return ks}replaceTransport(t){this.connectClock++,this.closeWasClean=!0,clearTimeout(this.fallbackTimer),this.reconnectTimer.reset(),this.conn&&(this.conn.close(),this.conn=null),this.transport=t}protocol(){return location.protocol.match(/^https/)?"wss":"ws"}endPointURL(){let t=Cs.appendParams(Cs.appendParams(this.endPoint,this.params()),{vsn:this.vsn});return"/"!==t.charAt(0)?t:"/"===t.charAt(1)?`${this.protocol()}:${t}`:`${this.protocol()}://${location.host}${t}`}disconnect(t,e,n){this.connectClock++,this.disconnecting=!0,this.closeWasClean=!0,clearTimeout(this.fallbackTimer),this.reconnectTimer.reset(),this.teardown(()=>{this.disconnecting=!1,t&&t()},e,n)}connect(t){t&&(console&&console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor"),this.params=ds(t)),this.conn&&!this.disconnecting||(this.longPollFallbackMs&&this.transport!==ks?this.connectWithFallback(ks,this.longPollFallbackMs):this.transportConnect())}log(t,e,n){this.logger&&this.logger(t,e,n)}hasLogger(){return null!==this.logger}onOpen(t){let e=this.makeRef();return this.stateChangeCallbacks.open.push([e,t]),e}onClose(t){let e=this.makeRef();return this.stateChangeCallbacks.close.push([e,t]),e}onError(t){let e=this.makeRef();return this.stateChangeCallbacks.error.push([e,t]),e}onMessage(t){let e=this.makeRef();return this.stateChangeCallbacks.message.push([e,t]),e}onHeartbeat(t){this.heartbeatCallback=t}ping(t){if(!this.isConnected())return!1;let e=this.makeRef(),n=Date.now();this.push({topic:"phoenix",event:"heartbeat",payload:{},ref:e});let r=this.onMessage(o=>{o.ref===e&&(this.off([r]),t(Date.now()-n))});return!0}transportName(t){return t===ks?"LongPoll":t.name}transportConnect(){let t;this.connectClock++,this.closeWasClean=!1,this.authToken&&(t=["phoenix",`${Ts}${btoa(this.authToken()).replace(/=/g,"")}`]),this.conn=new this.transport(this.endPointURL(),t),this.conn.binaryType=this.binaryType,this.conn.timeout=this.longpollerTimeout,this.conn.onopen=()=>this.onConnOpen(),this.conn.onerror=t=>this.onConnError(t),this.conn.onmessage=t=>this.onConnMessage(t),this.conn.onclose=t=>this.onConnClose(t)}getSession(t){return this.sessionStore&&this.sessionStore.getItem(t)}storeSession(t,e){this.sessionStore&&this.sessionStore.setItem(t,e)}connectWithFallback(t,e=2500){clearTimeout(this.fallbackTimer);let n,r=!1,o=!0,i=this.transportName(t),s=e=>{this.log("transport",`falling back to ${i}...`,e),this.off([void 0,n]),o=!1,this.replaceTransport(t),this.transportConnect()};if(this.getSession(`phx:fallback:${i}`))return s("memorized");this.fallbackTimer=setTimeout(s,e),n=this.onError(t=>{this.log("transport","error",t),o&&!r&&(clearTimeout(this.fallbackTimer),s(t))}),this.fallbackRef&&this.off([this.fallbackRef]),this.fallbackRef=this.onOpen(()=>{if(r=!0,!o){let e=this.transportName(t);return this.primaryPassedHealthCheck||this.storeSession(`phx:fallback:${e}`,"true"),this.log("transport",`established ${e} fallback`)}clearTimeout(this.fallbackTimer),this.fallbackTimer=setTimeout(s,e),this.ping(t=>{this.log("transport","connected to primary after",t),this.primaryPassedHealthCheck=!0,clearTimeout(this.fallbackTimer)})}),this.transportConnect()}clearHeartbeats(){clearTimeout(this.heartbeatTimer),clearTimeout(this.heartbeatTimeoutTimer)}onConnOpen(){this.hasLogger()&&this.log("transport",`connected to ${this.endPointURL()}`),this.closeWasClean=!1,this.disconnecting=!1,this.establishedConnections++,this.flushSendBuffer(),this.reconnectTimer.reset(),this.autoSendHeartbeat&&this.resetHeartbeat(),this.triggerStateCallbacks("open")}heartbeatTimeout(){if(this.pendingHeartbeatRef){this.pendingHeartbeatRef=null,this.heartbeatSentAt=null,this.hasLogger()&&this.log("transport","heartbeat timeout. Attempting to re-establish connection");try{this.heartbeatCallback("timeout")}catch(t){this.log("error","error in heartbeat callback",t)}this.triggerChanError(new Error("heartbeat timeout")),this.closeWasClean=!1,this.teardown(()=>this.reconnectTimer.scheduleTimeout(),1e3,"heartbeat timeout")}}resetHeartbeat(){this.conn&&this.conn.skipHeartbeat||(this.pendingHeartbeatRef=null,this.clearHeartbeats(),this.heartbeatTimer=setTimeout(()=>this.sendHeartbeat(),this.heartbeatIntervalMs))}teardown(t,e,n){if(!this.conn)return t&&t();const r=this.conn;this.waitForBufferDone(r,()=>{e?r.close(e,n||""):r.close(),this.waitForSocketClosed(r,()=>{this.conn===r&&(this.conn.onopen=function(){},this.conn.onerror=function(){},this.conn.onmessage=function(){},this.conn.onclose=function(){},this.conn=null),t&&t()})})}waitForBufferDone(t,e,n=1){5!==n&&t.bufferedAmount?setTimeout(()=>{this.waitForBufferDone(t,e,n+1)},150*n):e()}waitForSocketClosed(t,e,n=1){5!==n&&3!==t.readyState?setTimeout(()=>{this.waitForSocketClosed(t,e,n+1)},150*n):e()}onConnClose(t){this.conn&&(this.conn.onclose=()=>{}),this.hasLogger()&&this.log("transport","close",t),this.triggerChanError(t),this.clearHeartbeats(),this.closeWasClean||this.reconnectTimer.scheduleTimeout(),this.triggerStateCallbacks("close",t)}onConnError(t){this.hasLogger()&&this.log("transport","error",t);let e=this.transport,n=this.establishedConnections;this.triggerStateCallbacks("error",t,e,n),(e===this.transport||n>0)&&this.triggerChanError(t)}triggerChanError(t){this.channels.forEach(e=>{e.isErrored()||e.isLeaving()||e.isClosed()||e.trigger(Es,t)})}connectionState(){switch(this.conn&&this.conn.readyState){case 0:return"connecting";case 1:return"open";case 2:return"closing";default:return"closed"}}isConnected(){return"open"===this.connectionState()}remove(t){this.off(t.stateChangeRefs),this.channels=this.channels.filter(e=>e!==t)}off(t){for(let e in this.stateChangeCallbacks)this.stateChangeCallbacks[e]=this.stateChangeCallbacks[e].filter(([e])=>-1===t.indexOf(e))}channel(t,e={}){let n=new Rs(t,e,this);return this.channels.push(n),n}push(t){if(this.hasLogger()){let{topic:e,event:n,payload:r,ref:o,join_ref:i}=t;this.log("push",`${e} ${n} (${i}, ${o})`,r)}this.isConnected()?this.encode(t,t=>this.conn.send(t)):this.sendBuffer.push(()=>this.encode(t,t=>this.conn.send(t)))}makeRef(){let t=this.ref+1;return t===this.ref?this.ref=0:this.ref=t,this.ref.toString()}sendHeartbeat(){if(this.isConnected())if(this.pendingHeartbeatRef)this.heartbeatTimeout();else{this.pendingHeartbeatRef=this.makeRef(),this.heartbeatSentAt=Date.now(),this.push({topic:"phoenix",event:"heartbeat",payload:{},ref:this.pendingHeartbeatRef});try{this.heartbeatCallback("sent")}catch(t){this.log("error","error in heartbeat callback",t)}this.heartbeatTimeoutTimer=setTimeout(()=>this.heartbeatTimeout(),this.heartbeatIntervalMs)}else try{this.heartbeatCallback("disconnected")}catch(t){this.log("error","error in heartbeat callback",t)}}flushSendBuffer(){this.isConnected()&&this.sendBuffer.length>0&&(this.sendBuffer.forEach(t=>t()),this.sendBuffer=[])}onConnMessage(t){this.decode(t.data,t=>{let{topic:e,event:n,payload:r,ref:o,join_ref:i}=t;if(o&&o===this.pendingHeartbeatRef){const t=this.heartbeatSentAt?Date.now()-this.heartbeatSentAt:void 0;this.clearHeartbeats();try{this.heartbeatCallback("ok"===r.status?"ok":"error",t)}catch(t){this.log("error","error in heartbeat callback",t)}this.pendingHeartbeatRef=null,this.heartbeatSentAt=null,this.autoSendHeartbeat&&(this.heartbeatTimer=setTimeout(()=>this.sendHeartbeat(),this.heartbeatIntervalMs))}this.hasLogger()&&this.log("receive",`${r.status||""} ${e} ${n} ${o&&"("+o+")"||""}`.trim(),r);for(let t=0;t<this.channels.length;t++){const s=this.channels[t];s.isMember(e,n,r,i)&&s.trigger(n,r,o,i)}this.triggerStateCallbacks("message",t)})}triggerStateCallbacks(t,...e){try{this.stateChangeCallbacks[t].forEach(([n,r])=>{try{r(...e)}catch(e){this.log("error",`error in ${t} callback`,e)}})}catch(e){this.log("error",`error triggering ${t} callbacks`,e)}}leaveOpenTopic(t){let e=this.channels.find(e=>e.topic===t&&(e.isJoined()||e.isJoining()));e&&(this.hasLogger()&&this.log("transport",`leaving duplicate topic "${t}"`),e.leave())}},Ls=function(){function t(e,n){var r=function(t){return(null==t?void 0:t.events)&&{events:t.events}}(n);this.presence=new Ns(e.getChannel(),r),this.presence.onJoin(function(n,r,o){var i=t.onJoinPayload(n,r,o);e.getChannel().trigger("presence",i)}),this.presence.onLeave(function(n,r,o){var i=t.onLeavePayload(n,r,o);e.getChannel().trigger("presence",i)}),this.presence.onSync(function(){e.getChannel().trigger("presence",{event:"sync"})})}return Object.defineProperty(t.prototype,"state",{get:function(){return t.transformState(this.presence.state)},enumerable:!1,configurable:!0}),t.transformState=function(t){return t=function(t){return JSON.parse(JSON.stringify(t))}(t),Object.getOwnPropertyNames(t).reduce(function(e,n){var r=t[n];return e[n]=js(r),e},{})},t.onJoinPayload=function(t,e,n){return{event:"join",key:t,currentPresences:qs(e),newPresences:js(n)}},t.onLeavePayload=function(t,e,n){return{event:"leave",key:t,currentPresences:qs(e),leftPresences:js(n)}},t}();const Ds=Ls;function js(t){return t.metas.map(function(t){var e=Object.getOwnPropertyDescriptors(t),n=Object.defineProperties({},e);return n.presence_ref=n.phx_ref,delete n.phx_ref,delete n.phx_ref_prev,n})}function qs(t){return(null==t?void 0:t.metas)?js(t):[]}var Ms;!function(t){t.SYNC="sync",t.JOIN="join",t.LEAVE="leave"}(Ms||(Ms={}));const Bs=function(){function t(t,e){this.channel=t,this.presenceAdapter=new Ds(this.channel.channelAdapter,e)}return Object.defineProperty(t.prototype,"state",{get:function(){return this.presenceAdapter.state},enumerable:!1,configurable:!0}),t}();var Ws=function(){return Ws=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ws.apply(this,arguments)};const Fs=function(){function t(t,e,n){var r={config:Ws({broadcast:{ack:!1,self:!1},presence:{key:"",enabled:!1},private:!1},n.config)};this.channel=t.getSocket().channel(e,r),this.socket=t}return Object.defineProperty(t.prototype,"state",{get:function(){return this.channel.state},set:function(t){this.channel.state=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"joinedOnce",{get:function(){return this.channel.joinedOnce},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"joinPush",{get:function(){return this.channel.joinPush},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rejoinTimer",{get:function(){return this.channel.rejoinTimer},enumerable:!1,configurable:!0}),t.prototype.on=function(t,e){return this.channel.on(t,e)},t.prototype.off=function(t,e){this.channel.off(t,e)},t.prototype.subscribe=function(t){return this.channel.join(t)},t.prototype.unsubscribe=function(t){return this.channel.leave(t)},t.prototype.teardown=function(){this.channel.teardown()},t.prototype.detachLifecycleHooks=function(){this.channel.off(zi),this.channel.off($i)},t.prototype.onClose=function(t){this.channel.onClose(t)},t.prototype.onError=function(t){return this.channel.onError(t)},t.prototype.push=function(t,e,n){var r;try{r=this.channel.push(t,e,n)}catch(e){throw new Error("tried to push '".concat(t,"' to '").concat(this.channel.topic,"' before joining. Use channel.subscribe() before pushing events"))}if(this.channel.pushBuffer.length>100){var o=this.channel.pushBuffer.shift();o.cancelTimeout(),this.socket.log("channel","discarded push due to buffer overflow: ".concat(o.event),o.payload())}return r},t.prototype.updateJoinPayload=function(t){var e=this.channel.joinPush.payload();this.channel.joinPush.payload=function(){return Ws(Ws({},e),t)}},t.prototype.canPush=function(){return this.socket.isConnected()&&this.state===Ji},t.prototype.isJoined=function(){return this.state===Ji},t.prototype.isJoining=function(){return"joining"===this.state},t.prototype.isClosed=function(){return"closed"===this.state},t.prototype.isLeaving=function(){return"leaving"===this.state},t.prototype.updateFilterBindings=function(t){this.channel.filterBindings=t},t.prototype.updatePayloadTransform=function(t){this.channel.onMessage=t},t.prototype.getChannel=function(){return this.channel},t}();var Hs,Vs,Gs,Ks=/[,()"\\]/,Js=function(t){var e=null===t?"null":String(t);return function(t){return Ks.test(t)||t!==t.trim()}(e)?function(t){return'"'.concat(t.replace(/\\/g,"\\\\").replace(/"/g,'\\"'),'"')}(e):e},zs=function(){function t(){this.filters=[]}return t.prototype.add=function(t,e,n,r){void 0===r&&(r=!1);var o=r?"not.":"";return this.filters.push("".concat(t,"=").concat(o).concat(function(t,e){if("in"===t){var n=Array.isArray(e)?e:[e];if(0===n.length)throw new Error("Realtime `in` filter requires at least one value.");var r=Array.from(new Set(n)).map(function(t){return Js(t)}).join(",");return"in.(".concat(r,")")}return"is"===t?"is.".concat(function(t){return null===t?"null":String(t)}(e)):"".concat(t,".").concat(Js(e))}(e,n))),this},t.prototype.eq=function(t,e){return this.add(t,"eq",e)},t.prototype.neq=function(t,e){return this.add(t,"neq",e)},t.prototype.gt=function(t,e){return this.add(t,"gt",e)},t.prototype.gte=function(t,e){return this.add(t,"gte",e)},t.prototype.lt=function(t,e){return this.add(t,"lt",e)},t.prototype.lte=function(t,e){return this.add(t,"lte",e)},t.prototype.in=function(t,e){return this.add(t,"in",e)},t.prototype.like=function(t,e){return this.add(t,"like",e)},t.prototype.ilike=function(t,e){return this.add(t,"ilike",e)},t.prototype.match=function(t,e){return this.add(t,"match",e)},t.prototype.imatch=function(t,e){return this.add(t,"imatch",e)},t.prototype.is=function(t,e){return this.add(t,"is",e)},t.prototype.isDistinct=function(t,e){return this.add(t,"isdistinct",e)},t.prototype.not=function(t,e,n){return this.add(t,e,n,!0)},t.prototype.build=function(){return this.filters.join(",")},t.prototype.toString=function(){return this.build()},t}(),$s=function(){return $s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},$s.apply(this,arguments)},Ys=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Qs=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(t){t.ALL="*",t.INSERT="INSERT",t.UPDATE="UPDATE",t.DELETE="DELETE"}(Hs||(Hs={})),function(t){t.BROADCAST="broadcast",t.PRESENCE="presence",t.POSTGRES_CHANGES="postgres_changes",t.SYSTEM="system"}(Vs||(Vs={})),function(t){t.SUBSCRIBED="SUBSCRIBED",t.TIMED_OUT="TIMED_OUT",t.CLOSED="CLOSED",t.CHANNEL_ERROR="CHANNEL_ERROR"}(Gs||(Gs={}));var Xs=function(){function t(t,e,n){void 0===e&&(e={config:{}});var r,o,i=this;if(this.topic=t,this.params=e,this.socket=n,this.bindings={},this.subTopic=t.replace(/^realtime:/i,""),this.params.config=$s({broadcast:{ack:!1,self:!1},presence:{key:"",enabled:!1},private:!1},e.config),this.channelAdapter=new Fs(this.socket.socketAdapter,t,this.params),this.presence=new Bs(this),this._onClose(function(){i.socket._remove(i)}),this._updateFilterTransform(),this.private=this.params.config.private||!1,!this.private&&(null===(o=null===(r=this.params.config)||void 0===r?void 0:r.broadcast)||void 0===o?void 0:o.replay))throw new Error("tried to use replay on public channel '".concat(this.topic,"'. It must be a private channel."))}return Object.defineProperty(t.prototype,"state",{get:function(){return this.channelAdapter.state},set:function(t){this.channelAdapter.state=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"joinedOnce",{get:function(){return this.channelAdapter.joinedOnce},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"timeout",{get:function(){return this.socket.timeout},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"broadcastEndpointURL",{get:function(){return hs(this.socket.socketAdapter.endPointURL())},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"joinPush",{get:function(){return this.channelAdapter.joinPush},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rejoinTimer",{get:function(){return this.channelAdapter.rejoinTimer},enumerable:!1,configurable:!0}),t.prototype.subscribe=function(t,e){var n,r,o,i;if(void 0===e&&(e=this.timeout),this.socket.isConnected()||this.socket.connect(),this.channelAdapter.isClosed()){var s=this.params.config,a=s.broadcast,c=s.presence,u=s.private,l=s.postgres_changes_options,h=null!==(r=null===(n=this.bindings.postgres_changes)||void 0===n?void 0:n.map(function(t){return t.filter}))&&void 0!==r?r:[],d=!!this.bindings[Vs.PRESENCE]&&this.bindings[Vs.PRESENCE].length>0||!0===(null===(o=this.params.config.presence)||void 0===o?void 0:o.enabled),f=$s({broadcast:a,presence:$s($s({},c),{enabled:d}),postgres_changes:h,private:u},l?{postgres_changes_options:l}:{});this._subscribeCallback=t,this._subscribeTimeout=e,this._bindSubscribeLifecycle(),this.updateJoinPayload({config:f}),this._updateFilterMessage();var p=(null==l?void 0:l.wait)&&h.length>0?Math.max(e,(null!==(i=l.timeout)&&void 0!==i?i:15e3)+1e4):e;this._subscribeJoinTimeout=p,this.channelAdapter.subscribe(p),this._bindJoinPushReceivers()}return this},t.prototype._warmupOn=function(t){var e=this,n=new Fs(t,this.topic,this.params);return n.updateJoinPayload(this.channelAdapter.joinPush.payload()),new Promise(function(t,r){var o,i;n.subscribe(null!==(i=null!==(o=e._subscribeJoinTimeout)&&void 0!==o?o:e._subscribeTimeout)&&void 0!==i?i:e.timeout).receive("ok",function(o){var i=o.postgres_changes;void 0===i||e._postgresBindingsAlign(i)?t({adapter:n,postgres_changes:i}):r(new Error("mismatch between server and client bindings for postgres changes"))}).receive("error",function(t){var e=Object.values(t).join(", ")||"error";r(new Error(e,{cause:t}))}).receive("timeout",function(){r(new Error("standby channel join timed out"))})})},t.prototype._adopt=function(t){var e=this,n=this.channelAdapter;n.detachLifecycleHooks(),n.teardown(),this.channelAdapter=t.adapter;for(var r=0,o=Object.keys(this.bindings);r<o.length;r++)for(var i=o[r],s=0,a=this.bindings[i];s<a.length;s++){var c=a[s];c.ref=this.channelAdapter.on(c.type,c.callback)}this._updateFilterMessage(),this._updateFilterTransform(),void 0!==t.postgres_changes&&this._applyPostgresBindingIds(t.postgres_changes),this._onClose(function(){e.socket._remove(e)}),this._bindSubscribeLifecycle(),this._bindJoinPushReceivers({skipImmediate:!0}),this.presence=new Bs(this)},t.prototype._bindSubscribeLifecycle=function(){if(this._subscribeCallback){var t=this._subscribeCallback;this._onError(function(e){t(Gs.CHANNEL_ERROR,function(t){if(t instanceof Error)return t;if("string"==typeof t)return new Error(t);if(t&&"object"==typeof t){var e=t;if("number"==typeof e.code){var n="string"==typeof e.reason&&e.reason?" (".concat(e.reason,")"):"";return new Error("socket closed: ".concat(e.code).concat(n),{cause:t})}return new Error("channel error: transport failure",{cause:t})}return new Error("channel error: connection lost")}(e))}),this._onClose(function(){return t(Gs.CLOSED)})}},t.prototype._bindJoinPushReceivers=function(t){var e,n=this,r=function(t){var e=t.postgres_changes;return Ys(n,void 0,void 0,function(){var t;return Qs(this,function(n){return this.socket._isManualToken()||this.socket.setAuth(),void 0===e?(null===(t=this._subscribeCallback)||void 0===t||t.call(this,Gs.SUBSCRIBED),[2]):(this._updatePostgresBindings(e,this._subscribeCallback),[2])})})},o=function(t){var e;n.state=Ki;var r=Object.values(t).join(", ")||"error";null===(e=n._subscribeCallback)||void 0===e||e.call(n,Gs.CHANNEL_ERROR,new Error(r,{cause:t}))},i=function(){var t;null===(t=n._subscribeCallback)||void 0===t||t.call(n,Gs.TIMED_OUT)},s=this.channelAdapter.joinPush;if((null==t?void 0:t.skipImmediate)&&"ok"===(null===(e=s.receivedResp)||void 0===e?void 0:e.status))return s.recHooks.push({status:"ok",callback:r}),s.recHooks.push({status:"error",callback:o}),void s.recHooks.push({status:"timeout",callback:i});this.channelAdapter.joinPush.receive("ok",r),this.channelAdapter.joinPush.receive("error",o),this.channelAdapter.joinPush.receive("timeout",i)},t.prototype._postgresBindingsAlign=function(e){for(var n,r=this.bindings.postgres_changes,o=null!==(n=null==r?void 0:r.length)&&void 0!==n?n:0,i=0;i<o;i++){var s=r[i].filter,a=s.event,c=s.schema,u=s.table,l=s.filter,h=e&&e[i];if(!(h&&h.event===a&&t.isFilterValueEqual(h.schema,c)&&t.isFilterValueEqual(h.table,u)&&t.isFilterValueEqual(h.filter,l)))return!1}return!0},t.prototype._applyPostgresBindingIds=function(t){for(var e,n=this.bindings.postgres_changes,r=null!==(e=null==n?void 0:n.length)&&void 0!==e?e:0,o=[],i=0;i<r;i++){var s=n[i],a=t&&t[i];o.push($s($s({},s),{id:null==a?void 0:a.id}))}this.bindings.postgres_changes=o},t.prototype._updatePostgresBindings=function(t,e){if(!this._postgresBindingsAlign(t))return this.unsubscribe(),this.state=Ki,void(null==e||e(Gs.CHANNEL_ERROR,new Error("mismatch between server and client bindings for postgres changes")));this._applyPostgresBindingIds(t),this.state!=Ki&&e&&e(Gs.SUBSCRIBED)},t.prototype.presenceState=function(){return this.presence.state},t.prototype.track=function(t,e){return void 0===e&&(e={}),Ys(this,void 0,Promise,function(){return Qs(this,function(n){switch(n.label){case 0:return[4,this.send({type:"presence",event:"track",payload:t},e)];case 1:return[2,n.sent()]}})})},t.prototype.untrack=function(t){return void 0===t&&(t={}),Ys(this,void 0,Promise,function(){return Qs(this,function(e){switch(e.label){case 0:return[4,this.send({type:"presence",event:"untrack"},t)];case 1:return[2,e.sent()]}})})},t.prototype.on=function(t,e,n){var r=this.channelAdapter.isJoined()||this.channelAdapter.isJoining(),o=t===Vs.PRESENCE||t===Vs.POSTGRES_CHANGES;if(r&&o)throw this.socket.log("channel","cannot add `".concat(t,"` callbacks for ").concat(this.topic," after `subscribe()`.")),new Error("cannot add `".concat(t,"` callbacks for ").concat(this.topic," after `subscribe()`."));return this._on(t,e,n)},t.prototype.httpSend=function(t,e,n){var r;return void 0===n&&(n={}),Ys(this,void 0,Promise,function(){var o,i,s,a,c,u,l;return Qs(this,function(h){switch(h.label){case 0:return null==e?[2,Promise.reject(new Error("Payload is required for httpSend()"))]:[4,this.socket.setAuth()];case 1:return h.sent(),o=e instanceof ArrayBuffer||ArrayBuffer.isView(e),i={apikey:this.socket.apiKey?this.socket.apiKey:"","Content-Type":o?"application/octet-stream":"application/json"},this.socket.accessTokenValue&&(i.Authorization="Bearer ".concat(this.socket.accessTokenValue)),s=function(t,e,n,r){var o=ls(t),i=o.base,s=o.query,a=o.hash,c="/".concat(encodeURIComponent(e),"/events/").concat(encodeURIComponent(n)),u=i.replace(/\/+$/,"")+c,l=[];if(s.startsWith("?")&&s.length>1&&l.push(s.slice(1)),r)for(var h=0,d=Object.entries(r);h<d.length;h++){var f=d[h],p=f[0],v=f[1];l.push("".concat(encodeURIComponent(p),"=").concat(encodeURIComponent(v)))}return u+(l.length?"?".concat(l.join("&")):"")+a}(this.broadcastEndpointURL,this.subTopic,t,this.private?{private:"true"}:void 0),a={method:"POST",headers:i,body:o?e:JSON.stringify(e)},[4,this._fetchWithTimeout(s,a,null!==(r=n.timeout)&&void 0!==r?r:this.timeout)];case 2:if(202===(c=h.sent()).status)return[2,{success:!0}];if(404===c.status)return[2,Promise.reject(new Error("httpSend() requires Realtime server v2.97.0 or newer; the endpoint returned 404. Update your Supabase CLI to a recent version, or upgrade the Realtime server in your self-hosted setup. See https://github.com/TencentCloudBase/cloudbase-js-sdk/blob/master/packages/realtime-js/migrations/httpsend-server-version.md"))];u=c.statusText,h.label=3;case 3:return h.trys.push([3,5,,6]),[4,c.json()];case 4:return l=h.sent(),u=l.error||l.message||u,[3,6];case 5:return h.sent(),[3,6];case 6:return[2,Promise.reject(new Error(u))]}})})},t.prototype.send=function(t,e){var n,r;return void 0===e&&(e={}),Ys(this,void 0,Promise,function(){var o,i,s,a,c,u,l,h=this;return Qs(this,function(d){switch(d.label){case 0:return this.channelAdapter.canPush()||"broadcast"!==t.type?[3,7]:(o="Realtime send() is automatically falling back to REST API. This behavior will be deprecated in the future. Please use httpSend() explicitly for REST delivery.",this.socket.hasLogger()?this.socket.log("channel",o):console.warn(o),i=t.event,s=t.payload,[4,this.socket.setAuth()]);case 1:d.sent(),a={apikey:this.socket.apiKey?this.socket.apiKey:"","Content-Type":"application/json"},this.socket.accessTokenValue&&(a.Authorization="Bearer ".concat(this.socket.accessTokenValue)),c={method:"POST",headers:a,body:JSON.stringify({messages:[{topic:this.subTopic,event:i,payload:s,private:this.private}]})},d.label=2;case 2:return d.trys.push([2,5,,6]),[4,this._fetchWithTimeout(this.broadcastEndpointURL,c,null!==(n=e.timeout)&&void 0!==n?n:this.timeout)];case 3:return u=d.sent(),[4,null===(r=u.body)||void 0===r?void 0:r.cancel()];case 4:return d.sent(),[2,u.ok?"ok":"error"];case 5:return(l=d.sent())instanceof Error&&"AbortError"===l.name?[2,"timed out"]:[2,"error"];case 6:return[3,8];case 7:return[2,new Promise(function(n){var r,o,i,s=h.channelAdapter.push(t.type,t,e.timeout||h.timeout);"broadcast"!==t.type||(null===(i=null===(o=null===(r=h.params)||void 0===r?void 0:r.config)||void 0===o?void 0:o.broadcast)||void 0===i?void 0:i.ack)||n("ok"),s.receive("ok",function(){return n("ok")}),s.receive("error",function(){return n("error")}),s.receive("timeout",function(){return n("timed out")})})];case 8:return[2]}})})},t.prototype.updateJoinPayload=function(t){this.channelAdapter.updateJoinPayload(t)},t.prototype.unsubscribe=function(t){return void 0===t&&(t=this.timeout),Ys(this,void 0,void 0,function(){var e=this;return Qs(this,function(n){return[2,new Promise(function(n){e.channelAdapter.unsubscribe(t).receive("ok",function(){return n("ok")}).receive("timeout",function(){return n("timed out")}).receive("error",function(){return n("error")})})]})})},t.prototype.teardown=function(){this.channelAdapter.teardown()},t.prototype._fetchWithTimeout=function(t,e,n){return Ys(this,void 0,void 0,function(){var r,o,i,s;return Qs(this,function(a){switch(a.label){case 0:if(r=function(){var t=new Error("The operation was aborted");return t.name="AbortError",t},"undefined"!=typeof AbortController)return[3,4];a.label=1;case 1:return a.trys.push([1,,3,4]),[4,Promise.race([this.socket.fetch(t,e),new Promise(function(t,e){o=setTimeout(function(){return e(r())},n)})])];case 2:return[2,a.sent()];case 3:return o&&clearTimeout(o),[7];case 4:i=new AbortController,s=setTimeout(function(){return i.abort()},n),a.label=5;case 5:return a.trys.push([5,,7,8]),[4,this.socket.fetch(t,$s($s({},e),{signal:i.signal}))];case 6:return[2,a.sent()];case 7:return clearTimeout(s),[7];case 8:return[2]}})})},t.prototype._on=function(e,n,r){var o,i=e.toLocaleLowerCase(),s=null==n?void 0:n.filter;if((s instanceof zs||"object"==typeof s&&null!==s&&"function"==typeof s.build)&&(n=$s($s({},n),{filter:s.build()})),i===Vs.POSTGRES_CHANGES&&(null===(o=this.bindings[i])||void 0===o?void 0:o.find(function(e){return t.isSamePostgresFilter(e.filter,n)})))return this.socket.log("error","duplicate `postgres_changes` binding for ".concat(this.topic," ignored"),n),this;var a=this.channelAdapter.on(e,r),c={type:i,filter:n,callback:r,ref:a};return this.bindings[i]?this.bindings[i].push(c):this.bindings[i]=[c],this._updateFilterMessage(),this},t.prototype._onClose=function(t){this.channelAdapter.onClose(t)},t.prototype._onError=function(t){this.channelAdapter.onError(t)},t.prototype._updateFilterMessage=function(){var t=this;this.channelAdapter.updateFilterBindings(function(e,n,r){var o,i,s,a,c,u,l,h=e.event.toLocaleLowerCase();if(t._notThisChannelEvent(h,r))return!1;var d=null===(o=t.bindings[h])||void 0===o?void 0:o.find(function(t){return t.ref===e.ref});if(!d)return!0;if(["broadcast","presence","postgres_changes"].includes(h)){if("id"in d){var f=d.id,p=null===(i=d.filter)||void 0===i?void 0:i.event;return f&&(null===(s=n.ids)||void 0===s?void 0:s.includes(f))&&("*"===p||(null==p?void 0:p.toLocaleLowerCase())===(null===(a=n.data)||void 0===a?void 0:a.type.toLocaleLowerCase()))}return"*"===(p=null===(u=null===(c=null==d?void 0:d.filter)||void 0===c?void 0:c.event)||void 0===u?void 0:u.toLocaleLowerCase())||p===(null===(l=null==n?void 0:n.event)||void 0===l?void 0:l.toLocaleLowerCase())}return d.type.toLocaleLowerCase()===h})},t.prototype._notThisChannelEvent=function(t,e){return e&&[zi,$i,Qi,Yi].includes(t)&&e!==this.joinPush.ref},t.prototype._updateFilterTransform=function(){var t=this;this.channelAdapter.updatePayloadTransform(function(e,n,r){if("object"==typeof n&&"ids"in n){var o=n.data,i=o.schema,s=o.table,a=o.commit_timestamp,c=o.type,u=o.errors;return $s($s({},{schema:i,table:s,commit_timestamp:a,eventType:c,new:{},old:{},errors:u}),t._getPayloadRecords(o))}return n})},t.prototype.copyBindings=function(t){if(this.joinedOnce)throw new Error("cannot copy bindings into joined channel");for(var e in t.bindings)for(var n=0,r=t.bindings[e];n<r.length;n++){var o=r[n];this._on(o.type,o.filter,o.callback)}},t.isFilterValueEqual=function(t,e){return(null!=t?t:void 0)===(null!=e?e:void 0)},t.isSamePostgresFilter=function(e,n){var r,o,i,s,a=null!==(o=null===(r=null==e?void 0:e.select)||void 0===r?void 0:r.join())&&void 0!==o?o:void 0,c=null!==(s=null===(i=null==n?void 0:n.select)||void 0===i?void 0:i.join())&&void 0!==s?s:void 0;return(null==e?void 0:e.event)===(null==n?void 0:n.event)&&t.isFilterValueEqual(null==e?void 0:e.schema,null==n?void 0:n.schema)&&t.isFilterValueEqual(null==e?void 0:e.table,null==n?void 0:n.table)&&t.isFilterValueEqual(null==e?void 0:e.filter,null==n?void 0:n.filter)&&a===c},t.prototype._getPayloadRecords=function(t){var e={new:{},old:{}};return"INSERT"!==t.type&&"UPDATE"!==t.type||(e.new=es(t.columns,t.record)),"UPDATE"!==t.type&&"DELETE"!==t.type||(e.old=es(t.columns,t.old_record)),e},t}();const Zs=Xs,ta=function(){function t(t,e){this.socket=new Us(t,e)}return Object.defineProperty(t.prototype,"timeout",{get:function(){return this.socket.timeout},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"endPoint",{get:function(){return this.socket.endPoint},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transport",{get:function(){return this.socket.transport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatIntervalMs",{get:function(){return this.socket.heartbeatIntervalMs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatCallback",{get:function(){return this.socket.heartbeatCallback},set:function(t){this.socket.heartbeatCallback=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatTimer",{get:function(){return this.socket.heartbeatTimer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"pendingHeartbeatRef",{get:function(){return this.socket.pendingHeartbeatRef},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"reconnectTimer",{get:function(){return this.socket.reconnectTimer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vsn",{get:function(){return this.socket.vsn},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"encode",{get:function(){return this.socket.encode},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"decode",{get:function(){return this.socket.decode},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"reconnectAfterMs",{get:function(){return this.socket.reconnectAfterMs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sendBuffer",{get:function(){return this.socket.sendBuffer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"stateChangeCallbacks",{get:function(){return this.socket.stateChangeCallbacks},enumerable:!1,configurable:!0}),t.prototype.connect=function(){this.socket.connect()},t.prototype.disconnect=function(t,e,n,r){var o=this;return void 0===r&&(r=1e4),new Promise(function(i){setTimeout(function(){return i("timeout")},r),o.socket.disconnect(function(){t(),i("ok")},e,n)})},t.prototype.push=function(t){this.socket.push(t)},t.prototype.log=function(t,e,n){this.socket.log(t,e,n)},t.prototype.hasLogger=function(){return this.socket.hasLogger()},t.prototype.makeRef=function(){return this.socket.makeRef()},t.prototype.onOpen=function(t){this.socket.onOpen(t)},t.prototype.onClose=function(t){this.socket.onClose(t)},t.prototype.onError=function(t){this.socket.onError(t)},t.prototype.onMessage=function(t){this.socket.onMessage(t)},t.prototype.isConnected=function(){return this.socket.isConnected()},t.prototype.isConnecting=function(){return"connecting"==this.socket.connectionState()},t.prototype.isDisconnecting=function(){return"closing"==this.socket.connectionState()},t.prototype.connectionState=function(){return this.socket.connectionState()},t.prototype.endPointURL=function(){return this.socket.endPointURL()},t.prototype.sendHeartbeat=function(){this.socket.sendHeartbeat()},t.prototype.getSocket=function(){return this.socket},t}();var ea=function(){return ea=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ea.apply(this,arguments)},na=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},ra=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},oa=[1e3,2e3,5e3,1e4];var ia=function(){function t(t,e){var n;if(this.channels=new Array,this.accessTokenValue=null,this.accessToken=null,this.apiKey=null,this.httpEndpoint="",this.headers={},this.params={},this.ref=0,this.serializer=new Zi,this._manuallySetToken=!1,this._authPromise=null,this._authGeneration=0,this._workerHeartbeatTimer=void 0,this._pendingWorkerHeartbeatRef=null,this._pendingDisconnectTimer=null,this._disconnectOnEmptyChannelsAfterMs=0,this._endPoint="",this._socketOptions={},this._openingActive=!1,this._handlersAdapter=null,this._standbyAdapter=null,this._rotating=!1,this._cutoverStarted=!1,this._refreshTimer=null,this._rotateRetryTimer=null,this.connectionMaxAgeMs=0,this.connectionRefreshJitterMs=2e4,this._resolveFetch=function(t){return t?function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t.apply(void 0,e)}:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if("undefined"==typeof fetch)throw new Error("httpSend() requires a fetch implementation. Pass options.fetch, or use app.realtime() after registering a platform adapter that provides reqClass.");return fetch.apply(void 0,t)}},!(null===(n=null==e?void 0:e.params)||void 0===n?void 0:n.apikey))throw new Error("API key is required to connect to Realtime");this.apiKey=e.params.apikey;var r=this._initializeOptions(e);this._endPoint=t,this._socketOptions=r,this.socketAdapter=this._createSocketAdapter(),this.httpEndpoint=hs(t),this.fetch=this._resolveFetch(null==e?void 0:e.fetch)}return Object.defineProperty(t.prototype,"endPoint",{get:function(){return this.socketAdapter.endPoint},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"timeout",{get:function(){return this.socketAdapter.timeout},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transport",{get:function(){return this.socketAdapter.transport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatCallback",{get:function(){return this.socketAdapter.heartbeatCallback},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatIntervalMs",{get:function(){return this.socketAdapter.heartbeatIntervalMs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatTimer",{get:function(){return this.worker?this._workerHeartbeatTimer:this.socketAdapter.heartbeatTimer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"pendingHeartbeatRef",{get:function(){return this.worker?this._pendingWorkerHeartbeatRef:this.socketAdapter.pendingHeartbeatRef},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"reconnectTimer",{get:function(){return this.socketAdapter.reconnectTimer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vsn",{get:function(){return this.socketAdapter.vsn},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"encode",{get:function(){return this.socketAdapter.encode},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"decode",{get:function(){return this.socketAdapter.decode},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"reconnectAfterMs",{get:function(){return this.socketAdapter.reconnectAfterMs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sendBuffer",{get:function(){return this.socketAdapter.sendBuffer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"stateChangeCallbacks",{get:function(){return this.socketAdapter.stateChangeCallbacks},enumerable:!1,configurable:!0}),t.prototype.connect=function(){var t=this;if(!(this.isConnecting()||this.isDisconnecting()||this.isConnected()||this._openingActive)){if(this.accessToken&&!this._authPromise&&this._setAuthSafely("connect"),this._beforeTransportConnect)return this._openingActive=!0,void this._openActiveSocket().catch(function(e){t.log("error","failed to open socket",e)});this._setupConnectionHandlers();try{this.socketAdapter.connect()}catch(t){var e=t.message;throw new Error("WebSocket not available: ".concat(e))}this._handleNodeJsRaceCondition()}},t.prototype.endpointURL=function(){return this.socketAdapter.endPointURL()},t.prototype.disconnect=function(t,e){return na(this,void 0,void 0,function(){var n,r,o=this;return ra(this,function(i){switch(i.label){case 0:return this._cancelPendingDisconnect(),this._cancelConnectionRefresh(),this._cancelRotateRetry(),this._rotating=!1,this._cutoverStarted=!1,n=this._standbyAdapter,this._standbyAdapter=null,this.isDisconnecting()?n?[4,n.disconnect(function(){},1e3,"connection refresh abort")]:[3,2]:[3,3];case 1:i.sent(),i.label=2;case 2:return[2,"ok"];case 3:return[4,this.socketAdapter.disconnect(function(){clearInterval(o._workerHeartbeatTimer),o._terminateWorker()},t,e)];case 4:return r=i.sent(),n?[4,n.disconnect(function(){},1e3,"connection refresh abort")]:[3,6];case 5:i.sent(),i.label=6;case 6:return[2,r]}})})},t.prototype.getChannels=function(){return this.channels},t.prototype.removeChannel=function(t){return na(this,void 0,Promise,function(){var e;return ra(this,function(n){switch(n.label){case 0:return[4,t.unsubscribe()];case 1:return"ok"===(e=n.sent())&&t.teardown(),[2,e]}})})},t.prototype.removeAllChannels=function(){return na(this,void 0,Promise,function(){var t,e,n=this;return ra(this,function(r){switch(r.label){case 0:return t=this.channels.map(function(t){return na(n,void 0,void 0,function(){var e;return ra(this,function(n){switch(n.label){case 0:return[4,t.unsubscribe()];case 1:return e=n.sent(),t.teardown(),[2,e]}})})}),[4,Promise.all(t)];case 1:return e=r.sent(),[4,this.disconnect()];case 2:return r.sent(),[2,e]}})})},t.prototype.log=function(t,e,n){this.socketAdapter.log(t,e,n)},t.prototype.hasLogger=function(){return this.socketAdapter.hasLogger()},t.prototype.connectionState=function(){return this.socketAdapter.connectionState()||"closed"},t.prototype.isConnected=function(){return this.socketAdapter.isConnected()},t.prototype.isConnecting=function(){return this.socketAdapter.isConnecting()},t.prototype.isDisconnecting=function(){return this.socketAdapter.isDisconnecting()},t.prototype.channel=function(t,e){void 0===e&&(e={config:{}});var n="realtime:".concat(t),r=this.getChannels().find(function(t){return t.topic===n});if(r)return r;var o=new Zs("realtime:".concat(t),e,this);return this._cancelPendingDisconnect(),this.channels.push(o),o},t.prototype.push=function(t){this.socketAdapter.push(t)},t.prototype.setAuth=function(t){return void 0===t&&(t=null),na(this,void 0,Promise,function(){var e,n;return ra(this,function(r){switch(r.label){case 0:e=++this._authGeneration,n=this._performAuth(t,e),e===this._authGeneration&&(this._authPromise=n),r.label=1;case 1:return r.trys.push([1,,3,4]),[4,n];case 2:return r.sent(),[3,4];case 3:return this._authPromise===n&&(this._authPromise=null),[7];case 4:return[2]}})})},t.prototype._isManualToken=function(){return this._manuallySetToken},t.prototype.sendHeartbeat=function(){return na(this,void 0,void 0,function(){return ra(this,function(t){return this.socketAdapter.sendHeartbeat(),[2]})})},t.prototype.onHeartbeat=function(t){this.socketAdapter.heartbeatCallback=this._wrapHeartbeatCallback(t)},t.prototype._makeRef=function(){return this.socketAdapter.makeRef()},t.prototype._remove=function(t){this.channels=this.channels.filter(function(e){return e.topic!==t.topic}),0===this.channels.length&&(this.log("transport","no channels remaining, scheduling disconnect"),this._cancelConnectionRefresh(),this._cancelRotateRetry(),this._abortRotate(),this._schedulePendingDisconnect())},t.prototype._schedulePendingDisconnect=function(){var t=this;if(this._cancelPendingDisconnect(),0===this._disconnectOnEmptyChannelsAfterMs)return this.log("transport","disconnecting immediately - no channels"),void this.disconnect();this._pendingDisconnectTimer=setTimeout(function(){t._pendingDisconnectTimer=null,0===t.channels.length&&(t.log("transport","deferred disconnect fired - no channels, disconnecting"),t.disconnect())},this._disconnectOnEmptyChannelsAfterMs),this.log("transport","deferred disconnect scheduled in ".concat(this._disconnectOnEmptyChannelsAfterMs,"ms"))},t.prototype._cancelPendingDisconnect=function(){null!==this._pendingDisconnectTimer&&(this.log("transport","pending disconnect cancelled - channel activity detected"),clearTimeout(this._pendingDisconnectTimer),this._pendingDisconnectTimer=null)},t.prototype._performAuth=function(t,e){return na(this,void 0,Promise,function(){var n,r,o;return ra(this,function(i){switch(i.label){case 0:return r=!1,t?(n=t,r=!0,[3,7]):[3,1];case 1:if(!this.accessToken)return[3,6];i.label=2;case 2:return i.trys.push([2,4,,5]),[4,this.accessToken()];case 3:return n=i.sent(),[3,5];case 4:return o=i.sent(),this.log("error","Error fetching access token from callback",o),n=this.accessTokenValue,[3,5];case 5:return[3,7];case 6:n=this.accessTokenValue,i.label=7;case 7:return e!==this._authGeneration||(this.accessToken?this._manuallySetToken=!1:r&&(this._manuallySetToken=!0),this.accessTokenValue!=n&&(this.accessTokenValue=n)),[2]}})})},t.prototype._waitForAuthIfNeeded=function(){return na(this,void 0,Promise,function(){return ra(this,function(t){switch(t.label){case 0:return this._authPromise?[4,this._authPromise]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})},t.prototype._setAuthSafely=function(t){var e=this;void 0===t&&(t="general"),this._isManualToken()||this.setAuth().catch(function(n){e.log("error","Error setting auth in ".concat(t),n)})},t.prototype._setupConnectionHandlers=function(){var t=this;if(this._handlersAdapter!==this.socketAdapter){this._handlersAdapter=this.socketAdapter;var e=this.socketAdapter;e.onOpen(function(){t.socketAdapter===e&&((t._authPromise||(t.accessToken&&!t.accessTokenValue?t.setAuth():Promise.resolve())).catch(function(e){t.log("error","error waiting for auth on connect",e)}),t.worker&&!t.workerRef&&t._startWorkerHeartbeat(),t._scheduleConnectionRefresh())}),e.onClose(function(){t.socketAdapter===e&&(t.worker&&t.workerRef&&t._terminateWorker(),t._rotating&&!t._cutoverStarted&&(t.log("transport","active socket closed during refresh, aborting standby"),t._abortRotate()),t._rotating||t._cancelConnectionRefresh())}),e.onMessage(function(n){t.socketAdapter===e&&n.ref&&n.ref===t._pendingWorkerHeartbeatRef&&(t._pendingWorkerHeartbeatRef=null)})}},t.prototype._handleNodeJsRaceCondition=function(){this.socketAdapter.isConnected()&&this.socketAdapter.getSocket().onConnOpen()},t.prototype._wrapHeartbeatCallback=function(t){var e=this;return function(n,r){"disconnected"!==n&&("sent"==n&&e._setAuthSafely(),t&&t(n,r))}},t.prototype._startWorkerHeartbeat=function(){var t=this;this.workerUrl?this.log("worker","starting worker for from ".concat(this.workerUrl)):this.log("worker","starting default worker");var e=this._workerObjectUrl(this.workerUrl);this.workerRef=new Worker(e),this.workerRef.onerror=function(e){t.log("worker","worker error",e.message),t._terminateWorker(),t.disconnect()},this.workerRef.onmessage=function(e){"keepAlive"===e.data.event&&t.sendHeartbeat()},this.workerRef.postMessage({event:"start",interval:this.heartbeatIntervalMs})},t.prototype._terminateWorker=function(){this.workerRef&&(this.log("worker","terminating worker"),this.workerRef.terminate(),this.workerRef=void 0)},t.prototype._workerObjectUrl=function(t){var e;if(t)e=t;else{var n=new Blob(['\n addEventListener("message", (e) => {\n if (e.data.event === "start") {\n setInterval(() => postMessage({ event: "keepAlive" }), e.data.interval);\n }\n });'],{type:"application/javascript"});e=URL.createObjectURL(n)}return e},t.prototype._initializeOptions=function(t){var e,n,r,o,i,s,a,c,u,l,h,d,f,p;this.worker=null!==(e=null==t?void 0:t.worker)&&void 0!==e&&e,this.accessToken=null!==(n=null==t?void 0:t.accessToken)&&void 0!==n?n:null,this.connectionMaxAgeMs=null!==(r=null==t?void 0:t.connectionMaxAgeMs)&&void 0!==r?r:0,this.connectionRefreshJitterMs=null!==(o=null==t?void 0:t.connectionRefreshJitterMs)&&void 0!==o?o:2e4,this._beforeTransportConnect=null==t?void 0:t.beforeTransportConnect;var v,y,g={};g.timeout=null!==(i=null==t?void 0:t.timeout)&&void 0!==i?i:1e4,g.heartbeatIntervalMs=null!==(s=null==t?void 0:t.heartbeatIntervalMs)&&void 0!==s?s:25e3,this._disconnectOnEmptyChannelsAfterMs=null!==(a=null==t?void 0:t.disconnectOnEmptyChannelsAfterMs)&&void 0!==a?a:2*(null!==(c=null==t?void 0:t.heartbeatIntervalMs)&&void 0!==c?c:25e3),g.transport=null!==(u=null==t?void 0:t.transport)&&void 0!==u?u:Fi.getWebSocketConstructor(),g.params=null==t?void 0:t.params,g.logger=null==t?void 0:t.logger,g.heartbeatCallback=this._wrapHeartbeatCallback(null==t?void 0:t.heartbeatCallback),g.sessionStorage=null!==(l=null==t?void 0:t.sessionStorage)&&void 0!==l?l:function(){try{if("undefined"!=typeof globalThis&&globalThis.sessionStorage)return globalThis.sessionStorage}catch(t){}return t=new Map,{get length(){return t.size},clear:function(){t.clear()},getItem:function(e){return t.has(e)?t.get(e):null},key:function(e){var n;return null!==(n=Array.from(t.keys())[e])&&void 0!==n?n:null},removeItem:function(e){t.delete(e)},setItem:function(e,n){t.set(e,String(n))}};var t}(),g.reconnectAfterMs=null!==(h=null==t?void 0:t.reconnectAfterMs)&&void 0!==h?h:function(t){return oa[t-1]||1e4};var m=null!==(d=null==t?void 0:t.vsn)&&void 0!==d?d:Gi;switch(m){case Hi:v=function(t,e){return e(JSON.stringify(t))},y=function(t,e){return e(JSON.parse(t))};break;case Vi:v=this.serializer.encode.bind(this.serializer),y=this.serializer.decode.bind(this.serializer);break;default:throw new Error("Unsupported serializer version: ".concat(g.vsn))}if(g.vsn=m,g.encode=null!==(f=null==t?void 0:t.encode)&&void 0!==f?f:v,g.decode=null!==(p=null==t?void 0:t.decode)&&void 0!==p?p:y,g.beforeReconnect=this._reconnectAuth.bind(this),((null==t?void 0:t.logLevel)||(null==t?void 0:t.log_level))&&(this.logLevel=t.logLevel||t.log_level,g.params=ea(ea({},g.params),{log_level:this.logLevel})),this.worker){if("undefined"!=typeof window&&!window.Worker)throw new Error("Web Worker is not supported");this.workerUrl=null==t?void 0:t.workerUrl,g.autoSendHeartbeat=!this.worker}return g},t.prototype._reconnectAuth=function(){return na(this,void 0,void 0,function(){return ra(this,function(t){switch(t.label){case 0:return[4,this._waitForAuthIfNeeded()];case 1:return t.sent(),this.isConnected()||this.connect(),[2]}})})},t.prototype._createSocketAdapter=function(){return new ta(this._endPoint,this._socketOptions)},t.prototype._openActiveSocket=function(){return na(this,void 0,void 0,function(){var t,e;return ra(this,function(n){switch(n.label){case 0:return n.trys.push([0,3,4,5]),this._beforeTransportConnect?[4,this._beforeTransportConnect()]:[3,2];case 1:n.sent(),n.label=2;case 2:return this.isConnecting()||this.isDisconnecting()||this.isConnected()?[2]:(this._setupConnectionHandlers(),this.socketAdapter.connect(),this._handleNodeJsRaceCondition(),[3,5]);case 3:throw t=n.sent(),e=t.message,new Error("WebSocket not available: ".concat(e));case 4:return this._openingActive=!1,[7];case 5:return[2]}})})},t.prototype._scheduleConnectionRefresh=function(){var t=this;if(this._cancelConnectionRefresh(),!(this.connectionMaxAgeMs<=0)){var e=this.connectionRefreshJitterMs>0?Math.floor(Math.random()*this.connectionRefreshJitterMs):0,n=this.connectionMaxAgeMs+e;this._refreshTimer=setTimeout(function(){t._refreshTimer=null,t._rotateConnection()},n),this.log("transport","connection refresh scheduled in ".concat(n,"ms"))}},t.prototype._cancelConnectionRefresh=function(){null!==this._refreshTimer&&(clearTimeout(this._refreshTimer),this._refreshTimer=null)},t.prototype._scheduleRotateRetry=function(){var t=this;this._cancelRotateRetry(),this._rotateRetryTimer=setTimeout(function(){t._rotateRetryTimer=null,t.isConnected()&&!t._rotating&&t._rotateConnection()},1e4),this.log("transport","connection refresh retry scheduled in ".concat(1e4,"ms"))},t.prototype._cancelRotateRetry=function(){null!==this._rotateRetryTimer&&(clearTimeout(this._rotateRetryTimer),this._rotateRetryTimer=null)},t.prototype._rotateConnection=function(){return na(this,void 0,void 0,function(){var t,e,n,r;return ra(this,function(o){switch(o.label){case 0:if(this._rotating||!this.isConnected()||0===this.channels.length)return[2];this._rotating=!0,this._cutoverStarted=!1,this._cancelConnectionRefresh(),this.log("transport","starting connection refresh"),o.label=1;case 1:return o.trys.push([1,6,,8]),this._beforeTransportConnect?[4,this._beforeTransportConnect()]:[3,3];case 2:o.sent(),o.label=3;case 3:if(!this.isConnected()||0===this.channels.length)throw new Error("active connection lost before standby connect");return t=this._createSocketAdapter(),this._standbyAdapter=t,[4,this._connectAndWaitOpen(t)];case 4:return o.sent(),e=this.channels.filter(function(t){return t.joinedOnce&&!t.channelAdapter.isClosed()&&!t.channelAdapter.isLeaving()}),[4,Promise.all(e.map(function(e){return e._warmupOn(t)}))];case 5:return n=o.sent(),this._cutover(e,n,t),[3,8];case 6:return r=o.sent(),this.log("transport","connection refresh failed",r),[4,this._teardownStandby()];case 7:return o.sent(),this._rotating=!1,this._cutoverStarted=!1,this.isConnected()&&this.channels.length>0&&this._scheduleRotateRetry(),[3,8];case 8:return[2]}})})},t.prototype._cutover=function(t,e,n){this._cutoverStarted=!0;for(var r=this.socketAdapter,o=0;o<t.length;o++)t[o]._adopt(e[o]);this.socketAdapter=n,this._standbyAdapter=null,this._setupConnectionHandlers(),this.worker&&(this._terminateWorker(),this._startWorkerHeartbeat()),this._rotating=!1,this._scheduleConnectionRefresh(),r.disconnect(function(){},1e3,"connection refresh"),this.log("transport","connection refresh complete")},t.prototype._connectAndWaitOpen=function(t,e){return void 0===e&&(e=1e4),na(this,void 0,Promise,function(){return ra(this,function(n){switch(n.label){case 0:return[4,new Promise(function(n,r){var o=setTimeout(function(){r(new Error("standby connect timed out"))},e);t.onOpen(function(){clearTimeout(o),n()}),t.onError(function(t){clearTimeout(o),r(t instanceof Error?t:new Error(String(t)))});try{t.connect()}catch(t){clearTimeout(o),r(t)}})];case 1:return n.sent(),[2]}})})},t.prototype._teardownStandby=function(){return na(this,void 0,void 0,function(){var t;return ra(this,function(e){switch(e.label){case 0:if(t=this._standbyAdapter,this._standbyAdapter=null,!t)return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,t.disconnect(function(){},1e3,"connection refresh abort")];case 2:case 3:return e.sent(),[3,4];case 4:return[2]}})})},t.prototype._abortRotate=function(){return na(this,void 0,void 0,function(){return ra(this,function(t){switch(t.label){case 0:return this._cancelRotateRetry(),[4,this._teardownStandby()];case 1:return t.sent(),this._rotating=!1,this._cutoverStarted=!1,[2]}})})},t}();const sa=ia;var aa=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},ca=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function ua(t){if(!t)return{};if("undefined"!=typeof Headers&&t instanceof Headers){var e={};return t.forEach(function(t,n){e[n]=t}),e}if(Array.isArray(t)){for(var n={},r=0,o=t;r<o.length;r++){var i=o[r],s=i[0],a=i[1];n[s]=String(a)}return n}for(var c={},u=0,l=Object.entries(t);u<l.length;u++){var h=l[u];s=h[0],null!=(a=h[1])&&(c[s]=String(a))}return c}function la(t){var e;return"string"==typeof t?t:"undefined"!=typeof URL&&t instanceof URL?t.toString():"undefined"!=typeof Request&&t instanceof Request?t.url:String(null!==(e=t.url)&&void 0!==e?e:t)}function ha(t){return aa(this,void 0,Promise,function(){var e;return ca(this,function(n){switch(n.label){case 0:return[4,t];case 1:if(null==(e=n.sent())||""===e)return[2,{}];if("string"==typeof e)try{return[2,JSON.parse(e)]}catch(t){return[2,{message:e}]}return[2,e]}})})}function da(t){var e,n,r,o,i=this;if(t&&"object"==typeof t&&"number"==typeof t.status&&"function"==typeof t.json)return t;var s=null!=t?t:{},a=null!==(n=null!==(e=s.statusCode)&&void 0!==e?e:s.status)&&void 0!==n?n:0,c=s.data;return{ok:a>=200&&a<300,status:a,statusText:s.statusMessage||s.statusText||s.errMsg||"",headers:null!==(o=null!==(r=s.header)&&void 0!==r?r:s.headers)&&void 0!==o?o:{},json:function(){return aa(i,void 0,void 0,function(){return ca(this,function(t){return[2,ha(c)]})})},text:function(){return aa(i,void 0,void 0,function(){var t;return ca(this,function(e){switch(e.label){case 0:return[4,c];case 1:return"string"==typeof(t=e.sent())?[2,t]:null==t?[2,""]:[2,JSON.stringify(t)]}})})}}}var fa=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},pa=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},va=new Set(["TOKEN_REFRESHED","SIGNED_IN","INITIAL_SESSION"]),ya=new WeakSet,ga=new WeakMap;function ma(t){var e,n;return fa(this,void 0,Promise,function(){var r;return pa(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,null===(n=null===(e=t.request)||void 0===e?void 0:e.getAccessToken)||void 0===n?void 0:n.call(e)];case 1:return(r=o.sent())?(ya.delete(t),[2,r]):[3,3];case 2:return o.sent(),[3,3];case 3:return function(t){ya.has(t)||(ya.add(t),console.warn("[CloudBase Realtime] 当前没有登录态,无法使用 realtime 能力。\n请确认以下各项:\n 1 - 是否已调用 app.auth() 初始化认证\n 2 - 是否已完成登录(如 auth.signInAnonymously() / auth.signInWithPassword())\n 3 - 登录态是否已过期,需要重新登录"))}(t),[2,null]}})})}function ba(t){return!!t&&"function"==typeof t.onAuthStateChange}var wa=new WeakSet,_a=new WeakMap,Ea=new WeakSet;function Ia(t,e){var n;wa.has(t)||(wa.add(t),e.onAuthStateChange(function(e,r){var o,i=null!==(o=null==r?void 0:r.access_token)&&void 0!==o?o:void 0;if(va.has(e)&&i&&n!==i)return n=i,void t.setAuth(i).catch(function(e){t.log("error","Error setting auth from auth state change",e)});"SIGNED_OUT"===e&&(n=void 0,t.setAuth().catch(function(e){t.log("error","Error clearing auth from SIGNED_OUT",e)}))}))}function Sa(t){var e,n,r,o,i,s,a=this,c=function(t){var e=t.getEndPointWithKey("GATEWAY"),n=e.BASE_URL,r=e.PROTOCOL,o=/^https:?$/i.test(r)?"wss:":"ws:",i=String(n||"").replace(/\/+$/,"");return"".concat(o).concat(i,"/realtime")}(t),u={apikey:(null===(e=t.config)||void 0===e?void 0:e.env)||"cloudbase"},l=function(t){return t&&(s.apiKey=t,u.apikey=t),t},h={params:u,vsn:Hi,accessToken:function(){return fa(a,void 0,void 0,function(){var e;return pa(this,function(n){switch(n.label){case 0:return e=l,[4,ma(t)];case 1:return[2,e.apply(void 0,[n.sent()])]}})})},connectionMaxAgeMs:27e4,beforeTransportConnect:function(){return fa(a,void 0,void 0,function(){return pa(this,function(t){switch(t.label){case 0:return[4,s.setAuth()];case 1:return t.sent(),[2]}})})}},d=null===(r=null===(n=t.platform)||void 0===n?void 0:n.adapter)||void 0===r?void 0:r.wsClass;d&&(h.transport=d);var f=null===(i=null===(o=t.platform)||void 0===o?void 0:o.adapter)||void 0===i?void 0:i.reqClass;return f&&(h.fetch=function(t,e){var n=this;void 0===e&&(e={});var r=new t(e);return function(t,e){return void 0===e&&(e={}),aa(n,void 0,void 0,function(){var n;return ca(this,function(o){switch(o.label){case 0:return[4,r.fetch({url:la(t),method:e.method||"GET",headers:ua(e.headers),body:e.body,data:e.body,signal:null!==(n=e.signal)&&void 0!==n?n:void 0,shouldThrowOnError:!1})];case 1:return[2,da(o.sent())]}})})}}(f)),s=new sa(c,h),function(t,e){var n=function(t){try{if(ba(t.auth))return t.auth;if(ba(t.authInstance))return t.authInstance}catch(t){}return null}(t);if(n)Ia(e,n);else{var r=t.auth;if("function"==typeof r){var o=_a.get(t);if(o||(o=new Set,_a.set(t,o)),o.add(e),!Ea.has(t)){Ea.add(t);var i=function(e){var n=r.call(null!=this?this:t,e);return ba(n)&&function(t,e){var n=_a.get(t);if(n){for(var r=0,o=n;r<o.length;r++)Ia(o[r],e);n.clear(),_a.delete(t)}}(t,n),n};try{Object.defineProperty(t,"auth",{configurable:!0,enumerable:!0,writable:!0,value:i})}catch(e){t.auth=i}}}}}(t,s),s}var Oa={name:"realtime-js",entity:{realtime:function(){return function(t){var e=ga.get(t);if(e)return e;var n=Sa(t);return ga.set(t,n),n}(this)}}};try{cloudbase.registerComponent(Oa)}catch(Mt){}function Ta(t){try{t.registerComponent(Oa)}catch(t){console.warn(t)}}try{window.registerRealtimeJs=Ta}catch(t){}const Aa=(t=>{var e={};return l.d(e,t),e})({generateHTTPClient:()=>r.generateHTTPClient,generateMySQLClient:()=>r.generateMySQLClient,generatePGClient:()=>r.generatePGClient});var Pa=function(){return Pa=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Pa.apply(this,arguments)},Ra=X,Ca="models",ka=new WeakMap;function Na(t){return new Proxy({},{get:function(e,n){var r=t.getEndPointWithKey("GATEWAY"),o=r.BASE_URL,i=r.PROTOCOL,s=Pa(Pa({},t),{BASE_URL:o,PROTOCOL:i}),a=ka.get(s);return a||(a=function(t){var e=this,n=t.callFunction.bind(t),r=t.request.fetch.bind(t.request),o=t.getEndPointWithKey("GATEWAY"),i=o.BASE_URL,s=o.PROTOCOL,a="".concat(s).concat(i,"/model"),c="".concat(s).concat(i,"/sql"),u=(0,Aa.generateHTTPClient)(n,function(t){return n=e,o=void 0,s=function(){return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(e){switch(e.label){case 0:return[4,r(Pa(Pa({},t),{headers:Pa({"Content-Type":"application/json"},t.headers)}))];case 1:return[4,e.sent().data];case 2:return[2,e.sent()]}})},new((i=void 0)||(i=Promise))(function(t,e){function r(t){try{c(s.next(t))}catch(t){e(t)}}function a(t){try{c(s.throw(t))}catch(t){e(t)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof i?n:new i(function(t){t(n)})).then(r,a)}c((s=s.apply(n,o||[])).next())});var n,o,i,s},a,{sqlBaseUrl:c});return u}(t),ka.set(s,a)),a[n]}})}var xa="cloudbase_init",Ua=new Ra;Ua.on(xa,function(t){var e=t.data;Object.assign(e,{models:Na(e)})});var La={name:Ca,namespace:Ca,entity:new Proxy({},{get:function(t,e){console.warn("【deprecated】Accessing Cloudbase.prototype.models.".concat(e,"."))}}),injectEvents:{bus:Ua,events:[xa]}};try{cloudbase.registerComponent(La)}catch(t){}function Da(t){try{t.registerComponent(La)}catch(t){console.warn(t)}}try{window.registerModel=Da}catch(t){}const ja=(t=>{var e={};return l.d(e,t),e})({ReadableStream:()=>o.ReadableStream,TransformStream:()=>o.TransformStream}),qa=(t=>{var e={};return l.d(e,t),e})({createReadableStreamWrapper:()=>i.createReadableStreamWrapper});var Ma=[239,187,191];const Ba=(t=>{var e={};return l.d(e,t),e})({TextDecoder:()=>s.TextDecoder});var Wa=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Fa=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Ha="function"==typeof globalThis.ReadableStream&&"function"==typeof globalThis.TransformStream&&"function"==typeof globalThis.ReadableStream.prototype.pipeThrough,Va=Ha?globalThis.ReadableStream:ja.ReadableStream,Ga=Ha?globalThis.TransformStream:ja.TransformStream,Ka=function(){var t;return new Ga({start:function(e){t=function(t){var e,n,r,o,i,s,a;return c(),{feed:function(t){n=n?n+t:t,e&&function(t){return Ma.every(function(e,n){return t.charCodeAt(n)===e})}(n)&&(n=n.slice(Ma.length)),e=!1;for(var i=n.length,s=0,a=!1;s<i;){a&&("\n"===n[s]&&(s+=1),a=!1);for(var c=-1,l=o,h=void 0,d=r;c<0&&d<i;d++)":"===(h=n[d])&&l<0?l=d-s:"\r"===h?(a=!0,c=d-s):"\n"===h&&(c=d-s);if(c<0){r=i-s,o=l;break}r=0,o=-1,u(n,s,l,c),s+=c+1}s===i?n="":s>0&&(n=n.slice(s))},reset:c};function c(){e=!0,n="",r=0,o=-1,i=void 0,s=void 0,a=""}function u(e,n,r,o){if(0===o)return a.length>0&&(t({type:"event",id:i,event:s||void 0,data:a.slice(0,-1)}),a="",i=void 0),void(s=void 0);var c,u=r<0,l=e.slice(n,n+(u?o:r)),h=n+(c=u?o:" "===e[n+r+1]?r+2:r+1),d=o-c,f=e.slice(h,h+d).toString();if("data"===l)a+=f?"".concat(f,"\n"):"\n";else if("event"===l)s=f;else if("id"!==l||f.includes("\0")){if("retry"===l){var p=parseInt(f,10);Number.isNaN(p)||t({type:"reconnect-interval",value:p})}}else i=f}}(function(t){"event"===t.type&&e.enqueue(t)})},transform:function(e){t.feed(e)}})},Ja=Ha?function(t){return t}:(0,qa.createReadableStreamWrapper)(Va),za=function(){function t(t,e){void 0===t&&(t="utf-8"),void 0===e&&(e={});var n=this;this.transform=new Ga({transform:function(t,e){var r=n.handle.decode(new Uint8Array(t),{stream:!0});r&&e.enqueue(r)},flush:function(t){var e=n.handle.decode();e&&t.enqueue(e),t.terminate()}}),this.handle=new Ba.TextDecoder(t,e)}return Object.defineProperty(t.prototype,"encoding",{get:function(){return this.handle.encoding},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"fatal",{get:function(){return this.handle.fatal},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ignoreBOM",{get:function(){return this.handle.ignoreBOM},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"readable",{get:function(){return this.transform.readable},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"writable",{get:function(){return this.transform.writable},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,Symbol.toStringTag,{get:function(){return"TextDecoderStream"},enumerable:!1,configurable:!0}),t}();function $a(t){var e=t;return e[Symbol.asyncIterator]=function(){var e=t.getReader();return{next:function(){return Wa(this,void 0,Promise,function(){var t,n,r;return Fa(this,function(o){switch(o.label){case 0:return[4,e.read()];case 1:return t=o.sent(),n=t.done,r=t.value,[2,n?{done:!0,value:void 0}:{done:!1,value:r}]}})})}}},e}function Ya(t){return $a(t.pipeThrough(new za).pipeThrough(Ka()).pipeThrough(new Ga({transform:function(t,e){try{var n=JSON.parse(t.data);e.enqueue(n)}catch(n){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",n,t):e.terminate()}}})))}function Qa(t){var e,n,r,o;return Wa(this,void 0,void 0,function(){var i,s,a,c,u,l;return Fa(this,function(h){switch(h.label){case 0:i=function(t){return $a(Ja(t).pipeThrough(new za))}(t),s="",h.label=1;case 1:h.trys.push([1,6,7,12]),a=!0,c=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise(function(r,o){!function(t,e,n,r){Promise.resolve(r).then(function(e){t({value:e,done:n})},e)}(r,o,(e=t[n](e)).done,e.value)})}}}(i),h.label=2;case 2:return[4,c.next()];case 3:if(u=h.sent(),e=u.done)return[3,5];o=u.value,a=!1;try{s+=o}finally{a=!0}h.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return l=h.sent(),n={error:l},[3,12];case 7:return h.trys.push([7,,10,11]),a||e||!(r=c.return)?[3,9]:[4,r.call(c)];case 8:h.sent(),h.label=9;case 9:return[3,11];case 10:if(n)throw n.error;return[7];case 11:return[7];case 12:return[2,JSON.parse(s)]}})})}function Xa(){var t,e;return{promise:new Promise(function(n,r){t=n,e=r}),res:t,rej:e}}function Za(t){var e;return"assistant"===t.role&&"tool_calls"in t&&null!=(null===(e=t.tool_calls)||void 0===e?void 0:e[0])}var tc=function(){return tc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},tc.apply(this,arguments)},ec=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},nc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},rc=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},oc=function(){function t(t,e){this.baseUrl=e;var n=arguments[2];this.req="string"==typeof n?function(e){var r=e.headers,o=void 0===r?{}:r,i=rc(e,["headers"]);return t(tc(tc({},i),{headers:tc(tc({},o),{Authorization:"Bearer ".concat(n)})}))}:t}return t.prototype.list=function(t,e){return this.req({method:"get",url:this.join("bots"),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.create=function(t,e){var n=t.botInfo;return this.req({method:"post",url:this.join("bots"),data:n,timeout:null==e?void 0:e.timeout})},t.prototype.get=function(t,e){var n=t.botId;return this.req({method:"get",url:this.join("bots/".concat(n)),timeout:null==e?void 0:e.timeout})},t.prototype.update=function(t,e){var n=t.botId,r=t.botInfo;return this.req({method:"PATCH",url:this.join("bots/".concat(n)),data:r,timeout:null==e?void 0:e.timeout})},t.prototype.delete=function(t,e){var n=t.botId;return this.req({method:"delete",url:this.join("bots/".concat(n)),timeout:null==e?void 0:e.timeout})},t.prototype.getChatRecords=function(t,e){return this.req({method:"get",url:this.join("bots/".concat(t.botId,"/records")),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.sendFeedback=function(t,e){var n=t.userFeedback;return this.req({method:"post",url:this.join("bots/".concat(n.botId,"/feedback")),data:n,timeout:null==e?void 0:e.timeout})},t.prototype.getFeedback=function(t,e){return this.req({method:"get",url:this.join("bots/".concat(t.botId,"/feedback")),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.uploadFiles=function(t,e){return ec(this,void 0,void 0,function(){return nc(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/files")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.createConversation=function(t,e){var n=t.botId,r=rc(t,["botId"]);return ec(this,void 0,void 0,function(){return nc(this,function(t){return[2,this.req({method:"post",url:this.join("bots/".concat(n,"/conversation")),data:r,timeout:null==e?void 0:e.timeout})]})})},t.prototype.getConversation=function(t,e){var n=t.pageSize,r=void 0===n?10:n,o=t.pageNumber,i=void 0===o?1:o,s=t.botId,a=rc(t,["pageSize","pageNumber","botId"]);return ec(this,void 0,void 0,function(){var t,n;return nc(this,function(o){if(i<1)throw new Error("pageNumber must be greater than 0");return t=r*(i-1),n=r,[2,this.req({method:"get",url:this.join("bots/".concat(s,"/conversation")),data:tc(tc({},a),{offset:t,limit:n}),timeout:null==e?void 0:e.timeout})]})})},t.prototype.deleteConversation=function(t,e){var n=t.botId,r=t.conversationId,o=rc(t,["botId","conversationId"]);return ec(this,void 0,void 0,function(){return nc(this,function(t){return[2,this.req({method:"delete",url:this.join("bots/".concat(n,"/conversation/").concat(r)),data:o,timeout:null==e?void 0:e.timeout})]})})},t.prototype.speechToText=function(t,e){return ec(this,void 0,void 0,function(){return nc(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/speech-to-text")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.textToSpeech=function(t,e){return ec(this,void 0,void 0,function(){return nc(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/text-to-speech")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.getTextToSpeechResult=function(t,e){return ec(this,void 0,void 0,function(){return nc(this,function(n){return[2,this.req({method:"get",url:this.join("bots/".concat(t.botId,"/text-to-speech")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.getRecommendQuestions=function(t,e){return ec(this,void 0,void 0,function(){var n;return nc(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/recommend-questions")),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new ic(n)]}})})},t.prototype.generateBot=function(t,e){return ec(this,void 0,void 0,function(){var n;return nc(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("generate-bot"),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new ic(n)]}})})},t.prototype.getPreview=function(t,e){return ec(this,void 0,void 0,function(){var n;return nc(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("preview"),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new ic(n)]}})})},t.prototype.generateImage=function(t,e){return this.req({method:"post",url:this.join("generate-image"),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.sendMessage=function(t,e){return ec(this,void 0,void 0,function(){var n;return nc(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/send-message")),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new ic(n)]}})})},t.prototype.join=function(t){return"".concat(this.baseUrl,"/").concat(t)},t}(),ic=function(){function t(t){var e=Ja(t);this._eventSourceStream=e.pipeThrough(new za).pipeThrough(Ka())}return Object.defineProperty(t.prototype,"teeedStream",{get:function(){var t=this._eventSourceStream.tee(),e=t[0],n=t[1];return this._eventSourceStream=n,e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"eventSourceStream",{get:function(){return $a(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dataStream",{get:function(){return $a(this.eventSourceStream.pipeThrough(new Ga({transform:function(t,e){try{var n=JSON.parse(t.data);e.enqueue(n)}catch(n){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",n,t):e.terminate()}}})))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textStream",{get:function(){return $a(this.dataStream.pipeThrough(new Ga({transform:function(t,e){var n;e.enqueue(null!==(n=null==t?void 0:t.content)&&void 0!==n?n:"")}})))},enumerable:!1,configurable:!0}),t}(),sc=function(){return sc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},sc.apply(this,arguments)},ac=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},cc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function uc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,s=t.top_p;return sc(sc({},t),{messages:e,model:n,temperature:r,tool_choice:(o&&"auto"!==o&&console.warn("`tool_choice` is not 'auto'"),o),tools:i,top_p:s})}var lc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="zhipu/api/paas/v4/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return ac(this,void 0,Promise,function(){var n,r;return cc(this,function(o){switch(o.label){case 0:return n=uc(t),[4,this.req({url:this.url,data:sc(sc({},n),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return r=o.sent(),[2,sc(sc({},r),{rawResponse:r})]}})})},t.prototype.doStream=function(t,e){return ac(this,void 0,Promise,function(){var n,r,o,i;return cc(this,function(s){switch(s.label){case 0:return n=uc(t),r=null,[4,this.req({url:this.url,data:sc(sc({},n),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return o=s.sent(),i=Ja(o),[2,$a(Ya(i).pipeThrough(new Ga({transform:function(t,e){var n=t.choices.map(function(t){var e=t.delta;return null==r&&(r=Za(e)),r?sc(sc({},t),{finish_reason:"tool_calls",delta:e}):t}),o=sc(sc({},t),{choices:n});e.enqueue(sc(sc({},o),{rawResponse:t}))}})))]}})})},t}(),hc=function(){return hc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},hc.apply(this,arguments)};function dc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,s=t.top_p;return hc(hc({},t),{messages:(e.forEach(function(t){"tool_calls"in t&&t.tool_calls.filter(function(t){return"function"!==t.type}).forEach(function(e){return console.warn("`type` in tool_call is not 'function'",e,t)})}),e),model:n,tools:function(){if(i)return i.forEach(function(t){"function"!==t.type&&console.warn("`type` in tool is not 'function'",t)}),i}(),top_p:s,tool_choice:o,temperature:r})}function fc(t){return"object"!=typeof t||null==t?t:Array.isArray(t)?t.map(function(t){return fc(t)}):Object.entries(t).reduce(function(t,e){var n,r=e[0],o=e[1];return t["_"===(n=r.replace(/[A-Z]/g,function(t){return"_".concat(t.toLowerCase())})).charAt(0)?n.slice(1):n]="object"==typeof o?fc(o):o,t},{})}var pc=function(){return pc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},pc.apply(this,arguments)},vc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},yc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},gc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-beta/openapi/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return vc(this,void 0,Promise,function(){var n;return yc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:pc(pc({},dc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,pc(pc({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return vc(this,void 0,Promise,function(){var n,r,o;return yc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:pc(pc({},dc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?pc(pc({},t),{finish_reason:"tool_calls",delta:e}):t}),o=pc(pc({},t),{choices:r});e.enqueue(pc(pc({},o),{rawResponse:t}))}})))]}})})},t}(),mc=function(){return mc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},mc.apply(this,arguments)},bc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},wc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},_c=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return bc(this,void 0,Promise,function(){var n,r;return wc(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:mc(mc({},dc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=o.sent(),r=fc(n.Response),[2,mc(mc({},r),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return bc(this,void 0,Promise,function(){var n,r,o;return wc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:mc(mc({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=fc(t),o=r.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?mc(mc({},t),{finish_reason:"tool_calls",delta:e}):t}),i=mc(mc({},r),{choices:o});e.enqueue(mc(mc({},i),{rawResponse:t}))}})))]}})})},t}(),Ec=function(){return Ec=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ec.apply(this,arguments)},Ic=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Sc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Oc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return Ec(Ec({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var Tc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="ark/api/v3/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return Ic(this,void 0,Promise,function(){var n;return Sc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Ec(Ec({},Oc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Ec(Ec({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return Ic(this,void 0,Promise,function(){var n,r,o;return Sc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Ec(Ec({},Oc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?Ec(Ec({},t),{finish_reason:"tool_calls",delta:e}):t}),o=Ec(Ec({},t),{choices:r});e.enqueue(Ec(Ec({},o),{rawResponse:t}))}})))]}})})},t}(),Ac=function(){return Ac=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ac.apply(this,arguments)},Pc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Rc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Cc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return Ac(Ac({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var kc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="dashscope/compatible-mode/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return Pc(this,void 0,Promise,function(){var n;return Rc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Ac(Ac({},Cc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Ac(Ac({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return Pc(this,void 0,Promise,function(){var n,r,o;return Rc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Ac(Ac({},Cc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=Za(e)),Ac(Ac({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})}),o=Ac(Ac({},t),{choices:r});e.enqueue(Ac(Ac({},o),{rawResponse:t}))}})))]}})})},t}(),Nc=function(){return Nc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Nc.apply(this,arguments)},xc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Uc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Lc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return Nc(Nc({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var Dc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="01-ai/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return xc(this,void 0,Promise,function(){var n;return Uc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Nc(Nc({},Lc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Nc(Nc({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return xc(this,void 0,Promise,function(){var n,r,o,i,s;return Uc(this,function(a){switch(a.label){case 0:return n=null,[4,this.req({url:this.url,data:Nc(Nc({},Lc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=a.sent(),o=Ja(r),i=Ya(o),s=i.pipeThrough(new Ga({transform:function(t,e){var r,o,i,s,a,c;if((null===(i=null===(o=null===(r=null==t?void 0:t.choices)||void 0===r?void 0:r[0])||void 0===o?void 0:o.delta)||void 0===i?void 0:i.content)||(null===(c=null===(a=null===(s=null==t?void 0:t.choices)||void 0===s?void 0:s[0])||void 0===a?void 0:a.delta)||void 0===c?void 0:c.tool_calls)){var u=t.choices.map(function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=Za(e)),Nc(Nc({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})}),l=Nc(Nc({},t),{choices:u});e.enqueue(Nc(Nc({},l),{rawResponse:t}))}}})),[2,$a(s)]}})})},t}(),jc=function(){return jc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},jc.apply(this,arguments)},qc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Mc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Bc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return jc(jc({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var Wc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="moonshot/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return qc(this,void 0,Promise,function(){var n;return Mc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:jc(jc({},Bc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,jc(jc({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return qc(this,void 0,Promise,function(){var n,r,o;return Mc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:jc(jc({},Bc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?jc(jc({},t),{finish_reason:"tool_calls",delta:e}):t}),o=jc(jc({},t),{choices:r});e.enqueue(jc(jc({},o),{rawResponse:t}))}})))]}})})},t}(),Fc=function(){return Fc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Fc.apply(this,arguments)},Hc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Vc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Gc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-exp/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t){return Hc(this,void 0,Promise,function(){var e;return Vc(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Fc(Fc({},dc(t)),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,Fc(Fc({},e),{rawResponse:e})]}})})},t.prototype.doStream=function(t){return Hc(this,void 0,Promise,function(){var e,n,r;return Vc(this,function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:Fc(Fc({},dc(t)),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=Ja(n),[2,$a(Ya(r).pipeThrough(new Ga({transform:function(t,n){var r=t.choices.map(function(t){var n=t.delta;return null==e&&(e=Za(n)),e?Fc(Fc({},t),{finish_reason:"tool_calls",delta:n}):t}),o=Fc(Fc({},t),{choices:r});n.enqueue(Fc(Fc({},o),{rawResponse:t}))}})))]}})})},t}(),Kc=function(){return Kc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Kc.apply(this,arguments)},Jc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},zc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},$c=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-open/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return Jc(this,void 0,Promise,function(){var n;return zc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Kc(Kc({},dc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Kc(Kc({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return Jc(this,void 0,Promise,function(){var n,r,o;return zc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Kc(Kc({},dc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?Kc(Kc({},t),{finish_reason:"tool_calls",delta:e}):t}),o=Kc(Kc({},t),{choices:r});e.enqueue(Kc(Kc({},o),{rawResponse:t}))}})))]}})})},t}(),Yc=function(){return Yc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Yc.apply(this,arguments)},Qc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Xc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Zc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="deepseek/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return Qc(this,void 0,Promise,function(){var n;return Xc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Yc(Yc({},t),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Yc(Yc({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return Qc(this,void 0,Promise,function(){var n,r,o;return Xc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Yc(Yc({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?Yc(Yc({},t),{finish_reason:"tool_calls",delta:e}):t}),o=Yc(Yc({},t),{choices:r});e.enqueue(Yc(Yc({},o),{rawResponse:t}))}})))]}})})},t}(),tu=function(){return tu=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},tu.apply(this,arguments)},eu=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},nu=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},ru=function(){function t(t,e,n){void 0===n&&(n=""),this.req=t,this.baseUrl=e,this.subUrl=n}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t){return eu(this,void 0,Promise,function(){var e;return nu(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:tu(tu({},t),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,tu(tu({},e),{rawResponse:e})]}})})},t.prototype.doStream=function(t){return eu(this,void 0,Promise,function(){var e,n,r;return nu(this,function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:tu(tu({},t),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=Ja(n),[2,$a(Ya(r).pipeThrough(new Ga({transform:function(t,n){var r=t.choices.map(function(t){var n=t.delta;return null==e&&(e=Za(n)),e?tu(tu({},t),{finish_reason:"tool_calls",delta:n}):t}),o=tu(tu({},t),{choices:r});n.enqueue(tu(tu({},o),{rawResponse:t}))}})))]}})})},t}(),ou=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),iu=function(t){function e(e,n){var r=t.call(this,e)||this;return r.name="InvalidParamsError",r.code="INVALID_PARAMS",r.field=n,r}return ou(e,t),e.prototype.toJSON=function(){return{code:this.code,message:this.message,field:this.field}},e}(Error),su=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.provider=n,this.defaultGenerateImageSubUrl="images/ar/generations",this.generateImageSubUrlConfig={"hunyuan-image":[[/^hunyuan-image(-v[12](\..*)?)?$/,"images/generations"]]},this.generateImage=this.generateImageImpl.bind(this)}return t.prototype.generateImageImpl=function(t){return e=this,n=void 0,o=function(){var e,n,r,o,i;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(s){switch(s.label){case 0:if("object"==typeof t&&t&&"model"in t&&"HY-Image-v3.0-I2I-ToB-v1.0.1"===t.model&&(""===this.provider||"hunyuan-image"===this.provider)){if(n=(e=t).image_urls,r=e.images,n&&n.length>1)throw new iu("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,image_urls 最多只能有 1 个元素","image_urls");if(r&&r.length>1)throw new iu("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,images 最多只能有 1 个元素","images")}return o=this.defaultGenerateImageSubUrl,"object"==typeof t&&t&&"model"in t&&"string"==typeof t.model&&(i=this.getGenerateImageSubUrl(this.provider,t.model))&&(o=i),[4,this.req({url:this.getGenerateUrl(o),data:t,stream:!1})];case 1:return[2,s.sent()]}})},new((r=Promise)||(r=Promise))(function(t,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r(function(t){t(n)})).then(s,a)}c((o=o.apply(e,n||[])).next())});var e,n,r,o},t.prototype.getGenerateUrl=function(t){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(t)},t.prototype.getGenerateImageSubUrl=function(t,e){var n=this.generateImageSubUrlConfig[t];if(n)for(var r=0,o=n;r<o.length;r++){var i=o[r],s=i[0],a=i[1];if(s.test(e))return a}},t}(),au=function(){return au=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},au.apply(this,arguments)},cu=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},uu=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},lu=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function hu(t){var e,n=t.onStepFinish,r=t.abortSignal,o=t.maxSteps,i=t.topP,s=t.toolChoice,a=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(t,["onStepFinish","abortSignal","maxSteps","topP","toolChoice"]);if(null!=o&&o<1)throw new Error("`maxSteps` muse be greater than 0.");return[{onStepFinish:n,abortSignal:r,maxSteps:o},au(au({},a),{tools:null===(e=a.tools)||void 0===e?void 0:e.map(function(t){return"fn"in t?function(t){return{type:"function",function:{description:t.description,name:t.name,parameters:t.parameters}}}(t):t}),top_p:null!=i?i:a.top_p,tool_choice:null!=s?s:a.tool_choice})]}var du=function(){function t(t){this.model=t}return t.prototype.generateText=function(t,e){var n,r;return cu(this,void 0,Promise,function(){var o,i,s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I,S,O=this;return uu(this,function(T){switch(T.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},s=hu(t),a=s[0],c=a.onStepFinish,u=a.maxSteps,l=void 0===u?10:u,h=s[1],[4,(d=function(){return O.model.doGenerate(h,e)})()];case 1:f=T.sent(),p=1,f.rawResponse&&o.push(f.rawResponse),v=null,T.label=2;case 2:if(!(p<l&&null!=(v=fu(f))))return[3,9];y=gu(f.usage),mu(i,y),T.label=3;case 3:return T.trys.push([3,7,,8]),[4,yu(v)];case 4:return g=T.sent(),m=f.choices[0],[4,null==c?void 0:c({finishReason:m.finish_reason,messages:h.messages.slice(),text:m.message.content,toolCall:v,toolResult:g,stepUsage:y,totalUsage:Object.assign({},i)})];case 5:return T.sent(),pu(h.messages,m.message,g),[4,d()];case 6:return(f=T.sent()).rawResponse&&o.push(f.rawResponse),p+=1,[3,8];case 7:return b=T.sent(),[2,{text:"",messages:h.messages,usage:i,error:b,rawResponses:o}];case 8:return[3,2];case 9:return w=null===(n=null==f?void 0:f.choices)||void 0===n?void 0:n[0],_=null==w?void 0:w.message,E=null!==(r=null==_?void 0:_.content)&&void 0!==r?r:"",I=_?lu(lu([],h.messages,!0),[_],!1):h.messages,S=gu(f.usage),mu(i,S),[4,null==c?void 0:c({finishReason:w.finish_reason,messages:I.slice(),text:E,toolCall:fu(f),toolResult:null,stepUsage:S,totalUsage:Object.assign({},i)})];case 10:return T.sent(),[2,{text:E,messages:I,usage:i,rawResponses:o}]}})})},t.prototype.streamText=function(t,e){var n;return cu(this,void 0,Promise,function(){var r,o,i,s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I,S,O,T,A,P,R,C,k,N,x,U,L,D,j,q,M=this;return uu(this,function(B){switch(B.label){case 0:return r={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=hu(t),i=o[0],s=i.onStepFinish,a=i.maxSteps,c=void 0===a?10:a,u=o[1],[4,(l=function(){return M.model.doStream(u,e)})()];case 1:h=B.sent(),d=1,f=null,p=function(){var t=h.tee(),e=t[0],n=t[1];return h=$a(e),function(t){var e,n,r,o,i,s,a,c,u,l;return cu(this,void 0,Promise,function(){var h,d,f,p,v,y,g,m,b,w,_,E,I;return uu(this,function(S){switch(S.label){case 0:h={completion_tokens:0,prompt_tokens:0,total_tokens:0},d=$a(t),p={role:"assistant",content:"",tool_calls:[f={id:"",function:{name:"",arguments:""},type:""}]},S.label=1;case 1:S.trys.push([1,6,7,12]),v=!0,y=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise(function(r,o){!function(t,e,n,r){Promise.resolve(r).then(function(e){t({value:e,done:n})},e)}(r,o,(e=t[n](e)).done,e.value)})}}}(d),S.label=2;case 2:return[4,y.next()];case 3:if(g=S.sent(),e=g.done)return[3,5];o=g.value,v=!1;try{if(!(b=null==(m=o)?void 0:m.choices[0]))return[2,null];if(w=b.finish_reason,_=b.delta,"tool_calls"!==w)return[2,null];if(!_)return[3,4];if(_.content&&(p.content+=_.content),!("tool_calls"in _))return[3,4];(null==(E=null===(i=null==_?void 0:_.tool_calls)||void 0===i?void 0:i[0])?void 0:E.id)&&(f.id=E.id),(null==E?void 0:E.type)&&(f.type=E.type),(null===(s=null==E?void 0:E.function)||void 0===s?void 0:s.name)&&(f.function.name=E.function.name),(null===(a=null==E?void 0:E.function)||void 0===a?void 0:a.arguments)&&(f.function.arguments+=E.function.arguments),(null===(c=null==m?void 0:m.usage)||void 0===c?void 0:c.completion_tokens)&&(h.completion_tokens=m.usage.completion_tokens),(null===(u=null==m?void 0:m.usage)||void 0===u?void 0:u.prompt_tokens)&&(h.prompt_tokens=m.usage.prompt_tokens),(null===(l=null==m?void 0:m.usage)||void 0===l?void 0:l.total_tokens)&&(h.total_tokens=m.usage.total_tokens)}finally{v=!0}S.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return I=S.sent(),n={error:I},[3,12];case 7:return S.trys.push([7,,10,11]),v||e||!(r=y.return)?[3,9]:[4,r.call(y)];case 8:S.sent(),S.label=9;case 9:return[3,11];case 10:if(n)throw n.error;return[7];case 11:return[7];case 12:return[2,{message:p,usage:h}]}})})}(n)},B.label=2;case 2:return(v=d<c)?[4,p()]:[3,4];case 3:v=null!=(f=B.sent()),B.label=4;case 4:if(!v)return[3,11];y=f.message,g=f.usage,mu(r,g),m=null===(n=y.tool_calls)||void 0===n?void 0:n[0],B.label=5;case 5:return B.trys.push([5,9,,10]),[4,yu(m)];case 6:return b=B.sent(),[4,null==s?void 0:s({finishReason:"tool_calls",messages:u.messages.slice(),text:y.content,toolCall:m,toolResult:b,stepUsage:g,totalUsage:Object.assign({},r)})];case 7:return B.sent(),pu(u.messages,y,b),[4,l()];case 8:return h=B.sent(),[3,10];case 9:return w=B.sent(),_=h.tee(),E=_[0],I=_[1],[2,{messages:Promise.resolve(u.messages),dataStream:$a(E),textStream:$a(I.pipeThrough(new Ga({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:Promise.resolve(r),error:w}];case 10:return[3,2];case 11:return[4,p()];case 12:return(f=B.sent())?(S=f.message,O=f.usage,mu(r,O),T=lu(lu([],u.messages,!0),[S],!1),s({messages:T.slice(),finishReason:"tool_call",stepUsage:O,text:S.content,toolCall:S.tool_calls[0],totalUsage:Object.assign({},r)}),A=h.tee(),P=A[0],R=A[1],[2,{messages:Promise.resolve(lu(lu([],u.messages,!0),[S],!1)),dataStream:$a(P),textStream:$a(R.pipeThrough(new Ga({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:Promise.resolve(r)}]):(C=Xa(),k=Xa(),N={role:"assistant",content:""},x="",U={completion_tokens:0,prompt_tokens:0,total_tokens:0},L=h.pipeThrough(new Ga({transform:function(t,e){var n,r,o,i,s,a,c,u,l=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof l&&(N.content+=l);var h=null===(s=null===(i=null==t?void 0:t.choices)||void 0===i?void 0:i[0])||void 0===s?void 0:s.finish_reason;h&&(x=h),(null===(a=null==t?void 0:t.usage)||void 0===a?void 0:a.completion_tokens)&&(U.completion_tokens=t.usage.completion_tokens),(null===(c=null==t?void 0:t.usage)||void 0===c?void 0:c.prompt_tokens)&&(U.prompt_tokens=t.usage.prompt_tokens),(null===(u=null==t?void 0:t.usage)||void 0===u?void 0:u.total_tokens)&&(U.total_tokens=t.usage.total_tokens),e.enqueue(t)},flush:function(){C.res(lu(lu([],u.messages,!0),[N],!1)),mu(r,U),k.res(Object.assign({},r)),null==s||s({messages:lu(lu([],u.messages,!0),[N],!1),finishReason:x,text:N.content,stepUsage:U,totalUsage:Object.assign({},r)})}})),D=L.tee(),j=D[0],q=D[1],[2,{messages:C.promise,dataStream:$a(j),textStream:$a(q.pipeThrough(new Ga({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:k.promise}])}})})},t}();function fu(t){var e,n=null===(e=null==t?void 0:t.choices)||void 0===e?void 0:e[0];if(!n)return null;var r=n.finish_reason,o=n.message;return"tool_calls"!==r?null:o&&Za(o)?o.tool_calls[0]:null}function pu(t,e,n){t.push(e,{role:"tool",tool_call_id:e.tool_calls[0].id,content:JSON.stringify(n)})}var vu=new Map;function yu(t){return vu.get(t.function.name)(JSON.parse(t.function.arguments))}function gu(t){var e,n,r;return{completion_tokens:null!==(e=null==t?void 0:t.completion_tokens)&&void 0!==e?e:0,prompt_tokens:null!==(n=null==t?void 0:t.prompt_tokens)&&void 0!==n?n:0,total_tokens:null!==(r=null==t?void 0:t.total_tokens)&&void 0!==r?r:0}}function mu(t,e){t.completion_tokens+=e.completion_tokens,t.prompt_tokens+=e.prompt_tokens,t.total_tokens+=e.total_tokens}var bu={hunyuan:_c,"hunyuan-beta":gc,ark:Tc,dashscope:kc,"01-ai":Dc,moonshot:Wc,zhipu:lc,"hunyuan-exp":Gc,"hunyuan-open":$c,deepseek:Zc},wu=function(){return wu=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},wu.apply(this,arguments)},_u=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Eu=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Iu=bu,Su=function(){function t(t,e,n,r){var o=this;this.req=t,this.baseUrl=e,this.modelRequest=function(t){var e=t.url,n=t.data,r=t.headers,i=t.stream,s=t.timeout;return _u(o,void 0,void 0,function(){var t,o,a,c,u,l,h;return Eu(this,function(d){switch(d.label){case 0:return t={"Content-Type":"application/json"},i&&Object.assign(t,{Accept:"text/event-stream"}),[4,this.req.fetch({method:"post",headers:wu(wu((u={},u[null===(l=this.i18n)||void 0===l?void 0:l.LANG_HEADER_KEY]=null===(h=this.i18n)||void 0===h?void 0:h.lang,u),t),r),body:JSON.stringify(n),url:this.resolveUrl(e),stream:i,timeout:s})];case 1:return o=d.sent(),a=o.data,c=o.header,[2,this.handleResponseData(a,c)]}})})},this.botRequest=function(t){var e=t.method,n=t.url,r=t.data,i=void 0===r?{}:r,s=t.headers,a=t.stream,c=t.timeout;return _u(o,void 0,void 0,function(){var t,r,o,u,l,h,d,f,p;return Eu(this,function(v){switch(v.label){case 0:return t=this.resolveUrl(n),"get"!==e?[3,2]:(r=this.handleResponseData,[4,this.req.fetch({url:"".concat(t,"?").concat((y=i,Object.entries(y).map(function(t){var e=t[0],n=t[1];return"".concat(e,"=").concat(n)}).join("&"))),method:e,headers:s,stream:a,timeout:c})]);case 1:return[2,r.apply(this,[v.sent().data])];case 2:return o={"Content-Type":"application/json"},a&&Object.assign(o,{Accept:"text/event-stream"}),[4,this.req.fetch({url:t,body:JSON.stringify(i),headers:wu(wu((d={},d[null===(f=this.i18n)||void 0===f?void 0:f.LANG_HEADER_KEY]=null===(p=this.i18n)||void 0===p?void 0:p.lang,d),o),s),stream:a,method:e,timeout:c})];case 3:return u=v.sent(),l=u.data,h=u.header,[2,this.handleResponseData(l,h)]}var y})})},this._getBaseUrl=r,this.bot=new oc(this.botRequest,this.aiBotBaseUrl),this.i18n=n,Z.on(tt,function(t){var e;o.i18n=(null===(e=t.data)||void 0===e?void 0:e.i18n)||o.i18n})}return Object.defineProperty(t.prototype,"aiBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/ai")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"aiBotBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/aibot")},enumerable:!1,configurable:!0}),t.prototype.handleResponseData=function(t,e){var n,r;return _u(this,void 0,void 0,function(){var o,i,s,a,c=this;return Eu(this,function(u){switch(u.label){case 0:return o="".concat(this.i18n.t("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),i=function(t){if("object"==typeof t&&t&&"code"in t&&"NORMAL"!==t.code)throw new Error("".concat(c.i18n.t("AI+ 请求出错,错误码"),":").concat(t.code,",").concat(c.i18n.t("错误信息"),":").concat(t.message,"\n").concat(o,"\n").concat(JSON.stringify(t,null,2)))},"object"==typeof t&&t&&"function"!=typeof t.getReader?"then"in t?[4,t]:[3,2]:[3,4];case 1:return s=u.sent(),[3,3];case 2:s=t,u.label=3;case 3:return i(a=s),[2,t];case 4:if("function"!=typeof(null==t?void 0:t.getReader)){if("object"==typeof(a=t)&&a&&"code"in a&&"NORMAL"!==a.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(a.code,",").concat(this.i18n.t("错误信息"),":").concat(a.message,"\n").concat(o,"\n").concat(JSON.stringify(a,null,2)));return[2,t]}return(null===(r=null===(n=null==e?void 0:e.get)||void 0===n?void 0:n.call(e,"content-type"))||void 0===r?void 0:r.includes("application/json"))?[4,Qa(t)]:[3,6];case 5:a=u.sent(),i(a),u.label=6;case 6:return[2,t]}})})},t.prototype.createModel=function(t,e){var n,r=Iu[t];if(r)n=new r(this.modelRequest,this.aiBaseUrl);else{var o="string"==typeof(null==e?void 0:e.defaultModelSubUrl)?e.defaultModelSubUrl:"/chat/completions";n=new ru(this.modelRequest,this.aiBaseUrl,"".concat(t).concat(o))}return new du(n)},t.prototype.registerModel=function(t,e){null==Iu[t]?Iu[t]=e:console.warn("AI model ".concat(t," already exists!"))},t.prototype.createImageModel=function(t){return new su(this.modelRequest,this.aiBaseUrl,t)},t.prototype.registerFunctionTool=function(t){vu.has(t.name)&&console.warn("AI function tool ".concat(t.name," already exists and will be overwritten!")),vu.set(t.name,t.fn)},t.prototype.resolveUrl=function(t){if(!this._getBaseUrl)return t;var e=this._getBaseUrl();return e!==this.baseUrl&&t.startsWith(this.baseUrl)?t.replace(this.baseUrl,e):t},t}(),Ou=function(){return Ou=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ou.apply(this,arguments)},Tu=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n};function Au(t){var e=t.env,n=t.baseUrl,r=t.getBaseUrl,o=t.req,i=t.getAccessToken,s=t.handleReqInstance,a=t.i18n;return new Su(function(){if(null==s){if(null==i)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return function(t){var e=t.getAccessToken,n=t.req;return{download:n.download,post:n.post,upload:n.upload,fetch:function(t){return r=void 0,o=void 0,s=function(){var r,o,i,s,a;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(c){switch(c.label){case 0:if("function"!=typeof n.fetch)throw new Error("req.fetch is not a function");return r=t.token,o=t.headers,i=void 0===o?{}:o,s=Tu(t,["token","headers"]),null==r?[3,1]:(a=r,[3,3]);case 1:return[4,e()];case 2:a=c.sent().accessToken,c.label=3;case 3:return[2,n.fetch(Ou({headers:Ou({Authorization:"Bearer ".concat(a)},i)},s))]}})},new((i=void 0)||(i=Promise))(function(t,e){function n(t){try{c(s.next(t))}catch(t){e(t)}}function a(t){try{c(s.throw(t))}catch(t){e(t)}}function c(e){var r;e.done?t(e.value):(r=e.value,r instanceof i?r:new i(function(t){t(r)})).then(n,a)}c((s=s.apply(r,o||[])).next())});var r,o,i,s}}}({req:o,getAccessToken:i})}return s({req:o})}(),function(){if(null!=r)return r();if(null!=n)return n;if(null==e)throw new Error("`env` is required when `baseUrl` is not provided!");return"https://".concat(e,".api.tcloudbasegateway.com/v1")}(),a,r)}Tu(c,["MODELS"]);var Pu={name:"ai",entity:{ai:function(t){var e=this,n=this.request;if(null==n.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");var r=function(){var t=e.getEndPointWithKey("GATEWAY"),n=t.BASE_URL,r=t.PROTOCOL;return"".concat(r).concat(n)};return(null==t?void 0:t.baseUrl)?Au({req:n,baseUrl:t.baseUrl,handleReqInstance:function(t){return t.req},i18n:this.config.i18n}):Au({req:n,baseUrl:r(),getBaseUrl:r,handleReqInstance:function(t){return t.req},i18n:this.config.i18n})}}};function Ru(t){try{t.registerComponent(Pu)}catch(t){console.warn(t)}}try{window.registerAi=Ru}catch(t){}var Cu=function(){return Cu=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Cu.apply(this,arguments)};function ku(t){if(!t)return{get:function(){return null},forEach:function(){}};if("function"==typeof t.get)return t;var e={};return Object.keys(t).forEach(function(n){e[n.toLowerCase()]=t[n]}),{get:function(t){var n;return null!==(n=e[t.toLowerCase()])&&void 0!==n?n:null},forEach:function(t){Object.entries(e).forEach(function(e){var n=e[0],r=e[1];return t(r,n)})}}}function Nu(t,e,n){var r=this,o=t.request.fetch.bind(t.request),i=e||{},s=i.instance,a=void 0===s?n?void 0:"default":s,c=i.database,u=void 0===c?n?void 0:t.config.env:c,l=t.getEndPointWithKey("GATEWAY"),h=l.BASE_URL,d=l.PROTOCOL,f="".concat(d).concat(h),p=function(e,n){return i=r,s=void 0,l=function(){var r,i,s,c,l,h,d,p,v,y;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(g){switch(g.label){case 0:return r={},n.headers instanceof Headers?n.headers.forEach(function(t,e){r[e]=t}):n.headers&&Object.assign(r,n.headers),[["X-Db-Instance",a],["Accept-Profile",u],["Content-Profile",u]].forEach(function(t){var e=t[0],n=t[1];r[e]||r[e.toLocaleLowerCase()]||!n||(r[e]=n)}),i=e.toString(),s=t.getEndPointWithKey("GATEWAY"),c=s.BASE_URL,l=s.PROTOCOL,(h="".concat(l).concat(c))!==f&&i.startsWith(f)&&(i=i.replace(f,h)),[4,o(Cu(Cu({url:i},n),{headers:Cu({"Content-Type":"application/json"},r),shouldThrowOnError:!1}))];case 1:d=g.sent(),p={},g.label=2;case 2:return g.trys.push([2,4,,5]),[4,d.data];case 3:return p=g.sent(),[3,5];case 4:if(v=g.sent(),!(null===(y=null==v?void 0:v.message)||void 0===y?void 0:y.includes("Unexpected end of JSON input")))throw v;return[3,5];case 5:return[2,{ok:(null==d?void 0:d.statusCode)>=200&&(null==d?void 0:d.statusCode)<300,status:(null==d?void 0:d.statusCode)||200,statusText:(null==d?void 0:d.statusMessage)||"OK",json:function(){return Promise.resolve(p||{})},text:function(){return Promise.resolve("string"==typeof p?p:JSON.stringify(p||{}))},headers:ku(null==d?void 0:d.header)}]}})},new((c=void 0)||(c=Promise))(function(t,e){function n(t){try{o(l.next(t))}catch(t){e(t)}}function r(t){try{o(l.throw(t))}catch(t){e(t)}}function o(e){var o;e.done?t(e.value):(o=e.value,o instanceof c?o:new c(function(t){t(o)})).then(n,r)}o((l=l.apply(i,s||[])).next())});var i,s,c,l},v="".concat(d).concat(h,"/rdb/rest");return n?(0,Aa.generatePGClient)(t,{pgBaseUrl:v,fetch:p}):(0,Aa.generateMySQLClient)(t,{mysqlBaseUrl:v,fetch:p})}var xu={name:"mysql",entity:{mysql:function(t){return Nu(this,t,!1)(t)}}},Uu={name:"rdb",entity:{rdb:function(t){return Nu(this,t,!0)(t)}}};try{cloudbase.registerComponent(xu),cloudbase.registerComponent(Uu)}catch(t){}function Lu(t){try{t.registerComponent(xu),t.registerComponent(Uu)}catch(t){console.warn(t)}}try{window.registerMySQL=Lu}catch(t){}var Du=function(){return Du=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Du.apply(this,arguments)},ju=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},qu=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Mu(t,e){var n,r,o,i;return ju(this,void 0,Promise,function(){var s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I,S,O,T,A,P;return qu(this,function(R){switch(R.label){case 0:a=(s=t||{}).name,c=s.body,u=s.path,l=void 0===u?"":u,h=s.method,d=void 0===h?"POST":h,f=s.headers,p=void 0===f?{}:f,v=(t||{}).token,y={};try{y=JSON.parse(c)}catch(t){y=c||{}}if(!a)throw new Error(JSON.stringify({code:Cn.ERRORS.INVALID_PARAMS,msg:"[apis] invalid api name"}));return g="",b=(m=this).gatewayOrigin,w=m.getAccessToken,_=m.env,b?g="".concat(b,"/v1"):this.getEndPointWithKey?(E=this.getEndPointWithKey("GATEWAY"),I=E.BASE_URL,S=E.PROTOCOL,g="".concat(S).concat(I)):g="https://".concat(_,".api.tcloudbasegateway.com/v1"),O="".concat(g,"/apis/").concat(a),T=l.startsWith("/")?l:"/".concat(l),w?[4,w()]:[3,2];case 1:A=R.sent().accessToken,p.Authorization="Bearer ".concat(A),R.label=2;case 2:if(P=["GET","HEAD"].includes(null===(n=null==d?void 0:d.toUpperCase)||void 0===n?void 0:n.call(d)))try{T="".concat(T).concat(T.includes("?")?"&":"?").concat(Object.keys(y).map(function(t){return"".concat(t,"=").concat(y[t])}).join("&"))}catch(t){}return[4,this.request.fetch(Du(Du(Du({url:"".concat(O).concat(T),method:d||"POST",headers:Du({"Content-Type":"application/json; charset=utf-8"},p)},P?{}:{body:JSON.stringify(y)}),{token:(null===(r=null==v?void 0:v.trim)||void 0===r?void 0:r.call(v))||(null===(i=null===(o=p.Authorization)||void 0===o?void 0:o.replace)||void 0===i?void 0:i.call(o,/^Bearer /,""))||null}),e))];case 3:return[4,R.sent().data];case 4:return[2,R.sent()]}})})}var Bu=["GET","POST","PUT","DELETE","HEAD","OPTIONS","PATCH","REQUEST"];function Wu(t){var e=this;return new Proxy({},{get:function(n,r){if("string"!=typeof r)throw new Error("[apis] method must be string");var o=r.toLocaleUpperCase();if(!Bu.includes(o))throw new Error("[apis] invalid method: ".concat(r));return function(n,r){return ju(e,void 0,void 0,function(){return qu(this,function(e){switch(e.label){case 0:return[4,Mu.call(this,Du({name:t,method:("REQUEST"===o?n.method:o)||"POST"},n),r)];case 1:return[2,e.sent()]}})})}}})}function Fu(t){var e=this;return Object.keys(t||{}).forEach(function(n){void 0!==t[n]&&(e[n]=t[n])}),new Proxy({},{get:function(t,n){if("string"==typeof n)return Wu.call(e,n)}})}var Hu,Vu,Gu="apis",Ku={name:Gu,IIFE:!0,entity:function(){Object.defineProperty(this.prototype,Gu,{get:function(){return Fu.call(this)},configurable:!0,enumerable:!0})}};function Ju(t){try{t.registerComponent(Ku)}catch(t){console.warn(t)}}try{cloudbase.registerComponent(Ku)}catch(t){}try{window.registerApis=Ju}catch(t){}!function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.BooleanError="must be boolean",t.ArrayError="must be array",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined",t.CentersPhereError="centersPhere结构不合法"}(Vu||(Vu={}));var zu,$u,Yu="Object",Qu="GeoPoint",Xu="GeoLineString",Zu="GeoPolygon",tl="GeoMultiPoint",el="GeoMultiLineString",nl="GeoMultiPolygon",rl="Date",ol="ServerDate",il=["desc","asc"],sl=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(zu||(zu={})),(Hu={})[zu.eq]="$eq",Hu[zu.lt]="$lt",Hu[zu.lte]="$lte",Hu[zu.gt]="$gt",Hu[zu.gte]="$gte",function(t){t.WHERE="WHERE",t.DOC="DOC"}($u||($u={}));var al=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),cl=[],ul={},ll=function(t){function e(e,n){if(n!==ul)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return al(e,t),e.for=function(t){for(var n=0,r=cl.length;n<r;n++)if(cl[n].target===t)return cl[n].instance;var o=new e(t,ul);return cl.push({target:t,instance:o}),o},e}(function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})});const hl=ll;var dl=hl.for("UNSET_FIELD_NAME"),fl=hl.for("UPDATE_COMMAND"),pl=hl.for("QUERY_COMMAND"),vl=hl.for("LOGIC_COMMAND"),yl=hl.for("GEO_POINT"),gl=hl.for("SYMBOL_GEO_LINE_STRING"),ml=hl.for("SYMBOL_GEO_POLYGON"),bl=hl.for("SYMBOL_GEO_MULTI_POINT"),wl=hl.for("SYMBOL_GEO_MULTI_LINE_STRING"),_l=hl.for("SYMBOL_GEO_MULTI_POLYGON"),El=hl.for("SERVER_DATE"),Il=hl.for("REGEXP"),Sl=hl.for("OBJECTID"),Ol=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},Tl=function(t){return"object"===Ol(t)},Al=function(t){return"number"===Ol(t)},Pl=function(t){return Array.isArray(t)},Rl=function(t){return"date"===Ol(t)},Cl=function(t){return"regexp"===Ol(t)},kl=function(t){return t&&t._internalType instanceof ll},Nl=function(){function t(t){if(!Pl(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(t.length<2)throw new Error('"points" must contain 2 points at least');t.forEach(function(t){if(!(t instanceof uh))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("LineString"!==t.type||!Pl(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!Al(i[0])||!Al(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},t.isClosed=function(t){var e=t.points[0],n=t.points[t.points.length-1];if(e.latitude===n.latitude&&e.longitude===n.longitude)return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return gl},enumerable:!1,configurable:!0}),t}(),xl=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ul=function(){function t(t){if(!Pl(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof Nl))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"));if(!Nl.isClosed(t))throw new Error("LineString ".concat(t.points.map(function(t){return t.toReadableString()})," is not a closed cycle"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("Polygon"!==t.type||!Pl(t.coordinates))return!1;try{for(var i=xl(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;if(!this.isCloseLineString(a))return!1;try{for(var c=(r=void 0,xl(a)),u=c.next();!u.done;u=c.next()){var l=u.value;if(!Al(l[0])||!Al(l[1]))return!1}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},t.isCloseLineString=function(t){var e=t[0],n=t[t.length-1];return e[0]===n[0]&&e[1]===n[1]},Object.defineProperty(t.prototype,"_internalType",{get:function(){return ml},enumerable:!1,configurable:!0}),t}(),Ll=function(){function t(t){if(!Pl(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(0===t.length)throw new Error('"points" must contain 1 point at least');t.forEach(function(t){if(!(t instanceof uh))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("MultiPoint"!==t.type||!Pl(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!Al(i[0])||!Al(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return bl},enumerable:!1,configurable:!0}),t}(),Dl=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},jl=function(){function t(t){if(!Pl(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof Nl))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("MultiLineString"!==t.type||!Pl(t.coordinates))return!1;try{for(var i=Dl(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;try{for(var c=(r=void 0,Dl(a)),u=c.next();!u.done;u=c.next()){var l=u.value;if(!Al(l[0])||!Al(l[1]))return!1}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return wl},enumerable:!1,configurable:!0}),t}(),ql=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ml=function(){function t(t){var e,n;if(!Pl(t))throw new TypeError('"polygons" must be of type Polygon[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("MultiPolygon must contain 1 polygon at least");try{for(var r=ql(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof Ul))throw new TypeError('"polygon" must be of type Polygon[]. Received type '.concat(typeof i,"[]"))}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}this.polygons=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})},e},t.prototype.toJSON=function(){return{type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})}},t.validate=function(t){var e,n,r,o,i,s;if("MultiPolygon"!==t.type||!Pl(t.coordinates))return!1;try{for(var a=ql(t.coordinates),c=a.next();!c.done;c=a.next()){var u=c.value;try{for(var l=(r=void 0,ql(u)),h=l.next();!h.done;h=l.next()){var d=h.value;try{for(var f=(i=void 0,ql(d)),p=f.next();!p.done;p=f.next()){var v=p.value;if(!Al(v[0])||!Al(v[1]))return!1}}catch(t){i={error:t}}finally{try{p&&!p.done&&(s=f.return)&&s.call(f)}finally{if(i)throw i.error}}}}catch(t){r={error:t}}finally{try{h&&!h.done&&(o=l.return)&&o.call(l)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return _l},enumerable:!1,configurable:!0}),t}(),Bl=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},Wl=function(){function t(){}return t.formatResDocumentData=function(e){return e.map(function(e){return t.formatField(e)})},t.formatField=function(e){var n=Object.keys(e),r={};return Array.isArray(e)&&(r=[]),n.forEach(function(n){var o,i=e[n];switch(t.whichType(i)){case Qu:o=new uh(i.coordinates[0],i.coordinates[1]);break;case Xu:o=new Nl(i.coordinates.map(function(t){return new uh(t[0],t[1])}));break;case Zu:o=new Ul(i.coordinates.map(function(t){return new Nl(t.map(function(t){var e=Bl(t,2),n=e[0],r=e[1];return new uh(n,r)}))}));break;case tl:o=new Ll(i.coordinates.map(function(t){return new uh(t[0],t[1])}));break;case el:o=new jl(i.coordinates.map(function(t){return new Nl(t.map(function(t){var e=Bl(t,2),n=e[0],r=e[1];return new uh(n,r)}))}));break;case nl:o=new Ml(i.coordinates.map(function(t){return new Ul(t.map(function(t){return new Nl(t.map(function(t){var e=Bl(t,2),n=e[0],r=e[1];return new uh(n,r)}))}))}));break;case rl:o=i;break;case Yu:case"Array":o=t.formatField(i);break;case ol:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o}),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);return e===rl?rl:(e===Yu&&(t.$date?e=ol:uh.validate(t)?e=Qu:Nl.validate(t)?e=Xu:Ul.validate(t)?e=Zu:Ll.validate(t)?e=tl:jl.validate(t)?e=el:Ml.validate(t)&&(e=nl)),e)},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),Fl={code:"INVALID_PARAM",message:"Invalid request param"},Hl="DATABASE_TRANSACTION_CONFLICT",Vl={code:"DATABASE_REQUEST_FAILED",message:"database request failed"};const Gl=(t=>{var e={};return l.d(e,t),e})({EJSON:()=>a.EJSON});var Kl=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Jl=function(){return Jl=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Jl.apply(this,arguments)};function zl(t,e){if("function"!=typeof e)return t;t.then(function(t){return e(0,t)},function(t){return e(t)})}var $l={};function Yl(t){if(!hd.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return $l[e]||($l[e]=new hd.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:hd.createRequest(t.config)}}})),$l[e]}var Ql=function(t){return void 0!==t.timeout?{timeout:t.timeout}:{}},Xl=function(t){if(!Tl(t))return t;for(var e in t)void 0===t[e]?delete t[e]:Tl(t[e])&&(t[e]=Xl(t[e]));return t},Zl=function(t){return t=Xl(t),Gl.EJSON.stringify(t,{relaxed:!1})},th=function(t){var e,n;if(t instanceof Date)return{$date:+t};if(t instanceof RegExp)return{$regex:t.source,$options:t.flags};if(t&&"object"==typeof t){if("ObjectId"===t._bsontype)return{$oid:t.toHexString()};if("BSONRegExp"===t._bsontype)return{$regex:t.pattern,$options:t.options};if(Array.isArray(t))return t.map(th);var r={};try{for(var o=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.keys(t)),i=o.next();!i.done;i=o.next()){var s=i.value;r[s]=th(t[s])}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}return t},eh=function(t){if(!t)return"{}";try{var e=Gl.EJSON.parse(t);return JSON.stringify(th(e))}catch(e){return t}},nh=function(t){function e(e){var n=t.call(this,e.message)||this;return n.code=e.code,n.message=e.message,n}return Kl(e,t),e}(Error),rh=function(t){return new nh(t)};function oh(t,e){if(!1===t)return e;throw rh(Jl({},e))}var ih,sh=function(){return sh=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},sh.apply(this,arguments)},ah=["limit","offset","projection","order","multiple","timeout","raw"],ch=function(){function t(){}return t.isGeopoint=function(t,e){if("Number"!==Wl.whichType(e))throw new Error("Geo Point must be number type");var n=Math.abs(e);if("latitude"===t&&n>90)throw new Error("latitude should be a number ranges from -90 to 90");if("longitude"===t&&n>180)throw new Error("longitude should be a number ranges from -180 to 180");return!0},t.isInteger=function(t,e){if(!Number.isInteger(e))throw new Error(t+Vu.IntergerError);return!0},t.mustBeBoolean=function(t,e){if("boolean"!=typeof e)throw new Error(t+Vu.BooleanError);return!0},t.isProjection=function(t,e){if("object"!==Ol(e))throw rh(sh(sh({},Fl),{message:"".concat(t," projection must be an object")}));for(var n in e){var r=e[n];if("number"===Ol(r)){if(0!==r&&1!==r)throw rh(sh(sh({},Fl),{message:"if the value in projection is of number, it must be 0 or 1"}))}else if("object"!==Ol(r))throw rh(sh(sh({},Fl),{message:"invalid projection"}))}return!0},t.isOrder=function(t,e){if("object"!==Ol(e))throw rh(sh(sh({},Fl),{message:"".concat(t," order must be an object")}));for(var n in e){var r=e[n];if(1!==r&&-1!==r)throw rh(sh(sh({},Fl),{message:"order value must be 1 or -1"}))}return!0},t.isFieldOrder=function(t){if(-1===il.indexOf(t))throw new Error(Vu.DirectionError);return!0},t.isFieldPath=function(t){if(!/^[a-zA-Z0-9-_\.]/.test(t))throw new Error;return!0},t.isOperator=function(t){if(-1===sl.indexOf(t))throw new Error(Vu.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(Vu.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(Vu.DocIDError);return!0},t.isValidOptions=function(e){if(void 0===e&&(e={}),"object"!==Ol(e))throw rh(sh(sh({},Fl),{message:"options must be an object"}));var n=Object.keys(e);for(var r in n)if(ah.indexOf(n[r])<0)throw rh(sh(sh({},Fl),{message:"".concat(n[r]," is invalid options key")}));var o=e,i=o.limit,s=o.offset,a=o.projection,c=o.order,u=e.multiple;return void 0!==i&&t.isInteger("limit",i),void 0!==s&&t.isInteger("offset",s),void 0!==a&&t.isProjection("projection",a),void 0!==c&&t.isOrder("order",c),void 0!==u&&t.mustBeBoolean("multiple",u),void 0!==e.timeout&&t.isInteger("timeout",e.timeout),!0},t.isValidAggregation=function(t){if(1!==Object.keys(t).length)throw rh(sh(sh({},Fl),{message:"aggregation stage must have one key"}));return!0},t.isCentersPhere=function(e){if(Array.isArray(e)&&2===e.length){if("object"===Ol(e[0])&&e[0]._internalType===yl&&"number"==typeof e[1])return!0;if(Array.isArray(e[0])&&2===e[0].length){var n=e[0][0],r=e[0][1];if(t.isGeopoint("longitude",n),t.isGeopoint("latitude",r),"number"==typeof e[1])return!0}}throw new Error("".concat(Vu.CentersPhereError))},t}(),uh=function(){function t(t,e){ch.isGeopoint("longitude",t),ch.isGeopoint("latitude",e),this.longitude=t,this.latitude=e}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Point",coordinates:[this.longitude,this.latitude]},e},t.prototype.toJSON=function(){return{type:"Point",coordinates:[this.longitude,this.latitude]}},t.prototype.toReadableString=function(){return"[".concat(this.longitude,",").concat(this.latitude,"]")},t.validate=function(t){return"Point"===t.type&&Pl(t.coordinates)&&ch.isGeopoint("longitude",t.coordinates[0])&&ch.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return yl},enumerable:!1,configurable:!0}),t}();!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(ih||(ih={}));var lh,hh=function(){function t(t,e,n){this._internalType=fl,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||dl}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function dh(t){return t&&t instanceof hh&&t._internalType===fl}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(lh||(lh={}));var fh=function(){function t(t,e,n){if(this._internalType=vl,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||dl,this.fieldName!==dl)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(ph(i=e[r])||mh(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(ph(i=e)||mh(i))&&(e=i._setFieldName(this.fieldName))}}return t.prototype._setFieldName=function(e){var n=this.operands.map(function(n){return n instanceof t?n._setFieldName(e):n});return new t(this.operator,n,e)},t.prototype.and=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(lh.AND,r,this.fieldName)},t.prototype.or=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(lh.OR,r,this.fieldName)},t}();function ph(t){return t&&t instanceof fh&&t._internalType===vl}var vh,yh=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();!function(t){t.EQ="eq",t.NEQ="neq",t.GT="gt",t.GTE="gte",t.LT="lt",t.LTE="lte",t.IN="in",t.NIN="nin",t.ALL="all",t.ELEM_MATCH="elemMatch",t.EXISTS="exists",t.SIZE="size",t.MOD="mod",t.GEO_NEAR="geoNear",t.GEO_WITHIN="geoWithin",t.GEO_INTERSECTS="geoIntersects"}(vh||(vh={}));var gh=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=pl,o}return yh(e,t),e.prototype.toJSON=function(){var t,e,n;switch(this.operator){case vh.IN:case vh.NIN:return(t={})["$"+this.operator]=this.operands,t;case vh.NEQ:return(e={}).$ne=this.operands[0],e;default:return(n={})["$"+this.operator]=this.operands[0],n}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(vh.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(vh.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(vh.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(vh.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(vh.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(vh.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(vh.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(vh.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof uh))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!Al(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!Al(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(vh.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof Ml||t.geometry instanceof Ul||ch.isCentersPhere(t.centerSphere)))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(vh.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof uh||t.geometry instanceof Nl||t.geometry instanceof Ul||t.geometry instanceof Ll||t.geometry instanceof jl||t.geometry instanceof Ml))throw new TypeError('"geometry" must be of type Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(vh.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(fh);function mh(t){return t&&t instanceof gh&&t._internalType===pl}function bh(t){return mh(t)}var wh={};for(var _h in vh)wh[_h]="$"+_h;for(var _h in lh)wh[_h]="$"+_h;for(var _h in ih)wh[_h]="$"+_h;function Eh(t){return wh[t]||"$"+t}wh[vh.NEQ]="$ne",wh[ih.REMOVE]="$unset",wh[ih.SHIFT]="$pop",wh[ih.UNSHIFT]="$push";var Ih=function(){return Ih=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ih.apply(this,arguments)},Sh=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},Oh=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Th(t){return Ah(t,[t])}function Ah(t,e){if(!kl(t)){if(Rl(t))return t;if(Cl(t))return{$regularExpression:{pattern:t.source,options:t.flags}};if(Pl(t))return t.map(function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return Ah(t,Oh(Oh([],Sh(e),!1),[t],!1))});if(Tl(t)){var n=Ih({},t),r={};for(var o in n){if(e.indexOf(n[o])>-1)throw new Error("Cannot convert circular structure to JSON");void 0!==n[o]&&(r[o]=Ah(n[o],Oh(Oh([],Sh(e),!1),[n[o]],!1)))}return r}return t}switch(t._internalType){case yl:return t.toJSON();case El:case Il:case Sl:return t.parse();default:return t.toJSON?t.toJSON():t}}var Ph=function(){return Ph=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ph.apply(this,arguments)},Rh=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},Ch=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function kh(t,e,n,r){var o=Ph({},t);for(var i in t)if(!/^\$/.test(i)){var s=t[i];if(void 0!==s){if(s&&Tl(s)&&!e(s)){if(r.indexOf(s)>-1)throw new Error("Cannot convert circular structure to JSON");var a=kh(s,e,Ch(Ch([],Rh(n),!1),[i],!1),Ch(Ch([],Rh(r),!1),[s],!1));o[i]=a;var c=!1;for(var u in a)/^\$/.test(u)?c=!0:(o["".concat(i,".").concat(u)]=a[u],delete o[i][u]);c||delete o[i]}}else delete o[i]}return o}function Nh(t){return kh(t,Uh,[],[t])}function xh(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?Pl(t[r])?t[r].push(e[r]):Tl(t[r])?Tl(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(Ol(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(Ol(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function Uh(t){return kl(t)||Rl(t)||Cl(t)}function Lh(t){return Th(t)}var Dh=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.encodeEJSON=function(e,n){var r=new t;return Zl(n?e:r.encodeUpdate(e))},t.prototype.encodeUpdate=function(t){return dh(t)?this.encodeUpdateCommand(t):"object"===Ol(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===dl)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case ih.PUSH:case ih.PULL:case ih.PULL_ALL:case ih.POP:case ih.SHIFT:case ih.UNSHIFT:case ih.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=Eh(t.operator);return t.operator===ih.REMOVE?((e={})[i]=((n={})[t.fieldName]="",n),e):((r={})[i]=((o={})[t.fieldName]=t.operands[0],o),r)},t.prototype.encodeArrayUpdateCommand=function(t){var e,n,r,o,i,s,a,c,u,l,h=Eh(t.operator);switch(t.operator){case ih.PUSH:var d=void 0;return d=Pl(t.operands)?{$each:t.operands.map(Lh)}:t.operands,(e={})[h]=((n={})[t.fieldName]=d,n),e;case ih.UNSHIFT:return d={$each:t.operands.map(Lh),$position:0},(r={})[h]=((o={})[t.fieldName]=d,o),r;case ih.POP:return(i={})[h]=((s={})[t.fieldName]=1,s),i;case ih.SHIFT:return(a={})[h]=((c={})[t.fieldName]=-1,c),a;default:return(u={})[h]=((l={})[t.fieldName]=Lh(t.operands),l),u}},t.prototype.encodeUpdateObject=function(t){var e=Nh(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(dh(r))e[n]=r._setFieldName(n),xh(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=Lh(r);var o=new hh(ih.SET,[r],n);xh(e,this.encodeUpdateCommand(o),n)}}return e},t}(),jh=function(){return jh=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},jh.apply(this,arguments)},qh=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Mh=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Bh=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return Yl(i._db).watch(jh(jh({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify({_id:i.id})}))},this._db=t,this._coll=e,this.id=r,this._transactionId=o,this.request=hd.createRequest(this._db.config),this._apiOptions=n}return t.prototype.create=function(t,e){return zl(this._create(t),e)},t.prototype._create=function(t){return qh(this,void 0,void 0,function(){var e,n,r;return Mh(this,function(o){switch(o.label){case 0:return!(e=Array.isArray(t))&&this.id&&(t._id=this.id),n={collectionName:this._coll,data:e?t.map(function(t){return Zl(Th(t))}):[Zl(Th(t))],transactionId:this._transactionId},[4,this.request.send("database.insertDocument",n,Ql(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:e?[2,{ids:r.data&&r.data.insertedIds||[],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})})},t.prototype.set=function(t,e){return zl(this._set(t),e)},t.prototype._set=function(t){return qh(this,void 0,void 0,function(){var e,n,r,o;return Mh(this,function(i){switch(i.label){case 0:return this.id?t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,oh(this._db.config.throwOnCode,jh(jh({},Fl),{message:"不能更新_id的值"}))]:(e=!1,n=function(t){if("object"==typeof t)for(var r in t)t[r]instanceof hh?e=!0:"object"==typeof t[r]&&n(t[r])},n(t),e?[2,oh(this._db.config.throwOnCode,jh(jh({},Vl),{message:"update operator complicit"}))]:(r={collectionName:this._coll,queryType:$u.DOC,data:Zl(Th(t)),transactionId:this._transactionId,multi:!1,merge:!1,upsert:!0},this.id&&(r.query=Zl({_id:this.id})),[4,this.request.send("database.modifyDocument",r,Ql(this._apiOptions))])):[2,oh(this._db.config.throwOnCode,jh(jh({},Fl),{message:"参数必需是非空对象"}))]:[2,oh(this._db.config.throwOnCode,jh(jh({},Fl),{message:"docId不能为空"}))];case 1:return(o=i.sent()).code?[2,o]:this._transactionId?[2,{updated:o.data.updated,upserted:[{_id:o.data.upsert_id}],requestId:o.requestId}]:[2,{updated:o.data.updated,upsertedId:o.data.upsert_id,requestId:o.requestId}]}})})},t.prototype.update=function(t,e){return zl(this._update(t),e)},t.prototype._update=function(t){return qh(this,void 0,void 0,function(){var e,n,r;return Mh(this,function(o){switch(o.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,oh(this._db.config.throwOnCode,jh(jh({},Fl),{message:"不能更新_id的值"}))]:(e=Zl({_id:this.id}),n={collectionName:this._coll,transactionId:this._transactionId,data:Dh.encodeEJSON(t,this._apiOptions.raw||!1),query:e,queryType:$u.DOC,multi:!1,merge:!0,upsert:!1},[4,this.request.send("database.modifyDocument",n,Ql(this._apiOptions))]):[2,oh(this._db.config.throwOnCode,jh(jh({},Fl),{message:"参数必需是非空对象"}))];case 1:return(r=o.sent()).code?[2,r]:[2,{updated:r.data.updated,requestId:r.requestId}]}})})},t.prototype.delete=function(t){return this.remove(t)},t.prototype.remove=function(t){return zl(this._remove(),t)},t.prototype._remove=function(){return qh(this,void 0,void 0,function(){var t,e,n;return Mh(this,function(r){switch(r.label){case 0:return t=Zl({_id:this.id}),e={collectionName:this._coll,transactionId:this._transactionId,query:t,queryType:$u.DOC,multi:!1},[4,this.request.send("database.removeDocument",e,Ql(this._apiOptions))];case 1:return(n=r.sent()).code?[2,n]:[2,{deleted:n.data.deleted,requestId:n.requestId}]}})})},t.prototype.get=function(t){return zl(this._get(),t)},t.prototype._get=function(){return qh(this,void 0,void 0,function(){var t,e,n,r,o,i;return Mh(this,function(s){switch(s.label){case 0:return t=Zl({_id:this.id}),e=this._apiOptions.projection,n={collectionName:this._coll,query:t,transactionId:this._transactionId,queryType:$u.DOC,multi:!1},e&&(n.projection=Zl(e)),[4,this.request.send("database.getDocument",n,Ql(this._apiOptions))];case 1:return(r=s.sent()).code?[2,r]:(o=r.data.list.map(function(t){return Gl.EJSON.parse(t)}),i=Wl.formatResDocumentData(o),this._transactionId?[2,{data:i[0]||null,requestId:r.requestId}]:[2,{data:i,requestId:r.requestId}])}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=jh({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,o,this.id,this._transactionId)},t}(),Wh=function(){function t(){}return t.encode=function(t){return(new Fh).encodeQuery(t)},t.encodeEJSON=function(t,e){var n=new Fh;return Zl(e?t:n.encodeQuery(t))},t}(),Fh=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n,r,o;return Uh(t)?ph(t)?this.encodeLogicCommand(t):mh(t)?this.encodeQueryCommand(t):Cl(t)?((n={})[e]=this.encodeRegExp(t),n):Rl(t)?((r={})[e]=Lh(t),r):((o={})[e]=this.encodeQueryObject(t),o):Tl(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regularExpression:{pattern:t.source,options:t.flags}}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,s,a,c=this;switch(t.operator){case lh.NOR:case lh.AND:case lh.OR:var u=Eh(t.operator),l=t.operands.map(function(e){return c.encodeQuery(e,t.fieldName)});return(e={})[u]=l,e;case lh.NOT:u=Eh(t.operator);var h=t.operands[0];return Cl(h)?((n={})[t.fieldName]=((r={})[u]=this.encodeRegExp(h),r),n):(l=this.encodeQuery(h)[t.fieldName],(o={})[t.fieldName]=((i={})[u]=l,i),o);default:if(u=Eh(t.operator),1===t.operands.length){var d=this.encodeQuery(t.operands[0]);return(s={})[u]=d,s}return l=t.operands.map(this.encodeQuery.bind(this)),(a={})[u]=l,a}},t.prototype.encodeQueryCommand=function(t){return bh(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,s,a,c,u,l,h;if(t.fieldName===dl)throw new Error("Cannot encode a comparison command with unset field name");var d=Eh(t.operator);switch(t.operator){case vh.EQ:case vh.NEQ:case vh.LT:case vh.LTE:case vh.GT:case vh.GTE:case vh.ELEM_MATCH:case vh.EXISTS:case vh.SIZE:case vh.MOD:return(e={})[t.fieldName]=((n={})[d]=Lh(t.operands[0]),n),e;case vh.IN:case vh.NIN:case vh.ALL:return(r={})[t.fieldName]=((o={})[d]=Lh(t.operands),o),r;case vh.GEO_NEAR:var f=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:f.geometry.toJSON(),$maxDistance:f.maxDistance,$minDistance:f.minDistance}},i;case vh.GEO_WITHIN:if((f=t.operands[0]).centerSphere){ch.isCentersPhere(f.centerSphere);var p=f.centerSphere;return p[0]._internalType===yl?((s={})[t.fieldName]={$geoWithin:{$centerSphere:[p[0].toJSON().coordinates,p[1]]}},s):((a={})[t.fieldName]={$geoWithin:{$centerSphere:f.centerSphere}},a)}return(c={})[t.fieldName]={$geoWithin:{$geometry:f.geometry.toJSON()}},c;case vh.GEO_INTERSECTS:return f=t.operands[0],(u={})[t.fieldName]={$geoIntersects:{$geometry:f.geometry.toJSON()}},u;default:return(l={})[t.fieldName]=((h={})[d]=Lh(t.operands[0]),h),l}},t.prototype.encodeQueryObject=function(t){var e=Nh(t);for(var n in e){var r=e[n];if(ph(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else bh(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):Uh(r)&&(e[n]=Lh(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?Pl(t[r])?t[r]=t[r].concat(e[r]):Tl(t[r])?Tl(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(Ol(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(Ol(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),Hh=function(){return Hh=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Hh.apply(this,arguments)},Vh=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Gh=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Kh=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){var e=Yl(i._db),n=i._apiOptions,r=n.limit,o=n.order,s=o?Object.entries(o).reduce(function(t,e){var n=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(e,2),r=n[0],o=n[1];return t[r]=-1===o?"desc":"asc",t},{}):void 0;return e.watch(Hh(Hh({},t),{envId:i._db.config.env,collectionName:i._coll,query:eh(i._fieldFilters),limit:r,orderBy:s}))},this._db=t,this._coll=e,this._fieldFilters=n,this._apiOptions=r||{},this._request=hd.createRequest(this._db.config),this._transactionId=o}return t.prototype.get=function(t){return zl(this._get(),t)},t.prototype._get=function(){return Vh(this,void 0,void 0,function(){var t,e,n,r,o,i,s,a,c;return Gh(this,function(u){switch(u.label){case 0:return t=this._apiOptions.order,e={collectionName:this._coll,queryType:$u.WHERE,transactionId:this._transactionId},this._fieldFilters&&(e.query=this._fieldFilters),t&&(e.order=Zl(t)),(n=this._apiOptions.offset)&&(e.offset=n),r=this._apiOptions.limit,e.limit=r?r<1e3?r:1e3:100,(o=this._apiOptions.projection)&&(e.projection=Zl(o)),[4,this._request.send("database.getDocument",e,Ql(this._apiOptions))];case 1:return(i=u.sent()).code?[2,i]:(s=i.data.list.map(function(t){return Gl.EJSON.parse(t)}),a=Wl.formatResDocumentData(s),c={data:a,requestId:i.requestId},i.total&&(c.total=i.total),i.limit&&(c.limit=i.limit),i.offset&&(c.offset=i.offset),[2,c])}})})},t.prototype.count=function(t){return zl(this._count(),t)},t.prototype._count=function(){return Vh(this,void 0,void 0,function(){var t,e;return Gh(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,queryType:$u.WHERE},this._fieldFilters&&(t.query=this._fieldFilters),[4,this._request.send("database.calculateDocument",t,Ql(this._apiOptions))];case 1:return(e=n.sent()).code?[2,e]:[2,{requestId:e.requestId,total:e.data.total}]}})})},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(Vu.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(Vu.QueryParamValueError);return new t(this._db,this._coll,Wh.encodeEJSON(e,this._apiOptions.raw||!1),this._apiOptions,this._transactionId)},t.prototype.options=function(e){return ch.isValidOptions(e),new t(this._db,this._coll,this._fieldFilters,e,this._transactionId)},t.prototype.orderBy=function(e,n){var r;ch.isFieldPath(e),ch.isFieldOrder(n);var o=((r={})[e]="desc"===n?-1:1,r),i=this._apiOptions.order||{},s=Object.assign({},this._apiOptions,{order:Object.assign({},i,o)});return new t(this._db,this._coll,this._fieldFilters,s,this._transactionId)},t.prototype.limit=function(e){ch.isInteger("limit",e);var n=Hh({},this._apiOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.skip=function(e){ch.isInteger("offset",e);var n=Hh({},this._apiOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.update=function(t,e){return zl(this._update(t),e)},t.prototype._update=function(t){return Vh(this,void 0,void 0,function(){var e,n,r,o;return Gh(this,function(i){switch(i.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,oh(this._db.config.throwOnCode,Hh(Hh({},Fl),{message:"不能更新_id的值"}))]:(e=this._apiOptions.multiple,n=void 0===e||e,r={collectionName:this._coll,queryType:$u.WHERE,multi:n,merge:!0,upsert:!1,data:Dh.encodeEJSON(t,this._apiOptions.raw||!1)},this._transactionId&&(r.transactionId=this._transactionId),this._fieldFilters&&(r.query=this._fieldFilters),[4,this._request.send("database.modifyDocument",r,Ql(this._apiOptions))]):[2,oh(this._db.config.throwOnCode,Hh(Hh({},Fl),{message:"参数必需是非空对象"}))];case 1:return(o=i.sent()).code?[2,o]:[2,{requestId:o.requestId,updated:o.data.updated,upsertId:o.data.upsert_id}]}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=Hh({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,this._fieldFilters,o,this._transactionId)},t.prototype.remove=function(t){return zl(this._remove(),t)},t.prototype._remove=function(){return Vh(this,void 0,void 0,function(){var t,e,n,r,o,i,s,a,c;return Gh(this,function(u){switch(u.label){case 0:return t=this._apiOptions,e=t.offset,n=t.limit,r=t.projection,o=t.order,void 0===e&&void 0===n&&void 0===r&&void 0===o||console.warn("`offset`, `limit`, `projection`, `orderBy` are not supported in remove() operation"),i=this._apiOptions.multiple,s=void 0===i||i,a={collectionName:this._coll,query:this._fieldFilters,queryType:$u.WHERE,multi:s},this._transactionId&&(a.transactionId=this._transactionId),[4,this._request.send("database.removeDocument",a,Ql(this._apiOptions))];case 1:return(c=u.sent()).code?[2,c]:[2,{requestId:c.requestId,deleted:c.data.deleted}]}})})},t.prototype.updateAndReturn=function(t){return Vh(this,void 0,void 0,function(){var e,n;return Gh(this,function(r){switch(r.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,oh(this._db.config.throwOnCode,Hh(Hh({},Fl),{message:"不能更新_id的值"}))]:(e={collectionName:this._coll,queryType:$u.WHERE,data:Dh.encodeEJSON(t,!1)},this._transactionId&&(e.transactionId=this._transactionId),this._fieldFilters&&(e.query=this._fieldFilters),[4,this._request.send("database.modifyAndReturnDoc",e,Ql(this._apiOptions))]):[2,oh(this._db.config.throwOnCode,Hh(Hh({},Fl),{message:"参数必需是非空对象"}))];case 1:return(n=r.sent()).code?[2,n]:[2,{requestId:n.requestId,updated:n.data.updated,doc:n.data.doc&&Gl.EJSON.parse(n.data.doc)}]}})})},t}(),Jh=function(){function t(t,e,n){var r=this;this._stages=[],t&&e&&(this._db=t,this._request=hd.createRequest(this._db.config),this._collectionName=e,n&&n.length>0&&n.forEach(function(t){ch.isValidAggregation(t);var e=Object.keys(t)[0];r._pipe(e,t[e],!0)}))}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregateDocuments",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:t.data.list.map(Gl.EJSON.parse)}]:[2,t]}})},new((n=void 0)||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())});var t,e,n,r},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map(function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e})},t.prototype._pipe=function(t,e,n){void 0===n&&(n=!1);var r;return r="object"===Ol(e)?Zl(e):JSON.stringify(e),this._stages.push({stageKey:n?t:"$".concat(t),stageValue:r}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=Wh.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new uh(t.near.longitude,t.near.latitude).toJSON()),this._pipe("geoNear",t)},t.prototype.group=function(t){return this._pipe("group",t)},t.prototype.limit=function(t){return this._pipe("limit",t)},t.prototype.match=function(t){return this._pipe("match",Wh.encode(t))},t.prototype.project=function(t){return this._pipe("project",t)},t.prototype.lookup=function(t){return this._pipe("lookup",t)},t.prototype.replaceRoot=function(t){return this._pipe("replaceRoot",t)},t.prototype.sample=function(t){return this._pipe("sample",t)},t.prototype.skip=function(t){return this._pipe("skip",t)},t.prototype.sort=function(t){return this._pipe("sort",t)},t.prototype.sortByCount=function(t){return this._pipe("sortByCount",t)},t.prototype.unwind=function(t){return this._pipe("unwind",t)},t}();const zh=Jh;var $h=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Yh=function(t){function e(e,n,r,o){var i=t.call(this,e,n,"",r,o)||this;return o&&(i._transactionId=o),i}return $h(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!1,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new Bh(this._db,this._coll,this._apiOptions,t,this._transactionId)},e.prototype.add=function(t,e){return zl(this._add(t),e)},e.prototype._add=function(t){return e=this,n=void 0,o=function(){var e,n,r;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(o){switch(o.label){case 0:return e=t,Pl(t)||(e=[t]),e=e.map(function(t){return Zl(Th(t))}),n={collectionName:this._coll,data:e},this._transactionId&&(n.transactionId=this._transactionId),[4,this._request.send("database.insertDocument",n,Ql(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:Pl(t)?[2,{ids:r.data.insertedIds,requestId:r.requestId}]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})},new((r=void 0)||(r=Promise))(function(t,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r(function(t){t(n)})).then(s,a)}c((o=o.apply(e,n||[])).next())});var e,n,r,o},e.prototype.aggregate=function(t){return void 0===t&&(t=[]),new zh(this._db,this._coll,this._apiOptions.raw?t:[])},e.prototype.options=function(t){return ch.isValidOptions(t),new e(this._db,this._coll,t,this._transactionId)},e}(Kh),Qh={eq:function(t){return new gh(vh.EQ,[t])},neq:function(t){return new gh(vh.NEQ,[t])},lt:function(t){return new gh(vh.LT,[t])},lte:function(t){return new gh(vh.LTE,[t])},gt:function(t){return new gh(vh.GT,[t])},gte:function(t){return new gh(vh.GTE,[t])},in:function(t){return new gh(vh.IN,t)},nin:function(t){return new gh(vh.NIN,t)},all:function(t){return new gh(vh.ALL,t)},elemMatch:function(t){return new gh(vh.ELEM_MATCH,[t])},exists:function(t){return new gh(vh.EXISTS,[t])},size:function(t){return new gh(vh.SIZE,[t])},mod:function(){return new gh(vh.MOD,1==arguments.length?[arguments[0]]:2==arguments.length?[[arguments[0],arguments[1]]]:arguments)},geoNear:function(t){return new gh(vh.GEO_NEAR,[t])},geoWithin:function(t){return new gh(vh.GEO_WITHIN,[t])},geoIntersects:function(t){return new gh(vh.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Pl(arguments[0])?arguments[0]:Array.from(arguments);return new fh(lh.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Pl(arguments[0])?arguments[0]:Array.from(arguments);return new fh(lh.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Pl(arguments[0])?arguments[0]:Array.from(arguments);return new fh(lh.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Pl(arguments[0])?arguments[0]:Array.from(arguments);return new fh(lh.NOT,n)},set:function(t){return new hh(ih.SET,[t])},remove:function(){return new hh(ih.REMOVE,[])},inc:function(t){return new hh(ih.INC,[t])},mul:function(t){return new hh(ih.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(Tl(e[0])&&e[0].hasOwnProperty("each")){t={};var r=e[0];void 0!==r.each&&(t.$each=r.each),void 0!==r.position&&(t.$position=r.position),void 0!==r.sort&&(t.$sort=r.sort),void 0!==r.slice&&(t.$slice=r.slice)}else t=Pl(e[0])?e[0]:Array.from(e);return new hh(ih.PUSH,t)},pull:function(t){return new hh(ih.PULL,t)},pullAll:function(t){return new hh(ih.PULL_ALL,t)},pop:function(){return new hh(ih.POP,[])},shift:function(){return new hh(ih.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Pl(arguments[0])?arguments[0]:Array.from(arguments);return new hh(ih.UNSHIFT,n)},addToSet:function(t){return new hh(ih.ADD_TO_SET,t)},rename:function(t){return new hh(ih.RENAME,[t])},bit:function(t){return new hh(ih.BIT,[t])},max:function(t){return new hh(ih.MAX,[t])},min:function(t){return new hh(ih.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return function(t){return"string"===Ol(t)}(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new zh},abs:function(t){return new Xh("abs",t)},add:function(t){return new Xh("add",t)},ceil:function(t){return new Xh("ceil",t)},divide:function(t){return new Xh("divide",t)},exp:function(t){return new Xh("exp",t)},floor:function(t){return new Xh("floor",t)},ln:function(t){return new Xh("ln",t)},log:function(t){return new Xh("log",t)},log10:function(t){return new Xh("log10",t)},mod:function(t){return new Xh("mod",t)},multiply:function(t){return new Xh("multiply",t)},pow:function(t){return new Xh("pow",t)},sqrt:function(t){return new Xh("sqrt",t)},subtract:function(t){return new Xh("subtract",t)},trunc:function(t){return new Xh("trunc",t)},arrayElemAt:function(t){return new Xh("arrayElemAt",t)},arrayToObject:function(t){return new Xh("arrayToObject",t)},concatArrays:function(t){return new Xh("concatArrays",t)},filter:function(t){return new Xh("filter",t)},in:function(t){return new Xh("in",t)},indexOfArray:function(t){return new Xh("indexOfArray",t)},isArray:function(t){return new Xh("isArray",t)},map:function(t){return new Xh("map",t)},range:function(t){return new Xh("range",t)},reduce:function(t){return new Xh("reduce",t)},reverseArray:function(t){return new Xh("reverseArray",t)},size:function(t){return new Xh("size",t)},slice:function(t){return new Xh("slice",t)},zip:function(t){return new Xh("zip",t)},and:function(t){return new Xh("and",t)},not:function(t){return new Xh("not",t)},or:function(t){return new Xh("or",t)},cmp:function(t){return new Xh("cmp",t)},eq:function(t){return new Xh("eq",t)},gt:function(t){return new Xh("gt",t)},gte:function(t){return new Xh("gte",t)},lt:function(t){return new Xh("lt",t)},lte:function(t){return new Xh("lte",t)},neq:function(t){return new Xh("ne",t)},cond:function(t){return new Xh("cond",t)},ifNull:function(t){return new Xh("ifNull",t)},switch:function(t){return new Xh("switch",t)},dateFromParts:function(t){return new Xh("dateFromParts",t)},dateFromString:function(t){return new Xh("dateFromString",t)},dayOfMonth:function(t){return new Xh("dayOfMonth",t)},dayOfWeek:function(t){return new Xh("dayOfWeek",t)},dayOfYear:function(t){return new Xh("dayOfYear",t)},isoDayOfWeek:function(t){return new Xh("isoDayOfWeek",t)},isoWeek:function(t){return new Xh("isoWeek",t)},isoWeekYear:function(t){return new Xh("isoWeekYear",t)},millisecond:function(t){return new Xh("millisecond",t)},minute:function(t){return new Xh("minute",t)},month:function(t){return new Xh("month",t)},second:function(t){return new Xh("second",t)},hour:function(t){return new Xh("hour",t)},week:function(t){return new Xh("week",t)},year:function(t){return new Xh("year",t)},literal:function(t){return new Xh("literal",t)},mergeObjects:function(t){return new Xh("mergeObjects",t)},objectToArray:function(t){return new Xh("objectToArray",t)},allElementsTrue:function(t){return new Xh("allElementsTrue",t)},anyElementTrue:function(t){return new Xh("anyElementTrue",t)},setDifference:function(t){return new Xh("setDifference",t)},setEquals:function(t){return new Xh("setEquals",t)},setIntersection:function(t){return new Xh("setIntersection",t)},setIsSubset:function(t){return new Xh("setIsSubset",t)},setUnion:function(t){return new Xh("setUnion",t)},concat:function(t){return new Xh("concat",t)},dateToString:function(t){return new Xh("dateToString",t)},indexOfBytes:function(t){return new Xh("indexOfBytes",t)},indexOfCP:function(t){return new Xh("indexOfCP",t)},split:function(t){return new Xh("split",t)},strLenBytes:function(t){return new Xh("strLenBytes",t)},strLenCP:function(t){return new Xh("strLenCP",t)},strcasecmp:function(t){return new Xh("strcasecmp",t)},substr:function(t){return new Xh("substr",t)},substrBytes:function(t){return new Xh("substrBytes",t)},substrCP:function(t){return new Xh("substrCP",t)},toLower:function(t){return new Xh("toLower",t)},toUpper:function(t){return new Xh("toUpper",t)},meta:function(t){return new Xh("meta",t)},addToSet:function(t){return new Xh("addToSet",t)},avg:function(t){return new Xh("avg",t)},first:function(t){return new Xh("first",t)},last:function(t){return new Xh("last",t)},max:function(t){return new Xh("max",t)},min:function(t){return new Xh("min",t)},push:function(t){return new Xh("push",t)},stdDevPop:function(t){return new Xh("stdDevPop",t)},stdDevSamp:function(t){return new Xh("stdDevSamp",t)},sum:function(t){return new Xh("sum",t)},let:function(t){return new Xh("let",t)}},project:{slice:function(t){return new Zh("slice",t)},elemMatch:function(t){return new Zh("elemMatch",t)}}},Xh=function(t,e){this["$"+t]=e},Zh=function(t,e){this["$"+t]=e},td=function(){function t(t){var e=(void 0===t?{}:t).offset,n=void 0===e?0:e;this.offset=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return El},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$tcb_server_date:{offset:this.offset}}},t}();function ed(t){return new td(t)}var nd=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regularExpression={pattern:e||"",options:n||""}}return t.prototype.parse=function(){return{$regularExpression:{pattern:this.$regularExpression.pattern,options:this.$regularExpression.options}}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return Il},enumerable:!1,configurable:!0}),t}();function rd(t){return new nd(t)}var od=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},id=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},sd=function(){function t(t){this._db=t,this._request=hd.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return od(this,void 0,void 0,function(){var t;return id(this,function(e){switch(e.label){case 0:return[4,this._request.send("database.startTransaction")];case 1:if((t=e.sent()).code)throw t;return this.inited=!0,this._id=t.transactionId,[2]}})})},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new Yh(this._db,t,{},this._id)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return od(this,void 0,void 0,function(){var t,e;return id(this,function(n){switch(n.label){case 0:return t={transactionId:this._id},[4,this._request.send("database.commitTransaction",t)];case 1:if((e=n.sent()).code)throw e;return this.commited=!0,[2,e]}})})},t.prototype.rollback=function(t){return od(this,void 0,void 0,function(){var e,n;return id(this,function(r){switch(r.label){case 0:return e={transactionId:this._id},[4,this._request.send("database.abortTransaction",e)];case 1:if((n=r.sent()).code)throw n;return this.aborted=!0,this.abortReason=t,[2,n]}})})},t}();function ad(){return od(this,void 0,void 0,function(){var t;return id(this,function(e){switch(e.label){case 0:return[4,(t=new sd(this)).init()];case 1:return e.sent(),[2,t]}})})}function cd(t,e){return void 0===e&&(e=3),od(this,void 0,void 0,function(){var n,r,o,i,s=this;return id(this,function(a){switch(a.label){case 0:return a.trys.push([0,4,,10]),[4,(n=new sd(this)).init()];case 1:return a.sent(),[4,t(n)];case 2:if(r=a.sent(),!0===n.aborted)throw n.abortReason;return[4,n.commit()];case 3:return a.sent(),[2,r];case 4:if(o=a.sent(),!1===n.inited)throw o;return i=function(t){return od(s,void 0,void 0,function(){return id(this,function(e){switch(e.label){case 0:if(n.aborted||n.commited)return[3,5];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,n.rollback()];case 2:case 3:return e.sent(),[3,4];case 4:throw t;case 5:if(!0===n.aborted)throw n.abortReason;throw t}})})},e<=0?[4,i(o)]:[3,6];case 5:a.sent(),a.label=6;case 6:return o&&o.code===Hl?[4,cd.bind(this)(t,--e)]:[3,8];case 7:return[2,a.sent()];case 8:return[4,i(o)];case 9:return a.sent(),[3,10];case 10:return[2]}})})}var ud=function(){function t(t){var e=(void 0===t?{}:t).id,n=void 0===e?"":e;this.id=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return Sl},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$oid:this.id}},t}();function ld(t){return new ud(t)}var hd=function(){function t(t){this.config=t,this.Geo=u,this.serverDate=ed,this.command=Qh,this.RegExp=rd,this.ObjectId=ld,this.startTransaction=ad,this.runTransaction=cd,this.logicCommand=fh,this.updateCommand=hh,this.queryCommand=gh}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];return n&&(e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database)),r.call.apply(r,function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([this,t,n],function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(o),!1))},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new Yh(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}(),dd=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),fd=function(){return fd=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},fd.apply(this,arguments)},pd=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},vd=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function yd(t,e,n,r){(function(t){var e,n,r;return!0===(null===(r=null===(n=null===(e=null==t?void 0:t.config)||void 0===e?void 0:e._fromApp)||void 0===n?void 0:n.config)||void 0===r?void 0:r.debug)})(t)&&function(t,e){var n=t.data;console.error("[cloudbase] NETWORK_ERROR",{status:e,requestId:t.requestId,body:"string"==typeof n?n.slice(0,1024):""})}(e,n),e.code=g.NETWORK_ERROR,e.message=function(t,e){return"HTTP ".concat(t,". Expected ").concat(e,". Set debug: true to see the response.")}(n,r)}var gd={filterRes:function(t,e){t=U(t);var n=Number(t.statusCode);return n>=400&&!t.code&&yd(null!=e?e:this,t,n,"HTTP 2xx"),delete t.header,delete t.statusCode,t},normalizeTransactionResponse:function(t,e){var n=null==(t=U(t))?void 0:t.data;n&&"object"==typeof n&&"string"==typeof n.request_id&&n.request_id&&(t.requestId=n.request_id);var r=Number(t.statusCode),o="start"===e?"HTTP 201 with transactionId":"HTTP 204 with an empty body";if(r>=400)return t.code||yd(this,t,r,o),delete t.header,delete t.statusCode,t;if("start"===e){var i=null==n?void 0:n.transactionId;if(201===r&&"string"==typeof i&&i){var s=gd.flattenResData(t);return delete s.header,delete s.statusCode,s}return t.code||yd(this,t,r,o),delete t.header,delete t.statusCode,t}return 204!==r||""!==n&&null!=n?(t.code||yd(this,t,r,o),delete t.header,delete t.statusCode,t):(delete t.data,delete t.header,delete t.statusCode,t)},flattenResData:function(t){if("object"==typeof t.data&&null!==t.data){var e=fd(fd({},t),t.data);return delete e.data,e}return t},safeParseEJSON:function(t){if("string"!=typeof t)return t;try{return Gl.EJSON.parse(t)}catch(e){return t}},parseEJSONParam:function(t){if("string"!=typeof t)return t;try{return JSON.parse(t)}catch(e){return t}},parseEJSONValue:function(t){if("string"!=typeof t)return t;try{return Gl.EJSON.parse(t)}catch(e){return gd.parseEJSONParam(t)}},normalizeOrderParam:function(t){if(null!=t&&""!==t){for(var e=gd.parseEJSONValue(t),n=function(t){var e=t&&"object"==typeof t?Number(t):t;if("number"==typeof e&&!isNaN(e))return e<0?"desc":"asc";if("string"==typeof e){var n=e.toLowerCase();if("desc"===n||"-1"===n)return"desc";if("asc"===n||"1"===n)return"asc"}},r=[],o=0,i=Array.isArray(e)?e:[e];o<i.length;o++){var s=i[o];if(s&&"object"==typeof s)if(void 0!==s.field)(u=n(s.direction))&&r.push({field:s.field,direction:u});else for(var a=0,c=Object.entries(s);a<c.length;a++){var u,l=c[a],h=l[0];(u=n(l[1]))&&r.push({field:h,direction:u})}}return r.length?r:void 0}},extractDocId:function(t){if(t&&"object"==typeof t&&!Array.isArray(t)&&1===Object.keys(t).length&&"_id"in t){var e=t._id;if("string"==typeof e||"number"==typeof e)return String(e);if(e&&"object"==typeof e){if("string"==typeof e.$oid)return e.$oid;var n=e.$eq;if("string"==typeof n||"number"==typeof n)return String(n);if(n&&"object"==typeof n&&"string"==typeof n.$oid)return n.$oid}}},toLegacyRegExp:function(t){if(!t||"object"!=typeof t)return t;if(t.$regularExpression&&"object"==typeof t.$regularExpression){var e=t.$regularExpression;return{$regex:e.pattern,$options:e.options}}if(Array.isArray(t))return t.map(function(t){return gd.toLegacyRegExp(t)});var n={};for(var r in t)n[r]=gd.toLegacyRegExp(t[r]);return n},parseWriteParam:function(t){return gd.toLegacyRegExp(gd.parseEJSONParam(t))},buildQueryParams:function(t){return Object.entries(t).filter(function(t){t[0];var e=t[1];return null!=e&&""!==e}).map(function(t){var e=t[0],n=t[1],r="object"==typeof n?JSON.stringify(n):String(n);return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(r))}).join("&")},getUrlPrefix:function(t){var e=(null==t?void 0:t.instance)||"(default)",n=(null==t?void 0:t.database)||"(default)";return"/database/instances/".concat(e,"/databases/").concat(n)},"database.queryDocument":function(t,e){var n,r,o,i;return pd(this,void 0,Promise,function(){var s,a,c,u,l,h,d;return vd(this,function(f){switch(f.label){case 0:return s=gd.parseEJSONParam(t.query),a=gd.parseEJSONValue(t.projection),c=gd.extractDocId(s),u=void 0!==c,l=gd.buildQueryParams(fd({projection:a,transactionId:t.transactionId},u?{}:{offset:null!==(n=t.offset)&&void 0!==n?n:0,limit:null!==(r=t.limit)&&void 0!==r?r:100,order:gd.normalizeOrderParam(t.order),query:s?Gl.EJSON.stringify(s,{relaxed:!1}):void 0})),h="".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(l),u&&(h="".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/").concat(c,"?").concat(l)),[4,this.gateWay({url:h,method:"GET"},e)];case 1:return(d=f.sent()).data=gd.safeParseEJSON(JSON.stringify(d.data)),!u||d.code||(null===(o=d.data)||void 0===o?void 0:o.code)?(d.code||(null===(i=d.data)||void 0===i?void 0:i.code)?d=fd(fd({},d),{data:fd(fd({},d.data),{list:[]})}):Array.isArray(d.data)?d=fd(fd({},d),{data:{list:d.data}}):d.data&&!Array.isArray(d.data.list)&&(d=fd(fd({},d),{data:fd(fd({},d.data),{list:[]})})),[2,gd.filterRes(d,this)]):[2,fd(fd({},d),{data:{list:[d.data]}})]}})})},"database.addDocument":function(t,e){var n,r,o;return pd(this,void 0,Promise,function(){var i,s;return vd(this,function(a){switch(a.label){case 0:return i=(Array.isArray(t.data)?t.data:[t.data]).map(function(t){return gd.parseWriteParam(t)}),[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:fd({data:i},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return s=a.sent(),Array.isArray(t.data)?s=fd(fd({},s),{data:fd({ids:(null===(n=s.data)||void 0===n?void 0:n.insertedIds)||[]},s.data)}):(null===(o=null===(r=s.data)||void 0===r?void 0:r.insertedIds)||void 0===o?void 0:o[0])&&(s=fd(fd({},s),{data:fd({_id:s.data.insertedIds[0]},s.data)})),[2,gd.filterRes(s,this)]}})})},"database.updateDocument":function(t,e){var n;return pd(this,void 0,Promise,function(){var r;return vd(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:fd({query:gd.parseEJSONParam(t.query),data:gd.parseEJSONParam(t.data),multi:!!t.multi,upsert:!!t.upsert,replaceMode:null!==(n=t.replaceMode)&&void 0!==n?n:!1===t.merge},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return r=o.sent(),[2,gd.filterRes(r,this)]}})})},"database.deleteDocument":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:fd({query:gd.parseEJSONParam(t.query),multi:!!t.multi},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return n=r.sent(),[2,gd.filterRes(n,this)]}})})},"database.countDocument":function(t,e){return pd(this,void 0,Promise,function(){var n,r,o;return vd(this,function(i){switch(i.label){case 0:return n=gd.parseEJSONParam(t.query),r=gd.buildQueryParams({count:!0,query:n?Gl.EJSON.stringify(n,{relaxed:!1}):void 0}),[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(r),method:"GET"},e)];case 1:return o=i.sent(),[2,gd.filterRes(o,this)]}})})},"database.addCollection":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}},e)];case 1:return n=r.sent(),[2,gd.filterRes(n,this)]}})})},"database.aggregate":function(t,e){var n;return pd(this,void 0,Promise,function(){var r,o;return vd(this,function(i){switch(i.label){case 0:return r=t.stages.map(function(t){var e,n;try{var r="string"==typeof t.stageValue?JSON.parse(t.stageValue):t.stageValue;return(e={})[t.stageKey]=Gl.EJSON.serialize(r),e}catch(e){return(n={})[t.stageKey]=t.stageValue,n}}),[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/aggregations"),method:"POST",data:{pipeline:r}},e)];case 1:return o=i.sent(),Array.isArray(null===(n=o.data)||void 0===n?void 0:n.list)&&(o.data.list=JSON.stringify(o.data.list.map(function(t){return JSON.stringify(t)}))),[2,gd.filterRes(o,this)]}})})},"database.startTransaction":function(t,e){return pd(this,void 0,void 0,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/transactions"),method:"POST",shouldThrowOnError:!1},e)];case 1:return n=r.sent(),[2,gd.normalizeTransactionResponse.call(this,n,"start")]}})})},"database.commitTransaction":function(t,e){return pd(this,void 0,void 0,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST",shouldThrowOnError:!1},e)];case 1:return n=r.sent(),[2,gd.normalizeTransactionResponse.call(this,n,"commit")]}})})},"database.abortTransaction":function(t,e){return pd(this,void 0,void 0,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST",shouldThrowOnError:!1},e)];case 1:return n=r.sent(),[2,gd.normalizeTransactionResponse.call(this,n,"rollback")]}})})},"database.getInTransaction":function(t,e){var n;return pd(this,void 0,void 0,function(){var r;return vd(this,function(o){switch(o.label){case 0:return[4,gd["database.queryDocument"].call(this,t,e)];case 1:return"object"==typeof(r=o.sent()).data&&null!==r.data?(null===(n=r.data)||void 0===n?void 0:n.code)?[2,gd.flattenResData(r)]:[2,fd(fd({},r),{data:JSON.stringify(r.data)})]:[2,r]}})})},"database.updateDocInTransaction":function(t,e){return pd(this,void 0,void 0,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,gd["database.updateDocument"].call(this,t,e)];case 1:return n=r.sent(),[2,gd.flattenResData(n)]}})})},"database.deleteDocInTransaction":function(t,e){return pd(this,void 0,void 0,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,gd["database.deleteDocument"].call(this,t,e)];case 1:return n=r.sent(),[2,gd.flattenResData(n)]}})})},"database.insertDocInTransaction":function(t,e){var n;return pd(this,void 0,Promise,function(){var r,o;return vd(this,function(i){switch(i.label){case 0:return[4,gd["database.addDocument"].call(this,t,e)];case 1:return"object"==typeof(r=i.sent()).data&&null!==r.data?(o=!!(null===(n=r.data)||void 0===n?void 0:n._id),r=fd(fd(fd({},r),{inserted:o?1:0,ok:o?1:0}),r.data)):r=fd({inserted:0,ok:0},r),delete r.data,[2,r]}})})},"database.runCommands":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/commands"),method:"POST",data:fd({commands:Gl.EJSON.serialize(Array.isArray(t.commands)?t.commands.map(function(t){return gd.parseEJSONParam(t)}):t.commands)},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:"object"==typeof(n=r.sent()).data&&null!==n.data&&(delete(n=fd(fd({},n),n.data)).data,delete n.request_id);try{n=Gl.EJSON.deserialize(n)}catch(t){}return[2,gd.filterRes(n,this)]}})})},"database.getDocument":function(t,e){var n;return pd(this,void 0,Promise,function(){var r,o;return vd(this,function(i){switch(i.label){case 0:return(r=fd({},t)).query=gd.parseEJSONParam(r.query),r.projection=gd.parseEJSONValue(r.projection),[4,gd["database.queryDocument"].call(this,r,e)];case 1:return o=i.sent(),Array.isArray(null===(n=o.data)||void 0===n?void 0:n.list)&&(o.data.list=o.data.list.map(function(t){return Gl.EJSON.stringify(t,{relaxed:!1})})),[2,o]}})})},"database.insertDocument":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){return(n=fd({},t)).data=Array.isArray(n.data)?n.data.map(function(t){return gd.parseWriteParam(t)}):gd.parseWriteParam(n.data),[2,gd["database.addDocument"].call(this,n,e)]})})},"database.modifyDocument":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){return(n=fd({},t)).query=gd.parseEJSONParam(n.query),n.data=gd.parseEJSONParam(n.data),[2,gd["database.updateDocument"].call(this,n,e)]})})},"database.modifyAndReturnDoc":function(t,e){var n,r;return pd(this,void 0,Promise,function(){var o,i,s;return vd(this,function(a){switch(a.label){case 0:return(o=fd({},t)).query=gd.parseEJSONParam(o.query),o.data=gd.parseEJSONParam(o.data),(i=gd.extractDocId(o.query))?[4,this.gateWay({url:"".concat(gd.getUrlPrefix(o),"/collections/").concat(o.collectionName,"/documents/").concat(i),method:"PATCH",data:fd({data:o.data,replaceMode:null!==(n=o.replaceMode)&&void 0!==n&&n,upsert:!!o.upsert,returnDoc:!0},o.transactionId&&{transactionId:o.transactionId})},e)]:[2,gd["database.updateDocument"].call(this,o,e)];case 1:return s=a.sent(),void 0!==(null===(r=s.data)||void 0===r?void 0:r.doc)&&"string"!=typeof s.data.doc&&(s.data.doc=Gl.EJSON.stringify(s.data.doc,{relaxed:!1})),[2,gd.filterRes(s,this)]}})})},"database.removeDocument":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){return(n=fd({},t)).query=gd.parseEJSONParam(n.query),void 0!==n.query&&null!==n.query&&""!==n.query||(n.query={_id:{$exists:!0}}),[2,gd["database.deleteDocument"].call(this,n,e)]})})},"database.calculateDocument":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){return(n=fd({},t)).query=gd.parseEJSONParam(n.query),[2,gd["database.countDocument"].call(this,n,e)]})})},"database.aggregateDocuments":function(t,e){var n;return pd(this,void 0,Promise,function(){var r,o;return vd(this,function(i){switch(i.label){case 0:return r=fd({},t),Array.isArray(r.stages)&&(r.stages=r.stages.map(function(t){return fd(fd({},t),{stageValue:gd.parseEJSONParam(t.stageValue)})})),[4,gd["database.aggregate"].call(this,r,e)];case 1:if(o=i.sent(),"string"==typeof(null===(n=o.data)||void 0===n?void 0:n.list))try{o.data.list=JSON.parse(o.data.list)}catch(t){}return[2,o]}})})}},md={name:"database",entity:{database:function(t){var e;if(void 0!==t&&"Object"!==Object.prototype.toString.call(t).slice(8,-1))throw k({code:"INVALID_PARAM",msg:"dbConfig must be an object"},null===(e=this.config)||void 0===e?void 0:e.errorFactory);var n=this.platform,r=n.adapter,o=n.runtime,i=function(t){function e(e){return t.call(this,e)||this}return dd(e,t),e.prototype.send=function(e,n,r){var o,i,s,a;return pd(this,void 0,void 0,function(){var c,u,l;return vd(this,function(h){switch(h.label){case 0:return c=null,u=r&&"number"==typeof r.timeout?{timeout:r.timeout}:void 0,"GATEWAY"===this.config.endPointMode&&gd[e]?[4,gd[e].call(this,n,u)]:[3,2];case 1:return c=h.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,e,n,void 0,u)];case 3:c=h.sent(),h.label=4;case 4:if(l=N(null!==(s=null===(i=null===(o=this.config)||void 0===o?void 0:o._fromApp)||void 0===i?void 0:i.config)&&void 0!==s?s:this.config),c&&c.code&&l)throw k({code:c.code,msg:c.message||c.data&&c.data.message||"",requestId:c.requestId},null===(a=this.config)||void 0===a?void 0:a.errorFactory);return[2,c]}})})},e}(this.request.constructor);return hd.reqClass=i,hd.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},hd.runtime=o,this.wsClientClass&&(hd.wsClass=r.wsClass,hd.wsClientClass=this.wsClientClass),hd.ws||(hd.ws=null),new(function(t){function e(e){return t.call(this,e)||this}return dd(e,t),e.prototype.runCommands=function(t){return pd(this,void 0,Promise,function(){return vd(this,function(e){return[2,hd.createRequest(this.config).send("database.runCommands",t)]})})},e}(hd))(fd(fd(fd({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(md)}catch(t){}function bd(t){try{t.registerComponent(md)}catch(t){console.warn(t)}}try{window.registerDatabase=bd}catch(t){}ae.registerVersion("3.10.4-beta.0");try{!function(t){try{t.registerComponent(hr)}catch(t){console.warn(t)}}(ae),function(t){try{t.registerComponent(Mr)}catch(t){console.warn(t)}}(ae),ri(ae),bd(ae),function(t){try{t.registerComponent(Bi),t.registerHook(Mi)}catch(t){console.warn(t)}}(ae),Ta(ae),Da(ae),Ru(ae),Er(ae),Lu(ae),Ju(ae)}catch(t){}try{window.cloudbase=ae}catch(t){}const wd=ae})();var d=h.Z;export{d as default};
2
+ import*as t from"@cloudbase/adapter-interface";import*as e from"jwt-decode";import*as n from"@cloudbase/adapter-wx_mp";import*as r from"@cloudbase/wx-cloud-client-sdk";import*as o from"web-streams-polyfill";import*as i from"@mattiasbuelens/web-streams-adapter";import*as s from"text-encoding-shim";import*as a from"bson";var c={3171:(t,e,n)=>{var r;if(n.r(e),n.d(e,{getEncryptInfo:()=>q}),!globalThis.IS_MP_BUILD){var o="undefined"!=typeof globalThis?globalThis.navigator:window.globalThis;function M(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}function B(t,e){return t&e}function W(t,e){return t|e}function F(t,e){return t^e}function H(t,e){return t&~e}function V(t){if(0==t)return-1;var e=0;return 65535&t||(t>>=16,e+=16),255&t||(t>>=8,e+=8),15&t||(t>>=4,e+=4),3&t||(t>>=2,e+=2),1&t||++e,e}function G(t){for(var e=0;0!=t;)t&=t-1,++e;return e}var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function K(t){var e,n,r="";for(e=0;e+3<=t.length;e+=3)n=parseInt(t.substring(e,e+3),16),r+=i.charAt(n>>6)+i.charAt(63&n);for(e+1==t.length?(n=parseInt(t.substring(e,e+1),16),r+=i.charAt(n<<2)):e+2==t.length&&(n=parseInt(t.substring(e,e+2),16),r+=i.charAt(n>>2)+i.charAt((3&n)<<4));(3&r.length)>0;)r+="=";return r}function J(t){var e,n="",r=0,o=0;for(e=0;e<t.length&&"="!=t.charAt(e);++e){var s=i.indexOf(t.charAt(e));s<0||(0==r?(n+=M(s>>2),o=3&s,r=1):1==r?(n+=M(o<<2|s>>4),o=15&s,r=2):2==r?(n+=M(o),n+=M(s>>2),o=3&s,r=3):(n+=M(o<<2|s>>4),n+=M(15&s),r=0))}return 1==r&&(n+=M(o<<2)),n}var s,a,c={decode:function(t){var e;if(void 0===s){var n="0123456789ABCDEF";for(s={},e=0;e<16;++e)s[n.charAt(e)]=e;for(n=n.toLowerCase(),e=10;e<16;++e)s[n.charAt(e)]=e;for(e=0;e<8;++e)s[" \f\n\r\t \u2028\u2029".charAt(e)]=-1}var r=[],o=0,i=0;for(e=0;e<t.length;++e){var a=t.charAt(e);if("="==a)break;if(-1!=(a=s[a])){if(void 0===a)throw new Error("Illegal character at offset "+e);o|=a,++i>=2?(r[r.length]=o,o=0,i=0):o<<=4}}if(i)throw new Error("Hex encoding incomplete: 4 bits missing");return r}},u={decode:function(t){var e;if(void 0===a){for(a=Object.create(null),e=0;e<64;++e)a["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;for(e=0;e<9;++e)a["= \f\n\r\t \u2028\u2029".charAt(e)]=-1}var n=[],r=0,o=0;for(e=0;e<t.length;++e){var i=t.charAt(e);if("="==i)break;if(-1!=(i=a[i])){if(void 0===i)throw new Error("Illegal character at offset "+e);r|=i,++o>=4?(n[n.length]=r>>16,n[n.length]=r>>8&255,n[n.length]=255&r,r=0,o=0):r<<=6}}switch(o){case 1:throw new Error("Base64 encoding incomplete: at least 2 bits missing");case 2:n[n.length]=r>>10;break;case 3:n[n.length]=r>>16,n[n.length]=r>>8&255}return n},re:/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,unarmor:function(t){var e=u.re.exec(t);if(e)if(e[1])t=e[1];else{if(!e[2])throw new Error("RegExp out of sync");t=e[2]}return u.decode(t)}},l=1e13;class z{constructor(t){this.buf=[+t||0]}mulAdd(t,e){var n,r,o=this.buf,i=o.length;for(n=0;n<i;++n)(r=o[n]*t+e)<l?e=0:r-=(e=0|r/l)*l,o[n]=r;e>0&&(o[n]=e)}sub(t){var e,n,r=this.buf,o=r.length;for(e=0;e<o;++e)(n=r[e]-t)<0?(n+=l,t=1):t=0,r[e]=n;for(;0===r[r.length-1];)r.pop()}toString(t){if(10!=(t||10))throw new Error("only base 10 is supported");for(var e=this.buf,n=e[e.length-1].toString(),r=e.length-2;r>=0;--r)n+=(l+e[r]).toString().substring(1);return n}valueOf(){for(var t=this.buf,e=0,n=t.length-1;n>=0;--n)e=e*l+t[n];return e}simplify(){var t=this.buf;return 1==t.length?t[0]:this}}var h,d=/^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/,f=/^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;function $(t,e){return t.length>e&&(t=t.substring(0,e)+"…"),t}class Y{constructor(t,e){this.hexDigits="0123456789ABCDEF",t instanceof Y?(this.enc=t.enc,this.pos=t.pos):(this.enc=t,this.pos=e)}get(t){if(void 0===t&&(t=this.pos++),t>=this.enc.length)throw new Error("Requesting byte offset "+t+" on a stream of length "+this.enc.length);return"string"==typeof this.enc?this.enc.charCodeAt(t):this.enc[t]}hexByte(t){return this.hexDigits.charAt(t>>4&15)+this.hexDigits.charAt(15&t)}hexDump(t,e,n){for(var r="",o=t;o<e;++o)if(r+=this.hexByte(this.get(o)),!0!==n)switch(15&o){case 7:r+=" ";break;case 15:r+="\n";break;default:r+=" "}return r}isASCII(t,e){for(var n=t;n<e;++n){var r=this.get(n);if(r<32||r>176)return!1}return!0}parseStringISO(t,e){for(var n="",r=t;r<e;++r)n+=String.fromCharCode(this.get(r));return n}parseStringUTF(t,e){for(var n="",r=t;r<e;){var o=this.get(r++);n+=o<128?String.fromCharCode(o):o>191&&o<224?String.fromCharCode((31&o)<<6|63&this.get(r++)):String.fromCharCode((15&o)<<12|(63&this.get(r++))<<6|63&this.get(r++))}return n}parseStringBMP(t,e){for(var n,r,o="",i=t;i<e;)n=this.get(i++),r=this.get(i++),o+=String.fromCharCode(n<<8|r);return o}parseTime(t,e,n){var r=this.parseStringISO(t,e),o=(n?d:f).exec(r);return o?(n&&(o[1]=+o[1],o[1]+=+o[1]<70?2e3:1900),r=o[1]+"-"+o[2]+"-"+o[3]+" "+o[4],o[5]&&(r+=":"+o[5],o[6]&&(r+=":"+o[6],o[7]&&(r+="."+o[7]))),o[8]&&(r+=" UTC","Z"!=o[8]&&(r+=o[8],o[9]&&(r+=":"+o[9]))),r):"Unrecognized time: "+r}parseInteger(t,e){for(var n,r=this.get(t),o=r>127,i=o?255:0,s="";r==i&&++t<e;)r=this.get(t);if(0===(n=e-t))return o?-1:0;if(n>4){for(s=r,n<<=3;!(128&(+s^i));)s=+s<<1,--n;s="("+n+" bit)\n"}o&&(r-=256);for(var a=new z(r),c=t+1;c<e;++c)a.mulAdd(256,this.get(c));return s+a.toString()}parseBitString(t,e,n){for(var r=this.get(t),o="("+((e-t-1<<3)-r)+" bit)\n",i="",s=t+1;s<e;++s){for(var a=this.get(s),c=s==e-1?r:0,u=7;u>=c;--u)i+=a>>u&1?"1":"0";if(i.length>n)return o+$(i,n)}return o+i}parseOctetString(t,e,n){if(this.isASCII(t,e))return $(this.parseStringISO(t,e),n);var r=e-t,o="("+r+" byte)\n";r>(n/=2)&&(e=t+n);for(var i=t;i<e;++i)o+=this.hexByte(this.get(i));return r>n&&(o+="…"),o}parseOID(t,e,n){for(var r="",o=new z,i=0,s=t;s<e;++s){var a=this.get(s);if(o.mulAdd(128,127&a),i+=7,!(128&a)){if(""===r)if((o=o.simplify())instanceof z)o.sub(80),r="2."+o.toString();else{var c=o<80?o<40?0:1:2;r=c+"."+(o-40*c)}else r+="."+o.toString();if(r.length>n)return $(r,n);o=new z,i=0}}return i>0&&(r+=".incomplete"),r}}class Q{constructor(t,e,n,r,o){if(!(r instanceof X))throw new Error("Invalid tag value.");this.stream=t,this.header=e,this.length=n,this.tag=r,this.sub=o}typeName(){switch(this.tag.tagClass){case 0:switch(this.tag.tagNumber){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString"}return"Universal_"+this.tag.tagNumber.toString();case 1:return"Application_"+this.tag.tagNumber.toString();case 2:return"["+this.tag.tagNumber.toString()+"]";case 3:return"Private_"+this.tag.tagNumber.toString()}}content(t){if(void 0===this.tag)return null;void 0===t&&(t=1/0);var e=this.posContent(),n=Math.abs(this.length);if(!this.tag.isUniversal())return null!==this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+n,t);switch(this.tag.tagNumber){case 1:return 0===this.stream.get(e)?"false":"true";case 2:return this.stream.parseInteger(e,e+n);case 3:return this.sub?"("+this.sub.length+" elem)":this.stream.parseBitString(e,e+n,t);case 4:return this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+n,t);case 6:return this.stream.parseOID(e,e+n,t);case 16:case 17:return null!==this.sub?"("+this.sub.length+" elem)":"(no elem)";case 12:return $(this.stream.parseStringUTF(e,e+n),t);case 18:case 19:case 20:case 21:case 22:case 26:return $(this.stream.parseStringISO(e,e+n),t);case 30:return $(this.stream.parseStringBMP(e,e+n),t);case 23:case 24:return this.stream.parseTime(e,e+n,23==this.tag.tagNumber)}return null}toString(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+(null===this.sub?"null":this.sub.length)+"]"}toPrettyString(t){void 0===t&&(t="");var e=t+this.typeName()+" @"+this.stream.pos;if(this.length>=0&&(e+="+"),e+=this.length,this.tag.tagConstructed?e+=" (constructed)":!this.tag.isUniversal()||3!=this.tag.tagNumber&&4!=this.tag.tagNumber||null===this.sub||(e+=" (encapsulates)"),e+="\n",null!==this.sub){t+=" ";for(var n=0,r=this.sub.length;n<r;++n)e+=this.sub[n].toPrettyString(t)}return e}posStart(){return this.stream.pos}posContent(){return this.stream.pos+this.header}posEnd(){return this.stream.pos+this.header+Math.abs(this.length)}toHexString(){return this.stream.hexDump(this.posStart(),this.posEnd(),!0)}static decodeLength(t){var e=t.get(),n=127&e;if(n==e)return n;if(n>6)throw new Error("Length over 48 bits not supported at position "+(t.pos-1));if(0===n)return null;e=0;for(var r=0;r<n;++r)e=256*e+t.get();return e}getHexStringValue(){var t=this.toHexString(),e=2*this.header,n=2*this.length;return t.substr(e,n)}static decode(t){var e;e=t instanceof Y?t:new Y(t,0);var n=new Y(e),r=new X(e),o=Q.decodeLength(e),i=e.pos,s=i-n.pos,a=null,c=function(){var t=[];if(null!==o){for(var n=i+o;e.pos<n;)t[t.length]=Q.decode(e);if(e.pos!=n)throw new Error("Content size is not correct for container starting at offset "+i)}else try{for(;;){var r=Q.decode(e);if(r.tag.isEOC())break;t[t.length]=r}o=i-e.pos}catch(t){throw new Error("Exception while decoding undefined length content: "+t)}return t};if(r.tagConstructed)a=c();else if(r.isUniversal()&&(3==r.tagNumber||4==r.tagNumber))try{if(3==r.tagNumber&&0!=e.get())throw new Error("BIT STRINGs with unused bits cannot encapsulate.");a=c();for(var u=0;u<a.length;++u)if(a[u].tag.isEOC())throw new Error("EOC is not supposed to be actual content.")}catch(t){a=null}if(null===a){if(null===o)throw new Error("We can't skip over an invalid tag with undefined length at offset "+i);e.pos=i+Math.abs(o)}return new Q(n,s,o,r,a)}}class X{constructor(t){var e=t.get();if(this.tagClass=e>>6,this.tagConstructed=!!(32&e),this.tagNumber=31&e,31==this.tagNumber){var n=new z;do{e=t.get(),n.mulAdd(128,127&e)}while(128&e);this.tagNumber=n.simplify()}}isUniversal(){return 0===this.tagClass}isEOC(){return 0===this.tagClass&&0===this.tagNumber}}var p=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],v=(1<<26)/p[p.length-1];class Z{constructor(t,e,n){null!=t&&("number"==typeof t?this.fromNumber(t,e,n):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}toString(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var n,r=(1<<e)-1,o=!1,i="",s=this.t,a=this.DB-s*this.DB%e;if(s-- >0)for(a<this.DB&&(n=this[s]>>a)>0&&(o=!0,i=M(n));s>=0;)a<e?(n=(this[s]&(1<<a)-1)<<e-a,n|=this[--s]>>(a+=this.DB-e)):(n=this[s]>>(a-=e)&r,a<=0&&(a+=this.DB,--s)),n>0&&(o=!0),o&&(i+=M(n));return o?i:"0"}negate(){var t=tt();return Z.ZERO.subTo(this,t),t}abs(){return this.s<0?this.negate():this}compareTo(t){var e=this.s-t.s;if(0!=e)return e;var n=this.t;if(0!=(e=n-t.t))return this.s<0?-e:e;for(;--n>=0;)if(0!=(e=this[n]-t[n]))return e;return 0}bitLength(){return this.t<=0?0:this.DB*(this.t-1)+at(this[this.t-1]^this.s&this.DM)}mod(t){var e=tt();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(Z.ZERO)>0&&t.subTo(e,e),e}modPowInt(t,e){var n;return n=t<256||e.isEven()?new g(e):new m(e),this.exp(t,n)}clone(){var t=tt();return this.copyTo(t),t}intValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}byteValue(){return 0==this.t?this.s:this[0]<<24>>24}shortValue(){return 0==this.t?this.s:this[0]<<16>>16}signum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}toByteArray(){var t=this.t,e=[];e[0]=this.s;var n,r=this.DB-t*this.DB%8,o=0;if(t-- >0)for(r<this.DB&&(n=this[t]>>r)!=(this.s&this.DM)>>r&&(e[o++]=n|this.s<<this.DB-r);t>=0;)r<8?(n=(this[t]&(1<<r)-1)<<8-r,n|=this[--t]>>(r+=this.DB-8)):(n=this[t]>>(r-=8)&255,r<=0&&(r+=this.DB,--t)),128&n&&(n|=-256),0==o&&(128&this.s)!=(128&n)&&++o,(o>0||n!=this.s)&&(e[o++]=n);return e}equals(t){return 0==this.compareTo(t)}min(t){return this.compareTo(t)<0?this:t}max(t){return this.compareTo(t)>0?this:t}and(t){var e=tt();return this.bitwiseTo(t,B,e),e}or(t){var e=tt();return this.bitwiseTo(t,W,e),e}xor(t){var e=tt();return this.bitwiseTo(t,F,e),e}andNot(t){var e=tt();return this.bitwiseTo(t,H,e),e}not(){for(var t=tt(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t}shiftLeft(t){var e=tt();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}shiftRight(t){var e=tt();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}getLowestSetBit(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+V(this[t]);return this.s<0?this.t*this.DB:-1}bitCount(){for(var t=0,e=this.s&this.DM,n=0;n<this.t;++n)t+=G(this[n]^e);return t}testBit(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:!!(this[e]&1<<t%this.DB)}setBit(t){return this.changeBit(t,W)}clearBit(t){return this.changeBit(t,H)}flipBit(t){return this.changeBit(t,F)}add(t){var e=tt();return this.addTo(t,e),e}subtract(t){var e=tt();return this.subTo(t,e),e}multiply(t){var e=tt();return this.multiplyTo(t,e),e}divide(t){var e=tt();return this.divRemTo(t,e,null),e}remainder(t){var e=tt();return this.divRemTo(t,null,e),e}divideAndRemainder(t){var e=tt(),n=tt();return this.divRemTo(t,e,n),[e,n]}modPow(t,e){var n,r,o=t.bitLength(),i=st(1);if(o<=0)return i;n=o<18?1:o<48?3:o<144?4:o<768?5:6,r=o<8?new g(e):e.isEven()?new b(e):new m(e);var s=[],a=3,c=n-1,u=(1<<n)-1;if(s[1]=r.convert(this),n>1){var l=tt();for(r.sqrTo(s[1],l);a<=u;)s[a]=tt(),r.mulTo(l,s[a-2],s[a]),a+=2}var h,d,f=t.t-1,p=!0,v=tt();for(o=at(t[f])-1;f>=0;){for(o>=c?h=t[f]>>o-c&u:(h=(t[f]&(1<<o+1)-1)<<c-o,f>0&&(h|=t[f-1]>>this.DB+o-c)),a=n;!(1&h);)h>>=1,--a;if((o-=a)<0&&(o+=this.DB,--f),p)s[h].copyTo(i),p=!1;else{for(;a>1;)r.sqrTo(i,v),r.sqrTo(v,i),a-=2;a>0?r.sqrTo(i,v):(d=i,i=v,v=d),r.mulTo(v,s[h],i)}for(;f>=0&&!(t[f]&1<<o);)r.sqrTo(i,v),d=i,i=v,v=d,--o<0&&(o=this.DB-1,--f)}return r.revert(i)}modInverse(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return Z.ZERO;for(var n=t.clone(),r=this.clone(),o=st(1),i=st(0),s=st(0),a=st(1);0!=n.signum();){for(;n.isEven();)n.rShiftTo(1,n),e?(o.isEven()&&i.isEven()||(o.addTo(this,o),i.subTo(t,i)),o.rShiftTo(1,o)):i.isEven()||i.subTo(t,i),i.rShiftTo(1,i);for(;r.isEven();)r.rShiftTo(1,r),e?(s.isEven()&&a.isEven()||(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);n.compareTo(r)>=0?(n.subTo(r,n),e&&o.subTo(s,o),i.subTo(a,i)):(r.subTo(n,r),e&&s.subTo(o,s),a.subTo(i,a))}return 0!=r.compareTo(Z.ONE)?Z.ZERO:a.compareTo(t)>=0?a.subtract(t):a.signum()<0?(a.addTo(t,a),a.signum()<0?a.add(t):a):a}pow(t){return this.exp(t,new y)}gcd(t){var e=this.s<0?this.negate():this.clone(),n=t.s<0?t.negate():t.clone();if(e.compareTo(n)<0){var r=e;e=n,n=r}var o=e.getLowestSetBit(),i=n.getLowestSetBit();if(i<0)return e;for(o<i&&(i=o),i>0&&(e.rShiftTo(i,e),n.rShiftTo(i,n));e.signum()>0;)(o=e.getLowestSetBit())>0&&e.rShiftTo(o,e),(o=n.getLowestSetBit())>0&&n.rShiftTo(o,n),e.compareTo(n)>=0?(e.subTo(n,e),e.rShiftTo(1,e)):(n.subTo(e,n),n.rShiftTo(1,n));return i>0&&n.lShiftTo(i,n),n}isProbablePrime(t){var e,n=this.abs();if(1==n.t&&n[0]<=p[p.length-1]){for(e=0;e<p.length;++e)if(n[0]==p[e])return!0;return!1}if(n.isEven())return!1;for(e=1;e<p.length;){for(var r=p[e],o=e+1;o<p.length&&r<v;)r*=p[o++];for(r=n.modInt(r);e<o;)if(r%p[e++]==0)return!1}return n.millerRabin(t)}copyTo(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}fromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}fromString(t,e){var n;if(16==e)n=4;else if(8==e)n=3;else if(256==e)n=8;else if(2==e)n=1;else if(32==e)n=5;else{if(4!=e)return void this.fromRadix(t,e);n=2}this.t=0,this.s=0;for(var r=t.length,o=!1,i=0;--r>=0;){var s=8==n?255&+t[r]:it(t,r);s<0?"-"==t.charAt(r)&&(o=!0):(o=!1,0==i?this[this.t++]=s:i+n>this.DB?(this[this.t-1]|=(s&(1<<this.DB-i)-1)<<i,this[this.t++]=s>>this.DB-i):this[this.t-1]|=s<<i,(i+=n)>=this.DB&&(i-=this.DB))}8==n&&128&+t[0]&&(this.s=-1,i>0&&(this[this.t-1]|=(1<<this.DB-i)-1<<i)),this.clamp(),o&&Z.ZERO.subTo(this,this)}clamp(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}dlShiftTo(t,e){var n;for(n=this.t-1;n>=0;--n)e[n+t]=this[n];for(n=t-1;n>=0;--n)e[n]=0;e.t=this.t+t,e.s=this.s}drShiftTo(t,e){for(var n=t;n<this.t;++n)e[n-t]=this[n];e.t=Math.max(this.t-t,0),e.s=this.s}lShiftTo(t,e){for(var n=t%this.DB,r=this.DB-n,o=(1<<r)-1,i=Math.floor(t/this.DB),s=this.s<<n&this.DM,a=this.t-1;a>=0;--a)e[a+i+1]=this[a]>>r|s,s=(this[a]&o)<<n;for(a=i-1;a>=0;--a)e[a]=0;e[i]=s,e.t=this.t+i+1,e.s=this.s,e.clamp()}rShiftTo(t,e){e.s=this.s;var n=Math.floor(t/this.DB);if(n>=this.t)e.t=0;else{var r=t%this.DB,o=this.DB-r,i=(1<<r)-1;e[0]=this[n]>>r;for(var s=n+1;s<this.t;++s)e[s-n-1]|=(this[s]&i)<<o,e[s-n]=this[s]>>r;r>0&&(e[this.t-n-1]|=(this.s&i)<<o),e.t=this.t-n,e.clamp()}}subTo(t,e){for(var n=0,r=0,o=Math.min(t.t,this.t);n<o;)r+=this[n]-t[n],e[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r-=t.s;n<this.t;)r+=this[n],e[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r-=t[n],e[n++]=r&this.DM,r>>=this.DB;r-=t.s}e.s=r<0?-1:0,r<-1?e[n++]=this.DV+r:r>0&&(e[n++]=r),e.t=n,e.clamp()}multiplyTo(t,e){var n=this.abs(),r=t.abs(),o=n.t;for(e.t=o+r.t;--o>=0;)e[o]=0;for(o=0;o<r.t;++o)e[o+n.t]=n.am(0,r[o],e,o,0,n.t);e.s=0,e.clamp(),this.s!=t.s&&Z.ZERO.subTo(e,e)}squareTo(t){for(var e=this.abs(),n=t.t=2*e.t;--n>=0;)t[n]=0;for(n=0;n<e.t-1;++n){var r=e.am(n,e[n],t,2*n,0,1);(t[n+e.t]+=e.am(n+1,2*e[n],t,2*n+1,r,e.t-n-1))>=e.DV&&(t[n+e.t]-=e.DV,t[n+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(n,e[n],t,2*n,0,1)),t.s=0,t.clamp()}divRemTo(t,e,n){var r=t.abs();if(!(r.t<=0)){var o=this.abs();if(o.t<r.t)return null!=e&&e.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=tt());var i=tt(),s=this.s,a=t.s,c=this.DB-at(r[r.t-1]);c>0?(r.lShiftTo(c,i),o.lShiftTo(c,n)):(r.copyTo(i),o.copyTo(n));var u=i.t,l=i[u-1];if(0!=l){var h=l*(1<<this.F1)+(u>1?i[u-2]>>this.F2:0),d=this.FV/h,f=(1<<this.F1)/h,p=1<<this.F2,v=n.t,y=v-u,g=e??tt();for(i.dlShiftTo(y,g),n.compareTo(g)>=0&&(n[n.t++]=1,n.subTo(g,n)),Z.ONE.dlShiftTo(u,g),g.subTo(i,i);i.t<u;)i[i.t++]=0;for(;--y>=0;){var m=n[--v]==l?this.DM:Math.floor(n[v]*d+(n[v-1]+p)*f);if((n[v]+=i.am(0,m,n,y,0,u))<m)for(i.dlShiftTo(y,g),n.subTo(g,n);n[v]<--m;)n.subTo(g,n)}null!=e&&(n.drShiftTo(u,e),s!=a&&Z.ZERO.subTo(e,e)),n.t=u,n.clamp(),c>0&&n.rShiftTo(c,n),s<0&&Z.ZERO.subTo(n,n)}}}invDigit(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e}isEven(){return 0==(this.t>0?1&this[0]:this.s)}exp(t,e){if(t>4294967295||t<1)return Z.ONE;var n=tt(),r=tt(),o=e.convert(this),i=at(t)-1;for(o.copyTo(n);--i>=0;)if(e.sqrTo(n,r),(t&1<<i)>0)e.mulTo(r,o,n);else{var s=n;n=r,r=s}return e.revert(n)}chunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}toRadix(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),n=Math.pow(t,e),r=st(n),o=tt(),i=tt(),s="";for(this.divRemTo(r,o,i);o.signum()>0;)s=(n+i.intValue()).toString(t).substr(1)+s,o.divRemTo(r,o,i);return i.intValue().toString(t)+s}fromRadix(t,e){this.fromInt(0),null==e&&(e=10);for(var n=this.chunkSize(e),r=Math.pow(e,n),o=!1,i=0,s=0,a=0;a<t.length;++a){var c=it(t,a);c<0?"-"==t.charAt(a)&&0==this.signum()&&(o=!0):(s=e*s+c,++i>=n&&(this.dMultiply(r),this.dAddOffset(s,0),i=0,s=0))}i>0&&(this.dMultiply(Math.pow(e,i)),this.dAddOffset(s,0)),o&&Z.ZERO.subTo(this,this)}fromNumber(t,e,n){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,n),this.testBit(t-1)||this.bitwiseTo(Z.ONE.shiftLeft(t-1),W,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(Z.ONE.shiftLeft(t-1),this);else{var r=[],o=7&t;r.length=1+(t>>3),e.nextBytes(r),o>0?r[0]&=(1<<o)-1:r[0]=0,this.fromString(r,256)}}bitwiseTo(t,e,n){var r,o,i=Math.min(t.t,this.t);for(r=0;r<i;++r)n[r]=e(this[r],t[r]);if(t.t<this.t){for(o=t.s&this.DM,r=i;r<this.t;++r)n[r]=e(this[r],o);n.t=this.t}else{for(o=this.s&this.DM,r=i;r<t.t;++r)n[r]=e(o,t[r]);n.t=t.t}n.s=e(this.s,t.s),n.clamp()}changeBit(t,e){var n=Z.ONE.shiftLeft(t);return this.bitwiseTo(n,e,n),n}addTo(t,e){for(var n=0,r=0,o=Math.min(t.t,this.t);n<o;)r+=this[n]+t[n],e[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r+=t.s;n<this.t;)r+=this[n],e[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r+=t[n],e[n++]=r&this.DM,r>>=this.DB;r+=t.s}e.s=r<0?-1:0,r>0?e[n++]=r:r<-1&&(e[n++]=this.DV+r),e.t=n,e.clamp()}dMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}dAddOffset(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}}multiplyLowerTo(t,e,n){var r=Math.min(this.t+t.t,e);for(n.s=0,n.t=r;r>0;)n[--r]=0;for(var o=n.t-this.t;r<o;++r)n[r+this.t]=this.am(0,t[r],n,r,0,this.t);for(o=Math.min(t.t,e);r<o;++r)this.am(0,t[r],n,r,0,e-r);n.clamp()}multiplyUpperTo(t,e,n){--e;var r=n.t=this.t+t.t-e;for(n.s=0;--r>=0;)n[r]=0;for(r=Math.max(e-this.t,0);r<t.t;++r)n[this.t+r-e]=this.am(e-r,t[r],n,0,0,this.t+r-e);n.clamp(),n.drShiftTo(1,n)}modInt(t){if(t<=0)return 0;var e=this.DV%t,n=this.s<0?t-1:0;if(this.t>0)if(0==e)n=this[0]%t;else for(var r=this.t-1;r>=0;--r)n=(e*n+this[r])%t;return n}millerRabin(t){var e=this.subtract(Z.ONE),n=e.getLowestSetBit();if(n<=0)return!1;var r=e.shiftRight(n);(t=t+1>>1)>p.length&&(t=p.length);for(var o=tt(),i=0;i<t;++i){o.fromInt(p[Math.floor(Math.random()*p.length)]);var s=o.modPow(r,this);if(0!=s.compareTo(Z.ONE)&&0!=s.compareTo(e)){for(var a=1;a++<n&&0!=s.compareTo(e);)if(0==(s=s.modPowInt(2,this)).compareTo(Z.ONE))return!1;if(0!=s.compareTo(e))return!1}}return!0}square(){var t=tt();return this.squareTo(t),t}gcda(t,e){var n=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(n.compareTo(r)<0){var o=n;n=r,r=o}var i=n.getLowestSetBit(),s=r.getLowestSetBit();if(s<0)e(n);else{i<s&&(s=i),s>0&&(n.rShiftTo(s,n),r.rShiftTo(s,r));var a=()=>{(i=n.getLowestSetBit())>0&&n.rShiftTo(i,n),(i=r.getLowestSetBit())>0&&r.rShiftTo(i,r),n.compareTo(r)>=0?(n.subTo(r,n),n.rShiftTo(1,n)):(r.subTo(n,r),r.rShiftTo(1,r)),n.signum()>0?setTimeout(a,0):(s>0&&r.lShiftTo(s,r),setTimeout(function(){e(r)},0))};setTimeout(a,10)}}fromNumberAsync(t,e,n,r){if("number"==typeof e)if(t<2)this.fromInt(1);else{this.fromNumber(t,n),this.testBit(t-1)||this.bitwiseTo(Z.ONE.shiftLeft(t-1),W,this),this.isEven()&&this.dAddOffset(1,0);var o=this,i=function(){o.dAddOffset(2,0),o.bitLength()>t&&o.subTo(Z.ONE.shiftLeft(t-1),o),o.isProbablePrime(e)?setTimeout(function(){r()},0):setTimeout(i,0)};setTimeout(i,0)}else{var s=[],a=7&t;s.length=1+(t>>3),e.nextBytes(s),a>0?s[0]&=(1<<a)-1:s[0]=0,this.fromString(s,256)}}}var y=function(){function t(){}return t.prototype.convert=function(t){return t},t.prototype.revert=function(t){return t},t.prototype.mulTo=function(t,e,n){t.multiplyTo(e,n)},t.prototype.sqrTo=function(t,e){t.squareTo(e)},t}(),g=function(){function t(t){this.m=t}return t.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},t.prototype.mulTo=function(t,e,n){t.multiplyTo(e,n),this.reduce(n)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}(),m=function(){function t(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}return t.prototype.convert=function(t){var e=tt();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(Z.ZERO)>0&&this.m.subTo(e,e),e},t.prototype.revert=function(t){var e=tt();return t.copyTo(e),this.reduce(e),e},t.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var n=32767&t[e],r=n*this.mpl+((n*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[n=e+this.m.t]+=this.m.am(0,r,t,e,0,this.m.t);t[n]>=t.DV;)t[n]-=t.DV,t[++n]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},t.prototype.mulTo=function(t,e,n){t.multiplyTo(e,n),this.reduce(n)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}(),b=function(){function t(t){this.m=t,this.r2=tt(),this.q3=tt(),Z.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t)}return t.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=tt();return t.copyTo(e),this.reduce(e),e},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},t.prototype.mulTo=function(t,e,n){t.multiplyTo(e,n),this.reduce(n)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}();function tt(){return new Z(null)}function et(t,e){return new Z(t,e)}function nt(t,e,n,r,o,i){for(;--i>=0;){var s=e*this[t++]+n[r]+o;o=Math.floor(s/67108864),n[r++]=67108863&s}return o}function rt(t,e,n,r,o,i){for(var s=32767&e,a=e>>15;--i>=0;){var c=32767&this[t],u=this[t++]>>15,l=a*c+u*s;o=((c=s*c+((32767&l)<<15)+n[r]+(1073741823&o))>>>30)+(l>>>15)+a*u+(o>>>30),n[r++]=1073741823&c}return o}function ot(t,e,n,r,o,i){for(var s=16383&e,a=e>>14;--i>=0;){var c=16383&this[t],u=this[t++]>>14,l=a*c+u*s;o=((c=s*c+((16383&l)<<14)+n[r]+o)>>28)+(l>>14)+a*u,n[r++]=268435455&c}return o}void 0!==o&&"Microsoft Internet Explorer"==(null==o?void 0:o.appName)?(Z.prototype.am=rt,h=30):"Netscape"!=(null==o?void 0:o.appName)?(Z.prototype.am=nt,h=26):(Z.prototype.am=ot,h=28),Z.prototype.DB=h,Z.prototype.DM=(1<<h)-1,Z.prototype.DV=1<<h,Z.prototype.FV=Math.pow(2,52),Z.prototype.F1=52-h,Z.prototype.F2=2*h-52;var w,_,E=[];for(w="0".charCodeAt(0),_=0;_<=9;++_)E[w++]=_;for(w="a".charCodeAt(0),_=10;_<36;++_)E[w++]=_;for(w="A".charCodeAt(0),_=10;_<36;++_)E[w++]=_;function it(t,e){return E[t.charCodeAt(e)]??-1}function st(t){var e=tt();return e.fromInt(t),e}function at(t){var e,n=1;return 0!=(e=t>>>16)&&(t=e,n+=16),0!=(e=t>>8)&&(t=e,n+=8),0!=(e=t>>4)&&(t=e,n+=4),0!=(e=t>>2)&&(t=e,n+=2),0!=(e=t>>1)&&(t=e,n+=1),n}Z.ZERO=st(0),Z.ONE=st(1);class ct{constructor(){this.i=0,this.j=0,this.S=[]}init(t){var e,n,r;for(e=0;e<256;++e)this.S[e]=e;for(n=0,e=0;e<256;++e)n=n+this.S[e]+t[e%t.length]&255,r=this.S[e],this.S[e]=this.S[n],this.S[n]=r;this.i=0,this.j=0}next(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]}}var I,S,O=null;if(null==O){O=[],S=0;var T,A,P=void 0;if("undefined"!=typeof window&&null!==(T=window)&&void 0!==T&&T.crypto&&null!==(A=window)&&void 0!==A&&A.crypto.getRandomValues){var R,C=new Uint32Array(256);for(null===(R=window)||void 0===R||R.crypto.getRandomValues(C),P=0;P<C.length;++P)O[S++]=255&C[P]}var k,N,x,U=function(t){var e,n,r;if(this.count=this.count||0,this.count>=256||S>=256){if("undefined"!=typeof window)if(null!==(e=window)&&void 0!==e&&e.removeEventListener)null===(r=window)||void 0===r||r.removeEventListener("mousemove",U,!1);else if(null!==(n=window)&&void 0!==n&&n.detachEvent){var o;null===(o=window)||void 0===o||o.detachEvent("onmousemove",U)}}else try{var i=t.x+t.y;O[S++]=255&i,this.count+=1}catch(t){}};if("undefined"!=typeof window)if(null!==(k=window)&&void 0!==k&&k.addEventListener)null===(x=window)||void 0===x||x.addEventListener("mousemove",U,!1);else if(null!==(N=window)&&void 0!==N&&N.attachEvent){var L;null===(L=window)||void 0===L||L.attachEvent("onmousemove",U)}}function ut(){if(null==I){for(I=new ct;S<256;){var t=Math.floor(65536*Math.random());O[S++]=255&t}for(I.init(O),S=0;S<O.length;++S)O[S]=0;S=0}return I.next()}class lt{constructor(){}nextBytes(t){for(var e=0;e<t.length;++e)t[e]=ut()}}function ht(t,e){if(e<t.length+11)return console.error("Message too long for RSA"),null;for(var n=[],r=t.length-1;r>=0&&e>0;){var o=t.charCodeAt(r--);o<128?n[--e]=o:o>127&&o<2048?(n[--e]=63&o|128,n[--e]=o>>6|192):(n[--e]=63&o|128,n[--e]=o>>6&63|128,n[--e]=o>>12|224)}n[--e]=0;for(var i=new lt,s=[];e>2;){for(s[0]=0;0==s[0];)i.nextBytes(s);n[--e]=s[0]}return n[--e]=2,n[--e]=0,new Z(n)}class dt{constructor(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}doPublic(t){return t.modPowInt(this.e,this.n)}doPrivate(t){if(null==this.p||null==this.q)return t.modPow(this.d,this.n);for(var e=t.mod(this.p).modPow(this.dmp1,this.p),n=t.mod(this.q).modPow(this.dmq1,this.q);e.compareTo(n)<0;)e=e.add(this.p);return e.subtract(n).multiply(this.coeff).mod(this.p).multiply(this.q).add(n)}setPublic(t,e){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=et(t,16),this.e=parseInt(e,16)):console.error("Invalid RSA public key")}encrypt(t){var e=ht(t,this.n.bitLength()+7>>3);if(null==e)return null;var n=this.doPublic(e);if(null==n)return null;var r=n.toString(16);return 1&r.length?"0"+r:r}encryptLong(t){var e=this,n=(this.n.bitLength()+7>>3)-11;try{var r="";return t.length>n?(t.match(/.{1,117}/g).forEach(function(t){var n=e.encrypt(t);r+=n}),K(r)):K(this.encrypt(t))}catch(t){return!1}}decryptLong(t){var e=this,n=this.n.bitLength()+7>>3;t=J(t);try{if(t.length>n){var r="";return t.match(/.{1,256}/g).forEach(function(t){var n=e.decrypt(t);r+=n}),r}return this.decrypt(t)}catch(t){return!1}}setPrivate(t,e,n){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=et(t,16),this.e=parseInt(e,16),this.d=et(n,16)):console.error("Invalid RSA private key")}setPrivateEx(t,e,n,r,o,i,s,a){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=et(t,16),this.e=parseInt(e,16),this.d=et(n,16),this.p=et(r,16),this.q=et(o,16),this.dmp1=et(i,16),this.dmq1=et(s,16),this.coeff=et(a,16)):console.error("Invalid RSA private key")}generate(t,e){var n=new lt,r=t>>1;this.e=parseInt(e,16);for(var o=new Z(e,16);;){for(;this.p=new Z(t-r,1,n),0!=this.p.subtract(Z.ONE).gcd(o).compareTo(Z.ONE)||!this.p.isProbablePrime(10););for(;this.q=new Z(r,1,n),0!=this.q.subtract(Z.ONE).gcd(o).compareTo(Z.ONE)||!this.q.isProbablePrime(10););if(this.p.compareTo(this.q)<=0){var i=this.p;this.p=this.q,this.q=i}var s=this.p.subtract(Z.ONE),a=this.q.subtract(Z.ONE),c=s.multiply(a);if(0==c.gcd(o).compareTo(Z.ONE)){this.n=this.p.multiply(this.q),this.d=o.modInverse(c),this.dmp1=this.d.mod(s),this.dmq1=this.d.mod(a),this.coeff=this.q.modInverse(this.p);break}}}decrypt(t){var e=et(t,16),n=this.doPrivate(e);return null==n?null:ft(n,this.n.bitLength()+7>>3)}generateAsync(t,e,n){var r=new lt,o=t>>1;this.e=parseInt(e,16);var i=new Z(e,16),s=this,a=()=>{var e=()=>{if(s.p.compareTo(s.q)<=0){var t=s.p;s.p=s.q,s.q=t}var e=s.p.subtract(Z.ONE),r=s.q.subtract(Z.ONE),o=e.multiply(r);0==o.gcd(i).compareTo(Z.ONE)?(s.n=s.p.multiply(s.q),s.d=i.modInverse(o),s.dmp1=s.d.mod(e),s.dmq1=s.d.mod(r),s.coeff=s.q.modInverse(s.p),setTimeout(function(){n()},0)):setTimeout(a,0)},c=()=>{s.q=tt(),s.q.fromNumberAsync(o,1,r,function(){s.q.subtract(Z.ONE).gcda(i,function(t){0==t.compareTo(Z.ONE)&&s.q.isProbablePrime(10)?setTimeout(e,0):setTimeout(c,0)})})},u=()=>{s.p=tt(),s.p.fromNumberAsync(t-o,1,r,function(){s.p.subtract(Z.ONE).gcda(i,function(t){0==t.compareTo(Z.ONE)&&s.p.isProbablePrime(10)?setTimeout(c,0):setTimeout(u,0)})})};setTimeout(u,0)};setTimeout(a,0)}}function ft(t,e){for(var n=t.toByteArray(),r=0;r<n.length&&0==n[r];)++r;if(n.length-r!=e-1||2!=n[r])return null;for(++r;0!=n[r];)if(++r>=n.length)return null;for(var o="";++r<n.length;){var i=255&n[r];i<128?o+=String.fromCharCode(i):i>191&&i<224?(o+=String.fromCharCode((31&i)<<6|63&n[r+1]),++r):(o+=String.fromCharCode((15&i)<<12|(63&n[r+1])<<6|63&n[r+2]),r+=2)}return o}class pt extends dt{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";super(),t&&("string"==typeof t?this.parseKey(t):(this.hasPrivateKeyProperty(t)||this.hasPublicKeyProperty(t))&&this.parsePropertiesFrom(t))}parseKey(t){try{var e=0,n=0,r=/^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/.test(t)?c.decode(t):u.unarmor(t),o=Q.decode(r);if(3===o.sub.length&&(o=o.sub[2].sub[0]),9===o.sub.length){e=o.sub[1].getHexStringValue(),this.n=et(e,16),n=o.sub[2].getHexStringValue(),this.e=parseInt(n,16);var i=o.sub[3].getHexStringValue();this.d=et(i,16);var s=o.sub[4].getHexStringValue();this.p=et(s,16);var a=o.sub[5].getHexStringValue();this.q=et(a,16);var l=o.sub[6].getHexStringValue();this.dmp1=et(l,16);var h=o.sub[7].getHexStringValue();this.dmq1=et(h,16);var d=o.sub[8].getHexStringValue();this.coeff=et(d,16)}else{if(2!==o.sub.length)return!1;var f=o.sub[1].sub[0];e=f.sub[0].getHexStringValue(),this.n=et(e,16),n=f.sub[1].getHexStringValue(),this.e=parseInt(n,16)}return!0}catch(t){return!1}}hasPublicKeyProperty(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")}hasPrivateKeyProperty(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")&&t.hasOwnProperty("d")&&t.hasOwnProperty("p")&&t.hasOwnProperty("q")&&t.hasOwnProperty("dmp1")&&t.hasOwnProperty("dmq1")&&t.hasOwnProperty("coeff")}parsePropertiesFrom(t){this.n=t.n,this.e=t.e,t.hasOwnProperty("d")&&(this.d=t.d,this.p=t.p,this.q=t.q,this.dmp1=t.dmp1,this.dmq1=t.dmq1,this.coeff=t.coeff)}}(r=function(t){t=t||{},this.default_key_size=parseInt(t.default_key_size,10)||1024,this.default_public_exponent=t.default_public_exponent||"010001",this.log=t.log||!1,this.key=null}).prototype.setKey=function(t){this.log&&this.key&&console.warn("A key was already set, overriding existing."),this.key=new pt(t)},r.prototype.setPrivateKey=function(t){this.setKey(t)},r.prototype.setPublicKey=function(t){this.setKey(t)},r.prototype.decrypt=function(t){try{return this.getKey().decrypt(J(t))}catch(t){return!1}},r.prototype.encrypt=function(t){try{return K(this.getKey().encrypt(t))}catch(t){return!1}},r.prototype.encryptLong=function(t){try{for(var e=this.getKey().encryptLong(t)||"",n=this.getKey().decryptLong(e)||"",r=0,o=/null$/g;o.test(n)&&(r++,e=this.getKey().encryptLong(t)||"",n=this.getKey().decryptLong(e)||"",!(r>10)););return e}catch(t){return!1}},r.prototype.getKey=function(t){if(!this.key){if(this.key=new pt,t&&"[object Function]"==={}.toString.call(t))return void this.key.generateAsync(this.default_key_size,this.default_public_exponent,t);this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},r.version="3.1.4"}const D=r;var j=n(2631),q=function(t){var e=void 0===t?{}:t,n=e.publicKey,r=void 0===n?"":n,o=e.payload,i=void 0===o?{}:o;if(!r)return"";try{var s=(0,j.I)(i),a=new D;return a.setPublicKey(r),a.encryptLong("object"==typeof s?JSON.stringify(s):s)}catch(t){console.error("encrypt error:",t)}return""}},2631:(t,e,n)=>{n.d(e,{I:()=>r,y:()=>o});var r=function(t){var e=function(e){for(var n in t)t.hasOwnProperty(n)&&(e[n]=r(t[n]));return e},n=null==t?"NullOrUndefined":Object.prototype.toString.call(t).slice(8,-1);if(["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(n))return t.slice();switch(n){case"Object":return e(Object.create(Object.getPrototypeOf(t)));case"Array":return e([]);case"Date":return new Date(t.valueOf());case"RegExp":return new RegExp(t.source,(t.global?"g":"")+(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.sticky?"y":"")+(t.unicode?"u":""));default:return t}},o=function(t){var e=t.match(/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/);return e&&e[2]||""}},3388:t=>{t.exports={}},8182:function(t,e,n){var r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)},o=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&o(e,t,n);return i(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.useDefaultAdapter=e.useAdapters=e.RUNTIME=void 0;var a,c=s(n(4274)),u=n(3616);!function(t){t.WEB="web",t.WX_MP="wx_mp"}(a=e.RUNTIME||(e.RUNTIME={})),e.useAdapters=function(t,e){for(var n=0,o=(0,u.isArray)(t)?t:[t];n<o.length;n++){var i=o[n],s=i.isMatch,a=i.genAdapter,c=i.runtime;if(s())return{adapter:r({isMatch:s},a(e)),runtime:c}}},e.useDefaultAdapter=function(){return{adapter:r({},c.genAdapter()),runtime:a.WEB}}},4274:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},a=this&&this.__generator||function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.WebRequest=e.genAdapter=void 0;var c=n(7149),u=n(3616),l=n(2946);function h(t){try{return JSON.parse(t)}catch(e){return t}}var d=function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}return o(e,t),e.prototype.get=function(t){return this.request(i(i({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(i(i({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(i(i({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t,n=e.data,r=e.file,o=e.fileContent,s=e.name,a=e.method,c=e.headers,u=void 0===c?{}:c,l=null!=r?r:o,h={post:"post",put:"put"}[null==a?void 0:a.toLowerCase()]||"put",d=new FormData;return"post"===h?(Object.keys(n).forEach(function(t){d.append(t,n[t])}),d.append("key",s),d.append("file",l instanceof Blob?l:new Blob([l])),this.request(i(i({},t),{data:d,method:h}),this.restrictedMethods.includes("upload"))):this.request(i(i({},t),{method:"put",headers:u,body:l}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return s(this,void 0,void 0,function(){var e,n,r,o;return a(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this.get(i(i({},t),{headers:{},responseType:"blob"}))];case 1:return e=s.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return s.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return s(this,void 0,void 0,function(){var n,r,o,c,u,l,d,f,p,v,y,g,m,b,w,_=this;return a(this,function(E){switch(E.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,c=void 0!==o&&o,u=t.stream,l=void 0!==u&&u,d=t.signal,f=t.timeout,p=t.shouldThrowOnError,v=void 0===p||p,y=null!=f?f:this.timeout,d&&(d.aborted&&n.abort(),d.addEventListener("abort",function(){return n.abort()})),g=null,c&&y&&(g=setTimeout(function(){console.warn(_.timeoutMsg),n.abort(new Error(_.timeoutMsg))},y)),[4,fetch(r,i(i({},t),{signal:n.signal})).then(function(t){return s(_,void 0,void 0,function(){var e,n,r;return a(this,function(o){switch(o.label){case 0:return clearTimeout(g),v?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(g),Promise.reject(t)})];case 1:return m=E.sent(),l?(b=m.body,[3,5]):[3,2];case 2:return(null===(e=m.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?(w=h,[4,m.text()]):[3,4];case 3:return b=w.apply(void 0,[E.sent()]),[3,5];case 4:b=m.text(),E.label=5;case 5:return[2,{data:b,statusCode:m.status,header:m.headers,response:m}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var i=t.url,s=t.headers,a=void 0===s?{}:s,c=t.data,h=t.responseType,d=t.withCredentials,f=t.body,p=t.onUploadProgress,v=(0,u.formatUrl)((0,l.getProtocol)(),i,"get"===r?c:{}),y=new XMLHttpRequest;y.open(r,v),h&&(y.responseType=h);var g,m,b=t.signal;b&&(b.aborted?y.abort():b.addEventListener("abort",function(){return y.abort()},{once:!0})),Object.keys(a).forEach(function(t){y.setRequestHeader(t,a[t])}),p&&y.upload.addEventListener("progress",p),y.onreadystatechange=function(){var t={};if(4===y.readyState){var e=y.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=y.status;try{t.data="blob"===h?y.response:JSON.parse(y.responseText)}catch(e){t.data="blob"===h?y.response:y.responseText}clearTimeout(g),o(t)}},e&&n.timeout&&(g=setTimeout(function(){console.warn(n.timeoutMsg),y.abort()},n.timeout)),m=(0,u.isFormData)(c)?c:"application/x-www-form-urlencoded"===a["content-type"]?(0,u.toQueryString)(c):f||(c?JSON.stringify(c):void 0),d&&(y.withCredentials=!0),y.send(m)})},e}(c.AbstractSDKRequest);e.WebRequest=d,e.genAdapter=function(){return{type:"default",root:window,reqClass:d,wsClass:WebSocket,localStorage}}},2946:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.COMMUNITY_SITE_URL=e.IS_DEBUG_MODE=e.getProtocol=e.setProtocol=e.getSdkName=e.setSdkName=void 0;var n="@cloudbase/js-sdk";e.setSdkName=function(t){n=t},e.getSdkName=function(){return n};var r="https:";e.setProtocol=function(t){r=t},e.getProtocol=function(){return r},e.IS_DEBUG_MODE=!1,e.COMMUNITY_SITE_URL="https://support.qq.com/products/148793"},6205:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ERRORS=void 0,e.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}},794:function(t,e,n){var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.OATUH_LOGINTYPE=void 0,o(n(2946),e),o(n(6205),e),e.OATUH_LOGINTYPE="constants"},7718:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},o=this&&this.__generator||function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.catchErrorsDecorator=void 0;var i=n(3616),s=n(794),a=!1;"undefined"!=typeof navigator&&navigator.userAgent&&(a=-1!==navigator.userAgent.indexOf("Firefox"));var c=a?/(\.js\/)?__decorate(\$\d+)?<@.*\d$/:/(\/\w+\.js\.)?__decorate(\$\d+)?\s*\(.*\)$/,u=/https?:\/\/.+:\d*\/.*\.js:\d+:\d+/;function l(t){var e=t.err,n=t.className,r=t.methodName,o=t.sourceLink;if(!o)return null;var i,s=e.stack.split("\n"),c=a?/^catchErrorsDecorator\/<\/descriptor.value@.*\d$/:new RegExp("".concat(n,"\\.descriptor.value\\s*\\[as\\s").concat(r,"\\]\\s*\\(.*\\)$")),l=a?/^catchErrorsDecorator\/<\/descriptor.value/:new RegExp("".concat(n,"\\.descriptor.value\\s*\\[as\\s").concat(r,"\\]")),h=s.findIndex(function(t){return c.test(t)});if(-1!==h){var d=s.filter(function(t,e){return e>h});d.unshift(s[h].replace(l,"".concat(n,".").concat(r)).replace(u,o)),(i=new Error).stack="".concat(a?"@debugger":"Error","\n").concat(d.join("\n"))}return i}e.catchErrorsDecorator=function(t){var e=t.mode,n=void 0===e?"async":e,a=t.customInfo,h=void 0===a?{}:a,d=t.title,f=t.messages,p=void 0===f?[]:f;return function(t,e,a){if(s.IS_DEBUG_MODE){var f=h.className||t.constructor.name,v=h.methodName||e,y=a.value,g=function(){var t="",e=(new Error).stack.split("\n"),n=e.findIndex(function(t){return c.test(t)});if(-1!==n){var r=u.exec(e[n+1]||"");t=r?r[0]:""}return t}();a.value="sync"===n?function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=l({err:new Error,className:f,methodName:v,sourceLink:g});try{return y.apply(this,t)}catch(t){var r=t,o=t.message,s=t.error,a=t.error_description,c={title:d||"".concat(f,".").concat(v," failed"),content:[{type:"error",body:t}]};if(o&&/^\{.*\}$/.test(o)){var u=JSON.parse(o);c.subtitle=o,u.code&&(n?(n.code=u.code,n.msg=u.msg):(t.code=u.code,t.message=u.msg),r=n||t,c.content=p.map(function(t){return{type:"info",body:t}}))}throw s&&a&&(c.subtitle=a,n?(n.code=s,n.msg=a):(t.code=s,t.message=a),r=n||t,c.content=p.map(function(t){return{type:"info",body:t}})),(0,i.printGroupLog)(c),r}}:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return r(this,void 0,void 0,function(){var e,n,r,s,a,c,u,h;return o(this,function(o){switch(o.label){case 0:e=l({err:new Error,className:f,methodName:v,sourceLink:g}),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,y.apply(this,t)];case 2:return[2,o.sent()];case 3:throw n=o.sent(),r=n,s=n.message,a=n.error,c=n.error_description,u={title:d||"".concat(f,".").concat(v," failed"),content:[{type:"error",body:n}]},s&&/^\{.*\}$/.test(s)&&(h=JSON.parse(s),u.subtitle=h,h.code&&(e?(e.code=h.code,e.message=h.msg):(n.code=h.code,n.message=h.msg),r=e||n,u.content=p.map(function(t){return{type:"info",body:t}}))),a&&c&&(u.subtitle=c,e?(e.code=a,e.msg=c):(n.code=a,n.message=c),r=e||n,u.content=p.map(function(t){return{type:"info",body:t}})),(0,i.printGroupLog)(u),r;case 4:return[2]}})})}}}}},141:function(t,e,n){var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),o(n(7718),e)},6197:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},s=this&&this.__generator||function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.CloudbaseCache=void 0;var a=n(7149),c=n(3616),u=n(794),l=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return o(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(a.AbstractStorage),h=function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:((0,c.printWarn)(u.ERRORS.INVALID_PARAMS,"localStorage is not supported on current platform"),new l(e.root));case"none":return new l(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}return Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:u.ERRORS.OPERATION_FAIL,msg:"[".concat((0,u.getSdkName)(),"][").concat(u.ERRORS.OPERATION_FAIL,"]setStore failed"),info:t}))}}else(0,c.printWarn)(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return i(this,void 0,void 0,function(){var r;return s(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}(0,c.printWarn)(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return i(this,void 0,void 0,function(){var r;return s(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):(0,c.printWarn)(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return i(this,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})},t}();e.CloudbaseCache=h},9689:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0}),e.removeEventListener=e.activateEvent=e.addEventListener=e.CloudbaseEventEmitter=e.IErrorEvent=e.CloudbaseEvent=void 0;var s=n(3616),a=function(t,e){this.data=e||null,this.name=t};e.CloudbaseEvent=a;var c=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return o(e,t),e}(a);e.IErrorEvent=c;var u=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if((0,s.isInstanceOf)(t,c))return console.error(t.error),this;var n=(0,s.isString)(t)?new a(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,u=this.listeners[r]?i([],this.listeners[r],!0):[];o<u.length;o++)u[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();e.CloudbaseEventEmitter=u;var l=new u;e.addEventListener=function(t,e){l.on(t,e)},e.activateEvent=function(t,e){void 0===e&&(e={}),l.fire(t,e)},e.removeEventListener=function(t,e){l.off(t,e)}},3616:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},i.apply(this,arguments)},s=this&&this.__rest||function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n};Object.defineProperty(e,"__esModule",{value:!0}),e.parseCaptcha=e.parseQueryString=e.transformPhone=e.sleep=e.printGroupLog=e.errorToResult=e.promoteGatewayError=e.maybeThrow=e.resolveThrow=e.createCloudbaseError=e.CloudbaseError=e.throwError=e.printInfo=e.printError=e.printWarn=e.execCallback=e.createPromiseCallback=e.removeParam=e.getHash=e.getQuery=e.toQueryString=e.formatUrl=e.generateRequestId=e.genSeqId=e.isFormData=e.isInstanceOf=e.isNull=e.isPalinObject=e.isUndefined=e.isString=e.isArray=void 0;var a=n(794);e.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},e.isString=function(t){return"string"==typeof t},e.isUndefined=function(t){return void 0===t},e.isPalinObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)},e.isNull=function(t){return"[object Null]"===Object.prototype.toString.call(t)},e.isInstanceOf=function(t,e){return t instanceof e},e.isFormData=function(t){return"[object FormData]"===Object.prototype.toString.call(t)},e.genSeqId=function(){return Math.random().toString(16).slice(2)},e.generateRequestId=function(){var t=(new Date).getTime(),e=(null===Date||void 0===Date?void 0:Date.now)&&1e3*Date.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){var r=16*Math.random();return t>0?(r=(t+r)%16|0,t=Math.floor(t/16)):(r=(e+r)%16|0,e=Math.floor(e/16)),("x"===n?r:7&r|8).toString(16)})},e.formatUrl=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)},e.toQueryString=function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")},e.getQuery=function(t,e){if("undefined"==typeof window)return!1;var n=e||decodeURIComponent(window.location.search),r=new RegExp("(^|&)".concat(t,"=([^&]*)(&|$)")),o=n.substr(n.indexOf("?")+1).match(r);return null!=o?o[2]:""},e.getHash=function(t){if("undefined"==typeof window)return"";var e=window.location.hash.match(new RegExp("[#?&/]".concat(t,"=([^&#]*)")));return e?e[1]:""},e.removeParam=function(t,e){var n=e.split("?")[0],r=[],o=-1!==e.indexOf("?")?e.split("?")[1]:"";if(""!==o){for(var i=(r=o.split("&")).length-1;i>=0;i-=1)r[i].split("=")[0]===t&&r.splice(i,1);n="".concat(n,"?").concat(r.join("&"))}return n},e.createPromiseCallback=function(){var t={};if(!Promise){(t=function(){}).promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var n=new Promise(function(e,n){t=function(t,r){return t?n(t):e(r)}});return t.promise=n,t},e.execCallback=function(t,e,n){if(void 0===n&&(n=null),t&&"function"==typeof t)return t(e,n);if(e)throw e;return n},e.printWarn=function(t,e){console.warn("[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e))},e.printError=function(t,e){console.error({code:t,msg:"[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e)})},e.printInfo=function(t,e){console.log("[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e))},e.throwError=function(t,e){var n=new Error(JSON.stringify({code:t,msg:"[".concat((0,a.getSdkName)(),"][").concat(t,"]:").concat(e)}));throw n.code=t,n};var c=function(t){function e(e){var n=t.call(this,e.msg||e.message||"")||this;return n.code=e.code||"",n.requestId=e.requestId||"",Object.defineProperty(n,"message",{value:e.msg||e.message||"",enumerable:!0,writable:!0,configurable:!0}),n}return o(e,t),e}(Error);e.CloudbaseError=c;var u=function(t){return new c(t)};function l(t,e){return(e||u)(t)}function h(t){return!t||"boolean"!=typeof t.throw||t.throw}e.createCloudbaseError=l,e.resolveThrow=h,e.maybeThrow=function(t,e){if(h(t))throw l(i(i({},e),{msg:e.message}),null==t?void 0:t.errorFactory);return i({code:e.code,message:e.message},e.requestId?{requestId:e.requestId}:{})},e.promoteGatewayError=function(t){if(t&&"object"==typeof t&&t.data&&"object"==typeof t.data){var e=t.data,n=e.code,r=e.message;if(!t.code&&n||!t.message&&r)return i(i(i({},t),!t.code&&n?{code:n}:{}),!t.message&&r?{message:r}:{})}return t},e.errorToResult=function(t){if(t instanceof Error&&"string"==typeof t.message)try{var e=JSON.parse(t.message);if(e&&"string"==typeof e.code)return{code:e.code,message:e.msg||e.message||"",requestId:e.requestId}}catch(t){}return t&&"string"==typeof t.code?{code:t.code,message:t.message||"",requestId:t.requestId}:{code:"UNKNOWN_ERROR",message:String((null==t?void 0:t.message)||t||"")}},e.printGroupLog=function(t){var e,n=t.title,r=t.subtitle,o=void 0===r?"":r,i=t.content,s=void 0===i?[]:i,a=t.printTrace,c=void 0!==a&&a,u=t.collapsed;void 0!==u&&u?(console.groupCollapsed||console.error)(n,o):(console.group||console.error)(n,o);for(var l=0,h=s;l<h.length;l++){var d=h[l],f=d.type,p=d.body;switch(f){case"info":console.log(p);break;case"warn":console.warn(p);break;case"error":console.error(p)}}c&&(console.trace||console.log)("stack trace:"),null===(e=console.groupEnd)||void 0===e||e.call(console)},e.sleep=function(t){return void 0===t&&(t=0),new Promise(function(e){return setTimeout(e,t)})},e.transformPhone=function(t){return"+86".concat(t)},e.parseQueryString=function(t){t=t.replace(/^\?/,"");var e={};return t.split("&").forEach(function(t){var n=t.split("="),r=n[0],o=n[1];r=decodeURIComponent(r),o=decodeURIComponent(o),r&&(e[r]?Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]:e[r]=o)}),e},e.parseCaptcha=function(t){var n={},r=t.match(/^(data:.*?)(\?[^#\s]*)?$/);if(r){t=r[1];var o=r[2];o&&(n=(0,e.parseQueryString)(o))}var i=n.token,a=s(n,["token"]);return/^data:/.test(t)&&!i?{error:"invalid_argument",error_description:"invalid captcha data: ".concat(t)}:i?{state:a.state,token:i,captchaData:t}:{error:"unimplemented",error_description:"need to impl captcha data"}}},9515:(t,e,n)=>{var r=n(8761)(n(7772),"DataView");t.exports=r},9612:(t,e,n)=>{var r=n(2118),o=n(6909),i=n(8138),s=n(4174),a=n(7942);function c(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}c.prototype.clear=r,c.prototype.delete=o,c.prototype.get=i,c.prototype.has=s,c.prototype.set=a,t.exports=c},235:(t,e,n)=>{var r=n(3945),o=n(1846),i=n(8028),s=n(2344),a=n(4769);function c(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}c.prototype.clear=r,c.prototype.delete=o,c.prototype.get=i,c.prototype.has=s,c.prototype.set=a,t.exports=c},326:(t,e,n)=>{var r=n(8761)(n(7772),"Map");t.exports=r},6738:(t,e,n)=>{var r=n(2411),o=n(6417),i=n(6928),s=n(9493),a=n(4150);function c(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}c.prototype.clear=r,c.prototype.delete=o,c.prototype.get=i,c.prototype.has=s,c.prototype.set=a,t.exports=c},2760:(t,e,n)=>{var r=n(8761)(n(7772),"Promise");t.exports=r},2143:(t,e,n)=>{var r=n(8761)(n(7772),"Set");t.exports=r},6571:(t,e,n)=>{var r=n(235),o=n(5243),i=n(2858),s=n(4417),a=n(8605),c=n(1418);function u(t){var e=this.__data__=new r(t);this.size=e.size}u.prototype.clear=o,u.prototype.delete=i,u.prototype.get=s,u.prototype.has=a,u.prototype.set=c,t.exports=u},857:(t,e,n)=>{var r=n(7772).Symbol;t.exports=r},9162:(t,e,n)=>{var r=n(7772).Uint8Array;t.exports=r},3215:(t,e,n)=>{var r=n(8761)(n(7772),"WeakMap");t.exports=r},2517:t=>{t.exports=function(t,e){for(var n=-1,r=null==t?0:t.length;++n<r&&!1!==e(t[n],n,t););return t}},7552:t=>{t.exports=function(t,e){for(var n=-1,r=null==t?0:t.length,o=0,i=[];++n<r;){var s=t[n];e(s,n,t)&&(i[o++]=s)}return i}},1634:(t,e,n)=>{var r=n(6473),o=n(9631),i=n(6152),s=n(3226),a=n(9045),c=n(7598),u=Object.prototype.hasOwnProperty;t.exports=function(t,e){var n=i(t),l=!n&&o(t),h=!n&&!l&&s(t),d=!n&&!l&&!h&&c(t),f=n||l||h||d,p=f?r(t.length,String):[],v=p.length;for(var y in t)!e&&!u.call(t,y)||f&&("length"==y||h&&("offset"==y||"parent"==y)||d&&("buffer"==y||"byteLength"==y||"byteOffset"==y)||a(y,v))||p.push(y);return p}},343:t=>{t.exports=function(t,e){for(var n=-1,r=null==t?0:t.length,o=Array(r);++n<r;)o[n]=e(t[n],n,t);return o}},5067:t=>{t.exports=function(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}},91:(t,e,n)=>{var r=n(3940),o=n(1225),i=Object.prototype.hasOwnProperty;t.exports=function(t,e,n){var s=t[e];i.call(t,e)&&o(s,n)&&(void 0!==n||e in t)||r(t,e,n)}},2218:(t,e,n)=>{var r=n(1225);t.exports=function(t,e){for(var n=t.length;n--;)if(r(t[n][0],e))return n;return-1}},7993:(t,e,n)=>{var r=n(752),o=n(249);t.exports=function(t,e){return t&&r(e,o(e),t)}},5906:(t,e,n)=>{var r=n(752),o=n(8582);t.exports=function(t,e){return t&&r(e,o(e),t)}},3940:(t,e,n)=>{var r=n(3043);t.exports=function(t,e,n){"__proto__"==e&&r?r(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}},8874:(t,e,n)=>{var r=n(6571),o=n(2517),i=n(91),s=n(7993),a=n(5906),c=n(2175),u=n(1522),l=n(7680),h=n(9987),d=n(3483),f=n(6939),p=n(940),v=n(9917),y=n(8222),g=n(8725),m=n(6152),b=n(3226),w=n(4714),_=n(9259),E=n(3679),I=n(249),S=n(8582),O="[object Arguments]",T="[object Function]",A="[object Object]",P={};P[O]=P["[object Array]"]=P["[object ArrayBuffer]"]=P["[object DataView]"]=P["[object Boolean]"]=P["[object Date]"]=P["[object Float32Array]"]=P["[object Float64Array]"]=P["[object Int8Array]"]=P["[object Int16Array]"]=P["[object Int32Array]"]=P["[object Map]"]=P["[object Number]"]=P[A]=P["[object RegExp]"]=P["[object Set]"]=P["[object String]"]=P["[object Symbol]"]=P["[object Uint8Array]"]=P["[object Uint8ClampedArray]"]=P["[object Uint16Array]"]=P["[object Uint32Array]"]=!0,P["[object Error]"]=P[T]=P["[object WeakMap]"]=!1,t.exports=function t(e,n,R,C,k,N){var x,U=1&n,L=2&n,D=4&n;if(R&&(x=k?R(e,C,k,N):R(e)),void 0!==x)return x;if(!_(e))return e;var j=m(e);if(j){if(x=v(e),!U)return u(e,x)}else{var q=p(e),M=q==T||"[object GeneratorFunction]"==q;if(b(e))return c(e,U);if(q==A||q==O||M&&!k){if(x=L||M?{}:g(e),!U)return L?h(e,a(x,e)):l(e,s(x,e))}else{if(!P[q])return k?e:{};x=y(e,q,U)}}N||(N=new r);var B=N.get(e);if(B)return B;N.set(e,x),E(e)?e.forEach(function(r){x.add(t(r,n,R,r,e,N))}):w(e)&&e.forEach(function(r,o){x.set(o,t(r,n,R,o,e,N))});var W=j?void 0:(D?L?f:d:L?S:I)(e);return o(W||e,function(r,o){W&&(r=e[o=r]),i(x,o,t(r,n,R,o,e,N))}),x}},9413:(t,e,n)=>{var r=n(9259),o=Object.create,i=function(){function t(){}return function(e){if(!r(e))return{};if(o)return o(e);t.prototype=e;var n=new t;return t.prototype=void 0,n}}();t.exports=i},3324:(t,e,n)=>{var r=n(7297),o=n(3812);t.exports=function(t,e){for(var n=0,i=(e=r(e,t)).length;null!=t&&n<i;)t=t[o(e[n++])];return n&&n==i?t:void 0}},1897:(t,e,n)=>{var r=n(5067),o=n(6152);t.exports=function(t,e,n){var i=e(t);return o(t)?i:r(i,n(t))}},3366:(t,e,n)=>{var r=n(857),o=n(2107),i=n(7157),s=r?r.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":s&&s in Object(t)?o(t):i(t)}},5183:(t,e,n)=>{var r=n(3366),o=n(5125);t.exports=function(t){return o(t)&&"[object Arguments]"==r(t)}},4511:(t,e,n)=>{var r=n(940),o=n(5125);t.exports=function(t){return o(t)&&"[object Map]"==r(t)}},6840:(t,e,n)=>{var r=n(1049),o=n(7394),i=n(9259),s=n(7035),a=/^\[object .+?Constructor\]$/,c=Function.prototype,u=Object.prototype,l=c.toString,h=u.hasOwnProperty,d=RegExp("^"+l.call(h).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=function(t){return!(!i(t)||o(t))&&(r(t)?d:a).test(s(t))}},8436:(t,e,n)=>{var r=n(940),o=n(5125);t.exports=function(t){return o(t)&&"[object Set]"==r(t)}},5522:(t,e,n)=>{var r=n(3366),o=n(1158),i=n(5125),s={};s["[object Float32Array]"]=s["[object Float64Array]"]=s["[object Int8Array]"]=s["[object Int16Array]"]=s["[object Int32Array]"]=s["[object Uint8Array]"]=s["[object Uint8ClampedArray]"]=s["[object Uint16Array]"]=s["[object Uint32Array]"]=!0,s["[object Arguments]"]=s["[object Array]"]=s["[object ArrayBuffer]"]=s["[object Boolean]"]=s["[object DataView]"]=s["[object Date]"]=s["[object Error]"]=s["[object Function]"]=s["[object Map]"]=s["[object Number]"]=s["[object Object]"]=s["[object RegExp]"]=s["[object Set]"]=s["[object String]"]=s["[object WeakMap]"]=!1,t.exports=function(t){return i(t)&&o(t.length)&&!!s[r(t)]}},6411:(t,e,n)=>{var r=n(6001),o=n(4248),i=Object.prototype.hasOwnProperty;t.exports=function(t){if(!r(t))return o(t);var e=[];for(var n in Object(t))i.call(t,n)&&"constructor"!=n&&e.push(n);return e}},8390:(t,e,n)=>{var r=n(9259),o=n(6001),i=n(2966),s=Object.prototype.hasOwnProperty;t.exports=function(t){if(!r(t))return i(t);var e=o(t),n=[];for(var a in t)("constructor"!=a||!e&&s.call(t,a))&&n.push(a);return n}},2857:(t,e,n)=>{var r=n(91),o=n(7297),i=n(9045),s=n(9259),a=n(3812);t.exports=function(t,e,n,c){if(!s(t))return t;for(var u=-1,l=(e=o(e,t)).length,h=l-1,d=t;null!=d&&++u<l;){var f=a(e[u]),p=n;if("__proto__"===f||"constructor"===f||"prototype"===f)return t;if(u!=h){var v=d[f];void 0===(p=c?c(v,f,d):void 0)&&(p=s(v)?v:i(e[u+1])?[]:{})}r(d,f,p),d=d[f]}return t}},9872:t=>{t.exports=function(t,e,n){var r=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(n=n>o?o:n)<0&&(n+=o),o=e>n?0:n-e>>>0,e>>>=0;for(var i=Array(o);++r<o;)i[r]=t[r+e];return i}},6473:t=>{t.exports=function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}},1054:(t,e,n)=>{var r=n(857),o=n(343),i=n(6152),s=n(4795),a=r?r.prototype:void 0,c=a?a.toString:void 0;t.exports=function t(e){if("string"==typeof e)return e;if(i(e))return o(e,t)+"";if(s(e))return c?c.call(e):"";var n=e+"";return"0"==n&&1/e==-1/0?"-0":n}},7826:t=>{t.exports=function(t){return function(e){return t(e)}}},9078:(t,e,n)=>{var r=n(7297),o=n(6974),i=n(2721),s=n(3812),a=Object.prototype.hasOwnProperty;t.exports=function(t,e){var n=-1,c=(e=r(e,t)).length;if(!c)return!0;for(;++n<c;){var u=s(e[n]);if("__proto__"===u&&!a.call(t,"__proto__"))return!1;if(("constructor"===u||"prototype"===u)&&n<c-1)return!1}var l=i(t,e);return null==l||delete l[s(o(e))]}},7297:(t,e,n)=>{var r=n(6152),o=n(1401),i=n(4452),s=n(6188);t.exports=function(t,e){return r(t)?t:o(t,e)?[t]:i(s(t))}},9882:(t,e,n)=>{var r=n(9162);t.exports=function(t){var e=new t.constructor(t.byteLength);return new r(e).set(new r(t)),e}},2175:(t,e,n)=>{t=n.nmd(t);var r=n(7772),o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,s=i&&i.exports===o?r.Buffer:void 0,a=s?s.allocUnsafe:void 0;t.exports=function(t,e){if(e)return t.slice();var n=t.length,r=a?a(n):new t.constructor(n);return t.copy(r),r}},4727:(t,e,n)=>{var r=n(9882);t.exports=function(t,e){var n=e?r(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}},6058:t=>{var e=/\w*$/;t.exports=function(t){var n=new t.constructor(t.source,e.exec(t));return n.lastIndex=t.lastIndex,n}},169:(t,e,n)=>{var r=n(857),o=r?r.prototype:void 0,i=o?o.valueOf:void 0;t.exports=function(t){return i?Object(i.call(t)):{}}},6190:(t,e,n)=>{var r=n(9882);t.exports=function(t,e){var n=e?r(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}},1522:t=>{t.exports=function(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}},752:(t,e,n)=>{var r=n(91),o=n(3940);t.exports=function(t,e,n,i){var s=!n;n||(n={});for(var a=-1,c=e.length;++a<c;){var u=e[a],l=i?i(n[u],t[u],u,n,t):void 0;void 0===l&&(l=t[u]),s?o(n,u,l):r(n,u,l)}return n}},7680:(t,e,n)=>{var r=n(752),o=n(633);t.exports=function(t,e){return r(t,o(t),e)}},9987:(t,e,n)=>{var r=n(752),o=n(2680);t.exports=function(t,e){return r(t,o(t),e)}},4019:(t,e,n)=>{var r=n(7772)["__core-js_shared__"];t.exports=r},3043:(t,e,n)=>{var r=n(8761),o=function(){try{var t=r(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();t.exports=o},1242:(t,e,n)=>{var r="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g;t.exports=r},3483:(t,e,n)=>{var r=n(1897),o=n(633),i=n(249);t.exports=function(t){return r(t,i,o)}},6939:(t,e,n)=>{var r=n(1897),o=n(2680),i=n(8582);t.exports=function(t){return r(t,i,o)}},7937:(t,e,n)=>{var r=n(8304);t.exports=function(t,e){var n=t.__data__;return r(e)?n["string"==typeof e?"string":"hash"]:n.map}},8761:(t,e,n)=>{var r=n(6840),o=n(8109);t.exports=function(t,e){var n=o(t,e);return r(n)?n:void 0}},7353:(t,e,n)=>{var r=n(241)(Object.getPrototypeOf,Object);t.exports=r},2107:(t,e,n)=>{var r=n(857),o=Object.prototype,i=o.hasOwnProperty,s=o.toString,a=r?r.toStringTag:void 0;t.exports=function(t){var e=i.call(t,a),n=t[a];try{t[a]=void 0;var r=!0}catch(t){}var o=s.call(t);return r&&(e?t[a]=n:delete t[a]),o}},633:(t,e,n)=>{var r=n(7552),o=n(981),i=Object.prototype.propertyIsEnumerable,s=Object.getOwnPropertySymbols,a=s?function(t){return null==t?[]:(t=Object(t),r(s(t),function(e){return i.call(t,e)}))}:o;t.exports=a},2680:(t,e,n)=>{var r=n(5067),o=n(7353),i=n(633),s=n(981),a=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)r(e,i(t)),t=o(t);return e}:s;t.exports=a},940:(t,e,n)=>{var r=n(9515),o=n(326),i=n(2760),s=n(2143),a=n(3215),c=n(3366),u=n(7035),l="[object Map]",h="[object Promise]",d="[object Set]",f="[object WeakMap]",p="[object DataView]",v=u(r),y=u(o),g=u(i),m=u(s),b=u(a),w=c;(r&&w(new r(new ArrayBuffer(1)))!=p||o&&w(new o)!=l||i&&w(i.resolve())!=h||s&&w(new s)!=d||a&&w(new a)!=f)&&(w=function(t){var e=c(t),n="[object Object]"==e?t.constructor:void 0,r=n?u(n):"";if(r)switch(r){case v:return p;case y:return l;case g:return h;case m:return d;case b:return f}return e}),t.exports=w},8109:t=>{t.exports=function(t,e){return null==t?void 0:t[e]}},2118:(t,e,n)=>{var r=n(9191);t.exports=function(){this.__data__=r?r(null):{},this.size=0}},6909:t=>{t.exports=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}},8138:(t,e,n)=>{var r=n(9191),o=Object.prototype.hasOwnProperty;t.exports=function(t){var e=this.__data__;if(r){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return o.call(e,t)?e[t]:void 0}},4174:(t,e,n)=>{var r=n(9191),o=Object.prototype.hasOwnProperty;t.exports=function(t){var e=this.__data__;return r?void 0!==e[t]:o.call(e,t)}},7942:(t,e,n)=>{var r=n(9191);t.exports=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=r&&void 0===e?"__lodash_hash_undefined__":e,this}},9917:t=>{var e=Object.prototype.hasOwnProperty;t.exports=function(t){var n=t.length,r=new t.constructor(n);return n&&"string"==typeof t[0]&&e.call(t,"index")&&(r.index=t.index,r.input=t.input),r}},8222:(t,e,n)=>{var r=n(9882),o=n(4727),i=n(6058),s=n(169),a=n(6190);t.exports=function(t,e,n){var c=t.constructor;switch(e){case"[object ArrayBuffer]":return r(t);case"[object Boolean]":case"[object Date]":return new c(+t);case"[object DataView]":return o(t,n);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return a(t,n);case"[object Map]":case"[object Set]":return new c;case"[object Number]":case"[object String]":return new c(t);case"[object RegExp]":return i(t);case"[object Symbol]":return s(t)}}},8725:(t,e,n)=>{var r=n(9413),o=n(7353),i=n(6001);t.exports=function(t){return"function"!=typeof t.constructor||i(t)?{}:r(o(t))}},9045:t=>{var e=/^(?:0|[1-9]\d*)$/;t.exports=function(t,n){var r=typeof t;return!!(n=n??9007199254740991)&&("number"==r||"symbol"!=r&&e.test(t))&&t>-1&&t%1==0&&t<n}},1401:(t,e,n)=>{var r=n(6152),o=n(4795),i=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,s=/^\w*$/;t.exports=function(t,e){if(r(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!o(t))||s.test(t)||!i.test(t)||null!=e&&t in Object(e)}},8304:t=>{t.exports=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}},7394:(t,e,n)=>{var r,o=n(4019),i=(r=/[^.]+$/.exec(o&&o.keys&&o.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"";t.exports=function(t){return!!i&&i in t}},6001:t=>{var e=Object.prototype;t.exports=function(t){var n=t&&t.constructor;return t===("function"==typeof n&&n.prototype||e)}},3945:t=>{t.exports=function(){this.__data__=[],this.size=0}},1846:(t,e,n)=>{var r=n(2218),o=Array.prototype.splice;t.exports=function(t){var e=this.__data__,n=r(e,t);return!(n<0||(n==e.length-1?e.pop():o.call(e,n,1),--this.size,0))}},8028:(t,e,n)=>{var r=n(2218);t.exports=function(t){var e=this.__data__,n=r(e,t);return n<0?void 0:e[n][1]}},2344:(t,e,n)=>{var r=n(2218);t.exports=function(t){return r(this.__data__,t)>-1}},4769:(t,e,n)=>{var r=n(2218);t.exports=function(t,e){var n=this.__data__,o=r(n,t);return o<0?(++this.size,n.push([t,e])):n[o][1]=e,this}},2411:(t,e,n)=>{var r=n(9612),o=n(235),i=n(326);t.exports=function(){this.size=0,this.__data__={hash:new r,map:new(i||o),string:new r}}},6417:(t,e,n)=>{var r=n(7937);t.exports=function(t){var e=r(this,t).delete(t);return this.size-=e?1:0,e}},6928:(t,e,n)=>{var r=n(7937);t.exports=function(t){return r(this,t).get(t)}},9493:(t,e,n)=>{var r=n(7937);t.exports=function(t){return r(this,t).has(t)}},4150:(t,e,n)=>{var r=n(7937);t.exports=function(t,e){var n=r(this,t),o=n.size;return n.set(t,e),this.size+=n.size==o?0:1,this}},7777:(t,e,n)=>{var r=n(733);t.exports=function(t){var e=r(t,function(t){return 500===n.size&&n.clear(),t}),n=e.cache;return e}},9191:(t,e,n)=>{var r=n(8761)(Object,"create");t.exports=r},4248:(t,e,n)=>{var r=n(241)(Object.keys,Object);t.exports=r},2966:t=>{t.exports=function(t){var e=[];if(null!=t)for(var n in Object(t))e.push(n);return e}},4146:(t,e,n)=>{t=n.nmd(t);var r=n(1242),o=e&&!e.nodeType&&e,i=o&&t&&!t.nodeType&&t,s=i&&i.exports===o&&r.process,a=function(){try{return i&&i.require&&i.require("util").types||s&&s.binding&&s.binding("util")}catch(t){}}();t.exports=a},7157:t=>{var e=Object.prototype.toString;t.exports=function(t){return e.call(t)}},241:t=>{t.exports=function(t,e){return function(n){return t(e(n))}}},2721:(t,e,n)=>{var r=n(3324),o=n(9872);t.exports=function(t,e){return e.length<2?t:r(t,o(e,0,-1))}},7772:(t,e,n)=>{var r=n(1242),o="object"==typeof self&&self&&self.Object===Object&&self,i=r||o||Function("return this")();t.exports=i},5243:(t,e,n)=>{var r=n(235);t.exports=function(){this.__data__=new r,this.size=0}},2858:t=>{t.exports=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n}},4417:t=>{t.exports=function(t){return this.__data__.get(t)}},8605:t=>{t.exports=function(t){return this.__data__.has(t)}},1418:(t,e,n)=>{var r=n(235),o=n(326),i=n(6738);t.exports=function(t,e){var n=this.__data__;if(n instanceof r){var s=n.__data__;if(!o||s.length<199)return s.push([t,e]),this.size=++n.size,this;n=this.__data__=new i(s)}return n.set(t,e),this.size=n.size,this}},4452:(t,e,n)=>{var r=n(7777),o=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,i=/\\(\\)?/g,s=r(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(o,function(t,n,r,o){e.push(r?o.replace(i,"$1"):n||t)}),e});t.exports=s},3812:(t,e,n)=>{var r=n(4795);t.exports=function(t){if("string"==typeof t||r(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}},7035:t=>{var e=Function.prototype.toString;t.exports=function(t){if(null!=t){try{return e.call(t)}catch(t){}try{return t+""}catch(t){}}return""}},9850:(t,e,n)=>{var r=n(8874);t.exports=function(t){return r(t,5)}},1225:t=>{t.exports=function(t,e){return t===e||t!=t&&e!=e}},9631:(t,e,n)=>{var r=n(5183),o=n(5125),i=Object.prototype,s=i.hasOwnProperty,a=i.propertyIsEnumerable,c=r(function(){return arguments}())?r:function(t){return o(t)&&s.call(t,"callee")&&!a.call(t,"callee")};t.exports=c},6152:t=>{var e=Array.isArray;t.exports=e},7878:(t,e,n)=>{var r=n(1049),o=n(1158);t.exports=function(t){return null!=t&&o(t.length)&&!r(t)}},3226:(t,e,n)=>{t=n.nmd(t);var r=n(7772),o=n(6330),i=e&&!e.nodeType&&e,s=i&&t&&!t.nodeType&&t,a=s&&s.exports===i?r.Buffer:void 0,c=(a?a.isBuffer:void 0)||o;t.exports=c},1049:(t,e,n)=>{var r=n(3366),o=n(9259);t.exports=function(t){if(!o(t))return!1;var e=r(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}},1158:t=>{t.exports=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}},4714:(t,e,n)=>{var r=n(4511),o=n(7826),i=n(4146),s=i&&i.isMap,a=s?o(s):r;t.exports=a},9259:t=>{t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},5125:t=>{t.exports=function(t){return null!=t&&"object"==typeof t}},3679:(t,e,n)=>{var r=n(8436),o=n(7826),i=n(4146),s=i&&i.isSet,a=s?o(s):r;t.exports=a},4795:(t,e,n)=>{var r=n(3366),o=n(5125);t.exports=function(t){return"symbol"==typeof t||o(t)&&"[object Symbol]"==r(t)}},7598:(t,e,n)=>{var r=n(5522),o=n(7826),i=n(4146),s=i&&i.isTypedArray,a=s?o(s):r;t.exports=a},249:(t,e,n)=>{var r=n(1634),o=n(6411),i=n(7878);t.exports=function(t){return i(t)?r(t):o(t)}},8582:(t,e,n)=>{var r=n(1634),o=n(8390),i=n(7878);t.exports=function(t){return i(t)?r(t,!0):o(t)}},6974:t=>{t.exports=function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0}},733:(t,e,n)=>{var r=n(6738);function o(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=t.apply(this,r);return n.cache=i.set(o,s)||i,s};return n.cache=new(o.Cache||r),n}o.Cache=r,t.exports=o},6765:(t,e,n)=>{var r=n(2857);t.exports=function(t,e,n){return null==t?t:r(t,e,n)}},981:t=>{t.exports=function(){return[]}},6330:t=>{t.exports=function(){return!1}},6188:(t,e,n)=>{var r=n(1054);t.exports=function(t){return null==t?"":r(t)}},7195:(t,e,n)=>{var r=n(9078);t.exports=function(t,e){return null==t||r(t,e)}},7149:e=>{e.exports=t}},u={};function l(t){var e=u[t];if(void 0!==e)return e.exports;var n=u[t]={id:t,loaded:!1,exports:{}};return c[t].call(n.exports,n,n.exports,l),n.loaded=!0,n.exports}l.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return l.d(e,{a:e}),e},l.d=(t,e)=>{for(var n in e)l.o(e,n)&&!l.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},l.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),l.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),l.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},l.nmd=t=>(t.paths=[],t.children||(t.children=[]),t);var h={};(()=>{l.d(h,{Z:()=>wd});var t={};l.r(t);var c={};l.r(c),l.d(c,{ArkSimpleModel:()=>Tc,DSSimpleModel:()=>kc,DefaultImageModel:()=>su,DefaultSimpleModel:()=>ru,HunYuanBetaSimpleModel:()=>gc,HunYuanExpSimpleModel:()=>Gc,HunYuanOpenSimpleModel:()=>$c,HunYuanSimpleModel:()=>_c,MODELS:()=>bu,MoonshotSimpleModel:()=>Wc,ReactModel:()=>du,YiSimpleModel:()=>Dc,ZhiPuSimpleModel:()=>lc,toolMap:()=>vu});var u={};l.r(u),l.d(u,{LineString:()=>Nl,MultiLineString:()=>jl,MultiPoint:()=>Ll,MultiPolygon:()=>Ml,Point:()=>uh,Polygon:()=>Ul});var d="@cloudbase/js-sdk";function f(){return d}var p,v="https:",y="https://support.qq.com/products/148793",g={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"},m=l(7149),b=(p=function(t,e){return p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},p(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}p(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),w=function(){return w=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},w.apply(this,arguments)};function _(t){return"[object Array]"===Object.prototype.toString.call(t)}function E(t){return"string"==typeof t}function I(t){return"[object FormData]"===Object.prototype.toString.call(t)}function S(){var t=(new Date).getTime(),e=(null===Date||void 0===Date?void 0:Date.now)&&1e3*Date.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){var r=16*Math.random();return t>0?(r=(t+r)%16|0,t=Math.floor(t/16)):(r=(e+r)%16|0,e=Math.floor(e/16)),("x"===n?r:7&r|8).toString(16)})}function O(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}function T(t,e){if("undefined"==typeof window)return!1;var n=e||decodeURIComponent(window.location.search),r=new RegExp("(^|&)".concat(t,"=([^&]*)(&|$)")),o=n.substr(n.indexOf("?")+1).match(r);return null!=o?o[2]:""}function A(t,e,n){if(void 0===n&&(n=null),t&&"function"==typeof t)return t(e,n);if(e)throw e;return n}function P(t,e){console.warn("[".concat(f(),"][").concat(t,"]:").concat(e))}var R=function(t){function e(e){var n=t.call(this,e.msg||e.message||"")||this;return n.code=e.code||"",n.requestId=e.requestId||"",Object.defineProperty(n,"message",{value:e.msg||e.message||"",enumerable:!0,writable:!0,configurable:!0}),n}return b(e,t),e}(Error),C=function(t){return new R(t)};function k(t,e){return(e||C)(t)}function N(t){return!t||"boolean"!=typeof t.throw||t.throw}function x(t,e){if(N(t))throw k(w(w({},e),{msg:e.message}),null==t?void 0:t.errorFactory);return w({code:e.code,message:e.message},e.requestId?{requestId:e.requestId}:{})}function U(t){if(t&&"object"==typeof t&&t.data&&"object"==typeof t.data){var e=t.data,n=e.code,r=e.message;if(!t.code&&n||!t.message&&r)return w(w(w({},t),!t.code&&n?{code:n}:{}),!t.message&&r?{message:r}:{})}return t}function L(t){var e={},n=t.match(/^(data:.*?)(\?[^#\s]*)?$/);if(n){t=n[1];var r=n[2];r&&(e=function(t){t=t.replace(/^\?/,"");var e={};return t.split("&").forEach(function(t){var n=t.split("="),r=n[0],o=n[1];r=decodeURIComponent(r),o=decodeURIComponent(o),r&&(e[r]?Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]:e[r]=o)}),e}(r))}var o=e.token,i=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(e,["token"]);return/^data:/.test(t)&&!o?{error:"invalid_argument",error_description:"invalid captcha data: ".concat(t)}:o?{state:i.state,token:o,captchaData:t}:{error:"unimplemented",error_description:"need to impl captcha data"}}var D=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),j=function(){return j=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},j.apply(this,arguments)},q=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},M=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function B(t){try{return JSON.parse(t)}catch(e){return t}}var W,F=function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}return D(e,t),e.prototype.get=function(t){return this.request(j(j({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(j(j({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(j(j({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t,n=e.data,r=e.file,o=e.fileContent,i=e.name,s=e.method,a=e.headers,c=void 0===a?{}:a,u=null!=r?r:o,l={post:"post",put:"put"}[null==s?void 0:s.toLowerCase()]||"put",h=new FormData;return"post"===l?(Object.keys(n).forEach(function(t){h.append(t,n[t])}),h.append("key",i),h.append("file",u instanceof Blob?u:new Blob([u])),this.request(j(j({},t),{data:h,method:l}),this.restrictedMethods.includes("upload"))):this.request(j(j({},t),{method:"put",headers:c,body:u}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return q(this,void 0,Promise,function(){var e,n,r,o;return M(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(j(j({},t),{headers:{},responseType:"blob"}))];case 1:return e=i.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return q(this,void 0,Promise,function(){var n,r,o,i,s,a,c,u,l,h,d,f,p,v,y,g=this;return M(this,function(m){switch(m.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,i=void 0!==o&&o,s=t.stream,a=void 0!==s&&s,c=t.signal,u=t.timeout,l=t.shouldThrowOnError,h=void 0===l||l,d=null!=u?u:this.timeout,c&&(c.aborted&&n.abort(),c.addEventListener("abort",function(){return n.abort()})),f=null,i&&d&&(f=setTimeout(function(){console.warn(g.timeoutMsg),n.abort(new Error(g.timeoutMsg))},d)),[4,fetch(r,j(j({},t),{signal:n.signal})).then(function(t){return q(g,void 0,void 0,function(){var e,n,r;return M(this,function(o){switch(o.label){case 0:return clearTimeout(f),h?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(f),Promise.reject(t)})];case 1:return p=m.sent(),a?(v=p.body,[3,5]):[3,2];case 2:return(null===(e=p.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?(y=B,[4,p.text()]):[3,4];case 3:return v=y.apply(void 0,[m.sent()]),[3,5];case 4:v=p.text(),m.label=5;case 5:return[2,{data:v,statusCode:p.status,header:p.headers,response:p}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var i=t.url,s=t.headers,a=void 0===s?{}:s,c=t.data,u=t.responseType,l=t.withCredentials,h=t.body,d=t.onUploadProgress,f=O(v,i,"get"===r?c:{}),p=new XMLHttpRequest;p.open(r,f),u&&(p.responseType=u);var y,g,m=t.signal;m&&(m.aborted?p.abort():m.addEventListener("abort",function(){return p.abort()},{once:!0})),Object.keys(a).forEach(function(t){p.setRequestHeader(t,a[t])}),d&&p.upload.addEventListener("progress",d),p.onreadystatechange=function(){var t={};if(4===p.readyState){var e=p.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=p.status;try{t.data="blob"===u?p.response:JSON.parse(p.responseText)}catch(e){t.data="blob"===u?p.response:p.responseText}clearTimeout(y),o(t)}},e&&n.timeout&&(y=setTimeout(function(){console.warn(n.timeoutMsg),p.abort()},n.timeout)),g=I(c)?c:"application/x-www-form-urlencoded"===a["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")}(c):h||(c?JSON.stringify(c):void 0),l&&(p.withCredentials=!0),p.send(g)})},e}(m.AbstractSDKRequest),H=function(){return H=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},H.apply(this,arguments)};!function(t){t.WEB="web",t.WX_MP="wx_mp"}(W||(W={}));var V=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),G=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},K=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},J=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return V(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(m.AbstractStorage),z=function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(P(g.INVALID_PARAMS,"localStorage is not supported on current platform"),new J(e.root));case"none":return new J(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}return Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:g.OPERATION_FAIL,msg:"[".concat(f(),"][").concat(g.OPERATION_FAIL,"]setStore failed"),info:t}))}}else P(g.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return G(this,void 0,void 0,function(){var r;return K(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}P(g.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return G(this,void 0,void 0,function(){var r;return K(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):P(g.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return G(this,void 0,void 0,function(){return K(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})},t}(),$=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Y=function(t,e){this.data=e||null,this.name=t},Q=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return $(e,t),e}(Y),X=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof Q)return console.error(t.error),this;var n=E(t)?new Y(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,i=this.listeners[r]?function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],this.listeners[r],!0):[];o<i.length;o++)i[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new X;var Z=new X,tt="lang_change";function et(t){return t.mode,t.customInfo,t.title,t.messages,function(t,e,n){}}"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");nt={default:()=>e.default},rt={},l.d(rt,nt);var nt,rt,ot=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},it=g,st={};function at(t,e){var n=e.name,r=e.namespace,o=e.entity,i=e.injectEvents,s=e.IIFE,a=void 0!==s&&s;if(st[n]||r&&t[r])throw new Error(JSON.stringify({code:it.INVALID_OPERATION,msg:"Duplicate component ".concat(n)}));if(a){if(!o||"function"!=typeof o)throw new Error(JSON.stringify({code:it.INVALID_PARAMS,msg:"IIFE component's entity must be a function"}));o.call(t)}if(st[n]=e,r?t.prototype[r]=o:ct(t.prototype,o),i){var c=i.bus,u=i.events;if(!c||!u||0===u.length)return;var l=t.prototype.fire||function(){};t.prototype.events||(t.prototype.events={}),(t.prototype.events||{})[n]?t.prototype.events[n].events=ot(ot([],t.prototype.events[n].events,!0),u,!0):t.prototype.events[n]={bus:c,events:u},t.prototype.fire=function(t,e){l(t,e);for(var n=0,r=Object.keys(this.events);n<r.length;n++){var o=r[n],i=this.events[o],s=i.bus;if(i.events.includes(t)){s.fire(t,e);break}}}}}function ct(t,e){if(!(e instanceof Object))return e;switch(e.constructor){case Date:return new Date(e.getTime());case Object:void 0===t&&(t={});break;case Array:t=[];break;default:return e}for(var n=0,r=Object.keys(e);n<r.length;n++){var o=r[n];Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=ct(t[o],e[o]))}return t}const ut=(t=>{var e={};return l.d(e,t),e})({WxMpWebSocket:()=>n.WxMpWebSocket,WxRequest:()=>n.WxRequest,default:()=>n.default,parseQueryString:()=>n.parseQueryString,wxMpStorage:()=>n.wxMpStorage});var lt=function(){return lt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},lt.apply(this,arguments)},ht={},dt=function(){return dt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},dt.apply(this,arguments)},ft=z,pt={},vt={};function yt(t){var e=t.env,n=t.platformInfo,r={userInfoKey:"".concat("user_info","_").concat(e)};pt[e]=pt[e]||new ft(dt(dt({},t),{keys:r,platformInfo:n})),vt[e]=vt[e]||new ft(dt(dt({},t),{keys:r,platformInfo:n,persistence:"local"}))}function gt(t){return vt[t]}var mt=function(){return mt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},mt.apply(this,arguments)},bt="",wt="@cloudbase/js-sdk";function _t(){return bt}var Et,It=[],St=["env","endPointKey","region"],Ot="https:";function Tt(t){return It.find(function(e){return St.filter(function(e){return null!=t[e]}).every(function(n){return e[n]===t[n]})})}function At(t){var e,n;t.protocol&&!/:$/.test(t.protocol)&&(t.protocol="".concat(t.protocol,":"));var r,o=Tt(t);o?(null!=t.baseUrl&&(o.baseUrl=t.baseUrl),null!=t.protocol&&(o.protocol=t.protocol)):It.push(mt(mt({},t),{protocol:null!==(e=t.protocol)&&void 0!==e?e:Ot})),"CLOUD_API"===t.endPointKey&&(r=null!==(n=t.protocol)&&void 0!==n?n:Ot,v=r)}function Pt(t,e,n){return Tt({env:t,endPointKey:e,region:n})}function Rt(t,e){void 0===e&&(e="CLOUD_API");var n=Pt(t,e||"CLOUD_API"),r=n.protocol,o=n.baseUrl;return"".concat(r).concat(o).match(/(http(s)?:)?\/\/([^/?#]*)/)[0]}!function(t){t.NULL="NULL",t.ANONYMOUS="ANONYMOUS",t.WECHAT="WECHAT",t.WECHAT_PUBLIC="WECHAT-PUBLIC",t.WECHAT_OPEN="WECHAT-OPEN",t.CUSTOM="CUSTOM",t.EMAIL="EMAIL",t.USERNAME="USERNAME",t.PHONE="PHONE"}(Et||(Et={}));var Ct=function(){return Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ct.apply(this,arguments)},kt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Nt=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},xt=g,Ut=I,Lt=O,Dt=["auth.getJwt","auth.logout","auth.signInWithTicket","auth.signInAnonymously","auth.signIn","auth.fetchAccessTokenWithRefreshToken","auth.signUpWithEmailAndPassword","auth.activateEndUserMail","auth.sendPasswordResetEmail","auth.resetPasswordWithToken","auth.isUsernameRegistered"];function jt(t,e,n){var r=t[e];t[e]=function(e){var o={},i={};n.forEach(function(n){var r=n.call(t,e),s=r.data,a=r.headers;Object.assign(o,s),Object.assign(i,a)});var s=e.data;return s&&(Ut(s)?Object.keys(o).forEach(function(t){s.append(t,o[t])}):e.data=Ct(Ct({},s),o)),e.headers=Ct(Ct({},e.headers||{}),i),r.call(t,e)}}function qt(){var t=Math.random().toString(16).slice(2);return{data:{seqId:t},headers:{"X-SDK-Version":"@cloudbase/js-sdk/".concat(_t()),"x-seqid":t}}}var Mt,Bt,Wt=function(){function t(t){var e=this;this.config=t;var n={env:this.config.env,region:this.config.region,accessKey:this.config.accessKey,context:this.config.context,auth:this.config.auth,timeout:this.config.timeout,timeoutMsg:"[@cloudbase/js-sdk] 请求在".concat(this.config.timeout/1e3,"s内未完成,已中断"),restrictedMethods:["post","put"]};this.reqClass=new ht.adapter.reqClass(n),this.localCache=gt(this.config.env),"GATEWAY"!==this.config.endPointMode&&(jt(this.reqClass,"post",[qt]),jt(this.reqClass,"upload",[qt]),jt(this.reqClass,"download",[qt])),Z.on(tt,function(t){var n;e.config.i18n=(null===(n=t.data)||void 0===n?void 0:n.i18n)||e.config.i18n})}return Object.defineProperty(t.prototype,"throwWhenRequestFail",{get:function(){var t,e,n,r,o=null===(n=null===(e=null===(t=this.config)||void 0===t?void 0:t._fromApp)||void 0===e?void 0:e.config)||void 0===n?void 0:n.throw;return"boolean"==typeof o?o:!1!==(null===(r=this.config)||void 0===r?void 0:r.throw)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"errorFactory",{get:function(){var t,e,n,r=this.config;return null!==(t=null==r?void 0:r.errorFactory)&&void 0!==t?t:null===(n=null===(e=null==r?void 0:r._fromApp)||void 0===e?void 0:e.config)||void 0===n?void 0:n.errorFactory},enumerable:!1,configurable:!0}),t.prototype.getAccessToken=function(t){return void 0===t&&(t=null),kt(this,void 0,void 0,function(){var e,n,r;return Nt(this,function(o){switch(o.label){case 0:if(null!=t)return[2,t];if(!(e=this.config._fromApp).oauthInstance)throw new Error("you can't request without auth");return n=e.oauthInstance,r=n.oauth2client,[4,this.getOauthAccessTokenV2(r)];case 1:return[2,o.sent().accessToken]}})})},t.prototype.getDefaultHeaders=function(){var t,e,n;return(t={})[null===(e=this.config.i18n)||void 0===e?void 0:e.LANG_HEADER_KEY]=null===(n=this.config.i18n)||void 0===n?void 0:n.lang,t["X-SDK-Version"]="@cloudbase/js-sdk/".concat(_t()),t},Object.defineProperty(t.prototype,"requestDebug",{get:function(){var t,e,n;return!0===(null===(n=null===(e=null===(t=this.config)||void 0===t?void 0:t._fromApp)||void 0===e?void 0:e.config)||void 0===n?void 0:n.debug)},enumerable:!1,configurable:!0}),t.prototype.post=function(t,e){return kt(this,void 0,Promise,function(){return Nt(this,function(n){switch(n.label){case 0:return[4,this.reqClass.post(Ct(Ct({},t),{headers:Ct(Ct({},t.headers),this.getDefaultHeaders()),customReqOpts:e,debug:this.requestDebug}))];case 1:return[2,n.sent()]}})})},t.prototype.upload=function(t){var e;return kt(this,void 0,Promise,function(){var n,r,o;return Nt(this,function(i){switch(i.label){case 0:return r=null!==(e=(n=t).file)&&void 0!==e?e:n.fileContent,delete(o=Ct(Ct({},n),{file:r,headers:Ct(Ct({},n.headers),this.getDefaultHeaders()),debug:this.requestDebug})).fileContent,[4,this.reqClass.upload(o)];case 1:return[2,i.sent()]}})})},t.prototype.download=function(t){return kt(this,void 0,Promise,function(){return Nt(this,function(e){switch(e.label){case 0:return[4,this.reqClass.download(Ct(Ct({},t),{headers:Ct(Ct({},t.headers),this.getDefaultHeaders()),debug:this.requestDebug}))];case 1:return[2,e.sent()]}})})},t.prototype.getUploadByteLength=function(t){var e,n;return null===(n=(e=this.reqClass).getUploadByteLength)||void 0===n?void 0:n.call(e,t)},t.prototype.getBaseEndPoint=function(t){return void 0===t&&(t="CLOUD_API"),Rt(this.config.env,t)},t.prototype.getOauthAccessTokenV2=function(t){return kt(this,void 0,Promise,function(){var e,n;return Nt(this,function(r){switch(r.label){case 0:return[4,t.getAccessToken()];case 1:return e=r.sent(),[4,t.getCredentials()];case 2:return n=r.sent(),[2,{accessToken:e,accessTokenExpire:new Date(n.expires_at).getTime()}]}})})},t.prototype.request=function(t,e,n,r){var o,i;return kt(this,void 0,Promise,function(){var s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I,S,O,T,A,P;return Nt(this,function(R){switch(R.label){case 0:if(R.trys.push([0,4,,5]),s="x-tcb-trace_".concat(this.config.env),a="application/x-www-form-urlencoded",c=Ct({action:t,dataVersion:"2020-01-10",env:this.config.env},e),-1!==Dt.indexOf(t))return[3,2];if(!(u=this.config._fromApp).oauthInstance)throw new Error("you can't request without auth");return l=u.oauthInstance,h=l.oauth2client,d=c,[4,this.getOauthAccessTokenV2(h)];case 1:d.access_token=R.sent().accessToken,R.label=2;case 2:return"storage.uploadFile"===t?(f=new FormData,Object.keys(f).forEach(function(t){Object.prototype.hasOwnProperty.call(f,t)&&void 0!==f[t]&&f.append(t,c[t])}),a="multipart/form-data"):(a="application/json;charset=UTF-8",f={},Object.keys(c).forEach(function(t){void 0!==c[t]&&(f[t]=c[t])})),p={headers:Ct(Ct({"content-type":a},this.getDefaultHeaders()),null==n?void 0:n.headers)},(null==n?void 0:n.onUploadProgress)&&(p.onUploadProgress=n.onUploadProgress),this.config.region&&(p.headers["X-TCB-Region"]=this.config.region),(v=this.localCache.getStore(s))&&(p.headers["X-TCB-Trace"]=v),y=void 0!==(null==n?void 0:n.parse)?n.parse:e.parse,g=void 0!==(null==n?void 0:n.inQuery)?n.inQuery:e.inQuery,m=void 0!==(null==n?void 0:n.search)?n.search:e.search,b=Ct(Ct({},(null==n?void 0:n.defaultQuery)||{}),{env:this.config.env}),y&&(b.parse=!0),g&&(b=Ct(Ct({},g),b)),w=(null==n?void 0:n.endPointMode)||this.config.endPointMode||"CLOUD_API",_=Pt(this.config.env,w),E=_.baseUrl,I=_.protocol,"GATEWAY"===w&&/^((database)\.)|(auth\.wsWebSign)/.test(t)&&(S=Pt(this.config.env,"CLOUD_API"),E="".concat(S.baseUrl.match(/\/\/([^/?#]*)/)[0],"/web")),O=void 0,O=n.pathname?Lt(I,"".concat(null===(o=Rt(this.config.env,w))||void 0===o?void 0:o.replace(/^https?:/,""),"/").concat(n.pathname),b):Lt(I,E,b),m&&(O+=m),[4,this.post(Ct({url:O,data:f},p),r)];case 3:if(T=R.sent(),(A=null===(i=T.header)||void 0===i?void 0:i["x-tcb-trace"])&&this.localCache.setStore(s,A),200!==Number(T.status)&&200!==Number(T.statusCode)||!T.data)throw new Error("network request error");return[2,T];case 4:P=R.sent();try{P.requestId=P.requestId||(null==n?void 0:n.headers["x-request-id"])||(null==n?void 0:n.headers["X-Request-Id"])||""}catch(t){}throw P;case 5:return[2]}})})},t.prototype.fetch=function(t){var e,n,r,o,i,s,a,c;return kt(this,void 0,Promise,function(){var u,l,h,d,f,p,v,y,g=this;return Nt(this,function(m){switch(m.label){case 0:u=t.token,l=t.headers,h=void 0===l?{}:l,d=t.withCredentials,f=void 0===d||d,p=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(t,["token","headers","withCredentials"]),v=function(){return kt(g,void 0,void 0,function(){var t,e,n,r;return Nt(this,function(o){switch(o.label){case 0:if(t={},!f)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.getAccessToken(u)];case 2:return(e=o.sent())&&(t.Authorization="Bearer ".concat(e)),[3,4];case 3:if(n=o.sent(),"undefined"==typeof process||null==process.versions||null==process.versions.node)throw n;return[3,4];case 4:return r=Ct({headers:Ct(Ct(Ct({"X-SDK-Version":"@cloudbase/js-sdk/".concat(_t())},t),this.getDefaultHeaders()),h),withCredentials:f},p),[2,this.reqClass.fetch(r)]}})})},m.label=1;case 1:return m.trys.push([1,3,,6]),[4,v()];case 2:return[2,m.sent()];case 3:y=m.sent();try{y.requestId=y.requestId||h["x-request-id"]||h["X-Request-Id"]||""}catch(t){}if("ACCESS_TOKEN_EXPIRED"!==(null==y?void 0:y.code))return[3,5];if("function"!=typeof(null===(o=null===(r=null===(n=null===(e=this.config)||void 0===e?void 0:e._fromApp)||void 0===n?void 0:n.oauthInstance)||void 0===r?void 0:r.authApi)||void 0===o?void 0:o.refreshTokenForce))throw y;return[4,null===(c=null===(a=null===(s=null===(i=this.config)||void 0===i?void 0:i._fromApp)||void 0===s?void 0:s.oauthInstance)||void 0===a?void 0:a.authApi)||void 0===c?void 0:c.refreshTokenForce()];case 4:return m.sent(),[2,v()];case 5:throw y;case 6:return[2]}})})},t.prototype.send=function(t,e,n,r){return void 0===e&&(e={}),void 0===n&&(n={}),kt(this,void 0,Promise,function(){var o;return Nt(this,function(i){switch(i.label){case 0:return[4,this.request(t,e,Ct(Ct({},n),{onUploadProgress:e.onUploadProgress}),r)];case 1:if((o=i.sent()).data.code&&this.throwWhenRequestFail)throw k({code:o.data.code,msg:o.data.message||"",requestId:o.requestId},this.errorFactory);return[2,o.data]}})})},t.prototype.gateWay=function(t,e){var n,r;return kt(this,void 0,void 0,function(){var o,i,s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E;return Nt(this,function(I){switch(I.label){case 0:if(o=t.url,i=t.name,s=t.data,a=t.path,c=void 0===a?"":a,u=t.method,l=t.header,h=void 0===l?{}:l,!(i&&c||o))throw k({code:xt.INVALID_PARAMS,msg:"[gateWay] invalid function name or path or url"},this.errorFactory);try{d=s?JSON.stringify(s):""}catch(t){throw k({code:xt.INVALID_PARAMS,msg:"[gateWay] invalid data"},this.errorFactory)}if(f=S(),p=Pt(this.config.env,"GATEWAY"),v=p.baseUrl,y=p.protocol,g="".concat(y).concat(v).concat(o||"/".concat(c,"/").concat(i)),m=["GET","HEAD"].includes(null===(n=null==u?void 0:u.toUpperCase)||void 0===n?void 0:n.call(u)))try{b={};try{b=JSON.parse(s)}catch(t){b=s||{}}g="".concat(g).concat(g.includes("?")?"&":"?").concat(Object.keys(b).map(function(t){return"".concat(t,"=").concat(b[t])}).join("&"))}catch(t){}return[4,this.fetch(Ct(Ct({method:u||"POST",headers:Ct({"Content-Type":"application/json; charset=utf-8","X-Request-Id":f},h)},m?{}:{body:d}),{url:g,customReqOpts:e,shouldThrowOnError:null!==(r=t.shouldThrowOnError)&&void 0!==r?r:this.throwWhenRequestFail}))];case 1:return w=I.sent(),_=[Ct({requestId:f},w)],E={},[4,w.data];case 2:return[2,Ct.apply(void 0,_.concat([(E.data=I.sent(),E)]))]}})})},t}(),Ft={};!function(t){t.ZH="zh-CN",t.EN="en-US"}(Bt||(Bt={}));var Ht=((Mt={})[Bt.EN]={"请检查调用方式,或前往云开发 AI+ 首页查看文档":"Please check the calling method or visit the AI+ homepage to view the documentation","AI+ 请求出错,错误码":"AI+ request error, error code",错误信息:"error message",未实现:"not implemented","小程序不支持 wasm 加载":"wasm loading is not supported in mini programs","小程序不支持动态 js 加载":"dynamic js loading is not supported in mini programs",请求超时:"request timeout","缺少 privatelink sdk 地址":"missing privatelink sdk address"},Mt),Vt=function(t,e){var n;return(null===(n=Ht[e])||void 0===n?void 0:n[t])||t},Gt=function(t,e){var n,r,o=function(t){return"lang_".concat(t.clientId||t.env)}(e),i=(t.adapter||{}).localStorage,s=e.lang||(null===(n=null==i?void 0:i.getItem)||void 0===n?void 0:n.call(i,o))||Bt.ZH;return null===(r=null==i?void 0:i.setItem)||void 0===r||r.call(i,o,s),new Proxy({t:function(t){return Vt(t,s)},LANG_HEADER_KEY:"Accept-Language",lang:s},{get:function(t,e){var n;return"lang"===e&&(null===(n=null==i?void 0:i.getItem)||void 0===n?void 0:n.call(i,o))||t[e]},set:function(t,e,n){var r;return"lang"===e&&n!==t[e]&&(t[e]=n,t.t=function(t){return Vt(t,n)},null===(r=null==i?void 0:i.setItem)||void 0===r||r.call(i,o,n),Z.fire(tt,{i18n:t})),t[e]=n,!0}})},Kt=new Set,Jt=function(){return Jt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Jt.apply(this,arguments)},zt=function(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s},$t=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},Yt=function(){return{adapter:H({},{type:"default",root:window,reqClass:F,wsClass:WebSocket,localStorage}),runtime:W.WEB}},Qt=g,Xt=y,Zt=P,te=et,ee={persistence:"local"},ne=6e5,re={},oe=function(){function t(t){this.cloudbaseConfig=t||this.cloudbaseConfig,this.authInstance=null,this.oauthInstance=null,this.requestInstance=null,this.version=_t()}return Object.defineProperty(t.prototype,"config",{get:function(){return this.cloudbaseConfig},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"platform",{get:function(){return ht},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"cache",{get:function(){return t=this.cloudbaseConfig.env,pt[t];var t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"localCache",{get:function(){return gt(this.cloudbaseConfig.env)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"request",{get:function(){return this.requestInstance||(t=this.cloudbaseConfig.env,Ft[t]);var t},enumerable:!1,configurable:!0}),t.prototype.init=function(e){var n,r,o,i,s;if(void 0===e&&(e={env:""}),e.endPointMode=e.endPointMode||"GATEWAY",ht.adapter||this.useDefaultAdapter(),(e=this.dealNodeAdapterConfig(e)).throw=null===(r=null!==(n=e.throw)&&void 0!==n?n:e.throwOnCode)||void 0===r||r,delete e.throwOnCode,!e.env)throw new Error(JSON.stringify({code:Qt.INVALID_PARAMS,msg:"env must not be specified"}));this.isInitialized(e);var a=this.isNodeEnv()?void 0:15e3,c=e.timeout||a,u={env:e.env,region:e.region,accessKey:e.accessKey,context:e.context,auth:e.auth,timeout:c,timeoutMsg:c?"[".concat(wt,"][REQUEST TIMEOUT] request had been abort since didn't finished within").concat(c/1e3,"s"):void 0};this.requestClient=new ht.adapter.reqClass(u),this.cloudbaseConfig=Jt(Jt(Jt({},ee),e),{timeout:c,i18n:Gt(ht,e)}),function(t){t&&"object"==typeof t&&Kt.add(t)}(this.cloudbaseConfig),delete this.cloudbaseConfig.lang,this.cloudbaseConfig.timeout=this.formatTimeout(this.cloudbaseConfig.timeout);var l=this.cloudbaseConfig,h=l.env,d=l.persistence,f=l.debug,p=l.timeout,v=l.oauthClient,y=l.i18n;yt({env:h,persistence:d,debug:f,platformInfo:this.platform}),function(t,e){At({env:t,region:e,baseUrl:"//".concat(t,".").concat(e||"ap-shanghai",".tcb-api.tencentcloudapi.com/web"),protocol:void 0,endPointKey:"CLOUD_API"})}(h,e.region||""),function(t,e,n){var r="//".concat(t,".api.tcloudbasegateway.com/v1");n&&(r="//".concat(t,".api.intl.tcloudbasegateway.com/v1")),At({endPointKey:"GATEWAY",env:t,baseUrl:r,protocol:e})}(h,Ot,e.intl);var g=new t(this.cloudbaseConfig);return g.requestInstance=function(t){var e=new Wt(Ct(Ct({},t),{throw:t.throw}));return Ft[t.env]=e,e}({env:h,region:e.region||"",timeout:p,oauthClient:v,_fromApp:g,i18n:y,endPointMode:e.endPointMode,auth:e.auth,context:e.context,accessKey:e.accessKey,throw:e.throw}),g.requestClient=this.requestClient,null===(o=null==this?void 0:this.fire)||void 0===o||o.call(this,"cloudbase_init",g),this.try2InitAuth(g),(null===(i=ht.adapter)||void 0===i?void 0:i.nodeTool)&&(null===(s=ht.adapter)||void 0===s||s.nodeTool(g,this.cloudbaseConfig)),g},t.prototype.updateConfig=function(t){var e=t.persistence,n=t.debug;this.cloudbaseConfig.persistence=e,this.cloudbaseConfig.debug=n,yt({env:this.cloudbaseConfig.env,persistence:e,debug:n,platformInfo:this.platform})},t.prototype.setThrowOnCode=function(t){this.cloudbaseConfig.throw=t},t.prototype.updateLang=function(t){var e;t&&t!==(null===(e=this.cloudbaseConfig.i18n)||void 0===e?void 0:e.lang)&&(this.cloudbaseConfig.i18n.lang=t)},t.prototype.registerExtension=function(t){re[t.name]=t},t.prototype.invokeExtension=function(t,e){return n=this,r=void 0,i=function(){var n;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(r){switch(r.label){case 0:if(!(n=re[t]))throw new Error(JSON.stringify({code:Qt.INVALID_PARAMS,msg:"extension:".concat(t," must be registered before invoke")}));return[4,n.invoke(e,this)];case 1:return[2,r.sent()]}})},new((o=void 0)||(o=Promise))(function(t,e){function s(t){try{c(i.next(t))}catch(t){e(t)}}function a(t){try{c(i.throw(t))}catch(t){e(t)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof o?n:new o(function(t){t(n)})).then(s,a)}c((i=i.apply(n,r||[])).next())});var n,r,o,i},t.prototype.useAdapters=function(t,e){var n=function(t,e){for(var n=0,r=_(t)?t:[t];n<r.length;n++){var o=r[n],i=o.isMatch,s=o.genAdapter,a=o.runtime;if(i())return{adapter:H({isMatch:i},s(e)),runtime:a}}}(t,e)||{},r=n.adapter,o=n.runtime;r&&(ht.adapter=r),o&&(ht.runtime=o)},t.prototype.registerHook=function(e){!function(t,e){var n=e.entity,r=e.target;if(Object.prototype.hasOwnProperty.call(t,r))throw new Error(JSON.stringify({code:it.INVALID_OPERATION,msg:"target:".concat(r," is not exist")}));var o=t.prototype[r];if("function"!=typeof o)throw new Error(JSON.stringify({code:it.INVALID_OPERATION,msg:"target:".concat(r," is not a function which is the only type supports hook")}));t.prototype[r]=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return n.call.apply(n,ot([this],t,!1)),o.call.apply(o,ot([this],t,!1))}}(t,e)},t.prototype.registerComponent=function(e){at(t,e)},t.prototype.registerVersion=function(t){!function(t){bt=t}(t),this.version=t},t.prototype.registerSdkName=function(t){!function(t){wt=t,function(t){d=t}(t)}(t)},t.prototype.isInitialized=function(t){return void 0===t&&(t=this.cloudbaseConfig),"string"==typeof t.env&&["your-env-id","your-envid","your_env_id","xxx-yyy","xxxx-yyy","envId","env-id","your-environment-id","REPLACE_ME"].some(function(e){return t.env.toLowerCase()===e.toLowerCase()})&&Zt(Qt.INVALID_PARAMS,'[CloudBase] 检测到环境 ID "'.concat(t.env,'" 可能是占位符,请替换为真实的环境 ID。\n')+" 获取方式:登录腾讯云开发平台 → 环境管理 → 环境设置 → 环境 ID\n 建议通过环境变量配置:process.env.CLOUDBASE_ENV 或 import.meta.env.VITE_CLOUDBASE_ENV"),!!(null==t?void 0:t.env)},t.prototype.registerEndPoint=function(t,e){At({baseUrl:t,protocol:e,env:this.config.env,endPointKey:"CLOUD_API"})},t.prototype.registerEndPointWithKey=function(t){At({env:this.config.env,endPointKey:t.key,baseUrl:t.url,protocol:t.protocol})},t.prototype.registerHost=function(t,e){void 0===e&&(e="http");var n=t.replace(/^(https?:)?\/\//,""),r="//".concat(n);At({baseUrl:"".concat(r,"/web"),protocol:e,env:this.config.env,endPointKey:"CLOUD_API"}),At({baseUrl:"".concat(r,"/v1"),protocol:e,env:this.config.env,endPointKey:"GATEWAY"})},t.prototype.getEndPointWithKey=function(t){var e=Pt(this.config.env,t);return{BASE_URL:e.baseUrl,PROTOCOL:e.protocol}},t.prototype.parseCaptcha=function(t){return L(t)},t.prototype.useDefaultAdapter=function(){var t=Yt.bind(this)(),e=t.adapter,n=t.runtime;ht.adapter=e,ht.runtime=n},t.prototype.isNodeEnv=function(){var t;return"undefined"!=typeof process&&!!(null===(t=ht.adapter)||void 0===t?void 0:t.getSecretInfo)},t.prototype.formatTimeout=function(t){if(null==t)return t;switch(!0){case t>ne:return Zt(Qt.INVALID_PARAMS,"timeout is greater than maximum value[10min]"),ne;case t<100:return Zt(Qt.INVALID_PARAMS,"timeout is less than maximum value[100ms]"),100;default:return t}},t.prototype.try2InitAuth=function(t){try{t.auth()}catch(t){console.log("try2InitAuth error:",t)}},t.prototype.dealNodeAdapterConfig=function(t){var e,n,r,o,i;if(this.isNodeEnv()){var s=null===(e=ht.adapter)||void 0===e?void 0:e.getSecretInfo(t);t.env&&"symbol"!=typeof t.env||(t.env=s.env),s.credentials&&(t.auth=Jt(Jt({},t.auth),{credentials:s.credentials}));var a=t,c=a.secretId||(null===(n=t.auth)||void 0===n?void 0:n.secretId),u=a.secretKey||(null===(r=t.auth)||void 0===r?void 0:r.secretKey);if(c&&u){var l=a.sessionToken||(null===(o=t.auth)||void 0===o?void 0:o.sessionToken)||"";t.auth=Jt(Jt({},t.auth),{secretId:c,secretKey:u,sessionToken:l,secretType:(null===(i=t.auth)||void 0===i?void 0:i.secretType)||(l?"SESSION_SECRET":"SECRET")})}}return t},zt([te({mode:"sync",title:"Cloudbase 初始化失败",messages:["请确认以下各项:"," 1 - 调用 cloudbase.init() 的语法或参数是否正确"," 2 - 如果是非浏览器环境,是否配置了安全应用来源(https://docs.cloudbase.net/api-reference/webv3/adapter#%E7%AC%AC-2-%E6%AD%A5%E9%85%8D%E7%BD%AE%E5%AE%89%E5%85%A8%E5%BA%94%E7%94%A8%E6%9D%A5%E6%BA%90)","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Xt)]}),$t("design:type",Function),$t("design:paramtypes",[Object]),$t("design:returntype",t)],t.prototype,"init",null),zt([te({title:"调用扩展能力失败",messages:["请确认以下各项:"," 1 - 调用 invokeExtension() 的语法或参数是否正确"," 2 - 被调用的扩展能力是否已经安装并通过 registerExtension() 注册","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Xt)]}),$t("design:type",Function),$t("design:paramtypes",[String,Object]),$t("design:returntype",Promise)],t.prototype,"invokeExtension",null),t}(),ie=new oe,se=void 0===ut.WxRequest?null:(ut.default.genAdapter=function(t){return{root:{globalThis:{}},reqClass:ut.WxRequest,wsClass:ut.WxMpWebSocket,captchaOptions:{openURIWithCallback:function(e){var n=t.EventBus,r={},o=e;console.log("openURIWithCallback",e);var i=e.match(/^(data:.*?)(\?[^#\s]*)?$/);if(i){o=i[1],console.log("openURIWithCallback url",o);var s=i[2];s&&(r=(0,ut.parseQueryString)(s))}console.log("openURIWithCallback queryObj",r);var a=r.token,c=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(r,["token"]);return/^data:/.test(o)&&!a?Promise.reject({error:"invalid_argument",error_description:"invalie captcha data: ".concat(e)}):a?new Promise(function(t){console.log("wait for captcha..."),n.$emit("CAPTCHA_DATA_CHANGE",lt(lt({},c),{token:a,url:o})),n.$once("RESOLVE_CAPTCHA_DATA",function(e){t(e)})}):Promise.reject({error:"unimplemented",error_description:"need to impl captcha data"})}},localStorage:ut.wxMpStorage,primaryStorage:m.StorageType.local,getAppSign:function(){var t=wx.getAccountInfoSync();return"undefined"!=typeof App||"undefined"!=typeof getApp||wx.onAppHide||wx.offAppHide||wx.onAppShow||wx.offAppShow?t&&t.miniProgram?t.miniProgram.appId:"":t&&t.plugin?t.plugin.appId:""}}},ut.default);se&&ie.useAdapters(se);const ae=ie;var ce,ue,le,he,de,fe,pe="/auth";!function(t){t.AUTH_SIGN_UP_URL="/v1/signup",t.AUTH_TOKEN_URL="/v1/token",t.AUTH_REVOKE_URL="/v1/revoke",t.WEDA_USER_URL="/v1/plugin/weda/userinfo",t.AUTH_RESET_PASSWORD="/v1/reset",t.AUTH_GET_DEVICE_CODE="/v1/device/code",t.CHECK_USERNAME="/v1/checkUsername",t.CHECK_IF_USER_EXIST="/v1/checkIfUserExist",t.GET_PROVIDER_TYPE="/v1/mgr/provider/providerSubType",t.AUTH_SIGN_IN_URL="/v1/signin",t.AUTH_SIGN_IN_ANONYMOUSLY_URL="/v1/signin/anonymously",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v1/signin/with/provider",t.AUTH_SIGN_IN_WITH_WECHAT_URL="/v1/signin/wechat/noauth",t.AUTH_SIGN_IN_CUSTOM="/v1/signin/custom",t.PROVIDER_TOKEN_URL="/v1/provider/token",t.PROVIDER_URI_URL="/v1/provider/uri",t.USER_ME_URL="/v1/user/me",t.AUTH_SIGNOUT_URL="/v1/user/signout",t.USER_QUERY_URL="/v1/user/query",t.USER_PRIFILE_URL="/v1/user/profile",t.USER_BASIC_EDIT_URL="/v1/user/basic/edit",t.USER_TRANS_BY_PROVIDER_URL="/v1/user/trans/by/provider",t.PROVIDER_LIST="/v1/user/provider",t.PROVIDER_BIND_URL="/v1/user/provider/bind",t.PROVIDER_UNBIND_URL="/v1/user/provider",t.CHECK_PWD_URL="/v1/user/sudo",t.SUDO_URL="/v1/user/sudo",t.BIND_CONTACT_URL="/v1/user/contact",t.AUTH_SET_PASSWORD="/v1/user/password",t.AUTHORIZE_DEVICE_URL="/v1/user/device/authorize",t.AUTHORIZE_URL="/v1/user/authorize",t.AUTHORIZE_INFO_URL="/v1/user/authorize/info",t.AUTHORIZED_DEVICES_DELETE_URL="/v1/user/authorized/devices/",t.AUTH_REVOKE_ALL_URL="/v1/user/revoke/all",t.GET_USER_BEHAVIOR_LOG="/v1/user/security/history",t.VERIFICATION_URL="/v1/verification",t.VERIFY_URL="/v1/verification/verify",t.CAPTCHA_DATA_URL="/v1/captcha/data",t.VERIFY_CAPTCHA_DATA_URL="/v1/captcha/data/verify",t.GET_CAPTCHA_URL="/v1/captcha/init",t.GET_MINIPROGRAM_QRCODE="/v1/qrcode/generate",t.GET_MINIPROGRAM_QRCODE_STATUS="/v1/qrcode/get/status"}(ce||(ce={})),function(t){t.AUTH_SIGN_IN_URL="/v2/signin/username",t.AUTH_TOKEN_URL="/v2/token",t.USER_ME_URL="/v2/user/me",t.VERIFY_URL="/v2/signin/verificationcode",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",t.AUTH_PUBLIC_KEY="/v2/signin/publichkey",t.AUTH_RESET_PASSWORD="/v2/signin/password/update"}(ue||(ue={})),function(t){t.REGISTER="REGISTER",t.SIGN_IN="SIGN_IN",t.PASSWORD_RESET="PASSWORD_RESET",t.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",t.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"}(le||(le={})),(fe=he||(he={})).UNREACHABLE="unreachable",fe.LOCAL="local",fe.CANCELLED="cancelled",fe.UNKNOWN="unknown",fe.UNAUTHENTICATED="unauthenticated",fe.RESOURCE_EXHAUSTED="resource_exhausted",fe.FAILED_PRECONDITION="failed_precondition",fe.INVALID_ARGUMENT="invalid_argument",fe.DEADLINE_EXCEEDED="deadline_exceeded",fe.NOT_FOUND="not_found",fe.ALREADY_EXISTS="already_exists",fe.PERMISSION_DENIED="permission_denied",fe.ABORTED="aborted",fe.OUT_OF_RANGE="out_of_range",fe.UNIMPLEMENTED="unimplemented",fe.INTERNAL="internal",fe.UNAVAILABLE="unavailable",fe.DATA_LOSS="data_loss",fe.INVALID_PASSWORD="invalid_password",fe.PASSWORD_NOT_SET="password_not_set",fe.INVALID_STATUS="invalid_status",fe.USER_PENDING="user_pending",fe.USER_BLOCKED="user_blocked",fe.INVALID_VERIFICATION_CODE="invalid_verification_code",fe.TWO_FACTOR_REQUIRED="two_factor_required",fe.INVALID_TWO_FACTOR="invalid_two_factor",fe.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",fe.UNDER_REVIEW="under_review",fe.INVALID_REQUEST="invalid_request",fe.UNAUTHORIZED_CLIENT="unauthorized_client",fe.ACCESS_DENIED="access_denied",fe.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",fe.INVALID_SCOPE="invalid_scope",fe.INVALID_GRANT="invalid_grant",fe.SERVER_ERROR="server_error",fe.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",fe.INTERACTION_REQUIRED="interaction_required",fe.LOGIN_REQUIRED="login_required",fe.ACCOUNT_SELECTION_REQUIRED="account_selection_required",fe.CONSENT_REQUIRED="consent_required",fe.INVALID_REQUEST_URI="invalid_request_uri",fe.INVALID_REQUEST_OBJECT="invalid_request_object",fe.REQUEST_NOT_SUPPORTED="request_not_supported",fe.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",fe.REGISTRATION_NOT_SUPPORTED="registration_not_supported",fe.CAPTCHA_REQUIRED="captcha_required",fe.CAPTCHA_INVALID="captcha_invalid",fe.PROVIDER_NOT_ENABLED="provider_not_enabled",fe.LOGIN_METHOD_DISABLED="login_method_disabled",fe.INVALID_USERNAME_OR_PASSWORD="invalid_username_or_password",fe.INVALID_CREDENTIALS="invalid_credentials",fe.WRONG_PASSWORD="wrong_password",fe.USER_NOT_FOUND="user_not_found",fe.MFA_PHONE_REQUIRED="mfa_phone_required",fe.LOGIN_TYPE_DISABLED="login_type_disabled",fe.PROVIDER_ERROR="provider_error",fe.MISSING_REQUIRED_PARAM="missing_required_param",function(t){t[t.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",t[t.NOT_FOUND=5]="NOT_FOUND",t[t.PERMISSION_DENIED=7]="PERMISSION_DENIED",t[t.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",t[t.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",t[t.ABORTED=10]="ABORTED",t[t.UNIMPLEMENTED=12]="UNIMPLEMENTED",t[t.INTERNAL=13]="INTERNAL",t[t.UNAVAILABLE=14]="UNAVAILABLE",t[t.UNAUTHENTICATED=16]="UNAUTHENTICATED",t[t.MISSING_REQUIRED_PARAM=4e3]="MISSING_REQUIRED_PARAM",t[t.CAPTCHA_REQUIRED=4001]="CAPTCHA_REQUIRED",t[t.CAPTCHA_INVALID=4002]="CAPTCHA_INVALID",t[t.PROVIDER_ERROR=4019]="PROVIDER_ERROR",t[t.UNAUTHORIZED_CLIENT=4022]="UNAUTHORIZED_CLIENT",t[t.MFA_PHONE_REQUIRED=4042]="MFA_PHONE_REQUIRED",t[t.LOGIN_TYPE_DISABLED=4045]="LOGIN_TYPE_DISABLED"}(de||(de={}));var ve,ye,ge="credentials_error",me="SIGNED_OUT",be="SIGNED_IN",we="INITIAL_SESSION",_e="TOKEN_REFRESHED",Ee="USER_UPDATED",Ie="BIND_IDENTITY",Se="loginStateChanged",Oe="authStateChanged",Te="sign_in",Ae="bind_identity",Pe="node-sdk-scope";function Re(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})}!function(t){t.EMAIL="email",t.RECOVERY="recovery",t.REAUTHENTICATION="reauthentication"}(ve||(ve={})),function(t){t.CLIENT_ID="client_id",t.CLIENT_SECRET="client_secret",t.RESPONSE_TYPE="response_type",t.SCOPE="scope",t.STATE="state",t.REDIRECT_URI="redirect_uri",t.ERROR="error",t.ERROR_DESCRIPTION="error_description",t.ERROR_URI="error_uri",t.GRANT_TYPE="grant_type",t.CODE="code",t.ACCESS_TOKEN="access_token",t.TOKEN_TYPE="token_type",t.EXPIRES_IN="expires_in",t.USERNAME="username",t.PASSWORD="password",t.REFRESH_TOKEN="refresh_token"}(ye||(ye={}));var Ce=l(2631),ke=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Ne=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},xe=new Map,Ue=function(){function t(t){this.clientId=(null==t?void 0:t.clientId)||"",this.getScope=null==t?void 0:t.getScope,xe=xe||new Map}return t.prototype.run=function(t,e){return ke(this,void 0,Promise,function(){var n,r,o=this;return Ne(this,function(i){return n=this.getScope?this.getScope():this.clientId,t="".concat(n,"_").concat(t),(r=xe.get(t))||(r=new Promise(function(n,r){ke(o,void 0,void 0,function(){var o,i,s;return Ne(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,4,5]),[4,this.runIdlePromise()];case 1:return a.sent(),o=e(),i=n,[4,o];case 2:return i.apply(void 0,[a.sent()]),[3,5];case 3:return s=a.sent(),r(s),[3,5];case 4:return xe.delete(t),[7];case 5:return[2]}})})}),xe.set(t,r)),[2,r]})})},t.prototype.runIdlePromise=function(){return Promise.resolve()},t}(),Le="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",De=/^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/,je=function(t){if(t=String(t).replace(/[\t\n\f\r ]+/g,""),!De.test(t))throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");var e;t+="==".slice(2-(3&t.length));for(var n,r,o="",i=0;i<t.length;)e=Le.indexOf(t.charAt(i++))<<18|Le.indexOf(t.charAt(i++))<<12|(n=Le.indexOf(t.charAt(i++)))<<6|(r=Le.indexOf(t.charAt(i++))),o+=64===n?String.fromCharCode(e>>16&255):64===r?String.fromCharCode(e>>16&255,e>>8&255):String.fromCharCode(e>>16&255,e>>8&255,255&e);return o};function qe(){if("undefined"==typeof globalThis)return!1;var t=globalThis.wx;if(void 0===t)return!1;if(void 0===globalThis.Page)return!1;if(!t.getDeviceInfo)return!1;if(!t.getStorageSync)return!1;if(!t.setStorageSync)return!1;if(!t.connectSocket)return!1;if(!t.request)return!1;try{if(!t.getDeviceInfo())return!1;if("qq"===t.getDeviceInfo().platform)return!1}catch(t){return!1}return!0}var Me=!1;function Be(){Me=Me||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{qe()||(Me=Me||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?Be():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",Be,!1))}catch(t){}var We=function(){return We=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},We.apply(this,arguments)},Fe=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},He=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Ve=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},Ge="x-request-id",Ke="x-device-id",Je="device_id",ze=function(t,e){return Fe(this,void 0,Promise,function(){var n,r,o,i,s;return He(this,function(a){switch(a.label){case 0:n=null,r=null,a.label=1;case 1:return a.trys.push([1,4,,5]),(o=Object.assign({},e)).method||(o.method="GET"),o.body&&"string"!=typeof o.body&&(o.body=JSON.stringify(o.body)),[4,fetch(t,o)];case 2:return[4,a.sent().json()];case 3:return(null==(i=a.sent())?void 0:i.error)?(r=i).error_uri=new URL(t).pathname:n=i,[3,5];case 4:return s=a.sent(),r={error:he.UNREACHABLE,error_description:s.message,error_uri:new URL(t).pathname},[3,5];case 5:if(r)throw r;return[2,n]}})})},$e=function(){function t(t){this._env=(null==t?void 0:t.env)||""}return t.prototype.getItem=function(t){return Fe(this,void 0,Promise,function(){return He(this,function(e){return[2,window.localStorage.getItem("".concat(t).concat(this._env))]})})},t.prototype.removeItem=function(t){return Fe(this,void 0,Promise,function(){return He(this,function(e){return window.localStorage.removeItem("".concat(t).concat(this._env)),[2]})})},t.prototype.setItem=function(t,e){return Fe(this,void 0,Promise,function(){return He(this,function(n){return window.localStorage.setItem("".concat(t).concat(this._env),e),[2]})})},t.prototype.getItemSync=function(t){return window.localStorage.getItem("".concat(t).concat(this._env))},t.prototype.removeItemSync=function(t){window.localStorage.removeItem("".concat(t).concat(this._env))},t.prototype.setItemSync=function(t,e){window.localStorage.setItem("".concat(t).concat(this._env),e)},t}(),Ye=new $e,Qe=function(){function t(t){var e=this;this.credentials=null,this.accessKeyCredentials=null,this.singlePromise=null,this.tokenSectionName=t.tokenSectionName,this.storage=t.storage,this.clientId=t.clientId,this.singlePromise=new Ue({clientId:this.clientId,getScope:function(){var t;return(null===(t=e.accessKeyCredentials)||void 0===t?void 0:t.access_token)?"".concat(e.clientId,"_").concat(e.accessKeyCredentials.access_token):e.clientId}}),this.credentials=t.credentials||null,this.onCredentialsChange=t.onCredentialsChange}return t.prototype.syncMemoryCredentials=function(t){this.credentials=t},t.prototype.getMemoryCredentials=function(){return this.credentials},t.prototype.getStorageCredentialsSync=function(){var t=null,e=this.storage.getItemSync(this.tokenSectionName);if(null!=e)try{(null==(t=JSON.parse(e))?void 0:t.expires_at)&&(t.expires_at=new Date(t.expires_at))}catch(e){this.storage.removeItem(this.tokenSectionName),t=null}return t},t.prototype.setCredentials=function(t,e){var n;return Fe(this,void 0,Promise,function(){var r,o;return He(this,function(i){switch(i.label){case 0:return r=!(!this.credentials||!this.credentials.access_token),(null==t?void 0:t.expires_in)?((null==t?void 0:t.expires_at)||(t.expires_at=new Date(Date.now()+1e3*(t.expires_in-30))),this.storage?(o=JSON.stringify(t),[4,this.storage.setItem(this.tokenSectionName,o)]):[3,2]):[3,3];case 1:i.sent(),i.label=2;case 2:return this.credentials=t,[3,6];case 3:return this.storage?[4,this.storage.removeItem(this.tokenSectionName)]:[3,5];case 4:i.sent(),i.label=5;case 5:this.credentials=null,i.label=6;case 6:return this.onCredentialsChange&&this.onCredentialsChange(t||null,{isInit:null!==(n=null==e?void 0:e.isInit)&&void 0!==n&&n,hadCredentials:r}),[2]}})})},t.prototype.setAccessKeyCredentials=function(t){this.accessKeyCredentials=t,t.scope===Pe&&(this.credentials=t)},t.prototype.getCredentials=function(){return Fe(this,void 0,Promise,function(){var t=this;return He(this,function(e){return[2,this.singlePromise.run("getCredentials",function(){return Fe(t,void 0,void 0,function(){var t,e;return He(this,function(n){switch(n.label){case 0:return[4,this.getStorageCredentials()];case 1:return t=n.sent(),e=t.credentials,t.isAccessKeyCredentials?[2,e]:(this.credentials=e,[2,this.credentials])}})})})]})})},t.prototype.getStorageCredentials=function(){return Fe(this,void 0,Promise,function(){var t=this;return He(this,function(e){return[2,this.singlePromise.run("_getStorageCredentials",function(){return Fe(t,void 0,void 0,function(){var t,e,n;return He(this,function(r){switch(r.label){case 0:return t=null,e=!1,[4,this.storage.getItem(this.tokenSectionName)];case 1:if(!(n=r.sent()))return[3,6];r.label=2;case 2:return r.trys.push([2,3,,5]),(null==(t=JSON.parse(n))?void 0:t.expires_at)&&(t.expires_at=new Date(t.expires_at)),[3,5];case 3:return r.sent(),[4,this.storage.removeItem(this.tokenSectionName)];case 4:return r.sent(),t=null,[3,5];case 5:return[3,7];case 6:t=this.accessKeyCredentials||null,e=!0,r.label=7;case 7:return[2,{credentials:t,isAccessKeyCredentials:e}]}})})})]})})},t}(),Xe=function(){function t(e){var n,r=this;this.initializePromise=null,this.lockAcquired=!1,this.pendingInLock=[],this.singlePromise=null,this._initSessionEmitted=!1,e.clientSecret||(e.clientSecret=""),!e.clientId&&e.env&&(e.clientId=e.env),this.apiOrigin=e.apiOrigin,this.getApiOriginFunc=e.getApiOrigin,this.apiPath=e.apiPath||pe,this.clientId=e.clientId,this.i18n=e.i18n,this.eventBus=e.eventBus,this.singlePromise=new Ue({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,t.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=ze,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||Ye,this.localCredentials=new Qe({tokenSectionName:"credentials_".concat(e.clientId),storage:this.storage,clientId:e.clientId,onCredentialsChange:this._handleCredentialsChange.bind(this)}),this.clientSecret=e.clientSecret,e.clientId&&(this.basicAuth="Basic ".concat(function(t){for(var e,n,r,o,i="",s=0,a=(t=String(t)).length%3;s<t.length;){if((n=t.charCodeAt(s++))>255||(r=t.charCodeAt(s++))>255||(o=t.charCodeAt(s++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");i+=Le.charAt((e=n<<16|r<<8|o)>>18&63)+Le.charAt(e>>12&63)+Le.charAt(e>>6&63)+Le.charAt(63&e)}return a?i.slice(0,a-3)+"===".substring(a):i}("".concat(e.clientId,":").concat(this.clientSecret)))),this.wxCloud=e.wxCloud;try{qe()&&(this.useWxCloud=e.useWxCloud,void 0===this.wxCloud&&e.env&&(wx.cloud.init({env:e.env}),this.wxCloud=wx.cloud))}catch(t){}this.refreshTokenFunc=e.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=e.anonymousSignInFunc,this.onCredentialsError=e.onCredentialsError,this.getInitialSession=e.getInitialSession,this.onInitialSessionObtained=e.onInitialSessionObtained,this.logDebugMessages=null!==(n=e.debug)&&void 0!==n&&n,Z.on(tt,function(t){var e;r.i18n=(null===(e=t.data)||void 0===e?void 0:e.i18n)||r.i18n}),this._initBroadcastChannel(),this._initVisibilityListener()}return t.prototype.setGetInitialSession=function(t){this.getInitialSession=t},t.prototype.setOnInitialSessionObtained=function(t){this.onInitialSessionObtained=t},t.prototype.initialize=function(t){return Fe(this,void 0,Promise,function(){var e=this;return He(this,function(n){switch(n.label){case 0:return this.initializePromise?[4,this.initializePromise]:[3,2];case 1:case 3:case 5:return[2,n.sent()];case 2:return void 0===t?[3,4]:(this.initializePromise=t,[4,this.initializePromise]);case 4:return this.initializePromise=Fe(e,void 0,void 0,function(){var t=this;return He(this,function(e){switch(e.label){case 0:return[4,this._acquireLock(-1,function(){return Fe(t,void 0,void 0,function(){return He(this,function(t){switch(t.label){case 0:return[4,this._initialize()];case 1:return[2,t.sent()]}})})})];case 1:return[2,e.sent()]}})}),[4,this.initializePromise]}})})},t.prototype.setCredentials=function(t){return Fe(this,void 0,Promise,function(){var e=this;return He(this,function(n){switch(n.label){case 0:return[4,this.initializePromise];case 1:return n.sent(),[2,this._acquireLock(-1,function(){return Fe(e,void 0,void 0,function(){return He(this,function(e){return[2,this.localCredentials.setCredentials(t)]})})})]}})})},Object.defineProperty(t.prototype,"initSessionEmitted",{get:function(){return this._initSessionEmitted},enumerable:!1,configurable:!0}),t.prototype.destroy=function(){try{this.broadcastChannel&&"function"==typeof this.broadcastChannel.close&&this.broadcastChannel.close()}catch(t){this._debug("#destroy","close BroadcastChannel error",t)}finally{this.broadcastChannel=null}try{var t=this.visibilityEventHandler;this.visibilityEventHandler=void 0,t&&"undefined"!=typeof window&&"undefined"!=typeof document&&"function"==typeof window.removeEventListener&&window.removeEventListener("visibilitychange",t)}catch(t){this._debug("#destroy","remove visibility listener error",t)}},t.prototype.setAccessKeyCredentials=function(t){return this.localCredentials.setAccessKeyCredentials(t)},t.prototype.getAccessToken=function(){return Fe(this,void 0,Promise,function(){var t,e;return He(this,function(n){switch(n.label){case 0:return[4,this.initializePromise];case 1:return n.sent(),[4,this.getCredentials()];case 2:return(null==(t=n.sent())?void 0:t.scope)===Pe||(null==t?void 0:t.access_token)?[2,Promise.resolve(t.access_token)]:(e={error:he.UNAUTHENTICATED},[2,Promise.reject(e)])}})})},t.prototype.request=function(e,n){var r,o;return Fe(this,void 0,Promise,function(){var i,s,a,c,u,l,h,d,f,p;return He(this,function(v){switch(v.label){case 0:return n||(n={}),i=this.formatRetry(n.retry,this.retry),n.headers=We(We({},n.headers),((p={})[null===(r=this.i18n)||void 0===r?void 0:r.LANG_HEADER_KEY]=null===(o=this.i18n)||void 0===o?void 0:o.lang,p)),this.headers&&(n.headers=We(We({},this.headers),n.headers)),n.headers[Ge]||(n.headers[Ge]=Re()),n.headers[Ke]?[3,2]:[4,this.getDeviceId()];case 1:s=v.sent(),n.headers[Ke]=s,v.label=2;case 2:return(null==n?void 0:n.withBasicAuth)&&this.basicAuth&&(n.headers.Authorization=this.basicAuth),(null==n?void 0:n.withCredentials)?n.getCredentials?[4,n.getCredentials()]:[3,4]:[3,7];case 3:return c=v.sent(),[3,6];case 4:return[4,this.getCredentials()];case 5:c=v.sent(),v.label=6;case 6:return(a=c)&&(this.tokenInURL?(e.indexOf("?")<0&&(e+="?"),e+="access_token=".concat(a.access_token)):n.headers.Authorization="".concat(a.token_type," ").concat(a.access_token)),[3,8];case 7:this.clientId&&e.indexOf("client_id")<0&&(e+=e.indexOf("?")<0?"?":"&",e+="client_id=".concat(this.clientId)),v.label=8;case 8:e.startsWith("/")&&(u=this.getApiOriginFunc?this.getApiOriginFunc():this.apiOrigin,e="".concat(u).concat(this.apiPath).concat(e)),l=null,h=i+1,d=0,v.label=9;case 9:if(!(d<h))return[3,21];v.label=10;case 10:return v.trys.push([10,15,,18]),n.useWxCloud||this.useWxCloud?[4,this.wxCloudCallFunction(e,n)]:[3,12];case 11:return l=v.sent(),[3,14];case 12:return[4,this.baseRequest(e,n)];case 13:l=v.sent(),v.label=14;case 14:if(null==l?void 0:l.code)throw{error:l.code,error_description:l.message,error_uri:new URL(e).pathname};return[3,21];case 15:f=v.sent();try{f.requestId=f.requestId||n.headers[Ge]||""}catch(t){}return n.withCredentials&&f&&f.error===he.UNAUTHENTICATED?[4,this.setCredentials(null)]:[3,17];case 16:return v.sent(),[2,Promise.reject(f)];case 17:return d!==i&&f&&"unreachable"===f.error?[3,18]:[2,Promise.reject(f)];case 18:return[4,this.sleep(t.retryInterval)];case 19:v.sent(),v.label=20;case 20:return d++,[3,9];case 21:return[2,l]}})})},t.prototype.wxCloudCallFunction=function(t,e){var n;return Fe(this,void 0,Promise,function(){var r,o,i,s,a;return He(this,function(c){switch(c.label){case 0:r=null,o=null,c.label=1;case 1:c.trys.push([1,7,,8]),i="",c.label=2;case 2:return c.trys.push([2,4,,5]),[4,wx.getRendererUserAgent()];case 3:return i=c.sent(),[3,5];case 4:return c.sent(),[3,5];case 5:return[4,this.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:t,method:e.method,headers:We({origin:"https://servicewechat.com","User-Agent":i},e.headers),body:e.body}})];case 6:return s=c.sent().result,(null===(n=null==s?void 0:s.body)||void 0===n?void 0:n.error_code)?(o=null==s?void 0:s.body).error_uri=(0,Ce.y)(t):r=null==s?void 0:s.body,[3,8];case 7:return a=c.sent(),o={error:he.UNREACHABLE,error_description:a.message,error_uri:(0,Ce.y)(t)},[3,8];case 8:if(o)throw o;return[2,r]}})})},t.prototype.getCredentials=function(){return Fe(this,void 0,Promise,function(){var t=this;return He(this,function(e){switch(e.label){case 0:return[4,this.initializePromise];case 1:return e.sent(),[2,this._acquireLock(-1,function(){return Fe(t,void 0,void 0,function(){return He(this,function(t){return[2,this._getCredentials()]})})})]}})})},t.prototype.getCredentialsSync=function(){return this.localCredentials.getStorageCredentialsSync()},t.prototype.getCredentialsAsync=function(){return this.getCredentials()},t.prototype.getScope=function(){var t;return Fe(this,void 0,Promise,function(){var e,n;return He(this,function(r){switch(r.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return(e=r.sent())?[2,e.scope]:(n="credentials not found",null===(t=this.onCredentialsError)||void 0===t||t.call(this,{msg:n}),[2,this.unAuthenticatedError(n)])}})})},t.prototype.getGroups=function(){var t;return Fe(this,void 0,Promise,function(){var e,n;return He(this,function(r){switch(r.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return(e=r.sent())?[2,e.groups]:(n="credentials not found",null===(t=this.onCredentialsError)||void 0===t||t.call(this,{msg:n}),[2,this.unAuthenticatedError(n)])}})})},t.prototype.refreshToken=function(t,e){return Fe(this,void 0,Promise,function(){var n=this;return He(this,function(r){switch(r.label){case 0:return[4,this.initializePromise];case 1:return r.sent(),[2,this._acquireLock(-1,function(){return Fe(n,void 0,void 0,function(){return He(this,function(n){return[2,this._refreshToken(t,e)]})})})]}})})},t.prototype._refreshToken=function(t,e){return Fe(this,void 0,Promise,function(){var n=this;return He(this,function(r){return[2,this.singlePromise.run("_refreshToken",function(){return Fe(n,void 0,void 0,function(){var n,r,o,i,s,a;return He(this,function(c){switch(c.label){case 0:if((null==t?void 0:t.scope)===Pe)return[2,t];if(!t||!t.refresh_token)return o="no refresh token found in credentials",null===(i=this.onCredentialsError)||void 0===i||i.call(this,{msg:o}),[2,this.unAuthenticatedError(o)];c.label=1;case 1:return c.trys.push([1,4,,7]),[4,this.refreshTokenFunc(t.refresh_token,t)];case 2:return n=c.sent(),[4,this.localCredentials.setCredentials(n)];case 3:return c.sent(),[2,n];case 4:if(r=c.sent(),null==e?void 0:e.throwError)throw r;return r.error!==he.INVALID_GRANT?[3,6]:[4,this.localCredentials.setCredentials(null)];case 5:return c.sent(),o=r.error_description,null===(s=this.onCredentialsError)||void 0===s||s.call(this,{msg:o}),[2,this.unAuthenticatedError(o)];case 6:return null===(a=this.onCredentialsError)||void 0===a||a.call(this,{msg:r.error_description}),[2,Promise.reject(r)];case 7:return[2]}})})})]})})},t.prototype.anonymousLogin=function(t){return Fe(this,void 0,void 0,function(){var e=this;return He(this,function(n){return[2,this.singlePromise.run("_anonymousLogin",function(){return Fe(e,void 0,void 0,function(){var e,n;return He(this,function(r){switch(r.label){case 0:return this.anonymousSignInFunc?[4,this.anonymousSignInFunc(t)]:[3,4];case 1:return e=r.sent(),(n=e)?[3,3]:[4,this.localCredentials.getCredentials()];case 2:n=r.sent(),r.label=3;case 3:return t=n,[3,6];case 4:return[4,this.anonymousSignIn(t)];case 5:t=r.sent(),r.label=6;case 6:return[2,t]}})})})]})})},t.prototype.checkRetry=function(e){var n=null;if(("number"!=typeof e||e<t.minRetry||e>t.maxRetry)&&(n={error:he.UNREACHABLE,error_description:"wrong options param: retry"}),n)throw n;return e},t.prototype.formatRetry=function(t,e){return void 0===t?e:this.checkRetry(t)},t.prototype.sleep=function(t){return Fe(this,void 0,Promise,function(){return He(this,function(e){return[2,new Promise(function(e){setTimeout(function(){e()},t)})]})})},t.prototype.anonymousSignIn=function(t){return Fe(this,void 0,Promise,function(){var e=this;return He(this,function(n){return[2,this.singlePromise.run("_anonymous",function(){return Fe(e,void 0,void 0,function(){var e,n;return He(this,function(r){switch(r.label){case 0:if(!t||"anonymous"!==t.scope)return[2,this.unAuthenticatedError("no anonymous in credentials")];r.label=1;case 1:return r.trys.push([1,4,,7]),[4,this.request(ce.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}})];case 2:return e=r.sent(),[4,this.localCredentials.setCredentials(e)];case 3:return r.sent(),[2,e];case 4:return(n=r.sent()).error!==he.INVALID_GRANT?[3,6]:[4,this.localCredentials.setCredentials(null)];case 5:return r.sent(),[2,this.unAuthenticatedError(n.error_description)];case 6:return[2,Promise.reject(n)];case 7:return[2]}})})})]})})},t.prototype.defaultRefreshTokenFunc=function(t,e){var n;return Fe(this,void 0,Promise,function(){var r,o,i;return He(this,function(s){switch(s.label){case 0:return void 0===t||""===t?(r="refresh token not found",null===(n=this.onCredentialsError)||void 0===n||n.call(this,{msg:r}),[2,this.unAuthenticatedError(r)]):(o=ce.AUTH_TOKEN_URL,"v2"===(null==e?void 0:e.version)&&(o=ue.AUTH_TOKEN_URL),[4,this.request(o,{method:"POST",body:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"refresh_token",refresh_token:t}})]);case 1:return i=s.sent(),[2,We(We({},i),{version:(null==e?void 0:e.version)||"v1"})]}})})},t.prototype.getDeviceId=function(){return Fe(this,void 0,Promise,function(){var t;return He(this,function(e){switch(e.label){case 0:return this.deviceID?[2,this.deviceID]:[4,this.storage.getItem(Je)];case 1:return"string"==typeof(t=e.sent())&&t.length>=16&&t.length<=48?[3,3]:(t=Re(),[4,this.storage.setItem(Je,t)]);case 2:e.sent(),e.label=3;case 3:return this.deviceID=t,[2,t]}})})},t.prototype.unAuthenticatedError=function(t){var e={error:he.UNAUTHENTICATED,error_description:t};return Promise.reject(e)},t.prototype._debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this.logDebugMessages&&console.log.apply(console,Ve(["[OAuth2Client]"],t,!1))},t.prototype._initialize=function(){return Fe(this,void 0,Promise,function(){var t,e,n,r,o,i;return He(this,function(s){switch(s.label){case 0:if(s.trys.push([0,11,12,13]),!this.getInitialSession)return this._debug("#_initialize()","no getInitialSession callback set, skipping"),[2,{error:null}];this._debug("#_initialize()","calling getInitialSession callback"),s.label=1;case 1:return s.trys.push([1,9,,10]),[4,this.getInitialSession()];case 2:return i=s.sent(),t=i.data,e=i.error,(null==t?void 0:t.session)?(this._debug("#_initialize()","session obtained from getInitialSession",t.session),this._initSessionEmitted=!0,[4,this.localCredentials.setCredentials(null==t?void 0:t.session,{isInit:!0})]):[3,4];case 3:s.sent(),s.label=4;case 4:if(!this.onInitialSessionObtained)return[3,8];this._debug("#_initialize()","calling onInitialSessionObtained callback"),s.label=5;case 5:return s.trys.push([5,7,,8]),[4,this.onInitialSessionObtained(t,e)];case 6:return s.sent(),[3,8];case 7:return n=s.sent(),this._debug("#_initialize()","error in onInitialSessionObtained",n),[3,8];case 8:return e?(this._debug("#_initialize()","error from getInitialSession",e),[2,{error:e}]):[2,{error:null}];case 9:return r=s.sent(),this._debug("#_initialize()","exception during getInitialSession",r),[2,{error:r instanceof Error?r:new Error(String(r))}];case 10:return[3,13];case 11:return o=s.sent(),this._debug("#_initialize()","unexpected error",o),[2,{error:o instanceof Error?o:new Error(String(o))}];case 12:return this._debug("#_initialize()","end"),[7];case 13:return[2]}})})},t.prototype._acquireLock=function(t,e){return Fe(this,void 0,Promise,function(){var n,r,o,i,s=this;return He(this,function(a){switch(a.label){case 0:this._debug("#_acquireLock","begin",t),a.label=1;case 1:if(a.trys.push([1,,10,11]),this.lockAcquired)return n=this.pendingInLock.length?this.pendingInLock[this.pendingInLock.length-1]:Promise.resolve(),r=Fe(s,void 0,void 0,function(){return He(this,function(t){switch(t.label){case 0:return[4,n];case 1:return t.sent(),[4,e()];case 2:return[2,t.sent()]}})}),this.pendingInLock.push(Fe(s,void 0,void 0,function(){return He(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,r];case 1:case 2:return t.sent(),[3,3];case 3:return[2]}})})),[2,r];this._debug("#_acquireLock","acquiring lock for client",this.clientId),a.label=2;case 2:return a.trys.push([2,,8,9]),this.lockAcquired=!0,o=e(),this.pendingInLock.push(Fe(s,void 0,void 0,function(){return He(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,o];case 1:case 2:return t.sent(),[3,3];case 3:return[2]}})})),[4,o];case 3:a.sent(),a.label=4;case 4:return this.pendingInLock.length?(i=Ve([],this.pendingInLock,!0),[4,Promise.all(i)]):[3,6];case 5:return a.sent(),this.pendingInLock.splice(0,i.length),[3,4];case 6:return[4,o];case 7:return[2,a.sent()];case 8:return this._debug("#_acquireLock","releasing lock for client",this.clientId),this.lockAcquired=!1,[7];case 9:return[3,11];case 10:return this._debug("#_acquireLock","end"),[7];case 11:return[2]}})})},t.prototype._getCredentials=function(){var t,e,n;return Fe(this,void 0,Promise,function(){var r,o,i;return He(this,function(s){switch(s.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:if((null==(r=s.sent())?void 0:r.scope)===Pe)return[2,r];if(!r)return i="credentials not found",null===(t=this.onCredentialsError)||void 0===t||t.call(this,{msg:i}),[2,this.unAuthenticatedError(i)];if(!function(t){var e=!0;return(null==t?void 0:t.expires_at)&&(null==t?void 0:t.access_token)&&(e=t.expires_at<new Date),e}(r))return[3,12];if(!r.refresh_token)return[3,9];s.label=2;case 2:return s.trys.push([2,4,,8]),[4,this._refreshToken(r)];case 3:return r=s.sent(),[3,8];case 4:return o=s.sent(),"anonymous"!==r.scope?[3,6]:[4,this.anonymousLogin(r)];case 5:return r=s.sent(),[3,7];case 6:return null===(e=this.onCredentialsError)||void 0===e||e.call(this,{msg:o.error_description}),[2,Promise.reject(o)];case 7:return[3,8];case 8:return[3,12];case 9:return"anonymous"!==r.scope?[3,11]:[4,this.anonymousLogin(r)];case 10:return r=s.sent(),[3,12];case 11:return i="no refresh token found in credentials",null===(n=this.onCredentialsError)||void 0===n||n.call(this,{msg:i}),[2,this.unAuthenticatedError(i)];case 12:return[2,r]}})})},t.prototype._isUserCredentials=function(t){return!!(null==t?void 0:t.access_token)&&"accessKey"!==t.scope&&t.scope!==Pe},t.prototype._fireCredentialsEvents=function(t,e,n){var r,o,i,s,a,c;this._isUserCredentials(t)?e?null===(i=this.eventBus)||void 0===i||i.fire(Oe,{event:we}):n?null===(s=this.eventBus)||void 0===s||s.fire(Oe,{event:_e}):(null===(a=this.eventBus)||void 0===a||a.fire(Oe,{event:be}),null===(c=this.eventBus)||void 0===c||c.fire(Se,{eventType:"sign_in"})):n&&(null===(r=this.eventBus)||void 0===r||r.fire(Oe,{event:me}),null===(o=this.eventBus)||void 0===o||o.fire(Se,{eventType:"sign_out"}))},t.prototype._handleCredentialsChange=function(t,e){this._fireCredentialsEvents(t,e.isInit,e.hadCredentials),this._broadcastCredentials(t,e)},t.prototype._initBroadcastChannel=function(){var t=this;if(void 0===this.broadcastChannel)try{"undefined"!=typeof BroadcastChannel&&(this.broadcastChannelName="credentials_".concat(this.clientId),this.broadcastChannel=new BroadcastChannel(this.broadcastChannelName),this.broadcastChannel.addEventListener("message",function(e){t._handleBroadcastMessage(e.data)}),this._debug("#_initBroadcastChannel","channel created: ".concat(this.broadcastChannelName)))}catch(t){this.broadcastChannel=null,this._debug("#_initBroadcastChannel","BroadcastChannel not available, skip",t)}},t.prototype._broadcastCredentials=function(t,e){if(this.broadcastChannel)try{this.broadcastChannel.postMessage({type:"credentials_changed",credentials:t,context:e})}catch(t){this._debug("#_broadcastCredentials","postMessage error",t)}},t.prototype._handleBroadcastMessage=function(t){var e,n;try{if(!t||"credentials_changed"!==t.type)return;var r=t.context,o=t.credentials;if((null==o?void 0:o.expires_at)&&"string"==typeof o.expires_at&&(o=We(We({},o),{expires_at:new Date(o.expires_at)})),(null==o?void 0:o.access_token)===(null===(e=this.localCredentials.getMemoryCredentials())||void 0===e?void 0:e.access_token))return;var i=!!(null===(n=this.localCredentials.getMemoryCredentials())||void 0===n?void 0:n.access_token);this.localCredentials.syncMemoryCredentials(o),this._fireCredentialsEvents(o,r.isInit,i)}catch(t){this._debug("#_handleBroadcastMessage","error",t)}},t.prototype._initVisibilityListener=function(){var t=this;try{if("undefined"==typeof window||"undefined"==typeof document||"function"!=typeof window.addEventListener)return;this.visibilityEventHandler=function(){return Fe(t,void 0,void 0,function(){var t;return He(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this._onVisibilityChanged()];case 1:return e.sent(),[3,3];case 2:return t=e.sent(),this._debug("#visibilityChangedCallback","error",t),[3,3];case 3:return[2]}})})},window.addEventListener("visibilitychange",this.visibilityEventHandler)}catch(t){this._debug("#_initVisibilityListener",t)}},t.prototype._onVisibilityChanged=function(){return Fe(this,void 0,Promise,function(){var t=this;return He(this,function(e){return"visible"!==document.visibilityState||this._acquireLock(-1,function(){return Fe(t,void 0,void 0,function(){var t,e,n,r,o,i;return He(this,function(s){switch(s.label){case 0:if("visible"!==document.visibilityState)return[2];s.label=1;case 1:return s.trys.push([1,3,,4]),t=this.localCredentials.getMemoryCredentials(),[4,this.localCredentials.getCredentials()];case 2:return e=s.sent(),n=null==t?void 0:t.access_token,r=null==e?void 0:e.access_token,n===r?[2]:(o=!!n,this._fireCredentialsEvents(e,!1,o),[3,4]);case 3:return i=s.sent(),this._debug("#_onVisibilityChanged","reload credentials error",i),[3,4];case 4:return[2]}})})}),[2]})})},t.defaultRetry=2,t.minRetry=0,t.maxRetry=5,t.retryInterval=1e3,t}(),Ze=l(9689),tn=l(3616),en=function(){return en=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},en.apply(this,arguments)},nn=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},rn=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},on=function(t,e){var n;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];clearTimeout(n),n=setTimeout(function(){return t.apply(null,r)},e)}},sn=new Ze.CloudbaseEventEmitter,an="resolveCaptchaData",cn="padding:10px 8px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer;flex:1;white-space:nowrap;margin-left:10px",un="width:100%;padding:10px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer",ln="background:#6c757d;cursor:not-allowed",hn=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},dn=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},fn=function(){function t(t){t.openURIWithCallback||(t.openURIWithCallback=this.getDefaultOpenURIWithCallback()),t.storage||(t.storage=Ye),this.config=t,this.tokenSectionName="captcha_".concat(t.clientId||t.env)}return t.prototype.isMatch=function(){var t,e,n;return(null===(n=null===(e=null===(t=this.config)||void 0===t?void 0:t.adapter)||void 0===e?void 0:e.isMatch)||void 0===n?void 0:n.call(e))||qe()},t.prototype.request=function(t,e){return hn(this,void 0,Promise,function(){var n,r,o,i;return dn(this,function(s){switch(s.label){case 0:return e||(e={}),e.method||(e.method="GET"),n="".concat(e.method,":").concat(t),r=t,e.withCaptcha?[4,this.appendCaptchaTokenToURL(t,n,!1)]:[3,2];case 1:r=s.sent(),s.label=2;case 2:return s.trys.push([2,4,,7]),[4,this.config.request(r,e)];case 3:return o=s.sent(),[3,7];case 4:return(i=s.sent()).error!==he.CAPTCHA_REQUIRED&&i.error!==he.CAPTCHA_INVALID?[3,6]:[4,this.appendCaptchaTokenToURL(t,n,i.error===he.CAPTCHA_INVALID)];case 5:return t=s.sent(),[2,this.config.request(t,e)];case 6:return[2,Promise.reject(i)];case 7:return[2,o]}})})},t.prototype.getDefaultOpenURIWithCallback=function(){var t=this;return function(e){return function(t,e){return nn(void 0,void 0,Promise,function(){var n,r,o,i;return rn(this,function(s){return n=(0,tn.parseCaptcha)(t),r=n.captchaData,o=n.state,i=n.token,function(t){var e=t.oauthInstance,n=t.captchaState,r="captcha-image",o=function(){return nn(void 0,void 0,void 0,function(){var t,o;return rn(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,e.createCaptchaData({state:n.state})];case 1:return t=i.sent(),n=en(en({},n),{captchaData:t.data,token:t.token}),document.getElementById(r).src=t.data,[3,3];case 2:return o=i.sent(),console.error("刷新图形验证码失败",o),[3,3];case 3:return[2]}})})},i=function(t,e,n){var r=document.createElement(t);return e&&(r.style.cssText=e),n&&(r.textContent=n),r},s=i("div","position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:999"),a=i("div","position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:320px;padding:20px;background:#fff;border-radius:8px;box-shadow:0 0 10px rgba(0,0,0,0.2);z-index:1000");a.appendChild(i("p","margin-bottom:15px","请输入你看到的字符:"));var c=i("div","display:flex;align-items:center;justify-content:space-between;margin-bottom:15px"),u=i("img","width:100%;height:auto;border:1px solid #eee");u.id=r,u.src=n.captchaData,c.appendChild(u);var l=i("button",cn,"刷新");l.onclick=on(function(){return nn(void 0,void 0,void 0,function(){return rn(this,function(t){switch(t.label){case 0:l.textContent="加载中...",l.disabled=!0,l.style.cssText="".concat(cn,";").concat(ln),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,o()];case 2:return t.sent(),[3,4];case 3:return l.textContent="刷新",l.disabled=!1,l.style.cssText=cn,[7];case 4:return[2]}})})},500),c.appendChild(l),a.appendChild(c);var h=i("input","width:100%;padding:14px 16px;margin-bottom:15px;box-sizing:border-box;border:2px solid #e8ecf4;border-radius:10px;font-size:15px");h.type="text",h.placeholder="输入字符",h.maxLength=4,a.appendChild(h);var d=i("div","color:#dc3545;font-size:12px;margin-bottom:10px;display:none;padding:8px;background:#f8d7da;border:1px solid #f5c6cb;border-radius:4px");a.appendChild(d);var f=function(t){d.textContent=t,d.style.display="block"},p=i("button",un,"确定");p.onclick=on(function(){return nn(void 0,void 0,void 0,function(){var t,r,i,c;return rn(this,function(u){switch(u.label){case 0:if(!(t=h.value.trim()))return f("请输入字符"),[2];d.style.display="none",p.textContent="验证中...",p.disabled=!0,p.style.cssText="".concat(un,";").concat(ln),u.label=1;case 1:return u.trys.push([1,3,5,6]),[4,e.verifyCaptchaData({token:n.token,key:t})];case 2:return r=u.sent(),sn.fire(an,r),console.log("图形验证码校验成功"),document.body.removeChild(s),document.body.removeChild(a),[3,6];case 3:return i=u.sent(),console.error("图形验证码校验失败",i),c=i.error_description||"图形验证码校验失败",f(c),h.value="",h.focus(),[4,o()];case 4:return u.sent(),[3,6];case 5:return p.textContent="确定",p.disabled=!1,p.style.cssText=un,[7];case 6:return[2]}})})},500),a.appendChild(p),document.body.appendChild(s),document.body.appendChild(a)}({oauthInstance:e,captchaState:{captchaData:r,state:o,token:i}}),[2,new Promise(function(t){console.log("等待图形验证码校验结果..."),sn.on(an,function(e){t(null==e?void 0:e.data)})})]})})}(e,t.config.oauthInstance)}},t.prototype.getCaptchaToken=function(t,e){return hn(this,void 0,Promise,function(){var n,r,o,i;return dn(this,function(s){switch(s.label){case 0:return t?[3,2]:[4,this.findCaptchaToken()];case 1:if(n=s.sent())return[2,n];s.label=2;case 2:return[4,this.config.request(ce.CAPTCHA_DATA_URL,{method:"POST",body:{state:e,redirect_uri:""},withCredentials:!1})];case 3:return r=s.sent(),o="".concat(r.data,"?state=").concat(encodeURIComponent(e),"&token=").concat(encodeURIComponent(r.token)),[4,this.config.openURIWithCallback(o)];case 4:return i=s.sent(),this.saveCaptchaToken(i),[2,i.captcha_token]}})})},t.prototype.appendCaptchaTokenToURL=function(t,e,n){return hn(this,void 0,Promise,function(){var r;return dn(this,function(o){switch(o.label){case 0:return[4,this.getCaptchaToken(n,e)];case 1:return r=o.sent(),t.indexOf("?")>0?t+="&captcha_token=".concat(r):t+="?captcha_token=".concat(r),[2,t]}})})},t.prototype.saveCaptchaToken=function(t){return hn(this,void 0,void 0,function(){var e;return dn(this,function(n){switch(n.label){case 0:return t.expires_at=new Date(Date.now()+1e3*(t.expires_in-10)),e=JSON.stringify(t),[4,this.config.storage.setItem(this.tokenSectionName,e)];case 1:return n.sent(),[2]}})})},t.prototype.findCaptchaToken=function(){return hn(this,void 0,Promise,function(){var t,e;return dn(this,function(n){switch(n.label){case 0:return[4,this.config.storage.getItem(this.tokenSectionName)];case 1:if(null==(t=n.sent()))return[3,5];n.label=2;case 2:return n.trys.push([2,3,,5]),(null==(e=JSON.parse(t))?void 0:e.expires_at)&&(e.expires_at=new Date(e.expires_at)),e.expires_at<new Date?[2,null]:[2,e.captcha_token];case 3:return n.sent(),[4,this.config.storage.removeItem(this.tokenSectionName)];case 4:return n.sent(),[2,null];case 5:return[2,null]}})})},t}(),pn=function(){function t(t){if(this.params={},"string"==typeof t)this.parse(t);else if(t&&"object"==typeof t)for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&this.append(e,t[e])}return t.prototype.parse=function(t){var e=this;t.split("&").forEach(function(t){var n=t.split("=").map(decodeURIComponent),r=n[0],o=n[1];e.append(r,o)})},t.prototype.append=function(t,e){this.params[t]?this.params[t]=this.params[t].concat([e]):this.params[t]=[e]},t.prototype.get=function(t){return this.params[t]?this.params[t][0]:null},t.prototype.getAll=function(t){return this.params[t]||[]},t.prototype.delete=function(t){delete this.params[t]},t.prototype.has=function(t){return Object.prototype.hasOwnProperty.call(this.params,t)},t.prototype.set=function(t,e){this.params[t]=[e]},t.prototype.toString=function(){var t=[],e=function(e){Object.prototype.hasOwnProperty.call(n.params,e)&&n.params[e].forEach(function(n){t.push("".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(n)))})},n=this;for(var r in this.params)e(r);return t.join("&")},t}();const vn=pn;var yn,gn=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();!function(t){t.PROVIDER_NOT_ENABLED="PROVIDER_NOT_ENABLED",t.INVALID_CREDENTIALS="INVALID_CREDENTIALS",t.USER_NOT_FOUND="USER_NOT_FOUND",t.USER_STATUS_ABNORMAL="USER_STATUS_ABNORMAL",t.SERVICE_ERROR="SERVICE_ERROR",t.INVALID_PARAMS="INVALID_PARAMS",t.AUTH_METHOD_MISMATCH="AUTH_METHOD_MISMATCH",t.RATE_LIMITED="RATE_LIMITED",t.CAPTCHA_REQUIRED="CAPTCHA_REQUIRED",t.CAPTCHA_INVALID="CAPTCHA_INVALID",t.MFA_REQUIRED="MFA_REQUIRED",t.PRECONDITION_FAILED="PRECONDITION_FAILED",t.VERIFICATION_FAILED="VERIFICATION_FAILED",t.UNKNOWN="UNKNOWN"}(yn||(yn={}));var mn="https://tcb.cloud.tencent.com/dev?envId=#/identity/login-manage",bn="https://docs.cloudbase.net/api-reference/webv3/initialization";function wn(t,e){var n=(null==e?void 0:e.method)||"signIn",r={signInWithPassword:"「用户名密码登录」",signInAnonymously:"「匿名登录」",signInWithOtp:"「短信验证码登录」或「邮箱验证码登录」",signUp:"「短信验证码登录」或「邮箱验证码登录」",signInWithOAuth:"对应的第三方身份源",signInWithIdToken:"对应的第三方身份源",signInWithOpenId:"「微信小程序 OpenID 登录」",signInWithPhoneAuth:"「微信小程序手机号授权登录」",signInWithCustomTicket:"「自定义登录」",getVerification:"「短信验证码登录」或「邮箱验证码登录」",verify:"「短信验证码登录」或「邮箱验证码登录」",verifyOtp:"「短信验证码登录」或「邮箱验证码登录」",resetPasswordForEmail:"「邮箱验证码登录」",reauthenticate:"「短信验证码登录」或「邮箱验证码登录」"}[n]||"对应的登录方式";switch(t){case yn.PROVIDER_NOT_ENABLED:return"[CloudBase Auth] 登录方式未开启\n\n"+" 当前调用的 ".concat(n,"() 所需的登录方式尚未在云开发控制台启用。\n")+" 需要开启的登录方式:".concat(r,"\n")+"\n 请按以下步骤开启:\n"+" 1. 打开云开发控制台:".concat(mn,"\n")+" 2. 选择对应的云开发环境\n 3. 进入「登录授权」页面,在「登录方式」或「身份源列表」中开启所需的登录方式\n\n 各登录方法与所需登录方式的对应关系:\n - signInWithPassword → 「用户名密码登录」\n - signInAnonymously → 「匿名登录」\n - signInWithOtp/signUp → 「短信验证码登录」或「邮箱验证码登录」\n - signInWithOAuth/signInWithIdToken → 对应的第三方身份源\n\n 如使用 CLI/MCP 工具,可通过 auth 工具查询和配置身份源状态。\n"+" 更多帮助请参考文档:".concat(bn);case yn.INVALID_CREDENTIALS:return"[CloudBase Auth] 凭据验证失败\n\n"+" 调用 ".concat(n,"() 时凭据校验未通过。\n")+"\n 请按优先级逐项排查:\n 1. 确认用户名/邮箱/手机号是否拼写正确、格式完整\n 2. 确认密码是否正确(注意大小写、特殊字符、前后空格)\n 3. 确认用户账号确实存在(可通过 auth.isUsernameRegistered() 检查)\n 4. 确认凭据参数来源可靠(环境变量、配置文件中的值是否已正确设置)\n 5. 如使用加密登录(is_encrypt: true),请确认公钥版本正确\n\n 如忘记密码,可通过 auth.resetPasswordForEmail() 重置密码。\n\n 提示:如果是 AI agent / 自动化测试场景,请确认 ENV_ID、USERNAME、PASSWORD\n 等环境变量已正确传入,且对应用户已在目标环境中注册。";case yn.USER_NOT_FOUND:return"[CloudBase Auth] 用户不存在\n\n 请检查以下项目:\n 1. 确认用户名/邮箱/手机号是否正确\n 2. 确认是在正确的云开发环境(envId)下操作\n 3. 如果是新用户,请先通过 auth.signUp() 注册\n"+" 4. 也可在云开发控制台手动创建用户:".concat(mn,"\n")+"\n 提示:不同环境(开发/测试/生产)的用户库是隔离的,请确认 envId 正确。";case yn.USER_STATUS_ABNORMAL:return"[CloudBase Auth] 用户状态异常\n\n 当前用户账号可能处于以下状态之一:\n - 账号已被封禁\n - 账号正在审核中\n - 账号已被锁定(多次密码错误)\n\n"+" 请联系管理员在云开发控制台检查用户状态:".concat(mn);case yn.SERVICE_ERROR:return"[CloudBase Auth] 服务异常\n\n 请检查以下项目:\n 1. 网络连接是否正常\n 2. 云开发环境是否正常运行\n 3. 稍后重试,如持续失败请联系技术支持\n\n 提示:如果是超时错误,请检查网络环境和请求频率。\n 常见服务端错误:smtp 未配置、短信服务未配置、wedaapis 未设置等。";case yn.INVALID_PARAMS:if((null==e?void 0:e.errorCode)===de.MISSING_REQUIRED_PARAM||(null==e?void 0:e.code)===he.MISSING_REQUIRED_PARAM){var o=["verifyOtp","signInWithOtp","signUp"].includes(n)?"\n 若在校验验证码阶段缺参:\n - 独立调用 auth.verifyOtp() 时 messageId 为必填,请补上 params.messageId。\n - 推荐改用发码接口返回的回调(SDK 会自动携带 messageId):\n const { data } = await auth.signInWithOtp({ phone })\n await data.verifyOtp({ token })\n // 或 auth.signUp({ phone }) 返回的 data.verifyOtp\n":"";return"[CloudBase Auth] 缺少必填参数\n\n"+" 调用 auth.".concat(n,"() 时缺少必填参数。\n")+" 这是客户端入参问题,不是控制台通道配置问题。\n\n 修复方式:\n"+" 1. 查看 error.message 中的参数路径,补上缺失字段。\n".concat(o,"\n 参考 API 文档确认各参数的格式和约束:").concat(bn)}return"[CloudBase Auth] 参数错误\n\n 请检查传入的参数是否符合要求:\n - 不能同时输入手机号和邮箱\n - 手机号格式需正确(如 +86 开头)\n - 必须提供手机号或邮箱\n\n"+" 参考 API 文档确认各参数的格式和约束:".concat(bn);case yn.AUTH_METHOD_MISMATCH:return"[CloudBase Auth] 登录方式不匹配\n\n"+" 调用 ".concat(n,"() 时遇到错误,可能原因:\n")+" - 匿名登录失败后尝试了用户名密码登录,但凭据不正确或用户不存在\n - 应使用匿名登录但传入了密码参数\n - 应使用密码登录但未传入正确的凭据\n\n 建议:\n 1. 明确当前场景需要的登录方式:\n - 无需用户注册 → auth.signInAnonymously()\n - 有用户名和密码 → auth.signInWithPassword({ username, password })\n - 第三方平台 → auth.signInWithOAuth({ provider })\n 2. 不要在同一流程中混合使用不同的登录方式\n 3. 每种登录方式需要在控制台开启对应的身份源\n"+" 4. 控制台地址:".concat(mn);case yn.RATE_LIMITED:return"[CloudBase Auth] 发送频率受限\n\n 验证码发送过于频繁,已触发频率限制。\n\n 限制规则:\n - 手机号:每分钟最多 1 条,每天有上限\n - 邮箱:每分钟有上限,每天有上限(默认 50 条)\n\n 建议:\n 1. 检查 error.retryAfter 获取建议等待时间\n 2. 在 UI 中显示倒计时,防止用户重复点击\n 3. 如业务需要更高频率,请联系技术支持调整限额";case yn.CAPTCHA_REQUIRED:return"[CloudBase Auth] 需要滑块验证码\n\n 当前操作触发了风控策略,需要完成滑块验证。\n\n 处理方式:\n 1. 调用滑块验证码 SDK 展示验证组件\n 2. 用户完成验证后,将 captcha_token 附带到请求中重新发送\n 3. 可通过 getVerification 的 options.withCaptcha 参数自动携带验证码";case yn.CAPTCHA_INVALID:return"[CloudBase Auth] 滑块验证码校验失败\n\n 提交的验证码 token 校验未通过(可能已过期或 client_id 不匹配)。\n\n 处理方式:\n 1. 刷新滑块验证码,让用户重新验证\n 2. 确认 captcha 组件初始化的 client_id 与认证配置一致";case yn.MFA_REQUIRED:return"[CloudBase Auth] 需要 MFA 验证\n\n 当前操作要求用户绑定手机号进行多因素认证 (MFA)。\n\n 处理方式:\n 1. 引导用户进入手机号绑定流程\n 2. 绑定完成后重新执行原操作\n 3. error 中可能包含 MFA 详情信息";case yn.PRECONDITION_FAILED:return"[CloudBase Auth] 前置条件不满足\n\n 当前操作的前置条件不满足,常见原因:\n - 该手机号/邮箱已被其他账号绑定\n - 目标用户不存在或已存在(与 target 参数冲突)\n - 当前邮箱/手机号未注册用户\n\n 请根据 error.message 中的具体描述处理。";case yn.VERIFICATION_FAILED:return'[CloudBase Auth] 验证码校验失败\n\n 验证码验证未通过,常见原因:\n - 验证码已过期(通常有效期为几分钟)\n - 验证码输入不正确\n - verification_id 无效或已被使用\n - 验证码不属于当前项目(project id does not match)\n\n 处理方式:\n 1. 提示用户"验证码已过期或不正确,请重新获取"\n 2. 调用 getVerification() 重新发送验证码\n 3. 确保 verification_id 与最新发送的验证码对应\n\n 注意:每次重新发送验证码后,之前的 verification_id 即失效。';default:return"[CloudBase Auth] 操作失败\n\n 如果问题持续存在,建议:\n"+" 1. 检查云开发控制台的认证配置:".concat(mn,"\n")+" 2. 到官方问答社区提问:https://cnb.cool/tencent/cloud/cloudbase/community/-/issues\n"+" 3. 查阅文档:".concat(bn)}}function _n(t){return t&&{signInWithPassword:"当前使用「用户名密码登录」,需确保:\n ✓ 控制台已开启「用户名密码登录」\n ✓ 用户已注册且凭据正确\n 如果不需要用户系统,建议改用 auth.signInAnonymously()",signInAnonymously:"当前使用「匿名登录」,需确保:\n ✓ 控制台已开启「匿名登录」\n 注意:匿名用户无需用户名密码,适用于快速体验或临时访问场景",signInWithOtp:"当前使用「OTP 验证码登录」,需确保:\n ✓ 控制台已开启「短信验证码登录」或「邮箱验证码登录」",signInWithOAuth:"当前使用「第三方 OAuth 登录」,需确保:\n ✓ 控制台已配置并开启对应的第三方身份源"}[t]||""}var En=function(t){function e(e,n){var r=this,o=function(t){return"object"==typeof t&&null!==t&&"__isAuthError"in t}(e);return(r=t.call(this,o?e.message:e.error_description||e.message)||this).__isAuthError=!0,r.name="AuthError",o?(r.status=e.status,r.code=e.code,r.errorCode=e.errorCode,r.requestId=e.requestId,r.category=e.category,r.retryAfter=e.retryAfter,r.helpMessage=wn(r.category,{method:null==n?void 0:n.method,errorCode:r.errorCode,code:r.code}),r.loginMethodHint=_n(null==n?void 0:n.method),r):(r.status=e.error,r.code=String(e.error||e.error_code||"unknown").toLowerCase(),r.errorCode="number"==typeof e.error_code?e.error_code:"string"==typeof e.error_code&&parseInt(e.error_code,10)||void 0,r.requestId=e.requestId,r.category=function(t,e,n){if(!t&&!e&&!n)return yn.UNKNOWN;try{var r=(t||"").toLowerCase(),o="string"==typeof n?parseInt(n,10):n;return o===de.MISSING_REQUIRED_PARAM||e===he.MISSING_REQUIRED_PARAM?yn.INVALID_PARAMS:o===de.CAPTCHA_REQUIRED||e===he.CAPTCHA_REQUIRED?yn.CAPTCHA_REQUIRED:o===de.CAPTCHA_INVALID||e===he.CAPTCHA_INVALID?yn.CAPTCHA_INVALID:o===de.MFA_PHONE_REQUIRED||e===he.MFA_PHONE_REQUIRED?yn.MFA_REQUIRED:o===de.LOGIN_TYPE_DISABLED||e===he.LOGIN_TYPE_DISABLED?yn.PROVIDER_NOT_ENABLED:o===de.RESOURCE_EXHAUSTED||e===he.RESOURCE_EXHAUSTED?yn.RATE_LIMITED:o===de.INTERNAL||o===de.UNAVAILABLE||o===de.UNIMPLEMENTED||o===de.ABORTED?yn.SERVICE_ERROR:o===de.NOT_FOUND?yn.USER_NOT_FOUND:o===de.UNAUTHENTICATED?yn.INVALID_CREDENTIALS:o===de.INVALID_ARGUMENT&&(r.includes("验证码")||r.includes("verification")||r.includes("verification_code")||r.includes("verification_id")||r.includes("does not match")||r.includes("token expired")||r.includes("token error")||r.includes("过期"))?yn.VERIFICATION_FAILED:e===he.PROVIDER_NOT_ENABLED||e===he.LOGIN_METHOD_DISABLED||r.includes("身份源")||r.includes("开启")||r.includes("identity provider")||r.includes("provider not enabled")||r.includes("login method")||r.includes("登录方式")||r.includes("not enabled")||r.includes("未开启")||r.includes("未启用")||r.includes("请联系开发者")||r.includes("anonymous login is not enabled")||r.includes("匿名登录未开启")?yn.PROVIDER_NOT_ENABLED:e===he.FAILED_PRECONDITION||o===de.FAILED_PRECONDITION&&!r.includes("请联系开发者")?r.includes("不存在")||r.includes("not found")||r.includes("未注册")?yn.USER_NOT_FOUND:yn.PRECONDITION_FAILED:e===he.INVALID_PASSWORD||e===he.INVALID_GRANT||e===he.INVALID_VERIFICATION_CODE||e===he.INVALID_USERNAME_OR_PASSWORD||e===he.INVALID_CREDENTIALS||e===he.WRONG_PASSWORD||e===he.UNAUTHENTICATED||e===he.INVALID_TWO_FACTOR||e===he.INVALID_TWO_FACTOR_RECOVERY||e===he.PASSWORD_NOT_SET||r.includes("密码不正确")||r.includes("password")||r.includes("invalid_password")||r.includes("凭据")||r.includes("credentials")||r.includes("验证码")||r.includes("verification")||r.includes("invalid_verification_code")||r.includes("invalid_username_or_password")||r.includes("username or password")||r.includes("用户名或密码")||r.includes("wrong password")||r.includes("incorrect password")?yn.INVALID_CREDENTIALS:e===he.NOT_FOUND||e===he.USER_NOT_FOUND||r.includes("用户不存在")||r.includes("not found")||r.includes("user not found")||r.includes("no such user")||r.includes("user does not exist")?yn.USER_NOT_FOUND:e===he.USER_BLOCKED||e===he.USER_PENDING||e===he.UNDER_REVIEW||e===he.INVALID_STATUS||r.includes("被封禁")||r.includes("blocked")||r.includes("pending")||r.includes("审核")||r.includes("review")||r.includes("locked")||r.includes("已锁定")?yn.USER_STATUS_ABNORMAL:e===he.SERVER_ERROR||e===he.UNAVAILABLE||e===he.TEMPORARILY_UNAVAILABLE||e===he.INTERNAL||e===he.UNREACHABLE||e===he.DEADLINE_EXCEEDED||e===he.DATA_LOSS||e===he.ABORTED||r.includes("network")||r.includes("timeout")||r.includes("timed out")||r.includes("超时")||r.includes("smtp is not set")||r.includes("sms sender does not config")?yn.SERVICE_ERROR:e===he.INVALID_ARGUMENT||e===he.INVALID_REQUEST||e===he.INVALID_SCOPE||e===he.INVALID_REQUEST_URI||e===he.INVALID_REQUEST_OBJECT||o===de.INVALID_ARGUMENT?yn.INVALID_PARAMS:e===he.PERMISSION_DENIED||e===he.ACCESS_DENIED||e===he.UNAUTHORIZED_CLIENT?yn.PROVIDER_NOT_ENABLED:yn.UNKNOWN}catch(t){return e}}(r.message,r.status,r.errorCode),r.helpMessage=wn(r.category,{method:null==n?void 0:n.method,errorCode:r.errorCode,code:r.code}),r.loginMethodHint=_n(null==n?void 0:n.method),r.category===yn.RATE_LIMITED&&(r.retryAfter=e.retry_after||e.retryAfter||void 0),r)}return gn(e,t),e.prototype.toJSON=function(){return{name:this.name,message:this.message,code:this.code,errorCode:this.errorCode,status:this.status,requestId:this.requestId,category:this.category,retryAfter:this.retryAfter}},e}(Error),In=function(){return In=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},In.apply(this,arguments)},Sn=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},On=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Tn(t,e){var n;return Sn(this,void 0,void 0,function(){var r,o=this;return On(this,function(i){r=function(){return Sn(o,void 0,void 0,function(){return On(this,function(t){switch(t.label){case 0:return t.trys.push([0,1,,6]),[2,l(3171)];case 1:t.sent(),t.label=2;case 2:return t.trys.push([2,4,,5]),[4,Promise.resolve().then(l.bind(l,3171))];case 3:return[2,t.sent()];case 4:return t.sent(),[2];case 5:return[3,6];case 6:return[2]}})})};try{if(((null===(n=null==e?void 0:e.root)||void 0===n?void 0:n.globalThis)||globalThis).IS_MP_BUILD)return[2];if(t)return[2,r()]}catch(e){if(t)return[2,r()]}return[2]})})}var An=function(){function t(t){var e=t.request,n=t.credentialsClient;if(!n){var r={apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,storage:t.storage,env:t.env,baseRequest:t.baseRequest,anonymousSignInFunc:t.anonymousSignInFunc,wxCloud:t.wxCloud,onCredentialsError:t.onCredentialsError,headers:t.headers||{},i18n:t.i18n,debug:t.debug};n=new Xe(r)}if(!e){var o=n.request.bind(n),i=new fn(In({env:t.env,clientId:t.clientId,request:o,storage:t.storage,adapter:t.adapter,oauthInstance:this},t.captchaOptions));e=i.request.bind(i)}this.config={env:t.env,apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,request:e,credentialsClient:n,storage:t.storage||Ye,adapter:t.adapter}}return t.parseParamsToSearch=function(t){return Object.keys(t).forEach(function(e){t[e]||delete t[e]}),new vn(t).toString()},t.prototype.getParamsByVersion=function(t,e){var n,r=(0,Ce.I)(t),o=(null===(n={v2:ue}[null==r?void 0:r.version])||void 0===n?void 0:n[e])||ce[e];return r&&delete r.version,{params:r,url:o}},t.prototype.signIn=function(t){return Sn(this,void 0,Promise,function(){var e,n,r,o;return On(this,function(i){switch(i.label){case 0:return e=t.version||"v1",(n=this.getParamsByVersion(t,"AUTH_SIGN_IN_URL")).params.query&&delete n.params.query,[4,this.getEncryptParams(n.params)];case 1:return r=i.sent(),[4,this.config.request(n.url,{method:"POST",body:r})];case 2:return o=i.sent(),[4,this.config.credentialsClient.setCredentials(In(In({},o),{version:e}))];case 3:return i.sent(),[2,Promise.resolve(o)]}})})},t.prototype.signInAnonymously=function(t,e){return void 0===t&&(t={}),void 0===e&&(e=!1),Sn(this,void 0,Promise,function(){var n;return On(this,function(r){switch(r.label){case 0:return[4,this.config.request(ce.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:t,useWxCloud:e})];case 1:return n=r.sent(),[4,this.config.credentialsClient.setCredentials(n)];case 2:return r.sent(),[2,Promise.resolve(n)]}})})},t.prototype.signUp=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){switch(n.label){case 0:return[4,this.config.request(ce.AUTH_SIGN_UP_URL,{method:"POST",body:t})];case 1:return e=n.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return n.sent(),[2,Promise.resolve(e)]}})})},t.prototype.signOut=function(t){return Sn(this,void 0,Promise,function(){var e,n,r,o;return On(this,function(i){switch(i.label){case 0:if(e={},!t)return[3,6];i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.config.request(ce.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:t})];case 2:return e=i.sent(),[3,4];case 3:return(n=i.sent()).error!==he.UNAUTHENTICATED&&console.log("sign_out_error",n),[3,4];case 4:return[4,this.config.credentialsClient.setCredentials()];case 5:return i.sent(),[2,e];case 6:return[4,this.config.credentialsClient.getAccessToken()];case 7:return r=i.sent(),[4,this.config.request(ce.AUTH_REVOKE_URL,{method:"POST",body:{token:r}})];case 8:return o=i.sent(),[4,this.config.credentialsClient.setCredentials()];case 9:return i.sent(),[2,Promise.resolve(o)]}})})},t.prototype.revokeAllDevices=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){switch(t.label){case 0:return[4,this.config.request(ce.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})];case 1:return t.sent(),[2]}})})},t.prototype.revokeDevice=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){switch(e.label){case 0:return[4,this.config.request(ce.AUTHORIZED_DEVICES_DELETE_URL+t.device_id,{method:"DELETE",withCredentials:!0})];case 1:return e.sent(),[2]}})})},t.prototype.getVerification=function(t,e){return Sn(this,void 0,Promise,function(){var n,r;return On(this,function(o){switch(o.label){case 0:return n=!1,"CUR_USER"!==t.target?[3,1]:(n=!0,[3,3]);case 1:return[4,this.hasLoginState()];case 2:o.sent()&&(n=!0),o.label=3;case 3:return(r=(0,Ce.I)(t)).phone_number&&!/^\+\d{1,3}\s+\d+/.test(r.phone_number)&&(r.phone_number="+86 ".concat(r.phone_number)),[2,this.config.request(ce.VERIFICATION_URL,{method:"POST",body:r,withCaptcha:(null==e?void 0:e.withCaptcha)||!1,withCredentials:n})]}})})},t.prototype.verify=function(t){return Sn(this,void 0,Promise,function(){var e,n;return On(this,function(r){switch(r.label){case 0:return e=this.getParamsByVersion(t,"VERIFY_URL"),[4,this.config.request(e.url,{method:"POST",body:e.params})];case 1:return n=r.sent(),"v2"!==(null==t?void 0:t.version)?[3,3]:[4,this.config.credentialsClient.setCredentials(In(In({},n),{version:"v2"}))];case 2:r.sent(),r.label=3;case 3:return[2,n]}})})},t.prototype.genProviderRedirectUri=function(e){return Sn(this,void 0,Promise,function(){var n,r,o,i,s;return On(this,function(a){return n=e.provider_redirect_uri,r=e.other_params,o=void 0===r?{}:r,i=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(e,["provider_redirect_uri","other_params"]),n&&!i.redirect_uri&&(i.redirect_uri=n),s="".concat(ce.PROVIDER_URI_URL,"?").concat(t.parseParamsToSearch(i)),Object.keys(o).forEach(function(t){var e=o[t];("sign_out_uri"!==t||(null==e?void 0:e.length)>0)&&(s+="&other_params[".concat(t,"]=").concat(encodeURIComponent(e)))}),[2,this.config.request(s,{method:"GET"})]})})},t.prototype.grantProviderToken=function(t,e){return void 0===e&&(e=!1),Sn(this,void 0,Promise,function(){return On(this,function(n){return[2,this.config.request(ce.PROVIDER_TOKEN_URL,{method:"POST",body:t,useWxCloud:e})]})})},t.prototype.patchProviderToken=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.PROVIDER_TOKEN_URL,{method:"PATCH",body:t})]})})},t.prototype.signInWithProvider=function(t,e){return void 0===e&&(e=!1),Sn(this,void 0,Promise,function(){var n,r;return On(this,function(o){switch(o.label){case 0:return n=this.getParamsByVersion(t,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),[4,this.config.request(n.url,{method:"POST",body:n.params,useWxCloud:e})];case 1:return r=o.sent(),[4,this.config.credentialsClient.setCredentials(In(In({},r),{version:(null==t?void 0:t.version)||"v1"}))];case 2:return o.sent(),[2,Promise.resolve(r)]}})})},t.prototype.toBindIdentity=function(t){var e,n;return Sn(this,void 0,void 0,function(){var r,o,i,s;return On(this,function(a){switch(a.label){case 0:return(o=t.credentials)?[3,2]:[4,this.config.credentialsClient.localCredentials.getCredentials()];case 1:o=a.sent(),a.label=2;case 2:r=o,a.label=3;case 3:return a.trys.push([3,5,,6]),[4,this.bindWithProvider({provider_token:t.provider_token},r)];case 4:return a.sent(),i={data:{type:Ae,provider:t.provider},error:null},[3,6];case 5:return s=a.sent(),i={data:{type:Ae},error:new En(s)},[3,6];case 6:return t.fireEvent&&(null===(n=null===(e=this.config.eventBus)||void 0===e?void 0:e.fire)||void 0===n||n.call(e,Oe,{event:Ie,info:i})),[2,i]}})})},t.prototype.getInitialSession=function(){return Sn(this,void 0,Promise,function(){var t,e,n,r,o,i,s,a,c,u,l,h,d,f,p;return On(this,function(v){switch(v.label){case 0:t={},v.label=1;case 1:if(v.trys.push([1,12,,13]),"undefined"==typeof window||"undefined"==typeof document)return[2,{data:null,error:null}];if(e=new URLSearchParams(null===location||void 0===location?void 0:location.search),n=e.get("code"),r=e.get("state"),!n||!r)return[2,{data:null,error:null}];o=null;try{o=JSON.parse(sessionStorage.getItem(r)||"null")}catch(t){}return t={type:null==o?void 0:o.type},i=e.get("error"),s=e.get("error_description"),i||s?[2,{data:t,error:new En({message:s||i||"Unknown error from OAuth provider"})}]:(a=(null==o?void 0:o.provider)||e.get("provider"))?(c=location.origin+location.pathname,[4,this.grantProviderToken({provider_id:a,provider_redirect_uri:c,provider_code:n})]):[2,{data:t,error:new En({message:"Provider is required for OAuth verification"})}];case 2:return u=v.sent().provider_token,l=void 0,h=null,d=void 0,o.type!==Ae?[3,5]:[4,this.config.credentialsClient.localCredentials.getCredentials()];case 3:return l=v.sent(),[4,this.toBindIdentity({provider:a,provider_token:u,credentials:l})];case 4:return d=v.sent(),[3,11];case 5:return o.type!==Te?[3,11]:(d=this.getParamsByVersion({provider:a},"AUTH_SIGN_IN_WITH_PROVIDER_URL"),[4,this.config.request(d.url,{method:"POST",body:{provider_token:u}})]);case 6:l=v.sent(),v.label=7;case 7:return v.trys.push([7,9,,10]),[4,this.getUserInfo({credentials:l})];case 8:return h=v.sent(),[3,10];case 9:return f=v.sent(),console.error("get user info error",f),[3,10];case 10:d={data:In(In({},t),{session:l,user:h}),error:null},v.label=11;case 11:e.delete("code"),e.delete("state"),e.delete("provider"),this.restoreUrlState(void 0===(null==o?void 0:o.search)?"?".concat(e.toString()):o.search,(null==o?void 0:o.hash)||location.hash);try{sessionStorage.removeItem(r)}catch(t){}return[2,d];case 12:return p=v.sent(),[2,{data:t,error:new En(p)}];case 13:return[2]}})})},t.prototype.signInCustom=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){switch(n.label){case 0:return[4,this.config.request(ce.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:t})];case 1:return e=n.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return n.sent(),[2,Promise.resolve(e)]}})})},t.prototype.signInWithWechat=function(t){return void 0===t&&(t={}),Sn(this,void 0,Promise,function(){var e;return On(this,function(n){switch(n.label){case 0:return[4,this.config.request(ce.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:t})];case 1:return e=n.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return n.sent(),[2,Promise.resolve(e)]}})})},t.prototype.bindWithProvider=function(t,e){return Sn(this,void 0,Promise,function(){return On(this,function(n){return[2,this.config.request(ce.PROVIDER_BIND_URL,{method:"POST",body:t,withCredentials:!0,getCredentials:e?function(){return e}:void 0})]})})},t.prototype.getUserProfile=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.getUserInfo(t)]})})},t.prototype.getUserInfo=function(t){var e,n,r;return void 0===t&&(t={}),Sn(this,void 0,Promise,function(){var o,i,s,a,c;return On(this,function(u){switch(u.label){case 0:return o=this.getParamsByVersion(t,"USER_ME_URL"),(null===(e=o.params)||void 0===e?void 0:e.query)&&(i=new vn(o.params.query),o.url+="?".concat(i.toString())),[4,this.config.request(o.url,{method:"GET",withCredentials:!0,getCredentials:t.credentials?function(){return t.credentials}:void 0})];case 1:if((s=u.sent()).sub&&(s.uid=s.sub),null===(n=s.providers)||void 0===n?void 0:n.length)try{"undefined"!=typeof wx&&wx.getAccountInfoSync&&(a=null===(r=wx.getAccountInfoSync().miniProgram)||void 0===r?void 0:r.appId,(null==(c=s.providers.find(function(t){return t.id===a}))?void 0:c.provider_user_id)&&(s.open_id=c.provider_user_id))}catch(t){}return[2,s]}})})},t.prototype.getWedaUserInfo=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){switch(t.label){case 0:return[4,this.config.request(ce.WEDA_USER_URL,{method:"GET",withCredentials:!0})];case 1:return[2,t.sent()]}})})},t.prototype.deleteMe=function(e){return Sn(this,void 0,Promise,function(){var n,r;return On(this,function(o){return n=this.getParamsByVersion(e,"USER_ME_URL"),r="".concat(n.url,"?").concat(t.parseParamsToSearch(n.params)),[2,this.config.request(r,{method:"DELETE",withCredentials:!0})]})})},t.prototype.hasLoginState=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.config.credentialsClient.getAccessToken()];case 1:return t.sent(),[2,!0];case 2:return t.sent(),[2,!1];case 3:return[2]}})})},t.prototype.hasLoginStateSync=function(){return this.config.credentialsClient.getCredentialsSync()},t.prototype.getLoginState=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.credentialsClient.getCredentialsAsync()]})})},t.prototype.transByProvider=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:t,withCredentials:!0})]})})},t.prototype.grantToken=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){return e=this.getParamsByVersion(t,"AUTH_TOKEN_URL"),[2,this.config.request(e.url,{method:"POST",body:e.params})]})})},t.prototype.getProviders=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.request(ce.PROVIDER_LIST,{method:"GET",withCredentials:!0})]})})},t.prototype.unbindProvider=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.PROVIDER_UNBIND_URL,"/").concat(t.provider_id),{method:"DELETE",withCredentials:!0})]})})},t.prototype.checkPassword=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.editContact=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:t})]})})},t.prototype.setPassword=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:t})]})})},t.prototype.updatePasswordByOld=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){switch(n.label){case 0:return[4,this.sudo({password:t.old_password})];case 1:return e=n.sent(),[2,this.setPassword({sudo_token:e.sudo_token,new_password:t.new_password})]}})})},t.prototype.sudo=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.SUDO_URL),{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.sendVerificationCodeToCurrentUser=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return t.target="CUR_USER",[2,this.config.request(ce.VERIFICATION_URL,{method:"POST",body:t,withCredentials:!0,withCaptcha:!0})]})})},t.prototype.changeBoundProvider=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request("".concat(ce.PROVIDER_LIST,"/").concat(t.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:t.trans_token},withCredentials:!0})]})})},t.prototype.setUserProfile=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.USER_PRIFILE_URL,{method:"PATCH",body:t,withCredentials:!0})]})})},t.prototype.updateUserBasicInfo=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.queryUserProfile=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){return e=new vn(t),[2,this.config.request("".concat(ce.USER_QUERY_URL,"?").concat(e.toString()),{method:"GET",withCredentials:!0})]})})},t.prototype.setCustomSignFunc=function(t){this.getCustomSignTicketFn=t},t.prototype.signInWithCustomTicket=function(){return Sn(this,void 0,Promise,function(){var t,e;return On(this,function(n){switch(n.label){case 0:return(t=this.getCustomSignTicketFn)?[4,t()]:[2,Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"})];case 1:return e=n.sent(),[2,this.signInCustom({provider_id:"custom",ticket:e})]}})})},t.prototype.resetPassword=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.AUTH_RESET_PASSWORD,{method:"POST",body:t})]})})},t.prototype.authorize=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.authorizeDevice=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.deviceAuthorize=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.AUTH_GET_DEVICE_CODE,{method:"POST",body:t})]})})},t.prototype.authorizeInfo=function(e){return Sn(this,void 0,Promise,function(){var n,r,o;return On(this,function(i){switch(i.label){case 0:return n="".concat(ce.AUTHORIZE_INFO_URL,"?").concat(t.parseParamsToSearch(e)),r=!0,o=!1,[4,this.hasLoginState()];case 1:return i.sent()&&(o=!0,r=!1),[2,this.config.request(n,{method:"GET",withBasicAuth:r,withCredentials:o})]}})})},t.prototype.checkUsername=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.CHECK_USERNAME,{method:"GET",body:t,withCredentials:!0})]})})},t.prototype.checkIfUserExist=function(t){return Sn(this,void 0,Promise,function(){var e;return On(this,function(n){return e=new vn(t),[2,this.config.request("".concat(ce.CHECK_IF_USER_EXIST,"?").concat(e.toString()),{method:"GET"})]})})},t.prototype.loginScope=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.credentialsClient.getScope()]})})},t.prototype.loginGroups=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.credentialsClient.getGroups()]})})},t.prototype.refreshTokenForce=function(t){return Sn(this,void 0,void 0,function(){var e;return On(this,function(n){switch(n.label){case 0:return[4,this.config.credentialsClient.getCredentials()];case 1:return e=n.sent(),[4,this.config.credentialsClient.refreshToken(In(In({},e),{version:(null==t?void 0:t.version)||"v1"}))];case 2:return[2,n.sent()]}})})},t.prototype.getCredentials=function(){return Sn(this,void 0,void 0,function(){return On(this,function(t){return[2,this.config.credentialsClient.getCredentials()]})})},t.prototype.getPublicKey=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.request(ue.AUTH_PUBLIC_KEY,{method:"POST",body:{}})]})})},t.prototype.getEncryptParams=function(t){return Sn(this,void 0,Promise,function(){var e,n,r,o,i,s;return On(this,function(a){switch(a.label){case 0:return e=t.isEncrypt,delete t.isEncrypt,n=(0,Ce.I)(t),[4,Tn(e,this.config.adapter)];case 1:if(!(r=a.sent()))return[2,t];o="",i="",a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.getPublicKey()];case 3:if(s=a.sent(),o=s.public_key,i=s.public_key_thumbprint,!o||!i)throw s;return[3,5];case 4:throw a.sent();case 5:return[2,{params:r.getEncryptInfo({publicKey:o,payload:n}),public_key_thumbprint:i}]}})})},t.prototype.getProviderSubType=function(){return Sn(this,void 0,Promise,function(){return On(this,function(t){return[2,this.config.request(ce.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})]})})},t.prototype.verifyCaptchaData=function(t){var e=t.token,n=t.key;return Sn(this,void 0,void 0,function(){return On(this,function(t){return[2,this.config.request(ce.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:e,key:n},withCredentials:!1})]})})},t.prototype.createCaptchaData=function(t){var e=t.state,n=t.redirect_uri,r=void 0===n?void 0:n;return Sn(this,void 0,void 0,function(){return On(this,function(t){return[2,this.config.request(ce.CAPTCHA_DATA_URL,{method:"POST",body:{state:e,redirect_uri:r},withCredentials:!1})]})})},t.prototype.getMiniProgramCode=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.GET_MINIPROGRAM_QRCODE,{method:"POST",body:t})]})})},t.prototype.getMiniProgramQrCodeStatus=function(t){return Sn(this,void 0,Promise,function(){return On(this,function(e){return[2,this.config.request(ce.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:t})]})})},t.prototype.getUserBehaviorLog=function(t){return Sn(this,void 0,Promise,function(){var e,n;return On(this,function(r){return e={LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"},n="".concat(ce.GET_USER_BEHAVIOR_LOG,"?").concat(e[t.type],"&limit=").concat(t.limit).concat(t.page_token?"&page_token=".concat(t.page_token):""),[2,this.config.request(n,{method:"GET",withCredentials:!0})]})})},t.prototype.modifyPassword=function(t){return Sn(this,void 0,Promise,function(){var e,n,r,o,i,s;return On(this,function(a){switch(a.label){case 0:return e="",n="",[4,Tn(!0,this.config.adapter)];case 1:if(!(r=a.sent()))throw new Error("do not support encrypt, a encrypt util required.");a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.getPublicKey()];case 3:if(o=a.sent(),e=o.public_key,n=o.public_key_thumbprint,!e||!n)throw o;return[3,5];case 4:throw a.sent();case 5:return i=t.password?r.getEncryptInfo({publicKey:e,payload:t.password}):"",s=r.getEncryptInfo({publicKey:e,payload:t.new_password}),[2,this.config.request(ce.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:t.user_id,encrypt_password:i,encrypt_new_password:s,public_key_thumbprint:n}})]}})})},t.prototype.modifyPasswordWithoutLogin=function(t){return Sn(this,void 0,Promise,function(){var e,n,r,o,i,s;return On(this,function(a){switch(a.label){case 0:return e="",n="",[4,Tn(!0,this.config.adapter)];case 1:if(!(r=a.sent()))throw new Error("do not support encrypt, a encrypt util required.");a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.getPublicKey()];case 3:if(o=a.sent(),e=o.public_key,n=o.public_key_thumbprint,!e||!n)throw o;return[3,5];case 4:throw a.sent();case 5:return i=t.password?r.getEncryptInfo({publicKey:e,payload:t.password}):"",s=r.getEncryptInfo({publicKey:e,payload:t.new_password}),[2,this.config.request(ue.AUTH_RESET_PASSWORD,{method:"POST",body:{username:t.username,password:i,new_password:s,public_key_thumbprint:n}})]}})})},t.prototype.restoreUrlState=function(t,e){if(void 0!==t)try{var n=new URL(window.location.href);n.search=t,n.hash=e||"",window.history.replaceState(null,"",n.toString()),window.location.replace(n.toString())}catch(t){}},t}(),Pn=function(){return Pn=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Pn.apply(this,arguments)},Rn=function(){function t(t){var e=t.apiOrigin,n=t.getApiOrigin,r=t.apiPath,o=void 0===r?pe:r,i=t.clientId,s=t.env,a=t.storage,c=t.request,u=t.baseRequest,l=t.anonymousSignInFunc,h=t.wxCloud,d=t.adapter,f=t.onCredentialsError,p=t.headers,v=t.i18n,y=t.useWxCloud,g=t.eventBus,m=t.detectSessionInUrl,b=t.debug;if(this.detectSessionInUrl=null!=m&&m,this.oauth2client=new Xe({apiOrigin:e,getApiOrigin:n,apiPath:o,clientId:i,env:s,storage:a,baseRequest:u||c,anonymousSignInFunc:l,wxCloud:h,onCredentialsError:f,headers:p||{},i18n:v,useWxCloud:y,eventBus:g,debug:b}),this.authApi=new An(Pn(Pn({credentialsClient:this.oauth2client},t),{request:c?this.oauth2client.request.bind(this.oauth2client):void 0,adapter:d})),m)this.oauth2client.setGetInitialSession(this.authApi.getInitialSession.bind(this.authApi));else try{var w=new URL(window.location.href),_=w.searchParams.get("code"),E=w.searchParams.get("state"),I=JSON.parse(sessionStorage.getItem(E)||"null");_&&E&&(null==I?void 0:I.hash)&&(w.hash=I.hash,window.history.replaceState(null,"",w.toString()),window.location.replace(w.toString()))}catch(t){}}return t.prototype.initializeSession=function(t){this.detectSessionInUrl?(this.oauth2client.setOnInitialSessionObtained(t),this.oauth2client.initialize()):this.oauth2client.initialize(Promise.resolve({error:null}))},t}(),Cn=l(794),kn=l(141),Nn=l(6197),xn=l(8182),Un=function(){return Un=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Un.apply(this,arguments)},Ln=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Dn=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},jn=function(){function t(t){var e,n;try{this.localStorage=(null==t?void 0:t.localStorage)||((null===(n=null===(e=null==t?void 0:t.adapter)||void 0===e?void 0:e.root)||void 0===n?void 0:n.globalThis)||globalThis).localStorage}catch(e){this.localStorage=(null==t?void 0:t.localStorage)||{}}}return t.prototype.getItem=function(t){return Ln(this,void 0,Promise,function(){return Dn(this,function(e){return[2,this.localStorage.getItem(t)]})})},t.prototype.removeItem=function(t){return Ln(this,void 0,void 0,function(){return Dn(this,function(e){return this.localStorage.removeItem(t),[2]})})},t.prototype.setItem=function(t,e){return Ln(this,void 0,Promise,function(){return Dn(this,function(n){return this.localStorage.setItem(t,e),[2]})})},t.prototype.getItemSync=function(t){return this.localStorage.getItem(t)},t.prototype.setItemSync=function(t,e){this.localStorage.setItem(t,e)},t.prototype.removeItemSync=function(t){this.localStorage.removeItem(t)},t}(),qn=/^[^:]+:\/\/[^/]+(\/[^?#]+)/,Mn=function(t,e){var n,r,o,i,s=null===(n=null==e?void 0:e.headers)||void 0===n?void 0:n["x-request-id"];return t||(t={}),((null==t?void 0:t.code)||(null===(r=null==t?void 0:t.data)||void 0===r?void 0:r.error_code))&&(t={error:t.code||t.data.error,error_description:t.data.error_description||t.message||t.code||t.data.error_code,request_id:t.requestId,error_code:null===(o=t.data)||void 0===o?void 0:o.error_code}),(null==t?void 0:t.request_id)||(t.request_id=t.request_id||s),(null==t?void 0:t.error)?(t.error_uri=(i=null==e?void 0:e.url,qn.test(i)?RegExp.$1:i),t):(null==t?void 0:t.data)||{}},Bn=function(t){return t.adapter&&"default"!==t.adapter.type?function(t,e){var n=Un({},t);try{if(!(null==t?void 0:t.storage)&&(null==e?void 0:e.localStorage)&&(n.storage=new jn({localStorage:e.localStorage,adapter:e})),!t.captchaOptions&&(null==e?void 0:e.captchaOptions)&&(n.captchaOptions=e.captchaOptions),!t.baseRequest&&!t.request&&(null==e?void 0:e.reqClass)){var r={timeout:1e4,restrictedMethods:["get","post","upload","download","request"],auth:t.auth},o=new e.reqClass(r);n.baseRequest=function(t,e){var n,r,i,s,a;return Ln(this,void 0,void 0,function(){var c,u,l,h;return Dn(this,function(d){switch(d.label){case 0:if(c={},u=(null===(n=e.method)||void 0===n?void 0:n.toLocaleLowerCase())||"post","function"!=typeof(l=null===(i=null===(r=null==o?void 0:o[u])||void 0===r?void 0:r.bind)||void 0===i?void 0:i.call(r,o)))throw new Error("invalid 【".concat(u,"】 request method"));d.label=1;case 1:return d.trys.push([1,3,,4]),(null===(s=e.headers)||void 0===s?void 0:s["content-type"])&&!(null===(a=e.headers)||void 0===a?void 0:a["content-type"].includes("application/json"))||["string","undefined"].includes(typeof e.body)||(e.data=e.data||e.body,e.body=JSON.stringify(e.body)),[4,l(Un({url:t},e))];case 2:return c=d.sent(),c=Mn(c,Un(Un({},e),{url:t})),[3,4];case 3:throw h=d.sent(),c=Un(Un({},null==h?void 0:h.data),h);case 4:if(null==c?void 0:c.error)throw c;return[2,c]}})})}}}catch(t){console.error("user adapter generate fail:",t)}return n}(t,t.adapter):function(t,e){var n=Un({},t),r={};if((null==e?void 0:e.captchaOptions)&&(n.captchaOptions=e.captchaOptions),!ut.default.isMatch()||t.storage&&t.baseRequest)return n;try{var o=ut.default.genAdapter({}),i=o.localStorage,s=o.reqClass;if(i&&(r.storage=new jn({localStorage:i,adapter:e})),s){var a=new s({timeout:1e4,restrictedMethods:["get","post","upload","download","request"]});r.request=function(t){return function(e,n){return Ln(this,void 0,void 0,function(){return Dn(this,function(r){return[2,new Promise(function(r,o){var i=Object.assign({},n);i.body&&"string"!=typeof i.body&&(i.body=JSON.stringify(i.body));var s=wx.request({url:e,data:i.body,timeout:t._timeout,method:i.method||"GET",header:i.headers,success:function(t){(t=Mn(t,Un(Un({},n),{url:e}))).error&&o(t),r(t)},fail:function(t){o({error:"unreachable",error_description:t.message})},complete:function(e){if(e&&e.errMsg&&t._timeout&&-1!==t._restrictedMethods.indexOf("request")&&"request:fail timeout"===e.errMsg){console.warn(t._timeoutMsg);try{s.abort()}catch(t){}}}})})]})})}}(a)}return n.captchaOptions&&(r.baseRequest=r.request,r.request=void 0),Un(Un({},n),r)}catch(t){console.error("adapter generate fail:",t)}return n}(t,t.adapter)},Wn=function(){return Wn=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Wn.apply(this,arguments)},Fn=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Hn=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Vn=function(){function t(t){}return t.prototype.signInWithRedirect=function(){throw new Error("[v1 兼容] WeixinAuthProvider.signInWithRedirect() 在当前版本中无法实现。 建议使用 auth.signInWithOAuth({ provider: 'providerId' }) 替代。")},t.prototype.getRedirectResult=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] WeixinAuthProvider.getRedirectResult() 在当前版本中无法实现。 建议使用 auth.verifyOAuth({ code, state, provider }) 替代。")})})},t.prototype.getLinkRedirectResult=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] WeixinAuthProvider.getLinkRedirectResult() 在当前版本中无法实现。 建议使用 auth.linkIdentity({ provider: 'providerId' }) 替代。")})})},t}(),Gn=function(){function t(t){this.authInstance=t.authInstance}return t.prototype.signIn=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(e){switch(e.label){case 0:return[4,this.authInstance.signInWithCustomTicket(function(){return Promise.resolve(t)})];case 1:return e.sent(),[2]}})})},t}(),Kn=function(){function t(t){this.authInstance=t.authInstance}return t.prototype.signIn=function(){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){switch(t.label){case 0:return[4,this.authInstance.signInAnonymously({})];case 1:return t.sent(),[2]}})})},t}(),Jn=function(){function t(){}return t.prototype.weixinAuthProvider=function(t){return new Vn({authInstance:this,appid:t.appid,scope:t.scope})},t.prototype.customAuthProvider=function(){return new Gn({authInstance:this})},t.prototype.anonymousAuthProvider=function(){return new Kn({authInstance:this})},t.prototype.signUpWithEmailAndPassword=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(n){switch(n.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"email must be a string"),"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"password must be a string"),[4,this.signUp({email:t,password:e})];case 1:return[2,n.sent()]}})})},t.prototype.signInWithEmailAndPassword=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(n){switch(n.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"email must be a string"),"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"password must be a string"),[4,this.signIn({username:t,password:e})];case 1:return n.sent(),[2,this.createLoginState()]}})})},t.prototype.sendPasswordResetEmail=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(e){switch(e.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"email must be a string"),[4,this.getVerification({email:t})];case 1:return e.sent(),[2]}})})},t.prototype.signInWithUsernameAndPassword=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(n){switch(n.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"username must be a string"),"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"password must be a string"),[4,this.signIn({username:t,password:e})];case 1:return n.sent(),[2,this.createLoginState()]}})})},t.prototype.sendPhoneCode=function(t){return Fn(this,void 0,Promise,function(){var e;return Hn(this,function(n){switch(n.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneNumber must be a string"),e=this.formatPhone(t),[4,this.getVerification({phone_number:e})];case 1:return n.sent(),[2,!0]}})})},t.prototype.signUpWithPhoneCode=function(t,e,n){return Fn(this,void 0,Promise,function(){var r;return Hn(this,function(o){switch(o.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneNumber must be a string"),"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneCode must be a string"),r=this.formatPhone(t),[4,this.signUp(Wn({phone_number:r,verification_code:e},n?{password:n}:{}))];case 1:return o.sent(),[2,this.createLoginState()]}})})},t.prototype.signInWithPhoneCodeOrPassword=function(t){return Fn(this,void 0,Promise,function(){var e,n,r,o;return Hn(this,function(i){switch(i.label){case 0:return e=t.phoneNumber,n=t.phoneCode,r=t.password,"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneNumber must be a string"),o=this.formatPhone(e),r?[4,this.signIn({username:o,password:r})]:[3,2];case 1:return i.sent(),[3,5];case 2:return n?[4,this.signIn({username:o,verification_token:n})]:[3,4];case 3:return i.sent(),[3,5];case 4:(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneCode or password must be provided"),i.label=5;case 5:return[2,this.createLoginState()]}})})},t.prototype.forceResetPwdByPhoneCode=function(t){return Fn(this,void 0,Promise,function(){var e,n,r,o;return Hn(this,function(i){switch(i.label){case 0:return e=t.phoneNumber,n=t.phoneCode,r=t.password,"string"!=typeof e&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneNumber must be a string"),"string"!=typeof n&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"phoneCode must be a string"),"string"!=typeof r&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"password must be a string"),o=this.formatPhone(e),[4,this.resetPassword({phone_number:o,new_password:r,verification_token:n})];case 1:return i.sent(),[4,this.signIn({username:o,password:r})];case 2:return i.sent(),[2,this.createLoginState()]}})})},t.prototype.shouldRefreshAccessToken=function(t){throw new Error("[v1 兼容] shouldRefreshAccessToken() 在当前版本中无法实现。 建议使用 auth.onAuthStateChange(callback) 来监听 TOKEN_REFRESHED 事件替代。")},t.prototype.onLoginStateExpired=function(t){var e=this;this.onLoginStateChanged(function(n){(null==n?void 0:n.eventType)===ge&&t.call(e)})},t.prototype.onAccessTokenRefreshed=function(t){var e=this;this.onAuthStateChange(function(n){n===_e&&t.call(e)})},t.prototype.onAnonymousConverted=function(t){var e=this;this.onAuthStateChange(function(n){n===be&&t.call(e)})},t.prototype.onLoginTypeChanged=function(t){var e=this;this.onAuthStateChange(function(n){n!==be&&n!==me||t.call(e)})},t}(),zn=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),$n=function(){return $n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},$n.apply(this,arguments)},Yn=function(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s},Qn=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},Xn=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Zn=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},tr=function(){return"undefined"!=typeof window&&"undefined"!=typeof document},er=function(t){return function(e){t.fire(Se,$n($n({},e),{eventType:ge}))}},nr=["avatar_url","avatarUrl"];function rr(t){return"undefined"!=typeof TextEncoder?(new TextEncoder).encode(t).length:t.length}function or(t,e){if(t)for(var n=0,r=nr;n<r.length;n++){var o=r[n],i=t[o];if(null!=i&&""!==i){var s=rr(String(i));if(s>204800)throw new En({error:"invalid_argument",error_code:de.INVALID_ARGUMENT,error_description:"auth.".concat(e,'(params): "').concat(o,'" 超过 200KB 限制(当前 ').concat(s," 字节),请传入图片 URL 而非文件内容")},{method:e})}}}var ir,sr=function(){function e(t){var e=t.cache,n=t.oauthInstance;this.cache=e,this.oauthInstance=n,this.setUserInfo()}var n,r,o;return e.prototype.checkLocalInfo=function(){return Xn(this,void 0,void 0,function(){return Zn(this,function(t){return this.uid=this.getLocalUserInfo("uid"),this.gender=this.getLocalUserInfo("gender"),this.picture=this.getLocalUserInfo("picture"),this.email=this.getLocalUserInfo("email"),this.emailVerified=this.getLocalUserInfo("email_verified"),this.phoneNumber=this.getLocalUserInfo("phone_number"),this.username=this.getLocalUserInfo("username"),this.name=this.getLocalUserInfo("name"),this.birthdate=this.getLocalUserInfo("birthdate"),this.zoneinfo=this.getLocalUserInfo("zoneinfo"),this.locale=this.getLocalUserInfo("locale"),this.sub=this.getLocalUserInfo("sub"),this.createdFrom=this.getLocalUserInfo("created_from"),this.providers=this.getLocalUserInfo("providers"),[2]})})},e.prototype.checkLocalInfoAsync=function(){return Xn(this,void 0,void 0,function(){var t,e,n,r;return Zn(this,function(o){switch(o.label){case 0:return t=this,[4,this.getLocalUserInfoAsync("uid")];case 1:return t.uid=o.sent(),e=this,[4,this.getLocalUserInfoAsync("gender")];case 2:return e.gender=o.sent(),this.picture=this.getLocalUserInfo("picture"),n=this,[4,this.getLocalUserInfoAsync("email")];case 3:return n.email=o.sent(),this.emailVerified=this.getLocalUserInfo("email_verified"),this.phoneNumber=this.getLocalUserInfo("phone_number"),r=this,[4,this.getLocalUserInfoAsync("username")];case 4:return r.username=o.sent(),this.name=this.getLocalUserInfo("name"),this.birthdate=this.getLocalUserInfo("birthdate"),this.zoneinfo=this.getLocalUserInfo("zoneinfo"),this.locale=this.getLocalUserInfo("locale"),this.sub=this.getLocalUserInfo("sub"),this.createdFrom=this.getLocalUserInfo("created_from"),this.providers=this.getLocalUserInfo("providers"),[2]}})})},e.prototype.update=function(t){return Xn(this,void 0,Promise,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return or(t,"update"),[4,this.oauthInstance.authApi.setUserProfile($n({},t))];case 1:return e=n.sent(),this.setLocalUserInfo(e),[2]}})})},e.prototype.updateUserBasicInfo=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return or(t,"updateUserBasicInfo"),[4,this.oauthInstance.authApi.updateUserBasicInfo($n({},t))];case 1:return e.sent(),[4,this.refresh()];case 2:return e.sent(),[2]}})})},e.prototype.updatePassword=function(t,e){return this.oauthInstance.authApi.updatePasswordByOld({old_password:e,new_password:t})},e.prototype.updateUsername=function(t){return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"username must be a string"),this.update({username:t})},e.prototype.refresh=function(t){return Xn(this,void 0,Promise,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return[4,this.oauthInstance.authApi.getUserInfo(t)];case 1:if("INVALID_ACCESS_TOKEN"===(e=n.sent()).code)throw this.setLocalUserInfo({}),e;return this.setLocalUserInfo(e),[2,e]}})})},e.prototype.getLocalUserInfo=function(t){var e=this.cache.keys.userInfoKey,n=this.cache.getStore(e);return t?n[t]:n||{}},e.prototype.setLocalUserInfo=function(t){var e=this.cache.keys.userInfoKey;this.cache.setStore(e,t),this.setUserInfo()},e.prototype.getLocalUserInfoAsync=function(t){return Xn(this,void 0,Promise,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return e=this.cache.keys.userInfoKey,[4,this.cache.getStoreAsync(e)];case 1:return[2,n.sent()[t]]}})})},e.prototype.setUserInfo=function(){var t=this,e=this.cache.keys.userInfoKey,n=this.cache.getStore(e);["uid","email","name","gender","picture","email_verified","phone_number","birthdate","zoneinfo","locale","sub","created_from","providers","username","created_at","open_id"].forEach(function(e){t[e]=n[e]})},Yn([(0,kn.catchErrorsDecorator)({title:"更新用户信息失败",messages:["请确认以下各项:"," 1 - 调用 User.update() 的语法或参数是否正确"," 2 - 用户信息中是否包含非法值","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(n=t.UserProfile)?n:Object]),Qn("design:returntype","function"==typeof(r="undefined"!=typeof Promise&&Promise)?r:Object)],e.prototype,"update",null),Yn([(0,kn.catchErrorsDecorator)({title:"更新密码失败",messages:["请确认以下各项:"," 1 - 调用 User.updatePassword() 的语法或参数是否正确"," 3 - 新密码中是否包含非法字符","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[String,String]),Qn("design:returntype",void 0)],e.prototype,"updatePassword",null),Yn([(0,kn.catchErrorsDecorator)({title:"更新用户名失败",messages:["请确认以下各项:"," 1 - 调用 User.updateUsername() 的语法或参数是否正确"," 2 - 当前环境是否开通了用户名密码登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[String]),Qn("design:returntype",void 0)],e.prototype,"updateUsername",null),Yn([(0,kn.catchErrorsDecorator)({title:"刷新本地用户信息失败",messages:["请确认以下各项:"," 1 - 调用 User.refresh() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[Object]),Qn("design:returntype","function"==typeof(o="undefined"!=typeof Promise&&Promise)?o:Object)],e.prototype,"refresh",null),e}();(ir=sr).prototype.linkWithTicket=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] User.linkWithTicket() 在当前版本中无法实现。 建议使用 auth.signInWithCustomTicket(() => Promise.resolve(ticket)) 替代。")})})},ir.prototype.linkWithRedirect=function(t){throw new Error("[v1 兼容] User.linkWithRedirect() 在当前版本中无法实现。 建议使用 auth.linkIdentity({ provider: 'providerId' }) 替代。")},ir.prototype.updateEmail=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(e){switch(e.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"newEmail must be a string"),[4,this.updateUserBasicInfo({email:t})];case 1:return e.sent(),[2]}})})},ir.prototype.linkWithPhoneNumber=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] User.linkWithPhoneNumber() 在当前版本中无法实现。 建议使用 auth.bindPhoneNumber({ phone_number, verification_token, sudo_token }) 替代。")})})},ir.prototype.updatePhoneNumber=function(t,e){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] User.updatePhoneNumber() 在当前版本中无法实现。 建议使用 auth.updateUser({ phone: newPhoneNumber }) 替代。")})})},ir.prototype.unlink=function(t){return Fn(this,void 0,Promise,function(){return Hn(this,function(t){throw new Error("[v1 兼容] User.unlink() 在当前版本中无法实现。 建议使用 auth.unlinkIdentity({ provider: loginType }) 替代。")})})};var ar=function(){function t(t){var e=t.envId,n=t.cache,r=t.oauthInstance;e||(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"envId is not defined"),this.cache=n,this.oauthInstance=r,this.user=new sr({cache:this.cache,oauthInstance:r})}return t.prototype.checkLocalState=function(){var t;this.oauthLoginState=null===(t=this.oauthInstance)||void 0===t?void 0:t.authApi.hasLoginStateSync(),this.user.checkLocalInfo()},t.prototype.checkLocalStateAsync=function(){var t;return Xn(this,void 0,void 0,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,null===(t=this.oauthInstance)||void 0===t?void 0:t.authApi.getLoginState()];case 1:return e.sent(),[4,this.user.checkLocalInfoAsync()];case 2:return e.sent(),[2]}})})},t}(),cr=function(e){function n(t){var n=e.call(this)||this;return n.listeners=new Map,n.hasListenerSetUp=!1,n.config=t,n.oauthInstance=t.oauthInstance,n.cache=t.cache,n.init(),n.setAccessKey(),n}var r,o,i,s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I;return zn(n,e),n.prototype.signInAnonymously=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o,i;return Zn(this,function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),[4,this.oauthInstance.authApi.signInAnonymously(t)];case 1:return s.sent(),[4,this.createLoginState()];case 2:return e=s.sent(),[4,this.getSession()];case 3:return n=s.sent().data,r=(void 0===n?{}:n).session,[2,$n($n({},e),{data:{user:r.user,session:r},error:null})];case 4:return o=s.sent(),(i=new En(o,{method:"signInAnonymously"})).category===yn.PROVIDER_NOT_ENABLED?(console.error(i.helpMessage),console.error("[CloudBase Auth] 提示:匿名登录需要在控制台开启「匿名登录」。\n 如果您需要使用用户名密码登录,请改用 auth.signInWithPassword({ username, password })。\n 不要在匿名登录失败后自动回退到密码登录,这两种方式的使用场景不同。")):(console.warn("[CloudBase Auth] signInAnonymously 失败 [".concat(i.category,"]: ").concat(i.message)),i.loginMethodHint&&console.warn(i.loginMethodHint)),[2,{data:{user:null,session:null},error:i}];case 5:return[2]}})})},n.prototype.signUp=function(t){return Xn(this,void 0,Promise,function(){var e,n,r=this;return Zn(this,function(o){switch(o.label){case 0:return t.phone_number||t.verification_code||t.verification_token||t.provider_token?(t.phone_number&&(t.phone_number=this.formatPhone(t.phone_number)),[4,this.oauthInstance.authApi.signUp(t)]):[3,2];case 1:return o.sent(),[2,this.createLoginState()];case 2:return o.trys.push([2,4,,5]),this.validateAtLeastOne(t,[["email"],["phone"]],"signUp"),[4,this.getVerification(t.email?{email:t.email,usage:ve.EMAIL}:{phone_number:this.formatPhone(t.phone)})];case 3:return e=o.sent(),[2,{data:{verifyOtp:function(n){var o=n.token,i=n.messageId,s=void 0===i?e.verification_id:i;return Xn(r,void 0,Promise,function(){var n,r,i,a,c;return Zn(this,function(u){switch(u.label){case 0:return u.trys.push([0,8,,9]),[4,this.verify({verification_id:s||e.verification_id,verification_code:String(o)})];case 1:return n=u.sent(),e.is_user?[4,this.signIn({username:t.email||this.formatPhone(t.phone),verification_token:n.verification_token})]:[3,3];case 2:return u.sent(),[3,6];case 3:return delete(r=JSON.parse(JSON.stringify(t))).email,delete r.phone,[4,this.oauthInstance.authApi.signUp($n($n($n({},r),t.email?{email:t.email}:{phone_number:this.formatPhone(t.phone)}),{verification_token:n.verification_token,verification_code:o}))];case 4:return u.sent(),[4,this.createLoginState()];case 5:u.sent(),u.label=6;case 6:return[4,this.getSession()];case 7:return i=u.sent().data,[2,{data:{user:(a=(void 0===i?{}:i).session).user,session:a},error:null}];case 8:return c=u.sent(),[2,{data:{user:null,session:null},error:new En(c,{method:"signUp"})}];case 9:return[2]}})})}},error:null}];case 4:return n=o.sent(),[2,{data:{user:null,session:null},error:new En(n,{method:"signUp"})}];case 5:return[2]}})})},n.prototype.signOut=function(t){return Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),e=this.cache.keys.userInfoKey,[4,this.oauthInstance.authApi.signOut(t)];case 1:return n=o.sent(),[4,this.cache.removeStoreAsync(e)];case 2:return o.sent(),this.setAccessKey(),[2,$n($n({},n),{data:{},error:null})];case 3:return r=o.sent(),[2,{data:{},error:new En(r,{method:"signOut"})}];case 4:return[2]}})})},n.prototype.onAuthStateChange=function(t){var e=this;this.hasListenerSetUp||(this.setupListeners(),this.hasListenerSetUp=!0);var n=Math.random().toString(36);return this.listeners.has(n)||this.listeners.set(n,new Set),this.listeners.get(n).add(t),{data:{subscription:{id:n,callback:t,unsubscribe:function(){var r=e.listeners.get(n);r&&(r.delete(t),0===r.size&&e.listeners.delete(n))}}}}},n.prototype.signInWithPassword=function(t){var e,n;return Xn(this,void 0,Promise,function(){var r,o,i,s,a,c,u,l;return Zn(this,function(h){switch(h.label){case 0:return h.trys.push([0,3,,4]),this.validateAtLeastOne(t,[["username"],["email"],["phone"]],"signInWithPassword"),this.validateParams(t,{password:{required:!0,message:"Password is required"}},"signInWithPassword"),r="username"in t?t.username:void 0,o="email"in t?t.email:void 0,i="phone"in t?t.phone:void 0,s=null!==(n=null===(e=t.options)||void 0===e?void 0:e.is_encrypt)&&void 0!==n?n:t.is_encrypt,[4,this.signIn($n({username:r||o||this.formatPhone(i),password:t.password},s?{isEncrypt:!0,version:"v2"}:{}))];case 1:return h.sent(),[4,this.getSession()];case 2:return a=h.sent().data,[2,{data:{user:(c=(void 0===a?{}:a).session).user,session:c},error:null}];case 3:return u=h.sent(),(l=new En(u,{method:"signInWithPassword"})).category===yn.PROVIDER_NOT_ENABLED?console.error(l.helpMessage):l.category===yn.INVALID_CREDENTIALS||l.category===yn.USER_NOT_FOUND?console.warn(l.helpMessage):console.warn("[CloudBase Auth] signInWithPassword 失败 [".concat(l.category,"]: ").concat(l.message)),l.loginMethodHint&&console.info(l.loginMethodHint),[2,{data:{user:null,session:null},error:l}];case 4:return[2]}})})},n.prototype.signInWithIdToken=function(t){return Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),this.validateParams(t,{token:{required:!0,message:"Token is required"}},"signInWithIdToken"),[4,this.signInWithProvider({provider_id:t.provider,provider_id_token:t.token})];case 1:return o.sent(),[4,this.getSession()];case 2:return e=o.sent().data,[2,{data:{user:(n=(void 0===e?{}:e).session).user,session:n},error:null}];case 3:return r=o.sent(),[2,{data:{user:null,session:null},error:new En(r,{method:"signInWithIdToken"})}];case 4:return[2]}})})},n.prototype.signInWithOtp=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o,i,s=this;return Zn(this,function(a){switch(a.label){case 0:if(e=t.options,n="email"in t?t.email:void 0,r="phone"in t?t.phone:void 0,!(null==e?void 0:e.emailRedirectTo)&&(void 0===(null==e?void 0:e.shouldCreateUser)||(null==e?void 0:e.shouldCreateUser)))return[2,this.signUp(n?{email:n}:{phone:r})];a.label=1;case 1:return a.trys.push([1,3,,4]),this.validateAtLeastOne(t,[["email"],["phone"]],"signInWithOtp"),[4,this.getVerification($n($n({email_redirect_to:null==e?void 0:e.emailRedirectTo},n?{email:n,usage:ve.EMAIL}:{phone_number:this.formatPhone(r)}),{target:(null==e?void 0:e.emailRedirectTo)&&(null==e?void 0:e.shouldCreateUser)?"ANY":"USER"}))];case 2:return o=a.sent(),[2,{data:{user:null,session:null,verifyOtp:function(t){var e=t.token,i=t.messageId,a=void 0===i?o.verification_id:i;return Xn(s,void 0,Promise,function(){return Zn(this,function(t){return[2,this.verifyOtp(n?{email:n,token:String(e),messageId:a||""}:{phone:r,token:String(e),messageId:a||""})]})})}},error:null}];case 3:return i=a.sent(),[2,{data:{user:null,session:null},error:new En(i,{method:"signInWithOtp"})}];case 4:return[2]}})})},n.prototype.verifyOAuth=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o,i,s,a,c,u;return Zn(this,function(l){switch(l.label){case 0:e={},l.label=1;case 1:return l.trys.push([1,7,,8]),n=(null==t?void 0:t.code)||T("code"),r=(null==t?void 0:t.state)||T("state"),n?r?(o=function(t){try{return JSON.parse(sessionStorage.getItem(t))}catch(t){return console.error("Failed to get browser session:",t),null}}(r),e.type=null==o?void 0:o.type,(i=(null==t?void 0:t.provider)||(null==o?void 0:o.provider)||T("provider"))?[4,this.grantProviderToken({provider_id:i,provider_redirect_uri:location.origin+location.pathname,provider_code:n})]:[2,{data:$n($n({},e),{user:null,session:null,redirectUrl:null}),error:this.missingRequiredParam("verifyOAuth","provider")}]):[2,{data:{user:null,session:null,redirectUrl:null},error:this.missingRequiredParam("verifyOAuth","state")}]:[2,{data:{user:null,session:null,redirectUrl:null},error:this.missingRequiredParam("verifyOAuth","code")}];case 2:return s=l.sent().provider_token,a=void 0,o.type!==Ae?[3,4]:[4,this.oauthInstance.authApi.toBindIdentity({provider_token:s,provider:i,fireEvent:!0})];case 3:return a=l.sent(),[3,6];case 4:return[4,this.signInWithIdToken({token:s})];case 5:(a=l.sent()).data=$n($n({},e),a.data),l.label=6;case 6:return(c=new URLSearchParams(null===location||void 0===location?void 0:location.search)).delete("code"),c.delete("state"),a.data.redirectUrl=function(t,e){if(void 0!==t){var n=new URL(window.location.href);return n.search=t,n.hash=e||n.hash,window.history.replaceState({},"",n.href),n.href}}(void 0===(null==o?void 0:o.search)?"?".concat(c.toString()):null==o?void 0:o.search,(null==o?void 0:o.hash)||location.hash),function(t){try{return sessionStorage.removeItem(t),!0}catch(t){return console.error("Failed to remove browser session:",t),null}}(r),[2,a];case 7:return u=l.sent(),[2,{data:$n($n({},e),{user:null,session:null,redirectUrl:null}),error:new En(u,{method:"verifyOAuth"})}];case 8:return[2]}})})},n.prototype.signInWithOAuth=function(t){var e,n,r,o,i;return Xn(this,void 0,Promise,function(){var s,a,c,u,l,h,d,f,p;return Zn(this,function(v){switch(v.label){case 0:return v.trys.push([0,2,,3]),this.validateParams(t,{provider:{required:!0,message:"Provider is required"}},"signInWithOAuth"),s=(null===(e=t.options)||void 0===e?void 0:e.redirectTo)||location.href,a=new URL(s),c=a.origin+a.pathname,u=(null===(n=t.options)||void 0===n?void 0:n.state)||"prd-".concat(t.provider,"-").concat(Math.random().toString(36).slice(2)),[4,this.genProviderRedirectUri({provider_id:t.provider,provider_redirect_uri:c,state:u})];case 1:return l=v.sent().uri,h=decodeURIComponent(l),d=h,(null===(r=t.options)||void 0===r?void 0:r.queryParams)&&(f=new URL(h),Object.entries(t.options.queryParams).forEach(function(t){var e=t[0],n=t[1];f.searchParams.set(e,n)}),d=f.toString()),function(t,e){try{sessionStorage.setItem(t,JSON.stringify(e))}catch(t){console.error("Failed to save to browser session:",t)}}(u,{provider:t.provider,search:a.search,hash:a.hash,type:(null===(o=t.options)||void 0===o?void 0:o.type)||Te}),tr()&&!(null===(i=t.options)||void 0===i?void 0:i.skipBrowserRedirect)&&window.location.assign(d),[2,{data:{url:d,provider:t.provider},error:null}];case 2:return p=v.sent(),[2,{data:{url:null,provider:null},error:new En(p,{method:"signInWithOAuth"})}];case 3:return[2]}})})},n.prototype.getClaims=function(){return Xn(this,void 0,Promise,function(){var t;return Zn(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.getAccessToken()];case 1:return[2,{data:function(t){if("string"!=typeof t)throw new Error("Invalid token specified");try{var e=t.split(".").map(function(t,e){return 2===e?t:JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("Illegal base64url string!")}try{return function(t){return decodeURIComponent(je(t).replace(/(.)/g,function(t){var e=t.charCodeAt(0).toString(16).toUpperCase();return e.length<2&&(e="0".concat(e)),"%".concat(e)}))}(e)}catch(t){return je(e)}}(t))});return{claims:e[1],header:e[0],signature:e[2]}}catch(t){throw new Error("Invalid token specified: ".concat(t)?t.message:0)}}(e.sent().accessToken),error:null}];case 2:return t=e.sent(),[2,{data:{claims:null,header:null,signature:null},error:new En(t,{method:"getClaims"})}];case 3:return[2]}})})},n.prototype.resetPasswordForEmail=function(t,e){return Xn(this,void 0,Promise,function(){var n,r,o,i,s,a,c=this;return Zn(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),this.validateParams({emailOrPhone:t},{emailOrPhone:{required:!0,message:"Email or phone is required"}},"resetPasswordForEmail"),n=(e||{}).redirectTo,r=t.includes("@"),o=void 0,r?o={email:t,usage:ve.RECOVERY}:(i=this.formatPhone(t),o={phone_number:i}),[4,this.getVerification($n($n({},o),{target:"USER"}))];case 1:return s=u.sent(),[2,{data:{updateUser:function(e){return Xn(c,void 0,Promise,function(){var o,i,a,c;return Zn(this,function(u){switch(u.label){case 0:this.validateParams(e,{nonce:{required:!0,message:"Nonce is required"},password:{required:!0,message:"Password is required"}},"resetPasswordForEmail"),u.label=1;case 1:return u.trys.push([1,5,,6]),[4,this.verify({verification_id:s.verification_id,verification_code:e.nonce})];case 2:return o=u.sent(),[4,this.oauthInstance.authApi.resetPassword({email:r?t:void 0,phone_number:r?void 0:t,new_password:e.password,verification_token:o.verification_token})];case 3:return u.sent(),null===(c=this.config.eventBus)||void 0===c||c.fire(Oe,{event:"PASSWORD_RECOVERY"}),[4,this.signInWithPassword({email:r?t:void 0,phone:r?void 0:t,password:e.password})];case 4:return i=u.sent(),n&&tr()&&window.location.assign(n),[2,i];case 5:return a=u.sent(),[2,{data:{user:null,session:null},error:new En(a,{method:"resetPasswordForEmail"})}];case 6:return[2]}})})}},error:null}];case 2:return a=u.sent(),[2,{data:{updateUser:null},error:new En(a,{method:"resetPasswordForEmail"})}];case 3:return[2]}})})},n.prototype.resetPasswordForOld=function(t){return Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,this.oauthInstance.authApi.updatePasswordByOld({old_password:t.old_password,new_password:t.new_password})];case 1:return o.sent(),[4,this.getSession()];case 2:return e=o.sent().data,[2,{data:{user:(n=(void 0===e?{}:e).session).user,session:n},error:null}];case 3:return r=o.sent(),[2,{data:{user:null,session:null},error:new En(r,{method:"resetPasswordForOld"})}];case 4:return[2]}})})},n.prototype.verifyOtp=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o,i,s,a;return Zn(this,function(c){switch(c.label){case 0:return c.trys.push([0,6,,7]),e=t.type,n=String(t.token),r="email"in t?t.email:void 0,o="phone"in t?t.phone:void 0,this.validateParams(t,{token:{required:!0,message:"Token is required"},messageId:{required:!0,message:"messageId is required"}},"verifyOtp"),["phone_change","email_change"].includes(e)?[4,this.verify({verification_id:t.messageId,verification_code:n})]:[3,2];case 1:return c.sent(),[3,4];case 2:return[4,this.signInWithUsername({verificationInfo:{verification_id:t.messageId,is_user:!0},verificationCode:n,username:r||this.formatPhone(o)||"",loginType:r?"email":"phone"})];case 3:c.sent(),c.label=4;case 4:return[4,this.getSession()];case 5:return i=c.sent().data,[2,{data:{user:(s=(void 0===i?{}:i).session).user,session:s},error:null}];case 6:return a=c.sent(),[2,{data:{user:null,session:null},error:new En(a,{method:"verifyOtp"})}];case 7:return[2]}})})},n.prototype.getSession=function(){return Xn(this,void 0,Promise,function(){var t,e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,this.oauthInstance.oauth2client.getCredentials()];case 1:return(t=o.sent())&&"accessKey"!==t.scope?[4,this.getUser(!1)]:[2,{data:{session:null,user:null},error:null}];case 2:return e=o.sent().data,n=(void 0===e?{}:e).user,[2,{data:{session:$n($n({},t),{user:n}),user:n},error:null}];case 3:return r=o.sent(),[2,{data:{session:null,user:null},error:new En(r,{method:"getSession"})}];case 4:return[2]}})})},n.prototype.refreshSession=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o,i;return Zn(this,function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),[4,this.oauthInstance.oauth2client.localCredentials.getCredentials()];case 1:return(e=s.sent()).refresh_token=t||e.refresh_token,[4,this.oauthInstance.oauth2client.refreshToken(e)];case 2:return n=s.sent(),[4,this.getUser(!1)];case 3:return r=s.sent().data,[2,{data:{user:o=(void 0===r?{}:r).user,session:$n($n({},n),{user:o})},error:null}];case 4:return i=s.sent(),[2,{data:{user:null,session:null},error:new En(i,{method:"refreshSession"})}];case 5:return[2]}})})},n.prototype.getUser=function(t){return void 0===t&&(t=!0),Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),[4,this.oauthInstance.oauth2client.getCredentials()];case 1:return(e=o.sent())&&"accessKey"!==e.scope?(n=this.convertToUser,[4,this.getCurrentUser(t)]):[2,{data:{user:null},error:null}];case 2:return[2,{data:{user:n.apply(this,[o.sent()])},error:null}];case 3:return r=o.sent(),[2,{data:{user:null},error:new En(r,{method:"getUser"})}];case 4:return[2]}})})},n.prototype.refreshUser=function(){return Xn(this,void 0,Promise,function(){var t,e,n;return Zn(this,function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),[4,this.currentUser.refresh()];case 1:return r.sent(),[4,this.getSession()];case 2:return t=r.sent().data,[2,{data:{user:(e=(void 0===t?{}:t).session).user,session:e},error:null}];case 3:return n=r.sent(),[2,{data:{user:null,session:null},error:new En(n,{method:"refreshUser"})}];case 4:return[2]}})})},n.prototype.updateUser=function(t){var e;return Xn(this,void 0,Promise,function(){var n,r,o,i,s,a,c,u,l,h,d,f,p,v,y=this;return Zn(this,function(g){switch(g.label){case 0:if(g.trys.push([0,8,,9]),or(t,"updateUser"),n=["password","new_password"].find(function(e){var n=t[e];return null!=n&&""!==n}),n)throw new En({message:'updateUser 不支持更新密码,检测到传入了 "'.concat(n,'" 参数。如需修改密码请使用 resetPasswordForOld(旧密码修改)、resetPasswordForEmail(验证码重置)或 reauthenticate(重新认证后改密)')});if(r=Object.keys(t).some(function(e){return void 0!==t[e]&&null!==t[e]&&""!==t[e]}),!r)throw this.missingRequiredParam("updateUser","(at least one field)");return o=t.email,i=t.phone,s=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(t,["email","phone"]),c=void 0!==i,u={},(a=void 0!==o)||c?(l=void 0,a?(l={email:t.email,usage:ve.REAUTHENTICATION},h="email_change"):(d=this.formatPhone(t.phone),l={phone_number:d},h="phone_change"),[4,this.getVerification($n({},l))]):[3,4];case 1:return f=g.sent(),Object.keys(s).length>0?[4,this.updateUserBasicInfo(s)]:[3,3];case 2:g.sent(),g.label=3;case 3:return u={messageId:f.verification_id,verifyOtp:function(e){return Xn(y,void 0,Promise,function(){var n,r,o,i;return Zn(this,function(s){switch(s.label){case 0:return s.trys.push([0,11,,12]),e.email&&t.email===e.email?[4,this.verifyOtp({type:"email_change",email:t.email,token:e.token,messageId:f.verification_id||""})]:[3,3];case 1:return(n=s.sent()).error?[2,n]:[4,this.updateUserBasicInfo({email:t.email})];case 2:return s.sent(),[3,9];case 3:return e.phone&&t.phone===e.phone?[4,this.verifyOtp({type:"phone_change",phone:t.phone,token:e.token,messageId:f.verification_id||""})]:[3,6];case 4:return(n=s.sent()).error?[2,n]:[4,this.updateUserBasicInfo({phone:this.formatPhone(t.phone)})];case 5:return s.sent(),[3,9];case 6:return[4,this.verifyOtp(a?{type:h,email:t.email,token:e.token,messageId:f.verification_id||""}:{type:h,phone:t.phone,token:e.token,messageId:f.verification_id||""})];case 7:return(n=s.sent()).error?[2,n]:[4,this.updateUserBasicInfo(t)];case 8:s.sent(),s.label=9;case 9:return[4,this.getUser(!1)];case 10:return r=s.sent().data.user,null===(i=this.config.eventBus)||void 0===i||i.fire(Oe,{event:Ee}),[2,{data:{user:r},error:null}];case 11:return o=s.sent(),[2,{data:{user:null},error:new En(o,{method:"updateUser"})}];case 12:return[2]}})})}},[3,6];case 4:return[4,this.updateUserBasicInfo(t)];case 5:g.sent(),g.label=6;case 6:return[4,this.getUser(!1)];case 7:return p=g.sent().data.user,Object.keys(s).length>0&&(null===(e=this.config.eventBus)||void 0===e||e.fire(Oe,{event:Ee})),[2,{data:$n({user:p},u),error:null}];case 8:return v=g.sent(),[2,{data:{user:null},error:new En(v,{method:"updateUser"})}];case 9:return[2]}})})},n.prototype.getUserIdentities=function(){var t;return Xn(this,void 0,Promise,function(){var e,n;return Zn(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.oauthInstance.authApi.getProviders()];case 1:return e=r.sent(),[2,{data:{identities:null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.filter(function(t){return!!t.bind})},error:null}];case 2:return n=r.sent(),[2,{data:{identities:null},error:new En(n,{method:"getUserIdentities"})}];case 3:return[2]}})})},n.prototype.linkIdentity=function(t){return Xn(this,void 0,Promise,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.validateParams(t,{provider:{required:!0,message:"Provider is required"}},"linkIdentity"),[4,this.signInWithOAuth({provider:t.provider,options:{type:Ae}})];case 1:return n.sent(),[2,{data:{provider:t.provider},error:null}];case 2:return e=n.sent(),[2,{data:{provider:null},error:new En(e,{method:"linkIdentity"})}];case 3:return[2]}})})},n.prototype.unlinkIdentity=function(t){return Xn(this,void 0,Promise,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.validateParams(t,{provider:{required:!0,message:"Provider is required"}},"unlinkIdentity"),[4,this.oauthInstance.authApi.unbindProvider({provider_id:t.provider})];case 1:return n.sent(),[2,{data:{},error:null}];case 2:return e=n.sent(),[2,{data:{},error:new En(e,{method:"unlinkIdentity"})}];case 3:return[2]}})})},n.prototype.reauthenticate=function(){return Xn(this,void 0,Promise,function(){var t,e,n,r,o=this;return Zn(this,function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),[4,this.getUser(!1)];case 1:return t=i.sent().data.user,this.validateAtLeastOne(t,[["email","phone"]],"reauthenticate"),e=t.email?{email:t.email,usage:ve.REAUTHENTICATION}:{phone_number:this.formatPhone(t.phone)},[4,this.getVerification(e)];case 2:return n=i.sent(),[2,{data:{updateUser:function(t){return Xn(o,void 0,Promise,function(){var r,o,i,s,a;return Zn(this,function(c){switch(c.label){case 0:this.validateParams(t,{nonce:{required:!0,message:"Nonce is required"}},"reauthenticate"),c.label=1;case 1:return c.trys.push([1,9,,10]),t.password?[4,this.verify({verification_id:n.verification_id,verification_code:t.nonce})]:[3,5];case 2:return r=c.sent(),[4,this.oauthInstance.authApi.sudo({verification_token:r.verification_token})];case 3:return o=c.sent(),[4,this.oauthInstance.authApi.setPassword({new_password:t.password,sudo_token:o.sudo_token})];case 4:return c.sent(),[3,7];case 5:return[4,this.signInWithUsername($n($n({verificationInfo:n,verificationCode:t.nonce},e),{loginType:e.email?"email":"phone"}))];case 6:c.sent(),c.label=7;case 7:return[4,this.getSession()];case 8:return i=c.sent().data,[2,{data:{user:(s=(void 0===i?{}:i).session).user,session:s},error:null}];case 9:return a=c.sent(),[2,{data:{user:null,session:null},error:new En(a,{method:"reauthenticate"})}];case 10:return[2]}})})}},error:null}];case 3:return r=i.sent(),[2,{data:{updateUser:null},error:new En(r,{method:"reauthenticate"})}];case 4:return[2]}})})},n.prototype.resend=function(t){return Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),this.validateAtLeastOne(t,[["email"],["phone"]],"resend"),e="signup"===t.type?"ANY":"USER",n={target:e},"email"in t&&(n.email=t.email,n.usage=ve.EMAIL),"phone"in t&&(n.phone_number=this.formatPhone(t.phone)),[4,this.oauthInstance.authApi.getVerification(n)];case 1:return[2,{data:{messageId:o.sent().verification_id},error:null}];case 2:return r=o.sent(),[2,{data:{messageId:null},error:new En(r,{method:"resend"})}];case 3:return[2]}})})},n.prototype.setSession=function(t){return Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),this.validateParams(t,{access_token:{required:!0,message:"Access token is required"},refresh_token:{required:!0,message:"Refresh token is required"}},"setSession"),[4,this.oauthInstance.oauth2client.refreshToken(t,{throwError:!0})];case 1:return o.sent(),[4,this.getSession()];case 2:return e=o.sent().data,[2,{data:{user:(n=(void 0===e?{}:e).session).user,session:n},error:null}];case 3:return r=o.sent(),[2,{data:{user:null,session:null},error:new En(r,{method:"setSession"})}];case 4:return[2]}})})},n.prototype.exchangeCodeForSession=function(){return Xn(this,void 0,void 0,function(){return Zn(this,function(t){return[2]})})},n.prototype.deleteUser=function(t){return Xn(this,void 0,Promise,function(){var e,n;return Zn(this,function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),this.validateParams(t,{password:{required:!0,message:"Password is required"}},"deleteUser"),[4,this.oauthInstance.authApi.sudo(t)];case 1:return e=r.sent().sudo_token,[4,this.oauthInstance.authApi.deleteMe({sudo_token:e})];case 2:return r.sent(),[2,{data:{},error:null}];case 3:return n=r.sent(),[2,{data:{},error:new En(n,{method:"deleteUser"})}];case 4:return[2]}})})},n.prototype.toDefaultLoginPage=function(t){return void 0===t&&(t={}),Xn(this,void 0,Promise,function(){var e,n,r,o,i;return Zn(this,function(s){try{return e=t.config_version||"env",n=Object.keys(t.query||{}).map(function(e){return"".concat(e,"=").concat(t.query[e])}).join("&"),ut.default.isMatch()?wx.navigateTo({url:"/packages/$wd_system/pages/login/index".concat(n?"?".concat(n):"")}):(r=t.redirect_uri||window.location.href,o=new URL(r),i="".concat(o.origin,"/__auth/?app_id=").concat(t.app_id||"","&env_id=").concat(this.config.env,"&client_id=").concat(this.config.clientId||this.config.env,"&config_version=").concat(e,"&redirect_uri=").concat(encodeURIComponent(r)).concat(n?"&".concat(n):""),window.location.href=i),[2,{data:{},error:null}]}catch(t){return[2,{data:{},error:new En(t,{method:"toDefaultLoginPage"})}]}return[2]})})},n.prototype.signInWithCustomTicket=function(t){return Xn(this,void 0,Promise,function(){var e,n,r,o;return Zn(this,function(i){switch(i.label){case 0:t&&this.setCustomSignFunc(t),i.label=1;case 1:return i.trys.push([1,5,,6]),[4,this.oauthInstance.authApi.signInWithCustomTicket()];case 2:return i.sent(),[4,this.createLoginState()];case 3:return e=i.sent(),[4,this.getSession()];case 4:return n=i.sent().data,r=(void 0===n?{}:n).session,[2,$n($n({},e),{data:{user:r.user,session:r},error:null})];case 5:return o=i.sent(),[2,{data:{user:null,session:null},error:new En(o,{method:"signInWithCustomTicket"})}];case 6:return[2]}})})},n.prototype.signInWithOpenId=function(t){var e=(void 0===t?{}:t).useWxCloud,n=void 0===e||e;return Xn(this,void 0,Promise,function(){var t,e,r,o,i,s,a=this;return Zn(this,function(c){switch(c.label){case 0:if(!ut.default.isMatch())throw Error("wx api undefined");t=wx.getAccountInfoSync().miniProgram,e=function(e){return Xn(a,void 0,void 0,function(){var r,o;return Zn(this,function(i){switch(i.label){case 0:r=void 0,o=void 0,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:null==t?void 0:t.appId,provider_code:e,provider_params:{provider_code_type:"open_id",appid:null==t?void 0:t.appId}},n)];case 2:if((null==(r=i.sent())?void 0:r.error_code)||!r.provider_token)throw r;return[4,this.oauthInstance.authApi.signInWithProvider({provider_token:r.provider_token},n)];case 3:if(null==(o=i.sent())?void 0:o.error_code)throw o;return[3,5];case 4:throw i.sent();case 5:return[4,this.oauthInstance.oauth2client.setCredentials(o)];case 6:return i.sent(),[2]}})})},c.label=1;case 1:return c.trys.push([1,5,,6]),[4,new Promise(function(t,n){wx.login({success:function(r){return Xn(a,void 0,void 0,function(){var o;return Zn(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,e(r.code)];case 1:return i.sent(),t(!0),[3,3];case 2:return o=i.sent(),n(o),[3,3];case 3:return[2]}})})},fail:function(t){var e=new Error(null==t?void 0:t.errMsg);e.code=null==t?void 0:t.errno,n(e)}})})];case 2:return c.sent(),[4,this.createLoginState()];case 3:return r=c.sent(),[4,this.getSession()];case 4:return o=c.sent().data,i=(void 0===o?{}:o).session,[2,$n($n({},r),{data:{user:i.user,session:i},error:null})];case 5:return s=c.sent(),[2,{data:{user:null,session:null},error:new En(s,{method:"signInWithOpenId"})}];case 6:return[2]}})})},n.prototype.signInWithPhoneAuth=function(t){var e=t.phoneCode,n=void 0===e?"":e,r=t.useWxCloud,o=void 0!==r&&r;return Xn(this,void 0,Promise,function(){var t,e,r,i,s,a,c,u,l;return Zn(this,function(h){switch(h.label){case 0:return ut.default.isMatch()?(t=wx.getAccountInfoSync().miniProgram,e={provider_params:{provider_code_type:"phone",code:n,appid:t.appId},provider_id:t.appId},[4,wx.login()]):[2,{data:{user:null,session:null},error:new En({message:"wx api undefined"})}];case 1:r=h.sent().code,e.provider_code=r,h.label=2;case 2:return h.trys.push([2,5,,6]),[4,this.oauthInstance.authApi.grantProviderToken(e,o)];case 3:if((i=h.sent()).error_code)throw i;return[4,this.oauthInstance.authApi.signInWithProvider({provider_token:i.provider_token},o)];case 4:if(null==(s=h.sent())?void 0:s.error_code)throw s;return[3,6];case 5:return a=h.sent(),[2,{data:{user:null,session:null},error:new En(a,{method:"signInWithPhoneAuth"})}];case 6:return[4,this.createLoginState()];case 7:return c=h.sent(),[4,this.getSession()];case 8:return u=h.sent().data,l=(void 0===u?{}:u).session,[2,$n($n({},c),{data:{user:l.user,session:l},error:null})]}})})},n.prototype.bindPhoneNumber=function(t){return Xn(this,void 0,void 0,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.editContact(t)]})})},n.prototype.unbindProvider=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.unbindProvider(t)]})})},n.prototype.bindEmail=function(t){return this.oauthInstance.authApi.editContact(t)},n.prototype.verify=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.verify(t)]})})},n.prototype.getVerification=function(t,e){return Xn(this,void 0,Promise,function(){return Zn(this,function(n){return t.phone_number&&(t.phone_number=this.formatPhone(t.phone_number)),[2,this.oauthInstance.authApi.getVerification(t,e)]})})},Object.defineProperty(n.prototype,"currentUser",{get:function(){if("async"!==this.cache.mode){var t=this.hasLoginState();return t&&t.user||null}(0,tn.printWarn)(Cn.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getCurrentUser instead")},enumerable:!1,configurable:!0}),n.prototype.getCurrentUser=function(t){return void 0===t&&(t=!0),Xn(this,void 0,Promise,function(){var e,n,r;return Zn(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),t?[4,this.getLoginState()]:[3,3];case 1:return(e=o.sent())?[4,e.user.refresh()]:[3,3];case 2:o.sent(),o.label=3;case 3:return[3,5];case 4:return o.sent(),[3,5];case 5:return[4,this.getLoginState()];case 6:return(n=o.sent())?(r=n.user.getLocalUserInfo(),[4,n.user.checkLocalInfoAsync()]):[3,8];case 7:return o.sent(),[2,$n($n({},n.user),r)];case 8:return[2,null]}})})},n.prototype.signInAnonymouslyInWx=function(t){var e=(void 0===t?{}:t).useWxCloud;return Xn(this,void 0,Promise,function(){var t,n,r=this;return Zn(this,function(o){switch(o.label){case 0:if(!ut.default.isMatch())throw Error("wx api undefined");return t=wx.getAccountInfoSync().miniProgram,n=function(n){return Xn(r,void 0,void 0,function(){var r,o;return Zn(this,function(i){switch(i.label){case 0:r=void 0,o=void 0,i.label=1;case 1:return i.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:null==t?void 0:t.appId,provider_code:n,provider_params:{provider_code_type:"open_id",appid:null==t?void 0:t.appId}},e)];case 2:if((null==(r=i.sent())?void 0:r.error_code)||!r.provider_token)throw r;return[4,this.oauthInstance.authApi.signInAnonymously({provider_token:r.provider_token},e)];case 3:if(null==(o=i.sent())?void 0:o.error_code)throw o;return[3,5];case 4:throw i.sent();case 5:return[2]}})})},[4,new Promise(function(t,e){wx.login({success:function(o){return Xn(r,void 0,void 0,function(){var r;return Zn(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,n(o.code)];case 1:return i.sent(),t(!0),[3,3];case 2:return r=i.sent(),e(r),[3,3];case 3:return[2]}})})},fail:function(t){var n=new Error(null==t?void 0:t.errMsg);n.code=null==t?void 0:t.errno,e(n)}})})];case 1:return o.sent(),[2,this.createLoginState(void 0,{asyncRefreshUser:!0})]}})})},n.prototype.bindOpenId=function(){return Xn(this,void 0,Promise,function(){var t,e,n=this;return Zn(this,function(r){switch(r.label){case 0:if(!ut.default.isMatch())throw Error("wx api undefined");return t=wx.getAccountInfoSync().miniProgram,e=function(e){return Xn(n,void 0,void 0,function(){var n;return Zn(this,function(r){switch(r.label){case 0:n=void 0,r.label=1;case 1:return r.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:null==t?void 0:t.appId,provider_code:e,provider_params:{provider_code_type:"open_id",appid:null==t?void 0:t.appId}})];case 2:if((null==(n=r.sent())?void 0:n.error_code)||!n.provider_token)throw n;return[4,this.oauthInstance.authApi.bindWithProvider({provider_token:n.provider_token})];case 3:return r.sent(),[3,5];case 4:throw r.sent();case 5:return[2]}})})},[4,new Promise(function(t,r){wx.login({success:function(o){return Xn(n,void 0,void 0,function(){var n;return Zn(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,e(o.code)];case 1:return i.sent(),t(!0),[3,3];case 2:return n=i.sent(),r(n),[3,3];case 3:return[2]}})})},fail:function(t){var e=new Error(null==t?void 0:t.errMsg);e.code=null==t?void 0:t.errno,r(e)}})})];case 1:return r.sent(),[2]}})})},n.prototype.signInWithUnionId=function(){return Xn(this,void 0,Promise,function(){var t=this;return Zn(this,function(e){switch(e.label){case 0:if(!ut.default.isMatch())throw Error("wx api undefined");e.label=1;case 1:return e.trys.push([1,3,,4]),[4,new Promise(function(e,n){var r=wx.getAccountInfoSync().miniProgram;wx.login({success:function(o){return Xn(t,void 0,void 0,function(){var t,i,s,a,c;return Zn(this,function(u){switch(u.label){case 0:t=null==r?void 0:r.appId,u.label=1;case 1:return u.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_code:o.code,provider_id:t,provider_params:{provider_code_type:"union_id",appid:null==r?void 0:r.appId}})];case 2:return i=u.sent(),(s=i.provider_token)?[4,this.oauthInstance.authApi.signInWithProvider({provider_id:t,provider_token:s})]:(n(i),[2]);case 3:return(null==(a=u.sent())?void 0:a.error_code)?(n(a),[2]):(e(!0),[3,5]);case 4:return c=u.sent(),n(c),[3,5];case 5:return[2]}})})},fail:function(t){var e=new Error(null==t?void 0:t.errMsg);e.code=null==t?void 0:t.errno,n(e)}})})];case 2:return e.sent(),[3,4];case 3:throw e.sent();case 4:return[2,this.createLoginState()]}})})},n.prototype.signInWithSms=function(t){var e=t.verificationInfo,n=void 0===e?{verification_id:"",is_user:!1}:e,r=t.verificationCode,o=void 0===r?"":r,i=t.phoneNum,s=void 0===i?"":i,a=t.bindInfo,c=void 0===a?void 0:a;return Xn(this,void 0,Promise,function(){return Zn(this,function(t){try{return[2,this.signInWithUsername({verificationInfo:n,verificationCode:o,bindInfo:c,username:s,loginType:"sms"})]}catch(t){throw t}return[2]})})},n.prototype.signInWithEmail=function(t){var e=t.verificationInfo,n=void 0===e?{verification_id:"",is_user:!1}:e,r=t.verificationCode,o=void 0===r?"":r,i=t.bindInfo,s=void 0===i?void 0:i,a=t.email,c=void 0===a?"":a;return Xn(this,void 0,Promise,function(){return Zn(this,function(t){try{return[2,this.signInWithUsername({verificationInfo:n,verificationCode:o,bindInfo:s,username:c,loginType:"email"})]}catch(t){throw t}return[2]})})},n.prototype.setCustomSignFunc=function(t){this.oauthInstance.authApi.setCustomSignFunc(t)},n.prototype.signIn=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.authApi.signIn(t)];case 1:return e.sent(),[2,this.createLoginState(t)]}})})},n.prototype.setPassword=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.setPassword(t)]})})},n.prototype.isUsernameRegistered=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return"string"!=typeof t&&(0,tn.throwError)(Cn.ERRORS.INVALID_PARAMS,"username must be a string"),[4,this.oauthInstance.authApi.checkIfUserExist({username:t})];case 1:return[2,e.sent().exist]}})})},n.prototype.hasLoginState=function(){var t;if("async"!==this.cache.mode)return(null===(t=this.oauthInstance)||void 0===t?void 0:t.authApi.hasLoginStateSync())?new ar({envId:this.config.env,cache:this.cache,oauthInstance:this.oauthInstance}):null;(0,tn.printWarn)(Cn.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getLoginState instead")},n.prototype.getLoginState=function(){return Xn(this,void 0,Promise,function(){var t;return Zn(this,function(e){switch(e.label){case 0:t=null,e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.oauthInstance.authApi.getLoginState()];case 2:return t=e.sent(),[3,4];case 3:return e.sent(),[2,null];case 4:return t?[2,new ar({envId:this.config.env,cache:this.cache,oauthInstance:this.oauthInstance})]:[2,null]}})})},n.prototype.getUserInfo=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.getCurrentUser()]})})},n.prototype.getWedaUserInfo=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.getWedaUserInfo()]})})},n.prototype.updateUserBasicInfo=function(t){return Xn(this,void 0,void 0,function(){var e;return Zn(this,function(n){switch(n.label){case 0:return[4,this.getLoginState()];case 1:return(e=n.sent())?[4,e.user.updateUserBasicInfo(t)]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}})})},n.prototype.getAuthHeader=function(){return console.error("Auth.getAuthHeader API 已废弃"),{}},n.prototype.bindWithProvider=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.bindWithProvider(t)]})})},n.prototype.queryUser=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.queryUserProfile(t)]})})},n.prototype.getAccessToken=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){switch(t.label){case 0:return[4,this.oauthInstance.oauth2client.getAccessToken()];case 1:return[2,{accessToken:t.sent(),env:this.config.env}]}})})},n.prototype.grantProviderToken=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.grantProviderToken(t)]})})},n.prototype.patchProviderToken=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.patchProviderToken(t)]})})},n.prototype.signInWithProvider=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.authApi.signInWithProvider(t)];case 1:return e.sent(),[2,this.createLoginState(t)]}})})},n.prototype.signInWithWechat=function(t){return void 0===t&&(t={}),Xn(this,void 0,void 0,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.authApi.signInWithWechat(t)];case 1:return e.sent(),[2,this.createLoginState(t)]}})})},n.prototype.grantToken=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.authApi.grantToken(t)];case 1:return e.sent(),[2,this.createLoginState()]}})})},n.prototype.genProviderRedirectUri=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.genProviderRedirectUri(t)]})})},n.prototype.resetPassword=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.resetPassword(t)]})})},n.prototype.deviceAuthorize=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.deviceAuthorize(t)]})})},n.prototype.sudo=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.sudo(t)]})})},n.prototype.deleteMe=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.deleteMe(t)]})})},n.prototype.getProviders=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.getProviders()]})})},n.prototype.loginScope=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.loginScope()]})})},n.prototype.loginGroups=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.loginGroups()]})})},n.prototype.onLoginStateChanged=function(t){var e;return Xn(this,void 0,void 0,function(){var n,r=this;return Zn(this,function(o){switch(o.label){case 0:return null===(e=this.config.eventBus)||void 0===e||e.on(Se,function(e){return Xn(r,void 0,void 0,function(){var n,r,o;return Zn(this,function(i){switch(i.label){case 0:return(null===(o=null==e?void 0:e.data)||void 0===o?void 0:o.eventType)===ge?[3,2]:[4,this.getLoginState()];case 1:return r=i.sent(),[3,3];case 2:r={},i.label=3;case 3:return n=r,t.call(this,$n($n({},e),n)),[2]}})})}),[4,this.getLoginState()];case 1:return n=o.sent(),t.call(this,n),[2]}})})},n.prototype.refreshTokenForce=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.refreshTokenForce(t)]})})},n.prototype.getCredentials=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.getCredentials()]})})},n.prototype.setCredentials=function(t){return Xn(this,void 0,void 0,function(){return Zn(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.oauth2client.setCredentials(t)];case 1:return e.sent(),[2]}})})},n.prototype.getProviderSubType=function(){return Xn(this,void 0,Promise,function(){return Zn(this,function(t){return[2,this.oauthInstance.authApi.getProviderSubType()]})})},n.prototype.createCaptchaData=function(t){return Xn(this,void 0,void 0,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.createCaptchaData(t)]})})},n.prototype.verifyCaptchaData=function(t){return Xn(this,void 0,void 0,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.verifyCaptchaData(t)]})})},n.prototype.getMiniProgramQrCode=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.getMiniProgramCode(t)]})})},n.prototype.getMiniProgramQrCodeStatus=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.getMiniProgramQrCodeStatus(t)]})})},n.prototype.modifyPassword=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.modifyPassword(t)]})})},n.prototype.modifyPasswordWithoutLogin=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.modifyPasswordWithoutLogin(t)]})})},n.prototype.getUserBehaviorLog=function(t){return Xn(this,void 0,Promise,function(){return Zn(this,function(e){return[2,this.oauthInstance.authApi.getUserBehaviorLog(t)]})})},n.prototype.signInWithUsername=function(t){var e=t.verificationInfo,n=void 0===e?{verification_id:"",is_user:!1}:e,r=t.verificationCode,o=void 0===r?"":r,i=t.username,s=void 0===i?"":i,a=t.bindInfo,c=void 0===a?void 0:a,u=t.loginType,l=void 0===u?"":u;return Xn(this,void 0,Promise,function(){var t,e,r,i,a,u,h;return Zn(this,function(d){switch(d.label){case 0:return d.trys.push([0,8,,9]),[4,this.oauthInstance.authApi.verify({verification_id:n.verification_id,verification_code:o})];case 1:if(null==(t=d.sent())?void 0:t.error_code)throw t;return e=t.verification_token,r=this.formatPhone(s),i={phone_number:r},"email"===l&&(i={email:r=s}),n.is_user?[4,this.oauthInstance.authApi.signIn({username:r,verification_token:e})]:[3,5];case 2:if(null==(a=d.sent())?void 0:a.error_code)throw a;return c?[4,this.oauthInstance.authApi.bindWithProvider({provider_token:null==c?void 0:c.providerToken})]:[3,4];case 3:if(null==(u=d.sent())?void 0:u.error_code)throw u;d.label=4;case 4:return[3,7];case 5:return[4,this.oauthInstance.authApi.signUp($n($n({},i),{verification_token:e,provider_token:null==c?void 0:c.providerId}))];case 6:if(null==(h=d.sent())?void 0:h.error_code)throw h;d.label=7;case 7:return[2,this.createLoginState()];case 8:throw d.sent();case 9:return[2]}})})},n.prototype.createLoginState=function(t,e){return Xn(this,void 0,Promise,function(){var n;return Zn(this,function(r){switch(r.label){case 0:return[4,(n=new ar({envId:this.config.env,cache:this.cache,oauthInstance:this.oauthInstance})).checkLocalStateAsync()];case 1:return r.sent(),(null==e?void 0:e.userInfo)?(n.user.setLocalUserInfo(e.userInfo),[3,5]):[3,2];case 2:return(null==e?void 0:e.asyncRefreshUser)?(n.user.refresh(t),[3,5]):[3,3];case 3:return[4,n.user.refresh(t)];case 4:r.sent(),r.label=5;case 5:return[2,n]}})})},n.prototype.setAccessKey=function(){var t,e;return Xn(this,void 0,void 0,function(){var n,r;return Zn(this,function(o){if(n="",r="",this.config.accessKey?(n=this.config.accessKey,r="accessKey"):(null===(t=this.config.auth)||void 0===t?void 0:t.secretId)&&(null===(e=this.config.auth)||void 0===e?void 0:e.secretKey)&&(n="",r=Pe),!r)return[2];try{this.oauthInstance.oauth2client.setAccessKeyCredentials({access_token:n,token_type:"Bearer",scope:r,expires_at:new Date(+new Date+ +new Date),expires_in:+new Date+ +new Date})}catch(t){console.warn("accessKey error: ",t)}return[2]})})},n.prototype.formatPhone=function(t){return!/\s+/.test(t)&&/^\+\d{1,3}\d+/.test(t)?t.replace(/^(\+\d{1,2})(\d+)$/,"$1 $2"):/^\+\d{1,3}\s+/.test(t)?t:"+86 ".concat(t)},n.prototype.notifyListeners=function(t,e,n){this.listeners.forEach(function(r){r.forEach(function(r){try{r(t,e,n)}catch(t){console.error("Error in auth state change callback:",t)}})})},n.prototype.setupListeners=function(){var t,e=this;null===(t=this.config.eventBus)||void 0===t||t.on(Oe,function(t){return Xn(e,void 0,void 0,function(){var e,n,r,o,i,s,a;return Zn(this,function(c){switch(c.label){case 0:return e=null===(s=null==t?void 0:t.data)||void 0===s?void 0:s.event,n=null===(a=null==t?void 0:t.data)||void 0===a?void 0:a.info,e!==be||n?[3,2]:[4,this.getUser(!0)];case 1:r=c.sent().data,(o=(void 0===r?{}:r).user)&&(n={user:o}),c.label=2;case 2:return[4,this.getSession()];case 3:return i=c.sent().data.session,this.notifyListeners(e,i,n),[2]}})})})},n.prototype.convertToUser=function(t){var e,n,r,o,i,s;if(!t)return null;var a=(null==t?void 0:t.email)||"",c=(null==t?void 0:t.phone_number)||"",u=(null==t?void 0:t.sub)||(null==t?void 0:t.uid)||"";return{id:u,aud:"authenticated",role:null===(n=null===(e=t.groups)||void 0===e?void 0:e.map)||void 0===n?void 0:n.call(e,function(t){return"string"==typeof t?t:t.id}),email:a||"",email_confirmed_at:(null==t||t.email_verified,t.created_at),phone:c,phone_confirmed_at:c?t.created_at:void 0,confirmed_at:t.created_at,last_sign_in_at:t.last_sign_in_at,app_metadata:{provider:(null===(r=t.loginType)||void 0===r?void 0:r.toLowerCase())||"cloudbase",providers:[(null===(o=t.loginType)||void 0===o?void 0:o.toLowerCase())||"cloudbase"]},user_metadata:{name:null==t?void 0:t.name,picture:null==t?void 0:t.picture,username:null==t?void 0:t.username,gender:null==t?void 0:t.gender,locale:null==t?void 0:t.locale,uid:t.uid,nickName:t.nickName||(null==t?void 0:t.name),avatarUrl:t.avatarUrl||t.picture,location:t.location,hasPassword:null!==(i=t.hasPassword)&&void 0!==i?i:"SET"===t.password,open_id:null==t?void 0:t.open_id},identities:(null===(s=null==t?void 0:t.providers)||void 0===s?void 0:s.map(function(e){return{id:e.id||"",identity_id:e.id||"",user_id:u,identity_data:{provider_id:e.id,provider_user_id:e.provider_user_id,name:e.name},provider:e.id||"cloudbase",created_at:t.created_at,updated_at:t.updated_at,last_sign_in_at:t.last_sign_in_at}}))||[],created_at:t.created_at,updated_at:t.updated_at,is_anonymous:"anonymous"===t.name}},n.prototype.missingRequiredParam=function(t,e){return new En({error:"missing_required_param",error_code:4e3,error_description:"auth.".concat(t,"(params): missing required param '").concat(e,"'")},{method:t})},n.prototype.validateParams=function(t,e,n){for(var r=0,o=Object.entries(e);r<o.length;r++){var i=o[r],s=i[0];if(i[1].required&&(void 0===(null==t?void 0:t[s])||null===(null==t?void 0:t[s])||""===(null==t?void 0:t[s])))throw this.missingRequiredParam(n,s)}},n.prototype.validateAtLeastOne=function(t,e,n){if(!e.some(function(e){return e.some(function(e){return void 0!==(null==t?void 0:t[e])&&null!==(null==t?void 0:t[e])&&""!==(null==t?void 0:t[e])})}))throw this.missingRequiredParam(n,e.map(function(t){return t.join("|")}).join("|"))},n.prototype.init=function(){var t;return Xn(this,void 0,Promise,function(){return Zn(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.oauthInstance.oauth2client.localCredentials.getCredentials()];case 1:return e.sent()&&!this.oauthInstance.oauth2client.initSessionEmitted&&(null===(t=this.config.eventBus)||void 0===t||t.fire(Oe,{event:we})),[3,3];case 2:return e.sent(),[3,3];case 3:return[2,{error:null}]}})})},Yn([(0,kn.catchErrorsDecorator)({title:"绑定手机号失败",messages:["请确认以下各项:"," 1 - 调用 auth().bindPhoneNumber() 的语法或参数是否正确"," 2 - 当前环境是否开通了短信验证码登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(r=t.BindPhoneRequest)?r:Object]),Qn("design:returntype",Promise)],n.prototype,"bindPhoneNumber",null),Yn([(0,kn.catchErrorsDecorator)({title:"解除三方绑定失败",messages:["请确认以下各项:"," 1 - 调用 auth().unbindProvider() 的语法或参数是否正确"," 2 - 当前账户是否已经与此登录方式解绑","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(o=t.UnbindProviderRequest)?o:Object]),Qn("design:returntype","function"==typeof(i="undefined"!=typeof Promise&&Promise)?i:Object)],n.prototype,"unbindProvider",null),Yn([(0,kn.catchErrorsDecorator)({title:"绑定邮箱地址失败",messages:["请确认以下各项:"," 1 - 调用 auth().bindEmail() 的语法或参数是否正确"," 2 - 当前环境是否开通了邮箱密码登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(s=t.BindEmailRequest)?s:Object]),Qn("design:returntype",void 0)],n.prototype,"bindEmail",null),Yn([(0,kn.catchErrorsDecorator)({title:"验证码验证失败",messages:["请确认以下各项:"," 1 - 调用 auth().verify() 的语法或参数是否正确"," 2 - 当前环境是否开通了手机验证码/邮箱登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(a=t.VerifyRequest)?a:Object]),Qn("design:returntype","function"==typeof(c="undefined"!=typeof Promise&&Promise)?c:Object)],n.prototype,"verify",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取验证码失败",messages:["请确认以下各项:"," 1 - 调用 auth().getVerification() 的语法或参数是否正确"," 2 - 当前环境是否开通了手机验证码/邮箱登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(u=t.GetVerificationRequest)?u:Object,Object]),Qn("design:returntype","function"==typeof(l="undefined"!=typeof Promise&&Promise)?l:Object)],n.prototype,"getVerification",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取用户信息失败",messages:["请确认以下各项:"," 1 - 调用 auth().getCurrentUser() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[Object]),Qn("design:returntype","function"==typeof(h="undefined"!=typeof Promise&&Promise)?h:Object)],n.prototype,"getCurrentUser",null),Yn([(0,kn.catchErrorsDecorator)({title:"小程序匿名登录失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了匿名登录"," 2 - 调用 auth().signInAnonymouslyInWx() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[Object]),Qn("design:returntype","function"==typeof(d="undefined"!=typeof Promise&&Promise)?d:Object)],n.prototype,"signInAnonymouslyInWx",null),Yn([(0,kn.catchErrorsDecorator)({title:"小程序绑定OpenID失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序openId静默登录"," 2 - 调用 auth().bindOpenId() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(f="undefined"!=typeof Promise&&Promise)?f:Object)],n.prototype,"bindOpenId",null),Yn([(0,kn.catchErrorsDecorator)({title:"小程序unionId静默登录失败",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序unionId静默登录"," 2 - 调用 auth().signInWithUnionId() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(p="undefined"!=typeof Promise&&Promise)?p:Object)],n.prototype,"signInWithUnionId",null),Yn([(0,kn.catchErrorsDecorator)({title:"短信验证码登陆",messages:["请确认以下各项:"," 1 - 当前环境是否开启了小程序短信验证码登陆"," 2 - 调用 auth().signInWithSms() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[Object]),Qn("design:returntype","function"==typeof(v="undefined"!=typeof Promise&&Promise)?v:Object)],n.prototype,"signInWithSms",null),Yn([(0,kn.catchErrorsDecorator)({title:"邮箱验证码登陆",messages:["请确认以下各项:"," 1 - 当前环境是否开启了邮箱登陆"," 2 - 调用 auth().signInWithEmail() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[Object]),Qn("design:returntype","function"==typeof(y="undefined"!=typeof Promise&&Promise)?y:Object)],n.prototype,"signInWithEmail",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取用户是否被占用失败",messages:["请确认以下各项:"," 1 - 调用 auth().isUsernameRegistered() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[String]),Qn("design:returntype","function"==typeof(g="undefined"!=typeof Promise&&Promise)?g:Object)],n.prototype,"isUsernameRegistered",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取本地登录态失败",messages:["请确认以下各项:"," 1 - 调用 auth().getLoginState() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(m="undefined"!=typeof Promise&&Promise)?m:Object)],n.prototype,"getLoginState",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取用户信息失败",messages:["请确认以下各项:"," 1 - 是否已登录"," 2 - 调用 auth().getUserInfo() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(b="undefined"!=typeof Promise&&Promise)?b:Object)],n.prototype,"getUserInfo",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取微搭插件用户信息失败",messages:["请确认以下各项:"," 1 - 是否已登录"," 2 - 调用 auth().getWedaUserInfo() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(w="undefined"!=typeof Promise&&Promise)?w:Object)],n.prototype,"getWedaUserInfo",null),Yn([(0,kn.catchErrorsDecorator)({title:"绑定第三方登录方式失败",messages:["请确认以下各项:"," 1 - 调用 auth().bindWithProvider() 的语法或参数是否正确"," 2 - 此账户是否已经绑定此第三方","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",["function"==typeof(_=t.BindWithProviderRequest)?_:Object]),Qn("design:returntype","function"==typeof(E="undefined"!=typeof Promise&&Promise)?E:Object)],n.prototype,"bindWithProvider",null),Yn([(0,kn.catchErrorsDecorator)({title:"获取身份源类型",messages:["请确认以下各项:"," 1 - 调用 auth().getProviderSubType() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Cn.COMMUNITY_SITE_URL)]}),Qn("design:type",Function),Qn("design:paramtypes",[]),Qn("design:returntype","function"==typeof(I="undefined"!=typeof Promise&&Promise)?I:Object)],n.prototype,"getProviderSubType",null),n}(Jn),ur="auth";function lr(t,e){for(var n=[],r=0;r<=t.length;r++)n[r]=[r];for(var o=0;o<=e.length;o++)n[0][o]=o;for(r=1;r<=t.length;r++)for(o=1;o<=e.length;o++){var i=t[r-1].toLowerCase()===e[o-1].toLowerCase()?0:1;n[r][o]=Math.min(n[r-1][o]+1,n[r][o-1]+1,n[r-1][o-1]+i)}return n[t.length][e.length]}var hr={name:"auth",namespace:ur,entity:function(t){var e=function(t){var e,n=this;if(this.authInstance&&!t)return this.authInstance;t=t||{region:"",persistence:"local",apiPath:pe};var r=this.platform.adapter,o=t.persistence||r.primaryStorage;o&&o!==this.config.persistence&&this.updateConfig({persistence:o});var i=function(t,e){var n,r,o,i,s=this,a=t.region,c=void 0===a?"ap-shanghai":a,u=t.i18n,l=t.accessKey,h=t.useWxCloud,d=(null==e?void 0:e.platform)||xn.useDefaultAdapter.bind(e)(),f=d.runtime,p=d.adapter,v=e||{},y=v.env,g=v.clientId,m=v.debug,b=v.cache,w=v.app,_=v.getApiOrigin,E=(e||{}).apiOrigin;E||(E="https://".concat(y,".").concat(c,".tcb-api.tencentcloudapi.com"));var I={env:y,clientId:g,i18n:u,accessKey:l,useWxCloud:h,eventBus:new Ze.CloudbaseEventEmitter},S=new Rn(Bn($n($n({},I),{apiOrigin:E,getApiOrigin:_,apiPath:(null==t?void 0:t.apiPath)||pe,storage:null==t?void 0:t.storage,baseRequest:null==t?void 0:t.baseRequest,request:null==t?void 0:t.request,anonymousSignInFunc:null==t?void 0:t.anonymousSignInFunc,captchaOptions:null==t?void 0:t.captchaOptions,wxCloud:null==t?void 0:t.wxCloud,adapter:p,onCredentialsError:er(I.eventBus),headers:$n({"X-SDK-Version":"@cloudbase/js-sdk/".concat(t.sdkVersion)},t.headers||{}),detectSessionInUrl:t.detectSessionInUrl,debug:m,auth:null===(r=null===(n=e.app)||void 0===n?void 0:n.config)||void 0===r?void 0:r.auth}))),O=new cr($n($n({},I),{region:c,persistence:t.persistence,debug:m,cache:b||new Nn.CloudbaseCache({persistence:t.persistence,keys:{userInfoKey:"user_info_".concat(y)},platformInfo:d}),runtime:f||"web",_fromApp:w,oauthInstance:S,auth:null===(i=null===(o=e.app)||void 0===o?void 0:o.config)||void 0===i?void 0:i.auth}));return S.initializeSession(function(t,e){return Xn(s,void 0,void 0,function(){return Zn(this,function(n){return t?(t.type===Te?e?I.eventBus.fire(Oe,{event:be,info:$n($n({},t),{error:e})}):t.user&&O.createLoginState({},{userInfo:t.user}):t.type===Ae&&I.eventBus.fire(Oe,{event:Ie,info:$n($n({},t),{error:e})}),[2]):[2]})})}),{authInstance:O,oauthInstance:S}}($n($n({wxCloud:this.config.wxCloud,storage:this.config.storage},t),{persistence:this.config.persistence,i18n:this.config.i18n,accessKey:this.config.accessKey,useWxCloud:this.config.useWxCloud,sdkVersion:this.version,detectSessionInUrl:null===(e=this.config.auth)||void 0===e?void 0:e.detectSessionInUrl}),{env:this.config.env,clientId:this.config.clientId,getApiOrigin:function(){return n.request.getBaseEndPoint(n.config.endPointMode||"CLOUD_API")},platform:this.platform,cache:this.cache,app:this,debug:this.config.debug}),s=i.authInstance,a=i.oauthInstance;return this.oauthInstance=a,this.authInstance=s,this.authInstance},n=e.call(this,t);Object.assign(e,n),Object.setPrototypeOf(e,Object.getPrototypeOf(n));var r="undefined"!=typeof Proxy?new Proxy(e,{get:function(t,e,n){var r=Reflect.get(t,e,n);if(void 0!==r||"string"!=typeof e)return r;var o=function(t,e){for(var n=null,r=1/0,o=0,i=e;o<i.length;o++){var s=i[o];if(!s.startsWith("_")&&"constructor"!==s){var a=lr(t,s);a<r&&(r=a,n=s)}}return n}(e,Object.getOwnPropertyNames(Object.getPrototypeOf(t)).concat(Object.keys(t)).filter(function(e){return"function"==typeof t[e]}));return o&&console.warn("[CloudBase Auth] auth.".concat(e," is not a function. Did you mean: auth.").concat(o,"() ?")),r}}):e;return this[ur]=r,r}};try{cloudbase.registerComponent(hr)}catch(t){}var dr=l(3388),fr=function(){return fr=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},fr.apply(this,arguments)},pr=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},vr=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},yr=g,gr="cloudrun",mr=function(){function t(){}return t.prototype.callContainer=function(t,e){return pr(this,void 0,void 0,function(){var n,r,o;return vr(this,function(i){switch(i.label){case 0:if(n=t.name,r=t.data,!n)throw new Error(JSON.stringify({code:yr.INVALID_PARAMS,msg:"[".concat(gr,".callContainer] invalid name")}));try{o=r?JSON.stringify(r):""}catch(t){throw new Error(JSON.stringify({code:yr.INVALID_PARAMS,msg:"[".concat(gr,".callContainer] invalid data")}))}return[4,br.call(this,fr(fr({},t),{data:o}),e)];case 1:return[2,i.sent()]}})})},t}();function br(t,e){var n;return pr(this,void 0,void 0,function(){var r,o,i,s,a,c,u,l,h,d,f,p,v,y,g;return vr(this,function(m){switch(m.label){case 0:if(r=t.name,o=t.data,i=t.path,s=void 0===i?"":i,a=t.method,c=t.header,u=void 0===c?{}:c,l=this.getEndPointWithKey("GATEWAY"),h=l.BASE_URL,d=l.PROTOCOL,f="".concat(d).concat(h,"/cloudrun/").concat(r),p=s.startsWith("/")?s:"/".concat(s),v=["GET","HEAD"].includes(null===(n=null==a?void 0:a.toUpperCase)||void 0===n?void 0:n.call(a)))try{y={};try{y=JSON.parse(o)}catch(t){y=o||{}}p="".concat(p).concat(p.includes("?")?"&":"?").concat(Object.keys(y).map(function(t){return"".concat(t,"=").concat(y[t])}).join("&"))}catch(t){}return[4,this.request.fetch(fr(fr({method:a||"POST",headers:Object.assign({},{"Content-Type":"application/json; charset=utf-8"},u)},v?{}:{body:o}),{url:"".concat(f).concat(p),customReqOpts:e}))];case 1:return g=m.sent(),"node-sdk"===(null==e?void 0:e.from)?[2,g]:[4,g.data];case 2:return[2,m.sent()]}})})}var wr=new mr,_r={name:gr,entity:{callContainer:wr.callContainer}};try{cloudbase.registerComponent(_r)}catch(t){}function Er(t){try{t.registerComponent(_r)}catch(t){console.warn(t)}}try{window.registerCloudrun=Er}catch(t){}var Ir=function(){return Ir=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ir.apply(this,arguments)},Sr=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},Or=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Tr=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Ar=f,Pr=g,Rr=y,Cr=A,kr=x,Nr=et,xr="functions";function Ur(t){return t.length<=1024?t:"".concat(t.slice(0,1024),"…")}function Lr(t,e){return{code:(null==t?void 0:t.code)||Pr.NETWORK_ERROR,message:(null==t?void 0:t.message)||(null==t?void 0:t.msg)||"",requestId:e}}function Dr(t,e){if(t&&"object"==typeof t&&!Array.isArray(t))return Lr(t,e);if("string"==typeof t){try{var n=JSON.parse(t);if(n&&"object"==typeof n&&!Array.isArray(n))return Lr(n,e)}catch(t){}return{code:Pr.NETWORK_ERROR,message:Ur(t),requestId:e}}return{code:Pr.NETWORK_ERROR,message:Ur(null==t?"":String(t)),requestId:e}}var jr=function(){function t(){}var e,n,r;return t.invokeCloudrun=function(t,e,n){return Or(this,void 0,void 0,function(){var r,o,i,s,a,c,u;return Tr(this,function(l){switch(l.label){case 0:return r=e.name,o=e.path,i=void 0===o?"":o,s=e.method,a=e.header,c=void 0===a?{}:a,u=S(),[4,br.call(t,{name:r,data:n,path:i,method:s,header:Ir(Ir({},c),{"X-Request-Id":u})})];case 1:return[2,{result:l.sent(),requestId:u}]}})})},t.invokeGateway=function(t,e,n,r){return Or(this,void 0,void 0,function(){var o,i,s,a,c;return Tr(this,function(u){switch(u.label){case 0:o=t.request,i=t.config,u.label=1;case 1:return u.trys.push([1,3,,4]),[4,o.gateWay(Ir(Ir({},e),{path:"functions",shouldThrowOnError:!1}),r)];case 2:return s=u.sent(),[3,4];case 3:return a=u.sent(),function(t){if(!t)return!1;if(t instanceof SyntaxError||"SyntaxError"===t.name)return!0;var e=String(t.message||"");return/not valid JSON|Unexpected token|JSON\.parse|Failed to execute 'json'/i.test(e)}(c=a)?[2,kr(i,Dr(c.message,c.requestId))]:[2,Cr(n,c)];case 4:return Number(null==s?void 0:s.statusCode)>=400?[2,kr(i,Dr(null==s?void 0:s.data,null==s?void 0:s.requestId))]:[2,Cr(n,null,{requestId:null==s?void 0:s.requestId,result:null==s?void 0:s.data})]}})})},t.invokeCloudApi=function(t,e,n,r,o){var i,s,a;return Or(this,void 0,void 0,function(){var c,u,l,h,d,f,p;return Tr(this,function(v){switch(v.label){case 0:return c=e.name,u=e.data,l=e.query,h=e.parse,d=e.search,[4,t.request.send("functions.invokeFunction",{inQuery:l,parse:h,search:d,function_name:c,request_data:n},{endPointMode:"CLOUD_API",defaultQuery:(null===(i=null==u?void 0:u.params)||void 0===i?void 0:i.action)?{action:null===(s=null==u?void 0:u.params)||void 0===s?void 0:s.action}:{}},o)];case 1:if(f=v.sent(),void 0===(p=null===(a=f.data)||void 0===a?void 0:a.response_data))return[2,Cr(r,null,f)];if(h)return[2,Cr(r,null,{result:p,requestId:f.requestId})];try{return p=JSON.parse(p),[2,Cr(r,null,{result:p,requestId:f.requestId})]}catch(t){return[2,Cr(r,new Error("[".concat(Ar(),"][").concat(Pr.INVALID_PARAMS,"][").concat(xr,".callFunction] response data must be json")))]}return[2]}})})},t.prototype.callFunction=function(e,n,r){return Or(this,void 0,void 0,function(){var o,i,s,a,c,u;return Tr(this,function(l){switch(l.label){case 0:if(o=e.name,i=e.data,s=e.type,a=this.config,!o)return[2,kr(a,{code:Pr.INVALID_PARAMS,message:"[".concat(xr,".callFunction] invalid function name")})];try{c=i?JSON.stringify(i):""}catch(t){return[2,kr(a,{code:Pr.INVALID_PARAMS,message:"[".concat(xr,".callFunction] invalid data")})]}if("cloudrun"===s)return[2,t.invokeCloudrun(this,e,c)];l.label=1;case 1:return l.trys.push([1,5,,6]),function(t,e){return"GATEWAY"===t.endPointMode&&!function(t){return"lcap-common-service"===t||"lcap-datasource-test"===t||t.startsWith("lcap-data")||t.startsWith("lowcode-datasource")||"cloudbase_module"===t}(e)&&!function(t){return"lowcode-wx-datasource"===t}(e)}(a,o)?[4,t.invokeGateway(this,e,n,r)]:[3,3];case 2:return[2,l.sent()];case 3:return[4,t.invokeCloudApi(this,e,c,n,r)];case 4:return[2,l.sent()];case 5:return u=l.sent(),Cr(n,u),[3,6];case 6:return[2]}})})},function(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);i>3&&s&&Object.defineProperty(e,n,s)}([Nr({customInfo:{className:"Cloudbase",methodName:"callFunction"},title:"函数调用失败",messages:["请确认以下各项:"," 1 - 调用 callFunction() 的语法或参数是否正确"," 2 - 当前环境下是否存在此函数"," 3 - 函数安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(Rr)]}),Sr("design:type",Function),Sr("design:paramtypes",["function"==typeof(e=void 0!==dr.ICallFunctionOptions&&dr.ICallFunctionOptions)?e:Object,"function"==typeof(n="undefined"!=typeof Function&&Function)?n:Object,"function"==typeof(r=void 0!==dr.ICustomReqOpts&&dr.ICustomReqOpts)?r:Object]),Sr("design:returntype",Promise)],t.prototype,"callFunction",null),t}(),qr=new jr,Mr={name:xr,entity:{callFunction:qr.callFunction}};try{cloudbase.registerComponent(Mr)}catch(t){}var Br=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Wr=function(t){function e(e){var n=t.call(this,e)||this;return n.__isStorageError=!0,n.name="StorageError",n}return Br(e,t),e}(Error);function Fr(t){return"object"==typeof t&&null!==t&&"__isStorageError"in t}var Hr,Vr=function(t){function e(e,n,r){var o=t.call(this,e)||this;return o.name="StorageApiError",o.status=n,o.statusCode=r,o}return Br(e,t),e.prototype.toJSON=function(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}},e}(Wr);function Gr(){return globalThis.Buffer}function Kr(t){var e=Gr();return e?e.from(t).toString("base64"):btoa(t)}function Jr(t){return t.split("/").map(function(t){return encodeURIComponent(t)}).join("/")}Br(function(t,e){var n=Hr.call(this,t)||this;return n.name="StorageUnknownError",n.originalError=e,n},Hr=Wr);var zr=function(){return zr=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},zr.apply(this,arguments)},$r=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Yr=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Qr="/v1/storages";function Xr(t,e){return $r(this,void 0,Promise,function(){var n;return Yr(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,t()];case 1:return[2,{data:r.sent(),error:null}];case 2:if(n=r.sent(),e)throw n;return Fr(n)?[2,{data:null,error:n}]:[2,{data:null,error:new Wr((null==n?void 0:n.message)||String(n))}];case 3:return[2]}})})}var Zr=function(){function t(t){this.ctx=t}return Object.defineProperty(t.prototype,"request",{get:function(){return this.ctx.request},enumerable:!1,configurable:!0}),t.prototype.gatewayOrigin=function(){return this.request.getBaseEndPoint("GATEWAY")},t.prototype.buildUrl=function(t,e){var n="".concat(this.gatewayOrigin()).concat(Qr).concat(t),r=function(t){if(!t)return"";var e=[];return Object.keys(t).forEach(function(n){var r=t[n];null!=r&&e.push("".concat(encodeURIComponent(n),"=").concat(encodeURIComponent(String(r))))}),e.join("&")}(e);return r&&(n+=(n.includes("?")?"&":"?")+r),n},t.prototype.toFullUrl=function(t){return t?/^https?:\/\//.test(t)||t.startsWith("//")?t:"".concat(this.gatewayOrigin()).concat(Qr).concat(t.startsWith("/")?"":"/").concat(t):t},t.prototype.send=function(t){return $r(this,void 0,Promise,function(){var e,n,r,o,i,s;return Yr(this,function(a){switch(a.label){case 0:return e=this.buildUrl(t.path,t.query),n=t.method.toUpperCase(),r=["GET","HEAD"].includes(n),o=zr({},t.headers||{}),r||(void 0!==t.rawBody?i=t.rawBody:void 0!==t.json&&(o["Content-Type"]=o["Content-Type"]||"application/json",i=JSON.stringify(t.json))),[4,this.request.fetch(zr(zr(zr(zr({url:e,method:n,headers:o},void 0!==i?{body:i}:{}),{withCredentials:!1!==t.withCredentials,shouldThrowOnError:!1}),t.signal?{signal:t.signal}:{}),t.cache?{cache:t.cache}:{}))];case 1:return s=a.sent(),[2,this.unwrap(s,e)]}})})},t.prototype.download=function(t){var e,n;return $r(this,void 0,Promise,function(){var r,o,i,s;return Yr(this,function(a){switch(a.label){case 0:return r=this.buildUrl(t.path,t.query),[4,this.request.fetch(zr(zr({url:r,method:"GET",headers:zr({},t.headers||{}),stream:!0,withCredentials:!1!==t.withCredentials,shouldThrowOnError:!1},t.signal?{signal:t.signal}:{}),t.cache?{cache:t.cache}:{}))];case 1:if(o=a.sent(),null===(e=t.signal)||void 0===e?void 0:e.aborted)throw new Vr("The download was aborted",0,"STORAGE_PG_ABORTED");if(304===(i=Number(null!==(n=null==o?void 0:o.statusCode)&&void 0!==n?n:200)))throw new Vr("Not Modified",i,"STORAGE_PG_NOT_MODIFIED");if(i>=400)throw new Vr("Download failed with status ".concat(i),i,"STORAGE_PG_REQUEST_FAIL");if(!(s=null==o?void 0:o.response))throw new Vr("Underlying adapter did not expose the raw Response",i,"STORAGE_PG_NO_RESPONSE");return[2,{response:s,status:i,header:null==o?void 0:o.header}]}})})},t.prototype.unwrap=function(t,e){var n,r;return $r(this,void 0,Promise,function(){var o,i,s,a;return Yr(this,function(c){switch(c.label){case 0:o=Number(null!==(r=null!==(n=null==t?void 0:t.statusCode)&&void 0!==n?n:null==t?void 0:t.status)&&void 0!==r?r:200),i=null==t?void 0:t.data,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,i];case 2:return i=c.sent(),[3,4];case 3:return c.sent(),i=void 0,[3,4];case 4:if(o>=200&&o<300)return[2,i];throw s=(null==i?void 0:i.code)||(null==i?void 0:i.error)||"STORAGE_PG_REQUEST_FAIL",a=(null==i?void 0:i.message)||"Storage request failed with status ".concat(o,": ").concat(e),new Vr(a,o,s)}})})},t}(),to=function(){return to=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},to.apply(this,arguments)},eo=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},no=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function ro(t){return Fr(t)?t:new Wr((null==t?void 0:t.message)||String(t))}function oo(t){var e={};return void 0!==(null==t?void 0:t.download)&&(e.download=!0===t.download?"":t.download),void 0!==(null==t?void 0:t.cacheNonce)&&(e.cacheNonce=String(t.cacheNonce)),{headers:{},query:e}}var io=function(){function t(t){this.ctx=t}return t.prototype.then=function(t,e){return this.execute().then(t,e)},t.prototype.execute=function(){var t,e;return eo(this,void 0,Promise,function(){var n,r,o,i,s;return no(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),n=oo(this.ctx.options),r=n.headers,o=n.query,[4,this.ctx.http.download({path:"/object/".concat(this.ctx.bucketId,"/").concat(Jr(this.ctx.cleanName)),headers:to(to({},this.ctx.headers),r),query:o,signal:null===(t=this.ctx.parameters)||void 0===t?void 0:t.signal,cache:null===(e=this.ctx.parameters)||void 0===e?void 0:e.cache})];case 1:if(!(i=a.sent().response).body)throw new Vr("Response body is empty",i.status,"STORAGE_PG_EMPTY_BODY");return[2,{data:i.body,error:null}];case 2:if(s=a.sent(),this.ctx.shouldThrowOnError)throw s;return[2,{data:null,error:ro(s)}];case 3:return[2]}})})},t}(),so=function(){function t(t){this.ctx=t}return t.prototype.asStream=function(){return new io(this.ctx)},t.prototype.then=function(t,e){return this.execute().then(t,e)},t.prototype.execute=function(){var t,e;return eo(this,void 0,Promise,function(){var n,r,o,i,s,a;return no(this,function(c){switch(c.label){case 0:return c.trys.push([0,3,,4]),n=oo(this.ctx.options),r=n.headers,o=n.query,[4,this.ctx.http.download({path:"/object/".concat(this.ctx.bucketId,"/").concat(Jr(this.ctx.cleanName)),headers:to(to({},this.ctx.headers),r),query:o,signal:null===(t=this.ctx.parameters)||void 0===t?void 0:t.signal,cache:null===(e=this.ctx.parameters)||void 0===e?void 0:e.cache})];case 1:return i=c.sent().response,a={},[4,i.blob()];case 2:return[2,(a.data=c.sent(),a.error=null,a)];case 3:if(s=c.sent(),this.ctx.shouldThrowOnError)throw s;return[2,{data:null,error:ro(s)}];case 4:return[2]}})})},t}(),ao=function(){return ao=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ao.apply(this,arguments)},co=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},uo=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},lo="3600",ho=function(){function t(t,e,n){void 0===n&&(n=!1),this.headers={},this.http=t,this.bucketId=e,this.shouldThrowOnError=n}return t.prototype.throwOnError=function(){return this.shouldThrowOnError=!0,this},t.prototype.setHeader=function(t,e){var n;if("string"!=typeof t||""===t.trim())throw new Wr("setHeader requires a non-empty header name");if(/[\r\n]/.test(t)||"string"==typeof e&&/[\r\n]/.test(e))throw new Wr("setHeader does not allow CR/LF characters in header name or value");return this.headers=ao(ao({},this.headers),((n={})[t]=String(e),n)),this},t.prototype.upload=function(t,e,n){return co(this,void 0,Promise,function(){return uo(this,function(r){return[2,this.uploadOrUpdate("POST",t,e,n)]})})},t.prototype.update=function(t,e,n){return co(this,void 0,Promise,function(){return uo(this,function(r){return[2,this.uploadOrUpdate("PUT",t,e,n)]})})},t.prototype.download=function(t,e,n){return new so({http:this.http,bucketId:this.bucketId,cleanName:this.cleanPath(t),options:e,parameters:n,headers:this.headers,shouldThrowOnError:this.shouldThrowOnError})},t.prototype.list=function(t,e,n){return co(this,void 0,Promise,function(){var r=this;return uo(this,function(o){return[2,Xr(function(){return co(r,void 0,void 0,function(){var r;return uo(this,function(o){return r={prefix:t||""},void 0!==(null==e?void 0:e.limit)&&(r.limit=e.limit),void 0!==(null==e?void 0:e.cursor)&&(r.cursor=e.cursor),void 0!==(null==e?void 0:e.withDelimiter)&&(r.with_delimiter=e.withDelimiter),void 0!==(null==e?void 0:e.sortBy)&&(r.sortBy=e.sortBy),[2,this.send({method:"POST",path:"/object/list/".concat(this.bucketId),json:r,signal:null==n?void 0:n.signal,cache:null==n?void 0:n.cache})]})})},this.shouldThrowOnError)]})})},t.prototype.remove=function(t){return co(this,void 0,Promise,function(){var e=this;return uo(this,function(n){return[2,Xr(function(){return co(e,void 0,void 0,function(){var e,n,r,o,i,s=this;return uo(this,function(a){switch(a.label){case 0:e=t.map(function(t){return s.cleanPath(t)}),n=[],r=0,a.label=1;case 1:return r<e.length?(o=e.slice(r,r+100),[4,this.send({method:"DELETE",path:"/object/".concat(this.bucketId),json:{prefixes:o}})]):[3,4];case 2:i=a.sent(),Array.isArray(i)&&n.push.apply(n,i),a.label=3;case 3:return r+=100,[3,1];case 4:return[2,n]}})})},this.shouldThrowOnError)]})})},t.prototype.copy=function(t,e,n){return co(this,void 0,Promise,function(){var r=this;return uo(this,function(o){return[2,Xr(function(){return co(r,void 0,void 0,function(){var r;return uo(this,function(o){switch(o.label){case 0:return r=this.buildCopyMoveHeaders(n),[4,this.send({method:"POST",path:"/object/copy",json:{bucketId:this.bucketId,sourceKey:this.cleanPath(t),destinationKey:this.cleanPath(e),destinationBucket:null==n?void 0:n.destinationBucket,copyMetadata:null==n?void 0:n.copyMetadata,metadata:null==n?void 0:n.metadata},headers:r})];case 1:return[2,{path:o.sent().Key}]}})})},this.shouldThrowOnError)]})})},t.prototype.move=function(t,e,n){return co(this,void 0,Promise,function(){var r=this;return uo(this,function(o){return[2,Xr(function(){return co(r,void 0,void 0,function(){return uo(this,function(r){switch(r.label){case 0:return[4,this.send({method:"POST",path:"/object/move",json:{bucketId:this.bucketId,sourceKey:this.cleanPath(t),destinationKey:this.cleanPath(e),destinationBucket:null==n?void 0:n.destinationBucket}})];case 1:return[2,{message:r.sent().message||"Successfully moved"}]}})})},this.shouldThrowOnError)]})})},t.prototype.info=function(t){return co(this,void 0,Promise,function(){var e=this;return uo(this,function(n){return[2,Xr(function(){return co(e,void 0,void 0,function(){var e,n;return uo(this,function(r){switch(r.label){case 0:return e=this.cleanPath(t),[4,this.send({method:"GET",path:"/object/info/".concat(this.bucketId,"/").concat(this.encodePath(e))})];case 1:return[2,{id:(n=r.sent()).id,name:n.name,version:n.version,bucketId:n.bucket_id,size:n.size,contentType:n.content_type,cacheControl:n.cache_control,etag:n.etag,metadata:n.metadata,lastModified:n.last_modified,createdAt:n.created_at}]}})})},this.shouldThrowOnError)]})})},t.prototype.exists=function(t){return co(this,void 0,Promise,function(){var e,n,r;return uo(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),e=this.cleanPath(t),[4,this.send({method:"GET",path:"/object/info/".concat(this.bucketId,"/").concat(this.encodePath(e))})];case 1:return o.sent(),[2,{data:!0,error:null}];case 2:if(n=o.sent(),void 0!==(r=null==n?void 0:n.status)&&[400,404].includes(Number(r)))return[2,{data:!1,error:null}];if(this.shouldThrowOnError)throw n;return[2,{data:null,error:n instanceof Wr?n:new Wr((null==n?void 0:n.message)||String(n))}];case 3:return[2]}})})},t.prototype.createSignedUrl=function(t,e,n){return co(this,void 0,Promise,function(){var r=this;return uo(this,function(o){return[2,Xr(function(){return co(r,void 0,void 0,function(){var r,o,i;return uo(this,function(s){switch(s.label){case 0:return r=this.cleanPath(t),[4,this.send({method:"POST",path:"/object/sign/".concat(this.bucketId,"/").concat(this.encodePath(r)),json:{expiresIn:e}})];case 1:return o=s.sent(),i=o.fullSignedURL||this.http.toFullUrl(o.signedURL||""),[2,{fullSignedURL:this.appendUrlOptions(i,n)}]}})})},this.shouldThrowOnError)]})})},t.prototype.createSignedUrls=function(t,e,n){return co(this,void 0,Promise,function(){var r=this;return uo(this,function(o){return[2,Xr(function(){return co(r,void 0,void 0,function(){var r,o,i,s,a=this;return uo(this,function(c){switch(c.label){case 0:r=t.map(function(t){return a.cleanPath(t)}),o=[],i=0,c.label=1;case 1:return i<r.length?(s=r.slice(i,i+500),[4,this.send({method:"POST",path:"/object/sign/".concat(this.bucketId),json:{expiresIn:e,paths:s}})]):[3,4];case 2:c.sent().forEach(function(t){var e,r=t.fullSignedURL||(t.signedURL?a.http.toFullUrl(t.signedURL):null);o.push({path:t.path,fullSignedURL:r?a.appendUrlOptions(r,n):null,error:null!==(e=t.error)&&void 0!==e?e:null})}),c.label=3;case 3:return i+=500,[3,1];case 4:return[2,o]}})})},this.shouldThrowOnError)]})})},t.prototype.createSignedUploadUrl=function(t,e){return co(this,void 0,Promise,function(){var n=this;return uo(this,function(r){return[2,Xr(function(){return co(n,void 0,void 0,function(){var n,r,o;return uo(this,function(i){switch(i.label){case 0:return n=this.cleanPath(t),r={},(null==e?void 0:e.upsert)&&(r["x-upsert"]="true"),[4,this.send({method:"POST",path:"/object/upload/sign/".concat(this.bucketId,"/").concat(this.encodePath(n)),headers:r})];case 1:return[2,{fullSignedURL:(o=i.sent()).fullURL||this.http.toFullUrl(o.url||""),path:n,token:o.token}]}})})},this.shouldThrowOnError)]})})},t.prototype.uploadToSignedUrl=function(t,e,n,r){return co(this,void 0,Promise,function(){var o=this;return uo(this,function(i){return[2,Xr(function(){return co(o,void 0,void 0,function(){var o,i,s,a,c;return uo(this,function(u){switch(u.label){case 0:return o=this.cleanPath(t),i=this.buildUploadBody(n,r),s=i.body,a=i.headers,[4,this.send({method:"PUT",path:"/object/upload/sign/".concat(this.bucketId,"/").concat(this.encodePath(o)),query:{token:e},rawBody:s,headers:a,withCredentials:!1})];case 1:return c=u.sent(),[2,{path:o,fullPath:c.Key}]}})})},this.shouldThrowOnError)]})})},t.prototype.getPublicUrl=function(t,e){var n=this.cleanPath(t),r=this.http.buildUrl("/object/public/".concat(this.bucketId,"/").concat(this.encodePath(n)));return{data:{publicUrl:this.appendUrlOptions(r,e)}}},t.prototype.send=function(t){return this.http.send(ao(ao({},t),{headers:ao(ao({},this.headers),t.headers||{})}))},t.prototype.uploadOrUpdate=function(t,e,n,r){return co(this,void 0,Promise,function(){var o=this;return uo(this,function(i){return[2,Xr(function(){return co(o,void 0,void 0,function(){var o,i,s,a,c;return uo(this,function(u){switch(u.label){case 0:return o=this.cleanPath(e),i=this.buildUploadBody(n,r),s=i.body,a=i.headers,"POST"===t&&(a["x-upsert"]=String(Boolean(null==r?void 0:r.upsert))),[4,this.send({method:t,path:"/object/".concat(this.bucketId,"/").concat(this.encodePath(o)),rawBody:s,headers:a})];case 1:return[2,{id:(c=u.sent()).Id,path:o,fullPath:c.Key}]}})})},this.shouldThrowOnError)]})})},t.prototype.cleanPath=function(t){var e=t.replace(/^\/+|\/+$/g,"").replace(/\/+/g,"/");if(e.split("/").some(function(t){return".."===t}))throw new Wr('invalid path: ".." segment is not allowed');return e},t.prototype.encodePath=function(t){return Jr(t)},t.prototype.buildUploadBody=function(t,e){var n,r,o,i,s,a=ao({},(null==e?void 0:e.headers)||{}),c=t,u="undefined"!=typeof FormData&&t instanceof FormData;if("undefined"!=typeof Blob&&t instanceof Blob||u){var l=void 0,h={};if(u){var d=this.extractFromFormData(t);l=d.file,h=d.fields}else l=t;var f=null!==(r=null!==(n=null==e?void 0:e.cacheControl)&&void 0!==n?n:h.cacheControl)&&void 0!==r?r:lo,p=null!==(o=null==e?void 0:e.contentType)&&void 0!==o?o:h.contentType,v=void 0!==(null==e?void 0:e.metadata)?JSON.stringify(e.metadata):h.metadata,y=new FormData;void 0!==f&&y.append("cacheControl",String(f)),void 0!==p&&y.append("contentType",p),void 0!==v&&y.append("metadata",v),y.append("",l),c=y}else c=t,f=null!==(i=null==e?void 0:e.cacheControl)&&void 0!==i?i:lo,p=null!==(s=null==e?void 0:e.contentType)&&void 0!==s?s:"text/plain;charset=UTF-8",a["cache-control"]="max-age=".concat(f),p&&(a["content-type"]=p),(null==e?void 0:e.metadata)&&(a["x-metadata"]=this.toBase64(JSON.stringify(e.metadata)));return{body:c,headers:a}},t.prototype.extractFromFormData=function(t){var e,n={},r=0,o=[];if(t.forEach(function(t,i){if("undefined"!=typeof Blob&&t instanceof Blob)return e=t,void(r+=1);"cacheControl"!==i&&"contentType"!==i&&"metadata"!==i?o.push(i):n[i]=String(t)}),o.length>0&&console.warn("Ignored unsupported FormData field(s): [".concat(o.join(", "),"]. Only file, cacheControl, contentType and metadata are supported")),0===r||!e)throw new Wr("FormData must contain a file");if(r>1)throw new Wr("FormData must contain exactly one file");return{file:e,fields:n}},t.prototype.buildCopyMoveHeaders=function(t){var e={};return(null==t?void 0:t.upsert)&&(e["x-upsert"]="true"),!1===(null==t?void 0:t.copyMetadata)&&(null==t?void 0:t.metadata)&&(e["x-metadata"]=this.toBase64(JSON.stringify(t.metadata))),e},t.prototype.appendUrlOptions=function(t,e){var n=[];if(void 0!==(null==e?void 0:e.download)){var r=!0===e.download?"":String(e.download);n.push("download=".concat(encodeURIComponent(r)))}if(void 0!==(null==e?void 0:e.cacheNonce)&&n.push("cacheNonce=".concat(encodeURIComponent(String(e.cacheNonce)))),0===n.length)return t;var o=t.includes("?")?"&":"?";return"".concat(t).concat(o).concat(n.join("&"))},t.prototype.toBase64=function(t){return Kr(t)},t}(),fo=/[\x00-\x20\x7f/\\?#%]/;function po(t,e){if("string"!=typeof t||0===t.length)throw new Wr("[storage.".concat(e,"] bucketId is required"));if(t.length>256)throw new Wr("[storage.".concat(e,"] invalid bucketId: length must be 1-").concat(256));var n=fo.exec(t);if(n){var r="[storage.".concat(e,'] invalid bucketId "').concat(t,'": ')+"contains forbidden character ".concat(JSON.stringify(n[0]),"; ")+'must not contain whitespace, control chars, "/", "\\", "?", "#" or "%"';throw new Wr(r)}}var vo,yo=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},go=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},mo=function(){function t(t,e){void 0===e&&(e=!1),this.http=new Zr(t),this.shouldThrowOnError=e}return t.prototype.throwOnError=function(){return this.shouldThrowOnError=!0,this},t.prototype.listBuckets=function(t){return yo(this,void 0,Promise,function(){var e=this;return go(this,function(n){return[2,Xr(function(){var n={};return void 0!==(null==t?void 0:t.limit)&&(n.limit=t.limit),void 0!==(null==t?void 0:t.offset)&&(n.offset=t.offset),(null==t?void 0:t.sortColumn)&&(n.sortColumn=t.sortColumn),(null==t?void 0:t.sortOrder)&&(n.sortOrder=t.sortOrder),(null==t?void 0:t.search)&&(n.search=t.search),e.http.send({method:"GET",path:"/bucket/",query:n})},this.shouldThrowOnError)]})})},t.prototype.getBucket=function(t){return yo(this,void 0,Promise,function(){var e=this;return go(this,function(n){return[2,Xr(function(){return po(t,"getBucket"),e.http.send({method:"GET",path:"/bucket/".concat(t)})},this.shouldThrowOnError)]})})},t.prototype.createBucket=function(t,e){return yo(this,void 0,Promise,function(){var n=this;return go(this,function(r){return[2,Xr(function(){var r;return po(t,"createBucket"),n.http.send({method:"POST",path:"/bucket/",json:{id:t,name:t,public:null!==(r=null==e?void 0:e.public)&&void 0!==r&&r,type:null==e?void 0:e.type,file_size_limit:null==e?void 0:e.fileSizeLimit,allowed_mime_types:null==e?void 0:e.allowedMimeTypes}})},this.shouldThrowOnError)]})})},t.prototype.updateBucket=function(t,e){return yo(this,void 0,Promise,function(){var n=this;return go(this,function(r){return[2,Xr(function(){return po(t,"updateBucket"),n.http.send({method:"PUT",path:"/bucket/".concat(t),json:{public:e.public,file_size_limit:e.fileSizeLimit,allowed_mime_types:e.allowedMimeTypes}})},this.shouldThrowOnError)]})})},t.prototype.deleteBucket=function(t){return yo(this,void 0,Promise,function(){var e=this;return go(this,function(n){return[2,Xr(function(){return po(t,"deleteBucket"),e.http.send({method:"DELETE",path:"/bucket/".concat(t)})},this.shouldThrowOnError)]})})},t}(),bo=function(){return bo=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},bo.apply(this,arguments)},wo=function(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s},_o=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},Eo=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Io=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(t){t.put="put",t.post="post"}(vo||(vo={}));var So=f,Oo=g,To=y,Ao=_,Po=E,Ro=function(t){return"[object Object]"===Object.prototype.toString.call(t)},Co=A,ko=x,No=P,xo=et,Uo="storage";function Lo(t,e){return e&&"function"!=typeof e?[bo(bo({},t),{customReqOpts:e}),void 0]:[t,e]}var Do=function(t,e,n){return Eo(void 0,void 0,void 0,function(){var r,o,i;return Io(this,function(s){switch(s.label){case 0:return[4,t.gateWay({path:"storages",name:"get-objects-upload-info",data:[bo({objectId:e.path},e.signedHeader?{signedHeader:e.signedHeader}:{})]},n)];case 1:return r=U(r=s.sent()),o=(null===(i=r.data)||void 0===i?void 0:i[0])||{},[2,bo(bo({},r),{data:bo(bo({},o.code?bo({},o):{}),{authorization:o.authorization,token:o.token,url:o.uploadUrl,fileId:o.cloudObjectId,cosFileId:o.cloudObjectMeta,download_url:o.downloadUrl})})]}})})},jo=function(t,e,n){return Eo(void 0,void 0,void 0,function(){var r;return Io(this,function(o){switch(o.label){case 0:return[4,t.gateWay({path:"storages",name:"get-objects-download-info",data:e.convertedFileList.map(function(t){return bo({cloudObjectId:t.fileid},null!=t.max_age?{maxAge:t.max_age}:{})})},n)];case 1:return r=U(r=o.sent()),[2,bo(bo({},r),{data:{download_list:Array.isArray(r.data)?r.data.map(function(t){return{code:t.code||"SUCCESS",message:t.message,fileid:t.cloudObjectId,download_url:t.downloadUrl,fileID:t.cloudObjectId,tempFileURL:t.downloadUrl,mime_type:t.contentType||Wo(null,t.cloudObjectId||"")}}):[]}})]}})})},qo=function(t,e,n){return Eo(void 0,void 0,void 0,function(){var r;return Io(this,function(o){switch(o.label){case 0:return[4,t.gateWay({path:"storages",name:"delete-objects",data:e.fileList.map(function(t){return{cloudObjectId:t}})},n)];case 1:return r=U(r=o.sent()),[2,bo(bo({},r),{data:{delete_list:Array.isArray(r.data)?r.data.map(function(t){return{code:t.code||"SUCCESS",fileID:t.cloudObjectId,message:t.message}}):[]}})]}})})},Mo=function(t,e,n){return Eo(void 0,void 0,void 0,function(){var r;return Io(this,function(o){switch(o.label){case 0:return[4,t.gateWay({path:"storages",name:"copy-objects",data:e.convertedFileList.map(function(t){return{srcPath:t.src_path,dstPath:t.dst_path,overwrite:t.overwrite,removeOriginal:t.remove_original}})},n)];case 1:return r=U(r=o.sent()),[2,bo(bo({},r),{data:{copy_list:Array.isArray(r.data)?r.data.map(function(t){return{code:t.code||"SUCCESS",fileID:t.cloudObjectId,fileId:t.cloudObjectId,message:t.message}}):[]}})]}})})},Bo={txt:"text/plain",json:"application/json",html:"text/html",htm:"text/html",css:"text/css",js:"application/javascript",csv:"text/csv",xml:"application/xml",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",ico:"image/x-icon",pdf:"application/pdf",zip:"application/zip",gz:"application/gzip",mp4:"video/mp4",webm:"video/webm",mp3:"audio/mpeg",wav:"audio/wav"};function Wo(t,e){if("undefined"!=typeof Blob&&t instanceof Blob&&t.type)return t.type;var n=/\.([a-zA-Z0-9]+)$/.exec(e||""),r=n?n[1].toLowerCase():"";return Bo[r]||"application/octet-stream"}function Fo(){var t=globalThis.wx;return"function"==typeof(null==t?void 0:t.getFileSystemManager)}function Ho(t,e){var n=e.toLowerCase();return Object.keys(t).some(function(t){return t.toLowerCase()===n})}function Vo(t){return Object.keys(t).reduce(function(e,n){var r;return bo(bo({},e),((r={})[n]=[t[n]],r))},{})}function Go(t){return"number"==typeof t&&Number.isInteger(t)&&t>=1}var Ko=function(){function t(t){this.context=t}var e,n,r,o,i,s,a,c,u,l,h,d,f,p,v,y,g;return Object.defineProperty(t.prototype,"config",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.config},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"request",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.request},enumerable:!1,configurable:!0}),t.prototype.isGateWay=function(){return"GATEWAY"===(this.config.endPointMode||"CLOUD_API")},t.prototype.uploadFile=function(t,e){var n,r;return Eo(this,void 0,Promise,function(){var o,i,s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I,S,O,T,A,P,R,C,k,N,x,U,L,D,j;return Io(this,function(q){switch(q.label){case 0:if(U=Lo(t,e),t=U[0],e=U[1],o=t.cloudPath,i=t.filePath,s=t.onUploadProgress,L=t.method,a=void 0===L?"put":L,D=t.headers,c=void 0===D?{}:D,u=t.fileContent,!Po(o)||!i&&!u)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".uploadFile] invalid params")})];if(i&&u&&console.warn("[".concat(So(),"][").concat(Uo,".uploadFile] fileContent 是兼容字段,与 filePath 同时传入时忽略,实际使用 filePath")),l=null!=i?i:u,(h={put:vo.put,post:vo.post}[a.toLocaleLowerCase()]||vo.put)===vo.post&&console.warn("[".concat(So(),"][").concat(Uo,".uploadFile] method: 'post' 已废弃,请改用 'put'")),d=this.isGateWay(),f=bo({},c),p=Object.keys(c).reduce(function(t,e){return"content-length"!==e.toLowerCase()&&(t[e]=c[e]),t},{}),h===vo.put&&d){if(!Ho(f,"content-length")){if(v=null===(r=null===(n=this.request)||void 0===n?void 0:n.getUploadByteLength)||void 0===r?void 0:r.call(n,l),"number"!=typeof(y="number"==typeof v?v:function(t){if((!Fo()||"string"!=typeof t)&&null!==t){if("undefined"!=typeof Blob&&t instanceof Blob)return t.size;if("undefined"!=typeof ArrayBuffer){if(t instanceof ArrayBuffer)return t.byteLength;if("function"==typeof ArrayBuffer.isView&&ArrayBuffer.isView(t))return t.byteLength}if("string"==typeof t){if("undefined"!=typeof Blob)return new Blob([t]).size;var e=function(t){var e;return null===(e=Gr())||void 0===e?void 0:e.byteLength(t)}(t);return"number"==typeof e?e:t.length}return"object"==typeof t&&"number"==typeof t.size?t.size:void 0}}(l)))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:Fo()?"[".concat(Uo,".uploadFile] 无法计算 content-length,请确认上传内容为有效的本地临时路径,或传入 ArrayBuffer"):"[".concat(Uo,".uploadFile] 无法计算 content-length,请传入 File/Blob/Buffer/ArrayBuffer,或在 headers 中提供 content-length")})];f["content-length"]=String(y)}Ho(f,"content-type")||(f["content-type"]=Wo(l,o)),Ho(p,"content-type")||(p["content-type"]=Wo(l,o))}return[4,this.getUploadMetadata({cloudPath:o,method:h,headers:h!==vo.put||d?void 0:p,signedHeader:h===vo.put&&d?Vo(f):void 0,customReqOpts:t.customReqOpts})];case 1:return g=q.sent(),m=g.data,b=g.requestId,(null==(w=m)?void 0:w.code)||!(null==w?void 0:w.url)?(_=(null==w?void 0:w.code)||Oo.OPERATION_FAIL,E=(null==w?void 0:w.message)||"get upload info failed",[2,Co(e,new Error("[".concat(So(),"][").concat(_,"][").concat(Uo,"]:").concat(E)))]):(I=m.url,S=m.authorization,O=m.token,T=m.fileId,A=m.cosFileId,P=m.download_url,C=bo(bo({},R={url:I,file:l,name:o,onUploadProgress:s,fileId:T,requestId:b}),{method:vo.put,headers:bo(bo({},p),{authorization:S,"x-cos-meta-fileid":A,"x-cos-security-token":O})}),k=bo(bo({},R),{method:vo.post,data:{key:o,signature:S,"x-cos-meta-fileid":A,success_action_status:"201","x-cos-security-token":O}}),(j={})[vo.put]={params:C,isSuccess:function(t){return t>=200&&t<300}},j[vo.post]={params:k,isSuccess:function(t){return 201===t}},N=j,[4,this.request.upload(N[h].params)]);case 2:return x=q.sent(),N[h].isSuccess(x.statusCode)?[2,Co(e,null,{fileID:T,download_url:P,requestId:b})]:[2,Co(e,new Error("[".concat(So(),"][").concat(Oo.OPERATION_FAIL,"][").concat(Uo,"]:").concat(x.data)))]}})})},t.prototype.getUploadMetadata=function(t,e){return Eo(this,void 0,Promise,function(){var n,r,o,i,s,a,c,u,l,h;return Io(this,function(d){switch(d.label){case 0:if(n=t.cloudPath,r=t.method,o=t.headers,i=t.signedHeader,!Po(n))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getUploadMetadata] invalid cloudPath")})];s=this.request,a="storage.getUploadMetadata",d.label=1;case 1:return d.trys.push([1,6,,7]),c=void 0,u={path:n},l=this.isGateWay(),r&&(u.method=r),r===vo.put&&(l&&i?u.signedHeader=i:!l&&o&&(u.headers=o)),r!==vo.post&&l?[3,3]:[4,s.send(a,u,{endPointMode:"CLOUD_API"},t.customReqOpts)];case 2:return c=d.sent(),[3,5];case 3:return[4,Do(s,u,t.customReqOpts)];case 4:c=d.sent(),d.label=5;case 5:return[2,Co(e,null,c)];case 6:return h=d.sent(),[2,Co(e,h)];case 7:return[2]}})})},t.prototype.deleteFile=function(t,e){return Eo(this,void 0,Promise,function(){var n,r,o,i,s,a,c,u,l;return Io(this,function(h){switch(h.label){case 0:if(l=Lo(t,e),t=l[0],e=l[1],!(n=t.fileList)||!Ao(n)||0===n.length)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".deleteFile] fileList must not be empty")})];for(r=0,o=n;r<o.length;r++)if(!(i=o[r])||!Po(i))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".deleteFile] fileID must be string")})];return s="storage.batchDeleteFile",a=this.request,c={},this.isGateWay()?[4,qo(a,{fileList:n},t.customReqOpts)]:[3,2];case 1:return c=h.sent(),[3,4];case 2:return[4,a.send(s,{fileid_list:n},t.customReqOpts)];case 3:c=h.sent(),h.label=4;case 4:return c.code?[2,Co(e,null,c)]:(u={fileList:c.data.delete_list,requestId:c.requestId},[2,Co(e,null,u)])}})})},t.prototype.getTempFileURL=function(t,e){var n;return Eo(this,void 0,Promise,function(){var r,o,i,s,a,c,u,l,h,d,f,p;return Io(this,function(v){switch(v.label){case 0:if(p=Lo(t,e),t=p[0],e=p[1],!(r=t.fileList)||!Ao(r)||0===r.length)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getTempFileURL] fileList must not be empty")})];for(o=[],i=!1,s=0,a=r;s<a.length;s++)if(c=a[s],Ro(c)){if(!Object.prototype.hasOwnProperty.call(c,"fileID"))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getTempFileURL] file info must include fileID")})];if(u={fileid:c.fileID},Object.prototype.hasOwnProperty.call(c,"maxAge")){if(!Go(l=c.maxAge))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getTempFileURL] maxAge must be an integer greater than or equal to ").concat(1)})];l>3600&&!i&&(No(Oo.INVALID_PARAMS,"[".concat(Uo,".getTempFileURL] maxAge ").concat(l," 大于 ").concat(3600,",仍按原值下发")),i=!0),u.max_age=l}o.push(u)}else{if(!Po(c))return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getTempFileURL] invalid fileList")})];o.push({fileid:c})}return h="storage.batchGetDownloadUrl",d=this.request,f={},this.isGateWay()?[4,jo(d,{convertedFileList:o},t.customReqOpts)]:[3,2];case 1:return f=v.sent(),[3,4];case 2:return[4,d.send(h,{file_list:o},t.customReqOpts)];case 3:f=v.sent(),v.label=4;case 4:return f.code?[2,Co(e,null,f)]:[2,Co(e,null,{fileList:Array.isArray(null===(n=f.data)||void 0===n?void 0:n.download_list)?f.data.download_list:[],requestId:f.requestId})]}})})},t.prototype.downloadFile=function(t,e){return Eo(this,void 0,Promise,function(){var n,r,o,i,s,a,c;return Io(this,function(u){switch(u.label){case 0:return c=Lo(t,e),t=c[0],e=c[1],n=t.fileID,Po(n)?[4,this.getTempFileURL.call(this,{fileList:[{fileID:n,maxAge:600}],customReqOpts:t.customReqOpts})]:[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".getTempFileURL] fileID must be string")})];case 1:return r=u.sent(),"SUCCESS"!==(o=r.fileList[0]).code?[2,Co(e,o)]:(i=this.request,s=encodeURI(o.download_url),[4,i.download({url:s,tempFilePath:t.tempFilePath})]);case 2:return a=u.sent(),[2,Co(e,null,a)]}})})},t.prototype.copyFile=function(t,e){return Eo(this,void 0,Promise,function(){var n,r,o,i,s,a,c,u,l,h;return Io(this,function(d){switch(d.label){case 0:if(h=Lo(t,e),t=h[0],e=h[1],!(n=t.fileList)||!Ao(n)||0===n.length)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".copyFile] fileList must not be empty")})];for(r=[],o=0,i=n;o<i.length;o++){if(s=i[o],a=s.srcPath,c=s.dstPath,!a||!c||"string"!=typeof a||"string"!=typeof c)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".copyFile] srcPath and dstPath may not be empty")})];if(a===c)return[2,ko(this.config,{code:Oo.INVALID_PARAMS,message:"[".concat(Uo,".copyFile] srcPath and dstPath can not be the same")})];r.push({src_path:a,dst_path:c,overwrite:s.overwrite,remove_original:s.removeOriginal})}return u=this.request,l={},this.isGateWay()?[4,Mo(u,{convertedFileList:r},t.customReqOpts)]:[3,2];case 1:return l=d.sent(),[3,4];case 2:return[4,u.send("storage.batchCopyFile",{file_list:r},t.customReqOpts)];case 3:l=d.sent(),d.label=4;case 4:return l.code?[2,Co(e,null,l)]:[2,Co(e,null,{fileList:l.data.copy_list,requestId:l.requestId})]}})})},t.prototype.getFileInfo=function(t){var e;return Eo(this,void 0,Promise,function(){var n,r=this;return Io(this,function(o){switch(o.label){case 0:return[4,this.getTempFileURL(t)];case 1:return(null==(n=o.sent())?void 0:n.fileList)&&(null===(e=null==n?void 0:n.fileList)||void 0===e?void 0:e.length)>0?[4,Promise.all(n.fileList.map(function(t){return Eo(r,void 0,void 0,function(){var e,n,r,o,i,s,a;return Io(this,function(c){switch(c.label){case 0:if("SUCCESS"!==t.code)return[2,{code:t.code,fileID:t.fileID,tempFileURL:t.tempFileURL,message:t.message}];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,this.request.fetch({url:t.tempFileURL,method:"HEAD"})];case 2:return e=c.sent(),n=e.header,"undefined"!=typeof Headers&&n instanceof Headers&&(r={},n.forEach(function(t,e){r[e]=t}),n=r),o=parseInt(n["content-length"])||0,i=n["content-type"]||"",[400,404].includes(Number(e.statusCode))?[2,{code:"FILE_NOT_FOUND",fileID:t.fileID,tempFileURL:t.tempFileURL,message:"file not found"}]:[2,{code:t.code,fileID:t.fileID,tempFileURL:t.tempFileURL,cloudId:t.fileID,fileName:t.fileID.split("/").pop(),contentType:i,mime:i.split(";")[0].trim(),size:o,etag:n.etag||"",lastModified:n["last-modified"]||"",cacheControl:n["cache-control"]||""}];case 3:return s=c.sent(),a="object"==typeof s&&null!==s&&"message"in s?String(s.message):void 0,[2,{code:"FETCH_FILE_INFO_ERROR",fileID:t.fileID,tempFileURL:t.tempFileURL,message:a}];case 4:return[2]}})})}))]:[3,3];case 2:return[2,{fileList:o.sent(),requestId:n.requestId}];case 3:return[2,{fileList:[],requestId:n.requestId}]}})})},wo([xo({customInfo:{className:"Cloudbase",methodName:"uploadFile"},title:"上传文件失败",messages:["请确认以下各项:"," 1 - 调用 uploadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",["function"==typeof(e=void 0!==dr.ICloudbaseUploadFileParams&&dr.ICloudbaseUploadFileParams)?e:Object,"function"==typeof(n="undefined"!=typeof Function&&Function)?n:Object]),_o("design:returntype","function"==typeof(r="undefined"!=typeof Promise&&Promise)?r:Object)],t.prototype,"uploadFile",null),wo([xo({customInfo:{className:"Cloudbase",methodName:"getUploadMetadata"},title:"获取上传元信息失败",messages:["请确认以下各项:"," 1 - 调用 getUploadMetadata() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",[Object,"function"==typeof(o="undefined"!=typeof Function&&Function)?o:Object]),_o("design:returntype","function"==typeof(i="undefined"!=typeof Promise&&Promise)?i:Object)],t.prototype,"getUploadMetadata",null),wo([xo({customInfo:{className:"Cloudbase",methodName:"deleteFile"},title:"删除文件失败",messages:["请确认以下各项:"," 1 - 调用 deleteFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",["function"==typeof(s=void 0!==dr.ICloudbaseDeleteFileParams&&dr.ICloudbaseDeleteFileParams)?s:Object,"function"==typeof(a="undefined"!=typeof Function&&Function)?a:Object]),_o("design:returntype","function"==typeof(c="undefined"!=typeof Promise&&Promise)?c:Object)],t.prototype,"deleteFile",null),wo([xo({customInfo:{className:"Cloudbase",methodName:"getTempFileURL"},title:"获取文件下载链接",messages:["请确认以下各项:"," 1 - 调用 getTempFileURL() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",["function"==typeof(u=void 0!==dr.ICloudbaseGetTempFileURLParams&&dr.ICloudbaseGetTempFileURLParams)?u:Object,"function"==typeof(l="undefined"!=typeof Function&&Function)?l:Object]),_o("design:returntype","function"==typeof(h="undefined"!=typeof Promise&&Promise)?h:Object)],t.prototype,"getTempFileURL",null),wo([xo({customInfo:{className:"Cloudbase",methodName:"downloadFile"},title:"下载文件失败",messages:["请确认以下各项:"," 1 - 调用 downloadFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",["function"==typeof(d=void 0!==dr.ICloudbaseDownloadFileParams&&dr.ICloudbaseDownloadFileParams)?d:Object,"function"==typeof(f="undefined"!=typeof Function&&Function)?f:Object]),_o("design:returntype","function"==typeof(p="undefined"!=typeof Promise&&Promise)?p:Object)],t.prototype,"downloadFile",null),wo([xo({customInfo:{className:"Cloudbase",methodName:"copyFile"},title:"批量复制文件",messages:["请确认以下各项:"," 1 - 调用 copyFile() 的语法或参数是否正确"," 2 - 当前域名是否在安全域名列表中:https://console.cloud.tencent.com/tcb/env/safety"," 3 - 云存储安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(To)]}),_o("design:type",Function),_o("design:paramtypes",["function"==typeof(v=void 0!==dr.ICloudbaseCopyFileParams&&dr.ICloudbaseCopyFileParams)?v:Object,"function"==typeof(y="undefined"!=typeof Function&&Function)?y:Object]),_o("design:returntype","function"==typeof(g="undefined"!=typeof Promise&&Promise)?g:Object)],t.prototype,"copyFile",null),t}(),Jo=function(){return Jo=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Jo.apply(this,arguments)},zo=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},$o=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Yo=g,Qo=function(){function t(t,e){void 0===e&&(e=!1),this.shouldThrowOnError=!1,this.bucketId="",this.context=t,this.shouldThrowOnError=e,this.storage=new Ko(t)}return Object.defineProperty(t.prototype,"config",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.config},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"request",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.request},enumerable:!1,configurable:!0}),t.prototype.throwOnError=function(){return this.shouldThrowOnError=!0,this},t.prototype.upload=function(t,e,n){return zo(this,void 0,Promise,function(){var r,o,i,s,a,c,u,l,h;return $o(this,function(d){switch(d.label){case 0:r=Jo({upsert:!0},n),o=r.cacheControl,i=r.contentType,s=r.metadata,d.label=1;case 1:return d.trys.push([1,3,,4]),a=this.getCloudPath(t),c={cloudPath:a,filePath:e},(o||i||s)&&(u={},o&&(u["cache-control"]=o),i&&(u["content-type"]=i),s&&(u["x-cos-metadata-metadata"]=this.toBase64(JSON.stringify(s))),c.headers=u),[4,this.storage.uploadFile(c)];case 2:if(!(l=d.sent()).fileID)throw new Error(JSON.stringify({code:Yo.OPERATION_FAIL,msg:"[".concat(Uo,".update] no fileID returned")}));return[2,{data:{id:l.fileID,path:t,fullPath:t},error:null}];case 3:if(h=d.sent(),this.shouldThrowOnError)throw h;if(Fr(h))return[2,{data:null,error:h}];throw h;case 4:return[2]}})})},t.prototype.uploadToSignedUrl=function(t,e,n,r){return zo(this,void 0,Promise,function(){return $o(this,function(e){return[2,this.upload(t,n,r)]})})},t.prototype.createSignedUploadUrl=function(t){return zo(this,void 0,Promise,function(){var e,n,r;return $o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),e=this.getCloudPath(t),[4,this.storage.getUploadMetadata({cloudPath:e})];case 1:return[2,{data:{signedUrl:(n=o.sent().data).url,token:n.token,path:t,authorization:n.authorization,id:n.fileId,cosFileId:n.cosFileId,downloadUrl:n.download_url},error:null}];case 2:if(r=o.sent(),this.shouldThrowOnError)throw r;return[2,{data:null,error:r instanceof Wr?r:new Wr(r.message)}];case 3:return[2]}})})},t.prototype.update=function(t,e,n){return zo(this,void 0,Promise,function(){return $o(this,function(r){return[2,this.upload(t,e,Jo(Jo({},n),{upsert:!0}))]})})},t.prototype.move=function(t,e){return zo(this,void 0,Promise,function(){var n,r;return $o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.storage.copyFile({fileList:[{srcPath:this.getCloudPath(t),dstPath:this.getCloudPath(e),overwrite:!0,removeOriginal:!0}]})];case 1:if((n=o.sent()).fileList[0].code&&"SUCCESS"!==n.fileList[0].code)throw new Wr(n.fileList[0].message||"Move failed");return[2,{data:{message:"File moved from ".concat(t," to ").concat(e)},error:null}];case 2:if(r=o.sent(),this.shouldThrowOnError)throw r;if(Fr(r))return[2,{data:null,error:r}];throw r;case 3:return[2]}})})},t.prototype.copy=function(t,e){return zo(this,void 0,Promise,function(){var n,r;return $o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.storage.copyFile({fileList:[{srcPath:this.getCloudPath(t),dstPath:this.getCloudPath(e),overwrite:!0,removeOriginal:!1}]})];case 1:if((n=o.sent()).fileList[0].code&&"SUCCESS"!==n.fileList[0].code)throw new Wr(n.fileList[0].message||"Copy failed");return[2,{data:{path:this.getCloudPath(e)},error:null}];case 2:if(r=o.sent(),this.shouldThrowOnError)throw r;if(Fr(r))return[2,{data:null,error:r}];throw r;case 3:return[2]}})})},t.prototype.createSignedUrl=function(t,e,n){return zo(this,void 0,Promise,function(){var r,o,i,s,a,c,u;return $o(this,function(l){switch(l.label){case 0:if(l.trys.push([0,2,,3]),!Go(e))throw new Wr("[".concat(Uo,".createSignedUrl] expiresIn must be an integer greater than or equal to ").concat(1));return r=this.normalizeCloudId(t),[4,this.storage.getTempFileURL({fileList:[{fileID:r,maxAge:e}]})];case 1:if("SUCCESS"!==(o=l.sent()).fileList[0].code)throw new Wr("Failed to create signed URL: [".concat(o.fileList[0].code,"] ").concat(o.fileList[0].fileID));return i=o.fileList[0].download_url,s=[],void 0!==(null==n?void 0:n.download)&&("string"==typeof n.download?s.push("download=".concat(encodeURIComponent(n.download))):!0===n.download&&s.push("download=true")),(null==n?void 0:n.transform)&&(a=this.transformOptsToQueryString(n.transform))&&s.push(a),s.length>0&&(c=i.includes("?")?"&":"?",i="".concat(i).concat(c).concat(s.join("&"))),[2,{data:{signedUrl:i},error:null}];case 2:if(u=l.sent(),this.shouldThrowOnError)throw u;if(Fr(u))return[2,{data:null,error:u}];throw u;case 3:return[2]}})})},t.prototype.createSignedUrls=function(t,e){return zo(this,void 0,Promise,function(){var n,r,o=this;return $o(this,function(i){switch(i.label){case 0:if(i.trys.push([0,2,,3]),!Go(e))throw new Wr("[".concat(Uo,".createSignedUrls] expiresIn must be an integer greater than or equal to ").concat(1));return n=t.map(function(t){return{fileID:o.normalizeCloudId(t),maxAge:e}}),[4,this.storage.getTempFileURL({fileList:n})];case 1:return[2,{data:i.sent().fileList.map(function(e,n){return{path:t[n],signedUrl:e.tempFileURL||"",error:"SUCCESS"===e.code?null:e.message}}),error:null}];case 2:if(r=i.sent(),this.shouldThrowOnError)throw r;if(Fr(r))return[2,{data:null,error:r}];throw r;case 3:return[2]}})})},t.prototype.download=function(t,e){return zo(this,void 0,Promise,function(){var n,r,o=this;return $o(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),r={},[4,zo(o,void 0,void 0,function(){var n,r,o,i;return $o(this,function(s){switch(s.label){case 0:return[4,this.createSignedUrl(t,600,{transform:e})];case 1:if((n=s.sent()).error)throw n.error;return r=encodeURI(null===(i=n.data)||void 0===i?void 0:i.signedUrl),[4,this.request.reqClass.get({url:r,headers:{},responseType:"blob"})];case 2:if(!(o=s.sent().data))throw new Wr("Download failed: no file content");return[2,new Blob([o])]}})})];case 1:return[2,(r.data=i.sent(),r.error=null,r)];case 2:if(n=i.sent(),this.shouldThrowOnError)throw n;if(Fr(n))return[2,{data:null,error:n}];throw n;case 3:return[2]}})})},t.prototype.info=function(t){return zo(this,void 0,Promise,function(){var e,n,r,o,i,s,a,c;return $o(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),e=t.startsWith("cloud://"),n=e?this.extractPathFromFileId(t):t,r=e?this.extractBucketFromFileId(t):this.bucketId,[4,this.storage.getFileInfo({fileList:[this.normalizeCloudId(t)]})];case 1:if(o=u.sent(),"SUCCESS"!==(i=o.fileList[0]).code)throw new Wr(i.message);return s=(new Date).toISOString(),a=(i.lastModified?new Date(i.lastModified):new Date).toISOString(),[2,{data:{id:i.fileID,version:"1",name:n,bucketId:r,updatedAt:a,createdAt:a,lastAccessedAt:s,size:i.size,cacheControl:i.cacheControl,contentType:i.contentType,etag:i.etag,lastModified:a,metadata:{}},error:null}];case 2:if(c=u.sent(),this.shouldThrowOnError)throw c;return[2,{data:null,error:c instanceof Wr?c:new Wr(c.message)}];case 3:return[2]}})})},t.prototype.exists=function(t){return zo(this,void 0,Promise,function(){var e,n,r;return $o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.storage.getFileInfo({fileList:[this.normalizeCloudId(t)]})];case 1:if(e=o.sent(),"FILE_NOT_FOUND"===(n=e.fileList[0]).code)return[2,{data:!1,error:null}];if("SUCCESS"!==n.code)throw new Wr(n.message);return[2,{data:!0,error:null}];case 2:if(r=o.sent(),this.shouldThrowOnError)throw r;if(Fr(r))return[2,{data:null,error:r}];throw r;case 3:return[2]}})})},t.prototype.getPublicUrl=function(t,e){return zo(this,void 0,Promise,function(){var n;return $o(this,function(r){switch(r.label){case 0:return[4,this.createSignedUrl(t,600,e)];case 1:return(n=r.sent()).data?[2,{data:{publicUrl:n.data.signedUrl}}]:[2,{data:null,error:n.error}]}})})},t.prototype.remove=function(t){return zo(this,void 0,Promise,function(){var e,n,r,o,i,s,a,c,u,l,h=this;return $o(this,function(d){switch(d.label){case 0:for(d.trys.push([0,3,,4]),e=10,n=[],r=0;r<t.length;r+=e)n.push(t.slice(r,r+e));return[4,Promise.all(n.map(function(t){return Promise.all(t.map(function(t){return h.info(t)}))}))];case 1:return o=d.sent(),i=new Map,o.forEach(function(n,r){n.forEach(function(n,o){n.data&&i.set(t[r*e+o],n.data)})}),s=t.map(function(t){return h.normalizeCloudId(t)}),[4,this.storage.deleteFile({fileList:s})];case 2:if(a=d.sent(),(c=a.fileList.filter(function(t){return"SUCCESS"!==t.code})).length>0)throw new Wr("Delete failed for ".concat(c.length," file(s)"));return u=(new Date).toISOString(),[2,{data:t.map(function(t){var e=i.get(t);return{name:null==e?void 0:e.name,id:null==e?void 0:e.id,bucket_id:null==e?void 0:e.bucketId,owner:void 0,updated_at:(null==e?void 0:e.updatedAt)||u,created_at:null==e?void 0:e.createdAt,last_accessed_at:(null==e?void 0:e.lastAccessedAt)||u,metadata:(null==e?void 0:e.metadata)||{},buckets:{id:null==e?void 0:e.bucketId,name:null==e?void 0:e.bucketId,owner:void 0,public:!1,created_at:"",updated_at:u}}}),error:null}];case 3:if(l=d.sent(),this.shouldThrowOnError)throw l;if(Fr(l))return[2,{data:null,error:l}];throw l;case 4:return[2]}})})},t.prototype.list=function(){return zo(this,void 0,void 0,function(){return $o(this,function(t){throw new Wr("Not implemented")})})},t.prototype.getCloudPath=function(t){return t.replace(/^\/|\/$/g,"").replace(/\/+/g,"/")},t.prototype.normalizeCloudId=function(t){var e;if(/^cloud:\/\//.test(t))return t;var n=this.getCloudPath(t);if(!this.bucketId)throw new Wr("bucketId is not set");var r=(null===(e=this.config)||void 0===e?void 0:e.env)||"";return r?"cloud://".concat(r,".").concat(this.bucketId,"/").concat(n):void 0},t.prototype.toBase64=function(t){return Kr(t)},t.prototype.transformOptsToQueryString=function(t){var e=["imageMogr2"];if(t.width||t.height){var n=t.width||"",r=t.height||"";"fill"===t.resize?e.push("thumbnail/".concat(n,"x").concat(r,"!")):"contain"===t.resize?e.push("thumbnail/".concat(n,"x").concat(r)):e.push("thumbnail/".concat(n,"x").concat(r,"^"))}if(t.format&&"origin"!==t.format&&e.push("format/".concat(t.format)),void 0!==t.quality){var o=Math.max(1,Math.min(100,t.quality));e.push("quality/".concat(o))}return e.join("/")},t.prototype.extractPathFromFileId=function(t){var e=t.replace(/^cloud:\/\//,"").split("/");return e.length<2?t:e.slice(1).join("/")},t.prototype.extractBucketFromFileId=function(t){var e=t.replace(/^cloud:\/\//,"").split("/");if(e.length<1)return"";var n=e[0],r=n.indexOf(".");return-1===r?n:n.substring(r+1)},t}(),Xo=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Zo=new Ko,ti={name:Uo,entity:{uploadFile:Zo.uploadFile,deleteFile:Zo.deleteFile,getTempFileURL:Zo.getTempFileURL,downloadFile:Zo.downloadFile,getUploadMetadata:Zo.getUploadMetadata,copyFile:Zo.copyFile,getFileInfo:Zo.getFileInfo,isGateWay:Zo.isGateWay}},ei=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Xo(e,t),e.prototype.from=function(t){return t?(po(t,"from"),new ho(this.http,t,this.shouldThrowOnError)):new Qo(this.http.ctx,this.shouldThrowOnError)},e}(mo),ni={name:"".concat(Uo,"/supabase"),IIFE:!0,entity:function(){var t=new WeakMap;Object.defineProperty(this.prototype,"storage",{get:function(){if(t.has(this))return t.get(this);var e=this,n=new Proxy({},{get:function(t,n){return"config"===n?e.config:"request"===n?e.request:void 0}}),r=new ei(n);return t.set(this,r),r},configurable:!0,enumerable:!0})}};try{cloudbase.registerComponent(ti),cloudbase.registerComponent(ni)}catch(t){}function ri(t){try{t.registerComponent(ti),t.registerComponent(ni)}catch(t){console.warn(t)}}try{window.registerStorage=ri}catch(t){}var oi=l(6765),ii=l.n(oi),si=l(7195),ai=l.n(si),ci=l(9850),ui=l.n(ci);function li(t){return void 0===t&&(t=""),"".concat(t?"".concat(t,"_"):"").concat(+new Date,"_").concat(Math.random())}var hi,di=function(t){this.close=t.close,this.onChange=t.onChange,this.onError=t.onError,t.debug&&Object.defineProperty(this,"virtualClient",{get:function(){return t.virtualClient}})},fi=function(t){var e,n,r=t.id,o=t.docChanges,i=t.docs,s=t.msgType,a=t.type;Object.defineProperties(this,{id:{get:function(){return r},enumerable:!0},docChanges:{get:function(){return e||(e=JSON.parse(JSON.stringify(o))),e},enumerable:!0},docs:{get:function(){return n||(n=JSON.parse(JSON.stringify(i))),n},enumerable:!0},msgType:{get:function(){return s},enumerable:!0},type:{get:function(){return a},enumerable:!0}})},pi=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),vi=function(t){function e(e){var n=t.call(this,"Watch Error ".concat(JSON.stringify(e.msgData)," (requestid: ").concat(e.requestId,")"))||this;return n.isRealtimeErrorMessageError=!0,n.payload=e,n}return pi(e,t),e}(Error),yi=function(t){return null==t?void 0:t.isRealtimeErrorMessageError},gi=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="timeout",e.payload=null,e.generic=!0,e}return pi(e,t),e}(Error),mi=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="cancelled",e.payload=null,e.generic=!0,e}return pi(e,t),e}(Error),bi=function(t){function e(e){var n=t.call(this,e.errMsg)||this;return n.errCode="UNKNOWN_ERROR",Object.defineProperties(n,{message:{get:function(){return"errCode: ".concat(this.errCode," ").concat(wi[this.errCode]||""," | errMsg: ").concat(this.errMsg)},set:function(t){this.errMsg=t}}}),n.errCode=e.errCode||"UNKNOWN_ERROR",n.errMsg=e.errMsg,n}return pi(e,t),Object.defineProperty(e.prototype,"message",{get:function(){return"errCode: ".concat(this.errCode," | errMsg: ").concat(this.errMsg)},set:function(t){this.errMsg=t},enumerable:!1,configurable:!0}),e}(Error),wi={UNKNOWN_ERROR:"UNKNOWN_ERROR",SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG:"SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG",SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA:"SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED",SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL",SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR:"SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR"},_i=function(t){return void 0===t&&(t=0),new Promise(function(e){return setTimeout(e,t)})},Ei=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Ii=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Si=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};!function(t){t.LOGGINGIN="LOGGINGIN",t.INITING="INITING",t.REBUILDING="REBUILDING",t.ACTIVE="ACTIVE",t.ERRORED="ERRORED",t.CLOSING="CLOSING",t.CLOSED="CLOSED",t.PAUSED="PAUSED",t.RESUMING="RESUMING"}(hi||(hi={}));var Oi=function(){function t(t){var e=this;this.watchStatus=hi.INITING,this.wsLogin=function(t,n){return Ei(e,void 0,Promise,function(){var e;return Ii(this,function(r){switch(r.label){case 0:return this.watchStatus=hi.LOGGINGIN,[4,this.login(t,n)];case 1:return e=r.sent(),this.envId||(this.envId=e.envId),[2,e]}})})},this.initWatch=function(t){return Ei(e,void 0,Promise,function(){var e,n=this;return Ii(this,function(r){switch(r.label){case 0:if(null!==this.initWatchPromise&&void 0!==this.initWatchPromise)return[2,this.initWatchPromise];this.initWatchPromise=new Promise(function(e,r){Ei(n,void 0,void 0,function(){var n,o,i,s,a,c,u,l,h,d;return Ii(this,function(f){switch(f.label){case 0:return f.trys.push([0,3,,4]),this.watchStatus===hi.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,e()]):[4,this.wsLogin(this.envId,t)];case 1:return n=f.sent().envId,this.watchStatus===hi.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,e()]):(this.watchStatus=hi.INITING,o={watchId:this.watchId,requestId:li(),msgType:"INIT_WATCH",msgData:{envId:n,collName:this.collectionName,query:this.query,limit:this.limit,orderBy:this.orderBy}},[4,this.send({msg:o,waitResponse:!0,skipOnMessage:!0,timeout:1e4})]);case 2:if(i=f.sent(),s=i.msgData,a=s.events,c=s.currEvent,this.sessionInfo={queryID:i.msgData.queryID,currentEventId:c-1,currentDocs:[]},a.length>0){for(u=0,l=a;u<l.length;u++)l[u].ID=c;this.handleServerEvents(i)}else this.sessionInfo.currentEventId=c,h=new fi({id:c,docChanges:[],docs:[],type:"init"}),this.listener.onChange(h),this.scheduleSendACK();return this.onWatchStart(this,this.sessionInfo.queryID),this.watchStatus=hi.ACTIVE,this.availableRetries.INIT_WATCH=2,e(),[3,4];case 3:return d=f.sent(),this.handleWatchEstablishmentError(d,{operationName:"INIT_WATCH",resolve:e,reject:r}),[3,4];case 4:return[2]}})})}),e=!1,r.label=1;case 1:return r.trys.push([1,,3,4]),[4,this.initWatchPromise];case 2:return r.sent(),e=!0,[3,4];case 3:return this.initWatchPromise=void 0,[7];case 4:return console.log("[realtime] initWatch ".concat(e?"success":"fail")),[2]}})})},this.rebuildWatch=function(t){return Ei(e,void 0,Promise,function(){var e,n=this;return Ii(this,function(r){switch(r.label){case 0:if(null!==this.rebuildWatchPromise&&void 0!==this.rebuildWatchPromise)return[2,this.rebuildWatchPromise];this.rebuildWatchPromise=new Promise(function(e,r){Ei(n,void 0,void 0,function(){var n,o,i,s;return Ii(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),this.watchStatus===hi.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,e()]):[4,this.wsLogin(this.envId,t)];case 1:if(n=a.sent().envId,!this.sessionInfo)throw new Error("can not rebuildWatch without a successful initWatch (lack of sessionInfo)");return this.watchStatus===hi.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,e()]):(this.watchStatus=hi.REBUILDING,o={watchId:this.watchId,requestId:li(),msgType:"REBUILD_WATCH",msgData:{envId:n,collName:this.collectionName,queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:o,waitResponse:!0,skipOnMessage:!1,timeout:1e4})]);case 2:return i=a.sent(),this.handleServerEvents(i),this.watchStatus=hi.ACTIVE,this.availableRetries.REBUILD_WATCH=2,e(),[3,4];case 3:return s=a.sent(),this.handleWatchEstablishmentError(s,{operationName:"REBUILD_WATCH",resolve:e,reject:r}),[3,4];case 4:return[2]}})})}),e=!1,r.label=1;case 1:return r.trys.push([1,,3,4]),[4,this.rebuildWatchPromise];case 2:return r.sent(),e=!0,[3,4];case 3:return this.rebuildWatchPromise=void 0,[7];case 4:return console.log("[realtime] rebuildWatch ".concat(e?"success":"fail")),[2]}})})},this.handleWatchEstablishmentError=function(t,n){return Ei(e,void 0,void 0,function(){var e,r,o,i=this;return Ii(this,function(s){return e="INIT_WATCH"===n.operationName,r=function(){i.closeWithError(new bi({errCode:e?wi.SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:wi.SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL,errMsg:t})),n.reject(t)},o=function(t){i.useRetryTicket(n.operationName)?e?(i.initWatchPromise=void 0,n.resolve(i.initWatch(t))):(i.rebuildWatchPromise=void 0,n.resolve(i.rebuildWatch(t))):r()},this.handleCommonError(t,{onSignError:function(){return o(!0)},onTimeoutError:function(){return o(!1)},onNotRetryableError:r,onCancelledError:n.reject,onUnknownError:function(){Ei(i,void 0,void 0,function(){var t,e=this;return Ii(this,function(r){switch(r.label){case 0:return r.trys.push([0,8,,9]),t=function(){return Ei(e,void 0,void 0,function(){return Ii(this,function(t){switch(t.label){case 0:return this.pause(),[4,this.onceWSConnected()];case 1:return t.sent(),o(!0),[2]}})})},this.isWSConnected()?[3,2]:[4,t()];case 1:return r.sent(),[3,7];case 2:return[4,_i(100)];case 3:return r.sent(),this.watchStatus!==hi.PAUSED?[3,4]:(n.reject(new mi("".concat(n.operationName," cancelled due to pause after unknownError"))),[3,7]);case 4:return this.isWSConnected()?[3,6]:[4,t()];case 5:return r.sent(),[3,7];case 6:o(!1),r.label=7;case 7:return[3,9];case 8:return r.sent(),o(!0),[3,9];case 9:return[2]}})})}}),[2]})})},this.closeWatch=function(){return Ei(e,void 0,void 0,function(){var t,e,n;return Ii(this,function(r){switch(r.label){case 0:if(t=this.sessionInfo?this.sessionInfo.queryID:"",this.watchStatus!==hi.ACTIVE)return this.watchStatus=hi.CLOSED,this.onWatchClose(this,t),[2];r.label=1;case 1:return r.trys.push([1,3,4,5]),this.watchStatus=hi.CLOSING,e={watchId:this.watchId,requestId:li(),msgType:"CLOSE_WATCH",msgData:null},[4,this.send({msg:e})];case 2:return r.sent(),this.sessionInfo=void 0,this.watchStatus=hi.CLOSED,[3,5];case 3:return n=r.sent(),this.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL,errMsg:n})),[3,5];case 4:return this.onWatchClose(this,t),[7];case 5:return[2]}})})},this.scheduleSendACK=function(){e.clearACKSchedule(),e.ackTimeoutId=setTimeout(function(){e.waitExpectedTimeoutId?e.scheduleSendACK():e.sendACK()},1e4)},this.clearACKSchedule=function(){e.ackTimeoutId&&clearTimeout(e.ackTimeoutId)},this.sendACK=function(){return Ei(e,void 0,Promise,function(){var t,e,n;return Ii(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.watchStatus!==hi.ACTIVE?(this.scheduleSendACK(),[2]):this.sessionInfo?(t={watchId:this.watchId,requestId:li(),msgType:"CHECK_LAST",msgData:{queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:t})]):(console.warn("[realtime listener] can not send ack without a successful initWatch (lack of sessionInfo)"),[2]);case 1:return r.sent(),this.scheduleSendACK(),[3,3];case 2:if(e=r.sent(),yi(e))switch((n=e.payload).msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return this.rebuildWatch(),[2];case"QUERYID_INVALID_ERROR":case"SYS_ERR":case"INVALIID_ENV":case"COLLECTION_PERMISSION_DENIED":return this.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:n.msgData.code})),[2]}return this.availableRetries.CHECK_LAST&&this.availableRetries.CHECK_LAST>0?(this.availableRetries.CHECK_LAST-=1,this.scheduleSendACK()):this.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:e})),[3,3];case 3:return[2]}})})},this.handleCommonError=function(t,e){if(yi(t))switch(t.payload.msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return void e.onSignError(t);default:return void e.onNotRetryableError(t)}else{if(function(t){return"timeout"===t.type}(t))return void e.onTimeoutError(t);if(function(t){return"cancelled"===t.type}(t))return void e.onCancelledError(t)}e.onUnknownError(t)},this.watchId="watchid_".concat(+new Date,"_").concat(Math.random()),this.envId=t.envId,this.collectionName=t.collectionName,this.query=t.query,this.limit=t.limit,this.orderBy=t.orderBy,this.send=t.send,this.login=t.login,this.isWSConnected=t.isWSConnected,this.onceWSConnected=t.onceWSConnected,this.getWaitExpectedTimeoutLength=t.getWaitExpectedTimeoutLength,this.onWatchStart=t.onWatchStart,this.onWatchClose=t.onWatchClose,this.debug=t.debug,this.availableRetries={INIT_WATCH:2,REBUILD_WATCH:2,CHECK_LAST:2},this.listener=new di({close:function(){e.closeWatch()},onChange:t.onChange,onError:t.onError,debug:this.debug,virtualClient:this}),this.initWatch()}return t.prototype.onMessage=function(t){var e=this;switch(this.watchStatus){case hi.PAUSED:if("ERROR"!==t.msgType)return;break;case hi.LOGGINGIN:case hi.INITING:case hi.REBUILDING:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received while ".concat(this.watchStatus));case hi.CLOSED:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has closed");case hi.ERRORED:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has ended with error")}if(this.sessionInfo)switch(this.scheduleSendACK(),t.msgType){case"NEXT_EVENT":console.warn("nextevent ".concat(t.msgData.currEvent," ignored"),t),this.handleServerEvents(t);break;case"CHECK_EVENT":this.sessionInfo.currentEventId<t.msgData.currEvent&&(this.sessionInfo.expectEventId=t.msgData.currEvent,this.clearWaitExpectedEvent(),this.waitExpectedTimeoutId=setTimeout(function(){e.rebuildWatch()},this.getWaitExpectedTimeoutLength()),console.log("[realtime] waitExpectedTimeoutLength ".concat(this.getWaitExpectedTimeoutLength())));break;case"ERROR":this.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG,errMsg:"".concat(t.msgData.code," - ").concat(t.msgData.message)}));break;default:console.warn("[realtime listener] virtual client receive unexpected msg ".concat(t.msgType,": "),t)}else console.warn("[realtime listener] internal non-fatal error: sessionInfo not found while message is received.")},t.prototype.closeWithError=function(t){var e;this.watchStatus=hi.ERRORED,this.clearACKSchedule(),this.listener.onError(t),this.onWatchClose(this,(null===(e=this.sessionInfo)||void 0===e?void 0:e.queryID)||""),console.log("[realtime] client closed (".concat(this.collectionName," ").concat(this.query,") (watchId ").concat(this.watchId,")"))},t.prototype.pause=function(){this.watchStatus=hi.PAUSED,console.log("[realtime] client paused (".concat(this.collectionName," ").concat(this.query,") (watchId ").concat(this.watchId,")"))},t.prototype.resume=function(){return Ei(this,void 0,Promise,function(){var t;return Ii(this,function(e){switch(e.label){case 0:this.watchStatus=hi.RESUMING,console.log("[realtime] client resuming with ".concat(this.sessionInfo?"REBUILD_WATCH":"INIT_WATCH"," (").concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")")),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.sessionInfo?this.rebuildWatch():this.initWatch()];case 2:return e.sent(),console.log("[realtime] client successfully resumed (".concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")")),[3,4];case 3:return t=e.sent(),console.error("[realtime] client resume failed (".concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")"),t),[3,4];case 4:return[2]}})})},t.prototype.useRetryTicket=function(t){return!!(this.availableRetries[t]&&this.availableRetries[t]>0)&&(this.availableRetries[t]-=1,console.log("[realtime] ".concat(t," use a retry ticket, now only ").concat(this.availableRetries[t]," retry left")),!0)},t.prototype.handleServerEvents=function(t){return Ei(this,void 0,void 0,function(){var e;return Ii(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.scheduleSendACK(),[4,this.handleServerEventsInternel(t)];case 1:return n.sent(),this.postHandleServerEventsValidityCheck(t),[3,3];case 2:throw e=n.sent(),console.error("[realtime listener] internal non-fatal error: handle server events failed with error: ",e),e;case 3:return[2]}})})},t.prototype.handleServerEventsInternel=function(t){return Ei(this,void 0,void 0,function(){var e,n,r,o,i,s,a,c,u,l,h,d;return Ii(this,function(f){switch(f.label){case 0:if(e=t.requestId,n=t.msgData.events,r=t.msgType,!n.length||!this.sessionInfo)return[2];o=this.sessionInfo;try{i=n.map(Ti)}catch(t){return this.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA,errMsg:t})),[2]}s=Si([],o.currentDocs,!0),a=!1,c=function(n,c){var l,h,d,f,p,v,y,g,m,b,w,_;return Ii(this,function(E){switch(E.label){case 0:return l=i[n],o.currentEventId>=l.id?(!i[n-1]||l.id>i[n-1].id?console.warn("[realtime] duplicate event received, cur ".concat(o.currentEventId," but got ").concat(l.id)):console.error("[realtime listener] server non-fatal error: events out of order (the latter event's id is smaller than that of the former) (requestId ".concat(e,")")),[2,"continue"]):[3,1];case 1:if(o.currentEventId!==l.id-1)return[3,2];switch(l.dataType){case"update":if(!l.doc)switch(l.queueType){case"update":case"dequeue":if(h=s.find(function(t){return t._id===l.docId}),h){if(d=ui()(h),l.updatedFields&&Object.keys(l.updatedFields).forEach(function(t){ii()(d,t,l.updatedFields[t])}),l.removedFields)for(f=0,p=l.removedFields;f<p.length;f++)v=p[f],ai()(d,v);l.doc=d}else console.error("[realtime listener] internal non-fatal server error: unexpected update dataType event where no doc is associated.");break;case"enqueue":throw g=new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="update" and queueType="enqueue" (requestId '.concat(t.requestId,")")}),u.closeWithError(g),g}break;case"replace":if(!l.doc)throw g=new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="replace" (requestId '.concat(t.requestId,")")}),u.closeWithError(g),g;break;case"remove":(y=s.find(function(t){return t._id===l.docId}))?l.doc=y:console.error("[realtime listener] internal non-fatal server error: unexpected remove event where no doc is associated.");break;case"limit":if(!l.doc)switch(l.queueType){case"dequeue":(y=s.find(function(t){return t._id===l.docId}))?l.doc=y:console.error("[realtime listener] internal non-fatal server error: unexpected limit dataType event where no doc is associated.");break;case"enqueue":throw g=new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="limit" and queueType="enqueue" (requestId '.concat(t.requestId,")")}),u.closeWithError(g),g}}switch(l.queueType){case"init":a?s.push(l.doc):(a=!0,s=[l.doc]);break;case"enqueue":s.push(l.doc);break;case"dequeue":m=s.findIndex(function(t){return t._id===l.docId}),m>-1?s.splice(m,1):console.error("[realtime listener] internal non-fatal server error: unexpected dequeue event where no doc is associated.");break;case"update":m=s.findIndex(function(t){return t._id===l.docId}),m>-1?s[m]=l.doc:console.error("[realtime listener] internal non-fatal server error: unexpected queueType update event where no doc is associated.")}return(n===c-1||i[n+1]&&i[n+1].id!==l.id)&&(b=Si([],s,!0),w=i.slice(0,n+1).filter(function(t){return t.id===l.id}),u.sessionInfo.currentEventId=l.id,u.sessionInfo.currentDocs=s,_=new fi({id:l.id,docChanges:w,docs:b,msgType:r}),u.listener.onChange(_)),[3,4];case 2:return console.warn("[realtime listener] event received is out of order, cur ".concat(u.sessionInfo.currentEventId," but got ").concat(l.id)),[4,u.rebuildWatch()];case 3:return E.sent(),[2,{value:void 0}];case 4:return[2]}})},u=this,l=0,h=i.length,f.label=1;case 1:return l<h?[5,c(l,h)]:[3,4];case 2:if("object"==typeof(d=f.sent()))return[2,d.value];f.label=3;case 3:return l++,[3,1];case 4:return[2]}})})},t.prototype.postHandleServerEventsValidityCheck=function(t){this.sessionInfo?(this.sessionInfo.expectEventId&&this.sessionInfo.currentEventId>=this.sessionInfo.expectEventId&&this.clearWaitExpectedEvent(),this.sessionInfo.currentEventId<t.msgData.currEvent&&console.warn("[realtime listener] internal non-fatal error: client eventId does not match with server event id after server event handling")):console.error("[realtime listener] internal non-fatal error: sessionInfo lost after server event handling, this should never occur")},t.prototype.clearWaitExpectedEvent=function(){this.waitExpectedTimeoutId&&(clearTimeout(this.waitExpectedTimeoutId),this.waitExpectedTimeoutId=void 0)},t}();function Ti(t){var e={id:t.ID,dataType:t.DataType,queueType:t.QueueType,docId:t.DocID,doc:t.Doc&&"{}"!==t.Doc?JSON.parse(t.Doc):void 0};return"update"===t.DataType&&(t.UpdatedFields&&(e.updatedFields=JSON.parse(t.UpdatedFields)),(t.removedFields||t.RemovedFields)&&(e.removedFields=JSON.parse(t.removedFields))),e}var Ai,Pi={1e3:{code:1e3,name:"Normal Closure",description:"Normal closure; the connection successfully completed whatever purpose for which it was created."},1001:{code:1001,name:"Going Away",description:"The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection."},1002:{code:1002,name:"Protocol Error",description:"The endpoint is terminating the connection due to a protocol error."},1003:{code:1003,name:"Unsupported Data",description:"The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data)."},1005:{code:1005,name:"No Status Received",description:"Indicates that no status code was provided even though one was expected."},1006:{code:1006,name:"Abnormal Closure",description:"Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected."},1007:{code:1007,name:"Invalid frame payload data",description:"The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message)."},1008:{code:1008,name:"Policy Violation",description:"The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable."},1009:{code:1009,name:"Message too big",description:"The endpoint is terminating the connection because a data frame was received that is too large."},1010:{code:1010,name:"Missing Extension",description:"The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't."},1011:{code:1011,name:"Internal Error",description:"The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request."},1012:{code:1012,name:"Service Restart",description:"The server is terminating the connection because it is restarting."},1013:{code:1013,name:"Try Again Later",description:"The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients."},1014:{code:1014,name:"Bad Gateway",description:"The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code."},1015:{code:1015,name:"TLS Handshake",description:"Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified)."},3e3:{code:3e3,name:"Reconnect WebSocket",description:"The client is terminating the connection because it wants to reconnect"},3001:{code:3001,name:"No Realtime Listeners",description:"The client is terminating the connection because no more realtime listeners exist"},3002:{code:3002,name:"Heartbeat Ping Error",description:"The client is terminating the connection due to its failure in sending heartbeat messages"},3003:{code:3003,name:"Heartbeat Pong Timeout Error",description:"The client is terminating the connection because no heartbeat response is received from the server"},3050:{code:3050,name:"Server Close",description:"The client is terminating the connection because no heartbeat response is received from the server"}};!function(t){t[t.NormalClosure=1e3]="NormalClosure",t[t.GoingAway=1001]="GoingAway",t[t.ProtocolError=1002]="ProtocolError",t[t.UnsupportedData=1003]="UnsupportedData",t[t.NoStatusReceived=1005]="NoStatusReceived",t[t.AbnormalClosure=1006]="AbnormalClosure",t[t.InvalidFramePayloadData=1007]="InvalidFramePayloadData",t[t.PolicyViolation=1008]="PolicyViolation",t[t.MessageTooBig=1009]="MessageTooBig",t[t.MissingExtension=1010]="MissingExtension",t[t.InternalError=1011]="InternalError",t[t.ServiceRestart=1012]="ServiceRestart",t[t.TryAgainLater=1013]="TryAgainLater",t[t.BadGateway=1014]="BadGateway",t[t.TLSHandshake=1015]="TLSHandshake",t[t.ReconnectWebSocket=3e3]="ReconnectWebSocket",t[t.NoRealtimeListeners=3001]="NoRealtimeListeners",t[t.HeartbeatPingError=3002]="HeartbeatPingError",t[t.HeartbeatPongTimeoutError=3003]="HeartbeatPongTimeoutError",t[t.NoAuthentication=3050]="NoAuthentication"}(Ai||(Ai={}));var Ri=function(t,e){var n=Pi[t],r=n?"".concat(n.name,", code ").concat(t,", reason ").concat(e||n.description):"code ".concat(t);return new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED,errMsg:r})},Ci=null,ki="web";function Ni(){return Ci}function xi(){return ki}function Ui(t){ki=t}var Li=function(){return Li=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Li.apply(this,arguments)},Di=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},ji=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},qi=function(){function t(t){var e=this;this.virtualWSClient=new Set,this.queryIdClientMap=new Map,this.watchIdClientMap=new Map,this.pingFailed=0,this.pongMissed=0,this.logins=new Map,this.wsReadySubsribers=[],this.wsResponseWait=new Map,this.rttObserved=[],this.send=function(t){return Di(e,void 0,Promise,function(){var e=this;return ji(this,function(n){return[2,new Promise(function(n,r){Di(e,void 0,void 0,function(){var e,o,i,s,a,c,u,l,h=this;return ji(this,function(d){switch(d.label){case 0:o=!1,i=!1,s=function(t){o=!0,e&&clearTimeout(e),n(t)},a=function(t){i=!0,e&&clearTimeout(e),r(t)},t.timeout&&(e=setTimeout(function(){Di(h,void 0,void 0,function(){return ji(this,function(t){switch(t.label){case 0:return o&&i?[3,2]:[4,_i(0)];case 1:t.sent(),o&&i||a(new gi("wsclient.send timedout")),t.label=2;case 2:return[2]}})})},t.timeout)),d.label=1;case 1:return d.trys.push([1,8,,9]),void 0===this.wsInitPromise&&null===this.wsInitPromise?[3,3]:[4,this.wsInitPromise];case 2:d.sent(),d.label=3;case 3:if(!this.ws)return a(new Error("invalid state: ws connection not exists, can not send message")),[2];if(1!==this.ws.readyState)return a(new Error("ws readyState invalid: ".concat(this.ws.readyState,", can not send message"))),[2];t.waitResponse&&(c={resolve:s,reject:a,skipOnMessage:t.skipOnMessage},this.wsResponseWait.set(t.msg.requestId,c)),d.label=4;case 4:return d.trys.push([4,6,,7]),[4,this.ws.send(JSON.stringify(t.msg))];case 5:return d.sent(),t.waitResponse||s(void 0),[3,7];case 6:return(u=d.sent())&&(a(u),t.waitResponse&&this.wsResponseWait.delete(t.msg.requestId)),[3,7];case 7:return[3,9];case 8:return l=d.sent(),a(l),[3,9];case 9:return[2]}})})})]})})},this.closeAllClients=function(t){e.virtualWSClient.forEach(function(e){e.closeWithError(t)})},this.pauseClients=function(t){(t||e.virtualWSClient).forEach(function(t){t.pause()})},this.resumeClients=function(t){(t||e.virtualWSClient).forEach(function(t){t.resume()})},this.initWebSocketConnection=function(t,n){return void 0===n&&(n=e.maxReconnect),Di(e,void 0,Promise,function(){var e=this;return ji(this,function(r){switch(r.label){case 0:if(t&&this.reconnectState)return[2];if(t&&(this.reconnectState=!0),void 0!==this.wsInitPromise&&null!==this.wsInitPromise)return[2,this.wsInitPromise];t&&this.pauseClients(),this.close(Ai.ReconnectWebSocket),this.wsInitPromise=new Promise(function(r,o){Di(e,void 0,void 0,function(){var e,i,s=this;return ji(this,function(a){switch(a.label){case 0:return a.trys.push([0,6,,11]),[4,this.getWsSign()];case 1:return e=a.sent(),[4,new Promise(function(t){var n=e.wsUrl||"wss://tcb-ws.tencentcloudapi.com",r=Ni();s.ws=r?new r(n):new WebSocket(n),t(void 0)})];case 2:return a.sent(),this.ws.connect?[4,this.ws.connect()]:[3,4];case 3:a.sent(),a.label=4;case 4:return[4,this.initWebSocketEvent()];case 5:return a.sent(),r(),t&&(this.resumeClients(),this.reconnectState=!1),[3,11];case 6:return i=a.sent(),console.error("[realtime] initWebSocketConnection connect fail",i),n>0?(this.wsInitPromise=void 0,[4,_i(this.reconnectInterval)]):[3,9];case 7:a.sent(),t&&(this.reconnectState=!1),a.label=8;case 8:return r(this.initWebSocketConnection(t,n-1)),[3,10];case 9:o(i),t&&this.closeAllClients(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL,errMsg:i})),a.label=10;case 10:return[3,11];case 11:return[2]}})})}),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,this.wsInitPromise];case 2:return r.sent(),this.wsReadySubsribers.forEach(function(t){return(0,t.resolve)()}),[3,5];case 3:return r.sent(),this.wsReadySubsribers.forEach(function(t){return(0,t.reject)()}),[3,5];case 4:return this.wsInitPromise=void 0,this.wsReadySubsribers=[],[7];case 5:return[2]}})})},this.initWebSocketEvent=function(){return new Promise(function(t,n){if(!e.ws)throw new Error("can not initWebSocketEvent, ws not exists");var r=!1;e.ws.onopen=function(e){console.warn("[realtime] ws event: open",e),r=!0,t()},e.ws.onerror=function(t){e.logins=new Map,r?(console.error("[realtime] ws event: error",t),e.clearHeartbeat(),e.virtualWSClient.forEach(function(e){return e.closeWithError(new bi({errCode:wi.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR,errMsg:t}))})):(console.error("[realtime] ws open failed with ws event: error",t),n(t))},e.ws.onclose=function(t){switch(console.warn("[realtime] ws event: close",t),e.logins=new Map,e.clearHeartbeat(),t.code){case Ai.ReconnectWebSocket:case Ai.NoRealtimeListeners:break;case Ai.HeartbeatPingError:case Ai.HeartbeatPongTimeoutError:case Ai.NormalClosure:case Ai.AbnormalClosure:e.maxReconnect>0?e.initWebSocketConnection(!0,e.maxReconnect):e.closeAllClients(Ri(t.code));break;case Ai.NoAuthentication:e.closeAllClients(Ri(t.code,t.reason));break;default:e.maxReconnect>0?e.initWebSocketConnection(!0,e.maxReconnect):e.closeAllClients(Ri(t.code))}},e.ws.onmessage=function(t){var n,r,o=(null===(n=t.data)||void 0===n?void 0:n.data)||t.data;e.heartbeat();try{r="string"==typeof o?JSON.parse(o):o}catch(t){throw new Error("[realtime] onMessage parse res.data error: ".concat(t))}if("ERROR"===r.msgType){var i=null;e.virtualWSClient.forEach(function(t){t.watchId===r.watchId&&(i=t)}),i&&i.listener.onError(r)}var s=e.wsResponseWait.get(r.requestId);if(s){try{"ERROR"===r.msgType?s.reject(new vi(r)):s.resolve(r)}catch(t){console.error("ws onMessage responseWaitSpec.resolve(msg) errored:",t)}finally{e.wsResponseWait.delete(r.requestId)}if(s.skipOnMessage)return}if("PONG"!==r.msgType){var a=r.watchId&&e.watchIdClientMap.get(r.watchId);if(a)a.onMessage(r);else switch(console.error("[realtime] no realtime listener found responsible for watchId ".concat(r.watchId,": "),r),r.msgType){case"INIT_EVENT":case"NEXT_EVENT":case"CHECK_EVENT":(a=e.queryIdClientMap.get(r.msgData.queryID))&&a.onMessage(r);break;default:for(var c=0,u=Array.from(e.watchIdClientMap.entries());c<u.length;c++){u[c][1].onMessage(r);break}}}else if(e.lastPingSendTS){var l=Date.now()-e.lastPingSendTS;if(l>1e4)return void console.warn("[realtime] untrusted rtt observed: ".concat(l));e.rttObserved.length>=3&&e.rttObserved.splice(0,e.rttObserved.length-3+1),e.rttObserved.push(l)}},e.heartbeat()})},this.isWSConnected=function(){return Boolean(e.ws&&1===e.ws.readyState)},this.onceWSConnected=function(){return Di(e,void 0,Promise,function(){var t=this;return ji(this,function(e){return this.isWSConnected()?[2]:null!==this.wsInitPromise&&void 0!==this.wsInitPromise?[2,this.wsInitPromise]:[2,new Promise(function(e,n){t.wsReadySubsribers.push({resolve:e,reject:n})})]})})},this.webLogin=function(t,n){return Di(e,void 0,Promise,function(){var e,r,o,i,s,a,c,u,l=this;return ji(this,function(h){switch(h.label){case 0:if(!n)if(t){if(e=this.logins.get(t)){if(e.loggedIn&&e.loginResult)return[2,e.loginResult];if(null!==e.loggingInPromise&&void 0!==e.loggingInPromise)return[2,e.loggingInPromise]}}else if(null!==(null==(r=this.logins.get(""))?void 0:r.loggingInPromise)&&void 0!==(null==r?void 0:r.loggingInPromise))return[2,r.loggingInPromise];o=new Promise(function(t,e){Di(l,void 0,void 0,function(){var n,r,o,i,s;return ji(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,this.getWsSign()];case 1:return n=a.sent(),r={envId:n.envId||"",accessToken:"",referrer:"web",sdkVersion:"",dataVersion:""},o={watchId:void 0,requestId:li(),msgType:"LOGIN",msgData:r,exMsgData:{runtime:xi(),signStr:n.signStr,secretVersion:n.secretVersion}},[4,this.send({msg:o,waitResponse:!0,skipOnMessage:!0,timeout:5e3})];case 2:return(i=a.sent()).msgData.code?e(new Error("".concat(i.msgData.code," ").concat(i.msgData.message))):t({envId:n.envId}),[3,4];case 3:return s=a.sent(),e(s),[3,4];case 4:return[2]}})})}),i=t&&this.logins.get(t),s=Date.now(),i?(i.loggedIn=!1,i.loggingInPromise=o,i.loginStartTS=s):(i={loggedIn:!1,loggingInPromise:o,loginStartTS:s},this.logins.set(t||"",i)),h.label=1;case 1:return h.trys.push([1,3,,4]),[4,o];case 2:if(a=h.sent(),(c=t&&this.logins.get(t))&&c===i&&c.loginStartTS===s)return i.loggedIn=!0,i.loggingInPromise=void 0,i.loginStartTS=void 0,i.loginResult=a,[2,a];if(c){if(c.loggedIn&&c.loginResult)return[2,c.loginResult];if(null!==c.loggingInPromise&&void 0!==c.loggingInPromise)return[2,c.loggingInPromise];throw new Error("ws unexpected login info")}throw new Error("ws login info reset");case 3:throw u=h.sent(),i.loggedIn=!1,i.loggingInPromise=void 0,i.loginStartTS=void 0,i.loginResult=void 0,u;case 4:return[2]}})})},this.getWsSign=function(){return Di(e,void 0,Promise,function(){var t,e,n,r,o,i,s;return ji(this,function(a){switch(a.label){case 0:return this.wsSign&&this.wsSign.expiredTs>Date.now()?[2,this.wsSign]:(t=Date.now()+6e4,[4,this.context.appConfig.request.send("auth.wsWebSign",{runtime:xi()})]);case 1:if((e=a.sent()).code)throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败: ".concat(e.code));if(e.data)return n=e.data,r=n.signStr,o=n.wsUrl,i=n.secretVersion,s=n.envId,[2,{signStr:r,wsUrl:o,secretVersion:i,envId:s,expiredTs:t}];throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败")}})})},this.getWaitExpectedTimeoutLength=function(){return e.rttObserved.length?e.rttObserved.reduce(function(t,e){return t+e})/e.rttObserved.length*1.5:5e3},this.ping=function(){return Di(e,void 0,void 0,function(){var t;return ji(this,function(e){switch(e.label){case 0:return t={watchId:void 0,requestId:li(),msgType:"PING",msgData:null},[4,this.send({msg:t})];case 1:return e.sent(),[2]}})})},this.onWatchStart=function(t,n){e.queryIdClientMap.set(n,t)},this.onWatchClose=function(t,n){n&&e.queryIdClientMap.delete(n),e.watchIdClientMap.delete(t.watchId),e.virtualWSClient.delete(t),e.virtualWSClient.size||e.close(Ai.NoRealtimeListeners)},this.maxReconnect=t.maxReconnect||5,this.reconnectInterval=t.reconnectInterval||1e4,this.context=t.context}return t.prototype.clearHeartbeat=function(){this.pingTimeoutId&&clearTimeout(this.pingTimeoutId),this.pongTimeoutId&&clearTimeout(this.pongTimeoutId)},t.prototype.close=function(t){this.clearHeartbeat(),this.ws&&(this.ws.close(t,Pi[t].name),this.ws=void 0)},t.prototype.watch=function(t){this.ws||void 0!==this.wsInitPromise&&null!==this.wsInitPromise||this.initWebSocketConnection(!1);var e=new Oi(Li(Li({},t),{send:this.send,login:this.webLogin,isWSConnected:this.isWSConnected,onceWSConnected:this.onceWSConnected,getWaitExpectedTimeoutLength:this.getWaitExpectedTimeoutLength,onWatchStart:this.onWatchStart,onWatchClose:this.onWatchClose,debug:!0}));return this.virtualWSClient.add(e),this.watchIdClientMap.set(e.watchId,e),e.listener},t.prototype.heartbeat=function(t){var e=this;this.clearHeartbeat(),this.pingTimeoutId=setTimeout(function(){Di(e,void 0,void 0,function(){var t=this;return ji(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),this.ws&&1===this.ws.readyState?(this.lastPingSendTS=Date.now(),[4,this.ping()]):[2];case 1:return e.sent(),this.pingFailed=0,this.pongTimeoutId=setTimeout(function(){console.error("pong timed out"),t.pongMissed<2?(t.pongMissed+=1,t.heartbeat(!0)):t.initWebSocketConnection(!0)},this.context.appConfig.realtimePongWaitTimeout),[3,3];case 2:return e.sent(),this.pingFailed<2?(this.pingFailed+=1,this.heartbeat()):this.close(Ai.HeartbeatPingError),[3,3];case 3:return[2]}})})},t?0:this.context.appConfig.realtimePingInterval)},t}(),Mi={target:"database",entity:function(){var t,e=this.platform,n=e.adapter,r=e.runtime;t=n.wsClass,Ci=t,Ui(r)}},Bi={name:"realtime",IIFE:!0,entity:function(){this.prototype.wsClientClass=qi}};try{cloudbase.registerComponent(Bi),cloudbase.registerHook(Mi)}catch(t){}var Wi=function(){function t(){}return t.detectEnvironment=function(){var t;if("undefined"!=typeof WebSocket)return{type:"native",wsConstructor:WebSocket};var e=globalThis;if("undefined"!=typeof globalThis&&void 0!==e.WebSocket)return{type:"native",wsConstructor:e.WebSocket};var n=void 0!==l.g?l.g:void 0;if(n&&void 0!==n.WebSocket)return{type:"native",wsConstructor:n.WebSocket};if("undefined"!=typeof globalThis&&void 0!==e.WebSocketPair&&void 0===globalThis.WebSocket)return{type:"cloudflare",error:"Cloudflare Workers detected. WebSocket clients are not supported in Cloudflare Workers.",workaround:"Use Cloudflare Workers WebSocket API for server-side WebSocket handling, or deploy to a different runtime."};if("undefined"!=typeof globalThis&&e.EdgeRuntime||"undefined"!=typeof navigator&&(null===(t=navigator.userAgent)||void 0===t?void 0:t.includes("Vercel-Edge")))return{type:"unsupported",error:"Edge runtime detected (Vercel Edge/Netlify Edge). WebSockets are not supported in edge functions.",workaround:"Use serverless functions or a different deployment target for WebSocket functionality."};var r=globalThis.process;if(r){var o=r.versions;if(o&&o.node)return{type:"unsupported",error:"Node.js detected but native WebSocket not found.",workaround:"Ensure you are running Node.js 22+ or provide a WebSocket implementation via the transport option."}}return{type:"unsupported",error:"Unknown JavaScript runtime without WebSocket support.",workaround:"Ensure you're running in a supported environment (browser, Node.js, Deno) or provide a custom WebSocket implementation."}},t.getWebSocketConstructor=function(){var t=this.detectEnvironment();if(t.wsConstructor)return t.wsConstructor;var e=t.error||"WebSocket not supported in this environment.";throw t.workaround&&(e+="\n\nSuggested solution: ".concat(t.workaround)),new Error(e)},t.isWebSocketSupported=function(){try{return"native"===this.detectEnvironment().type}catch(t){return!1}},t}();const Fi=Wi;"realtime-js/".concat("1.0.0-alpha.0");var Hi="1.0.0",Vi="2.0.0",Gi=Vi,Ki="errored",Ji="joined",zi="phx_close",$i="phx_error",Yi="phx_join",Qi="phx_leave",Xi=function(){function t(t){this.HEADER_LENGTH=1,this.USER_BROADCAST_PUSH_META_LENGTH=6,this.KINDS={userBroadcastPush:3,userBroadcast:4},this.BINARY_ENCODING=0,this.JSON_ENCODING=1,this.BROADCAST_EVENT="broadcast",this.allowedMetadataKeys=[],this.allowedMetadataKeys=null!=t?t:[]}return t.prototype.encode=function(t,e){if(t.event===this.BROADCAST_EVENT&&!(t.payload instanceof ArrayBuffer)&&"string"==typeof t.payload.event)return e(this._binaryEncodeUserBroadcastPush(t));var n=[t.join_ref,t.ref,t.topic,t.event,t.payload];return e(JSON.stringify(n))},t.prototype._binaryEncodeUserBroadcastPush=function(t){var e;return this._isArrayBuffer(null===(e=t.payload)||void 0===e?void 0:e.payload)?this._encodeBinaryUserBroadcastPush(t):this._encodeJsonUserBroadcastPush(t)},t.prototype._encodeBinaryUserBroadcastPush=function(t){var e,n,r=null!==(n=null===(e=t.payload)||void 0===e?void 0:e.payload)&&void 0!==n?n:new ArrayBuffer(0);return this._encodeUserBroadcastPush(t,this.BINARY_ENCODING,r)},t.prototype._encodeJsonUserBroadcastPush=function(t){var e,n,r=null!==(n=null===(e=t.payload)||void 0===e?void 0:e.payload)&&void 0!==n?n:{},o=(new TextEncoder).encode(JSON.stringify(r)).buffer;return this._encodeUserBroadcastPush(t,this.JSON_ENCODING,o)},t.prototype._encodeUserBroadcastPush=function(t,e,n){var r,o,i=new TextEncoder,s=i.encode(t.topic),a=i.encode(null!==(r=t.ref)&&void 0!==r?r:""),c=i.encode(null!==(o=t.join_ref)&&void 0!==o?o:""),u=i.encode(t.payload.event),l=this.allowedMetadataKeys?this._pick(t.payload,this.allowedMetadataKeys):{},h=i.encode(0===Object.keys(l).length?"":JSON.stringify(l));if(c.length>255)throw new Error("joinRef length ".concat(c.length," exceeds maximum of 255"));if(a.length>255)throw new Error("ref length ".concat(a.length," exceeds maximum of 255"));if(s.length>255)throw new Error("topic length ".concat(s.length," exceeds maximum of 255"));if(u.length>255)throw new Error("userEvent length ".concat(u.length," exceeds maximum of 255"));if(h.length>255)throw new Error("metadata length ".concat(h.length," exceeds maximum of 255"));var d=this.USER_BROADCAST_PUSH_META_LENGTH+c.length+a.length+s.length+u.length+h.length,f=new ArrayBuffer(this.HEADER_LENGTH+d),p=new DataView(f),v=new Uint8Array(f),y=0;p.setUint8(y++,this.KINDS.userBroadcastPush),p.setUint8(y++,c.length),p.setUint8(y++,a.length),p.setUint8(y++,s.length),p.setUint8(y++,u.length),p.setUint8(y++,h.length),p.setUint8(y++,e),v.set(c,y),y+=c.length,v.set(a,y),y+=a.length,v.set(s,y),y+=s.length,v.set(u,y),y+=u.length,v.set(h,y),y+=h.length;var g=new Uint8Array(f.byteLength+n.byteLength);return g.set(new Uint8Array(f),0),g.set(new Uint8Array(n),f.byteLength),g.buffer},t.prototype.decode=function(t,e){if(this._isArrayBuffer(t))return e(this._binaryDecode(t));if("string"==typeof t){var n=JSON.parse(t);return e({join_ref:n[0],ref:n[1],topic:n[2],event:n[3],payload:n[4]})}return e({})},t.prototype._binaryDecode=function(t){var e=new DataView(t),n=e.getUint8(0),r=new TextDecoder;if(n===this.KINDS.userBroadcast)return this._decodeUserBroadcast(t,e,r)},t.prototype._decodeUserBroadcast=function(t,e,n){var r=e.getUint8(1),o=e.getUint8(2),i=e.getUint8(3),s=e.getUint8(4),a=this.HEADER_LENGTH+4,c=n.decode(t.slice(a,a+r));a+=r;var u=n.decode(t.slice(a,a+o));a+=o;var l=n.decode(t.slice(a,a+i));a+=i;var h=t.slice(a,t.byteLength),d=s===this.JSON_ENCODING?JSON.parse(n.decode(h)):h,f={type:this.BROADCAST_EVENT,event:u,payload:d};return i>0&&(f.meta=JSON.parse(l)),{join_ref:null,ref:null,topic:c,event:this.BROADCAST_EVENT,payload:f}},t.prototype._isArrayBuffer=function(t){var e;return t instanceof ArrayBuffer||"ArrayBuffer"===(null===(e=null==t?void 0:t.constructor)||void 0===e?void 0:e.name)},t.prototype._pick=function(t,e){return t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(function(t){var n=t[0];return e.includes(n)})):{}},t}();const Zi=Xi;var ts;!function(t){t.abstime="abstime",t.bool="bool",t.date="date",t.daterange="daterange",t.float4="float4",t.float8="float8",t.int2="int2",t.int4="int4",t.int4range="int4range",t.int8="int8",t.int8range="int8range",t.json="json",t.jsonb="jsonb",t.money="money",t.numeric="numeric",t.oid="oid",t.reltime="reltime",t.text="text",t.time="time",t.timestamp="timestamp",t.timestamptz="timestamptz",t.timetz="timetz",t.tsrange="tsrange",t.tstzrange="tstzrange"}(ts||(ts={}));var es=function(t,e,n){var r;void 0===n&&(n={});var o=null!==(r=n.skipTypes)&&void 0!==r?r:[];return e?Object.keys(e).reduce(function(n,r){return n[r]=ns(r,t,e,o),n},{}):{}},ns=function(t,e,n,r){var o=e.find(function(e){return e.name===t}),i=null==o?void 0:o.type,s=n[t];return i&&!r.includes(i)?rs(i,s):os(s)},rs=function(t,e){if("_"===t.charAt(0)){var n=t.slice(1,t.length);return cs(e,n)}switch(t){case ts.bool:return is(e);case ts.float4:case ts.float8:case ts.int2:case ts.int4:case ts.int8:case ts.numeric:case ts.oid:return ss(e);case ts.json:case ts.jsonb:return as(e);case ts.timestamp:return us(e);case ts.abstime:case ts.date:case ts.daterange:case ts.int4range:case ts.int8range:case ts.money:case ts.reltime:case ts.text:case ts.time:case ts.timestamptz:case ts.timetz:case ts.tsrange:case ts.tstzrange:default:return os(e)}},os=function(t){return t},is=function(t){switch(t){case"t":return!0;case"f":return!1;default:return t}},ss=function(t){if("string"==typeof t){var e=parseFloat(t);if(!Number.isNaN(e))return e}return t},as=function(t){if("string"==typeof t)try{return JSON.parse(t)}catch(e){return t}return t},cs=function(t,e){if("string"!=typeof t)return t;var n=t.length-1,r=t[n];if("{"===t[0]&&"}"===r){var o=void 0,i=t.slice(1,n);try{o=JSON.parse("["+i+"]")}catch(t){o=i?i.split(","):[]}return o.map(function(t){return rs(e,t)})}return t},us=function(t){return"string"==typeof t?t.replace(" ","T"):t};function ls(t){var e=t.indexOf("#"),n=-1===e?t:t.slice(0,e),r=-1===e?"":t.slice(e),o=n.indexOf("?");return{base:-1===o?n:n.slice(0,o),query:-1===o?"":n.slice(o),hash:r}}var hs=function(t){var e=ls(t),n=e.base,r=e.query,o=e.hash,i=n.replace(/^ws/i,"http").replace(/\/+$/,"");return(i=(i=i.replace(/\/socket\/websocket$/i,"").replace(/\/socket$/i,"").replace(/\/websocket$/i,"")).replace(/\/+$/,"")+"/api/broadcast")+r+o},ds=t=>"function"==typeof t?t:function(){return t},fs="undefined"!=typeof self?self:null,ps="undefined"!=typeof window?window:null,vs=fs||ps||globalThis,ys="closed",gs="errored",ms="joined",bs="joining",ws="leaving",_s="phx_close",Es="phx_error",Is="phx_reply",Ss="phx_leave",Os="websocket",Ts="base64url.bearer.phx.",As=class{constructor(t,e,n,r){this.channel=t,this.event=e,this.payload=n||function(){return{}},this.receivedResp=null,this.timeout=r,this.timeoutTimer=null,this.recHooks=[],this.sent=!1,this.ref=void 0}resend(t){this.timeout=t,this.reset(),this.send()}send(){this.hasReceived("timeout")||(this.startTimeout(),this.sent=!0,this.channel.socket.push({topic:this.channel.topic,event:this.event,payload:this.payload(),ref:this.ref,join_ref:this.channel.joinRef()}))}receive(t,e){return this.hasReceived(t)&&e(this.receivedResp.response),this.recHooks.push({status:t,callback:e}),this}reset(){this.cancelRefEvent(),this.ref=null,this.refEvent=null,this.receivedResp=null,this.sent=!1}destroy(){this.cancelRefEvent(),this.cancelTimeout()}matchReceive({status:t,response:e,_ref:n}){this.recHooks.filter(e=>e.status===t).forEach(t=>t.callback(e))}cancelRefEvent(){this.refEvent&&this.channel.off(this.refEvent)}cancelTimeout(){clearTimeout(this.timeoutTimer),this.timeoutTimer=null}startTimeout(){this.timeoutTimer&&this.cancelTimeout(),this.ref=this.channel.socket.makeRef(),this.refEvent=this.channel.replyEventName(this.ref),this.channel.on(this.refEvent,t=>{this.cancelRefEvent(),this.cancelTimeout(),this.receivedResp=t,this.matchReceive(t)}),this.timeoutTimer=setTimeout(()=>{this.trigger("timeout",{})},this.timeout)}hasReceived(t){return this.receivedResp&&this.receivedResp.status===t}trigger(t,e){this.channel.trigger(this.refEvent,{status:t,response:e})}},Ps=class{constructor(t,e){this.callback=t,this.timerCalc=e,this.timer=void 0,this.tries=0}reset(){this.tries=0,clearTimeout(this.timer)}scheduleTimeout(){clearTimeout(this.timer),this.timer=setTimeout(()=>{this.tries=this.tries+1,this.callback()},this.timerCalc(this.tries+1))}},Rs=class{constructor(t,e,n){this.state=ys,this.topic=t,this.params=ds(e||{}),this.socket=n,this.bindings=[],this.bindingRef=0,this.timeout=this.socket.timeout,this.joinedOnce=!1,this.joinPush=new As(this,"phx_join",this.params,this.timeout),this.pushBuffer=[],this.stateChangeRefs=[],this.rejoinTimer=new Ps(()=>{this.socket.isConnected()&&this.rejoin()},this.socket.rejoinAfterMs),this.stateChangeRefs.push(this.socket.onError(()=>this.rejoinTimer.reset())),this.stateChangeRefs.push(this.socket.onOpen(()=>{this.rejoinTimer.reset(),this.isErrored()&&this.rejoin()})),this.joinPush.receive("ok",()=>{this.state=ms,this.rejoinTimer.reset(),this.pushBuffer.forEach(t=>t.send()),this.pushBuffer=[]}),this.joinPush.receive("error",t=>{this.state=gs,this.socket.hasLogger()&&this.socket.log("channel",`error ${this.topic}`,t),this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.onClose(()=>{this.rejoinTimer.reset(),this.socket.hasLogger()&&this.socket.log("channel",`close ${this.topic}`),this.state=ys,this.socket.remove(this)}),this.onError(t=>{this.socket.hasLogger()&&this.socket.log("channel",`error ${this.topic}`,t),this.isJoining()&&this.joinPush.reset(),this.state=gs,this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.joinPush.receive("timeout",()=>{this.socket.hasLogger()&&this.socket.log("channel",`timeout ${this.topic}`,this.joinPush.timeout),new As(this,Ss,ds({}),this.timeout).send(),this.state=gs,this.joinPush.reset(),this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.on(Is,(t,e)=>{this.trigger(this.replyEventName(e),t)})}join(t=this.timeout){if(this.joinedOnce)throw new Error("tried to join multiple times. 'join' can only be called a single time per channel instance");return this.timeout=t,this.joinedOnce=!0,this.rejoin(),this.joinPush}teardown(){this.pushBuffer.forEach(t=>t.destroy()),this.pushBuffer=[],this.rejoinTimer.reset(),this.joinPush.destroy(),this.state=ys,this.bindings=[]}onClose(t){this.on(_s,t)}onError(t){return this.on(Es,e=>t(e))}on(t,e){let n=this.bindingRef++;return this.bindings.push({event:t,ref:n,callback:e}),n}off(t,e){this.bindings=this.bindings.filter(n=>!(n.event===t&&(void 0===e||e===n.ref)))}canPush(){return this.socket.isConnected()&&this.isJoined()}push(t,e,n=this.timeout){if(e=e||{},!this.joinedOnce)throw new Error(`tried to push '${t}' to '${this.topic}' before joining. Use channel.join() before pushing events`);let r=new As(this,t,function(){return e},n);return this.canPush()?r.send():(r.startTimeout(),this.pushBuffer.push(r)),r}leave(t=this.timeout){this.rejoinTimer.reset(),this.joinPush.cancelTimeout(),this.state=ws;let e=()=>{this.socket.hasLogger()&&this.socket.log("channel",`leave ${this.topic}`),this.trigger(_s,"leave")},n=new As(this,Ss,ds({}),t);return n.receive("ok",()=>e()).receive("timeout",()=>e()),n.send(),this.canPush()||n.trigger("ok",{}),n}onMessage(t,e,n){return e}filterBindings(t,e,n){return!0}isMember(t,e,n,r){return!(this.topic!==t||r&&r!==this.joinRef()&&(this.socket.hasLogger()&&this.socket.log("channel","dropping outdated message",{topic:t,event:e,payload:n,joinRef:r}),1))}joinRef(){return this.joinPush.ref}rejoin(t=this.timeout){this.isLeaving()||(this.socket.leaveOpenTopic(this.topic),this.state=bs,this.joinPush.resend(t))}trigger(t,e,n,r){let o=this.onMessage(t,e,n,r);if(e&&!o)throw new Error("channel onMessage callbacks must return the payload, modified or unmodified");let i=this.bindings.filter(r=>r.event===t&&this.filterBindings(r,e,n));for(let t=0;t<i.length;t++)i[t].callback(o,n,r||this.joinRef())}replyEventName(t){return`chan_reply_${t}`}isClosed(){return this.state===ys}isErrored(){return this.state===gs}isJoined(){return this.state===ms}isJoining(){return this.state===bs}isLeaving(){return this.state===ws}},Cs=class{static request(t,e,n,r,o,i,s){if(vs.XDomainRequest){let n=new vs.XDomainRequest;return this.xdomainRequest(n,t,e,r,o,i,s)}if(vs.XMLHttpRequest){let a=new vs.XMLHttpRequest;return this.xhrRequest(a,t,e,n,r,o,i,s)}if(vs.fetch&&vs.AbortController)return this.fetchRequest(t,e,n,r,o,i,s);throw new Error("No suitable XMLHttpRequest implementation found")}static fetchRequest(t,e,n,r,o,i,s){let a={method:t,headers:n,body:r},c=null;return o&&(c=new AbortController,setTimeout(()=>c.abort(),o),a.signal=c.signal),vs.fetch(e,a).then(t=>t.text()).then(t=>this.parseJSON(t)).then(t=>s&&s(t)).catch(t=>{"AbortError"===t.name&&i?i():s&&s(null)}),c}static xdomainRequest(t,e,n,r,o,i,s){return t.timeout=o,t.open(e,n),t.onload=()=>{let e=this.parseJSON(t.responseText);s&&s(e)},i&&(t.ontimeout=i),t.onprogress=()=>{},t.send(r),t}static xhrRequest(t,e,n,r,o,i,s,a){t.open(e,n,!0),t.timeout=i;for(let[e,n]of Object.entries(r))t.setRequestHeader(e,n);return t.onerror=()=>a&&a(null),t.onreadystatechange=()=>{if(4===t.readyState&&a){let e=this.parseJSON(t.responseText);a(e)}},s&&(t.ontimeout=s),t.send(o),t}static parseJSON(t){if(!t||""===t)return null;try{return JSON.parse(t)}catch{return console&&console.log("failed to parse JSON response",t),null}}static serialize(t,e){let n=[];for(var r in t){if(!Object.prototype.hasOwnProperty.call(t,r))continue;let o=e?`${e}[${r}]`:r,i=t[r];"object"==typeof i?n.push(this.serialize(i,o)):n.push(encodeURIComponent(o)+"="+encodeURIComponent(i))}return n.join("&")}static appendParams(t,e){if(0===Object.keys(e).length)return t;let n=t.match(/\?/)?"&":"?";return`${t}${n}${this.serialize(e)}`}},ks=class{constructor(t,e){e&&2===e.length&&e[1].startsWith(Ts)&&(this.authToken=atob(e[1].slice(21))),this.endPoint=null,this.token=null,this.skipHeartbeat=!0,this.reqs=new Set,this.awaitingBatchAck=!1,this.currentBatch=null,this.currentBatchTimer=null,this.batchBuffer=[],this.onopen=function(){},this.onerror=function(){},this.onmessage=function(){},this.onclose=function(){},this.pollEndpoint=this.normalizeEndpoint(t),this.readyState=0,setTimeout(()=>this.poll(),0)}normalizeEndpoint(t){return t.replace("ws://","http://").replace("wss://","https://").replace(new RegExp("(.*)/"+Os),"$1/longpoll")}endpointURL(){return Cs.appendParams(this.pollEndpoint,{token:this.token})}closeAndRetry(t,e,n){this.close(t,e,n),this.readyState=0}ontimeout(){this.onerror("timeout"),this.closeAndRetry(1005,"timeout",!1)}isActive(){return 1===this.readyState||0===this.readyState}poll(){const t={Accept:"application/json"};this.authToken&&(t["X-Phoenix-AuthToken"]=this.authToken),this.ajax("GET",t,null,()=>this.ontimeout(),t=>{if(t){var{status:e,token:n,messages:r}=t;if(410===e&&null!==this.token)return this.onerror(410),void this.closeAndRetry(3410,"session_gone",!1);this.token=n}else e=0;switch(e){case 200:r.forEach(t=>{setTimeout(()=>this.onmessage({data:t}),0)}),this.poll();break;case 204:this.poll();break;case 410:this.readyState=1,this.onopen({}),this.poll();break;case 403:this.onerror(403),this.close(1008,"forbidden",!1);break;case 0:case 500:this.onerror(500),this.closeAndRetry(1011,"internal server error",500);break;default:throw new Error(`unhandled poll status ${e}`)}})}send(t){"string"!=typeof t&&(t=(t=>{let e="",n=new Uint8Array(t),r=n.byteLength;for(let t=0;t<r;t++)e+=String.fromCharCode(n[t]);return btoa(e)})(t)),this.currentBatch?this.currentBatch.push(t):this.awaitingBatchAck?this.batchBuffer.push(t):(this.currentBatch=[t],this.currentBatchTimer=setTimeout(()=>{this.batchSend(this.currentBatch),this.currentBatch=null},0))}batchSend(t,e=0){this.awaitingBatchAck=!0;const n=e+100,r=t.slice(e,n);this.ajax("POST",{"Content-Type":"application/x-ndjson"},r.join("\n"),()=>this.onerror("timeout"),e=>{e&&200===e.status?n<t.length?this.batchSend(t,n):this.batchBuffer.length>0?(this.batchSend(this.batchBuffer),this.batchBuffer=[]):this.awaitingBatchAck=!1:(this.awaitingBatchAck=!1,this.onerror(e&&e.status),this.closeAndRetry(1011,"internal server error",!1))})}close(t,e,n){for(let t of this.reqs)t.abort();this.readyState=3;let r=Object.assign({code:1e3,reason:void 0,wasClean:!0},{code:t,reason:e,wasClean:n});this.batchBuffer=[],clearTimeout(this.currentBatchTimer),this.currentBatchTimer=null,"undefined"!=typeof CloseEvent?this.onclose(new CloseEvent("close",r)):this.onclose(r)}ajax(t,e,n,r,o){let i;i=Cs.request(t,this.endpointURL(),e,n,this.timeout,()=>{this.reqs.delete(i),r()},t=>{this.reqs.delete(i),this.isActive()&&o(t)}),this.reqs.add(i)}},Ns=class t{constructor(e,n={}){let r=n.events||{state:"presence_state",diff:"presence_diff"};this.state=Object.create(null),this.pendingDiffs=[],this.channel=e,this.joinRef=null,this.caller={onJoin:function(){},onLeave:function(){},onSync:function(){}},this.channel.on(r.state,e=>{let{onJoin:n,onLeave:r,onSync:o}=this.caller;this.joinRef=this.channel.joinRef(),this.state=t.syncState(this.state,e,n,r),this.pendingDiffs.forEach(e=>{this.state=t.syncDiff(this.state,e,n,r)}),this.pendingDiffs=[],o()}),this.channel.on(r.diff,e=>{let{onJoin:n,onLeave:r,onSync:o}=this.caller;this.inPendingSyncState()?this.pendingDiffs.push(e):(this.state=t.syncDiff(this.state,e,n,r),o())})}onJoin(t){this.caller.onJoin=t}onLeave(t){this.caller.onLeave=t}onSync(t){this.caller.onSync=t}list(e){return t.list(this.state,e)}inPendingSyncState(){return!this.joinRef||this.joinRef!==this.channel.joinRef()}static syncState(t,e,n,r){let o=this.toNullProtoObj(this.clone(t));e=this.toNullProtoObj(e);let i=Object.create(null),s=Object.create(null);return this.map(o,(t,n)=>{e[t]||(s[t]=n)}),this.map(e,(t,e)=>{let n=o[t];if(n){let r=e.metas.map(t=>t.phx_ref),o=n.metas.map(t=>t.phx_ref),a=e.metas.filter(t=>o.indexOf(t.phx_ref)<0),c=n.metas.filter(t=>r.indexOf(t.phx_ref)<0);a.length>0&&(i[t]=e,i[t].metas=a),c.length>0&&(s[t]=this.clone(n),s[t].metas=c)}else i[t]=e}),this.syncDiff(o,{joins:i,leaves:s},n,r)}static syncDiff(t,e,n,r){t=this.toNullProtoObj(t);let{joins:o,leaves:i}=this.clone(e);return n||(n=function(){}),r||(r=function(){}),this.map(o,(e,r)=>{let o=t[e];if(t[e]=this.clone(r),o){let n=t[e].metas.map(t=>t.phx_ref),r=o.metas.filter(t=>n.indexOf(t.phx_ref)<0);t[e].metas.unshift(...r)}n(e,o,r)}),this.map(i,(e,n)=>{let o=t[e];if(!o)return;let i=n.metas.map(t=>t.phx_ref);o.metas=o.metas.filter(t=>i.indexOf(t.phx_ref)<0),r(e,o,n),0===o.metas.length&&delete t[e]}),t}static list(t,e){return e||(e=function(t,e){return e}),this.map(t,(t,n)=>e(t,n))}static map(t,e){return Object.getOwnPropertyNames(t).map(n=>e(n,t[n]))}static toNullProtoObj(t){if(null===Object.getPrototypeOf(t))return t;let e=Object.create(null);return Object.getOwnPropertyNames(t).forEach(n=>{e[n]=t[n]}),e}static clone(t){return JSON.parse(JSON.stringify(t))}},xs={HEADER_LENGTH:1,META_LENGTH:4,KINDS:{push:0,reply:1,broadcast:2},encode(t,e){if(t.payload.constructor===ArrayBuffer)return e(this.binaryEncode(t));{let n=[t.join_ref,t.ref,t.topic,t.event,t.payload];return e(JSON.stringify(n))}},decode(t,e){if(t.constructor===ArrayBuffer)return e(this.binaryDecode(t));{let[n,r,o,i,s]=JSON.parse(t);return e({join_ref:n,ref:r,topic:o,event:i,payload:s})}},binaryEncode(t){let{join_ref:e,ref:n,event:r,topic:o,payload:i}=t,s=new TextEncoder,a=s.encode(e),c=s.encode(n),u=s.encode(o),l=s.encode(r);this.assertFieldSize(a.byteLength,"join_ref"),this.assertFieldSize(c.byteLength,"ref"),this.assertFieldSize(u.byteLength,"topic"),this.assertFieldSize(l.byteLength,"event");let h=this.META_LENGTH+a.byteLength+c.byteLength+u.byteLength+l.byteLength,d=new ArrayBuffer(this.HEADER_LENGTH+h),f=new Uint8Array(d),p=new DataView(d),v=0;p.setUint8(v++,this.KINDS.push),p.setUint8(v++,a.byteLength),p.setUint8(v++,c.byteLength),p.setUint8(v++,u.byteLength),p.setUint8(v++,l.byteLength),f.set(a,v),v+=a.byteLength,f.set(c,v),v+=c.byteLength,f.set(u,v),v+=u.byteLength,f.set(l,v),v+=l.byteLength;var y=new Uint8Array(d.byteLength+i.byteLength);return y.set(f,0),y.set(new Uint8Array(i),d.byteLength),y.buffer},assertFieldSize(t,e){if(t>255)throw new Error(`unable to convert ${e} to binary: must be less than or equal to 255 bytes, but is ${t} bytes`)},binaryDecode(t){let e=new DataView(t),n=e.getUint8(0),r=new TextDecoder;switch(n){case this.KINDS.push:return this.decodePush(t,e,r);case this.KINDS.reply:return this.decodeReply(t,e,r);case this.KINDS.broadcast:return this.decodeBroadcast(t,e,r)}},decodePush(t,e,n){let r=e.getUint8(1),o=e.getUint8(2),i=e.getUint8(3),s=this.HEADER_LENGTH+this.META_LENGTH-1,a=n.decode(t.slice(s,s+r));s+=r;let c=n.decode(t.slice(s,s+o));s+=o;let u=n.decode(t.slice(s,s+i));return s+=i,{join_ref:a,ref:null,topic:c,event:u,payload:t.slice(s,t.byteLength)}},decodeReply(t,e,n){let r=e.getUint8(1),o=e.getUint8(2),i=e.getUint8(3),s=e.getUint8(4),a=this.HEADER_LENGTH+this.META_LENGTH,c=n.decode(t.slice(a,a+r));a+=r;let u=n.decode(t.slice(a,a+o));a+=o;let l=n.decode(t.slice(a,a+i));a+=i;let h=n.decode(t.slice(a,a+s));a+=s;let d=t.slice(a,t.byteLength);return{join_ref:c,ref:u,topic:l,event:Is,payload:{status:h,response:d}}},decodeBroadcast(t,e,n){let r=e.getUint8(1),o=e.getUint8(2),i=this.HEADER_LENGTH+2,s=n.decode(t.slice(i,i+r));i+=r;let a=n.decode(t.slice(i,i+o));return i+=o,{join_ref:null,ref:null,topic:s,event:a,payload:t.slice(i,t.byteLength)}}},Us=class{constructor(t,e={}){this.stateChangeCallbacks={open:[],close:[],error:[],message:[]},this.channels=[],this.sendBuffer=[],this.ref=0,this.fallbackRef=null,this.timeout=e.timeout||1e4,this.transport=e.transport||vs.WebSocket||ks,this.conn=void 0,this.primaryPassedHealthCheck=!1,this.longPollFallbackMs=e.longPollFallbackMs,this.fallbackTimer=null;let n=null;try{n=vs&&vs.sessionStorage}catch{}this.sessionStore=e.sessionStorage||n,this.establishedConnections=0,this.defaultEncoder=xs.encode.bind(xs),this.defaultDecoder=xs.decode.bind(xs),this.closeWasClean=!0,this.disconnecting=!1,this.binaryType=e.binaryType||"arraybuffer",this.connectClock=1,this.pageHidden=!1,this.encode=void 0,this.decode=void 0,this.transport!==ks?(this.encode=e.encode||this.defaultEncoder,this.decode=e.decode||this.defaultDecoder):(this.encode=this.defaultEncoder,this.decode=this.defaultDecoder);let r=null;ps&&ps.addEventListener&&(ps.addEventListener("pagehide",t=>{this.conn&&(this.disconnect(),r=this.connectClock)}),ps.addEventListener("pageshow",t=>{r===this.connectClock&&(r=null,this.connect())}),ps.addEventListener("visibilitychange",()=>{"hidden"===document.visibilityState?this.pageHidden=!0:(this.pageHidden=!1,this.isConnected()||this.closeWasClean||this.teardown(()=>this.connect()))})),this.heartbeatIntervalMs=e.heartbeatIntervalMs||3e4,this.autoSendHeartbeat=e.autoSendHeartbeat??!0,this.heartbeatCallback=e.heartbeatCallback??(()=>{}),this.rejoinAfterMs=t=>e.rejoinAfterMs?e.rejoinAfterMs(t):[1e3,2e3,5e3][t-1]||1e4,this.reconnectAfterMs=t=>e.reconnectAfterMs?e.reconnectAfterMs(t):[10,50,100,150,200,250,500,1e3,2e3][t-1]||5e3,this.logger=e.logger||null,!this.logger&&e.debug&&(this.logger=(t,e,n)=>{console.log(`${t}: ${e}`,n)}),this.longpollerTimeout=e.longpollerTimeout||2e4,this.params=ds(e.params||{}),this.endPoint=`${t}/${Os}`,this.vsn=e.vsn||"2.0.0",this.heartbeatTimeoutTimer=null,this.heartbeatTimer=null,this.heartbeatSentAt=null,this.pendingHeartbeatRef=null,this.reconnectTimer=new Ps(()=>{if(this.pageHidden)return this.log("Not reconnecting as page is hidden!"),void this.teardown();this.teardown(async()=>{e.beforeReconnect&&await e.beforeReconnect(),this.connect()})},this.reconnectAfterMs),this.authToken=e.authToken&&ds(e.authToken)}getLongPollTransport(){return ks}replaceTransport(t){this.connectClock++,this.closeWasClean=!0,clearTimeout(this.fallbackTimer),this.reconnectTimer.reset(),this.conn&&(this.conn.close(),this.conn=null),this.transport=t}protocol(){return location.protocol.match(/^https/)?"wss":"ws"}endPointURL(){let t=Cs.appendParams(Cs.appendParams(this.endPoint,this.params()),{vsn:this.vsn});return"/"!==t.charAt(0)?t:"/"===t.charAt(1)?`${this.protocol()}:${t}`:`${this.protocol()}://${location.host}${t}`}disconnect(t,e,n){this.connectClock++,this.disconnecting=!0,this.closeWasClean=!0,clearTimeout(this.fallbackTimer),this.reconnectTimer.reset(),this.teardown(()=>{this.disconnecting=!1,t&&t()},e,n)}connect(t){t&&(console&&console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor"),this.params=ds(t)),this.conn&&!this.disconnecting||(this.longPollFallbackMs&&this.transport!==ks?this.connectWithFallback(ks,this.longPollFallbackMs):this.transportConnect())}log(t,e,n){this.logger&&this.logger(t,e,n)}hasLogger(){return null!==this.logger}onOpen(t){let e=this.makeRef();return this.stateChangeCallbacks.open.push([e,t]),e}onClose(t){let e=this.makeRef();return this.stateChangeCallbacks.close.push([e,t]),e}onError(t){let e=this.makeRef();return this.stateChangeCallbacks.error.push([e,t]),e}onMessage(t){let e=this.makeRef();return this.stateChangeCallbacks.message.push([e,t]),e}onHeartbeat(t){this.heartbeatCallback=t}ping(t){if(!this.isConnected())return!1;let e=this.makeRef(),n=Date.now();this.push({topic:"phoenix",event:"heartbeat",payload:{},ref:e});let r=this.onMessage(o=>{o.ref===e&&(this.off([r]),t(Date.now()-n))});return!0}transportName(t){return t===ks?"LongPoll":t.name}transportConnect(){let t;this.connectClock++,this.closeWasClean=!1,this.authToken&&(t=["phoenix",`${Ts}${btoa(this.authToken()).replace(/=/g,"")}`]),this.conn=new this.transport(this.endPointURL(),t),this.conn.binaryType=this.binaryType,this.conn.timeout=this.longpollerTimeout,this.conn.onopen=()=>this.onConnOpen(),this.conn.onerror=t=>this.onConnError(t),this.conn.onmessage=t=>this.onConnMessage(t),this.conn.onclose=t=>this.onConnClose(t)}getSession(t){return this.sessionStore&&this.sessionStore.getItem(t)}storeSession(t,e){this.sessionStore&&this.sessionStore.setItem(t,e)}connectWithFallback(t,e=2500){clearTimeout(this.fallbackTimer);let n,r=!1,o=!0,i=this.transportName(t),s=e=>{this.log("transport",`falling back to ${i}...`,e),this.off([void 0,n]),o=!1,this.replaceTransport(t),this.transportConnect()};if(this.getSession(`phx:fallback:${i}`))return s("memorized");this.fallbackTimer=setTimeout(s,e),n=this.onError(t=>{this.log("transport","error",t),o&&!r&&(clearTimeout(this.fallbackTimer),s(t))}),this.fallbackRef&&this.off([this.fallbackRef]),this.fallbackRef=this.onOpen(()=>{if(r=!0,!o){let e=this.transportName(t);return this.primaryPassedHealthCheck||this.storeSession(`phx:fallback:${e}`,"true"),this.log("transport",`established ${e} fallback`)}clearTimeout(this.fallbackTimer),this.fallbackTimer=setTimeout(s,e),this.ping(t=>{this.log("transport","connected to primary after",t),this.primaryPassedHealthCheck=!0,clearTimeout(this.fallbackTimer)})}),this.transportConnect()}clearHeartbeats(){clearTimeout(this.heartbeatTimer),clearTimeout(this.heartbeatTimeoutTimer)}onConnOpen(){this.hasLogger()&&this.log("transport",`connected to ${this.endPointURL()}`),this.closeWasClean=!1,this.disconnecting=!1,this.establishedConnections++,this.flushSendBuffer(),this.reconnectTimer.reset(),this.autoSendHeartbeat&&this.resetHeartbeat(),this.triggerStateCallbacks("open")}heartbeatTimeout(){if(this.pendingHeartbeatRef){this.pendingHeartbeatRef=null,this.heartbeatSentAt=null,this.hasLogger()&&this.log("transport","heartbeat timeout. Attempting to re-establish connection");try{this.heartbeatCallback("timeout")}catch(t){this.log("error","error in heartbeat callback",t)}this.triggerChanError(new Error("heartbeat timeout")),this.closeWasClean=!1,this.teardown(()=>this.reconnectTimer.scheduleTimeout(),1e3,"heartbeat timeout")}}resetHeartbeat(){this.conn&&this.conn.skipHeartbeat||(this.pendingHeartbeatRef=null,this.clearHeartbeats(),this.heartbeatTimer=setTimeout(()=>this.sendHeartbeat(),this.heartbeatIntervalMs))}teardown(t,e,n){if(!this.conn)return t&&t();const r=this.conn;this.waitForBufferDone(r,()=>{e?r.close(e,n||""):r.close(),this.waitForSocketClosed(r,()=>{this.conn===r&&(this.conn.onopen=function(){},this.conn.onerror=function(){},this.conn.onmessage=function(){},this.conn.onclose=function(){},this.conn=null),t&&t()})})}waitForBufferDone(t,e,n=1){5!==n&&t.bufferedAmount?setTimeout(()=>{this.waitForBufferDone(t,e,n+1)},150*n):e()}waitForSocketClosed(t,e,n=1){5!==n&&3!==t.readyState?setTimeout(()=>{this.waitForSocketClosed(t,e,n+1)},150*n):e()}onConnClose(t){this.conn&&(this.conn.onclose=()=>{}),this.hasLogger()&&this.log("transport","close",t),this.triggerChanError(t),this.clearHeartbeats(),this.closeWasClean||this.reconnectTimer.scheduleTimeout(),this.triggerStateCallbacks("close",t)}onConnError(t){this.hasLogger()&&this.log("transport","error",t);let e=this.transport,n=this.establishedConnections;this.triggerStateCallbacks("error",t,e,n),(e===this.transport||n>0)&&this.triggerChanError(t)}triggerChanError(t){this.channels.forEach(e=>{e.isErrored()||e.isLeaving()||e.isClosed()||e.trigger(Es,t)})}connectionState(){switch(this.conn&&this.conn.readyState){case 0:return"connecting";case 1:return"open";case 2:return"closing";default:return"closed"}}isConnected(){return"open"===this.connectionState()}remove(t){this.off(t.stateChangeRefs),this.channels=this.channels.filter(e=>e!==t)}off(t){for(let e in this.stateChangeCallbacks)this.stateChangeCallbacks[e]=this.stateChangeCallbacks[e].filter(([e])=>-1===t.indexOf(e))}channel(t,e={}){let n=new Rs(t,e,this);return this.channels.push(n),n}push(t){if(this.hasLogger()){let{topic:e,event:n,payload:r,ref:o,join_ref:i}=t;this.log("push",`${e} ${n} (${i}, ${o})`,r)}this.isConnected()?this.encode(t,t=>this.conn.send(t)):this.sendBuffer.push(()=>this.encode(t,t=>this.conn.send(t)))}makeRef(){let t=this.ref+1;return t===this.ref?this.ref=0:this.ref=t,this.ref.toString()}sendHeartbeat(){if(this.isConnected())if(this.pendingHeartbeatRef)this.heartbeatTimeout();else{this.pendingHeartbeatRef=this.makeRef(),this.heartbeatSentAt=Date.now(),this.push({topic:"phoenix",event:"heartbeat",payload:{},ref:this.pendingHeartbeatRef});try{this.heartbeatCallback("sent")}catch(t){this.log("error","error in heartbeat callback",t)}this.heartbeatTimeoutTimer=setTimeout(()=>this.heartbeatTimeout(),this.heartbeatIntervalMs)}else try{this.heartbeatCallback("disconnected")}catch(t){this.log("error","error in heartbeat callback",t)}}flushSendBuffer(){this.isConnected()&&this.sendBuffer.length>0&&(this.sendBuffer.forEach(t=>t()),this.sendBuffer=[])}onConnMessage(t){this.decode(t.data,t=>{let{topic:e,event:n,payload:r,ref:o,join_ref:i}=t;if(o&&o===this.pendingHeartbeatRef){const t=this.heartbeatSentAt?Date.now()-this.heartbeatSentAt:void 0;this.clearHeartbeats();try{this.heartbeatCallback("ok"===r.status?"ok":"error",t)}catch(t){this.log("error","error in heartbeat callback",t)}this.pendingHeartbeatRef=null,this.heartbeatSentAt=null,this.autoSendHeartbeat&&(this.heartbeatTimer=setTimeout(()=>this.sendHeartbeat(),this.heartbeatIntervalMs))}this.hasLogger()&&this.log("receive",`${r.status||""} ${e} ${n} ${o&&"("+o+")"||""}`.trim(),r);for(let t=0;t<this.channels.length;t++){const s=this.channels[t];s.isMember(e,n,r,i)&&s.trigger(n,r,o,i)}this.triggerStateCallbacks("message",t)})}triggerStateCallbacks(t,...e){try{this.stateChangeCallbacks[t].forEach(([n,r])=>{try{r(...e)}catch(e){this.log("error",`error in ${t} callback`,e)}})}catch(e){this.log("error",`error triggering ${t} callbacks`,e)}}leaveOpenTopic(t){let e=this.channels.find(e=>e.topic===t&&(e.isJoined()||e.isJoining()));e&&(this.hasLogger()&&this.log("transport",`leaving duplicate topic "${t}"`),e.leave())}},Ls=function(){function t(e,n){var r=function(t){return(null==t?void 0:t.events)&&{events:t.events}}(n);this.presence=new Ns(e.getChannel(),r),this.presence.onJoin(function(n,r,o){var i=t.onJoinPayload(n,r,o);e.getChannel().trigger("presence",i)}),this.presence.onLeave(function(n,r,o){var i=t.onLeavePayload(n,r,o);e.getChannel().trigger("presence",i)}),this.presence.onSync(function(){e.getChannel().trigger("presence",{event:"sync"})})}return Object.defineProperty(t.prototype,"state",{get:function(){return t.transformState(this.presence.state)},enumerable:!1,configurable:!0}),t.transformState=function(t){return t=function(t){return JSON.parse(JSON.stringify(t))}(t),Object.getOwnPropertyNames(t).reduce(function(e,n){var r=t[n];return e[n]=js(r),e},{})},t.onJoinPayload=function(t,e,n){return{event:"join",key:t,currentPresences:qs(e),newPresences:js(n)}},t.onLeavePayload=function(t,e,n){return{event:"leave",key:t,currentPresences:qs(e),leftPresences:js(n)}},t}();const Ds=Ls;function js(t){return t.metas.map(function(t){var e=Object.getOwnPropertyDescriptors(t),n=Object.defineProperties({},e);return n.presence_ref=n.phx_ref,delete n.phx_ref,delete n.phx_ref_prev,n})}function qs(t){return(null==t?void 0:t.metas)?js(t):[]}var Ms;!function(t){t.SYNC="sync",t.JOIN="join",t.LEAVE="leave"}(Ms||(Ms={}));const Bs=function(){function t(t,e){this.channel=t,this.presenceAdapter=new Ds(this.channel.channelAdapter,e)}return Object.defineProperty(t.prototype,"state",{get:function(){return this.presenceAdapter.state},enumerable:!1,configurable:!0}),t}();var Ws=function(){return Ws=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ws.apply(this,arguments)};const Fs=function(){function t(t,e,n){var r={config:Ws({broadcast:{ack:!1,self:!1},presence:{key:"",enabled:!1},private:!1},n.config)};this.channel=t.getSocket().channel(e,r),this.socket=t}return Object.defineProperty(t.prototype,"state",{get:function(){return this.channel.state},set:function(t){this.channel.state=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"joinedOnce",{get:function(){return this.channel.joinedOnce},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"joinPush",{get:function(){return this.channel.joinPush},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rejoinTimer",{get:function(){return this.channel.rejoinTimer},enumerable:!1,configurable:!0}),t.prototype.on=function(t,e){return this.channel.on(t,e)},t.prototype.off=function(t,e){this.channel.off(t,e)},t.prototype.subscribe=function(t){return this.channel.join(t)},t.prototype.unsubscribe=function(t){return this.channel.leave(t)},t.prototype.teardown=function(){this.channel.teardown()},t.prototype.detachLifecycleHooks=function(){this.channel.off(zi),this.channel.off($i)},t.prototype.onClose=function(t){this.channel.onClose(t)},t.prototype.onError=function(t){return this.channel.onError(t)},t.prototype.push=function(t,e,n){var r;try{r=this.channel.push(t,e,n)}catch(e){throw new Error("tried to push '".concat(t,"' to '").concat(this.channel.topic,"' before joining. Use channel.subscribe() before pushing events"))}if(this.channel.pushBuffer.length>100){var o=this.channel.pushBuffer.shift();o.cancelTimeout(),this.socket.log("channel","discarded push due to buffer overflow: ".concat(o.event),o.payload())}return r},t.prototype.updateJoinPayload=function(t){var e=this.channel.joinPush.payload();this.channel.joinPush.payload=function(){return Ws(Ws({},e),t)}},t.prototype.canPush=function(){return this.socket.isConnected()&&this.state===Ji},t.prototype.isJoined=function(){return this.state===Ji},t.prototype.isJoining=function(){return"joining"===this.state},t.prototype.isClosed=function(){return"closed"===this.state},t.prototype.isLeaving=function(){return"leaving"===this.state},t.prototype.updateFilterBindings=function(t){this.channel.filterBindings=t},t.prototype.updatePayloadTransform=function(t){this.channel.onMessage=t},t.prototype.getChannel=function(){return this.channel},t}();var Hs,Vs,Gs,Ks=/[,()"\\]/,Js=function(t){var e=null===t?"null":String(t);return function(t){return Ks.test(t)||t!==t.trim()}(e)?function(t){return'"'.concat(t.replace(/\\/g,"\\\\").replace(/"/g,'\\"'),'"')}(e):e},zs=function(){function t(){this.filters=[]}return t.prototype.add=function(t,e,n,r){void 0===r&&(r=!1);var o=r?"not.":"";return this.filters.push("".concat(t,"=").concat(o).concat(function(t,e){if("in"===t){var n=Array.isArray(e)?e:[e];if(0===n.length)throw new Error("Realtime `in` filter requires at least one value.");var r=Array.from(new Set(n)).map(function(t){return Js(t)}).join(",");return"in.(".concat(r,")")}return"is"===t?"is.".concat(function(t){return null===t?"null":String(t)}(e)):"".concat(t,".").concat(Js(e))}(e,n))),this},t.prototype.eq=function(t,e){return this.add(t,"eq",e)},t.prototype.neq=function(t,e){return this.add(t,"neq",e)},t.prototype.gt=function(t,e){return this.add(t,"gt",e)},t.prototype.gte=function(t,e){return this.add(t,"gte",e)},t.prototype.lt=function(t,e){return this.add(t,"lt",e)},t.prototype.lte=function(t,e){return this.add(t,"lte",e)},t.prototype.in=function(t,e){return this.add(t,"in",e)},t.prototype.like=function(t,e){return this.add(t,"like",e)},t.prototype.ilike=function(t,e){return this.add(t,"ilike",e)},t.prototype.match=function(t,e){return this.add(t,"match",e)},t.prototype.imatch=function(t,e){return this.add(t,"imatch",e)},t.prototype.is=function(t,e){return this.add(t,"is",e)},t.prototype.isDistinct=function(t,e){return this.add(t,"isdistinct",e)},t.prototype.not=function(t,e,n){return this.add(t,e,n,!0)},t.prototype.build=function(){return this.filters.join(",")},t.prototype.toString=function(){return this.build()},t}(),$s=function(){return $s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},$s.apply(this,arguments)},Ys=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Qs=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(t){t.ALL="*",t.INSERT="INSERT",t.UPDATE="UPDATE",t.DELETE="DELETE"}(Hs||(Hs={})),function(t){t.BROADCAST="broadcast",t.PRESENCE="presence",t.POSTGRES_CHANGES="postgres_changes",t.SYSTEM="system"}(Vs||(Vs={})),function(t){t.SUBSCRIBED="SUBSCRIBED",t.TIMED_OUT="TIMED_OUT",t.CLOSED="CLOSED",t.CHANNEL_ERROR="CHANNEL_ERROR"}(Gs||(Gs={}));var Xs=function(){function t(t,e,n){void 0===e&&(e={config:{}});var r,o,i=this;if(this.topic=t,this.params=e,this.socket=n,this.bindings={},this.subTopic=t.replace(/^realtime:/i,""),this.params.config=$s({broadcast:{ack:!1,self:!1},presence:{key:"",enabled:!1},private:!1},e.config),this.channelAdapter=new Fs(this.socket.socketAdapter,t,this.params),this.presence=new Bs(this),this._onClose(function(){i.socket._remove(i)}),this._updateFilterTransform(),this.private=this.params.config.private||!1,!this.private&&(null===(o=null===(r=this.params.config)||void 0===r?void 0:r.broadcast)||void 0===o?void 0:o.replay))throw new Error("tried to use replay on public channel '".concat(this.topic,"'. It must be a private channel."))}return Object.defineProperty(t.prototype,"state",{get:function(){return this.channelAdapter.state},set:function(t){this.channelAdapter.state=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"joinedOnce",{get:function(){return this.channelAdapter.joinedOnce},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"timeout",{get:function(){return this.socket.timeout},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"broadcastEndpointURL",{get:function(){return hs(this.socket.socketAdapter.endPointURL())},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"joinPush",{get:function(){return this.channelAdapter.joinPush},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rejoinTimer",{get:function(){return this.channelAdapter.rejoinTimer},enumerable:!1,configurable:!0}),t.prototype.subscribe=function(t,e){var n,r,o,i;if(void 0===e&&(e=this.timeout),this.socket.isConnected()||this.socket.connect(),this.channelAdapter.isClosed()){var s=this.params.config,a=s.broadcast,c=s.presence,u=s.private,l=s.postgres_changes_options,h=null!==(r=null===(n=this.bindings.postgres_changes)||void 0===n?void 0:n.map(function(t){return t.filter}))&&void 0!==r?r:[],d=!!this.bindings[Vs.PRESENCE]&&this.bindings[Vs.PRESENCE].length>0||!0===(null===(o=this.params.config.presence)||void 0===o?void 0:o.enabled),f=$s({broadcast:a,presence:$s($s({},c),{enabled:d}),postgres_changes:h,private:u},l?{postgres_changes_options:l}:{});this._subscribeCallback=t,this._subscribeTimeout=e,this._bindSubscribeLifecycle(),this.updateJoinPayload({config:f}),this._updateFilterMessage();var p=(null==l?void 0:l.wait)&&h.length>0?Math.max(e,(null!==(i=l.timeout)&&void 0!==i?i:15e3)+1e4):e;this._subscribeJoinTimeout=p,this.channelAdapter.subscribe(p),this._bindJoinPushReceivers()}return this},t.prototype._warmupOn=function(t){var e=this,n=new Fs(t,this.topic,this.params);return n.updateJoinPayload(this.channelAdapter.joinPush.payload()),new Promise(function(t,r){var o,i;n.subscribe(null!==(i=null!==(o=e._subscribeJoinTimeout)&&void 0!==o?o:e._subscribeTimeout)&&void 0!==i?i:e.timeout).receive("ok",function(o){var i=o.postgres_changes;void 0===i||e._postgresBindingsAlign(i)?t({adapter:n,postgres_changes:i}):r(new Error("mismatch between server and client bindings for postgres changes"))}).receive("error",function(t){var e=Object.values(t).join(", ")||"error";r(new Error(e,{cause:t}))}).receive("timeout",function(){r(new Error("standby channel join timed out"))})})},t.prototype._adopt=function(t){var e=this,n=this.channelAdapter;n.detachLifecycleHooks(),n.teardown(),this.channelAdapter=t.adapter;for(var r=0,o=Object.keys(this.bindings);r<o.length;r++)for(var i=o[r],s=0,a=this.bindings[i];s<a.length;s++){var c=a[s];c.ref=this.channelAdapter.on(c.type,c.callback)}this._updateFilterMessage(),this._updateFilterTransform(),void 0!==t.postgres_changes&&this._applyPostgresBindingIds(t.postgres_changes),this._onClose(function(){e.socket._remove(e)}),this._bindSubscribeLifecycle(),this._bindJoinPushReceivers({skipImmediate:!0}),this.presence=new Bs(this)},t.prototype._bindSubscribeLifecycle=function(){if(this._subscribeCallback){var t=this._subscribeCallback;this._onError(function(e){t(Gs.CHANNEL_ERROR,function(t){if(t instanceof Error)return t;if("string"==typeof t)return new Error(t);if(t&&"object"==typeof t){var e=t;if("number"==typeof e.code){var n="string"==typeof e.reason&&e.reason?" (".concat(e.reason,")"):"";return new Error("socket closed: ".concat(e.code).concat(n),{cause:t})}return new Error("channel error: transport failure",{cause:t})}return new Error("channel error: connection lost")}(e))}),this._onClose(function(){return t(Gs.CLOSED)})}},t.prototype._bindJoinPushReceivers=function(t){var e,n=this,r=function(t){var e=t.postgres_changes;return Ys(n,void 0,void 0,function(){var t;return Qs(this,function(n){return this.socket._isManualToken()||this.socket.setAuth(),void 0===e?(null===(t=this._subscribeCallback)||void 0===t||t.call(this,Gs.SUBSCRIBED),[2]):(this._updatePostgresBindings(e,this._subscribeCallback),[2])})})},o=function(t){var e;n.state=Ki;var r=Object.values(t).join(", ")||"error";null===(e=n._subscribeCallback)||void 0===e||e.call(n,Gs.CHANNEL_ERROR,new Error(r,{cause:t}))},i=function(){var t;null===(t=n._subscribeCallback)||void 0===t||t.call(n,Gs.TIMED_OUT)},s=this.channelAdapter.joinPush;if((null==t?void 0:t.skipImmediate)&&"ok"===(null===(e=s.receivedResp)||void 0===e?void 0:e.status))return s.recHooks.push({status:"ok",callback:r}),s.recHooks.push({status:"error",callback:o}),void s.recHooks.push({status:"timeout",callback:i});this.channelAdapter.joinPush.receive("ok",r),this.channelAdapter.joinPush.receive("error",o),this.channelAdapter.joinPush.receive("timeout",i)},t.prototype._postgresBindingsAlign=function(e){for(var n,r=this.bindings.postgres_changes,o=null!==(n=null==r?void 0:r.length)&&void 0!==n?n:0,i=0;i<o;i++){var s=r[i].filter,a=s.event,c=s.schema,u=s.table,l=s.filter,h=e&&e[i];if(!(h&&h.event===a&&t.isFilterValueEqual(h.schema,c)&&t.isFilterValueEqual(h.table,u)&&t.isFilterValueEqual(h.filter,l)))return!1}return!0},t.prototype._applyPostgresBindingIds=function(t){for(var e,n=this.bindings.postgres_changes,r=null!==(e=null==n?void 0:n.length)&&void 0!==e?e:0,o=[],i=0;i<r;i++){var s=n[i],a=t&&t[i];o.push($s($s({},s),{id:null==a?void 0:a.id}))}this.bindings.postgres_changes=o},t.prototype._updatePostgresBindings=function(t,e){if(!this._postgresBindingsAlign(t))return this.unsubscribe(),this.state=Ki,void(null==e||e(Gs.CHANNEL_ERROR,new Error("mismatch between server and client bindings for postgres changes")));this._applyPostgresBindingIds(t),this.state!=Ki&&e&&e(Gs.SUBSCRIBED)},t.prototype.presenceState=function(){return this.presence.state},t.prototype.track=function(t,e){return void 0===e&&(e={}),Ys(this,void 0,Promise,function(){return Qs(this,function(n){switch(n.label){case 0:return[4,this.send({type:"presence",event:"track",payload:t},e)];case 1:return[2,n.sent()]}})})},t.prototype.untrack=function(t){return void 0===t&&(t={}),Ys(this,void 0,Promise,function(){return Qs(this,function(e){switch(e.label){case 0:return[4,this.send({type:"presence",event:"untrack"},t)];case 1:return[2,e.sent()]}})})},t.prototype.on=function(t,e,n){var r=this.channelAdapter.isJoined()||this.channelAdapter.isJoining(),o=t===Vs.PRESENCE||t===Vs.POSTGRES_CHANGES;if(r&&o)throw this.socket.log("channel","cannot add `".concat(t,"` callbacks for ").concat(this.topic," after `subscribe()`.")),new Error("cannot add `".concat(t,"` callbacks for ").concat(this.topic," after `subscribe()`."));return this._on(t,e,n)},t.prototype.httpSend=function(t,e,n){var r;return void 0===n&&(n={}),Ys(this,void 0,Promise,function(){var o,i,s,a,c,u,l;return Qs(this,function(h){switch(h.label){case 0:return null==e?[2,Promise.reject(new Error("Payload is required for httpSend()"))]:[4,this.socket.setAuth()];case 1:return h.sent(),o=e instanceof ArrayBuffer||ArrayBuffer.isView(e),i={apikey:this.socket.apiKey?this.socket.apiKey:"","Content-Type":o?"application/octet-stream":"application/json"},this.socket.accessTokenValue&&(i.Authorization="Bearer ".concat(this.socket.accessTokenValue)),s=function(t,e,n,r){var o=ls(t),i=o.base,s=o.query,a=o.hash,c="/".concat(encodeURIComponent(e),"/events/").concat(encodeURIComponent(n)),u=i.replace(/\/+$/,"")+c,l=[];if(s.startsWith("?")&&s.length>1&&l.push(s.slice(1)),r)for(var h=0,d=Object.entries(r);h<d.length;h++){var f=d[h],p=f[0],v=f[1];l.push("".concat(encodeURIComponent(p),"=").concat(encodeURIComponent(v)))}return u+(l.length?"?".concat(l.join("&")):"")+a}(this.broadcastEndpointURL,this.subTopic,t,this.private?{private:"true"}:void 0),a={method:"POST",headers:i,body:o?e:JSON.stringify(e)},[4,this._fetchWithTimeout(s,a,null!==(r=n.timeout)&&void 0!==r?r:this.timeout)];case 2:if(202===(c=h.sent()).status)return[2,{success:!0}];if(404===c.status)return[2,Promise.reject(new Error("httpSend() requires Realtime server v2.97.0 or newer; the endpoint returned 404. Update your Supabase CLI to a recent version, or upgrade the Realtime server in your self-hosted setup. See https://github.com/TencentCloudBase/cloudbase-js-sdk/blob/master/packages/realtime-js/migrations/httpsend-server-version.md"))];u=c.statusText,h.label=3;case 3:return h.trys.push([3,5,,6]),[4,c.json()];case 4:return l=h.sent(),u=l.error||l.message||u,[3,6];case 5:return h.sent(),[3,6];case 6:return[2,Promise.reject(new Error(u))]}})})},t.prototype.send=function(t,e){var n,r;return void 0===e&&(e={}),Ys(this,void 0,Promise,function(){var o,i,s,a,c,u,l,h=this;return Qs(this,function(d){switch(d.label){case 0:return this.channelAdapter.canPush()||"broadcast"!==t.type?[3,7]:(o="Realtime send() is automatically falling back to REST API. This behavior will be deprecated in the future. Please use httpSend() explicitly for REST delivery.",this.socket.hasLogger()?this.socket.log("channel",o):console.warn(o),i=t.event,s=t.payload,[4,this.socket.setAuth()]);case 1:d.sent(),a={apikey:this.socket.apiKey?this.socket.apiKey:"","Content-Type":"application/json"},this.socket.accessTokenValue&&(a.Authorization="Bearer ".concat(this.socket.accessTokenValue)),c={method:"POST",headers:a,body:JSON.stringify({messages:[{topic:this.subTopic,event:i,payload:s,private:this.private}]})},d.label=2;case 2:return d.trys.push([2,5,,6]),[4,this._fetchWithTimeout(this.broadcastEndpointURL,c,null!==(n=e.timeout)&&void 0!==n?n:this.timeout)];case 3:return u=d.sent(),[4,null===(r=u.body)||void 0===r?void 0:r.cancel()];case 4:return d.sent(),[2,u.ok?"ok":"error"];case 5:return(l=d.sent())instanceof Error&&"AbortError"===l.name?[2,"timed out"]:[2,"error"];case 6:return[3,8];case 7:return[2,new Promise(function(n){var r,o,i,s=h.channelAdapter.push(t.type,t,e.timeout||h.timeout);"broadcast"!==t.type||(null===(i=null===(o=null===(r=h.params)||void 0===r?void 0:r.config)||void 0===o?void 0:o.broadcast)||void 0===i?void 0:i.ack)||n("ok"),s.receive("ok",function(){return n("ok")}),s.receive("error",function(){return n("error")}),s.receive("timeout",function(){return n("timed out")})})];case 8:return[2]}})})},t.prototype.updateJoinPayload=function(t){this.channelAdapter.updateJoinPayload(t)},t.prototype.unsubscribe=function(t){return void 0===t&&(t=this.timeout),Ys(this,void 0,void 0,function(){var e=this;return Qs(this,function(n){return[2,new Promise(function(n){e.channelAdapter.unsubscribe(t).receive("ok",function(){return n("ok")}).receive("timeout",function(){return n("timed out")}).receive("error",function(){return n("error")})})]})})},t.prototype.teardown=function(){this.channelAdapter.teardown()},t.prototype._fetchWithTimeout=function(t,e,n){return Ys(this,void 0,void 0,function(){var r,o,i,s;return Qs(this,function(a){switch(a.label){case 0:if(r=function(){var t=new Error("The operation was aborted");return t.name="AbortError",t},"undefined"!=typeof AbortController)return[3,4];a.label=1;case 1:return a.trys.push([1,,3,4]),[4,Promise.race([this.socket.fetch(t,e),new Promise(function(t,e){o=setTimeout(function(){return e(r())},n)})])];case 2:return[2,a.sent()];case 3:return o&&clearTimeout(o),[7];case 4:i=new AbortController,s=setTimeout(function(){return i.abort()},n),a.label=5;case 5:return a.trys.push([5,,7,8]),[4,this.socket.fetch(t,$s($s({},e),{signal:i.signal}))];case 6:return[2,a.sent()];case 7:return clearTimeout(s),[7];case 8:return[2]}})})},t.prototype._on=function(e,n,r){var o,i=e.toLocaleLowerCase(),s=null==n?void 0:n.filter;if((s instanceof zs||"object"==typeof s&&null!==s&&"function"==typeof s.build)&&(n=$s($s({},n),{filter:s.build()})),i===Vs.POSTGRES_CHANGES&&(null===(o=this.bindings[i])||void 0===o?void 0:o.find(function(e){return t.isSamePostgresFilter(e.filter,n)})))return this.socket.log("error","duplicate `postgres_changes` binding for ".concat(this.topic," ignored"),n),this;var a=this.channelAdapter.on(e,r),c={type:i,filter:n,callback:r,ref:a};return this.bindings[i]?this.bindings[i].push(c):this.bindings[i]=[c],this._updateFilterMessage(),this},t.prototype._onClose=function(t){this.channelAdapter.onClose(t)},t.prototype._onError=function(t){this.channelAdapter.onError(t)},t.prototype._updateFilterMessage=function(){var t=this;this.channelAdapter.updateFilterBindings(function(e,n,r){var o,i,s,a,c,u,l,h=e.event.toLocaleLowerCase();if(t._notThisChannelEvent(h,r))return!1;var d=null===(o=t.bindings[h])||void 0===o?void 0:o.find(function(t){return t.ref===e.ref});if(!d)return!0;if(["broadcast","presence","postgres_changes"].includes(h)){if("id"in d){var f=d.id,p=null===(i=d.filter)||void 0===i?void 0:i.event;return f&&(null===(s=n.ids)||void 0===s?void 0:s.includes(f))&&("*"===p||(null==p?void 0:p.toLocaleLowerCase())===(null===(a=n.data)||void 0===a?void 0:a.type.toLocaleLowerCase()))}return"*"===(p=null===(u=null===(c=null==d?void 0:d.filter)||void 0===c?void 0:c.event)||void 0===u?void 0:u.toLocaleLowerCase())||p===(null===(l=null==n?void 0:n.event)||void 0===l?void 0:l.toLocaleLowerCase())}return d.type.toLocaleLowerCase()===h})},t.prototype._notThisChannelEvent=function(t,e){return e&&[zi,$i,Qi,Yi].includes(t)&&e!==this.joinPush.ref},t.prototype._updateFilterTransform=function(){var t=this;this.channelAdapter.updatePayloadTransform(function(e,n,r){if("object"==typeof n&&"ids"in n){var o=n.data,i=o.schema,s=o.table,a=o.commit_timestamp,c=o.type,u=o.errors;return $s($s({},{schema:i,table:s,commit_timestamp:a,eventType:c,new:{},old:{},errors:u}),t._getPayloadRecords(o))}return n})},t.prototype.copyBindings=function(t){if(this.joinedOnce)throw new Error("cannot copy bindings into joined channel");for(var e in t.bindings)for(var n=0,r=t.bindings[e];n<r.length;n++){var o=r[n];this._on(o.type,o.filter,o.callback)}},t.isFilterValueEqual=function(t,e){return(null!=t?t:void 0)===(null!=e?e:void 0)},t.isSamePostgresFilter=function(e,n){var r,o,i,s,a=null!==(o=null===(r=null==e?void 0:e.select)||void 0===r?void 0:r.join())&&void 0!==o?o:void 0,c=null!==(s=null===(i=null==n?void 0:n.select)||void 0===i?void 0:i.join())&&void 0!==s?s:void 0;return(null==e?void 0:e.event)===(null==n?void 0:n.event)&&t.isFilterValueEqual(null==e?void 0:e.schema,null==n?void 0:n.schema)&&t.isFilterValueEqual(null==e?void 0:e.table,null==n?void 0:n.table)&&t.isFilterValueEqual(null==e?void 0:e.filter,null==n?void 0:n.filter)&&a===c},t.prototype._getPayloadRecords=function(t){var e={new:{},old:{}};return"INSERT"!==t.type&&"UPDATE"!==t.type||(e.new=es(t.columns,t.record)),"UPDATE"!==t.type&&"DELETE"!==t.type||(e.old=es(t.columns,t.old_record)),e},t}();const Zs=Xs,ta=function(){function t(t,e){this.socket=new Us(t,e)}return Object.defineProperty(t.prototype,"timeout",{get:function(){return this.socket.timeout},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"endPoint",{get:function(){return this.socket.endPoint},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transport",{get:function(){return this.socket.transport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatIntervalMs",{get:function(){return this.socket.heartbeatIntervalMs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatCallback",{get:function(){return this.socket.heartbeatCallback},set:function(t){this.socket.heartbeatCallback=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatTimer",{get:function(){return this.socket.heartbeatTimer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"pendingHeartbeatRef",{get:function(){return this.socket.pendingHeartbeatRef},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"reconnectTimer",{get:function(){return this.socket.reconnectTimer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vsn",{get:function(){return this.socket.vsn},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"encode",{get:function(){return this.socket.encode},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"decode",{get:function(){return this.socket.decode},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"reconnectAfterMs",{get:function(){return this.socket.reconnectAfterMs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sendBuffer",{get:function(){return this.socket.sendBuffer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"stateChangeCallbacks",{get:function(){return this.socket.stateChangeCallbacks},enumerable:!1,configurable:!0}),t.prototype.connect=function(){this.socket.connect()},t.prototype.disconnect=function(t,e,n,r){var o=this;return void 0===r&&(r=1e4),new Promise(function(i){setTimeout(function(){return i("timeout")},r),o.socket.disconnect(function(){t(),i("ok")},e,n)})},t.prototype.push=function(t){this.socket.push(t)},t.prototype.log=function(t,e,n){this.socket.log(t,e,n)},t.prototype.hasLogger=function(){return this.socket.hasLogger()},t.prototype.makeRef=function(){return this.socket.makeRef()},t.prototype.onOpen=function(t){this.socket.onOpen(t)},t.prototype.onClose=function(t){this.socket.onClose(t)},t.prototype.onError=function(t){this.socket.onError(t)},t.prototype.onMessage=function(t){this.socket.onMessage(t)},t.prototype.isConnected=function(){return this.socket.isConnected()},t.prototype.isConnecting=function(){return"connecting"==this.socket.connectionState()},t.prototype.isDisconnecting=function(){return"closing"==this.socket.connectionState()},t.prototype.connectionState=function(){return this.socket.connectionState()},t.prototype.endPointURL=function(){return this.socket.endPointURL()},t.prototype.sendHeartbeat=function(){this.socket.sendHeartbeat()},t.prototype.getSocket=function(){return this.socket},t}();var ea=function(){return ea=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ea.apply(this,arguments)},na=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},ra=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},oa=[1e3,2e3,5e3,1e4];var ia=function(){function t(t,e){var n;if(this.channels=new Array,this.accessTokenValue=null,this.accessToken=null,this.apiKey=null,this.httpEndpoint="",this.headers={},this.params={},this.ref=0,this.serializer=new Zi,this._manuallySetToken=!1,this._authPromise=null,this._authGeneration=0,this._workerHeartbeatTimer=void 0,this._pendingWorkerHeartbeatRef=null,this._pendingDisconnectTimer=null,this._disconnectOnEmptyChannelsAfterMs=0,this._endPoint="",this._socketOptions={},this._openingActive=!1,this._handlersAdapter=null,this._standbyAdapter=null,this._rotating=!1,this._cutoverStarted=!1,this._refreshTimer=null,this._rotateRetryTimer=null,this.connectionMaxAgeMs=0,this.connectionRefreshJitterMs=2e4,this._resolveFetch=function(t){return t?function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t.apply(void 0,e)}:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if("undefined"==typeof fetch)throw new Error("httpSend() requires a fetch implementation. Pass options.fetch, or use app.realtime() after registering a platform adapter that provides reqClass.");return fetch.apply(void 0,t)}},!(null===(n=null==e?void 0:e.params)||void 0===n?void 0:n.apikey))throw new Error("API key is required to connect to Realtime");this.apiKey=e.params.apikey;var r=this._initializeOptions(e);this._endPoint=t,this._socketOptions=r,this.socketAdapter=this._createSocketAdapter(),this.httpEndpoint=hs(t),this.fetch=this._resolveFetch(null==e?void 0:e.fetch)}return Object.defineProperty(t.prototype,"endPoint",{get:function(){return this.socketAdapter.endPoint},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"timeout",{get:function(){return this.socketAdapter.timeout},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transport",{get:function(){return this.socketAdapter.transport},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatCallback",{get:function(){return this.socketAdapter.heartbeatCallback},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatIntervalMs",{get:function(){return this.socketAdapter.heartbeatIntervalMs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"heartbeatTimer",{get:function(){return this.worker?this._workerHeartbeatTimer:this.socketAdapter.heartbeatTimer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"pendingHeartbeatRef",{get:function(){return this.worker?this._pendingWorkerHeartbeatRef:this.socketAdapter.pendingHeartbeatRef},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"reconnectTimer",{get:function(){return this.socketAdapter.reconnectTimer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"vsn",{get:function(){return this.socketAdapter.vsn},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"encode",{get:function(){return this.socketAdapter.encode},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"decode",{get:function(){return this.socketAdapter.decode},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"reconnectAfterMs",{get:function(){return this.socketAdapter.reconnectAfterMs},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sendBuffer",{get:function(){return this.socketAdapter.sendBuffer},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"stateChangeCallbacks",{get:function(){return this.socketAdapter.stateChangeCallbacks},enumerable:!1,configurable:!0}),t.prototype.connect=function(){var t=this;if(!(this.isConnecting()||this.isDisconnecting()||this.isConnected()||this._openingActive)){if(this.accessToken&&!this._authPromise&&this._setAuthSafely("connect"),this._beforeTransportConnect)return this._openingActive=!0,void this._openActiveSocket().catch(function(e){t.log("error","failed to open socket",e)});this._setupConnectionHandlers();try{this.socketAdapter.connect()}catch(t){var e=t.message;throw new Error("WebSocket not available: ".concat(e))}this._handleNodeJsRaceCondition()}},t.prototype.endpointURL=function(){return this.socketAdapter.endPointURL()},t.prototype.disconnect=function(t,e){return na(this,void 0,void 0,function(){var n,r,o=this;return ra(this,function(i){switch(i.label){case 0:return this._cancelPendingDisconnect(),this._cancelConnectionRefresh(),this._cancelRotateRetry(),this._rotating=!1,this._cutoverStarted=!1,n=this._standbyAdapter,this._standbyAdapter=null,this.isDisconnecting()?n?[4,n.disconnect(function(){},1e3,"connection refresh abort")]:[3,2]:[3,3];case 1:i.sent(),i.label=2;case 2:return[2,"ok"];case 3:return[4,this.socketAdapter.disconnect(function(){clearInterval(o._workerHeartbeatTimer),o._terminateWorker()},t,e)];case 4:return r=i.sent(),n?[4,n.disconnect(function(){},1e3,"connection refresh abort")]:[3,6];case 5:i.sent(),i.label=6;case 6:return[2,r]}})})},t.prototype.getChannels=function(){return this.channels},t.prototype.removeChannel=function(t){return na(this,void 0,Promise,function(){var e;return ra(this,function(n){switch(n.label){case 0:return[4,t.unsubscribe()];case 1:return"ok"===(e=n.sent())&&t.teardown(),[2,e]}})})},t.prototype.removeAllChannels=function(){return na(this,void 0,Promise,function(){var t,e,n=this;return ra(this,function(r){switch(r.label){case 0:return t=this.channels.map(function(t){return na(n,void 0,void 0,function(){var e;return ra(this,function(n){switch(n.label){case 0:return[4,t.unsubscribe()];case 1:return e=n.sent(),t.teardown(),[2,e]}})})}),[4,Promise.all(t)];case 1:return e=r.sent(),[4,this.disconnect()];case 2:return r.sent(),[2,e]}})})},t.prototype.log=function(t,e,n){this.socketAdapter.log(t,e,n)},t.prototype.hasLogger=function(){return this.socketAdapter.hasLogger()},t.prototype.connectionState=function(){return this.socketAdapter.connectionState()||"closed"},t.prototype.isConnected=function(){return this.socketAdapter.isConnected()},t.prototype.isConnecting=function(){return this.socketAdapter.isConnecting()},t.prototype.isDisconnecting=function(){return this.socketAdapter.isDisconnecting()},t.prototype.channel=function(t,e){void 0===e&&(e={config:{}});var n="realtime:".concat(t),r=this.getChannels().find(function(t){return t.topic===n});if(r)return r;var o=new Zs("realtime:".concat(t),e,this);return this._cancelPendingDisconnect(),this.channels.push(o),o},t.prototype.push=function(t){this.socketAdapter.push(t)},t.prototype.setAuth=function(t){return void 0===t&&(t=null),na(this,void 0,Promise,function(){var e,n;return ra(this,function(r){switch(r.label){case 0:e=++this._authGeneration,n=this._performAuth(t,e),e===this._authGeneration&&(this._authPromise=n),r.label=1;case 1:return r.trys.push([1,,3,4]),[4,n];case 2:return r.sent(),[3,4];case 3:return this._authPromise===n&&(this._authPromise=null),[7];case 4:return[2]}})})},t.prototype._isManualToken=function(){return this._manuallySetToken},t.prototype.sendHeartbeat=function(){return na(this,void 0,void 0,function(){return ra(this,function(t){return this.socketAdapter.sendHeartbeat(),[2]})})},t.prototype.onHeartbeat=function(t){this.socketAdapter.heartbeatCallback=this._wrapHeartbeatCallback(t)},t.prototype._makeRef=function(){return this.socketAdapter.makeRef()},t.prototype._remove=function(t){this.channels=this.channels.filter(function(e){return e.topic!==t.topic}),0===this.channels.length&&(this.log("transport","no channels remaining, scheduling disconnect"),this._cancelConnectionRefresh(),this._cancelRotateRetry(),this._abortRotate(),this._schedulePendingDisconnect())},t.prototype._schedulePendingDisconnect=function(){var t=this;if(this._cancelPendingDisconnect(),0===this._disconnectOnEmptyChannelsAfterMs)return this.log("transport","disconnecting immediately - no channels"),void this.disconnect();this._pendingDisconnectTimer=setTimeout(function(){t._pendingDisconnectTimer=null,0===t.channels.length&&(t.log("transport","deferred disconnect fired - no channels, disconnecting"),t.disconnect())},this._disconnectOnEmptyChannelsAfterMs),this.log("transport","deferred disconnect scheduled in ".concat(this._disconnectOnEmptyChannelsAfterMs,"ms"))},t.prototype._cancelPendingDisconnect=function(){null!==this._pendingDisconnectTimer&&(this.log("transport","pending disconnect cancelled - channel activity detected"),clearTimeout(this._pendingDisconnectTimer),this._pendingDisconnectTimer=null)},t.prototype._performAuth=function(t,e){return na(this,void 0,Promise,function(){var n,r,o;return ra(this,function(i){switch(i.label){case 0:return r=!1,t?(n=t,r=!0,[3,7]):[3,1];case 1:if(!this.accessToken)return[3,6];i.label=2;case 2:return i.trys.push([2,4,,5]),[4,this.accessToken()];case 3:return n=i.sent(),[3,5];case 4:return o=i.sent(),this.log("error","Error fetching access token from callback",o),n=this.accessTokenValue,[3,5];case 5:return[3,7];case 6:n=this.accessTokenValue,i.label=7;case 7:return e!==this._authGeneration||(this.accessToken?this._manuallySetToken=!1:r&&(this._manuallySetToken=!0),this.accessTokenValue!=n&&(this.accessTokenValue=n)),[2]}})})},t.prototype._waitForAuthIfNeeded=function(){return na(this,void 0,Promise,function(){return ra(this,function(t){switch(t.label){case 0:return this._authPromise?[4,this._authPromise]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})},t.prototype._setAuthSafely=function(t){var e=this;void 0===t&&(t="general"),this._isManualToken()||this.setAuth().catch(function(n){e.log("error","Error setting auth in ".concat(t),n)})},t.prototype._setupConnectionHandlers=function(){var t=this;if(this._handlersAdapter!==this.socketAdapter){this._handlersAdapter=this.socketAdapter;var e=this.socketAdapter;e.onOpen(function(){t.socketAdapter===e&&((t._authPromise||(t.accessToken&&!t.accessTokenValue?t.setAuth():Promise.resolve())).catch(function(e){t.log("error","error waiting for auth on connect",e)}),t.worker&&!t.workerRef&&t._startWorkerHeartbeat(),t._scheduleConnectionRefresh())}),e.onClose(function(){t.socketAdapter===e&&(t.worker&&t.workerRef&&t._terminateWorker(),t._rotating&&!t._cutoverStarted&&(t.log("transport","active socket closed during refresh, aborting standby"),t._abortRotate()),t._rotating||t._cancelConnectionRefresh())}),e.onMessage(function(n){t.socketAdapter===e&&n.ref&&n.ref===t._pendingWorkerHeartbeatRef&&(t._pendingWorkerHeartbeatRef=null)})}},t.prototype._handleNodeJsRaceCondition=function(){this.socketAdapter.isConnected()&&this.socketAdapter.getSocket().onConnOpen()},t.prototype._wrapHeartbeatCallback=function(t){var e=this;return function(n,r){"disconnected"!==n&&("sent"==n&&e._setAuthSafely(),t&&t(n,r))}},t.prototype._startWorkerHeartbeat=function(){var t=this;this.workerUrl?this.log("worker","starting worker for from ".concat(this.workerUrl)):this.log("worker","starting default worker");var e=this._workerObjectUrl(this.workerUrl);this.workerRef=new Worker(e),this.workerRef.onerror=function(e){t.log("worker","worker error",e.message),t._terminateWorker(),t.disconnect()},this.workerRef.onmessage=function(e){"keepAlive"===e.data.event&&t.sendHeartbeat()},this.workerRef.postMessage({event:"start",interval:this.heartbeatIntervalMs})},t.prototype._terminateWorker=function(){this.workerRef&&(this.log("worker","terminating worker"),this.workerRef.terminate(),this.workerRef=void 0)},t.prototype._workerObjectUrl=function(t){var e;if(t)e=t;else{var n=new Blob(['\n addEventListener("message", (e) => {\n if (e.data.event === "start") {\n setInterval(() => postMessage({ event: "keepAlive" }), e.data.interval);\n }\n });'],{type:"application/javascript"});e=URL.createObjectURL(n)}return e},t.prototype._initializeOptions=function(t){var e,n,r,o,i,s,a,c,u,l,h,d,f,p;this.worker=null!==(e=null==t?void 0:t.worker)&&void 0!==e&&e,this.accessToken=null!==(n=null==t?void 0:t.accessToken)&&void 0!==n?n:null,this.connectionMaxAgeMs=null!==(r=null==t?void 0:t.connectionMaxAgeMs)&&void 0!==r?r:0,this.connectionRefreshJitterMs=null!==(o=null==t?void 0:t.connectionRefreshJitterMs)&&void 0!==o?o:2e4,this._beforeTransportConnect=null==t?void 0:t.beforeTransportConnect;var v,y,g={};g.timeout=null!==(i=null==t?void 0:t.timeout)&&void 0!==i?i:1e4,g.heartbeatIntervalMs=null!==(s=null==t?void 0:t.heartbeatIntervalMs)&&void 0!==s?s:25e3,this._disconnectOnEmptyChannelsAfterMs=null!==(a=null==t?void 0:t.disconnectOnEmptyChannelsAfterMs)&&void 0!==a?a:2*(null!==(c=null==t?void 0:t.heartbeatIntervalMs)&&void 0!==c?c:25e3),g.transport=null!==(u=null==t?void 0:t.transport)&&void 0!==u?u:Fi.getWebSocketConstructor(),g.params=null==t?void 0:t.params,g.logger=null==t?void 0:t.logger,g.heartbeatCallback=this._wrapHeartbeatCallback(null==t?void 0:t.heartbeatCallback),g.sessionStorage=null!==(l=null==t?void 0:t.sessionStorage)&&void 0!==l?l:function(){try{if("undefined"!=typeof globalThis&&globalThis.sessionStorage)return globalThis.sessionStorage}catch(t){}return t=new Map,{get length(){return t.size},clear:function(){t.clear()},getItem:function(e){return t.has(e)?t.get(e):null},key:function(e){var n;return null!==(n=Array.from(t.keys())[e])&&void 0!==n?n:null},removeItem:function(e){t.delete(e)},setItem:function(e,n){t.set(e,String(n))}};var t}(),g.reconnectAfterMs=null!==(h=null==t?void 0:t.reconnectAfterMs)&&void 0!==h?h:function(t){return oa[t-1]||1e4};var m=null!==(d=null==t?void 0:t.vsn)&&void 0!==d?d:Gi;switch(m){case Hi:v=function(t,e){return e(JSON.stringify(t))},y=function(t,e){return e(JSON.parse(t))};break;case Vi:v=this.serializer.encode.bind(this.serializer),y=this.serializer.decode.bind(this.serializer);break;default:throw new Error("Unsupported serializer version: ".concat(g.vsn))}if(g.vsn=m,g.encode=null!==(f=null==t?void 0:t.encode)&&void 0!==f?f:v,g.decode=null!==(p=null==t?void 0:t.decode)&&void 0!==p?p:y,g.beforeReconnect=this._reconnectAuth.bind(this),((null==t?void 0:t.logLevel)||(null==t?void 0:t.log_level))&&(this.logLevel=t.logLevel||t.log_level,g.params=ea(ea({},g.params),{log_level:this.logLevel})),this.worker){if("undefined"!=typeof window&&!window.Worker)throw new Error("Web Worker is not supported");this.workerUrl=null==t?void 0:t.workerUrl,g.autoSendHeartbeat=!this.worker}return g},t.prototype._reconnectAuth=function(){return na(this,void 0,void 0,function(){return ra(this,function(t){switch(t.label){case 0:return[4,this._waitForAuthIfNeeded()];case 1:return t.sent(),this.isConnected()||this.connect(),[2]}})})},t.prototype._createSocketAdapter=function(){return new ta(this._endPoint,this._socketOptions)},t.prototype._openActiveSocket=function(){return na(this,void 0,void 0,function(){var t,e;return ra(this,function(n){switch(n.label){case 0:return n.trys.push([0,3,4,5]),this._beforeTransportConnect?[4,this._beforeTransportConnect()]:[3,2];case 1:n.sent(),n.label=2;case 2:return this.isConnecting()||this.isDisconnecting()||this.isConnected()?[2]:(this._setupConnectionHandlers(),this.socketAdapter.connect(),this._handleNodeJsRaceCondition(),[3,5]);case 3:throw t=n.sent(),e=t.message,new Error("WebSocket not available: ".concat(e));case 4:return this._openingActive=!1,[7];case 5:return[2]}})})},t.prototype._scheduleConnectionRefresh=function(){var t=this;if(this._cancelConnectionRefresh(),!(this.connectionMaxAgeMs<=0)){var e=this.connectionRefreshJitterMs>0?Math.floor(Math.random()*this.connectionRefreshJitterMs):0,n=this.connectionMaxAgeMs+e;this._refreshTimer=setTimeout(function(){t._refreshTimer=null,t._rotateConnection()},n),this.log("transport","connection refresh scheduled in ".concat(n,"ms"))}},t.prototype._cancelConnectionRefresh=function(){null!==this._refreshTimer&&(clearTimeout(this._refreshTimer),this._refreshTimer=null)},t.prototype._scheduleRotateRetry=function(){var t=this;this._cancelRotateRetry(),this._rotateRetryTimer=setTimeout(function(){t._rotateRetryTimer=null,t.isConnected()&&!t._rotating&&t._rotateConnection()},1e4),this.log("transport","connection refresh retry scheduled in ".concat(1e4,"ms"))},t.prototype._cancelRotateRetry=function(){null!==this._rotateRetryTimer&&(clearTimeout(this._rotateRetryTimer),this._rotateRetryTimer=null)},t.prototype._rotateConnection=function(){return na(this,void 0,void 0,function(){var t,e,n,r;return ra(this,function(o){switch(o.label){case 0:if(this._rotating||!this.isConnected()||0===this.channels.length)return[2];this._rotating=!0,this._cutoverStarted=!1,this._cancelConnectionRefresh(),this.log("transport","starting connection refresh"),o.label=1;case 1:return o.trys.push([1,6,,8]),this._beforeTransportConnect?[4,this._beforeTransportConnect()]:[3,3];case 2:o.sent(),o.label=3;case 3:if(!this.isConnected()||0===this.channels.length)throw new Error("active connection lost before standby connect");return t=this._createSocketAdapter(),this._standbyAdapter=t,[4,this._connectAndWaitOpen(t)];case 4:return o.sent(),e=this.channels.filter(function(t){return t.joinedOnce&&!t.channelAdapter.isClosed()&&!t.channelAdapter.isLeaving()}),[4,Promise.all(e.map(function(e){return e._warmupOn(t)}))];case 5:return n=o.sent(),this._cutover(e,n,t),[3,8];case 6:return r=o.sent(),this.log("transport","connection refresh failed",r),[4,this._teardownStandby()];case 7:return o.sent(),this._rotating=!1,this._cutoverStarted=!1,this.isConnected()&&this.channels.length>0&&this._scheduleRotateRetry(),[3,8];case 8:return[2]}})})},t.prototype._cutover=function(t,e,n){this._cutoverStarted=!0;for(var r=this.socketAdapter,o=0;o<t.length;o++)t[o]._adopt(e[o]);this.socketAdapter=n,this._standbyAdapter=null,this._setupConnectionHandlers(),this.worker&&(this._terminateWorker(),this._startWorkerHeartbeat()),this._rotating=!1,this._scheduleConnectionRefresh(),r.disconnect(function(){},1e3,"connection refresh"),this.log("transport","connection refresh complete")},t.prototype._connectAndWaitOpen=function(t,e){return void 0===e&&(e=1e4),na(this,void 0,Promise,function(){return ra(this,function(n){switch(n.label){case 0:return[4,new Promise(function(n,r){var o=setTimeout(function(){r(new Error("standby connect timed out"))},e);t.onOpen(function(){clearTimeout(o),n()}),t.onError(function(t){clearTimeout(o),r(t instanceof Error?t:new Error(String(t)))});try{t.connect()}catch(t){clearTimeout(o),r(t)}})];case 1:return n.sent(),[2]}})})},t.prototype._teardownStandby=function(){return na(this,void 0,void 0,function(){var t;return ra(this,function(e){switch(e.label){case 0:if(t=this._standbyAdapter,this._standbyAdapter=null,!t)return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,t.disconnect(function(){},1e3,"connection refresh abort")];case 2:case 3:return e.sent(),[3,4];case 4:return[2]}})})},t.prototype._abortRotate=function(){return na(this,void 0,void 0,function(){return ra(this,function(t){switch(t.label){case 0:return this._cancelRotateRetry(),[4,this._teardownStandby()];case 1:return t.sent(),this._rotating=!1,this._cutoverStarted=!1,[2]}})})},t}();const sa=ia;var aa=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},ca=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function ua(t){if(!t)return{};if("undefined"!=typeof Headers&&t instanceof Headers){var e={};return t.forEach(function(t,n){e[n]=t}),e}if(Array.isArray(t)){for(var n={},r=0,o=t;r<o.length;r++){var i=o[r],s=i[0],a=i[1];n[s]=String(a)}return n}for(var c={},u=0,l=Object.entries(t);u<l.length;u++){var h=l[u];s=h[0],null!=(a=h[1])&&(c[s]=String(a))}return c}function la(t){var e;return"string"==typeof t?t:"undefined"!=typeof URL&&t instanceof URL?t.toString():"undefined"!=typeof Request&&t instanceof Request?t.url:String(null!==(e=t.url)&&void 0!==e?e:t)}function ha(t){return aa(this,void 0,Promise,function(){var e;return ca(this,function(n){switch(n.label){case 0:return[4,t];case 1:if(null==(e=n.sent())||""===e)return[2,{}];if("string"==typeof e)try{return[2,JSON.parse(e)]}catch(t){return[2,{message:e}]}return[2,e]}})})}function da(t){var e,n,r,o,i=this;if(t&&"object"==typeof t&&"number"==typeof t.status&&"function"==typeof t.json)return t;var s=null!=t?t:{},a=null!==(n=null!==(e=s.statusCode)&&void 0!==e?e:s.status)&&void 0!==n?n:0,c=s.data;return{ok:a>=200&&a<300,status:a,statusText:s.statusMessage||s.statusText||s.errMsg||"",headers:null!==(o=null!==(r=s.header)&&void 0!==r?r:s.headers)&&void 0!==o?o:{},json:function(){return aa(i,void 0,void 0,function(){return ca(this,function(t){return[2,ha(c)]})})},text:function(){return aa(i,void 0,void 0,function(){var t;return ca(this,function(e){switch(e.label){case 0:return[4,c];case 1:return"string"==typeof(t=e.sent())?[2,t]:null==t?[2,""]:[2,JSON.stringify(t)]}})})}}}var fa=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},pa=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},va=new Set(["TOKEN_REFRESHED","SIGNED_IN","INITIAL_SESSION"]),ya=new WeakSet,ga=new WeakMap;function ma(t){var e,n;return fa(this,void 0,Promise,function(){var r;return pa(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,null===(n=null===(e=t.request)||void 0===e?void 0:e.getAccessToken)||void 0===n?void 0:n.call(e)];case 1:return(r=o.sent())?(ya.delete(t),[2,r]):[3,3];case 2:return o.sent(),[3,3];case 3:return function(t){ya.has(t)||(ya.add(t),console.warn("[CloudBase Realtime] 当前没有登录态,无法使用 realtime 能力。\n请确认以下各项:\n 1 - 是否已调用 app.auth() 初始化认证\n 2 - 是否已完成登录(如 auth.signInAnonymously() / auth.signInWithPassword())\n 3 - 登录态是否已过期,需要重新登录"))}(t),[2,null]}})})}function ba(t){return!!t&&"function"==typeof t.onAuthStateChange}var wa=new WeakSet,_a=new WeakMap,Ea=new WeakSet;function Ia(t,e){var n;wa.has(t)||(wa.add(t),e.onAuthStateChange(function(e,r){var o,i=null!==(o=null==r?void 0:r.access_token)&&void 0!==o?o:void 0;if(va.has(e)&&i&&n!==i)return n=i,void t.setAuth(i).catch(function(e){t.log("error","Error setting auth from auth state change",e)});"SIGNED_OUT"===e&&(n=void 0,t.setAuth().catch(function(e){t.log("error","Error clearing auth from SIGNED_OUT",e)}))}))}function Sa(t){var e,n,r,o,i,s,a=this,c=function(t){var e=t.getEndPointWithKey("GATEWAY"),n=e.BASE_URL,r=e.PROTOCOL,o=/^https:?$/i.test(r)?"wss:":"ws:",i=String(n||"").replace(/\/+$/,"");return"".concat(o).concat(i,"/realtime")}(t),u={apikey:(null===(e=t.config)||void 0===e?void 0:e.env)||"cloudbase"},l=function(t){return t&&(s.apiKey=t,u.apikey=t),t},h={params:u,vsn:Hi,accessToken:function(){return fa(a,void 0,void 0,function(){var e;return pa(this,function(n){switch(n.label){case 0:return e=l,[4,ma(t)];case 1:return[2,e.apply(void 0,[n.sent()])]}})})},connectionMaxAgeMs:27e4,beforeTransportConnect:function(){return fa(a,void 0,void 0,function(){return pa(this,function(t){switch(t.label){case 0:return[4,s.setAuth()];case 1:return t.sent(),[2]}})})}},d=null===(r=null===(n=t.platform)||void 0===n?void 0:n.adapter)||void 0===r?void 0:r.wsClass;d&&(h.transport=d);var f=null===(i=null===(o=t.platform)||void 0===o?void 0:o.adapter)||void 0===i?void 0:i.reqClass;return f&&(h.fetch=function(t,e){var n=this;void 0===e&&(e={});var r=new t(e);return function(t,e){return void 0===e&&(e={}),aa(n,void 0,void 0,function(){var n;return ca(this,function(o){switch(o.label){case 0:return[4,r.fetch({url:la(t),method:e.method||"GET",headers:ua(e.headers),body:e.body,data:e.body,signal:null!==(n=e.signal)&&void 0!==n?n:void 0,shouldThrowOnError:!1})];case 1:return[2,da(o.sent())]}})})}}(f)),s=new sa(c,h),function(t,e){var n=function(t){try{if(ba(t.auth))return t.auth;if(ba(t.authInstance))return t.authInstance}catch(t){}return null}(t);if(n)Ia(e,n);else{var r=t.auth;if("function"==typeof r){var o=_a.get(t);if(o||(o=new Set,_a.set(t,o)),o.add(e),!Ea.has(t)){Ea.add(t);var i=function(e){var n=r.call(null!=this?this:t,e);return ba(n)&&function(t,e){var n=_a.get(t);if(n){for(var r=0,o=n;r<o.length;r++)Ia(o[r],e);n.clear(),_a.delete(t)}}(t,n),n};try{Object.defineProperty(t,"auth",{configurable:!0,enumerable:!0,writable:!0,value:i})}catch(e){t.auth=i}}}}}(t,s),s}var Oa={name:"realtime-js",entity:{realtime:function(){return function(t){var e=ga.get(t);if(e)return e;var n=Sa(t);return ga.set(t,n),n}(this)}}};try{cloudbase.registerComponent(Oa)}catch(Mt){}function Ta(t){try{t.registerComponent(Oa)}catch(t){console.warn(t)}}try{window.registerRealtimeJs=Ta}catch(t){}const Aa=(t=>{var e={};return l.d(e,t),e})({generateHTTPClient:()=>r.generateHTTPClient,generateMySQLClient:()=>r.generateMySQLClient,generatePGClient:()=>r.generatePGClient});var Pa=function(){return Pa=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Pa.apply(this,arguments)},Ra=X,Ca="models",ka=new WeakMap;function Na(t){return new Proxy({},{get:function(e,n){var r=t.getEndPointWithKey("GATEWAY"),o=r.BASE_URL,i=r.PROTOCOL,s=Pa(Pa({},t),{BASE_URL:o,PROTOCOL:i}),a=ka.get(s);return a||(a=function(t){var e=this,n=t.callFunction.bind(t),r=t.request.fetch.bind(t.request),o=t.getEndPointWithKey("GATEWAY"),i=o.BASE_URL,s=o.PROTOCOL,a="".concat(s).concat(i,"/model"),c="".concat(s).concat(i,"/sql"),u=(0,Aa.generateHTTPClient)(n,function(t){return n=e,o=void 0,s=function(){return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(e){switch(e.label){case 0:return[4,r(Pa(Pa({},t),{headers:Pa({"Content-Type":"application/json"},t.headers)}))];case 1:return[4,e.sent().data];case 2:return[2,e.sent()]}})},new((i=void 0)||(i=Promise))(function(t,e){function r(t){try{c(s.next(t))}catch(t){e(t)}}function a(t){try{c(s.throw(t))}catch(t){e(t)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof i?n:new i(function(t){t(n)})).then(r,a)}c((s=s.apply(n,o||[])).next())});var n,o,i,s},a,{sqlBaseUrl:c});return u}(t),ka.set(s,a)),a[n]}})}var xa="cloudbase_init",Ua=new Ra;Ua.on(xa,function(t){var e=t.data;Object.assign(e,{models:Na(e)})});var La={name:Ca,namespace:Ca,entity:new Proxy({},{get:function(t,e){console.warn("【deprecated】Accessing Cloudbase.prototype.models.".concat(e,"."))}}),injectEvents:{bus:Ua,events:[xa]}};try{cloudbase.registerComponent(La)}catch(t){}function Da(t){try{t.registerComponent(La)}catch(t){console.warn(t)}}try{window.registerModel=Da}catch(t){}const ja=(t=>{var e={};return l.d(e,t),e})({ReadableStream:()=>o.ReadableStream,TransformStream:()=>o.TransformStream}),qa=(t=>{var e={};return l.d(e,t),e})({createReadableStreamWrapper:()=>i.createReadableStreamWrapper});var Ma=[239,187,191];const Ba=(t=>{var e={};return l.d(e,t),e})({TextDecoder:()=>s.TextDecoder});var Wa=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Fa=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Ha="function"==typeof globalThis.ReadableStream&&"function"==typeof globalThis.TransformStream&&"function"==typeof globalThis.ReadableStream.prototype.pipeThrough,Va=Ha?globalThis.ReadableStream:ja.ReadableStream,Ga=Ha?globalThis.TransformStream:ja.TransformStream,Ka=function(){var t;return new Ga({start:function(e){t=function(t){var e,n,r,o,i,s,a;return c(),{feed:function(t){n=n?n+t:t,e&&function(t){return Ma.every(function(e,n){return t.charCodeAt(n)===e})}(n)&&(n=n.slice(Ma.length)),e=!1;for(var i=n.length,s=0,a=!1;s<i;){a&&("\n"===n[s]&&(s+=1),a=!1);for(var c=-1,l=o,h=void 0,d=r;c<0&&d<i;d++)":"===(h=n[d])&&l<0?l=d-s:"\r"===h?(a=!0,c=d-s):"\n"===h&&(c=d-s);if(c<0){r=i-s,o=l;break}r=0,o=-1,u(n,s,l,c),s+=c+1}s===i?n="":s>0&&(n=n.slice(s))},reset:c};function c(){e=!0,n="",r=0,o=-1,i=void 0,s=void 0,a=""}function u(e,n,r,o){if(0===o)return a.length>0&&(t({type:"event",id:i,event:s||void 0,data:a.slice(0,-1)}),a="",i=void 0),void(s=void 0);var c,u=r<0,l=e.slice(n,n+(u?o:r)),h=n+(c=u?o:" "===e[n+r+1]?r+2:r+1),d=o-c,f=e.slice(h,h+d).toString();if("data"===l)a+=f?"".concat(f,"\n"):"\n";else if("event"===l)s=f;else if("id"!==l||f.includes("\0")){if("retry"===l){var p=parseInt(f,10);Number.isNaN(p)||t({type:"reconnect-interval",value:p})}}else i=f}}(function(t){"event"===t.type&&e.enqueue(t)})},transform:function(e){t.feed(e)}})},Ja=Ha?function(t){return t}:(0,qa.createReadableStreamWrapper)(Va),za=function(){function t(t,e){void 0===t&&(t="utf-8"),void 0===e&&(e={});var n=this;this.transform=new Ga({transform:function(t,e){var r=n.handle.decode(new Uint8Array(t),{stream:!0});r&&e.enqueue(r)},flush:function(t){var e=n.handle.decode();e&&t.enqueue(e),t.terminate()}}),this.handle=new Ba.TextDecoder(t,e)}return Object.defineProperty(t.prototype,"encoding",{get:function(){return this.handle.encoding},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"fatal",{get:function(){return this.handle.fatal},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ignoreBOM",{get:function(){return this.handle.ignoreBOM},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"readable",{get:function(){return this.transform.readable},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"writable",{get:function(){return this.transform.writable},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,Symbol.toStringTag,{get:function(){return"TextDecoderStream"},enumerable:!1,configurable:!0}),t}();function $a(t){var e=t;return e[Symbol.asyncIterator]=function(){var e=t.getReader();return{next:function(){return Wa(this,void 0,Promise,function(){var t,n,r;return Fa(this,function(o){switch(o.label){case 0:return[4,e.read()];case 1:return t=o.sent(),n=t.done,r=t.value,[2,n?{done:!0,value:void 0}:{done:!1,value:r}]}})})}}},e}function Ya(t){return $a(t.pipeThrough(new za).pipeThrough(Ka()).pipeThrough(new Ga({transform:function(t,e){try{var n=JSON.parse(t.data);e.enqueue(n)}catch(n){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",n,t):e.terminate()}}})))}function Qa(t){var e,n,r,o;return Wa(this,void 0,void 0,function(){var i,s,a,c,u,l;return Fa(this,function(h){switch(h.label){case 0:i=function(t){return $a(Ja(t).pipeThrough(new za))}(t),s="",h.label=1;case 1:h.trys.push([1,6,7,12]),a=!0,c=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise(function(r,o){!function(t,e,n,r){Promise.resolve(r).then(function(e){t({value:e,done:n})},e)}(r,o,(e=t[n](e)).done,e.value)})}}}(i),h.label=2;case 2:return[4,c.next()];case 3:if(u=h.sent(),e=u.done)return[3,5];o=u.value,a=!1;try{s+=o}finally{a=!0}h.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return l=h.sent(),n={error:l},[3,12];case 7:return h.trys.push([7,,10,11]),a||e||!(r=c.return)?[3,9]:[4,r.call(c)];case 8:h.sent(),h.label=9;case 9:return[3,11];case 10:if(n)throw n.error;return[7];case 11:return[7];case 12:return[2,JSON.parse(s)]}})})}function Xa(){var t,e;return{promise:new Promise(function(n,r){t=n,e=r}),res:t,rej:e}}function Za(t){var e;return"assistant"===t.role&&"tool_calls"in t&&null!=(null===(e=t.tool_calls)||void 0===e?void 0:e[0])}var tc=function(){return tc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},tc.apply(this,arguments)},ec=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},nc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},rc=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},oc=function(){function t(t,e){this.baseUrl=e;var n=arguments[2];this.req="string"==typeof n?function(e){var r=e.headers,o=void 0===r?{}:r,i=rc(e,["headers"]);return t(tc(tc({},i),{headers:tc(tc({},o),{Authorization:"Bearer ".concat(n)})}))}:t}return t.prototype.list=function(t,e){return this.req({method:"get",url:this.join("bots"),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.create=function(t,e){var n=t.botInfo;return this.req({method:"post",url:this.join("bots"),data:n,timeout:null==e?void 0:e.timeout})},t.prototype.get=function(t,e){var n=t.botId;return this.req({method:"get",url:this.join("bots/".concat(n)),timeout:null==e?void 0:e.timeout})},t.prototype.update=function(t,e){var n=t.botId,r=t.botInfo;return this.req({method:"PATCH",url:this.join("bots/".concat(n)),data:r,timeout:null==e?void 0:e.timeout})},t.prototype.delete=function(t,e){var n=t.botId;return this.req({method:"delete",url:this.join("bots/".concat(n)),timeout:null==e?void 0:e.timeout})},t.prototype.getChatRecords=function(t,e){return this.req({method:"get",url:this.join("bots/".concat(t.botId,"/records")),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.sendFeedback=function(t,e){var n=t.userFeedback;return this.req({method:"post",url:this.join("bots/".concat(n.botId,"/feedback")),data:n,timeout:null==e?void 0:e.timeout})},t.prototype.getFeedback=function(t,e){return this.req({method:"get",url:this.join("bots/".concat(t.botId,"/feedback")),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.uploadFiles=function(t,e){return ec(this,void 0,void 0,function(){return nc(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/files")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.createConversation=function(t,e){var n=t.botId,r=rc(t,["botId"]);return ec(this,void 0,void 0,function(){return nc(this,function(t){return[2,this.req({method:"post",url:this.join("bots/".concat(n,"/conversation")),data:r,timeout:null==e?void 0:e.timeout})]})})},t.prototype.getConversation=function(t,e){var n=t.pageSize,r=void 0===n?10:n,o=t.pageNumber,i=void 0===o?1:o,s=t.botId,a=rc(t,["pageSize","pageNumber","botId"]);return ec(this,void 0,void 0,function(){var t,n;return nc(this,function(o){if(i<1)throw new Error("pageNumber must be greater than 0");return t=r*(i-1),n=r,[2,this.req({method:"get",url:this.join("bots/".concat(s,"/conversation")),data:tc(tc({},a),{offset:t,limit:n}),timeout:null==e?void 0:e.timeout})]})})},t.prototype.deleteConversation=function(t,e){var n=t.botId,r=t.conversationId,o=rc(t,["botId","conversationId"]);return ec(this,void 0,void 0,function(){return nc(this,function(t){return[2,this.req({method:"delete",url:this.join("bots/".concat(n,"/conversation/").concat(r)),data:o,timeout:null==e?void 0:e.timeout})]})})},t.prototype.speechToText=function(t,e){return ec(this,void 0,void 0,function(){return nc(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/speech-to-text")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.textToSpeech=function(t,e){return ec(this,void 0,void 0,function(){return nc(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/text-to-speech")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.getTextToSpeechResult=function(t,e){return ec(this,void 0,void 0,function(){return nc(this,function(n){return[2,this.req({method:"get",url:this.join("bots/".concat(t.botId,"/text-to-speech")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.getRecommendQuestions=function(t,e){return ec(this,void 0,void 0,function(){var n;return nc(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/recommend-questions")),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new ic(n)]}})})},t.prototype.generateBot=function(t,e){return ec(this,void 0,void 0,function(){var n;return nc(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("generate-bot"),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new ic(n)]}})})},t.prototype.getPreview=function(t,e){return ec(this,void 0,void 0,function(){var n;return nc(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("preview"),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new ic(n)]}})})},t.prototype.generateImage=function(t,e){return this.req({method:"post",url:this.join("generate-image"),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.sendMessage=function(t,e){return ec(this,void 0,void 0,function(){var n;return nc(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/send-message")),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new ic(n)]}})})},t.prototype.join=function(t){return"".concat(this.baseUrl,"/").concat(t)},t}(),ic=function(){function t(t){var e=Ja(t);this._eventSourceStream=e.pipeThrough(new za).pipeThrough(Ka())}return Object.defineProperty(t.prototype,"teeedStream",{get:function(){var t=this._eventSourceStream.tee(),e=t[0],n=t[1];return this._eventSourceStream=n,e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"eventSourceStream",{get:function(){return $a(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dataStream",{get:function(){return $a(this.eventSourceStream.pipeThrough(new Ga({transform:function(t,e){try{var n=JSON.parse(t.data);e.enqueue(n)}catch(n){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",n,t):e.terminate()}}})))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textStream",{get:function(){return $a(this.dataStream.pipeThrough(new Ga({transform:function(t,e){var n;e.enqueue(null!==(n=null==t?void 0:t.content)&&void 0!==n?n:"")}})))},enumerable:!1,configurable:!0}),t}(),sc=function(){return sc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},sc.apply(this,arguments)},ac=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},cc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function uc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,s=t.top_p;return sc(sc({},t),{messages:e,model:n,temperature:r,tool_choice:(o&&"auto"!==o&&console.warn("`tool_choice` is not 'auto'"),o),tools:i,top_p:s})}var lc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="zhipu/api/paas/v4/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return ac(this,void 0,Promise,function(){var n,r;return cc(this,function(o){switch(o.label){case 0:return n=uc(t),[4,this.req({url:this.url,data:sc(sc({},n),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return r=o.sent(),[2,sc(sc({},r),{rawResponse:r})]}})})},t.prototype.doStream=function(t,e){return ac(this,void 0,Promise,function(){var n,r,o,i;return cc(this,function(s){switch(s.label){case 0:return n=uc(t),r=null,[4,this.req({url:this.url,data:sc(sc({},n),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return o=s.sent(),i=Ja(o),[2,$a(Ya(i).pipeThrough(new Ga({transform:function(t,e){var n=t.choices.map(function(t){var e=t.delta;return null==r&&(r=Za(e)),r?sc(sc({},t),{finish_reason:"tool_calls",delta:e}):t}),o=sc(sc({},t),{choices:n});e.enqueue(sc(sc({},o),{rawResponse:t}))}})))]}})})},t}(),hc=function(){return hc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},hc.apply(this,arguments)};function dc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,s=t.top_p;return hc(hc({},t),{messages:(e.forEach(function(t){"tool_calls"in t&&t.tool_calls.filter(function(t){return"function"!==t.type}).forEach(function(e){return console.warn("`type` in tool_call is not 'function'",e,t)})}),e),model:n,tools:function(){if(i)return i.forEach(function(t){"function"!==t.type&&console.warn("`type` in tool is not 'function'",t)}),i}(),top_p:s,tool_choice:o,temperature:r})}function fc(t){return"object"!=typeof t||null==t?t:Array.isArray(t)?t.map(function(t){return fc(t)}):Object.entries(t).reduce(function(t,e){var n,r=e[0],o=e[1];return t["_"===(n=r.replace(/[A-Z]/g,function(t){return"_".concat(t.toLowerCase())})).charAt(0)?n.slice(1):n]="object"==typeof o?fc(o):o,t},{})}var pc=function(){return pc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},pc.apply(this,arguments)},vc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},yc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},gc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-beta/openapi/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return vc(this,void 0,Promise,function(){var n;return yc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:pc(pc({},dc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,pc(pc({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return vc(this,void 0,Promise,function(){var n,r,o;return yc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:pc(pc({},dc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?pc(pc({},t),{finish_reason:"tool_calls",delta:e}):t}),o=pc(pc({},t),{choices:r});e.enqueue(pc(pc({},o),{rawResponse:t}))}})))]}})})},t}(),mc=function(){return mc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},mc.apply(this,arguments)},bc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},wc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},_c=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return bc(this,void 0,Promise,function(){var n,r;return wc(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:mc(mc({},dc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=o.sent(),r=fc(n.Response),[2,mc(mc({},r),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return bc(this,void 0,Promise,function(){var n,r,o;return wc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:mc(mc({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=fc(t),o=r.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?mc(mc({},t),{finish_reason:"tool_calls",delta:e}):t}),i=mc(mc({},r),{choices:o});e.enqueue(mc(mc({},i),{rawResponse:t}))}})))]}})})},t}(),Ec=function(){return Ec=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ec.apply(this,arguments)},Ic=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Sc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Oc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return Ec(Ec({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var Tc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="ark/api/v3/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return Ic(this,void 0,Promise,function(){var n;return Sc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Ec(Ec({},Oc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Ec(Ec({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return Ic(this,void 0,Promise,function(){var n,r,o;return Sc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Ec(Ec({},Oc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?Ec(Ec({},t),{finish_reason:"tool_calls",delta:e}):t}),o=Ec(Ec({},t),{choices:r});e.enqueue(Ec(Ec({},o),{rawResponse:t}))}})))]}})})},t}(),Ac=function(){return Ac=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ac.apply(this,arguments)},Pc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Rc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Cc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return Ac(Ac({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var kc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="dashscope/compatible-mode/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return Pc(this,void 0,Promise,function(){var n;return Rc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Ac(Ac({},Cc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Ac(Ac({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return Pc(this,void 0,Promise,function(){var n,r,o;return Rc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Ac(Ac({},Cc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=Za(e)),Ac(Ac({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})}),o=Ac(Ac({},t),{choices:r});e.enqueue(Ac(Ac({},o),{rawResponse:t}))}})))]}})})},t}(),Nc=function(){return Nc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Nc.apply(this,arguments)},xc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Uc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Lc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return Nc(Nc({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var Dc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="01-ai/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return xc(this,void 0,Promise,function(){var n;return Uc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Nc(Nc({},Lc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Nc(Nc({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return xc(this,void 0,Promise,function(){var n,r,o,i,s;return Uc(this,function(a){switch(a.label){case 0:return n=null,[4,this.req({url:this.url,data:Nc(Nc({},Lc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=a.sent(),o=Ja(r),i=Ya(o),s=i.pipeThrough(new Ga({transform:function(t,e){var r,o,i,s,a,c;if((null===(i=null===(o=null===(r=null==t?void 0:t.choices)||void 0===r?void 0:r[0])||void 0===o?void 0:o.delta)||void 0===i?void 0:i.content)||(null===(c=null===(a=null===(s=null==t?void 0:t.choices)||void 0===s?void 0:s[0])||void 0===a?void 0:a.delta)||void 0===c?void 0:c.tool_calls)){var u=t.choices.map(function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=Za(e)),Nc(Nc({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})}),l=Nc(Nc({},t),{choices:u});e.enqueue(Nc(Nc({},l),{rawResponse:t}))}}})),[2,$a(s)]}})})},t}(),jc=function(){return jc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},jc.apply(this,arguments)},qc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Mc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Bc(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return jc(jc({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var Wc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="moonshot/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return qc(this,void 0,Promise,function(){var n;return Mc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:jc(jc({},Bc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,jc(jc({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return qc(this,void 0,Promise,function(){var n,r,o;return Mc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:jc(jc({},Bc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?jc(jc({},t),{finish_reason:"tool_calls",delta:e}):t}),o=jc(jc({},t),{choices:r});e.enqueue(jc(jc({},o),{rawResponse:t}))}})))]}})})},t}(),Fc=function(){return Fc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Fc.apply(this,arguments)},Hc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Vc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Gc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-exp/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t){return Hc(this,void 0,Promise,function(){var e;return Vc(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Fc(Fc({},dc(t)),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,Fc(Fc({},e),{rawResponse:e})]}})})},t.prototype.doStream=function(t){return Hc(this,void 0,Promise,function(){var e,n,r;return Vc(this,function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:Fc(Fc({},dc(t)),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=Ja(n),[2,$a(Ya(r).pipeThrough(new Ga({transform:function(t,n){var r=t.choices.map(function(t){var n=t.delta;return null==e&&(e=Za(n)),e?Fc(Fc({},t),{finish_reason:"tool_calls",delta:n}):t}),o=Fc(Fc({},t),{choices:r});n.enqueue(Fc(Fc({},o),{rawResponse:t}))}})))]}})})},t}(),Kc=function(){return Kc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Kc.apply(this,arguments)},Jc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},zc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},$c=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-open/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return Jc(this,void 0,Promise,function(){var n;return zc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Kc(Kc({},dc(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Kc(Kc({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return Jc(this,void 0,Promise,function(){var n,r,o;return zc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Kc(Kc({},dc(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?Kc(Kc({},t),{finish_reason:"tool_calls",delta:e}):t}),o=Kc(Kc({},t),{choices:r});e.enqueue(Kc(Kc({},o),{rawResponse:t}))}})))]}})})},t}(),Yc=function(){return Yc=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Yc.apply(this,arguments)},Qc=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Xc=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Zc=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="deepseek/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return Qc(this,void 0,Promise,function(){var n;return Xc(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Yc(Yc({},t),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Yc(Yc({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return Qc(this,void 0,Promise,function(){var n,r,o;return Xc(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Yc(Yc({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=Ja(r),[2,$a(Ya(o).pipeThrough(new Ga({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=Za(e)),n?Yc(Yc({},t),{finish_reason:"tool_calls",delta:e}):t}),o=Yc(Yc({},t),{choices:r});e.enqueue(Yc(Yc({},o),{rawResponse:t}))}})))]}})})},t}(),tu=function(){return tu=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},tu.apply(this,arguments)},eu=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},nu=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},ru=function(){function t(t,e,n){void 0===n&&(n=""),this.req=t,this.baseUrl=e,this.subUrl=n}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t){return eu(this,void 0,Promise,function(){var e;return nu(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:tu(tu({},t),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,tu(tu({},e),{rawResponse:e})]}})})},t.prototype.doStream=function(t){return eu(this,void 0,Promise,function(){var e,n,r;return nu(this,function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:tu(tu({},t),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=Ja(n),[2,$a(Ya(r).pipeThrough(new Ga({transform:function(t,n){var r=t.choices.map(function(t){var n=t.delta;return null==e&&(e=Za(n)),e?tu(tu({},t),{finish_reason:"tool_calls",delta:n}):t}),o=tu(tu({},t),{choices:r});n.enqueue(tu(tu({},o),{rawResponse:t}))}})))]}})})},t}(),ou=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),iu=function(t){function e(e,n){var r=t.call(this,e)||this;return r.name="InvalidParamsError",r.code="INVALID_PARAMS",r.field=n,r}return ou(e,t),e.prototype.toJSON=function(){return{code:this.code,message:this.message,field:this.field}},e}(Error),su=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.provider=n,this.defaultGenerateImageSubUrl="images/ar/generations",this.generateImageSubUrlConfig={"hunyuan-image":[[/^hunyuan-image(-v[12](\..*)?)?$/,"images/generations"]],cloudbase:[[/^hy-image-v3\.5-preview$/,"wand/hunyuan-image/v35-generation"]]},this.generateImage=this.generateImageImpl.bind(this)}return t.prototype.generateImageImpl=function(t){return e=this,n=void 0,o=function(){var e;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(n){switch(n.label){case 0:return this.validateInput(t),e=this.resolveSubUrl(t),[4,this.req({url:this.getGenerateUrl(e),data:t,stream:!1})];case 1:return[2,n.sent()]}})},new((r=Promise)||(r=Promise))(function(t,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r(function(t){t(n)})).then(s,a)}c((o=o.apply(e,n||[])).next())});var e,n,r,o},t.prototype.validateInput=function(t){""!==this.provider&&"hunyuan-image"!==this.provider||this.assertHunyuanInput(t)},t.prototype.assertHunyuanInput=function(t){if(t&&"HY-Image-v3.0-I2I-ToB-v1.0.1"===t.model){var e=t.image_urls,n=t.images;if(e&&e.length>1)throw new iu("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,image_urls 最多只能有 1 个元素","image_urls");if(n&&n.length>1)throw new iu("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,images 最多只能有 1 个元素","images")}},t.prototype.resolveSubUrl=function(t){var e=t&&"string"==typeof t.model?t.model:void 0,n=e?this.getGenerateImageSubUrl(this.provider,e):void 0;if(n)return n;if("cloudbase"===this.provider)throw new iu("cloudbase provider 不支持的模型:".concat(null!=e?e:"(未指定)"),"model");return this.defaultGenerateImageSubUrl},t.prototype.getGenerateUrl=function(t){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(t)},t.prototype.getGenerateImageSubUrl=function(t,e){var n=this.generateImageSubUrlConfig[t];if(n)for(var r=0,o=n;r<o.length;r++){var i=o[r],s=i[0],a=i[1];if(s.test(e))return a}},t}(),au=function(){return au=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},au.apply(this,arguments)},cu=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},uu=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},lu=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function hu(t){var e,n=t.onStepFinish,r=t.abortSignal,o=t.maxSteps,i=t.topP,s=t.toolChoice,a=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(t,["onStepFinish","abortSignal","maxSteps","topP","toolChoice"]);if(null!=o&&o<1)throw new Error("`maxSteps` muse be greater than 0.");return[{onStepFinish:n,abortSignal:r,maxSteps:o},au(au({},a),{tools:null===(e=a.tools)||void 0===e?void 0:e.map(function(t){return"fn"in t?function(t){return{type:"function",function:{description:t.description,name:t.name,parameters:t.parameters}}}(t):t}),top_p:null!=i?i:a.top_p,tool_choice:null!=s?s:a.tool_choice})]}var du=function(){function t(t){this.model=t}return t.prototype.generateText=function(t,e){var n,r;return cu(this,void 0,Promise,function(){var o,i,s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I,S,O=this;return uu(this,function(T){switch(T.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},s=hu(t),a=s[0],c=a.onStepFinish,u=a.maxSteps,l=void 0===u?10:u,h=s[1],[4,(d=function(){return O.model.doGenerate(h,e)})()];case 1:f=T.sent(),p=1,f.rawResponse&&o.push(f.rawResponse),v=null,T.label=2;case 2:if(!(p<l&&null!=(v=fu(f))))return[3,9];y=gu(f.usage),mu(i,y),T.label=3;case 3:return T.trys.push([3,7,,8]),[4,yu(v)];case 4:return g=T.sent(),m=f.choices[0],[4,null==c?void 0:c({finishReason:m.finish_reason,messages:h.messages.slice(),text:m.message.content,toolCall:v,toolResult:g,stepUsage:y,totalUsage:Object.assign({},i)})];case 5:return T.sent(),pu(h.messages,m.message,g),[4,d()];case 6:return(f=T.sent()).rawResponse&&o.push(f.rawResponse),p+=1,[3,8];case 7:return b=T.sent(),[2,{text:"",messages:h.messages,usage:i,error:b,rawResponses:o}];case 8:return[3,2];case 9:return w=null===(n=null==f?void 0:f.choices)||void 0===n?void 0:n[0],_=null==w?void 0:w.message,E=null!==(r=null==_?void 0:_.content)&&void 0!==r?r:"",I=_?lu(lu([],h.messages,!0),[_],!1):h.messages,S=gu(f.usage),mu(i,S),[4,null==c?void 0:c({finishReason:w.finish_reason,messages:I.slice(),text:E,toolCall:fu(f),toolResult:null,stepUsage:S,totalUsage:Object.assign({},i)})];case 10:return T.sent(),[2,{text:E,messages:I,usage:i,rawResponses:o}]}})})},t.prototype.streamText=function(t,e){var n;return cu(this,void 0,Promise,function(){var r,o,i,s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I,S,O,T,A,P,R,C,k,N,x,U,L,D,j,q,M=this;return uu(this,function(B){switch(B.label){case 0:return r={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=hu(t),i=o[0],s=i.onStepFinish,a=i.maxSteps,c=void 0===a?10:a,u=o[1],[4,(l=function(){return M.model.doStream(u,e)})()];case 1:h=B.sent(),d=1,f=null,p=function(){var t=h.tee(),e=t[0],n=t[1];return h=$a(e),function(t){var e,n,r,o,i,s,a,c,u,l;return cu(this,void 0,Promise,function(){var h,d,f,p,v,y,g,m,b,w,_,E,I;return uu(this,function(S){switch(S.label){case 0:h={completion_tokens:0,prompt_tokens:0,total_tokens:0},d=$a(t),p={role:"assistant",content:"",tool_calls:[f={id:"",function:{name:"",arguments:""},type:""}]},S.label=1;case 1:S.trys.push([1,6,7,12]),v=!0,y=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise(function(r,o){!function(t,e,n,r){Promise.resolve(r).then(function(e){t({value:e,done:n})},e)}(r,o,(e=t[n](e)).done,e.value)})}}}(d),S.label=2;case 2:return[4,y.next()];case 3:if(g=S.sent(),e=g.done)return[3,5];o=g.value,v=!1;try{if(!(b=null==(m=o)?void 0:m.choices[0]))return[2,null];if(w=b.finish_reason,_=b.delta,"tool_calls"!==w)return[2,null];if(!_)return[3,4];if(_.content&&(p.content+=_.content),!("tool_calls"in _))return[3,4];(null==(E=null===(i=null==_?void 0:_.tool_calls)||void 0===i?void 0:i[0])?void 0:E.id)&&(f.id=E.id),(null==E?void 0:E.type)&&(f.type=E.type),(null===(s=null==E?void 0:E.function)||void 0===s?void 0:s.name)&&(f.function.name=E.function.name),(null===(a=null==E?void 0:E.function)||void 0===a?void 0:a.arguments)&&(f.function.arguments+=E.function.arguments),(null===(c=null==m?void 0:m.usage)||void 0===c?void 0:c.completion_tokens)&&(h.completion_tokens=m.usage.completion_tokens),(null===(u=null==m?void 0:m.usage)||void 0===u?void 0:u.prompt_tokens)&&(h.prompt_tokens=m.usage.prompt_tokens),(null===(l=null==m?void 0:m.usage)||void 0===l?void 0:l.total_tokens)&&(h.total_tokens=m.usage.total_tokens)}finally{v=!0}S.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return I=S.sent(),n={error:I},[3,12];case 7:return S.trys.push([7,,10,11]),v||e||!(r=y.return)?[3,9]:[4,r.call(y)];case 8:S.sent(),S.label=9;case 9:return[3,11];case 10:if(n)throw n.error;return[7];case 11:return[7];case 12:return[2,{message:p,usage:h}]}})})}(n)},B.label=2;case 2:return(v=d<c)?[4,p()]:[3,4];case 3:v=null!=(f=B.sent()),B.label=4;case 4:if(!v)return[3,11];y=f.message,g=f.usage,mu(r,g),m=null===(n=y.tool_calls)||void 0===n?void 0:n[0],B.label=5;case 5:return B.trys.push([5,9,,10]),[4,yu(m)];case 6:return b=B.sent(),[4,null==s?void 0:s({finishReason:"tool_calls",messages:u.messages.slice(),text:y.content,toolCall:m,toolResult:b,stepUsage:g,totalUsage:Object.assign({},r)})];case 7:return B.sent(),pu(u.messages,y,b),[4,l()];case 8:return h=B.sent(),[3,10];case 9:return w=B.sent(),_=h.tee(),E=_[0],I=_[1],[2,{messages:Promise.resolve(u.messages),dataStream:$a(E),textStream:$a(I.pipeThrough(new Ga({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:Promise.resolve(r),error:w}];case 10:return[3,2];case 11:return[4,p()];case 12:return(f=B.sent())?(S=f.message,O=f.usage,mu(r,O),T=lu(lu([],u.messages,!0),[S],!1),s({messages:T.slice(),finishReason:"tool_call",stepUsage:O,text:S.content,toolCall:S.tool_calls[0],totalUsage:Object.assign({},r)}),A=h.tee(),P=A[0],R=A[1],[2,{messages:Promise.resolve(lu(lu([],u.messages,!0),[S],!1)),dataStream:$a(P),textStream:$a(R.pipeThrough(new Ga({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:Promise.resolve(r)}]):(C=Xa(),k=Xa(),N={role:"assistant",content:""},x="",U={completion_tokens:0,prompt_tokens:0,total_tokens:0},L=h.pipeThrough(new Ga({transform:function(t,e){var n,r,o,i,s,a,c,u,l=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof l&&(N.content+=l);var h=null===(s=null===(i=null==t?void 0:t.choices)||void 0===i?void 0:i[0])||void 0===s?void 0:s.finish_reason;h&&(x=h),(null===(a=null==t?void 0:t.usage)||void 0===a?void 0:a.completion_tokens)&&(U.completion_tokens=t.usage.completion_tokens),(null===(c=null==t?void 0:t.usage)||void 0===c?void 0:c.prompt_tokens)&&(U.prompt_tokens=t.usage.prompt_tokens),(null===(u=null==t?void 0:t.usage)||void 0===u?void 0:u.total_tokens)&&(U.total_tokens=t.usage.total_tokens),e.enqueue(t)},flush:function(){C.res(lu(lu([],u.messages,!0),[N],!1)),mu(r,U),k.res(Object.assign({},r)),null==s||s({messages:lu(lu([],u.messages,!0),[N],!1),finishReason:x,text:N.content,stepUsage:U,totalUsage:Object.assign({},r)})}})),D=L.tee(),j=D[0],q=D[1],[2,{messages:C.promise,dataStream:$a(j),textStream:$a(q.pipeThrough(new Ga({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:k.promise}])}})})},t}();function fu(t){var e,n=null===(e=null==t?void 0:t.choices)||void 0===e?void 0:e[0];if(!n)return null;var r=n.finish_reason,o=n.message;return"tool_calls"!==r?null:o&&Za(o)?o.tool_calls[0]:null}function pu(t,e,n){t.push(e,{role:"tool",tool_call_id:e.tool_calls[0].id,content:JSON.stringify(n)})}var vu=new Map;function yu(t){return vu.get(t.function.name)(JSON.parse(t.function.arguments))}function gu(t){var e,n,r;return{completion_tokens:null!==(e=null==t?void 0:t.completion_tokens)&&void 0!==e?e:0,prompt_tokens:null!==(n=null==t?void 0:t.prompt_tokens)&&void 0!==n?n:0,total_tokens:null!==(r=null==t?void 0:t.total_tokens)&&void 0!==r?r:0}}function mu(t,e){t.completion_tokens+=e.completion_tokens,t.prompt_tokens+=e.prompt_tokens,t.total_tokens+=e.total_tokens}var bu={hunyuan:_c,"hunyuan-beta":gc,ark:Tc,dashscope:kc,"01-ai":Dc,moonshot:Wc,zhipu:lc,"hunyuan-exp":Gc,"hunyuan-open":$c,deepseek:Zc},wu=function(){return wu=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},wu.apply(this,arguments)},_u=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Eu=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Iu=bu,Su=function(){function t(t,e,n,r){var o=this;this.req=t,this.baseUrl=e,this.modelRequest=function(t){var e=t.url,n=t.data,r=t.headers,i=t.stream,s=t.timeout;return _u(o,void 0,void 0,function(){var t,o,a,c,u,l,h;return Eu(this,function(d){switch(d.label){case 0:return t={"Content-Type":"application/json"},i&&Object.assign(t,{Accept:"text/event-stream"}),[4,this.req.fetch({method:"post",headers:wu(wu((u={},u[null===(l=this.i18n)||void 0===l?void 0:l.LANG_HEADER_KEY]=null===(h=this.i18n)||void 0===h?void 0:h.lang,u),t),r),body:JSON.stringify(n),url:this.resolveUrl(e),stream:i,timeout:s})];case 1:return o=d.sent(),a=o.data,c=o.header,[2,this.handleResponseData(a,c)]}})})},this.botRequest=function(t){var e=t.method,n=t.url,r=t.data,i=void 0===r?{}:r,s=t.headers,a=t.stream,c=t.timeout;return _u(o,void 0,void 0,function(){var t,r,o,u,l,h,d,f,p;return Eu(this,function(v){switch(v.label){case 0:return t=this.resolveUrl(n),"get"!==e?[3,2]:(r=this.handleResponseData,[4,this.req.fetch({url:"".concat(t,"?").concat((y=i,Object.entries(y).map(function(t){var e=t[0],n=t[1];return"".concat(e,"=").concat(n)}).join("&"))),method:e,headers:s,stream:a,timeout:c})]);case 1:return[2,r.apply(this,[v.sent().data])];case 2:return o={"Content-Type":"application/json"},a&&Object.assign(o,{Accept:"text/event-stream"}),[4,this.req.fetch({url:t,body:JSON.stringify(i),headers:wu(wu((d={},d[null===(f=this.i18n)||void 0===f?void 0:f.LANG_HEADER_KEY]=null===(p=this.i18n)||void 0===p?void 0:p.lang,d),o),s),stream:a,method:e,timeout:c})];case 3:return u=v.sent(),l=u.data,h=u.header,[2,this.handleResponseData(l,h)]}var y})})},this._getBaseUrl=r,this.bot=new oc(this.botRequest,this.aiBotBaseUrl),this.i18n=n,Z.on(tt,function(t){var e;o.i18n=(null===(e=t.data)||void 0===e?void 0:e.i18n)||o.i18n})}return Object.defineProperty(t.prototype,"aiBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/ai")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"aiBotBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/aibot")},enumerable:!1,configurable:!0}),t.prototype.handleResponseData=function(t,e){var n,r;return _u(this,void 0,void 0,function(){var o,i,s,a,c,u=this;return Eu(this,function(l){switch(l.label){case 0:return o=function(t){var e,n,r;return null!==(r=null===(n=null===(e=u.i18n)||void 0===e?void 0:e.t)||void 0===n?void 0:n.call(e,t))&&void 0!==r?r:t},i="".concat(o("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),s=function(t){if("object"==typeof t&&t&&"code"in t&&"NORMAL"!==t.code)throw new Error("".concat(o("AI+ 请求出错,错误码"),":").concat(t.code,",").concat(o("错误信息"),":").concat(t.message,"\n").concat(i,"\n").concat(JSON.stringify(t,null,2)))},"object"==typeof t&&t&&"function"!=typeof t.getReader?"then"in t?[4,t]:[3,2]:[3,4];case 1:return a=l.sent(),[3,3];case 2:a=t,l.label=3;case 3:return s(c=a),[2,t];case 4:if("function"!=typeof(null==t?void 0:t.getReader)){if("object"==typeof(c=t)&&c&&"code"in c&&"NORMAL"!==c.code)throw new Error("".concat(o("AI+ 请求出错,错误码"),":").concat(c.code,",").concat(o("错误信息"),":").concat(c.message,"\n").concat(i,"\n").concat(JSON.stringify(c,null,2)));return[2,t]}return(null===(r=null===(n=null==e?void 0:e.get)||void 0===n?void 0:n.call(e,"content-type"))||void 0===r?void 0:r.includes("application/json"))?[4,Qa(t)]:[3,6];case 5:c=l.sent(),s(c),l.label=6;case 6:return[2,t]}})})},t.prototype.createModel=function(t,e){var n,r=Iu[t];if(r)n=new r(this.modelRequest,this.aiBaseUrl);else{var o="string"==typeof(null==e?void 0:e.defaultModelSubUrl)?e.defaultModelSubUrl:"/chat/completions";n=new ru(this.modelRequest,this.aiBaseUrl,"".concat(t).concat(o))}return new du(n)},t.prototype.registerModel=function(t,e){null==Iu[t]?Iu[t]=e:console.warn("AI model ".concat(t," already exists!"))},t.prototype.createImageModel=function(t){return new su(this.modelRequest,this.aiBaseUrl,t)},t.prototype.registerFunctionTool=function(t){vu.has(t.name)&&console.warn("AI function tool ".concat(t.name," already exists and will be overwritten!")),vu.set(t.name,t.fn)},t.prototype.resolveUrl=function(t){if(!this._getBaseUrl)return t;var e=this._getBaseUrl();return e!==this.baseUrl&&t.startsWith(this.baseUrl)?t.replace(this.baseUrl,e):t},t}(),Ou=function(){return Ou=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ou.apply(this,arguments)},Tu=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n};function Au(t){var e=t.env,n=t.baseUrl,r=t.getBaseUrl,o=t.req,i=t.getAccessToken,s=t.handleReqInstance,a=t.i18n;return new Su(function(){if(null==s){if(null==i)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return function(t){var e=t.getAccessToken,n=t.req;return{download:n.download,post:n.post,upload:n.upload,fetch:function(t){return r=void 0,o=void 0,s=function(){var r,o,i,s,a;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(c){switch(c.label){case 0:if("function"!=typeof n.fetch)throw new Error("req.fetch is not a function");return r=t.token,o=t.headers,i=void 0===o?{}:o,s=Tu(t,["token","headers"]),null==r?[3,1]:(a=r,[3,3]);case 1:return[4,e()];case 2:a=c.sent().accessToken,c.label=3;case 3:return[2,n.fetch(Ou({headers:Ou({Authorization:"Bearer ".concat(a)},i)},s))]}})},new((i=void 0)||(i=Promise))(function(t,e){function n(t){try{c(s.next(t))}catch(t){e(t)}}function a(t){try{c(s.throw(t))}catch(t){e(t)}}function c(e){var r;e.done?t(e.value):(r=e.value,r instanceof i?r:new i(function(t){t(r)})).then(n,a)}c((s=s.apply(r,o||[])).next())});var r,o,i,s}}}({req:o,getAccessToken:i})}return s({req:o})}(),function(){if(null!=r)return r();if(null!=n)return n;if(null==e)throw new Error("`env` is required when `baseUrl` is not provided!");return"https://".concat(e,".api.tcloudbasegateway.com/v1")}(),a,r)}Tu(c,["MODELS"]);var Pu={name:"ai",entity:{ai:function(t){var e=this,n=this.request;if(null==n.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");var r=function(){var t=e.getEndPointWithKey("GATEWAY"),n=t.BASE_URL,r=t.PROTOCOL;return"".concat(r).concat(n)};return(null==t?void 0:t.baseUrl)?Au({req:n,baseUrl:t.baseUrl,handleReqInstance:function(t){return t.req},i18n:this.config.i18n}):Au({req:n,baseUrl:r(),getBaseUrl:r,handleReqInstance:function(t){return t.req},i18n:this.config.i18n})}}};function Ru(t){try{t.registerComponent(Pu)}catch(t){console.warn(t)}}try{window.registerAi=Ru}catch(t){}var Cu=function(){return Cu=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Cu.apply(this,arguments)};function ku(t){if(!t)return{get:function(){return null},forEach:function(){}};if("function"==typeof t.get)return t;var e={};return Object.keys(t).forEach(function(n){e[n.toLowerCase()]=t[n]}),{get:function(t){var n;return null!==(n=e[t.toLowerCase()])&&void 0!==n?n:null},forEach:function(t){Object.entries(e).forEach(function(e){var n=e[0],r=e[1];return t(r,n)})}}}function Nu(t,e,n){var r=this,o=t.request.fetch.bind(t.request),i=e||{},s=i.instance,a=void 0===s?n?void 0:"default":s,c=i.database,u=void 0===c?n?void 0:t.config.env:c,l=t.getEndPointWithKey("GATEWAY"),h=l.BASE_URL,d=l.PROTOCOL,f="".concat(d).concat(h),p=function(e,n){return i=r,s=void 0,l=function(){var r,i,s,c,l,h,d,p,v,y;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(g){switch(g.label){case 0:return r={},n.headers instanceof Headers?n.headers.forEach(function(t,e){r[e]=t}):n.headers&&Object.assign(r,n.headers),[["X-Db-Instance",a],["Accept-Profile",u],["Content-Profile",u]].forEach(function(t){var e=t[0],n=t[1];r[e]||r[e.toLocaleLowerCase()]||!n||(r[e]=n)}),i=e.toString(),s=t.getEndPointWithKey("GATEWAY"),c=s.BASE_URL,l=s.PROTOCOL,(h="".concat(l).concat(c))!==f&&i.startsWith(f)&&(i=i.replace(f,h)),[4,o(Cu(Cu({url:i},n),{headers:Cu({"Content-Type":"application/json"},r),shouldThrowOnError:!1}))];case 1:d=g.sent(),p={},g.label=2;case 2:return g.trys.push([2,4,,5]),[4,d.data];case 3:return p=g.sent(),[3,5];case 4:if(v=g.sent(),!(null===(y=null==v?void 0:v.message)||void 0===y?void 0:y.includes("Unexpected end of JSON input")))throw v;return[3,5];case 5:return[2,{ok:(null==d?void 0:d.statusCode)>=200&&(null==d?void 0:d.statusCode)<300,status:(null==d?void 0:d.statusCode)||200,statusText:(null==d?void 0:d.statusMessage)||"OK",json:function(){return Promise.resolve(p||{})},text:function(){return Promise.resolve("string"==typeof p?p:JSON.stringify(p||{}))},headers:ku(null==d?void 0:d.header)}]}})},new((c=void 0)||(c=Promise))(function(t,e){function n(t){try{o(l.next(t))}catch(t){e(t)}}function r(t){try{o(l.throw(t))}catch(t){e(t)}}function o(e){var o;e.done?t(e.value):(o=e.value,o instanceof c?o:new c(function(t){t(o)})).then(n,r)}o((l=l.apply(i,s||[])).next())});var i,s,c,l},v="".concat(d).concat(h,"/rdb/rest");return n?(0,Aa.generatePGClient)(t,{pgBaseUrl:v,fetch:p}):(0,Aa.generateMySQLClient)(t,{mysqlBaseUrl:v,fetch:p})}var xu={name:"mysql",entity:{mysql:function(t){return Nu(this,t,!1)(t)}}},Uu={name:"rdb",entity:{rdb:function(t){return Nu(this,t,!0)(t)}}};try{cloudbase.registerComponent(xu),cloudbase.registerComponent(Uu)}catch(t){}function Lu(t){try{t.registerComponent(xu),t.registerComponent(Uu)}catch(t){console.warn(t)}}try{window.registerMySQL=Lu}catch(t){}var Du=function(){return Du=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Du.apply(this,arguments)},ju=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},qu=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Mu(t,e){var n,r,o,i;return ju(this,void 0,Promise,function(){var s,a,c,u,l,h,d,f,p,v,y,g,m,b,w,_,E,I,S,O,T,A,P;return qu(this,function(R){switch(R.label){case 0:a=(s=t||{}).name,c=s.body,u=s.path,l=void 0===u?"":u,h=s.method,d=void 0===h?"POST":h,f=s.headers,p=void 0===f?{}:f,v=(t||{}).token,y={};try{y=JSON.parse(c)}catch(t){y=c||{}}if(!a)throw new Error(JSON.stringify({code:Cn.ERRORS.INVALID_PARAMS,msg:"[apis] invalid api name"}));return g="",b=(m=this).gatewayOrigin,w=m.getAccessToken,_=m.env,b?g="".concat(b,"/v1"):this.getEndPointWithKey?(E=this.getEndPointWithKey("GATEWAY"),I=E.BASE_URL,S=E.PROTOCOL,g="".concat(S).concat(I)):g="https://".concat(_,".api.tcloudbasegateway.com/v1"),O="".concat(g,"/apis/").concat(a),T=l.startsWith("/")?l:"/".concat(l),w?[4,w()]:[3,2];case 1:A=R.sent().accessToken,p.Authorization="Bearer ".concat(A),R.label=2;case 2:if(P=["GET","HEAD"].includes(null===(n=null==d?void 0:d.toUpperCase)||void 0===n?void 0:n.call(d)))try{T="".concat(T).concat(T.includes("?")?"&":"?").concat(Object.keys(y).map(function(t){return"".concat(t,"=").concat(y[t])}).join("&"))}catch(t){}return[4,this.request.fetch(Du(Du(Du({url:"".concat(O).concat(T),method:d||"POST",headers:Du({"Content-Type":"application/json; charset=utf-8"},p)},P?{}:{body:JSON.stringify(y)}),{token:(null===(r=null==v?void 0:v.trim)||void 0===r?void 0:r.call(v))||(null===(i=null===(o=p.Authorization)||void 0===o?void 0:o.replace)||void 0===i?void 0:i.call(o,/^Bearer /,""))||null}),e))];case 3:return[4,R.sent().data];case 4:return[2,R.sent()]}})})}var Bu=["GET","POST","PUT","DELETE","HEAD","OPTIONS","PATCH","REQUEST"];function Wu(t){var e=this;return new Proxy({},{get:function(n,r){if("string"!=typeof r)throw new Error("[apis] method must be string");var o=r.toLocaleUpperCase();if(!Bu.includes(o))throw new Error("[apis] invalid method: ".concat(r));return function(n,r){return ju(e,void 0,void 0,function(){return qu(this,function(e){switch(e.label){case 0:return[4,Mu.call(this,Du({name:t,method:("REQUEST"===o?n.method:o)||"POST"},n),r)];case 1:return[2,e.sent()]}})})}}})}function Fu(t){var e=this;return Object.keys(t||{}).forEach(function(n){void 0!==t[n]&&(e[n]=t[n])}),new Proxy({},{get:function(t,n){if("string"==typeof n)return Wu.call(e,n)}})}var Hu,Vu,Gu="apis",Ku={name:Gu,IIFE:!0,entity:function(){Object.defineProperty(this.prototype,Gu,{get:function(){return Fu.call(this)},configurable:!0,enumerable:!0})}};function Ju(t){try{t.registerComponent(Ku)}catch(t){console.warn(t)}}try{cloudbase.registerComponent(Ku)}catch(t){}try{window.registerApis=Ju}catch(t){}!function(t){t.DocIDError="文档ID不合法",t.CollNameError="集合名称不合法",t.OpStrError="操作符不合法",t.DirectionError="排序字符不合法",t.IntergerError="must be integer",t.BooleanError="must be boolean",t.ArrayError="must be array",t.QueryParamTypeError="查询参数必须为对象",t.QueryParamValueError="查询参数对象值不能均为undefined",t.CentersPhereError="centersPhere结构不合法"}(Vu||(Vu={}));var zu,$u,Yu="Object",Qu="GeoPoint",Xu="GeoLineString",Zu="GeoPolygon",tl="GeoMultiPoint",el="GeoMultiLineString",nl="GeoMultiPolygon",rl="Date",ol="ServerDate",il=["desc","asc"],sl=["<","<=","==",">=",">"];!function(t){t.lt="<",t.gt=">",t.lte="<=",t.gte=">=",t.eq="=="}(zu||(zu={})),(Hu={})[zu.eq]="$eq",Hu[zu.lt]="$lt",Hu[zu.lte]="$lte",Hu[zu.gt]="$gt",Hu[zu.gte]="$gte",function(t){t.WHERE="WHERE",t.DOC="DOC"}($u||($u={}));var al=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),cl=[],ul={},ll=function(t){function e(e,n){if(n!==ul)throw new TypeError("InternalSymbol cannot be constructed with new operator");return t.call(this,e)||this}return al(e,t),e.for=function(t){for(var n=0,r=cl.length;n<r;n++)if(cl[n].target===t)return cl[n].instance;var o=new e(t,ul);return cl.push({target:t,instance:o}),o},e}(function(t){Object.defineProperties(this,{target:{enumerable:!1,writable:!1,configurable:!1,value:t}})});const hl=ll;var dl=hl.for("UNSET_FIELD_NAME"),fl=hl.for("UPDATE_COMMAND"),pl=hl.for("QUERY_COMMAND"),vl=hl.for("LOGIC_COMMAND"),yl=hl.for("GEO_POINT"),gl=hl.for("SYMBOL_GEO_LINE_STRING"),ml=hl.for("SYMBOL_GEO_POLYGON"),bl=hl.for("SYMBOL_GEO_MULTI_POINT"),wl=hl.for("SYMBOL_GEO_MULTI_LINE_STRING"),_l=hl.for("SYMBOL_GEO_MULTI_POLYGON"),El=hl.for("SERVER_DATE"),Il=hl.for("REGEXP"),Sl=hl.for("OBJECTID"),Ol=function(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()},Tl=function(t){return"object"===Ol(t)},Al=function(t){return"number"===Ol(t)},Pl=function(t){return Array.isArray(t)},Rl=function(t){return"date"===Ol(t)},Cl=function(t){return"regexp"===Ol(t)},kl=function(t){return t&&t._internalType instanceof ll},Nl=function(){function t(t){if(!Pl(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(t.length<2)throw new Error('"points" must contain 2 points at least');t.forEach(function(t){if(!(t instanceof uh))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"LineString",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("LineString"!==t.type||!Pl(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!Al(i[0])||!Al(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},t.isClosed=function(t){var e=t.points[0],n=t.points[t.points.length-1];if(e.latitude===n.latitude&&e.longitude===n.longitude)return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return gl},enumerable:!1,configurable:!0}),t}(),xl=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ul=function(){function t(t){if(!Pl(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof Nl))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"));if(!Nl.isClosed(t))throw new Error("LineString ".concat(t.points.map(function(t){return t.toReadableString()})," is not a closed cycle"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"Polygon",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("Polygon"!==t.type||!Pl(t.coordinates))return!1;try{for(var i=xl(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;if(!this.isCloseLineString(a))return!1;try{for(var c=(r=void 0,xl(a)),u=c.next();!u.done;u=c.next()){var l=u.value;if(!Al(l[0])||!Al(l[1]))return!1}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},t.isCloseLineString=function(t){var e=t[0],n=t[t.length-1];return e[0]===n[0]&&e[1]===n[1]},Object.defineProperty(t.prototype,"_internalType",{get:function(){return ml},enumerable:!1,configurable:!0}),t}(),Ll=function(){function t(t){if(!Pl(t))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t));if(0===t.length)throw new Error('"points" must contain 1 point at least');t.forEach(function(t){if(!(t instanceof uh))throw new TypeError('"points" must be of type Point[]. Received type '.concat(typeof t,"[]"))}),this.points=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})},e},t.prototype.toJSON=function(){return{type:"MultiPoint",coordinates:this.points.map(function(t){return t.toJSON().coordinates})}},t.validate=function(t){var e,n;if("MultiPoint"!==t.type||!Pl(t.coordinates))return!1;try{for(var r=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(t.coordinates),o=r.next();!o.done;o=r.next()){var i=o.value;if(!Al(i[0])||!Al(i[1]))return!1}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return bl},enumerable:!1,configurable:!0}),t}(),Dl=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},jl=function(){function t(t){if(!Pl(t))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("Polygon must contain 1 linestring at least");t.forEach(function(t){if(!(t instanceof Nl))throw new TypeError('"lines" must be of type LineString[]. Received type '.concat(typeof t,"[]"))}),this.lines=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})},e},t.prototype.toJSON=function(){return{type:"MultiLineString",coordinates:this.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})}},t.validate=function(t){var e,n,r,o;if("MultiLineString"!==t.type||!Pl(t.coordinates))return!1;try{for(var i=Dl(t.coordinates),s=i.next();!s.done;s=i.next()){var a=s.value;try{for(var c=(r=void 0,Dl(a)),u=c.next();!u.done;u=c.next()){var l=u.value;if(!Al(l[0])||!Al(l[1]))return!1}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return wl},enumerable:!1,configurable:!0}),t}(),ql=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ml=function(){function t(t){var e,n;if(!Pl(t))throw new TypeError('"polygons" must be of type Polygon[]. Received type '.concat(typeof t));if(0===t.length)throw new Error("MultiPolygon must contain 1 polygon at least");try{for(var r=ql(t),o=r.next();!o.done;o=r.next()){var i=o.value;if(!(i instanceof Ul))throw new TypeError('"polygon" must be of type Polygon[]. Received type '.concat(typeof i,"[]"))}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}this.polygons=t}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})},e},t.prototype.toJSON=function(){return{type:"MultiPolygon",coordinates:this.polygons.map(function(t){return t.lines.map(function(t){return t.points.map(function(t){return[t.longitude,t.latitude]})})})}},t.validate=function(t){var e,n,r,o,i,s;if("MultiPolygon"!==t.type||!Pl(t.coordinates))return!1;try{for(var a=ql(t.coordinates),c=a.next();!c.done;c=a.next()){var u=c.value;try{for(var l=(r=void 0,ql(u)),h=l.next();!h.done;h=l.next()){var d=h.value;try{for(var f=(i=void 0,ql(d)),p=f.next();!p.done;p=f.next()){var v=p.value;if(!Al(v[0])||!Al(v[1]))return!1}}catch(t){i={error:t}}finally{try{p&&!p.done&&(s=f.return)&&s.call(f)}finally{if(i)throw i.error}}}}catch(t){r={error:t}}finally{try{h&&!h.done&&(o=l.return)&&o.call(l)}finally{if(r)throw r.error}}}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return!0},Object.defineProperty(t.prototype,"_internalType",{get:function(){return _l},enumerable:!1,configurable:!0}),t}(),Bl=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},Wl=function(){function t(){}return t.formatResDocumentData=function(e){return e.map(function(e){return t.formatField(e)})},t.formatField=function(e){var n=Object.keys(e),r={};return Array.isArray(e)&&(r=[]),n.forEach(function(n){var o,i=e[n];switch(t.whichType(i)){case Qu:o=new uh(i.coordinates[0],i.coordinates[1]);break;case Xu:o=new Nl(i.coordinates.map(function(t){return new uh(t[0],t[1])}));break;case Zu:o=new Ul(i.coordinates.map(function(t){return new Nl(t.map(function(t){var e=Bl(t,2),n=e[0],r=e[1];return new uh(n,r)}))}));break;case tl:o=new Ll(i.coordinates.map(function(t){return new uh(t[0],t[1])}));break;case el:o=new jl(i.coordinates.map(function(t){return new Nl(t.map(function(t){var e=Bl(t,2),n=e[0],r=e[1];return new uh(n,r)}))}));break;case nl:o=new Ml(i.coordinates.map(function(t){return new Ul(t.map(function(t){return new Nl(t.map(function(t){var e=Bl(t,2),n=e[0],r=e[1];return new uh(n,r)}))}))}));break;case rl:o=i;break;case Yu:case"Array":o=t.formatField(i);break;case ol:o=new Date(i.$date);break;default:o=i}Array.isArray(r)?r.push(o):r[n]=o}),r},t.whichType=function(t){var e=Object.prototype.toString.call(t).slice(8,-1);return e===rl?rl:(e===Yu&&(t.$date?e=ol:uh.validate(t)?e=Qu:Nl.validate(t)?e=Xu:Ul.validate(t)?e=Zu:Ll.validate(t)?e=tl:jl.validate(t)?e=el:Ml.validate(t)&&(e=nl)),e)},t.generateDocId=function(){for(var t="",e=0;e<24;e++)t+="ABCDEFabcdef0123456789".charAt(Math.floor(22*Math.random()));return t},t}(),Fl={code:"INVALID_PARAM",message:"Invalid request param"},Hl="DATABASE_TRANSACTION_CONFLICT",Vl={code:"DATABASE_REQUEST_FAILED",message:"database request failed"};const Gl=(t=>{var e={};return l.d(e,t),e})({EJSON:()=>a.EJSON});var Kl=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Jl=function(){return Jl=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Jl.apply(this,arguments)};function zl(t,e){if("function"!=typeof e)return t;t.then(function(t){return e(0,t)},function(t){return e(t)})}var $l={};function Yl(t){if(!hd.wsClientClass)throw new Error("to use realtime you must import realtime module first");var e=t.config.env;return $l[e]||($l[e]=new hd.wsClientClass({context:{appConfig:{docSizeLimit:1e3,realtimePingInterval:1e4,realtimePongWaitTimeout:5e3,request:hd.createRequest(t.config)}}})),$l[e]}var Ql=function(t){return void 0!==t.timeout?{timeout:t.timeout}:{}},Xl=function(t){if(!Tl(t))return t;for(var e in t)void 0===t[e]?delete t[e]:Tl(t[e])&&(t[e]=Xl(t[e]));return t},Zl=function(t){return t=Xl(t),Gl.EJSON.stringify(t,{relaxed:!1})},th=function(t){var e,n;if(t instanceof Date)return{$date:+t};if(t instanceof RegExp)return{$regex:t.source,$options:t.flags};if(t&&"object"==typeof t){if("ObjectId"===t._bsontype)return{$oid:t.toHexString()};if("BSONRegExp"===t._bsontype)return{$regex:t.pattern,$options:t.options};if(Array.isArray(t))return t.map(th);var r={};try{for(var o=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(Object.keys(t)),i=o.next();!i.done;i=o.next()){var s=i.value;r[s]=th(t[s])}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}return t},eh=function(t){if(!t)return"{}";try{var e=Gl.EJSON.parse(t);return JSON.stringify(th(e))}catch(e){return t}},nh=function(t){function e(e){var n=t.call(this,e.message)||this;return n.code=e.code,n.message=e.message,n}return Kl(e,t),e}(Error),rh=function(t){return new nh(t)};function oh(t,e){if(!1===t)return e;throw rh(Jl({},e))}var ih,sh=function(){return sh=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},sh.apply(this,arguments)},ah=["limit","offset","projection","order","multiple","timeout","raw"],ch=function(){function t(){}return t.isGeopoint=function(t,e){if("Number"!==Wl.whichType(e))throw new Error("Geo Point must be number type");var n=Math.abs(e);if("latitude"===t&&n>90)throw new Error("latitude should be a number ranges from -90 to 90");if("longitude"===t&&n>180)throw new Error("longitude should be a number ranges from -180 to 180");return!0},t.isInteger=function(t,e){if(!Number.isInteger(e))throw new Error(t+Vu.IntergerError);return!0},t.mustBeBoolean=function(t,e){if("boolean"!=typeof e)throw new Error(t+Vu.BooleanError);return!0},t.isProjection=function(t,e){if("object"!==Ol(e))throw rh(sh(sh({},Fl),{message:"".concat(t," projection must be an object")}));for(var n in e){var r=e[n];if("number"===Ol(r)){if(0!==r&&1!==r)throw rh(sh(sh({},Fl),{message:"if the value in projection is of number, it must be 0 or 1"}))}else if("object"!==Ol(r))throw rh(sh(sh({},Fl),{message:"invalid projection"}))}return!0},t.isOrder=function(t,e){if("object"!==Ol(e))throw rh(sh(sh({},Fl),{message:"".concat(t," order must be an object")}));for(var n in e){var r=e[n];if(1!==r&&-1!==r)throw rh(sh(sh({},Fl),{message:"order value must be 1 or -1"}))}return!0},t.isFieldOrder=function(t){if(-1===il.indexOf(t))throw new Error(Vu.DirectionError);return!0},t.isFieldPath=function(t){if(!/^[a-zA-Z0-9-_\.]/.test(t))throw new Error;return!0},t.isOperator=function(t){if(-1===sl.indexOf(t))throw new Error(Vu.OpStrError);return!0},t.isCollName=function(t){if(!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(t))throw new Error(Vu.CollNameError);return!0},t.isDocID=function(t){if(!/^([a-fA-F0-9]){24}$/.test(t))throw new Error(Vu.DocIDError);return!0},t.isValidOptions=function(e){if(void 0===e&&(e={}),"object"!==Ol(e))throw rh(sh(sh({},Fl),{message:"options must be an object"}));var n=Object.keys(e);for(var r in n)if(ah.indexOf(n[r])<0)throw rh(sh(sh({},Fl),{message:"".concat(n[r]," is invalid options key")}));var o=e,i=o.limit,s=o.offset,a=o.projection,c=o.order,u=e.multiple;return void 0!==i&&t.isInteger("limit",i),void 0!==s&&t.isInteger("offset",s),void 0!==a&&t.isProjection("projection",a),void 0!==c&&t.isOrder("order",c),void 0!==u&&t.mustBeBoolean("multiple",u),void 0!==e.timeout&&t.isInteger("timeout",e.timeout),!0},t.isValidAggregation=function(t){if(1!==Object.keys(t).length)throw rh(sh(sh({},Fl),{message:"aggregation stage must have one key"}));return!0},t.isCentersPhere=function(e){if(Array.isArray(e)&&2===e.length){if("object"===Ol(e[0])&&e[0]._internalType===yl&&"number"==typeof e[1])return!0;if(Array.isArray(e[0])&&2===e[0].length){var n=e[0][0],r=e[0][1];if(t.isGeopoint("longitude",n),t.isGeopoint("latitude",r),"number"==typeof e[1])return!0}}throw new Error("".concat(Vu.CentersPhereError))},t}(),uh=function(){function t(t,e){ch.isGeopoint("longitude",t),ch.isGeopoint("latitude",e),this.longitude=t,this.latitude=e}return t.prototype.parse=function(t){var e;return(e={})[t]={type:"Point",coordinates:[this.longitude,this.latitude]},e},t.prototype.toJSON=function(){return{type:"Point",coordinates:[this.longitude,this.latitude]}},t.prototype.toReadableString=function(){return"[".concat(this.longitude,",").concat(this.latitude,"]")},t.validate=function(t){return"Point"===t.type&&Pl(t.coordinates)&&ch.isGeopoint("longitude",t.coordinates[0])&&ch.isGeopoint("latitude",t.coordinates[1])},Object.defineProperty(t.prototype,"_internalType",{get:function(){return yl},enumerable:!1,configurable:!0}),t}();!function(t){t.SET="set",t.REMOVE="remove",t.INC="inc",t.MUL="mul",t.PUSH="push",t.PULL="pull",t.PULL_ALL="pullAll",t.POP="pop",t.SHIFT="shift",t.UNSHIFT="unshift",t.ADD_TO_SET="addToSet",t.BIT="bit",t.RENAME="rename",t.MAX="max",t.MIN="min"}(ih||(ih={}));var lh,hh=function(){function t(t,e,n){this._internalType=fl,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||dl}return t.prototype._setFieldName=function(e){return new t(this.operator,this.operands,e)},t}();function dh(t){return t&&t instanceof hh&&t._internalType===fl}!function(t){t.AND="and",t.OR="or",t.NOT="not",t.NOR="nor"}(lh||(lh={}));var fh=function(){function t(t,e,n){if(this._internalType=vl,Object.defineProperties(this,{_internalType:{enumerable:!1,configurable:!1}}),this.operator=t,this.operands=e,this.fieldName=n||dl,this.fieldName!==dl)if(Array.isArray(e)){e=e.slice(),this.operands=e;for(var r=0,o=e.length;r<o;r++)(ph(i=e[r])||mh(i))&&(e[r]=i._setFieldName(this.fieldName))}else{var i;(ph(i=e)||mh(i))&&(e=i._setFieldName(this.fieldName))}}return t.prototype._setFieldName=function(e){var n=this.operands.map(function(n){return n instanceof t?n._setFieldName(e):n});return new t(this.operator,n,e)},t.prototype.and=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(lh.AND,r,this.fieldName)},t.prototype.or=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments);return r.unshift(this),new t(lh.OR,r,this.fieldName)},t}();function ph(t){return t&&t instanceof fh&&t._internalType===vl}var vh,yh=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();!function(t){t.EQ="eq",t.NEQ="neq",t.GT="gt",t.GTE="gte",t.LT="lt",t.LTE="lte",t.IN="in",t.NIN="nin",t.ALL="all",t.ELEM_MATCH="elemMatch",t.EXISTS="exists",t.SIZE="size",t.MOD="mod",t.GEO_NEAR="geoNear",t.GEO_WITHIN="geoWithin",t.GEO_INTERSECTS="geoIntersects"}(vh||(vh={}));var gh=function(t){function e(e,n,r){var o=t.call(this,e,n,r)||this;return o.operator=e,o._internalType=pl,o}return yh(e,t),e.prototype.toJSON=function(){var t,e,n;switch(this.operator){case vh.IN:case vh.NIN:return(t={})["$"+this.operator]=this.operands,t;case vh.NEQ:return(e={}).$ne=this.operands[0],e;default:return(n={})["$"+this.operator]=this.operands[0],n}},e.prototype._setFieldName=function(t){return new e(this.operator,this.operands,t)},e.prototype.eq=function(t){var n=new e(vh.EQ,[t],this.fieldName);return this.and(n)},e.prototype.neq=function(t){var n=new e(vh.NEQ,[t],this.fieldName);return this.and(n)},e.prototype.gt=function(t){var n=new e(vh.GT,[t],this.fieldName);return this.and(n)},e.prototype.gte=function(t){var n=new e(vh.GTE,[t],this.fieldName);return this.and(n)},e.prototype.lt=function(t){var n=new e(vh.LT,[t],this.fieldName);return this.and(n)},e.prototype.lte=function(t){var n=new e(vh.LTE,[t],this.fieldName);return this.and(n)},e.prototype.in=function(t){var n=new e(vh.IN,t,this.fieldName);return this.and(n)},e.prototype.nin=function(t){var n=new e(vh.NIN,t,this.fieldName);return this.and(n)},e.prototype.geoNear=function(t){if(!(t.geometry instanceof uh))throw new TypeError('"geometry" must be of type Point. Received type '.concat(typeof t.geometry));if(void 0!==t.maxDistance&&!Al(t.maxDistance))throw new TypeError('"maxDistance" must be of type Number. Received type '.concat(typeof t.maxDistance));if(void 0!==t.minDistance&&!Al(t.minDistance))throw new TypeError('"minDistance" must be of type Number. Received type '.concat(typeof t.minDistance));var n=new e(vh.GEO_NEAR,[t],this.fieldName);return this.and(n)},e.prototype.geoWithin=function(t){if(!(t.geometry instanceof Ml||t.geometry instanceof Ul||ch.isCentersPhere(t.centerSphere)))throw new TypeError('"geometry" must be of type Polygon or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(vh.GEO_WITHIN,[t],this.fieldName);return this.and(n)},e.prototype.geoIntersects=function(t){if(!(t.geometry instanceof uh||t.geometry instanceof Nl||t.geometry instanceof Ul||t.geometry instanceof Ll||t.geometry instanceof jl||t.geometry instanceof Ml))throw new TypeError('"geometry" must be of type Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon. Received type '.concat(typeof t.geometry));var n=new e(vh.GEO_INTERSECTS,[t],this.fieldName);return this.and(n)},e}(fh);function mh(t){return t&&t instanceof gh&&t._internalType===pl}function bh(t){return mh(t)}var wh={};for(var _h in vh)wh[_h]="$"+_h;for(var _h in lh)wh[_h]="$"+_h;for(var _h in ih)wh[_h]="$"+_h;function Eh(t){return wh[t]||"$"+t}wh[vh.NEQ]="$ne",wh[ih.REMOVE]="$unset",wh[ih.SHIFT]="$pop",wh[ih.UNSHIFT]="$push";var Ih=function(){return Ih=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ih.apply(this,arguments)},Sh=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},Oh=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Th(t){return Ah(t,[t])}function Ah(t,e){if(!kl(t)){if(Rl(t))return t;if(Cl(t))return{$regularExpression:{pattern:t.source,options:t.flags}};if(Pl(t))return t.map(function(t){if(e.indexOf(t)>-1)throw new Error("Cannot convert circular structure to JSON");return Ah(t,Oh(Oh([],Sh(e),!1),[t],!1))});if(Tl(t)){var n=Ih({},t),r={};for(var o in n){if(e.indexOf(n[o])>-1)throw new Error("Cannot convert circular structure to JSON");void 0!==n[o]&&(r[o]=Ah(n[o],Oh(Oh([],Sh(e),!1),[n[o]],!1)))}return r}return t}switch(t._internalType){case yl:return t.toJSON();case El:case Il:case Sl:return t.parse();default:return t.toJSON?t.toJSON():t}}var Ph=function(){return Ph=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ph.apply(this,arguments)},Rh=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},Ch=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function kh(t,e,n,r){var o=Ph({},t);for(var i in t)if(!/^\$/.test(i)){var s=t[i];if(void 0!==s){if(s&&Tl(s)&&!e(s)){if(r.indexOf(s)>-1)throw new Error("Cannot convert circular structure to JSON");var a=kh(s,e,Ch(Ch([],Rh(n),!1),[i],!1),Ch(Ch([],Rh(r),!1),[s],!1));o[i]=a;var c=!1;for(var u in a)/^\$/.test(u)?c=!0:(o["".concat(i,".").concat(u)]=a[u],delete o[i][u]);c||delete o[i]}}else delete o[i]}return o}function Nh(t){return kh(t,Uh,[],[t])}function xh(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?Pl(t[r])?t[r].push(e[r]):Tl(t[r])?Tl(e[r])?Object.assign(t[r],e[r]):(console.warn("unmergable condition, query is object but condition is ".concat(Ol(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(Ol(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]}function Uh(t){return kl(t)||Rl(t)||Cl(t)}function Lh(t){return Th(t)}var Dh=function(){function t(){}return t.encode=function(e){return(new t).encodeUpdate(e)},t.encodeEJSON=function(e,n){var r=new t;return Zl(n?e:r.encodeUpdate(e))},t.prototype.encodeUpdate=function(t){return dh(t)?this.encodeUpdateCommand(t):"object"===Ol(t)?this.encodeUpdateObject(t):t},t.prototype.encodeUpdateCommand=function(t){if(t.fieldName===dl)throw new Error("Cannot encode a comparison command with unset field name");switch(t.operator){case ih.PUSH:case ih.PULL:case ih.PULL_ALL:case ih.POP:case ih.SHIFT:case ih.UNSHIFT:case ih.ADD_TO_SET:return this.encodeArrayUpdateCommand(t);default:return this.encodeFieldUpdateCommand(t)}},t.prototype.encodeFieldUpdateCommand=function(t){var e,n,r,o,i=Eh(t.operator);return t.operator===ih.REMOVE?((e={})[i]=((n={})[t.fieldName]="",n),e):((r={})[i]=((o={})[t.fieldName]=t.operands[0],o),r)},t.prototype.encodeArrayUpdateCommand=function(t){var e,n,r,o,i,s,a,c,u,l,h=Eh(t.operator);switch(t.operator){case ih.PUSH:var d=void 0;return d=Pl(t.operands)?{$each:t.operands.map(Lh)}:t.operands,(e={})[h]=((n={})[t.fieldName]=d,n),e;case ih.UNSHIFT:return d={$each:t.operands.map(Lh),$position:0},(r={})[h]=((o={})[t.fieldName]=d,o),r;case ih.POP:return(i={})[h]=((s={})[t.fieldName]=1,s),i;case ih.SHIFT:return(a={})[h]=((c={})[t.fieldName]=-1,c),a;default:return(u={})[h]=((l={})[t.fieldName]=Lh(t.operands),l),u}},t.prototype.encodeUpdateObject=function(t){var e=Nh(t);for(var n in e)if(!/^\$/.test(n)){var r=e[n];if(dh(r))e[n]=r._setFieldName(n),xh(e,this.encodeUpdateCommand(e[n]),n);else{e[n]=r=Lh(r);var o=new hh(ih.SET,[r],n);xh(e,this.encodeUpdateCommand(o),n)}}return e},t}(),jh=function(){return jh=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},jh.apply(this,arguments)},qh=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Mh=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Bh=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){return Yl(i._db).watch(jh(jh({},t),{envId:i._db.config.env,collectionName:i._coll,query:JSON.stringify({_id:i.id})}))},this._db=t,this._coll=e,this.id=r,this._transactionId=o,this.request=hd.createRequest(this._db.config),this._apiOptions=n}return t.prototype.create=function(t,e){return zl(this._create(t),e)},t.prototype._create=function(t){return qh(this,void 0,void 0,function(){var e,n,r;return Mh(this,function(o){switch(o.label){case 0:return!(e=Array.isArray(t))&&this.id&&(t._id=this.id),n={collectionName:this._coll,data:e?t.map(function(t){return Zl(Th(t))}):[Zl(Th(t))],transactionId:this._transactionId},[4,this.request.send("database.insertDocument",n,Ql(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:e?[2,{ids:r.data&&r.data.insertedIds||[],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})})},t.prototype.set=function(t,e){return zl(this._set(t),e)},t.prototype._set=function(t){return qh(this,void 0,void 0,function(){var e,n,r,o;return Mh(this,function(i){switch(i.label){case 0:return this.id?t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,oh(this._db.config.throwOnCode,jh(jh({},Fl),{message:"不能更新_id的值"}))]:(e=!1,n=function(t){if("object"==typeof t)for(var r in t)t[r]instanceof hh?e=!0:"object"==typeof t[r]&&n(t[r])},n(t),e?[2,oh(this._db.config.throwOnCode,jh(jh({},Vl),{message:"update operator complicit"}))]:(r={collectionName:this._coll,queryType:$u.DOC,data:Zl(Th(t)),transactionId:this._transactionId,multi:!1,merge:!1,upsert:!0},this.id&&(r.query=Zl({_id:this.id})),[4,this.request.send("database.modifyDocument",r,Ql(this._apiOptions))])):[2,oh(this._db.config.throwOnCode,jh(jh({},Fl),{message:"参数必需是非空对象"}))]:[2,oh(this._db.config.throwOnCode,jh(jh({},Fl),{message:"docId不能为空"}))];case 1:return(o=i.sent()).code?[2,o]:this._transactionId?[2,{updated:o.data.updated,upserted:[{_id:o.data.upsert_id}],requestId:o.requestId}]:[2,{updated:o.data.updated,upsertedId:o.data.upsert_id,requestId:o.requestId}]}})})},t.prototype.update=function(t,e){return zl(this._update(t),e)},t.prototype._update=function(t){return qh(this,void 0,void 0,function(){var e,n,r;return Mh(this,function(o){switch(o.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,oh(this._db.config.throwOnCode,jh(jh({},Fl),{message:"不能更新_id的值"}))]:(e=Zl({_id:this.id}),n={collectionName:this._coll,transactionId:this._transactionId,data:Dh.encodeEJSON(t,this._apiOptions.raw||!1),query:e,queryType:$u.DOC,multi:!1,merge:!0,upsert:!1},[4,this.request.send("database.modifyDocument",n,Ql(this._apiOptions))]):[2,oh(this._db.config.throwOnCode,jh(jh({},Fl),{message:"参数必需是非空对象"}))];case 1:return(r=o.sent()).code?[2,r]:[2,{updated:r.data.updated,requestId:r.requestId}]}})})},t.prototype.delete=function(t){return this.remove(t)},t.prototype.remove=function(t){return zl(this._remove(),t)},t.prototype._remove=function(){return qh(this,void 0,void 0,function(){var t,e,n;return Mh(this,function(r){switch(r.label){case 0:return t=Zl({_id:this.id}),e={collectionName:this._coll,transactionId:this._transactionId,query:t,queryType:$u.DOC,multi:!1},[4,this.request.send("database.removeDocument",e,Ql(this._apiOptions))];case 1:return(n=r.sent()).code?[2,n]:[2,{deleted:n.data.deleted,requestId:n.requestId}]}})})},t.prototype.get=function(t){return zl(this._get(),t)},t.prototype._get=function(){return qh(this,void 0,void 0,function(){var t,e,n,r,o,i;return Mh(this,function(s){switch(s.label){case 0:return t=Zl({_id:this.id}),e=this._apiOptions.projection,n={collectionName:this._coll,query:t,transactionId:this._transactionId,queryType:$u.DOC,multi:!1},e&&(n.projection=Zl(e)),[4,this.request.send("database.getDocument",n,Ql(this._apiOptions))];case 1:return(r=s.sent()).code?[2,r]:(o=r.data.list.map(function(t){return Gl.EJSON.parse(t)}),i=Wl.formatResDocumentData(o),this._transactionId?[2,{data:i[0]||null,requestId:r.requestId}]:[2,{data:i,requestId:r.requestId}])}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=jh({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,o,this.id,this._transactionId)},t}(),Wh=function(){function t(){}return t.encode=function(t){return(new Fh).encodeQuery(t)},t.encodeEJSON=function(t,e){var n=new Fh;return Zl(e?t:n.encodeQuery(t))},t}(),Fh=function(){function t(){}return t.prototype.encodeQuery=function(t,e){var n,r,o;return Uh(t)?ph(t)?this.encodeLogicCommand(t):mh(t)?this.encodeQueryCommand(t):Cl(t)?((n={})[e]=this.encodeRegExp(t),n):Rl(t)?((r={})[e]=Lh(t),r):((o={})[e]=this.encodeQueryObject(t),o):Tl(t)?this.encodeQueryObject(t):t},t.prototype.encodeRegExp=function(t){return{$regularExpression:{pattern:t.source,options:t.flags}}},t.prototype.encodeLogicCommand=function(t){var e,n,r,o,i,s,a,c=this;switch(t.operator){case lh.NOR:case lh.AND:case lh.OR:var u=Eh(t.operator),l=t.operands.map(function(e){return c.encodeQuery(e,t.fieldName)});return(e={})[u]=l,e;case lh.NOT:u=Eh(t.operator);var h=t.operands[0];return Cl(h)?((n={})[t.fieldName]=((r={})[u]=this.encodeRegExp(h),r),n):(l=this.encodeQuery(h)[t.fieldName],(o={})[t.fieldName]=((i={})[u]=l,i),o);default:if(u=Eh(t.operator),1===t.operands.length){var d=this.encodeQuery(t.operands[0]);return(s={})[u]=d,s}return l=t.operands.map(this.encodeQuery.bind(this)),(a={})[u]=l,a}},t.prototype.encodeQueryCommand=function(t){return bh(t),this.encodeComparisonCommand(t)},t.prototype.encodeComparisonCommand=function(t){var e,n,r,o,i,s,a,c,u,l,h;if(t.fieldName===dl)throw new Error("Cannot encode a comparison command with unset field name");var d=Eh(t.operator);switch(t.operator){case vh.EQ:case vh.NEQ:case vh.LT:case vh.LTE:case vh.GT:case vh.GTE:case vh.ELEM_MATCH:case vh.EXISTS:case vh.SIZE:case vh.MOD:return(e={})[t.fieldName]=((n={})[d]=Lh(t.operands[0]),n),e;case vh.IN:case vh.NIN:case vh.ALL:return(r={})[t.fieldName]=((o={})[d]=Lh(t.operands),o),r;case vh.GEO_NEAR:var f=t.operands[0];return(i={})[t.fieldName]={$nearSphere:{$geometry:f.geometry.toJSON(),$maxDistance:f.maxDistance,$minDistance:f.minDistance}},i;case vh.GEO_WITHIN:if((f=t.operands[0]).centerSphere){ch.isCentersPhere(f.centerSphere);var p=f.centerSphere;return p[0]._internalType===yl?((s={})[t.fieldName]={$geoWithin:{$centerSphere:[p[0].toJSON().coordinates,p[1]]}},s):((a={})[t.fieldName]={$geoWithin:{$centerSphere:f.centerSphere}},a)}return(c={})[t.fieldName]={$geoWithin:{$geometry:f.geometry.toJSON()}},c;case vh.GEO_INTERSECTS:return f=t.operands[0],(u={})[t.fieldName]={$geoIntersects:{$geometry:f.geometry.toJSON()}},u;default:return(l={})[t.fieldName]=((h={})[d]=Lh(t.operands[0]),h),l}},t.prototype.encodeQueryObject=function(t){var e=Nh(t);for(var n in e){var r=e[n];if(ph(r)){e[n]=r._setFieldName(n);var o=this.encodeLogicCommand(e[n]);this.mergeConditionAfterEncode(e,o,n)}else bh(r)?(e[n]=r._setFieldName(n),o=this.encodeComparisonCommand(e[n]),this.mergeConditionAfterEncode(e,o,n)):Uh(r)&&(e[n]=Lh(r))}return e},t.prototype.mergeConditionAfterEncode=function(t,e,n){for(var r in e[n]||delete t[n],e)t[r]?Pl(t[r])?t[r]=t[r].concat(e[r]):Tl(t[r])?Tl(e[r])?Object.assign(t,e):(console.warn("unmergable condition, query is object but condition is ".concat(Ol(e),", can only overwrite"),e,n),t[r]=e[r]):(console.warn("to-merge query is of type ".concat(Ol(t),", can only overwrite"),t,e,n),t[r]=e[r]):t[r]=e[r]},t}(),Hh=function(){return Hh=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Hh.apply(this,arguments)},Vh=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},Gh=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Kh=function(){function t(t,e,n,r,o){var i=this;this.watch=function(t){var e=Yl(i._db),n=i._apiOptions,r=n.limit,o=n.order,s=o?Object.entries(o).reduce(function(t,e){var n=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(e,2),r=n[0],o=n[1];return t[r]=-1===o?"desc":"asc",t},{}):void 0;return e.watch(Hh(Hh({},t),{envId:i._db.config.env,collectionName:i._coll,query:eh(i._fieldFilters),limit:r,orderBy:s}))},this._db=t,this._coll=e,this._fieldFilters=n,this._apiOptions=r||{},this._request=hd.createRequest(this._db.config),this._transactionId=o}return t.prototype.get=function(t){return zl(this._get(),t)},t.prototype._get=function(){return Vh(this,void 0,void 0,function(){var t,e,n,r,o,i,s,a,c;return Gh(this,function(u){switch(u.label){case 0:return t=this._apiOptions.order,e={collectionName:this._coll,queryType:$u.WHERE,transactionId:this._transactionId},this._fieldFilters&&(e.query=this._fieldFilters),t&&(e.order=Zl(t)),(n=this._apiOptions.offset)&&(e.offset=n),r=this._apiOptions.limit,e.limit=r?r<1e3?r:1e3:100,(o=this._apiOptions.projection)&&(e.projection=Zl(o)),[4,this._request.send("database.getDocument",e,Ql(this._apiOptions))];case 1:return(i=u.sent()).code?[2,i]:(s=i.data.list.map(function(t){return Gl.EJSON.parse(t)}),a=Wl.formatResDocumentData(s),c={data:a,requestId:i.requestId},i.total&&(c.total=i.total),i.limit&&(c.limit=i.limit),i.offset&&(c.offset=i.offset),[2,c])}})})},t.prototype.count=function(t){return zl(this._count(),t)},t.prototype._count=function(){return Vh(this,void 0,void 0,function(){var t,e;return Gh(this,function(n){switch(n.label){case 0:return t={collectionName:this._coll,queryType:$u.WHERE},this._fieldFilters&&(t.query=this._fieldFilters),[4,this._request.send("database.calculateDocument",t,Ql(this._apiOptions))];case 1:return(e=n.sent()).code?[2,e]:[2,{requestId:e.requestId,total:e.data.total}]}})})},t.prototype.where=function(e){if("Object"!==Object.prototype.toString.call(e).slice(8,-1))throw Error(Vu.QueryParamTypeError);var n=Object.keys(e),r=n.some(function(t){return void 0!==e[t]});if(n.length&&!r)throw Error(Vu.QueryParamValueError);return new t(this._db,this._coll,Wh.encodeEJSON(e,this._apiOptions.raw||!1),this._apiOptions,this._transactionId)},t.prototype.options=function(e){return ch.isValidOptions(e),new t(this._db,this._coll,this._fieldFilters,e,this._transactionId)},t.prototype.orderBy=function(e,n){var r;ch.isFieldPath(e),ch.isFieldOrder(n);var o=((r={})[e]="desc"===n?-1:1,r),i=this._apiOptions.order||{},s=Object.assign({},this._apiOptions,{order:Object.assign({},i,o)});return new t(this._db,this._coll,this._fieldFilters,s,this._transactionId)},t.prototype.limit=function(e){ch.isInteger("limit",e);var n=Hh({},this._apiOptions);return n.limit=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.skip=function(e){ch.isInteger("offset",e);var n=Hh({},this._apiOptions);return n.offset=e,new t(this._db,this._coll,this._fieldFilters,n,this._transactionId)},t.prototype.update=function(t,e){return zl(this._update(t),e)},t.prototype._update=function(t){return Vh(this,void 0,void 0,function(){var e,n,r,o;return Gh(this,function(i){switch(i.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,oh(this._db.config.throwOnCode,Hh(Hh({},Fl),{message:"不能更新_id的值"}))]:(e=this._apiOptions.multiple,n=void 0===e||e,r={collectionName:this._coll,queryType:$u.WHERE,multi:n,merge:!0,upsert:!1,data:Dh.encodeEJSON(t,this._apiOptions.raw||!1)},this._transactionId&&(r.transactionId=this._transactionId),this._fieldFilters&&(r.query=this._fieldFilters),[4,this._request.send("database.modifyDocument",r,Ql(this._apiOptions))]):[2,oh(this._db.config.throwOnCode,Hh(Hh({},Fl),{message:"参数必需是非空对象"}))];case 1:return(o=i.sent()).code?[2,o]:[2,{requestId:o.requestId,updated:o.data.updated,upsertId:o.data.upsert_id}]}})})},t.prototype.field=function(e){var n={};for(var r in e)"boolean"==typeof e[r]&&(n[r]=!0===e[r]?1:0),"number"==typeof e[r]&&(n[r]=e[r]>0?1:0),"object"==typeof e[r]&&(n[r]=e[r]);var o=Hh({},this._apiOptions);return o.projection=n,new t(this._db,this._coll,this._fieldFilters,o,this._transactionId)},t.prototype.remove=function(t){return zl(this._remove(),t)},t.prototype._remove=function(){return Vh(this,void 0,void 0,function(){var t,e,n,r,o,i,s,a,c;return Gh(this,function(u){switch(u.label){case 0:return t=this._apiOptions,e=t.offset,n=t.limit,r=t.projection,o=t.order,void 0===e&&void 0===n&&void 0===r&&void 0===o||console.warn("`offset`, `limit`, `projection`, `orderBy` are not supported in remove() operation"),i=this._apiOptions.multiple,s=void 0===i||i,a={collectionName:this._coll,query:this._fieldFilters,queryType:$u.WHERE,multi:s},this._transactionId&&(a.transactionId=this._transactionId),[4,this._request.send("database.removeDocument",a,Ql(this._apiOptions))];case 1:return(c=u.sent()).code?[2,c]:[2,{requestId:c.requestId,deleted:c.data.deleted}]}})})},t.prototype.updateAndReturn=function(t){return Vh(this,void 0,void 0,function(){var e,n;return Gh(this,function(r){switch(r.label){case 0:return t&&"object"==typeof t?t.hasOwnProperty("_id")?[2,oh(this._db.config.throwOnCode,Hh(Hh({},Fl),{message:"不能更新_id的值"}))]:(e={collectionName:this._coll,queryType:$u.WHERE,data:Dh.encodeEJSON(t,!1)},this._transactionId&&(e.transactionId=this._transactionId),this._fieldFilters&&(e.query=this._fieldFilters),[4,this._request.send("database.modifyAndReturnDoc",e,Ql(this._apiOptions))]):[2,oh(this._db.config.throwOnCode,Hh(Hh({},Fl),{message:"参数必需是非空对象"}))];case 1:return(n=r.sent()).code?[2,n]:[2,{requestId:n.requestId,updated:n.data.updated,doc:n.data.doc&&Gl.EJSON.parse(n.data.doc)}]}})})},t}(),Jh=function(){function t(t,e,n){var r=this;this._stages=[],t&&e&&(this._db=t,this._request=hd.createRequest(this._db.config),this._collectionName=e,n&&n.length>0&&n.forEach(function(t){ch.isValidAggregation(t);var e=Object.keys(t)[0];r._pipe(e,t[e],!0)}))}return t.prototype.end=function(){return t=this,e=void 0,r=function(){var t;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(e){switch(e.label){case 0:if(!this._collectionName||!this._db)throw new Error("Aggregation pipeline cannot send request");return[4,this._request.send("database.aggregateDocuments",{collectionName:this._collectionName,stages:this._stages})];case 1:return(t=e.sent())&&t.data&&t.data.list?[2,{requestId:t.requestId,data:t.data.list.map(Gl.EJSON.parse)}]:[2,t]}})},new((n=void 0)||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())});var t,e,n,r},t.prototype.unwrap=function(){return this._stages},t.prototype.done=function(){return this._stages.map(function(t){var e,n=t.stageKey,r=t.stageValue;return(e={})[n]=JSON.parse(r),e})},t.prototype._pipe=function(t,e,n){void 0===n&&(n=!1);var r;return r="object"===Ol(e)?Zl(e):JSON.stringify(e),this._stages.push({stageKey:n?t:"$".concat(t),stageValue:r}),this},t.prototype.addFields=function(t){return this._pipe("addFields",t)},t.prototype.bucket=function(t){return this._pipe("bucket",t)},t.prototype.bucketAuto=function(t){return this._pipe("bucketAuto",t)},t.prototype.count=function(t){return this._pipe("count",t)},t.prototype.geoNear=function(t){return t.query&&(t.query=Wh.encode(t.query)),t.distanceMultiplier&&"number"==typeof t.distanceMultiplier&&(t.distanceMultiplier=t.distanceMultiplier),t.near&&(t.near=new uh(t.near.longitude,t.near.latitude).toJSON()),this._pipe("geoNear",t)},t.prototype.group=function(t){return this._pipe("group",t)},t.prototype.limit=function(t){return this._pipe("limit",t)},t.prototype.match=function(t){return this._pipe("match",Wh.encode(t))},t.prototype.project=function(t){return this._pipe("project",t)},t.prototype.lookup=function(t){return this._pipe("lookup",t)},t.prototype.replaceRoot=function(t){return this._pipe("replaceRoot",t)},t.prototype.sample=function(t){return this._pipe("sample",t)},t.prototype.skip=function(t){return this._pipe("skip",t)},t.prototype.sort=function(t){return this._pipe("sort",t)},t.prototype.sortByCount=function(t){return this._pipe("sortByCount",t)},t.prototype.unwind=function(t){return this._pipe("unwind",t)},t}();const zh=Jh;var $h=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Yh=function(t){function e(e,n,r,o){var i=t.call(this,e,n,"",r,o)||this;return o&&(i._transactionId=o),i}return $h(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this._coll},enumerable:!1,configurable:!0}),e.prototype.doc=function(t){if("string"!=typeof t&&"number"!=typeof t)throw new Error("docId必须为字符串或数字");return new Bh(this._db,this._coll,this._apiOptions,t,this._transactionId)},e.prototype.add=function(t,e){return zl(this._add(t),e)},e.prototype._add=function(t){return e=this,n=void 0,o=function(){var e,n,r;return function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(this,function(o){switch(o.label){case 0:return e=t,Pl(t)||(e=[t]),e=e.map(function(t){return Zl(Th(t))}),n={collectionName:this._coll,data:e},this._transactionId&&(n.transactionId=this._transactionId),[4,this._request.send("database.insertDocument",n,Ql(this._apiOptions))];case 1:return(r=o.sent()).code?[2,r]:Pl(t)?[2,{ids:r.data.insertedIds,requestId:r.requestId}]:this._transactionId?[2,{inserted:1,ok:1,id:r.data.insertedIds[0],requestId:r.requestId}]:[2,{id:r.data.insertedIds[0],requestId:r.requestId}]}})},new((r=void 0)||(r=Promise))(function(t,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r(function(t){t(n)})).then(s,a)}c((o=o.apply(e,n||[])).next())});var e,n,r,o},e.prototype.aggregate=function(t){return void 0===t&&(t=[]),new zh(this._db,this._coll,this._apiOptions.raw?t:[])},e.prototype.options=function(t){return ch.isValidOptions(t),new e(this._db,this._coll,t,this._transactionId)},e}(Kh),Qh={eq:function(t){return new gh(vh.EQ,[t])},neq:function(t){return new gh(vh.NEQ,[t])},lt:function(t){return new gh(vh.LT,[t])},lte:function(t){return new gh(vh.LTE,[t])},gt:function(t){return new gh(vh.GT,[t])},gte:function(t){return new gh(vh.GTE,[t])},in:function(t){return new gh(vh.IN,t)},nin:function(t){return new gh(vh.NIN,t)},all:function(t){return new gh(vh.ALL,t)},elemMatch:function(t){return new gh(vh.ELEM_MATCH,[t])},exists:function(t){return new gh(vh.EXISTS,[t])},size:function(t){return new gh(vh.SIZE,[t])},mod:function(){return new gh(vh.MOD,1==arguments.length?[arguments[0]]:2==arguments.length?[[arguments[0],arguments[1]]]:arguments)},geoNear:function(t){return new gh(vh.GEO_NEAR,[t])},geoWithin:function(t){return new gh(vh.GEO_WITHIN,[t])},geoIntersects:function(t){return new gh(vh.GEO_INTERSECTS,[t])},and:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Pl(arguments[0])?arguments[0]:Array.from(arguments);return new fh(lh.AND,n)},nor:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Pl(arguments[0])?arguments[0]:Array.from(arguments);return new fh(lh.NOR,n)},or:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Pl(arguments[0])?arguments[0]:Array.from(arguments);return new fh(lh.OR,n)},not:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Pl(arguments[0])?arguments[0]:Array.from(arguments);return new fh(lh.NOT,n)},set:function(t){return new hh(ih.SET,[t])},remove:function(){return new hh(ih.REMOVE,[])},inc:function(t){return new hh(ih.INC,[t])},mul:function(t){return new hh(ih.MUL,[t])},push:function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(Tl(e[0])&&e[0].hasOwnProperty("each")){t={};var r=e[0];void 0!==r.each&&(t.$each=r.each),void 0!==r.position&&(t.$position=r.position),void 0!==r.sort&&(t.$sort=r.sort),void 0!==r.slice&&(t.$slice=r.slice)}else t=Pl(e[0])?e[0]:Array.from(e);return new hh(ih.PUSH,t)},pull:function(t){return new hh(ih.PULL,t)},pullAll:function(t){return new hh(ih.PULL_ALL,t)},pop:function(){return new hh(ih.POP,[])},shift:function(){return new hh(ih.SHIFT,[])},unshift:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=Pl(arguments[0])?arguments[0]:Array.from(arguments);return new hh(ih.UNSHIFT,n)},addToSet:function(t){return new hh(ih.ADD_TO_SET,t)},rename:function(t){return new hh(ih.RENAME,[t])},bit:function(t){return new hh(ih.BIT,[t])},max:function(t){return new hh(ih.MAX,[t])},min:function(t){return new hh(ih.MIN,[t])},expr:function(t){return{$expr:t}},jsonSchema:function(t){return{$jsonSchema:t}},text:function(t){return function(t){return"string"===Ol(t)}(t)?{$search:t.search}:{$search:t.search,$language:t.language,$caseSensitive:t.caseSensitive,$diacriticSensitive:t.diacriticSensitive}},aggregate:{pipeline:function(){return new zh},abs:function(t){return new Xh("abs",t)},add:function(t){return new Xh("add",t)},ceil:function(t){return new Xh("ceil",t)},divide:function(t){return new Xh("divide",t)},exp:function(t){return new Xh("exp",t)},floor:function(t){return new Xh("floor",t)},ln:function(t){return new Xh("ln",t)},log:function(t){return new Xh("log",t)},log10:function(t){return new Xh("log10",t)},mod:function(t){return new Xh("mod",t)},multiply:function(t){return new Xh("multiply",t)},pow:function(t){return new Xh("pow",t)},sqrt:function(t){return new Xh("sqrt",t)},subtract:function(t){return new Xh("subtract",t)},trunc:function(t){return new Xh("trunc",t)},arrayElemAt:function(t){return new Xh("arrayElemAt",t)},arrayToObject:function(t){return new Xh("arrayToObject",t)},concatArrays:function(t){return new Xh("concatArrays",t)},filter:function(t){return new Xh("filter",t)},in:function(t){return new Xh("in",t)},indexOfArray:function(t){return new Xh("indexOfArray",t)},isArray:function(t){return new Xh("isArray",t)},map:function(t){return new Xh("map",t)},range:function(t){return new Xh("range",t)},reduce:function(t){return new Xh("reduce",t)},reverseArray:function(t){return new Xh("reverseArray",t)},size:function(t){return new Xh("size",t)},slice:function(t){return new Xh("slice",t)},zip:function(t){return new Xh("zip",t)},and:function(t){return new Xh("and",t)},not:function(t){return new Xh("not",t)},or:function(t){return new Xh("or",t)},cmp:function(t){return new Xh("cmp",t)},eq:function(t){return new Xh("eq",t)},gt:function(t){return new Xh("gt",t)},gte:function(t){return new Xh("gte",t)},lt:function(t){return new Xh("lt",t)},lte:function(t){return new Xh("lte",t)},neq:function(t){return new Xh("ne",t)},cond:function(t){return new Xh("cond",t)},ifNull:function(t){return new Xh("ifNull",t)},switch:function(t){return new Xh("switch",t)},dateFromParts:function(t){return new Xh("dateFromParts",t)},dateFromString:function(t){return new Xh("dateFromString",t)},dayOfMonth:function(t){return new Xh("dayOfMonth",t)},dayOfWeek:function(t){return new Xh("dayOfWeek",t)},dayOfYear:function(t){return new Xh("dayOfYear",t)},isoDayOfWeek:function(t){return new Xh("isoDayOfWeek",t)},isoWeek:function(t){return new Xh("isoWeek",t)},isoWeekYear:function(t){return new Xh("isoWeekYear",t)},millisecond:function(t){return new Xh("millisecond",t)},minute:function(t){return new Xh("minute",t)},month:function(t){return new Xh("month",t)},second:function(t){return new Xh("second",t)},hour:function(t){return new Xh("hour",t)},week:function(t){return new Xh("week",t)},year:function(t){return new Xh("year",t)},literal:function(t){return new Xh("literal",t)},mergeObjects:function(t){return new Xh("mergeObjects",t)},objectToArray:function(t){return new Xh("objectToArray",t)},allElementsTrue:function(t){return new Xh("allElementsTrue",t)},anyElementTrue:function(t){return new Xh("anyElementTrue",t)},setDifference:function(t){return new Xh("setDifference",t)},setEquals:function(t){return new Xh("setEquals",t)},setIntersection:function(t){return new Xh("setIntersection",t)},setIsSubset:function(t){return new Xh("setIsSubset",t)},setUnion:function(t){return new Xh("setUnion",t)},concat:function(t){return new Xh("concat",t)},dateToString:function(t){return new Xh("dateToString",t)},indexOfBytes:function(t){return new Xh("indexOfBytes",t)},indexOfCP:function(t){return new Xh("indexOfCP",t)},split:function(t){return new Xh("split",t)},strLenBytes:function(t){return new Xh("strLenBytes",t)},strLenCP:function(t){return new Xh("strLenCP",t)},strcasecmp:function(t){return new Xh("strcasecmp",t)},substr:function(t){return new Xh("substr",t)},substrBytes:function(t){return new Xh("substrBytes",t)},substrCP:function(t){return new Xh("substrCP",t)},toLower:function(t){return new Xh("toLower",t)},toUpper:function(t){return new Xh("toUpper",t)},meta:function(t){return new Xh("meta",t)},addToSet:function(t){return new Xh("addToSet",t)},avg:function(t){return new Xh("avg",t)},first:function(t){return new Xh("first",t)},last:function(t){return new Xh("last",t)},max:function(t){return new Xh("max",t)},min:function(t){return new Xh("min",t)},push:function(t){return new Xh("push",t)},stdDevPop:function(t){return new Xh("stdDevPop",t)},stdDevSamp:function(t){return new Xh("stdDevSamp",t)},sum:function(t){return new Xh("sum",t)},let:function(t){return new Xh("let",t)}},project:{slice:function(t){return new Zh("slice",t)},elemMatch:function(t){return new Zh("elemMatch",t)}}},Xh=function(t,e){this["$"+t]=e},Zh=function(t,e){this["$"+t]=e},td=function(){function t(t){var e=(void 0===t?{}:t).offset,n=void 0===e?0:e;this.offset=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return El},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$tcb_server_date:{offset:this.offset}}},t}();function ed(t){return new td(t)}var nd=function(){function t(t){var e=t.regexp,n=t.options;if(!e)throw new TypeError("regexp must be a string");this.$regularExpression={pattern:e||"",options:n||""}}return t.prototype.parse=function(){return{$regularExpression:{pattern:this.$regularExpression.pattern,options:this.$regularExpression.options}}},Object.defineProperty(t.prototype,"_internalType",{get:function(){return Il},enumerable:!1,configurable:!0}),t}();function rd(t){return new nd(t)}var od=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},id=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},sd=function(){function t(t){this._db=t,this._request=hd.createRequest(this._db.config),this.aborted=!1,this.commited=!1,this.inited=!1}return t.prototype.init=function(){return od(this,void 0,void 0,function(){var t;return id(this,function(e){switch(e.label){case 0:return[4,this._request.send("database.startTransaction")];case 1:if((t=e.sent()).code)throw t;return this.inited=!0,this._id=t.transactionId,[2]}})})},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new Yh(this._db,t,{},this._id)},t.prototype.getTransactionId=function(){return this._id},t.prototype.getRequestMethod=function(){return this._request},t.prototype.commit=function(){return od(this,void 0,void 0,function(){var t,e;return id(this,function(n){switch(n.label){case 0:return t={transactionId:this._id},[4,this._request.send("database.commitTransaction",t)];case 1:if((e=n.sent()).code)throw e;return this.commited=!0,[2,e]}})})},t.prototype.rollback=function(t){return od(this,void 0,void 0,function(){var e,n;return id(this,function(r){switch(r.label){case 0:return e={transactionId:this._id},[4,this._request.send("database.abortTransaction",e)];case 1:if((n=r.sent()).code)throw n;return this.aborted=!0,this.abortReason=t,[2,n]}})})},t}();function ad(){return od(this,void 0,void 0,function(){var t;return id(this,function(e){switch(e.label){case 0:return[4,(t=new sd(this)).init()];case 1:return e.sent(),[2,t]}})})}function cd(t,e){return void 0===e&&(e=3),od(this,void 0,void 0,function(){var n,r,o,i,s=this;return id(this,function(a){switch(a.label){case 0:return a.trys.push([0,4,,10]),[4,(n=new sd(this)).init()];case 1:return a.sent(),[4,t(n)];case 2:if(r=a.sent(),!0===n.aborted)throw n.abortReason;return[4,n.commit()];case 3:return a.sent(),[2,r];case 4:if(o=a.sent(),!1===n.inited)throw o;return i=function(t){return od(s,void 0,void 0,function(){return id(this,function(e){switch(e.label){case 0:if(n.aborted||n.commited)return[3,5];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,n.rollback()];case 2:case 3:return e.sent(),[3,4];case 4:throw t;case 5:if(!0===n.aborted)throw n.abortReason;throw t}})})},e<=0?[4,i(o)]:[3,6];case 5:a.sent(),a.label=6;case 6:return o&&o.code===Hl?[4,cd.bind(this)(t,--e)]:[3,8];case 7:return[2,a.sent()];case 8:return[4,i(o)];case 9:return a.sent(),[3,10];case 10:return[2]}})})}var ud=function(){function t(t){var e=(void 0===t?{}:t).id,n=void 0===e?"":e;this.id=n}return Object.defineProperty(t.prototype,"_internalType",{get:function(){return Sl},enumerable:!1,configurable:!0}),t.prototype.parse=function(){return{$oid:this.id}},t}();function ld(t){return new ud(t)}var hd=function(){function t(t){this.config=t,this.Geo=u,this.serverDate=ed,this.command=Qh,this.RegExp=rd,this.ObjectId=ld,this.startTransaction=ad,this.runTransaction=cd,this.logicCommand=fh,this.updateCommand=hh,this.queryCommand=gh}return t.createRequest=function(e){var n=new t.reqClass(e),r=n.send;return n.send=function(t,n){for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];return n&&(e.instance&&(n.instance=e.instance),e.database&&(n.database=e.database)),r.call.apply(r,function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([this,t,n],function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}(o),!1))},n},t.prototype.collection=function(t){if(!t)throw new Error("Collection name is required");return new Yh(this,t)},t.prototype.createCollection=function(e){var n={collectionName:e};return t.createRequest(this.config).send("database.addCollection",n)},t}(),dd=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),fd=function(){return fd=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},fd.apply(this,arguments)},pd=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(s,a)}c((r=r.apply(t,e||[])).next())})},vd=function(t,e){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(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function yd(t,e,n,r){(function(t){var e,n,r;return!0===(null===(r=null===(n=null===(e=null==t?void 0:t.config)||void 0===e?void 0:e._fromApp)||void 0===n?void 0:n.config)||void 0===r?void 0:r.debug)})(t)&&function(t,e){var n=t.data;console.error("[cloudbase] NETWORK_ERROR",{status:e,requestId:t.requestId,body:"string"==typeof n?n.slice(0,1024):""})}(e,n),e.code=g.NETWORK_ERROR,e.message=function(t,e){return"HTTP ".concat(t,". Expected ").concat(e,". Set debug: true to see the response.")}(n,r)}var gd={filterRes:function(t,e){t=U(t);var n=Number(t.statusCode);return n>=400&&!t.code&&yd(null!=e?e:this,t,n,"HTTP 2xx"),delete t.header,delete t.statusCode,t},normalizeTransactionResponse:function(t,e){var n=null==(t=U(t))?void 0:t.data;n&&"object"==typeof n&&"string"==typeof n.request_id&&n.request_id&&(t.requestId=n.request_id);var r=Number(t.statusCode),o="start"===e?"HTTP 201 with transactionId":"HTTP 204 with an empty body";if(r>=400)return t.code||yd(this,t,r,o),delete t.header,delete t.statusCode,t;if("start"===e){var i=null==n?void 0:n.transactionId;if(201===r&&"string"==typeof i&&i){var s=gd.flattenResData(t);return delete s.header,delete s.statusCode,s}return t.code||yd(this,t,r,o),delete t.header,delete t.statusCode,t}return 204!==r||""!==n&&null!=n?(t.code||yd(this,t,r,o),delete t.header,delete t.statusCode,t):(delete t.data,delete t.header,delete t.statusCode,t)},flattenResData:function(t){if("object"==typeof t.data&&null!==t.data){var e=fd(fd({},t),t.data);return delete e.data,e}return t},safeParseEJSON:function(t){if("string"!=typeof t)return t;try{return Gl.EJSON.parse(t)}catch(e){return t}},parseEJSONParam:function(t){if("string"!=typeof t)return t;try{return JSON.parse(t)}catch(e){return t}},parseEJSONValue:function(t){if("string"!=typeof t)return t;try{return Gl.EJSON.parse(t)}catch(e){return gd.parseEJSONParam(t)}},normalizeOrderParam:function(t){if(null!=t&&""!==t){for(var e=gd.parseEJSONValue(t),n=function(t){var e=t&&"object"==typeof t?Number(t):t;if("number"==typeof e&&!isNaN(e))return e<0?"desc":"asc";if("string"==typeof e){var n=e.toLowerCase();if("desc"===n||"-1"===n)return"desc";if("asc"===n||"1"===n)return"asc"}},r=[],o=0,i=Array.isArray(e)?e:[e];o<i.length;o++){var s=i[o];if(s&&"object"==typeof s)if(void 0!==s.field)(u=n(s.direction))&&r.push({field:s.field,direction:u});else for(var a=0,c=Object.entries(s);a<c.length;a++){var u,l=c[a],h=l[0];(u=n(l[1]))&&r.push({field:h,direction:u})}}return r.length?r:void 0}},extractDocId:function(t){if(t&&"object"==typeof t&&!Array.isArray(t)&&1===Object.keys(t).length&&"_id"in t){var e=t._id;if("string"==typeof e||"number"==typeof e)return String(e);if(e&&"object"==typeof e){if("string"==typeof e.$oid)return e.$oid;var n=e.$eq;if("string"==typeof n||"number"==typeof n)return String(n);if(n&&"object"==typeof n&&"string"==typeof n.$oid)return n.$oid}}},toLegacyRegExp:function(t){if(!t||"object"!=typeof t)return t;if(t.$regularExpression&&"object"==typeof t.$regularExpression){var e=t.$regularExpression;return{$regex:e.pattern,$options:e.options}}if(Array.isArray(t))return t.map(function(t){return gd.toLegacyRegExp(t)});var n={};for(var r in t)n[r]=gd.toLegacyRegExp(t[r]);return n},parseWriteParam:function(t){return gd.toLegacyRegExp(gd.parseEJSONParam(t))},buildQueryParams:function(t){return Object.entries(t).filter(function(t){t[0];var e=t[1];return null!=e&&""!==e}).map(function(t){var e=t[0],n=t[1],r="object"==typeof n?JSON.stringify(n):String(n);return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(r))}).join("&")},getUrlPrefix:function(t){var e=(null==t?void 0:t.instance)||"(default)",n=(null==t?void 0:t.database)||"(default)";return"/database/instances/".concat(e,"/databases/").concat(n)},"database.queryDocument":function(t,e){var n,r,o,i;return pd(this,void 0,Promise,function(){var s,a,c,u,l,h,d;return vd(this,function(f){switch(f.label){case 0:return s=gd.parseEJSONParam(t.query),a=gd.parseEJSONValue(t.projection),c=gd.extractDocId(s),u=void 0!==c,l=gd.buildQueryParams(fd({projection:a,transactionId:t.transactionId},u?{}:{offset:null!==(n=t.offset)&&void 0!==n?n:0,limit:null!==(r=t.limit)&&void 0!==r?r:100,order:gd.normalizeOrderParam(t.order),query:s?Gl.EJSON.stringify(s,{relaxed:!1}):void 0})),h="".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(l),u&&(h="".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/").concat(c,"?").concat(l)),[4,this.gateWay({url:h,method:"GET"},e)];case 1:return(d=f.sent()).data=gd.safeParseEJSON(JSON.stringify(d.data)),!u||d.code||(null===(o=d.data)||void 0===o?void 0:o.code)?(d.code||(null===(i=d.data)||void 0===i?void 0:i.code)?d=fd(fd({},d),{data:fd(fd({},d.data),{list:[]})}):Array.isArray(d.data)?d=fd(fd({},d),{data:{list:d.data}}):d.data&&!Array.isArray(d.data.list)&&(d=fd(fd({},d),{data:fd(fd({},d.data),{list:[]})})),[2,gd.filterRes(d,this)]):[2,fd(fd({},d),{data:{list:[d.data]}})]}})})},"database.addDocument":function(t,e){var n,r,o;return pd(this,void 0,Promise,function(){var i,s;return vd(this,function(a){switch(a.label){case 0:return i=(Array.isArray(t.data)?t.data:[t.data]).map(function(t){return gd.parseWriteParam(t)}),[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"POST",data:fd({data:i},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return s=a.sent(),Array.isArray(t.data)?s=fd(fd({},s),{data:fd({ids:(null===(n=s.data)||void 0===n?void 0:n.insertedIds)||[]},s.data)}):(null===(o=null===(r=s.data)||void 0===r?void 0:r.insertedIds)||void 0===o?void 0:o[0])&&(s=fd(fd({},s),{data:fd({_id:s.data.insertedIds[0]},s.data)})),[2,gd.filterRes(s,this)]}})})},"database.updateDocument":function(t,e){var n;return pd(this,void 0,Promise,function(){var r;return vd(this,function(o){switch(o.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents"),method:"PATCH",data:fd({query:gd.parseEJSONParam(t.query),data:gd.parseEJSONParam(t.data),multi:!!t.multi,upsert:!!t.upsert,replaceMode:null!==(n=t.replaceMode)&&void 0!==n?n:!1===t.merge},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return r=o.sent(),[2,gd.filterRes(r,this)]}})})},"database.deleteDocument":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/remove"),method:"POST",data:fd({query:gd.parseEJSONParam(t.query),multi:!!t.multi},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:return n=r.sent(),[2,gd.filterRes(n,this)]}})})},"database.countDocument":function(t,e){return pd(this,void 0,Promise,function(){var n,r,o;return vd(this,function(i){switch(i.label){case 0:return n=gd.parseEJSONParam(t.query),r=gd.buildQueryParams({count:!0,query:n?Gl.EJSON.stringify(n,{relaxed:!1}):void 0}),[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents?").concat(r),method:"GET"},e)];case 1:return o=i.sent(),[2,gd.filterRes(o,this)]}})})},"database.addCollection":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections"),method:"POST",data:{collectionName:t.collectionName}},e)];case 1:return n=r.sent(),[2,gd.filterRes(n,this)]}})})},"database.aggregate":function(t,e){var n;return pd(this,void 0,Promise,function(){var r,o;return vd(this,function(i){switch(i.label){case 0:return r=t.stages.map(function(t){var e,n;try{var r="string"==typeof t.stageValue?JSON.parse(t.stageValue):t.stageValue;return(e={})[t.stageKey]=Gl.EJSON.serialize(r),e}catch(e){return(n={})[t.stageKey]=t.stageValue,n}}),[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/collections/").concat(t.collectionName,"/documents/aggregations"),method:"POST",data:{pipeline:r}},e)];case 1:return o=i.sent(),Array.isArray(null===(n=o.data)||void 0===n?void 0:n.list)&&(o.data.list=JSON.stringify(o.data.list.map(function(t){return JSON.stringify(t)}))),[2,gd.filterRes(o,this)]}})})},"database.startTransaction":function(t,e){return pd(this,void 0,void 0,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/transactions"),method:"POST",shouldThrowOnError:!1},e)];case 1:return n=r.sent(),[2,gd.normalizeTransactionResponse.call(this,n,"start")]}})})},"database.commitTransaction":function(t,e){return pd(this,void 0,void 0,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/commit"),method:"POST",shouldThrowOnError:!1},e)];case 1:return n=r.sent(),[2,gd.normalizeTransactionResponse.call(this,n,"commit")]}})})},"database.abortTransaction":function(t,e){return pd(this,void 0,void 0,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/transactions/").concat(t.transactionId,"/rollback"),method:"POST",shouldThrowOnError:!1},e)];case 1:return n=r.sent(),[2,gd.normalizeTransactionResponse.call(this,n,"rollback")]}})})},"database.getInTransaction":function(t,e){var n;return pd(this,void 0,void 0,function(){var r;return vd(this,function(o){switch(o.label){case 0:return[4,gd["database.queryDocument"].call(this,t,e)];case 1:return"object"==typeof(r=o.sent()).data&&null!==r.data?(null===(n=r.data)||void 0===n?void 0:n.code)?[2,gd.flattenResData(r)]:[2,fd(fd({},r),{data:JSON.stringify(r.data)})]:[2,r]}})})},"database.updateDocInTransaction":function(t,e){return pd(this,void 0,void 0,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,gd["database.updateDocument"].call(this,t,e)];case 1:return n=r.sent(),[2,gd.flattenResData(n)]}})})},"database.deleteDocInTransaction":function(t,e){return pd(this,void 0,void 0,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,gd["database.deleteDocument"].call(this,t,e)];case 1:return n=r.sent(),[2,gd.flattenResData(n)]}})})},"database.insertDocInTransaction":function(t,e){var n;return pd(this,void 0,Promise,function(){var r,o;return vd(this,function(i){switch(i.label){case 0:return[4,gd["database.addDocument"].call(this,t,e)];case 1:return"object"==typeof(r=i.sent()).data&&null!==r.data?(o=!!(null===(n=r.data)||void 0===n?void 0:n._id),r=fd(fd(fd({},r),{inserted:o?1:0,ok:o?1:0}),r.data)):r=fd({inserted:0,ok:0},r),delete r.data,[2,r]}})})},"database.runCommands":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){switch(r.label){case 0:return[4,this.gateWay({url:"".concat(gd.getUrlPrefix(t),"/commands"),method:"POST",data:fd({commands:Gl.EJSON.serialize(Array.isArray(t.commands)?t.commands.map(function(t){return gd.parseEJSONParam(t)}):t.commands)},t.transactionId&&{transactionId:t.transactionId})},e)];case 1:"object"==typeof(n=r.sent()).data&&null!==n.data&&(delete(n=fd(fd({},n),n.data)).data,delete n.request_id);try{n=Gl.EJSON.deserialize(n)}catch(t){}return[2,gd.filterRes(n,this)]}})})},"database.getDocument":function(t,e){var n;return pd(this,void 0,Promise,function(){var r,o;return vd(this,function(i){switch(i.label){case 0:return(r=fd({},t)).query=gd.parseEJSONParam(r.query),r.projection=gd.parseEJSONValue(r.projection),[4,gd["database.queryDocument"].call(this,r,e)];case 1:return o=i.sent(),Array.isArray(null===(n=o.data)||void 0===n?void 0:n.list)&&(o.data.list=o.data.list.map(function(t){return Gl.EJSON.stringify(t,{relaxed:!1})})),[2,o]}})})},"database.insertDocument":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){return(n=fd({},t)).data=Array.isArray(n.data)?n.data.map(function(t){return gd.parseWriteParam(t)}):gd.parseWriteParam(n.data),[2,gd["database.addDocument"].call(this,n,e)]})})},"database.modifyDocument":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){return(n=fd({},t)).query=gd.parseEJSONParam(n.query),n.data=gd.parseEJSONParam(n.data),[2,gd["database.updateDocument"].call(this,n,e)]})})},"database.modifyAndReturnDoc":function(t,e){var n,r;return pd(this,void 0,Promise,function(){var o,i,s;return vd(this,function(a){switch(a.label){case 0:return(o=fd({},t)).query=gd.parseEJSONParam(o.query),o.data=gd.parseEJSONParam(o.data),(i=gd.extractDocId(o.query))?[4,this.gateWay({url:"".concat(gd.getUrlPrefix(o),"/collections/").concat(o.collectionName,"/documents/").concat(i),method:"PATCH",data:fd({data:o.data,replaceMode:null!==(n=o.replaceMode)&&void 0!==n&&n,upsert:!!o.upsert,returnDoc:!0},o.transactionId&&{transactionId:o.transactionId})},e)]:[2,gd["database.updateDocument"].call(this,o,e)];case 1:return s=a.sent(),void 0!==(null===(r=s.data)||void 0===r?void 0:r.doc)&&"string"!=typeof s.data.doc&&(s.data.doc=Gl.EJSON.stringify(s.data.doc,{relaxed:!1})),[2,gd.filterRes(s,this)]}})})},"database.removeDocument":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){return(n=fd({},t)).query=gd.parseEJSONParam(n.query),void 0!==n.query&&null!==n.query&&""!==n.query||(n.query={_id:{$exists:!0}}),[2,gd["database.deleteDocument"].call(this,n,e)]})})},"database.calculateDocument":function(t,e){return pd(this,void 0,Promise,function(){var n;return vd(this,function(r){return(n=fd({},t)).query=gd.parseEJSONParam(n.query),[2,gd["database.countDocument"].call(this,n,e)]})})},"database.aggregateDocuments":function(t,e){var n;return pd(this,void 0,Promise,function(){var r,o;return vd(this,function(i){switch(i.label){case 0:return r=fd({},t),Array.isArray(r.stages)&&(r.stages=r.stages.map(function(t){return fd(fd({},t),{stageValue:gd.parseEJSONParam(t.stageValue)})})),[4,gd["database.aggregate"].call(this,r,e)];case 1:if(o=i.sent(),"string"==typeof(null===(n=o.data)||void 0===n?void 0:n.list))try{o.data.list=JSON.parse(o.data.list)}catch(t){}return[2,o]}})})}},md={name:"database",entity:{database:function(t){var e;if(void 0!==t&&"Object"!==Object.prototype.toString.call(t).slice(8,-1))throw k({code:"INVALID_PARAM",msg:"dbConfig must be an object"},null===(e=this.config)||void 0===e?void 0:e.errorFactory);var n=this.platform,r=n.adapter,o=n.runtime,i=function(t){function e(e){return t.call(this,e)||this}return dd(e,t),e.prototype.send=function(e,n,r){var o,i,s,a;return pd(this,void 0,void 0,function(){var c,u,l;return vd(this,function(h){switch(h.label){case 0:return c=null,u=r&&"number"==typeof r.timeout?{timeout:r.timeout}:void 0,"GATEWAY"===this.config.endPointMode&&gd[e]?[4,gd[e].call(this,n,u)]:[3,2];case 1:return c=h.sent(),[3,4];case 2:return[4,t.prototype.send.call(this,e,n,void 0,u)];case 3:c=h.sent(),h.label=4;case 4:if(l=N(null!==(s=null===(i=null===(o=this.config)||void 0===o?void 0:o._fromApp)||void 0===i?void 0:i.config)&&void 0!==s?s:this.config),c&&c.code&&l)throw k({code:c.code,msg:c.message||c.data&&c.data.message||"",requestId:c.requestId},null===(a=this.config)||void 0===a?void 0:a.errorFactory);return[2,c]}})})},e}(this.request.constructor);return hd.reqClass=i,hd.getAccessToken=this.authInstance?this.authInstance.getAccessToken.bind(this.authInstance):function(){return""},hd.runtime=o,this.wsClientClass&&(hd.wsClass=r.wsClass,hd.wsClientClass=this.wsClientClass),hd.ws||(hd.ws=null),new(function(t){function e(e){return t.call(this,e)||this}return dd(e,t),e.prototype.runCommands=function(t){return pd(this,void 0,Promise,function(){return vd(this,function(e){return[2,hd.createRequest(this.config).send("database.runCommands",t)]})})},e}(hd))(fd(fd(fd({},this.config),{_fromApp:this}),t))}}};try{cloudbase.registerComponent(md)}catch(t){}function bd(t){try{t.registerComponent(md)}catch(t){console.warn(t)}}try{window.registerDatabase=bd}catch(t){}ae.registerVersion("3.11.0");try{!function(t){try{t.registerComponent(hr)}catch(t){console.warn(t)}}(ae),function(t){try{t.registerComponent(Mr)}catch(t){console.warn(t)}}(ae),ri(ae),bd(ae),function(t){try{t.registerComponent(Bi),t.registerHook(Mi)}catch(t){console.warn(t)}}(ae),Ta(ae),Da(ae),Ru(ae),Er(ae),Lu(ae),Ju(ae)}catch(t){}try{window.cloudbase=ae}catch(t){}const wd=ae})();var d=h.Z;export{d as default};
3
3
  //# sourceMappingURL=index.esm.js.map