skapi-js 1.0.58 → 1.0.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/skapi.js +1 -1
- package/dist/skapi.js.map +1 -1
- package/dist/skapi.module.js +1 -1
- package/dist/skapi.module.js.map +1 -1
- package/js/main/skapi.js +1 -1
- package/js/methods/subscription.d.ts +2 -2
- package/js/methods/subscription.js +16 -17
- package/js/methods/user.d.ts +0 -3
- package/package.json +2 -3
package/dist/skapi.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see skapi.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(self,(()=>(()=>{var e={742:(e,t)=>{"use strict";t.byteLength=function(e){var t=a(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,s=a(e),o=s[0],u=s[1],c=new i(function(e,t,n){return 3*(t+n)/4-n}(0,o,u)),l=0,h=u>0?o-4:o;for(n=0;n<h;n+=4)t=r[e.charCodeAt(n)]<<18|r[e.charCodeAt(n+1)]<<12|r[e.charCodeAt(n+2)]<<6|r[e.charCodeAt(n+3)],c[l++]=t>>16&255,c[l++]=t>>8&255,c[l++]=255&t;return 2===u&&(t=r[e.charCodeAt(n)]<<2|r[e.charCodeAt(n+1)]>>4,c[l++]=255&t),1===u&&(t=r[e.charCodeAt(n)]<<10|r[e.charCodeAt(n+1)]<<4|r[e.charCodeAt(n+2)]>>2,c[l++]=t>>8&255,c[l++]=255&t),c},t.fromByteArray=function(e){for(var t,r=e.length,i=r%3,s=[],o=16383,a=0,c=r-i;a<c;a+=o)s.push(u(e,a,a+o>c?c:a+o));return 1===i?(t=e[r-1],s.push(n[t>>2]+n[t<<4&63]+"==")):2===i&&(t=(e[r-2]<<8)+e[r-1],s.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"=")),s.join("")};for(var n=[],r=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0;o<64;++o)n[o]=s[o],r[s.charCodeAt(o)]=o;function a(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function u(e,t,r){for(var i,s,o=[],a=t;a<r;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(n[(s=i)>>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return o.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},764:(e,t,n)=>{"use strict";var r=n(742),i=n(645),s=n(826);function o(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(o()<t)throw new RangeError("Invalid typed array length");return u.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=u.prototype:(null===e&&(e=new u(t)),e.length=t),e}function u(e,t,n){if(!(u.TYPED_ARRAY_SUPPORT||this instanceof u))return new u(e,t,n);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return h(this,e)}return c(this,e,t,n)}function c(e,t,n,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,n,r){if(t.byteLength,n<0||t.byteLength<n)throw new RangeError("'offset' is out of bounds");if(t.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");return t=void 0===n&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,n):new Uint8Array(t,n,r),u.TYPED_ARRAY_SUPPORT?(e=t).__proto__=u.prototype:e=f(e,t),e}(e,t,n,r):"string"==typeof t?function(e,t,n){if("string"==typeof n&&""!==n||(n="utf8"),!u.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|p(t,n),i=(e=a(e,r)).write(t,n);return i!==r&&(e=e.slice(0,i)),e}(e,t,n):function(e,t){if(u.isBuffer(t)){var n=0|d(t.length);return 0===(e=a(e,n)).length||t.copy(e,0,0,n),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(r=t.length)!=r?a(e,0):f(e,t);if("Buffer"===t.type&&s(t.data))return f(e,t.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function l(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function h(e,t){if(l(t),e=a(e,t<0?0:0|d(t)),!u.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)e[n]=0;return e}function f(e,t){var n=t.length<0?0:0|d(t.length);e=a(e,n);for(var r=0;r<n;r+=1)e[r]=255&t[r];return e}function d(e){if(e>=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|e}function p(e,t){if(u.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return B(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return $(e).length;default:if(r)return B(e).length;t=(""+t).toLowerCase(),r=!0}}function g(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return C(this,t,n);case"utf8":case"utf-8":return R(this,t,n);case"ascii":return U(this,t,n);case"latin1":case"binary":return D(this,t,n);case"base64":return I(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function m(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function y(e,t,n,r,i){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof t&&(t=u.from(t,r)),u.isBuffer(t))return 0===t.length?-1:w(e,t,n,r,i);if("number"==typeof t)return t&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):w(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function w(e,t,n,r,i){var s,o=1,a=e.length,u=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;o=2,a/=2,u/=2,n/=2}function c(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){var l=-1;for(s=n;s<a;s++)if(c(e,s)===c(t,-1===l?0:s-l)){if(-1===l&&(l=s),s-l+1===u)return l*o}else-1!==l&&(s-=s-l),l=-1}else for(n+u>a&&(n=a-u),s=n;s>=0;s--){for(var h=!0,f=0;f<u;f++)if(c(e,s+f)!==c(t,f)){h=!1;break}if(h)return s}return-1}function _(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r))>i&&(r=i):r=i;var s=t.length;if(s%2!=0)throw new TypeError("Invalid hex string");r>s/2&&(r=s/2);for(var o=0;o<r;++o){var a=parseInt(t.substr(2*o,2),16);if(isNaN(a))return o;e[n+o]=a}return o}function b(e,t,n,r){return q(B(t,e.length-n),e,n,r)}function A(e,t,n,r){return q(function(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function v(e,t,n,r){return A(e,t,n,r)}function E(e,t,n,r){return q($(t),e,n,r)}function S(e,t,n,r){return q(function(e,t){for(var n,r,i,s=[],o=0;o<e.length&&!((t-=2)<0);++o)r=(n=e.charCodeAt(o))>>8,i=n%256,s.push(i),s.push(r);return s}(t,e.length-n),e,n,r)}function I(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function R(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i<n;){var s,o,a,u,c=e[i],l=null,h=c>239?4:c>223?3:c>191?2:1;if(i+h<=n)switch(h){case 1:c<128&&(l=c);break;case 2:128==(192&(s=e[i+1]))&&(u=(31&c)<<6|63&s)>127&&(l=u);break;case 3:s=e[i+1],o=e[i+2],128==(192&s)&&128==(192&o)&&(u=(15&c)<<12|(63&s)<<6|63&o)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:s=e[i+1],o=e[i+2],a=e[i+3],128==(192&s)&&128==(192&o)&&128==(192&a)&&(u=(15&c)<<18|(63&s)<<12|(63&o)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,h=1):l>65535&&(l-=65536,r.push(l>>>10&1023|55296),l=56320|1023&l),r.push(l),i+=h}return function(e){var t=e.length;if(t<=T)return String.fromCharCode.apply(String,e);for(var n="",r=0;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=T));return n}(r)}t.lW=u,t.h2=50,u.TYPED_ARRAY_SUPPORT=void 0!==n.g.TYPED_ARRAY_SUPPORT?n.g.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),o(),u.poolSize=8192,u._augment=function(e){return e.__proto__=u.prototype,e},u.from=function(e,t,n){return c(null,e,t,n)},u.TYPED_ARRAY_SUPPORT&&(u.prototype.__proto__=Uint8Array.prototype,u.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&u[Symbol.species]===u&&Object.defineProperty(u,Symbol.species,{value:null,configurable:!0})),u.alloc=function(e,t,n){return function(e,t,n,r){return l(t),t<=0?a(e,t):void 0!==n?"string"==typeof r?a(e,t).fill(n,r):a(e,t).fill(n):a(e,t)}(null,e,t,n)},u.allocUnsafe=function(e){return h(null,e)},u.allocUnsafeSlow=function(e){return h(null,e)},u.isBuffer=function(e){return!(null==e||!e._isBuffer)},u.compare=function(e,t){if(!u.isBuffer(e)||!u.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,i=0,s=Math.min(n,r);i<s;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:r<n?1:0},u.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}},u.concat=function(e,t){if(!s(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return u.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=u.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){var o=e[n];if(!u.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(r,i),i+=o.length}return r},u.byteLength=p,u.prototype._isBuffer=!0,u.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)m(this,t,t+1);return this},u.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)m(this,t,t+3),m(this,t+1,t+2);return this},u.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)m(this,t,t+7),m(this,t+1,t+6),m(this,t+2,t+5),m(this,t+3,t+4);return this},u.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?R(this,0,e):g.apply(this,arguments)},u.prototype.equals=function(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===u.compare(this,e)},u.prototype.inspect=function(){var e="",n=t.h2;return this.length>0&&(e=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(e+=" ... ")),"<Buffer "+e+">"},u.prototype.compare=function(e,t,n,r,i){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(this===e)return 0;for(var s=(i>>>=0)-(r>>>=0),o=(n>>>=0)-(t>>>=0),a=Math.min(s,o),c=this.slice(r,i),l=e.slice(t,n),h=0;h<a;++h)if(c[h]!==l[h]){s=c[h],o=l[h];break}return s<o?-1:o<s?1:0},u.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},u.prototype.indexOf=function(e,t,n){return y(this,e,t,n,!0)},u.prototype.lastIndexOf=function(e,t,n){return y(this,e,t,n,!1)},u.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var i=this.length-t;if((void 0===n||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var s=!1;;)switch(r){case"hex":return _(this,e,t,n);case"utf8":case"utf-8":return b(this,e,t,n);case"ascii":return A(this,e,t,n);case"latin1":case"binary":return v(this,e,t,n);case"base64":return E(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var T=4096;function U(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(127&e[i]);return r}function D(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function C(e,t,n){var r,i=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>i)&&(n=i);for(var s="",o=t;o<n;++o)s+=(r=e[o])<16?"0"+r.toString(16):r.toString(16);return s}function P(e,t,n){for(var r=e.slice(t,n),i="",s=0;s<r.length;s+=2)i+=String.fromCharCode(r[s]+256*r[s+1]);return i}function N(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function k(e,t,n,r,i,s){if(!u.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function M(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,s=Math.min(e.length-n,2);i<s;++i)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function O(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,s=Math.min(e.length-n,4);i<s;++i)e[n+i]=t>>>8*(r?i:3-i)&255}function V(e,t,n,r,i,s){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function L(e,t,n,r,s){return s||V(e,0,n,4),i.write(e,t,n,r,23,4),n+4}function F(e,t,n,r,s){return s||V(e,0,n,8),i.write(e,t,n,r,52,8),n+8}u.prototype.slice=function(e,t){var n,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e),u.TYPED_ARRAY_SUPPORT)(n=this.subarray(e,t)).__proto__=u.prototype;else{var i=t-e;n=new u(i,void 0);for(var s=0;s<i;++s)n[s]=this[s+e]}return n},u.prototype.readUIntLE=function(e,t,n){e|=0,t|=0,n||N(e,t,this.length);for(var r=this[e],i=1,s=0;++s<t&&(i*=256);)r+=this[e+s]*i;return r},u.prototype.readUIntBE=function(e,t,n){e|=0,t|=0,n||N(e,t,this.length);for(var r=this[e+--t],i=1;t>0&&(i*=256);)r+=this[e+--t]*i;return r},u.prototype.readUInt8=function(e,t){return t||N(e,1,this.length),this[e]},u.prototype.readUInt16LE=function(e,t){return t||N(e,2,this.length),this[e]|this[e+1]<<8},u.prototype.readUInt16BE=function(e,t){return t||N(e,2,this.length),this[e]<<8|this[e+1]},u.prototype.readUInt32LE=function(e,t){return t||N(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},u.prototype.readUInt32BE=function(e,t){return t||N(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},u.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||N(e,t,this.length);for(var r=this[e],i=1,s=0;++s<t&&(i*=256);)r+=this[e+s]*i;return r>=(i*=128)&&(r-=Math.pow(2,8*t)),r},u.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||N(e,t,this.length);for(var r=t,i=1,s=this[e+--r];r>0&&(i*=256);)s+=this[e+--r]*i;return s>=(i*=128)&&(s-=Math.pow(2,8*t)),s},u.prototype.readInt8=function(e,t){return t||N(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},u.prototype.readInt16LE=function(e,t){t||N(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt16BE=function(e,t){t||N(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt32LE=function(e,t){return t||N(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},u.prototype.readInt32BE=function(e,t){return t||N(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},u.prototype.readFloatLE=function(e,t){return t||N(e,4,this.length),i.read(this,e,!0,23,4)},u.prototype.readFloatBE=function(e,t){return t||N(e,4,this.length),i.read(this,e,!1,23,4)},u.prototype.readDoubleLE=function(e,t){return t||N(e,8,this.length),i.read(this,e,!0,52,8)},u.prototype.readDoubleBE=function(e,t){return t||N(e,8,this.length),i.read(this,e,!1,52,8)},u.prototype.writeUIntLE=function(e,t,n,r){e=+e,t|=0,n|=0,r||k(this,e,t,n,Math.pow(2,8*n)-1,0);var i=1,s=0;for(this[t]=255&e;++s<n&&(i*=256);)this[t+s]=e/i&255;return t+n},u.prototype.writeUIntBE=function(e,t,n,r){e=+e,t|=0,n|=0,r||k(this,e,t,n,Math.pow(2,8*n)-1,0);var i=n-1,s=1;for(this[t+i]=255&e;--i>=0&&(s*=256);)this[t+i]=e/s&255;return t+n},u.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,1,255,0),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},u.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):M(this,e,t,!0),t+2},u.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):M(this,e,t,!1),t+2},u.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):O(this,e,t,!0),t+4},u.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):O(this,e,t,!1),t+4},u.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);k(this,e,t,n,i-1,-i)}var s=0,o=1,a=0;for(this[t]=255&e;++s<n&&(o*=256);)e<0&&0===a&&0!==this[t+s-1]&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+n},u.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);k(this,e,t,n,i-1,-i)}var s=n-1,o=1,a=0;for(this[t+s]=255&e;--s>=0&&(o*=256);)e<0&&0===a&&0!==this[t+s+1]&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+n},u.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,1,127,-128),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},u.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):M(this,e,t,!0),t+2},u.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):M(this,e,t,!1),t+2},u.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):O(this,e,t,!0),t+4},u.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):O(this,e,t,!1),t+4},u.prototype.writeFloatLE=function(e,t,n){return L(this,e,t,!0,n)},u.prototype.writeFloatBE=function(e,t,n){return L(this,e,t,!1,n)},u.prototype.writeDoubleLE=function(e,t,n){return F(this,e,t,!0,n)},u.prototype.writeDoubleBE=function(e,t,n){return F(this,e,t,!1,n)},u.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var i,s=r-n;if(this===e&&n<t&&t<r)for(i=s-1;i>=0;--i)e[i+t]=this[i+n];else if(s<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i<s;++i)e[i+t]=this[i+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+s),t);return s},u.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===e.length){var i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!u.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;var s;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(s=t;s<n;++s)this[s]=e;else{var o=u.isBuffer(e)?e:B(new u(e,r).toString()),a=o.length;for(s=0;s<n-t;++s)this[s+t]=o[s%a]}return this};var x=/[^+\/0-9A-Za-z-_]/g;function B(e,t){var n;t=t||1/0;for(var r=e.length,i=null,s=[],o=0;o<r;++o){if((n=e.charCodeAt(o))>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===r){(t-=3)>-1&&s.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&s.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;s.push(n)}else if(n<2048){if((t-=2)<0)break;s.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;s.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return s}function $(e){return r.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(x,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function q(e,t,n,r){for(var i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}},249:function(e,t,n){var r;e.exports=(r=r||function(e,t){var r;if("undefined"!=typeof window&&window.crypto&&(r=window.crypto),"undefined"!=typeof self&&self.crypto&&(r=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(r=globalThis.crypto),!r&&"undefined"!=typeof window&&window.msCrypto&&(r=window.msCrypto),!r&&void 0!==n.g&&n.g.crypto&&(r=n.g.crypto),!r)try{r=n(480)}catch(e){}var i=function(){if(r){if("function"==typeof r.getRandomValues)try{return r.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof r.randomBytes)try{return r.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||function(){function e(){}return function(t){var n;return e.prototype=t,n=new e,e.prototype=null,n}}(),o={},a=o.lib={},u=a.Base={extend:function(e){var t=s(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},c=a.WordArray=u.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes,i=e.sigBytes;if(this.clamp(),r%4)for(var s=0;s<i;s++){var o=n[s>>>2]>>>24-s%4*8&255;t[r+s>>>2]|=o<<24-(r+s)%4*8}else for(var a=0;a<i;a+=4)t[r+a>>>2]=n[a>>>2];return this.sigBytes+=i,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=u.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],n=0;n<e;n+=4)t.push(i());return new c.init(t,e)}}),l=o.enc={},h=l.Hex={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],i=0;i<n;i++){var s=t[i>>>2]>>>24-i%4*8&255;r.push((s>>>4).toString(16)),r.push((15&s).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new c.init(n,t/2)}},f=l.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],i=0;i<n;i++){var s=t[i>>>2]>>>24-i%4*8&255;r.push(String.fromCharCode(s))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new c.init(n,t)}},d=l.Utf8={stringify:function(e){try{return decodeURIComponent(escape(f.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return f.parse(unescape(encodeURIComponent(e)))}},p=a.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new c.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=d.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n,r=this._data,i=r.words,s=r.sigBytes,o=this.blockSize,a=s/(4*o),u=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,l=e.min(4*u,s);if(u){for(var h=0;h<u;h+=o)this._doProcessBlock(i,h);n=i.splice(0,u),r.sigBytes-=l}return new c.init(n,l)},clone:function(){var e=u.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),g=(a.Hasher=p.extend({cfg:u.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){p.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new g.HMAC.init(e,n).finalize(t)}}}),o.algo={});return o}(Math),r)},269:function(e,t,n){var r,i,s;e.exports=(r=n(249),s=(i=r).lib.WordArray,i.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,r=this._map;e.clamp();for(var i=[],s=0;s<n;s+=3)for(var o=(t[s>>>2]>>>24-s%4*8&255)<<16|(t[s+1>>>2]>>>24-(s+1)%4*8&255)<<8|t[s+2>>>2]>>>24-(s+2)%4*8&255,a=0;a<4&&s+.75*a<n;a++)i.push(r.charAt(o>>>6*(3-a)&63));var u=r.charAt(64);if(u)for(;i.length%4;)i.push(u);return i.join("")},parse:function(e){var t=e.length,n=this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var i=0;i<n.length;i++)r[n.charCodeAt(i)]=i}var o=n.charAt(64);if(o){var a=e.indexOf(o);-1!==a&&(t=a)}return function(e,t,n){for(var r=[],i=0,o=0;o<t;o++)if(o%4){var a=n[e.charCodeAt(o-1)]<<o%4*2|n[e.charCodeAt(o)]>>>6-o%4*2;r[i>>>2]|=a<<24-i%4*8,i++}return s.create(r,i)}(e,t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},r.enc.Base64)},10:function(e,t,n){var r;e.exports=(r=n(249),n(153),n(824),r.HmacSHA256)},824:function(e,t,n){var r,i,s;e.exports=(i=(r=n(249)).lib.Base,s=r.enc.Utf8,void(r.algo.HMAC=i.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var i=this._oKey=t.clone(),o=this._iKey=t.clone(),a=i.words,u=o.words,c=0;c<n;c++)a[c]^=1549556828,u[c]^=909522486;i.sigBytes=o.sigBytes=r,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,n=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(n))}})))},433:function(e,t,n){var r;e.exports=(r=n(249),function(){if("function"==typeof ArrayBuffer){var e=r.lib.WordArray,t=e.init,n=e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var n=e.byteLength,r=[],i=0;i<n;i++)r[i>>>2]|=e[i]<<24-i%4*8;t.call(this,r,n)}else t.apply(this,arguments)};n.prototype=e}}(),r.lib.WordArray)},153:function(e,t,n){var r;e.exports=(r=n(249),function(e){var t=r,n=t.lib,i=n.WordArray,s=n.Hasher,o=t.algo,a=[],u=[];!function(){function t(t){for(var n=e.sqrt(t),r=2;r<=n;r++)if(!(t%r))return!1;return!0}function n(e){return 4294967296*(e-(0|e))|0}for(var r=2,i=0;i<64;)t(r)&&(i<8&&(a[i]=n(e.pow(r,.5))),u[i]=n(e.pow(r,1/3)),i++),r++}();var c=[],l=o.SHA256=s.extend({_doReset:function(){this._hash=new i.init(a.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],i=n[1],s=n[2],o=n[3],a=n[4],l=n[5],h=n[6],f=n[7],d=0;d<64;d++){if(d<16)c[d]=0|e[t+d];else{var p=c[d-15],g=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,m=c[d-2],y=(m<<15|m>>>17)^(m<<13|m>>>19)^m>>>10;c[d]=g+c[d-7]+y+c[d-16]}var w=r&i^r&s^i&s,_=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22),b=f+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&l^~a&h)+u[d]+c[d];f=h,h=l,l=a,a=o+b|0,o=s,s=i,i=r,r=b+(_+w)|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+s|0,n[3]=n[3]+o|0,n[4]=n[4]+a|0,n[5]=n[5]+l|0,n[6]=n[6]+h|0,n[7]=n[7]+f|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;return n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=e.floor(r/4294967296),n[15+(i+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(l),t.HmacSHA256=s._createHmacHelper(l)}(Math),r.SHA256)},645:(e,t)=>{t.read=function(e,t,n,r,i){var s,o,a=8*i-r-1,u=(1<<a)-1,c=u>>1,l=-7,h=n?i-1:0,f=n?-1:1,d=e[t+h];for(h+=f,s=d&(1<<-l)-1,d>>=-l,l+=a;l>0;s=256*s+e[t+h],h+=f,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=r;l>0;o=256*o+e[t+h],h+=f,l-=8);if(0===s)s=1-c;else{if(s===u)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,r),s-=c}return(d?-1:1)*o*Math.pow(2,s-r)},t.write=function(e,t,n,r,i,s){var o,a,u,c=8*s-i-1,l=(1<<c)-1,h=l>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:s-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-o))<1&&(o--,u*=2),(t+=o+h>=1?f/u:f*Math.pow(2,1-h))*u>=2&&(o++,u/=2),o+h>=l?(a=0,o=l):o+h>=1?(a=(t*u-1)*Math.pow(2,i),o+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),o=0));i>=8;e[n+d]=255&a,d+=p,a/=256,i-=8);for(o=o<<i|a,c+=i;c>0;e[n+d]=255&o,d+=p,o/=256,c-=8);e[n+d-p]|=128*g}},826:e=>{var t={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==t.call(e)}},204:(e,t,n)=>{e.exports=self.fetch||(self.fetch=n(869).default||n(869))},808:(e,t,n)=>{var r,i,s;void 0===(i="function"==typeof(r=s=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(r){function i(){}function s(t,n,s){if("undefined"!=typeof document){"number"==typeof(s=e({path:"/"},i.defaults,s)).expires&&(s.expires=new Date(1*new Date+864e5*s.expires)),s.expires=s.expires?s.expires.toUTCString():"";try{var o=JSON.stringify(n);/^[\{\[]/.test(o)&&(n=o)}catch(e){}n=r.write?r.write(n,t):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var u in s)s[u]&&(a+="; "+u,!0!==s[u]&&(a+="="+s[u].split(";")[0]));return document.cookie=t+"="+n+a}}function o(e,n){if("undefined"!=typeof document){for(var i={},s=document.cookie?document.cookie.split("; "):[],o=0;o<s.length;o++){var a=s[o].split("="),u=a.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var c=t(a[0]);if(u=(r.read||r)(u,c)||t(u),n)try{u=JSON.parse(u)}catch(e){}if(i[c]=u,e===c)break}catch(e){}}return e?i[e]:i}}return i.set=s,i.get=function(e){return o(e,!1)},i.getJSON=function(e){return o(e,!0)},i.remove=function(t,n){s(t,"",e(n,{expires:-1}))},i.defaults={},i.withConverter=n,i}((function(){}))})?r.call(t,n,t,e):r)||(e.exports=i),e.exports=s()},869:(e,t,n)=>{"use strict";function r(e,t){return t=t||{},new Promise((function(n,r){var i=new XMLHttpRequest,s=[],o=[],a={},u=function(){return{ok:2==(i.status/100|0),statusText:i.statusText,status:i.status,url:i.responseURL,text:function(){return Promise.resolve(i.responseText)},json:function(){return Promise.resolve(i.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([i.response]))},clone:u,headers:{keys:function(){return s},entries:function(){return o},get:function(e){return a[e.toLowerCase()]},has:function(e){return e.toLowerCase()in a}}}};for(var c in i.open(t.method||"get",e,!0),i.onload=function(){i.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,n){s.push(t=t.toLowerCase()),o.push([t,n]),a[t]=a[t]?a[t]+","+n:n})),n(u())},i.onerror=r,i.withCredentials="include"==t.credentials,t.headers)i.setRequestHeader(c,t.headers[c]);i.send(t.body||null)}))}n.r(t),n.d(t,{default:()=>r})},296:()=>{},480:()=>{}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,n),s.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{Skapi:()=>Lt,SkapiError:()=>e});class e extends Error{constructor(e,t){if(Array.isArray(e)&&e.length<=2){let n=e[1];if(e.length>2)for(let t=2;t<e.length&&"string"==typeof e[t];t++)n+=e[t];super((n||"Something went wrong.").trim()),this.name=t?.name||"SKAPI",this.code=t?.code||e[0]||"ERROR",t?.cause&&(this.cause=t.cause)}else"string"==typeof e?(super((e||"Something went wrong.").trim()),this.name=t?.name||"SKAPI",this.code=t?.code||"ERROR",t?.cause&&(this.cause=t.cause)):e instanceof Error&&(super((e.message||"Something went wrong.").trim()),this.cause=e,this.name=e.name,e.hasOwnProperty("code")&&(this.code=e.code))}}class t{static hash(e){"string"!=typeof e&&(console.warn("coercing non-string value to empty string"),e="");const n=t.sb(e);let r,i,s,o,a=1732584193,u=-271733879,c=-1732584194,l=271733878;for(let e=0;e<n.length;e+=16)r=a,i=u,s=c,o=l,a=t.ff(a,u,c,l,n[e],7,-680876936),l=t.ff(l,a,u,c,n[e+1],12,-389564586),c=t.ff(c,l,a,u,n[e+2],17,606105819),u=t.ff(u,c,l,a,n[e+3],22,-1044525330),a=t.ff(a,u,c,l,n[e+4],7,-176418897),l=t.ff(l,a,u,c,n[e+5],12,1200080426),c=t.ff(c,l,a,u,n[e+6],17,-1473231341),u=t.ff(u,c,l,a,n[e+7],22,-45705983),a=t.ff(a,u,c,l,n[e+8],7,1770035416),l=t.ff(l,a,u,c,n[e+9],12,-1958414417),c=t.ff(c,l,a,u,n[e+10],17,-42063),u=t.ff(u,c,l,a,n[e+11],22,-1990404162),a=t.ff(a,u,c,l,n[e+12],7,1804603682),l=t.ff(l,a,u,c,n[e+13],12,-40341101),c=t.ff(c,l,a,u,n[e+14],17,-1502002290),u=t.ff(u,c,l,a,n[e+15],22,1236535329),a=t.gg(a,u,c,l,n[e+1],5,-165796510),l=t.gg(l,a,u,c,n[e+6],9,-1069501632),c=t.gg(c,l,a,u,n[e+11],14,643717713),u=t.gg(u,c,l,a,n[e],20,-373897302),a=t.gg(a,u,c,l,n[e+5],5,-701558691),l=t.gg(l,a,u,c,n[e+10],9,38016083),c=t.gg(c,l,a,u,n[e+15],14,-660478335),u=t.gg(u,c,l,a,n[e+4],20,-405537848),a=t.gg(a,u,c,l,n[e+9],5,568446438),l=t.gg(l,a,u,c,n[e+14],9,-1019803690),c=t.gg(c,l,a,u,n[e+3],14,-187363961),u=t.gg(u,c,l,a,n[e+8],20,1163531501),a=t.gg(a,u,c,l,n[e+13],5,-1444681467),l=t.gg(l,a,u,c,n[e+2],9,-51403784),c=t.gg(c,l,a,u,n[e+7],14,1735328473),u=t.gg(u,c,l,a,n[e+12],20,-1926607734),a=t.hh(a,u,c,l,n[e+5],4,-378558),l=t.hh(l,a,u,c,n[e+8],11,-2022574463),c=t.hh(c,l,a,u,n[e+11],16,1839030562),u=t.hh(u,c,l,a,n[e+14],23,-35309556),a=t.hh(a,u,c,l,n[e+1],4,-1530992060),l=t.hh(l,a,u,c,n[e+4],11,1272893353),c=t.hh(c,l,a,u,n[e+7],16,-155497632),u=t.hh(u,c,l,a,n[e+10],23,-1094730640),a=t.hh(a,u,c,l,n[e+13],4,681279174),l=t.hh(l,a,u,c,n[e],11,-358537222),c=t.hh(c,l,a,u,n[e+3],16,-722521979),u=t.hh(u,c,l,a,n[e+6],23,76029189),a=t.hh(a,u,c,l,n[e+9],4,-640364487),l=t.hh(l,a,u,c,n[e+12],11,-421815835),c=t.hh(c,l,a,u,n[e+15],16,530742520),u=t.hh(u,c,l,a,n[e+2],23,-995338651),a=t.ii(a,u,c,l,n[e],6,-198630844),l=t.ii(l,a,u,c,n[e+7],10,1126891415),c=t.ii(c,l,a,u,n[e+14],15,-1416354905),u=t.ii(u,c,l,a,n[e+5],21,-57434055),a=t.ii(a,u,c,l,n[e+12],6,1700485571),l=t.ii(l,a,u,c,n[e+3],10,-1894986606),c=t.ii(c,l,a,u,n[e+10],15,-1051523),u=t.ii(u,c,l,a,n[e+1],21,-2054922799),a=t.ii(a,u,c,l,n[e+8],6,1873313359),l=t.ii(l,a,u,c,n[e+15],10,-30611744),c=t.ii(c,l,a,u,n[e+6],15,-1560198380),u=t.ii(u,c,l,a,n[e+13],21,1309151649),a=t.ii(a,u,c,l,n[e+4],6,-145523070),l=t.ii(l,a,u,c,n[e+11],10,-1120210379),c=t.ii(c,l,a,u,n[e+2],15,718787259),u=t.ii(u,c,l,a,n[e+9],21,-343485551),a=t.ad(a,r),u=t.ad(u,i),c=t.ad(c,s),l=t.ad(l,o);return t.rh(a)+t.rh(u)+t.rh(c)+t.rh(l)}static rh(e){let n="";for(let r=0;r<=3;r++)n+=t.alphabet.charAt(e>>8*r+4&15)+t.alphabet.charAt(e>>8*r&15);return n}static ad(e,t){const n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}static rl(e,t){return e<<t|e>>>32-t}static cm(e,n,r,i,s,o){return t.ad(t.rl(t.ad(t.ad(n,e),t.ad(i,o)),s),r)}static ff(e,n,r,i,s,o,a){return t.cm(n&r|~n&i,e,n,s,o,a)}static gg(e,n,r,i,s,o,a){return t.cm(n&i|r&~i,e,n,s,o,a)}static hh(e,n,r,i,s,o,a){return t.cm(n^r^i,e,n,s,o,a)}static ii(e,n,r,i,s,o,a){return t.cm(r^(n|~i),e,n,s,o,a)}static sb(e){let t;const n=1+(e.length+8>>6),r=new Array(16*n);for(t=0;t<16*n;t++)r[t]=0;for(t=0;t<e.length;t++)r[t>>2]|=e.charCodeAt(t)<<t%4*8;return r[t>>2]|=128<<t%4*8,r[16*n-2]=8*e.length,r}}function i(e){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";if(0===e)return t[0];let n="";for(;e>0;)n=t[e%62]+n,e=Math.floor(e/62);return n}function s(e){return e.split("").reverse().reduce(((e,t,n)=>e+"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".indexOf(t)*62**n),0)}function o(e=6){let t="";let n=0;for(;n<e;)t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random())),n+=1;return t}function a(t){function n(e,t,n){let r=t.slice(0,1),i=t.slice(-1);if("."===r&&(t=t.slice(1)),"."===i&&(t=t.slice(0,-1)),t.includes(".")){let n=t.split(".");t=n.pop();for(let t of n)t&&(e.hasOwnProperty(t)||(e[t]={}),e=e[t])}e.hasOwnProperty(t)?Array.isArray(e[t])?e[t].push(n):e[t]=[e[t],n]:e[t]=n}let r=[];if(t instanceof FormData){let e={},i=0,s=[];for(let o of t.entries()){let t=o[0],a=o[1];if(a instanceof File){if(i+a.size>4e6){r.push({name:t,file:a});continue}i+=a.size,s.push({name:t,file:a})}else if(a instanceof FileList){if(a&&a.length>0)for(let e=0;e<=a.length-1;e++)i+a.item(e).size>4e6?r.push({name:t,file:a.item(e)}):(i+=a.item(e).size,s.push({name:t,file:a.item(e)}))}else n(e,t,a)}return{meta:e,files:s,to_bin:r}}if(t instanceof SubmitEvent&&(t=t.target),t instanceof HTMLFormElement){let s={},o=[],a=0,u=t.querySelectorAll("input"),c=t.querySelectorAll("textarea");for(let e=0;e<c.length;e++){let t=c[e];t.name&&n(s,t.name,t.value)}for(let e=0;e<u.length;e++){let t=u[e];if(t.name)if("number"===t.type)t.value&&n(s,t.name,Number(t.value));else if("checkbox"===t.type||"radio"===t.type)t.checked?""===t.value&&"checkbox"===t.type||"on"===t.value||"true"===t.value?n(s,t.name,!0):"false"===t.value?n(s,t.name,!1):t.value&&n(s,t.name,t.value):"checkbox"===t.type&&(""===t.value||"on"===t.value||"true"===t.value?n(s,t.name,!1):"false"===t.value?n(s,t.name,!0):n(s,t.name,void 0));else if("file"===t.type){if(t.files&&t.files.length>0)for(let e=0;e<=t.files.length-1;e++)a+t.files.item(e).size>4e6?r.push({name:t.name,file:t.files.item(e)}):(a+=t.files.item(e).size,o.push({name:t.name,file:t.files.item(e)}))}else n(s,t.name,t.value)}if(i=s,new Blob([JSON.stringify(i)]).size>2097152)throw new e("JSON Data should not exceed 2MB",{code:"INVALID_REQUEST"});return{meta:s,files:o,to_bin:r}}var i;return null}t.alphabet="0123456789abcdef";const u={UserId:function(t,n="User ID"){if(!t)throw new e(`${n} is empty.`,{code:"INVALID_PARAMETER"});if("string"!=typeof t)throw new e(`${n} should be type: string.`,{code:"INVALID_PARAMETER"});if(!t.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i))throw new e(`${n} is invalid.`,{code:"INVALID_PARAMETER"});return t},PhoneNumber:function(t){if(t&&("string"!=typeof t||"+"!==t.charAt(0)||isNaN(Number(t.substring(1)))))throw new e('"phone_number" is invalid. The format should be "+00123456789". Type: string.',{code:"INVALID_PARAMETER"});return t||""},Birthdate:function(t){if(t){if("string"!=typeof t)throw new e('"birthdate" is invalid. The format should be "yyyy-mm-dd". Type: string.',{code:"INVALID_PARAMETER"});{let n=new RegExp(/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/);if(10!==t.length||3!==t.split("-").length||!n.test(t))throw new e('"birthdate" is invalid. The format should be "yyyy-mm-dd". Type: string.',{code:"INVALID_PARAMETER"})}}return t||""},Password:function(t){if(!t)throw new e('"password" is required.',{code:"INVALID_PARAMETER"});if("string"!=typeof t)throw new e('"password" should be type: string.',{code:"INVALID_PARAMETER"});if(t.length<6)throw new e('"password" should be at least 6 characters.',{code:"INVALID_PARAMETER"});if(t.length>60)throw new e('"password" can be up to 60 characters max.',{code:"INVALID_PARAMETER"});return t},Email:function(t,n="email"){if(!t)throw new e(`"${n}" is required.`,{code:"INVALID_PARAMETER"});if("string"!=typeof t)throw new e(`"${n}"should be type: string.`,{code:"INVALID_PARAMETER"});if(t.length<5)throw new e(`"${n}" should be at least 5 characters.`,{code:"INVALID_PARAMETER"});if(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(t)&&(t=t.trim()).split("@")[1].split(".").length>=2)return t.toLowerCase();throw new e(`"${t}" is an invalid email.`,{code:"INVALID_PARAMETER"})},Url:function(t){const n=(()=>{let e=window.location.origin||null;return e&&"/"===e.slice(-1)&&(e=e.slice(0,-1)),e})();let r=t=>{if("string"==typeof t){if("*"===t)return"*";{let r,i=t.trim();if("/"===i[0]&&n){if("file:"===n.slice(0,5))throw new e(`"${t}" is an invalid url. Relative URL does not work on local file system. Use full URL string.`,{code:"INVALID_PARAMETER"});i=n+i}else if("."===i[0]&&n){if("file:"===n.slice(0,5))throw new e(`"${t}" is an invalid url. Relative URL does not work on local file system. Use full URL string.`,{code:"INVALID_PARAMETER"});let r=window.location.href.split("?")[0];"/"!==r.slice(-1)&&(r+="/"),i=r+i.slice(1)}try{r=new URL(i)}catch(n){throw new e(`"${t}" is an invalid url.`,{code:"INVALID_PARAMETER"})}if(r.protocol)return r.href}}throw new e(`"${t}" is an invalid url.`,{code:"INVALID_PARAMETER"})};return Array.isArray(t)?t.map((e=>r(e))):r(t)},specialChars:function(t,n="parameter",r=!1,i=!1){let s=t=>{if("string"!=typeof t)throw new e(`${n} should be type: <string | string[]>.`,{code:"INVALID_PARAMETER"});if(!i&&t.includes(" "))throw new e(`${n} should not have whitespace.`,{code:"INVALID_PARAMETER"});if(!r&&t.includes("."))throw new e(`${n} should not have periods.`,{code:"INVALID_PARAMETER"});if(/[!@#$%&*()+\-={};':"\|,<>\/?~]/.test(t))throw new e(`${n} should not have special characters.`,{code:"INVALID_PARAMETER"})};if(Array.isArray(t))for(let e of t)s(e);else s(t);return t},Params:function t(n,r,i=null,s=[],o=null){function u(t){if(t instanceof Promise)throw new e("Parameter should not be a promise",{code:"INVALID_PARAMETER"});return t&&"object"==typeof t&&!Array.isArray(t)&&Object.keys(t).length}Array.isArray(s)&&(s=s.concat(["service","owner"]));let c,l=n,h=null,f=o?` in "${o}" is invalid.`:". Parameter should be type <object>.";if(null===o){if(u(l)){l=l instanceof HTMLFormElement||l instanceof FormData||l instanceof SubmitEvent?a(n)?.meta:JSON.parse(JSON.stringify(n));for(let t in l)if(!r.hasOwnProperty(t)&&Array.isArray(s)&&!s.includes(t))throw new e(`Key name "${t}" is invalid in parameter.`,{code:"INVALID_PARAMETER"});if(Array.isArray(i)&&i.length)for(let t of i)if(!Object.keys(l).includes(t))throw new e(`Key "${t}" is required in parameter.`,{code:"INVALID_PARAMETER"})}else if((d=l)&&"object"==typeof d&&!Array.isArray(d)&&!Object.keys(d).length||void 0===l){let e={};for(let t in r){let n=r[t];Array.isArray(n)&&"function"==typeof n[n.length-1]&&(e[t]=n[n.length-1]())}return Object.keys(e).length?e:l}if(null===l)return null}var d;if(u(r)&&u(l)){for(let e in r){let n=r[e];if(l.hasOwnProperty(e)&&null===l[e])l[e]=null;else if(l.hasOwnProperty(e)&&void 0!==l[e])l[e]=t(l[e],n,null,null,e);else{let t=Array.isArray(n)&&"function"==typeof n[n.length-1]?n[n.length-1]:null;if(t){let n=t();void 0!==n&&(l[e]=n)}}}c=l}else if(Array.isArray(r))for(let n of r)try{void 0!==typeof l&&"function"!=typeof n&&(c=t(l,n,null,null,o));break}catch(t){if("string"==typeof t&&"BREAK:"===t.substring(0,6)){let n=(t=t.substring(6)).split(":");h=new e(n[1],{code:n[0]});break}h=t}else{if("function"==typeof r)return r(l);if("string"==typeof r)if(Array.isArray(l)){if("array"!==r)throw new e(`Invalid type "${typeof l}"${f}`,{code:"INVALID_PARAMETER"});for(let t of l)if(!["number","string","boolean"].includes(typeof t)&&null!==t)throw new e(`Invalid type "${typeof t}" in "${o}" array value.`,{code:"INVALID_PARAMETER"});c=l}else if(["number","string","boolean","array","function"].includes(r)){if(typeof l!==r)throw new e(`Value: ${l}${f}`,{code:"INVALID_PARAMETER"});if("number"===r&&Math.abs(l)>4503599627370496)throw`BREAK:INVALID_PARAMETER:"${o}" integer value should be within -4503599627370496 ~ +4503599627370546.`;c=l}else{if(l!==r)throw new e(`Value: ${l}${f}`,{code:"INVALID_PARAMETER"});c=l}else null===r&&(c=l)}if(void 0===c&&h)throw h;return c}};async function c(e,t){const n=await Promise.all([this.admin_endpoint,this.record_endpoint]),r=n[0],i=n[1];let s=e.split("?"),o=s.length>1?"?"+s[1]:"";switch(e=s[0]){case"get-newsletters":case"get-public-newsletters":case"get-users":case"post-userdata":case"remove-account":case"post-secure":case"subscribe-newsletter":case"subscribe-public-newsletter":case"signup":case"confirm-signup":case"recover-account":case"mock":case"service":case"grant-access":case"last-verified-email":case"ticket":case"register-ticket":case"get-newsletter-subscription":case"request-username-change":case"jwt-login":case"client-secret-request":return(t?r.admin_private:r.admin_public)+e+o;case"post-record":case"get-records":case"subscription":case"get-subscription":case"del-records":case"get-table":case"get-tag":case"get-index":case"get-signed-url":case"grant-private-access":case"request-private-access-key":case"get-ws-group":case"del-files":return(t?i.record_private:i.record_public)+e+o;default:return u.Url(e)}}const l={};async function h(n,r=null,i){i=i||{};let{auth:s=!1,method:o="post",bypassAwaitConnection:a=!1}=i;o=o.toUpperCase();let h=null,g=this.service,m=this.owner,y=null,w=await c.bind(this)(n,!!s);if(!a&&(h=await this.__connection,!h))throw new e("Invalid connection. The service could have been disabled, or has a restricted CORS.",{code:"INVALID_REQUEST"});if(s){if(!this.session)throw this.logout(),new e("User login is required.",{code:"INVALID_REQUEST"});{let t=Date.now()/1e3;if(this.session.idToken.payload.exp<t)try{await this.authentication().getSession({refreshToken:!0})}catch(t){throw this.logout(),new e("User login is required.",{code:"INVALID_REQUEST"})}y=this.session?.idToken?.jwtToken}}let _={},{fetchMore:b=!1,progress:A}=i?.fetchOptions||{};if(i?.fetchOptions&&Object.keys(i.fetchOptions).length){for(let e of["limit","startKey","ascending"])i.fetchOptions.hasOwnProperty(e)&&(_[e]=i.fetchOptions[e]);_=u.Params(_,{limit:t=>{if("number"!=typeof t)throw new e("Fetch limit should be a number.",{code:"INVALID_REQUEST"});if(t>1e3)throw new e("Fetch limit should be below 1000.",{code:"INVALID_REQUEST"});return t},startKey:e=>e,ascending:"boolean"})}let v={service:g,owner:m};Object.assign(v,_),r instanceof SubmitEvent&&(r=r?.target),r instanceof HTMLFormElement&&(r=new FormData(r));let E=r instanceof FormData;if(r)if(E)for(let e in v)void 0!==v[e]&&r.set(e,new Blob([JSON.stringify(v[e])],{type:"application/json"}));else r=Object.assign(v,r);else r=v;let S=(()=>{if(r&&"object"==typeof r&&Object.keys(r).length&&!(r instanceof FormData)){function e(t){return"object"==typeof t&&null!==t?Object.keys(t).sort().reduce(((n,r)=>("object"==typeof t[r]&&null!==t[r]?n[r]=e(t[r]):n[r]=t[r],n)),{}):t}return t.hash(n+"/"+JSON.stringify(e(r)))}return t.hash(n+"/"+this.service)})(),I=f.bind(this)({params:r,url:n,fetchMore:b,hashedParams:S});if(!I||I&&"object"==typeof I)return I;if(l[I]instanceof Promise)return l[I];let R={Accept:"*/*","Content-Type":i?.contentType||r instanceof FormData?"multipart/form-data":"application/json"};y&&(R.Authorization=y);let T={headers:R};if(i?.responseType&&(T.responseType=i.responseType),"GET"===o){if(r){let e=[];if(r instanceof FormData)for(let[t,n]of r.entries())"string"==typeof n&&(n=encodeURIComponent(n),e.push(`&${t}=${n}`));else e=Object.keys(r).map((e=>{let t=r[e];return"string"!=typeof t&&(t=JSON.stringify(t)),encodeURIComponent(e)+"="+encodeURIComponent(t)}));e.length&&("?"!==w.substring(w.length-1)&&(w+="?"),w+=e.join("&"))}T.body=null}else T.body=r instanceof FormData?r:r?JSON.stringify(r):null;T.method=o,l[I]=d.bind(this)(w,T,A);try{return p.bind(this)({hashedParam:I,url:n,fetched:await l[I]})}finally{I&&l.hasOwnProperty(I)&&delete l[I]}}function f(n){let{params:r={},url:i,fetchMore:s=!1,hashedParams:o}=n||{};if(r.startKey){if(("object"!=typeof r.startKey||!Object.keys(r.startKey).length)&&"start"!==r.startKey&&"end"!==r.startKey)throw new e(`"${r.startKey}" is invalid startKey key.`,{code:"INVALID_PARAMETER"});"start"===r.startKey&&(s=!1,delete r.startKey)}if(!s&&this.__startKeyHistory?.[i]?.[o]){if(this.__cached_requests?.[i]?.[o]&&delete this.__cached_requests[i][o],Array.isArray(this.__startKeyHistory[i][o])&&this.__startKeyHistory[i][o].length)for(let e of this.__startKeyHistory[i][o]){let n=o+t.hash(e);this.__cached_requests?.[i]&&this.__cached_requests?.[i]?.[n]&&delete this.__cached_requests[i][n]}return delete this.__startKeyHistory[i][o],o}if(!Array.isArray(this.__startKeyHistory?.[i]?.[o]))return o;let a=this.__startKeyHistory[i][o],u=a[a.length-1],c=o;if(u){if("end"===u)return{list:[],startKey:"end",endOfList:!0,startKeyHistory:a};c+=t.hash(u),r.startKey=JSON.parse(u)}return this.__cached_requests?.[i]?.[c]?this.__cached_requests[i][c]:o}function d(t,n,r){return new Promise(((i,s)=>{let o=new XMLHttpRequest;for(var a in o.open(n.method||"GET",t),n.headers||{})o.setRequestHeader(a,n.headers[a]);n.responseType&&(o.responseType=n.responseType),o.onload=()=>{if(o.status<400)if("json"==n.responseType||"blob"==n.responseType)i(o.response);else{let e=o.responseText;try{e=JSON.parse(e)}catch(e){}i(e)}else{let t=o.status,n=["INVALID_CORS","INVALID_REQUEST","SERVICE_DISABLED","INVALID_PARAMETER","ERROR","EXISTS","NOT_EXISTS"],r=o.responseText;try{r=JSON.parse(r)}catch(e){}if("string"==typeof r){let t=o.response.split(":"),r=t.splice(0,1)[0].trim();s(new e(t.join(":").trim(),{code:n.includes(r)?r:"ERROR"}))}else if("object"==typeof r&&r?.message){let n=r?.code||(t?t.toString():null)||"ERROR",i=r.message;"string"==typeof i&&(i=i.trim()),s(new e(i,{code:n}))}else s(r)}},o.onerror=()=>s("Network error"),o.onabort=()=>s("Aborted"),o.ontimeout=()=>s("Timeout"),"function"==typeof r&&(o.onprogress=e=>{r({status:"download",progress:e.loaded/e.total*100,loaded:e.loaded,total:e.total,abort:()=>o.abort()})},o.upload&&(o.upload.onprogress=e=>{r({status:"upload",progress:e.loaded/e.total*100,loaded:e.loaded,total:e.total,abort:()=>o.abort()})})),o.send(n.body)}))}function p(e){let{hashedParam:t,url:n,fetched:r}=e;if(!r?.startKey)return r;this.__startKeyHistory.hasOwnProperty(n)||(this.__startKeyHistory[n]={}),this.__cached_requests?.[n]||(this.__cached_requests[n]={}),this.__cached_requests[n][t]=r,this.__startKeyHistory[n].hasOwnProperty(t)||(this.__startKeyHistory[n][t]=[]);let i="end"===r.startKey?"end":JSON.stringify(r.startKey);return this.__startKeyHistory[n][t].includes(i)||this.__startKeyHistory[n][t].push(i),Object.assign({startKeyHistory:this.__startKeyHistory[n][t]},r)}async function g(t,n){await this.__connection;let{service:r,dir:s="",progress:a}=n;if(s&&(s=s.replace(/^\//,"").replace(/\/$/,"")+"/"),!r||r===this.service)throw new e("invalid service.",{code:"INVALID_PARAMETER"});if(!(t instanceof FormData))throw new e('"fileList" should be a FormData or HTMLFormElement.',{code:"INVALID_PARAMETER"});let u,c={reserved_key:o(),service:r,request:"host"},l=(e,t,n)=>new Promise(((r,i)=>{u=new XMLHttpRequest,u.open("POST",e),u.onload=()=>{let e=u.responseText;try{e=JSON.parse(e)}catch(e){}u.status>=200&&u.status<300?r(e):i(e)},u.onerror=()=>i("Network error"),u.onabort=()=>i("Aborted"),u.ontimeout=()=>i("Timeout"),u.upload&&"function"==typeof n&&(u.upload.onprogress=n),u.send(t)})),f=[],d=[],p=[];for(let[e,n]of t.entries()){if(!(n instanceof File))continue;let e=Object.assign({key:s+n.name,sizeKey:i(n.size),contentType:n.type||null},c),{fields:t=null,url:r,cdn:o}=await h.bind(this)("get-signed-url",e,{auth:!0});p.push(o);let g=new FormData;for(let e in t)g.append(e,t[e]);g.append("file",n);try{await l(r,g,"function"==typeof a?e=>a({status:"upload",progress:e.loaded/e.total*100,currentFile:n,completed:f,failed:d,loaded:e.loaded,total:e.total,abort:()=>u.abort()}):null),f.push(n)}catch(e){d.push(n)}}return{completed:f,failed:d,bin_endpoints:p}}async function m(t,n){await this.__connection;let{record_id:r,service:i=this.service,progress:s}=n;if(!r)throw new e('"record_id" is required.',{code:"INVALID_PARAMETER"});if(t instanceof SubmitEvent&&(t=t.target),t instanceof HTMLFormElement&&(t=new FormData(t)),!(t instanceof FormData))throw new e('"fileList" should be a FormData or HTMLFormElement.',{code:"INVALID_PARAMETER"});let a,u={reserved_key:o(),service:i,request:"post"};n?.record_id&&(u.id=n.record_id);let c=(e,t,n)=>new Promise(((r,i)=>{a=new XMLHttpRequest,a.open("POST",e),a.onload=()=>{let e=a.responseText;try{e=JSON.parse(e)}catch(e){}a.status>=200&&a.status<300?r(e):i(e)},a.onerror=()=>i("Network error"),a.onabort=()=>i("Aborted"),a.ontimeout=()=>i("Timeout"),a.upload&&"function"==typeof n&&(a.upload.onprogress=n),a.send(t)})),l=[],f=[];function d(e){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";if(0===e)return t[0];let n="";for(;e>0;)n=t[e%62]+n,e=Math.floor(e/62);return n}let p=[];for(let[e,n]of t.entries()){if(!(n instanceof File))continue;let t=Object.assign({key:e+"/"+n.name,sizeKey:d(n.size),contentType:n.type||null},u),{fields:r=null,url:i,cdn:o}=await h.bind(this)("get-signed-url",t,{auth:!0});p.push(o);let g=new FormData;for(let e in r)g.append(e,r[e]);g.append("file",n);try{await c(i,g,"function"==typeof s?e=>s({status:"upload",progress:e.loaded/e.total*100,currentFile:n,completed:l,failed:f,loaded:e.loaded,total:e.total,abort:()=>a.abort()}):null),l.push(n)}catch(e){f.push(n)}}return{completed:l,failed:f,bin_endpoints:p}}const y={};function w(n){let{preventMultipleCalls:r=!1}=n||{};return function(n,i,s){const o=s.value;s.value=function(...n){let s=n[0],a=!0,u=null,c="",l={};if(s instanceof SubmitEvent){s.preventDefault();let e=window.location.href;u=s.target;let t=new URL(u.action);c=t.href;let n=c?c.match(/(?<=\{).*?(?=\})/g):"";if(n)for(let e of n){if(!e)continue;let t=u.querySelector(`[name="${e}"]`);if(t)if("file"===t.type)for(let n=0;n<=t.files.length-1;n++)t.files[n]&&(l[e]||(l[e]=[]),l[e].push(new Promise(((e,r)=>{let i=new FileReader;i.onload=function(){e(i.result)},i.readAsDataURL(t.files[n]),i.onerror=r}))));else c=c.replace(`{${e}}`,t.value)}u.action&&t.href!==e||(a=!1)}const h=async e=>{if(c)for(let e in l)l[e].length&&(c=c.replace(`{${e}}`,(await Promise.all(l[e])).join(",")));return u&&a&&(window.sessionStorage.setItem(`${this.service}:${t.hash(c)}`,JSON.stringify(e)),window.location.href=c),e};let f;const d=async()=>{try{if(f=o.bind(this)(...n),f instanceof Promise){let e=await f;return await h(e),f}}catch(t){throw(t=>{throw t instanceof e?t.name=i+"()":t=t instanceof Error?t:new e(t,{name:i+"()"}),t})(t)}};return r?(y?.[i]||(y[i]=d().finally((()=>{delete y[i]}))),y[i]):d()}}}async function _(){await this.__connection;let e=`${this.service}:${t.hash(window.location.href.split("?")[0])}`,n=window.sessionStorage.getItem(e);if(null!==n){try{n=JSON.parse(n)}catch(e){}return n}return null}const b=4503599627370496;function A(t){const n={user_id:"",record_id:"",updated:0,uploaded:0,table:{name:"",access_group:0},reference:{reference_limit:null,allow_multiple_reference:!0,referenced_count:0},ip:"",bin:{}},r={ip:e=>{"R"===e.slice(-1)?(n.readonly=!0,e=e.slice(0,-1)):n.readonly=!1,n.ip=e},rec:e=>{if(!e)return;n.record_id=e;let t=s(e.substring(0,e.length-9));n.uploaded=t},usr:e=>{n.user_id=e},tbl:e=>{if(!e)return;let t=e.split("/");n.table.name=t[0],n.table.access_group="**"==t[2]?"private":parseInt(t[2]),n.table.subscription=!!t?.[3]},usr_tbl:e=>{let t=e.split("/");n.user_id=t[0],n.table.name=t[1],n.table.access_group="**"==t[3]?"private":parseInt(t[3]),n.table.subscription=!!t?.[4]},idx:t=>{if(!t)return;let r=t.split("!"),i=r.splice(0,1)[0],s=function(t){let n=t.substring(3);switch(t.substring(0,3)){case"!S%":return n;case"!N%":let r=n.split("."),i=Number(r[0])-4503599627370496;return 1===r.length?i:parseFloat(i.toString()+"."+r[1]);case"!B%":return"1"===n;case"!L%":case"!D%":try{return JSON.parse(n)}catch(t){throw new e("Value parse error.",{code:"PARSE_ERROR"})}default:return t}}("!"+r.join("!"));n.index={name:i,value:s}},ref:e=>{e&&(n.reference.record_id=e.split("/")[0])},tags:e=>{n.tags=e},upd:e=>{n.updated=e},acpt_mrf:e=>{n.reference.allow_multiple_reference=e},ref_limt:e=>{n.reference.reference_limit=e},rfd:e=>{n.reference.referenced_count=e},bin:e=>{let t={};if(Array.isArray(e))for(let n of e){let e=n.split("/").slice(3).join("/"),r=e.split("/"),i=decodeURIComponent(r.slice(-1)[0]),o=decodeURIComponent(r[10]),a=r[9],u=r[8],c="**"==r[6]?"private":parseInt(r[6]);c=0==c?"public":1==c?"authorized":c;let l={access_group:c,filename:i,url:n,path:e,size:s(a),uploaded:s(u),getFile:(e,t)=>{let r={dataType:e||"download",progress:t};return E.bind(this)(n,r)}};t[o]?t[o].push(l):t[o]=[l]}n.bin=t},data:e=>{let t=e;"!D%{}"===e?t={}:"!L%[]"===e&&(t=[]),n.data=t}};if(t.record_id)return t;for(let e in r)t.hasOwnProperty(e)&&r[e](t[e]);return t.private_key&&(this.__private_access_key[n.record_id]=t.private_key),n}async function v(t){let{endpoints:n}=t;if("string"==typeof n&&(n=[n]),!Array.isArray(n))throw new e('"endpoints" should be type: array | string.',{code:"INVALID_PARAMETER"});return h.bind(this)("del-files",{endpoints:n,storage:"records"},{auth:!0,method:"post"}).map((e=>A.bind(this)(e)))}async function E(t,n){if("string"!=typeof t)throw new e('"url" should be type: string.',{code:"INVALID_PARAMETER"});u.Url(t);let r=!1,i=t.split("/"),s=i[2].split("."),o=null;3===s.length&&"skapi"===s[1]&&(o=s[0],r=!0);let a=i.slice(3);if(!r){if("auth"!==a[0]&&"publ"!==a[0])throw new e("Invalid file url.",{code:"INVALID_PARAMETER"});try{u.UserId(a[2]),u.UserId(a[3])}catch{throw new e("Invalid file url.",{code:"INVALID_PARAMETER"})}}let c=o?null:a[1];n=u.Params(n,{expires:"number",dataType:["base64","blob","endpoint","download",()=>"download"],progress:e=>e});let l="auth"==a[0],f=t.split("/").slice(-1)[0],d=n?.expires||0;if(d){if(d<0)throw new e('"config.expires" should be > 0. (seconds)',{code:"INVALID_PARAMETER"});let n={request:o?"get-host":"get",id:o||a[5],key:t,expires:d};c&&(n.service=c),t=(await h.bind(this)("get-signed-url",n,{auth:!0})).url}else if(l){let n=this.session?.idToken?.jwtToken,r="**"===a[6]?"**":parseInt(a[6]);if(!n)throw new e("User login is required.",{code:"INVALID_REQUEST"});{let t=Date.now()/1e3;if(this.session.idToken.payload.exp<t)try{await this.authentication().getSession({refreshToken:!0}),n=this.session?.idToken?.jwtToken}catch(t){throw this.logout(),new e("User login is required.",{code:"INVALID_REQUEST"})}}if("**"===r){if(this.__user.user_id!==a[3])throw new e("User has no access.",{code:"INVALID_REQUEST"})}else if(this.__user.access_group<r)throw new e("User has no access.",{code:"INVALID_REQUEST"});t+=`?t=${n}`}if("endpoint"===n?.dataType)return t;if("download"===n?.dataType){let e=document.createElement("a");return e.href=t,document.body.appendChild(e),e.setAttribute("download",f),e.target="_blank",e.click(),document.body.removeChild(e),null}return new Promise((async(e,r)=>{try{let r=await h.bind(this)(t,{service:c||this.service},{method:"get",noParams:!0,contentType:null,responseType:"blob",fetchOptions:{progress:n?.progress}});if("base64"===n?.dataType){const t=new FileReader;t.onloadend=()=>e(t.result),t.readAsDataURL(r)}}catch(e){r(e)}}))}async function S(t,n){await this.__connection;const r={$updated:"number",$uploaded:"number",$referenced_count:"number"};"string"==typeof t?.table&&(t.table={name:t.table,access_group:0});const i={table:{name:"string",access_group:["number","private","public","authorized"],subscription:e=>u.UserId(e,'User ID in "subscription"')},reference:"string",index:{name:t=>{if("string"!=typeof t)throw new e('"index.name" should be type: string.',{code:"INVALID_PARAMETER"});return r.hasOwnProperty(t)||["$uploaded","$updated","$referenced_count","$user_id"].includes(t)?t:u.specialChars(t,"index.name",!0,!1)},value:n=>{if(t.index?.name&&r.hasOwnProperty(t.index.name)){let i=r[t.index.name];if(typeof n===i)return n;throw new e(`"index.value" should be type: ${i}.`,{code:"INVALID_PARAMETER"})}if("number"==typeof n){if(n>b||n<-4503599627370496)throw new e("Number value should be within range -4503599627370496 ~ +4503599627370496",{code:"INVALID_PARAMETER"});return n}return"boolean"==typeof n?n:"$user_id"==t.index?.name?u.UserId(n):u.specialChars(n,"index.value",!1,!0)},condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"],range:n=>{if(!t.index||!("value"in t.index))throw new e('"index.value" is required.',{code:"INVALID_PARAMETER"});if("$record_id"===t.index.name)throw new e(`Cannot do "index.range" on ${t.index.name}`,{code:"INVALID_PARAMETER"});if(typeof t.index.value!=typeof n)throw new e('"index.range" type should match the type of "index.value".',{code:"INVALID_PARAMETER"});return"string"==typeof n?u.specialChars(n,"index.range",!1,!0):n}},tag:"string",private_key:"string"};if(t?.tag&&u.specialChars(t.tag,"tag",!1,!0),t?.table){if("public"===t.table.access_group?t.table.access_group=0:"authorized"===t.table.access_group&&(t.table.access_group=1),t.table?.name&&u.specialChars(t.table.name,"table name",!0,!0),"number"==typeof t.table.access_group)if(this.__user){if(this.user.access_group<t.table.access_group)throw new e("User has no access",{code:"INVALID_REQUEST"})}else if(0<t.table.access_group)throw new e("User has no access",{code:"INVALID_REQUEST"});t.table.hasOwnProperty("access_group")||(t.table.access_group=t.table?.subscription?1:0)}if(t?.index&&!t.index?.name)throw new e('"index.name" is required when using "index" parameter.',{code:"INVALID_REQUEST"});let s="";if(t?.record_id){u.specialChars(t.record_id,"record_id",!1,!1);let e={record_id:t.record_id};t?.service&&(e.service=t.service),t=e,this.__private_access_key[t.record_id]&&(t.private_key=this.__private_access_key[t.record_id])}else{let n;if(!this.session&&"private"===t.table?.access_group)throw new e("Unsigned users have no access to private records.",{code:"INVALID_REQUEST"});if(t.reference)try{n=u.UserId(t.reference)}catch(e){u.specialChars(t.reference,"reference",!1,!1),s=t.reference,this.__private_access_key[s]&&(t.private_key=this.__private_access_key[s])}let r=await this.checkAdmin(),o=u.Params(t||{},i,n||r?[]:["table"]);if("string"!=typeof o.table&&o.table?.subscription){if(!this.session)throw new e("Unsigned users have no access to subscription records.",{code:"INVALID_REQUEST"});o.table.subscription={user_id:o.table.subscription,group:1}}t=o}let o=!(!t.hasOwnProperty("access_group")||"string"==typeof t.table||!t.table.access_group)||!!this.__user,a=await h.bind(this)("get-records",t,{fetchOptions:n,auth:o,method:o?"post":"get"});for(let e in a.list)a.list[e]=A.bind(this)(a.list[e]);return s&&a?.reference_private_key&&(this.__private_access_key[s]=a.reference_private_key),a}async function I(t,n){let r=await this.checkAdmin();if(!n)throw new e('"config" argument is required.',{code:"INVALID_PARAMETER"});if(!this.user)throw new e("Login is required.",{code:"INVALID_REQUEST"});let i={};"string"==typeof n.table&&(n.table={name:n.table},n.record_id||(n.table.access_group=0)),"string"==typeof n.reference&&(n.reference={record_id:n.reference});let s=n.progress||null,o=null,c=u.Params(n||{},{record_id:"string",readonly:"boolean",table:{name:"string",subscription:"boolean",access_group:["number","private","public","authorized"]},reference:{record_id:e=>(u.specialChars(e,'"reference.record_id"',!1,!1),this.__private_access_key[e]&&(o=this.__private_access_key[e]),e),reference_limit:t=>{if(null===t)return null;if("number"==typeof t){if(0>t)throw new e('"reference_limit" should be >= 0',{code:"INVALID_PARAMETER"});if(t>4503599627370546)throw new e('"reference_limit" should be <= 4503599627370546',{code:"INVALID_PARAMETER"});return t}throw new e('"reference_limit" should be type: <number | null>',{code:"INVALID_PARAMETER"})},allow_multiple_reference:"boolean"},index:{name:"string",value:["string","number","boolean"]},tags:t=>{if(null===t)return t;if("string"==typeof t)return t.split(",").map((e=>e.trim()));if(Array.isArray(t)){for(let n of t){if("string"!=typeof n)throw new e('"tags" should be type: <string | string[]>',{code:"INVALID_PARAMETER"});u.specialChars(t,"tag",!1,!0)}return t}throw new e('"tags" should be type: <string | string[]>',{code:"INVALID_PARAMETER"})},remove_bin:t=>{if(!t)return null;let n=[];if(!Array.isArray(t))throw new e('"remove_bin" should be type: <string[] | BinaryFile[]>',{code:"INVALID_PARAMETER"});for(let r of t)if("string"==typeof r)n.push(r);else{if(!(r.url&&r.size&&r.filename))throw new e('"remove_bin" should be type: <string[] | BinaryFile[]>',{code:"INVALID_PARAMETER"});n.push(r.url)}return n}},[],["response","onerror","progress"],null);if(!c?.table&&!c?.record_id)throw new e('Either "record_id" or "table" should have a value.',{code:"INVALID_PARAMETER"});if(c.table){if("public"===c.table.access_group?c.table.access_group=0:"authorized"===c.table.access_group&&(c.table.access_group=1),"number"==typeof c.table.access_group&&!r&&this.user.access_group<c.table.access_group)throw new e("User has no access",{code:"INVALID_REQUEST"});if(!c.table.name)throw new e('"table.name" cannot be empty string.',{code:"INVALID_PARAMETER"});if(u.specialChars(c.table.name,"table name",!0,!0),r&&!c.record_id&&"private"===c.table.access_group)throw new e("Service owner cannot write private records.",{code:"INVALID_REQUEST"});if(c.table?.subscription){if(c?.record_id||c.table.hasOwnProperty("access_group")||(c.table.access_group=1),0===c.table.access_group)throw new e("Public records cannot require subscription.",{code:"INVALID_REQUEST"});c.table.subscription_group=1,delete c.table.subscription}}if(delete(n=c).progress,o&&(n.reference_private_key=o),n.index){if(!n.index.name||"string"!=typeof n.index.name)throw new e('"index.name" is required. type: string.',{code:"INVALID_PARAMETER"});if(["$uploaded","$updated","$referenced_count","$user_id"].includes(n.index.name)||u.specialChars(n.index.name,"index name",!0),!n.index.hasOwnProperty("value"))throw new e('"index.value" is required.',{code:"INVALID_PARAMETER"});if("string"==typeof n.index.value)u.specialChars(n.index.value,"index value",!1,!0);else if("number"==typeof n.index.value&&(n.index.value>b||n.index.value<-4503599627370496))throw new e("Number value should be within range -4503599627370496 ~ +4503599627370496",{code:"INVALID_PARAMETER"})}let l={auth:!0},f=null,d=null;if(t instanceof HTMLFormElement||t instanceof FormData||t instanceof SubmitEvent){let e=a(t=t instanceof SubmitEvent?t.target:t);if(e.to_bin.length&&(d=e.to_bin),e.files.length){d||(d=[]);for(let t of e.files)d.push(t)}f=Object.assign({data:e.meta},n)}else f=Object.assign({data:t},n);"function"==typeof s&&(i.progress=s),Object.keys(i).length&&Object.assign(l,{fetchOptions:i});let p=await h.bind(this)("post-record",f,l);if(d){let e=new FormData;for(let t of d)e.append(t.name,t.file,t.file.name);let t={record_id:p.rec,progress:s};n.hasOwnProperty("service")&&(t.service=n.service);let{bin_endpoints:r}=await m.bind(this)(e,t);p.bin?p.bin.push(...r):p.bin=r}return A.bind(this)(p)}async function R(e,t){let n=await h.bind(this)("get-table",u.Params(e||{},{table:"string",condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}),Object.assign({auth:!0},{fetchOptions:t})),r={cnt_rec:"number_of_records",tbl:"table",srvc:"service"};if(Array.isArray(n?.list))for(let e of n.list)for(let t in r)e.hasOwnProperty(t)&&(e[r[t]]=e[t],delete e[t]);return n}async function T(t,n){if(!t?.table)throw new e('"table" is required.',{code:"INVALID_PARAMETER"});let r=u.Params(t||{},{table:"string",index:e=>u.specialChars(e,"index name",!0,!1),order:{by:["average_number","total_number","number_count","average_bool","total_bool","bool_count","string_count","index_name","number_of_records"],value:["string","number","boolean"],condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}},["table"]);if(r.hasOwnProperty("order")){if(!r.order?.by)throw new e('"order.by" is required.',{code:"INVALID_PARAMETER"});if(r.order.hasOwnProperty("condition")&&!r.order.hasOwnProperty("value"))throw new e('"value" is required for "condition".',{code:"INVALID_PARAMETER"});if(r.hasOwnProperty("index")&&"."!==r.index.substring(r.index.length-1))throw new e('"index" should be a parent index name of the compound index when using "order.by"',{code:"INVALID_PARAMETER"})}let i=await h.bind(this)("get-index",r,Object.assign({auth:!0},{fetchOptions:n})),s={cnt_bool:"boolean_count",cnt_numb:"number_count",totl_numb:"total_number",totl_bool:"total_bool",avrg_numb:"average_number",avrg_bool:"average_bool",cnt_str:"string_count"};return Array.isArray(i?.list)&&(i.list=i.list.map((e=>{let t=e.idx.split("/"),n={table:t[1],index:t[2],number_of_records:e.cnt_rec};for(let t in s)e?.[t]&&(n[s[t]]=e[t]);return n}))),i}async function U(e,t){let n=await h.bind(this)("get-tag",u.Params(e||{},{table:"string",tag:"string",condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}),Object.assign({auth:!0},{fetchOptions:t}));if(Array.isArray(n?.list))for(let e in n.list){let t=n.list[e],r=t.tag.split("/");n.list[e]={table:r[1],tag:r[0],number_of_records:t.cnt_rec}}return n}async function D(t){let n=await this.checkAdmin();if(n&&!t?.service)throw new e("Service ID is required.",{code:"INVALID_PARAMETER"});if(t?.record_id)return await h.bind(this)("del-records",{service:t.service||this.service,record_id:(t=>{if("string"==typeof t)return[t];if(!Array.isArray(t))throw new e('"record_id" should be type: <string | string[]>',{code:"INVALID_PARAMETER"});if(t.length>100)throw new e('"record_id" should not exceed 100 items.',{code:"INVALID_PARAMETER"});return u.specialChars(t,"record_id",!1,!1)})(t.record_id)},{auth:!0});{if(!t?.table){if(n)return null;throw new e('Either "table" or "record_id" is required.',{code:"INVALID_PARAMETER"})}let r={access_group:t=>{if("string"==typeof t&&["private","public","authorized"].includes(t))switch(t){case"private":return t;case"public":return 0;case"authorized":return 1}else if("number"==typeof t&&t>=0&&t<100)return t;throw new e('Invalid "table.access_group". Access group should be type <number (0~99) | "private" | "public" | "authorized">.',{code:"INVALID_PARAMETER"})},name:"string",subscription:r=>{if(n&&"string"==typeof t?.table?.subscription)return u.UserId(r,'User ID in "table.subscription"');if("boolean"==typeof r)return r?this.__user.user_id:null;throw new e('"table.subscription" is an invalid parameter key.',{code:"INVALID_PARAMETER"})}},i=u.Params(t.table||{},r,n?[]:["name"]);if(i.hasOwnProperty("subscription"))if(null===i.subscription)delete i.subscription;else{if(!i.hasOwnProperty("access_group"))throw new e('"table.access_group" is required for subscription records.',{code:"INVALID_PARAMETER"});if(0===i.access_group)throw new e("Public tables does not hold subscription records.",{code:"INVALID_REQUEST"});i.subscription_group=1}t.table=i}return await h.bind(this)("del-records",t,{auth:!0})}function C(t){if(!t.record_id)throw new e("Record ID is required.",{code:"INVALID_PARAMETER"});if(!t.user_id||Array.isArray(t.user_id)&&!t.user_id.length)throw new e("User ID is required.",{code:"INVALID_PARAMETER"});return M.bind(this)({record_id:t.record_id,user_id:t.user_id||null,execute:"add"})}function P(t){if(!t.record_id)throw new e("Record ID is required.",{code:"INVALID_PARAMETER"});if(!t.user_id||Array.isArray(t.user_id)&&!t.user_id.length)throw new e("User ID is required.",{code:"INVALID_PARAMETER"});return M.bind(this)({record_id:t.record_id,user_id:t.user_id||null,execute:"remove"})}function N(e){let t=M.bind(this)({record_id:e.record_id,user_id:e.user_id||null,execute:"list"});t.list=t.list.map((e=>(e.record_id=e.rec_usr.split("/")[0],e.user_id=e.rec_usr.split("/")[1],e)))}function k(e){return h.bind(this)("request-private-access-key",{record_id:e},{auth:!0})}function M(t){let n=t.execute,r=u.Params(t,{record_id:"string",user_id:t=>{if(!t){if("list"==n)return null;throw new e("User ID is required.",{code:"INVALID_PARAMETER"})}let r=t;if("string"==typeof r&&(r=[r]),r.length>100)throw new e("Cannot process more than 100 users at once.",{code:"INVALID_REQUEST"});for(let e of r)u.UserId(e,'User ID in "user_id"');return r},execute:["add","remove","list"]},["execute","record_id","user_id"]);return r.user_id||(r.user_id=null),h.bind(this)("grant-private-access",r,{auth:!0})}async function O(){if(await this.getProfile(),!this.session)throw new e("No access.",{code:"INVALID_REQUEST"});let t=await this.record_endpoint;return new WebSocket(t.websocket_private+"?token="+this.session.accessToken.jwtToken)}let V=0;async function L(){let e=this.__socket?await this.__socket:this.__socket;return e&&e.close(),this.__socket=null,this.__socket_group=null,null}function F(t,n=0){if("function"!=typeof t)throw new e("Callback must be a function.",{code:"INVALID_REQUEST"});return!V&&this.__socket instanceof Promise||(this.__socket=new Promise((async r=>{setTimeout((async()=>{if(await this.__connection,!await this.getProfile())throw new e("No access.",{code:"INVALID_REQUEST"});let n=await O.bind(this)();n.onopen=()=>{V=0,t({status:"success",message:"Connected to WebSocket server."}),this.__socket_group&&n.send(JSON.stringify({action:"joinGroup",rid:this.__socket_group,token:this.session.accessToken.jwtToken})),r(n)},n.onmessage=e=>{let n=JSON.parse(decodeURI(e.data)),r="message";n?.["#private"]?r="private":n?.["#notice"]&&(r="notice");let i={status:r,message:n?.["#message"]||n?.["#private"]||n?.["#notice"]||null};n?.["#user_id"]&&(i.sender=n["#user_id"]),t(i)},n.onclose=e=>{if(e.wasClean)t({status:"close",message:"WebSocket connection closed."}),this.__socket=null,this.__socket_group=null;else if(V++,V<10){let e=Math.min(1e3*2**V,3e4);t({status:"error",message:`Skapi: WebSocket connection error. Reconnecting in ${e/1e3} seconds...`}),F.bind(this)(t,e)}else t({status:"error",message:"Skapi: WebSocket connection error. Max reconnection attempts reached."}),this.__socket=null},n.onerror=()=>{throw t({status:"error",message:"Skapi: WebSocket connection error."}),new e("Skapi: WebSocket connection error.",{code:"ERROR"})}}),n)}))),this.__socket}async function x(t,n){let r=this.__socket?await this.__socket:this.__socket;if(!r)throw new e("No realtime connection. Execute connectRealtime() before this method.",{code:"INVALID_REQUEST"});if(!n)throw new e("No recipient.",{code:"INVALID_REQUEST"});if((t instanceof FormData||t instanceof SubmitEvent||t instanceof HTMLFormElement)&&(t=a(t).meta),1===r.readyState){try{u.UserId(n),r.send(JSON.stringify({action:"sendMessage",uid:n,content:t,token:this.session.accessToken.jwtToken}))}catch(i){if(this.__socket_group!==n)throw new e(`User has not joined to the recipient group. Run joinRealtime({ group: "${n}" })`,{code:"INVALID_REQUEST"});r.send(JSON.stringify({action:"broadcast",rid:n,content:t,token:this.session.accessToken.jwtToken}))}return{status:"success",message:"Message sent."}}throw new e("Realtime connection is not open. Try reconnecting with connectRealtime().",{code:"INVALID_REQUEST"})}async function B(t){let n=this.__socket?await this.__socket:this.__socket;if(!n)throw new e("No realtime connection. Execute connectRealtime() before this method.",{code:"INVALID_REQUEST"});(t instanceof FormData||t instanceof SubmitEvent||t instanceof HTMLFormElement)&&(t=a(t).meta);let{group:r=null}=t;if(!r&&!this.__socket_group)return{status:"success",message:"Left realtime message group."};if(null!==r&&"string"!=typeof r)throw new e('"group" must be a string | null.',{code:"INVALID_PARAMETER"});return n.send(JSON.stringify({action:"joinGroup",rid:r,token:this.session.accessToken.jwtToken})),this.__socket_group=r,{status:"success",message:r?`Joined realtime message group: "${r}".`:"Left realtime message group."}}async function $(t,n){if(await this.__connection,!(t=u.Params(t,{user_id:e=>u.UserId(e,'User ID in "user_id"'),group:"string"},["group"])).group)throw new e('"group" is required.',{code:"INVALID_PARAMETER"});let r=await h.bind(this)("get-ws-group",t,{fetchOptions:n,auth:!0,method:"post"});for(let e=0;e<r.list.length;e++)r.list[e]=r.list[e].uid.split("#")[1];return r}async function q(t,n){if(await this.__connection,t||(t={searchFor:"group"}),(t=u.Params(t,{searchFor:["group","number_of_users",()=>"group"],value:["string","number",()=>t?.searchFor&&"number_of_users"===t?.searchFor?0:" "],condition:[">",">=","=","<","<=","!=","gt","gte","eq","lt","lte","ne"],range:["string","number"]})).condition||(" "!==t.value&&t.value?t.condition="=":t.condition=">"),t.range&&t.condition&&delete t.condition,"number_of_users"===t.searchFor&&"number"!=typeof t.value)throw new e('"value" must be a number.',{code:"INVALID_PARAMETER"});if("group"===t.searchFor&&"string"!=typeof t.value)throw new e('"value" must be a string.',{code:"INVALID_PARAMETER"});if(t.hasOwnProperty("range")&&typeof t.range!=typeof t.value)throw new e(`"range" must be a ${typeof t.value}.`,{code:"INVALID_PARAMETER"});let r=await h.bind(this)("get-ws-group",t,{fetchOptions:n,auth:!0,method:"post"});return r.list=r.list.map((e=>({group:e.rid.split("#")[1],number_of_users:e.cnt}))),r}function K(t){let n=!1,r=e=>{for(let t in e)if("string"==typeof e[t]&&e[t].includes("$CLIENT_SECRET")){n=!0;break}};if(u.Params(t,{url:"string",clientSecretName:"string",method:t=>{if(t&&"string"!=typeof t)throw new e('"method" should be type: <string>.',{code:"INVALID_PARAMETER"});if("get"!==t.toLowerCase()&&"post"!==t.toLowerCase())throw new e('"method" should be either "GET" or "POST".',{code:"INVALID_PARAMETER"});return t.toLowerCase()},headers:t=>{if(t&&"object"!=typeof t)throw new e('"headers" should be type: <object>.',{code:"INVALID_PARAMETER"});return r(t),t},data:t=>{if(t&&"object"!=typeof t)throw new e('"data" should be type: <object>.',{code:"INVALID_PARAMETER"});return r(t),t},params:t=>{if(t&&"object"!=typeof t)throw new e('"params" should be type: <object>.',{code:"INVALID_PARAMETER"});return r(t),t}},["clientSecretName","method","url"]),!n)throw new e(`At least one parameter value should include "$CLIENT_SECRET" in ${"post"===t.method.toLowerCase()?'"data"':'"params"'} or "headers".`,{code:"INVALID_PARAMETER"});return h.bind(this)("client-secret-request",t)}async function j(e){await this.__connection;let t={url:e=>u.Url(e),data:null,sync:["boolean",()=>!0]};if(Array.isArray(e))for(let n of e)n=u.Params(n,t);else e=u.Params(e,t);return h.bind(this)("post-secure",e,{auth:!0})}async function H(e,t){await this.__connection;let{auth:n=!0,method:r="POST",bypassAwaitConnection:i=!1,responseType:s,contentType:o,progress:a}=t||{};return t=Object.assign({auth:n,method:r,bypassAwaitConnection:i,responseType:s,contentType:o},{fetchOptions:{progress:a}}),h.bind(this)("mock",e,t)}function W(t){if(t=u.Params(t,{user_id:e=>u.UserId(e,'"user_id"')},["user_id"]),this.__user&&t.user_id===this.__user.user_id)throw new e('"user_id" cannot be the user\'s own ID.',{code:"INVALID_PARAMETER"});return t}async function J(t,n,r){if(!(t=u.Params(t,{subscriber:e=>u.UserId(e,'User ID in "subscriber"'),subscription:e=>u.UserId(e,'User ID in "subscription"'),blocked:"boolean"})).subscriber&&!t.subscription)throw new e('At least either "subscriber" or "subscription" should have a value.',{code:"INVALID_PARAMETER"});Object.assign(t,{group:1});let i=await h.bind(this)("get-subscription",t,Object.assign({auth:!0},{fetchOptions:n}));return i.list=i.list.map(r||(e=>{let t={},n=e.sub.split("#");return t.subscriber=n[2],t.subscription=n[0],t.group=parseInt(n[1]),t.timestamp=e.stmp,t.blocked="N"===e.grp.substring(0,1),t})),i}async function z(e){await this.__connection;let{user_id:t}=W.bind(this)(e);return await h.bind(this)("subscription",{subscribe:t,group:1},{auth:!0})}async function Y(e){await this.__connection;let{user_id:t}=W.bind(this)(e);return await h.bind(this)("subscription",{unsubscribe:t,group:1},{auth:!0})}async function Q(e){await this.__connection;let{user_id:t}=W.bind(this)(e);return await h.bind(this)("subscription",{block:t,group:1},{auth:!0})}async function G(e){await this.__connection;let{user_id:t}=W.bind(this)(e);return await h.bind(this)("subscription",{unblock:t,group:1},{auth:!0})}async function Z(t){await this.__connection;let n=await this.checkAdmin();t=u.Params(t,{user_id:t=>{if(t!==this.__user.user_id&&!n)throw new e("No access.",{code:"INVALID_REQUEST"});return t},group:t=>{if("public"===t&&(t=0),"authorized"===t&&(t=1),"number"!=typeof t)throw new e('"group" should be type number | "public" | "authorized".',{code:"INVALID_PARAMETER"});return t}});let r=await h.bind(this)("get-newsletter-subscription",t,{auth:!0}),i=[];for(let e of r){let t=e.subt.split("#"),n=!0;"@"===t[0].charAt(0)&&(n=!1,t[0]=t[0].substring(1));let r=parseInt(t[0]);i.push({timestamp:e.stmp,group:r,subscribed_email:t[1],active:n})}return i}async function X(e){await this.__connection;let t=u.Params(e||{},{email:e=>u.Email(e),group:["number","public","authorized"],redirect:e=>u.Url(e)},this.__user?["group"]:["email","group"]);return h.bind(this)(`subscribe-${this.__user?"":"public-"}newsletter`,t,{auth:!!this.__user})}async function ee(e){await this.__connection,e=u.Params(e,{group:["number","public","authorized"]},["group"]);let t=Object.assign({action:"unsubscribe"},e);return h.bind(this)("subscribe-newsletter",t,{auth:!0})}async function te(t,n){let r=await this.checkAdmin(),i={message_id:"string",timestamp:"number",read:"number",complaint:"number",subject:"string"};t||(n||(n={}),n.ascending=!1);let s=t||{searchFor:"timestamp",value:0,condition:">"};t=u.Params(s,{searchFor:["message_id","timestamp","read","complaint","group","subject"],value:t=>{if(typeof t!==i[s.searchFor])throw new e(`"value" type does not match the type of "${s.searchFor}" index.`,{code:"INVALID_PARAMETER"});if("string"==typeof t&&!t)throw new e('"value" should not be empty string.',{code:"INVALID_PARAMETER"});return t},range:t=>{if(!s.hasOwnProperty("value")||typeof t!=typeof s.value)throw new e('"range" should match type of "value".',{code:"INVALID_PARAMETER"});return t},condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],group:t=>{if(!this.session)throw new e("User should be logged in.",{code:"INVALID_REQUEST"});if("public"===t)return 0;if("authorized"===t)return 1;if("number"==typeof t&&!r&&t>parseInt(this.session.idToken.payload.access_group))throw new e("User has no access.",{code:"INVALID_REQUEST"});return t}},["searchFor","value","group"]);let o=await h.bind(this)(0===t.group?"get-public-newsletters":"get-newsletters",t,Object.assign({method:"get",auth:0!==t.group},{fetchOptions:n})),a={message_id:"mid",timestamp:"stmp",complaint:"cmpl",read:"read",subject:"subj",bounced:"bnce",url:"url"},c={message_id:"",timestamp:0,complaint:0,read:0,subject:"",bounced:0,url:""};return o.list=o.list.map((e=>{let t={};for(let n in a)t[n]=e[a[n]]||c[a[n]];return t})),o}var ne,re=function(){function e(e){var t=e||{},n=t.ValidationData,r=t.Username,i=t.Password,s=t.AuthParameters,o=t.ClientMetadata;this.validationData=n||{},this.authParameters=s||{},this.clientMetadata=o||{},this.username=r,this.password=i}var t=e.prototype;return t.getUsername=function(){return this.username},t.getPassword=function(){return this.password},t.getValidationData=function(){return this.validationData},t.getAuthParameters=function(){return this.authParameters},t.getClientMetadata=function(){return this.clientMetadata},e}(),ie=n(764),se=n(249),oe=n.n(se),ae=(n(433),n(153)),ue=n.n(ae),ce=n(10),le=n.n(ce);if("undefined"!=typeof window&&window.crypto&&(ne=window.crypto),!ne&&"undefined"!=typeof window&&window.msCrypto&&(ne=window.msCrypto),!ne&&void 0!==n.g&&n.g.crypto&&(ne=n.g.crypto),!ne)try{ne=n(296)}catch(e){}function he(){if(ne){if("function"==typeof ne.getRandomValues)try{return ne.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof ne.randomBytes)try{return ne.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")}var fe=function(){function e(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length}var t=e.prototype;return t.random=function(t){for(var n=[],r=0;r<t;r+=4)n.push(he());return new e(n,t)},t.toString=function(){return function(e){for(var t=e.words,n=e.sigBytes,r=[],i=0;i<n;i++){var s=t[i>>>2]>>>24-i%4*8&255;r.push((s>>>4).toString(16)),r.push((15&s).toString(16))}return r.join("")}(this)},e}();const de=pe;function pe(e,t){null!=e&&this.fromString(e,t)}function ge(){return new pe(null)}var me,ye="undefined"!=typeof navigator;ye&&"Microsoft Internet Explorer"==navigator.appName?(pe.prototype.am=function(e,t,n,r,i,s){for(var o=32767&t,a=t>>15;--s>=0;){var u=32767&this[e],c=this[e++]>>15,l=a*u+c*o;i=((u=o*u+((32767&l)<<15)+n[r]+(1073741823&i))>>>30)+(l>>>15)+a*c+(i>>>30),n[r++]=1073741823&u}return i},me=30):ye&&"Netscape"!=navigator.appName?(pe.prototype.am=function(e,t,n,r,i,s){for(;--s>=0;){var o=t*this[e++]+n[r]+i;i=Math.floor(o/67108864),n[r++]=67108863&o}return i},me=26):(pe.prototype.am=function(e,t,n,r,i,s){for(var o=16383&t,a=t>>14;--s>=0;){var u=16383&this[e],c=this[e++]>>14,l=a*u+c*o;i=((u=o*u+((16383&l)<<14)+n[r]+i)>>28)+(l>>14)+a*c,n[r++]=268435455&u}return i},me=28),pe.prototype.DB=me,pe.prototype.DM=(1<<me)-1,pe.prototype.DV=1<<me,pe.prototype.FV=Math.pow(2,52),pe.prototype.F1=52-me,pe.prototype.F2=2*me-52;var we,_e,be=new Array;for(we="0".charCodeAt(0),_e=0;_e<=9;++_e)be[we++]=_e;for(we="a".charCodeAt(0),_e=10;_e<36;++_e)be[we++]=_e;for(we="A".charCodeAt(0),_e=10;_e<36;++_e)be[we++]=_e;function Ae(e){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(e)}function ve(e,t){var n=be[e.charCodeAt(t)];return null==n?-1:n}function Ee(e){var t=ge();return t.fromInt(e),t}function Se(e){var t,n=1;return 0!=(t=e>>>16)&&(e=t,n+=16),0!=(t=e>>8)&&(e=t,n+=8),0!=(t=e>>4)&&(e=t,n+=4),0!=(t=e>>2)&&(e=t,n+=2),0!=(t=e>>1)&&(e=t,n+=1),n}function Ie(e){this.m=e,this.mp=e.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function Re(e){return ie.lW.from((new fe).random(e).toString(),"hex")}Ie.prototype.convert=function(e){var t=ge();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(pe.ZERO)>0&&this.m.subTo(t,t),t},Ie.prototype.revert=function(e){var t=ge();return e.copyTo(t),this.reduce(t),t},Ie.prototype.reduce=function(e){for(;e.t<=this.mt2;)e[e.t++]=0;for(var t=0;t<this.m.t;++t){var n=32767&e[t],r=n*this.mpl+((n*this.mph+(e[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(e[n=t+this.m.t]+=this.m.am(0,r,e,t,0,this.m.t);e[n]>=e.DV;)e[n]-=e.DV,e[++n]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)},Ie.prototype.mulTo=function(e,t,n){e.multiplyTo(t,n),this.reduce(n)},Ie.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},pe.prototype.copyTo=function(e){for(var t=this.t-1;t>=0;--t)e[t]=this[t];e.t=this.t,e.s=this.s},pe.prototype.fromInt=function(e){this.t=1,this.s=e<0?-1:0,e>0?this[0]=e:e<-1?this[0]=e+this.DV:this.t=0},pe.prototype.fromString=function(e,t){var n;if(16==t)n=4;else if(8==t)n=3;else if(2==t)n=1;else if(32==t)n=5;else{if(4!=t)throw new Error("Only radix 2, 4, 8, 16, 32 are supported");n=2}this.t=0,this.s=0;for(var r=e.length,i=!1,s=0;--r>=0;){var o=ve(e,r);o<0?"-"==e.charAt(r)&&(i=!0):(i=!1,0==s?this[this.t++]=o:s+n>this.DB?(this[this.t-1]|=(o&(1<<this.DB-s)-1)<<s,this[this.t++]=o>>this.DB-s):this[this.t-1]|=o<<s,(s+=n)>=this.DB&&(s-=this.DB))}this.clamp(),i&&pe.ZERO.subTo(this,this)},pe.prototype.clamp=function(){for(var e=this.s&this.DM;this.t>0&&this[this.t-1]==e;)--this.t},pe.prototype.dlShiftTo=function(e,t){var n;for(n=this.t-1;n>=0;--n)t[n+e]=this[n];for(n=e-1;n>=0;--n)t[n]=0;t.t=this.t+e,t.s=this.s},pe.prototype.drShiftTo=function(e,t){for(var n=e;n<this.t;++n)t[n-e]=this[n];t.t=Math.max(this.t-e,0),t.s=this.s},pe.prototype.lShiftTo=function(e,t){var n,r=e%this.DB,i=this.DB-r,s=(1<<i)-1,o=Math.floor(e/this.DB),a=this.s<<r&this.DM;for(n=this.t-1;n>=0;--n)t[n+o+1]=this[n]>>i|a,a=(this[n]&s)<<r;for(n=o-1;n>=0;--n)t[n]=0;t[o]=a,t.t=this.t+o+1,t.s=this.s,t.clamp()},pe.prototype.rShiftTo=function(e,t){t.s=this.s;var n=Math.floor(e/this.DB);if(n>=this.t)t.t=0;else{var r=e%this.DB,i=this.DB-r,s=(1<<r)-1;t[0]=this[n]>>r;for(var o=n+1;o<this.t;++o)t[o-n-1]|=(this[o]&s)<<i,t[o-n]=this[o]>>r;r>0&&(t[this.t-n-1]|=(this.s&s)<<i),t.t=this.t-n,t.clamp()}},pe.prototype.subTo=function(e,t){for(var n=0,r=0,i=Math.min(e.t,this.t);n<i;)r+=this[n]-e[n],t[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r-=e.s;n<this.t;)r+=this[n],t[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r-=e[n],t[n++]=r&this.DM,r>>=this.DB;r-=e.s}t.s=r<0?-1:0,r<-1?t[n++]=this.DV+r:r>0&&(t[n++]=r),t.t=n,t.clamp()},pe.prototype.multiplyTo=function(e,t){var n=this.abs(),r=e.abs(),i=n.t;for(t.t=i+r.t;--i>=0;)t[i]=0;for(i=0;i<r.t;++i)t[i+n.t]=n.am(0,r[i],t,i,0,n.t);t.s=0,t.clamp(),this.s!=e.s&&pe.ZERO.subTo(t,t)},pe.prototype.squareTo=function(e){for(var t=this.abs(),n=e.t=2*t.t;--n>=0;)e[n]=0;for(n=0;n<t.t-1;++n){var r=t.am(n,t[n],e,2*n,0,1);(e[n+t.t]+=t.am(n+1,2*t[n],e,2*n+1,r,t.t-n-1))>=t.DV&&(e[n+t.t]-=t.DV,e[n+t.t+1]=1)}e.t>0&&(e[e.t-1]+=t.am(n,t[n],e,2*n,0,1)),e.s=0,e.clamp()},pe.prototype.divRemTo=function(e,t,n){var r=e.abs();if(!(r.t<=0)){var i=this.abs();if(i.t<r.t)return null!=t&&t.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=ge());var s=ge(),o=this.s,a=e.s,u=this.DB-Se(r[r.t-1]);u>0?(r.lShiftTo(u,s),i.lShiftTo(u,n)):(r.copyTo(s),i.copyTo(n));var c=s.t,l=s[c-1];if(0!=l){var h=l*(1<<this.F1)+(c>1?s[c-2]>>this.F2:0),f=this.FV/h,d=(1<<this.F1)/h,p=1<<this.F2,g=n.t,m=g-c,y=null==t?ge():t;for(s.dlShiftTo(m,y),n.compareTo(y)>=0&&(n[n.t++]=1,n.subTo(y,n)),pe.ONE.dlShiftTo(c,y),y.subTo(s,s);s.t<c;)s[s.t++]=0;for(;--m>=0;){var w=n[--g]==l?this.DM:Math.floor(n[g]*f+(n[g-1]+p)*d);if((n[g]+=s.am(0,w,n,m,0,c))<w)for(s.dlShiftTo(m,y),n.subTo(y,n);n[g]<--w;)n.subTo(y,n)}null!=t&&(n.drShiftTo(c,t),o!=a&&pe.ZERO.subTo(t,t)),n.t=c,n.clamp(),u>0&&n.rShiftTo(u,n),o<0&&pe.ZERO.subTo(n,n)}}},pe.prototype.invDigit=function(){if(this.t<1)return 0;var e=this[0];if(0==(1&e))return 0;var t=3&e;return(t=(t=(t=(t=t*(2-(15&e)*t)&15)*(2-(255&e)*t)&255)*(2-((65535&e)*t&65535))&65535)*(2-e*t%this.DV)%this.DV)>0?this.DV-t:-t},pe.prototype.addTo=function(e,t){for(var n=0,r=0,i=Math.min(e.t,this.t);n<i;)r+=this[n]+e[n],t[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r+=e.s;n<this.t;)r+=this[n],t[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r+=e[n],t[n++]=r&this.DM,r>>=this.DB;r+=e.s}t.s=r<0?-1:0,r>0?t[n++]=r:r<-1&&(t[n++]=this.DV+r),t.t=n,t.clamp()},pe.prototype.toString=function(e){if(this.s<0)return"-"+this.negate().toString(e);var t;if(16==e)t=4;else if(8==e)t=3;else if(2==e)t=1;else if(32==e)t=5;else{if(4!=e)throw new Error("Only radix 2, 4, 8, 16, 32 are supported");t=2}var n,r=(1<<t)-1,i=!1,s="",o=this.t,a=this.DB-o*this.DB%t;if(o-- >0)for(a<this.DB&&(n=this[o]>>a)>0&&(i=!0,s=Ae(n));o>=0;)a<t?(n=(this[o]&(1<<a)-1)<<t-a,n|=this[--o]>>(a+=this.DB-t)):(n=this[o]>>(a-=t)&r,a<=0&&(a+=this.DB,--o)),n>0&&(i=!0),i&&(s+=Ae(n));return i?s:"0"},pe.prototype.negate=function(){var e=ge();return pe.ZERO.subTo(this,e),e},pe.prototype.abs=function(){return this.s<0?this.negate():this},pe.prototype.compareTo=function(e){var t=this.s-e.s;if(0!=t)return t;var n=this.t;if(0!=(t=n-e.t))return this.s<0?-t:t;for(;--n>=0;)if(0!=(t=this[n]-e[n]))return t;return 0},pe.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+Se(this[this.t-1]^this.s&this.DM)},pe.prototype.mod=function(e){var t=ge();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(pe.ZERO)>0&&e.subTo(t,t),t},pe.prototype.equals=function(e){return 0==this.compareTo(e)},pe.prototype.add=function(e){var t=ge();return this.addTo(e,t),t},pe.prototype.subtract=function(e){var t=ge();return this.subTo(e,t),t},pe.prototype.multiply=function(e){var t=ge();return this.multiplyTo(e,t),t},pe.prototype.divide=function(e){var t=ge();return this.divRemTo(e,t,null),t},pe.prototype.modPow=function(e,t,n){var r,i=e.bitLength(),s=Ee(1),o=new Ie(t);if(i<=0)return s;r=i<18?1:i<48?3:i<144?4:i<768?5:6;var a=new Array,u=3,c=r-1,l=(1<<r)-1;if(a[1]=o.convert(this),r>1){var h=ge();for(o.sqrTo(a[1],h);u<=l;)a[u]=ge(),o.mulTo(h,a[u-2],a[u]),u+=2}var f,d,p=e.t-1,g=!0,m=ge();for(i=Se(e[p])-1;p>=0;){for(i>=c?f=e[p]>>i-c&l:(f=(e[p]&(1<<i+1)-1)<<c-i,p>0&&(f|=e[p-1]>>this.DB+i-c)),u=r;0==(1&f);)f>>=1,--u;if((i-=u)<0&&(i+=this.DB,--p),g)a[f].copyTo(s),g=!1;else{for(;u>1;)o.sqrTo(s,m),o.sqrTo(m,s),u-=2;u>0?o.sqrTo(s,m):(d=s,s=m,m=d),o.mulTo(m,a[f],s)}for(;p>=0&&0==(e[p]&1<<i);)o.sqrTo(s,m),d=s,s=m,m=d,--i<0&&(i=this.DB-1,--p)}var y=o.revert(s);return n(null,y),y},pe.ZERO=Ee(0),pe.ONE=Ee(1);var Te=/^[89a-f]/i,Ue=function(){function e(e){this.N=new de("FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF",16),this.g=new de("2",16),this.k=new de(this.hexHash(""+this.padHex(this.N)+this.padHex(this.g)),16),this.smallAValue=this.generateRandomSmallA(),this.getLargeAValue((function(){})),this.infoBits=ie.lW.from("Caldera Derived Key","utf8"),this.poolName=e}var t=e.prototype;return t.getSmallAValue=function(){return this.smallAValue},t.getLargeAValue=function(e){var t=this;this.largeAValue?e(null,this.largeAValue):this.calculateA(this.smallAValue,(function(n,r){n&&e(n,null),t.largeAValue=r,e(null,t.largeAValue)}))},t.generateRandomSmallA=function(){var e=Re(128).toString("hex");return new de(e,16)},t.generateRandomString=function(){return Re(40).toString("base64")},t.getRandomPassword=function(){return this.randomPassword},t.getSaltDevices=function(){return this.SaltToHashDevices},t.getVerifierDevices=function(){return this.verifierDevices},t.generateHashDevice=function(e,t,n){var r=this;this.randomPassword=this.generateRandomString();var i=""+e+t+":"+this.randomPassword,s=this.hash(i),o=Re(16).toString("hex");this.SaltToHashDevices=this.padHex(new de(o,16)),this.g.modPow(new de(this.hexHash(this.SaltToHashDevices+s),16),this.N,(function(e,t){e&&n(e,null),r.verifierDevices=r.padHex(t),n(null,null)}))},t.calculateA=function(e,t){var n=this;this.g.modPow(e,this.N,(function(e,r){e&&t(e,null),r.mod(n.N).equals(de.ZERO)&&t(new Error("Illegal paramater. A mod N cannot be 0."),null),t(null,r)}))},t.calculateU=function(e,t){return this.UHexHash=this.hexHash(this.padHex(e)+this.padHex(t)),new de(this.UHexHash,16)},t.hash=function(e){var t=e instanceof ie.lW?oe().lib.WordArray.create(e):e,n=ue()(t).toString();return new Array(64-n.length).join("0")+n},t.hexHash=function(e){return this.hash(ie.lW.from(e,"hex"))},t.computehkdf=function(e,t){var n=oe().lib.WordArray.create(ie.lW.concat([this.infoBits,ie.lW.from(String.fromCharCode(1),"utf8")])),r=e instanceof ie.lW?oe().lib.WordArray.create(e):e,i=t instanceof ie.lW?oe().lib.WordArray.create(t):t,s=le()(r,i),o=le()(n,s);return ie.lW.from(o.toString(),"hex").slice(0,16)},t.getPasswordAuthenticationKey=function(e,t,n,r,i){var s=this;if(n.mod(this.N).equals(de.ZERO))throw new Error("B cannot be zero.");if(this.UValue=this.calculateU(this.largeAValue,n),this.UValue.equals(de.ZERO))throw new Error("U cannot be zero.");var o=""+this.poolName+e+":"+t,a=this.hash(o),u=new de(this.hexHash(this.padHex(r)+a),16);this.calculateS(u,n,(function(e,t){e&&i(e,null);var n=s.computehkdf(ie.lW.from(s.padHex(t),"hex"),ie.lW.from(s.padHex(s.UValue),"hex"));i(null,n)}))},t.calculateS=function(e,t,n){var r=this;this.g.modPow(e,this.N,(function(i,s){i&&n(i,null),t.subtract(r.k.multiply(s)).modPow(r.smallAValue.add(r.UValue.multiply(e)),r.N,(function(e,t){e&&n(e,null),n(null,t.mod(r.N))}))}))},t.getNewPasswordRequiredChallengeUserAttributePrefix=function(){return"userAttributes."},t.padHex=function(e){if(!(e instanceof de))throw new Error("Not a BigInteger");var t=e.compareTo(de.ZERO)<0,n=e.abs().toString(16);if(n=n.length%2!=0?"0"+n:n,n=Te.test(n)?"00"+n:n,t){var r=n.split("").map((function(e){var t=15&~parseInt(e,16);return"0123456789ABCDEF".charAt(t)})).join("");(n=new de(r,16).add(de.ONE).toString(16)).toUpperCase().startsWith("FF8")&&(n=n.substring(2))}return n},e}(),De=function(){function e(e){this.jwtToken=e||"",this.payload=this.decodePayload()}var t=e.prototype;return t.getJwtToken=function(){return this.jwtToken},t.getExpiration=function(){return this.payload.exp},t.getIssuedAt=function(){return this.payload.iat},t.decodePayload=function(){var e=this.jwtToken.split(".")[1];try{return JSON.parse(ie.lW.from(e,"base64").toString("utf8"))}catch(e){return{}}},e}();function Ce(e,t){return Ce=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ce(e,t)}var Pe=function(e){var t,n;function r(t){var n=(void 0===t?{}:t).AccessToken;return e.call(this,n||"")||this}return n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,Ce(t,n),r}(De);function Ne(e,t){return Ne=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ne(e,t)}var ke=function(e){var t,n;function r(t){var n=(void 0===t?{}:t).IdToken;return e.call(this,n||"")||this}return n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,Ne(t,n),r}(De),Me=n(269),Oe=n.n(Me),Ve=function(){function e(e){var t=(void 0===e?{}:e).RefreshToken;this.token=t||""}return e.prototype.getToken=function(){return this.token},e}(),Le=function(){function e(e){var t=void 0===e?{}:e,n=t.IdToken,r=t.RefreshToken,i=t.AccessToken,s=t.ClockDrift;if(null==i||null==n)throw new Error("Id token and Access Token must be present.");this.idToken=n,this.refreshToken=r,this.accessToken=i,this.clockDrift=void 0===s?this.calculateClockDrift():s}var t=e.prototype;return t.getIdToken=function(){return this.idToken},t.getRefreshToken=function(){return this.refreshToken},t.getAccessToken=function(){return this.accessToken},t.getClockDrift=function(){return this.clockDrift},t.calculateClockDrift=function(){return Math.floor(new Date/1e3)-Math.min(this.accessToken.getIssuedAt(),this.idToken.getIssuedAt())},t.isValid=function(){var e=Math.floor(new Date/1e3)-this.clockDrift;return e<this.accessToken.getExpiration()&&e<this.idToken.getExpiration()},e}(),Fe=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],xe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Be=function(){function e(){}return e.prototype.getNowString=function(){var e=new Date,t=xe[e.getUTCDay()],n=Fe[e.getUTCMonth()],r=e.getUTCDate(),i=e.getUTCHours();i<10&&(i="0"+i);var s=e.getUTCMinutes();s<10&&(s="0"+s);var o=e.getUTCSeconds();return o<10&&(o="0"+o),t+" "+n+" "+r+" "+i+":"+s+":"+o+" UTC "+e.getUTCFullYear()},e}(),$e=function(){function e(e){var t=void 0===e?{}:e,n=t.Name,r=t.Value;this.Name=n||"",this.Value=r||""}var t=e.prototype;return t.getValue=function(){return this.Value},t.setValue=function(e){return this.Value=e,this},t.getName=function(){return this.Name},t.setName=function(e){return this.Name=e,this},t.toString=function(){return JSON.stringify(this)},t.toJSON=function(){return{Name:this.Name,Value:this.Value}},e}(),qe={},Ke=function(){function e(){}return e.setItem=function(e,t){return qe[e]=t,qe[e]},e.getItem=function(e){return Object.prototype.hasOwnProperty.call(qe,e)?qe[e]:void 0},e.removeItem=function(e){return delete qe[e]},e.clear=function(){return qe={}},e}(),je=function(){function e(){try{this.storageWindow=window.localStorage,this.storageWindow.setItem("aws.cognito.test-ls",1),this.storageWindow.removeItem("aws.cognito.test-ls")}catch(e){this.storageWindow=Ke}}return e.prototype.getStorage=function(){return this.storageWindow},e}(),He="undefined"!=typeof navigator?navigator.userAgent:"nodejs",We=function(){function e(e){if(null==e||null==e.Username||null==e.Pool)throw new Error("Username and Pool information are required.");this.username=e.Username||"",this.pool=e.Pool,this.Session=null,this.client=e.Pool.client,this.signInUserSession=null,this.authenticationFlowType="USER_SRP_AUTH",this.storage=e.Storage||(new je).getStorage(),this.keyPrefix="CognitoIdentityServiceProvider."+this.pool.getClientId(),this.userDataKey=this.keyPrefix+"."+this.username+".userData"}var t=e.prototype;return t.setSignInUserSession=function(e){this.clearCachedUserData(),this.signInUserSession=e,this.cacheTokens()},t.getSignInUserSession=function(){return this.signInUserSession},t.getUsername=function(){return this.username},t.getAuthenticationFlowType=function(){return this.authenticationFlowType},t.setAuthenticationFlowType=function(e){this.authenticationFlowType=e},t.initiateAuth=function(e,t){var n=this,r=e.getAuthParameters();r.USERNAME=this.username;var i=0!==Object.keys(e.getValidationData()).length?e.getValidationData():e.getClientMetadata(),s={AuthFlow:"CUSTOM_AUTH",ClientId:this.pool.getClientId(),AuthParameters:r,ClientMetadata:i};this.getUserContextData()&&(s.UserContextData=this.getUserContextData()),this.client.request("InitiateAuth",s,(function(e,r){if(e)return t.onFailure(e);var i=r.ChallengeName,s=r.ChallengeParameters;return"CUSTOM_CHALLENGE"===i?(n.Session=r.Session,t.customChallenge(s)):(n.signInUserSession=n.getCognitoUserSession(r.AuthenticationResult),n.cacheTokens(),t.onSuccess(n.signInUserSession))}))},t.authenticateUser=function(e,t){return"USER_PASSWORD_AUTH"===this.authenticationFlowType?this.authenticateUserPlainUsernamePassword(e,t):"USER_SRP_AUTH"===this.authenticationFlowType||"CUSTOM_AUTH"===this.authenticationFlowType?this.authenticateUserDefaultAuth(e,t):t.onFailure(new Error("Authentication flow type is invalid."))},t.authenticateUserDefaultAuth=function(e,t){var n,r,i=this,s=new Ue(this.pool.getUserPoolName()),o=new Be,a={};null!=this.deviceKey&&(a.DEVICE_KEY=this.deviceKey),a.USERNAME=this.username,s.getLargeAValue((function(u,c){u&&t.onFailure(u),a.SRP_A=c.toString(16),"CUSTOM_AUTH"===i.authenticationFlowType&&(a.CHALLENGE_NAME="SRP_A");var l=0!==Object.keys(e.getValidationData()).length?e.getValidationData():e.getClientMetadata(),h={AuthFlow:i.authenticationFlowType,ClientId:i.pool.getClientId(),AuthParameters:a,ClientMetadata:l};i.getUserContextData(i.username)&&(h.UserContextData=i.getUserContextData(i.username)),i.client.request("InitiateAuth",h,(function(a,u){if(a)return t.onFailure(a);var c=u.ChallengeParameters;i.username=c.USER_ID_FOR_SRP,i.userDataKey=i.keyPrefix+"."+i.username+".userData",n=new de(c.SRP_B,16),r=new de(c.SALT,16),i.getCachedDeviceKeyAndPassword(),s.getPasswordAuthenticationKey(i.username,e.getPassword(),n,r,(function(e,n){e&&t.onFailure(e);var r=o.getNowString(),a=oe().lib.WordArray.create(ie.lW.concat([ie.lW.from(i.pool.getUserPoolName(),"utf8"),ie.lW.from(i.username,"utf8"),ie.lW.from(c.SECRET_BLOCK,"base64"),ie.lW.from(r,"utf8")])),h=oe().lib.WordArray.create(n),f=Oe().stringify(le()(a,h)),d={};d.USERNAME=i.username,d.PASSWORD_CLAIM_SECRET_BLOCK=c.SECRET_BLOCK,d.TIMESTAMP=r,d.PASSWORD_CLAIM_SIGNATURE=f,null!=i.deviceKey&&(d.DEVICE_KEY=i.deviceKey);var p={ChallengeName:"PASSWORD_VERIFIER",ClientId:i.pool.getClientId(),ChallengeResponses:d,Session:u.Session,ClientMetadata:l};i.getUserContextData()&&(p.UserContextData=i.getUserContextData()),function e(t,n){return i.client.request("RespondToAuthChallenge",t,(function(r,s){return r&&"ResourceNotFoundException"===r.code&&-1!==r.message.toLowerCase().indexOf("device")?(d.DEVICE_KEY=null,i.deviceKey=null,i.randomPassword=null,i.deviceGroupKey=null,i.clearCachedDeviceKeyAndPassword(),e(t,n)):n(r,s)}))}(p,(function(e,n){return e?t.onFailure(e):i.authenticateUserInternal(n,s,t)}))}))}))}))},t.authenticateUserPlainUsernamePassword=function(e,t){var n=this,r={};if(r.USERNAME=this.username,r.PASSWORD=e.getPassword(),r.PASSWORD){var i=new Ue(this.pool.getUserPoolName());this.getCachedDeviceKeyAndPassword(),null!=this.deviceKey&&(r.DEVICE_KEY=this.deviceKey);var s=0!==Object.keys(e.getValidationData()).length?e.getValidationData():e.getClientMetadata(),o={AuthFlow:"USER_PASSWORD_AUTH",ClientId:this.pool.getClientId(),AuthParameters:r,ClientMetadata:s};this.getUserContextData(this.username)&&(o.UserContextData=this.getUserContextData(this.username)),this.client.request("InitiateAuth",o,(function(e,r){return e?t.onFailure(e):n.authenticateUserInternal(r,i,t)}))}else t.onFailure(new Error("PASSWORD parameter is required"))},t.authenticateUserInternal=function(e,t,n){var r=this,i=e.ChallengeName,s=e.ChallengeParameters;if("SMS_MFA"===i)return this.Session=e.Session,n.mfaRequired(i,s);if("SELECT_MFA_TYPE"===i)return this.Session=e.Session,n.selectMFAType(i,s);if("MFA_SETUP"===i)return this.Session=e.Session,n.mfaSetup(i,s);if("SOFTWARE_TOKEN_MFA"===i)return this.Session=e.Session,n.totpRequired(i,s);if("CUSTOM_CHALLENGE"===i)return this.Session=e.Session,n.customChallenge(s);if("NEW_PASSWORD_REQUIRED"===i){this.Session=e.Session;var o=null,a=null,u=[],c=t.getNewPasswordRequiredChallengeUserAttributePrefix();if(s&&(o=JSON.parse(e.ChallengeParameters.userAttributes),a=JSON.parse(e.ChallengeParameters.requiredAttributes)),a)for(var l=0;l<a.length;l++)u[l]=a[l].substr(c.length);return n.newPasswordRequired(o,u)}if("DEVICE_SRP_AUTH"===i)return this.Session=e.Session,void this.getDeviceResponse(n);this.signInUserSession=this.getCognitoUserSession(e.AuthenticationResult),this.challengeName=i,this.cacheTokens();var h=e.AuthenticationResult.NewDeviceMetadata;if(null==h)return n.onSuccess(this.signInUserSession);t.generateHashDevice(e.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,e.AuthenticationResult.NewDeviceMetadata.DeviceKey,(function(i){if(i)return n.onFailure(i);var s={Salt:ie.lW.from(t.getSaltDevices(),"hex").toString("base64"),PasswordVerifier:ie.lW.from(t.getVerifierDevices(),"hex").toString("base64")};r.verifierDevices=s.PasswordVerifier,r.deviceGroupKey=h.DeviceGroupKey,r.randomPassword=t.getRandomPassword(),r.client.request("ConfirmDevice",{DeviceKey:h.DeviceKey,AccessToken:r.signInUserSession.getAccessToken().getJwtToken(),DeviceSecretVerifierConfig:s,DeviceName:He},(function(t,i){return t?n.onFailure(t):(r.deviceKey=e.AuthenticationResult.NewDeviceMetadata.DeviceKey,r.cacheDeviceKeyAndPassword(),!0===i.UserConfirmationNecessary?n.onSuccess(r.signInUserSession,i.UserConfirmationNecessary):n.onSuccess(r.signInUserSession))}))}))},t.completeNewPasswordChallenge=function(e,t,n,r){var i=this;if(!e)return n.onFailure(new Error("New password is required."));var s=new Ue(this.pool.getUserPoolName()),o=s.getNewPasswordRequiredChallengeUserAttributePrefix(),a={};t&&Object.keys(t).forEach((function(e){a[o+e]=t[e]})),a.NEW_PASSWORD=e,a.USERNAME=this.username;var u={ChallengeName:"NEW_PASSWORD_REQUIRED",ClientId:this.pool.getClientId(),ChallengeResponses:a,Session:this.Session,ClientMetadata:r};this.getUserContextData()&&(u.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",u,(function(e,t){return e?n.onFailure(e):i.authenticateUserInternal(t,s,n)}))},t.getDeviceResponse=function(e,t){var n=this,r=new Ue(this.deviceGroupKey),i=new Be,s={};s.USERNAME=this.username,s.DEVICE_KEY=this.deviceKey,r.getLargeAValue((function(o,a){o&&e.onFailure(o),s.SRP_A=a.toString(16);var u={ChallengeName:"DEVICE_SRP_AUTH",ClientId:n.pool.getClientId(),ChallengeResponses:s,ClientMetadata:t,Session:n.Session};n.getUserContextData()&&(u.UserContextData=n.getUserContextData()),n.client.request("RespondToAuthChallenge",u,(function(t,s){if(t)return e.onFailure(t);var o=s.ChallengeParameters,a=new de(o.SRP_B,16),u=new de(o.SALT,16);r.getPasswordAuthenticationKey(n.deviceKey,n.randomPassword,a,u,(function(t,r){if(t)return e.onFailure(t);var a=i.getNowString(),u=oe().lib.WordArray.create(ie.lW.concat([ie.lW.from(n.deviceGroupKey,"utf8"),ie.lW.from(n.deviceKey,"utf8"),ie.lW.from(o.SECRET_BLOCK,"base64"),ie.lW.from(a,"utf8")])),c=oe().lib.WordArray.create(r),l=Oe().stringify(le()(u,c)),h={};h.USERNAME=n.username,h.PASSWORD_CLAIM_SECRET_BLOCK=o.SECRET_BLOCK,h.TIMESTAMP=a,h.PASSWORD_CLAIM_SIGNATURE=l,h.DEVICE_KEY=n.deviceKey;var f={ChallengeName:"DEVICE_PASSWORD_VERIFIER",ClientId:n.pool.getClientId(),ChallengeResponses:h,Session:s.Session};n.getUserContextData()&&(f.UserContextData=n.getUserContextData()),n.client.request("RespondToAuthChallenge",f,(function(t,r){return t?e.onFailure(t):(n.signInUserSession=n.getCognitoUserSession(r.AuthenticationResult),n.cacheTokens(),e.onSuccess(n.signInUserSession))}))}))}))}))},t.confirmRegistration=function(e,t,n,r){var i={ClientId:this.pool.getClientId(),ConfirmationCode:e,Username:this.username,ForceAliasCreation:t,ClientMetadata:r};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("ConfirmSignUp",i,(function(e){return e?n(e,null):n(null,"SUCCESS")}))},t.sendCustomChallengeAnswer=function(e,t,n){var r=this,i={};i.USERNAME=this.username,i.ANSWER=e;var s=new Ue(this.pool.getUserPoolName());this.getCachedDeviceKeyAndPassword(),null!=this.deviceKey&&(i.DEVICE_KEY=this.deviceKey);var o={ChallengeName:"CUSTOM_CHALLENGE",ChallengeResponses:i,ClientId:this.pool.getClientId(),Session:this.Session,ClientMetadata:n};this.getUserContextData()&&(o.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",o,(function(e,n){return e?t.onFailure(e):r.authenticateUserInternal(n,s,t)}))},t.sendMFACode=function(e,t,n,r){var i=this,s={};s.USERNAME=this.username,s.SMS_MFA_CODE=e;var o=n||"SMS_MFA";"SOFTWARE_TOKEN_MFA"===o&&(s.SOFTWARE_TOKEN_MFA_CODE=e),null!=this.deviceKey&&(s.DEVICE_KEY=this.deviceKey);var a={ChallengeName:o,ChallengeResponses:s,ClientId:this.pool.getClientId(),Session:this.Session,ClientMetadata:r};this.getUserContextData()&&(a.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",a,(function(e,n){if(e)return t.onFailure(e);if("DEVICE_SRP_AUTH"!==n.ChallengeName){if(i.signInUserSession=i.getCognitoUserSession(n.AuthenticationResult),i.cacheTokens(),null==n.AuthenticationResult.NewDeviceMetadata)return t.onSuccess(i.signInUserSession);var r=new Ue(i.pool.getUserPoolName());r.generateHashDevice(n.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,n.AuthenticationResult.NewDeviceMetadata.DeviceKey,(function(e){if(e)return t.onFailure(e);var s={Salt:ie.lW.from(r.getSaltDevices(),"hex").toString("base64"),PasswordVerifier:ie.lW.from(r.getVerifierDevices(),"hex").toString("base64")};i.verifierDevices=s.PasswordVerifier,i.deviceGroupKey=n.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,i.randomPassword=r.getRandomPassword(),i.client.request("ConfirmDevice",{DeviceKey:n.AuthenticationResult.NewDeviceMetadata.DeviceKey,AccessToken:i.signInUserSession.getAccessToken().getJwtToken(),DeviceSecretVerifierConfig:s,DeviceName:He},(function(e,r){return e?t.onFailure(e):(i.deviceKey=n.AuthenticationResult.NewDeviceMetadata.DeviceKey,i.cacheDeviceKeyAndPassword(),!0===r.UserConfirmationNecessary?t.onSuccess(i.signInUserSession,r.UserConfirmationNecessary):t.onSuccess(i.signInUserSession))}))}))}else i.getDeviceResponse(t)}))},t.changePassword=function(e,t,n,r){if(null==this.signInUserSession||!this.signInUserSession.isValid())return n(new Error("User is not authenticated"),null);this.client.request("ChangePassword",{PreviousPassword:e,ProposedPassword:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),ClientMetadata:r},(function(e){return e?n(e,null):n(null,"SUCCESS")}))},t.enableMFA=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e(new Error("User is not authenticated"),null);var t=[];t.push({DeliveryMedium:"SMS",AttributeName:"phone_number"}),this.client.request("SetUserSettings",{MFAOptions:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(t){return t?e(t,null):e(null,"SUCCESS")}))},t.setUserMfaPreference=function(e,t,n){if(null==this.signInUserSession||!this.signInUserSession.isValid())return n(new Error("User is not authenticated"),null);this.client.request("SetUserMFAPreference",{SMSMfaSettings:e,SoftwareTokenMfaSettings:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(e){return e?n(e,null):n(null,"SUCCESS")}))},t.disableMFA=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e(new Error("User is not authenticated"),null);this.client.request("SetUserSettings",{MFAOptions:[],AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(t){return t?e(t,null):e(null,"SUCCESS")}))},t.deleteUser=function(e,t){var n=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return e(new Error("User is not authenticated"),null);this.client.request("DeleteUser",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),ClientMetadata:t},(function(t){return t?e(t,null):(n.clearCachedUser(),e(null,"SUCCESS"))}))},t.updateAttributes=function(e,t,n){var r=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return t(new Error("User is not authenticated"),null);this.client.request("UpdateUserAttributes",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),UserAttributes:e,ClientMetadata:n},(function(e){return e?t(e,null):r.getUserData((function(){return t(null,"SUCCESS")}),{bypassCache:!0})}))},t.getUserAttributes=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e(new Error("User is not authenticated"),null);this.client.request("GetUser",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(t,n){if(t)return e(t,null);for(var r=[],i=0;i<n.UserAttributes.length;i++){var s={Name:n.UserAttributes[i].Name,Value:n.UserAttributes[i].Value},o=new $e(s);r.push(o)}return e(null,r)}))},t.getMFAOptions=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e(new Error("User is not authenticated"),null);this.client.request("GetUser",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(t,n){return t?e(t,null):e(null,n.MFAOptions)}))},t.createGetUserRequest=function(){return this.client.promisifyRequest("GetUser",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken()})},t.refreshSessionIfPossible=function(e){var t=this;return void 0===e&&(e={}),new Promise((function(n){var r=t.signInUserSession.getRefreshToken();r&&r.getToken()?t.refreshSession(r,n,e.clientMetadata):n()}))},t.getUserData=function(e,t){var n=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return this.clearCachedUserData(),e(new Error("User is not authenticated"),null);var r=this.getUserDataFromCache();if(r)if(this.isFetchUserDataAndTokenRequired(t))this.fetchUserData().then((function(e){return n.refreshSessionIfPossible(t).then((function(){return e}))})).then((function(t){return e(null,t)})).catch(e);else try{return void e(null,JSON.parse(r))}catch(t){return this.clearCachedUserData(),void e(t,null)}else this.fetchUserData().then((function(t){e(null,t)})).catch(e)},t.getUserDataFromCache=function(){return this.storage.getItem(this.userDataKey)},t.isFetchUserDataAndTokenRequired=function(e){var t=(e||{}).bypassCache;return void 0!==t&&t},t.fetchUserData=function(){var e=this;return this.createGetUserRequest().then((function(t){return e.cacheUserData(t),t}))},t.deleteAttributes=function(e,t){var n=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return t(new Error("User is not authenticated"),null);this.client.request("DeleteUserAttributes",{UserAttributeNames:e,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(e){return e?t(e,null):n.getUserData((function(){return t(null,"SUCCESS")}),{bypassCache:!0})}))},t.resendConfirmationCode=function(e,t){var n={ClientId:this.pool.getClientId(),Username:this.username,ClientMetadata:t};this.client.request("ResendConfirmationCode",n,(function(t,n){return t?e(t,null):e(null,n)}))},t.getSession=function(e,t){if(void 0===t&&(t={}),null==this.username)return e(new Error("Username is null. Cannot retrieve a new session"),null);if(null!=this.signInUserSession&&this.signInUserSession.isValid())return e(null,this.signInUserSession);var n="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,r=n+".idToken",i=n+".accessToken",s=n+".refreshToken",o=n+".clockDrift";if(this.storage.getItem(r)){var a=new ke({IdToken:this.storage.getItem(r)}),u=new Pe({AccessToken:this.storage.getItem(i)}),c=new Ve({RefreshToken:this.storage.getItem(s)}),l=parseInt(this.storage.getItem(o),0)||0,h=new Le({IdToken:a,AccessToken:u,RefreshToken:c,ClockDrift:l});if(h.isValid())return this.signInUserSession=h,e(null,this.signInUserSession);if(!c.getToken())return e(new Error("Cannot retrieve a new session. Please authenticate."),null);this.refreshSession(c,e,t.clientMetadata)}else e(new Error("Local storage is missing an ID Token, Please authenticate"),null)},t.refreshSession=function(e,t,n){var r=this,i=this.pool.wrapRefreshSessionCallback?this.pool.wrapRefreshSessionCallback(t):t,s={};s.REFRESH_TOKEN=e.getToken();var o="CognitoIdentityServiceProvider."+this.pool.getClientId(),a=o+".LastAuthUser";if(this.storage.getItem(a)){this.username=this.storage.getItem(a);var u=o+"."+this.username+".deviceKey";this.deviceKey=this.storage.getItem(u),s.DEVICE_KEY=this.deviceKey}var c={ClientId:this.pool.getClientId(),AuthFlow:"REFRESH_TOKEN_AUTH",AuthParameters:s,ClientMetadata:n};this.getUserContextData()&&(c.UserContextData=this.getUserContextData()),this.client.request("InitiateAuth",c,(function(t,n){if(t)return"NotAuthorizedException"===t.code&&r.clearCachedUser(),i(t,null);if(n){var s=n.AuthenticationResult;return Object.prototype.hasOwnProperty.call(s,"RefreshToken")||(s.RefreshToken=e.getToken()),r.signInUserSession=r.getCognitoUserSession(s),r.cacheTokens(),i(null,r.signInUserSession)}}))},t.cacheTokens=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId(),t=e+"."+this.username+".idToken",n=e+"."+this.username+".accessToken",r=e+"."+this.username+".refreshToken",i=e+"."+this.username+".clockDrift",s=e+".LastAuthUser";this.storage.setItem(t,this.signInUserSession.getIdToken().getJwtToken()),this.storage.setItem(n,this.signInUserSession.getAccessToken().getJwtToken()),this.storage.setItem(r,this.signInUserSession.getRefreshToken().getToken()),this.storage.setItem(i,""+this.signInUserSession.getClockDrift()),this.storage.setItem(s,this.username)},t.cacheUserData=function(e){this.storage.setItem(this.userDataKey,JSON.stringify(e))},t.clearCachedUserData=function(){this.storage.removeItem(this.userDataKey)},t.clearCachedUser=function(){this.clearCachedTokens(),this.clearCachedUserData()},t.cacheDeviceKeyAndPassword=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,t=e+".deviceKey",n=e+".randomPasswordKey",r=e+".deviceGroupKey";this.storage.setItem(t,this.deviceKey),this.storage.setItem(n,this.randomPassword),this.storage.setItem(r,this.deviceGroupKey)},t.getCachedDeviceKeyAndPassword=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,t=e+".deviceKey",n=e+".randomPasswordKey",r=e+".deviceGroupKey";this.storage.getItem(t)&&(this.deviceKey=this.storage.getItem(t),this.randomPassword=this.storage.getItem(n),this.deviceGroupKey=this.storage.getItem(r))},t.clearCachedDeviceKeyAndPassword=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,t=e+".deviceKey",n=e+".randomPasswordKey",r=e+".deviceGroupKey";this.storage.removeItem(t),this.storage.removeItem(n),this.storage.removeItem(r)},t.clearCachedTokens=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId(),t=e+"."+this.username+".idToken",n=e+"."+this.username+".accessToken",r=e+"."+this.username+".refreshToken",i=e+".LastAuthUser",s=e+"."+this.username+".clockDrift";this.storage.removeItem(t),this.storage.removeItem(n),this.storage.removeItem(r),this.storage.removeItem(i),this.storage.removeItem(s)},t.getCognitoUserSession=function(e){var t=new ke(e),n=new Pe(e),r=new Ve(e);return new Le({IdToken:t,AccessToken:n,RefreshToken:r})},t.forgotPassword=function(e,t){var n={ClientId:this.pool.getClientId(),Username:this.username,ClientMetadata:t};this.getUserContextData()&&(n.UserContextData=this.getUserContextData()),this.client.request("ForgotPassword",n,(function(t,n){return t?e.onFailure(t):"function"==typeof e.inputVerificationCode?e.inputVerificationCode(n):e.onSuccess(n)}))},t.confirmPassword=function(e,t,n,r){var i={ClientId:this.pool.getClientId(),Username:this.username,ConfirmationCode:e,Password:t,ClientMetadata:r};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("ConfirmForgotPassword",i,(function(e){return e?n.onFailure(e):n.onSuccess("SUCCESS")}))},t.getAttributeVerificationCode=function(e,t,n){if(null==this.signInUserSession||!this.signInUserSession.isValid())return t.onFailure(new Error("User is not authenticated"));this.client.request("GetUserAttributeVerificationCode",{AttributeName:e,AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),ClientMetadata:n},(function(e,n){return e?t.onFailure(e):"function"==typeof t.inputVerificationCode?t.inputVerificationCode(n):t.onSuccess("SUCCESS")}))},t.verifyAttribute=function(e,t,n){if(null==this.signInUserSession||!this.signInUserSession.isValid())return n.onFailure(new Error("User is not authenticated"));this.client.request("VerifyUserAttribute",{AttributeName:e,Code:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(e){return e?n.onFailure(e):n.onSuccess("SUCCESS")}))},t.getDevice=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e.onFailure(new Error("User is not authenticated"));this.client.request("GetDevice",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),DeviceKey:this.deviceKey},(function(t,n){return t?e.onFailure(t):e.onSuccess(n)}))},t.forgetSpecificDevice=function(e,t){if(null==this.signInUserSession||!this.signInUserSession.isValid())return t.onFailure(new Error("User is not authenticated"));this.client.request("ForgetDevice",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),DeviceKey:e},(function(e){return e?t.onFailure(e):t.onSuccess("SUCCESS")}))},t.forgetDevice=function(e){var t=this;this.forgetSpecificDevice(this.deviceKey,{onFailure:e.onFailure,onSuccess:function(n){return t.deviceKey=null,t.deviceGroupKey=null,t.randomPassword=null,t.clearCachedDeviceKeyAndPassword(),e.onSuccess(n)}})},t.setDeviceStatusRemembered=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e.onFailure(new Error("User is not authenticated"));this.client.request("UpdateDeviceStatus",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),DeviceKey:this.deviceKey,DeviceRememberedStatus:"remembered"},(function(t){return t?e.onFailure(t):e.onSuccess("SUCCESS")}))},t.setDeviceStatusNotRemembered=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e.onFailure(new Error("User is not authenticated"));this.client.request("UpdateDeviceStatus",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),DeviceKey:this.deviceKey,DeviceRememberedStatus:"not_remembered"},(function(t){return t?e.onFailure(t):e.onSuccess("SUCCESS")}))},t.listDevices=function(e,t,n){if(null==this.signInUserSession||!this.signInUserSession.isValid())return n.onFailure(new Error("User is not authenticated"));var r={AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),Limit:e};t&&(r.PaginationToken=t),this.client.request("ListDevices",r,(function(e,t){return e?n.onFailure(e):n.onSuccess(t)}))},t.globalSignOut=function(e){var t=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return e.onFailure(new Error("User is not authenticated"));this.client.request("GlobalSignOut",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(n){return n?e.onFailure(n):(t.clearCachedUser(),e.onSuccess("SUCCESS"))}))},t.signOut=function(e){var t=this;e&&"function"==typeof e?this.getSession((function(n,r){if(n)return e(n);t.revokeTokens((function(n){t.cleanClientData(),e(n)}))})):this.cleanClientData()},t.revokeTokens=function(e){if(void 0===e&&(e=function(){}),"function"!=typeof e)throw new Error("Invalid revokeTokenCallback. It should be a function.");if(!this.signInUserSession)return e(new Error("User is not authenticated"));if(!this.signInUserSession.getAccessToken())return e(new Error("No Access token available"));var t=this.signInUserSession.getRefreshToken().getToken(),n=this.signInUserSession.getAccessToken();if(this.isSessionRevocable(n)&&t)return this.revokeToken({token:t,callback:e});e()},t.isSessionRevocable=function(e){if(e&&"function"==typeof e.decodePayload)try{return!!e.decodePayload().origin_jti}catch(e){}return!1},t.cleanClientData=function(){this.signInUserSession=null,this.clearCachedUser()},t.revokeToken=function(e){var t=e.token,n=e.callback;this.client.requestWithRetry("RevokeToken",{Token:t,ClientId:this.pool.getClientId()},(function(e){if(e)return n(e);n()}))},t.sendMFASelectionAnswer=function(e,t){var n=this,r={};r.USERNAME=this.username,r.ANSWER=e;var i={ChallengeName:"SELECT_MFA_TYPE",ChallengeResponses:r,ClientId:this.pool.getClientId(),Session:this.Session};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",i,(function(r,i){return r?t.onFailure(r):(n.Session=i.Session,"SMS_MFA"===e?t.mfaRequired(i.ChallengeName,i.ChallengeParameters):"SOFTWARE_TOKEN_MFA"===e?t.totpRequired(i.ChallengeName,i.ChallengeParameters):void 0)}))},t.getUserContextData=function(){return this.pool.getUserContextData(this.username)},t.associateSoftwareToken=function(e){var t=this;null!=this.signInUserSession&&this.signInUserSession.isValid()?this.client.request("AssociateSoftwareToken",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(t,n){return t?e.onFailure(t):e.associateSecretCode(n.SecretCode)})):this.client.request("AssociateSoftwareToken",{Session:this.Session},(function(n,r){return n?e.onFailure(n):(t.Session=r.Session,e.associateSecretCode(r.SecretCode))}))},t.verifySoftwareToken=function(e,t,n){var r=this;null!=this.signInUserSession&&this.signInUserSession.isValid()?this.client.request("VerifySoftwareToken",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),UserCode:e,FriendlyDeviceName:t},(function(e,t){return e?n.onFailure(e):n.onSuccess(t)})):this.client.request("VerifySoftwareToken",{Session:this.Session,UserCode:e,FriendlyDeviceName:t},(function(e,t){if(e)return n.onFailure(e);r.Session=t.Session;var i={};i.USERNAME=r.username;var s={ChallengeName:"MFA_SETUP",ClientId:r.pool.getClientId(),ChallengeResponses:i,Session:r.Session};r.getUserContextData()&&(s.UserContextData=r.getUserContextData()),r.client.request("RespondToAuthChallenge",s,(function(e,t){return e?n.onFailure(e):(r.signInUserSession=r.getCognitoUserSession(t.AuthenticationResult),r.cacheTokens(),n.onSuccess(r.signInUserSession))}))}))},e}(),Je=(n(204),"aws-amplify/5.0.4"),ze={userAgent:Je+" js",product:"",navigator:null,isReactNative:!1};function Ye(){}"undefined"!=typeof navigator&&navigator.product&&(ze.product=navigator.product||"",ze.navigator=navigator||null,"ReactNative"===navigator.product?(ze.userAgent=Je+" react-native",ze.isReactNative=!0):(ze.userAgent=Je+" js",ze.isReactNative=!1)),Ye.prototype.userAgent=ze.userAgent;const Qe=Ye;function Ge(e){var t="function"==typeof Map?new Map:void 0;return Ge=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return Ze(e,arguments,et(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),Xe(r,e)},Ge(e)}function Ze(e,t,n){return Ze=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&Xe(i,n.prototype),i},Ze.apply(null,arguments)}function Xe(e,t){return Xe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Xe(e,t)}function et(e){return et=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},et(e)}var tt=function(e){function t(t,n,r,i){var s;return(s=e.call(this,t)||this).code=n,s.name=r,s.statusCode=i,s}return r=e,(n=t).prototype=Object.create(r.prototype),n.prototype.constructor=n,Xe(n,r),t;var n,r}(Ge(Error)),nt=function(){function e(e,t,n){this.endpoint=t||"https://cognito-idp."+e+".amazonaws.com/";var r=(n||{}).credentials;this.fetchOptions=r?{credentials:r}:{}}var t=e.prototype;return t.promisifyRequest=function(e,t){var n=this;return new Promise((function(r,i){n.request(e,t,(function(e,t){e?i(new tt(e.message,e.code,e.name,e.statusCode)):r(t)}))}))},t.requestWithRetry=function(e,t,n){var r,i,s=this;(r=[t],i=5e3,void 0===i&&(i=ot),st((function(t){return new Promise((function(n,r){s.request(e,t,(function(e,t){e?r(e):n(t)}))}))}),r,function(e){return function(t){var n=100*Math.pow(2,t)+100*Math.random();return!(n>e)&&n}}(i))).then((function(e){return n(null,e)})).catch((function(e){return n(e)}))},t.request=function(e,t,n){var r,i={"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityProviderService."+e,"X-Amz-User-Agent":Qe.prototype.userAgent,"Cache-Control":"no-store"},s=Object.assign({},this.fetchOptions,{headers:i,method:"POST",mode:"cors",body:JSON.stringify(t)});fetch(this.endpoint,s).then((function(e){return r=e,e}),(function(e){if(e instanceof TypeError)throw new Error("Network error");throw e})).then((function(e){return e.json().catch((function(){return{}}))})).then((function(e){if(r.ok)return n(null,e);var t=(e.__type||e.code).split("#").pop(),i=new Error(e.message||e.Message||null);return i.name=t,i.code=t,n(i)})).catch((function(e){if(r&&r.headers&&r.headers.get("x-amzn-errortype"))try{var t=r.headers.get("x-amzn-errortype").split(":")[0],i=new Error(r.status?r.status.toString():null);return i.code=t,i.name=t,i.statusCode=r.status,n(i)}catch(t){return n(e)}else e instanceof Error&&"Network error"===e.message&&(e.code="NetworkError");return n(e)}))},e}(),rt={debug:function(){}},it=function(e){return e&&e.nonRetryable};function st(e,t,n,r){if(void 0===r&&(r=1),"function"!=typeof e)throw Error("functionToRetry must be a function");return rt.debug(e.name+" attempt #"+r+" with args: "+JSON.stringify(t)),e.apply(void 0,t).catch((function(i){if(rt.debug("error on "+e.name,i),it(i))throw rt.debug(e.name+" non retryable error",i),i;var s=n(r,t,i);if(rt.debug(e.name+" retrying in "+s+" ms"),!1!==s)return new Promise((function(e){return setTimeout(e,s)})).then((function(){return st(e,t,n,r+1)}));throw i}))}var ot=3e5,at=function(){function e(e,t){var n=e||{},r=n.UserPoolId,i=n.ClientId,s=n.endpoint,o=n.fetchOptions,a=n.AdvancedSecurityDataCollectionFlag;if(!r||!i)throw new Error("Both UserPoolId and ClientId are required.");if(r.length>55||!/^[\w-]+_[0-9a-zA-Z]+$/.test(r))throw new Error("Invalid UserPoolId format.");var u=r.split("_")[0];this.userPoolId=r,this.clientId=i,this.client=new nt(u,s,o),this.advancedSecurityDataCollectionFlag=!1!==a,this.storage=e.Storage||(new je).getStorage(),t&&(this.wrapRefreshSessionCallback=t)}var t=e.prototype;return t.getUserPoolId=function(){return this.userPoolId},t.getUserPoolName=function(){return this.getUserPoolId().split("_")[1]},t.getClientId=function(){return this.clientId},t.signUp=function(e,t,n,r,i,s){var o=this,a={ClientId:this.clientId,Username:e,Password:t,UserAttributes:n,ValidationData:r,ClientMetadata:s};this.getUserContextData(e)&&(a.UserContextData=this.getUserContextData(e)),this.client.request("SignUp",a,(function(t,n){if(t)return i(t,null);var r={Username:e,Pool:o,Storage:o.storage},s={user:new We(r),userConfirmed:n.UserConfirmed,userSub:n.UserSub,codeDeliveryDetails:n.CodeDeliveryDetails};return i(null,s)}))},t.getCurrentUser=function(){var e="CognitoIdentityServiceProvider."+this.clientId+".LastAuthUser",t=this.storage.getItem(e);if(t){var n={Username:t,Pool:this,Storage:this.storage};return new We(n)}return null},t.getUserContextData=function(e){if("undefined"!=typeof AmazonCognitoAdvancedSecurityData){var t=AmazonCognitoAdvancedSecurityData;if(this.advancedSecurityDataCollectionFlag){var n=t.getData(e,this.userPoolId,this.clientId);if(n)return{EncodedData:n}}return{}}},e}();n(808);let ut=null,ct=null;function lt(e){let t={tkid:"ticket_id",cond:"condition",actn:"action",cnt:"count",ttl:"time_to_live",stmp:"timestamp",plch:"placeholder",hash:"hash",desc:"description"},n={};for(let r in e)if("tkid"===r){let t=e[r].split("#");if(1===t.length){n.ticket_id=t[0];continue}n.ticket_id=t[1],n.consume_id=t[2],n.user_id=t[3],e.stmp||(n.timestamp=s(t[2].slice(0,-4)))}else t[r]?n[t[r]]=e[r]:n[r]=e[r];return n}async function ht(t){if(!t.ticket_id)throw new e("Ticket ID is required.",{code:"INVALID_PARAMETER"});let n=t.ticket_id;return delete t.ticket_id,await this.__connection,lt(await h.bind(this)(`https://${this.service.slice(0,4)}.skapi.dev/auth/consume/${this.service}/${this.owner}/${n}`,t,{auth:!0}))}async function ft(e,t){await this.__connection;let n=await h.bind(this)("ticket",Object.assign({exec:"list"},e||{}),{auth:!0,fetchOptions:t});return n.list=n.list.map(lt),n}async function dt(e,t){await this.__connection;let n=await h.bind(this)("ticket",Object.assign({exec:"consumed"},e||{}),{auth:!0,fetchOptions:t});return n.list=n.list.map(lt),n}async function pt(e){return this.request("register-ticket",Object.assign({exec:"reg"},e),{auth:!0})}async function gt(e){return this.request("register-ticket",Object.assign({exec:"unreg"},e),{auth:!0})}function mt(){if(!ct)throw new e("User pool is missing",{code:"INVALID_REQUEST"});const n=t=>{let n={};if(Array.isArray(t)){let n={};for(let r of t)if(n[r.Name]=r.Value,"custom:service"===r.Name&&n[r.Name]!==this.service)throw new e("The user is not registered to the service.",{code:"INVALID_REQUEST"});t=n}for(let r in t)if(r.includes("custom:")){if("custom:service"===r&&t[r]!==this.service)throw new e("The user is not registered to the service.",{code:"INVALID_REQUEST"});n[r.replace("custom:","")]=t[r]}else{if("address"===r){let e=t[r];if(e&&"object"==typeof e&&Object.keys(e).length&&e?.formatted)try{t[r]=JSON.parse(e.formatted)}catch(n){t[r]=e.formatted}}n[r]=t[r]}for(let e of["address_public","birthdate_public","email_public","gender_public","phone_number_public","access_group"])e.includes("_public")?n.hasOwnProperty(e.split("_")[0])?n[e]=!!n.hasOwnProperty(e)&&!!Number(n[e]):delete n[e]:n[e]=n.hasOwnProperty(e)?Number(n[e]):0;for(let e of["email","phone_number"])n.hasOwnProperty(e)?!0===n[e+"_verified"]||"true"===n[e+"_verified"]?n[e+"_verified"]=!0:n[e+"_verified"]=!1:delete n[e+"_verified"];for(let e of["aud",{from:"auth_time",to:"log"},"cognito:username","event_id","exp","iat","iss","jti","origin_jti","secret_key",{from:"sub",to:"user_id"},"token_use"])"string"==typeof e?delete n[e]:(n[e.to]=n[e.from],delete n[e.from]);this.__user=n},r=async t=>{let{refreshToken:r=!1}=t||{};return new Promise(((t,i)=>{ut=ct?.getCurrentUser()||null,null!==ut?ut.getSession(((s,o)=>{if(s)return void i(s);if(!o)return void i(new e("Current session does not exist.",{code:"INVALID_REQUEST"}));let a=r=>{let s=r.getIdToken().payload;if(s["custom:service"]!==this.service)return ut.signOut(),this.session=null,void i(new e("Invalid session.",{code:"INVALID_REQUEST"}));this.session=r,n(s),t(r)};if(!r&&o.isValid())return a(o);ut.refreshSession(o.getRefreshToken(),((t,n)=>{if(!t)return n.isValid()?a(n):void i(new e("Invalid session.",{code:"INVALID_REQUEST"}));i(t)}))})):i(null)}))},i=async n=>{if(!n)throw new e("E-Mail is required.",{code:"INVALID_PARAMETER"});let r=n.includes(this.service+"-")?n:this.service+"-"+t.hash(n);return{cognitoUser:new We({Username:r,Pool:ct}),cognitoUsername:r}};return{getSession:r,authenticateUser:(t,n)=>new Promise(((s,o)=>{this.__request_signup_confirmation=null,this.__disabledAccount=null,i(t).then((t=>{let i=t.cognitoUsername,a=new re({Username:i,Password:n});t.cognitoUser.authenticateUser(a,{newPasswordRequired:(a,u)=>{this.__request_signup_confirmation=i,"PASS"===a["custom:signup_ticket"]||"MEMBER"===a["custom:signup_ticket"]?t.cognitoUser.completeNewPasswordChallenge(n,{},{onSuccess:e=>{ut=t.cognitoUser,r().then((e=>s(this.user)))},onFailure:t=>{o(new e(t.message||"Failed to authenticate user.",{code:t.code}))}}):o(new e("User's signup confirmation is required.",{code:"SIGNUP_CONFIRMATION_NEEDED"}))},onSuccess:e=>r().then((e=>{s(this.user)})),onFailure:t=>{let n=[t.message||"Failed to authenticate user.",t?.code||"INVALID_REQUEST"];"NotAuthorizedException"===t.code?"User is disabled."===t.message?(this.__disabledAccount=i,n=["This account is disabled.","USER_IS_DISABLED"]):n=["Incorrect username or password.","INCORRECT_USERNAME_OR_PASSWORD"]:"UserNotFoundException"===t.code?n=["Incorrect username or password.","INCORRECT_USERNAME_OR_PASSWORD"]:"TooManyRequestsException"!==t.code&&"LimitExceededException"!==t.code||(n=["Too many attempts. Please try again later.","REQUEST_EXCEED"]);let r=n[1],s=n[0],a=n[0].split("#");a.length>1&&(a=a[a.length-1].split(":"),r=a[0],s=a[1]),o(new e(s,{code:r,cause:t}))}})}))})),createCognitoUser:i,getUser:()=>new Promise(((t,r)=>{this.session||t(null),null===ut?r(new e("Invalid session",{code:"INVALID_REQUEST"})):ut.getUserAttributes(((e,i)=>{e?r(e):(n(i),t(this.user))}))}))}}async function yt(e){await this.__authConnection;try{return await mt.bind(this)().getSession(e),this.user}catch(e){return null}}async function wt(){return await this.__connection,this.__user?.service===this.service?this.__user?.owner===this.host:(await _t.bind(this)(),!1)}async function _t(){await this.__connection,ut&&ut.signOut();let e={session:null,__startKeyHistory:{},__cached_requests:{},__user:null};for(let t in e)this[t]=e[t];return"SUCCESS: The user has been logged out."}async function bt(t){if(!this.__request_signup_confirmation)throw new e("Least one login attempt is required.",{code:"INVALID_REQUEST"});return t=t?u.Url(t):void 0,await h.bind(this)("confirm-signup",{username:this.__request_signup_confirmation,redirect:t})}async function At(t=!1){if("string"==typeof t)t=u.Url(t);else if("boolean"!=typeof t)throw new e("Argument should be type: <boolean | string>.",{code:"INVALID_REQUEST"});if(!this.__disabledAccount)throw new e("Least one signin attempt of disabled account is required.",{code:"INVALID_REQUEST"});return await h.bind(this)("recover-account",{username:this.__disabledAccount,redirect:t}),this.__disabledAccount=null,"SUCCESS: Recovery e-mail has been sent."}async function vt(t){u.Params(t,{idToken:"string",clientId:"string",keyUrl:e=>u.Url(e),provider:"string",nonce:"string"},["idToken","keyUrl","clientId"]);let{hashedPassword:n,username:r}=await h.bind(this)("jwt-login",t);try{return Et.bind(this)({username:r,password:n})}catch(t){if("INCORRECT_USERNAME_OR_PASSWORD"===t?.code)throw new e("User has migrated the account. Login with the service username and password.",{code:"INVALID_REQUEST"})}}async function Et(t){await this.logout();let n=u.Params(t,{username:"string",email:"string",password:"string"},["password"]);if(n.email)try{u.Email(n.email)}catch(e){n.username=n.email,delete n.email}if(!n.username&&!n.email)throw new e('Least one of "username" or "email" is required.',{code:"INVALID_PARAMETER"});return mt.bind(this)().authenticateUser(n.username||n.email,n.password)}async function St(t,n){let r=await wt.bind(this)(),i=u.Params(t||{},{username:"string",email:e=>u.Email(e),password:e=>u.Password(e),name:"string",address:"string",gender:"string",birthdate:e=>u.Birthdate(e),phone_number:e=>u.PhoneNumber(e),email_public:["boolean",()=>!1],address_public:["boolean",()=>!1],gender_public:["boolean",()=>!1],birthdate_public:["boolean",()=>!1],phone_number_public:["boolean",()=>!1],access_group:"number",misc:"string",picture:e=>u.Url(e),profile:e=>u.Url(e),family_name:"string",given_name:"string",middle_name:"string",nickname:"string",website:e=>u.Url(e)},r?["email"]:["email","password"]),s=r&&i.service&&this.service!==i.service;if(s)i.owner=this.__user.user_id;else if(!r){if(i.access_group)throw new e('Only admins can set "access_group" parameter.',{code:"INVALID_PARAMETER"});await this.logout()}n=u.Params(n||{},{email_subscription:t=>{if("boolean"!=typeof t)throw new e('"option.email_subscription" should be type: <boolean>.',{code:"INVALID_PARAMETER"});if(!n?.signup_confirmation)throw new e('"option.signup_confirmation" is required for email subscription.',{code:"INVALID_PARAMETER"});return t},signup_confirmation:t=>{if("string"==typeof t)return u.Url(t);if("boolean"==typeof t)return t;throw new e('"option.signup_confirmation" should be type: <string | boolean>.',{code:"INVALID_PARAMETER"})},login:t=>{if("boolean"==typeof t){if(n.signup_confirmation&&t)throw new e('"login" is not allowed when "option.signup_confirmation" is true.',{code:"INVALID_PARAMETER"});return t}throw new e('"option.login" should be type: boolean.',{code:"INVALID_PARAMETER"})}});let o=n?.login||!1,a=n?.signup_confirmation||!1;if(s&&a&&i?.password)throw new e('Admins cannot create an account with "option.signup_confirmation" option.',{code:"INVALID_PARAMETER"});if(i.email_public&&!a)throw new e('"option.signup_confirmation" should be true if "email_public" is set to true.',{code:"INVALID_PARAMETER"});i.signup_confirmation=a,i.email_subscription=n?.email_subscription||!1,s||(delete i.service,delete i.owner);let c=await h.bind(this)("signup",i,{auth:r});if(!r){if(a){let e=await mt.bind(this)().createCognitoUser(i.username||i.email);return ut=e.cognitoUser,this.__request_signup_confirmation=e.cognitoUsername,"SUCCESS: The account has been created. User's signup confirmation is required."}return o?Et.bind(this)({email:i.username||i.email,password:i.password}):"SUCCESS: The account has been created."}return c}async function It(){await this.__connection;let e=await h.bind(this)("remove-account",{disable:this.__user.user_id},{auth:!0});return await _t.bind(this)(),e}async function Rt(t){await this.__connection;let n=u.Params(t,{email:e=>u.Email(e),code:["number","string"],new_password:e=>u.Password(e)},["email","code","new_password"]),r=n.code,i=n.new_password;return"number"==typeof r&&(r=r.toString()),new Promise((async(t,s)=>{(await mt.bind(this)().createCognitoUser(n.email)).cognitoUser.confirmPassword(r,i,{onSuccess:e=>{t("SUCCESS: New password has been set.")},onFailure:t=>{s(new e(t?.message||"Failed to reset password.",{code:t?.code}))}})}))}async function Tt(t,n){let r;if(await this.__connection,!ut)throw new e("The user has to be logged in.",{code:"INVALID_REQUEST"});if("email"===t||"phone_number"===t){if(!this.__user.hasOwnProperty(t))throw new e(`No ${"email"===t?"e-mail":"phone number"} to verify`,{code:"INVALID_REQUEST"});return this.__user?.[`${t}_verified`]?`SUCCESS: "${t}" is verified.`:(r=(n?u.Params(n,{code:["string"]}):{}).code||"",new Promise(((n,i)=>{let s={onSuccess:e=>{r?mt.bind(this)().getSession({refreshToken:!0}).then((()=>{this.__user&&(this.__user[t+"_verified"]=!0),n(`SUCCESS: "${t}" is verified.`)})).catch((e=>{i(e)})):n("SUCCESS: Verification code has been sent.")},onFailure:t=>{i(new e(t.message||"Failed to request verification code.",{code:t?.code}))}};r?ut?.verifyAttribute(t,r,s):(s.inputVerificationCode=null,ut?.getAttributeVerificationCode(t,s))})))}}function Ut(e){return Tt.bind(this)("phone_number",e)}function Dt(e){return Tt.bind(this)("email",e)}async function Ct(t){await this.__connection;let n=u.Params(t,{email:e=>u.Email(e)},["email"]);return new Promise((async(t,r)=>{(await mt.bind(this)().createCognitoUser(n.email)).cognitoUser.forgotPassword({onSuccess:e=>{t("SUCCESS: Verification code has been sent.")},onFailure:t=>{r(new e(t?.message||"Failed to send verification code.",{code:t?.code||"ERROR"}))}})}))}async function Pt(t){if(await this.__connection,!this.session)throw new e("User login is required.",{code:"INVALID_REQUEST"});let n=u.Params(t,{current_password:"string",new_password:"string"});if(!n?.current_password)throw new e('"current_password" is required to change password.',{code:"INVALID_PARAMETER"});if(!n?.new_password)throw new e('"new_password" is required to change password.',{code:"INVALID_PARAMETER"});return u.Password(n.current_password),u.Password(n.new_password),new Promise(((t,r)=>{ut.changePassword(n.current_password,n.new_password,((n,i)=>{n&&r("InvalidParameterException"===n?.code?new e("Invalid password parameter.",{code:"INVALID_PARAMETER"}):"NotAuthorizedException"===n?.code?new e("Incorrect password.",{code:"INVALID_REQUEST"}):"TooManyRequestsException"===n?.code||"LimitExceededException"===n?.code?new e("Too many attempts. Please try again later.",{code:"REQUEST_EXCEED"}):new e(n?.message||"Failed to change user password.",{code:n?.code||n?.name})),t("SUCCESS: Password has been changed.")}))}))}async function Nt(n){if(await this.__connection,!this.session)throw new e("User login is required.",{code:"INVALID_REQUEST"});let r=u.Params(n||{},{email:e=>u.Email(e),address:e=>e?"string"==typeof e?e:"object"==typeof e?JSON.stringify(e):"":"",name:"string",gender:"string",birthdate:e=>u.Birthdate(e),phone_number:e=>u.PhoneNumber(e),email_public:"boolean",phone_number_public:"boolean",address_public:"boolean",gender_public:"boolean",birthdate_public:"boolean",misc:"string",picture:e=>u.Url(e),profile:e=>u.Url(e),family_name:"string",given_name:"string",middle_name:"string",nickname:"string",website:e=>u.Url(e)});if(r&&"object"==typeof r&&!Object.keys(r).length)return this.user;r.email&&(r.preferred_username=this.service+"-"+t.hash(r.email));let i=[["email_public","email_verified","User's E-Mail should be verified to set"],["phone_number_public","phone_number_verified","User's phone number should be verified to set"]];if(this.__user)for(let t of i)if(r[t[0]]&&!this.__user[t[1]])throw new e(`${t[2]} "${t[0]}" to true.`,{code:"INVALID_REQUEST"});let s=[];for(let e in r)if(r[e]!==this.user[e]){if(["email_public","phone_number_public","address_public","gender_public","birthdate_public","misc"].includes(e)){let t=r[e];"boolean"==typeof t&&(t=t?"1":"0"),r["custom:"+e]=t,s.push(e)}}else s.push(e);for(let e of s)delete r[e];if(r&&"object"==typeof r&&Object.keys(r).length){let e=[];for(let t in r)e.push(new $e({Name:t,Value:r[t]}));return await new Promise(((t,n)=>{ut?.updateAttributes(e,((e,r)=>{e&&n([e?.code||e?.name,e?.message||"Failed to update user settings."]),t(r)}))})),await mt.bind(this)().getSession({refreshToken:!0}),this.user}return this.user}async function kt(t,n){if(t||(t={searchFor:"timestamp",condition:">",value:0},n||(n={}),n.ascending=!1),await wt.bind(this)()&&!t.hasOwnProperty("service"))throw new e("Service ID is required.",{code:"INVALID_PARAMETER"});const r={user_id:e=>u.UserId(e),email:e=>u.Email(e),phone_number:e=>u.PhoneNumber(e),locale:t=>{if("string"!=typeof t||"string"==typeof t&&t.length>5)throw new e('Value of "locale" should be a country code.',{code:"INVALID_PARAMETER"});return t},name:"string",address:"string",gender:"string",birthdate:e=>u.Birthdate(e),subscribers:"number",timestamp:"number",access_group:"number",approved:e=>e?"by_admin:approved":"by_admin:suspended"};if(t=u.Params(t,{searchFor:["user_id","name","email","phone_number","address","gender","birthdate","locale","subscribers","timestamp","access_group","approved"],condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],value:n=>{let i=r[t.searchFor];if("function"==typeof i){if(!t?.condition||"="===t?.condition||t?.range)return i(n)}else if(typeof n!==i)throw new e(`Value does not match the type of "${t.searchFor}" index.`,{code:"INVALID_PARAMETER"});return n},range:n=>{let i=r[t.searchFor];if("function"==typeof i)return i(n);if(typeof n!==i)throw new e(`Range does not match the type of "${t.searchFor}" index.`,{code:"INVALID_PARAMETER"});return n}},["searchFor","value"]),t?.condition&&"="!==t?.condition&&t.hasOwnProperty("range"))throw new e("Conditions does not apply on range search.",{code:"INVALID_PARAMETER"});if("user_id"===t.searchFor&&"="!==t.condition)throw new e('Conditions are not allowed on "user_id"',{code:"INVALID_PARAMETER"});if("string"==typeof t?.value&&!t?.value)throw new e("Value should not be an empty string.",{code:"INVALID_PARAMETER"});if("string"==typeof t?.searchFor&&!t?.searchFor)throw new e('"searchFor" should not be an empty string.',{code:"INVALID_PARAMETER"});return h.bind(this)("get-users",t,{auth:!0,fetchOptions:n})}async function Mt(e){await this.__connection;let t=await h.bind(this)("last-verified-email",e,{auth:!0});return t.includes("SUCCESS")?(await mt.bind(this)().getSession({refreshToken:!0}),this.user):t}async function Ot(e){return await this.__connection,e=u.Params(e,{username:u.Email,redirect:u.Url},["username"]),await h.bind(this)("request-username-change",e,{auth:!0})}var Vt=function(e,t,n,r){var i,s=arguments.length,o=s<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(o=(s<3?i(o):s>3?i(t,n,o):i(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o};class Lt{get user(){return this.__user&&Object.keys(this.__user).length?JSON.parse(JSON.stringify(this.__user)):null}set user(e){}constructor(t,n,r,i){if(this.version="1.0.58",this.session=null,this.connection=null,this.host="skapi",this.hostDomain="skapi.com",this.target_cdn="d3e9syvbtso631",this.__disabledAccount=null,this.__cached_requests={},this.__startKeyHistory={},this.__request_signup_confirmation=null,this.__private_access_key={},this.__class_properties_has_been_cached=!1,this.__user=null,this.validate={userId(e){try{return u.UserId(e),!0}catch(e){return!1}},url(e){try{return u.Url(e),!0}catch(e){return!1}},phoneNumber(e){try{return u.PhoneNumber(e),!0}catch(e){return!1}},birthdate(e){try{return u.Birthdate(e),!0}catch(e){return!1}},email(e){try{return u.Email(e),!0}catch(e){return!1}}},this.checkAdmin=wt.bind(this),this.request=h.bind(this),this.registerTicket=pt.bind(this),this.unregisterTicket=gt.bind(this),this.hostFiles=g.bind(this),this.normalizeRecord=A.bind(this),"string"!=typeof t||"string"!=typeof n)throw new e('"service" and "owner" should be type <string>.',{code:"INVALID_PARAMETER"});if(!t||!n)throw new e('"service" and "owner" is required',{code:"INVALID_PARAMETER"});n!==this.host&&u.UserId(n,'"owner"'),this.service=t,this.owner=n;let s=!!r?.autoLogin;this.target_cdn=i?.target_cdn||this.target_cdn,this.hostDomain=i?.hostDomain||this.hostDomain;const o=`https://${this.target_cdn}.cloudfront.net`;let a=t.substring(0,4);if(this.admin_endpoint=fetch(`${o}/${a}/admin.json`).then((e=>e.blob())).then((e=>new Promise(((t,n)=>{const r=new FileReader;r.onloadend=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)})))).then((e=>"string"==typeof e?JSON.parse(window.atob(e.split(",")[1])):null)),this.record_endpoint=fetch(`${o}/${a}/record.json`).then((e=>e.blob())).then((e=>new Promise(((t,n)=>{const r=new FileReader;r.onloadend=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)})))).then((e=>"string"==typeof e?JSON.parse(window.atob(e.split(",")[1])):null)),!window.sessionStorage)throw new Error("This browser does not support skapi.");const c=JSON.parse(window.sessionStorage.getItem(`${t}#${n}`)||"null");if(c?.connection)for(let e in c)this[e]=c[e];this.__authConnection=(async()=>{const e=await this.admin_endpoint;var t;if(t={UserPoolId:e.userpool_id,ClientId:e.userpool_client},ct=new at(t),!c?.connection&&!s){let e=ct.getCurrentUser();e&&e.signOut()}if(s)try{await mt.bind(this)().getSession({refreshToken:!c?.connection})}catch(e){this.__user=null}})(),this.__connection=(async()=>{let e=null;c?.connection||(e=this.updateConnection());const r=()=>{if(this.__class_properties_has_been_cached)return;let r=()=>{let e={};const r=["__startKeyHistory","__cached_requests","__request_signup_confirmation","connection"];if(this.connection){for(let t of r)e[t]=this[t];window.sessionStorage.setItem(`${t}#${n}`,JSON.stringify(e)),this.__class_properties_has_been_cached=!0}};return e instanceof Promise?e.then((()=>r())):r()};return window.addEventListener("beforeunload",(()=>{r(),this.closeRealtime()})),await e,await this.__authConnection,console.log(`Built with:\n%c\r\n $$\\ $$\\ \r\n $$ | \\__|\r\n $$$$$$$\\ $$ | $$\\ $$$$$$\\ $$$$$$\\ $$\\ \r\n$$ _____|$$ | $$ |\\____$$\\ $$ __$$\\ $$ |\r\n\\$$$$$$\\ $$$$$$ / $$$$$$$ |$$ / $$ |$$ |\r\n \\____$$\\ $$ _$$< $$ __$$ |$$ | $$ |$$ |\r\n$$$$$$$ |$$ | \\$$\\\\$$$$$$$ |$$$$$$$ |$$ |\r\n\\_______/ \\__| \\__|\\_______|$$ ____/ \\__|\r\n $$ | \r\n $$ | \r\n \\__| \r\nVersion: ${this.version}\n\nDocumentation: https://docs.skapi.com`,"font-family: monospace; color:blue;"),1===this.connection.group&&console.log("%cSKAPI: THE SERVICE IS IN TRIAL MODE. ALL THE USERS AND DATA WILL BE INITIALIZED EVERY 7 DAYS.","font-family: monospace; color:red;"),this.connection})()}async updateConnection(){return this.connection=await h.bind(this)("service",{service:this.service,owner:this.owner},{bypassAwaitConnection:!0,method:"get"}),this.connection}connectRealtime(e){return F.bind(this)(e)}jwtLogin(e){return vt.bind(this)(e)}clientSecretRequest(e){return K.bind(this)(e)}consumeTicket(e){return ht.bind(this)(e)}getConsumedTickets(e,t){return dt.bind(this)(e,t)}getTickets(e,t){return ft.bind(this)(e,t)}closeRealtime(){return L.bind(this)()}getRealtimeUsers(e,t){return $.bind(this)(e,t)}getRealtimeGroups(e,t){return q.bind(this)(e,t)}postRealtime(e,t){return x.bind(this)(e,t)}joinRealtime(e){return B.bind(this)(e)}getConnection(){return this.__connection}getProfile(e){return yt.bind(this)(e)}getFile(e,t){return E.bind(this)(e,t)}secureRequest(e){return j.bind(this)(e)}getFormResponse(){return _.bind(this)()}getRecords(e,t){return S.bind(this)(e,t)}getTables(e,t){return R.bind(this)(e,t)}getIndexes(e,t){return T.bind(this)(e,t)}getTags(e,t){return U.bind(this)(e,t)}deleteRecords(e){return D.bind(this)(e)}resendSignupConfirmation(e){return bt.bind(this)(e)}recoverAccount(e=!1){return At.bind(this)(e)}getUsers(e,t){return kt.bind(this)(e,t)}disableAccount(){return It.bind(this)()}lastVerifiedEmail(e){return Mt.bind(this)(e)}unsubscribeNewsletter(e){return ee.bind(this)(e)}getNewsletters(e,t){return te.bind(this)(e,t)}getNewsletterSubscription(e){return Z.bind(this)(e)}requestUsernameChange(e){return Ot.bind(this)(e)}grantPrivateRecordAccess(e){return C.bind(this)(e)}removePrivateRecordAccess(e){return P.bind(this)(e)}listPrivateRecordAccess(e){return N.bind(this)(e)}requestPrivateRecordAccessKey(e){return k.bind(this)(e)}deleteFiles(e){return v.bind(this)(e)}uploadFiles(e,t){return m.bind(this)(e,t)}mock(e,t){return H.bind(this)(e,t)}login(e){return Et.bind(this)(e)}logout(){return _t.bind(this)()}signup(e,t){return St.bind(this)(e,t)}resetPassword(e){return Rt.bind(this)(e)}verifyEmail(e){return Dt.bind(this)(e)}verifyPhoneNumber(e){return Ut.bind(this)(e)}forgotPassword(e){return Ct.bind(this)(e)}changePassword(e){return Pt.bind(this)(e)}updateProfile(e){return Nt.bind(this)(e)}postRecord(e,t){return I.bind(this)(e,t)}getSubscriptions(e,t){return J.bind(this)(e,t)}subscribe(e){return z.bind(this)(e)}unsubscribe(e){return Y.bind(this)(e)}blockSubscriber(e){return Q.bind(this)(e)}unblockSubscriber(e){return G.bind(this)(e)}subscribeNewsletter(e){return X.bind(this)(e)}}Vt([w()],Lt.prototype,"consumeTicket",null),Vt([w()],Lt.prototype,"getConsumedTickets",null),Vt([w()],Lt.prototype,"getTickets",null),Vt([w()],Lt.prototype,"getRealtimeUsers",null),Vt([w()],Lt.prototype,"getRealtimeGroups",null),Vt([w()],Lt.prototype,"postRealtime",null),Vt([w()],Lt.prototype,"joinRealtime",null),Vt([w()],Lt.prototype,"getProfile",null),Vt([w()],Lt.prototype,"getFile",null),Vt([w()],Lt.prototype,"secureRequest",null),Vt([w()],Lt.prototype,"getFormResponse",null),Vt([w()],Lt.prototype,"getRecords",null),Vt([w()],Lt.prototype,"getTables",null),Vt([w()],Lt.prototype,"getIndexes",null),Vt([w()],Lt.prototype,"getTags",null),Vt([w()],Lt.prototype,"deleteRecords",null),Vt([w()],Lt.prototype,"resendSignupConfirmation",null),Vt([w()],Lt.prototype,"recoverAccount",null),Vt([w()],Lt.prototype,"getUsers",null),Vt([w()],Lt.prototype,"disableAccount",null),Vt([w()],Lt.prototype,"lastVerifiedEmail",null),Vt([w()],Lt.prototype,"unsubscribeNewsletter",null),Vt([w()],Lt.prototype,"getNewsletters",null),Vt([w()],Lt.prototype,"getNewsletterSubscription",null),Vt([w()],Lt.prototype,"requestUsernameChange",null),Vt([w()],Lt.prototype,"grantPrivateRecordAccess",null),Vt([w()],Lt.prototype,"removePrivateRecordAccess",null),Vt([w()],Lt.prototype,"listPrivateRecordAccess",null),Vt([w()],Lt.prototype,"requestPrivateRecordAccessKey",null),Vt([w()],Lt.prototype,"deleteFiles",null),Vt([w()],Lt.prototype,"uploadFiles",null),Vt([w()],Lt.prototype,"mock",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"login",null),Vt([w()],Lt.prototype,"logout",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"signup",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"resetPassword",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"verifyEmail",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"verifyPhoneNumber",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"forgotPassword",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"changePassword",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"updateProfile",null),Vt([w()],Lt.prototype,"postRecord",null),Vt([w()],Lt.prototype,"getSubscriptions",null),Vt([w()],Lt.prototype,"subscribe",null),Vt([w()],Lt.prototype,"unsubscribe",null),Vt([w()],Lt.prototype,"blockSubscriber",null),Vt([w()],Lt.prototype,"unblockSubscriber",null),Vt([w()],Lt.prototype,"subscribeNewsletter",null)})(),r})()));
|
|
2
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(self,(()=>(()=>{var e={742:(e,t)=>{"use strict";t.byteLength=function(e){var t=a(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,s=a(e),o=s[0],u=s[1],c=new i(function(e,t,n){return 3*(t+n)/4-n}(0,o,u)),l=0,h=u>0?o-4:o;for(n=0;n<h;n+=4)t=r[e.charCodeAt(n)]<<18|r[e.charCodeAt(n+1)]<<12|r[e.charCodeAt(n+2)]<<6|r[e.charCodeAt(n+3)],c[l++]=t>>16&255,c[l++]=t>>8&255,c[l++]=255&t;return 2===u&&(t=r[e.charCodeAt(n)]<<2|r[e.charCodeAt(n+1)]>>4,c[l++]=255&t),1===u&&(t=r[e.charCodeAt(n)]<<10|r[e.charCodeAt(n+1)]<<4|r[e.charCodeAt(n+2)]>>2,c[l++]=t>>8&255,c[l++]=255&t),c},t.fromByteArray=function(e){for(var t,r=e.length,i=r%3,s=[],o=16383,a=0,c=r-i;a<c;a+=o)s.push(u(e,a,a+o>c?c:a+o));return 1===i?(t=e[r-1],s.push(n[t>>2]+n[t<<4&63]+"==")):2===i&&(t=(e[r-2]<<8)+e[r-1],s.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"=")),s.join("")};for(var n=[],r=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0;o<64;++o)n[o]=s[o],r[s.charCodeAt(o)]=o;function a(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function u(e,t,r){for(var i,s,o=[],a=t;a<r;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(n[(s=i)>>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return o.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},764:(e,t,n)=>{"use strict";var r=n(742),i=n(645),s=n(826);function o(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(o()<t)throw new RangeError("Invalid typed array length");return u.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=u.prototype:(null===e&&(e=new u(t)),e.length=t),e}function u(e,t,n){if(!(u.TYPED_ARRAY_SUPPORT||this instanceof u))return new u(e,t,n);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return h(this,e)}return c(this,e,t,n)}function c(e,t,n,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,n,r){if(t.byteLength,n<0||t.byteLength<n)throw new RangeError("'offset' is out of bounds");if(t.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");return t=void 0===n&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,n):new Uint8Array(t,n,r),u.TYPED_ARRAY_SUPPORT?(e=t).__proto__=u.prototype:e=f(e,t),e}(e,t,n,r):"string"==typeof t?function(e,t,n){if("string"==typeof n&&""!==n||(n="utf8"),!u.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|p(t,n),i=(e=a(e,r)).write(t,n);return i!==r&&(e=e.slice(0,i)),e}(e,t,n):function(e,t){if(u.isBuffer(t)){var n=0|d(t.length);return 0===(e=a(e,n)).length||t.copy(e,0,0,n),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(r=t.length)!=r?a(e,0):f(e,t);if("Buffer"===t.type&&s(t.data))return f(e,t.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function l(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function h(e,t){if(l(t),e=a(e,t<0?0:0|d(t)),!u.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)e[n]=0;return e}function f(e,t){var n=t.length<0?0:0|d(t.length);e=a(e,n);for(var r=0;r<n;r+=1)e[r]=255&t[r];return e}function d(e){if(e>=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|e}function p(e,t){if(u.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return B(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return $(e).length;default:if(r)return B(e).length;t=(""+t).toLowerCase(),r=!0}}function g(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return C(this,t,n);case"utf8":case"utf-8":return R(this,t,n);case"ascii":return U(this,t,n);case"latin1":case"binary":return D(this,t,n);case"base64":return I(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function m(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function y(e,t,n,r,i){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof t&&(t=u.from(t,r)),u.isBuffer(t))return 0===t.length?-1:w(e,t,n,r,i);if("number"==typeof t)return t&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):w(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function w(e,t,n,r,i){var s,o=1,a=e.length,u=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;o=2,a/=2,u/=2,n/=2}function c(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){var l=-1;for(s=n;s<a;s++)if(c(e,s)===c(t,-1===l?0:s-l)){if(-1===l&&(l=s),s-l+1===u)return l*o}else-1!==l&&(s-=s-l),l=-1}else for(n+u>a&&(n=a-u),s=n;s>=0;s--){for(var h=!0,f=0;f<u;f++)if(c(e,s+f)!==c(t,f)){h=!1;break}if(h)return s}return-1}function _(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r))>i&&(r=i):r=i;var s=t.length;if(s%2!=0)throw new TypeError("Invalid hex string");r>s/2&&(r=s/2);for(var o=0;o<r;++o){var a=parseInt(t.substr(2*o,2),16);if(isNaN(a))return o;e[n+o]=a}return o}function b(e,t,n,r){return q(B(t,e.length-n),e,n,r)}function A(e,t,n,r){return q(function(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function v(e,t,n,r){return A(e,t,n,r)}function E(e,t,n,r){return q($(t),e,n,r)}function S(e,t,n,r){return q(function(e,t){for(var n,r,i,s=[],o=0;o<e.length&&!((t-=2)<0);++o)r=(n=e.charCodeAt(o))>>8,i=n%256,s.push(i),s.push(r);return s}(t,e.length-n),e,n,r)}function I(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function R(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i<n;){var s,o,a,u,c=e[i],l=null,h=c>239?4:c>223?3:c>191?2:1;if(i+h<=n)switch(h){case 1:c<128&&(l=c);break;case 2:128==(192&(s=e[i+1]))&&(u=(31&c)<<6|63&s)>127&&(l=u);break;case 3:s=e[i+1],o=e[i+2],128==(192&s)&&128==(192&o)&&(u=(15&c)<<12|(63&s)<<6|63&o)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:s=e[i+1],o=e[i+2],a=e[i+3],128==(192&s)&&128==(192&o)&&128==(192&a)&&(u=(15&c)<<18|(63&s)<<12|(63&o)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,h=1):l>65535&&(l-=65536,r.push(l>>>10&1023|55296),l=56320|1023&l),r.push(l),i+=h}return function(e){var t=e.length;if(t<=T)return String.fromCharCode.apply(String,e);for(var n="",r=0;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=T));return n}(r)}t.lW=u,t.h2=50,u.TYPED_ARRAY_SUPPORT=void 0!==n.g.TYPED_ARRAY_SUPPORT?n.g.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),o(),u.poolSize=8192,u._augment=function(e){return e.__proto__=u.prototype,e},u.from=function(e,t,n){return c(null,e,t,n)},u.TYPED_ARRAY_SUPPORT&&(u.prototype.__proto__=Uint8Array.prototype,u.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&u[Symbol.species]===u&&Object.defineProperty(u,Symbol.species,{value:null,configurable:!0})),u.alloc=function(e,t,n){return function(e,t,n,r){return l(t),t<=0?a(e,t):void 0!==n?"string"==typeof r?a(e,t).fill(n,r):a(e,t).fill(n):a(e,t)}(null,e,t,n)},u.allocUnsafe=function(e){return h(null,e)},u.allocUnsafeSlow=function(e){return h(null,e)},u.isBuffer=function(e){return!(null==e||!e._isBuffer)},u.compare=function(e,t){if(!u.isBuffer(e)||!u.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,i=0,s=Math.min(n,r);i<s;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:r<n?1:0},u.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}},u.concat=function(e,t){if(!s(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return u.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=u.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){var o=e[n];if(!u.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(r,i),i+=o.length}return r},u.byteLength=p,u.prototype._isBuffer=!0,u.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)m(this,t,t+1);return this},u.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)m(this,t,t+3),m(this,t+1,t+2);return this},u.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)m(this,t,t+7),m(this,t+1,t+6),m(this,t+2,t+5),m(this,t+3,t+4);return this},u.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?R(this,0,e):g.apply(this,arguments)},u.prototype.equals=function(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===u.compare(this,e)},u.prototype.inspect=function(){var e="",n=t.h2;return this.length>0&&(e=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(e+=" ... ")),"<Buffer "+e+">"},u.prototype.compare=function(e,t,n,r,i){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(this===e)return 0;for(var s=(i>>>=0)-(r>>>=0),o=(n>>>=0)-(t>>>=0),a=Math.min(s,o),c=this.slice(r,i),l=e.slice(t,n),h=0;h<a;++h)if(c[h]!==l[h]){s=c[h],o=l[h];break}return s<o?-1:o<s?1:0},u.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},u.prototype.indexOf=function(e,t,n){return y(this,e,t,n,!0)},u.prototype.lastIndexOf=function(e,t,n){return y(this,e,t,n,!1)},u.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var i=this.length-t;if((void 0===n||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var s=!1;;)switch(r){case"hex":return _(this,e,t,n);case"utf8":case"utf-8":return b(this,e,t,n);case"ascii":return A(this,e,t,n);case"latin1":case"binary":return v(this,e,t,n);case"base64":return E(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var T=4096;function U(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(127&e[i]);return r}function D(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function C(e,t,n){var r,i=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>i)&&(n=i);for(var s="",o=t;o<n;++o)s+=(r=e[o])<16?"0"+r.toString(16):r.toString(16);return s}function P(e,t,n){for(var r=e.slice(t,n),i="",s=0;s<r.length;s+=2)i+=String.fromCharCode(r[s]+256*r[s+1]);return i}function N(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function k(e,t,n,r,i,s){if(!u.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function M(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,s=Math.min(e.length-n,2);i<s;++i)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function O(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,s=Math.min(e.length-n,4);i<s;++i)e[n+i]=t>>>8*(r?i:3-i)&255}function V(e,t,n,r,i,s){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function L(e,t,n,r,s){return s||V(e,0,n,4),i.write(e,t,n,r,23,4),n+4}function F(e,t,n,r,s){return s||V(e,0,n,8),i.write(e,t,n,r,52,8),n+8}u.prototype.slice=function(e,t){var n,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e),u.TYPED_ARRAY_SUPPORT)(n=this.subarray(e,t)).__proto__=u.prototype;else{var i=t-e;n=new u(i,void 0);for(var s=0;s<i;++s)n[s]=this[s+e]}return n},u.prototype.readUIntLE=function(e,t,n){e|=0,t|=0,n||N(e,t,this.length);for(var r=this[e],i=1,s=0;++s<t&&(i*=256);)r+=this[e+s]*i;return r},u.prototype.readUIntBE=function(e,t,n){e|=0,t|=0,n||N(e,t,this.length);for(var r=this[e+--t],i=1;t>0&&(i*=256);)r+=this[e+--t]*i;return r},u.prototype.readUInt8=function(e,t){return t||N(e,1,this.length),this[e]},u.prototype.readUInt16LE=function(e,t){return t||N(e,2,this.length),this[e]|this[e+1]<<8},u.prototype.readUInt16BE=function(e,t){return t||N(e,2,this.length),this[e]<<8|this[e+1]},u.prototype.readUInt32LE=function(e,t){return t||N(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},u.prototype.readUInt32BE=function(e,t){return t||N(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},u.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||N(e,t,this.length);for(var r=this[e],i=1,s=0;++s<t&&(i*=256);)r+=this[e+s]*i;return r>=(i*=128)&&(r-=Math.pow(2,8*t)),r},u.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||N(e,t,this.length);for(var r=t,i=1,s=this[e+--r];r>0&&(i*=256);)s+=this[e+--r]*i;return s>=(i*=128)&&(s-=Math.pow(2,8*t)),s},u.prototype.readInt8=function(e,t){return t||N(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},u.prototype.readInt16LE=function(e,t){t||N(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt16BE=function(e,t){t||N(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt32LE=function(e,t){return t||N(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},u.prototype.readInt32BE=function(e,t){return t||N(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},u.prototype.readFloatLE=function(e,t){return t||N(e,4,this.length),i.read(this,e,!0,23,4)},u.prototype.readFloatBE=function(e,t){return t||N(e,4,this.length),i.read(this,e,!1,23,4)},u.prototype.readDoubleLE=function(e,t){return t||N(e,8,this.length),i.read(this,e,!0,52,8)},u.prototype.readDoubleBE=function(e,t){return t||N(e,8,this.length),i.read(this,e,!1,52,8)},u.prototype.writeUIntLE=function(e,t,n,r){e=+e,t|=0,n|=0,r||k(this,e,t,n,Math.pow(2,8*n)-1,0);var i=1,s=0;for(this[t]=255&e;++s<n&&(i*=256);)this[t+s]=e/i&255;return t+n},u.prototype.writeUIntBE=function(e,t,n,r){e=+e,t|=0,n|=0,r||k(this,e,t,n,Math.pow(2,8*n)-1,0);var i=n-1,s=1;for(this[t+i]=255&e;--i>=0&&(s*=256);)this[t+i]=e/s&255;return t+n},u.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,1,255,0),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},u.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):M(this,e,t,!0),t+2},u.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):M(this,e,t,!1),t+2},u.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):O(this,e,t,!0),t+4},u.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):O(this,e,t,!1),t+4},u.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);k(this,e,t,n,i-1,-i)}var s=0,o=1,a=0;for(this[t]=255&e;++s<n&&(o*=256);)e<0&&0===a&&0!==this[t+s-1]&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+n},u.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);k(this,e,t,n,i-1,-i)}var s=n-1,o=1,a=0;for(this[t+s]=255&e;--s>=0&&(o*=256);)e<0&&0===a&&0!==this[t+s+1]&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+n},u.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,1,127,-128),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},u.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):M(this,e,t,!0),t+2},u.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):M(this,e,t,!1),t+2},u.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):O(this,e,t,!0),t+4},u.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||k(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):O(this,e,t,!1),t+4},u.prototype.writeFloatLE=function(e,t,n){return L(this,e,t,!0,n)},u.prototype.writeFloatBE=function(e,t,n){return L(this,e,t,!1,n)},u.prototype.writeDoubleLE=function(e,t,n){return F(this,e,t,!0,n)},u.prototype.writeDoubleBE=function(e,t,n){return F(this,e,t,!1,n)},u.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var i,s=r-n;if(this===e&&n<t&&t<r)for(i=s-1;i>=0;--i)e[i+t]=this[i+n];else if(s<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i<s;++i)e[i+t]=this[i+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+s),t);return s},u.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===e.length){var i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!u.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;var s;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(s=t;s<n;++s)this[s]=e;else{var o=u.isBuffer(e)?e:B(new u(e,r).toString()),a=o.length;for(s=0;s<n-t;++s)this[s+t]=o[s%a]}return this};var x=/[^+\/0-9A-Za-z-_]/g;function B(e,t){var n;t=t||1/0;for(var r=e.length,i=null,s=[],o=0;o<r;++o){if((n=e.charCodeAt(o))>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===r){(t-=3)>-1&&s.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&s.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;s.push(n)}else if(n<2048){if((t-=2)<0)break;s.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;s.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return s}function $(e){return r.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(x,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function q(e,t,n,r){for(var i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}},249:function(e,t,n){var r;e.exports=(r=r||function(e,t){var r;if("undefined"!=typeof window&&window.crypto&&(r=window.crypto),"undefined"!=typeof self&&self.crypto&&(r=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(r=globalThis.crypto),!r&&"undefined"!=typeof window&&window.msCrypto&&(r=window.msCrypto),!r&&void 0!==n.g&&n.g.crypto&&(r=n.g.crypto),!r)try{r=n(480)}catch(e){}var i=function(){if(r){if("function"==typeof r.getRandomValues)try{return r.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof r.randomBytes)try{return r.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||function(){function e(){}return function(t){var n;return e.prototype=t,n=new e,e.prototype=null,n}}(),o={},a=o.lib={},u=a.Base={extend:function(e){var t=s(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},c=a.WordArray=u.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes,i=e.sigBytes;if(this.clamp(),r%4)for(var s=0;s<i;s++){var o=n[s>>>2]>>>24-s%4*8&255;t[r+s>>>2]|=o<<24-(r+s)%4*8}else for(var a=0;a<i;a+=4)t[r+a>>>2]=n[a>>>2];return this.sigBytes+=i,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=u.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],n=0;n<e;n+=4)t.push(i());return new c.init(t,e)}}),l=o.enc={},h=l.Hex={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],i=0;i<n;i++){var s=t[i>>>2]>>>24-i%4*8&255;r.push((s>>>4).toString(16)),r.push((15&s).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new c.init(n,t/2)}},f=l.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],i=0;i<n;i++){var s=t[i>>>2]>>>24-i%4*8&255;r.push(String.fromCharCode(s))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new c.init(n,t)}},d=l.Utf8={stringify:function(e){try{return decodeURIComponent(escape(f.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return f.parse(unescape(encodeURIComponent(e)))}},p=a.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new c.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=d.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n,r=this._data,i=r.words,s=r.sigBytes,o=this.blockSize,a=s/(4*o),u=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,l=e.min(4*u,s);if(u){for(var h=0;h<u;h+=o)this._doProcessBlock(i,h);n=i.splice(0,u),r.sigBytes-=l}return new c.init(n,l)},clone:function(){var e=u.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),g=(a.Hasher=p.extend({cfg:u.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){p.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new g.HMAC.init(e,n).finalize(t)}}}),o.algo={});return o}(Math),r)},269:function(e,t,n){var r,i,s;e.exports=(r=n(249),s=(i=r).lib.WordArray,i.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,r=this._map;e.clamp();for(var i=[],s=0;s<n;s+=3)for(var o=(t[s>>>2]>>>24-s%4*8&255)<<16|(t[s+1>>>2]>>>24-(s+1)%4*8&255)<<8|t[s+2>>>2]>>>24-(s+2)%4*8&255,a=0;a<4&&s+.75*a<n;a++)i.push(r.charAt(o>>>6*(3-a)&63));var u=r.charAt(64);if(u)for(;i.length%4;)i.push(u);return i.join("")},parse:function(e){var t=e.length,n=this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var i=0;i<n.length;i++)r[n.charCodeAt(i)]=i}var o=n.charAt(64);if(o){var a=e.indexOf(o);-1!==a&&(t=a)}return function(e,t,n){for(var r=[],i=0,o=0;o<t;o++)if(o%4){var a=n[e.charCodeAt(o-1)]<<o%4*2|n[e.charCodeAt(o)]>>>6-o%4*2;r[i>>>2]|=a<<24-i%4*8,i++}return s.create(r,i)}(e,t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},r.enc.Base64)},10:function(e,t,n){var r;e.exports=(r=n(249),n(153),n(824),r.HmacSHA256)},824:function(e,t,n){var r,i,s;e.exports=(i=(r=n(249)).lib.Base,s=r.enc.Utf8,void(r.algo.HMAC=i.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var i=this._oKey=t.clone(),o=this._iKey=t.clone(),a=i.words,u=o.words,c=0;c<n;c++)a[c]^=1549556828,u[c]^=909522486;i.sigBytes=o.sigBytes=r,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,n=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(n))}})))},433:function(e,t,n){var r;e.exports=(r=n(249),function(){if("function"==typeof ArrayBuffer){var e=r.lib.WordArray,t=e.init,n=e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var n=e.byteLength,r=[],i=0;i<n;i++)r[i>>>2]|=e[i]<<24-i%4*8;t.call(this,r,n)}else t.apply(this,arguments)};n.prototype=e}}(),r.lib.WordArray)},153:function(e,t,n){var r;e.exports=(r=n(249),function(e){var t=r,n=t.lib,i=n.WordArray,s=n.Hasher,o=t.algo,a=[],u=[];!function(){function t(t){for(var n=e.sqrt(t),r=2;r<=n;r++)if(!(t%r))return!1;return!0}function n(e){return 4294967296*(e-(0|e))|0}for(var r=2,i=0;i<64;)t(r)&&(i<8&&(a[i]=n(e.pow(r,.5))),u[i]=n(e.pow(r,1/3)),i++),r++}();var c=[],l=o.SHA256=s.extend({_doReset:function(){this._hash=new i.init(a.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],i=n[1],s=n[2],o=n[3],a=n[4],l=n[5],h=n[6],f=n[7],d=0;d<64;d++){if(d<16)c[d]=0|e[t+d];else{var p=c[d-15],g=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,m=c[d-2],y=(m<<15|m>>>17)^(m<<13|m>>>19)^m>>>10;c[d]=g+c[d-7]+y+c[d-16]}var w=r&i^r&s^i&s,_=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22),b=f+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&l^~a&h)+u[d]+c[d];f=h,h=l,l=a,a=o+b|0,o=s,s=i,i=r,r=b+(_+w)|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+s|0,n[3]=n[3]+o|0,n[4]=n[4]+a|0,n[5]=n[5]+l|0,n[6]=n[6]+h|0,n[7]=n[7]+f|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;return n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=e.floor(r/4294967296),n[15+(i+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(l),t.HmacSHA256=s._createHmacHelper(l)}(Math),r.SHA256)},645:(e,t)=>{t.read=function(e,t,n,r,i){var s,o,a=8*i-r-1,u=(1<<a)-1,c=u>>1,l=-7,h=n?i-1:0,f=n?-1:1,d=e[t+h];for(h+=f,s=d&(1<<-l)-1,d>>=-l,l+=a;l>0;s=256*s+e[t+h],h+=f,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=r;l>0;o=256*o+e[t+h],h+=f,l-=8);if(0===s)s=1-c;else{if(s===u)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,r),s-=c}return(d?-1:1)*o*Math.pow(2,s-r)},t.write=function(e,t,n,r,i,s){var o,a,u,c=8*s-i-1,l=(1<<c)-1,h=l>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:s-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-o))<1&&(o--,u*=2),(t+=o+h>=1?f/u:f*Math.pow(2,1-h))*u>=2&&(o++,u/=2),o+h>=l?(a=0,o=l):o+h>=1?(a=(t*u-1)*Math.pow(2,i),o+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),o=0));i>=8;e[n+d]=255&a,d+=p,a/=256,i-=8);for(o=o<<i|a,c+=i;c>0;e[n+d]=255&o,d+=p,o/=256,c-=8);e[n+d-p]|=128*g}},826:e=>{var t={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==t.call(e)}},204:(e,t,n)=>{e.exports=self.fetch||(self.fetch=n(869).default||n(869))},808:(e,t,n)=>{var r,i,s;void 0===(i="function"==typeof(r=s=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(r){function i(){}function s(t,n,s){if("undefined"!=typeof document){"number"==typeof(s=e({path:"/"},i.defaults,s)).expires&&(s.expires=new Date(1*new Date+864e5*s.expires)),s.expires=s.expires?s.expires.toUTCString():"";try{var o=JSON.stringify(n);/^[\{\[]/.test(o)&&(n=o)}catch(e){}n=r.write?r.write(n,t):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var u in s)s[u]&&(a+="; "+u,!0!==s[u]&&(a+="="+s[u].split(";")[0]));return document.cookie=t+"="+n+a}}function o(e,n){if("undefined"!=typeof document){for(var i={},s=document.cookie?document.cookie.split("; "):[],o=0;o<s.length;o++){var a=s[o].split("="),u=a.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var c=t(a[0]);if(u=(r.read||r)(u,c)||t(u),n)try{u=JSON.parse(u)}catch(e){}if(i[c]=u,e===c)break}catch(e){}}return e?i[e]:i}}return i.set=s,i.get=function(e){return o(e,!1)},i.getJSON=function(e){return o(e,!0)},i.remove=function(t,n){s(t,"",e(n,{expires:-1}))},i.defaults={},i.withConverter=n,i}((function(){}))})?r.call(t,n,t,e):r)||(e.exports=i),e.exports=s()},869:(e,t,n)=>{"use strict";function r(e,t){return t=t||{},new Promise((function(n,r){var i=new XMLHttpRequest,s=[],o=[],a={},u=function(){return{ok:2==(i.status/100|0),statusText:i.statusText,status:i.status,url:i.responseURL,text:function(){return Promise.resolve(i.responseText)},json:function(){return Promise.resolve(i.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([i.response]))},clone:u,headers:{keys:function(){return s},entries:function(){return o},get:function(e){return a[e.toLowerCase()]},has:function(e){return e.toLowerCase()in a}}}};for(var c in i.open(t.method||"get",e,!0),i.onload=function(){i.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,n){s.push(t=t.toLowerCase()),o.push([t,n]),a[t]=a[t]?a[t]+","+n:n})),n(u())},i.onerror=r,i.withCredentials="include"==t.credentials,t.headers)i.setRequestHeader(c,t.headers[c]);i.send(t.body||null)}))}n.r(t),n.d(t,{default:()=>r})},296:()=>{},480:()=>{}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r].call(s.exports,s,s.exports,n),s.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{Skapi:()=>Lt,SkapiError:()=>e});class e extends Error{constructor(e,t){if(Array.isArray(e)&&e.length<=2){let n=e[1];if(e.length>2)for(let t=2;t<e.length&&"string"==typeof e[t];t++)n+=e[t];super((n||"Something went wrong.").trim()),this.name=t?.name||"SKAPI",this.code=t?.code||e[0]||"ERROR",t?.cause&&(this.cause=t.cause)}else"string"==typeof e?(super((e||"Something went wrong.").trim()),this.name=t?.name||"SKAPI",this.code=t?.code||"ERROR",t?.cause&&(this.cause=t.cause)):e instanceof Error&&(super((e.message||"Something went wrong.").trim()),this.cause=e,this.name=e.name,e.hasOwnProperty("code")&&(this.code=e.code))}}class t{static hash(e){"string"!=typeof e&&(console.warn("coercing non-string value to empty string"),e="");const n=t.sb(e);let r,i,s,o,a=1732584193,u=-271733879,c=-1732584194,l=271733878;for(let e=0;e<n.length;e+=16)r=a,i=u,s=c,o=l,a=t.ff(a,u,c,l,n[e],7,-680876936),l=t.ff(l,a,u,c,n[e+1],12,-389564586),c=t.ff(c,l,a,u,n[e+2],17,606105819),u=t.ff(u,c,l,a,n[e+3],22,-1044525330),a=t.ff(a,u,c,l,n[e+4],7,-176418897),l=t.ff(l,a,u,c,n[e+5],12,1200080426),c=t.ff(c,l,a,u,n[e+6],17,-1473231341),u=t.ff(u,c,l,a,n[e+7],22,-45705983),a=t.ff(a,u,c,l,n[e+8],7,1770035416),l=t.ff(l,a,u,c,n[e+9],12,-1958414417),c=t.ff(c,l,a,u,n[e+10],17,-42063),u=t.ff(u,c,l,a,n[e+11],22,-1990404162),a=t.ff(a,u,c,l,n[e+12],7,1804603682),l=t.ff(l,a,u,c,n[e+13],12,-40341101),c=t.ff(c,l,a,u,n[e+14],17,-1502002290),u=t.ff(u,c,l,a,n[e+15],22,1236535329),a=t.gg(a,u,c,l,n[e+1],5,-165796510),l=t.gg(l,a,u,c,n[e+6],9,-1069501632),c=t.gg(c,l,a,u,n[e+11],14,643717713),u=t.gg(u,c,l,a,n[e],20,-373897302),a=t.gg(a,u,c,l,n[e+5],5,-701558691),l=t.gg(l,a,u,c,n[e+10],9,38016083),c=t.gg(c,l,a,u,n[e+15],14,-660478335),u=t.gg(u,c,l,a,n[e+4],20,-405537848),a=t.gg(a,u,c,l,n[e+9],5,568446438),l=t.gg(l,a,u,c,n[e+14],9,-1019803690),c=t.gg(c,l,a,u,n[e+3],14,-187363961),u=t.gg(u,c,l,a,n[e+8],20,1163531501),a=t.gg(a,u,c,l,n[e+13],5,-1444681467),l=t.gg(l,a,u,c,n[e+2],9,-51403784),c=t.gg(c,l,a,u,n[e+7],14,1735328473),u=t.gg(u,c,l,a,n[e+12],20,-1926607734),a=t.hh(a,u,c,l,n[e+5],4,-378558),l=t.hh(l,a,u,c,n[e+8],11,-2022574463),c=t.hh(c,l,a,u,n[e+11],16,1839030562),u=t.hh(u,c,l,a,n[e+14],23,-35309556),a=t.hh(a,u,c,l,n[e+1],4,-1530992060),l=t.hh(l,a,u,c,n[e+4],11,1272893353),c=t.hh(c,l,a,u,n[e+7],16,-155497632),u=t.hh(u,c,l,a,n[e+10],23,-1094730640),a=t.hh(a,u,c,l,n[e+13],4,681279174),l=t.hh(l,a,u,c,n[e],11,-358537222),c=t.hh(c,l,a,u,n[e+3],16,-722521979),u=t.hh(u,c,l,a,n[e+6],23,76029189),a=t.hh(a,u,c,l,n[e+9],4,-640364487),l=t.hh(l,a,u,c,n[e+12],11,-421815835),c=t.hh(c,l,a,u,n[e+15],16,530742520),u=t.hh(u,c,l,a,n[e+2],23,-995338651),a=t.ii(a,u,c,l,n[e],6,-198630844),l=t.ii(l,a,u,c,n[e+7],10,1126891415),c=t.ii(c,l,a,u,n[e+14],15,-1416354905),u=t.ii(u,c,l,a,n[e+5],21,-57434055),a=t.ii(a,u,c,l,n[e+12],6,1700485571),l=t.ii(l,a,u,c,n[e+3],10,-1894986606),c=t.ii(c,l,a,u,n[e+10],15,-1051523),u=t.ii(u,c,l,a,n[e+1],21,-2054922799),a=t.ii(a,u,c,l,n[e+8],6,1873313359),l=t.ii(l,a,u,c,n[e+15],10,-30611744),c=t.ii(c,l,a,u,n[e+6],15,-1560198380),u=t.ii(u,c,l,a,n[e+13],21,1309151649),a=t.ii(a,u,c,l,n[e+4],6,-145523070),l=t.ii(l,a,u,c,n[e+11],10,-1120210379),c=t.ii(c,l,a,u,n[e+2],15,718787259),u=t.ii(u,c,l,a,n[e+9],21,-343485551),a=t.ad(a,r),u=t.ad(u,i),c=t.ad(c,s),l=t.ad(l,o);return t.rh(a)+t.rh(u)+t.rh(c)+t.rh(l)}static rh(e){let n="";for(let r=0;r<=3;r++)n+=t.alphabet.charAt(e>>8*r+4&15)+t.alphabet.charAt(e>>8*r&15);return n}static ad(e,t){const n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}static rl(e,t){return e<<t|e>>>32-t}static cm(e,n,r,i,s,o){return t.ad(t.rl(t.ad(t.ad(n,e),t.ad(i,o)),s),r)}static ff(e,n,r,i,s,o,a){return t.cm(n&r|~n&i,e,n,s,o,a)}static gg(e,n,r,i,s,o,a){return t.cm(n&i|r&~i,e,n,s,o,a)}static hh(e,n,r,i,s,o,a){return t.cm(n^r^i,e,n,s,o,a)}static ii(e,n,r,i,s,o,a){return t.cm(r^(n|~i),e,n,s,o,a)}static sb(e){let t;const n=1+(e.length+8>>6),r=new Array(16*n);for(t=0;t<16*n;t++)r[t]=0;for(t=0;t<e.length;t++)r[t>>2]|=e.charCodeAt(t)<<t%4*8;return r[t>>2]|=128<<t%4*8,r[16*n-2]=8*e.length,r}}function i(e){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";if(0===e)return t[0];let n="";for(;e>0;)n=t[e%62]+n,e=Math.floor(e/62);return n}function s(e){return e.split("").reverse().reduce(((e,t,n)=>e+"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".indexOf(t)*62**n),0)}function o(e=6){let t="";let n=0;for(;n<e;)t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random())),n+=1;return t}function a(t){function n(e,t,n){let r=t.slice(0,1),i=t.slice(-1);if("."===r&&(t=t.slice(1)),"."===i&&(t=t.slice(0,-1)),t.includes(".")){let n=t.split(".");t=n.pop();for(let t of n)t&&(e.hasOwnProperty(t)||(e[t]={}),e=e[t])}e.hasOwnProperty(t)?Array.isArray(e[t])?e[t].push(n):e[t]=[e[t],n]:e[t]=n}let r=[];if(t instanceof FormData){let e={},i=0,s=[];for(let o of t.entries()){let t=o[0],a=o[1];if(a instanceof File){if(i+a.size>4e6){r.push({name:t,file:a});continue}i+=a.size,s.push({name:t,file:a})}else if(a instanceof FileList){if(a&&a.length>0)for(let e=0;e<=a.length-1;e++)i+a.item(e).size>4e6?r.push({name:t,file:a.item(e)}):(i+=a.item(e).size,s.push({name:t,file:a.item(e)}))}else n(e,t,a)}return{meta:e,files:s,to_bin:r}}if(t instanceof SubmitEvent&&(t=t.target),t instanceof HTMLFormElement){let s={},o=[],a=0,u=t.querySelectorAll("input"),c=t.querySelectorAll("textarea");for(let e=0;e<c.length;e++){let t=c[e];t.name&&n(s,t.name,t.value)}for(let e=0;e<u.length;e++){let t=u[e];if(t.name)if("number"===t.type)t.value&&n(s,t.name,Number(t.value));else if("checkbox"===t.type||"radio"===t.type)t.checked?""===t.value&&"checkbox"===t.type||"on"===t.value||"true"===t.value?n(s,t.name,!0):"false"===t.value?n(s,t.name,!1):t.value&&n(s,t.name,t.value):"checkbox"===t.type&&(""===t.value||"on"===t.value||"true"===t.value?n(s,t.name,!1):"false"===t.value?n(s,t.name,!0):n(s,t.name,void 0));else if("file"===t.type){if(t.files&&t.files.length>0)for(let e=0;e<=t.files.length-1;e++)a+t.files.item(e).size>4e6?r.push({name:t.name,file:t.files.item(e)}):(a+=t.files.item(e).size,o.push({name:t.name,file:t.files.item(e)}))}else n(s,t.name,t.value)}if(i=s,new Blob([JSON.stringify(i)]).size>2097152)throw new e("JSON Data should not exceed 2MB",{code:"INVALID_REQUEST"});return{meta:s,files:o,to_bin:r}}var i;return null}t.alphabet="0123456789abcdef";const u={UserId:function(t,n="User ID"){if(!t)throw new e(`${n} is empty.`,{code:"INVALID_PARAMETER"});if("string"!=typeof t)throw new e(`${n} should be type: string.`,{code:"INVALID_PARAMETER"});if(!t.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i))throw new e(`${n} is invalid.`,{code:"INVALID_PARAMETER"});return t},PhoneNumber:function(t){if(t&&("string"!=typeof t||"+"!==t.charAt(0)||isNaN(Number(t.substring(1)))))throw new e('"phone_number" is invalid. The format should be "+00123456789". Type: string.',{code:"INVALID_PARAMETER"});return t||""},Birthdate:function(t){if(t){if("string"!=typeof t)throw new e('"birthdate" is invalid. The format should be "yyyy-mm-dd". Type: string.',{code:"INVALID_PARAMETER"});{let n=new RegExp(/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/);if(10!==t.length||3!==t.split("-").length||!n.test(t))throw new e('"birthdate" is invalid. The format should be "yyyy-mm-dd". Type: string.',{code:"INVALID_PARAMETER"})}}return t||""},Password:function(t){if(!t)throw new e('"password" is required.',{code:"INVALID_PARAMETER"});if("string"!=typeof t)throw new e('"password" should be type: string.',{code:"INVALID_PARAMETER"});if(t.length<6)throw new e('"password" should be at least 6 characters.',{code:"INVALID_PARAMETER"});if(t.length>60)throw new e('"password" can be up to 60 characters max.',{code:"INVALID_PARAMETER"});return t},Email:function(t,n="email"){if(!t)throw new e(`"${n}" is required.`,{code:"INVALID_PARAMETER"});if("string"!=typeof t)throw new e(`"${n}"should be type: string.`,{code:"INVALID_PARAMETER"});if(t.length<5)throw new e(`"${n}" should be at least 5 characters.`,{code:"INVALID_PARAMETER"});if(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(t)&&(t=t.trim()).split("@")[1].split(".").length>=2)return t.toLowerCase();throw new e(`"${t}" is an invalid email.`,{code:"INVALID_PARAMETER"})},Url:function(t){const n=(()=>{let e=window.location.origin||null;return e&&"/"===e.slice(-1)&&(e=e.slice(0,-1)),e})();let r=t=>{if("string"==typeof t){if("*"===t)return"*";{let r,i=t.trim();if("/"===i[0]&&n){if("file:"===n.slice(0,5))throw new e(`"${t}" is an invalid url. Relative URL does not work on local file system. Use full URL string.`,{code:"INVALID_PARAMETER"});i=n+i}else if("."===i[0]&&n){if("file:"===n.slice(0,5))throw new e(`"${t}" is an invalid url. Relative URL does not work on local file system. Use full URL string.`,{code:"INVALID_PARAMETER"});let r=window.location.href.split("?")[0];"/"!==r.slice(-1)&&(r+="/"),i=r+i.slice(1)}try{r=new URL(i)}catch(n){throw new e(`"${t}" is an invalid url.`,{code:"INVALID_PARAMETER"})}if(r.protocol)return r.href}}throw new e(`"${t}" is an invalid url.`,{code:"INVALID_PARAMETER"})};return Array.isArray(t)?t.map((e=>r(e))):r(t)},specialChars:function(t,n="parameter",r=!1,i=!1){let s=t=>{if("string"!=typeof t)throw new e(`${n} should be type: <string | string[]>.`,{code:"INVALID_PARAMETER"});if(!i&&t.includes(" "))throw new e(`${n} should not have whitespace.`,{code:"INVALID_PARAMETER"});if(!r&&t.includes("."))throw new e(`${n} should not have periods.`,{code:"INVALID_PARAMETER"});if(/[!@#$%&*()+\-={};':"\|,<>\/?~]/.test(t))throw new e(`${n} should not have special characters.`,{code:"INVALID_PARAMETER"})};if(Array.isArray(t))for(let e of t)s(e);else s(t);return t},Params:function t(n,r,i=null,s=[],o=null){function u(t){if(t instanceof Promise)throw new e("Parameter should not be a promise",{code:"INVALID_PARAMETER"});return t&&"object"==typeof t&&!Array.isArray(t)&&Object.keys(t).length}Array.isArray(s)&&(s=s.concat(["service","owner"]));let c,l=n,h=null,f=o?` in "${o}" is invalid.`:". Parameter should be type <object>.";if(null===o){if(u(l)){l=l instanceof HTMLFormElement||l instanceof FormData||l instanceof SubmitEvent?a(n)?.meta:JSON.parse(JSON.stringify(n));for(let t in l)if(!r.hasOwnProperty(t)&&Array.isArray(s)&&!s.includes(t))throw new e(`Key name "${t}" is invalid in parameter.`,{code:"INVALID_PARAMETER"});if(Array.isArray(i)&&i.length)for(let t of i)if(!Object.keys(l).includes(t))throw new e(`Key "${t}" is required in parameter.`,{code:"INVALID_PARAMETER"})}else if((d=l)&&"object"==typeof d&&!Array.isArray(d)&&!Object.keys(d).length||void 0===l){let e={};for(let t in r){let n=r[t];Array.isArray(n)&&"function"==typeof n[n.length-1]&&(e[t]=n[n.length-1]())}return Object.keys(e).length?e:l}if(null===l)return null}var d;if(u(r)&&u(l)){for(let e in r){let n=r[e];if(l.hasOwnProperty(e)&&null===l[e])l[e]=null;else if(l.hasOwnProperty(e)&&void 0!==l[e])l[e]=t(l[e],n,null,null,e);else{let t=Array.isArray(n)&&"function"==typeof n[n.length-1]?n[n.length-1]:null;if(t){let n=t();void 0!==n&&(l[e]=n)}}}c=l}else if(Array.isArray(r))for(let n of r)try{void 0!==typeof l&&"function"!=typeof n&&(c=t(l,n,null,null,o));break}catch(t){if("string"==typeof t&&"BREAK:"===t.substring(0,6)){let n=(t=t.substring(6)).split(":");h=new e(n[1],{code:n[0]});break}h=t}else{if("function"==typeof r)return r(l);if("string"==typeof r)if(Array.isArray(l)){if("array"!==r)throw new e(`Invalid type "${typeof l}"${f}`,{code:"INVALID_PARAMETER"});for(let t of l)if(!["number","string","boolean"].includes(typeof t)&&null!==t)throw new e(`Invalid type "${typeof t}" in "${o}" array value.`,{code:"INVALID_PARAMETER"});c=l}else if(["number","string","boolean","array","function"].includes(r)){if(typeof l!==r)throw new e(`Value: ${l}${f}`,{code:"INVALID_PARAMETER"});if("number"===r&&Math.abs(l)>4503599627370496)throw`BREAK:INVALID_PARAMETER:"${o}" integer value should be within -4503599627370496 ~ +4503599627370546.`;c=l}else{if(l!==r)throw new e(`Value: ${l}${f}`,{code:"INVALID_PARAMETER"});c=l}else null===r&&(c=l)}if(void 0===c&&h)throw h;return c}};async function c(e,t){const n=await Promise.all([this.admin_endpoint,this.record_endpoint]),r=n[0],i=n[1];let s=e.split("?"),o=s.length>1?"?"+s[1]:"";switch(e=s[0]){case"get-newsletters":case"get-public-newsletters":case"get-users":case"post-userdata":case"remove-account":case"post-secure":case"subscribe-newsletter":case"subscribe-public-newsletter":case"signup":case"confirm-signup":case"recover-account":case"mock":case"service":case"grant-access":case"last-verified-email":case"ticket":case"register-ticket":case"get-newsletter-subscription":case"request-username-change":case"jwt-login":case"client-secret-request":return(t?r.admin_private:r.admin_public)+e+o;case"post-record":case"get-records":case"subscription":case"get-subscription":case"del-records":case"get-table":case"get-tag":case"get-index":case"get-signed-url":case"grant-private-access":case"request-private-access-key":case"get-ws-group":case"del-files":return(t?i.record_private:i.record_public)+e+o;default:return u.Url(e)}}const l={};async function h(n,r=null,i){i=i||{};let{auth:s=!1,method:o="post",bypassAwaitConnection:a=!1}=i;o=o.toUpperCase();let h=null,g=this.service,m=this.owner,y=null,w=await c.bind(this)(n,!!s);if(!a&&(h=await this.__connection,!h))throw new e("Invalid connection. The service could have been disabled, or has a restricted CORS.",{code:"INVALID_REQUEST"});if(s){if(!this.session)throw this.logout(),new e("User login is required.",{code:"INVALID_REQUEST"});{let t=Date.now()/1e3;if(this.session.idToken.payload.exp<t)try{await this.authentication().getSession({refreshToken:!0})}catch(t){throw this.logout(),new e("User login is required.",{code:"INVALID_REQUEST"})}y=this.session?.idToken?.jwtToken}}let _={},{fetchMore:b=!1,progress:A}=i?.fetchOptions||{};if(i?.fetchOptions&&Object.keys(i.fetchOptions).length){for(let e of["limit","startKey","ascending"])i.fetchOptions.hasOwnProperty(e)&&(_[e]=i.fetchOptions[e]);_=u.Params(_,{limit:t=>{if("number"!=typeof t)throw new e("Fetch limit should be a number.",{code:"INVALID_REQUEST"});if(t>1e3)throw new e("Fetch limit should be below 1000.",{code:"INVALID_REQUEST"});return t},startKey:e=>e,ascending:"boolean"})}let v={service:g,owner:m};Object.assign(v,_),r instanceof SubmitEvent&&(r=r?.target),r instanceof HTMLFormElement&&(r=new FormData(r));let E=r instanceof FormData;if(r)if(E)for(let e in v)void 0!==v[e]&&r.set(e,new Blob([JSON.stringify(v[e])],{type:"application/json"}));else r=Object.assign(v,r);else r=v;let S=(()=>{if(r&&"object"==typeof r&&Object.keys(r).length&&!(r instanceof FormData)){function e(t){return"object"==typeof t&&null!==t?Object.keys(t).sort().reduce(((n,r)=>("object"==typeof t[r]&&null!==t[r]?n[r]=e(t[r]):n[r]=t[r],n)),{}):t}return t.hash(n+"/"+JSON.stringify(e(r)))}return t.hash(n+"/"+this.service)})(),I=f.bind(this)({params:r,url:n,fetchMore:b,hashedParams:S});if(!I||I&&"object"==typeof I)return I;if(l[I]instanceof Promise)return l[I];let R={Accept:"*/*","Content-Type":i?.contentType||r instanceof FormData?"multipart/form-data":"application/json"};y&&(R.Authorization=y);let T={headers:R};if(i?.responseType&&(T.responseType=i.responseType),"GET"===o){if(r){let e=[];if(r instanceof FormData)for(let[t,n]of r.entries())"string"==typeof n&&(n=encodeURIComponent(n),e.push(`&${t}=${n}`));else e=Object.keys(r).map((e=>{let t=r[e];return"string"!=typeof t&&(t=JSON.stringify(t)),encodeURIComponent(e)+"="+encodeURIComponent(t)}));e.length&&("?"!==w.substring(w.length-1)&&(w+="?"),w+=e.join("&"))}T.body=null}else T.body=r instanceof FormData?r:r?JSON.stringify(r):null;T.method=o,l[I]=d.bind(this)(w,T,A);try{return p.bind(this)({hashedParam:I,url:n,fetched:await l[I]})}finally{I&&l.hasOwnProperty(I)&&delete l[I]}}function f(n){let{params:r={},url:i,fetchMore:s=!1,hashedParams:o}=n||{};if(r.startKey){if(("object"!=typeof r.startKey||!Object.keys(r.startKey).length)&&"start"!==r.startKey&&"end"!==r.startKey)throw new e(`"${r.startKey}" is invalid startKey key.`,{code:"INVALID_PARAMETER"});"start"===r.startKey&&(s=!1,delete r.startKey)}if(!s&&this.__startKeyHistory?.[i]?.[o]){if(this.__cached_requests?.[i]?.[o]&&delete this.__cached_requests[i][o],Array.isArray(this.__startKeyHistory[i][o])&&this.__startKeyHistory[i][o].length)for(let e of this.__startKeyHistory[i][o]){let n=o+t.hash(e);this.__cached_requests?.[i]&&this.__cached_requests?.[i]?.[n]&&delete this.__cached_requests[i][n]}return delete this.__startKeyHistory[i][o],o}if(!Array.isArray(this.__startKeyHistory?.[i]?.[o]))return o;let a=this.__startKeyHistory[i][o],u=a[a.length-1],c=o;if(u){if("end"===u)return{list:[],startKey:"end",endOfList:!0,startKeyHistory:a};c+=t.hash(u),r.startKey=JSON.parse(u)}return this.__cached_requests?.[i]?.[c]?this.__cached_requests[i][c]:o}function d(t,n,r){return new Promise(((i,s)=>{let o=new XMLHttpRequest;for(var a in o.open(n.method||"GET",t),n.headers||{})o.setRequestHeader(a,n.headers[a]);n.responseType&&(o.responseType=n.responseType),o.onload=()=>{if(o.status<400)if("json"==n.responseType||"blob"==n.responseType)i(o.response);else{let e=o.responseText;try{e=JSON.parse(e)}catch(e){}i(e)}else{let t=o.status,n=["INVALID_CORS","INVALID_REQUEST","SERVICE_DISABLED","INVALID_PARAMETER","ERROR","EXISTS","NOT_EXISTS"],r=o.responseText;try{r=JSON.parse(r)}catch(e){}if("string"==typeof r){let t=o.response.split(":"),r=t.splice(0,1)[0].trim();s(new e(t.join(":").trim(),{code:n.includes(r)?r:"ERROR"}))}else if("object"==typeof r&&r?.message){let n=r?.code||(t?t.toString():null)||"ERROR",i=r.message;"string"==typeof i&&(i=i.trim()),s(new e(i,{code:n}))}else s(r)}},o.onerror=()=>s("Network error"),o.onabort=()=>s("Aborted"),o.ontimeout=()=>s("Timeout"),"function"==typeof r&&(o.onprogress=e=>{r({status:"download",progress:e.loaded/e.total*100,loaded:e.loaded,total:e.total,abort:()=>o.abort()})},o.upload&&(o.upload.onprogress=e=>{r({status:"upload",progress:e.loaded/e.total*100,loaded:e.loaded,total:e.total,abort:()=>o.abort()})})),o.send(n.body)}))}function p(e){let{hashedParam:t,url:n,fetched:r}=e;if(!r?.startKey)return r;this.__startKeyHistory.hasOwnProperty(n)||(this.__startKeyHistory[n]={}),this.__cached_requests?.[n]||(this.__cached_requests[n]={}),this.__cached_requests[n][t]=r,this.__startKeyHistory[n].hasOwnProperty(t)||(this.__startKeyHistory[n][t]=[]);let i="end"===r.startKey?"end":JSON.stringify(r.startKey);return this.__startKeyHistory[n][t].includes(i)||this.__startKeyHistory[n][t].push(i),Object.assign({startKeyHistory:this.__startKeyHistory[n][t]},r)}async function g(t,n){await this.__connection;let{service:r,dir:s="",progress:a}=n;if(s&&(s=s.replace(/^\//,"").replace(/\/$/,"")+"/"),!r||r===this.service)throw new e("invalid service.",{code:"INVALID_PARAMETER"});if(!(t instanceof FormData))throw new e('"fileList" should be a FormData or HTMLFormElement.',{code:"INVALID_PARAMETER"});let u,c={reserved_key:o(),service:r,request:"host"},l=(e,t,n)=>new Promise(((r,i)=>{u=new XMLHttpRequest,u.open("POST",e),u.onload=()=>{let e=u.responseText;try{e=JSON.parse(e)}catch(e){}u.status>=200&&u.status<300?r(e):i(e)},u.onerror=()=>i("Network error"),u.onabort=()=>i("Aborted"),u.ontimeout=()=>i("Timeout"),u.upload&&"function"==typeof n&&(u.upload.onprogress=n),u.send(t)})),f=[],d=[],p=[];for(let[e,n]of t.entries()){if(!(n instanceof File))continue;let e=Object.assign({key:s+n.name,sizeKey:i(n.size),contentType:n.type||null},c),{fields:t=null,url:r,cdn:o}=await h.bind(this)("get-signed-url",e,{auth:!0});p.push(o);let g=new FormData;for(let e in t)g.append(e,t[e]);g.append("file",n);try{await l(r,g,"function"==typeof a?e=>a({status:"upload",progress:e.loaded/e.total*100,currentFile:n,completed:f,failed:d,loaded:e.loaded,total:e.total,abort:()=>u.abort()}):null),f.push(n)}catch(e){d.push(n)}}return{completed:f,failed:d,bin_endpoints:p}}async function m(t,n){await this.__connection;let{record_id:r,service:i=this.service,progress:s}=n;if(!r)throw new e('"record_id" is required.',{code:"INVALID_PARAMETER"});if(t instanceof SubmitEvent&&(t=t.target),t instanceof HTMLFormElement&&(t=new FormData(t)),!(t instanceof FormData))throw new e('"fileList" should be a FormData or HTMLFormElement.',{code:"INVALID_PARAMETER"});let a,u={reserved_key:o(),service:i,request:"post"};n?.record_id&&(u.id=n.record_id);let c=(e,t,n)=>new Promise(((r,i)=>{a=new XMLHttpRequest,a.open("POST",e),a.onload=()=>{let e=a.responseText;try{e=JSON.parse(e)}catch(e){}a.status>=200&&a.status<300?r(e):i(e)},a.onerror=()=>i("Network error"),a.onabort=()=>i("Aborted"),a.ontimeout=()=>i("Timeout"),a.upload&&"function"==typeof n&&(a.upload.onprogress=n),a.send(t)})),l=[],f=[];function d(e){const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";if(0===e)return t[0];let n="";for(;e>0;)n=t[e%62]+n,e=Math.floor(e/62);return n}let p=[];for(let[e,n]of t.entries()){if(!(n instanceof File))continue;let t=Object.assign({key:e+"/"+n.name,sizeKey:d(n.size),contentType:n.type||null},u),{fields:r=null,url:i,cdn:o}=await h.bind(this)("get-signed-url",t,{auth:!0});p.push(o);let g=new FormData;for(let e in r)g.append(e,r[e]);g.append("file",n);try{await c(i,g,"function"==typeof s?e=>s({status:"upload",progress:e.loaded/e.total*100,currentFile:n,completed:l,failed:f,loaded:e.loaded,total:e.total,abort:()=>a.abort()}):null),l.push(n)}catch(e){f.push(n)}}return{completed:l,failed:f,bin_endpoints:p}}const y={};function w(n){let{preventMultipleCalls:r=!1}=n||{};return function(n,i,s){const o=s.value;s.value=function(...n){let s=n[0],a=!0,u=null,c="",l={};if(s instanceof SubmitEvent){s.preventDefault();let e=window.location.href;u=s.target;let t=new URL(u.action);c=t.href;let n=c?c.match(/(?<=\{).*?(?=\})/g):"";if(n)for(let e of n){if(!e)continue;let t=u.querySelector(`[name="${e}"]`);if(t)if("file"===t.type)for(let n=0;n<=t.files.length-1;n++)t.files[n]&&(l[e]||(l[e]=[]),l[e].push(new Promise(((e,r)=>{let i=new FileReader;i.onload=function(){e(i.result)},i.readAsDataURL(t.files[n]),i.onerror=r}))));else c=c.replace(`{${e}}`,t.value)}u.action&&t.href!==e||(a=!1)}const h=async e=>{if(c)for(let e in l)l[e].length&&(c=c.replace(`{${e}}`,(await Promise.all(l[e])).join(",")));return u&&a&&(window.sessionStorage.setItem(`${this.service}:${t.hash(c)}`,JSON.stringify(e)),window.location.href=c),e};let f;const d=async()=>{try{if(f=o.bind(this)(...n),f instanceof Promise){let e=await f;return await h(e),f}}catch(t){throw(t=>{throw t instanceof e?t.name=i+"()":t=t instanceof Error?t:new e(t,{name:i+"()"}),t})(t)}};return r?(y?.[i]||(y[i]=d().finally((()=>{delete y[i]}))),y[i]):d()}}}async function _(){await this.__connection;let e=`${this.service}:${t.hash(window.location.href.split("?")[0])}`,n=window.sessionStorage.getItem(e);if(null!==n){try{n=JSON.parse(n)}catch(e){}return n}return null}const b=4503599627370496;function A(t){const n={user_id:"",record_id:"",updated:0,uploaded:0,table:{name:"",access_group:0},reference:{reference_limit:null,allow_multiple_reference:!0,referenced_count:0},ip:"",bin:{}},r={ip:e=>{"R"===e.slice(-1)?(n.readonly=!0,e=e.slice(0,-1)):n.readonly=!1,n.ip=e},rec:e=>{if(!e)return;n.record_id=e;let t=s(e.substring(0,e.length-9));n.uploaded=t},usr:e=>{n.user_id=e},tbl:e=>{if(!e)return;let t=e.split("/");n.table.name=t[0],n.table.access_group="**"==t[2]?"private":parseInt(t[2]),n.table.subscription=!!t?.[3]},usr_tbl:e=>{let t=e.split("/");n.user_id=t[0],n.table.name=t[1],n.table.access_group="**"==t[3]?"private":parseInt(t[3]),n.table.subscription=!!t?.[4]},idx:t=>{if(!t)return;let r=t.split("!"),i=r.splice(0,1)[0],s=function(t){let n=t.substring(3);switch(t.substring(0,3)){case"!S%":return n;case"!N%":let r=n.split("."),i=Number(r[0])-4503599627370496;return 1===r.length?i:parseFloat(i.toString()+"."+r[1]);case"!B%":return"1"===n;case"!L%":case"!D%":try{return JSON.parse(n)}catch(t){throw new e("Value parse error.",{code:"PARSE_ERROR"})}default:return t}}("!"+r.join("!"));n.index={name:i,value:s}},ref:e=>{e&&(n.reference.record_id=e.split("/")[0])},tags:e=>{n.tags=e},upd:e=>{n.updated=e},acpt_mrf:e=>{n.reference.allow_multiple_reference=e},ref_limt:e=>{n.reference.reference_limit=e},rfd:e=>{n.reference.referenced_count=e},bin:e=>{let t={};if(Array.isArray(e))for(let n of e){let e=n.split("/").slice(3).join("/"),r=e.split("/"),i=decodeURIComponent(r.slice(-1)[0]),o=decodeURIComponent(r[10]),a=r[9],u=r[8],c="**"==r[6]?"private":parseInt(r[6]);c=0==c?"public":1==c?"authorized":c;let l={access_group:c,filename:i,url:n,path:e,size:s(a),uploaded:s(u),getFile:(e,t)=>{let r={dataType:e||"download",progress:t};return E.bind(this)(n,r)}};t[o]?t[o].push(l):t[o]=[l]}n.bin=t},data:e=>{let t=e;"!D%{}"===e?t={}:"!L%[]"===e&&(t=[]),n.data=t}};if(t.record_id)return t;for(let e in r)t.hasOwnProperty(e)&&r[e](t[e]);return t.private_key&&(this.__private_access_key[n.record_id]=t.private_key),n}async function v(t){let{endpoints:n}=t;if("string"==typeof n&&(n=[n]),!Array.isArray(n))throw new e('"endpoints" should be type: array | string.',{code:"INVALID_PARAMETER"});return h.bind(this)("del-files",{endpoints:n,storage:"records"},{auth:!0,method:"post"}).map((e=>A.bind(this)(e)))}async function E(t,n){if("string"!=typeof t)throw new e('"url" should be type: string.',{code:"INVALID_PARAMETER"});u.Url(t);let r=!1,i=t.split("/"),s=i[2].split("."),o=null;3===s.length&&"skapi"===s[1]&&(o=s[0],r=!0);let a=i.slice(3);if(!r){if("auth"!==a[0]&&"publ"!==a[0])throw new e("Invalid file url.",{code:"INVALID_PARAMETER"});try{u.UserId(a[2]),u.UserId(a[3])}catch{throw new e("Invalid file url.",{code:"INVALID_PARAMETER"})}}let c=o?null:a[1];n=u.Params(n,{expires:"number",dataType:["base64","blob","endpoint","download",()=>"download"],progress:e=>e});let l="auth"==a[0],f=t.split("/").slice(-1)[0],d=n?.expires||0;if(d){if(d<0)throw new e('"config.expires" should be > 0. (seconds)',{code:"INVALID_PARAMETER"});let n={request:o?"get-host":"get",id:o||a[5],key:t,expires:d};c&&(n.service=c),t=(await h.bind(this)("get-signed-url",n,{auth:!0})).url}else if(l){let n=this.session?.idToken?.jwtToken,r="**"===a[6]?"**":parseInt(a[6]);if(!n)throw new e("User login is required.",{code:"INVALID_REQUEST"});{let t=Date.now()/1e3;if(this.session.idToken.payload.exp<t)try{await this.authentication().getSession({refreshToken:!0}),n=this.session?.idToken?.jwtToken}catch(t){throw this.logout(),new e("User login is required.",{code:"INVALID_REQUEST"})}}if("**"===r){if(this.__user.user_id!==a[3])throw new e("User has no access.",{code:"INVALID_REQUEST"})}else if(this.__user.access_group<r)throw new e("User has no access.",{code:"INVALID_REQUEST"});t+=`?t=${n}`}if("endpoint"===n?.dataType)return t;if("download"===n?.dataType){let e=document.createElement("a");return e.href=t,document.body.appendChild(e),e.setAttribute("download",f),e.target="_blank",e.click(),document.body.removeChild(e),null}return new Promise((async(e,r)=>{try{let r=await h.bind(this)(t,{service:c||this.service},{method:"get",noParams:!0,contentType:null,responseType:"blob",fetchOptions:{progress:n?.progress}});if("base64"===n?.dataType){const t=new FileReader;t.onloadend=()=>e(t.result),t.readAsDataURL(r)}}catch(e){r(e)}}))}async function S(t,n){await this.__connection;const r={$updated:"number",$uploaded:"number",$referenced_count:"number"};"string"==typeof t?.table&&(t.table={name:t.table,access_group:0});const i={table:{name:"string",access_group:["number","private","public","authorized"],subscription:e=>u.UserId(e,'User ID in "subscription"')},reference:"string",index:{name:t=>{if("string"!=typeof t)throw new e('"index.name" should be type: string.',{code:"INVALID_PARAMETER"});return r.hasOwnProperty(t)||["$uploaded","$updated","$referenced_count","$user_id"].includes(t)?t:u.specialChars(t,"index.name",!0,!1)},value:n=>{if(t.index?.name&&r.hasOwnProperty(t.index.name)){let i=r[t.index.name];if(typeof n===i)return n;throw new e(`"index.value" should be type: ${i}.`,{code:"INVALID_PARAMETER"})}if("number"==typeof n){if(n>b||n<-4503599627370496)throw new e("Number value should be within range -4503599627370496 ~ +4503599627370496",{code:"INVALID_PARAMETER"});return n}return"boolean"==typeof n?n:"$user_id"==t.index?.name?u.UserId(n):u.specialChars(n,"index.value",!1,!0)},condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"],range:n=>{if(!t.index||!("value"in t.index))throw new e('"index.value" is required.',{code:"INVALID_PARAMETER"});if("$record_id"===t.index.name)throw new e(`Cannot do "index.range" on ${t.index.name}`,{code:"INVALID_PARAMETER"});if(typeof t.index.value!=typeof n)throw new e('"index.range" type should match the type of "index.value".',{code:"INVALID_PARAMETER"});return"string"==typeof n?u.specialChars(n,"index.range",!1,!0):n}},tag:"string",private_key:"string"};if(t?.tag&&u.specialChars(t.tag,"tag",!1,!0),t?.table){if("public"===t.table.access_group?t.table.access_group=0:"authorized"===t.table.access_group&&(t.table.access_group=1),t.table?.name&&u.specialChars(t.table.name,"table name",!0,!0),"number"==typeof t.table.access_group)if(this.__user){if(this.user.access_group<t.table.access_group)throw new e("User has no access",{code:"INVALID_REQUEST"})}else if(0<t.table.access_group)throw new e("User has no access",{code:"INVALID_REQUEST"});t.table.hasOwnProperty("access_group")||(t.table.access_group=t.table?.subscription?1:0)}if(t?.index&&!t.index?.name)throw new e('"index.name" is required when using "index" parameter.',{code:"INVALID_REQUEST"});let s="";if(t?.record_id){u.specialChars(t.record_id,"record_id",!1,!1);let e={record_id:t.record_id};t?.service&&(e.service=t.service),t=e,this.__private_access_key[t.record_id]&&(t.private_key=this.__private_access_key[t.record_id])}else{let n;if(!this.session&&"private"===t.table?.access_group)throw new e("Unsigned users have no access to private records.",{code:"INVALID_REQUEST"});if(t.reference)try{n=u.UserId(t.reference)}catch(e){u.specialChars(t.reference,"reference",!1,!1),s=t.reference,this.__private_access_key[s]&&(t.private_key=this.__private_access_key[s])}let r=await this.checkAdmin(),o=u.Params(t||{},i,n||r?[]:["table"]);if("string"!=typeof o.table&&o.table?.subscription){if(!this.session)throw new e("Unsigned users have no access to subscription records.",{code:"INVALID_REQUEST"});o.table.subscription={user_id:o.table.subscription,group:1}}t=o}let o=!(!t.hasOwnProperty("access_group")||"string"==typeof t.table||!t.table.access_group)||!!this.__user,a=await h.bind(this)("get-records",t,{fetchOptions:n,auth:o,method:o?"post":"get"});for(let e in a.list)a.list[e]=A.bind(this)(a.list[e]);return s&&a?.reference_private_key&&(this.__private_access_key[s]=a.reference_private_key),a}async function I(t,n){let r=await this.checkAdmin();if(!n)throw new e('"config" argument is required.',{code:"INVALID_PARAMETER"});if(!this.user)throw new e("Login is required.",{code:"INVALID_REQUEST"});let i={};"string"==typeof n.table&&(n.table={name:n.table},n.record_id||(n.table.access_group=0)),"string"==typeof n.reference&&(n.reference={record_id:n.reference});let s=n.progress||null,o=null,c=u.Params(n||{},{record_id:"string",readonly:"boolean",table:{name:"string",subscription:"boolean",access_group:["number","private","public","authorized"]},reference:{record_id:e=>(u.specialChars(e,'"reference.record_id"',!1,!1),this.__private_access_key[e]&&(o=this.__private_access_key[e]),e),reference_limit:t=>{if(null===t)return null;if("number"==typeof t){if(0>t)throw new e('"reference_limit" should be >= 0',{code:"INVALID_PARAMETER"});if(t>4503599627370546)throw new e('"reference_limit" should be <= 4503599627370546',{code:"INVALID_PARAMETER"});return t}throw new e('"reference_limit" should be type: <number | null>',{code:"INVALID_PARAMETER"})},allow_multiple_reference:"boolean"},index:{name:"string",value:["string","number","boolean"]},tags:t=>{if(null===t)return t;if("string"==typeof t)return t.split(",").map((e=>e.trim()));if(Array.isArray(t)){for(let n of t){if("string"!=typeof n)throw new e('"tags" should be type: <string | string[]>',{code:"INVALID_PARAMETER"});u.specialChars(t,"tag",!1,!0)}return t}throw new e('"tags" should be type: <string | string[]>',{code:"INVALID_PARAMETER"})},remove_bin:t=>{if(!t)return null;let n=[];if(!Array.isArray(t))throw new e('"remove_bin" should be type: <string[] | BinaryFile[]>',{code:"INVALID_PARAMETER"});for(let r of t)if("string"==typeof r)n.push(r);else{if(!(r.url&&r.size&&r.filename))throw new e('"remove_bin" should be type: <string[] | BinaryFile[]>',{code:"INVALID_PARAMETER"});n.push(r.url)}return n}},[],["response","onerror","progress"],null);if(!c?.table&&!c?.record_id)throw new e('Either "record_id" or "table" should have a value.',{code:"INVALID_PARAMETER"});if(c.table){if("public"===c.table.access_group?c.table.access_group=0:"authorized"===c.table.access_group&&(c.table.access_group=1),"number"==typeof c.table.access_group&&!r&&this.user.access_group<c.table.access_group)throw new e("User has no access",{code:"INVALID_REQUEST"});if(!c.table.name)throw new e('"table.name" cannot be empty string.',{code:"INVALID_PARAMETER"});if(u.specialChars(c.table.name,"table name",!0,!0),r&&!c.record_id&&"private"===c.table.access_group)throw new e("Service owner cannot write private records.",{code:"INVALID_REQUEST"});if(c.table?.subscription){if(c?.record_id||c.table.hasOwnProperty("access_group")||(c.table.access_group=1),0===c.table.access_group)throw new e("Public records cannot require subscription.",{code:"INVALID_REQUEST"});c.table.subscription_group=1,delete c.table.subscription}}if(delete(n=c).progress,o&&(n.reference_private_key=o),n.index){if(!n.index.name||"string"!=typeof n.index.name)throw new e('"index.name" is required. type: string.',{code:"INVALID_PARAMETER"});if(["$uploaded","$updated","$referenced_count","$user_id"].includes(n.index.name)||u.specialChars(n.index.name,"index name",!0),!n.index.hasOwnProperty("value"))throw new e('"index.value" is required.',{code:"INVALID_PARAMETER"});if("string"==typeof n.index.value)u.specialChars(n.index.value,"index value",!1,!0);else if("number"==typeof n.index.value&&(n.index.value>b||n.index.value<-4503599627370496))throw new e("Number value should be within range -4503599627370496 ~ +4503599627370496",{code:"INVALID_PARAMETER"})}let l={auth:!0},f=null,d=null;if(t instanceof HTMLFormElement||t instanceof FormData||t instanceof SubmitEvent){let e=a(t=t instanceof SubmitEvent?t.target:t);if(e.to_bin.length&&(d=e.to_bin),e.files.length){d||(d=[]);for(let t of e.files)d.push(t)}f=Object.assign({data:e.meta},n)}else f=Object.assign({data:t},n);"function"==typeof s&&(i.progress=s),Object.keys(i).length&&Object.assign(l,{fetchOptions:i});let p=await h.bind(this)("post-record",f,l);if(d){let e=new FormData;for(let t of d)e.append(t.name,t.file,t.file.name);let t={record_id:p.rec,progress:s};n.hasOwnProperty("service")&&(t.service=n.service);let{bin_endpoints:r}=await m.bind(this)(e,t);p.bin?p.bin.push(...r):p.bin=r}return A.bind(this)(p)}async function R(e,t){let n=await h.bind(this)("get-table",u.Params(e||{},{table:"string",condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}),Object.assign({auth:!0},{fetchOptions:t})),r={cnt_rec:"number_of_records",tbl:"table",srvc:"service"};if(Array.isArray(n?.list))for(let e of n.list)for(let t in r)e.hasOwnProperty(t)&&(e[r[t]]=e[t],delete e[t]);return n}async function T(t,n){if(!t?.table)throw new e('"table" is required.',{code:"INVALID_PARAMETER"});let r=u.Params(t||{},{table:"string",index:e=>u.specialChars(e,"index name",!0,!1),order:{by:["average_number","total_number","number_count","average_bool","total_bool","bool_count","string_count","index_name","number_of_records"],value:["string","number","boolean"],condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}},["table"]);if(r.hasOwnProperty("order")){if(!r.order?.by)throw new e('"order.by" is required.',{code:"INVALID_PARAMETER"});if(r.order.hasOwnProperty("condition")&&!r.order.hasOwnProperty("value"))throw new e('"value" is required for "condition".',{code:"INVALID_PARAMETER"});if(r.hasOwnProperty("index")&&"."!==r.index.substring(r.index.length-1))throw new e('"index" should be a parent index name of the compound index when using "order.by"',{code:"INVALID_PARAMETER"})}let i=await h.bind(this)("get-index",r,Object.assign({auth:!0},{fetchOptions:n})),s={cnt_bool:"boolean_count",cnt_numb:"number_count",totl_numb:"total_number",totl_bool:"total_bool",avrg_numb:"average_number",avrg_bool:"average_bool",cnt_str:"string_count"};return Array.isArray(i?.list)&&(i.list=i.list.map((e=>{let t=e.idx.split("/"),n={table:t[1],index:t[2],number_of_records:e.cnt_rec};for(let t in s)e?.[t]&&(n[s[t]]=e[t]);return n}))),i}async function U(e,t){let n=await h.bind(this)("get-tag",u.Params(e||{},{table:"string",tag:"string",condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}),Object.assign({auth:!0},{fetchOptions:t}));if(Array.isArray(n?.list))for(let e in n.list){let t=n.list[e],r=t.tag.split("/");n.list[e]={table:r[1],tag:r[0],number_of_records:t.cnt_rec}}return n}async function D(t){let n=await this.checkAdmin();if(n&&!t?.service)throw new e("Service ID is required.",{code:"INVALID_PARAMETER"});if(t?.record_id)return await h.bind(this)("del-records",{service:t.service||this.service,record_id:(t=>{if("string"==typeof t)return[t];if(!Array.isArray(t))throw new e('"record_id" should be type: <string | string[]>',{code:"INVALID_PARAMETER"});if(t.length>100)throw new e('"record_id" should not exceed 100 items.',{code:"INVALID_PARAMETER"});return u.specialChars(t,"record_id",!1,!1)})(t.record_id)},{auth:!0});{if(!t?.table){if(n)return null;throw new e('Either "table" or "record_id" is required.',{code:"INVALID_PARAMETER"})}let r={access_group:t=>{if("string"==typeof t&&["private","public","authorized"].includes(t))switch(t){case"private":return t;case"public":return 0;case"authorized":return 1}else if("number"==typeof t&&t>=0&&t<100)return t;throw new e('Invalid "table.access_group". Access group should be type <number (0~99) | "private" | "public" | "authorized">.',{code:"INVALID_PARAMETER"})},name:"string",subscription:r=>{if(n&&"string"==typeof t?.table?.subscription)return u.UserId(r,'User ID in "table.subscription"');if("boolean"==typeof r)return r?this.__user.user_id:null;throw new e('"table.subscription" is an invalid parameter key.',{code:"INVALID_PARAMETER"})}},i=u.Params(t.table||{},r,n?[]:["name"]);if(i.hasOwnProperty("subscription"))if(null===i.subscription)delete i.subscription;else{if(!i.hasOwnProperty("access_group"))throw new e('"table.access_group" is required for subscription records.',{code:"INVALID_PARAMETER"});if(0===i.access_group)throw new e("Public tables does not hold subscription records.",{code:"INVALID_REQUEST"});i.subscription_group=1}t.table=i}return await h.bind(this)("del-records",t,{auth:!0})}function C(t){if(!t.record_id)throw new e("Record ID is required.",{code:"INVALID_PARAMETER"});if(!t.user_id||Array.isArray(t.user_id)&&!t.user_id.length)throw new e("User ID is required.",{code:"INVALID_PARAMETER"});return M.bind(this)({record_id:t.record_id,user_id:t.user_id||null,execute:"add"})}function P(t){if(!t.record_id)throw new e("Record ID is required.",{code:"INVALID_PARAMETER"});if(!t.user_id||Array.isArray(t.user_id)&&!t.user_id.length)throw new e("User ID is required.",{code:"INVALID_PARAMETER"});return M.bind(this)({record_id:t.record_id,user_id:t.user_id||null,execute:"remove"})}function N(e){let t=M.bind(this)({record_id:e.record_id,user_id:e.user_id||null,execute:"list"});t.list=t.list.map((e=>(e.record_id=e.rec_usr.split("/")[0],e.user_id=e.rec_usr.split("/")[1],e)))}function k(e){return h.bind(this)("request-private-access-key",{record_id:e},{auth:!0})}function M(t){let n=t.execute,r=u.Params(t,{record_id:"string",user_id:t=>{if(!t){if("list"==n)return null;throw new e("User ID is required.",{code:"INVALID_PARAMETER"})}let r=t;if("string"==typeof r&&(r=[r]),r.length>100)throw new e("Cannot process more than 100 users at once.",{code:"INVALID_REQUEST"});for(let e of r)u.UserId(e,'User ID in "user_id"');return r},execute:["add","remove","list"]},["execute","record_id","user_id"]);return r.user_id||(r.user_id=null),h.bind(this)("grant-private-access",r,{auth:!0})}async function O(){if(await this.getProfile(),!this.session)throw new e("No access.",{code:"INVALID_REQUEST"});let t=await this.record_endpoint;return new WebSocket(t.websocket_private+"?token="+this.session.accessToken.jwtToken)}let V=0;async function L(){let e=this.__socket?await this.__socket:this.__socket;return e&&e.close(),this.__socket=null,this.__socket_group=null,null}function F(t,n=0){if("function"!=typeof t)throw new e("Callback must be a function.",{code:"INVALID_REQUEST"});return!V&&this.__socket instanceof Promise||(this.__socket=new Promise((async r=>{setTimeout((async()=>{if(await this.__connection,!await this.getProfile())throw new e("No access.",{code:"INVALID_REQUEST"});let n=await O.bind(this)();n.onopen=()=>{V=0,t({status:"success",message:"Connected to WebSocket server."}),this.__socket_group&&n.send(JSON.stringify({action:"joinGroup",rid:this.__socket_group,token:this.session.accessToken.jwtToken})),r(n)},n.onmessage=e=>{let n=JSON.parse(decodeURI(e.data)),r="message";n?.["#private"]?r="private":n?.["#notice"]&&(r="notice");let i={status:r,message:n?.["#message"]||n?.["#private"]||n?.["#notice"]||null};n?.["#user_id"]&&(i.sender=n["#user_id"]),t(i)},n.onclose=e=>{if(e.wasClean)t({status:"close",message:"WebSocket connection closed."}),this.__socket=null,this.__socket_group=null;else if(V++,V<10){let e=Math.min(1e3*2**V,3e4);t({status:"error",message:`Skapi: WebSocket connection error. Reconnecting in ${e/1e3} seconds...`}),F.bind(this)(t,e)}else t({status:"error",message:"Skapi: WebSocket connection error. Max reconnection attempts reached."}),this.__socket=null},n.onerror=()=>{throw t({status:"error",message:"Skapi: WebSocket connection error."}),new e("Skapi: WebSocket connection error.",{code:"ERROR"})}}),n)}))),this.__socket}async function x(t,n){let r=this.__socket?await this.__socket:this.__socket;if(!r)throw new e("No realtime connection. Execute connectRealtime() before this method.",{code:"INVALID_REQUEST"});if(!n)throw new e("No recipient.",{code:"INVALID_REQUEST"});if((t instanceof FormData||t instanceof SubmitEvent||t instanceof HTMLFormElement)&&(t=a(t).meta),1===r.readyState){try{u.UserId(n),r.send(JSON.stringify({action:"sendMessage",uid:n,content:t,token:this.session.accessToken.jwtToken}))}catch(i){if(this.__socket_group!==n)throw new e(`User has not joined to the recipient group. Run joinRealtime({ group: "${n}" })`,{code:"INVALID_REQUEST"});r.send(JSON.stringify({action:"broadcast",rid:n,content:t,token:this.session.accessToken.jwtToken}))}return{status:"success",message:"Message sent."}}throw new e("Realtime connection is not open. Try reconnecting with connectRealtime().",{code:"INVALID_REQUEST"})}async function B(t){let n=this.__socket?await this.__socket:this.__socket;if(!n)throw new e("No realtime connection. Execute connectRealtime() before this method.",{code:"INVALID_REQUEST"});(t instanceof FormData||t instanceof SubmitEvent||t instanceof HTMLFormElement)&&(t=a(t).meta);let{group:r=null}=t;if(!r&&!this.__socket_group)return{status:"success",message:"Left realtime message group."};if(null!==r&&"string"!=typeof r)throw new e('"group" must be a string | null.',{code:"INVALID_PARAMETER"});return n.send(JSON.stringify({action:"joinGroup",rid:r,token:this.session.accessToken.jwtToken})),this.__socket_group=r,{status:"success",message:r?`Joined realtime message group: "${r}".`:"Left realtime message group."}}async function $(t,n){if(await this.__connection,!(t=u.Params(t,{user_id:e=>u.UserId(e,'User ID in "user_id"'),group:"string"},["group"])).group)throw new e('"group" is required.',{code:"INVALID_PARAMETER"});let r=await h.bind(this)("get-ws-group",t,{fetchOptions:n,auth:!0,method:"post"});for(let e=0;e<r.list.length;e++)r.list[e]=r.list[e].uid.split("#")[1];return r}async function q(t,n){if(await this.__connection,t||(t={searchFor:"group"}),(t=u.Params(t,{searchFor:["group","number_of_users",()=>"group"],value:["string","number",()=>t?.searchFor&&"number_of_users"===t?.searchFor?0:" "],condition:[">",">=","=","<","<=","!=","gt","gte","eq","lt","lte","ne"],range:["string","number"]})).condition||(" "!==t.value&&t.value?t.condition="=":t.condition=">"),t.range&&t.condition&&delete t.condition,"number_of_users"===t.searchFor&&"number"!=typeof t.value)throw new e('"value" must be a number.',{code:"INVALID_PARAMETER"});if("group"===t.searchFor&&"string"!=typeof t.value)throw new e('"value" must be a string.',{code:"INVALID_PARAMETER"});if(t.hasOwnProperty("range")&&typeof t.range!=typeof t.value)throw new e(`"range" must be a ${typeof t.value}.`,{code:"INVALID_PARAMETER"});let r=await h.bind(this)("get-ws-group",t,{fetchOptions:n,auth:!0,method:"post"});return r.list=r.list.map((e=>({group:e.rid.split("#")[1],number_of_users:e.cnt}))),r}function K(t){let n=!1,r=e=>{for(let t in e)if("string"==typeof e[t]&&e[t].includes("$CLIENT_SECRET")){n=!0;break}};if(u.Params(t,{url:"string",clientSecretName:"string",method:t=>{if(t&&"string"!=typeof t)throw new e('"method" should be type: <string>.',{code:"INVALID_PARAMETER"});if("get"!==t.toLowerCase()&&"post"!==t.toLowerCase())throw new e('"method" should be either "GET" or "POST".',{code:"INVALID_PARAMETER"});return t.toLowerCase()},headers:t=>{if(t&&"object"!=typeof t)throw new e('"headers" should be type: <object>.',{code:"INVALID_PARAMETER"});return r(t),t},data:t=>{if(t&&"object"!=typeof t)throw new e('"data" should be type: <object>.',{code:"INVALID_PARAMETER"});return r(t),t},params:t=>{if(t&&"object"!=typeof t)throw new e('"params" should be type: <object>.',{code:"INVALID_PARAMETER"});return r(t),t}},["clientSecretName","method","url"]),!n)throw new e(`At least one parameter value should include "$CLIENT_SECRET" in ${"post"===t.method.toLowerCase()?'"data"':'"params"'} or "headers".`,{code:"INVALID_PARAMETER"});return h.bind(this)("client-secret-request",t)}async function j(e){await this.__connection;let t={url:e=>u.Url(e),data:null,sync:["boolean",()=>!0]};if(Array.isArray(e))for(let n of e)n=u.Params(n,t);else e=u.Params(e,t);return h.bind(this)("post-secure",e,{auth:!0})}async function H(e,t){await this.__connection;let{auth:n=!0,method:r="POST",bypassAwaitConnection:i=!1,responseType:s,contentType:o,progress:a}=t||{};return t=Object.assign({auth:n,method:r,bypassAwaitConnection:i,responseType:s,contentType:o},{fetchOptions:{progress:a}}),h.bind(this)("mock",e,t)}function W(t){if(t=u.Params(t,{user_id:e=>u.UserId(e,'"user_id"')},["user_id"]),this.__user&&t.user_id===this.__user.user_id)throw new e('"user_id" cannot be the user\'s own ID.',{code:"INVALID_PARAMETER"});return t}async function J(t,n,r){if(!(t=u.Params(t,{subscriber:e=>u.UserId(e,'User ID in "subscriber"'),subscription:e=>u.UserId(e,'User ID in "subscription"'),blocked:"boolean"})).subscriber&&!t.subscription)throw new e('At least either "subscriber" or "subscription" should have a value.',{code:"INVALID_PARAMETER"});Object.assign(t,{group:1});let i=await h.bind(this)("get-subscription",t,Object.assign({auth:!0},{fetchOptions:n}));return i.list=i.list.map(r||(e=>{let t={},n=e.sub.split("#");return t.subscriber=n[2],t.subscription=n[0],t.group=parseInt(n[1]),t.timestamp=e.stmp,t.blocked="N"===e.grp.substring(0,1),t})),i}async function z(e){await this.__connection;let{user_id:t}=W.bind(this)(e);return await h.bind(this)("subscription",{subscribe:t,group:1},{auth:!0})}async function Y(e){await this.__connection;let{user_id:t}=W.bind(this)(e);return await h.bind(this)("subscription",{unsubscribe:t,group:1},{auth:!0})}async function Q(e){await this.__connection;let{user_id:t}=W.bind(this)(e);return await h.bind(this)("subscription",{block:t,group:1},{auth:!0})}async function G(e){await this.__connection;let{user_id:t}=W.bind(this)(e);return await h.bind(this)("subscription",{unblock:t,group:1},{auth:!0})}async function Z(t){await this.__connection;let n=await this.checkAdmin();t=u.Params(t,{user_id:t=>{if(t!==this.__user.user_id&&!n)throw new e("No access.",{code:"INVALID_REQUEST"});return t},group:t=>{if("public"===t&&(t=0),"authorized"===t&&(t=1),"number"!=typeof t)throw new e('"group" should be type number | "public" | "authorized".',{code:"INVALID_PARAMETER"});return t}});let r=await h.bind(this)("get-newsletter-subscription",t,{auth:!0}),i=[];for(let e of r){let t=e.subt.split("#"),n=!0;"@"===t[0].charAt(0)&&(n=!1,t[0]=t[0].substring(1));let r=parseInt(t[0]);i.push({timestamp:e.stmp,group:r,subscribed_email:t[1],active:n})}return i}async function X(e){await this.__connection;let t=u.Params(e||{},{email:e=>u.Email(e),group:["number","public","authorized"],redirect:e=>u.Url(e)},this.__user?["group"]:["email","group"]);return h.bind(this)(`subscribe-${this.__user?"":"public-"}newsletter`,t,{auth:!!this.__user})}async function ee(e){await this.__connection,e=u.Params(e,{group:["number","public","authorized"]},["group"]);let t=Object.assign({action:"unsubscribe"},e);return h.bind(this)("subscribe-newsletter",t,{auth:!0})}async function te(t,n){let r=await this.checkAdmin(),i={message_id:"string",timestamp:"number",read:"number",complaint:"number",subject:"string"};t||(n=Object.assign({ascending:!1},n||{})),t=t||{searchFor:"timestamp",value:Date.now(),condition:"<",group:"public"},t=u.Params(t,{searchFor:["message_id","timestamp","read","complaint","group","subject"],value:n=>{if(typeof n!==i[t.searchFor])throw new e(`"value" type does not match the type of "${t.searchFor}" index.`,{code:"INVALID_PARAMETER"});if("string"==typeof n&&!n)throw new e('"value" should not be empty string.',{code:"INVALID_PARAMETER"});return n},range:n=>{if(!t.hasOwnProperty("value")||typeof n!=typeof t.value)throw new e('"range" should match type of "value".',{code:"INVALID_PARAMETER"});return n},condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],group:t=>{if("public"===t)return 0;if(!this.session)throw new e("User should be logged in.",{code:"INVALID_REQUEST"});if("authorized"===t)return 1;if("number"==typeof t){if(!r&&t>parseInt(this.session.idToken.payload.access_group))throw new e("User has no access.",{code:"INVALID_REQUEST"});return t}throw new e('"group" should be type: number | "public" | "authorized".',{code:"INVALID_PARAMETER"})}},["searchFor","value","group"]);let s=await h.bind(this)(0===t.group?"get-public-newsletters":"get-newsletters",t,Object.assign({method:"get",auth:0!==t.group},{fetchOptions:n})),o={message_id:"mid",timestamp:"stmp",complaint:"cmpl",read:"read",subject:"subj",bounced:"bnce",url:"url"},a={message_id:"",timestamp:0,complaint:0,read:0,subject:"",bounced:0,url:""};return s.list=s.list.map((e=>{let t={};for(let n in o)t[n]=e[o[n]]||a[o[n]];return t})),s}var ne,re=function(){function e(e){var t=e||{},n=t.ValidationData,r=t.Username,i=t.Password,s=t.AuthParameters,o=t.ClientMetadata;this.validationData=n||{},this.authParameters=s||{},this.clientMetadata=o||{},this.username=r,this.password=i}var t=e.prototype;return t.getUsername=function(){return this.username},t.getPassword=function(){return this.password},t.getValidationData=function(){return this.validationData},t.getAuthParameters=function(){return this.authParameters},t.getClientMetadata=function(){return this.clientMetadata},e}(),ie=n(764),se=n(249),oe=n.n(se),ae=(n(433),n(153)),ue=n.n(ae),ce=n(10),le=n.n(ce);if("undefined"!=typeof window&&window.crypto&&(ne=window.crypto),!ne&&"undefined"!=typeof window&&window.msCrypto&&(ne=window.msCrypto),!ne&&void 0!==n.g&&n.g.crypto&&(ne=n.g.crypto),!ne)try{ne=n(296)}catch(e){}function he(){if(ne){if("function"==typeof ne.getRandomValues)try{return ne.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof ne.randomBytes)try{return ne.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")}var fe=function(){function e(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length}var t=e.prototype;return t.random=function(t){for(var n=[],r=0;r<t;r+=4)n.push(he());return new e(n,t)},t.toString=function(){return function(e){for(var t=e.words,n=e.sigBytes,r=[],i=0;i<n;i++){var s=t[i>>>2]>>>24-i%4*8&255;r.push((s>>>4).toString(16)),r.push((15&s).toString(16))}return r.join("")}(this)},e}();const de=pe;function pe(e,t){null!=e&&this.fromString(e,t)}function ge(){return new pe(null)}var me,ye="undefined"!=typeof navigator;ye&&"Microsoft Internet Explorer"==navigator.appName?(pe.prototype.am=function(e,t,n,r,i,s){for(var o=32767&t,a=t>>15;--s>=0;){var u=32767&this[e],c=this[e++]>>15,l=a*u+c*o;i=((u=o*u+((32767&l)<<15)+n[r]+(1073741823&i))>>>30)+(l>>>15)+a*c+(i>>>30),n[r++]=1073741823&u}return i},me=30):ye&&"Netscape"!=navigator.appName?(pe.prototype.am=function(e,t,n,r,i,s){for(;--s>=0;){var o=t*this[e++]+n[r]+i;i=Math.floor(o/67108864),n[r++]=67108863&o}return i},me=26):(pe.prototype.am=function(e,t,n,r,i,s){for(var o=16383&t,a=t>>14;--s>=0;){var u=16383&this[e],c=this[e++]>>14,l=a*u+c*o;i=((u=o*u+((16383&l)<<14)+n[r]+i)>>28)+(l>>14)+a*c,n[r++]=268435455&u}return i},me=28),pe.prototype.DB=me,pe.prototype.DM=(1<<me)-1,pe.prototype.DV=1<<me,pe.prototype.FV=Math.pow(2,52),pe.prototype.F1=52-me,pe.prototype.F2=2*me-52;var we,_e,be=new Array;for(we="0".charCodeAt(0),_e=0;_e<=9;++_e)be[we++]=_e;for(we="a".charCodeAt(0),_e=10;_e<36;++_e)be[we++]=_e;for(we="A".charCodeAt(0),_e=10;_e<36;++_e)be[we++]=_e;function Ae(e){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(e)}function ve(e,t){var n=be[e.charCodeAt(t)];return null==n?-1:n}function Ee(e){var t=ge();return t.fromInt(e),t}function Se(e){var t,n=1;return 0!=(t=e>>>16)&&(e=t,n+=16),0!=(t=e>>8)&&(e=t,n+=8),0!=(t=e>>4)&&(e=t,n+=4),0!=(t=e>>2)&&(e=t,n+=2),0!=(t=e>>1)&&(e=t,n+=1),n}function Ie(e){this.m=e,this.mp=e.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function Re(e){return ie.lW.from((new fe).random(e).toString(),"hex")}Ie.prototype.convert=function(e){var t=ge();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(pe.ZERO)>0&&this.m.subTo(t,t),t},Ie.prototype.revert=function(e){var t=ge();return e.copyTo(t),this.reduce(t),t},Ie.prototype.reduce=function(e){for(;e.t<=this.mt2;)e[e.t++]=0;for(var t=0;t<this.m.t;++t){var n=32767&e[t],r=n*this.mpl+((n*this.mph+(e[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(e[n=t+this.m.t]+=this.m.am(0,r,e,t,0,this.m.t);e[n]>=e.DV;)e[n]-=e.DV,e[++n]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)},Ie.prototype.mulTo=function(e,t,n){e.multiplyTo(t,n),this.reduce(n)},Ie.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},pe.prototype.copyTo=function(e){for(var t=this.t-1;t>=0;--t)e[t]=this[t];e.t=this.t,e.s=this.s},pe.prototype.fromInt=function(e){this.t=1,this.s=e<0?-1:0,e>0?this[0]=e:e<-1?this[0]=e+this.DV:this.t=0},pe.prototype.fromString=function(e,t){var n;if(16==t)n=4;else if(8==t)n=3;else if(2==t)n=1;else if(32==t)n=5;else{if(4!=t)throw new Error("Only radix 2, 4, 8, 16, 32 are supported");n=2}this.t=0,this.s=0;for(var r=e.length,i=!1,s=0;--r>=0;){var o=ve(e,r);o<0?"-"==e.charAt(r)&&(i=!0):(i=!1,0==s?this[this.t++]=o:s+n>this.DB?(this[this.t-1]|=(o&(1<<this.DB-s)-1)<<s,this[this.t++]=o>>this.DB-s):this[this.t-1]|=o<<s,(s+=n)>=this.DB&&(s-=this.DB))}this.clamp(),i&&pe.ZERO.subTo(this,this)},pe.prototype.clamp=function(){for(var e=this.s&this.DM;this.t>0&&this[this.t-1]==e;)--this.t},pe.prototype.dlShiftTo=function(e,t){var n;for(n=this.t-1;n>=0;--n)t[n+e]=this[n];for(n=e-1;n>=0;--n)t[n]=0;t.t=this.t+e,t.s=this.s},pe.prototype.drShiftTo=function(e,t){for(var n=e;n<this.t;++n)t[n-e]=this[n];t.t=Math.max(this.t-e,0),t.s=this.s},pe.prototype.lShiftTo=function(e,t){var n,r=e%this.DB,i=this.DB-r,s=(1<<i)-1,o=Math.floor(e/this.DB),a=this.s<<r&this.DM;for(n=this.t-1;n>=0;--n)t[n+o+1]=this[n]>>i|a,a=(this[n]&s)<<r;for(n=o-1;n>=0;--n)t[n]=0;t[o]=a,t.t=this.t+o+1,t.s=this.s,t.clamp()},pe.prototype.rShiftTo=function(e,t){t.s=this.s;var n=Math.floor(e/this.DB);if(n>=this.t)t.t=0;else{var r=e%this.DB,i=this.DB-r,s=(1<<r)-1;t[0]=this[n]>>r;for(var o=n+1;o<this.t;++o)t[o-n-1]|=(this[o]&s)<<i,t[o-n]=this[o]>>r;r>0&&(t[this.t-n-1]|=(this.s&s)<<i),t.t=this.t-n,t.clamp()}},pe.prototype.subTo=function(e,t){for(var n=0,r=0,i=Math.min(e.t,this.t);n<i;)r+=this[n]-e[n],t[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r-=e.s;n<this.t;)r+=this[n],t[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r-=e[n],t[n++]=r&this.DM,r>>=this.DB;r-=e.s}t.s=r<0?-1:0,r<-1?t[n++]=this.DV+r:r>0&&(t[n++]=r),t.t=n,t.clamp()},pe.prototype.multiplyTo=function(e,t){var n=this.abs(),r=e.abs(),i=n.t;for(t.t=i+r.t;--i>=0;)t[i]=0;for(i=0;i<r.t;++i)t[i+n.t]=n.am(0,r[i],t,i,0,n.t);t.s=0,t.clamp(),this.s!=e.s&&pe.ZERO.subTo(t,t)},pe.prototype.squareTo=function(e){for(var t=this.abs(),n=e.t=2*t.t;--n>=0;)e[n]=0;for(n=0;n<t.t-1;++n){var r=t.am(n,t[n],e,2*n,0,1);(e[n+t.t]+=t.am(n+1,2*t[n],e,2*n+1,r,t.t-n-1))>=t.DV&&(e[n+t.t]-=t.DV,e[n+t.t+1]=1)}e.t>0&&(e[e.t-1]+=t.am(n,t[n],e,2*n,0,1)),e.s=0,e.clamp()},pe.prototype.divRemTo=function(e,t,n){var r=e.abs();if(!(r.t<=0)){var i=this.abs();if(i.t<r.t)return null!=t&&t.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=ge());var s=ge(),o=this.s,a=e.s,u=this.DB-Se(r[r.t-1]);u>0?(r.lShiftTo(u,s),i.lShiftTo(u,n)):(r.copyTo(s),i.copyTo(n));var c=s.t,l=s[c-1];if(0!=l){var h=l*(1<<this.F1)+(c>1?s[c-2]>>this.F2:0),f=this.FV/h,d=(1<<this.F1)/h,p=1<<this.F2,g=n.t,m=g-c,y=null==t?ge():t;for(s.dlShiftTo(m,y),n.compareTo(y)>=0&&(n[n.t++]=1,n.subTo(y,n)),pe.ONE.dlShiftTo(c,y),y.subTo(s,s);s.t<c;)s[s.t++]=0;for(;--m>=0;){var w=n[--g]==l?this.DM:Math.floor(n[g]*f+(n[g-1]+p)*d);if((n[g]+=s.am(0,w,n,m,0,c))<w)for(s.dlShiftTo(m,y),n.subTo(y,n);n[g]<--w;)n.subTo(y,n)}null!=t&&(n.drShiftTo(c,t),o!=a&&pe.ZERO.subTo(t,t)),n.t=c,n.clamp(),u>0&&n.rShiftTo(u,n),o<0&&pe.ZERO.subTo(n,n)}}},pe.prototype.invDigit=function(){if(this.t<1)return 0;var e=this[0];if(0==(1&e))return 0;var t=3&e;return(t=(t=(t=(t=t*(2-(15&e)*t)&15)*(2-(255&e)*t)&255)*(2-((65535&e)*t&65535))&65535)*(2-e*t%this.DV)%this.DV)>0?this.DV-t:-t},pe.prototype.addTo=function(e,t){for(var n=0,r=0,i=Math.min(e.t,this.t);n<i;)r+=this[n]+e[n],t[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r+=e.s;n<this.t;)r+=this[n],t[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r+=e[n],t[n++]=r&this.DM,r>>=this.DB;r+=e.s}t.s=r<0?-1:0,r>0?t[n++]=r:r<-1&&(t[n++]=this.DV+r),t.t=n,t.clamp()},pe.prototype.toString=function(e){if(this.s<0)return"-"+this.negate().toString(e);var t;if(16==e)t=4;else if(8==e)t=3;else if(2==e)t=1;else if(32==e)t=5;else{if(4!=e)throw new Error("Only radix 2, 4, 8, 16, 32 are supported");t=2}var n,r=(1<<t)-1,i=!1,s="",o=this.t,a=this.DB-o*this.DB%t;if(o-- >0)for(a<this.DB&&(n=this[o]>>a)>0&&(i=!0,s=Ae(n));o>=0;)a<t?(n=(this[o]&(1<<a)-1)<<t-a,n|=this[--o]>>(a+=this.DB-t)):(n=this[o]>>(a-=t)&r,a<=0&&(a+=this.DB,--o)),n>0&&(i=!0),i&&(s+=Ae(n));return i?s:"0"},pe.prototype.negate=function(){var e=ge();return pe.ZERO.subTo(this,e),e},pe.prototype.abs=function(){return this.s<0?this.negate():this},pe.prototype.compareTo=function(e){var t=this.s-e.s;if(0!=t)return t;var n=this.t;if(0!=(t=n-e.t))return this.s<0?-t:t;for(;--n>=0;)if(0!=(t=this[n]-e[n]))return t;return 0},pe.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+Se(this[this.t-1]^this.s&this.DM)},pe.prototype.mod=function(e){var t=ge();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(pe.ZERO)>0&&e.subTo(t,t),t},pe.prototype.equals=function(e){return 0==this.compareTo(e)},pe.prototype.add=function(e){var t=ge();return this.addTo(e,t),t},pe.prototype.subtract=function(e){var t=ge();return this.subTo(e,t),t},pe.prototype.multiply=function(e){var t=ge();return this.multiplyTo(e,t),t},pe.prototype.divide=function(e){var t=ge();return this.divRemTo(e,t,null),t},pe.prototype.modPow=function(e,t,n){var r,i=e.bitLength(),s=Ee(1),o=new Ie(t);if(i<=0)return s;r=i<18?1:i<48?3:i<144?4:i<768?5:6;var a=new Array,u=3,c=r-1,l=(1<<r)-1;if(a[1]=o.convert(this),r>1){var h=ge();for(o.sqrTo(a[1],h);u<=l;)a[u]=ge(),o.mulTo(h,a[u-2],a[u]),u+=2}var f,d,p=e.t-1,g=!0,m=ge();for(i=Se(e[p])-1;p>=0;){for(i>=c?f=e[p]>>i-c&l:(f=(e[p]&(1<<i+1)-1)<<c-i,p>0&&(f|=e[p-1]>>this.DB+i-c)),u=r;0==(1&f);)f>>=1,--u;if((i-=u)<0&&(i+=this.DB,--p),g)a[f].copyTo(s),g=!1;else{for(;u>1;)o.sqrTo(s,m),o.sqrTo(m,s),u-=2;u>0?o.sqrTo(s,m):(d=s,s=m,m=d),o.mulTo(m,a[f],s)}for(;p>=0&&0==(e[p]&1<<i);)o.sqrTo(s,m),d=s,s=m,m=d,--i<0&&(i=this.DB-1,--p)}var y=o.revert(s);return n(null,y),y},pe.ZERO=Ee(0),pe.ONE=Ee(1);var Te=/^[89a-f]/i,Ue=function(){function e(e){this.N=new de("FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF",16),this.g=new de("2",16),this.k=new de(this.hexHash(""+this.padHex(this.N)+this.padHex(this.g)),16),this.smallAValue=this.generateRandomSmallA(),this.getLargeAValue((function(){})),this.infoBits=ie.lW.from("Caldera Derived Key","utf8"),this.poolName=e}var t=e.prototype;return t.getSmallAValue=function(){return this.smallAValue},t.getLargeAValue=function(e){var t=this;this.largeAValue?e(null,this.largeAValue):this.calculateA(this.smallAValue,(function(n,r){n&&e(n,null),t.largeAValue=r,e(null,t.largeAValue)}))},t.generateRandomSmallA=function(){var e=Re(128).toString("hex");return new de(e,16)},t.generateRandomString=function(){return Re(40).toString("base64")},t.getRandomPassword=function(){return this.randomPassword},t.getSaltDevices=function(){return this.SaltToHashDevices},t.getVerifierDevices=function(){return this.verifierDevices},t.generateHashDevice=function(e,t,n){var r=this;this.randomPassword=this.generateRandomString();var i=""+e+t+":"+this.randomPassword,s=this.hash(i),o=Re(16).toString("hex");this.SaltToHashDevices=this.padHex(new de(o,16)),this.g.modPow(new de(this.hexHash(this.SaltToHashDevices+s),16),this.N,(function(e,t){e&&n(e,null),r.verifierDevices=r.padHex(t),n(null,null)}))},t.calculateA=function(e,t){var n=this;this.g.modPow(e,this.N,(function(e,r){e&&t(e,null),r.mod(n.N).equals(de.ZERO)&&t(new Error("Illegal paramater. A mod N cannot be 0."),null),t(null,r)}))},t.calculateU=function(e,t){return this.UHexHash=this.hexHash(this.padHex(e)+this.padHex(t)),new de(this.UHexHash,16)},t.hash=function(e){var t=e instanceof ie.lW?oe().lib.WordArray.create(e):e,n=ue()(t).toString();return new Array(64-n.length).join("0")+n},t.hexHash=function(e){return this.hash(ie.lW.from(e,"hex"))},t.computehkdf=function(e,t){var n=oe().lib.WordArray.create(ie.lW.concat([this.infoBits,ie.lW.from(String.fromCharCode(1),"utf8")])),r=e instanceof ie.lW?oe().lib.WordArray.create(e):e,i=t instanceof ie.lW?oe().lib.WordArray.create(t):t,s=le()(r,i),o=le()(n,s);return ie.lW.from(o.toString(),"hex").slice(0,16)},t.getPasswordAuthenticationKey=function(e,t,n,r,i){var s=this;if(n.mod(this.N).equals(de.ZERO))throw new Error("B cannot be zero.");if(this.UValue=this.calculateU(this.largeAValue,n),this.UValue.equals(de.ZERO))throw new Error("U cannot be zero.");var o=""+this.poolName+e+":"+t,a=this.hash(o),u=new de(this.hexHash(this.padHex(r)+a),16);this.calculateS(u,n,(function(e,t){e&&i(e,null);var n=s.computehkdf(ie.lW.from(s.padHex(t),"hex"),ie.lW.from(s.padHex(s.UValue),"hex"));i(null,n)}))},t.calculateS=function(e,t,n){var r=this;this.g.modPow(e,this.N,(function(i,s){i&&n(i,null),t.subtract(r.k.multiply(s)).modPow(r.smallAValue.add(r.UValue.multiply(e)),r.N,(function(e,t){e&&n(e,null),n(null,t.mod(r.N))}))}))},t.getNewPasswordRequiredChallengeUserAttributePrefix=function(){return"userAttributes."},t.padHex=function(e){if(!(e instanceof de))throw new Error("Not a BigInteger");var t=e.compareTo(de.ZERO)<0,n=e.abs().toString(16);if(n=n.length%2!=0?"0"+n:n,n=Te.test(n)?"00"+n:n,t){var r=n.split("").map((function(e){var t=15&~parseInt(e,16);return"0123456789ABCDEF".charAt(t)})).join("");(n=new de(r,16).add(de.ONE).toString(16)).toUpperCase().startsWith("FF8")&&(n=n.substring(2))}return n},e}(),De=function(){function e(e){this.jwtToken=e||"",this.payload=this.decodePayload()}var t=e.prototype;return t.getJwtToken=function(){return this.jwtToken},t.getExpiration=function(){return this.payload.exp},t.getIssuedAt=function(){return this.payload.iat},t.decodePayload=function(){var e=this.jwtToken.split(".")[1];try{return JSON.parse(ie.lW.from(e,"base64").toString("utf8"))}catch(e){return{}}},e}();function Ce(e,t){return Ce=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ce(e,t)}var Pe=function(e){var t,n;function r(t){var n=(void 0===t?{}:t).AccessToken;return e.call(this,n||"")||this}return n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,Ce(t,n),r}(De);function Ne(e,t){return Ne=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ne(e,t)}var ke=function(e){var t,n;function r(t){var n=(void 0===t?{}:t).IdToken;return e.call(this,n||"")||this}return n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,Ne(t,n),r}(De),Me=n(269),Oe=n.n(Me),Ve=function(){function e(e){var t=(void 0===e?{}:e).RefreshToken;this.token=t||""}return e.prototype.getToken=function(){return this.token},e}(),Le=function(){function e(e){var t=void 0===e?{}:e,n=t.IdToken,r=t.RefreshToken,i=t.AccessToken,s=t.ClockDrift;if(null==i||null==n)throw new Error("Id token and Access Token must be present.");this.idToken=n,this.refreshToken=r,this.accessToken=i,this.clockDrift=void 0===s?this.calculateClockDrift():s}var t=e.prototype;return t.getIdToken=function(){return this.idToken},t.getRefreshToken=function(){return this.refreshToken},t.getAccessToken=function(){return this.accessToken},t.getClockDrift=function(){return this.clockDrift},t.calculateClockDrift=function(){return Math.floor(new Date/1e3)-Math.min(this.accessToken.getIssuedAt(),this.idToken.getIssuedAt())},t.isValid=function(){var e=Math.floor(new Date/1e3)-this.clockDrift;return e<this.accessToken.getExpiration()&&e<this.idToken.getExpiration()},e}(),Fe=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],xe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Be=function(){function e(){}return e.prototype.getNowString=function(){var e=new Date,t=xe[e.getUTCDay()],n=Fe[e.getUTCMonth()],r=e.getUTCDate(),i=e.getUTCHours();i<10&&(i="0"+i);var s=e.getUTCMinutes();s<10&&(s="0"+s);var o=e.getUTCSeconds();return o<10&&(o="0"+o),t+" "+n+" "+r+" "+i+":"+s+":"+o+" UTC "+e.getUTCFullYear()},e}(),$e=function(){function e(e){var t=void 0===e?{}:e,n=t.Name,r=t.Value;this.Name=n||"",this.Value=r||""}var t=e.prototype;return t.getValue=function(){return this.Value},t.setValue=function(e){return this.Value=e,this},t.getName=function(){return this.Name},t.setName=function(e){return this.Name=e,this},t.toString=function(){return JSON.stringify(this)},t.toJSON=function(){return{Name:this.Name,Value:this.Value}},e}(),qe={},Ke=function(){function e(){}return e.setItem=function(e,t){return qe[e]=t,qe[e]},e.getItem=function(e){return Object.prototype.hasOwnProperty.call(qe,e)?qe[e]:void 0},e.removeItem=function(e){return delete qe[e]},e.clear=function(){return qe={}},e}(),je=function(){function e(){try{this.storageWindow=window.localStorage,this.storageWindow.setItem("aws.cognito.test-ls",1),this.storageWindow.removeItem("aws.cognito.test-ls")}catch(e){this.storageWindow=Ke}}return e.prototype.getStorage=function(){return this.storageWindow},e}(),He="undefined"!=typeof navigator?navigator.userAgent:"nodejs",We=function(){function e(e){if(null==e||null==e.Username||null==e.Pool)throw new Error("Username and Pool information are required.");this.username=e.Username||"",this.pool=e.Pool,this.Session=null,this.client=e.Pool.client,this.signInUserSession=null,this.authenticationFlowType="USER_SRP_AUTH",this.storage=e.Storage||(new je).getStorage(),this.keyPrefix="CognitoIdentityServiceProvider."+this.pool.getClientId(),this.userDataKey=this.keyPrefix+"."+this.username+".userData"}var t=e.prototype;return t.setSignInUserSession=function(e){this.clearCachedUserData(),this.signInUserSession=e,this.cacheTokens()},t.getSignInUserSession=function(){return this.signInUserSession},t.getUsername=function(){return this.username},t.getAuthenticationFlowType=function(){return this.authenticationFlowType},t.setAuthenticationFlowType=function(e){this.authenticationFlowType=e},t.initiateAuth=function(e,t){var n=this,r=e.getAuthParameters();r.USERNAME=this.username;var i=0!==Object.keys(e.getValidationData()).length?e.getValidationData():e.getClientMetadata(),s={AuthFlow:"CUSTOM_AUTH",ClientId:this.pool.getClientId(),AuthParameters:r,ClientMetadata:i};this.getUserContextData()&&(s.UserContextData=this.getUserContextData()),this.client.request("InitiateAuth",s,(function(e,r){if(e)return t.onFailure(e);var i=r.ChallengeName,s=r.ChallengeParameters;return"CUSTOM_CHALLENGE"===i?(n.Session=r.Session,t.customChallenge(s)):(n.signInUserSession=n.getCognitoUserSession(r.AuthenticationResult),n.cacheTokens(),t.onSuccess(n.signInUserSession))}))},t.authenticateUser=function(e,t){return"USER_PASSWORD_AUTH"===this.authenticationFlowType?this.authenticateUserPlainUsernamePassword(e,t):"USER_SRP_AUTH"===this.authenticationFlowType||"CUSTOM_AUTH"===this.authenticationFlowType?this.authenticateUserDefaultAuth(e,t):t.onFailure(new Error("Authentication flow type is invalid."))},t.authenticateUserDefaultAuth=function(e,t){var n,r,i=this,s=new Ue(this.pool.getUserPoolName()),o=new Be,a={};null!=this.deviceKey&&(a.DEVICE_KEY=this.deviceKey),a.USERNAME=this.username,s.getLargeAValue((function(u,c){u&&t.onFailure(u),a.SRP_A=c.toString(16),"CUSTOM_AUTH"===i.authenticationFlowType&&(a.CHALLENGE_NAME="SRP_A");var l=0!==Object.keys(e.getValidationData()).length?e.getValidationData():e.getClientMetadata(),h={AuthFlow:i.authenticationFlowType,ClientId:i.pool.getClientId(),AuthParameters:a,ClientMetadata:l};i.getUserContextData(i.username)&&(h.UserContextData=i.getUserContextData(i.username)),i.client.request("InitiateAuth",h,(function(a,u){if(a)return t.onFailure(a);var c=u.ChallengeParameters;i.username=c.USER_ID_FOR_SRP,i.userDataKey=i.keyPrefix+"."+i.username+".userData",n=new de(c.SRP_B,16),r=new de(c.SALT,16),i.getCachedDeviceKeyAndPassword(),s.getPasswordAuthenticationKey(i.username,e.getPassword(),n,r,(function(e,n){e&&t.onFailure(e);var r=o.getNowString(),a=oe().lib.WordArray.create(ie.lW.concat([ie.lW.from(i.pool.getUserPoolName(),"utf8"),ie.lW.from(i.username,"utf8"),ie.lW.from(c.SECRET_BLOCK,"base64"),ie.lW.from(r,"utf8")])),h=oe().lib.WordArray.create(n),f=Oe().stringify(le()(a,h)),d={};d.USERNAME=i.username,d.PASSWORD_CLAIM_SECRET_BLOCK=c.SECRET_BLOCK,d.TIMESTAMP=r,d.PASSWORD_CLAIM_SIGNATURE=f,null!=i.deviceKey&&(d.DEVICE_KEY=i.deviceKey);var p={ChallengeName:"PASSWORD_VERIFIER",ClientId:i.pool.getClientId(),ChallengeResponses:d,Session:u.Session,ClientMetadata:l};i.getUserContextData()&&(p.UserContextData=i.getUserContextData()),function e(t,n){return i.client.request("RespondToAuthChallenge",t,(function(r,s){return r&&"ResourceNotFoundException"===r.code&&-1!==r.message.toLowerCase().indexOf("device")?(d.DEVICE_KEY=null,i.deviceKey=null,i.randomPassword=null,i.deviceGroupKey=null,i.clearCachedDeviceKeyAndPassword(),e(t,n)):n(r,s)}))}(p,(function(e,n){return e?t.onFailure(e):i.authenticateUserInternal(n,s,t)}))}))}))}))},t.authenticateUserPlainUsernamePassword=function(e,t){var n=this,r={};if(r.USERNAME=this.username,r.PASSWORD=e.getPassword(),r.PASSWORD){var i=new Ue(this.pool.getUserPoolName());this.getCachedDeviceKeyAndPassword(),null!=this.deviceKey&&(r.DEVICE_KEY=this.deviceKey);var s=0!==Object.keys(e.getValidationData()).length?e.getValidationData():e.getClientMetadata(),o={AuthFlow:"USER_PASSWORD_AUTH",ClientId:this.pool.getClientId(),AuthParameters:r,ClientMetadata:s};this.getUserContextData(this.username)&&(o.UserContextData=this.getUserContextData(this.username)),this.client.request("InitiateAuth",o,(function(e,r){return e?t.onFailure(e):n.authenticateUserInternal(r,i,t)}))}else t.onFailure(new Error("PASSWORD parameter is required"))},t.authenticateUserInternal=function(e,t,n){var r=this,i=e.ChallengeName,s=e.ChallengeParameters;if("SMS_MFA"===i)return this.Session=e.Session,n.mfaRequired(i,s);if("SELECT_MFA_TYPE"===i)return this.Session=e.Session,n.selectMFAType(i,s);if("MFA_SETUP"===i)return this.Session=e.Session,n.mfaSetup(i,s);if("SOFTWARE_TOKEN_MFA"===i)return this.Session=e.Session,n.totpRequired(i,s);if("CUSTOM_CHALLENGE"===i)return this.Session=e.Session,n.customChallenge(s);if("NEW_PASSWORD_REQUIRED"===i){this.Session=e.Session;var o=null,a=null,u=[],c=t.getNewPasswordRequiredChallengeUserAttributePrefix();if(s&&(o=JSON.parse(e.ChallengeParameters.userAttributes),a=JSON.parse(e.ChallengeParameters.requiredAttributes)),a)for(var l=0;l<a.length;l++)u[l]=a[l].substr(c.length);return n.newPasswordRequired(o,u)}if("DEVICE_SRP_AUTH"===i)return this.Session=e.Session,void this.getDeviceResponse(n);this.signInUserSession=this.getCognitoUserSession(e.AuthenticationResult),this.challengeName=i,this.cacheTokens();var h=e.AuthenticationResult.NewDeviceMetadata;if(null==h)return n.onSuccess(this.signInUserSession);t.generateHashDevice(e.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,e.AuthenticationResult.NewDeviceMetadata.DeviceKey,(function(i){if(i)return n.onFailure(i);var s={Salt:ie.lW.from(t.getSaltDevices(),"hex").toString("base64"),PasswordVerifier:ie.lW.from(t.getVerifierDevices(),"hex").toString("base64")};r.verifierDevices=s.PasswordVerifier,r.deviceGroupKey=h.DeviceGroupKey,r.randomPassword=t.getRandomPassword(),r.client.request("ConfirmDevice",{DeviceKey:h.DeviceKey,AccessToken:r.signInUserSession.getAccessToken().getJwtToken(),DeviceSecretVerifierConfig:s,DeviceName:He},(function(t,i){return t?n.onFailure(t):(r.deviceKey=e.AuthenticationResult.NewDeviceMetadata.DeviceKey,r.cacheDeviceKeyAndPassword(),!0===i.UserConfirmationNecessary?n.onSuccess(r.signInUserSession,i.UserConfirmationNecessary):n.onSuccess(r.signInUserSession))}))}))},t.completeNewPasswordChallenge=function(e,t,n,r){var i=this;if(!e)return n.onFailure(new Error("New password is required."));var s=new Ue(this.pool.getUserPoolName()),o=s.getNewPasswordRequiredChallengeUserAttributePrefix(),a={};t&&Object.keys(t).forEach((function(e){a[o+e]=t[e]})),a.NEW_PASSWORD=e,a.USERNAME=this.username;var u={ChallengeName:"NEW_PASSWORD_REQUIRED",ClientId:this.pool.getClientId(),ChallengeResponses:a,Session:this.Session,ClientMetadata:r};this.getUserContextData()&&(u.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",u,(function(e,t){return e?n.onFailure(e):i.authenticateUserInternal(t,s,n)}))},t.getDeviceResponse=function(e,t){var n=this,r=new Ue(this.deviceGroupKey),i=new Be,s={};s.USERNAME=this.username,s.DEVICE_KEY=this.deviceKey,r.getLargeAValue((function(o,a){o&&e.onFailure(o),s.SRP_A=a.toString(16);var u={ChallengeName:"DEVICE_SRP_AUTH",ClientId:n.pool.getClientId(),ChallengeResponses:s,ClientMetadata:t,Session:n.Session};n.getUserContextData()&&(u.UserContextData=n.getUserContextData()),n.client.request("RespondToAuthChallenge",u,(function(t,s){if(t)return e.onFailure(t);var o=s.ChallengeParameters,a=new de(o.SRP_B,16),u=new de(o.SALT,16);r.getPasswordAuthenticationKey(n.deviceKey,n.randomPassword,a,u,(function(t,r){if(t)return e.onFailure(t);var a=i.getNowString(),u=oe().lib.WordArray.create(ie.lW.concat([ie.lW.from(n.deviceGroupKey,"utf8"),ie.lW.from(n.deviceKey,"utf8"),ie.lW.from(o.SECRET_BLOCK,"base64"),ie.lW.from(a,"utf8")])),c=oe().lib.WordArray.create(r),l=Oe().stringify(le()(u,c)),h={};h.USERNAME=n.username,h.PASSWORD_CLAIM_SECRET_BLOCK=o.SECRET_BLOCK,h.TIMESTAMP=a,h.PASSWORD_CLAIM_SIGNATURE=l,h.DEVICE_KEY=n.deviceKey;var f={ChallengeName:"DEVICE_PASSWORD_VERIFIER",ClientId:n.pool.getClientId(),ChallengeResponses:h,Session:s.Session};n.getUserContextData()&&(f.UserContextData=n.getUserContextData()),n.client.request("RespondToAuthChallenge",f,(function(t,r){return t?e.onFailure(t):(n.signInUserSession=n.getCognitoUserSession(r.AuthenticationResult),n.cacheTokens(),e.onSuccess(n.signInUserSession))}))}))}))}))},t.confirmRegistration=function(e,t,n,r){var i={ClientId:this.pool.getClientId(),ConfirmationCode:e,Username:this.username,ForceAliasCreation:t,ClientMetadata:r};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("ConfirmSignUp",i,(function(e){return e?n(e,null):n(null,"SUCCESS")}))},t.sendCustomChallengeAnswer=function(e,t,n){var r=this,i={};i.USERNAME=this.username,i.ANSWER=e;var s=new Ue(this.pool.getUserPoolName());this.getCachedDeviceKeyAndPassword(),null!=this.deviceKey&&(i.DEVICE_KEY=this.deviceKey);var o={ChallengeName:"CUSTOM_CHALLENGE",ChallengeResponses:i,ClientId:this.pool.getClientId(),Session:this.Session,ClientMetadata:n};this.getUserContextData()&&(o.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",o,(function(e,n){return e?t.onFailure(e):r.authenticateUserInternal(n,s,t)}))},t.sendMFACode=function(e,t,n,r){var i=this,s={};s.USERNAME=this.username,s.SMS_MFA_CODE=e;var o=n||"SMS_MFA";"SOFTWARE_TOKEN_MFA"===o&&(s.SOFTWARE_TOKEN_MFA_CODE=e),null!=this.deviceKey&&(s.DEVICE_KEY=this.deviceKey);var a={ChallengeName:o,ChallengeResponses:s,ClientId:this.pool.getClientId(),Session:this.Session,ClientMetadata:r};this.getUserContextData()&&(a.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",a,(function(e,n){if(e)return t.onFailure(e);if("DEVICE_SRP_AUTH"!==n.ChallengeName){if(i.signInUserSession=i.getCognitoUserSession(n.AuthenticationResult),i.cacheTokens(),null==n.AuthenticationResult.NewDeviceMetadata)return t.onSuccess(i.signInUserSession);var r=new Ue(i.pool.getUserPoolName());r.generateHashDevice(n.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,n.AuthenticationResult.NewDeviceMetadata.DeviceKey,(function(e){if(e)return t.onFailure(e);var s={Salt:ie.lW.from(r.getSaltDevices(),"hex").toString("base64"),PasswordVerifier:ie.lW.from(r.getVerifierDevices(),"hex").toString("base64")};i.verifierDevices=s.PasswordVerifier,i.deviceGroupKey=n.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,i.randomPassword=r.getRandomPassword(),i.client.request("ConfirmDevice",{DeviceKey:n.AuthenticationResult.NewDeviceMetadata.DeviceKey,AccessToken:i.signInUserSession.getAccessToken().getJwtToken(),DeviceSecretVerifierConfig:s,DeviceName:He},(function(e,r){return e?t.onFailure(e):(i.deviceKey=n.AuthenticationResult.NewDeviceMetadata.DeviceKey,i.cacheDeviceKeyAndPassword(),!0===r.UserConfirmationNecessary?t.onSuccess(i.signInUserSession,r.UserConfirmationNecessary):t.onSuccess(i.signInUserSession))}))}))}else i.getDeviceResponse(t)}))},t.changePassword=function(e,t,n,r){if(null==this.signInUserSession||!this.signInUserSession.isValid())return n(new Error("User is not authenticated"),null);this.client.request("ChangePassword",{PreviousPassword:e,ProposedPassword:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),ClientMetadata:r},(function(e){return e?n(e,null):n(null,"SUCCESS")}))},t.enableMFA=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e(new Error("User is not authenticated"),null);var t=[];t.push({DeliveryMedium:"SMS",AttributeName:"phone_number"}),this.client.request("SetUserSettings",{MFAOptions:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(t){return t?e(t,null):e(null,"SUCCESS")}))},t.setUserMfaPreference=function(e,t,n){if(null==this.signInUserSession||!this.signInUserSession.isValid())return n(new Error("User is not authenticated"),null);this.client.request("SetUserMFAPreference",{SMSMfaSettings:e,SoftwareTokenMfaSettings:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(e){return e?n(e,null):n(null,"SUCCESS")}))},t.disableMFA=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e(new Error("User is not authenticated"),null);this.client.request("SetUserSettings",{MFAOptions:[],AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(t){return t?e(t,null):e(null,"SUCCESS")}))},t.deleteUser=function(e,t){var n=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return e(new Error("User is not authenticated"),null);this.client.request("DeleteUser",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),ClientMetadata:t},(function(t){return t?e(t,null):(n.clearCachedUser(),e(null,"SUCCESS"))}))},t.updateAttributes=function(e,t,n){var r=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return t(new Error("User is not authenticated"),null);this.client.request("UpdateUserAttributes",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),UserAttributes:e,ClientMetadata:n},(function(e){return e?t(e,null):r.getUserData((function(){return t(null,"SUCCESS")}),{bypassCache:!0})}))},t.getUserAttributes=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e(new Error("User is not authenticated"),null);this.client.request("GetUser",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(t,n){if(t)return e(t,null);for(var r=[],i=0;i<n.UserAttributes.length;i++){var s={Name:n.UserAttributes[i].Name,Value:n.UserAttributes[i].Value},o=new $e(s);r.push(o)}return e(null,r)}))},t.getMFAOptions=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e(new Error("User is not authenticated"),null);this.client.request("GetUser",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(t,n){return t?e(t,null):e(null,n.MFAOptions)}))},t.createGetUserRequest=function(){return this.client.promisifyRequest("GetUser",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken()})},t.refreshSessionIfPossible=function(e){var t=this;return void 0===e&&(e={}),new Promise((function(n){var r=t.signInUserSession.getRefreshToken();r&&r.getToken()?t.refreshSession(r,n,e.clientMetadata):n()}))},t.getUserData=function(e,t){var n=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return this.clearCachedUserData(),e(new Error("User is not authenticated"),null);var r=this.getUserDataFromCache();if(r)if(this.isFetchUserDataAndTokenRequired(t))this.fetchUserData().then((function(e){return n.refreshSessionIfPossible(t).then((function(){return e}))})).then((function(t){return e(null,t)})).catch(e);else try{return void e(null,JSON.parse(r))}catch(t){return this.clearCachedUserData(),void e(t,null)}else this.fetchUserData().then((function(t){e(null,t)})).catch(e)},t.getUserDataFromCache=function(){return this.storage.getItem(this.userDataKey)},t.isFetchUserDataAndTokenRequired=function(e){var t=(e||{}).bypassCache;return void 0!==t&&t},t.fetchUserData=function(){var e=this;return this.createGetUserRequest().then((function(t){return e.cacheUserData(t),t}))},t.deleteAttributes=function(e,t){var n=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return t(new Error("User is not authenticated"),null);this.client.request("DeleteUserAttributes",{UserAttributeNames:e,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(e){return e?t(e,null):n.getUserData((function(){return t(null,"SUCCESS")}),{bypassCache:!0})}))},t.resendConfirmationCode=function(e,t){var n={ClientId:this.pool.getClientId(),Username:this.username,ClientMetadata:t};this.client.request("ResendConfirmationCode",n,(function(t,n){return t?e(t,null):e(null,n)}))},t.getSession=function(e,t){if(void 0===t&&(t={}),null==this.username)return e(new Error("Username is null. Cannot retrieve a new session"),null);if(null!=this.signInUserSession&&this.signInUserSession.isValid())return e(null,this.signInUserSession);var n="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,r=n+".idToken",i=n+".accessToken",s=n+".refreshToken",o=n+".clockDrift";if(this.storage.getItem(r)){var a=new ke({IdToken:this.storage.getItem(r)}),u=new Pe({AccessToken:this.storage.getItem(i)}),c=new Ve({RefreshToken:this.storage.getItem(s)}),l=parseInt(this.storage.getItem(o),0)||0,h=new Le({IdToken:a,AccessToken:u,RefreshToken:c,ClockDrift:l});if(h.isValid())return this.signInUserSession=h,e(null,this.signInUserSession);if(!c.getToken())return e(new Error("Cannot retrieve a new session. Please authenticate."),null);this.refreshSession(c,e,t.clientMetadata)}else e(new Error("Local storage is missing an ID Token, Please authenticate"),null)},t.refreshSession=function(e,t,n){var r=this,i=this.pool.wrapRefreshSessionCallback?this.pool.wrapRefreshSessionCallback(t):t,s={};s.REFRESH_TOKEN=e.getToken();var o="CognitoIdentityServiceProvider."+this.pool.getClientId(),a=o+".LastAuthUser";if(this.storage.getItem(a)){this.username=this.storage.getItem(a);var u=o+"."+this.username+".deviceKey";this.deviceKey=this.storage.getItem(u),s.DEVICE_KEY=this.deviceKey}var c={ClientId:this.pool.getClientId(),AuthFlow:"REFRESH_TOKEN_AUTH",AuthParameters:s,ClientMetadata:n};this.getUserContextData()&&(c.UserContextData=this.getUserContextData()),this.client.request("InitiateAuth",c,(function(t,n){if(t)return"NotAuthorizedException"===t.code&&r.clearCachedUser(),i(t,null);if(n){var s=n.AuthenticationResult;return Object.prototype.hasOwnProperty.call(s,"RefreshToken")||(s.RefreshToken=e.getToken()),r.signInUserSession=r.getCognitoUserSession(s),r.cacheTokens(),i(null,r.signInUserSession)}}))},t.cacheTokens=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId(),t=e+"."+this.username+".idToken",n=e+"."+this.username+".accessToken",r=e+"."+this.username+".refreshToken",i=e+"."+this.username+".clockDrift",s=e+".LastAuthUser";this.storage.setItem(t,this.signInUserSession.getIdToken().getJwtToken()),this.storage.setItem(n,this.signInUserSession.getAccessToken().getJwtToken()),this.storage.setItem(r,this.signInUserSession.getRefreshToken().getToken()),this.storage.setItem(i,""+this.signInUserSession.getClockDrift()),this.storage.setItem(s,this.username)},t.cacheUserData=function(e){this.storage.setItem(this.userDataKey,JSON.stringify(e))},t.clearCachedUserData=function(){this.storage.removeItem(this.userDataKey)},t.clearCachedUser=function(){this.clearCachedTokens(),this.clearCachedUserData()},t.cacheDeviceKeyAndPassword=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,t=e+".deviceKey",n=e+".randomPasswordKey",r=e+".deviceGroupKey";this.storage.setItem(t,this.deviceKey),this.storage.setItem(n,this.randomPassword),this.storage.setItem(r,this.deviceGroupKey)},t.getCachedDeviceKeyAndPassword=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,t=e+".deviceKey",n=e+".randomPasswordKey",r=e+".deviceGroupKey";this.storage.getItem(t)&&(this.deviceKey=this.storage.getItem(t),this.randomPassword=this.storage.getItem(n),this.deviceGroupKey=this.storage.getItem(r))},t.clearCachedDeviceKeyAndPassword=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,t=e+".deviceKey",n=e+".randomPasswordKey",r=e+".deviceGroupKey";this.storage.removeItem(t),this.storage.removeItem(n),this.storage.removeItem(r)},t.clearCachedTokens=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId(),t=e+"."+this.username+".idToken",n=e+"."+this.username+".accessToken",r=e+"."+this.username+".refreshToken",i=e+".LastAuthUser",s=e+"."+this.username+".clockDrift";this.storage.removeItem(t),this.storage.removeItem(n),this.storage.removeItem(r),this.storage.removeItem(i),this.storage.removeItem(s)},t.getCognitoUserSession=function(e){var t=new ke(e),n=new Pe(e),r=new Ve(e);return new Le({IdToken:t,AccessToken:n,RefreshToken:r})},t.forgotPassword=function(e,t){var n={ClientId:this.pool.getClientId(),Username:this.username,ClientMetadata:t};this.getUserContextData()&&(n.UserContextData=this.getUserContextData()),this.client.request("ForgotPassword",n,(function(t,n){return t?e.onFailure(t):"function"==typeof e.inputVerificationCode?e.inputVerificationCode(n):e.onSuccess(n)}))},t.confirmPassword=function(e,t,n,r){var i={ClientId:this.pool.getClientId(),Username:this.username,ConfirmationCode:e,Password:t,ClientMetadata:r};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("ConfirmForgotPassword",i,(function(e){return e?n.onFailure(e):n.onSuccess("SUCCESS")}))},t.getAttributeVerificationCode=function(e,t,n){if(null==this.signInUserSession||!this.signInUserSession.isValid())return t.onFailure(new Error("User is not authenticated"));this.client.request("GetUserAttributeVerificationCode",{AttributeName:e,AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),ClientMetadata:n},(function(e,n){return e?t.onFailure(e):"function"==typeof t.inputVerificationCode?t.inputVerificationCode(n):t.onSuccess("SUCCESS")}))},t.verifyAttribute=function(e,t,n){if(null==this.signInUserSession||!this.signInUserSession.isValid())return n.onFailure(new Error("User is not authenticated"));this.client.request("VerifyUserAttribute",{AttributeName:e,Code:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(e){return e?n.onFailure(e):n.onSuccess("SUCCESS")}))},t.getDevice=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e.onFailure(new Error("User is not authenticated"));this.client.request("GetDevice",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),DeviceKey:this.deviceKey},(function(t,n){return t?e.onFailure(t):e.onSuccess(n)}))},t.forgetSpecificDevice=function(e,t){if(null==this.signInUserSession||!this.signInUserSession.isValid())return t.onFailure(new Error("User is not authenticated"));this.client.request("ForgetDevice",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),DeviceKey:e},(function(e){return e?t.onFailure(e):t.onSuccess("SUCCESS")}))},t.forgetDevice=function(e){var t=this;this.forgetSpecificDevice(this.deviceKey,{onFailure:e.onFailure,onSuccess:function(n){return t.deviceKey=null,t.deviceGroupKey=null,t.randomPassword=null,t.clearCachedDeviceKeyAndPassword(),e.onSuccess(n)}})},t.setDeviceStatusRemembered=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e.onFailure(new Error("User is not authenticated"));this.client.request("UpdateDeviceStatus",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),DeviceKey:this.deviceKey,DeviceRememberedStatus:"remembered"},(function(t){return t?e.onFailure(t):e.onSuccess("SUCCESS")}))},t.setDeviceStatusNotRemembered=function(e){if(null==this.signInUserSession||!this.signInUserSession.isValid())return e.onFailure(new Error("User is not authenticated"));this.client.request("UpdateDeviceStatus",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),DeviceKey:this.deviceKey,DeviceRememberedStatus:"not_remembered"},(function(t){return t?e.onFailure(t):e.onSuccess("SUCCESS")}))},t.listDevices=function(e,t,n){if(null==this.signInUserSession||!this.signInUserSession.isValid())return n.onFailure(new Error("User is not authenticated"));var r={AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),Limit:e};t&&(r.PaginationToken=t),this.client.request("ListDevices",r,(function(e,t){return e?n.onFailure(e):n.onSuccess(t)}))},t.globalSignOut=function(e){var t=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return e.onFailure(new Error("User is not authenticated"));this.client.request("GlobalSignOut",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(n){return n?e.onFailure(n):(t.clearCachedUser(),e.onSuccess("SUCCESS"))}))},t.signOut=function(e){var t=this;e&&"function"==typeof e?this.getSession((function(n,r){if(n)return e(n);t.revokeTokens((function(n){t.cleanClientData(),e(n)}))})):this.cleanClientData()},t.revokeTokens=function(e){if(void 0===e&&(e=function(){}),"function"!=typeof e)throw new Error("Invalid revokeTokenCallback. It should be a function.");if(!this.signInUserSession)return e(new Error("User is not authenticated"));if(!this.signInUserSession.getAccessToken())return e(new Error("No Access token available"));var t=this.signInUserSession.getRefreshToken().getToken(),n=this.signInUserSession.getAccessToken();if(this.isSessionRevocable(n)&&t)return this.revokeToken({token:t,callback:e});e()},t.isSessionRevocable=function(e){if(e&&"function"==typeof e.decodePayload)try{return!!e.decodePayload().origin_jti}catch(e){}return!1},t.cleanClientData=function(){this.signInUserSession=null,this.clearCachedUser()},t.revokeToken=function(e){var t=e.token,n=e.callback;this.client.requestWithRetry("RevokeToken",{Token:t,ClientId:this.pool.getClientId()},(function(e){if(e)return n(e);n()}))},t.sendMFASelectionAnswer=function(e,t){var n=this,r={};r.USERNAME=this.username,r.ANSWER=e;var i={ChallengeName:"SELECT_MFA_TYPE",ChallengeResponses:r,ClientId:this.pool.getClientId(),Session:this.Session};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",i,(function(r,i){return r?t.onFailure(r):(n.Session=i.Session,"SMS_MFA"===e?t.mfaRequired(i.ChallengeName,i.ChallengeParameters):"SOFTWARE_TOKEN_MFA"===e?t.totpRequired(i.ChallengeName,i.ChallengeParameters):void 0)}))},t.getUserContextData=function(){return this.pool.getUserContextData(this.username)},t.associateSoftwareToken=function(e){var t=this;null!=this.signInUserSession&&this.signInUserSession.isValid()?this.client.request("AssociateSoftwareToken",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(t,n){return t?e.onFailure(t):e.associateSecretCode(n.SecretCode)})):this.client.request("AssociateSoftwareToken",{Session:this.Session},(function(n,r){return n?e.onFailure(n):(t.Session=r.Session,e.associateSecretCode(r.SecretCode))}))},t.verifySoftwareToken=function(e,t,n){var r=this;null!=this.signInUserSession&&this.signInUserSession.isValid()?this.client.request("VerifySoftwareToken",{AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),UserCode:e,FriendlyDeviceName:t},(function(e,t){return e?n.onFailure(e):n.onSuccess(t)})):this.client.request("VerifySoftwareToken",{Session:this.Session,UserCode:e,FriendlyDeviceName:t},(function(e,t){if(e)return n.onFailure(e);r.Session=t.Session;var i={};i.USERNAME=r.username;var s={ChallengeName:"MFA_SETUP",ClientId:r.pool.getClientId(),ChallengeResponses:i,Session:r.Session};r.getUserContextData()&&(s.UserContextData=r.getUserContextData()),r.client.request("RespondToAuthChallenge",s,(function(e,t){return e?n.onFailure(e):(r.signInUserSession=r.getCognitoUserSession(t.AuthenticationResult),r.cacheTokens(),n.onSuccess(r.signInUserSession))}))}))},e}(),Je=(n(204),"aws-amplify/5.0.4"),ze={userAgent:Je+" js",product:"",navigator:null,isReactNative:!1};function Ye(){}"undefined"!=typeof navigator&&navigator.product&&(ze.product=navigator.product||"",ze.navigator=navigator||null,"ReactNative"===navigator.product?(ze.userAgent=Je+" react-native",ze.isReactNative=!0):(ze.userAgent=Je+" js",ze.isReactNative=!1)),Ye.prototype.userAgent=ze.userAgent;const Qe=Ye;function Ge(e){var t="function"==typeof Map?new Map:void 0;return Ge=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return Ze(e,arguments,et(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),Xe(r,e)},Ge(e)}function Ze(e,t,n){return Ze=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&Xe(i,n.prototype),i},Ze.apply(null,arguments)}function Xe(e,t){return Xe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Xe(e,t)}function et(e){return et=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},et(e)}var tt=function(e){function t(t,n,r,i){var s;return(s=e.call(this,t)||this).code=n,s.name=r,s.statusCode=i,s}return r=e,(n=t).prototype=Object.create(r.prototype),n.prototype.constructor=n,Xe(n,r),t;var n,r}(Ge(Error)),nt=function(){function e(e,t,n){this.endpoint=t||"https://cognito-idp."+e+".amazonaws.com/";var r=(n||{}).credentials;this.fetchOptions=r?{credentials:r}:{}}var t=e.prototype;return t.promisifyRequest=function(e,t){var n=this;return new Promise((function(r,i){n.request(e,t,(function(e,t){e?i(new tt(e.message,e.code,e.name,e.statusCode)):r(t)}))}))},t.requestWithRetry=function(e,t,n){var r,i,s=this;(r=[t],i=5e3,void 0===i&&(i=ot),st((function(t){return new Promise((function(n,r){s.request(e,t,(function(e,t){e?r(e):n(t)}))}))}),r,function(e){return function(t){var n=100*Math.pow(2,t)+100*Math.random();return!(n>e)&&n}}(i))).then((function(e){return n(null,e)})).catch((function(e){return n(e)}))},t.request=function(e,t,n){var r,i={"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityProviderService."+e,"X-Amz-User-Agent":Qe.prototype.userAgent,"Cache-Control":"no-store"},s=Object.assign({},this.fetchOptions,{headers:i,method:"POST",mode:"cors",body:JSON.stringify(t)});fetch(this.endpoint,s).then((function(e){return r=e,e}),(function(e){if(e instanceof TypeError)throw new Error("Network error");throw e})).then((function(e){return e.json().catch((function(){return{}}))})).then((function(e){if(r.ok)return n(null,e);var t=(e.__type||e.code).split("#").pop(),i=new Error(e.message||e.Message||null);return i.name=t,i.code=t,n(i)})).catch((function(e){if(r&&r.headers&&r.headers.get("x-amzn-errortype"))try{var t=r.headers.get("x-amzn-errortype").split(":")[0],i=new Error(r.status?r.status.toString():null);return i.code=t,i.name=t,i.statusCode=r.status,n(i)}catch(t){return n(e)}else e instanceof Error&&"Network error"===e.message&&(e.code="NetworkError");return n(e)}))},e}(),rt={debug:function(){}},it=function(e){return e&&e.nonRetryable};function st(e,t,n,r){if(void 0===r&&(r=1),"function"!=typeof e)throw Error("functionToRetry must be a function");return rt.debug(e.name+" attempt #"+r+" with args: "+JSON.stringify(t)),e.apply(void 0,t).catch((function(i){if(rt.debug("error on "+e.name,i),it(i))throw rt.debug(e.name+" non retryable error",i),i;var s=n(r,t,i);if(rt.debug(e.name+" retrying in "+s+" ms"),!1!==s)return new Promise((function(e){return setTimeout(e,s)})).then((function(){return st(e,t,n,r+1)}));throw i}))}var ot=3e5,at=function(){function e(e,t){var n=e||{},r=n.UserPoolId,i=n.ClientId,s=n.endpoint,o=n.fetchOptions,a=n.AdvancedSecurityDataCollectionFlag;if(!r||!i)throw new Error("Both UserPoolId and ClientId are required.");if(r.length>55||!/^[\w-]+_[0-9a-zA-Z]+$/.test(r))throw new Error("Invalid UserPoolId format.");var u=r.split("_")[0];this.userPoolId=r,this.clientId=i,this.client=new nt(u,s,o),this.advancedSecurityDataCollectionFlag=!1!==a,this.storage=e.Storage||(new je).getStorage(),t&&(this.wrapRefreshSessionCallback=t)}var t=e.prototype;return t.getUserPoolId=function(){return this.userPoolId},t.getUserPoolName=function(){return this.getUserPoolId().split("_")[1]},t.getClientId=function(){return this.clientId},t.signUp=function(e,t,n,r,i,s){var o=this,a={ClientId:this.clientId,Username:e,Password:t,UserAttributes:n,ValidationData:r,ClientMetadata:s};this.getUserContextData(e)&&(a.UserContextData=this.getUserContextData(e)),this.client.request("SignUp",a,(function(t,n){if(t)return i(t,null);var r={Username:e,Pool:o,Storage:o.storage},s={user:new We(r),userConfirmed:n.UserConfirmed,userSub:n.UserSub,codeDeliveryDetails:n.CodeDeliveryDetails};return i(null,s)}))},t.getCurrentUser=function(){var e="CognitoIdentityServiceProvider."+this.clientId+".LastAuthUser",t=this.storage.getItem(e);if(t){var n={Username:t,Pool:this,Storage:this.storage};return new We(n)}return null},t.getUserContextData=function(e){if("undefined"!=typeof AmazonCognitoAdvancedSecurityData){var t=AmazonCognitoAdvancedSecurityData;if(this.advancedSecurityDataCollectionFlag){var n=t.getData(e,this.userPoolId,this.clientId);if(n)return{EncodedData:n}}return{}}},e}();n(808);let ut=null,ct=null;function lt(e){let t={tkid:"ticket_id",cond:"condition",actn:"action",cnt:"count",ttl:"time_to_live",stmp:"timestamp",plch:"placeholder",hash:"hash",desc:"description"},n={};for(let r in e)if("tkid"===r){let t=e[r].split("#");if(1===t.length){n.ticket_id=t[0];continue}n.ticket_id=t[1],n.consume_id=t[2],n.user_id=t[3],e.stmp||(n.timestamp=s(t[2].slice(0,-4)))}else t[r]?n[t[r]]=e[r]:n[r]=e[r];return n}async function ht(t){if(!t.ticket_id)throw new e("Ticket ID is required.",{code:"INVALID_PARAMETER"});let n=t.ticket_id;return delete t.ticket_id,await this.__connection,lt(await h.bind(this)(`https://${this.service.slice(0,4)}.skapi.dev/auth/consume/${this.service}/${this.owner}/${n}`,t,{auth:!0}))}async function ft(e,t){await this.__connection;let n=await h.bind(this)("ticket",Object.assign({exec:"list"},e||{}),{auth:!0,fetchOptions:t});return n.list=n.list.map(lt),n}async function dt(e,t){await this.__connection;let n=await h.bind(this)("ticket",Object.assign({exec:"consumed"},e||{}),{auth:!0,fetchOptions:t});return n.list=n.list.map(lt),n}async function pt(e){return this.request("register-ticket",Object.assign({exec:"reg"},e),{auth:!0})}async function gt(e){return this.request("register-ticket",Object.assign({exec:"unreg"},e),{auth:!0})}function mt(){if(!ct)throw new e("User pool is missing",{code:"INVALID_REQUEST"});const n=t=>{let n={};if(Array.isArray(t)){let n={};for(let r of t)if(n[r.Name]=r.Value,"custom:service"===r.Name&&n[r.Name]!==this.service)throw new e("The user is not registered to the service.",{code:"INVALID_REQUEST"});t=n}for(let r in t)if(r.includes("custom:")){if("custom:service"===r&&t[r]!==this.service)throw new e("The user is not registered to the service.",{code:"INVALID_REQUEST"});n[r.replace("custom:","")]=t[r]}else{if("address"===r){let e=t[r];if(e&&"object"==typeof e&&Object.keys(e).length&&e?.formatted)try{t[r]=JSON.parse(e.formatted)}catch(n){t[r]=e.formatted}}n[r]=t[r]}for(let e of["address_public","birthdate_public","email_public","gender_public","phone_number_public","access_group"])e.includes("_public")?n.hasOwnProperty(e.split("_")[0])?n[e]=!!n.hasOwnProperty(e)&&!!Number(n[e]):delete n[e]:n[e]=n.hasOwnProperty(e)?Number(n[e]):0;for(let e of["email","phone_number"])n.hasOwnProperty(e)?!0===n[e+"_verified"]||"true"===n[e+"_verified"]?n[e+"_verified"]=!0:n[e+"_verified"]=!1:delete n[e+"_verified"];for(let e of["aud",{from:"auth_time",to:"log"},"cognito:username","event_id","exp","iat","iss","jti","origin_jti","secret_key",{from:"sub",to:"user_id"},"token_use"])"string"==typeof e?delete n[e]:(n[e.to]=n[e.from],delete n[e.from]);this.__user=n},r=async t=>{let{refreshToken:r=!1}=t||{};return new Promise(((t,i)=>{ut=ct?.getCurrentUser()||null,null!==ut?ut.getSession(((s,o)=>{if(s)return void i(s);if(!o)return void i(new e("Current session does not exist.",{code:"INVALID_REQUEST"}));let a=r=>{let s=r.getIdToken().payload;if(s["custom:service"]!==this.service)return ut.signOut(),this.session=null,void i(new e("Invalid session.",{code:"INVALID_REQUEST"}));this.session=r,n(s),t(r)};if(!r&&o.isValid())return a(o);ut.refreshSession(o.getRefreshToken(),((t,n)=>{if(!t)return n.isValid()?a(n):void i(new e("Invalid session.",{code:"INVALID_REQUEST"}));i(t)}))})):i(null)}))},i=async n=>{if(!n)throw new e("E-Mail is required.",{code:"INVALID_PARAMETER"});let r=n.includes(this.service+"-")?n:this.service+"-"+t.hash(n);return{cognitoUser:new We({Username:r,Pool:ct}),cognitoUsername:r}};return{getSession:r,authenticateUser:(t,n)=>new Promise(((s,o)=>{this.__request_signup_confirmation=null,this.__disabledAccount=null,i(t).then((t=>{let i=t.cognitoUsername,a=new re({Username:i,Password:n});t.cognitoUser.authenticateUser(a,{newPasswordRequired:(a,u)=>{this.__request_signup_confirmation=i,"PASS"===a["custom:signup_ticket"]||"MEMBER"===a["custom:signup_ticket"]?t.cognitoUser.completeNewPasswordChallenge(n,{},{onSuccess:e=>{ut=t.cognitoUser,r().then((e=>s(this.user)))},onFailure:t=>{o(new e(t.message||"Failed to authenticate user.",{code:t.code}))}}):o(new e("User's signup confirmation is required.",{code:"SIGNUP_CONFIRMATION_NEEDED"}))},onSuccess:e=>r().then((e=>{s(this.user)})),onFailure:t=>{let n=[t.message||"Failed to authenticate user.",t?.code||"INVALID_REQUEST"];"NotAuthorizedException"===t.code?"User is disabled."===t.message?(this.__disabledAccount=i,n=["This account is disabled.","USER_IS_DISABLED"]):n=["Incorrect username or password.","INCORRECT_USERNAME_OR_PASSWORD"]:"UserNotFoundException"===t.code?n=["Incorrect username or password.","INCORRECT_USERNAME_OR_PASSWORD"]:"TooManyRequestsException"!==t.code&&"LimitExceededException"!==t.code||(n=["Too many attempts. Please try again later.","REQUEST_EXCEED"]);let r=n[1],s=n[0],a=n[0].split("#");a.length>1&&(a=a[a.length-1].split(":"),r=a[0],s=a[1]),o(new e(s,{code:r,cause:t}))}})}))})),createCognitoUser:i,getUser:()=>new Promise(((t,r)=>{this.session||t(null),null===ut?r(new e("Invalid session",{code:"INVALID_REQUEST"})):ut.getUserAttributes(((e,i)=>{e?r(e):(n(i),t(this.user))}))}))}}async function yt(e){await this.__authConnection;try{return await mt.bind(this)().getSession(e),this.user}catch(e){return null}}async function wt(){return await this.__connection,this.__user?.service===this.service?this.__user?.owner===this.host:(await _t.bind(this)(),!1)}async function _t(){await this.__connection,ut&&ut.signOut();let e={session:null,__startKeyHistory:{},__cached_requests:{},__user:null};for(let t in e)this[t]=e[t];return"SUCCESS: The user has been logged out."}async function bt(t){if(!this.__request_signup_confirmation)throw new e("Least one login attempt is required.",{code:"INVALID_REQUEST"});return t=t?u.Url(t):void 0,await h.bind(this)("confirm-signup",{username:this.__request_signup_confirmation,redirect:t})}async function At(t=!1){if("string"==typeof t)t=u.Url(t);else if("boolean"!=typeof t)throw new e("Argument should be type: <boolean | string>.",{code:"INVALID_REQUEST"});if(!this.__disabledAccount)throw new e("Least one signin attempt of disabled account is required.",{code:"INVALID_REQUEST"});return await h.bind(this)("recover-account",{username:this.__disabledAccount,redirect:t}),this.__disabledAccount=null,"SUCCESS: Recovery e-mail has been sent."}async function vt(t){u.Params(t,{idToken:"string",clientId:"string",keyUrl:e=>u.Url(e),provider:"string",nonce:"string"},["idToken","keyUrl","clientId"]);let{hashedPassword:n,username:r}=await h.bind(this)("jwt-login",t);try{return Et.bind(this)({username:r,password:n})}catch(t){if("INCORRECT_USERNAME_OR_PASSWORD"===t?.code)throw new e("User has migrated the account. Login with the service username and password.",{code:"INVALID_REQUEST"})}}async function Et(t){await this.logout();let n=u.Params(t,{username:"string",email:"string",password:"string"},["password"]);if(n.email)try{u.Email(n.email)}catch(e){n.username=n.email,delete n.email}if(!n.username&&!n.email)throw new e('Least one of "username" or "email" is required.',{code:"INVALID_PARAMETER"});return mt.bind(this)().authenticateUser(n.username||n.email,n.password)}async function St(t,n){let r=await wt.bind(this)(),i=u.Params(t||{},{username:"string",email:e=>u.Email(e),password:e=>u.Password(e),name:"string",address:"string",gender:"string",birthdate:e=>u.Birthdate(e),phone_number:e=>u.PhoneNumber(e),email_public:["boolean",()=>!1],address_public:["boolean",()=>!1],gender_public:["boolean",()=>!1],birthdate_public:["boolean",()=>!1],phone_number_public:["boolean",()=>!1],access_group:"number",misc:"string",picture:e=>u.Url(e),profile:e=>u.Url(e),family_name:"string",given_name:"string",middle_name:"string",nickname:"string",website:e=>u.Url(e)},r?["email"]:["email","password"]),s=r&&i.service&&this.service!==i.service;if(s)i.owner=this.__user.user_id;else if(!r){if(i.access_group)throw new e('Only admins can set "access_group" parameter.',{code:"INVALID_PARAMETER"});await this.logout()}n=u.Params(n||{},{email_subscription:t=>{if("boolean"!=typeof t)throw new e('"option.email_subscription" should be type: <boolean>.',{code:"INVALID_PARAMETER"});if(!n?.signup_confirmation)throw new e('"option.signup_confirmation" is required for email subscription.',{code:"INVALID_PARAMETER"});return t},signup_confirmation:t=>{if("string"==typeof t)return u.Url(t);if("boolean"==typeof t)return t;throw new e('"option.signup_confirmation" should be type: <string | boolean>.',{code:"INVALID_PARAMETER"})},login:t=>{if("boolean"==typeof t){if(n.signup_confirmation&&t)throw new e('"login" is not allowed when "option.signup_confirmation" is true.',{code:"INVALID_PARAMETER"});return t}throw new e('"option.login" should be type: boolean.',{code:"INVALID_PARAMETER"})}});let o=n?.login||!1,a=n?.signup_confirmation||!1;if(s&&a&&i?.password)throw new e('Admins cannot create an account with "option.signup_confirmation" option.',{code:"INVALID_PARAMETER"});if(i.email_public&&!a)throw new e('"option.signup_confirmation" should be true if "email_public" is set to true.',{code:"INVALID_PARAMETER"});i.signup_confirmation=a,i.email_subscription=n?.email_subscription||!1,s||(delete i.service,delete i.owner);let c=await h.bind(this)("signup",i,{auth:r});if(!r){if(a){let e=await mt.bind(this)().createCognitoUser(i.username||i.email);return ut=e.cognitoUser,this.__request_signup_confirmation=e.cognitoUsername,"SUCCESS: The account has been created. User's signup confirmation is required."}return o?Et.bind(this)({email:i.username||i.email,password:i.password}):"SUCCESS: The account has been created."}return c}async function It(){await this.__connection;let e=await h.bind(this)("remove-account",{disable:this.__user.user_id},{auth:!0});return await _t.bind(this)(),e}async function Rt(t){await this.__connection;let n=u.Params(t,{email:e=>u.Email(e),code:["number","string"],new_password:e=>u.Password(e)},["email","code","new_password"]),r=n.code,i=n.new_password;return"number"==typeof r&&(r=r.toString()),new Promise((async(t,s)=>{(await mt.bind(this)().createCognitoUser(n.email)).cognitoUser.confirmPassword(r,i,{onSuccess:e=>{t("SUCCESS: New password has been set.")},onFailure:t=>{s(new e(t?.message||"Failed to reset password.",{code:t?.code}))}})}))}async function Tt(t,n){let r;if(await this.__connection,!ut)throw new e("The user has to be logged in.",{code:"INVALID_REQUEST"});if("email"===t||"phone_number"===t){if(!this.__user.hasOwnProperty(t))throw new e(`No ${"email"===t?"e-mail":"phone number"} to verify`,{code:"INVALID_REQUEST"});return this.__user?.[`${t}_verified`]?`SUCCESS: "${t}" is verified.`:(r=(n?u.Params(n,{code:["string"]}):{}).code||"",new Promise(((n,i)=>{let s={onSuccess:e=>{r?mt.bind(this)().getSession({refreshToken:!0}).then((()=>{this.__user&&(this.__user[t+"_verified"]=!0),n(`SUCCESS: "${t}" is verified.`)})).catch((e=>{i(e)})):n("SUCCESS: Verification code has been sent.")},onFailure:t=>{i(new e(t.message||"Failed to request verification code.",{code:t?.code}))}};r?ut?.verifyAttribute(t,r,s):(s.inputVerificationCode=null,ut?.getAttributeVerificationCode(t,s))})))}}function Ut(e){return Tt.bind(this)("phone_number",e)}function Dt(e){return Tt.bind(this)("email",e)}async function Ct(t){await this.__connection;let n=u.Params(t,{email:e=>u.Email(e)},["email"]);return new Promise((async(t,r)=>{(await mt.bind(this)().createCognitoUser(n.email)).cognitoUser.forgotPassword({onSuccess:e=>{t("SUCCESS: Verification code has been sent.")},onFailure:t=>{r(new e(t?.message||"Failed to send verification code.",{code:t?.code||"ERROR"}))}})}))}async function Pt(t){if(await this.__connection,!this.session)throw new e("User login is required.",{code:"INVALID_REQUEST"});let n=u.Params(t,{current_password:"string",new_password:"string"});if(!n?.current_password)throw new e('"current_password" is required to change password.',{code:"INVALID_PARAMETER"});if(!n?.new_password)throw new e('"new_password" is required to change password.',{code:"INVALID_PARAMETER"});return u.Password(n.current_password),u.Password(n.new_password),new Promise(((t,r)=>{ut.changePassword(n.current_password,n.new_password,((n,i)=>{n&&r("InvalidParameterException"===n?.code?new e("Invalid password parameter.",{code:"INVALID_PARAMETER"}):"NotAuthorizedException"===n?.code?new e("Incorrect password.",{code:"INVALID_REQUEST"}):"TooManyRequestsException"===n?.code||"LimitExceededException"===n?.code?new e("Too many attempts. Please try again later.",{code:"REQUEST_EXCEED"}):new e(n?.message||"Failed to change user password.",{code:n?.code||n?.name})),t("SUCCESS: Password has been changed.")}))}))}async function Nt(n){if(await this.__connection,!this.session)throw new e("User login is required.",{code:"INVALID_REQUEST"});let r=u.Params(n||{},{email:e=>u.Email(e),address:e=>e?"string"==typeof e?e:"object"==typeof e?JSON.stringify(e):"":"",name:"string",gender:"string",birthdate:e=>u.Birthdate(e),phone_number:e=>u.PhoneNumber(e),email_public:"boolean",phone_number_public:"boolean",address_public:"boolean",gender_public:"boolean",birthdate_public:"boolean",misc:"string",picture:e=>u.Url(e),profile:e=>u.Url(e),family_name:"string",given_name:"string",middle_name:"string",nickname:"string",website:e=>u.Url(e)});if(r&&"object"==typeof r&&!Object.keys(r).length)return this.user;r.email&&(r.preferred_username=this.service+"-"+t.hash(r.email));let i=[["email_public","email_verified","User's E-Mail should be verified to set"],["phone_number_public","phone_number_verified","User's phone number should be verified to set"]];if(this.__user)for(let t of i)if(r[t[0]]&&!this.__user[t[1]])throw new e(`${t[2]} "${t[0]}" to true.`,{code:"INVALID_REQUEST"});let s=[];for(let e in r)if(r[e]!==this.user[e]){if(["email_public","phone_number_public","address_public","gender_public","birthdate_public","misc"].includes(e)){let t=r[e];"boolean"==typeof t&&(t=t?"1":"0"),r["custom:"+e]=t,s.push(e)}}else s.push(e);for(let e of s)delete r[e];if(r&&"object"==typeof r&&Object.keys(r).length){let e=[];for(let t in r)e.push(new $e({Name:t,Value:r[t]}));return await new Promise(((t,n)=>{ut?.updateAttributes(e,((e,r)=>{e&&n([e?.code||e?.name,e?.message||"Failed to update user settings."]),t(r)}))})),await mt.bind(this)().getSession({refreshToken:!0}),this.user}return this.user}async function kt(t,n){if(t||(t={searchFor:"timestamp",condition:">",value:0},n||(n={}),n.ascending=!1),await wt.bind(this)()&&!t.hasOwnProperty("service"))throw new e("Service ID is required.",{code:"INVALID_PARAMETER"});const r={user_id:e=>u.UserId(e),email:e=>u.Email(e),phone_number:e=>u.PhoneNumber(e),locale:t=>{if("string"!=typeof t||"string"==typeof t&&t.length>5)throw new e('Value of "locale" should be a country code.',{code:"INVALID_PARAMETER"});return t},name:"string",address:"string",gender:"string",birthdate:e=>u.Birthdate(e),subscribers:"number",timestamp:"number",access_group:"number",approved:e=>e?"by_admin:approved":"by_admin:suspended"};if(t=u.Params(t,{searchFor:["user_id","name","email","phone_number","address","gender","birthdate","locale","subscribers","timestamp","access_group","approved"],condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],value:n=>{let i=r[t.searchFor];if("function"==typeof i){if(!t?.condition||"="===t?.condition||t?.range)return i(n)}else if(typeof n!==i)throw new e(`Value does not match the type of "${t.searchFor}" index.`,{code:"INVALID_PARAMETER"});return n},range:n=>{let i=r[t.searchFor];if("function"==typeof i)return i(n);if(typeof n!==i)throw new e(`Range does not match the type of "${t.searchFor}" index.`,{code:"INVALID_PARAMETER"});return n}},["searchFor","value"]),t?.condition&&"="!==t?.condition&&t.hasOwnProperty("range"))throw new e("Conditions does not apply on range search.",{code:"INVALID_PARAMETER"});if("user_id"===t.searchFor&&"="!==t.condition)throw new e('Conditions are not allowed on "user_id"',{code:"INVALID_PARAMETER"});if("string"==typeof t?.value&&!t?.value)throw new e("Value should not be an empty string.",{code:"INVALID_PARAMETER"});if("string"==typeof t?.searchFor&&!t?.searchFor)throw new e('"searchFor" should not be an empty string.',{code:"INVALID_PARAMETER"});return h.bind(this)("get-users",t,{auth:!0,fetchOptions:n})}async function Mt(e){await this.__connection;let t=await h.bind(this)("last-verified-email",e,{auth:!0});return t.includes("SUCCESS")?(await mt.bind(this)().getSession({refreshToken:!0}),this.user):t}async function Ot(e){return await this.__connection,e=u.Params(e,{username:u.Email,redirect:u.Url},["username"]),await h.bind(this)("request-username-change",e,{auth:!0})}var Vt=function(e,t,n,r){var i,s=arguments.length,o=s<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(o=(s<3?i(o):s>3?i(t,n,o):i(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o};class Lt{get user(){return this.__user&&Object.keys(this.__user).length?JSON.parse(JSON.stringify(this.__user)):null}set user(e){}constructor(t,n,r,i){if(this.version="1.0.60",this.session=null,this.connection=null,this.host="skapi",this.hostDomain="skapi.com",this.target_cdn="d3e9syvbtso631",this.__disabledAccount=null,this.__cached_requests={},this.__startKeyHistory={},this.__request_signup_confirmation=null,this.__private_access_key={},this.__class_properties_has_been_cached=!1,this.__user=null,this.validate={userId(e){try{return u.UserId(e),!0}catch(e){return!1}},url(e){try{return u.Url(e),!0}catch(e){return!1}},phoneNumber(e){try{return u.PhoneNumber(e),!0}catch(e){return!1}},birthdate(e){try{return u.Birthdate(e),!0}catch(e){return!1}},email(e){try{return u.Email(e),!0}catch(e){return!1}}},this.checkAdmin=wt.bind(this),this.request=h.bind(this),this.registerTicket=pt.bind(this),this.unregisterTicket=gt.bind(this),this.hostFiles=g.bind(this),this.normalizeRecord=A.bind(this),"string"!=typeof t||"string"!=typeof n)throw new e('"service" and "owner" should be type <string>.',{code:"INVALID_PARAMETER"});if(!t||!n)throw new e('"service" and "owner" is required',{code:"INVALID_PARAMETER"});n!==this.host&&u.UserId(n,'"owner"'),this.service=t,this.owner=n;let s=!!r?.autoLogin;this.target_cdn=i?.target_cdn||this.target_cdn,this.hostDomain=i?.hostDomain||this.hostDomain;const o=`https://${this.target_cdn}.cloudfront.net`;let a=t.substring(0,4);if(this.admin_endpoint=fetch(`${o}/${a}/admin.json`).then((e=>e.blob())).then((e=>new Promise(((t,n)=>{const r=new FileReader;r.onloadend=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)})))).then((e=>"string"==typeof e?JSON.parse(window.atob(e.split(",")[1])):null)),this.record_endpoint=fetch(`${o}/${a}/record.json`).then((e=>e.blob())).then((e=>new Promise(((t,n)=>{const r=new FileReader;r.onloadend=()=>t(r.result),r.onerror=n,r.readAsDataURL(e)})))).then((e=>"string"==typeof e?JSON.parse(window.atob(e.split(",")[1])):null)),!window.sessionStorage)throw new Error("This browser does not support skapi.");const c=JSON.parse(window.sessionStorage.getItem(`${t}#${n}`)||"null");if(c?.connection)for(let e in c)this[e]=c[e];this.__authConnection=(async()=>{const e=await this.admin_endpoint;var t;if(t={UserPoolId:e.userpool_id,ClientId:e.userpool_client},ct=new at(t),!c?.connection&&!s){let e=ct.getCurrentUser();e&&e.signOut()}if(s)try{await mt.bind(this)().getSession({refreshToken:!c?.connection})}catch(e){this.__user=null}})(),this.__connection=(async()=>{let e=null;c?.connection||(e=this.updateConnection());const r=()=>{if(this.__class_properties_has_been_cached)return;let r=()=>{let e={};const r=["__startKeyHistory","__cached_requests","__request_signup_confirmation","connection"];if(this.connection){for(let t of r)e[t]=this[t];window.sessionStorage.setItem(`${t}#${n}`,JSON.stringify(e)),this.__class_properties_has_been_cached=!0}};return e instanceof Promise?e.then((()=>r())):r()};return window.addEventListener("beforeunload",(()=>{r(),this.closeRealtime()})),await e,await this.__authConnection,console.log(`Built with:\n%c\r\n $$\\ $$\\ \r\n $$ | \\__|\r\n $$$$$$$\\ $$ | $$\\ $$$$$$\\ $$$$$$\\ $$\\ \r\n$$ _____|$$ | $$ |\\____$$\\ $$ __$$\\ $$ |\r\n\\$$$$$$\\ $$$$$$ / $$$$$$$ |$$ / $$ |$$ |\r\n \\____$$\\ $$ _$$< $$ __$$ |$$ | $$ |$$ |\r\n$$$$$$$ |$$ | \\$$\\\\$$$$$$$ |$$$$$$$ |$$ |\r\n\\_______/ \\__| \\__|\\_______|$$ ____/ \\__|\r\n $$ | \r\n $$ | \r\n \\__| \r\nVersion: ${this.version}\n\nDocumentation: https://docs.skapi.com`,"font-family: monospace; color:blue;"),1===this.connection.group&&console.log("%cSKAPI: THE SERVICE IS IN TRIAL MODE. ALL THE USERS AND DATA WILL BE INITIALIZED EVERY 7 DAYS.","font-family: monospace; color:red;"),this.connection})()}async updateConnection(){return this.connection=await h.bind(this)("service",{service:this.service,owner:this.owner},{bypassAwaitConnection:!0,method:"get"}),this.connection}connectRealtime(e){return F.bind(this)(e)}jwtLogin(e){return vt.bind(this)(e)}clientSecretRequest(e){return K.bind(this)(e)}consumeTicket(e){return ht.bind(this)(e)}getConsumedTickets(e,t){return dt.bind(this)(e,t)}getTickets(e,t){return ft.bind(this)(e,t)}closeRealtime(){return L.bind(this)()}getRealtimeUsers(e,t){return $.bind(this)(e,t)}getRealtimeGroups(e,t){return q.bind(this)(e,t)}postRealtime(e,t){return x.bind(this)(e,t)}joinRealtime(e){return B.bind(this)(e)}getConnection(){return this.__connection}getProfile(e){return yt.bind(this)(e)}getFile(e,t){return E.bind(this)(e,t)}secureRequest(e){return j.bind(this)(e)}getFormResponse(){return _.bind(this)()}getRecords(e,t){return S.bind(this)(e,t)}getTables(e,t){return R.bind(this)(e,t)}getIndexes(e,t){return T.bind(this)(e,t)}getTags(e,t){return U.bind(this)(e,t)}deleteRecords(e){return D.bind(this)(e)}resendSignupConfirmation(e){return bt.bind(this)(e)}recoverAccount(e=!1){return At.bind(this)(e)}getUsers(e,t){return kt.bind(this)(e,t)}disableAccount(){return It.bind(this)()}lastVerifiedEmail(e){return Mt.bind(this)(e)}unsubscribeNewsletter(e){return ee.bind(this)(e)}getNewsletters(e,t){return te.bind(this)(e,t)}getNewsletterSubscription(e){return Z.bind(this)(e)}requestUsernameChange(e){return Ot.bind(this)(e)}grantPrivateRecordAccess(e){return C.bind(this)(e)}removePrivateRecordAccess(e){return P.bind(this)(e)}listPrivateRecordAccess(e){return N.bind(this)(e)}requestPrivateRecordAccessKey(e){return k.bind(this)(e)}deleteFiles(e){return v.bind(this)(e)}uploadFiles(e,t){return m.bind(this)(e,t)}mock(e,t){return H.bind(this)(e,t)}login(e){return Et.bind(this)(e)}logout(){return _t.bind(this)()}signup(e,t){return St.bind(this)(e,t)}resetPassword(e){return Rt.bind(this)(e)}verifyEmail(e){return Dt.bind(this)(e)}verifyPhoneNumber(e){return Ut.bind(this)(e)}forgotPassword(e){return Ct.bind(this)(e)}changePassword(e){return Pt.bind(this)(e)}updateProfile(e){return Nt.bind(this)(e)}postRecord(e,t){return I.bind(this)(e,t)}getSubscriptions(e,t){return J.bind(this)(e,t)}subscribe(e){return z.bind(this)(e)}unsubscribe(e){return Y.bind(this)(e)}blockSubscriber(e){return Q.bind(this)(e)}unblockSubscriber(e){return G.bind(this)(e)}subscribeNewsletter(e){return X.bind(this)(e)}}Vt([w()],Lt.prototype,"consumeTicket",null),Vt([w()],Lt.prototype,"getConsumedTickets",null),Vt([w()],Lt.prototype,"getTickets",null),Vt([w()],Lt.prototype,"getRealtimeUsers",null),Vt([w()],Lt.prototype,"getRealtimeGroups",null),Vt([w()],Lt.prototype,"postRealtime",null),Vt([w()],Lt.prototype,"joinRealtime",null),Vt([w()],Lt.prototype,"getProfile",null),Vt([w()],Lt.prototype,"getFile",null),Vt([w()],Lt.prototype,"secureRequest",null),Vt([w()],Lt.prototype,"getFormResponse",null),Vt([w()],Lt.prototype,"getRecords",null),Vt([w()],Lt.prototype,"getTables",null),Vt([w()],Lt.prototype,"getIndexes",null),Vt([w()],Lt.prototype,"getTags",null),Vt([w()],Lt.prototype,"deleteRecords",null),Vt([w()],Lt.prototype,"resendSignupConfirmation",null),Vt([w()],Lt.prototype,"recoverAccount",null),Vt([w()],Lt.prototype,"getUsers",null),Vt([w()],Lt.prototype,"disableAccount",null),Vt([w()],Lt.prototype,"lastVerifiedEmail",null),Vt([w()],Lt.prototype,"unsubscribeNewsletter",null),Vt([w()],Lt.prototype,"getNewsletters",null),Vt([w()],Lt.prototype,"getNewsletterSubscription",null),Vt([w()],Lt.prototype,"requestUsernameChange",null),Vt([w()],Lt.prototype,"grantPrivateRecordAccess",null),Vt([w()],Lt.prototype,"removePrivateRecordAccess",null),Vt([w()],Lt.prototype,"listPrivateRecordAccess",null),Vt([w()],Lt.prototype,"requestPrivateRecordAccessKey",null),Vt([w()],Lt.prototype,"deleteFiles",null),Vt([w()],Lt.prototype,"uploadFiles",null),Vt([w()],Lt.prototype,"mock",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"login",null),Vt([w()],Lt.prototype,"logout",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"signup",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"resetPassword",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"verifyEmail",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"verifyPhoneNumber",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"forgotPassword",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"changePassword",null),Vt([w({preventMultipleCalls:!0})],Lt.prototype,"updateProfile",null),Vt([w()],Lt.prototype,"postRecord",null),Vt([w()],Lt.prototype,"getSubscriptions",null),Vt([w()],Lt.prototype,"subscribe",null),Vt([w()],Lt.prototype,"unsubscribe",null),Vt([w()],Lt.prototype,"blockSubscriber",null),Vt([w()],Lt.prototype,"unblockSubscriber",null),Vt([w()],Lt.prototype,"subscribeNewsletter",null)})(),r})()));
|
|
3
3
|
//# sourceMappingURL=skapi.js.map
|