1(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,231526,252422,e=>{"use strict";let t;for(var r,n,i,o,s,a,c,u,f,l,h,d,p,y,g,w,m=e.i(247167),b=e.i(843476),v=e.i(271645),E=e.i(618566),S=e.i(705766),_=e.i(467034),A=[],x=[],O="u">typeof Uint8Array?Uint8Array:Array,T="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",N=0,k=T.length;N<k;++N)A[N]=T[N],x[T.charCodeAt(N)]=N;function U(e){var t=e.length;if(t%4>0)throw Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");-1===r&&(r=t);var n=r===t?0:4-r%4;return[r,n]}x[45]=62,x[95]=63;var I=function(e){var t,r,n=U(e),i=n[0],o=n[1],s=new O((i+o)*3/4-o),a=0,c=o>0?i-4:i;for(r=0;r<c;r+=4)t=x[e.charCodeAt(r)]<<18|x[e.charCodeAt(r+1)]<<12|x[e.charCodeAt(r+2)]<<6|x[e.charCodeAt(r+3)],s[a++]=t>>16&255,s[a++]=t>>8&255,s[a++]=255&t;return 2===o&&(t=x[e.charCodeAt(r)]<<2|x[e.charCodeAt(r+1)]>>4,s[a++]=255&t),1===o&&(t=x[e.charCodeAt(r)]<<10|x[e.charCodeAt(r+1)]<<4|x[e.charCodeAt(r+2)]>>2,s[a++]=t>>8&255,s[a++]=255&t),s},P=function(e){for(var t,r=e.length,n=r%3,i=[],o=0,s=r-n;o<s;o+=16383)i.push(function(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&0xff0000)+(e[o+1]<<8&65280)+(255&e[o+2]),i.push(A[n>>18&63]+A[n>>12&63]+A[n>>6&63]+A[63&n]);return i.join("")}(e,o,o+16383>s?s:o+16383));return 1===n?i.push(A[(t=e[r-1])>>2]+A[t<<4&63]+"=="):2===n&&i.push(A[(t=(e[r-2]<<8)+e[r-1])>>10]+A[t>>4&63]+A[t<<2&63]+"="),i.join("")},B=function(e,t,r,n,i){var o,s,a=8*i-n-1,c=(1<<a)-1,u=c>>1,f=-7,l=r?i-1:0,h=r?-1:1,d=e[t+l];for(l+=h,o=d&(1<<-f)-1,d>>=-f,f+=a;f>0;o=256*o+e[t+l],l+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+e[t+l],l+=h,f-=8);if(0===o)o=1-u;else{if(o===c)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,n),o-=u}return(d?-1:1)*s*Math.pow(2,o-n)},C=function(e,t,r,n,i,o){var s,a,c,u=8*o-i-1,f=(1<<u)-1,l=f>>1,h=5960464477539062e-23*(23===i),d=n?0:o-1,p=n?1:-1,y=+(t<0||0===t&&1/t<0);for(isNaN(t=Math.abs(t))||t===1/0?(a=+!!isNaN(t),s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+l>=1?t+=h/c:t+=h*Math.pow(2,1-l),t*c>=2&&(s++,c/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*c-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+d]=255&a,d+=p,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;e[r+d]=255&s,d+=p,s/=256,u-=8);e[r+d-p]|=128*y},R=(function(e,t){var r="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;function n(e){if(e>0x7fffffff)throw RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return Object.setPrototypeOf(t,i.prototype),t}function i(e,t,r){if("number"==typeof e){if("string"==typeof t)throw TypeError('The "string" argument must be of type string. Received type number');return a(e)}return o(e,t,r)}function o(e,t,r){if("string"==typeof e){var o=e,s=t;if(("string"!=typeof s||""===s)&&(s="utf8"),!i.isEncoding(s))throw TypeError("Unknown encoding: "+s);var a=0|l(o,s),h=n(a),d=h.write(o,s);return d!==a&&(h=h.slice(0,d)),h}if(ArrayBuffer.isView(e)){var p=e;if(O(p,Uint8Array)){var y=new Uint8Array(p);return u(y.buffer,y.byteOffset,y.byteLength)}return c(p)}if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+babelHelpers.typeof(e));if(O(e,ArrayBuffer)||e&&O(e.buffer,ArrayBuffer)||"u">typeof SharedArrayBuffer&&(O(e,SharedArrayBuffer)||e&&O(e.buffer,SharedArrayBuffer)))return u(e,t,r);if("number"==typeof e)throw TypeError('The "value" argument must not be of type number. Received type number');var g=e.valueOf&&e.valueOf();if(null!=g&&g!==e)return i.from(g,t,r);var w=function(e){if(i.isBuffer(e)){var t=0|f(e.length),r=n(t);return 0===r.length||e.copy(r,0,0,t),r}return void 0!==e.length?"number"!=typeof e.length||function(e){return e!=e}(e.length)?n(0):c(e):"Buffer"===e.type&&Array.isArray(e.data)?c(e.data):void 0}(e);if(w)return w;if("u">typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return i.from(e[Symbol.toPrimitive]("string"),t,r);throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+babelHelpers.typeof(e))}function s(e){if("number"!=typeof e)throw TypeError('"size" argument must be of type number');
vendor: 17,080 bytes, line 1
1if(e<0)throw RangeError('The value "'+e+'" is invalid for option "size"')}function a(e){return s(e),n(e<0?0:0|f(e))}function c(e){for(var t=e.length<0?0:0|f(e.length),r=n(t),i=0;i<t;i+=1)r[i]=255&e[i];return r}function u(e,t,r){var n;if(t<0||e.byteLength<t)throw RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw RangeError('"length" is outside of buffer bounds');return Object.setPrototypeOf(n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),i.prototype),n}function f(e){if(e>=0x7fffffff)throw RangeError("Attempt to allocate Buffer larger than maximum size: 0x7fffffff bytes");return 0|e}function l(e,t){if(i.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||O(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+babelHelpers.typeof(e));var r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var o=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return _(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return A(e).length;default:if(o)return n?-1:_(e).length;t=(""+t).toLowerCase(),o=!0}}function h(e,t,r){var n,i,o,s=!1;if((void 0===t||t<0)&&(t=0),t>this.length||((void 0===r||r>this.length)&&(r=this.length),r<=0||(r>>>=0)<=(t>>>=0)))return"";for(e||(e="utf8");;)switch(e){case"hex":return function(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=t;o<r;++o)i+=T[e[o]];return i}(this,t,r);case"utf8":case"utf-8":return g(this,t,r);case"ascii":return function(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}(this,t,r);case"latin1":case"binary":return function(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}(this,t,r);case"base64":return n=this,i=t,o=r,0===i&&o===n.length?P(n):P(n.slice(i,o));case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return function(e,t,r){for(var n=e.slice(t,r),i="",o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}(this,t,r);default:if(s)throw TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),s=!0}}function d(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function p(e,t,r,n,o){var s;if(0===e.length)return -1;if("string"==typeof r?(n=r,r=0):r>0x7fffffff?r=0x7fffffff:r<-0x80000000&&(r=-0x80000000),(s=r*=1)!=s&&(r=o?0:e.length-1),r<0&&(r=e.length+r),r>=e.length)if(o)return -1;else r=e.length-1;else if(r<0)if(!o)return -1;else r=0;if("string"==typeof t&&(t=i.from(t,n)),i.isBuffer(t))return 0===t.length?-1:y(e,t,r,n,o);if("number"==typeof t){if(t&=255,"function"==typeof Uint8Array.prototype.indexOf)if(o)return Uint8Array.prototype.indexOf.call(e,t,r);else return Uint8Array.prototype.lastIndexOf.call(e,t,r);return y(e,[t],r,n,o)}throw TypeError("val must be string, number or Buffer")}function y(e,t,r,n,i){var o,s=1,a=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return -1;s=2,a/=2,c/=2,r/=2}function u(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var f=-1;for(o=r;o<a;o++)if(u(e,o)===u(t,-1===f?0:o-f)){if(-1===f&&(f=o),o-f+1===c)return f*s}else -1!==f&&(o-=o-f),f=-1}else for(r+c>a&&(r=a-c),o=r;o>=0;o--){for(var l=!0,h=0;h<c;h++)if(u(e,o+h)!==u(t,h)){l=!1;break}if(l)return o}return -1}function g(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var o,s,a,c,u=e[i],f=null,l=u>239?4:u>223?3:u>191?2:1;if(i+l<=r)switch(l){case 1:u<128&&(f=u);break;case 2:(192&(o=e[i+1]))==128&&(c=(31&u)<<6|63&o)>127&&(f=c);break;case 3:o=e[i+1],s=e[i+2],(192&o)==128&&(192&s)==128&&(c=(15&u)<<12|(63&o)<<6|63&s)>2047&&(c<55296||c>57343)&&(f=c);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],(192&o)==128&&(192&s)==128&&(192&a)==128&&(c=(15&u)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(f=c)}null===f?(f=65533,l=1):f>65535&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|1023&f),n.push(f),i+=l}var h=n,d=h.length;if(d<=4096)return String.fromCharCode.apply(String,h);for(var p="",y=0;y<d;)p+=String.fromCharCode.apply(String,h.slice(y,y+=4096));return p}function w(e,t,r){if(e%1!=0||e<0)throw RangeError("offset is not uint");if(e+t>r)throw RangeError("Trying to access beyond buffer length")}function m(e,t,r,n,o,s){if(!i.isBuffer(e))throw TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<s)throw RangeError('"value" argument is out of bounds');if(r+n>e.length)throw RangeError("Index out of range")}function b(e,t,r,n,i,o){if(r+n>e.length||r<0)throw RangeError("Index out of range")}function v(e,t,r,n,i){return t*=1,r>>>=0,i||b(e,t,r,4),C(e,t,r,n,23,4),r+4}function E(e,t,r,n,i){return t*=1,r>>>=0,i||b(e,t,r,8),C(e,t,r,n,52,8),r+8}t.Buffer=i,t.SlowBuffer=function(e){return+e!=e&&(e=0),i.alloc(+e)},t.INSPECT_MAX_BYTES=50,t.kMaxLength=0x7fffffff,i.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){return!1}}(),!i.TYPED_ARRAY_SUPPORT&&"u">typeof console&&"function"==typeof console.error&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(i.prototype,"parent",{enumerable:!0,get:function(){if(i.isBuffer(this))return this.buffer}}),Object.defineProperty(i.prototype,"offset",{enumerable:!0,get:function(){if(i.isBuffer(this))return this.byteOffset}}),i.poolSize=8192,i.from=function(e,t,r){return o(e,t,r)},Object.setPrototypeOf(i.prototype,Uint8Array.prototype),Object.setPrototypeOf(i,Uint8Array),i.alloc=function(e,t,r){return(s(e),e<=0)?n(e):void 0!==t?"string"==typeof r?n(e).fill(t,r):n(e).fill(t):n(e)},i.allocUnsafe=function(e){return a(e)},i.allocUnsafeSlow=function(e){return a(e)},i.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==i.prototype},i.compare=function(e,t){if(O(e,Uint8Array)&&(e=i.from(e,e.offset,e.byteLength)),O(t,Uint8Array)&&(t=i.from(t,t.offset,t.byteLength)),!i.isBuffer(e)||!i.isBuffer(t))throw TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var r=e.length,n=t.length,o=0,s=Math.min(r,n);o<s;++o)if(e[o]!==t[o]){r=e[o],n=t[o];break}return r<n?-1:+(n<r)},i.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},i.concat=function(e,t){if(!Array.isArray(e))throw TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return i.alloc(0);if(void 0===t)for(r=0,t=0;r<e.length;++r)t+=e[r].length;var r,n=i.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var s=e[r];if(O(s,Uint8Array))o+s.length>n.length?i.from(s).copy(n,o):Uint8Array.prototype.set.call(n,s,o);else if(i.isBuffer(s))s.copy(n,o);else throw TypeError('"list" argument must be an Array of Buffers');o+=s.length}return n},i.byteLength=l,i.prototype._isBuffer=!0,i.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)d(this,t,t+1);return this},i.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)d(this,t,t+3),d(this,t+1,t+2);return this},i.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)d(this,t,t+7),d(this,t+1,t+6),d(this,t+2,t+5),d(this,t+3,t+4);return this},i.prototype.toString=function(){var e=this.length;return 0===e?"":0==arguments.length?g(this,0,e):h.apply(this,arguments)},i.prototype.toLocaleString=i.prototype.toString,i.prototype.equals=function(e){if(!i.isBuffer(e))throw TypeError("Argument must be a Buffer");return this===e||0===i.compare(this,e)},i.prototype.inspect=function(){var e="",r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},r&&(i.prototype[r]=i.prototype.inspect),i.prototype.compare=function(e,t,r,n,o){if(O(e,Uint8Array)&&(e=i.from(e,e.offset,e.byteLength)),!i.isBuffer(e))throw TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+babelHelpers.typeof(e));if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),t<0||r>e.length||n<0||o>this.length)throw RangeError("out of range index");if(n>=o&&t>=r)return 0;if(n>=o)return -1;if(t>=r)return 1;if(t>>>=0,r>>>=0,n>>>=0,o>>>=0,this===e)return 0;for(var s=o-n,a=r-t,c=Math.min(s,a),u=this.slice(n,o),f=e.slice(t,r),l=0;l<c;++l)if(u[l]!==f[l]){s=u[l],a=f[l];break}return s<a?-1:+(a<s)},i.prototype.includes=function(e,t,r){return -1!==this.indexOf(e,t,r)},i.prototype.indexOf=function(e,t,r){return p(this,e,t,r,!0)},i.prototype.lastIndexOf=function(e,t,r){return p(this,e,t,r,!1)},i.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else if(isFinite(t))t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0);else throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var i,o,s,a,c,u,f,l,h=this.length-t;if((void 0===r||r>h)&&(r=h),e.length>0&&(r<0||t<0)||t>this.length)throw RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var d=!1;;)switch(n){case"hex":return function(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=t.length;n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a,c=parseInt(t.substr(2*s,2),16);if((a=c)!=a)break;e[r+s]=c}return s}(this,e,t,r);case"utf8":case"utf-8":return i=t,o=r,x(_(e,this.length-i),this,i,o);case"ascii":case"latin1":case"binary":return s=t,a=r,x(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(e),this,s,a);case"base64":return c=t,u=r,x(A(e),this,c,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return f=t,l=r,x(function(e,t){for(var r,n,i=[],o=0;o<e.length&&!((t-=2)<0);++o)n=(r=e.charCodeAt(o))>>8,i.push(r%256),i.push(n);return i}(e,this.length-f),this,f,l);default:if(d)throw TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),d=!0}},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},i.prototype.slice=function(e,t){var r=this.length;e=~~e,t=void 0===t?r:~~t,e<0?(e+=r)<0&&(e=0):e>r&&(e=r),t<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);var n=this.subarray(e,t);return Object.setPrototypeOf(n,i.prototype),n},i.prototype.readUintLE=i.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||w(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n},i.prototype.readUintBE=i.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||w(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},i.prototype.readUint8=i.prototype.readUInt8=function(e,t){return e>>>=0,t||w(e,1,this.length),this[e]},i.prototype.readUint16LE=i.prototype.readUInt16LE=function(e,t){return e>>>=0,t||w(e,2,this.length),this[e]|this[e+1]<<8},i.prototype.readUint16BE=i.prototype.readUInt16BE=function(e,t){return e>>>=0,t||w(e,2,this.length),this[e]<<8|this[e+1]},i.prototype.readUint32LE=i.prototype.readUInt32LE=function(e,t){return e>>>=0,t||w(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+0x1000000*this[e+3]},i.prototype.readUint32BE=i.prototype.readUInt32BE=function(e,t){return e>>>=0,t||w(e,4,this.length),0x1000000*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},i.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||w(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*t)),n},i.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||w(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},i.prototype.readInt8=function(e,t){return(e>>>=0,t||w(e,1,this.length),128&this[e])?-((255-this[e]+1)*1):this[e]},i.prototype.readInt16LE=function(e,t){e>>>=0,t||w(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?0xffff0000|r:r},i.prototype.readInt16BE=function(e,t){e>>>=0,t||w(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?0xffff0000|r:r},i.prototype.readInt32LE=function(e,t){return e>>>=0,t||w(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},i.prototype.readInt32BE=function(e,t){return e>>>=0,t||w(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},i.prototype.readFloatLE=function(e,t){return e>>>=0,t||w(e,4,this.length),B(this,e,!0,23,4)},i.prototype.readFloatBE=function(e,t){return e>>>=0,t||w(e,4,this.length),B(this,e,!1,23,4)},i.prototype.readDoubleLE=function(e,t){return e>>>=0,t||w(e,8,this.length),B(this,e,!0,52,8)},i.prototype.readDoubleBE=function(e,t){return e>>>=0,t||w(e,8,this.length),B(this,e,!1,52,8)},i.prototype.writeUintLE=i.prototype.writeUIntLE=function(e,t,r,n){if(e*=1,t>>>=0,r>>>=0,!n){var i=Math.pow(2,8*r)-1;m(this,e,t,r,i,0)}var o=1,s=0;for(this[t]=255&e;++s<r&&(o*=256);)this[t+s]=e/o&255;return t+r},i.prototype.writeUintBE=i.prototype.writeUIntBE=function(e,t,r,n){if(e*=1,t>>>=0,r>>>=0,!n){var i=Math.pow(2,8*r)-1;m(this,e,t,r,i,0)}var o=r-1,s=1;for(this[t+o]=255&e;--o>=0&&(s*=256);)this[t+o]=e/s&255;return t+r},i.prototype.writeUint8=i.prototype.writeUInt8=function(e,t,r){return e*=1,t>>>=0,r||m(this,e,t,1,255,0),this[t]=255&e,t+1},i.prototype.writeUint16LE=i.prototype.writeUInt16LE=function(e,t,r){return e*=1,t>>>=0,r||m(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},i.prototype.writeUint16BE=i.prototype.writeUInt16BE=function(e,t,r){return e*=1,t>>>=0,r||m(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},i.prototype.writeUint32LE=i.prototype.writeUInt32LE=function(e,t,r){return e*=1,t>>>=0,r||m(this,e,t,4,0xffffffff,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},i.prototype.writeUint32BE=i.prototype.writeUInt32BE=function(e,t,r){return e*=1,t>>>=0,r||m(this,e,t,4,0xffffffff,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},i.prototype.writeIntLE=function(e,t,r,n){if(e*=1,t>>>=0,!n){var i=Math.pow(2,8*r-1);m(this,e,t,r,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o<r&&(s*=256);)e<0&&0===a&&0!==this[t+o-1]&&(a=1),this[t+o]=(e/s|0)-a&255;return t+r},i.prototype.writeIntBE=function(e,t,r,n){if(e*=1,t>>>=0,!n){var i=Math.pow(2,8*r-1);m(this,e,t,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s|0)-a&255;return t+r},i.prototype.writeInt8=function(e,t,r){return e*=1,t>>>=0,r||m(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},i.prototype.writeInt16LE=function(e,t,r){return e*=1,t>>>=0,r||m(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},i.prototype.writeInt16BE=function(e,t,r){return e*=1,t>>>=0,r||m(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},i.prototype.writeInt32LE=function(e,t,r){return e*=1,t>>>=0,r||m(this,e,t,4,0x7fffffff,-0x80000000),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},i.prototype.writeInt32BE=function(e,t,r){return e*=1,t>>>=0,r||m(this,e,t,4,0x7fffffff,-0x80000000),e<0&&(e=0xffffffff+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},i.prototype.writeFloatLE=function(e,t,r){return v(this,e,t,!0,r)},i.prototype.writeFloatBE=function(e,t,r){return v(this,e,t,!1,r)},i.prototype.writeDoubleLE=function(e,t,r){return E(this,e,t,!0,r)},i.prototype.writeDoubleBE=function(e,t,r){return E(this,e,t,!1,r)},i.prototype.copy=function(e,t,r,n){if(!i.isBuffer(e))throw TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r||0===e.length||0===this.length)return 0;if(t<0)throw RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw RangeError("Index out of range");if(n<0)throw RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var o=n-r;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,r,n):Uint8Array.prototype.set.call(e,this.subarray(r,n),t),o},i.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw TypeError("encoding must be a string");if("string"==typeof n&&!i.isEncoding(n))throw TypeError("Unknown encoding: "+n);if(1===e.length){var o,s=e.charCodeAt(0);("utf8"===n&&s<128||"latin1"===n)&&(e=s)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw RangeError("Out of range index");if(r<=t)return this;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(o=t;o<r;++o)this[o]=e;else{var a=i.isBuffer(e)?e:i.from(e,n),c=a.length;
1if(0===c)throw TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<r-t;++o)this[o+t]=a[o%c]}return this};var S=/[^+/0-9A-Za-z-_]/g;function _(e,t){t=t||1/0;for(var r,n=e.length,i=null,o=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!i){if(r>56319||s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else if(r<1114112){if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}else throw Error("Invalid code point")}return o}function A(e){return I(function(e){if((e=(e=e.split("=")[0]).trim().replace(S,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function x(e,t,r,n){for(var i=0;i<n&&!(i+r>=t.length)&&!(i>=e.length);++i)t[i+r]=e[i];return i}function O(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}var T=function(){for(var e="0123456789abcdef",t=Array(256),r=0;r<16;++r)for(var n=16*r,i=0;i<16;++i)t[n+i]=e[r]+e[i];return t}()}(r={exports:{}},r.exports),r.exports),j=R.Buffer;R.SlowBuffer,R.INSPECT_MAX_BYTES,R.kMaxLength;var H=function(e,t){return(H=Object.setPrototypeOf||({__proto__:[]})instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function D(e,t){function r(){this.constructor=e}H(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var W=function(){return(W=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},K=function(e){function t(r){var n=e.call(this,r)||this;return Object.setPrototypeOf(n,t.prototype),n}return D(t,e),Object.defineProperty(t.prototype,"name",{get:function(){return"BSONError"},enumerable:!1,configurable:!0}),t}(Error),M=function(e){function t(r){var n=e.call(this,r)||this;return Object.setPrototypeOf(n,t.prototype),n}return D(t,e),Object.defineProperty(t.prototype,"name",{get:function(){return"BSONTypeError"},enumerable:!1,configurable:!0}),t}(TypeError);function J(e){return e&&e.Math==Math&&e}function L(){return J("object"==typeof globalThis&&globalThis)||J("object"==typeof window&&window)||J("object"==typeof self&&self)||J(e.g)||Function("return this")()}function $(e){return e.toString().replace("function(","function (")}var F=function(e){console.warn("object"==typeof(t=L()).navigator&&"ReactNative"===t.navigator.product?"BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.":"BSON: No cryptographic implementation for random bytes present, falling back to a less secure implementation.");for(var t,r=j.alloc(e),n=0;n<e;++n)r[n]=Math.floor(256*Math.random());return r},V=function(){if("u">typeof window){var t=window.crypto||window.msCrypto;if(t&&t.getRandomValues)return function(e){return t.getRandomValues(j.alloc(e))}}return e.g.crypto&&e.g.crypto.getRandomValues?function(t){return e.g.crypto.getRandomValues(j.alloc(t))}:F}();function z(e){return["[object ArrayBuffer]","[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(e))}function G(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)}function Y(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function q(e){return X(e)&&"[object Date]"===Object.prototype.toString.call(e)}function X(e){return"object"==typeof e&&null!==e}function Z(e,t){var r=!1;return function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];return r||(console.warn(t),r=!0),e.apply(this,n)}}function Q(e){if(ArrayBuffer.isView(e))return j.from(e.buffer,e.byteOffset,e.byteLength);if(z(e))return j.from(e);throw new M("Must use either Buffer or TypedArray")}var ee=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15})$/i,et=function(e){return"string"==typeof e&&ee.test(e)},er=function(e){if(!et(e))throw new M('UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".');var t=e.replace(/-/g,"");return j.from(t,"hex")},en=function(e,t){return void 0===t&&(t=!0),t?e.toString("hex",0,4)+"-"+e.toString("hex",4,6)+"-"+e.toString("hex",6,8)+"-"+e.toString("hex",8,10)+"-"+e.toString("hex",10,16):e.toString("hex")},ei=function(){function e(t,r){if(!(this instanceof e))return new e(t,r);
1if(null!=t&&"string"!=typeof t&&!ArrayBuffer.isView(t)&&!(t instanceof ArrayBuffer)&&!Array.isArray(t))throw new M("Binary can only be constructed from string, Buffer, TypedArray, or Array<number>");this.sub_type=null!=r?r:e.BSON_BINARY_SUBTYPE_DEFAULT,null==t?(this.buffer=j.alloc(e.BUFFER_SIZE),this.position=0):("string"==typeof t?this.buffer=j.from(t,"binary"):Array.isArray(t)?this.buffer=j.from(t):this.buffer=Q(t),this.position=this.buffer.byteLength)}return e.prototype.put=function(t){if("string"==typeof t&&1!==t.length)throw new M("only accepts single character String");if("number"!=typeof t&&1!==t.length)throw new M("only accepts single character Uint8Array or Array");if((r="string"==typeof t?t.charCodeAt(0):"number"==typeof t?t:t[0])<0||r>255)throw new M("only accepts number in a valid unsigned byte range 0-255");if(this.buffer.length>this.position)this.buffer[this.position++]=r;else{var r,n=j.alloc(e.BUFFER_SIZE+this.buffer.length);this.buffer.copy(n,0,0,this.buffer.length),this.buffer=n,this.buffer[this.position++]=r}},e.prototype.write=function(e,t){if(t="number"==typeof t?t:this.position,this.buffer.length<t+e.length){var r=j.alloc(this.buffer.length+e.length);this.buffer.copy(r,0,0,this.buffer.length),this.buffer=r}ArrayBuffer.isView(e)?(this.buffer.set(Q(e),t),this.position=t+e.byteLength>this.position?t+e.length:this.position):"string"==typeof e&&(this.buffer.write(e,t,e.length,"binary"),this.position=t+e.length>this.position?t+e.length:this.position)},e.prototype.read=function(e,t){return t=t&&t>0?t:this.position,this.buffer.slice(e,e+t)},e.prototype.value=function(e){return(e=!!e)&&this.buffer.length===this.position?this.buffer:e?this.buffer.slice(0,this.position):this.buffer.toString("binary",0,this.position)},e.prototype.length=function(){return this.position},e.prototype.toJSON=function(){return this.buffer.toString("base64")},e.prototype.toString=function(e){return this.buffer.toString(e)},e.prototype.toExtendedJSON=function(e){e=e||{};var t=this.buffer.toString("base64"),r=Number(this.sub_type).toString(16);return e.legacy?{$binary:t,$type:1===r.length?"0"+r:r}:{$binary:{base64:t,subType:1===r.length?"0"+r:r}}},e.prototype.toUUID=function(){if(this.sub_type===e.SUBTYPE_UUID)return new eo(this.buffer.slice(0,this.position));throw new K('Binary sub_type "'.concat(this.sub_type,'" is not supported for converting to UUID. Only "').concat(e.SUBTYPE_UUID,'" is currently supported.'))},e.fromExtendedJSON=function(t,r){var n,i;if(r=r||{},"$binary"in t?r.legacy&&"string"==typeof t.$binary&&"$type"in t?(i=t.$type?parseInt(t.$type,16):0,n=j.from(t.$binary,"base64")):"string"!=typeof t.$binary&&(i=t.$binary.subType?parseInt(t.$binary.subType,16):0,n=j.from(t.$binary.base64,"base64")):"$uuid"in t&&(i=4,n=er(t.$uuid)),!n)throw new M("Unexpected Binary Extended JSON format ".concat(JSON.stringify(t)));return 4===i?new eo(n):new e(n,i)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){var e=this.value(!0);return'new Binary(Buffer.from("'.concat(e.toString("hex"),'", "hex"), ').concat(this.sub_type,")")},e.BSON_BINARY_SUBTYPE_DEFAULT=0,e.BUFFER_SIZE=256,e.SUBTYPE_DEFAULT=0,e.SUBTYPE_FUNCTION=1,e.SUBTYPE_BYTE_ARRAY=2,e.SUBTYPE_UUID_OLD=3,e.SUBTYPE_UUID=4,e.SUBTYPE_MD5=5,e.SUBTYPE_ENCRYPTED=6,e.SUBTYPE_COLUMN=7,e.SUBTYPE_USER_DEFINED=128,e}();Object.defineProperty(ei.prototype,"_bsontype",{value:"Binary"});var eo=function(e){function t(r){var n,i,o=this;if(null==r)n=t.generate();else if(r instanceof t)n=j.from(r.buffer),i=r.__id;else if(ArrayBuffer.isView(r)&&16===r.byteLength)n=Q(r);else if("string"==typeof r)n=er(r);else throw new M("Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).");return(o=e.call(this,n,4)||this).__id=i,o}return D(t,e),Object.defineProperty(t.prototype,"id",{get:function(){return this.buffer},set:function(e){this.buffer=e,t.cacheHexString&&(this.__id=en(e))},enumerable:!1,configurable:!0}),t.prototype.toHexString=function(e){if(void 0===e&&(e=!0),t.cac
1heHexString&&this.__id)return this.__id;var r=en(this.id,e);return t.cacheHexString&&(this.__id=r),r},t.prototype.toString=function(e){return e?this.id.toString(e):this.toHexString()},t.prototype.toJSON=function(){return this.toHexString()},t.prototype.equals=function(e){if(!e)return!1;if(e instanceof t)return e.id.equals(this.id);try{return new t(e).id.equals(this.id)}catch(e){return!1}},t.prototype.toBinary=function(){return new ei(this.id,ei.SUBTYPE_UUID)},t.generate=function(){var e=V(16);return e[6]=15&e[6]|64,e[8]=63&e[8]|128,j.from(e)},t.isValid=function(e){return!!e&&(e instanceof t||("string"==typeof e?et(e):!!G(e)&&16===e.length&&(240&e[6])==64&&(128&e[8])==128))},t.createFromHexString=function(e){return new t(er(e))},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return'new UUID("'.concat(this.toHexString(),'")')},t}(ei),es=function(){function e(t,r){if(!(this instanceof e))return new e(t,r);this.code=t,this.scope=r}return e.prototype.toJSON=function(){return{code:this.code,scope:this.scope}},e.prototype.toExtendedJSON=function(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}},e.fromExtendedJSON=function(t){return new e(t.$code,t.$scope)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){var e=this.toJSON();return'new Code("'.concat(String(e.code),'"').concat(e.scope?", ".concat(JSON.stringify(e.scope)):"",")")},e}();function ea(e){return X(e)&&null!=e.$id&&"string"==typeof e.$ref&&(null==e.$db||"string"==typeof e.$db)}Object.defineProperty(es.prototype,"_bsontype",{value:"Code"});var ec=function(){function e(t,r,n,i){if(!(this instanceof e))return new e(t,r,n,i);var o=t.split(".");2===o.length&&(n=o.shift(),t=o.shift()),this.collection=t,this.oid=r,this.db=n,this.fields=i||{}}return Object.defineProperty(e.prototype,"namespace",{get:function(){return this.collection},set:function(e){this.collection=e},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){var e=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return null!=this.db&&(e.$db=this.db),e},e.prototype.toExtendedJSON=function(e){e=e||{};var t={$ref:this.collection,$id:this.oid};return e.legacy?t:(this.db&&(t.$db=this.db),t=Object.assign(t,this.fields))},e.fromExtendedJSON=function(t){var r=Object.assign({},t);return delete r.$ref,delete r.$id,delete r.$db,new e(t.$ref,t.$id,t.$db,r)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){var e=void 0===this.oid||void 0===this.oid.toString?this.oid:this.oid.toString();return'new DBRef("'.concat(this.namespace,'", new ObjectId("').concat(String(e),'")').concat(this.db?', "'.concat(this.db,'"'):"",")")},e}();Object.defineProperty(ec.prototype,"_bsontype",{value:"DBRef"});var eu=void 0;try{eu=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(e){}var ef={},el={},eh=function(){function e(t,r,n){if(void 0===t&&(t=0),!(this instanceof e))return new e(t,r,n);"bigint"==typeof t?Object.assign(this,e.fromBigInt(t,!!r)):"string"==typeof t?Object.assign(this,e.fromString(t,!!r)):(this.low=0|t,this.high=0|r,this.unsigned=!!n),Object.defineProperty(this,"__isLong__",{value:!0,configurable:!1,writable:!1,enumerable:!1})}return e.fromBits=function(t,r,n){return new e(t,r,n)},e.fromInt=function(t,r){var n,i,o;if(r)return(t>>>=0,(o=0<=t&&t<256)&&(i=el[t]))?i:(n=e.fromBits(t,(0|t)<0?-1:0,!0),o&&(el[t]=n),n);return(t|=0,(o=-128<=t&&t<128)&&(i=ef[t]))?i:(n=e.fromBits(t,t<0?-1:0,!1),o&&(ef[t]=n),n)},e.fromNumber=function(t,r){if(isNaN(t))return r?e.UZERO:e.ZERO;if(r){if(t<0)return e.UZERO;if(t>=0xffffffffffffffff)return e.MAX_UNSIGNED_VALUE}
1else{if(t<=-0x8000000000000000)return e.MIN_VALUE;if(t+1>=0x8000000000000000)return e.MAX_VALUE}return t<0?e.fromNumber(-t,r).neg():e.fromBits(t%0x100000000|0,t/0x100000000|0,r)},e.fromBigInt=function(t,r){return e.fromString(t.toString(),r)},e.fromString=function(t,r,n){if(0===t.length)throw Error("empty string");if("NaN"===t||"Infinity"===t||"+Infinity"===t||"-Infinity"===t)return e.ZERO;if("number"==typeof r?(n=r,r=!1):r=!!r,(n=n||10)<2||36<n)throw RangeError("radix");if((i=t.indexOf("-"))>0)throw Error("interior hyphen");if(0===i)return e.fromString(t.substring(1),r,n).neg();for(var i,o=e.fromNumber(Math.pow(n,8)),s=e.ZERO,a=0;a<t.length;a+=8){var c=Math.min(8,t.length-a),u=parseInt(t.substring(a,a+c),n);if(c<8){var f=e.fromNumber(Math.pow(n,c));s=s.mul(f).add(e.fromNumber(u))}else s=(s=s.mul(o)).add(e.fromNumber(u))}return s.unsigned=r,s},e.fromBytes=function(t,r,n){return n?e.fromBytesLE(t,r):e.fromBytesBE(t,r)},e.fromBytesLE=function(t,r){return new e(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,r)},e.fromBytesBE=function(t,r){return new e(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],r)},e.isLong=function(e){return X(e)&&!0===e.__isLong__},e.fromValue=function(t,r){return"number"==typeof t?e.fromNumber(t,r):"string"==typeof t?e.fromString(t,r):e.fromBits(t.low,t.high,"boolean"==typeof r?r:t.unsigned)},e.prototype.add=function(t){e.isLong(t)||(t=e.fromValue(t));var r,n,i=this.high>>>16,o=65535&this.high,s=this.low>>>16,a=65535&this.low,c=t.high>>>16,u=65535&t.high,f=t.low>>>16,l=65535&t.low,h=0,d=0;return r=0+((n=0+(a+l))>>>16),n&=65535,r+=s+f,d+=r>>>16,r&=65535,d+=o+u,h+=d>>>16,d&=65535,h+=i+c,h&=65535,e.fromBits(r<<16|n,h<<16|d,this.unsigned)},e.prototype.and=function(t){return e.isLong(t)||(t=e.fromValue(t)),e.fromBits(this.low&t.low,this.high&t.high,this.unsigned)},e.prototype.compare=function(t){if(e.isLong(t)||(t=e.fromValue(t)),this.eq(t))return 0;var r=this.isNegative(),n=t.isNegative();return r&&!n?-1:!r&&n?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1},e.prototype.comp=function(e){return this.compare(e)},e.prototype.divide=function(t){if(e.isLong(t)||(t=e.fromValue(t)),t.isZero())throw Error("division by zero");if(eu){if(!this.unsigned&&-0x80000000===this.high&&-1===t.low&&-1===t.high)return this;var r,n,i,o=(this.unsigned?eu.div_u:eu.div_s)(this.low,this.high,t.low,t.high);return e.fromBits(o,eu.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?e.UZERO:e.ZERO;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return e.UZERO;if(t.gt(this.shru(1)))return e.UONE;i=e.UZERO}else{if(this.eq(e.MIN_VALUE))if(t.eq(e.ONE)||t.eq(e.NEG_ONE))return e.MIN_VALUE;else return t.eq(e.MIN_VALUE)?e.ONE:(r=this.shr(1).div(t).shl(1)).eq(e.ZERO)?t.isNegative()?e.ONE:e.NEG_ONE:(n=this.sub(t.mul(r)),i=r.add(n.div(t)));if(t.eq(e.MIN_VALUE))return this.unsigned?e.UZERO:e.ZERO;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();i=e.ZERO}for(n=this;n.gte(t);){for(var s=Math.ceil(Math.log(r=Math.max(1,Math.floor(n.toNumber()/t.toNumber())))/Math.LN2),a=s<=48?1:Math.pow(2,s-48),c=e.fromNumber(r),u=c.mul(t);u.isNegative()||u.gt(n);)r-=a,u=(c=e.fromNumber(r,this.unsigned)).mul(t);c.isZero()&&(c=e.ONE),i=i.add(c),n=n.sub(u)}return i},e.prototype.div=function(e){return this.divide(e)},e.prototype.equals=function(t){return e.isLong(t)||(t=e.fromValue(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=1)&&this.high===t.high&&this.low===t.low},e.prototype.eq=function(e){return this.equals(e)},e.prototype.getHighBits=function(){return this.high},e.prototype.getHighBitsUnsigned=function(){return this.high>>>0},e.prototype.getLowBits=function(){return this.low},e.prototype.getLowBitsUnsigned=function(){return this.low>>>0},e.prototype.getNumBitsAbs=function(){if(this.isNegative())return this.eq(e.MIN_VALUE)?64:this.neg().getNumBitsAbs();var t,r=0!==this.high?this.high:this.low;for(t=31;t>0&&(r&1<<t)==0;t--);return 0!==this.high?t+33:t+1},e.prototype.greaterThan=function(e){return this.comp(e)>0},e.prototype.gt=function(e){return this.greaterThan(e)},e.prototype.greaterThanOrEqual=function(e){return this.comp(e)>=0},e.prototype.gte=function(e){return this.greaterThanOrEqual(e)},e.prototype.ge=function(e){return this.greaterThanOrEqual(e)},e.prototype.isEven=function(){return(1&this.low)==0},e.prototype.isNegative=function(){return!this.unsigned&&this.high<0},e.prototype.isOdd=function(){return(1&this.low)==1},e.prototype.isPositive=function(){return this.unsigned||this.high>=0},e.prototype.isZero=function(){return 0===this.high&&0===this.low},e.prototype.lessThan=function(e){return 0>this.comp(e)},e.prototype.lt=function(e){return this.lessThan(e)},e.prototype.lessThanOrEqual=function(e){return 0>=this.comp(e)},e.prototype.lte=function(e){return this.lessThanOrEqual(e)},e.prototype.modulo=function(t){if(e.isLong(t)||(t=e.fromValue(t)),eu){var r=(this.unsigned?eu.rem_u:eu.rem_s)(this.low,this.high,t.low,t.high);return e.fromBits(r,eu.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))},e.prototype.mod=function(e){return this.modulo(e)},e.prototype.rem=function(e){return this.modulo(e)},e.prototype.multiply=function(t){if(this.isZero())return e.ZERO;if(e.isLong(t)||(t=e.fromValue(t)),eu){var r=eu.mul(this.low,this.high,t.low,t.high);return e.fromBits(r,eu.get_high(),this.unsigned)}if(t.isZero())return e.ZERO;if(this.eq(e.MIN_VALUE))return t.isOdd()?e.MIN_VALUE:e.ZERO;if(t.eq(e.MIN_VALUE))return this.isOdd()?e.MIN_VALUE:e.ZERO;if(this.isNegative())if(t.isNegative())return this.neg().mul(t.neg());else return this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(e.TWO_PWR_24)&&t.lt(e.TWO_PWR_24))return e.fromNumber(this.toNumber()*t.toNumber(),this.unsigned);var n,i,o=this.high>>>16,s=65535&this.high,a=this.low>>>16,c=65535&this.low,u=t.high>>>16,f=65535&t.high,l=t.low>>>16,h=65535&t.low,d=0,p=0;return n=0+((i=0+c*h)>>>16),i&=65535,n+=a*h,p+=n>>>16,n&=65535,n+=c*l,p+=n>>>16,n&=65535,p+=s*h,d+=p>>>16,p&=65535,p+=a*l,d+=p>>>16,p&=65535,p+=c*f,d+=p>>>16,p&=65535,d+=o*h+s*l+a*f+c*u,d&=65535,e.fromBits(n<<16|i,d<<16|p,this.unsigned)},e.prototype.mul=function(e){return this.multiply(e)},e.prototype.negate=function(){return!this.unsigned&&this.eq(e.MIN_VALUE)?e.MIN_VALUE:this.not().add(e.ONE)},e.prototype.neg=function(){return this.negate()},e.prototype.not=function(){return e.fromBits(~this.low,~this.high,this.unsigned)},e.prototype.notEquals=function(e){return!this.equals(e)},e.prototype.neq=function(e){return this.notEquals(e)},e.prototype.ne=function(e){return this.notEquals(e)},e.prototype.or=function(t){return e.isLong(t)||(t=e.fromValue(t)),e.fromBits(this.low|t.low,this.high|t.high,this.unsigned)},e.prototype.shiftLeft=function(t){return(e.isLong(t)&&(t=t.toInt()),0==(t&=63))?this:t<32?e.fromBits(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):e.fromBits(0,this.low<<t-32,this.unsigned)},e.prototype.shl=function(e){return this.shiftLeft(e)},e.prototype.shiftRight=function(t){return(e.isLong(t)&&(t=t.toInt()),0==(t&=63))?this:t<32?e.fromBits(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):e.fromBits(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},e.prototype.shr=function(e){return this.shiftRight(e)},e.prototype.shiftRightUnsigned=function(t){if(e.isLong(t)&&(t=t.toInt()),0==(t&=63))return this;var r=this.high;if(t<32){var n=this.low;return e.fromBits(n>>>t|r<<32-t,r>>>t,this.unsigned)}return 32===t?e.fromBits(r,0,this.unsigned):e.fromBits(r>>>t-32,0,this.unsigned)},e.prototype.shr_u=function(e){return this.shiftRightUnsigned(e)},e.prototype.shru=function(e){return this.shiftRightUnsigned(e)},e.prototype.subtract=function(t){return e.isLong(t)||(t=e.fromValue(t)),this.add(t.neg())},e.prototype.sub=function(e){return this.subtract(e)},e.prototype.toInt=function(){return this.unsigned?this.low>>>0:this.low},e.prototype.toNumber=function(){return this.unsigned?(this.high>>>0)*0x100000000+(this.low>>>0):0x100000000*this.high+(this.low>>>0)},e.prototype.toBigInt=function(){return BigInt(this.toString())},e.prototype.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},e.prototype.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},e.prototype.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},e.prototype.toSigned=function(){return this.unsigned?e.fromBits(this.low,this.high,!1):this},e.prototype.toString=function(t){if((t=t||10)<2||36<t)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative())if(!this.eq(e.MIN_VALUE))return"-"+this.neg().toString(t);else{var r=e.fromNumber(t),n=this.div(r),i=n.mul(r).sub(this);return n.toString(t)+i.toInt().toString(t)}for(var o=e.fromNumber(Math.pow(t,6),this.unsigned),s=this,a="";;){var c=s.div(o),u=(s.sub(c.mul(o)).toInt()>>>0).toString(t);if((s=c).isZero())return u+a;for(;u.length<6;)u="0"+u;a=""+u+a}},e.prototype.toUnsigned=function(){return this.unsigned?this:e.fromBits(this.low,this.high,!0)},e.prototype.xor=function(t){return e.isLong(t)||(t=e.fromValue(t)),e.fromBits(this.low^t.low,this.high^t.high,this.unsigned)},e.prototype.eqz=function(){return this.isZero()},e.prototype.le=function(e){return this.lessThanOrEqual(e)},e.prototype.toExtendedJSON=function(e){return e&&e.relaxed?this.toNumber():{$numberLong:this.toString()}},e.fromExtendedJSON=function(t,r){var n=e.fromString(t.$numberLong);return r&&r.relaxed?n.toNumber():n},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return'new Long("'.concat(this.toString(),'"').concat(this.unsigned?", true":"",")")},e.TWO_PWR_24=e.fromInt(0x1000000),e.MAX_UNSIGNED_VALUE=e.fromBits(-1,-1,!0),e.ZERO=e.fromInt(0),e.UZERO=e.fromInt(0,!0),e.ONE=e.fromInt(1),e.UONE=e.fromInt(1,!0),e.NEG_ONE=e.fromInt(-1),e.MAX_VALUE=e.fromBits(-1,0x7fffffff,!1),e.MIN_VALUE=e.fromBits(0,-0x80000000,!1),e}();Object.defineProperty(eh.prototype,"__isLong__",{value:!0}),Object.defineProperty(eh.prototype,"_bsontype",{value:"Long"});var ed=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,ep=/^(\+|-)?(Infinity|inf)$/i,ey=/^(\+|-)?NaN$/i,eg=[124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),ew=[248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),em=[120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse(),eb=/^([-+])?(\d+)?$/;function ev(e){return!isNaN(parseInt(e,10))}function eE(e,t){throw new M('"'.concat(e,'" is not a valid Decimal128 str
1ing - ').concat(t))}var eS=function(){function e(t){if(!(this instanceof e))return new e(t);if("string"==typeof t)this.bytes=e.fromString(t).bytes;else if(G(t)){if(16!==t.byteLength)throw new M("Decimal128 must take a Buffer of 16 bytes");this.bytes=t}else throw new M("Decimal128 must take a Buffer or string")}return e.fromString=function(t){var r,n,i,o,s=!1,a=!1,c=!1,u=0,f=0,l=0,h=0,d=0,p=[0],y=0,g=0,w=0,m=0,b=0,v=0,E=new eh(0,0),S=new eh(0,0),_=0,A=0;if(t.length>=7e3)throw new M(""+t+" not a valid Decimal128 string");var x=t.match(ed),O=t.match(ep),T=t.match(ey);if(!x&&!O&&!T||0===t.length)throw new M(""+t+" not a valid Decimal128 string");if(x){var N=x[2],k=x[4],U=x[5],I=x[6];k&&void 0===I&&eE(t,"missing exponent power"),k&&void 0===N&&eE(t,"missing exponent base"),void 0===k&&(U||I)&&eE(t,"missing e before exponent")}if(("+"===t[A]||"-"===t[A])&&(s="-"===t[A++]),!ev(t[A])&&"."!==t[A]){if("i"===t[A]||"I"===t[A])return new e(j.from(s?ew:em));else if("N"===t[A])return new e(j.from(eg))}for(;ev(t[A])||"."===t[A];){if("."===t[A]){a&&eE(t,"contains multiple periods"),a=!0,A+=1;continue}y<34&&("0"!==t[A]||c)&&(c||(d=f),c=!0,p[g++]=parseInt(t[A],10),y+=1),c&&(l+=1),a&&(h+=1),f+=1,A+=1}if(a&&!f)throw new M(""+t+" not a valid Decimal128 string");if("e"===t[A]||"E"===t[A]){var P=t.substr(++A).match(eb);if(!P||!P[2])return new e(j.from(eg));b=parseInt(P[0],10),A+=P[0].length}if(t[A])return new e(j.from(eg));if(w=0,y){if(m=y-1,1!==(u=l))for(;0===p[d+u-1];)u-=1}else w=0,m=0,p[0]=0,l=1,y=1,u=0;for(b<=h&&h-b>16384?b=-6176:b-=h;b>6111;){if((m+=1)-w>34){var B=p.join("");if(B.match(/^0+$/)){b=6111;break}eE(t,"overflow")}b-=1}for(;b<-6176||y<l;){if(0===m&&u<y){b=-6176,u=0;break}if(y<l?l-=1:m-=1,b<6111)b+=1;else{var B=p.join("");if(B.match(/^0+$/)){b=6111;break}eE(t,"overflow")}}if(m-w+1<u){var C=f;a&&(d+=1,C+=1),s&&(d+=1,C+=1);var R=parseInt(t[d+m+1],10),H=0;if(R>=5&&(H=1,5===R)){for(H=+(p[m]%2==1),v=d+m+2;v<C;v++)if(parseInt(t[v],10)){H=1;break}}if(H){for(var D=m;D>=0;D--)if(++p[D]>9&&(p[D]=0,0===D))if(!(b<6111))return new e(j.from(s?ew:em));else b+=1,p[D]=1}}if(E=eh.fromNumber(0),S=eh.fromNumber(0),0===u)E=eh.fromNumber(0),S=eh.fromNumber(0);else if(m-w<17){var D=w;for(S=eh.fromNumber(p[D++]),E=new eh(0,0);D<=m;D++)S=(S=S.multiply(eh.fromNumber(10))).add(eh.fromNumber(p[D]))}else{var D=w;for(E=eh.fromNumber(p[D++]);D<=m-17;D++)E=(E=E.multiply(eh.fromNumber(10))).add(eh.fromNumber(p[D]));for(S=eh.fromNumber(p[D++]);D<=m;D++)S=(S=S.multiply(eh.fromNumber(10))).add(eh.fromNumber(p[D]))}var W=function(e,t){if(!e&&!t)return{high:eh.fromNumber(0),low:eh.fromNumber(0)};var r=e.shiftRightUnsigned(32),n=new eh(e.getLowBits(),0),i=t.shiftRightUnsigned(32),o=new eh(t.getLowBits(),0),s=r.multiply(i),a=r.multiply(o),c=n.multiply(i),u=n.multiply(o);return s=s.add(a.shiftRightUnsigned(32)),a=new eh(a.getLowBits(),0).add(c).add(u.shiftRightUnsigned(32)),{high:s=s.add(a.shiftRightUnsigned(32)),low:u=a.shiftLeft(32).add(new eh(u.getLowBits(),0))}}(E,eh.fromString("100000000000000000"));W.low=W.low.add(S),r=W.low,n=S,i=r.high>>>0,(i<(o=n.high>>>0)||i===o&&r.low>>>0<n.low>>>0||0)&&(W.high=W.high.add(eh.fromNumber(1))),_=b+6176;var K={low:eh.fromNumber(0),high:eh.fromNumber(0)};W.high.shiftRightUnsigned(49).and(eh.fromNumber(1)).equals(eh.fromNumber(1))?(K.high=K.high.or(eh.fromNumber(3).shiftLeft(61)),K.high=K.high.or(eh.fromNumber(_).and(eh.fromNumber(16383).shiftLeft(47))),K.high=K.high.or(W.high.and(eh.fromNumber(0x7fffffffffff)))):(K.high=K.high.or(eh.fromNumber(16383&_).shiftLeft(49)),K.high=K.high.or(W.high.and(eh.fromNumber(0x1ffffffffffff)))),K.low=W.low,s&&(K.high=K.high.or(eh.fromString("9223372036854775808")));var J=j.alloc(16);return A=0,J[A++]=255&K.low.low,J[A++]=K.low.low>>8&255,J[A++]=K.low.low>>16&255,J[A++]=K.low.low>>24&255,J[A++]=255&K.low.high,J[A++]=K.low.high>>8&255,J[A++]=K.low.high>>16&255,J[A++]=K.low.high>>24&255,J[A++]=255&K.high.low,J[A++]=K.high.low>>8&255,J[A++]=K.high.low>>16&255,J[A++]=K.high.low>>24&255,J[A++]=255&K.high.high,J[A++]=K.high.high>>8&255,J[A++]=K.high.high>>16&255,J[A++]=K.high.high>>24&255,new e(J)},e.prototype.toString=function(){for(var e,t,r,n,i=0,o=Array(36),s=0;s<o.length;s++)o[s]=0;var a=0,c=!1,u={parts:[0,0,0,0]},f=[];a=0;var l=this.bytes,h=l[a++]|l[a++]<<8|l[a++]<<16|l[a++]<<24,d=l[a++]|l[a++]<<8|l[a++]<<16|l[a++]<<24,p=l[a++]|l[a++]<<8|l[a++]<<16|l[a++]<<24,y=l[a++]|l[a++]<<8|l[a++]<<16|l[a++]<<24;a=0,({low:new eh(h,d),high:new eh(p,y)}).high.lessThan(eh.ZERO)&&f.push("-");var g=y>>26&31;if(g>>3==3)if(30===g)return f.join("")+"Infinity";else{if(31===g)return"NaN";e=y>>15&16383,t=8+(y>>14&1)}else t=y>>14&7,e=y>>17&16383;var w=e-6176;if(u.parts[0]=(16383&y)+((15&t)<<14),u.parts[1]=p,u.parts[2]=d,u.parts[3]=h,0===u.parts[0]&&0===u.parts[1]&&0===u.parts[2]&&0===u.parts[3])c=!0;else for(n=3;n>=0;n--){var m=0,b=function(e){var t=eh.fromNumber(1e9),r=eh.fromNumber(0);if(!e.parts[0]&&!e.parts[1]&&!e.parts[2]&&!e.parts[3])return{quotient:e,rem:r};for(var n=0;n<=3;n++)r=(r=r.shiftLeft(32)).add(new eh(e.parts[n],0)),e.parts[n]=r.div(t).low,r=r.modulo(t);return{quotient:e,rem:r}}(u);if(u=b.quotient,m=b.rem.low)for(r=8;r>=0;r--)o[9*n+r]=m%10,m=Math.floor(m/10)}if(c)i=1,o[a]=0;else for(i=36;!o[a];)i-=1,a+=1;var v=i-1+w;if(v>=34||v<=-7||w>0){if(i>34)return f.push("".concat(0)),w>0?f.push("E+".concat(w)):w<0&&f.push("E".concat(w)),f.join("");f.push("".concat(o[a++])),(i-=1)&&f.push(".");for(var s=0;s<i;s++)f.push("".concat(o[a++]));f.push("E"),v>0?f.push("+".concat(v)):f.push("".concat(v))}else if(w>=0)for(var s=0;s<i;s++)f.push("".concat(o[a++]));else{var E=i+w;
1if(E>0)for(var s=0;s<E;s++)f.push("".concat(o[a++]));else f.push("0");for(f.push(".");E++<0;)f.push("0");for(var s=0;s<i-Math.max(E-1,0);s++)f.push("".concat(o[a++]))}return f.join("")},e.prototype.toJSON=function(){return{$numberDecimal:this.toString()}},e.prototype.toExtendedJSON=function(){return{$numberDecimal:this.toString()}},e.fromExtendedJSON=function(t){return e.fromString(t.$numberDecimal)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return'new Decimal128("'.concat(this.toString(),'")')},e}();Object.defineProperty(eS.prototype,"_bsontype",{value:"Decimal128"});var e_=function(){function e(t){if(!(this instanceof e))return new e(t);t instanceof Number&&(t=t.valueOf()),this.value=+t}return e.prototype.valueOf=function(){return this.value},e.prototype.toJSON=function(){return this.value},e.prototype.toString=function(e){return this.value.toString(e)},e.prototype.toExtendedJSON=function(e){return e&&(e.legacy||e.relaxed&&isFinite(this.value))?this.value:Object.is(Math.sign(this.value),-0)?{$numberDouble:"-".concat(this.value.toFixed(1))}:{$numberDouble:Number.isInteger(this.value)?this.value.toFixed(1):this.value.toString()}},e.fromExtendedJSON=function(t,r){var n=parseFloat(t.$numberDouble);return r&&r.relaxed?n:new e(n)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){var e=this.toExtendedJSON();return"new Double(".concat(e.$numberDouble,")")},e}();Object.defineProperty(e_.prototype,"_bsontype",{value:"Double"});var eA=function(){function e(t){if(!(this instanceof e))return new e(t);t instanceof Number&&(t=t.valueOf()),this.value=0|t}return e.prototype.valueOf=function(){return this.value},e.prototype.toString=function(e){return this.value.toString(e)},e.prototype.toJSON=function(){return this.value},e.prototype.toExtendedJSON=function(e){return e&&(e.relaxed||e.legacy)?this.value:{$numberInt:this.value.toString()}},e.fromExtendedJSON=function(t,r){return r&&r.relaxed?parseInt(t.$numberInt,10):new e(t.$numberInt)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return"new Int32(".concat(this.valueOf(),")")},e}();Object.defineProperty(eA.prototype,"_bsontype",{value:"Int32"});var ex=function(){function e(){if(!(this instanceof e))return new e}return e.prototype.toExtendedJSON=function(){return{$maxKey:1}},e.fromExtendedJSON=function(){return new e},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return"new MaxKey()"},e}();Object.defineProperty(ex.prototype,"_bsontype",{value:"MaxKey"});var eO=function(){function e(){if(!(this instanceof e))return new e}return e.prototype.toExtendedJSON=function(){return{$minKey:1}},e.fromExtendedJSON=function(){return new e},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return"new MinKey()"},e}();Object.defineProperty(eO.prototype,"_bsontype",{value:"MinKey"});var eT=RegExp("^[0-9a-fA-F]{24}$"),eN=null,ek=Symbol("id"),eU=function(){function e(t){if(!(this instanceof e))return new e(t);if("object"==typeof t&&t&&"id"in t){if("string"!=typeof t.id&&!ArrayBuffer.isView(t.id))throw new M("Argument passed in must have an id that is of type string or Buffer");r="toHexString"in t&&"function"==typeof t.toHexString?j.from(t.toHexString(),"hex"):t.id}else r=t;if(null==r||"number"==typeof r)this[ek]=e.generate("number"==typeof r?r:void 0);else if(ArrayBuffer.isView(r)&&12===r.byteLength)this[ek]=r instanceof j?r:Q(r);else if("string"==typeof r)if(12===r.length){var r,n=j.from(r);if(12===n.byteLength)this[ek]=n;else throw new M("Argument passed in must be a string of 12 bytes")}else if(24===r.length&&eT.test(r))this[ek]=j.from(r,"hex");else throw new M("Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer");else throw new M("Argument passed in does not match the accepted types");e.cacheHexString&&(this.__id=this.id.toString("hex"))}return Object.defineProperty(e.prototype,"id",{get:function(){return this[ek]},set:function(t){this[ek]=t,e.cacheHexString&&(this.__id=t.toString("hex"))}
1,enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"generationTime",{get:function(){return this.id.readInt32BE(0)},set:function(e){this.id.writeUInt32BE(e,0)},enumerable:!1,configurable:!0}),e.prototype.toHexString=function(){if(e.cacheHexString&&this.__id)return this.__id;var t=this.id.toString("hex");return e.cacheHexString&&!this.__id&&(this.__id=t),t},e.getInc=function(){return e.index=(e.index+1)%0xffffff},e.generate=function(t){"number"!=typeof t&&(t=Math.floor(Date.now()/1e3));var r=e.getInc(),n=j.alloc(12);return n.writeUInt32BE(t,0),null===eN&&(eN=V(5)),n[4]=eN[0],n[5]=eN[1],n[6]=eN[2],n[7]=eN[3],n[8]=eN[4],n[11]=255&r,n[10]=r>>8&255,n[9]=r>>16&255,n},e.prototype.toString=function(e){return e?this.id.toString(e):this.toHexString()},e.prototype.toJSON=function(){return this.toHexString()},e.prototype.equals=function(t){if(null==t)return!1;if(t instanceof e)return this[ek][11]===t[ek][11]&&this[ek].equals(t[ek]);if("string"==typeof t&&e.isValid(t)&&12===t.length&&G(this.id))return t===j.prototype.toString.call(this.id,"latin1");if("string"==typeof t&&e.isValid(t)&&24===t.length)return t.toLowerCase()===this.toHexString();if("string"==typeof t&&e.isValid(t)&&12===t.length)return j.from(t).equals(this.id);if("object"==typeof t&&"toHexString"in t&&"function"==typeof t.toHexString){var r=t.toHexString(),n=this.toHexString().toLowerCase();return"string"==typeof r&&r.toLowerCase()===n}return!1},e.prototype.getTimestamp=function(){var e=new Date,t=this.id.readUInt32BE(0);return e.setTime(1e3*Math.floor(t)),e},e.createPk=function(){return new e},e.createFromTime=function(t){var r=j.from([0,0,0,0,0,0,0,0,0,0,0,0]);return r.writeUInt32BE(t,0),new e(r)},e.createFromHexString=function(t){if(void 0===t||null!=t&&24!==t.length)throw new M("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");return new e(j.from(t,"hex"))},e.isValid=function(t){if(null==t)return!1;try{return new e(t),!0}catch(e){return!1}},e.prototype.toExtendedJSON=function(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}},e.fromExtendedJSON=function(t){return new e(t.$oid)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e.prototype.inspect=function(){return'new ObjectId("'.concat(this.toHexString(),'")')},e.index=Math.floor(0xffffff*Math.random()),e}();Object.defineProperty(eU.prototype,"generate",{value:Z(function(e){return eU.generate(e)},"Please use the static `ObjectId.generate(time)` instead")}),Object.defineProperty(eU.prototype,"getInc",{value:Z(function(){return eU.getInc()},"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(eU.prototype,"get_inc",{value:Z(function(){return eU.getInc()},"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(eU,"get_inc",{value:Z(function(){return eU.getInc()},"Please use the static `ObjectId.getInc()` instead")}),Object.defineProperty(eU.prototype,"_bsontype",{value:"ObjectID"});var eI=function(){function e(t,r){if(!(this instanceof e))return new e(t,r);
1if(this.pattern=t,this.options=(null!=r?r:"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new K("BSON Regex patterns cannot contain null bytes, found: ".concat(JSON.stringify(this.pattern)));if(-1!==this.options.indexOf("\0"))throw new K("BSON Regex options cannot contain null bytes, found: ".concat(JSON.stringify(this.options)));for(var n=0;n<this.options.length;n++)if("i"!==this.options[n]&&"m"!==this.options[n]&&"x"!==this.options[n]&&"l"!==this.options[n]&&"s"!==this.options[n]&&"u"!==this.options[n])throw new K("The regular expression option [".concat(this.options[n],"] is not supported"))}return e.parseOptions=function(e){return e?e.split("").sort().join(""):""},e.prototype.toExtendedJSON=function(e){return(e=e||{}).legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}},e.fromExtendedJSON=function(t){if("$regex"in t){if("string"==typeof t.$regex)return new e(t.$regex,e.parseOptions(t.$options));else if("BSONRegExp"===t.$regex._bsontype)return t}if("$regularExpression"in t)return new e(t.$regularExpression.pattern,e.parseOptions(t.$regularExpression.options));throw new M("Unexpected BSONRegExp EJSON object form: ".concat(JSON.stringify(t)))},e}();Object.defineProperty(eI.prototype,"_bsontype",{value:"BSONRegExp"});var eP=function(){function e(t){if(!(this instanceof e))return new e(t);this.value=t}return e.prototype.valueOf=function(){return this.value},e.prototype.toString=function(){return this.value},e.prototype.inspect=function(){return'new BSONSymbol("'.concat(this.value,'")')},e.prototype.toJSON=function(){return this.value},e.prototype.toExtendedJSON=function(){return{$symbol:this.value}},e.fromExtendedJSON=function(t){return new e(t.$symbol)},e.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},e}();Object.defineProperty(eP.prototype,"_bsontype",{value:"Symbol"});var eB=function(e){function t(r,n){var i=this;return i instanceof t?(Object.defineProperty(i=eh.isLong(r)?e.call(this,r.low,r.high,!0)||this:X(r)&&void 0!==r.t&&void 0!==r.i?e.call(this,r.i,r.t,!0)||this:e.call(this,r,n,!0)||this,"_bsontype",{value:"Timestamp",writable:!1,configurable:!1,enumerable:!1}),i):new t(r,n)}return D(t,e),t.prototype.toJSON=function(){return{$timestamp:this.toString()}},t.fromInt=function(e){return new t(eh.fromInt(e,!0))},t.fromNumber=function(e){return new t(eh.fromNumber(e,!0))},t.fromBits=function(e,r){return new t(e,r)},t.fromString=function(e,r){return new t(eh.fromString(e,!0,r))},t.prototype.toExtendedJSON=function(){return{$timestamp:{t:this.high>>>0,i:this.low>>>0}}},t.fromExtendedJSON=function(e){return new t(e.$timestamp)},t.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return this.inspect()},t.prototype.inspect=function(){return"new Timestamp({ t: ".concat(this.getHighBits(),", i: ").concat(this.getLowBits()," })")},t.MAX_VALUE=eh.MAX_UNSIGNED_VALUE,t}(eh);function eC(e){return X(e)&&Reflect.has(e,"_bsontype")&&"string"==typeof e._bsontype}var eR={$oid:eU,$binary:ei,$uuid:ei,$symbol:eP,$numberInt:eA,$numberDecimal:eS,$numberDouble:e_,$numberLong:eh,$minKey:eO,$maxKey:ex,$regex:eI,$regularExpression:eI,$timestamp:eB};function ej(e){var t=e.toISOString();return 0!==e.getUTCMilliseconds()?t:t.slice(0,-5)+"Z"}var eH={Binary:function(e){return new ei(e.value(),e.sub_type)},Code:function(e){return new es(e.code,e.scope)},DBRef:function(e){return new ec(e.collection||e.namespace,e.oid,e.db,e.fields)},Decimal128:function(e){return new eS(e.bytes)},Double:function(e){return new e_(e.value)},Int32:function(e){return new eA(e.value)},Long:function(e){return eh.fromBits(null!=e.low?e.low:e.low_,null!=e.low?e.high:e.high_,null!=e.low?e.unsigned:e.unsigned_)},MaxKey:function(){return new ex},MinKey:function(){return new eO},ObjectID:function(e){return new eU(e)},ObjectId:function(e){return new eU(e)},BSONRegExp:function(e){return new eI(e.pattern,e.options)},Symbol:function(e){return new eP(e.value)},Timestamp:function(e){return eB.fromBits(e.low,e.high)}},eD=f||(f={});function eW(e,t){var r=Object.assign({},{relaxed:!0,legacy:!1},t);return"boolean"==typeof r.relaxed&&(r.strict=!r.relaxed),"boolean"==typeof r.strict&&(r.relaxed=!r.strict),JSON.parse(e,function(e,t){if(-1!==e.indexOf("\0"))throw new K("BSON Document field names cannot contain null bytes, found: ".concat(JSON.stringify(e)));return function e(t,r){if(void 0===r&&(r={}),"number"==typeof t){if(r.relaxed||r.legacy)return t;if(Math.floor(t)===t){if(t>=-0x80000000&&t<=0x7fffffff)return new eA(t);if(t>=-0x8000000000000000&&t<=0x8000000000000000)return eh.fromNumber(t)}return new e_(t)}if(null==t||"object"!=typeof t)return t;if(t.$undefined)return null;for(var n=Object.keys(t).filter(function(e){return e.startsWith("$")&&null!=t[e]}),i=0;i<n.length;i++){var o=eR[n[i]];if(o)return o.fromExtendedJSON(t,r)}if(null!=t.$date){var s=t.$date,a=new Date;return r.legacy?"number"==typeof s?a.setTime(s):"string"==typeof s&&a.setTime(Date.parse(s)):"string"==typeof s?a.setTime(Date.parse(s)):eh.isLong(s)?a.setTime(s.toNumber()):"number"==typeof s&&r.relaxed&&a.setTime(s),a}if(null!=t.$code){var c=Object.assign({},t);
1return t.$scope&&(c.$scope=e(t.$scope)),es.fromExtendedJSON(t)}if(ea(t)||t.$dbPointer){var u=t.$ref?t:t.$dbPointer;if(u instanceof ec)return u;var f=Object.keys(u).filter(function(e){return e.startsWith("$")}),l=!0;if(f.forEach(function(e){-1===["$ref","$id","$db"].indexOf(e)&&(l=!1)}),l)return ec.fromExtendedJSON(u)}return t}(t,r)})}function eK(e,t,r,n){return null!=r&&"object"==typeof r&&(n=r,r=0),null==t||"object"!=typeof t||Array.isArray(t)||(n=t,t=void 0,r=0),JSON.stringify(function e(t,r){if(("object"==typeof t||"function"==typeof t)&&null!==t){var n=r.seenObjects.findIndex(function(e){return e.obj===t});if(-1!==n){var i=r.seenObjects.map(function(e){return e.propertyName}),o=i.slice(0,n).map(function(e){return"".concat(e," -> ")}).join(""),s=i[n],a=" -> "+i.slice(n+1,i.length-1).map(function(e){return"".concat(e," -> ")}).join(""),c=i[i.length-1],u=" ".repeat(o.length+s.length/2),f="-".repeat(a.length+(s.length+c.length)/2-1);throw new M("Converting circular structure to EJSON:\n"+" ".concat(o).concat(s).concat(a).concat(c,"\n")+" ".concat(u,"\\").concat(f,"/"))}r.seenObjects[r.seenObjects.length-1].obj=t}if(Array.isArray(t))return t.map(function(t,n){r.seenObjects.push({propertyName:"index ".concat(n),obj:null});try{return e(t,r)}finally{r.seenObjects.pop()}});if(void 0===t)return null;if(t instanceof Date||q(t)){var l=t.getTime(),h=l>-1&&l<2534023188e5;return r.legacy?r.relaxed&&h?{$date:t.getTime()}:{$date:ej(t)}:r.relaxed&&h?{$date:ej(t)}:{$date:{$numberLong:t.getTime().toString()}}}if("number"==typeof t&&(!r.relaxed||!isFinite(t))){if(Math.floor(t)===t){var d=t>=-0x80000000&&t<=0x7fffffff,p=t>=-0x8000000000000000&&t<=0x8000000000000000;if(d)return{$numberInt:t.toString()};if(p)return{$numberLong:t.toString()}}return{$numberDouble:t.toString()}}if(t instanceof RegExp||Y(t)){var y=t.flags;if(void 0===y){var g=t.toString().match(/[gimuy]*$/);g&&(y=g[0])}return new eI(t.source,y).toExtendedJSON(r)}return null!=t&&"object"==typeof t?function(t,r){if(null==t||"object"!=typeof t)throw new K("not an object instance");var n=t._bsontype;if(void 0===n){var i={};for(var o in t){r.seenObjects.push({propertyName:o,obj:null});try{var s=e(t[o],r);"__proto__"===o?Object.defineProperty(i,o,{value:s,writable:!0,enumerable:!0,configurable:!0}):i[o]=s}finally{r.seenObjects.pop()}}return i}if(eC(t)){var a=t;if("function"!=typeof a.toExtendedJSON){var c=eH[t._bsontype];if(!c)throw new M("Unrecognized or invalid _bsontype: "+t._bsontype);a=c(a)}return"Code"===n&&a.scope?a=new es(a.code,e(a.scope,r)):"DBRef"===n&&a.oid&&(a=new ec(e(a.collection,r),e(a.oid,r),e(a.db,r),e(a.fields,r))),a.toExtendedJSON(r)}throw new K("_bsontype must be a string, but was: "+typeof n)}(t,r):t}(e,Object.assign({relaxed:!0,legacy:!1},n,{seenObjects:[{propertyName:"(root)",obj:null}]})),t,r)}eD.parse=eW,eD.stringify=eK,eD.serialize=function(e,t){return JSON.parse(eK(e,t=t||{}))},eD.deserialize=function(e,t){return t=t||{},eW(JSON.stringify(e),t)};var eM=L();function eJ(e,t,r){var n=5;if(Array.isArray(e))for(var i=0;i<e.length;i++)n+=eL(i.toString(),e[i],t,!0,r);else for(var o in"function"==typeof(null==e?void 0:e.toBSON)&&(e=e.toBSON()),e)n+=eL(o,e[o],t,!1,r);return n}function eL(e,t,r,n,i){switch(void 0===r&&(r=!1),void 0===n&&(n=!1),void 0===i&&(i=!1),"function"==typeof(null==t?void 0:t.toBSON)&&(t=t.toBSON()),typeof t){case"string":return 1+j.byteLength(e,"utf8")+1+4+j.byteLength(t,"utf8")+1;case"number":if(Math.floor(t)!==t||!(t>=-0x20000000000000)||!(t<=0x20000000000000))return(null!=e?j.byteLength(e,"utf8")+1:0)+9;if(t>=-0x80000000&&t<=0x7fffffff)return(null!=e?j.byteLength(e,"utf8")+1:0)+5;return(null!=e?j.byteLength(e,"utf8")+1:0)+9;case"undefined":if(n||!i)return(null!=e?j.byteLength(e,"utf8")+1:0)+1;break;case"boolean":return(null!=e?j.byteLength(e,"utf8")+1:0)+2;case"object":if(null==t||"MinKey"===t._bsontype||"MaxKey"===t._bsontype)return(null!=e?j.byteLength(e,"utf8")+1:0)+1;if("ObjectId"===t._bsontype||"ObjectID"===t._bsontype)return(null!=e?j.byteLength(e,"utf8")+1:0)+13;if(t instanceof Date||q(t))return(null!=e?j.byteLength(e,"utf8")+1:0)+9;else if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer||z(t))return(null!=e?j.byteLength(e,"utf8")+1:0)+6+t.byteLength;else if("Long"===t._bsontype||"Double"===t._bsontype||"Timestamp"===t._bsontype)return(null!=e?j.byteLength(e,"utf8")+1:0)+9;else if("Decimal128"===t._bsontype)return(null!=e?j.byteLength(e,"utf8")+1:0)+17;else if("Code"===t._bsontype)if(null!=t.scope&&Object.keys(t.scope).length>0)return(null!=e?j.byteLength(e,"utf8")+1:0)+1+4+4+j.byteLength(t.code.toString(),"utf8")+1+eJ(t.scope,r,i);else return(null!=e?j.byteLength(e,"utf8")+1:0)+1+4+j.byteLength(t.code.toString(),"utf8")+1;else if("Binary"===t._bsontype){var o=t;if(o.sub_type===ei.SUBTYPE_BYTE_ARRAY)return(null!=e?j.byteLength(e,"utf8")+1:0)+(o.position+1+4+1+4);return(null!=e?j.byteLength(e,"utf8")+1:0)+(o.position+1+4+1)}else if("Symbol"===t._bsontype)return(null!=e?j.byteLength(e,"utf8")+1:0)+j.byteLength(t.value,"utf8")+4+1+1;else if("DBRef"===t._bsontype){var s=Object.assign({$ref:t.collection,$id:t.oid},t.fields);return null!=t.db&&(s.$db=t.db),(null!=e?j.byteLength(e,"utf8")+1:0)+1+eJ(s,r,i)}else if(t instanceof RegExp||Y(t))return(null!=e?j.byteLength(e,"utf8")+1:0)+1+j.byteLength(t.source,"utf8")+1+ +!!t.global+ +!!t.ignoreCase+ +!!t.multiline+1;else if("BSONRegExp"===t._bsontype)return(null!=e?j.byteLength(e,"utf8")+1:0)+1+j.byteLength(t.pattern,"utf8")+1+j.byteLength(t.options,"utf8")+1;else return(null!=e?j.byteLength(e,"utf8")+1:0)+eJ(t,r,i)+1;case"function":if(t instanceof RegExp||Y(t)||"[object RegExp]"===String.call(t))return(null!=e?j.byteLength(e,"utf8")+1:0)+1+j.byteLength(t.source,"utf8")+1+ +!!t.global+ +!!t.ignoreCase+ +!!t.multiline+1;if(r&&null!=t.scope&&Object.keys(t.scope).length>0)return(null!=e?j.byteLength(e,"utf8")+1:0)+1+4+4+j.byteLength($(t),"utf8")+1+eJ(t.scope,r,i);if(r)return(null!=e?j.byteLength(e,"utf8")+1:0)+1+4+j.byteLength($(t),"utf8")+1}return 0}function e$(e,t,r){for(var n=0,i=t;i<r;i+=1){var o=e[i];if(n){if((192&o)!=128)return!1;n-=1}else if(128&o)if((224&o)==192)n=1;else if((240&o)==224)n=2;else{if((248&o)!=240)return!1;n=3}}return!n}l=eM.Map?eM.Map:function(){function e(e){void 0===e&&(e=[]),this._keys=[],this._values={};for(var t=0;t<e.length;t++)if(null!=e[t]){var r=e[t],n=r[0],i=r[1];this._keys.push(n),this._values[n]={v:i,i:this._keys.length-1}}}return e.prototype.clear=function(){this._keys=[],this._values={}},e.prototype.delete=function(e){var t=this._values[e];return null!=t&&(delete this._values[e],this._keys.splice(t.i,1),!0)},e.prototype.entries=function(){var e=this,t=0;return{next:function(){var r=e._keys[t++];return{value:void 0!==r?[r,e._values[r].v]:void 0,done:void 0===r}}}},e.prototype.forEach=function(e,t){t=t||this;for(var r=0;r<this._keys.length;r++){var n=this._keys[r];e.call(t,this._values[n].v,n,t)}},e.prototype.get=function(e){return this._values[e]?this._values[e].v:void 0},e.prototype.has=function(e){return null!=this._values[e]},e.prototype.keys=function(){var e=this,t=0;return{next:function(){var r=e._keys[t++];return{value:void 0!==r?r:void 0,done:void 0===r}}}},e.prototype.set=function(e,t){return this._values[e]?this._values[e].v=t:(this._keys.push(e),this._values[e]={v:t,i:this._keys.length-1}),this},e.prototype.values=function(){var e=this,t=0;return{next:function(){var r=e._keys[t++];return{value:void 0!==r?e._values[r].v:void 0,done:void 0===r}}}},Object.defineProperty(e.prototype,"size",{get:function(){return this._keys.length}
1,enumerable:!1,configurable:!0}),e}();var eF=eh.fromNumber(0x20000000000000),eV=eh.fromNumber(-0x20000000000000),ez={};function eG(e,t,r){var n=(t=null==t?{}:t)&&t.index?t.index:0,i=e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24;if(i<5)throw new K("bson size must be >= 5, is ".concat(i));if(t.allowObjectSmallerThanBufferSize&&e.length<i)throw new K("buffer length ".concat(e.length," must be >= bson size ").concat(i));if(!t.allowObjectSmallerThanBufferSize&&e.length!==i)throw new K("buffer length ".concat(e.length," must === bson size ").concat(i));if(i+n>e.byteLength)throw new K("(bson size ".concat(i," + options.index ").concat(n," must be <= buffer length ").concat(e.byteLength,")"));if(0!==e[n+i-1])throw new K("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return function e(t,r,n,i){void 0===i&&(i=!1);var o,s=null!=n.evalFunctions&&n.evalFunctions,a=null!=n.cacheFunctions&&n.cacheFunctions,c=null==n.fieldsAsRaw?null:n.fieldsAsRaw,u=null!=n.raw&&n.raw,f="boolean"==typeof n.bsonRegExp&&n.bsonRegExp,l=null!=n.promoteBuffers&&n.promoteBuffers,h=null==n.promoteLongs||n.promoteLongs,d=null==n.promoteValues||n.promoteValues,p=null==n.validation?{utf8:!0}:n.validation,y=!0,g=new Set,w=p.utf8;if("boolean"==typeof w)o=w;else{y=!1;var m=Object.keys(w).map(function(e){return w[e]});if(0===m.length)throw new K("UTF-8 validation setting cannot be empty");if("boolean"!=typeof m[0])throw new K("Invalid UTF-8 validation option, must specify boolean values");if(o=m[0],!m.every(function(e){return e===o}))throw new K("Invalid UTF-8 validation option - keys must be all true or all false")}if(!y)for(var b=0,v=Object.keys(w);b<v.length;b++){var E=v[b];g.add(E)}var S=r;if(t.length<5)throw new K("corrupt bson message < 5 bytes long");var _=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;if(_<5||_>t.length)throw new K("corrupt bson message");for(var A=i?[]:{},x=0,O=!i&&null,T=new DataView(t.buffer,t.byteOffset,t.byteLength);;){var N=t[r++];if(0===N)break;for(var k=r;0!==t[k]&&k<t.length;)k++;if(k>=t.byteLength)throw new K("Bad BSON Document: illegal CString");var U=i?x++:t.toString("utf8",r,k),I=!0;I=y||g.has(U)?o:!o,!1!==O&&"$"===U[0]&&(O=eY.test(U));var P=void 0;if(r=k+1,2===N){var B=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;if(B<=0||B>t.length-r||0!==t[r+B-1])throw new K("bad string length in bson");P=eX(t,r,r+B-1,I),r+=B}else if(7===N){var C=j.alloc(12);t.copy(C,0,r,r+12),P=new eU(C),r+=12}else if(16===N&&!1===d)P=new eA(t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24);else if(16===N)P=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;else if(1===N&&!1===d)P=new e_(T.getFloat64(r,!0)),r+=8;else if(1===N)P=T.getFloat64(r,!0),r+=8;else if(9===N){var R=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24,H=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;P=new Date(new eh(R,H).toNumber())}else if(8===N){if(0!==t[r]&&1!==t[r])throw new K("illegal boolean type value");P=1===t[r++]}else if(3===N){var D=r,M=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24;if(M<=0||M>t.length-r)throw new K("bad embedded document length in bson");if(u)P=t.slice(r,r+M);else{var J=n;y||(J=W(W({},n),{validation:{utf8:I}})),P=e(t,D,J,!1)}r+=M}else if(4===N){var D=r,M=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,L=n,$=r+M;if(c&&c[U]){for(var F in L={},n)L[F]=n[F];L.raw=!0}if(y||(L=W(W({},L),{validation:{utf8:I}})),P=e(t,D,L,!0),0!==t[(r+=M)-1])throw new K("invalid array terminator byte");if(r!==$)throw new K("corrupted array bson")}else if(6===N)P=void 0;else if(10===N)P=null;else if(18===N){var R=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24,H=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24,V=new eh(R,H);P=h&&!0===d&&V.lessThanOrEqual(eF)&&V.greaterThanOrEqual(eV)?V.toNumber():V}else if(19===N){var z=j.alloc(16);t.copy(z,0,r,r+16),r+=16;var G=new eS(z);P="toObject"in G&&"function"==typeof G.toObject?G.toObject():G}else if(5===N){var Y=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24,q=Y,X=t[r++];if(Y<0)throw new K("Negative binary type element size found");if(Y>t.byteLength)throw new K("Binary type size larger than document size");if(null!=t.slice){if(X===ei.SUBTYPE_BYTE_ARRAY){if((Y=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24)<0)throw new K("Negative binary type element size found for subtype 0x02");if(Y>q-4)throw new K("Binary type with subtype 0x02 contains too long binary size");if(Y<q-4)throw new K("Binary type with subtype 0x02 contains too short binary size")}l&&d?P=t.slice(r,r+Y):(P=new ei(t.slice(r,r+Y),X),4===X&&(P=P.toUUID()))}else{var Z=j.alloc(Y);if(X===ei.SUBTYPE_BYTE_ARRAY){if((Y=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24)<0)throw new K("Negative binary type element size found for subtype 0x02");if(Y>q-4)throw new K("Binary type with subtype 0x02 contains too long binary size");if(Y<q-4)throw new K("Binary type with subtype 0x02 contains too short binary size")}for(k=0;k<Y;k++)Z[k]=t[r+k];P=l&&d?Z:4===X?new ei(t.slice(r,r+Y),X).toUUID():new ei(t.slice(r,r+Y),X)}r+=Y}else if(11===N&&!1===f){for(k=r;0!==t[k]&&k<t.length;)k++;if(k>=t.length)throw new K("Bad BSON Document: illegal CString");var Q=t.toString("utf8",r,k);for(k=r=k+1;0!==t[k]&&k<t.length;)k++;if(k>=t.length)throw new K("Bad BSON Document: illegal CString");var ee=t.toString("utf8",r,k);r=k+1;var et=Array(ee.length);for(k=0;k<ee.length;k++)switch(ee[k]){case"m":et[k]="m";break;case"s":et[k]="g";break;case"i":et[k]="i"}P=new RegExp(Q,et.join(""))}else if(11===N&&!0===f){for(k=r;0!==t[k]&&k<t.length;)k++;if(k>=t.length)throw new K("Bad BSON Document: illegal CString");var Q=t.toString("utf8",r,k);for(k=r=k+1;0!==t[k]&&k<t.length;)k++;if(k>=t.length)throw new K("Bad BSON Document: illegal CString");var ee=t.toString("utf8",r,k);r=k+1,P=new eI(Q,ee)}else if(14===N){var B=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;if(B<=0||B>t.length-r||0!==t[r+B-1])throw new K("bad string length in bson");var er=eX(t,r,r+B-1,I);P=d?er:new eP(er),r+=B}else if(17===N){var R=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24,H=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;P=new eB(R,H)}else if(255===N)P=new eO;else if(127===N)P=new ex;else if(13===N){var B=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;if(B<=0||B>t.length-r||0!==t[r+B-1])throw new K("bad string length in bson");var en=eX(t,r,r+B-1,I);P=s?a?eq(en,ez,A):eq(en):new es(en),r+=B}else if(15===N){var eo=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;if(eo<13)throw new K("code_w_scope total size shorter minimum expected length");var B=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;if(B<=0||B>t.length-r||0!==t[r+B-1])throw new K("bad string length in bson");var en=eX(t,r,r+B-1,I),D=r+=B,M=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,eu=e(t,D,n,!1);if(r+=M,eo<8+M+B)throw new K("code_w_scope total size is too short, truncating scope");if(eo>8+M+B)throw new K("code_w_scope total size is too long, clips outer document");s?(P=a?eq(en,ez,A):eq(en)).scope=eu:P=new es(en,eu)}else if(12===N){var B=t[r++]|t[r++]<<8|t[r++]<<16|t[r++]<<24;if(B<=0||B>t.length-r||0!==t[r+B-1])throw new K("bad string length in bson");if(null!=p&&p.utf8&&!e$(t,r,r+B-1))throw new K("Invalid UTF-8 string in BSON document");var ef=t.toString("utf8",r,r+B-1);r+=B;var el=j.alloc(12);t.copy(el,0,r,r+12);var C=new eU(el);r+=12,P=new ec(ef,C)}else throw new K("Detected unknown BSON type ".concat(N.toString(16),' for fieldname "').concat(U,'"'));"__proto__"===U?Object.defineProperty(A,U,{value:P,writable:!0,enumerable:!0,configurable:!0}):A[U]=P}if(_!==r-S){if(i)throw new K("corrupt array bson");throw new K("corrupt object bson")}if(!O)return A;if(ea(A)){var ed=Object.assign({},A);
1return delete ed.$ref,delete ed.$id,delete ed.$db,new ec(A.$ref,A.$id,A.$db,ed)}return A}(e,n,t,r)}var eY=/^\$ref$|^\$id$|^\$db$/;function eq(e,t,r){return t?(null==t[e]&&(t[e]=Function(e)),t[e].bind(r)):Function(e)}function eX(e,t,r,n){var i=e.toString("utf8",t,r);if(n){for(var o=0;o<i.length;o++)if(65533===i.charCodeAt(o)){if(!e$(e,t,r))throw new K("Invalid UTF-8 string in BSON document");break}}return i}var eZ=/\x00/,eQ=new Set(["$db","$ref","$id","$clusterTime"]);function e0(e,t,r,n,i){e[n++]=2;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");e[(n=n+o+1)-1]=0;var s=e.write(r,n+4,void 0,"utf8");return e[n+3]=s+1>>24&255,e[n+2]=s+1>>16&255,e[n+1]=s+1>>8&255,e[n]=s+1&255,n=n+4+s,e[n++]=0,n}var e1=new Uint8Array(8),e2=new DataView(e1.buffer,e1.byteOffset,e1.byteLength);function e5(e,t,r,n,i){if(Number.isInteger(r)&&r>=-0x80000000&&r<=0x7fffffff){e[n++]=16;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=o,e[n++]=0,e[n++]=255&r,e[n++]=r>>8&255,e[n++]=r>>16&255,e[n++]=r>>24&255}else{e[n++]=1;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=o,e[n++]=0,e2.setFloat64(0,r,!0),e.set(e1,n),n+=8}return n}function e6(e,t,r,n,i){e[n++]=10;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");return n+=o,e[n++]=0,n}function e8(e,t,r,n,i){e[n++]=8;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");return n+=o,e[n++]=0,e[n++]=+!!r,n}function e3(e,t,r,n,i){e[n++]=9;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=o,e[n++]=0;var s=eh.fromNumber(r.getTime()),a=s.getLowBits(),c=s.getHighBits();return e[n++]=255&a,e[n++]=a>>8&255,e[n++]=a>>16&255,e[n++]=a>>24&255,e[n++]=255&c,e[n++]=c>>8&255,e[n++]=c>>16&255,e[n++]=c>>24&255,n}function e4(e,t,r,n,i){e[n++]=11;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");if(n+=o,e[n++]=0,r.source&&null!=r.source.match(eZ))throw Error("value "+r.source+" must not contain null bytes");return n+=e.write(r.source,n,void 0,"utf8"),e[n++]=0,r.ignoreCase&&(e[n++]=105),r.global&&(e[n++]=115),r.multiline&&(e[n++]=109),e[n++]=0,n}function e9(e,t,r,n,i){e[n++]=11;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");if(n+=o,e[n++]=0,null!=r.pattern.match(eZ))throw Error("pattern "+r.pattern+" must not contain null bytes");return n+=e.write(r.pattern,n,void 0,"utf8"),e[n++]=0,n+=e.write(r.options.split("").sort().join(""),n,void 0,"utf8"),e[n++]=0,n}function e7(e,t,r,n,i){null===r?e[n++]=10:"MinKey"===r._bsontype?e[n++]=255:e[n++]=127;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");return n+=o,e[n++]=0,n}function te(e,t,r,n,i){e[n++]=7;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");if(n+=o,e[n++]=0,"string"==typeof r.id)e.write(r.id,n,void 0,"binary");else if(G(r.id))e.set(r.id.subarray(0,12),n);else throw new M("object ["+JSON.stringify(r)+"] is not a valid ObjectId");return n+12}function tt(e,t,r,n,i){e[n++]=5;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=o,e[n++]=0;var s=r.length;return e[n++]=255&s,e[n++]=s>>8&255,e[n++]=s>>16&255,e[n++]=s>>24&255,e[n++]=0,e.set(Q(r),n),n+=s}function tr(e,t,r,n,i,o,s,a,c,u){void 0===i&&(i=!1),void 0===o&&(o=0),void 0===s&&(s=!1),void 0===a&&(a=!0),void 0===c&&(c=!1),void 0===u&&(u=[]);for(var f=0;f<u.length;f++)if(u[f]===r)throw new K("cyclic dependency detected");u.push(r),e[n++]=Array.isArray(r)?4:3;var l=c?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=l,e[n++]=0;var h=th(e,r,i,n,o+1,s,a,u);return u.pop(),h}function tn(e,t,r,n,i){e[n++]=19;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");return n+=o,e[n++]=0,e.set(r.bytes.subarray(0,16),n),n+16}function ti(e,t,r,n,i){e[n++]="Long"===r._bsontype?18:17;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=o,e[n++]=0;var s=r.getLowBits(),a=r.getHighBits();return e[n++]=255&s,e[n++]=s>>8&255,e[n++]=s>>16&255,e[n++]=s>>24&255,e[n++]=255&a,e[n++]=a>>8&255,e[n++]=a>>16&255,e[n++]=a>>24&255,n}function to(e,t,r,n,i){r=r.valueOf(),e[n++]=16;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");return n+=o,e[n++]=0,e[n++]=255&r,e[n++]=r>>8&255,e[n++]=r>>16&255,e[n++]=r>>24&255,n}function ts(e,t,r,n,i){e[n++]=1;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");return n+=o,e[n++]=0,e2.setFloat64(0,r.value,!0),e.set(e1,n),n+=8}function ta(e,t,r,n,i,o,s){e[n++]=13;var a=s?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=a,e[n++]=0;var c=$(r),u=e.write(c,n+4,void 0,"utf8")+1;return e[n]=255&u,e[n+1]=u>>8&255,e[n+2]=u>>16&255,e[n+3]=u>>24&255,n=n+4+u-1,e[n++]=0,n}function tc(e,t,r,n,i,o,s,a,c){if(void 0===i&&(i=!1),void 0===o&&(o=0),void 0===s&&(s=!1),void 0===a&&(a=!0),void 0===c&&(c=!1),r.scope&&"object"==typeof r.scope){e[n++]=15;var u=c?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=u,e[n++]=0;var f=n,l="string"==typeof r.code?r.code:r.code.toString();n+=4;var h=e.write(l,n+4,void 0,"utf8")+1;e[n]=255&h,e[n+1]=h>>8&255,e[n+2]=h>>16&255,e[n+3]=h>>24&255,e[n+4+h-1]=0,n=n+h+4;var d=th(e,r.scope,i,n,o+1,s,a);n=d-1;var p=d-f;e[f++]=255&p,e[f++]=p>>8&255,e[f++]=p>>16&255,e[f++]=p>>24&255,e[n++]=0}else{e[n++]=13;var u=c?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=u,e[n++]=0;var l=r.code.toString(),y=e.write(l,n+4,void 0,"utf8")+1;e[n]=255&y,e[n+1]=y>>8&255,e[n+2]=y>>16&255,e[n+3]=y>>24&255,n=n+4+y-1,e[n++]=0}return n}function tu(e,t,r,n,i){e[n++]=5;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=o,e[n++]=0;var s=r.value(!0),a=r.position;return r.sub_type===ei.SUBTYPE_BYTE_ARRAY&&(a+=4),e[n++]=255&a,e[n++]=a>>8&255,e[n++]=a>>16&255,e[n++]=a>>24&255,e[n++]=r.sub_type,r.sub_type===ei.SUBTYPE_BYTE_ARRAY&&(a-=4,e[n++]=255&a,e[n++]=a>>8&255,e[n++]=a>>16&255,e[n++]=a>>24&255),e.set(s,n),n+=r.position}function tf(e,t,r,n,i){e[n++]=14;var o=i?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=o,e[n++]=0;var s=e.write(r.value,n+4,void 0,"utf8")+1;return e[n]=255&s,e[n+1]=s>>8&255,e[n+2]=s>>16&255,e[n+3]=s>>24&255,n=n+4+s-1,e[n++]=0,n}function tl(e,t,r,n,i,o,s){e[n++]=3;var a=s?e.write(t,n,void 0,"ascii"):e.write(t,n,void 0,"utf8");n+=a,e[n++]=0;var c=n,u={$ref:r.collection||r.namespace,$id:r.oid};null!=r.db&&(u.$db=r.db);var f=th(e,u=Object.assign(u,r.fields),!1,n,i+1,o),l=f-c;return e[c++]=255&l,e[c++]=l>>8&255,e[c++]=l>>16&255,e[c++]=l>>24&255,f}function th(e,t,r,n,i,o,s,a){void 0===r&&(r=!1),void 0===n&&(n=0),void 0===i&&(i=0),void 0===o&&(o=!1),void 0===s&&(s=!0),void 0===a&&(a=[]),n=n||0,(a=a||[]).push(t);var c=n+4;if(Array.isArray(t))for(var u=0;u<t.length;u++){var f="".concat(u),h=t[u];
1if("function"==typeof(null==h?void 0:h.toBSON)&&(h=h.toBSON()),"string"==typeof h)c=e0(e,f,h,c,!0);else if("number"==typeof h)c=e5(e,f,h,c,!0);else if("bigint"==typeof h)throw new M("Unsupported type BigInt, please use Decimal128");else if("boolean"==typeof h)c=e8(e,f,h,c,!0);else if(h instanceof Date||q(h))c=e3(e,f,h,c,!0);else if(void 0===h)c=e6(e,f,h,c,!0);else if(null===h)c=e6(e,f,h,c,!0);else if("ObjectId"===h._bsontype||"ObjectID"===h._bsontype)c=te(e,f,h,c,!0);else if(G(h))c=tt(e,f,h,c,!0);else if(h instanceof RegExp||Y(h))c=e4(e,f,h,c,!0);else if("object"==typeof h&&null==h._bsontype)c=tr(e,f,h,c,r,i,o,s,!0,a);else if("object"==typeof h&&eC(h)&&"Decimal128"===h._bsontype)c=tn(e,f,h,c,!0);else if("Long"===h._bsontype||"Timestamp"===h._bsontype)c=ti(e,f,h,c,!0);else if("Double"===h._bsontype)c=ts(e,f,h,c,!0);else if("function"==typeof h&&o)c=ta(e,f,h,c,r,i,!0);else if("Code"===h._bsontype)c=tc(e,f,h,c,r,i,o,s,!0);else if("Binary"===h._bsontype)c=tu(e,f,h,c,!0);else if("Symbol"===h._bsontype)c=tf(e,f,h,c,!0);else if("DBRef"===h._bsontype)c=tl(e,f,h,c,i,o,!0);else if("BSONRegExp"===h._bsontype)c=e9(e,f,h,c,!0);else if("Int32"===h._bsontype)c=to(e,f,h,c,!0);else if("MinKey"===h._bsontype||"MaxKey"===h._bsontype)c=e7(e,f,h,c,!0);else if(void 0!==h._bsontype)throw new M("Unrecognized or invalid _bsontype: ".concat(String(h._bsontype)))}else if(t instanceof l||(y=t,"[object Map]"===Object.prototype.toString.call(y)))for(var d=t.entries(),p=!1;!p;){var y,g,w,m=d.next();if(!(p=!!m.done)){var f=m.value[0],h=m.value[1],b=typeof h;if("string"==typeof f&&!eQ.has(f)){if(null!=f.match(eZ))throw Error("key "+f+" must not contain null bytes");if(r){if("$"===f[0])throw Error("key "+f+" must not start with '$'");else if(~f.indexOf("."))throw Error("key "+f+" must not contain '.'")}}if("string"===b)c=e0(e,f,h,c);else if("number"===b)c=e5(e,f,h,c);else{if("bigint"===b||(g=h,"[object BigInt64Array]"===Object.prototype.toString.call(g))||(w=h,"[object BigUint64Array]"===Object.prototype.toString.call(w)))throw new M("Unsupported type BigInt, please use Decimal128");if("boolean"===b)c=e8(e,f,h,c);else if(h instanceof Date||q(h))c=e3(e,f,h,c);else if(null===h||void 0===h&&!1===s)c=e6(e,f,h,c);else if("ObjectId"===h._bsontype||"ObjectID"===h._bsontype)c=te(e,f,h,c);else if(G(h))c=tt(e,f,h,c);else if(h instanceof RegExp||Y(h))c=e4(e,f,h,c);else if("object"===b&&null==h._bsontype)c=tr(e,f,h,c,r,i,o,s,!1,a);else if("object"===b&&"Decimal128"===h._bsontype)c=tn(e,f,h,c);else if("Long"===h._bsontype||"Timestamp"===h._bsontype)c=ti(e,f,h,c);else if("Double"===h._bsontype)c=ts(e,f,h,c);else if("Code"===h._bsontype)c=tc(e,f,h,c,r,i,o,s);else if("function"==typeof h&&o)c=ta(e,f,h,c,r,i,o);else if("Binary"===h._bsontype)c=tu(e,f,h,c);
1else if("Symbol"===h._bsontype)c=tf(e,f,h,c);else if("DBRef"===h._bsontype)c=tl(e,f,h,c,i,o);else if("BSONRegExp"===h._bsontype)c=e9(e,f,h,c);else if("Int32"===h._bsontype)c=to(e,f,h,c);else if("MinKey"===h._bsontype||"MaxKey"===h._bsontype)c=e7(e,f,h,c);else if(void 0!==h._bsontype)throw new M("Unrecognized or invalid _bsontype: ".concat(String(h._bsontype)))}}}else{if("function"==typeof(null==t?void 0:t.toBSON)&&null!=(t=t.toBSON())&&"object"!=typeof t)throw new M("toBSON function did not return an object");for(var f in t){var h=t[f];"function"==typeof(null==h?void 0:h.toBSON)&&(h=h.toBSON());var b=typeof h;if("string"==typeof f&&!eQ.has(f)){if(null!=f.match(eZ))throw Error("key "+f+" must not contain null bytes");if(r){if("$"===f[0])throw Error("key "+f+" must not start with '$'");else if(~f.indexOf("."))throw Error("key "+f+" must not contain '.'")}}if("string"===b)c=e0(e,f,h,c);else if("number"===b)c=e5(e,f,h,c);else if("bigint"===b)throw new M("Unsupported type BigInt, please use Decimal128");else if("boolean"===b)c=e8(e,f,h,c);else if(h instanceof Date||q(h))c=e3(e,f,h,c);else if(void 0===h)!1===s&&(c=e6(e,f,h,c));else if(null===h)c=e6(e,f,h,c);else if("ObjectId"===h._bsontype||"ObjectID"===h._bsontype)c=te(e,f,h,c);else if(G(h))c=tt(e,f,h,c);else if(h instanceof RegExp||Y(h))c=e4(e,f,h,c);else if("object"===b&&null==h._bsontype)c=tr(e,f,h,c,r,i,o,s,!1,a);else if("object"===b&&"Decimal128"===h._bsontype)c=tn(e,f,h,c);else if("Long"===h._bsontype||"Timestamp"===h._bsontype)c=ti(e,f,h,c);else if("Double"===h._bsontype)c=ts(e,f,h,c);else if("Code"===h._bsontype)c=tc(e,f,h,c,r,i,o,s);else if("function"==typeof h&&o)c=ta(e,f,h,c,r,i,o);else if("Binary"===h._bsontype)c=tu(e,f,h,c);
1else if("Symbol"===h._bsontype)c=tf(e,f,h,c);else if("DBRef"===h._bsontype)c=tl(e,f,h,c,i,o);else if("BSONRegExp"===h._bsontype)c=e9(e,f,h,c);else if("Int32"===h._bsontype)c=to(e,f,h,c);else if("MinKey"===h._bsontype||"MaxKey"===h._bsontype)c=e7(e,f,h,c);else if(void 0!==h._bsontype)throw new M("Unrecognized or invalid _bsontype: ".concat(String(h._bsontype)))}}a.pop(),e[c++]=0;var v=c-n;return e[n++]=255&v,e[n++]=v>>8&255,e[n++]=v>>16&255,e[n++]=v>>24&255,c}var td=j.alloc(0x1100000);function tp(e){td.length<e&&(td=j.alloc(e))}function ty(e,t){void 0===t&&(t={});var r="boolean"==typeof t.checkKeys&&t.checkKeys,n="boolean"==typeof t.serializeFunctions&&t.serializeFunctions,i="boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined,o="number"==typeof t.minInternalBufferSize?t.minInternalBufferSize:0x1100000;td.length<o&&(td=j.alloc(o));var s=th(td,e,r,0,0,n,i,[]),a=j.alloc(s);return td.copy(a,0,0,a.length),a}function tg(e,t,r){void 0===r&&(r={});var n="boolean"==typeof r.checkKeys&&r.checkKeys,i="boolean"==typeof r.serializeFunctions&&r.serializeFunctions,o="boolean"!=typeof r.ignoreUndefined||r.ignoreUndefined,s="number"==typeof r.index?r.index:0,a=th(td,e,n,0,0,i,o);return td.copy(t,s,0,a),s+a-1}function tw(e,t){return void 0===t&&(t={}),eG(e instanceof j?e:Q(e),t)}function tm(e,t){return void 0===t&&(t={}),eJ(e,"boolean"==typeof(t=t||{}).serializeFunctions&&t.serializeFunctions,"boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined)}function tb(e,t,r,n,i,o){for(var s=Object.assign({allowObjectSmallerThanBufferSize:!0,index:0},o),a=Q(e),c=t,u=0;u<r;u++){var f=a[c]|a[c+1]<<8|a[c+2]<<16|a[c+3]<<24;s.index=c,n[i+u]=eG(a,s),c+=f}return c}var tv={Binary:ei,Code:es,DBRef:ec,Decimal128:eS,Double:e_,Int32:eA,Long:eh,UUID:eo,Map:l,MaxKey:ex,MinKey:eO,ObjectId:eU,ObjectID:eU,BSONRegExp:eI,BSONSymbol:eP,Timestamp:eB,EJSON:f,setInternalBufferSize:tp,serialize:ty,serializeWithBufferAndIndex:tg,deserialize:tw,calculateObjectSize:tm,deserializeStream:tb,BSONError:K,BSONTypeError:M};e.s(["BSONError",0,K,"BSONRegExp",0,eI,"BSONSymbol",0,eP,"BSONTypeError",0,M,"BSON_BINARY_SUBTYPE_BYTE_ARRAY",0,2,"BSON_BINARY_SUBTYPE_COLUMN",0,7,"BSON_BINARY_SUBTYPE_DEFAULT",0,0,"BSON_BINARY_SUBTYPE_ENCRYPTED",0,6,"BSON_BINARY_SUBTYPE_FUNCTION",0,1,"BSON_BINARY_SUBTYPE_MD5",0,5,"BSON_BINARY_SUBTYPE_USER_DEFINED",0,128,"BSON_BINARY_SUBTYPE_UUID",0,3,"BSON_BINARY_SUBTYPE_UUID_NEW",0,4,"BSON_DATA_ARRAY",0,4,"BSON_DATA_BINARY",0,5,"BSON_DATA_BOOLEAN",0,8,"BSON_DATA_CODE",0,13,"BSON_DATA_CODE_W_SCOPE",0,15,"BSON_DATA_DATE",0,9,"BSON_DATA_DBPOINTER",0,12,"BSON_DATA_DECIMAL128",0,19,"BSON_DATA_INT",0,16,"BSON_DATA_LONG",0,18,"BSON_DATA_MAX_KEY",0,127,"BSON_DATA_MIN_KEY",0,255,"BSON_DATA_NULL",0,10,"BSON_DATA_NUMBER",0,1,"BSON_DATA_OBJECT",0,3,"BSON_DATA_OID",0,7,"BSON_DATA_REGEXP",0,11,"BSON_DATA_STRING",0,2,"BSON_DATA_SYMBOL",0,14,"BSON_DATA_TIMESTAMP",0,17,"BSON_DATA_UNDEFINED",0,6,"BSON_INT32_MAX",0,0x7fffffff,"BSON_INT32_MIN",0,-0x80000000,"BSON_INT64_MAX",0,0x8000000000000000-1,"BSON_INT64_MIN",0,-0x8000000000000000,"Binary",0,ei,"Code",0,es,"DBRef",0,ec,"Decimal128",0,eS,"Double",0,e_,"EJSON",0,f,"Int32",0,eA,"Long",0,eh,"LongWithoutOverridesClass",0,eh,"Map",0,l,"MaxKey",0,ex,"MinKey",0,eO,"ObjectID",0,eU,"ObjectId",0,eU,"Timestamp",0,eB,"UUID",0,eo,"calculateObjectSize",0,tm,"default",0,tv,"deserialize",0,tw,"deserializeStream",0,tb,"serialize",0,ty,"serializeWithBufferAndIndex",0,tg,"setInternalBufferSize",0,tp],639779),e.i(639779);var tE=function(e,t,r){if(r||2==arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))},tS=function(e,t,r){this.name=e,this.version=t,this.os=r,this.type="browser"},t_=function(e){this.version=e,this.type="node",this.name="node",this.os=m.default.platform},tA=function(e,t,r,n){this.name=e,this.version=t,this.os=r,this.bot=n,this.type="bot-device"},tx=function(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null},tO=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,tT=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;
1\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/]],tN=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];let tk=globalThis.fetch.bind(globalThis),tU="function"==typeof atob,tI="function"==typeof btoa,tP="function"==typeof _.Buffer,tB="function"==typeof TextDecoder?new TextDecoder:void 0,tC="function"==typeof TextEncoder?new TextEncoder:void 0,tR=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),tj=(t={},tR.forEach((e,r)=>t[e]=r),t),tH=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,tD=String.fromCharCode.bind(String),tW="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):e=>new Uint8Array(Array.prototype.slice.call(e,0)),tK=e=>e.replace(/=/g,"").replace(/[+\/]/g,e=>"+"==e?"-":"_"),tM=tI?e=>btoa(e):tP?e=>_.Buffer.from(e,"binary").toString("base64"):e=>{let t,r,n,i,o="",s=e.length%3;for(let s=0;s<e.length;){if((r=e.charCodeAt(s++))>255||(n=e.charCodeAt(s++))>255||(i=e.charCodeAt(s++))>255)throw TypeError("invalid character found");o+=tR[(t=r<<16|n<<8|i)>>18&63]+tR[t>>12&63]+tR[t>>6&63]+tR[63&t]}return s?o.slice(0,s-3)+"===".substring(s):o},tJ=tP?e=>_.Buffer.from(e).toString("base64"):e=>{let t=[];for(let r=0,n=e.length;r<n;r+=4096)t.push(tD.apply(null,e.subarray(r,r+4096)));return tM(t.join(""))},tL=e=>{if(e.length<2){var t=e.charCodeAt(0);return t<128?e:t<2048?tD(192|t>>>6)+tD(128|63&t):tD(224|t>>>12&15)+tD(128|t>>>6&63)+tD(128|63&t)}var t=65536+(e.charCodeAt(0)-55296)*1024+(e.charCodeAt(1)-56320);return tD(240|t>>>18&7)+tD(128|t>>>12&63)+tD(128|t>>>6&63)+tD(128|63&t)},t$=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,tF=tP?e=>_.Buffer.from(e,"utf8").toString("base64"):tC?e=>tJ(tC.encode(e)):e=>tM(e.replace(t$,tL)),tV=(e,t=!1)=>t?tK(tF(e)):tF(e),tz=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,tG=e=>{switch(e.length){case 4:var t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return tD((t>>>10)+55296)+tD((1023&t)+56320);case 3:return tD((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return tD((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},tY=tU?e=>atob(e.replace(/[^A-Za-z0-9\+\/]/g,"")):tP?e=>_.Buffer.from(e,"base64").toString("binary"):e=>{if(e=e.replace(/\s+/g,""),!tH.test(e))throw TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let t,r="",n,i;for(let o=0;o<e.length;)t=tj[e.charAt(o++)]<<18|tj[e.charAt(o++)]<<12|(n=tj[e.charAt(o++)])<<6|(i=tj[e.charAt(o++)]),r+=64===n?tD(t>>16&255):64===i?tD(t>>16&255,t>>8&255):tD(t>>16&255,t>>8&255,255&t);return r},tq=tP?e=>tW(_.Buffer.from(e,"base64")):e=>tW(tY(e).split("").map(e=>e.charCodeAt(0))),tX=tP?e=>_.Buffer.from(e,"base64").toString("utf8"):tB?e=>tB.decode(tq(e)):e=>tY(e).replace(tz,tG),tZ=e=>e.replace(/[-_]/g,e=>"-"==e?"+":"/").replace(/[^A-Za-z0-9\+\/]/g,""),tQ=e=>tX(tZ(e)),t0={relaxed:!1};function t1(e){return f.serialize(e,t0)}function t2(e){return Array.isArray(e)?e.map(e=>f.deserialize(e)):f.deserialize(e)}(n=h||(h={})).Normal="normal",n.Server="server",(i=d||(d={})).NAME="name",i.EMAIL="email",i.PICTURE="picture",i.FIRST_NAME="first_name",i.LAST_NAME="last_name",i.GENDER="gender",i.BIRTHDAY="birthday",i.MIN_AGE="min_age",i.MAX_AGE="max_age";let t5={[d.NAME]:"name",[d.EMAIL]:"email",[d.PICTURE]:"pictureUrl",[d.FIRST_NAME]:"firstName",[d.LAST_NAME]:"lastName",[d.GENDER]:"gender",[d.BIRTHDAY]:"birthday",[d.MIN_AGE]:"minAge",[d.MAX_AGE]:"maxAge"};
1class t6{constructor(e){if(this.type=h.Normal,this.identities=[],"object"==typeof e&&null!==e){const{type:t,identities:r,data:n}=e;if("string"==typeof t)this.type=t;else throw Error("Expected 'type' in the response body");if(Array.isArray(r))this.identities=r.map(e=>{let{id:t,provider_type:r}=e;return{id:t,providerType:r}});else throw Error("Expected 'identities' in the response body");if("object"==typeof n&&null!==n){const e=Object.fromEntries(Object.entries(n).map(([e,t])=>e in t5?[t5[e],t]:[e,t]));this.data=t2(e)}else throw Error("Expected 'data' in the response body")}else this.data={}}}class t8{constructor(e,t){this.storage=e,this.keyPart=t}get(e){return this.storage.get(this.keyPart+t8.PART_SEPARATOR+e)}set(e,t){return this.storage.set(this.keyPart+t8.PART_SEPARATOR+e,t)}remove(e){return this.storage.remove(this.keyPart+t8.PART_SEPARATOR+e)}prefix(e){return new t8(this,e)}clear(e=""){return this.storage.clear(this.keyPart+t8.PART_SEPARATOR+e)}addListener(e){return this.storage.addListener(e)}removeListener(e){return this.storage.addListener(e)}}t8.PART_SEPARATOR=":";let t3="accessToken",t4="refreshToken",t9="profile",t7="providerType";class re extends t8{constructor(e,t){super(e,`user(${t})`)}get accessToken(){return this.get(t3)}set accessToken(e){null===e?this.remove(t3):this.set(t3,e)}get refreshToken(){return this.get(t4)}set refreshToken(e){null===e?this.remove(t4):this.set(t4,e)}get profile(){let e=this.get(t9);if(e){let t=new t6;return Object.assign(t,JSON.parse(e)),t}}set profile(e){e?this.set(t9,JSON.stringify(e)):this.remove(t9)}get providerType(){let e=this.get(t7);if(e)return e}set providerType(e){e?this.set(t7,e):this.remove(t7)}}function rt(e){return Object.fromEntries(Object.entries(e).filter(e=>void 0!==e[1]))}function rr(e,t=!0){let r=rt(e);return(t&&Object.keys(r).length>0?"?":"")+Object.entries(r).map(([e,t])=>`${e}=${encodeURIComponent(t)}`).join("&")}let rn=["inspect","callFunction","callFunctionStreaming",...Object.getOwnPropertyNames(Object.prototype)];function ri(e){return(function(e){for(let t of e)if("object"==typeof t&&t)for(let[e,r]of Object.entries(t))void 0===r&&delete t[e];return e})(e).map(e=>"object"==typeof e?t1(e):e)}class ro{static create(e,t={}){return new Proxy(new ro(e,t),{get(e,t,r){if("string"==typeof t&&-1===rn.indexOf(t))return e.callFunction.bind(e,t);{let n=Reflect.get(e,t,r);return"function"==typeof n?n.bind(e):n}}})}constructor(e,t={}){this.fetcher=e,this.serviceName=t.serviceName,this.argsTransformation=t.argsTransformation||ri}async callFunction(e,...t){let r={name:e,arguments:this.argsTransformation?this.argsTransformation(t):t};this.serviceName&&(r.service=this.serviceName);let n=this.fetcher.appRoute;return this.fetcher.fetchJSON({method:"POST",path:n.functionsCall().path,body:r})}callFunctionStreaming(e,...t){let r={name:e,arguments:this.argsTransformation?this.argsTransformation(t):t};this.serviceName&&(r.service=this.serviceName);let n=this.fetcher.appRoute,i=rr({baas_request:tV(JSON.stringify(r))});return this.fetcher.fetchStream({method:"GET",path:n.functionsCall().path+i})}}class rs{constructor(e,t="local-userpass"){this.fetcher=e,this.providerName=t}async registerUser(e){let t=this.fetcher.appRoute;await this.fetcher.fetchJSON({method:"POST",path:t.emailPasswordAuth(this.providerName).register().path,body:e})}async confirmUser(e){let t=this.fetcher.appRoute;await this.fetcher.fetchJSON({method:"POST",path:t.emailPasswordAuth(this.providerName).confirm().path,body:e})}async resendConfirmationEmail(e){let t=this.fetcher.appRoute;await this.fetcher.fetchJSON({method:"POST",path:t.emailPasswordAuth(this.providerName).confirmSend().path,body:e})}async retryCustomConfirmation(e){let t=this.fetcher.appRoute;await this.fetcher.fetchJSON({method:"POST",path:t.emailPasswordAuth(this.providerName).confirmCall().path,body:e})}async resetPassword(e){let t=this.fetcher.appRoute;await this.fetcher.fetchJSON({method:"POST",path:t.emailPasswordAuth(this.providerName).reset().path,body:e})}async sendResetPasswordEmail(e){let t=this.fetcher.appRoute;await this.fetcher.fetchJSON({method:"POST",path:t.emailPasswordAuth(this.providerName).resetSend().path,body:e})}async callResetPasswordFunction(e,...t){let r=this.fetcher.appRoute;await this.fetcher.fetchJSON({method:"POST",path:r.emailPasswordAuth(this.providerName).resetCall().path,body:{...e,arguments:t}})}}var ra=function(){return{path:"/api/client/v2.0",app(e){return{path:this.path+`/app/${e}`,location(){return{path:this.path+"/location"}},authProvider(e){return{path:this.path+`/auth/providers/${e}`,login(){return{path:this.path+"/login"}}}},emailPasswordAuth(e){return{...this.authProvider(e),register(){return{path:this.path+"/register"}},confirm(){return{path:this.path+"/confirm"}},confirmSend(){return{path:this.path+"/confirm/send"}},confirmCall(){return{path:this.path+"/confirm/call"}},reset(){return{path:this.path+"/reset"}},resetSend(){return{path:this.path+"/reset/send"}},resetCall(){return{path:this.path+"/reset/call"}}
1}},functionsCall(){return{path:this.path+"/functions/call"}}}},auth(){return{path:this.path+"/auth",apiKeys(){return{path:this.path+"/api_keys",key(e){return{path:this.path+`/${e}`,enable(){return{path:this.path+"/enable"}},disable(){return{path:this.path+"/disable"}}}}}},profile(){return{path:this.path+"/profile"}},session(){return{path:this.path+"/session"}},delete(){return{path:this.path+"/delete"}}}}}};class rc{constructor(e){this.fetcher=e}create(e){return this.fetcher.fetchJSON({method:"POST",body:{name:e},path:ra().auth().apiKeys().path,tokenType:"refresh"})}fetch(e){return this.fetcher.fetchJSON({method:"GET",path:ra().auth().apiKeys().key(e).path,tokenType:"refresh"})}fetchAll(){return this.fetcher.fetchJSON({method:"GET",tokenType:"refresh",path:ra().auth().apiKeys().path})}async delete(e){await this.fetcher.fetchJSON({method:"DELETE",path:ra().auth().apiKeys().key(e).path,tokenType:"refresh"})}async enable(e){await this.fetcher.fetchJSON({method:"PUT",path:ra().auth().apiKeys().key(e).enable().path,tokenType:"refresh"})}async disable(e){await this.fetcher.fetchJSON({method:"PUT",path:ra().auth().apiKeys().key(e).disable().path,tokenType:"refresh"})}}let ru=null;function rf(){if(ru)return ru;throw Error("Cannot get environment before it's set")}class rl extends Error{constructor({message:e,code:t}){super(e),this.name="WatchError",this.code=t}}(o=p||(p={})).NEED_DATA="NEED_DATA",o.HAVE_EVENT="HAVE_EVENT",o.HAVE_ERROR="HAVE_ERROR";class rh{constructor(){this._state=p.NEED_DATA,this._error=null,this._textDecoder=new(rf()).TextDecoder,this._buffer="",this._bufferOffset=0,this._eventType="",this._dataBuffer=""}feedBuffer(e){this.assertState(p.NEED_DATA),this._buffer+=this._textDecoder.decode(e,{stream:!0}),this.advanceBufferState()}feedLine(e){if(this.assertState(p.NEED_DATA),e.endsWith("\n")&&(e=e.substr(0,e.length-1)),e.endsWith("\r")&&(e=e.substr(0,e.length-1)),0===e.length){if(0===this._dataBuffer.length){this._eventType="";return}this._dataBuffer.endsWith("\n")&&(this._dataBuffer=this._dataBuffer.substr(0,this._dataBuffer.length-1)),this.feedSse({data:this._dataBuffer,eventType:this._eventType}),this._dataBuffer="",this._eventType=""}if(":"===e[0])return;let t=e.indexOf(":"),r=e.substr(0,t),n=-1===t?"":e.substr(t+1);n.startsWith(" ")&&(n=n.substr(1)),"event"===r?this._eventType=n:"data"===r&&(this._dataBuffer+=n,this._dataBuffer+="\n")}feedSse(e){this.assertState(p.NEED_DATA);let t=e.data.indexOf("%");if(-1!==t){let r="",n=0;for(let i=t;-1!==i;i=e.data.indexOf("%",n)){r+=e.data.substr(n,i-n);let t=e.data.substr(i,3);"%25"===t?r+="%":"%0A"===t?r+="\n":"%0D"===t?r+="\r":r+=t,n=i+t.length}r+=e.data.substr(n),e.data=r}if(e.eventType&&"message"!==e.eventType){if("error"===e.eventType){this._state=p.HAVE_ERROR,this._error=new rl({message:e.data,code:"unknown"});try{let{error_code:t,error:r}=f.parse(e.data);if("string"!=typeof t||"string"!=typeof r)return;this._error=new rl({message:r,code:t})}catch{return}}}else{try{let t=f.parse(e.data);if("object"==typeof t){this._nextEvent=t,this._state=p.HAVE_EVENT;return}}catch{}this._state=p.HAVE_ERROR,this._error=new rl({message:"server returned malformed event: "+e.data,code:"bad bson parse"})}}get state(){return this._state}nextEvent(){this.assertState(p.HAVE_EVENT);let e=this._nextEvent;return this._state=p.NEED_DATA,this.advanceBufferState(),e}get error(){return this._error}advanceBufferState(){for(this.assertState(p.NEED_DATA);this.state===p.NEED_DATA;){if(this._bufferOffset===this._buffer.length){this._buffer="",this._bufferOffset=0;return}let e=this._buffer.indexOf("\n",this._bufferOffset);if(-1===e){0!==this._bufferOffset&&(this._buffer=this._buffer.substr(this._bufferOffset,this._buffer.length-this._bufferOffset),this._bufferOffset=0);return}this.feedLine(this._buffer.substr(this._bufferOffset,e-this._bufferOffset)),this._bufferOffset=e+1}}assertState(e){if(this._state!==e)throw Error(`Expected WatchStream to be in state ${e}, but in state ${this._state}`)}}class rd{constructor(e,t,r,n){this.functions=ro.create(e,{serviceName:t}),this.databaseName=r,this.collectionName=n,this.serviceName=t,this.fetcher=e}find(e={},t={}){return this.functions.find({database:this.databaseName,collection:this.collectionName,query:e,project:t.projection,sort:t.sort,limit:t.limit})}findOne(e={},t={}){return this.functions.findOne({database:this.databaseName,collection:this.collectionName,query:e,project:t.projection,sort:t.sort})}findOneAndUpdate(e={},t,r={}){return this.functions.findOneAndUpdate({database:this.databaseName,collection:this.collectionName,filter:e,update:t,sort:r.sort,projection:r.projection,upsert:r.upsert,returnNewDocument:r.returnNewDocument})}findOneAndReplace(e={},t,r={}){return this.functions.findOneAndReplace({database:this.databaseName,collection:this.collectionName,filter:e,update:t,sort:r.sort,projection:r.projection,upsert:r.upsert,returnNewDocument:r.returnNewDocument})}findOneAndDelete(e={},t={}){return this.functions.findOneAndReplace({database:this.databaseName,collection:this.collectionName,filter:e,sort:t.sort,projection:t.projection})}aggregate(e){return this.functions.aggregate({database:this.databaseName,collection:this.collectionName,pipeline:e})}count(e={},t={}){return this.functions.count({database:this.databaseName,collection:this.collectionName,query:e,limit:t.limit})}insertOne(e){return this.functions.insertOne({database:this.databaseName,collection:this.collectionName,document:e})}insertMany(e){return this.functions.insertMany({database:this.databaseName,collection:this.collectionName,documents:e})}deleteOne(e={}){return this.functions.deleteOne({database:this.databaseName,collection:this.collectionName,query:e})}deleteMany(e={}){return this.functions.deleteMany({database:this.databaseName,collection:this.collectionName,query:e})}updateOne(e,t,r={}){return this.functions.updateOne({database:this.databaseName,collection:this.collectionName,query:e,update:t,upsert:r.upsert,arrayFilters:r.arrayFilters})}updateMany(e,t,r={}){return this.functions.updateMany({database:this.databaseName,collection:this.collectionName,query:e,update:t,upsert:r.upsert,arrayFilters:r.arrayFilters})}watch({ids:e,filter:t}={}){let r=this.functions.callFunctionStreaming("watch",{database:this.databaseName,collection:this.collectionName,ids:e,filter:t}).then(e=>e[Symbol.asyncIterator]()),n=this.watchImpl(r),i=n.return;return Object.assign(n,{return:e=>(r.then(t=>t.return?t.return(e):void 0),i.call(n,e))})}async *watchImpl(e){let t=new rh,r=e.then(e=>({[Symbol.asyncIterator]:()=>e}));for await(let e of(await r))if(e){for(t.feedBuffer(e);t.state==p.HAVE_EVENT;)yield t.nextEvent();if(t.state==p.HAVE_ERROR)throw t.error}}}function rp(e,t,r,n){return new rd(e,t,r,n)}function ry(e,t,r){return{collection:rp.bind(null,e,t,r)}}(s=y||(y={})).Active="active",s.LoggedOut="logged-out",s.Removed="removed",(a=g||(g={})).Normal="normal",a.Server="server";class rg{constructor(e){if(this.app=e.app,this.id=e.id,this.storage=new re(this.app.storage,this.id),"accessToken"in e&&"refreshToken"in e&&"providerType"in e)this._accessToken=e.accessToken,this._refreshToken=e.refreshToken,this.providerType=e.providerType,this.storage.accessToken=e.accessToken,this.storage.refreshToken=e.refreshToken,this.storage.providerType=e.providerType;else{this._accessToken=this.storage.accessToken,this._refreshToken=this.storage.refreshToken;const e=this.storage.providerType;if(this._profile=this.storage.profile,e)this.providerType=e;else throw Error("Storage is missing a provider type")}this.fetcher=this.app.fetcher.clone({userContext:{currentUser:this}}),this.apiKeys=new rc(this.fetcher),this.functions=ro.create(this.fetcher)}get accessToken(){return this._accessToken}set accessToken(e){this._accessToken=e,this.storage.accessToken=e}get refreshToken(){return this._refreshToken}set refreshToken(e){this._refreshToken=e,this.storage.refreshToken=e}get state(){return this.id in this.app.allUsers?null===this.refreshToken?y.LoggedOut:y.Active:y.Removed}get isLoggedIn(){return this.state===y.Active}get customData(){if(this.accessToken)return this.decodeAccessToken().userData;throw Error("Cannot read custom data without an access token")}get profile(){if(this._profile)return this._profile.data;throw Error("A profile was never fetched for this user")}get identities(){if(this._profile)return this._profile.identities;throw Error("A profile was never fetched for this user")}get deviceId(){if(this.accessToken){let e=this.accessToken.split(".")[1];if(e){let t=JSON.parse(tQ(e)).baas_device_id;if("string"==typeof t&&"000000000000000000000000"!==t)return t}}return null}async refreshProfile(){let e=await this.fetcher.fetchJSON({method:"GET",path:ra().auth().profile().path});this._profile=new t6(e),this.storage.profile=this._profile}async logOut(){try{null!==this._refreshToken&&await this.fetcher.fetchJSON({method:"DELETE",path:ra().auth().session().path,tokenType:"refresh"})}catch(e){if(!(e instanceof Error)||!e.message.includes("failed to find refresh token"))throw e}finally{this.accessToken=null,this.refreshToken=null}}async linkCredentials(e){let t=await this.app.authenticator.authenticate(e,this);if(this.id!==t.userId){let e=`got user id ${t.userId} expected ${this.id}`;throw Error(`Link response ment for another user (${e})`)}this.accessToken=t.accessToken,await this.refreshProfile()}async refreshAccessToken(){let{access_token:e}=await this.fetcher.fetchJSON({method:"POST",path:ra().auth().session().path,tokenType:"refresh"});if("string"==typeof e)this.accessToken=e;else throw Error("Expected an 'access_token' in the response")}async refreshCustomData(){return await this.refreshAccessToken(),this.customData}addListener(){throw Error("Not yet implemented")}removeListener(){throw Error("Not yet implemented")}removeAllListeners(){throw Error("Not yet implemented")}callFunction(e,...t){return this.functions.callFunction(e,...t)}toJSON(){return{id:this.id,accessToken:this.accessToken,refreshToken:this.refreshToken,profile:this._profile,state:this.state,customData:this.customData}}push(){throw Error("Not yet implemented")}mongoClient(e){return function(e,t="mongo-db"){return{db:ry.bind(null,e,t)}}(this.fetcher,e)}decodeAccessToken(){if(this.accessToken){let e=this.accessToken.split(".");if(3!==e.length)throw Error("Expected an access token with three parts");let{exp:t,iat:r,sub:n,user_data:i={}}=JSON.parse(tQ(e[1]));if("number"!=typeof t)throw Error("Failed to decode access token 'exp'");if("number"!=typeof r)throw Error("Failed to decode access token 'iat'");return{expires:t,issuedAt:r,subject:n,userData:i}}throw Error("Missing an access token")}}let rw="userIds",rm="deviceId";class rb extends t8{constructor(e,t){super(e,`app(${t})`)}getUserIds(){let e=this.get(rw),t=e?JSON.parse(e):[];if(Array.isArray(t))return[...new Set(t)];throw Error("Expected the user ids to be an array")}setUserIds(e,t){if(t)for(let t of this.getUserIds())-1===e.indexOf(t)&&e.push(t);this.set(rw,JSON.stringify(e))}removeUserId(e){let t=this.getUserIds().filter(t=>t!==e);this.setUserIds(t,!1)}getDeviceId(){return this.get(rm)}setDeviceId(e){this.set(rm,e)}}let rv={_baas_client_app_id:"appId",_baas_ua:"userAuth",_baas_link:"link",_baas_error:"error",_baas_state:"state"};class rE{static parseRedirectLocation(e){let t=Object.fromEntries(("?"===e[0]?e.substr(1):e).split("&").filter(e=>e.length>0).map(e=>e.split("=")).map(([e,t])=>
1[e,decodeURIComponent(t)])),r={};for(let[e,n]of Object.entries(rv)){let i=t[e];i&&(r[n]=i)}return r}static handleRedirect(e,t=rf().defaultStorage){let r=rE.parseRedirectLocation(e),{state:n,error:i}=r;if("string"==typeof n){let e=t.prefix("oauth2");rE.getStateStorage(e,n).set("result",JSON.stringify(r))}else if(i)throw Error(`Failed to handle OAuth 2.0 redirect: ${i}`);else throw Error("Failed to handle OAuth 2.0 redirect.")}static decodeAuthInfo(e){let t=(e||"").split("$");if(4===t.length){let[e,r,n,i]=t;return{accessToken:e,refreshToken:r,userId:n,deviceId:i}}throw Error("Failed to decode 'authInfo' into ids and tokens")}static getStateStorage(e,t){return e.prefix(`state(${t})`)}constructor(e,t=rf().openWindow){this.storage=e.prefix("oauth2"),this.openWindow=t}openWindowAndWaitForRedirect(e,t){let r=rE.getStateStorage(this.storage,t);return new Promise((t,n)=>{let i,o=null,s=()=>{let e=r.get("result");if(e){let n=JSON.parse(e);r.removeListener(s),r.clear();try{o&&(clearInterval(i),o.close())}catch(e){console.warn(`Failed closing redirect window: ${e}`)}finally{t(n)}}};r.addListener(s),o=this.openWindow(e),i=setInterval(()=>{o?o.closed&&(clearInterval(i),r.removeListener(s),n(Error("Window closed"))):clearInterval(i)},100)})}generateState(){var e="abcdefghijklmnopqrstuvwxyz";let t="";for(let r=0;r<12;r++)t+=e[Math.floor(Math.random()*e.length)];return t}}let rS="x-baas-location";class r_{constructor(e,t,r){this.fetcher=e,this.oauth2=new rE(t),this.getDeviceInformation=r}async authenticate(e,t){let r=this.getDeviceInformation(),n="object"==typeof t;if(e.providerType.startsWith("oauth2")&&"string"==typeof e.payload.redirectUrl){let i=this.oauth2.generateState(),o=await this.getLogInUrl(e,n,{state:i,redirect:e.payload.redirectUrl,providerRedirectHeader:!!n||void 0,device:n?void 0:r.encode()});if(!n)return this.openWindowAndWaitForAuthResponse(o,i);{let e=(await this.fetcher.fetch({method:"GET",url:o,tokenType:n?"access":"none",user:t,mode:"cors",credentials:"include"})).headers.get(rS);if(e)return this.openWindowAndWaitForAuthResponse(e,i);throw Error(`Missing ${rS} header`)}}{let i=await this.getLogInUrl(e,n),{user_id:o,access_token:s,refresh_token:a=null,device_id:c}=await this.fetcher.fetchJSON({method:"POST",url:i,body:{...e.payload,options:{device:r.toJSON()}},tokenType:n?"access":"none",user:t});if("string"!=typeof o)throw Error("Expected a user id in the response");if("string"!=typeof s)throw Error("Expected an access token in the response");if("string"!=typeof a&&null!==a)throw Error("Expected refresh token to be a string or null");if("string"!=typeof c)throw Error("Expected device id to be a string");return{userId:o,accessToken:s,refreshToken:a,deviceId:c}}}async getLogInUrl(e,t=!1,r={}){let n=this.fetcher.appRoute.authProvider(e.providerName).login(),i=rr({link:t?"true":void 0,...r});return await this.fetcher.locationUrl+n.path+i}async openWindowAndWaitForAuthResponse(e,t){let r=await this.oauth2.openWindowAndWaitForRedirect(e,t);return rE.decodeAuthInfo(r.userAuth)}}class rA extends Error{static async fromRequestAndResponse(e,t,r){var n;let{method:i="unknown"}=t,{status:o,statusText:s}=r;if(null==(n=r.headers.get("content-type"))?void 0:n.startsWith("application/json")){let t=await r.json();if("object"==typeof t&&t){let{error:r,error_code:n,link:a}=t;return new rA(i,e,o,s,"string"==typeof r?r:void 0,"string"==typeof n?n:void 0,"string"==typeof a?a:void 0)}}return new rA(i,e,o,s)}constructor(e,t,r,n,i,o,s){const a=n?`status ${r} ${n}`:`status ${r}`;"string"==typeof i?super(`Request failed (${e} ${t}): ${i} (${a})`):super(`Request failed (${e} ${t}): (${a})`),this.method=e,this.url=t,this.statusText=n,this.statusCode=r,this.error=i,this.errorCode=o,this.link=s}}class rx{static buildAuthorizationHeader(e,t){if(!e||"none"===t)return{};if("access"===t)return{Authorization:`Bearer ${e.accessToken}`};if("refresh"===t)return{Authorization:`Bearer ${e.refreshToken}`};throw Error(`Unexpected token type (${t})`)}static buildBody(e){if(e){if("object"==typeof e&&null!==e)return JSON.stringify(t1(e));if("string"==typeof e)return e;throw console.log("body is",e),Error("Unexpected type of body")}}static buildJsonHeader(e){return e&&e.length>0?{"Content-Type":"application/json"}:{}}constructor(e){this.config=e}clone(e){return new rx({...this.config,...e})}async fetch(e){let{path:t,url:r,tokenType:n="access",user:i=this.config.userContext.currentUser,...o}=e;if("string"==typeof t&&"string"==typeof r)throw Error("Use of 'url' and 'path' mutually exclusive");
1if("string"==typeof t){let r=await this.config.locationUrlContext.locationUrl+t;return this.fetch({...e,path:void 0,url:r})}if("string"==typeof r){let t=await this.config.fetch(r,{...o,headers:{...rx.buildAuthorizationHeader(i,n),...e.headers}});if(t.ok)return t;{let o=await rA.fromRequestAndResponse(r,e,t);if(i&&401===t.status&&("InvalidSession"===o.errorCode||"unauthorized"===o.error))if("access"===n)return await i.refreshAccessToken(),this.fetch({...e,user:i});else"refresh"===n&&(i.accessToken=null,i.refreshToken=null);throw o}}throw Error("Expected either 'url' or 'path'")}async fetchJSON(e){let{body:t}=e,r=rx.buildBody(t),n=rx.buildJsonHeader(r),i=await this.fetch({...e,body:r,headers:{Accept:"application/json",...n,...e.headers}}),o=i.headers.get("content-type");if(null==o?void 0:o.startsWith("application/json"))return t2(await i.json());if(null===o)return null;throw Error(`Expected JSON response, got "${o}"`)}async fetchStream(e){return function({body:e}){if("object"!=typeof e||null===e)throw Error("Expected a non-null object");if("getReader"in e)return{[Symbol.asyncIterator](){let t=e.getReader();return{async next(){let{done:e,value:r}=await t.read();if(e)return{done:e,value:void 0};if(r instanceof Uint8Array)return{done:e,value:r};throw Error("Expected value to be Uint8Array")},return:async()=>(await t.cancel(),{done:!0,value:null})}}};throw Error("Expected an AsyncIterable or a ReadableStream")}(await this.fetch({...e,headers:{Accept:"text/event-stream",...e.headers}}))}get appRoute(){return ra().app(this.config.appId)}get locationUrl(){return this.config.locationUrlContext.locationUrl}}(c=w||(w={})).DEVICE_ID="deviceId",c.APP_ID="appId",c.APP_VERSION="appVersion",c.PLATFORM="platform",c.PLATFORM_VERSION="platformVersion",c.SDK_VERSION="sdkVersion";class rO{constructor({appId:e,appVersion:t,deviceId:r}){this.sdkVersion="2.0.1";const n=rf();this.platform=n.platform,this.platformVersion=n.platformVersion,this.appId=e,this.appVersion=t,this.deviceId=r}encode(){return tV(JSON.stringify(rt(this)))}toJSON(){return rt(this)}}class rT{static getApp(e){if(e in rT.appCache)return rT.appCache[e];{let t=new rT(e);return rT.appCache[e]=t,t}}constructor(e){var t;this.users=[],this._locationUrl=null;const r="string"==typeof e?{id:e}:e;if("object"==typeof r&&"string"==typeof r.id)this.id=r.id;else throw Error("Missing an Atlas App Services app-id");this.baseUrl=r.baseUrl||"https://services.cloud.mongodb.com",r.skipLocationRequest&&(this._locationUrl=Promise.resolve(this.baseUrl)),this.localApp=r.app,this.fetcher=new rx({appId:this.id,userContext:this,locationUrlContext:this,fetch:null!=(t=r.fetch)?t:tk}),this.emailPasswordAuth=new rs(this.fetcher);const n=r.storage||rf().defaultStorage;this.storage=new rb(n,this.id),this.authenticator=new r_(this.fetcher,n,()=>this.deviceInformation);try{this.hydrate()}catch(e){this.storage.clear(),console.warn("Realm app hydration failed:",e instanceof Error?e.message:e)}}switchUser(e){let t=this.users.findIndex(t=>t===e);if(-1===t)throw Error("The user was never logged into this app");let[r]=this.users.splice(t,1);this.users.unshift(r)}async logIn(e,t=!0){if(e.reuse){let r=this.users.find(t=>t.providerType===e.providerType);if(r)return this.switchUser(r),t&&await r.refreshProfile(),r}let r=await this.authenticator.authenticate(e),n=this.createOrUpdateUser(r,e.providerType);this.switchUser(n),t&&await n.refreshProfile(),this.storage.setUserIds(this.users.map(e=>e.id),!0);let i=r.deviceId;return i&&"000000000000000000000000"!==i&&this.storage.set("deviceId",i),n}async removeUser(e){let t=this.users.findIndex(t=>t===e);if(-1===t)throw Error("The user was never logged into this app");this.users.splice(t,1),await e.logOut(),this.storage.remove(`user(${e.id}):profile`),this.storage.removeUserId(e.id)}async deleteUser(e){await this.fetcher.fetchJSON({method:"DELETE",path:ra().auth().delete().path}),await this.removeUser(e)}addListener(){throw Error("Not yet implemented")}removeListener(){throw Error("Not yet implemented")}removeAllListeners(){throw Error("Not yet implemented")}get currentUser(){let e=this.users.filter(e=>e.state===y.Active);return 0===e.length?null:e[0]}get allUsers(){return Object.fromEntries(this.users.map(e=>[e.id,e]))}get locationUrl(){if(!this._locationUrl){let e=ra().app(this.id).location().path;this._locationUrl=this.fetcher.fetchJSON({method:"GET",url:this.baseUrl+e,tokenType:"none"}).then(e=>{if("object"==typeof e)return e;throw Error("Expected response body be an object")}).then(({hostname:e})=>
1{if("string"==typeof e)return e;throw Error("Expected response to contain a 'hostname'")}).catch(e=>{throw this._locationUrl=null,e})}return this._locationUrl}get deviceInformation(){let e=this.storage.getDeviceId(),t="string"==typeof e&&"000000000000000000000000"!==e?new eU(e):void 0;return new rO({appId:this.localApp?this.localApp.name:void 0,appVersion:this.localApp?this.localApp.version:void 0,deviceId:t})}createOrUpdateUser(e,t){let r=this.users.find(t=>t.id===e.userId);if(r)return r.accessToken=e.accessToken,r.refreshToken=e.refreshToken,r;{if(!e.refreshToken)throw Error("No refresh token in response from server");let r=new rg({app:this,id:e.userId,accessToken:e.accessToken,refreshToken:e.refreshToken,providerType:t});return this.users.unshift(r),r}}hydrate(){let e=this.storage.getUserIds();this.users=e.map(e=>new rg({app:this,id:e}))}}rT.appCache={},rT.Credentials=class e{static anonymous(t=!0){return new e("anon-user","anon-user",t,{})}static apiKey(t){return new e("api-key","api-key",!1,{key:t})}static emailPassword(t,r){return new e("local-userpass","local-userpass",!1,{username:t,password:r})}static function(t){return new e("custom-function","custom-function",!1,t)}static jwt(t){return new e("custom-token","custom-token",!1,{token:t})}static google(t){return new e("oauth2-google","oauth2-google",!1,e.derivePayload(t))}static derivePayload(e){if("string"==typeof e)throw Error("`google(<tokenString>)` has been deprecated. Please use `google(<authCodeObject>).");if(1===Object.keys(e).length)if("authCode"in e||"redirectUrl"in e)return e;else if("idToken"in e)return{id_token:e.idToken};else throw Error("Unexpected payload: "+JSON.stringify(e));throw Error("Expected only one property in payload, got "+JSON.stringify(e))}static facebook(t){return new e("oauth2-facebook","oauth2-facebook",!1,t.includes("://")?{redirectUrl:t}:{accessToken:t})}static apple(t){return new e("oauth2-apple","oauth2-apple",!1,t.includes("://")?{redirectUrl:t}:{id_token:t})}constructor(e,t,r,n){this.providerName=e,this.providerType=t,this.reuse=r,this.payload=n}};let rN=function(e){return e&&e.Math==Math&&e},rk=rN("object"==typeof globalThis&&globalThis)||rN("object"==typeof window&&window)||rN("object"==typeof self&&self)||rN(e.g)||function(){return this}()||Function("return this")();"u">typeof __DEV__&&__DEV__;let rU="u"<typeof document&&"u">typeof navigator&&"ReactNative"===navigator.product?new function(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}:"u">typeof navigator?function(e){var t=""!==e&&tT.reduce(function(t,r){var n=r[0],i=r[1];if(t)return t;var o=i.exec(e);return!!o&&[n,o]},!1);if(!t)return null;var r=t[0],n=t[1];if("searchbot"===r)return new tx;var i=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);i?i.length<3&&(i=tE(tE([],i,!0),function(e){for(var t=[],r=0;r<e;r++)t.push("0");return t}(3-i.length),!0)):i=[];var o=i.join("."),s=function(e){for(var t=0,r=tN.length;t<r;t++){var n=tN[t],i=n[0];if(n[1].exec(e))return i}return null}(e),a=tO.exec(e);return a&&a[1]?new tA(r,o,s,a[1]):new tS(r,o,s)}(navigator.userAgent):void 0!==m.default&&m.default.version?new t_(m.default.version.slice(1)):null;ru={defaultStorage:new("localStorage"in rk?class{constructor(){if("object"==typeof rk.localStorage)this.global=rk;else throw Error("Cannot use LocalStorage without a global localStorage object")}get(e){return this.global.localStorage.getItem(e)}set(e,t){return this.global.localStorage.setItem(e,t)}remove(e){return this.global.localStorage.removeItem(e)}prefix(e){return new t8(this,e)}clear(e){let t=[];for(let r=0;r<this.global.localStorage.length;r++){let n=this.global.localStorage.key(r);n&&(!e||n.startsWith(e))&&t.push(n)}for(let e of t)this.global.localStorage.removeItem(e)}addListener(e){return this.global.addEventListener("storage",e)}removeListener(e){return this.global.removeEventListener("storage",e)}}:class{constructor(){this.storage={},this.listeners=new Set}get(e){return e in this.storage?this.storage[e]:null}set(e,t){this.storage[e]=t,this.fireListeners()}remove(e){delete this.storage[e],this.fireListeners()}prefix(e){return new t8(this,e)}clear(e){for(let t of Object.keys(this.storage))(!e||t.startsWith(e))&&delete this.storage[t];this.fireListeners()}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}
1fireListeners(){this.listeners.forEach(e=>e())}})().prefix("realm-web"),openWindow:function(e){return"function"==typeof rk.open?rk.open(e):(console.log(`Please open ${e}`),null)},platform:(null==rU?void 0:rU.name)||"web",platformVersion:(null==rU?void 0:rU.version)||"0.0.0",TextDecoder},e.s([],252422),e.i(217255),e.i(151071);var rI=e.i(110394),rP=e.i(666298),rB=e.i(641188),rC=e.i(691741);e.s(["default",0,function(){let[e,t]=(0,v.useState)(""),[r,n]=(0,v.useState)(""),[i,o]=(0,v.useState)(""),[s,a]=(0,v.useState)(""),[c,u]=(0,v.useState)({instagram:"",tiktok:"",youtube:"",facebook:""}),f=e+r,[l,h]=(0,v.useState)(!0);async function d(e){let t=`/api/proxyImage?imageUrl=${encodeURIComponent(e)}`,r=await fetch(t);if(!r.ok)throw Error("Network response was not ok");return await r.blob()}async function p(e){let t=await fetch(e);if(!t.ok)throw Error("Network response was not ok");return await t.blob()}async function y(e,t){return(0,rP.uploadImage)(e,{folder:`creator_profile_pics/${t}`})}let[g,w]=(0,v.useState)(!1),m=(0,E.useRouter)(),[_,A]=(0,v.useState)(""),[x,O]=(0,v.useState)([]),[T,N]=(0,v.useState)(""),[k,U]=(0,v.useState)(""),[I,P]=(0,v.useState)(""),[B,C]=(0,v.useState)(""),[R,j]=(0,v.useState)("");(0,v.useEffect)(()=>{!async function(){if(!T)return O([]);try{console.log(`Searching for users with term: ${T}`);let e=await fetch(`https://www.socialscout.ai/api/searchAutoCompleteUsers?query=${encodeURIComponent(T)}`);if(e.ok){let t=await e.json();console.log("Users found:",t),O(t)}else console.error("Failed to fetch users:",await e.text())}catch(e){console.error("Error fetching users:",e)}}()},[T]);let H=async e=>{console.log("Starting getUserId function..."),console.log("userIDInstagram:",e);try{let t=await fetch("/api/ensembleInstagramUsernameToId",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userIDInstagram:e})});if(console.log("This is the response I'm getting back: ",t),!t.ok)throw Error("Network response was not ok");return await t.json()}catch(t){return console.error("Error fetching data for:",e,t),null}},D=async(e,t)=>{try{let r=await fetch("/api/esembleDataCreator",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({platform:e,identifier:t})});if(!r.ok)throw Error("Network response was not ok");return await r.json()}catch(r){return console.error("Error fetching data for:",e,t,r),null}},W=async e=>{try{let t=await fetch("/api/creatorYoutubeInfo",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({channelId:e})});if(!t.ok)throw Error("Network response was not ok");return await t.json()}catch(t){return console.error("Error fetching data for:",e,t),null}},K=async t=>{t.preventDefault();let n={};for(let e in c)if(console.log("Platform URL: ",c[e]),c[e]&&"tiktok"===e){let t=c[e].split("@").pop();console.log("This is the username ",t);let r=await D(e,t);if(console.log("There are this many followers",r?.data?.stats?.followingCount),r){console.log("This is the additional data: ",r);let i=r?.data?.user?.avatarLarger,o=await p(i),s=await y(o,t);n[e]={profile:c[e],followers:r?.data?.stats?.followerCount||0,handle:`@${t}`,image:s}}}else if(c[e]&&"instagram"===e){c[e];let t=c[e].split("@").pop();console.log("You have chosen the instagram platform and the username being passed to the api is: ",t);let r=await H(t);if(console.log("This is the instaId info: ",r),r){let t=r?.data.pk,i=await D(e,t);if(console.log("This is the additional data => ",i),i){let o=r?.data.profile_pic_url;console.log("This is the instagram imageUrl: ",o);let s=i.data.username;console.log("This is the instagram username ",s);let a=await d(o),c=await y(a,s);n[e]={profile:`https://www.instagram.com/${i.data.username}`,followers:i.data.followers||0,handle:`@${i.data.username}`,userId:t,pk:i.data.pk,image:c}}}}else if(c[e]&&"youtube"===e){let t,r,i=c[e].split("@").pop(),o=c[e].split("@").pop(),s=await D(e,o);console.log("This is the additional data for YouTube => ",s),t=s.data;let a=await W(t);r=function(e){if("string"!=typeof e)return null;let t=1;return e.endsWith("K")?(t=1e3,e=e.slice(0,-1)):e.endsWith("M")&&(t=1e6,e=e.slice(0,-1)),parseFloat(e)*t}(a.data),a&&(n[e]={profile:c[e],followers:r||0,handle:`@${i}`,browserID:t})}let o=`${e} ${r}`,a=T?._id;try{let t=await fetch("https://www.socialscout.ai/api/creator",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({first_name:e,last_name:r,name:o,country:B,city:k,state:I,category:s,sub_category:i,qyou_contact:a,image:_,socials:n})});if(!t.ok){let e=await t.json();S.default.error(e.err),console.log(e.err),w(!1);return}let c=await t.json();c.success?(S.default.success(c.success),w(!1),m.push(`/dashboard/user/creator/${c.creatorId}`)):(S.default.error(c.err),w(!1))}catch(e){console.log(e),w(!1),S.default.error("An error occurred. Try again")}},M=async e=>{let t=e.target.files[0];if(t){w(!0);try{let e=await (0,rP.uploadImage)(t,{folder:`creator_profile_pics/${f}`});A(e)}catch(e){console.log(e)}finally{w(!1)}}};return(0,b.jsxs)("div",{className:"flex-auto m-5 items-center justify-between space-y-5",children:[(0,b.jsx)("h1",{children:"Add Creator"}),(0,b.jsxs)("form",{onSubmit:K,children:[(0,b.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("label",{className:"font-thin",children:"First name"}
1),(0,b.jsx)("input",{type:"text",value:e,onChange:e=>t(e.target.value),className:"w-full mb-4 p-6 border border-gray-300 dark:border-zinc-700 rounded-md placeholder:font-light",placeholder:"Enter the creator's first name"})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("label",{className:"font-thin",children:"Last name"}),(0,b.jsx)("input",{type:"text",value:r,onChange:e=>n(e.target.value),className:"w-full mb-4 p-6 border border-gray-300 dark:border-zinc-700 rounded-md placeholder:font-light",placeholder:"Enter the creator's last name"})]})]}),(0,b.jsx)("label",{className:"font-thin",children:"What country is this creator located in?"}),(0,b.jsx)("input",{type:"text",value:B,onChange:e=>C(e.target.value),className:"w-full mb-4 p-6 border border-gray-300 dark:border-zinc-700 rounded-md placeholder:font-light",placeholder:"Enter the creator's country"}),(0,b.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("label",{className:"font-thin",children:"City"}),(0,b.jsx)("input",{type:"text",value:k,onChange:e=>U(e.target.value),className:"w-full mb-4 p-6 border border-gray-300 dark:border-zinc-700 rounded-md placeholder:font-light",placeholder:"Enter the creator's city"})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("label",{className:"font-thin",children:"State"}),(0,b.jsx)("input",{type:"text",value:I,onChange:e=>P(e.target.value),className:"w-full mb-4 p-6 border border-gray-300 dark:border-zinc-700 rounded-md placeholder:font-light",placeholder:"Enter the creator's state"})]})]}),(0,b.jsx)("label",{className:"font-thin",children:"Who is the Talent Relations POC?"}),(0,b.jsx)("input",{type:"text",value:T.name,onChange:e=>N(e.target.value),className:"w-full mb-4 p-6 border border-gray-300 dark:border-zinc-700 rounded-md placeholder:font-light",placeholder:"Enter name of Talent Manager"}),x.length>0&&(0,b.jsx)("ul",{className:"absolute mt-[-25px] w-full bg-gray-200 border border-green-500 rounded-md z-20 dark:bg-zinc-800",children:x.map(e=>(0,b.jsx)("li",{className:"px-4 py-2 hover:bg-green-300 cursor-pointer",onClick:()=>{N(()=>e),j(()=>e),O([]),console.log(e),O([])},children:e.name},e._id))}),(0,b.jsxs)("div",{className:"grid grid-cols-2 gap-4 mb-4",children:[(0,b.jsx)("div",{children:(0,b.jsx)(rB.default,{value:s,onChange:e=>a(e.target.value)})}),(0,b.jsx)("div",{children:(0,b.jsx)(rC.default,{value:i,onChange:e=>o(e.target.value)})})]}),(0,b.jsx)("div",{children:(0,b.jsx)(rI.default,{urls:c,setUrls:u,isInstagramValid:l,setIsInstagramValid:h})}),(0,b.jsx)("div",{children:(0,b.jsxs)("div",{className:"text-white bg-gradient-to-br from-cyan-500 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-pink-200 dark:focus:ring-pink-800 font-medium rounded-lg text-xl px-5 py-2.5 text-center mr-2 mt-6 mb-2 transition-all duration-500 hover:scale-105 mb-3",children:[(0,b.jsx)("label",{className:"mt-2 pointer",htmlFor:"upload-button",children:g?"Uploading":"Upload image"}),(0,b.jsx)("input",{id:"upload-button",type:"file",accept:"image/*",onChange:M,hidden:!0})]})}),(0,b.jsx)("button",{disabled:!l,className:`text-white mt-4 font-medium rounded-lg text-xl px-5 py-2.5 text-center mr-2 mb-2 transition-all duration-500 hover:scale-105 ${l?"bg-gradient-to-br from-pink-500 to-orange-400 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-pink-200 dark:focus:ring-pink-800":"bg-gray-400 dark:bg-zinc-600 cursor-not-allowed"}`,children:g?"Please wait...":"Submit"})]})]})}],231526)},53358,e=>{"use strict";class t extends Error{static get code(){return"ERR_JOSE_GENERIC"}constructor(e){var t;super(e),this.code="ERR_JOSE_GENERIC",this.name=this.constructor.name,null==(t=Error.captureStackTrace)||t.call(Error,this,this.constructor)}}class r extends t{static get code(){return"ERR_JWT_CLAIM_VALIDATION_FAILED"}constructor(e,t="unspecified",r="unspecified"){super(e),this.code="ERR_JWT_CLAIM_VALIDATION_FAILED",this.claim=t,this.reason=r}}class n extends t{static get code(){return"ERR_JWT_EXPIRED"}constructor(e,t="unspecified",r="unspecified"){super(e),this.code="ERR_JWT_EXPIRED",this.claim=t,this.reason=r}}class i extends t{constructor(){super(...arguments),this.code="ERR_JOSE_ALG_NOT_ALLOWED"}static get code(){return"ERR_JOSE_ALG_NOT_ALLOWED"}}class o extends t{constructor(){super(...arguments),this.code="ERR_JOSE_NOT_SUPPORTED"}static get code(){return"ERR_JOSE_NOT_SUPPORTED"}}class s extends t{constructor(){super(...arguments),this.code="ERR_JWE_DECRYPTION_FAILED",this.message="decryption operation failed"}static get code(){return"ERR_JWE_DECRYPTION_FAILED"}}class a extends t{constructor(){super(...arguments),this.code="ERR_JWE_INVALID"}static get code(){return"ERR_JWE_INVALID"}}class c extends t{constructor(){super(...arguments),this.code="ERR_JWS_INVALID"}static get code(){return"ERR_JWS_INVALID"}}class u extends t{constructor(){super(...arguments),this.code="ERR_JWT_INVALID"}static get code(){return"ERR_JWT_INVALID"}}class f extends t{constructor(){super(...arguments),this.code="ERR_JWK_INVALID"}static get code(){return"ERR_JWK_INVALID"}}class l extends t{constructor(){super(...arguments),this.code="ERR_JWKS_INVALID"}static get code(){return"ERR_JWKS_INVALID"}}class h extends t{constructor(){super(...arguments),this.code="ERR_JWKS_NO_MATCHING_KEY",this.message="no applicable key found in the JSON Web Key Set"}static get code(){return"ERR_JWKS_NO_MATCHING_KEY"}}class d extends t{constructor(){super(...arguments),this.code="ERR_JWKS_MULTIPLE_MATCHING_KEYS",this.message="multiple matching keys found in the JSON Web Key Set"}static get code(){return"ERR_JWKS_MULTIPLE_MATCHING_KEYS"}}class p extends t{constructor(){super(...arguments),this.code="ERR_JWKS_TIMEOUT",this.message="request timed out"}static get code(){return"ERR_JWKS_TIMEOUT"}}class y extends t{constructor(){super(...arguments),this.code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED",this.message="signature verification failed"}static get code(){return"ERR_JWS_SIGNATURE_VERIFICATION_FAILED"}}e.s(["JOSEAlgNotAllowed",0,i,"JOSEError",0,t,"JOSENotSupported",0,o,"JWEDecompressionFailed",0,class extends t{constructor(){super(...arguments),this.code="ERR_JWE_DECOMPRESSION_FAILED",this.message="decompression o
1peration failed"}static get code(){return"ERR_JWE_DECOMPRESSION_FAILED"}},"JWEDecryptionFailed",0,s,"JWEInvalid",0,a,"JWKInvalid",0,f,"JWKSInvalid",0,l,"JWKSMultipleMatchingKeys",0,d,"JWKSNoMatchingKey",0,h,"JWKSTimeout",0,p,"JWSInvalid",0,c,"JWSSignatureVerificationFailed",0,y,"JWTClaimValidationFailed",0,r,"JWTExpired",0,n,"JWTInvalid",0,u],469111);var g=e.i(469111);let w=crypto,m=async(e,t)=>{let r=`SHA-${e.slice(-3)}`;return new Uint8Array(await w.subtle.digest(r,t))},b=new TextEncoder,v=new TextDecoder;function E(...e){let t=new Uint8Array(e.reduce((e,{length:t})=>e+t,0)),r=0;return e.forEach(e=>{t.set(e,r),r+=e.length}),t}function S(e,t,r){if(t<0||t>=0x100000000)throw RangeError(`value must be >= 0 and <= ${0x100000000-1}. Received ${t}`);e.set([t>>>24,t>>>16,t>>>8,255&t],r)}function _(e){let t=Math.floor(e/0x100000000),r=new Uint8Array(8);return S(r,t,0),S(r,e%0x100000000,4),r}function A(e){let t=new Uint8Array(4);return S(t,e),t}function x(e){return E(A(e.length),e)}async function O(e,t,r){let n=Math.ceil((t>>3)/32),i=new Uint8Array(32*n);for(let t=0;t<n;t++){let n=new Uint8Array(4+e.length+r.length);n.set(A(t+1)),n.set(e,4),n.set(r,4+e.length),i.set(await m("sha256",n),32*t)}return i.slice(0,t>>3)}let T=e=>{let t=e;"string"==typeof t&&(t=b.encode(t));let r=[];for(let e=0;e<t.length;e+=32768)r.push(String.fromCharCode.apply(null,t.subarray(e,e+32768)));return btoa(r.join(""))},N=e=>T(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_"),k=e=>{let t=atob(e),r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=t.charCodeAt(e);return r},U=e=>{let t=e;t instanceof Uint8Array&&(t=v.decode(t)),t=t.replace(/-/g,"+").replace(/_/g,"/").replace(/\s/g,"");try{return k(t)}catch(e){throw TypeError("The input to be decoded is not correctly encoded.")}};e.s(["decode",0,U,"encode",0,N],216576);var I=e.i(216576);e.s([],205461),e.i(205461);let P=w.getRandomValues.bind(w);function B(e){switch(e){case"A128GCM":case"A128GCMKW":case"A192GCM":case"A192GCMKW":case"A256GCM":case"A256GCMKW":return 96;case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return 128;default:throw new o(`Unsupported JWE Algorithm: ${e}`)}}let C=e=>P(new Uint8Array(B(e)>>3)),R=(e,t)=>{if(t.length<<3!==B(e))throw new a("Invalid Initialization Vector length")},j=(e,t)=>{let r=e.byteLength<<3;if(r!==t)throw new a(`Invalid Content Encryption Key length. Expected ${t} bits, got ${r} bits`)};function H(e,t="algorithm.name"){return TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`)}function D(e,t){return e.name===t}function W(e){return parseInt(e.name.slice(4),10)}function K(e,t){if(t.length&&!t.some(t=>e.usages.includes(t))){let e="CryptoKey does not support this operation, its usages must include ";if(t.length>2){let r=t.pop();e+=`one of ${t.join(", ")}, or ${r}.`}else 2===t.length?e+=`one of ${t[0]} or ${t[1]}.`:e+=`${t[0]}.`;throw TypeError(e)}}function M(e,t,...r){switch(t){case"A128GCM":case"A192GCM":case"A256GCM":{if(!D(e.algorithm,"AES-GCM"))throw H("AES-GCM");let r=parseInt(t.slice(1,4),10);if(e.algorithm.length!==r)throw H(r,"algorithm.length");break}case"A128KW":case"A192KW":case"A256KW":{if(!D(e.algorithm,"AES-KW"))throw H("AES-KW");let r=parseInt(t.slice(1,4),10);if(e.algorithm.length!==r)throw H(r,"algorithm.length");break}case"ECDH":switch(e.algorithm.name){case"ECDH":case"X25519":case"X448":break;default:throw H("ECDH, X25519, or X448")}break;case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":if(!D(e.algorithm,"PBKDF2"))throw H("PBKDF2");break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":{if(!D(e.algorithm,"RSA-OAEP"))throw H("RSA-OAEP");let r=parseInt(t.slice(9),10)||1;if(W(e.algorithm.hash)!==r)throw H(`SHA-${r}`,"algorithm.hash");break}default:throw TypeError("CryptoKey does not support this operation")}K(e,r)}function J(e,t,...r){if(r.length>2){let t=r.pop();e+=`one of type ${r.join(", ")}, or ${t}.`}else 2===r.length?e+=`one of type ${r[0]} or ${r[1]}.`:e+=`of type ${r[0]}.`;return null==t?e+=` Received ${t}`:"function"==typeof t&&t.name?e+=` Received function ${t.name}`:"object"==typeof t&&null!=t&&t.constructor&&t.constructor.name&&(e+=` Received an instance of ${t.constructor.name}`),e}let L=(e,...t)=>J("Key must be ",e,...t);function $(e,t,...r){return J(`Key for the ${e} algorithm must be `,t,...r)}let F=["CryptoKey"];async function V(e,t,r,n,i,o){let a,c;if(!(t instanceof Uint8Array))throw TypeError(L(t,"Uint8Array"));let u=parseInt(e.slice(1,4),10),f=await w.subtle.importKey("raw",t.subarray(u>>3),"AES-CBC",!1,["decrypt"]),l=await w.subtle.importKey("raw",t.subarray(0,u>>3),{hash:`SHA-${u<<1}`,name:"HMAC"},!1,["sign"]),h=E(o,n,r,_(o.length<<3)),d=new Uint8Array((await w.subtle.sign("HMAC",l,h)).slice(0,u>>3));try{a=((e,t)=>{if(!(e instanceof Uint8Array))throw TypeError("First argument must be a buffer");if(!(t instanceof Uint8Array))throw TypeError("Second argument must be a buffer");if(e.length!==t.length)throw TypeError("Input buffers must have the same length");let r=e.length,n=0,i=-1;for(;++i<r;)n|=e[i]^t[i];return 0===n})(i,d)}catch(e){}if(!a)throw new s;try{c=new Uint8Array(await w.subtle.decrypt({iv:n,name:"AES-CBC"},f,r))}catch(e){}if(!c)throw new s;return c}async function z(e,t,r,n,i,o){let a;t instanceof Uint8Array?a=await w.subtle.importKey("raw",t,"AES-GCM",!1,["decrypt"]):(M(t,e,"decrypt"),a=t);try{return new Uint8Array(await w.subtle.decrypt({additionalData:o,iv:n,name:"AES-GCM",tagLength:128},a,E(r,i)))}catch(e){throw new s}}let G=async(e,t,r,n,i,s)=>{if(!(t instanceof CryptoKey)&&!(t instanceof Uint8Array))throw TypeError(L(t,...F,"Uint8Array"));
1switch(R(e,n),e){case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return t instanceof Uint8Array&&j(t,parseInt(e.slice(-3),10)),V(e,t,r,n,i,s);case"A128GCM":case"A192GCM":case"A256GCM":return t instanceof Uint8Array&&j(t,parseInt(e.slice(1,4),10)),z(e,t,r,n,i,s);default:throw new o("Unsupported JWE Content Encryption Algorithm")}},Y=async()=>{throw new o('JWE "zip" (Compression Algorithm) Header Parameter is not supported by your javascript runtime. You need to use the `inflateRaw` decrypt option to provide Inflate Raw implementation.')},q=async()=>{throw new o('JWE "zip" (Compression Algorithm) Header Parameter is not supported by your javascript runtime. You need to use the `deflateRaw` encrypt option to provide Deflate Raw implementation.')},X=(...e)=>{let t,r=e.filter(Boolean);if(0===r.length||1===r.length)return!0;for(let e of r){let r=Object.keys(e);if(!t||0===t.size){t=new Set(r);continue}for(let e of r){if(t.has(e))return!1;t.add(e)}}return!0};function Z(e){if("object"!=typeof e||null===e||"[object Object]"!==Object.prototype.toString.call(e))return!1;if(null===Object.getPrototypeOf(e))return!0;let t=e;for(;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}let Q=[{hash:"SHA-256",name:"HMAC"},!0,["sign"]];function ee(e,t){if(e.algorithm.length!==parseInt(t.slice(1,4),10))throw TypeError(`Invalid key size for alg: ${t}`)}function et(e,t,r){if(e instanceof CryptoKey)return M(e,t,r),e;if(e instanceof Uint8Array)return w.subtle.importKey("raw",e,"AES-KW",!0,[r]);throw TypeError(L(e,...F,"Uint8Array"))}let er=async(e,t,r)=>{let n=await et(t,e,"wrapKey");ee(n,e);let i=await w.subtle.importKey("raw",r,...Q);return new Uint8Array(await w.subtle.wrapKey("raw",i,n,"AES-KW"))},en=async(e,t,r)=>{let n=await et(t,e,"unwrapKey");ee(n,e);let i=await w.subtle.unwrapKey("raw",r,n,"AES-KW",...Q);return new Uint8Array(await w.subtle.exportKey("raw",i))};async function ei(e,t,r,n,i=new Uint8Array(0),o=new Uint8Array(0)){let s;if(!(e instanceof CryptoKey))throw TypeError(L(e,...F));if(M(e,"ECDH"),!(t instanceof CryptoKey))throw TypeError(L(t,...F));M(t,"ECDH","deriveBits");let a=E(x(b.encode(r)),x(i),x(o),A(n));return s="X25519"===e.algorithm.name?256:"X448"===e.algorithm.name?448:Math.ceil(parseInt(e.algorithm.namedCurve.substr(-3),10)/8)<<3,O(new Uint8Array(await w.subtle.deriveBits({name:e.algorithm.name,public:e},t,s)),n,a)}async function eo(e){if(!(e instanceof CryptoKey))throw TypeError(L(e,...F));return w.subtle.generateKey(e.algorithm,!0,["deriveBits"])}function es(e){if(!(e instanceof CryptoKey))throw TypeError(L(e,...F));return["P-256","P-384","P-521"].includes(e.algorithm.namedCurve)||"X25519"===e.algorithm.name||"X448"===e.algorithm.name}async function ea(e,t,r,n){if(!(e instanceof Uint8Array)||e.length<8)throw new a("PBES2 Salt Input must be 8 or more octets");let i=E(b.encode(t),new Uint8Array([0]),e),o=parseInt(t.slice(13,16),10),s={hash:`SHA-${t.slice(8,11)}`,iterations:r,name:"PBKDF2",salt:i},c=await function(e,t){if(e instanceof Uint8Array)return w.subtle.importKey("raw",e,"PBKDF2",!1,["deriveBits"]);if(e instanceof CryptoKey)return M(e,t,"deriveBits","deriveKey"),e;throw TypeError(L(e,...F,"Uint8Array"))}(n,t);if(c.usages.includes("deriveBits"))return new Uint8Array(await w.subtle.deriveBits(s,c,o));if(c.usages.includes("deriveKey"))return w.subtle.deriveKey(s,c,{length:o,name:"AES-KW"},!1,["wrapKey","unwrapKey"]);throw TypeError('PBKDF2 key "usages" must include "deriveBits" or "deriveKey"')}let ec=async(e,t,r,n=2048,i=P(new Uint8Array(16)))=>{let o=await ea(i,e,n,t);return{encryptedKey:await er(e.slice(-6),o,r),p2c:n,p2s:N(i)}},eu=async(e,t,r,n,i)=>{let o=await ea(i,e,n,t);return en(e.slice(-6),o,r)};function ef(e){switch(e){case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":return"RSA-OAEP";default:throw new o(`alg ${e} is not supported either by JOSE or your javascript runtime`)}}let el=(e,t)=>
1{if(e.startsWith("RS")||e.startsWith("PS")){let{modulusLength:r}=t.algorithm;if("number"!=typeof r||r<2048)throw TypeError(`${e} requires key modulusLength to be 2048 bits or larger`)}},eh=async(e,t,r)=>{if(!(t instanceof CryptoKey))throw TypeError(L(t,...F));if(M(t,e,"encrypt","wrapKey"),el(e,t),t.usages.includes("encrypt"))return new Uint8Array(await w.subtle.encrypt(ef(e),t,r));if(t.usages.includes("wrapKey")){let n=await w.subtle.importKey("raw",r,...Q);return new Uint8Array(await w.subtle.wrapKey("raw",n,t,ef(e)))}throw TypeError('RSA-OAEP key "usages" must include "encrypt" or "wrapKey" for this operation')},ed=async(e,t,r)=>{if(!(t instanceof CryptoKey))throw TypeError(L(t,...F));if(M(t,e,"decrypt","unwrapKey"),el(e,t),t.usages.includes("decrypt"))return new Uint8Array(await w.subtle.decrypt(ef(e),t,r));if(t.usages.includes("unwrapKey")){let n=await w.subtle.unwrapKey("raw",r,t,ef(e),...Q);return new Uint8Array(await w.subtle.exportKey("raw",n))}throw TypeError('RSA-OAEP key "usages" must include "decrypt" or "unwrapKey" for this operation')};function ep(e){switch(e){case"A128GCM":return 128;case"A192GCM":return 192;case"A256GCM":case"A128CBC-HS256":return 256;case"A192CBC-HS384":return 384;case"A256CBC-HS512":return 512;default:throw new o(`Unsupported JWE Algorithm: ${e}`)}}let ey=e=>P(new Uint8Array(ep(e)>>3)),eg=(e,t)=>{let r=(e.match(/.{1,64}/g)||[]).join("\n");return`-----BEGIN ${t}----- 2${r} 3-----END ${t}-----`},ew=async(e,t,r)=>{if(!(r instanceof CryptoKey))throw TypeError(L(r,...F));if(!r.extractable)throw TypeError("CryptoKey is not extractable");if(r.type!==e)throw TypeError(`key is not a ${e} key`);return eg(T(new Uint8Array(await w.subtle.exportKey(t,r))),`${e.toUpperCase()} KEY`)},em=(e,t,r=0)=>{0===r&&(t.unshift(t.length),t.unshift(6));let n=e.indexOf(t[0],r);if(-1===n)return!1;let i=e.subarray(n,n+t.length);return i.length===t.length&&(i.every((e,r)=>e===t[r])||em(e,t,n+1))},eb=e=>{switch(!0){case em(e,[42,134,72,206,61,3,1,7]):return"P-256";case em(e,[43,129,4,0,34]):return"P-384";case em(e,[43,129,4,0,35]):return"P-521";case em(e,[43,101,110]):return"X25519";case em(e,[43,101,111]):return"X448";case em(e,[43,101,112]):return"Ed25519";case em(e,[43,101,113]):return"Ed448";default:throw new o("Invalid or unsupported EC Key Curve or OKP Key Sub Type")}},ev=async(e,t,r,n,i)=>{var s;let a,c,u=new Uint8Array(atob(r.replace(e,"")).split("").map(e=>e.charCodeAt(0))),f="spki"===t;switch(n){case"PS256":case"PS384":case"PS512":a={name:"RSA-PSS",hash:`SHA-${n.slice(-3)}`},c=f?["verify"]:["sign"];break;case"RS256":case"RS384":case"RS512":a={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${n.slice(-3)}`},c=f?["verify"]:["sign"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":a={name:"RSA-OAEP",hash:`SHA-${parseInt(n.slice(-3),10)||1}`},c=f?["encrypt","wrapKey"]:["decrypt","unwrapKey"];break;case"ES256":a={name:"ECDSA",namedCurve:"P-256"},c=f?["verify"]:["sign"];break;case"ES384":a={name:"ECDSA",namedCurve:"P-384"},c=f?["verify"]:["sign"];break;case"ES512":a={name:"ECDSA",namedCurve:"P-521"},c=f?["verify"]:["sign"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{let e=eb(u);a=e.startsWith("P-")?{name:"ECDH",namedCurve:e}:{name:e},c=f?[]:["deriveBits"];break}
3case"EdDSA":a={name:eb(u)},c=f?["verify"]:["sign"];break;default:throw new o('Invalid or unsupported "alg" (Algorithm) value')}return w.subtle.importKey(t,u,a,null!=(s=null==i?void 0:i.extractable)&&s,c)};function eE(e){let t=[],r=0;for(;r<e.length;){let n=eS(e.subarray(r));t.push(n),r+=n.byteLength}return t}function eS(e){let t=0,r=31&e[0];if(t++,31===r){for(r=0;e[t]>=128;)r=128*r+e[t]-128,t++;r=128*r+e[t]-128,t++}let n=0;if(e[t]<128)n=e[t],t++;else if(128===n){for(n=0;0!==e[t+n]||0!==e[t+n+1];){if(n>e.byteLength)throw TypeError("invalid indefinite form length");n++}let r=t+n+2;return{byteLength:r,contents:e.subarray(t,t+n),raw:e.subarray(0,r)}}else{let r=127&e[t];t++,n=0;for(let i=0;i<r;i++)n=256*n+e[t],t++}let i=t+n;return{byteLength:i,contents:e.subarray(t,i),raw:e.subarray(0,i)}}let e_=async e=>{var t,r;if(!e.alg)throw TypeError('"alg" argument is required when "jwk.alg" is not present');let{algorithm:n,keyUsages:i}=function(e){let t,r;switch(e.kty){case"oct":switch(e.alg){case"HS256":case"HS384":case"HS512":t={name:"HMAC",hash:`SHA-${e.alg.slice(-3)}`},r=["sign","verify"];break;case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":throw new o(`${e.alg} keys cannot be imported as CryptoKey instances`);case"A128GCM":case"A192GCM":case"A256GCM":case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":t={name:"AES-GCM"},r=["encrypt","decrypt"];break;case"A128KW":case"A192KW":case"A256KW":t={name:"AES-KW"},r=["wrapKey","unwrapKey"];break;case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":t={name:"PBKDF2"},r=["deriveBits"];break;default:throw new o('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break;case"RSA":switch(e.alg){case"PS256":case"PS384":case"PS512":t={name:"RSA-PSS",hash:`SHA-${e.alg.slice(-3)}`},r=e.d?["sign"]:["verify"];break;case"RS256":case"RS384":case"RS512":t={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${e.alg.slice(-3)}`},r=e.d?["sign"]:["verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":t={name:"RSA-OAEP",hash:`SHA-${parseInt(e.alg.slice(-3),10)||1}`},r=e.d?["decrypt","unwrapKey"]:["encrypt","wrapKey"];break;default:throw new o('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break;case"EC":switch(e.alg){case"ES256":t={name:"ECDSA",namedCurve:"P-256"},r=e.d?["sign"]:["verify"];break;case"ES384":t={name:"ECDSA",namedCurve:"P-384"},r=e.d?["sign"]:["verify"];break;case"ES512":t={name:"ECDSA",namedCurve:"P-521"},r=e.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":t={name:"ECDH",namedCurve:e.crv},r=e.d?["deriveBits"]:[];break;default:throw new o('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break;case"OKP":switch(e.alg){case"EdDSA":t={name:e.crv},r=e.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":t={name:e.crv},r=e.d?["deriveBits"]:[];break;default:throw new o('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break;default:throw new o('Invalid or unsupported JWK "kty" (Key Type) Parameter value')}return{algorithm:t,keyUsages:r}}(e),s=[n,null!=(t=e.ext)&&t,null!=(r=e.key_ops)?r:i];if("PBKDF2"===n.name)return w.subtle.importKey("raw",U(e.k),...s);let a={...e};return delete a.alg,delete a.use,w.subtle.importKey("jwk",a,...s)};async function eA(e,t,r){if("string"!=typeof e||0!==e.indexOf("-----BEGIN PUBLIC KEY-----"))throw TypeError('"spki" must be SPKI formatted string');return ev(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g,"spki",e,t,r)}async function ex(e,t,r){let n;if("string"!=typeof e||0!==e.indexOf("-----BEGIN CERTIFICATE-----"))throw TypeError('"x509" must be X.509 formatted string');try{var i;let t;i=e,n=eg((t=eE(eE(eS(k(i.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g,""))).contents)[0].contents),T(t[160===t[0].raw[0]?6:5].raw)),"PUBLIC KEY")}catch(e){throw TypeError("Failed to parse the X.509 certificate",{cause:e})}return ev(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g,"spki",n,t,r)}async function eO(e,t,r){if("string"!=typeof e||0!==e.indexOf("-----BEGIN PRIVATE KEY-----"))throw TypeError('"pkcs8" must be PKCS#8 formatted string');
3return ev(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g,"pkcs8",e,t,r)}async function eT(e,t,r){var n;if(!Z(e))throw TypeError("JWK must be an object");switch(t||(t=e.alg),e.kty){case"oct":if("string"!=typeof e.k||!e.k)throw TypeError('missing "k" (Key Value) Parameter value');if(null!=r||(r=!0!==e.ext),r)return e_({...e,alg:t,ext:null!=(n=e.ext)&&n});return U(e.k);case"RSA":if(void 0!==e.oth)throw new o('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');case"EC":case"OKP":return e_({...e,alg:t});default:throw new o('Unsupported "kty" (Key Type) Parameter value')}}let eN=(e,t,r)=>{if(e.startsWith("HS")||"dir"===e||e.startsWith("PBES2")||/^A\d{3}(?:GCM)?KW$/.test(e)){if(!(t instanceof Uint8Array)){if(!(t instanceof CryptoKey))throw TypeError($(e,t,...F,"Uint8Array"));if("secret"!==t.type)throw TypeError(`${F.join(" or ")} instances for symmetric algorithms must be of type "secret"`)}}else{if(!(t instanceof CryptoKey))throw TypeError($(e,t,...F));if("secret"===t.type)throw TypeError(`${F.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);if("sign"===r&&"public"===t.type)throw TypeError(`${F.join(" or ")} instances for asymmetric algorithm signing must be of type "private"`);if("decrypt"===r&&"public"===t.type)throw TypeError(`${F.join(" or ")} instances for asymmetric algorithm decryption must be of type "private"`);if(t.algorithm&&"verify"===r&&"private"===t.type)throw TypeError(`${F.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);if(t.algorithm&&"encrypt"===r&&"private"===t.type)throw TypeError(`${F.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`)}};async function ek(e,t,r,n,i){if(!(r instanceof Uint8Array))throw TypeError(L(r,"Uint8Array"));let o=parseInt(e.slice(1,4),10),s=await w.subtle.importKey("raw",r.subarray(o>>3),"AES-CBC",!1,["encrypt"]),a=await w.subtle.importKey("raw",r.subarray(0,o>>3),{hash:`SHA-${o<<1}`,name:"HMAC"},!1,["sign"]),c=new Uint8Array(await w.subtle.encrypt({iv:n,name:"AES-CBC"},s,t)),u=E(i,n,c,_(i.length<<3));return{ciphertext:c,tag:new Uint8Array((await w.subtle.sign("HMAC",a,u)).slice(0,o>>3))}}async function eU(e,t,r,n,i){let o;r instanceof Uint8Array?o=await w.subtle.importKey("raw",r,"AES-GCM",!1,["encrypt"]):(M(r,e,"encrypt"),o=r);let s=new Uint8Array(await w.subtle.encrypt({additionalData:i,iv:n,name:"AES-GCM",tagLength:128},o,t)),a=s.slice(-16);return{ciphertext:s.slice(0,-16),tag:a}}let eI=async(e,t,r,n,i)=>{if(!(r instanceof CryptoKey)&&!(r instanceof Uint8Array))throw TypeError(L(r,...F,"Uint8Array"));switch(R(e,n),e){case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return r instanceof Uint8Array&&j(r,parseInt(e.slice(-3),10)),ek(e,t,r,n,i);case"A128GCM":case"A192GCM":case"A256GCM":return r instanceof Uint8Array&&j(r,parseInt(e.slice(1,4),10)),eU(e,t,r,n,i);default:throw new o("Unsupported JWE Content Encryption Algorithm")}};async function eP(e,t,r,n){let i=e.slice(0,7);n||(n=C(i));let{ciphertext:o,tag:s}=await eI(i,r,t,n,new Uint8Array(0));return{encryptedKey:o,iv:N(n),tag:N(s)}}async function eB(e,t,r,n,i){return G(e.slice(0,7),t,r,n,i,new Uint8Array(0))}async function eC(e,t,r,n,i){switch(eN(e,t,"decrypt"),e){case"dir":if(void 0!==r)throw new a("Encountered unexpected JWE Encrypted Key");return t;case"ECDH-ES":if(void 0!==r)throw new a("Encountered unexpected JWE Encrypted Key");case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{let i,s;if(!Z(n.epk))throw new a('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');if(!es(t))throw new o("ECDH with the provided key is not allowed or not supported by your javascript runtime");let c=await eT(n.epk,e);if(void 0!==n.apu){if("string"!=typeof n.apu)throw new a('JOSE Header "apu" (Agreement PartyUInfo) invalid');try{i=U(n.apu)}catch(e){throw new a("Failed to base64url decode the apu")}}if(void 0!==n.apv){if("string"!=typeof n.apv)throw new a('JOSE Header "apv" (Agreement PartyVInfo) invalid');try{s=U(n.apv)}catch(e){throw new a("Failed to base64url decode the apv")}}let u=await ei(c,t,"ECDH-ES"===e?n.enc:e,"ECDH-ES"===e?ep(n.enc):parseInt(e.slice(-5,-2),10),i,s);if("ECDH-ES"===e)return u;if(void 0===r)throw new a("JWE Encrypted Key missing");return en(e.slice(-6),u,r)}case"RSA1_5":case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":if(void 0===r)throw new a("JWE Encrypted Key missing");return ed(e,t,r);case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{let o;if(void 0===r)throw new a("JWE Encrypted Key missing");if("number"!=typeof n.p2c)throw new a('JOSE Header "p2c" (PBES2 Count) missing or invalid');let s=(null==i?void 0:i.maxPBES2Count)||1e4;if(n.p2c>s)throw new a('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if("string"!=typeof n.p2s)throw new a('JOSE Header "p2s" (PBES2 Salt) missing or invalid');try{o=U(n.p2s)}catch(e){throw new a("Failed to base64url decode the p2s")}return eu(e,t,r,n.p2c,o)}
3case"A128KW":case"A192KW":case"A256KW":if(void 0===r)throw new a("JWE Encrypted Key missing");return en(e,t,r);case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":{let i,o;if(void 0===r)throw new a("JWE Encrypted Key missing");if("string"!=typeof n.iv)throw new a('JOSE Header "iv" (Initialization Vector) missing or invalid');if("string"!=typeof n.tag)throw new a('JOSE Header "tag" (Authentication Tag) missing or invalid');try{i=U(n.iv)}catch(e){throw new a("Failed to base64url decode the iv")}try{o=U(n.tag)}catch(e){throw new a("Failed to base64url decode the tag")}return eB(e,t,r,i,o)}default:throw new o('Invalid or unsupported "alg" (JWE Algorithm) header value')}}let eR=function(e,t,r,n,i){let s;if(void 0!==i.crit&&void 0===n.crit)throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');if(!n||void 0===n.crit)return new Set;if(!Array.isArray(n.crit)||0===n.crit.length||n.crit.some(e=>"string"!=typeof e||0===e.length))throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');for(let a of(s=void 0!==r?new Map([...Object.entries(r),...t.entries()]):t,n.crit)){if(!s.has(a))throw new o(`Extension Header Parameter "${a}" is not recognized`);if(void 0===i[a])throw new e(`Extension Header Parameter "${a}" is missing`);if(s.get(a)&&void 0===n[a])throw new e(`Extension Header Parameter "${a}" MUST be integrity protected`)}return new Set(n.crit)},ej=(e,t)=>{if(void 0!==t&&(!Array.isArray(t)||t.some(e=>"string"!=typeof e)))throw TypeError(`"${e}" option must be an array of strings`);if(t)return new Set(t)};async function eH(e,t,r){var n;let s,c,u,f,l,h,d;if(!Z(e))throw new a("Flattened JWE must be an object");if(void 0===e.protected&&void 0===e.header&&void 0===e.unprotected)throw new a("JOSE Header missing");if("string"!=typeof e.iv)throw new a("JWE Initialization Vector missing or incorrect type");if("string"!=typeof e.ciphertext)throw new a("JWE Ciphertext missing or incorrect type");if("string"!=typeof e.tag)throw new a("JWE Authentication Tag missing or incorrect type");if(void 0!==e.protected&&"string"!=typeof e.protected)throw new a("JWE Protected Header incorrect type");if(void 0!==e.encrypted_key&&"string"!=typeof e.encrypted_key)throw new a("JWE Encrypted Key incorrect type");if(void 0!==e.aad&&"string"!=typeof e.aad)throw new a("JWE AAD incorrect type");if(void 0!==e.header&&!Z(e.header))throw new a("JWE Shared Unprotected Header incorrect type");if(void 0!==e.unprotected&&!Z(e.unprotected))throw new a("JWE Per-Recipient Unprotected Header incorrect type");if(e.protected)try{let t=U(e.protected);s=JSON.parse(v.decode(t))}catch(e){throw new a("JWE Protected Header is invalid")}if(!X(s,e.header,e.unprotected))throw new a("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");let p={...s,...e.header,...e.unprotected};if(eR(a,new Map,null==r?void 0:r.crit,s,p),void 0!==p.zip){if(!s||!s.zip)throw new a('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');if("DEF"!==p.zip)throw new o('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value')}let{alg:y,enc:g}=p;if("string"!=typeof y||!y)throw new a("missing JWE Algorithm (alg) in JWE Header");if("string"!=typeof g||!g)throw new a("missing JWE Encryption Algorithm (enc) in JWE Header");let w=r&&ej("keyManagementAlgorithms",r.keyManagementAlgorithms),m=r&&ej("contentEncryptionAlgorithms",r.contentEncryptionAlgorithms);if(w&&!w.has(y))throw new i('"alg" (Algorithm) Header Parameter not allowed');if(m&&!m.has(g))throw new i('"enc" (Encryption Algorithm) Header Parameter not allowed');if(void 0!==e.encrypted_key)try{c=U(e.encrypted_key)}catch(e){throw new a("Failed to base64url decode the encrypted_key")}let S=!1;"function"==typeof t&&(t=await t(s,e),S=!0);try{u=await eC(y,t,c,p,r)}catch(e){if(e instanceof TypeError||e instanceof a||e instanceof o)throw e;u=ey(g)}try{f=U(e.iv)}catch(e){throw new a("Failed to base64url decode the iv")}try{l=U(e.tag)}catch(e){throw new a("Failed to base64url decode the tag")}let _=b.encode(null!=(n=e.protected)?n:"");h=void 0!==e.aad?E(_,b.encode("."),b.encode(e.aad)):_;try{d=U(e.ciphertext)}catch(e){throw new a("Failed to base64url decode the ciphertext")}let A=await G(g,u,d,f,l,h);"DEF"===p.zip&&(A=await ((null==r?void 0:r.inflateRaw)||Y)(A));let x={plaintext:A};if(void 0!==e.protected&&(x.protectedHeader=s),void 0!==e.aad)try{x.additionalAuthenticatedData=U(e.aad)}catch(e){throw new a("Failed to base64url decode the aad")}return(void 0!==e.unprotected&&(x.sharedUnprotectedHeader=e.unprotected),void 0!==e.header&&(x.unprotectedHeader=e.header),S)?{...x,key:t}:x}async function eD(e,t,r){if(e instanceof Uint8Array&&(e=v.decode(e)),"string"!=typeof e)throw new a("Compact JWE must be a string or Uint8Array");let{0:n,1:i,2:o,3:s,4:c,length:u}=e.split(".");if(5!==u)throw new a("Invalid Compact JWE");let f=await eH({ciphertext:s,iv:o||void 0,protected:n||void 0,tag:c||void 0,encrypted_key:i||void 0},t,r),l={plaintext:f.plaintext,protectedHeader:f.protectedHeader};return"function"==typeof t?{...l,key:f.key}:l}async function eW(e,t,r){if(!Z(e))throw new a("General JWE must be an object");
3if(!Array.isArray(e.recipients)||!e.recipients.every(Z))throw new a("JWE Recipients missing or incorrect type");if(!e.recipients.length)throw new a("JWE Recipients has no members");for(let n of e.recipients)try{return await eH({aad:e.aad,ciphertext:e.ciphertext,encrypted_key:n.encrypted_key,header:n.header,iv:e.iv,protected:e.protected,tag:e.tag,unprotected:e.unprotected},t,r)}catch(e){}throw new s}let eK=async e=>{if(e instanceof Uint8Array)return{kty:"oct",k:N(e)};if(!(e instanceof CryptoKey))throw TypeError(L(e,...F,"Uint8Array"));if(!e.extractable)throw TypeError("non-extractable CryptoKey cannot be exported as a JWK");let{ext:t,key_ops:r,alg:n,use:i,...o}=await w.subtle.exportKey("jwk",e);return o};async function eM(e){return ew("public","spki",e)}async function eJ(e){return ew("private","pkcs8",e)}async function eL(e){return eK(e)}async function e$(e,t,r,n,i={}){let s,a,c;switch(eN(e,r,"encrypt"),e){case"dir":c=r;break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{if(!es(r))throw new o("ECDH with the provided key is not allowed or not supported by your javascript runtime");let{apu:u,apv:f}=i,{epk:l}=i;l||(l=(await eo(r)).privateKey);let{x:h,y:d,crv:p,kty:y}=await eL(l),g=await ei(r,l,"ECDH-ES"===e?t:e,"ECDH-ES"===e?ep(t):parseInt(e.slice(-5,-2),10),u,f);if(a={epk:{x:h,crv:p,kty:y}},"EC"===y&&(a.epk.y=d),u&&(a.apu=N(u)),f&&(a.apv=N(f)),"ECDH-ES"===e){c=g;break}c=n||ey(t);let w=e.slice(-6);s=await er(w,g,c);break}case"RSA1_5":case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":c=n||ey(t),s=await eh(e,r,c);break;case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{c=n||ey(t);let{p2c:o,p2s:u}=i;({encryptedKey:s,...a}=await ec(e,r,c,o,u));break}case"A128KW":case"A192KW":case"A256KW":c=n||ey(t),s=await er(e,r,c);break;case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":{c=n||ey(t);let{iv:o}=i;({encryptedKey:s,...a}=await eP(e,r,c,o));break}default:throw new o('Invalid or unsupported "alg" (JWE Algorithm) header value')}return{cek:c,encryptedKey:s,parameters:a}}let eF=Symbol();class eV{constructor(e){if(!(e instanceof Uint8Array))throw TypeError("plaintext must be an instance of Uint8Array");this._plaintext=e}setKeyManagementParameters(e){if(this._keyManagementParameters)throw TypeError("setKeyManagementParameters can only be called once");return this._keyManagementParameters=e,this}setProtectedHeader(e){if(this._protectedHeader)throw TypeError("setProtectedHeader can only be called once");return this._protectedHeader=e,this}setSharedUnprotectedHeader(e){if(this._sharedUnprotectedHeader)throw TypeError("setSharedUnprotectedHeader can only be called once");return this._sharedUnprotectedHeader=e,this}setUnprotectedHeader(e){if(this._unprotectedHeader)throw TypeError("setUnprotectedHeader can only be called once");return this._unprotectedHeader=e,this}setAdditionalAuthenticatedData(e){return this._aad=e,this}setContentEncryptionKey(e){if(this._cek)throw TypeError("setContentEncryptionKey can only be called once");return this._cek=e,this}setInitializationVector(e){if(this._iv)throw TypeError("setInitializationVector can only be called once");return this._iv=e,this}async encrypt(e,t){let r,n,i,s,c,u,f;if(!this._protectedHeader&&!this._unprotectedHeader&&!this._sharedUnprotectedHeader)throw new a("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(!X(this._protectedHeader,this._unprotectedHeader,this._sharedUnprotectedHeader))throw new a("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let l={...this._protectedHeader,...this._unprotectedHeader,...this._sharedUnprotectedHeader};if(eR(a,new Map,null==t?void 0:t.crit,this._protectedHeader,l),void 0!==l.zip){if(!this._protectedHeader||!this._protectedHeader.zip)throw new a('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');if("DEF"!==l.zip)throw new o('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value')}let{alg:h,enc:d}=l;if("string"!=typeof h||!h)throw new a('JWE "alg" (Algorithm) Header Parameter missing or invalid');if("string"!=typeof d||!d)throw new a('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');if("dir"===h){if(this._cek)throw TypeError("setContentEncryptionKey cannot be called when using Direct Encryption")}else if("ECDH-ES"===h&&this._cek)throw TypeError("setContentEncryptionKey cannot be called when using Direct Key Agreement");{let i;({cek:n,encryptedKey:r,parameters:i}=await e$(h,d,e,this._cek,this._keyManagementParameters)),i&&(t&&eF in t?this._unprotectedHeader?this._unprotectedHeader={...this._unprotectedHeader,...i}:this.setUnprotectedHeader(i):this._protectedHeader?this._protectedHeader={...this._protectedHeader,...i}:this.setProtectedHeader(i))}if(this._iv||(this._iv=C(d)),s=this._protectedHeader?b.encode(N(JSON.stringify(this._protectedHeader))):b.encode(""),this._aad?(c=N(this._aad),i=E(s,b.encode("."),b.encode(c))):i=s,"DEF"===l.zip){let e=await ((null==t?void 0:t.deflateRaw)||q)(this._plaintext);({ciphertext:u,tag:f}
3=await eI(d,e,n,this._iv,i))}else({ciphertext:u,tag:f}=await eI(d,this._plaintext,n,this._iv,i));let p={ciphertext:N(u),iv:N(this._iv),tag:N(f)};return r&&(p.encrypted_key=N(r)),c&&(p.aad=c),this._protectedHeader&&(p.protected=v.decode(s)),this._sharedUnprotectedHeader&&(p.unprotected=this._sharedUnprotectedHeader),this._unprotectedHeader&&(p.header=this._unprotectedHeader),p}}class ez{constructor(e,t,r){this.parent=e,this.key=t,this.options=r}setUnprotectedHeader(e){if(this.unprotectedHeader)throw TypeError("setUnprotectedHeader can only be called once");return this.unprotectedHeader=e,this}addRecipient(...e){return this.parent.addRecipient(...e)}encrypt(...e){return this.parent.encrypt(...e)}done(){return this.parent}}function eG(e,t){let r=`SHA-${e.slice(-3)}`;switch(e){case"HS256":case"HS384":case"HS512":return{hash:r,name:"HMAC"};case"PS256":case"PS384":case"PS512":return{hash:r,name:"RSA-PSS",saltLength:e.slice(-3)>>3};case"RS256":case"RS384":case"RS512":return{hash:r,name:"RSASSA-PKCS1-v1_5"};case"ES256":case"ES384":case"ES512":return{hash:r,name:"ECDSA",namedCurve:t.namedCurve};case"EdDSA":return{name:t.name};default:throw new o(`alg ${e} is not supported either by JOSE or your javascript runtime`)}}function eY(e,t,r){if(t instanceof CryptoKey)return!function(e,t,...r){switch(t){case"HS256":case"HS384":case"HS512":{if(!D(e.algorithm,"HMAC"))throw H("HMAC");let r=parseInt(t.slice(2),10);if(W(e.algorithm.hash)!==r)throw H(`SHA-${r}`,"algorithm.hash");break}case"RS256":case"RS384":case"RS512":{if(!D(e.algorithm,"RSASSA-PKCS1-v1_5"))throw H("RSASSA-PKCS1-v1_5");let r=parseInt(t.slice(2),10);if(W(e.algorithm.hash)!==r)throw H(`SHA-${r}`,"algorithm.hash");break}
3case"PS256":case"PS384":case"PS512":{if(!D(e.algorithm,"RSA-PSS"))throw H("RSA-PSS");let r=parseInt(t.slice(2),10);if(W(e.algorithm.hash)!==r)throw H(`SHA-${r}`,"algorithm.hash");break}case"EdDSA":if("Ed25519"!==e.algorithm.name&&"Ed448"!==e.algorithm.name)throw H("Ed25519 or Ed448");break;case"ES256":case"ES384":case"ES512":{if(!D(e.algorithm,"ECDSA"))throw H("ECDSA");let r=function(e){switch(e){case"ES256":return"P-256";case"ES384":return"P-384";case"ES512":return"P-521";default:throw Error("unreachable")}}(t);if(e.algorithm.namedCurve!==r)throw H(r,"algorithm.namedCurve");break}default:throw TypeError("CryptoKey does not support this operation")}K(e,r)}(t,e,r),t;if(t instanceof Uint8Array){if(!e.startsWith("HS"))throw TypeError(L(t,...F));return w.subtle.importKey("raw",t,{hash:`SHA-${e.slice(-3)}`,name:"HMAC"},!1,[r])}throw TypeError(L(t,...F,"Uint8Array"))}let eq=async(e,t,r,n)=>{let i=await eY(e,t,"verify");el(e,i);let o=eG(e,i.algorithm);try{return await w.subtle.verify(o,i,r,n)}catch(e){return!1}};async function eX(e,t,r){var n;let o,s;if(!Z(e))throw new c("Flattened JWS must be an object");if(void 0===e.protected&&void 0===e.header)throw new c('Flattened JWS must have either of the "protected" or "header" members');if(void 0!==e.protected&&"string"!=typeof e.protected)throw new c("JWS Protected Header incorrect type");if(void 0===e.payload)throw new c("JWS Payload missing");if("string"!=typeof e.signature)throw new c("JWS Signature missing or incorrect type");if(void 0!==e.header&&!Z(e.header))throw new c("JWS Unprotected Header incorrect type");let a={};if(e.protected)try{let t=U(e.protected);a=JSON.parse(v.decode(t))}catch(e){throw new c("JWS Protected Header is invalid")}if(!X(a,e.header))throw new c("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let u={...a,...e.header},f=eR(c,new Map([["b64",!0]]),null==r?void 0:r.crit,a,u),l=!0;if(f.has("b64")&&"boolean"!=typeof(l=a.b64))throw new c('The "b64" (base64url-encode payload) Header Parameter must be a boolean');let{alg:h}=u;if("string"!=typeof h||!h)throw new c('JWS "alg" (Algorithm) Header Parameter missing or invalid');let d=r&&ej("algorithms",r.algorithms);if(d&&!d.has(h))throw new i('"alg" (Algorithm) Header Parameter not allowed');if(l){if("string"!=typeof e.payload)throw new c("JWS Payload must be a string")}else if("string"!=typeof e.payload&&!(e.payload instanceof Uint8Array))throw new c("JWS Payload must be a string or an Uint8Array instance");let p=!1;"function"==typeof t&&(t=await t(a,e),p=!0),eN(h,t,"verify");let g=E(b.encode(null!=(n=e.protected)?n:""),b.encode("."),"string"==typeof e.payload?b.encode(e.payload):e.payload);try{o=U(e.signature)}catch(e){throw new c("Failed to base64url decode the signature")}if(!await eq(h,t,o,g))throw new y;if(l)try{s=U(e.payload)}catch(e){throw new c("Failed to base64url decode the payload")}else s="string"==typeof e.payload?b.encode(e.payload):e.payload;let w={payload:s};return(void 0!==e.protected&&(w.protectedHeader=a),void 0!==e.header&&(w.unprotectedHeader=e.header),p)?{...w,key:t}:w}async function eZ(e,t,r){if(e instanceof Uint8Array&&(e=v.decode(e)),"string"!=typeof e)throw new c("Compact JWS must be a string or Uint8Array");let{0:n,1:i,2:o,length:s}=e.split(".");if(3!==s)throw new c("Invalid Compact JWS");let a=await eX({payload:i,protected:n,signature:o},t,r),u={payload:a.payload,protectedHeader:a.protectedHeader};return"function"==typeof t?{...u,key:a.key}:u}async function eQ(e,t,r){if(!Z(e))throw new c("General JWS must be an object");if(!Array.isArray(e.signatures)||!e.signatures.every(Z))throw new c("JWS Signatures missing or incorrect type");for(let n of e.signatures)try{return await eX({header:n.header,payload:e.payload,protected:n.protected,signature:n.signature},t,r)}catch(e){}throw new y}let e0=e=>Math.floor(e.getTime()/1e3),e1=/^(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)$/i,e2=e=>{let t=e1.exec(e);if(!t)throw TypeError("Invalid time period format");let r=parseFloat(t[1]);switch(t[2].toLowerCase()){case"sec":case"secs":case"second":case"seconds":case"s":return Math.round(r);case"minute":case"minutes":case"min":case"mins":case"m":return Math.round(60*r);case"hour":case"hours":case"hr":case"hrs":case"h":return Math.round(3600*r);case"day":case"days":case"d":return Math.round(86400*r);case"week":case"weeks":case"w":return Math.round(604800*r);default:return Math.round(0x1e187e0*r)}},e5=e=>e.toLowerCase().replace(/^application\//,""),e6=(e,t,i={})=>{var o,s;let a,c,{typ:f}=i;if(f&&("string"!=typeof e.typ||e5(e.typ)!==e5(f)))throw new r('unexpected "typ" JWT header value',"typ","check_failed");try{a=JSON.parse(v.decode(t))}catch(e){}if(!Z(a))throw new u("JWT Claims Set must be a top-level JSON object");let{requiredClaims:l=[],issuer:h,subject:d,audience:p,maxTokenAge:y}=i;for(let e of(void 0!==y&&l.push("iat"),void 0!==p&&l.push("aud"),void 0!==d&&l.push("sub"),void 0!==h&&l.push("iss"),new Set(l.reverse())))if(!(e in a))throw new r(`missing required "${e}" claim`,e,"missing");if(h&&!(Array.isArray(h)?h:[h]).includes(a.iss))throw new r('unexpected "iss" claim value',"iss","check_failed");if(d&&a.sub!==d)throw new r('unexpected "sub" claim value',"sub","check_failed");if(p&&(o=a.aud,s="string"==typeof p?[p]:p,"string"==typeof o?!s.includes(o):!(Array.isArray(o)&&s.some(Set.prototype.has.bind(new Set(o))))))throw new r('unexpected "aud" claim value',"aud","check_failed");switch(typeof i.clockTolerance){case"string":c=e2(i.clockTolerance);break;case"number":c=i.clockTolerance;break;case"undefined":c=0;break;default:throw TypeError("Invalid clockTolerance option type")}let{currentDate:g}=i,w=e0(g||new Date);if((void 0!==a.iat||y)&&"number"!=typeof a.iat)throw new r('"iat" claim must be a number',"iat","invali
3d");if(void 0!==a.nbf){if("number"!=typeof a.nbf)throw new r('"nbf" claim must be a number',"nbf","invalid");if(a.nbf>w+c)throw new r('"nbf" claim timestamp check failed',"nbf","check_failed")}if(void 0!==a.exp){if("number"!=typeof a.exp)throw new r('"exp" claim must be a number',"exp","invalid");if(a.exp<=w-c)throw new n('"exp" claim timestamp check failed',"exp","check_failed")}if(y){let e=w-a.iat;if(e-c>("number"==typeof y?y:e2(y)))throw new n('"iat" claim timestamp check failed (too far in the past)',"iat","check_failed");if(e<0-c)throw new r('"iat" claim timestamp check failed (it should be in the past)',"iat","check_failed")}return a};async function e8(e,t,r){var n;let i=await eZ(e,t,r);if((null==(n=i.protectedHeader.crit)?void 0:n.includes("b64"))&&!1===i.protectedHeader.b64)throw new u("JWTs MUST NOT use unencoded payload");let o={payload:e6(i.protectedHeader,i.payload,r),protectedHeader:i.protectedHeader};return"function"==typeof t?{...o,key:i.key}:o}async function e3(e,t,n){let i=await eD(e,t,n),o=e6(i.protectedHeader,i.plaintext,n),{protectedHeader:s}=i;if(void 0!==s.iss&&s.iss!==o.iss)throw new r('replicated "iss" claim header parameter mismatch',"iss","mismatch");if(void 0!==s.sub&&s.sub!==o.sub)throw new r('replicated "sub" claim header parameter mismatch',"sub","mismatch");if(void 0!==s.aud&&JSON.stringify(s.aud)!==JSON.stringify(o.aud))throw new r('replicated "aud" claim header parameter mismatch',"aud","mismatch");let a={payload:o,protectedHeader:s};return"function"==typeof t?{...a,key:i.key}:a}class e4{constructor(e){this._flattened=new eV(e)}setContentEncryptionKey(e){return this._flattened.setContentEncryptionKey(e),this}setInitializationVector(e){return this._flattened.setInitializationVector(e),this}setProtectedHeader(e){return this._flattened.setProtectedHeader(e),this}setKeyManagementParameters(e){return this._flattened.setKeyManagementParameters(e),this}async encrypt(e,t){let r=await this._flattened.encrypt(e,t);return[r.protected,r.encrypted_key,r.iv,r.ciphertext,r.tag].join(".")}}let e9=async(e,t,r)=>{let n=await eY(e,t,"sign");return el(e,n),new Uint8Array(await w.subtle.sign(eG(e,n.algorithm),n,r))};class e7{constructor(e){if(!(e instanceof Uint8Array))throw TypeError("payload must be an instance of Uint8Array");this._payload=e}setProtectedHeader(e){if(this._protectedHeader)throw TypeError("setProtectedHeader can only be called once");return this._protectedHeader=e,this}setUnprotectedHeader(e){if(this._unprotectedHeader)throw TypeError("setUnprotectedHeader can only be called once");return this._unprotectedHeader=e,this}async sign(e,t){let r;if(!this._protectedHeader&&!this._unprotectedHeader)throw new c("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!X(this._protectedHeader,this._unprotectedHeader))throw new c("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let n={...this._protectedHeader,...this._unprotectedHeader},i=eR(c,new Map([["b64",!0]]),null==t?void 0:t.crit,this._protectedHeader,n),o=!0;if(i.has("b64")&&"boolean"!=typeof(o=this._protectedHeader.b64))throw new c('The "b64" (base64url-encode payload) Header Parameter must be a boolean');let{alg:s}=n;if("string"!=typeof s||!s)throw new c('JWS "alg" (Algorithm) Header Parameter missing or invalid');eN(s,e,"sign");let a=this._payload;o&&(a=b.encode(N(a)));let u=E(r=this._protectedHeader?b.encode(N(JSON.stringify(this._protectedHeader))):b.encode(""),b.encode("."),a),f={signature:N(await e9(s,e,u)),payload:""};return o&&(f.payload=v.decode(a)),this._unprotectedHeader&&(f.header=this._unprotectedHeader),this._protectedHeader&&(f.protected=v.decode(r)),f}}class te{constructor(e){this._flattened=new e7(e)}setProtectedHeader(e){return this._flattened.setProtectedHeader(e),this}async sign(e,t){let r=await this._flattened.sign(e,t);if(void 0===r.payload)throw TypeError("use the flattened module for creating JWS with b64: false");return`${r.protected}.${r.payload}.${r.signature}`}}class tt{constructor(e,t,r){this.parent=e,this.key=t,this.options=r}setProtectedHeader(e){if(this.protectedHeader)throw TypeError("setProtectedHeader can only be called once");return this.protectedHeader=e,this}setUnprotectedHeader(e){if(this.unprotectedHeader)throw TypeError("setUnprotectedHeader can only be called once");return this.unprotectedHeader=e,this}addSignature(...e){return this.parent.addSignature(...e)}sign(...e){return this.parent.sign(...e)}done(){return this.parent}}class tr{constructor(e){if(!Z(e))throw TypeError("JWT Claims Set MUST be an object");this._payload=e}setIssuer(e){return this._payload={...this._payload,iss:e},this}setSubject(e){return this._payload={...this._payload,sub:e},this}setAudience(e){return this._payload={...this._payload,aud:e},this}setJti(e){return this._payload={...this._payload,jti:e},this}setNotBefore(e){return"number"==typeof e?this._payload={...this._payload,nbf:e}:this._payload={...this._payload,nbf:e0(new Date)+e2(e)},this}setExpirationTime(e){return"number"==typeof e?this._payload={...this._payload,exp:e}:this._payload={...this._payload,exp:e0(new Date)+e2(e)},this}setIssuedAt(e){return void 0===e?this._payload={...this._payload,iat:e0(new Date)}:this._payload={...this._payload,iat:e},this}}let tn=(e,t)=>{if("string"!=typeof e||!e)throw new f(`${t} missing or invalid`)};async function ti(e,t){let r;if(!Z(e))throw TypeError("JWK must be an object");
3if(null!=t||(t="sha256"),"sha256"!==t&&"sha384"!==t&&"sha512"!==t)throw TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');switch(e.kty){case"EC":tn(e.crv,'"crv" (Curve) Parameter'),tn(e.x,'"x" (X Coordinate) Parameter'),tn(e.y,'"y" (Y Coordinate) Parameter'),r={crv:e.crv,kty:e.kty,x:e.x,y:e.y};break;case"OKP":tn(e.crv,'"crv" (Subtype of Key Pair) Parameter'),tn(e.x,'"x" (Public Key) Parameter'),r={crv:e.crv,kty:e.kty,x:e.x};break;case"RSA":tn(e.e,'"e" (Exponent) Parameter'),tn(e.n,'"n" (Modulus) Parameter'),r={e:e.e,kty:e.kty,n:e.n};break;case"oct":tn(e.k,'"k" (Key Value) Parameter'),r={k:e.k,kty:e.kty};break;default:throw new o('"kty" (Key Type) Parameter missing or unsupported')}let n=b.encode(JSON.stringify(r));return N(await m(t,n))}async function to(e,t){null!=t||(t="sha256");let r=await ti(e,t);return`urn:ietf:params:oauth:jwk-thumbprint:sha-${t.slice(-3)}:${r}`}async function ts(e,t){let r={...e,...null==t?void 0:t.header};if(!Z(r.jwk))throw new c('"jwk" (JSON Web Key) Header Parameter must be a JSON object');let n=await eT({...r.jwk,ext:!0},r.alg,!0);if(n instanceof Uint8Array||"public"!==n.type)throw new c('"jwk" (JSON Web Key) Header Parameter must be a public key');return n}function ta(e){return e&&"object"==typeof e&&Array.isArray(e.keys)&&e.keys.every(tc)}function tc(e){return Z(e)}class tu{constructor(e){if(this._cached=new WeakMap,!ta(e))throw new l("JSON Web Key Set malformed");this._jwks=function(e){return"function"==typeof structuredClone?structuredClone(e):JSON.parse(JSON.stringify(e))}(e)}async getKey(e,t){let{alg:r,kid:n}={...e,...null==t?void 0:t.header},i=function(e){switch("string"==typeof e&&e.slice(0,2)){case"RS":case"PS":return"RSA";case"ES":return"EC";case"Ed":return"OKP";default:throw new o('Unsupported "alg" value for a JSON Web Key Set')}}(r),s=this._jwks.keys.filter(e=>{let t=i===e.kty;if(t&&"string"==typeof n&&(t=n===e.kid),t&&"string"==typeof e.alg&&(t=r===e.alg),t&&"string"==typeof e.use&&(t="sig"===e.use),t&&Array.isArray(e.key_ops)&&(t=e.key_ops.includes("verify")),t&&"EdDSA"===r&&(t="Ed25519"===e.crv||"Ed448"===e.crv),t)switch(r){case"ES256":t="P-256"===e.crv;break;case"ES256K":t="secp256k1"===e.crv;break;case"ES384":t="P-384"===e.crv;break;case"ES512":t="P-521"===e.crv}return t}),{0:a,length:c}=s;if(0===c)throw new h;if(1!==c){let e=new d,{_cached:t}=this;throw e[Symbol.asyncIterator]=async function*(){for(let e of s)try{yield await tf(t,e,r)}catch(e){continue}},e}return tf(this._cached,a,r)}}async function tf(e,t,r){let n=e.get(t)||e.set(t,{}).get(t);if(void 0===n[r]){let e=await eT({...t,ext:!0},r);if(e instanceof Uint8Array||"public"!==e.type)throw new l("JSON Web Key Set members must be public keys");n[r]=e}return n[r]}let tl=async(e,r,n)=>{let i,o,s=!1;"function"==typeof AbortController&&(i=new AbortController,o=setTimeout(()=>{s=!0,i.abort()},r));let a=await fetch(e.href,{signal:i?i.signal:void 0,redirect:"manual",headers:n.headers}).catch(e=>{if(s)throw new p;throw e});if(void 0!==o&&clearTimeout(o),200!==a.status)throw new t("Expected 200 OK from the JSON Web Key Set HTTP response");try{return await a.json()}catch(e){throw new t("Failed to parse the JSON Web Key Set HTTP response as JSON")}};class th extends tu{constructor(e,t){if(super({keys:[]}),this._jwks=void 0,!(e instanceof URL))throw TypeError("url must be an instance of URL");this._url=new URL(e.href),this._options={agent:null==t?void 0:t.agent,headers:null==t?void 0:t.headers},this._timeoutDuration="number"==typeof(null==t?void 0:t.timeoutDuration)?null==t?void 0:t.timeoutDuration:5e3,this._cooldownDuration="number"==typeof(null==t?void 0:t.cooldownDuration)?null==t?void 0:t.cooldownDuration:3e4,this._cacheMaxAge="number"==typeof(null==t?void 0:t.cacheMaxAge)?null==t?void 0:t.cacheMaxAge:6e5}coolingDown(){return"number"==typeof this._jwksTimestamp&&Date.now()<this._jwksTimestamp+this._cooldownDuration}fresh(){return"number"==typeof this._jwksTimestamp&&Date.now()<this._jwksTimestamp+this._cacheMaxAge}async getKey(e,t){this._jwks&&this.fresh()||await this.reload();try{return await super.getKey(e,t)}catch(r){if(r instanceof h&&!1===this.coolingDown())return await this.reload(),super.getKey(e,t);throw r}}async reload(){this._pendingFetch&&("u">typeof WebSocketPair||"u">typeof navigator&&"Cloudflare-Workers"===navigator.userAgent||"u">
3typeof EdgeRuntime&&"vercel"===EdgeRuntime)&&(this._pendingFetch=void 0),this._pendingFetch||(this._pendingFetch=tl(this._url,this._timeoutDuration,this._options).then(e=>{if(!ta(e))throw new l("JSON Web Key Set malformed");this._jwks={keys:e.keys},this._jwksTimestamp=Date.now(),this._pendingFetch=void 0}).catch(e=>{throw this._pendingFetch=void 0,e})),await this._pendingFetch}}async function td(e,t){var r;let n,i,s;switch(e){case"HS256":case"HS384":case"HS512":n=parseInt(e.slice(-3),10),i={name:"HMAC",hash:`SHA-${n}`,length:n},s=["sign","verify"];break;case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return P(new Uint8Array((n=parseInt(e.slice(-3),10))>>3));case"A128KW":case"A192KW":case"A256KW":i={name:"AES-KW",length:n=parseInt(e.slice(1,4),10)},s=["wrapKey","unwrapKey"];break;case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":case"A128GCM":case"A192GCM":case"A256GCM":i={name:"AES-GCM",length:n=parseInt(e.slice(1,4),10)},s=["encrypt","decrypt"];break;default:throw new o('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}return w.subtle.generateKey(i,null!=(r=null==t?void 0:t.extractable)&&r,s)}function tp(e){var t;let r=null!=(t=null==e?void 0:e.modulusLength)?t:2048;if("number"!=typeof r||r<2048)throw new o("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");return r}async function ty(e,t){var r,n,i;let s,a;switch(e){case"PS256":case"PS384":case"PS512":s={name:"RSA-PSS",hash:`SHA-${e.slice(-3)}`,publicExponent:new Uint8Array([1,0,1]),modulusLength:tp(t)},a=["sign","verify"];break;case"RS256":case"RS384":case"RS512":s={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${e.slice(-3)}`,publicExponent:new Uint8Array([1,0,1]),modulusLength:tp(t)},a=["sign","verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":s={name:"RSA-OAEP",hash:`SHA-${parseInt(e.slice(-3),10)||1}`,publicExponent:new Uint8Array([1,0,1]),modulusLength:tp(t)},a=["decrypt","unwrapKey","encrypt","wrapKey"];break;case"ES256":s={name:"ECDSA",namedCurve:"P-256"},a=["sign","verify"];break;case"ES384":s={name:"ECDSA",namedCurve:"P-384"},a=["sign","verify"];break;case"ES512":s={name:"ECDSA",namedCurve:"P-521"},a=["sign","verify"];break;case"EdDSA":a=["sign","verify"];let c=null!=(r=null==t?void 0:t.crv)?r:"Ed25519";
3switch(c){case"Ed25519":case"Ed448":s={name:c};break;default:throw new o("Invalid or unsupported crv option provided")}break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{a=["deriveKey","deriveBits"];let e=null!=(n=null==t?void 0:t.crv)?n:"P-256";switch(e){case"P-256":case"P-384":case"P-521":s={name:"ECDH",namedCurve:e};break;case"X25519":case"X448":s={name:e};break;default:throw new o("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, X25519, and X448")}break}default:throw new o('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}return w.subtle.generateKey(s,null!=(i=null==t?void 0:t.extractable)&&i,a)}async function tg(e,t){return ty(e,t)}async function tw(e,t){return td(e,t)}e.s(["CompactEncrypt",0,e4,"CompactSign",0,te,"EmbeddedJWK",0,ts,"EncryptJWT",0,class extends tr{setProtectedHeader(e){if(this._protectedHeader)throw TypeError("setProtectedHeader can only be called once");return this._protectedHeader=e,this}setKeyManagementParameters(e){if(this._keyManagementParameters)throw TypeError("setKeyManagementParameters can only be called once");return this._keyManagementParameters=e,this}setContentEncryptionKey(e){if(this._cek)throw TypeError("setContentEncryptionKey can only be called once");return this._cek=e,this}setInitializationVector(e){if(this._iv)throw TypeError("setInitializationVector can only be called once");return this._iv=e,this}replicateIssuerAsHeader(){return this._replicateIssuerAsHeader=!0,this}replicateSubjectAsHeader(){return this._replicateSubjectAsHeader=!0,this}replicateAudienceAsHeader(){return this._replicateAudienceAsHeader=!0,this}async encrypt(e,t){let r=new e4(b.encode(JSON.stringify(this._payload)));return this._replicateIssuerAsHeader&&(this._protectedHeader={...this._protectedHeader,iss:this._payload.iss}),this._replicateSubjectAsHeader&&(this._protectedHeader={...this._protectedHeader,sub:this._payload.sub}),this._replicateAudienceAsHeader&&(this._protectedHeader={...this._protectedHeader,aud:this._payload.aud}),r.setProtectedHeader(this._protectedHeader),this._iv&&r.setInitializationVector(this._iv),this._cek&&r.setContentEncryptionKey(this._cek),this._keyManagementParameters&&r.setKeyManagementParameters(this._keyManagementParameters),r.encrypt(e,t)}},"FlattenedEncrypt",0,eV,"FlattenedSign",0,e7,"GeneralEncrypt",0,class{constructor(e){this._recipients=[],this._plaintext=e}addRecipient(e,t){let r=new ez(this,e,{crit:null==t?void 0:t.crit});return this._recipients.push(r),r}setProtectedHeader(e){if(this._protectedHeader)throw TypeError("setProtectedHeader can only be called once");return this._protectedHeader=e,this}setSharedUnprotectedHeader(e){if(this._unprotectedHeader)throw TypeError("setSharedUnprotectedHeader can only be called once");return this._unprotectedHeader=e,this}setAdditionalAuthenticatedData(e){return this._aad=e,this}async encrypt(e){var t,r,n;let i;if(!this._recipients.length)throw new a("at least one recipient must be added");if(e={deflateRaw:null==e?void 0:e.deflateRaw},1===this._recipients.length){let[t]=this._recipients,r=await new eV(this._plaintext).setAdditionalAuthenticatedData(this._aad).setProtectedHeader(this._protectedHeader).setSharedUnprotectedHeader(this._unprotectedHeader).setUnprotectedHeader(t.unprotectedHeader).encrypt(t.key,{...t.options,...e}),n={ciphertext:r.ciphertext,iv:r.iv,recipients:[{}],tag:r.tag};return r.aad&&(n.aad=r.aad),r.protected&&(n.protected=r.protected),r.unprotected&&(n.unprotected=r.unprotected),r.encrypted_key&&(n.recipients[0].encrypted_key=r.encrypted_key),r.header&&(n.recipients[0].header=r.header),n}for(let e=0;e<this._recipients.length;e++){let t=this._recipients[e];if(!X(this._protectedHeader,this._unprotectedHeader,t.unprotectedHeader))throw new a("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let r={...this._protectedHeader,...this._unprotectedHeader,...t.unprotectedHeader},{alg:n}=r;if("string"!=typeof n||!n)throw new a('JWE "alg" (Algorithm) Header Parameter missing or invalid');if("dir"===n||"ECDH-ES"===n)throw new a('"dir" and "ECDH-ES" alg may only be used with a single recipient');if("string"!=typeof r.enc||!r.enc)throw new a('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');if(i){if(i!==r.enc)throw new a('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients')}else i=r.enc;
3if(eR(a,new Map,t.options.crit,this._protectedHeader,r),void 0!==r.zip&&(!this._protectedHeader||!this._protectedHeader.zip))throw new a('JWE "zip" (Compression Algorithm) Header MUST be integrity protected')}let o=ey(i),s={ciphertext:"",iv:"",recipients:[],tag:""};for(let a=0;a<this._recipients.length;a++){let c=this._recipients[a],u={};s.recipients.push(u);let f=({...this._protectedHeader,...this._unprotectedHeader,...c.unprotectedHeader}).alg.startsWith("PBES2")?2048+a:void 0;if(0===a){let t=await new eV(this._plaintext).setAdditionalAuthenticatedData(this._aad).setContentEncryptionKey(o).setProtectedHeader(this._protectedHeader).setSharedUnprotectedHeader(this._unprotectedHeader).setUnprotectedHeader(c.unprotectedHeader).setKeyManagementParameters({p2c:f}).encrypt(c.key,{...c.options,...e,[eF]:!0});s.ciphertext=t.ciphertext,s.iv=t.iv,s.tag=t.tag,t.aad&&(s.aad=t.aad),t.protected&&(s.protected=t.protected),t.unprotected&&(s.unprotected=t.unprotected),u.encrypted_key=t.encrypted_key,t.header&&(u.header=t.header);continue}let{encryptedKey:l,parameters:h}=await e$((null==(t=c.unprotectedHeader)?void 0:t.alg)||(null==(r=this._protectedHeader)?void 0:r.alg)||(null==(n=this._unprotectedHeader)?void 0:n.alg),i,c.key,o,{p2c:f});u.encrypted_key=N(l),(c.unprotectedHeader||h)&&(u.header={...c.unprotectedHeader,...h})}return s}},"GeneralSign",0,class{constructor(e){this._signatures=[],this._payload=e}addSignature(e,t){let r=new tt(this,e,t);return this._signatures.push(r),r}async sign(){if(!this._signatures.length)throw new c("at least one signature must be added");let e={signatures:[],payload:""};for(let t=0;t<this._signatures.length;t++){let r=this._signatures[t],n=new e7(this._payload);n.setProtectedHeader(r.protectedHeader),n.setUnprotectedHeader(r.unprotectedHeader);let{payload:i,...o}=await n.sign(r.key,r.options);if(0===t)e.payload=i;else if(e.payload!==i)throw new c("inconsistent use of JWS Unencoded Payload (RFC7797)");e.signatures.push(o)}return e}},"SignJWT",0,class extends tr{setProtectedHeader(e){return this._protectedHeader=e,this}async sign(e,t){var r;let n=new te(b.encode(JSON.stringify(this._payload)));if(n.setProtectedHeader(this._protectedHeader),Array.isArray(null==(r=this._protectedHeader)?void 0:r.crit)&&this._protectedHeader.crit.includes("b64")&&!1===this._protectedHeader.b64)throw new u("JWTs MUST NOT use unencoded payload");return n.sign(e,t)}},"UnsecuredJWT",0,class extends tr{encode(){let e=N(JSON.stringify({alg:"none"})),t=N(JSON.stringify(this._payload));return`${e}.${t}.`}static decode(e,t){let r;if("string"!=typeof e)throw new u("Unsecured JWT must be a string");let{0:n,1:i,2:o,length:s}=e.split(".");if(3!==s||""!==o)throw new u("Invalid Unsecured JWT");try{if(r=JSON.parse(v.decode(U(n))),"none"!==r.alg)throw Error()}catch(e){throw new u("Invalid Unsecured JWT")}return{payload:e6(r,U(i),t),header:r}}},"base64url",0,I,"calculateJwkThumbprint",0,ti,"calculateJwkThumbprintUri",0,to,"compactDecrypt",0,eD,"compactVerify",0,eZ,"createLocalJWKSet",0,function(e){let t=new tu(e);return async function(e,r){return t.getKey(e,r)}},"createRemoteJWKSet",0,function(e,t){let r=new th(e,t);return async function(e,t){return r.getKey(e,t)}},"cryptoRuntime",0,"WebCryptoAPI","decodeJwt",0,function(e){let t,r;if("string"!=typeof e)throw new u("JWTs must use Compact JWS serialization, JWT must be a string");let{1:n,length:i}=e.split(".");if(5===i)throw new u("Only JWTs using Compact JWS serialization can be decoded");if(3!==i)throw new u("Invalid JWT");if(!n)throw new u("JWTs must contain a payload");try{t=U(n)}catch(e){throw new u("Failed to base64url decode the payload")}try{r=JSON.parse(v.decode(t))}catch(e){throw new u("Failed to parse the decoded payload as JSON")}if(!Z(r))throw new u("Invalid JWT Claims Set");return r},"decodeProtectedHeader",0,function(e){let t;if("string"==typeof e){let r=e.split(".");(3===r.length||5===r.length)&&([t]=r)}else if("object"==typeof e&&e)if("protected"in e)t=e.protected;else throw TypeError("Token does not contain a Protected Header");try{if("string"!=typeof t||!t)throw Error();let e=JSON.parse(v.decode(U(t)));if(!Z(e))throw Error();return e}catch(e){throw TypeError("Invalid Token or Protected Header formatting")}},"errors",0,g,"exportJWK",0,eL,"exportPKCS8",0,eJ,"exportSPKI",0,eM,"flattenedDecrypt",0,eH,"flattenedVerify",0,eX,"generalDecrypt",0,eW,"generalVerify",0,eQ,"generateKeyPair",0,tg,"generateSecret",0,tw,"importJWK",0,eT,"importPKCS8",0,eO,"importSPKI",0,eA,"importX509",0,ex,"jwtDecrypt",0,e3,"
3jwtVerify",0,e8],53358)},855271,e=>{"use strict";let t=async(e,t,r,n,i)=>{let{crypto:{subtle:o}}=(()=>{if("u">typeof globalThis)return globalThis;if("u">typeof self)return self;if("u">typeof window)return window;throw Error("unable to locate global object")})();return new Uint8Array(await o.deriveBits({name:"HKDF",hash:`SHA-${e.substr(3)}`,salt:r,info:n},await o.importKey("raw",t,"HKDF",!1,["deriveBits"]),i<<3))};function r(e,t){if("string"==typeof e)return new TextEncoder().encode(e);if(!(e instanceof Uint8Array))throw TypeError(`"${t}"" must be an instance of Uint8Array or a string`);return e}async function n(e,n,i,o,s){return t(function(e){switch(e){case"sha256":case"sha384":case"sha512":case"sha1":return e;default:throw TypeError('unsupported "digest" value')}}(e),function(e){let t=r(e,"ikm");if(!t.byteLength)throw TypeError('"ikm" must be at least one byte in length');return t}(n),r(i,"salt"),function(e){let t=r(e,"info");if(t.byteLength>1024)throw TypeError('"info" must not contain more than 1024 bytes');return t}(o),function(e,t){if("number"!=typeof e||!Number.isInteger(e)||e<1)throw TypeError('"keylen" must be a positive integer');if(e>255*(parseInt(t.substr(3),10)>>3||20))throw TypeError('"keylen" too large');return e}(s,e))}e.s(["default",0,n,"hkdf",0,n],855271)},625744,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default="ffffffff-ffff-ffff-ffff-ffffffffffff"},905368,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default="00000000-0000-0000-0000-000000000000"},953824,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i},653199,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0});let n=e.r(953824);r.default=function(e){return"string"==typeof e&&n.default.test(e)}},202214,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0});let n=e.r(653199);r.default=function(e){let t;if(!(0,n.default)(e))throw TypeError("Invalid UUID");return Uint8Array.of((t=parseInt(e.slice(0,8),16))>>>24,t>>>16&255,t>>>8&255,255&t,(t=parseInt(e.slice(9,13),16))>>>8,255&t,(t=parseInt(e.slice(14,18),16))>>>8,255&t,(t=parseInt(e.slice(19,23),16))>>>8,255&t,(t=parseInt(e.slice(24,36),16))/0x10000000000&255,t/0x100000000&255,t>>>24&255,t>>>16&255,t>>>8&255,255&t)}},630755,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.unsafeStringify=void 0;let n=e.r(653199),i=[];for(let e=0;e<256;++e)i.push((e+256).toString(16).slice(1));function o(e,t=0){return(i[e[t+0]]+i[e[t+1]]+i[e[t+2]]+i[e[t+3]]+"-"+i[e[t+4]]+i[e[t+5]]+"-"+i[e[t+6]]+i[e[t+7]]+"-"+i[e[t+8]]+i[e[t+9]]+"-"+i[e[t+10]]+i[e[t+11]]+i[e[t+12]]+i[e[t+13]]+i[e[t+14]]+i[e[t+15]]).toLowerCase()}r.unsafeStringify=o,r.default=function(e,t=0){let r=o(e,t);if(!(0,n.default)(r))throw TypeError("Stringified UUID is invalid");return r}},888479,(e,t,r)=>{"use strict";let n;Object.defineProperty(r,"__esModule",{value:!0});let i=new Uint8Array(16);r.default=function(){if(!n){if("u"<typeof crypto||!crypto.getRandomValues)throw Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");n=crypto.getRandomValues.bind(crypto)}return n(i)}},287060,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.updateV1State=void 0;let n=e.r(888479),i=e.r(630755),o={};function s(e,t,r){return e.msecs??=-1/0,e.nsecs??=0,t===e.msecs?(e.nsecs++,e.nsecs>=1e4&&(e.node=void 0,e.nsecs=0)):t>e.msecs?e.nsecs=0:t<e.msecs&&(e.node=void 0),e.node||(e.node=r.slice(10,16),e.node[0]|=1,e.clockseq=(r[8]<<8|r[9])&16383),e.msecs=t,e}function a(e,t,r,n,i,o,s=0){if(e.length<16)throw Error("Random bytes length must be >= 16");if(o){if(s<0||s+16>o.length)throw RangeError(`UUID byte range ${s}:${s+15} is out of buffer bounds`)}else o=new Uint8Array(16),s=0;t??=Date.now(),r??=0,n??=(e[8]<<8|e[9])&16383,i??=e.slice(10,16);let c=((0xfffffff&(t+=122192928e5))*1e4+r)%0x100000000;o[s++]=c>>>24&255,o[s++]=c>>>16&255,o[s++]=c>>>8&255,o[s++]=255&c;let u=t/0x100000000*1e4&0xfffffff;o[s++]=u>>>8&255,o[s++]=255&u,o[s++]=u>>>
324&15|16,o[s++]=u>>>16&255,o[s++]=n>>>8|128,o[s++]=255&n;for(let e=0;e<6;++e)o[s++]=i[e];return o}r.updateV1State=s,r.default=function(e,t,r){let c,u=e?._v6??!1;if(e){let t=Object.keys(e);1===t.length&&"_v6"===t[0]&&(e=void 0)}if(e)c=a(e.random??e.rng?.()??(0,n.default)(),e.msecs,e.nsecs,e.clockseq,e.node,t,r);else{let e=Date.now(),i=(0,n.default)();s(o,e,i),c=a(i,o.msecs,o.nsecs,u?void 0:o.clockseq,u?void 0:o.node,t,r)}return t??(0,i.unsafeStringify)(c)}},235541,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0});let n=e.r(202214),i=e.r(630755);r.default=function(e){var t;let r=(t="string"==typeof e?(0,n.default)(e):e,Uint8Array.of((15&t[6])<<4|t[7]>>4&15,(15&t[7])<<4|(240&t[4])>>4,(15&t[4])<<4|(240&t[5])>>4,(15&t[5])<<4|(240&t[0])>>4,(15&t[0])<<4|(240&t[1])>>4,(15&t[1])<<4|(240&t[2])>>4,96|15&t[2],t[3],t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15]));return"string"==typeof e?(0,i.unsafeStringify)(r):r}},121037,(e,t,r)=>{"use strict";function n(e){return(e+64>>>9<<4)+14+1}function i(e,t){let r=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(r>>16)<<16|65535&r}function o(e,t,r,n,o,s){var a;return i((a=i(i(t,e),i(n,s)))<<o|a>>>32-o,r)}function s(e,t,r,n,i,s,a){return o(t&r|~t&n,e,t,i,s,a)}function a(e,t,r,n,i,s,a){return o(t&n|r&~n,e,t,i,s,a)}function c(e,t,r,n,i,s,a){return o(t^r^n,e,t,i,s,a)}function u(e,t,r,n,i,s,a){return o(r^(t|~n),e,t,i,s,a)}Object.defineProperty(r,"__esModule",{value:!0}),r.default=function(e){var t=function(e,t){let r=new Uint32Array(n(t)).fill(0);r.set(e),r[t>>5]|=128<<t%32,r[r.length-1]=t,e=r;let o=0x67452301,f=-0x10325477,l=-0x67452302,h=0x10325476;for(let t=0;t<e.length;t+=16){let r=o,n=f,d=l,p=h;o=s(o,f,l,h,e[t],7,-0x28955b88),h=s(h,o,f,l,e[t+1],12,-0x173848aa),l=s(l,h,o,f,e[t+2],17,0x242070db),f=s(f,l,h,o,e[t+3],22,-0x3e423112),o=s(o,f,l,h,e[t+4],7,-0xa83f051),h=s(h,o,f,l,e[t+5],12,0x4787c62a),l=s(l,h,o,f,e[t+6],17,-0x57cfb9ed),f=s(f,l,h,o,e[t+7],22,-0x2b96aff),o=s(o,f,l,h,e[t+8],7,0x698098d8),h=s(h,o,f,l,e[t+9],12,-0x74bb0851),l=s(l,h,o,f,e[t+10],17,-42063),f=s(f,l,h,o,e[t+11],22,-0x76a32842),o=s(o,f,l,h,e[t+12],7,0x6b901122),h=s(h,o,f,l,e[t+13],12,-0x2678e6d),l=s(l,h,o,f,e[t+14],17,-0x5986bc72),f=s(f,l,h,o,e[t+15],22,0x49b40821),o=a(o,f,l,h,e[t+1],5,-0x9e1da9e),h=a(h,o,f,l,e[t+6],9,-0x3fbf4cc0),l=a(l,h,o,f,e[t+11],14,0x265e5a51),f=a(f,l,h,o,e[t],20,-0x16493856),o=a(o,f,l,h,e[t+5],5,-0x29d0efa3),h=a(h,o,f,l,e[t+10],9,0x2441453),l=a(l,h,o,f,e[t+15],14,-0x275e197f),f=a(f,l,h,o,e[t+4],20,-0x182c0438),o=a(o,f,l,h,e[t+9],5,0x21e1cde6),h=a(h,o,f,l,e[t+14],9,-0x3cc8f82a),l=a(l,h,o,f,e[t+3],14,-0xb2af279),f=a(f,l,h,o,e[t+8],20,0x455a14ed),o=a(o,f,l,h,e[t+13],5,-0x561c16fb),h=a(h,o,f,l,e[t+2],9,-0x3105c08),l=a(l,h,o,f,e[t+7],14,0x676f02d9),f=a(f,l,h,o,e[t+12],20,-0x72d5b376),o=c(o,f,l,h,e[t+5],4,-378558),h=c(h,o,f,l,e[t+8],11,-0x788e097f),l=c(l,h,o,f,e[t+11],16,0x6d9d6122),f=c(f,l,h,o,e[t+14],23,-0x21ac7f4),o=c(o,f,l,h,e[t+1],4,-0x5b4115bc),h=c(h,o,f,l,e[t+4],11,0x4bdecfa9),l=c(l,h,o,f,e[t+7],16,-0x944b4a0),f=c(f,l,h,o,e[t+10],23,-0x41404390),o=c(o,f,l,h,e[t+13],4,0x289b7ec6),h=c(h,o,f,l,e[t],11,-0x155ed806),l=c(l,h,o,f,e[t+3],16,-0x2b10cf7b),f=c(f,l,h,o,e[t+6],23,0x4881d05),o=c(o,f,l,h,e[t+9],4,-0x262b2fc7),h=c(h,o,f,l,e[t+12],11,-0x1924661b),l=c(l,h,o,f,e[t+15],16,0x1fa27cf8),f=c(f,l,h,o,e[t+2],23,-0x3b53a99b),o=u(o,f,l,h,e[t],6,-0xbd6ddbc),h=u(h,o,f,l,e[t+7],10,0x432aff97),l=u(l,h,o,f,e[t+14],15,-0x546bdc59),f=u(f,l,h,o,e[t+5],21,-0x36c5fc7),o=u(o,f,l,h,e[t+12],6,0x655b59c3),h=u(h,o,f,l,e[t+3],10,-0x70f3336e),l=u(l,h,o,f,e[t+10],15,-1051523),f=u(f,l,h,o,e[t+1],21,-0x7a7ba22f),o=u(o,f,l,h,e[t+8],6,0x6fa87e4f),h=u(h,o,f,l,e[t+15],10,-0x1d31920),l=u(l,h,o,f,e[t+6],15,-0x5cfebcec),f=u(f,l,h,o,e[t+13],21,0x4e0811a1),o=u(o,f,l,h,e[t+4],6,-0x8ac817e),h=u(h,o,f,l,e[t+11],10,-0x42c50dcb),l=u(l,h,o,f,e[t+2],15,0x2ad7d2bb),f=u(f,l,h,o,e[t+9],21,-0x14792c6f),o=i(o,r),f=i(f,n),l=i(l,d),h=i(h,p)}return Uint32Array.of(o,f,l,h)}(function(e){if(0===e.length)return new Uint32Array;let t=new Uint32Array(n(8*e.length)).fill(0);for(let r=0;r<e.length;r++)t[r>>2]|=(255&e[r])<<r%4*8;return t}(e),8*e.length);let r=new Uint8Array(4*t.length);for(let e=0;e<4*t.length;e++)r[e]=t[e>>2]>>>e%4*8&255;return r}},880602,(e,t,r)=>{"use strict";
3Object.defineProperty(r,"__esModule",{value:!0}),r.URL=r.DNS=r.stringToBytes=void 0;let n=e.r(202214),i=e.r(630755);function o(e){let t=new Uint8Array((e=unescape(encodeURIComponent(e))).length);for(let r=0;r<e.length;++r)t[r]=e.charCodeAt(r);return t}r.stringToBytes=o,r.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",r.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",r.default=function(e,t,r,s,a,c){let u="string"==typeof r?o(r):r,f="string"==typeof s?(0,n.default)(s):s;if("string"==typeof s&&(s=(0,n.default)(s)),s?.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+u.length);if(l.set(f),l.set(u,f.length),(l=t(l))[6]=15&l[6]|e,l[8]=63&l[8]|128,a){if((c=c||0)<0||c+16>a.length)throw RangeError(`UUID byte range ${c}:${c+15} is out of buffer bounds`);for(let e=0;e<16;++e)a[c+e]=l[e];return a}return(0,i.unsafeStringify)(l)}},637784,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.URL=r.DNS=void 0;let n=e.r(121037),i=e.r(880602);var o=e.r(880602);function s(e,t,r,o){return(0,i.default)(48,n.default,e,t,r,o)}Object.defineProperty(r,"DNS",{enumerable:!0,get:function(){return o.DNS}}),Object.defineProperty(r,"URL",{enumerable:!0,get:function(){return o.URL}}),s.DNS=i.DNS,s.URL=i.URL,r.default=s},713202,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default={randomUUID:"u">typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)}},385329,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0});let n=e.r(713202),i=e.r(888479),o=e.r(630755);r.default=function(e,t,r){if(n.default.randomUUID&&!t&&!e)return n.default.randomUUID();let s=(e=e||{}).random??e.rng?.()??(0,i.default)();if(s.length<16)throw Error("Random bytes length must be >= 16");if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t){if((r=r||0)<0||r+16>t.length)throw RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[r+e]=s[e];return t}return(0,o.unsafeStringify)(s)}},893072,(e,t,r)=>{"use strict";function n(e,t){return e<<t|e>>>32-t}Object.defineProperty(r,"__esModule",{value:!0}),r.default=function(e){let t=[0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6],r=[0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0],i=new Uint8Array(e.length+1);i.set(e),i[e.length]=128;let o=Math.ceil(((e=i).length/4+2)/16),s=Array(o);for(let t=0;t<o;++t){let r=new Uint32Array(16);for(let n=0;n<16;++n)r[n]=e[64*t+4*n]<<24|e[64*t+4*n+1]<<16|e[64*t+4*n+2]<<8|e[64*t+4*n+3];s[t]=r}s[o-1][14]=(e.length-1)*8/0x100000000,s[o-1][14]=Math.floor(s[o-1][14]),s[o-1][15]=(e.length-1)*8|0;for(let e=0;e<o;++e){let i=new Uint32Array(80);for(let t=0;t<16;++t)i[t]=s[e][t];for(let e=16;e<80;++e)i[e]=n(i[e-3]^i[e-8]^i[e-14]^i[e-16],1);let o=r[0],a=r[1],c=r[2],u=r[3],f=r[4];for(let e=0;e<80;++e){let r=Math.floor(e/20),s=n(o,5)+function(e,t,r,n){switch(e){case 0:return t&r^~t&n;case 1:case 3:return t^r^n;case 2:return t&r^t&n^r&n}}(r,a,c,u)+f+t[r]+i[e]>>>0;f=u,u=c,c=n(a,30)>>>0,a=o,o=s}r[0]=r[0]+o>>>0,r[1]=r[1]+a>>>0,r[2]=r[2]+c>>>0,r[3]=r[3]+u>>>0,r[4]=r[4]+f>>>0}return Uint8Array.of(r[0]>>24,r[0]>>16,r[0]>>8,r[0],r[1]>>24,r[1]>>16,r[1]>>8,r[1],r[2]>>24,r[2]>>16,r[2]>>8,r[2],r[3]>>24,r[3]>>16,r[3]>>8,r[3],r[4]>>24,r[4]>>16,r[4]>>8,r[4])}},635299,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.URL=r.DNS=void 0;let n=e.r(893072),i=e.r(880602);var o=e.r(880602);function s(e,t,r,o){return(0,i.default)(80,n.default,e,t,r,o)}Object.defineProperty(r,"DNS",{enumerable:!0,get:function(){return o.DNS}}),Object.defineProperty(r,"URL",{enumerable:!0,get:function(){return o.URL}}),s.DNS=i.DNS,s.URL=i.URL,r.default=s},633520,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0});let n=e.r(630755),i=e.r(287060),o=e.r(235541);r.default=function(e,t,r){e??={},r??=0;let s=(0,i.default)({...e,_v6:!0},new Uint8Array(16));if(s=(0,o.default)(s),t){if(r<0||r+16>t.length)throw RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let e=0;e<16;e++)t[r+e]=s[e];return t}return(0,n.unsafeStringify)(s)}},383857,(e,t,r)=>{"use strict";
3Object.defineProperty(r,"__esModule",{value:!0});let n=e.r(202214),i=e.r(630755);r.default=function(e){var t;let r=(t="string"==typeof e?(0,n.default)(e):e,Uint8Array.of((15&t[3])<<4|t[4]>>4&15,(15&t[4])<<4|(240&t[5])>>4,(15&t[5])<<4|15&t[6],t[7],(15&t[1])<<4|(240&t[2])>>4,(15&t[2])<<4|(240&t[3])>>4,16|(240&t[0])>>4,(15&t[0])<<4|(240&t[1])>>4,t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15]));return"string"==typeof e?(0,i.unsafeStringify)(r):r}},11497,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.updateV7State=void 0;let n=e.r(888479),i=e.r(630755),o={};function s(e,t,r){return e.msecs??=-1/0,e.seq??=0,t>e.msecs?(e.seq=r[6]<<23|r[7]<<16|r[8]<<8|r[9],e.msecs=t):(e.seq=e.seq+1|0,0===e.seq&&e.msecs++),e}function a(e,t,r,n,i=0){if(e.length<16)throw Error("Random bytes length must be >= 16");if(n){if(i<0||i+16>n.length)throw RangeError(`UUID byte range ${i}:${i+15} is out of buffer bounds`)}else n=new Uint8Array(16),i=0;return t??=Date.now(),r??=127*e[6]<<24|e[7]<<16|e[8]<<8|e[9],n[i++]=t/0x10000000000&255,n[i++]=t/0x100000000&255,n[i++]=t/0x1000000&255,n[i++]=t/65536&255,n[i++]=t/256&255,n[i++]=255&t,n[i++]=112|r>>>28&15,n[i++]=r>>>20&255,n[i++]=128|r>>>14&63,n[i++]=r>>>6&255,n[i++]=r<<2&255|3&e[10],n[i++]=e[11],n[i++]=e[12],n[i++]=e[13],n[i++]=e[14],n[i++]=e[15],n}r.updateV7State=s,r.default=function(e,t,r){let c;if(e)c=a(e.random??e.rng?.()??(0,n.default)(),e.msecs,e.seq,t,r);else{let e=Date.now(),i=(0,n.default)();s(o,e,i),c=a(i,o.msecs,o.seq,t,r)}return t??(0,i.unsafeStringify)(c)}},87211,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0});let n=e.r(653199);r.default=function(e){if(!(0,n.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}},95135,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.version=r.validate=r.v7=r.v6ToV1=r.v6=r.v5=r.v4=r.v3=r.v1ToV6=r.v1=r.stringify=r.parse=r.NIL=r.MAX=void 0;var n=e.r(625744);Object.defineProperty(r,"MAX",{enumerable:!0,get:function(){return n.default}});var i=e.r(905368);Object.defineProperty(r,"NIL",{enumerable:!0,get:function(){return i.default}});var o=e.r(202214);Object.defineProperty(r,"parse",{enumerable:!0,get:function(){return o.default}});var s=e.r(630755);Object.defineProperty(r,"stringify",{enumerable:!0,get:function(){return s.default}});var a=e.r(287060);Object.defineProperty(r,"v1",{enumerable:!0,get:function(){return a.default}});var c=e.r(235541);Object.defineProperty(r,"v1ToV6",{enumerable:!0,get:function(){return c.default}});var u=e.r(637784);Object.defineProperty(r,"v3",{enumerable:!0,get:function(){return u.default}});var f=e.r(385329);Object.defineProperty(r,"v4",{enumerable:!0,get:function(){return f.default}});var l=e.r(635299);Object.defineProperty(r,"v5",{enumerable:!0,get:function(){return l.default}});var h=e.r(633520);Object.defineProperty(r,"v6",{enumerable:!0,get:function(){return h.default}});var d=e.r(383857);Object.defineProperty(r,"v6ToV1",{enumerable:!0,get:function(){return d.default}});var p=e.r(11497);Object.defineProperty(r,"v7",{enumerable:!0,get:function(){return p.default}});var y=e.r(653199);Object.defineProperty(r,"validate",{enumerable:!0,get:function(){return y.default}});var g=e.r(87211);Object.defineProperty(r,"version",{enumerable:!0,get:function(){return g.default}})},401776,(e,t,r)=>{"use strict";function n(e,t,r){i(e,t),t.set(e,r)}function i(e,t){if(t.has(e))throw TypeError("Cannot initialize the same private elements twice on an object")}function o(e,t){return e.get(a(e,t))}function s(e,t,r){return e.set(a(e,t),r),r}function a(e,t,r){if("function"==typeof e?e===t:e.has(t))return arguments.length<3?t:r;throw TypeError("Private element is not present on this object")}Object.defineProperty(r,"__esModule",{value:!0}),r.SessionStore=void 0,r.defaultCookies=function(e){let t=e?"__Secure-":"";return{sessionToken:{name:`${t}next-auth.session-token`,options:{httpOnly:!0,sameSite:"lax",path:"/",secure:e}},callbackUrl:{name:`${t}next-auth.callback-url`,options:{httpOnly:!0,sameSite:"lax",path:"/",secure:e}},csrfToken:{name:`${e?"__Host-":""}next-auth.csrf-token`,options:{httpOnly:!0,sameSite:"lax",path:"/",secure:e}},pkceCodeVerifier:{name:`${t}next-auth.pkce.code_verifier`,options:{httpOnly:!0,sameSite:"lax",path:"/",secure:e,maxAge:900}},state:{name:`${t}next-auth.state`,options:{httpOnly:!0,sameSite:"lax",path:"/",secure:e,maxAge:900}},nonce:{name:`${t}next-auth.nonce`,options:{httpOnly:!0,sameSite:"lax",path:"/",secure:e}}}};var c=new WeakMap,u=new WeakMap,f=new WeakMap,l=new WeakSet;function h(e){let t=Math.ceil(e.value.length/3933);if(1===t)return o(c,this)[e.name]=e.value,[e];let r=[];for(let n=0;n<t;n++){let t=`${e.name}.${n}`,i=e.value.substr(3933*n,3933);r.push({...e,name:t,value:i}),o(c,this)[t]=i}return o(f,this).debug("CHUNKING_SESSION_COOKIE",{message:"Session cookie exceeds allowed 4096 bytes.",emptyCookieSize:163,valueSize:e.value.length,chunks:r.map(e=>e.value.length+163)}),r}function d(){let e={};for(let r in o(c,this)){var t;null==(t=o(c,this))||delete t[r],e[r]={name:r,value:"",options:{...o(u,this).options,maxAge:0}}}return e}r.SessionStore=class{constructor(e,t,r){!function(e,t){i(e,t),t.add(e)}(this,l),n(this,c,{}),n(this,u,void 0),n(this,f,void 0),s(f,this,r),s(u,this,e);const{cookies:a}=t,{name:h}=e;if("function"==typeof(null==a?void 0:a.getAll))for(const{name:e,value:t}of a.getAll())e.startsWith(h)&&(o(c,this)[e]=t);else if(a instanceof Map)for(const e of a.keys())e.startsWith(h)&&(o(c,this)[e]=a.get(e));else for(const e in a)e.startsWith(h)&&(o(c,this)[e]=a[e])}get value(){return Object.keys(o(c,this)).sort((e,t)=>
3{var r,n;return parseInt(null!=(r=e.split(".").pop())?r:"0")-parseInt(null!=(n=t.split(".").pop())?n:"0")}).map(e=>o(c,this)[e]).join("")}chunk(e,t){let r=a(l,this,d).call(this);for(let n of a(l,this,h).call(this,{name:o(u,this).name,value:e,options:{...o(u,this).options,...t}}))r[n.name]=n;return Object.values(r)}clean(){return Object.values(a(l,this,d).call(this))}}},587245,(e,t,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0})},151071,(e,t,r)=>{"use strict";var n=e.i(247167),i=e.r(13451);Object.defineProperty(r,"__esModule",{value:!0});var o={encode:!0,decode:!0,getToken:!0};r.decode=h,r.encode=l,r.getToken=d;var s=e.r(53358),a=i(e.r(855271)),c=e.r(95135),u=e.r(401776),f=e.r(587245);async function l(e){let{token:t={},secret:r,maxAge:n=2592e3,salt:i=""}=e,o=await p(r,i);return await new s.EncryptJWT(t).setProtectedHeader({alg:"dir",enc:"A256GCM"}).setIssuedAt().setExpirationTime((Date.now()/1e3|0)+n).setJti((0,c.v4)()).encrypt(o)}async function h(e){let{token:t,secret:r,salt:n=""}=e;if(!t)return null;let i=await p(r,n),{payload:o}=await (0,s.jwtDecrypt)(t,i,{clockTolerance:15});return o}async function d(e){var t,r,i;let{req:o,secureCookie:s=null!==(t="https://www.socialscout.ai".startsWith("https://"))&&void 0!==t?t:!!n.default.env.VERCEL,cookieName:a=s?"__Secure-next-auth.session-token":"next-auth.session-token",raw:c,decode:f=h,logger:l=console,secret:d=null!=(r=n.default.env.NEXTAUTH_SECRET)?r:n.default.env.AUTH_SECRET}=e;if(!o)throw Error("Must pass `req` to JWT getToken()");let p=new u.SessionStore({name:a,options:{secure:s}},{cookies:o.cookies,headers:o.headers},l).value,y=o.headers instanceof Headers?o.headers.get("authorization"):null==(i=o.headers)?void 0:i.authorization;if(!p&&(null==y?void 0:y.split(" ")[0])==="Bearer"){let e=y.split(" ")[1];try{p=decodeURIComponent(e)}catch(e){return null}}if(!p)return null;if(c)return p;try{return await f({token:p,secret:d})}catch(e){return null}}async function p(e,t){return await (0,a.default)("sha256",e,t,`NextAuth.js Generated Encryption Key${t?` (${t})`:""}`,32)}Object.keys(f).forEach(function(e){"default"===e||"__esModule"===e||Object.prototype.hasOwnProperty.call(o,e)||e in r&&r[e]===f[e]||Object.defineProperty(r,e,{enumerable:!0,get:function(){return f[e]}})})}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.