skapi-js 0.0.3 → 0.0.4
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/README.md +1 -1
- package/dist/skapi.js +1 -1
- package/dist/skapi.js.map +1 -1
- package/index.html +90 -0
- package/package.json +1 -1
- package/src/skapi.ts +3 -32
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 r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(self,(()=>(()=>{var e={864:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SkapiError=t.Skapi=void 0;const i=n(r(715));t.Skapi=i.default;const s=n(r(246));t.SkapiError=s.default},752:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.formResponse=void 0;const i=n(r(246)),s=r(170);t.formResponse=function(){return function(e,t,r){const n=r.value;r.value=function(...e){let t=e[0],r=(null==e?void 0:e[1])||{};const o=e=>{if(null==r?void 0:r.response){if("function"==typeof r.response)return r.response(e),e;throw new i.default('Callback "response" should be type: function.',{code:"INVALID_PARAMETER"})}if(!(t instanceof HTMLFormElement))return e;let n=new URL(t.action),o=(0,s.sha256)(t.action),a=Date.now().toString();window.sessionStorage.setItem(o,JSON.stringify({[a]:e})),n.searchParams.set(o,a),window.location.href=n.href};let a;function u(e){let t=e instanceof Error?e:new i.default(e);if(null==r?void 0:r.onerror){if("function"==typeof r.onerror)return r.onerror(t);throw new i.default('Callback "onerror" should be type: function.',{code:"INVALID_PARAMETER"})}return t}try{a=n.bind(this)(...e)}catch(e){let t=u(e);if(t instanceof Error)throw t;return t}return a instanceof Promise?new Promise(((e,t)=>{a.then((t=>{e(o(t))})).catch((r=>{(r=u(r))instanceof Error?t(r):e(r)}))})):o(a)}}}},715:function(e,t,r){"use strict";var n=this&&this.__decorate||function(e,t,r,n){var i,s=arguments.length,o=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(o=(s<3?i(o):s>3?i(t,r,o):i(t,r))||o);return s>3&&o&&Object.defineProperty(t,r,o),o},i=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(i,s){function o(e){try{u(n.next(e))}catch(e){s(e)}}function a(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,a)}u((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(243),a=s(r(246)),u=r(752),l=r(170);class c{constructor(e,t,r=!1){if(this.cognitoUser=null,this.__disabledAccount=null,this.__serviceHash={},this.__pendingRequest={},this.__cached_requests={},this.__startKey_keys={},this.__request_signup_confirmation=null,this.__index_number_range=4503599627370496,this.__class_properties_has_been_cached=!1,this.session=null,this.user=null,this.connection=null,this.host="skapi",this.hostDomain="skapi.com",this.userPool=null,this.regex={validateUserId(e){try{return(0,l.validateUserId)(e),!0}catch(e){return!1}},validateUrl(e){try{return(0,l.validateUrl)(e),!0}catch(e){return!1}},validatePhoneNumber(e){try{return(0,l.validatePhoneNumber)(e),!0}catch(e){return!1}},validateBirthdate(e){try{return(0,l.validateBirthdate)(e),!0}catch(e){return!1}},validateEmail(e){try{return(0,l.validateEmail)(e),!0}catch(e){return!1}}},this.update_startKey_keys=e=>i(this,void 0,void 0,(function*(){var t;let{hashedParam:r,url:n,response:i}=e,s=null;if(s=i instanceof Promise?yield i:i,"object"!=typeof s||!s.hasOwnProperty("startKey")||!r||!n)return s;this.__startKey_keys.hasOwnProperty(n)||(this.__startKey_keys[n]={}),(null===(t=this.__cached_requests)||void 0===t?void 0:t[n])||(this.__cached_requests[n]={}),this.__cached_requests[n][r]=s,this.__startKey_keys[n].hasOwnProperty(r)||(this.__startKey_keys[n][r]=[]);let o=JSON.stringify(s.startKey);return this.__startKey_keys[n][r].includes(o)||this.__startKey_keys[n][r].push(o),this.__cached_requests[n][r]=s,Object.assign({startKey_list:this.__startKey_keys[n][r]},s)})),this._fetch=(e,t,r)=>i(this,void 0,void 0,(function*(){let n=yield fetch(e,t);if(r){if(200===n.status)return yield n[r]();throw n}let i=yield n.text();try{i=JSON.parse(i)}catch(e){}if(200===n.status){if("object"==typeof i&&"GET"===t.method&&i.hasOwnProperty("body"))try{i=JSON.parse(i.body)}catch(e){}return i}{let e=null==n?void 0:n.status,t=["INVALID_CORS","INVALID_REQUEST","SERVICE_DISABLED","INVALID_PARAMETER","ERROR","EXISTS","NOT_EXISTS"];if("object"==typeof i&&(null==i?void 0:i.message)){let t=(e?e.toString():null)||"ERROR";throw new a.default(null==i?void 0:i.message,{code:t})}if("string"==typeof i){let e=i.split(":"),r=e.splice(0,1)[0];throw new a.default(e.join(""),{code:t.includes(r)?r:"ERROR"})}throw n}})),this._get=(e,t,r)=>i(this,void 0,void 0,(function*(){if(t&&"object"==typeof t&&Object.keys(t).length){"?"!==e.substring(e.length-1)&&(e+="?");let r=Object.keys(t).map((e=>{let r=t[e];return"string"!=typeof r&&(r=JSON.stringify(r)),encodeURIComponent(e)+"="+encodeURIComponent(r)})).join("&");e+=r}let n=null;r.hasOwnProperty("responseType")&&(n=r.responseType,delete r.responseType);let i=Object.assign({method:"GET"},r);return this._fetch(e,i,n)})),"string"!=typeof e||"string"!=typeof t)throw new a.default('"service_id" and "service_owner" should be type <string>.',{code:"INVALID_PARAMETER"});if(!e||!t)throw new a.default('"service_id" and "service_owner" is required',{code:"INVALID_PARAMETER"});t!==this.host&&(0,l.validateUserId)(t,'"service_owner"'),this.service=e,this.service_owner=t;const n="https://dkls9pxkgz855.cloudfront.net";let s=e.substring(0,4);this.admin_endpoint=fetch(`${n}/${s}/admin.json`).then((e=>e.blob())).then((e=>new Promise(((t,r)=>{const n=new FileReader;n.onloadend=()=>t(n.result),n.onerror=r,n.readAsDataURL(e)})))).then((e=>"string"==typeof e?JSON.parse(window.atob(e.split(",")[1])):null)),this.record_endpoint=fetch(`${n}/${s}/record.json`).then((e=>e.blob())).then((e=>new Promise(((t,r)=>{const n=new FileReader;n.onloadend=()=>t(n.result),n.onerror=r,n.readAsDataURL(e)})))).then((e=>"string"==typeof e?JSON.parse(window.atob(e.split(",")[1])):null)),this.__connection=(n=>i(this,void 0,void 0,(function*(){if(!window.sessionStorage)throw new Error("This browser does not support skapi.");const i=JSON.parse(window.sessionStorage.getItem(`${e}#${t}`)||"null");if(null==i?void 0:i.connection)for(let e in i)n[e]=i[e];const s=yield n.admin_endpoint;n.userPool=new o.CognitoUserPool({UserPoolId:s.userpool_id,ClientId:s.userpool_client});const a=[n.updateConnection()];((null==i?void 0:i.connection)||r)&&a.push(n.authentication().updateSession({refreshToken:!!(null==i?void 0:i.connection)}).catch((e=>{n.user=null}))),yield Promise.all(a);const u=()=>{if(n.__class_properties_has_been_cached)return;let r={};const i=["__startKey_keys","__cached_requests","__request_signup_confirmation","connection"];if(n.connection){for(let e of i)r[e]=n[e];sessionStorage.setItem(`${e}#${t}`,JSON.stringify(r)),n.__class_properties_has_been_cached=!0}};return window.addEventListener("beforeunload",u),window.addEventListener("visibilitychange",u),n.connection})))(this).catch((e=>{throw e}))}static connect(e,t,r=!1){return i(this,void 0,void 0,(function*(){const n=new c(e,t,r);return yield n.__connection,n}))}authentication(){if(!this.userPool)throw new a.default("User pool is missing",{code:"INVALID_REQUEST"});const e=e=>{let{refreshToken:t=!1}=e||{};return new Promise(((e,r)=>{var n;let s=(null===(n=this.userPool)||void 0===n?void 0:n.getCurrentUser())||null;this.cognitoUser=s,null===s&&r(null),s.getSession(((n,o)=>{n&&r(n);const u=t=>i(this,void 0,void 0,(function*(){t.isValid()&&s?s.getUserAttributes(((n,i)=>{if(n)r(n);else{let n={},s={};for(let e of i)n[e.Name]=e.Value,s[e.Name.replace("custom:","")]=e.Value,"custom:service"===e.Name&&n[e.Name]!==this.service&&r(new a.default("The user is not registered to the service.",{code:"INVALID_REQUEST"}));for(let e of["address_public","birthdate_public","email_public","email_subscription","gender_public","phone_number_public"])e.includes("_public")?s.hasOwnProperty(e.split("_")[0])?s[e]=s.hasOwnProperty(e)?Number(s[e]):0:delete s[e]:s[e]=s.hasOwnProperty(e)?Number(s[e]):0;for(let e of["email_verified","phone_number_verified"])s[e.split("_")[0]]?s[e]=!!s.hasOwnProperty(e)&&"true"===s[e]:s.hasOwnProperty(e)&&delete s[e];t.attributes=n,this.session=t,s.access_group=Number(this.session.idToken.payload.access_group),s.user_id=s.sub,delete s.sub,this.user=s,e(s)}})):r(new a.default("Invalid session.",{code:"INVALID_REQUEST"}))}));o?t?null==s||s.refreshSession(o.getRefreshToken(),((e,t)=>{e&&r(e),u(t).catch((e=>r(e)))})):u(o).catch((e=>r(e))):r(new a.default("Current session does not exist.",{code:"INVALID_REQUEST"}))}))}))},t=e=>i(this,void 0,void 0,(function*(){let t=null;if(e)t=this.__serviceHash[e]||(yield this.updateConnection({request_hash:e})).hash;else{if(!this.session)throw new a.default("E-Mail is required.",{code:"INVALID_PARAMETER"});t=this.session.idToken.payload["cognito:username"]}return{cognitoUser:new o.CognitoUser({Username:t,Pool:this.userPool}),cognitoUsername:t}}));return{updateSession:e,authenticateUser:(r,n)=>new Promise(((s,u)=>i(this,void 0,void 0,(function*(){this.logout(),this.__request_signup_confirmation=null,this.__disabledAccount=null;let i=yield t(r);this.cognitoUser=i.cognitoUser,r=i.cognitoUsername;let l=new o.AuthenticationDetails({Username:r,Password:n});this.cognitoUser.authenticateUser(l,{newPasswordRequired:(e,t)=>{this.__request_signup_confirmation=r,u(new a.default("User's signup confirmation is required.",{code:"SIGNUP_CONFIRMATION_NEEDED"}))},onSuccess:t=>{e().then((e=>{s(e)}))},onFailure:e=>{let t=[e.message||"Failed to authenticate user.",(null==e?void 0:e.code)||"INVALID_REQUEST"];"NotAuthorizedException"===e.code&&("User is disabled."===e.message?(this.__disabledAccount=r,t=["This account is disabled.","USER_IS_DISABLED"]):t=["Incorrect username or password.","INCORRECT_USERNAME_OR_PASSWORD"]),u(new a.default(t[0],{code:t[1],cause:e}))}})})))),createCognitoUser:t}}requireAdmin(e){var t,r,n,s,o,u;return i(this,void 0,void 0,(function*(){if((null===(r=null===(t=this.session)||void 0===t?void 0:t.attributes)||void 0===r?void 0:r["custom:service"])===this.service){if((null===(s=null===(n=this.session)||void 0===n?void 0:n.attributes)||void 0===s?void 0:s["custom:service_owner"])===this.host){if(!(null==e?void 0:e.ignoreVerification)&&!(null===(u=null===(o=this.session)||void 0===o?void 0:o.attributes)||void 0===u?void 0:u.email_verified))throw new a.default("Email verification is required.",{code:"INVALID_REQUEST"});return!0}if(null==e?void 0:e.throwError)throw new a.default("Admin access is required.",{code:"INVALID_REQUEST"})}else if(this.logout(),null==e?void 0:e.throwError)throw new a.default("User login is required.",{code:"INVALID_REQUEST"});return!1}))}getBlob(e,t){return i(this,void 0,void 0,(function*(){let r=(0,l.checkParams)(e,{url:e=>(0,l.validateUrl)(e)},["url"]);return yield this.request(r.url,t||null,{method:"get",auth:r.url.includes("/auth/"),contentType:null,responseType:"blob"})}))}secureRequest(e){return i(this,void 0,void 0,(function*(){let t={url:e=>(0,l.validateUrl)(e),data:null,sync:["boolean",()=>!0]};if(Array.isArray(e))for(let r of e)r=(0,l.checkParams)(r,t);else e=(0,l.checkParams)(e,t);return yield this.request("post-secure",e,{auth:!0})}))}getFormResponse(){let e=new URLSearchParams(window.location.search);for(let[t,r]of e.entries()){if("form-"!==t.substring(0,5))continue;let e=window.sessionStorage.getItem(t);if(e){window.sessionStorage.removeItem(t);try{e=JSON.parse(e)}catch(e){}}if("object"==typeof e&&e[r])return e[r]}return null}request(e,t=null,r={}){var n,s,o,u,c,h,f,d,p;return i(this,void 0,void 0,(function*(){let{auth:g=!1,method:v="post",meta:y=null,bypassAwaitConnection:m=!1}=r,w=m?null:yield this.__connection,_=g?null===(s=null===(n=this.session)||void 0===n?void 0:n.idToken)||void 0===s?void 0:s.jwtToken:null;if(g&&!_)throw this.logout(),new a.default("User login is required.",{code:"INVALID_REQUEST"});let A="";try{A=(0,l.validateUrl)(e)}catch(e){}let b=A||(yield((e,t)=>i(this,void 0,void 0,(function*(){const r=yield Promise.all([this.admin_endpoint,this.record_endpoint]),n=r[0],i=r[1];return(()=>{switch(e){case"get-serviceletters":case"delete-newsletter":case"block-account":case"register-service":case"get-users":case"post-userdata":case"remove-account":case"post-secure":case"get-newsletters":case"subscribe-newsletter":case"signup":case"confirm-signup":case"recover-account":case"service":return{public:n.admin_public,private:n.admin_private};case"post-record":case"get-records":case"subscription":case"get-subscription":case"del-records":case"get-table":case"get-tag":case"get-index":case"storage-info":return{private:i.record_private,public:i.record_public}}})()[t?"private":"public"]+e})))(e,!!g)),S=(null===(u=null===(o=this.session)||void 0===o?void 0:o.attributes)||void 0===u?void 0:u["custom:service"])||(null==w?void 0:w.service)||this.service,E=(null===(h=null===(c=this.session)||void 0===c?void 0:c.attributes)||void 0===h?void 0:h["custom:service_owner"])||(null==w?void 0:w.owner)||this.service_owner;if(y){if("object"!=typeof y||Array.isArray(y))throw new a.default("Invalid meta data.",{code:"INVALID_REQUEST"});y=JSON.parse(JSON.stringify(y))}if(Array.isArray(t)||t&&"object"!=typeof t)throw new a.default("Request data should be a JSON Object | FormData | HTMLFormElement.",{code:"INVALID_REQUEST"});let I={service:S,service_owner:E},U={},{refresh:R=!1}=r.fetchOptions||{};if(r.fetchOptions&&Object.keys(r.fetchOptions).length){let e=(0,l.checkParams)({limit:(null===(f=null==r?void 0:r.fetchOptions)||void 0===f?void 0:f.limit)||100,startKey:(null===(d=null==r?void 0:r.fetchOptions)||void 0===d?void 0:d.startKey)||null,ascending:"boolean"!=typeof(null===(p=null==r?void 0:r.fetchOptions)||void 0===p?void 0:p.ascending)||r.fetchOptions.ascending},{limit:["number",()=>100],startKey:null,ascending:["boolean",()=>!0]});if(e.hasOwnProperty("limit")&&"number"==typeof e.limit){if(e.limit>1e3)throw new a.default("Fetch limit should be below 1000.",{code:"INVALID_REQUEST"});Object.assign(U,{limit:e.limit})}e.hasOwnProperty("startKey")&&"object"==typeof e.startKey&&e.startKey&&Object.keys(e.startKey)&&Object.assign(U,{startKey:e.startKey}),e.hasOwnProperty("ascending")&&"boolean"==typeof e.ascending&&Object.assign(U,{ascending:e.ascending})}Object.assign(I,U);let D=(0,l.extractFormMetaData)(t),T=null==D?void 0:D.meta,C=(null==D?void 0:D.files)||[],P=(e,t,n=!1)=>i(this,void 0,void 0,(function*(){var i,s;if(null===t)return e;let o=!1;if(e instanceof HTMLFormElement&&(e=new FormData(e),o=!0),!(e instanceof FormData))return e;if(n)for(let t in I)void 0!==I[t]&&e.set(t,"string"==typeof I[t]?I[t]:new Blob([JSON.stringify(I[t])],{type:"application/json"}));for(let r in t)void 0!==t[r]&&e[C.includes(r)?"append":"set"](r,"string"==typeof t[r]?t[r]:new Blob([JSON.stringify(t[r])],{type:"application/json"}));if(null===(i=null==r?void 0:r.fetchOptions)||void 0===i?void 0:i.formData){if("function"!=typeof(null===(s=null==r?void 0:r.fetchOptions)||void 0===s?void 0:s.formData))throw new a.default('Callback "formData" should type: function.',{code:"INVALID_PARAMETER"});{if(!o)throw new a.default("Form data should be HTMLFormElement when formData() callback is used.",{code:"INVALID_PARAMETER"});let t=r.fetchOptions.formData(e);if(t instanceof Promise&&(t=yield t),!(t instanceof FormData))throw new a.default("Callback for extractFormData() should return FormData",{code:"INVALID_PARAMETER"});e=t}}return e}));y?(y=Object.assign(I,y),t=yield P(t,T)):t=t||null!==T?T?yield P(t,T,!0):Object.assign(I,t):I;let k=this.load_startKey_keys({params:Object.assign(T||t||{},I||{}),url:A||e,refresh:!!T||R});if(k&&"object"==typeof k)return k;if("string"==typeof k){if(!(this.__pendingRequest[k]instanceof Promise)){let e={Accept:"*/*"};_&&(e.Authorization=_),y&&(e["Content-Meta"]=JSON.stringify(y)),r.hasOwnProperty("contentType")?(null==r?void 0:r.contentType)&&(e["Content-Type"]=r.contentType):t instanceof FormData||(e["Content-Type"]="application/json");let n={headers:e};(null==r?void 0:r.responseType)&&(n.responseType=r.responseType),"post"===v?this.__pendingRequest[k]=this._post(b,t,n):"get"===v&&(this.__pendingRequest[k]=this._get(b,t,n))}try{let t=yield this.__pendingRequest[k];return T?t:yield this.update_startKey_keys({hashedParam:k,url:e,response:t})}catch(e){throw e}finally{k&&this.__pendingRequest.hasOwnProperty(k)&&delete this.__pendingRequest[k]}}}))}load_startKey_keys(e){var t,r,n,i,s,o,u,c,h,f,d,p,g,v;let{params:y={},url:m,refresh:w=!1}=e||{};if(y.hasOwnProperty("startKey")){if("object"!=typeof y.startKey&&!Object.keys(y.startKey).length||"end"!==y.startKey)throw new a.default(`"${y.startKey}" is invalid startKey key.`,{code:"INVALID_PARAMETER"});switch(y.startKey){case"end":return{list:[],startKey:"end",endOfList:!0};case"start":delete y.startKey}}(()=>{if(y&&"object"==typeof y&&Object.keys(y).length){let e=JSON.parse(JSON.stringify(y));function t(e){function t(e){return"object"==typeof e&&e?Object.keys(e).sort().reduce(((t,r)=>(t[r]=e[r],t)),{}):e}let r=t(e);for(let n in r)r[n]&&"object"==typeof r[n]&&(r[n]=t(e[n]));return r}return JSON.stringify(t(e))+m+this.service}this.service})();let _=(0,l.sha256)((()=>{if(y&&"object"==typeof y&&Object.keys(y).length){let e=JSON.parse(JSON.stringify(y));function t(e){function t(e){return"object"==typeof e&&e?Object.keys(e).sort().reduce(((t,r)=>(t[r]=e[r],t)),{}):e}let r=t(e);for(let n in r)r[n]&&"object"==typeof r[n]&&(r[n]=t(e[n]));return r}return JSON.stringify(t(e))+m+this.service}return m+this.service})());if(w&&(null===(r=null===(t=this.__startKey_keys)||void 0===t?void 0:t[m])||void 0===r?void 0:r[_])){if((null===(n=this.__cached_requests)||void 0===n?void 0:n[m])&&(null===(s=null===(i=this.__cached_requests)||void 0===i?void 0:i[m])||void 0===s?void 0:s[_])&&delete this.__cached_requests[m][_],Array.isArray(this.__startKey_keys[m][_])&&this.__startKey_keys[m][_].length)for(let e of this.__startKey_keys[m][_]){let t=_+(0,l.sha256)(JSON.stringify(e));(null===(o=this.__cached_requests)||void 0===o?void 0:o[m])&&(null===(c=null===(u=this.__cached_requests)||void 0===u?void 0:u[m])||void 0===c?void 0:c[t])&&delete this.__cached_requests[m][t]}return delete this.__startKey_keys[m][_],_}if(!Array.isArray(null===(f=null===(h=this.__startKey_keys)||void 0===h?void 0:h[m])||void 0===f?void 0:f[_]))return _;let A=this.__startKey_keys[m][_],b=A[A.length-1],S=_;if(b){if("end"===b)return{list:[],startKey:"end",endOfList:!0};S+=(0,l.sha256)(b),y.startKey=JSON.parse(b)}return(null===(p=null===(d=this.__cached_requests)||void 0===d?void 0:d[m])||void 0===p?void 0:p[S])?null===(v=null===(g=this.__cached_requests)||void 0===g?void 0:g[m])||void 0===v?void 0:v[S]:_}_post(e,t,r){let n=null;r.hasOwnProperty("responseType")&&(n=r.responseType,delete r.responseType);let i=Object.assign({method:"POST"},r,{body:t instanceof FormData?t:JSON.stringify(t)});return this._fetch(e,i,n)}postRecord(e,t){var r,n;return i(this,void 0,void 0,(function*(){let i=yield this.requireAdmin({ignoreVerification:!0}),{formData:s}=t,o={};if("function"==typeof s&&(o.formData=s),delete(t=(0,l.checkParams)(t||{},{record_id:"string",access_group:["number","private"],table:["string",()=>{if(!(null==t?void 0:t.record_id))throw new a.default('Either "record_id" or "table" should have a value.',{code:"INVALID_PARAMETER"})}],subscription_group:"number",reference:"string",index:{name:"string",value:["string","number","boolean"]},tags:e=>{if(null===e)return e;if("string"==typeof e)return[e];if(Array.isArray(e)){for(let t of e)if("string"!=typeof t)throw new a.default('"tags" should be type: <string | string[]>',{code:"INVALID_PARAMETER"});return e}throw new a.default('"tags" should be type: <string | string[]>',{code:"INVALID_PARAMETER"})},config:{reference_limit:["number",null],allow_multiple_reference:"boolean",private_access:e=>{let t="config.private_access";if(e&&"string"==typeof e&&(e=[e]),!Array.isArray(e))throw new a.default(`"${t}" should be an array of user ID.`,{code:"INVALID_PARAMETER"});for(let r of e)if((0,l.validateUserId)(r,`User ID in "${t}"`),this.user&&r===this.user.user_id)throw new a.default(`"${t}" should not be the uploader's user ID.`,{code:"INVALID_PARAMETER"});return e}}},[],["response","formData","onerror"])).response,delete t.formData,delete t.onerror,null==t?void 0:t.index){if(!(null===(r=t.index)||void 0===r?void 0:r.name)||"string"!=typeof(null===(n=t.index)||void 0===n?void 0:n.name))throw new a.default('"index.name" is required. type: string.',{code:"INVALID_PARAMETER"});if((0,l.checkWhiteSpaceAndSpecialChars)(t.index.name,"index name",!0),!t.index.hasOwnProperty("value"))throw new a.default('"index.value" is required.',{code:"INVALID_PARAMETER"});if("string"==typeof t.index.value)(0,l.checkWhiteSpaceAndSpecialChars)(t.index.value,"index value",!1,!0);else if("number"==typeof t.index.value&&(t.index.value>this.__index_number_range||t.index.value<-this.__index_number_range))throw new a.default(`Number value should be within range -${this.__index_number_range} ~ +${this.__index_number_range}`,{code:"INVALID_PARAMETER"})}if(i){if("private"===(null==t?void 0:t.access_group))throw new a.default("Service owner cannot write private records.",{code:"INVALID_REQUEST"});if(t.hasOwnProperty("subscription_group"))throw new a.default("Service owner cannot write to subscription table.",{code:"INVALID_REQUEST"})}let u={auth:!0},c=null;return e instanceof HTMLFormElement||e instanceof FormData?Object.assign(u,{meta:t}):c=Object.assign({data:e},t),Object.keys(o).length&&Object.assign(u,{fetchOptions:o}),(0,l.normalize_record_data)(yield this.request("post-record",c||e,u))}))}getRecords(e,t){return i(this,void 0,void 0,(function*(){const r={$record_id:"string",$updated:"number",$uploaded:"number",$referenced_count:"number"},n={table:"string",reference:"string",access_group:["number","private"],subscription:{user_id:e=>(0,l.validateUserId)(e,'User ID in "subscription.user_id"'),group:"number"},index:{name:e=>{if("string"!=typeof e)throw new a.default('"index.name" should be type: string.',{code:"INVALID_PARAMETER"});return r.hasOwnProperty(e)?e:(0,l.checkWhiteSpaceAndSpecialChars)(e,"index.name",!0,!1)},value:t=>{var n;if((null===(n=e.index)||void 0===n?void 0:n.name)&&r.hasOwnProperty(e.index.name)){let n=r[e.index.name];if(typeof t===n)return t;throw new a.default(`"index.value" should be type: ${n}.`,{code:"INVALID_PARAMETER"})}if("number"==typeof t){if(t>this.__index_number_range||t<-this.__index_number_range)throw new a.default(`Number value should be within range -${this.__index_number_range} ~ +${this.__index_number_range}`,{code:"INVALID_PARAMETER"});return t}return"boolean"==typeof t?t:(0,l.checkWhiteSpaceAndSpecialChars)(t,"index.value",!1,!0)},condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"],range:t=>{if(!("value"in e.index))throw new a.default('"index.value" is required.',{code:"INVALID_PARAMETER"});if("$record_id"===e.index.name)throw new a.default(`Cannot do "index.range" on ${e.index.name}`,{code:"INVALID_PARAMETER"});if(typeof e.index.value!=typeof t)throw new a.default('"index.range" type should match the type of "index.value".',{code:"INVALID_PARAMETER"});return"string"==typeof t?(0,l.checkWhiteSpaceAndSpecialChars)(t,"index.value"):t}},tags:e=>{if("string"==typeof e)return[e];if(Array.isArray(e)){if(e.length>10)throw new a.default("Cannot query more than 10 tags at once.",{code:"INVALID_REQUEST"});for(let t of e)if("string"!=typeof t)throw new a.default("Tags should be type: <string | string[]>",{code:"INVALID_PARAMETER"});return e}}};if((null==(e=(0,l.checkParams)(e||{},n,["table"]))?void 0:e.subscription)&&!this.session)throw new a.default("Requires login.",{code:"INVALID_REQUEST"});if(null==e?void 0:e.tags){let r=[],n=(null==t?void 0:t.startKey)||null;for(let i of e.tags){let s=JSON.parse(JSON.stringify(e));s.tag=i,delete s.tags;let o=t?JSON.parse(JSON.stringify(t)):null;o&&(delete o.startKey,n&&(null==n?void 0:n[i])&&(o.startKey=n[i])),r.push(this.request("get-records",s,Object.assign({auth:!(!e.hasOwnProperty("access_group")||!("private"===e.access_group||e.access_group>0))||!!this.session},{fetchOptions:o})))}let i=[],s={},o=yield Promise.all(r);for(let t of o){for(let e in t.list)r.includes(t.list[e].rec)||(r.push(t.list[e]),i.push((0,l.normalize_record_data)(t.list[e])));t.startKey&&Array.isArray(e.tags)&&(s[e.tags.splice(0,1)[0]]=t.startKey)}let a=!0;for(let e in s)if(s[e]&&"end"!==s[e]){a=!1;break}return{list:i,endOfList:a,startKey:s}}let i=yield this.request("get-records",e,Object.assign({auth:!(!e.hasOwnProperty("access_group")||!("private"===e.access_group||e.access_group>0))||!!this.user},{fetchOptions:t}));for(let e in i.list)i.list[e]=(0,l.normalize_record_data)(i.list[e]);return i}))}getTable(e,t){return i(this,void 0,void 0,(function*(){let r=yield this.request("get-table",(0,l.checkParams)(e||{},{table:"string",condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}),Object.assign({auth:!0},{fetchOptions:t})),n={cnt_rec:"number_of_records",tbl:"table",srvc:"service"};if(Array.isArray(r.list))for(let e of r.list)for(let t in n)e.hasOwnProperty(t)&&(e[n[t]]=e[t],delete e[t]);return r}))}getIndex(e,t){return i(this,void 0,void 0,(function*(){let r=(0,l.checkParams)(e||{},{table:"string",index:e=>(0,l.checkWhiteSpaceAndSpecialChars)(e,"index name",!0,!1),order_by:{name:["average_number","total_number","number_count","average_bool","total_bool","bool_count","string_count","index_name"],value:["string","number","boolean"],condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}},["table"]);if(r.hasOwnProperty("order_by")){if("index_name"===r.order_by){if(!r.hasOwnProperty("index"))throw new a.default('"index" is required for ordered by "index_name".',{code:"INVALID_PARAMETER"});if("."!==r.index.substring(r.index.length-1))throw new a.default('"index" should be parent "index name".',{code:"INVALID_PARAMETER"})}if(r.order_by.hasOwnProperty("condition")&&!r.order_by.hasOwnProperty("value"))throw new a.default('"value" is required for "condition".',{code:"INVALID_PARAMETER"})}let n=yield this.request("get-index",r,Object.assign({auth:!0},{fetchOptions:t})),i={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(n.list)&&(n.list=n.list.map((e=>{let t=e.idx.split("/"),r={table:t[1],index:t[2],number_of_records:e.cnt_rec};for(let t in i)(null==e?void 0:e[t])&&(r[i[t]]=e[t]),(null==r?void 0:r.number_of_number_values)&&(r.average_of_number_values=e.totl_numb/e.cnt_numb),(null==r?void 0:r.number_of_boolean_values)&&(r.average_of_boolean_values=e.totl_bool/e.cnt_bool);return r}))),n}))}getTag(e,t){return i(this,void 0,void 0,(function*(){let r=yield this.request("get-tag",(0,l.checkParams)(e||{},{table:"string",tag:"string",condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}),Object.assign({auth:!0},{fetchOptions:t}));if(Array.isArray(r.list))for(let e in r.list){let t=r.list[e],n=t.tag.split("/");r.list[e]={table:n[1],tag:n[0],number_of_records:t.cnt_rec}}return r}))}deleteRecords(e){return i(this,void 0,void 0,(function*(){let t=yield this.requireAdmin();if(t&&!(null==e?void 0:e.service))throw new a.default("Service ID is required.",{code:"INVALID_PARAMETER"});if(!t&&!(null==e?void 0:e.table))throw new a.default('"table" is required.',{code:"INVALID_PARAMETER"});if(null==e?void 0:e.record_id)return yield this.request("del-records",{service:e.service,record_id:(e=>{let t=(0,l.checkWhiteSpaceAndSpecialChars)(e,"record_id",!1);return"string"==typeof t?[t]:t})(e.record_id)},{auth:!0});{if(!(null==e?void 0:e.table))throw new a.default('Either "table" or "record_id" is required.',{code:"INVALID_PARAMETER"});let r={access_group:["number","private"],table:{name:"string",subscription:e=>{if(t)return(0,l.validateUserId)(e,'User ID in "table.subscription"');throw new a.default('"table.subscription" is an invalid parameter key.',{code:"INVALID_PARAMETER"})},subscription_group:r=>{var n;if(t&&"string"!=typeof(null===(n=null==e?void 0:e.table)||void 0===n?void 0:n.subscription))throw new a.default('"table.subscription" is required.',{code:"INVALID_PARAMETER"});if("number"==typeof r&&r>0&&r<99)return r;throw new a.default("Subscription group should be between 0 ~ 99.",{code:"INVALID_PARAMETER"})}}};e=(0,l.checkParams)(e||{},r,t?["service"]:["table","access_group"])}return yield this.request("del-records",e,{auth:!0})}))}subscribeNewsletter(e,t){return i(this,void 0,void 0,(function*(){let t=(0,l.checkParams)(e||{},{email:e=>(0,l.validateEmail)(e),bypassWelcome:["boolean",()=>!0]},["email"]);return yield this.request("subscribe-newsletter",t)}))}subscriptionGroupCheck(e){return i(this,void 0,void 0,(function*(){if(yield this.__connection,e=(0,l.checkParams)(e,{user_id:e=>(0,l.validateUserId)(e,'"user_id"'),group:e=>{if("*"===e)return e;if("number"!=typeof e)throw new a.default('"group" should be type: number.',{code:"INVALID_PARAMETER"});if(e<1&&e>9)throw new a.default('"group" should be within range 1 ~ 9.',{code:"INVALID_PARAMETER"});return e}},["user_id","group"]),this.user&&e.user_id===this.user.user_id)throw new a.default('"user_id" cannot be the user\'s own ID.',{code:"INVALID_PARAMETER"});return e}))}subscribe(e){return i(this,void 0,void 0,(function*(){let{user_id:t,group:r}=yield this.subscriptionGroupCheck(e);if("*"===r)throw new a.default("Cannot subscribe to all groups at once.",{code:"INVALID_PARAMETER"});return yield this.request("subscription",{subscribe:t,group:r},{auth:!0})}))}unsubscribe(e){return i(this,void 0,void 0,(function*(){let{user_id:t,group:r}=yield this.subscriptionGroupCheck(e);return yield this.request("subscription",{unsubscribe:t,group:r},{auth:!0})}))}blockSubscriber(e){return i(this,void 0,void 0,(function*(){let{user_id:t,group:r}=yield this.subscriptionGroupCheck(e);return yield this.request("subscription",{block:t,group:r},{auth:!0})}))}unblockSubscriber(e){return i(this,void 0,void 0,(function*(){let{user_id:t,group:r}=yield this.subscriptionGroupCheck(e);return yield this.request("subscription",{unblock:t,group:r},{auth:!0})}))}getUserSubscriptions(e){var t;return i(this,void 0,void 0,(function*(){return yield this.__connection,e=(0,l.checkParams)(e,{user_id:e=>{try{return(0,l.validateUserId)(e,'"user_id"')}catch(e){}try{return(0,l.validateEmail)(e)}catch(e){}throw new a.default('"subscriber" should be either valid user ID or E-Mail.',{code:"INVALID_PARAMETER"})},group:"number"})||{},this.getSubscriptions({subscriber:e.user_id||(null===(t=this.user)||void 0===t?void 0:t.user_id),group:e.group})}))}getUserSubscribers(e){var t;return i(this,void 0,void 0,(function*(){yield this.__connection;let r={subscription:(e=(0,l.checkParams)(e,{user_id:e=>(0,l.validateUserId)(e,'"user_id"'),group:"number"})||{}).user_id||(null===(t=this.user)||void 0===t?void 0:t.user_id),group:e.group};return this.getSubscriptions(r)}))}getSubscriptions(e,t,r){return i(this,void 0,void 0,(function*(){let n=!1;if(e=(0,l.checkParams)(e,{subscriber:e=>{try{return(0,l.validateUserId)(e,'User ID in "subscriber"')}catch(e){}try{let t=(0,l.validateEmail)(e);return n=!0,t}catch(e){}throw new a.default('"subscriber" should be either valid user ID or E-Mail.',{code:"INVALID_PARAMETER"})},group:"number",subscription:e=>{try{return(0,l.validateUserId)(e,'User ID in "subscription"')}catch(e){}if("string"==typeof e&&14===e.length)return e;throw new a.default('"subscriber" should be either valid service ID or user ID.',{code:"INVALID_PARAMETER"})},blocked:"boolean"}),n&&!(null==e?void 0:e.subscription)&&(e.subscription=this.service),!e.subscriber&&!e.subscription)throw new a.default('At least either "subscriber" or "subscription" should have a value.',{code:"INVALID_PARAMETER"});let i=yield this.request("get-subscription",e,Object.assign({auth:!n},{fetchOptions:t}));return i.list=i.list.map(r||(e=>{let t={},r=e.sub.split("#");return t.subscriber=r[2],t.subscription=r[0],t.group=parseInt(r[1]),t.timestamp=e.stmp,t.blocked="N"===e.grp.substring(0,1),t})),i}))}getNewsletters(e,t){return i(this,void 0,void 0,(function*(){let r=yield this.requireAdmin(),n={message_id:"string",timestamp:"number",read:"number",complaint:"number",subject:"string"};e||(t||(t={}),t.ascending=!1);let i=e||{searchFor:"timestamp",value:0,condition:">"};e=(0,l.checkParams)(i,{searchFor:["message_id","timestamp","read","complaint","group","subject"],value:e=>{if(typeof e!==n[i.searchFor])throw new a.default(`"value" type does not match the type of "${i.searchFor}" index.`,{code:"INVALID_PARAMETER"});if("string"==typeof e&&!e)throw new a.default('"value" should not be empty string.',{code:"INVALID_PARAMETER"});return e},range:e=>{if(!i.hasOwnProperty("value")||typeof e!=typeof i.value)throw new a.default('"range" should match type of "value".',{code:"INVALID_PARAMETER"});return e},condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],group:e=>{if("newsletter"!==e&&!this.session)throw new a.default("User should be logged in.",{code:"INVALID_REQUEST"});if("string"==typeof e&&"newsletter"!==e)throw new a.default('Group should be either "newsletter" or access group number.',{code:"INVALID_PARAMETER"});if(!r&&e>parseInt(this.session.idToken.payload.access_group))throw new a.default("User has no access.",{code:"INVALID_REQUEST"});return"newsletter"===e?0:e}},["searchFor","value","group"]);let s=yield this.request(0===e.group?"get-newsletters":"get-serviceletters",e,Object.assign({method:"get",auth:0!==e.group},{fetchOptions:t})),o={message_id:"mid",timestamp:"stmp",complaint:"cmpl",read:"read",subject:"subj",bounced:"bnce",url:"url"},u={message_id:"",timestamp:0,complaint:0,read:0,subject:"",bounced:0,url:""};return s.list=s.list.map((e=>{let t={};for(let r in o)t[r]=e[o[r]]||u[o[r]];return t})),s}))}signup(e,t){return i(this,void 0,void 0,(function*(){this.logout();let r=(0,l.checkParams)(e||{},{email:e=>(0,l.validateEmail)(e),password:e=>(0,l.validatePassword)(e),name:"string",address:"string",gender:"string",birthdate:e=>(0,l.validateBirthdate)(e),phone_number:e=>(0,l.validatePhoneNumber)(e),email_public:["boolean",()=>!1],address_public:["boolean",()=>!1],gender_public:["boolean",()=>!1],birthdate_public:["boolean",()=>!1],phone_number_public:["boolean",()=>!1],email_subscription:["boolean",()=>!1]},["email","password"]);t=(0,l.checkParams)(t||{},{confirmation:e=>{if("string"==typeof e)return(0,l.validateUrl)(e);if("boolean"==typeof e)return e;throw new a.default('"option.confirmation" should be type: <string | boolean>.',{code:"INVALID_PARAMETER"})},login:e=>{if("boolean"==typeof e){if(t.confirmation&&e)throw new a.default('"login" is not allowed when "option.confirmation" is true.',{code:"INVALID_PARAMETER"});return e}throw new a.default('"option.login" should be type: boolean.',{code:"INVALID_PARAMETER"})}});let{login:n=!1,confirmation:i=!1}=t||{};if(!i&&r.email_public)throw new a.default('"option.confirmation" should be true if "email_public" is set to true.',{code:"INVALID_PARAMETER"});return yield this.request("signup",r,{meta:t}),i?"SUCCESS: The account has been created. User's email confirmation is required.":n?yield this.login({email:r.email,password:r.password}):"SUCCESS: The account has been created."}))}logout(){this.cognitoUser&&this.cognitoUser.signOut();let e={session:null,__startKey_keys:{},__cached_requests:{},user:null};for(let t in e)this[t]=e[t];return"SUCCESS: The user has been logged out."}resendSignupConfirmation(e=!1){return i(this,void 0,void 0,(function*(){if(e&&"string"==typeof e)e=(0,l.validateUrl)(e);else if("boolean"!=typeof e)throw new a.default("Argument should be type: <boolean | string>.",{code:"INVALID_REQUEST"});if(!this.__request_signup_confirmation)throw new a.default("Least one signin attempt is required.",{code:"INVALID_REQUEST"});let t=yield this.request("confirm-signup",{username:this.__request_signup_confirmation,redirect:e});return this.__request_signup_confirmation=null,t}))}recoverAccount(e=!1){return i(this,void 0,void 0,(function*(){if("string"==typeof e)(0,l.validateUrl)(e);else if("boolean"!=typeof e)throw new a.default("Argument should be type: <boolean | string>.",{code:"INVALID_REQUEST"});if(!this.__disabledAccount)throw new a.default("Least one signin attempt of disabled account is required.",{code:"INVALID_REQUEST"});let t=yield this.request("recover-account",{username:this.__disabledAccount,redirect:e});return this.__disabledAccount=null,t}))}login(e,t){this.logout();let r=(0,l.checkParams)(e,{email:e=>(0,l.validateEmail)(e),password:e=>(0,l.validatePassword)(e)},["email","password"]);return this.authentication().authenticateUser(r.email,r.password)}verifyAttribute(e,t){if(!this.cognitoUser)throw new a.default("The user has to be logged in.",{code:"INVALID_REQUEST"});return new Promise(((r,n)=>{var i,s;let o={onSuccess:i=>{t?this.authentication().updateSession({refreshToken:!0}).then((()=>{this.user&&(this.user[e+"_verified"]=!0),r(`SUCCESS: "${e}" is verified.`)})).catch((e=>{n(e)})):r("SUCCESS: Verification code has been sent.")},onFailure:e=>{n(new a.default(e.message||"Failed to request verification code.",{code:null==e?void 0:e.code}))},inputVerificationCode:null};t?null===(i=this.cognitoUser)||void 0===i||i.verifyAttribute(e,t,o):null===(s=this.cognitoUser)||void 0===s||s.getAttributeVerificationCode(e,o)}))}verifyEmail(e,t){let r=(e?(0,l.checkParams)(e,{code:["number","string"]}):{}).code||"";return this.verifyAttribute("email",r.toString())}verifyMobile(e,t){let r=(e?(0,l.checkParams)(e,{code:["number","string"]}):{}).code||null;return this.verifyAttribute("phone_number",r.toString())}forgotPassword(e,t){return i(this,void 0,void 0,(function*(){yield this.__connection;let t=(0,l.checkParams)(e,{email:e=>(0,l.validateEmail)(e)},["email"]);return new Promise(((e,r)=>i(this,void 0,void 0,(function*(){(yield this.authentication().createCognitoUser(t.email)).cognitoUser.forgotPassword({onSuccess:t=>{e("SUCCESS: Verification code has been sent.")},onFailure:e=>{r(new a.default((null==e?void 0:e.message)||"Failed to send verification code.",{code:(null==e?void 0:e.code)||"ERROR"}))}})}))))}))}resetPassword(e,t){let r=(0,l.checkParams)(e,{email:e=>(0,l.validateEmail)(e),code:["number","string"],new_password:e=>(0,l.validatePassword)(e)},["email","code","new_password"]),n=r.code,s=r.new_password;return"number"==typeof n&&(n=n.toString()),new Promise(((e,t)=>i(this,void 0,void 0,(function*(){(yield this.authentication().createCognitoUser(r.email)).cognitoUser.confirmPassword(n,s,{onSuccess:t=>{e("SUCCESS: New password has been set.")},onFailure:e=>{t(new a.default((null==e?void 0:e.message)||"Failed to reset password.",{code:null==e?void 0:e.code}))}})}))))}disableAccount(){return i(this,void 0,void 0,(function*(){if(yield this.__connection,this.user&&Array.isArray(this.user.services))for(let e of this.user.services)if(e.active)throw new a.default("All services needs to be disabled.",{code:"INVALID_REQUEST"});let e=yield this.request("remove-account",{disable:!0},{auth:!0});return this.logout(),e}))}updateUserSettings(e,t){var r;return i(this,void 0,void 0,(function*(){yield this.__connection;let t=null===(r=this.session)||void 0===r?void 0:r.attributes;if(!t||!this.cognitoUser)throw new a.default("User has to be logged in.",{code:"INVALID_REQUEST"});let n=(0,l.checkParams)(e||{},{email:e=>(0,l.validateEmail)(e),name:"string",address:"string",gender:"string",birthdate:e=>(0,l.validateBirthdate)(e),phone_number:e=>(0,l.validatePhoneNumber)(e),email_public:"boolean",phone_number_public:"boolean",address_public:"boolean",gender_public:"boolean",birthdate_public:"boolean",email_subscription:"boolean",current_password:e=>(0,l.validatePassword)(e),new_password:e=>(0,l.validatePassword)(e)});if(n&&"object"==typeof n&&!Object.keys(n).length)return this.user;if(n.new_password||n.current_password){if(!n.current_password)throw new a.default('"current_password" is needed to change the password.',{code:"INVALID_PARAMETER"});if(!n.new_password)throw new a.default('"new_password" is needed to change password.',{code:"INVALID_PARAMETER"});n.new_password!==n.current_password&&(yield new Promise(((e,t)=>{this.cognitoUser.changePassword(n.current_password,n.new_password,((r,n)=>{r&&t(new a.default((null==r?void 0:r.message)||"Failed to change users password.",{code:(null==r?void 0:r.code)||(null==r?void 0:r.name)})),e(n)}))}))),delete n.current_password,delete n.new_password}if(n.email){let e=yield this.updateConnection({request_hash:n.email});n.preferred_username=e.hash}let i=[["email_subscription","email_verified","User's E-Mail should be verified to set"],["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 e of i)if(n[e[0]]&&!this.user[e[1]])throw new a.default(`${e[2]} "${e[0]}" to true.`,{code:"INVALID_PARAMETER"});let s=["email_public","phone_number_public","address_public","gender_public","birthdate_public","email_subscription"];for(let e in n)if(n[e]===t[e])delete n[e];else if(s.includes(e)){let t=n[e];"boolean"==typeof t&&(t=t?"1":"0"),n["custom:"+e]=t,delete n[e]}if(n&&"object"==typeof n&&Object.keys(n).length){let e=[];for(let t in n)e.push(new o.CognitoUserAttribute({Name:t,Value:n[t]}));yield new Promise(((t,r)=>{var n;null===(n=this.cognitoUser)||void 0===n||n.updateAttributes(e,((e,n)=>{e&&r([(null==e?void 0:e.code)||(null==e?void 0:e.name),(null==e?void 0:e.message)||"Failed to update user settings."]),t(n)}))})),yield this.authentication().updateSession({refreshToken:!0})}return this.user}))}uploadUserData(e,t){return i(this,void 0,void 0,(function*(){let r={auth:!0};return(t=(0,l.checkParams)(t||{},{private:"array"})).private&&Object.assign(r,{meta:{__private__:t.private}}),yield this.request("post-userdata",e,r),yield this.authentication().updateSession(),this.user}))}getUsers(e,t){return i(this,void 0,void 0,(function*(){let r=yield this.requireAdmin({ignoreVerification:!0});e||(t||(t={}),t.ascending=!1),e=e||{searchFor:"timestamp",condition:">",value:0};const n={user_id:e=>(0,l.validateUserId)(e),name:"string",email:e=>(0,l.validateEmail)(e),phone_number:e=>(0,l.validatePhoneNumber)(e),address:"string",gender:"string",birthdate:e=>(0,l.validateBirthdate)(e),locale:e=>{if("string"!=typeof e||"string"==typeof e&&e.length>5)throw new a.default('Value of "locale" should be a country code.');return e},subscribers:"number",timestamp:"number",group:"number",email_subscription:e=>{if(!r)throw new a.default('Only admin is allowed to search "email_subscription".',{code:"INVALID_REQUEST"});return e},blocked:e=>e?"by_admin:suspended":"by_admin:approved"};if((null==(e=(0,l.checkParams)(e,{searchFor:["user_id","name","email","phone_number","address","gender","birthdate","locale","subscribers","timestamp","group","email_subscription","blocked"],condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],value:t=>{let r=n[e.searchFor];if("function"==typeof r)return r(t);if(typeof t!==r)throw new a.default(`Value does not match the type of "${e.searchFor}" index.`,{code:"INVALID_PARAMETER"});return t},range:t=>{let r=n[e.searchFor];if("function"==typeof r)return r(t);if(typeof t!==r)throw new a.default(`Range does not match the type of "${e.searchFor}" index.`,{code:"INVALID_PARAMETER"});return t}},["searchFor","value"]))?void 0:e.condition)&&"="!==(null==e?void 0:e.condition)&&e.hasOwnProperty("range"))throw new a.default("Conditions does not apply on range search.",{code:"INVALID_PARAMETER"});if(["user_id","blocked"].includes(e.searchFor)&&"="!==e.condition)throw new a.default(`Condition is not allowed on "${e.searchFor}"`,{code:"INVALID_PARAMETER"});if("blocked"===e.searchFor&&(e.searchFor="suspended"),"string"==typeof(null==e?void 0:e.value)&&!(null==e?void 0:e.value))throw new a.default("Value should not be an empty string.",{code:"INVALID_PARAMETER"});if("string"==typeof(null==e?void 0:e.searchFor)&&!(null==e?void 0:e.searchFor))throw new a.default('"searchFor" should not be an empty string.',{code:"INVALID_PARAMETER"});let i="user_id"===e.searchFor&&e.value===this.session.idToken.payload.sub;if(r&&!i&&!e.service)throw new a.default("Service ID is required.",{code:"INVALID_PARAMETER"});let s=yield this.request("get-users",e,{auth:!0,fetchOptions:t});if(!s.list[0]||!i||s.list.length>1)return s;let o=s.list[0];Object.assign(o,this.user),o._what_public_see=JSON.parse(JSON.stringify(o));let u=["service","user_id","name","locale","address","birthdate","phone_number","email","gender","subscribers","timestamp","group","log","user_data"];for(let e in o._what_public_see)u.includes(e)||delete o._what_public_see[e];return o}))}updateConnection(e){return i(this,void 0,void 0,(function*(){let t=null,r={};(null==e?void 0:e.request_hash)&&(this.__serviceHash[e.request_hash]?Object.assign(r,{hash:this.__serviceHash[e.request_hash]}):t={request_hash:(0,l.validateEmail)(e.request_hash)}),this.connection&&this.connection.service===this.service&&!t||(null===t&&(t={}),Object.assign(t,{service:this.service,service_owner:this.service_owner})),Object.assign(r,t?yield this.request("service",t,{bypassAwaitConnection:!0}):this.connection),(null==e?void 0:e.request_hash)&&(this.__serviceHash[e.request_hash]=r.hash);let n=JSON.parse(JSON.stringify(r));return delete n.hash,this.connection=n,r}))}}n([(0,u.formResponse)()],c.prototype,"postRecord",null),n([(0,u.formResponse)()],c.prototype,"subscribeNewsletter",null),n([(0,u.formResponse)()],c.prototype,"subscribe",null),n([(0,u.formResponse)()],c.prototype,"unsubscribe",null),n([(0,u.formResponse)()],c.prototype,"blockSubscriber",null),n([(0,u.formResponse)()],c.prototype,"unblockSubscriber",null),n([(0,u.formResponse)()],c.prototype,"signup",null),n([(0,u.formResponse)()],c.prototype,"login",null),n([(0,u.formResponse)()],c.prototype,"verifyEmail",null),n([(0,u.formResponse)()],c.prototype,"verifyMobile",null),n([(0,u.formResponse)()],c.prototype,"forgotPassword",null),n([(0,u.formResponse)()],c.prototype,"resetPassword",null),n([(0,u.formResponse)()],c.prototype,"updateUserSettings",null),n([(0,u.formResponse)()],c.prototype,"uploadUserData",null),t.default=c},246:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});class r extends Error{constructor(e,t){e instanceof Error?(super(e.message||"Something went wrong."),this.cause=e,this.name=e.name,e.hasOwnProperty("code")&&(this.code=e.code)):"string"==typeof e&&(super(e||"Something went wrong."),this.name="SkapiError",this.code="ERROR",t&&(t.code&&(this.code=t.code),t.cause&&(this.cause=t.cause)))}}t.default=r},170:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.sha256=t.validateUrl=t.validatePhoneNumber=t.validatePassword=t.validateEmail=t.validateBirthdate=t.validateUserId=t.extractFormMetaData=t.checkParams=t.normalize_record_data=t.checkWhiteSpaceAndSpecialChars=void 0;const i=n(r(246)),s=function(e){function t(e,t){return e>>>t|e<<32-t}for(var r,n,i=Math.pow,o=i(2,32),a="",u=[],l=8*e.length,c=s.h=s.h||[],h=s.k=s.k||[],f=h.length,d={},p=2;f<64;p++)if(!d[p]){for(r=0;r<313;r+=p)d[r]=p;c[f]=i(p,.5)*o|0,h[f++]=i(p,1/3)*o|0}for(e+="";e.length%64-56;)e+="\0";for(r=0;r<e.length;r++){if((n=e.charCodeAt(r))>>8)return;u[r>>2]|=n<<(3-r)%4*8}for(u[u.length]=l/o|0,u[u.length]=l,n=0;n<u.length;){var g=u.slice(n,n+=16),v=c;for(c=c.slice(0,8),r=0;r<64;r++){var y=g[r-15],m=g[r-2],w=c[0],_=c[4],A=c[7]+(t(_,6)^t(_,11)^t(_,25))+(_&c[5]^~_&c[6])+h[r]+(g[r]=r<16?g[r]:g[r-16]+(t(y,7)^t(y,18)^y>>>3)+g[r-7]+(t(m,17)^t(m,19)^m>>>10)|0);(c=[A+((t(w,2)^t(w,13)^t(w,22))+(w&c[1]^w&c[2]^c[1]&c[2]))|0].concat(c))[4]=c[4]+A|0}for(r=0;r<8;r++)c[r]=c[r]+v[r]|0}for(r=0;r<8;r++)for(n=3;n+1;n--){var b=c[r]>>8*n&255;a+=(b<16?0:"")+b.toString(16)}return a};function o(e){function t(e,t,r,n=!0){e[t]&&n?Array.isArray(e)?e[t].push(r):e[t]=[e[t],r]:e[t]=r}if(e instanceof FormData){let r={},n=0,s=[];for(let i of e.entries()){let e=i[0],o=i[1];if(o instanceof File)s.includes(e)||s.push(e),n+=Math.round(o.size/1024);else if(o instanceof FileList){if(s.includes(e)||s.push(e),o&&o.length>0)for(let e=0;e<=o.length-1;e++)n+=Math.round(o.item(e).size/1024)}else t(r,e,o)}if(n>5120)throw new i.default("Files cannot exceed 5MB. Use skapi.uploadFiles(...) instead.",{code:"INVALID_REQUEST"});return{meta:r,files:s}}if(e instanceof HTMLFormElement){let r={},n=[],s=0,o=e.querySelectorAll("input"),a=e.querySelectorAll("textarea");for(let e of a)e.name&&t(r,e.name,e.value);for(let e of o)if(e.name)if("number"===e.type&&e.value)t(r,e.name,Number(e.value));else if("checkbox"===e.type||"radio"===e.type)"on"===e.value||"true"===e.value?t(r,e.name,e.checked,!1):"false"===e.value?t(r,e.name,!e.checked,!1):e.checked&&t(r,e.name,e.value,!1);else if("file"===e.type){if(n.includes(e.name)||n.push(e.name),e.files&&e.files.length>0)for(let t=0;t<=e.files.length-1;t++)s+=Math.round(e.files.item(t).size/1024)}else t(r,e.name,e.value);if(s>5120)throw new i.default("Files cannot exceed 5MB. Use skapi.uploadFiles(...) instead.",{code:"INVALID_REQUEST"});return{meta:r,files:n}}return null}t.sha256=s,t.checkParams=function e(t,r,n=null,s=[],a=null){var u;function l(e){if(e instanceof Promise)throw new i.default("Parameter should not be a promise",{code:"INVALID_PARAMETER"});return e&&"object"==typeof e&&!Array.isArray(e)&&Object.keys(e).length}Array.isArray(s)&&(s=s.concat(["service","service_owner"]));let c,h=t,f=null,d=a?` in "${a}" is invalid.`:". Parameter should be type <object>.";if(null===a){if(l(h)){h=h instanceof HTMLFormElement||h instanceof FormData?null===(u=o(t))||void 0===u?void 0:u.meta:JSON.parse(JSON.stringify(t));for(let e in h)if(!r.hasOwnProperty(e)&&Array.isArray(s)&&!s.includes(e))throw new i.default(`Key name "${e}" is invalid in parameter.`,{code:"INVALID_PARAMETER"});if(Array.isArray(n)&&n.length)for(let e of n)if(!Object.keys(h).includes(e))throw new i.default(`Key "${e}" is required in parameter.`,{code:"INVALID_PARAMETER"})}else if((p=h)&&"object"==typeof p&&!Array.isArray(p)&&!Object.keys(p).length||void 0===h){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:h}if(null===h)return null}var p;if(l(r)&&l(h)){for(let t in r){let n=r[t];if(h.hasOwnProperty(t)&&void 0!==h[t])h[t]=e(h[t],n,null,null,t);else{let e=Array.isArray(n)&&"function"==typeof n[n.length-1]?n[n.length-1]:null;if(e){let r=e();void 0!==r&&(h[t]=r)}}}c=h}else if(Array.isArray(r))for(let t of r)try{void 0!==typeof h&&"function"!=typeof t&&(c=e(h,t,null,null,a));break}catch(e){if("string"==typeof e&&"BREAK:"===e.substring(0,6)){let t=(e=e.substring(5)).split(":");f=new i.default(t[1],{code:t[0]});break}f=e}else{if("function"==typeof r)return r(h);if("string"==typeof r)if(Array.isArray(h)){if("array"!==r)throw new i.default(`Invalid type "${typeof h}"${d}`,{code:"INVALID_PARAMETER"});for(let e of h)if(!["number","string","boolean"].includes(typeof e)&&null!==e)throw new i.default(`Invalid type "${typeof e}" in "${a}" array value.`,{code:"INVALID_PARAMETER"});c=h}else if(["number","string","boolean","array","function"].includes(r)){if(typeof h===r){if("number"===r&&Math.abs(h)>4503599627370496)throw`BREAK:INVALID_PARAMETER:"${a}" integer value should be within -4503599627370496 ~ +4503599627370546.`;c=h}}else{if(h!==r)throw new i.default(`Value: ${h}${d}`,{code:"INVALID_PARAMETER"});c=h}else null===r&&(c=h)}if(void 0===c&&f)throw f;return c},t.extractFormMetaData=o,t.validateUserId=function(e,t="User ID"){if(!e)throw new i.default(`${t} is empty.`,{code:"INVALID_PARAMETER"});if("string"!=typeof e)throw new i.default(`${t} should be type: string.`,{code:"INVALID_PARAMETER"});if(!e.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 i.default(`${t} is invalid.`,{code:"INVALID_PARAMETER"});return e},t.validatePhoneNumber=function(e){if("string"!=typeof e||"+"!==e.charAt(0)||isNaN(Number(e.substring(1))))throw new i.default('"phone_number" is invalid. The format should be "+00123456789". Type: string.',{code:"INVALID_PARAMETER"});return e},t.validateBirthdate=function(e){if("string"!=typeof e)throw new i.default('"birthdate" is invalid. The format should be "yyyy-mm-dd". Type: string.',{code:"INVALID_PARAMETER"});{let t=new RegExp(/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/);if(10!==e.length||3!==e.split("-").length||!t.test(e))throw new i.default('"birthdate" is invalid. The format should be "yyyy-mm-dd". Type: string.',{code:"INVALID_PARAMETER"})}return e},t.validatePassword=function(e){if(!e)throw new i.default('"password" is empty.',{code:"PASSWORD_REQUIRED"});if("string"!=typeof e)throw new i.default('"password" should be type: string.',{code:"INVALID_PASSWORD"});if(e.length<6)throw new i.default('"password" should be at least 6 characters.',{code:"INVALID_PASSWORD"});if(e.length>60)throw new i.default('"password" can be up to 60 characters max.',{code:"INVALID_PASSWORD"});return e},t.validateEmail=function(e,t="email"){if(!e)throw new i.default(`"${t}" is empty.`,{code:"EMAIL_REQUIRED"});if("string"!=typeof e)throw new i.default(`"${t}"should be type: string.`,{code:"INVALID_EMAIL"});if(e.length<5||e.length>64)throw new i.default(`"${t}" should be at least 5 characters and max 64 characters.`,{code:"INVALID_EMAIL"});if(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(e)&&(e=e.trim()).split("@")[1].split(".").length>=2)return e.toLowerCase();throw new i.default(`"${e}" is an invalid email.`,{code:"INVALID_EMAIL"})},t.validateUrl=function(e){const t=(()=>{var e;let t=(null===(e=null===window||void 0===window?void 0:window.location)||void 0===e?void 0:e.origin)||null;if("file://"===t){t+=window.location.pathname;let e=t.split("/");e.pop(),t=e.join("/")}return t})();let r=e=>{if("string"==typeof e){if("*"===e)return"*";{let r=e.trim();if(!r.includes(" ")&&!r.includes(",")){"/"===r.substring(0,1)&&t&&(r=t+r);let n=null;try{n=new URL(r)}catch(t){throw new i.default(`"${e}" is an invalid url.`,{code:"INVALID_PARAMETER"})}if(n.protocol){let e=n.href;return"/"===e.charAt(e.length-1)&&(e=e.substring(0,e.length-1)),e}}}}throw new i.default(`"${e}" is an invalid url.`,{code:"INVALID_PARAMETER"})};return Array.isArray(e)?e.map((e=>r(e))):r(e)},t.normalize_record_data=function(e){const t={},r={rec:e=>{if(!e)return;t.record_id=e;let r=e.substring(0,8);t.uploaded=parseInt(r,36)},usr:e=>{e&&(t.user_id=e)},tbl:e=>{if(!e)return;let r=e.split("/");t.table=r[0],t.access_group="@@"==r[2]?"private":parseInt(r[2]),(null==r?void 0:r[3])&&(t.subscription={user_id:r[3],group:parseInt(r[4])})},idx:e=>{if(!e)return;let r=e.split("!"),n=r.splice(0,1)[0],s=function(e){let t=e.substring(2);switch(e.substring(0,2)){case"S%":return t;case"N%":return Number(t)-4503599627370496;case"B%":return"1"===t;case"L%":try{return JSON.parse(t)}catch(e){throw new i.default("Value parse error.",{code:"PARSE_ERROR"})}default:return e}}(r.join("!"));t.index={name:n,value:s}},ref:e=>{e&&(t.reference=e.split("/")[0])},tags:e=>{e&&(t.tags=e)},upd:e=>{e&&(t.updated=e)},acpt_mrf:e=>{e&&((null==t?void 0:t.config)||(t.config={}),t.config.allow_multiple_reference=e)},ref_limt:e=>{e&&((null==t?void 0:t.config)||(t.config={}),t.config.reference_limit=e)},rfd:e=>{t.referenced_count=e},prv_acs:e=>{e&&((null==t?void 0:t.config)||(t.config={}),t.config.private_access=e)},data:e=>{let r=e;"!D%{}"===e?r={}:"!L%[]"===e&&(r=[]),t.data=r}};if(e.record_id)return e;for(let t in r)r[t](e[t]);return t},t.checkWhiteSpaceAndSpecialChars=function(e,t="parameter",r=!1,n=!1){let s=(s,o=!1)=>{if("string"!=typeof s)throw new i.default(`${t} should be type: <string | string[]>.`,{code:"INVALID_PARAMETER"});if(!n&&e.includes(" "))throw new i.default(`${t} should not have whitespace.`,{code:"INVALID_PARAMETER"});if(!r&&e.includes("."))throw new i.default(`${t} should not have periods.`,{code:"INVALID_PARAMETER"});if(/[`!@#$%^&*()_+\-=\[\]{};':"\\|,<>\/?~]/.test(s))throw new i.default(`${t} should not have special characters.`,{code:"INVALID_PARAMETER"})};if(Array.isArray(e))for(let t of e)s(t,!0);else s(e,!1);return e}},243:(e,t,r)=>{"use strict";r.r(t),r.d(t,{AuthenticationDetails:()=>i,AuthenticationHelper:()=>T,CognitoAccessToken:()=>k,CognitoIdToken:()=>O,CognitoRefreshToken:()=>M,CognitoUser:()=>$,CognitoUserAttribute:()=>K,CognitoUserPool:()=>ue,CognitoUserSession:()=>V,CookieStorage:()=>ce,DateHelper:()=>q,WordArray:()=>d,appendToCognitoUserAgent:()=>Q});var n,i=function(){function e(e){var t=e||{},r=t.ValidationData,n=t.Username,i=t.Password,s=t.AuthParameters,o=t.ClientMetadata;this.validationData=r||{},this.authParameters=s||{},this.clientMetadata=o||{},this.username=n,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}(),s=r(764),o=r(249),a=r.n(o),u=(r(433),r(153)),l=r.n(u),c=r(10),h=r.n(c);if("undefined"!=typeof window&&window.crypto&&(n=window.crypto),!n&&"undefined"!=typeof window&&window.msCrypto&&(n=window.msCrypto),!n&&void 0!==r.g&&r.g.crypto&&(n=r.g.crypto),!n)try{n=r(296)}catch(e){}function f(){if(n){if("function"==typeof n.getRandomValues)try{return n.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof n.randomBytes)try{return n.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")}var d=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 r=[],n=0;n<t;n+=4)r.push(f());return new e(r,t)},t.toString=function(){return function(e){for(var t=e.words,r=e.sigBytes,n=[],i=0;i<r;i++){var s=t[i>>>2]>>>24-i%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")}(this)},e}();const p=g;function g(e,t){null!=e&&this.fromString(e,t)}function v(){return new g(null)}var y,m="undefined"!=typeof navigator;m&&"Microsoft Internet Explorer"==navigator.appName?(g.prototype.am=function(e,t,r,n,i,s){for(var o=32767&t,a=t>>15;--s>=0;){var u=32767&this[e],l=this[e++]>>15,c=a*u+l*o;i=((u=o*u+((32767&c)<<15)+r[n]+(1073741823&i))>>>30)+(c>>>15)+a*l+(i>>>30),r[n++]=1073741823&u}return i},y=30):m&&"Netscape"!=navigator.appName?(g.prototype.am=function(e,t,r,n,i,s){for(;--s>=0;){var o=t*this[e++]+r[n]+i;i=Math.floor(o/67108864),r[n++]=67108863&o}return i},y=26):(g.prototype.am=function(e,t,r,n,i,s){for(var o=16383&t,a=t>>14;--s>=0;){var u=16383&this[e],l=this[e++]>>14,c=a*u+l*o;i=((u=o*u+((16383&c)<<14)+r[n]+i)>>28)+(c>>14)+a*l,r[n++]=268435455&u}return i},y=28),g.prototype.DB=y,g.prototype.DM=(1<<y)-1,g.prototype.DV=1<<y,g.prototype.FV=Math.pow(2,52),g.prototype.F1=52-y,g.prototype.F2=2*y-52;var w,_,A=new Array;for(w="0".charCodeAt(0),_=0;_<=9;++_)A[w++]=_;for(w="a".charCodeAt(0),_=10;_<36;++_)A[w++]=_;for(w="A".charCodeAt(0),_=10;_<36;++_)A[w++]=_;function b(e){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(e)}function S(e,t){var r=A[e.charCodeAt(t)];return null==r?-1:r}function E(e){var t=v();return t.fromInt(e),t}function I(e){var t,r=1;return 0!=(t=e>>>16)&&(e=t,r+=16),0!=(t=e>>8)&&(e=t,r+=8),0!=(t=e>>4)&&(e=t,r+=4),0!=(t=e>>2)&&(e=t,r+=2),0!=(t=e>>1)&&(e=t,r+=1),r}function U(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 R(e){return s.lW.from((new d).random(e).toString(),"hex")}U.prototype.convert=function(e){var t=v();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(g.ZERO)>0&&this.m.subTo(t,t),t},U.prototype.revert=function(e){var t=v();return e.copyTo(t),this.reduce(t),t},U.prototype.reduce=function(e){for(;e.t<=this.mt2;)e[e.t++]=0;for(var t=0;t<this.m.t;++t){var r=32767&e[t],n=r*this.mpl+((r*this.mph+(e[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(e[r=t+this.m.t]+=this.m.am(0,n,e,t,0,this.m.t);e[r]>=e.DV;)e[r]-=e.DV,e[++r]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)},U.prototype.mulTo=function(e,t,r){e.multiplyTo(t,r),this.reduce(r)},U.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},g.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},g.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},g.prototype.fromString=function(e,t){var r;if(16==t)r=4;else if(8==t)r=3;else if(2==t)r=1;else if(32==t)r=5;else{if(4!=t)throw new Error("Only radix 2, 4, 8, 16, 32 are supported");r=2}this.t=0,this.s=0;for(var n=e.length,i=!1,s=0;--n>=0;){var o=S(e,n);o<0?"-"==e.charAt(n)&&(i=!0):(i=!1,0==s?this[this.t++]=o:s+r>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+=r)>=this.DB&&(s-=this.DB))}this.clamp(),i&&g.ZERO.subTo(this,this)},g.prototype.clamp=function(){for(var e=this.s&this.DM;this.t>0&&this[this.t-1]==e;)--this.t},g.prototype.dlShiftTo=function(e,t){var r;for(r=this.t-1;r>=0;--r)t[r+e]=this[r];for(r=e-1;r>=0;--r)t[r]=0;t.t=this.t+e,t.s=this.s},g.prototype.drShiftTo=function(e,t){for(var r=e;r<this.t;++r)t[r-e]=this[r];t.t=Math.max(this.t-e,0),t.s=this.s},g.prototype.lShiftTo=function(e,t){var r,n=e%this.DB,i=this.DB-n,s=(1<<i)-1,o=Math.floor(e/this.DB),a=this.s<<n&this.DM;for(r=this.t-1;r>=0;--r)t[r+o+1]=this[r]>>i|a,a=(this[r]&s)<<n;for(r=o-1;r>=0;--r)t[r]=0;t[o]=a,t.t=this.t+o+1,t.s=this.s,t.clamp()},g.prototype.rShiftTo=function(e,t){t.s=this.s;var r=Math.floor(e/this.DB);if(r>=this.t)t.t=0;else{var n=e%this.DB,i=this.DB-n,s=(1<<n)-1;t[0]=this[r]>>n;for(var o=r+1;o<this.t;++o)t[o-r-1]|=(this[o]&s)<<i,t[o-r]=this[o]>>n;n>0&&(t[this.t-r-1]|=(this.s&s)<<i),t.t=this.t-r,t.clamp()}},g.prototype.subTo=function(e,t){for(var r=0,n=0,i=Math.min(e.t,this.t);r<i;)n+=this[r]-e[r],t[r++]=n&this.DM,n>>=this.DB;if(e.t<this.t){for(n-=e.s;r<this.t;)n+=this[r],t[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<e.t;)n-=e[r],t[r++]=n&this.DM,n>>=this.DB;n-=e.s}t.s=n<0?-1:0,n<-1?t[r++]=this.DV+n:n>0&&(t[r++]=n),t.t=r,t.clamp()},g.prototype.multiplyTo=function(e,t){var r=this.abs(),n=e.abs(),i=r.t;for(t.t=i+n.t;--i>=0;)t[i]=0;for(i=0;i<n.t;++i)t[i+r.t]=r.am(0,n[i],t,i,0,r.t);t.s=0,t.clamp(),this.s!=e.s&&g.ZERO.subTo(t,t)},g.prototype.squareTo=function(e){for(var t=this.abs(),r=e.t=2*t.t;--r>=0;)e[r]=0;for(r=0;r<t.t-1;++r){var n=t.am(r,t[r],e,2*r,0,1);(e[r+t.t]+=t.am(r+1,2*t[r],e,2*r+1,n,t.t-r-1))>=t.DV&&(e[r+t.t]-=t.DV,e[r+t.t+1]=1)}e.t>0&&(e[e.t-1]+=t.am(r,t[r],e,2*r,0,1)),e.s=0,e.clamp()},g.prototype.divRemTo=function(e,t,r){var n=e.abs();if(!(n.t<=0)){var i=this.abs();if(i.t<n.t)return null!=t&&t.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=v());var s=v(),o=this.s,a=e.s,u=this.DB-I(n[n.t-1]);u>0?(n.lShiftTo(u,s),i.lShiftTo(u,r)):(n.copyTo(s),i.copyTo(r));var l=s.t,c=s[l-1];if(0!=c){var h=c*(1<<this.F1)+(l>1?s[l-2]>>this.F2:0),f=this.FV/h,d=(1<<this.F1)/h,p=1<<this.F2,y=r.t,m=y-l,w=null==t?v():t;for(s.dlShiftTo(m,w),r.compareTo(w)>=0&&(r[r.t++]=1,r.subTo(w,r)),g.ONE.dlShiftTo(l,w),w.subTo(s,s);s.t<l;)s[s.t++]=0;for(;--m>=0;){var _=r[--y]==c?this.DM:Math.floor(r[y]*f+(r[y-1]+p)*d);if((r[y]+=s.am(0,_,r,m,0,l))<_)for(s.dlShiftTo(m,w),r.subTo(w,r);r[y]<--_;)r.subTo(w,r)}null!=t&&(r.drShiftTo(l,t),o!=a&&g.ZERO.subTo(t,t)),r.t=l,r.clamp(),u>0&&r.rShiftTo(u,r),o<0&&g.ZERO.subTo(r,r)}}},g.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},g.prototype.addTo=function(e,t){for(var r=0,n=0,i=Math.min(e.t,this.t);r<i;)n+=this[r]+e[r],t[r++]=n&this.DM,n>>=this.DB;if(e.t<this.t){for(n+=e.s;r<this.t;)n+=this[r],t[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<e.t;)n+=e[r],t[r++]=n&this.DM,n>>=this.DB;n+=e.s}t.s=n<0?-1:0,n>0?t[r++]=n:n<-1&&(t[r++]=this.DV+n),t.t=r,t.clamp()},g.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 r,n=(1<<t)-1,i=!1,s="",o=this.t,a=this.DB-o*this.DB%t;if(o-- >0)for(a<this.DB&&(r=this[o]>>a)>0&&(i=!0,s=b(r));o>=0;)a<t?(r=(this[o]&(1<<a)-1)<<t-a,r|=this[--o]>>(a+=this.DB-t)):(r=this[o]>>(a-=t)&n,a<=0&&(a+=this.DB,--o)),r>0&&(i=!0),i&&(s+=b(r));return i?s:"0"},g.prototype.negate=function(){var e=v();return g.ZERO.subTo(this,e),e},g.prototype.abs=function(){return this.s<0?this.negate():this},g.prototype.compareTo=function(e){var t=this.s-e.s;if(0!=t)return t;var r=this.t;if(0!=(t=r-e.t))return this.s<0?-t:t;for(;--r>=0;)if(0!=(t=this[r]-e[r]))return t;return 0},g.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+I(this[this.t-1]^this.s&this.DM)},g.prototype.mod=function(e){var t=v();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(g.ZERO)>0&&e.subTo(t,t),t},g.prototype.equals=function(e){return 0==this.compareTo(e)},g.prototype.add=function(e){var t=v();return this.addTo(e,t),t},g.prototype.subtract=function(e){var t=v();return this.subTo(e,t),t},g.prototype.multiply=function(e){var t=v();return this.multiplyTo(e,t),t},g.prototype.divide=function(e){var t=v();return this.divRemTo(e,t,null),t},g.prototype.modPow=function(e,t,r){var n,i=e.bitLength(),s=E(1),o=new U(t);if(i<=0)return s;n=i<18?1:i<48?3:i<144?4:i<768?5:6;var a=new Array,u=3,l=n-1,c=(1<<n)-1;if(a[1]=o.convert(this),n>1){var h=v();for(o.sqrTo(a[1],h);u<=c;)a[u]=v(),o.mulTo(h,a[u-2],a[u]),u+=2}var f,d,p=e.t-1,g=!0,y=v();for(i=I(e[p])-1;p>=0;){for(i>=l?f=e[p]>>i-l&c:(f=(e[p]&(1<<i+1)-1)<<l-i,p>0&&(f|=e[p-1]>>this.DB+i-l)),u=n;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,y),o.sqrTo(y,s),u-=2;u>0?o.sqrTo(s,y):(d=s,s=y,y=d),o.mulTo(y,a[f],s)}for(;p>=0&&0==(e[p]&1<<i);)o.sqrTo(s,y),d=s,s=y,y=d,--i<0&&(i=this.DB-1,--p)}var m=o.revert(s);return r(null,m),m},g.ZERO=E(0),g.ONE=E(1);var D=/^[89a-f]/i,T=function(){function e(e){this.N=new p("FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF",16),this.g=new p("2",16),this.k=new p(this.hexHash(""+this.padHex(this.N)+this.padHex(this.g)),16),this.smallAValue=this.generateRandomSmallA(),this.getLargeAValue((function(){})),this.infoBits=s.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(r,n){r&&e(r,null),t.largeAValue=n,e(null,t.largeAValue)}))},t.generateRandomSmallA=function(){var e=R(128).toString("hex");return new p(e,16)},t.generateRandomString=function(){return R(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,r){var n=this;this.randomPassword=this.generateRandomString();var i=""+e+t+":"+this.randomPassword,s=this.hash(i),o=R(16).toString("hex");this.SaltToHashDevices=this.padHex(new p(o,16)),this.g.modPow(new p(this.hexHash(this.SaltToHashDevices+s),16),this.N,(function(e,t){e&&r(e,null),n.verifierDevices=n.padHex(t),r(null,null)}))},t.calculateA=function(e,t){var r=this;this.g.modPow(e,this.N,(function(e,n){e&&t(e,null),n.mod(r.N).equals(p.ZERO)&&t(new Error("Illegal paramater. A mod N cannot be 0."),null),t(null,n)}))},t.calculateU=function(e,t){return this.UHexHash=this.hexHash(this.padHex(e)+this.padHex(t)),new p(this.UHexHash,16)},t.hash=function(e){var t=e instanceof s.lW?a().lib.WordArray.create(e):e,r=l()(t).toString();return new Array(64-r.length).join("0")+r},t.hexHash=function(e){return this.hash(s.lW.from(e,"hex"))},t.computehkdf=function(e,t){var r=a().lib.WordArray.create(s.lW.concat([this.infoBits,s.lW.from(String.fromCharCode(1),"utf8")])),n=e instanceof s.lW?a().lib.WordArray.create(e):e,i=t instanceof s.lW?a().lib.WordArray.create(t):t,o=h()(n,i),u=h()(r,o);return s.lW.from(u.toString(),"hex").slice(0,16)},t.getPasswordAuthenticationKey=function(e,t,r,n,i){var o=this;if(r.mod(this.N).equals(p.ZERO))throw new Error("B cannot be zero.");if(this.UValue=this.calculateU(this.largeAValue,r),this.UValue.equals(p.ZERO))throw new Error("U cannot be zero.");var a=""+this.poolName+e+":"+t,u=this.hash(a),l=new p(this.hexHash(this.padHex(n)+u),16);this.calculateS(l,r,(function(e,t){e&&i(e,null);var r=o.computehkdf(s.lW.from(o.padHex(t),"hex"),s.lW.from(o.padHex(o.UValue),"hex"));i(null,r)}))},t.calculateS=function(e,t,r){var n=this;this.g.modPow(e,this.N,(function(i,s){i&&r(i,null),t.subtract(n.k.multiply(s)).modPow(n.smallAValue.add(n.UValue.multiply(e)),n.N,(function(e,t){e&&r(e,null),r(null,t.mod(n.N))}))}))},t.getNewPasswordRequiredChallengeUserAttributePrefix=function(){return"userAttributes."},t.padHex=function(e){if(!(e instanceof p))throw new Error("Not a BigInteger");var t=e.compareTo(p.ZERO)<0,r=e.abs().toString(16);if(r=r.length%2!=0?"0"+r:r,r=D.test(r)?"00"+r:r,t){var n=r.split("").map((function(e){var t=15&~parseInt(e,16);return"0123456789ABCDEF".charAt(t)})).join("");(r=new p(n,16).add(p.ONE).toString(16)).toUpperCase().startsWith("FF8")&&(r=r.substring(2))}return r},e}(),C=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(s.lW.from(e,"base64").toString("utf8"))}catch(e){return{}}},e}();function P(e,t){return P=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},P(e,t)}var k=function(e){var t,r;function n(t){var r=(void 0===t?{}:t).AccessToken;return e.call(this,r||"")||this}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,P(t,r),n}(C);function N(e,t){return N=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},N(e,t)}var O=function(e){var t,r;function n(t){var r=(void 0===t?{}:t).IdToken;return e.call(this,r||"")||this}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,N(t,r),n}(C),M=function(){function e(e){var t=(void 0===e?{}:e).RefreshToken;this.token=t||""}return e.prototype.getToken=function(){return this.token},e}(),F=r(269),x=r.n(F),V=function(){function e(e){var t=void 0===e?{}:e,r=t.IdToken,n=t.RefreshToken,i=t.AccessToken,s=t.ClockDrift;if(null==i||null==r)throw new Error("Id token and Access Token must be present.");this.idToken=r,this.refreshToken=n,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}(),L=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],B=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],q=function(){function e(){}return e.prototype.getNowString=function(){var e=new Date,t=B[e.getUTCDay()],r=L[e.getUTCMonth()],n=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+" "+r+" "+n+" "+i+":"+s+":"+o+" UTC "+e.getUTCFullYear()},e}(),K=function(){function e(e){var t=void 0===e?{}:e,r=t.Name,n=t.Value;this.Name=r||"",this.Value=n||""}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}(),j={},W=function(){function e(){}return e.setItem=function(e,t){return j[e]=t,j[e]},e.getItem=function(e){return Object.prototype.hasOwnProperty.call(j,e)?j[e]:void 0},e.removeItem=function(e){return delete j[e]},e.clear=function(){return j={}},e}(),H=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=W}}return e.prototype.getStorage=function(){return this.storageWindow},e}(),J="undefined"!=typeof navigator?navigator.userAgent:"nodejs",$=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 H).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 r=this,n=e.getAuthParameters();n.USERNAME=this.username;var i=0!==Object.keys(e.getValidationData()).length?e.getValidationData():e.getClientMetadata(),s={AuthFlow:"CUSTOM_AUTH",ClientId:this.pool.getClientId(),AuthParameters:n,ClientMetadata:i};this.getUserContextData()&&(s.UserContextData=this.getUserContextData()),this.client.request("InitiateAuth",s,(function(e,n){if(e)return t.onFailure(e);var i=n.ChallengeName,s=n.ChallengeParameters;return"CUSTOM_CHALLENGE"===i?(r.Session=n.Session,t.customChallenge(s)):(r.signInUserSession=r.getCognitoUserSession(n.AuthenticationResult),r.cacheTokens(),t.onSuccess(r.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 r,n,i=this,o=new T(this.pool.getUserPoolName()),u=new q,l={};null!=this.deviceKey&&(l.DEVICE_KEY=this.deviceKey),l.USERNAME=this.username,o.getLargeAValue((function(c,f){c&&t.onFailure(c),l.SRP_A=f.toString(16),"CUSTOM_AUTH"===i.authenticationFlowType&&(l.CHALLENGE_NAME="SRP_A");var d=0!==Object.keys(e.getValidationData()).length?e.getValidationData():e.getClientMetadata(),g={AuthFlow:i.authenticationFlowType,ClientId:i.pool.getClientId(),AuthParameters:l,ClientMetadata:d};i.getUserContextData(i.username)&&(g.UserContextData=i.getUserContextData(i.username)),i.client.request("InitiateAuth",g,(function(l,c){if(l)return t.onFailure(l);var f=c.ChallengeParameters;i.username=f.USER_ID_FOR_SRP,i.userDataKey=i.keyPrefix+"."+i.username+".userData",r=new p(f.SRP_B,16),n=new p(f.SALT,16),i.getCachedDeviceKeyAndPassword(),o.getPasswordAuthenticationKey(i.username,e.getPassword(),r,n,(function(e,r){e&&t.onFailure(e);var n=u.getNowString(),l=a().lib.WordArray.create(s.lW.concat([s.lW.from(i.pool.getUserPoolName(),"utf8"),s.lW.from(i.username,"utf8"),s.lW.from(f.SECRET_BLOCK,"base64"),s.lW.from(n,"utf8")])),p=a().lib.WordArray.create(r),g=x().stringify(h()(l,p)),v={};v.USERNAME=i.username,v.PASSWORD_CLAIM_SECRET_BLOCK=f.SECRET_BLOCK,v.TIMESTAMP=n,v.PASSWORD_CLAIM_SIGNATURE=g,null!=i.deviceKey&&(v.DEVICE_KEY=i.deviceKey);var y={ChallengeName:"PASSWORD_VERIFIER",ClientId:i.pool.getClientId(),ChallengeResponses:v,Session:c.Session,ClientMetadata:d};i.getUserContextData()&&(y.UserContextData=i.getUserContextData()),function e(t,r){return i.client.request("RespondToAuthChallenge",t,(function(n,s){return n&&"ResourceNotFoundException"===n.code&&-1!==n.message.toLowerCase().indexOf("device")?(v.DEVICE_KEY=null,i.deviceKey=null,i.randomPassword=null,i.deviceGroupKey=null,i.clearCachedDeviceKeyAndPassword(),e(t,r)):r(n,s)}))}(y,(function(e,r){return e?t.onFailure(e):i.authenticateUserInternal(r,o,t)}))}))}))}))},t.authenticateUserPlainUsernamePassword=function(e,t){var r=this,n={};if(n.USERNAME=this.username,n.PASSWORD=e.getPassword(),n.PASSWORD){var i=new T(this.pool.getUserPoolName());this.getCachedDeviceKeyAndPassword(),null!=this.deviceKey&&(n.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:n,ClientMetadata:s};this.getUserContextData(this.username)&&(o.UserContextData=this.getUserContextData(this.username)),this.client.request("InitiateAuth",o,(function(e,n){return e?t.onFailure(e):r.authenticateUserInternal(n,i,t)}))}else t.onFailure(new Error("PASSWORD parameter is required"))},t.authenticateUserInternal=function(e,t,r){var n=this,i=e.ChallengeName,o=e.ChallengeParameters;if("SMS_MFA"===i)return this.Session=e.Session,r.mfaRequired(i,o);if("SELECT_MFA_TYPE"===i)return this.Session=e.Session,r.selectMFAType(i,o);if("MFA_SETUP"===i)return this.Session=e.Session,r.mfaSetup(i,o);if("SOFTWARE_TOKEN_MFA"===i)return this.Session=e.Session,r.totpRequired(i,o);if("CUSTOM_CHALLENGE"===i)return this.Session=e.Session,r.customChallenge(o);if("NEW_PASSWORD_REQUIRED"===i){this.Session=e.Session;var a=null,u=null,l=[],c=t.getNewPasswordRequiredChallengeUserAttributePrefix();if(o&&(a=JSON.parse(e.ChallengeParameters.userAttributes),u=JSON.parse(e.ChallengeParameters.requiredAttributes)),u)for(var h=0;h<u.length;h++)l[h]=u[h].substr(c.length);return r.newPasswordRequired(a,l)}if("DEVICE_SRP_AUTH"===i)return this.Session=e.Session,void this.getDeviceResponse(r);this.signInUserSession=this.getCognitoUserSession(e.AuthenticationResult),this.challengeName=i,this.cacheTokens();var f=e.AuthenticationResult.NewDeviceMetadata;if(null==f)return r.onSuccess(this.signInUserSession);t.generateHashDevice(e.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,e.AuthenticationResult.NewDeviceMetadata.DeviceKey,(function(i){if(i)return r.onFailure(i);var o={Salt:s.lW.from(t.getSaltDevices(),"hex").toString("base64"),PasswordVerifier:s.lW.from(t.getVerifierDevices(),"hex").toString("base64")};n.verifierDevices=o.PasswordVerifier,n.deviceGroupKey=f.DeviceGroupKey,n.randomPassword=t.getRandomPassword(),n.client.request("ConfirmDevice",{DeviceKey:f.DeviceKey,AccessToken:n.signInUserSession.getAccessToken().getJwtToken(),DeviceSecretVerifierConfig:o,DeviceName:J},(function(t,i){return t?r.onFailure(t):(n.deviceKey=e.AuthenticationResult.NewDeviceMetadata.DeviceKey,n.cacheDeviceKeyAndPassword(),!0===i.UserConfirmationNecessary?r.onSuccess(n.signInUserSession,i.UserConfirmationNecessary):r.onSuccess(n.signInUserSession))}))}))},t.completeNewPasswordChallenge=function(e,t,r,n){var i=this;if(!e)return r.onFailure(new Error("New password is required."));var s=new T(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:n};this.getUserContextData()&&(u.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",u,(function(e,t){return e?r.onFailure(e):i.authenticateUserInternal(t,s,r)}))},t.getDeviceResponse=function(e,t){var r=this,n=new T(this.deviceGroupKey),i=new q,o={};o.USERNAME=this.username,o.DEVICE_KEY=this.deviceKey,n.getLargeAValue((function(u,l){u&&e.onFailure(u),o.SRP_A=l.toString(16);var c={ChallengeName:"DEVICE_SRP_AUTH",ClientId:r.pool.getClientId(),ChallengeResponses:o,ClientMetadata:t,Session:r.Session};r.getUserContextData()&&(c.UserContextData=r.getUserContextData()),r.client.request("RespondToAuthChallenge",c,(function(t,o){if(t)return e.onFailure(t);var u=o.ChallengeParameters,l=new p(u.SRP_B,16),c=new p(u.SALT,16);n.getPasswordAuthenticationKey(r.deviceKey,r.randomPassword,l,c,(function(t,n){if(t)return e.onFailure(t);var l=i.getNowString(),c=a().lib.WordArray.create(s.lW.concat([s.lW.from(r.deviceGroupKey,"utf8"),s.lW.from(r.deviceKey,"utf8"),s.lW.from(u.SECRET_BLOCK,"base64"),s.lW.from(l,"utf8")])),f=a().lib.WordArray.create(n),d=x().stringify(h()(c,f)),p={};p.USERNAME=r.username,p.PASSWORD_CLAIM_SECRET_BLOCK=u.SECRET_BLOCK,p.TIMESTAMP=l,p.PASSWORD_CLAIM_SIGNATURE=d,p.DEVICE_KEY=r.deviceKey;var g={ChallengeName:"DEVICE_PASSWORD_VERIFIER",ClientId:r.pool.getClientId(),ChallengeResponses:p,Session:o.Session};r.getUserContextData()&&(g.UserContextData=r.getUserContextData()),r.client.request("RespondToAuthChallenge",g,(function(t,n){return t?e.onFailure(t):(r.signInUserSession=r.getCognitoUserSession(n.AuthenticationResult),r.cacheTokens(),e.onSuccess(r.signInUserSession))}))}))}))}))},t.confirmRegistration=function(e,t,r,n){var i={ClientId:this.pool.getClientId(),ConfirmationCode:e,Username:this.username,ForceAliasCreation:t,ClientMetadata:n};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("ConfirmSignUp",i,(function(e){return e?r(e,null):r(null,"SUCCESS")}))},t.sendCustomChallengeAnswer=function(e,t,r){var n=this,i={};i.USERNAME=this.username,i.ANSWER=e;var s=new T(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:r};this.getUserContextData()&&(o.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",o,(function(e,r){return e?t.onFailure(e):n.authenticateUserInternal(r,s,t)}))},t.sendMFACode=function(e,t,r,n){var i=this,o={};o.USERNAME=this.username,o.SMS_MFA_CODE=e;var a=r||"SMS_MFA";"SOFTWARE_TOKEN_MFA"===a&&(o.SOFTWARE_TOKEN_MFA_CODE=e),null!=this.deviceKey&&(o.DEVICE_KEY=this.deviceKey);var u={ChallengeName:a,ChallengeResponses:o,ClientId:this.pool.getClientId(),Session:this.Session,ClientMetadata:n};this.getUserContextData()&&(u.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",u,(function(e,r){if(e)return t.onFailure(e);if("DEVICE_SRP_AUTH"!==r.ChallengeName){if(i.signInUserSession=i.getCognitoUserSession(r.AuthenticationResult),i.cacheTokens(),null==r.AuthenticationResult.NewDeviceMetadata)return t.onSuccess(i.signInUserSession);var n=new T(i.pool.getUserPoolName());n.generateHashDevice(r.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,r.AuthenticationResult.NewDeviceMetadata.DeviceKey,(function(e){if(e)return t.onFailure(e);var o={Salt:s.lW.from(n.getSaltDevices(),"hex").toString("base64"),PasswordVerifier:s.lW.from(n.getVerifierDevices(),"hex").toString("base64")};i.verifierDevices=o.PasswordVerifier,i.deviceGroupKey=r.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,i.randomPassword=n.getRandomPassword(),i.client.request("ConfirmDevice",{DeviceKey:r.AuthenticationResult.NewDeviceMetadata.DeviceKey,AccessToken:i.signInUserSession.getAccessToken().getJwtToken(),DeviceSecretVerifierConfig:o,DeviceName:J},(function(e,n){return e?t.onFailure(e):(i.deviceKey=r.AuthenticationResult.NewDeviceMetadata.DeviceKey,i.cacheDeviceKeyAndPassword(),!0===n.UserConfirmationNecessary?t.onSuccess(i.signInUserSession,n.UserConfirmationNecessary):t.onSuccess(i.signInUserSession))}))}))}else i.getDeviceResponse(t)}))},t.changePassword=function(e,t,r,n){if(null==this.signInUserSession||!this.signInUserSession.isValid())return r(new Error("User is not authenticated"),null);this.client.request("ChangePassword",{PreviousPassword:e,ProposedPassword:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),ClientMetadata:n},(function(e){return e?r(e,null):r(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,r){if(null==this.signInUserSession||!this.signInUserSession.isValid())return r(new Error("User is not authenticated"),null);this.client.request("SetUserMFAPreference",{SMSMfaSettings:e,SoftwareTokenMfaSettings:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(e){return e?r(e,null):r(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 r=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):(r.clearCachedUser(),e(null,"SUCCESS"))}))},t.updateAttributes=function(e,t,r){var n=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:r},(function(e){return e?t(e,null):n.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,r){if(t)return e(t,null);for(var n=[],i=0;i<r.UserAttributes.length;i++){var s={Name:r.UserAttributes[i].Name,Value:r.UserAttributes[i].Value},o=new K(s);n.push(o)}return e(null,n)}))},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,r){return t?e(t,null):e(null,r.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(r){var n=t.signInUserSession.getRefreshToken();n&&n.getToken()?t.refreshSession(n,r,e.clientMetadata):r()}))},t.getUserData=function(e,t){var r=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return this.clearCachedUserData(),e(new Error("User is not authenticated"),null);var n=this.getUserDataFromCache();if(n)if(this.isFetchUserDataAndTokenRequired(t))this.fetchUserData().then((function(e){return r.refreshSessionIfPossible(t).then((function(){return e}))})).then((function(t){return e(null,t)})).catch(e);else try{return void e(null,JSON.parse(n))}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 r=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):r.getUserData((function(){return t(null,"SUCCESS")}),{bypassCache:!0})}))},t.resendConfirmationCode=function(e,t){var r={ClientId:this.pool.getClientId(),Username:this.username,ClientMetadata:t};this.client.request("ResendConfirmationCode",r,(function(t,r){return t?e(t,null):e(null,r)}))},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 r="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,n=r+".idToken",i=r+".accessToken",s=r+".refreshToken",o=r+".clockDrift";if(this.storage.getItem(n)){var a=new O({IdToken:this.storage.getItem(n)}),u=new k({AccessToken:this.storage.getItem(i)}),l=new M({RefreshToken:this.storage.getItem(s)}),c=parseInt(this.storage.getItem(o),0)||0,h=new V({IdToken:a,AccessToken:u,RefreshToken:l,ClockDrift:c});if(h.isValid())return this.signInUserSession=h,e(null,this.signInUserSession);if(!l.getToken())return e(new Error("Cannot retrieve a new session. Please authenticate."),null);this.refreshSession(l,e,t.clientMetadata)}else e(new Error("Local storage is missing an ID Token, Please authenticate"),null)},t.refreshSession=function(e,t,r){var n=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 l={ClientId:this.pool.getClientId(),AuthFlow:"REFRESH_TOKEN_AUTH",AuthParameters:s,ClientMetadata:r};this.getUserContextData()&&(l.UserContextData=this.getUserContextData()),this.client.request("InitiateAuth",l,(function(t,r){if(t)return"NotAuthorizedException"===t.code&&n.clearCachedUser(),i(t,null);if(r){var s=r.AuthenticationResult;return Object.prototype.hasOwnProperty.call(s,"RefreshToken")||(s.RefreshToken=e.getToken()),n.signInUserSession=n.getCognitoUserSession(s),n.cacheTokens(),i(null,n.signInUserSession)}}))},t.cacheTokens=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId(),t=e+"."+this.username+".idToken",r=e+"."+this.username+".accessToken",n=e+"."+this.username+".refreshToken",i=e+"."+this.username+".clockDrift",s=e+".LastAuthUser";this.storage.setItem(t,this.signInUserSession.getIdToken().getJwtToken()),this.storage.setItem(r,this.signInUserSession.getAccessToken().getJwtToken()),this.storage.setItem(n,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",r=e+".randomPasswordKey",n=e+".deviceGroupKey";this.storage.setItem(t,this.deviceKey),this.storage.setItem(r,this.randomPassword),this.storage.setItem(n,this.deviceGroupKey)},t.getCachedDeviceKeyAndPassword=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,t=e+".deviceKey",r=e+".randomPasswordKey",n=e+".deviceGroupKey";this.storage.getItem(t)&&(this.deviceKey=this.storage.getItem(t),this.randomPassword=this.storage.getItem(r),this.deviceGroupKey=this.storage.getItem(n))},t.clearCachedDeviceKeyAndPassword=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,t=e+".deviceKey",r=e+".randomPasswordKey",n=e+".deviceGroupKey";this.storage.removeItem(t),this.storage.removeItem(r),this.storage.removeItem(n)},t.clearCachedTokens=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId(),t=e+"."+this.username+".idToken",r=e+"."+this.username+".accessToken",n=e+"."+this.username+".refreshToken",i=e+".LastAuthUser",s=e+"."+this.username+".clockDrift";this.storage.removeItem(t),this.storage.removeItem(r),this.storage.removeItem(n),this.storage.removeItem(i),this.storage.removeItem(s)},t.getCognitoUserSession=function(e){var t=new O(e),r=new k(e),n=new M(e);return new V({IdToken:t,AccessToken:r,RefreshToken:n})},t.forgotPassword=function(e,t){var r={ClientId:this.pool.getClientId(),Username:this.username,ClientMetadata:t};this.getUserContextData()&&(r.UserContextData=this.getUserContextData()),this.client.request("ForgotPassword",r,(function(t,r){return t?e.onFailure(t):"function"==typeof e.inputVerificationCode?e.inputVerificationCode(r):e.onSuccess(r)}))},t.confirmPassword=function(e,t,r,n){var i={ClientId:this.pool.getClientId(),Username:this.username,ConfirmationCode:e,Password:t,ClientMetadata:n};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("ConfirmForgotPassword",i,(function(e){return e?r.onFailure(e):r.onSuccess("SUCCESS")}))},t.getAttributeVerificationCode=function(e,t,r){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:r},(function(e,r){return e?t.onFailure(e):"function"==typeof t.inputVerificationCode?t.inputVerificationCode(r):t.onSuccess("SUCCESS")}))},t.verifyAttribute=function(e,t,r){if(null==this.signInUserSession||!this.signInUserSession.isValid())return r.onFailure(new Error("User is not authenticated"));this.client.request("VerifyUserAttribute",{AttributeName:e,Code:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(e){return e?r.onFailure(e):r.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,r){return t?e.onFailure(t):e.onSuccess(r)}))},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(r){return t.deviceKey=null,t.deviceGroupKey=null,t.randomPassword=null,t.clearCachedDeviceKeyAndPassword(),e.onSuccess(r)}})},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,r){if(null==this.signInUserSession||!this.signInUserSession.isValid())return r.onFailure(new Error("User is not authenticated"));var n={AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),Limit:e};t&&(n.PaginationToken=t),this.client.request("ListDevices",n,(function(e,t){return e?r.onFailure(e):r.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(r){return r?e.onFailure(r):(t.clearCachedUser(),e.onSuccess("SUCCESS"))}))},t.signOut=function(e){var t=this;e&&"function"==typeof e?this.getSession((function(r,n){if(r)return e(r);t.revokeTokens((function(r){t.cleanClientData(),e(r)}))})):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(),r=this.signInUserSession.getAccessToken();if(this.isSessionRevocable(r)&&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,r=e.callback;this.client.requestWithRetry("RevokeToken",{Token:t,ClientId:this.pool.getClientId()},(function(e){if(e)return r(e);r()}))},t.sendMFASelectionAnswer=function(e,t){var r=this,n={};n.USERNAME=this.username,n.ANSWER=e;var i={ChallengeName:"SELECT_MFA_TYPE",ChallengeResponses:n,ClientId:this.pool.getClientId(),Session:this.Session};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",i,(function(n,i){return n?t.onFailure(n):(r.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,r){return t?e.onFailure(t):e.associateSecretCode(r.SecretCode)})):this.client.request("AssociateSoftwareToken",{Session:this.Session},(function(r,n){return r?e.onFailure(r):(t.Session=n.Session,e.associateSecretCode(n.SecretCode))}))},t.verifySoftwareToken=function(e,t,r){var n=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?r.onFailure(e):r.onSuccess(t)})):this.client.request("VerifySoftwareToken",{Session:this.Session,UserCode:e,FriendlyDeviceName:t},(function(e,t){if(e)return r.onFailure(e);n.Session=t.Session;var i={};i.USERNAME=n.username;var s={ChallengeName:"MFA_SETUP",ClientId:n.pool.getClientId(),ChallengeResponses:i,Session:n.Session};n.getUserContextData()&&(s.UserContextData=n.getUserContextData()),n.client.request("RespondToAuthChallenge",s,(function(e,t){return e?r.onFailure(e):(n.signInUserSession=n.getCognitoUserSession(t.AuthenticationResult),n.cacheTokens(),r.onSuccess(n.signInUserSession))}))}))},e}(),Y=(r(204),"aws-amplify/5.0.4"),z={userAgent:Y+" js",product:"",navigator:null,isReactNative:!1};function G(){}"undefined"!=typeof navigator&&navigator.product&&(z.product=navigator.product||"",z.navigator=navigator||null,"ReactNative"===navigator.product?(z.userAgent=Y+" react-native",z.isReactNative=!0):(z.userAgent=Y+" js",z.isReactNative=!1)),G.prototype.userAgent=z.userAgent;var Q=function(e){e&&(G.prototype.userAgent&&!G.prototype.userAgent.includes(e)&&(G.prototype.userAgent=G.prototype.userAgent.concat(" ",e)),G.prototype.userAgent&&""!==G.prototype.userAgent||(G.prototype.userAgent=e))};const Z=G;function X(e){var t="function"==typeof Map?new Map:void 0;return X=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;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,n)}function n(){return ee(e,arguments,ne(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),re(n,e)},X(e)}function ee(e,t,r){return ee=te()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&re(i,r.prototype),i},ee.apply(null,arguments)}function te(){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}}function re(e,t){return re=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},re(e,t)}function ne(e){return ne=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ne(e)}var ie=function(e){function t(t,r,n,i){var s;return(s=e.call(this,t)||this).code=r,s.name=n,s.statusCode=i,s}return n=e,(r=t).prototype=Object.create(n.prototype),r.prototype.constructor=r,re(r,n),t;var r,n}(X(Error)),se=function(){function e(e,t,r){this.endpoint=t||"https://cognito-idp."+e+".amazonaws.com/";var n=(r||{}).credentials;this.fetchOptions=n?{credentials:n}:{}}var t=e.prototype;return t.promisifyRequest=function(e,t){var r=this;return new Promise((function(n,i){r.request(e,t,(function(e,t){e?i(new ie(e.message,e.code,e.name,e.statusCode)):n(t)}))}))},t.requestWithRetry=function(e,t,r){var n,i,s=this;(n=[t],i=5e3,void 0===i&&(i=ae),oe((function(t){return new Promise((function(r,n){s.request(e,t,(function(e,t){e?n(e):r(t)}))}))}),n,function(e){return function(t){var r=100*Math.pow(2,t)+100*Math.random();return!(r>e)&&r}}(i))).then((function(e){return r(null,e)})).catch((function(e){return r(e)}))},t.request=function(e,t,r){var n,i={"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityProviderService."+e,"X-Amz-User-Agent":Z.prototype.userAgent},s=Object.assign({},this.fetchOptions,{headers:i,method:"POST",mode:"cors",cache:"no-cache",body:JSON.stringify(t)});fetch(this.endpoint,s).then((function(e){return n=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(n.ok)return r(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,r(i)})).catch((function(e){if(n&&n.headers&&n.headers.get("x-amzn-errortype"))try{var t=n.headers.get("x-amzn-errortype").split(":")[0],i=new Error(n.status?n.status.toString():null);return i.code=t,i.name=t,i.statusCode=n.status,r(i)}catch(t){return r(e)}else e instanceof Error&&"Network error"===e.message&&(e.code="NetworkError");return r(e)}))},e}();function oe(e,t,r,n){if(void 0===n&&(n=1),"function"!=typeof e)throw Error("functionToRetry must be a function");return e.name,JSON.stringify(t),e.apply(void 0,t).catch((function(i){if(e.name,(s=i)&&s.nonRetryable)throw e.name,i;var s,o=r(n,t,i);if(e.name,!1!==o)return new Promise((function(e){return setTimeout(e,o)})).then((function(){return oe(e,t,r,n+1)}));throw i}))}Error;var ae=3e5,ue=function(){function e(e,t){var r=e||{},n=r.UserPoolId,i=r.ClientId,s=r.endpoint,o=r.fetchOptions,a=r.AdvancedSecurityDataCollectionFlag;if(!n||!i)throw new Error("Both UserPoolId and ClientId are required.");if(n.length>55||!/^[\w-]+_[0-9a-zA-Z]+$/.test(n))throw new Error("Invalid UserPoolId format.");var u=n.split("_")[0];this.userPoolId=n,this.clientId=i,this.client=new se(u,s,o),this.advancedSecurityDataCollectionFlag=!1!==a,this.storage=e.Storage||(new H).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,r,n,i,s){var o=this,a={ClientId:this.clientId,Username:e,Password:t,UserAttributes:r,ValidationData:n,ClientMetadata:s};this.getUserContextData(e)&&(a.UserContextData=this.getUserContextData(e)),this.client.request("SignUp",a,(function(t,r){if(t)return i(t,null);var n={Username:e,Pool:o,Storage:o.storage},s={user:new $(n),userConfirmed:r.UserConfirmed,userSub:r.UserSub,codeDeliveryDetails:r.CodeDeliveryDetails};return i(null,s)}))},t.getCurrentUser=function(){var e="CognitoIdentityServiceProvider."+this.clientId+".LastAuthUser",t=this.storage.getItem(e);if(t){var r={Username:t,Pool:this,Storage:this.storage};return new $(r)}return null},t.getUserContextData=function(e){if("undefined"!=typeof AmazonCognitoAdvancedSecurityData){var t=AmazonCognitoAdvancedSecurityData;if(this.advancedSecurityDataCollectionFlag){var r=t.getData(e,this.userPoolId,this.clientId);if(r)return{EncodedData:r}}return{}}},e}(),le=r(808),ce=function(){function e(e){if(!e.domain)throw new Error("The domain of cookieStorage can not be undefined.");if(this.domain=e.domain,e.path?this.path=e.path:this.path="/",Object.prototype.hasOwnProperty.call(e,"expires")?this.expires=e.expires:this.expires=365,Object.prototype.hasOwnProperty.call(e,"secure")?this.secure=e.secure:this.secure=!0,Object.prototype.hasOwnProperty.call(e,"sameSite")){if(!["strict","lax","none"].includes(e.sameSite))throw new Error('The sameSite value of cookieStorage must be "lax", "strict" or "none".');if("none"===e.sameSite&&!this.secure)throw new Error("sameSite = None requires the Secure attribute in latest browser versions.");this.sameSite=e.sameSite}else this.sameSite=null}var t=e.prototype;return t.setItem=function(e,t){var r={path:this.path,expires:this.expires,domain:this.domain,secure:this.secure};return this.sameSite&&(r.sameSite=this.sameSite),le.set(e,t,r),le.get(e)},t.getItem=function(e){return le.get(e)},t.removeItem=function(e){var t={path:this.path,expires:this.expires,domain:this.domain,secure:this.secure};return this.sameSite&&(t.sameSite=this.sameSite),le.remove(e,t)},t.clear=function(){for(var e=le.get(),t=Object.keys(e).length,r=0;r<t;++r)this.removeItem(Object.keys(e)[r]);return{}},e}()},742:(e,t)=>{"use strict";t.byteLength=function(e){var t=u(e),r=t[0],n=t[1];return 3*(r+n)/4-n},t.toByteArray=function(e){var t,r,s=u(e),o=s[0],a=s[1],l=new i(function(e,t,r){return 3*(t+r)/4-r}(0,o,a)),c=0,h=a>0?o-4:o;for(r=0;r<h;r+=4)t=n[e.charCodeAt(r)]<<18|n[e.charCodeAt(r+1)]<<12|n[e.charCodeAt(r+2)]<<6|n[e.charCodeAt(r+3)],l[c++]=t>>16&255,l[c++]=t>>8&255,l[c++]=255&t;return 2===a&&(t=n[e.charCodeAt(r)]<<2|n[e.charCodeAt(r+1)]>>4,l[c++]=255&t),1===a&&(t=n[e.charCodeAt(r)]<<10|n[e.charCodeAt(r+1)]<<4|n[e.charCodeAt(r+2)]>>2,l[c++]=t>>8&255,l[c++]=255&t),l},t.fromByteArray=function(e){for(var t,n=e.length,i=n%3,s=[],o=16383,a=0,u=n-i;a<u;a+=o)s.push(l(e,a,a+o>u?u:a+o));return 1===i?(t=e[n-1],s.push(r[t>>2]+r[t<<4&63]+"==")):2===i&&(t=(e[n-2]<<8)+e[n-1],s.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"=")),s.join("")};for(var r=[],n=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,a=s.length;o<a;++o)r[o]=s[o],n[s.charCodeAt(o)]=o;function u(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function l(e,t,n){for(var i,s,o=[],a=t;a<n;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(r[(s=i)>>18&63]+r[s>>12&63]+r[s>>6&63]+r[63&s]);return o.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},764:(e,t,r)=>{"use strict";var n=r(742),i=r(645),s=r(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,r){if(!(u.TYPED_ARRAY_SUPPORT||this instanceof u))return new u(e,t,r);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 l(this,e,t,r)}function l(e,t,r,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return t=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n),u.TYPED_ARRAY_SUPPORT?(e=t).__proto__=u.prototype:e=f(e,t),e}(e,t,r,n):"string"==typeof t?function(e,t,r){if("string"==typeof r&&""!==r||(r="utf8"),!u.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|p(t,r),i=(e=a(e,n)).write(t,r);return i!==n&&(e=e.slice(0,i)),e}(e,t,r):function(e,t){if(u.isBuffer(t)){var r=0|d(t.length);return 0===(e=a(e,r)).length||t.copy(e,0,0,r),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?a(e,0):f(e,t);if("Buffer"===t.type&&s(t.data))return f(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function c(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(c(t),e=a(e,t<0?0:0|d(t)),!u.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function f(e,t){var r=t.length<0?0:0|d(t.length);e=a(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];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 r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return B(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return q(e).length;default:if(n)return B(e).length;t=(""+t).toLowerCase(),n=!0}}function g(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return C(this,t,r);case"utf8":case"utf-8":return U(this,t,r);case"ascii":return D(this,t,r);case"latin1":case"binary":return T(this,t,r);case"base64":return I(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function v(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function y(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=u.from(t,n)),u.isBuffer(t))return 0===t.length?-1:m(e,t,r,n,i);if("number"==typeof t)return t&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):m(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(e,t,r,n,i){var s,o=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;o=2,a/=2,u/=2,r/=2}function l(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){var c=-1;for(s=r;s<a;s++)if(l(e,s)===l(t,-1===c?0:s-c)){if(-1===c&&(c=s),s-c+1===u)return c*o}else-1!==c&&(s-=s-c),c=-1}else for(r+u>a&&(r=a-u),s=r;s>=0;s--){for(var h=!0,f=0;f<u;f++)if(l(e,s+f)!==l(t,f)){h=!1;break}if(h)return s}return-1}function w(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;var s=t.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var o=0;o<n;++o){var a=parseInt(t.substr(2*o,2),16);if(isNaN(a))return o;e[r+o]=a}return o}function _(e,t,r,n){return K(B(t,e.length-r),e,r,n)}function A(e,t,r,n){return K(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function b(e,t,r,n){return A(e,t,r,n)}function S(e,t,r,n){return K(q(t),e,r,n)}function E(e,t,r,n){return K(function(e,t){for(var r,n,i,s=[],o=0;o<e.length&&!((t-=2)<0);++o)n=(r=e.charCodeAt(o))>>8,i=r%256,s.push(i),s.push(n);return s}(t,e.length-r),e,r,n)}function I(e,t,r){return 0===t&&r===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,r))}function U(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var s,o,a,u,l=e[i],c=null,h=l>239?4:l>223?3:l>191?2:1;if(i+h<=r)switch(h){case 1:l<128&&(c=l);break;case 2:128==(192&(s=e[i+1]))&&(u=(31&l)<<6|63&s)>127&&(c=u);break;case 3:s=e[i+1],o=e[i+2],128==(192&s)&&128==(192&o)&&(u=(15&l)<<12|(63&s)<<6|63&o)>2047&&(u<55296||u>57343)&&(c=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&l)<<18|(63&s)<<12|(63&o)<<6|63&a)>65535&&u<1114112&&(c=u)}null===c?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),i+=h}return function(e){var t=e.length;if(t<=R)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=R));return r}(n)}t.lW=u,t.h2=50,u.TYPED_ARRAY_SUPPORT=void 0!==r.g.TYPED_ARRAY_SUPPORT?r.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,r){return l(null,e,t,r)},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,r){return function(e,t,r,n){return c(t),t<=0?a(e,t):void 0!==r?"string"==typeof n?a(e,t).fill(r,n):a(e,t).fill(r):a(e,t)}(null,e,t,r)},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 r=e.length,n=t.length,i=0,s=Math.min(r,n);i<s;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?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 r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=u.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var o=e[r];if(!u.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},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)v(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)v(this,t,t+3),v(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)v(this,t,t+7),v(this,t+1,t+6),v(this,t+2,t+5),v(this,t+3,t+4);return this},u.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?U(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="",r=t.h2;return this.length>0&&(e=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(e+=" ... ")),"<Buffer "+e+">"},u.prototype.compare=function(e,t,r,n,i){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;for(var s=(i>>>=0)-(n>>>=0),o=(r>>>=0)-(t>>>=0),a=Math.min(s,o),l=this.slice(n,i),c=e.slice(t,r),h=0;h<a;++h)if(l[h]!==c[h]){s=l[h],o=c[h];break}return s<o?-1:o<s?1:0},u.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},u.prototype.indexOf=function(e,t,r){return y(this,e,t,r,!0)},u.prototype.lastIndexOf=function(e,t,r){return y(this,e,t,r,!1)},u.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return w(this,e,t,r);case"utf8":case"utf-8":return _(this,e,t,r);case"ascii":return A(this,e,t,r);case"latin1":case"binary":return b(this,e,t,r);case"base64":return S(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return E(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var R=4096;function D(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function T(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function C(e,t,r){var n,i=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>i)&&(r=i);for(var s="",o=t;o<r;++o)s+=(n=e[o])<16?"0"+n.toString(16):n.toString(16);return s}function P(e,t,r){for(var n=e.slice(t,r),i="",s=0;s<n.length;s+=2)i+=String.fromCharCode(n[s]+256*n[s+1]);return i}function k(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function N(e,t,r,n,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(r+n>e.length)throw new RangeError("Index out of range")}function O(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,s=Math.min(e.length-r,2);i<s;++i)e[r+i]=(t&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function M(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,s=Math.min(e.length-r,4);i<s;++i)e[r+i]=t>>>8*(n?i:3-i)&255}function F(e,t,r,n,i,s){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function x(e,t,r,n,s){return s||F(e,0,r,4),i.write(e,t,r,n,23,4),r+4}function V(e,t,r,n,s){return s||F(e,0,r,8),i.write(e,t,r,n,52,8),r+8}u.prototype.slice=function(e,t){var r,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),u.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=u.prototype;else{var i=t-e;r=new u(i,void 0);for(var s=0;s<i;++s)r[s]=this[s+e]}return r},u.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=this[e],i=1,s=0;++s<t&&(i*=256);)n+=this[e+s]*i;return n},u.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},u.prototype.readUInt8=function(e,t){return t||k(e,1,this.length),this[e]},u.prototype.readUInt16LE=function(e,t){return t||k(e,2,this.length),this[e]|this[e+1]<<8},u.prototype.readUInt16BE=function(e,t){return t||k(e,2,this.length),this[e]<<8|this[e+1]},u.prototype.readUInt32LE=function(e,t){return t||k(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||k(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},u.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=this[e],i=1,s=0;++s<t&&(i*=256);)n+=this[e+s]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*t)),n},u.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=t,i=1,s=this[e+--n];n>0&&(i*=256);)s+=this[e+--n]*i;return s>=(i*=128)&&(s-=Math.pow(2,8*t)),s},u.prototype.readInt8=function(e,t){return t||k(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},u.prototype.readInt16LE=function(e,t){t||k(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(e,t){t||k(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(e,t){return t||k(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||k(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||k(e,4,this.length),i.read(this,e,!0,23,4)},u.prototype.readFloatBE=function(e,t){return t||k(e,4,this.length),i.read(this,e,!1,23,4)},u.prototype.readDoubleLE=function(e,t){return t||k(e,8,this.length),i.read(this,e,!0,52,8)},u.prototype.readDoubleBE=function(e,t){return t||k(e,8,this.length),i.read(this,e,!1,52,8)},u.prototype.writeUIntLE=function(e,t,r,n){e=+e,t|=0,r|=0,n||N(this,e,t,r,Math.pow(2,8*r)-1,0);var i=1,s=0;for(this[t]=255&e;++s<r&&(i*=256);)this[t+s]=e/i&255;return t+r},u.prototype.writeUIntBE=function(e,t,r,n){e=+e,t|=0,r|=0,n||N(this,e,t,r,Math.pow(2,8*r)-1,0);var i=r-1,s=1;for(this[t+i]=255&e;--i>=0&&(s*=256);)this[t+i]=e/s&255;return t+r},u.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||N(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,r){return e=+e,t|=0,r||N(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):O(this,e,t,!0),t+2},u.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||N(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):O(this,e,t,!1),t+2},u.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||N(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):M(this,e,t,!0),t+4},u.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||N(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):M(this,e,t,!1),t+4},u.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);N(this,e,t,r,i-1,-i)}var s=0,o=1,a=0;for(this[t]=255&e;++s<r&&(o*=256);)e<0&&0===a&&0!==this[t+s-1]&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+r},u.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);N(this,e,t,r,i-1,-i)}var s=r-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+r},u.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||N(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,r){return e=+e,t|=0,r||N(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):O(this,e,t,!0),t+2},u.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||N(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):O(this,e,t,!1),t+2},u.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||N(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):M(this,e,t,!0),t+4},u.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||N(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):M(this,e,t,!1),t+4},u.prototype.writeFloatLE=function(e,t,r){return x(this,e,t,!0,r)},u.prototype.writeFloatBE=function(e,t,r){return x(this,e,t,!1,r)},u.prototype.writeDoubleLE=function(e,t,r){return V(this,e,t,!0,r)},u.prototype.writeDoubleBE=function(e,t,r){return V(this,e,t,!1,r)},u.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var i,s=n-r;if(this===e&&r<t&&t<n)for(i=s-1;i>=0;--i)e[i+t]=this[i+r];else if(s<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i<s;++i)e[i+t]=this[i+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+s),t);return s},u.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===e.length){var i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!u.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var s;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(s=t;s<r;++s)this[s]=e;else{var o=u.isBuffer(e)?e:B(new u(e,n).toString()),a=o.length;for(s=0;s<r-t;++s)this[s+t]=o[s%a]}return this};var L=/[^+\/0-9A-Za-z-_]/g;function B(e,t){var r;t=t||1/0;for(var n=e.length,i=null,s=[],o=0;o<n;++o){if((r=e.charCodeAt(o))>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(t-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;s.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function q(e){return n.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(L,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function K(e,t,r,n){for(var i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}},249:function(e,t,r){var n;e.exports=(n=n||function(e,t){var n;if("undefined"!=typeof window&&window.crypto&&(n=window.crypto),"undefined"!=typeof self&&self.crypto&&(n=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(n=globalThis.crypto),!n&&"undefined"!=typeof window&&window.msCrypto&&(n=window.msCrypto),!n&&void 0!==r.g&&r.g.crypto&&(n=r.g.crypto),!n)try{n=r(480)}catch(e){}var i=function(){if(n){if("function"==typeof n.getRandomValues)try{return n.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof n.randomBytes)try{return n.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 r;return e.prototype=t,r=new e,e.prototype=null,r}}(),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)}},l=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,r=e.words,n=this.sigBytes,i=e.sigBytes;if(this.clamp(),n%4)for(var s=0;s<i;s++){var o=r[s>>>2]>>>24-s%4*8&255;t[n+s>>>2]|=o<<24-(n+s)%4*8}else for(var a=0;a<i;a+=4)t[n+a>>>2]=r[a>>>2];return this.sigBytes+=i,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=u.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],r=0;r<e;r+=4)t.push(i());return new l.init(t,e)}}),c=o.enc={},h=c.Hex={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],i=0;i<r;i++){var s=t[i>>>2]>>>24-i%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new l.init(r,t/2)}},f=c.Latin1={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],i=0;i<r;i++){var s=t[i>>>2]>>>24-i%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new l.init(r,t)}},d=c.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 l.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 r,n=this._data,i=n.words,s=n.sigBytes,o=this.blockSize,a=s/(4*o),u=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,c=e.min(4*u,s);if(u){for(var h=0;h<u;h+=o)this._doProcessBlock(i,h);r=i.splice(0,u),n.sigBytes-=c}return new l.init(r,c)},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,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new g.HMAC.init(e,r).finalize(t)}}}),o.algo={});return o}(Math),n)},269:function(e,t,r){var n,i,s;e.exports=(n=r(249),s=(i=n).lib.WordArray,i.enc.Base64={stringify:function(e){var t=e.words,r=e.sigBytes,n=this._map;e.clamp();for(var i=[],s=0;s<r;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<r;a++)i.push(n.charAt(o>>>6*(3-a)&63));var u=n.charAt(64);if(u)for(;i.length%4;)i.push(u);return i.join("")},parse:function(e){var t=e.length,r=this._map,n=this._reverseMap;if(!n){n=this._reverseMap=[];for(var i=0;i<r.length;i++)n[r.charCodeAt(i)]=i}var o=r.charAt(64);if(o){var a=e.indexOf(o);-1!==a&&(t=a)}return function(e,t,r){for(var n=[],i=0,o=0;o<t;o++)if(o%4){var a=r[e.charCodeAt(o-1)]<<o%4*2|r[e.charCodeAt(o)]>>>6-o%4*2;n[i>>>2]|=a<<24-i%4*8,i++}return s.create(n,i)}(e,t,n)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},n.enc.Base64)},10:function(e,t,r){var n;e.exports=(n=r(249),r(153),r(824),n.HmacSHA256)},824:function(e,t,r){var n,i,s;e.exports=(i=(n=r(249)).lib.Base,s=n.enc.Utf8,void(n.algo.HMAC=i.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var r=e.blockSize,n=4*r;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var i=this._oKey=t.clone(),o=this._iKey=t.clone(),a=i.words,u=o.words,l=0;l<r;l++)a[l]^=1549556828,u[l]^=909522486;i.sigBytes=o.sigBytes=n,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,r=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(r))}})))},433:function(e,t,r){var n;e.exports=(n=r(249),function(){if("function"==typeof ArrayBuffer){var e=n.lib.WordArray,t=e.init,r=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 r=e.byteLength,n=[],i=0;i<r;i++)n[i>>>2]|=e[i]<<24-i%4*8;t.call(this,n,r)}else t.apply(this,arguments)};r.prototype=e}}(),n.lib.WordArray)},153:function(e,t,r){var n;e.exports=(n=r(249),function(e){var t=n,r=t.lib,i=r.WordArray,s=r.Hasher,o=t.algo,a=[],u=[];!function(){function t(t){for(var r=e.sqrt(t),n=2;n<=r;n++)if(!(t%n))return!1;return!0}function r(e){return 4294967296*(e-(0|e))|0}for(var n=2,i=0;i<64;)t(n)&&(i<8&&(a[i]=r(e.pow(n,.5))),u[i]=r(e.pow(n,1/3)),i++),n++}();var l=[],c=o.SHA256=s.extend({_doReset:function(){this._hash=new i.init(a.slice(0))},_doProcessBlock:function(e,t){for(var r=this._hash.words,n=r[0],i=r[1],s=r[2],o=r[3],a=r[4],c=r[5],h=r[6],f=r[7],d=0;d<64;d++){if(d<16)l[d]=0|e[t+d];else{var p=l[d-15],g=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,v=l[d-2],y=(v<<15|v>>>17)^(v<<13|v>>>19)^v>>>10;l[d]=g+l[d-7]+y+l[d-16]}var m=n&i^n&s^i&s,w=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),_=f+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&c^~a&h)+u[d]+l[d];f=h,h=c,c=a,a=o+_|0,o=s,s=i,i=n,n=_+(w+m)|0}r[0]=r[0]+n|0,r[1]=r[1]+i|0,r[2]=r[2]+s|0,r[3]=r[3]+o|0,r[4]=r[4]+a|0,r[5]=r[5]+c|0,r[6]=r[6]+h|0,r[7]=r[7]+f|0},_doFinalize:function(){var t=this._data,r=t.words,n=8*this._nDataBytes,i=8*t.sigBytes;return r[i>>>5]|=128<<24-i%32,r[14+(i+64>>>9<<4)]=e.floor(n/4294967296),r[15+(i+64>>>9<<4)]=n,t.sigBytes=4*r.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(c),t.HmacSHA256=s._createHmacHelper(c)}(Math),n.SHA256)},645:(e,t)=>{t.read=function(e,t,r,n,i){var s,o,a=8*i-n-1,u=(1<<a)-1,l=u>>1,c=-7,h=r?i-1:0,f=r?-1:1,d=e[t+h];for(h+=f,s=d&(1<<-c)-1,d>>=-c,c+=a;c>0;s=256*s+e[t+h],h+=f,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+e[t+h],h+=f,c-=8);if(0===s)s=1-l;else{if(s===u)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,n),s-=l}return(d?-1:1)*o*Math.pow(2,s-n)},t.write=function(e,t,r,n,i,s){var o,a,u,l=8*s-i-1,c=(1<<l)-1,h=c>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,p=n?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=c):(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>=c?(a=0,o=c):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[r+d]=255&a,d+=p,a/=256,i-=8);for(o=o<<i|a,l+=i;l>0;e[r+d]=255&o,d+=p,o/=256,l-=8);e[r+d-p]|=128*g}},826:e=>{var t={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==t.call(e)}},204:(e,t,r)=>{e.exports=self.fetch||(self.fetch=r(869).default||r(869))},808:(e,t,r)=>{var n,i,s;s=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var r=arguments[e];for(var n in r)t[n]=r[n]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function r(n){function i(){}function s(t,r,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(r);/^[\{\[]/.test(o)&&(r=o)}catch(e){}r=n.write?n.write(r,t):encodeURIComponent(String(r)).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+"="+r+a}}function o(e,r){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("=");r||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var l=t(a[0]);if(u=(n.read||n)(u,l)||t(u),r)try{u=JSON.parse(u)}catch(e){}if(i[l]=u,e===l)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,r){s(t,"",e(r,{expires:-1}))},i.defaults={},i.withConverter=r,i}((function(){}))},void 0===(i="function"==typeof(n=s)?n.call(t,r,t,e):n)||(e.exports=i),e.exports=s()},869:(e,t,r)=>{"use strict";function n(e,t){return t=t||{},new Promise((function(r,n){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 l in i.open(t.method||"get",e,!0),i.onload=function(){i.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,r){s.push(t=t.toLowerCase()),o.push([t,r]),a[t]=a[t]?a[t]+","+r:r})),r(u())},i.onerror=n,i.withCredentials="include"==t.credentials,t.headers)i.setRequestHeader(l,t.headers[l]);i.send(t.body||null)}))}r.r(t),r.d(t,{default:()=>n})},296:()=>{},480:()=>{}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}return r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(864)})()));
|
|
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 r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(self,(()=>(()=>{var e={864:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SkapiError=t.Skapi=void 0;const i=n(r(715));t.Skapi=i.default;const s=n(r(246));t.SkapiError=s.default},752:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.formResponse=void 0;const i=n(r(246)),s=r(170);t.formResponse=function(){return function(e,t,r){const n=r.value;r.value=function(...e){let t=e[0],r=(null==e?void 0:e[1])||{};const o=e=>{if(null==r?void 0:r.response){if("function"==typeof r.response)return r.response(e),e;throw new i.default('Callback "response" should be type: function.',{code:"INVALID_PARAMETER"})}if(!(t instanceof HTMLFormElement))return e;let n=new URL(t.action),o=(0,s.sha256)(t.action),a=Date.now().toString();window.sessionStorage.setItem(o,JSON.stringify({[a]:e})),n.searchParams.set(o,a),window.location.href=n.href};let a;function u(e){let t=e instanceof Error?e:new i.default(e);if(null==r?void 0:r.onerror){if("function"==typeof r.onerror)return r.onerror(t);throw new i.default('Callback "onerror" should be type: function.',{code:"INVALID_PARAMETER"})}return t}try{a=n.bind(this)(...e)}catch(e){let t=u(e);if(t instanceof Error)throw t;return t}return a instanceof Promise?new Promise(((e,t)=>{a.then((t=>{e(o(t))})).catch((r=>{(r=u(r))instanceof Error?t(r):e(r)}))})):o(a)}}}},715:function(e,t,r){"use strict";var n=this&&this.__decorate||function(e,t,r,n){var i,s=arguments.length,o=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,n);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(o=(s<3?i(o):s>3?i(t,r,o):i(t,r))||o);return s>3&&o&&Object.defineProperty(t,r,o),o},i=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(i,s){function o(e){try{u(n.next(e))}catch(e){s(e)}}function a(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,a)}u((n=n.apply(e,t||[])).next())}))},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(243),a=s(r(246)),u=r(752),l=r(170);class c{constructor(e,t,r=!1){if(this.cognitoUser=null,this.__disabledAccount=null,this.__serviceHash={},this.__pendingRequest={},this.__cached_requests={},this.__startKey_keys={},this.__request_signup_confirmation=null,this.__index_number_range=4503599627370496,this.__class_properties_has_been_cached=!1,this.session=null,this.user=null,this.connection=null,this.host="skapi",this.hostDomain="skapi.com",this.userPool=null,this.regex={validateUserId(e){try{return(0,l.validateUserId)(e),!0}catch(e){return!1}},validateUrl(e){try{return(0,l.validateUrl)(e),!0}catch(e){return!1}},validatePhoneNumber(e){try{return(0,l.validatePhoneNumber)(e),!0}catch(e){return!1}},validateBirthdate(e){try{return(0,l.validateBirthdate)(e),!0}catch(e){return!1}},validateEmail(e){try{return(0,l.validateEmail)(e),!0}catch(e){return!1}}},this.update_startKey_keys=e=>i(this,void 0,void 0,(function*(){var t;let{hashedParam:r,url:n,response:i}=e,s=null;if(s=i instanceof Promise?yield i:i,"object"!=typeof s||!s.hasOwnProperty("startKey")||!r||!n)return s;this.__startKey_keys.hasOwnProperty(n)||(this.__startKey_keys[n]={}),(null===(t=this.__cached_requests)||void 0===t?void 0:t[n])||(this.__cached_requests[n]={}),this.__cached_requests[n][r]=s,this.__startKey_keys[n].hasOwnProperty(r)||(this.__startKey_keys[n][r]=[]);let o=JSON.stringify(s.startKey);return this.__startKey_keys[n][r].includes(o)||this.__startKey_keys[n][r].push(o),this.__cached_requests[n][r]=s,Object.assign({startKey_list:this.__startKey_keys[n][r]},s)})),this._fetch=(e,t,r)=>i(this,void 0,void 0,(function*(){let n=yield fetch(e,t);if(r){if(200===n.status)return yield n[r]();throw n}let i=yield n.text();try{i=JSON.parse(i)}catch(e){}if(200===n.status){if("object"==typeof i&&"GET"===t.method&&i.hasOwnProperty("body"))try{i=JSON.parse(i.body)}catch(e){}return i}{let e=null==n?void 0:n.status,t=["INVALID_CORS","INVALID_REQUEST","SERVICE_DISABLED","INVALID_PARAMETER","ERROR","EXISTS","NOT_EXISTS"];if("object"==typeof i&&(null==i?void 0:i.message)){let t=(e?e.toString():null)||"ERROR";throw new a.default(null==i?void 0:i.message,{code:t})}if("string"==typeof i){let e=i.split(":"),r=e.splice(0,1)[0];throw new a.default(e.join(""),{code:t.includes(r)?r:"ERROR"})}throw n}})),this._get=(e,t,r)=>i(this,void 0,void 0,(function*(){if(t&&"object"==typeof t&&Object.keys(t).length){"?"!==e.substring(e.length-1)&&(e+="?");let r=Object.keys(t).map((e=>{let r=t[e];return"string"!=typeof r&&(r=JSON.stringify(r)),encodeURIComponent(e)+"="+encodeURIComponent(r)})).join("&");e+=r}let n=null;r.hasOwnProperty("responseType")&&(n=r.responseType,delete r.responseType);let i=Object.assign({method:"GET"},r);return this._fetch(e,i,n)})),"string"!=typeof e||"string"!=typeof t)throw new a.default('"service_id" and "service_owner" should be type <string>.',{code:"INVALID_PARAMETER"});if(!e||!t)throw new a.default('"service_id" and "service_owner" is required',{code:"INVALID_PARAMETER"});t!==this.host&&(0,l.validateUserId)(t,'"service_owner"'),this.service=e,this.service_owner=t;const n="https://dkls9pxkgz855.cloudfront.net";let s=e.substring(0,4);this.admin_endpoint=fetch(`${n}/${s}/admin.json`).then((e=>e.blob())).then((e=>new Promise(((t,r)=>{const n=new FileReader;n.onloadend=()=>t(n.result),n.onerror=r,n.readAsDataURL(e)})))).then((e=>"string"==typeof e?JSON.parse(window.atob(e.split(",")[1])):null)),this.record_endpoint=fetch(`${n}/${s}/record.json`).then((e=>e.blob())).then((e=>new Promise(((t,r)=>{const n=new FileReader;n.onloadend=()=>t(n.result),n.onerror=r,n.readAsDataURL(e)})))).then((e=>"string"==typeof e?JSON.parse(window.atob(e.split(",")[1])):null)),this.__connection=(n=>i(this,void 0,void 0,(function*(){if(!window.sessionStorage)throw new Error("This browser does not support skapi.");const i=JSON.parse(window.sessionStorage.getItem(`${e}#${t}`)||"null");if(null==i?void 0:i.connection)for(let e in i)n[e]=i[e];const s=yield n.admin_endpoint;n.userPool=new o.CognitoUserPool({UserPoolId:s.userpool_id,ClientId:s.userpool_client});const a=[n.updateConnection()];((null==i?void 0:i.connection)||r)&&a.push(n.authentication().updateSession({refreshToken:!!(null==i?void 0:i.connection)}).catch((e=>{n.user=null}))),yield Promise.all(a);const u=()=>{if(n.__class_properties_has_been_cached)return;let r={};const i=["__startKey_keys","__cached_requests","__request_signup_confirmation","connection"];if(n.connection){for(let e of i)r[e]=n[e];sessionStorage.setItem(`${e}#${t}`,JSON.stringify(r)),n.__class_properties_has_been_cached=!0}};return window.addEventListener("beforeunload",u),window.addEventListener("visibilitychange",u),n.connection})))(this).catch((e=>{throw e}))}static connect(e,t,r=!1){return i(this,void 0,void 0,(function*(){const n=new c(e,t,r);return yield n.__connection,n}))}authentication(){if(!this.userPool)throw new a.default("User pool is missing",{code:"INVALID_REQUEST"});const e=e=>{let{refreshToken:t=!1}=e||{};return new Promise(((e,r)=>{var n;let s=(null===(n=this.userPool)||void 0===n?void 0:n.getCurrentUser())||null;this.cognitoUser=s,null===s&&r(null),s.getSession(((n,o)=>{n&&r(n);const u=t=>i(this,void 0,void 0,(function*(){t.isValid()&&s?s.getUserAttributes(((n,i)=>{if(n)r(n);else{let n={},s={};for(let e of i)n[e.Name]=e.Value,s[e.Name.replace("custom:","")]=e.Value,"custom:service"===e.Name&&n[e.Name]!==this.service&&r(new a.default("The user is not registered to the service.",{code:"INVALID_REQUEST"}));for(let e of["address_public","birthdate_public","email_public","email_subscription","gender_public","phone_number_public"])e.includes("_public")?s.hasOwnProperty(e.split("_")[0])?s[e]=s.hasOwnProperty(e)?Number(s[e]):0:delete s[e]:s[e]=s.hasOwnProperty(e)?Number(s[e]):0;for(let e of["email_verified","phone_number_verified"])s[e.split("_")[0]]?s[e]=!!s.hasOwnProperty(e)&&"true"===s[e]:s.hasOwnProperty(e)&&delete s[e];t.attributes=n,this.session=t,s.access_group=Number(this.session.idToken.payload.access_group),s.user_id=s.sub,delete s.sub,this.user=s,e(s)}})):r(new a.default("Invalid session.",{code:"INVALID_REQUEST"}))}));o?t?null==s||s.refreshSession(o.getRefreshToken(),((e,t)=>{e&&r(e),u(t).catch((e=>r(e)))})):u(o).catch((e=>r(e))):r(new a.default("Current session does not exist.",{code:"INVALID_REQUEST"}))}))}))},t=e=>i(this,void 0,void 0,(function*(){let t=null;if(e)t=this.__serviceHash[e]||(yield this.updateConnection({request_hash:e})).hash;else{if(!this.session)throw new a.default("E-Mail is required.",{code:"INVALID_PARAMETER"});t=this.session.idToken.payload["cognito:username"]}return{cognitoUser:new o.CognitoUser({Username:t,Pool:this.userPool}),cognitoUsername:t}}));return{updateSession:e,authenticateUser:(r,n)=>new Promise(((s,u)=>i(this,void 0,void 0,(function*(){this.logout(),this.__request_signup_confirmation=null,this.__disabledAccount=null;let i=yield t(r);this.cognitoUser=i.cognitoUser,r=i.cognitoUsername;let l=new o.AuthenticationDetails({Username:r,Password:n});this.cognitoUser.authenticateUser(l,{newPasswordRequired:(e,t)=>{this.__request_signup_confirmation=r,u(new a.default("User's signup confirmation is required.",{code:"SIGNUP_CONFIRMATION_NEEDED"}))},onSuccess:t=>{e().then((e=>{s(e)}))},onFailure:e=>{let t=[e.message||"Failed to authenticate user.",(null==e?void 0:e.code)||"INVALID_REQUEST"];"NotAuthorizedException"===e.code&&("User is disabled."===e.message?(this.__disabledAccount=r,t=["This account is disabled.","USER_IS_DISABLED"]):t=["Incorrect username or password.","INCORRECT_USERNAME_OR_PASSWORD"]),u(new a.default(t[0],{code:t[1],cause:e}))}})})))),createCognitoUser:t}}requireAdmin(e){var t,r,n,s,o,u;return i(this,void 0,void 0,(function*(){if((null===(r=null===(t=this.session)||void 0===t?void 0:t.attributes)||void 0===r?void 0:r["custom:service"])===this.service){if((null===(s=null===(n=this.session)||void 0===n?void 0:n.attributes)||void 0===s?void 0:s["custom:service_owner"])===this.host){if(!(null==e?void 0:e.ignoreVerification)&&!(null===(u=null===(o=this.session)||void 0===o?void 0:o.attributes)||void 0===u?void 0:u.email_verified))throw new a.default("Email verification is required.",{code:"INVALID_REQUEST"});return!0}if(null==e?void 0:e.throwError)throw new a.default("Admin access is required.",{code:"INVALID_REQUEST"})}else if(this.logout(),null==e?void 0:e.throwError)throw new a.default("User login is required.",{code:"INVALID_REQUEST"});return!1}))}getBlob(e,t){return i(this,void 0,void 0,(function*(){let r=(0,l.checkParams)(e,{url:e=>(0,l.validateUrl)(e)},["url"]);return yield this.request(r.url,t||null,{method:"get",auth:r.url.includes("/auth/"),contentType:null,responseType:"blob"})}))}secureRequest(e){return i(this,void 0,void 0,(function*(){let t={url:e=>(0,l.validateUrl)(e),data:null,sync:["boolean",()=>!0]};if(Array.isArray(e))for(let r of e)r=(0,l.checkParams)(r,t);else e=(0,l.checkParams)(e,t);return yield this.request("post-secure",e,{auth:!0})}))}getFormResponse(){let e=new URLSearchParams(window.location.search);for(let[t,r]of e.entries()){if("form-"!==t.substring(0,5))continue;let e=window.sessionStorage.getItem(t);if(e){window.sessionStorage.removeItem(t);try{e=JSON.parse(e)}catch(e){}}if("object"==typeof e&&e[r])return e[r]}return null}request(e,t=null,r={}){var n,s,o,u,c,h,d,f,p;return i(this,void 0,void 0,(function*(){let{auth:g=!1,method:v="post",meta:y=null,bypassAwaitConnection:m=!1}=r,w=m?null:yield this.__connection,_=g?null===(s=null===(n=this.session)||void 0===n?void 0:n.idToken)||void 0===s?void 0:s.jwtToken:null;if(g&&!_)throw this.logout(),new a.default("User login is required.",{code:"INVALID_REQUEST"});let A="";try{A=(0,l.validateUrl)(e)}catch(e){}let b=A||(yield((e,t)=>i(this,void 0,void 0,(function*(){const r=yield Promise.all([this.admin_endpoint,this.record_endpoint]),n=r[0],i=r[1];return(()=>{switch(e){case"get-serviceletters":case"delete-newsletter":case"block-account":case"register-service":case"get-users":case"post-userdata":case"remove-account":case"post-secure":case"get-newsletters":case"subscribe-newsletter":case"signup":case"confirm-signup":case"recover-account":case"service":return{public:n.admin_public,private:n.admin_private};case"post-record":case"get-records":case"subscription":case"get-subscription":case"del-records":case"get-table":case"get-tag":case"get-index":case"storage-info":return{private:i.record_private,public:i.record_public}}})()[t?"private":"public"]+e})))(e,!!g)),S=(null===(u=null===(o=this.session)||void 0===o?void 0:o.attributes)||void 0===u?void 0:u["custom:service"])||(null==w?void 0:w.service)||this.service,E=(null===(h=null===(c=this.session)||void 0===c?void 0:c.attributes)||void 0===h?void 0:h["custom:service_owner"])||(null==w?void 0:w.owner)||this.service_owner;if(y){if("object"!=typeof y||Array.isArray(y))throw new a.default("Invalid meta data.",{code:"INVALID_REQUEST"});y=JSON.parse(JSON.stringify(y))}if(Array.isArray(t)||t&&"object"!=typeof t)throw new a.default("Request data should be a JSON Object | FormData | HTMLFormElement.",{code:"INVALID_REQUEST"});let I={service:S,service_owner:E},U={},{refresh:R=!1}=r.fetchOptions||{};if(r.fetchOptions&&Object.keys(r.fetchOptions).length){let e=(0,l.checkParams)({limit:(null===(d=null==r?void 0:r.fetchOptions)||void 0===d?void 0:d.limit)||100,startKey:(null===(f=null==r?void 0:r.fetchOptions)||void 0===f?void 0:f.startKey)||null,ascending:"boolean"!=typeof(null===(p=null==r?void 0:r.fetchOptions)||void 0===p?void 0:p.ascending)||r.fetchOptions.ascending},{limit:["number",()=>100],startKey:null,ascending:["boolean",()=>!0]});if(e.hasOwnProperty("limit")&&"number"==typeof e.limit){if(e.limit>1e3)throw new a.default("Fetch limit should be below 1000.",{code:"INVALID_REQUEST"});Object.assign(U,{limit:e.limit})}e.hasOwnProperty("startKey")&&"object"==typeof e.startKey&&e.startKey&&Object.keys(e.startKey)&&Object.assign(U,{startKey:e.startKey}),e.hasOwnProperty("ascending")&&"boolean"==typeof e.ascending&&Object.assign(U,{ascending:e.ascending})}Object.assign(I,U);let D=(0,l.extractFormMetaData)(t),T=null==D?void 0:D.meta,C=(null==D?void 0:D.files)||[],P=(e,t,n=!1)=>i(this,void 0,void 0,(function*(){var i,s;if(null===t)return e;let o=!1;if(e instanceof HTMLFormElement&&(e=new FormData(e),o=!0),!(e instanceof FormData))return e;if(n)for(let t in I)void 0!==I[t]&&e.set(t,"string"==typeof I[t]?I[t]:new Blob([JSON.stringify(I[t])],{type:"application/json"}));for(let r in t)void 0!==t[r]&&e[C.includes(r)?"append":"set"](r,"string"==typeof t[r]?t[r]:new Blob([JSON.stringify(t[r])],{type:"application/json"}));if(null===(i=null==r?void 0:r.fetchOptions)||void 0===i?void 0:i.formData){if("function"!=typeof(null===(s=null==r?void 0:r.fetchOptions)||void 0===s?void 0:s.formData))throw new a.default('Callback "formData" should type: function.',{code:"INVALID_PARAMETER"});{if(!o)throw new a.default("Form data should be HTMLFormElement when formData() callback is used.",{code:"INVALID_PARAMETER"});let t=r.fetchOptions.formData(e);if(t instanceof Promise&&(t=yield t),!(t instanceof FormData))throw new a.default("Callback for extractFormData() should return FormData",{code:"INVALID_PARAMETER"});e=t}}return e}));y?(y=Object.assign(I,y),t=yield P(t,T)):t=t||null!==T?T?yield P(t,T,!0):Object.assign(I,t):I;let k=this.load_startKey_keys({params:t,url:A||e,refresh:!!T||R});if(k&&"object"==typeof k)return k;if("string"==typeof k){if(!(this.__pendingRequest[k]instanceof Promise)){let e={Accept:"*/*"};_&&(e.Authorization=_),y&&(e["Content-Meta"]=JSON.stringify(y)),r.hasOwnProperty("contentType")?(null==r?void 0:r.contentType)&&(e["Content-Type"]=r.contentType):t instanceof FormData||(e["Content-Type"]="application/json");let n={headers:e};(null==r?void 0:r.responseType)&&(n.responseType=r.responseType),"post"===v?this.__pendingRequest[k]=this._post(b,t,n):"get"===v&&(this.__pendingRequest[k]=this._get(b,t,n))}try{let t=yield this.__pendingRequest[k];return T?t:yield this.update_startKey_keys({hashedParam:k,url:e,response:t})}catch(e){throw e}finally{k&&this.__pendingRequest.hasOwnProperty(k)&&delete this.__pendingRequest[k]}}}))}load_startKey_keys(e){var t,r,n,i,s,o,u,c,h,d,f,p,g,v;let{params:y={},url:m,refresh:w=!1}=e||{};if(y.hasOwnProperty("startKey")){if("object"!=typeof y.startKey&&!Object.keys(y.startKey).length||"end"!==y.startKey)throw new a.default(`"${y.startKey}" is invalid startKey key.`,{code:"INVALID_PARAMETER"});switch(y.startKey){case"end":return{list:[],startKey:"end",endOfList:!0};case"start":delete y.startKey}}let _=(0,l.sha256)((()=>{if(y&&"object"==typeof y&&Object.keys(y).length){let e=JSON.parse(JSON.stringify(y));function t(e){function t(e){return"object"==typeof e&&e?Object.keys(e).sort().reduce(((t,r)=>(t[r]=e[r],t)),{}):e}let r=t(e);for(let n in r)r[n]&&"object"==typeof r[n]&&(r[n]=t(e[n]));return r}return JSON.stringify(t(e))+m+this.service}return m+this.service})());if(w&&(null===(r=null===(t=this.__startKey_keys)||void 0===t?void 0:t[m])||void 0===r?void 0:r[_])){if((null===(n=this.__cached_requests)||void 0===n?void 0:n[m])&&(null===(s=null===(i=this.__cached_requests)||void 0===i?void 0:i[m])||void 0===s?void 0:s[_])&&delete this.__cached_requests[m][_],Array.isArray(this.__startKey_keys[m][_])&&this.__startKey_keys[m][_].length)for(let e of this.__startKey_keys[m][_]){let t=_+(0,l.sha256)(JSON.stringify(e));(null===(o=this.__cached_requests)||void 0===o?void 0:o[m])&&(null===(c=null===(u=this.__cached_requests)||void 0===u?void 0:u[m])||void 0===c?void 0:c[t])&&delete this.__cached_requests[m][t]}return delete this.__startKey_keys[m][_],_}if(!Array.isArray(null===(d=null===(h=this.__startKey_keys)||void 0===h?void 0:h[m])||void 0===d?void 0:d[_]))return _;let A=this.__startKey_keys[m][_],b=A[A.length-1],S=_;if(b){if('"end"'===b)return{list:[],startKey:"end",endOfList:!0};S+=(0,l.sha256)(b),y.startKey=JSON.parse(b)}return(null===(p=null===(f=this.__cached_requests)||void 0===f?void 0:f[m])||void 0===p?void 0:p[S])?null===(v=null===(g=this.__cached_requests)||void 0===g?void 0:g[m])||void 0===v?void 0:v[S]:_}_post(e,t,r){let n=null;r.hasOwnProperty("responseType")&&(n=r.responseType,delete r.responseType);let i=Object.assign({method:"POST"},r,{body:t instanceof FormData?t:JSON.stringify(t)});return this._fetch(e,i,n)}postRecord(e,t){var r,n;return i(this,void 0,void 0,(function*(){let i=yield this.requireAdmin({ignoreVerification:!0}),{formData:s}=t,o={};if("function"==typeof s&&(o.formData=s),delete(t=(0,l.checkParams)(t||{},{record_id:"string",access_group:["number","private"],table:["string",()=>{if(!(null==t?void 0:t.record_id))throw new a.default('Either "record_id" or "table" should have a value.',{code:"INVALID_PARAMETER"})}],subscription_group:"number",reference:"string",index:{name:"string",value:["string","number","boolean"]},tags:e=>{if(null===e)return e;if("string"==typeof e)return[e];if(Array.isArray(e)){for(let t of e)if("string"!=typeof t)throw new a.default('"tags" should be type: <string | string[]>',{code:"INVALID_PARAMETER"});return e}throw new a.default('"tags" should be type: <string | string[]>',{code:"INVALID_PARAMETER"})},config:{reference_limit:["number",null],allow_multiple_reference:"boolean",private_access:e=>{let t="config.private_access";if(e&&"string"==typeof e&&(e=[e]),!Array.isArray(e))throw new a.default(`"${t}" should be an array of user ID.`,{code:"INVALID_PARAMETER"});for(let r of e)if((0,l.validateUserId)(r,`User ID in "${t}"`),this.user&&r===this.user.user_id)throw new a.default(`"${t}" should not be the uploader's user ID.`,{code:"INVALID_PARAMETER"});return e}}},[],["response","formData","onerror"])).response,delete t.formData,delete t.onerror,null==t?void 0:t.index){if(!(null===(r=t.index)||void 0===r?void 0:r.name)||"string"!=typeof(null===(n=t.index)||void 0===n?void 0:n.name))throw new a.default('"index.name" is required. type: string.',{code:"INVALID_PARAMETER"});if((0,l.checkWhiteSpaceAndSpecialChars)(t.index.name,"index name",!0),!t.index.hasOwnProperty("value"))throw new a.default('"index.value" is required.',{code:"INVALID_PARAMETER"});if("string"==typeof t.index.value)(0,l.checkWhiteSpaceAndSpecialChars)(t.index.value,"index value",!1,!0);else if("number"==typeof t.index.value&&(t.index.value>this.__index_number_range||t.index.value<-this.__index_number_range))throw new a.default(`Number value should be within range -${this.__index_number_range} ~ +${this.__index_number_range}`,{code:"INVALID_PARAMETER"})}if(i){if("private"===(null==t?void 0:t.access_group))throw new a.default("Service owner cannot write private records.",{code:"INVALID_REQUEST"});if(t.hasOwnProperty("subscription_group"))throw new a.default("Service owner cannot write to subscription table.",{code:"INVALID_REQUEST"})}let u={auth:!0},c=null;return e instanceof HTMLFormElement||e instanceof FormData?Object.assign(u,{meta:t}):c=Object.assign({data:e},t),Object.keys(o).length&&Object.assign(u,{fetchOptions:o}),(0,l.normalize_record_data)(yield this.request("post-record",c||e,u))}))}getRecords(e,t){return i(this,void 0,void 0,(function*(){const r={$record_id:"string",$updated:"number",$uploaded:"number",$referenced_count:"number"},n={table:"string",reference:"string",access_group:["number","private"],subscription:{user_id:e=>(0,l.validateUserId)(e,'User ID in "subscription.user_id"'),group:"number"},index:{name:e=>{if("string"!=typeof e)throw new a.default('"index.name" should be type: string.',{code:"INVALID_PARAMETER"});return r.hasOwnProperty(e)?e:(0,l.checkWhiteSpaceAndSpecialChars)(e,"index.name",!0,!1)},value:t=>{var n;if((null===(n=e.index)||void 0===n?void 0:n.name)&&r.hasOwnProperty(e.index.name)){let n=r[e.index.name];if(typeof t===n)return t;throw new a.default(`"index.value" should be type: ${n}.`,{code:"INVALID_PARAMETER"})}if("number"==typeof t){if(t>this.__index_number_range||t<-this.__index_number_range)throw new a.default(`Number value should be within range -${this.__index_number_range} ~ +${this.__index_number_range}`,{code:"INVALID_PARAMETER"});return t}return"boolean"==typeof t?t:(0,l.checkWhiteSpaceAndSpecialChars)(t,"index.value",!1,!0)},condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"],range:t=>{if(!("value"in e.index))throw new a.default('"index.value" is required.',{code:"INVALID_PARAMETER"});if("$record_id"===e.index.name)throw new a.default(`Cannot do "index.range" on ${e.index.name}`,{code:"INVALID_PARAMETER"});if(typeof e.index.value!=typeof t)throw new a.default('"index.range" type should match the type of "index.value".',{code:"INVALID_PARAMETER"});return"string"==typeof t?(0,l.checkWhiteSpaceAndSpecialChars)(t,"index.value"):t}},tags:e=>{if("string"==typeof e)return[e];if(Array.isArray(e)){if(e.length>10)throw new a.default("Cannot query more than 10 tags at once.",{code:"INVALID_REQUEST"});for(let t of e)if("string"!=typeof t)throw new a.default("Tags should be type: <string | string[]>",{code:"INVALID_PARAMETER"});return e}}};if((null==(e=(0,l.checkParams)(e||{},n,["table"]))?void 0:e.subscription)&&!this.session)throw new a.default("Requires login.",{code:"INVALID_REQUEST"});if(null==e?void 0:e.tags){let r=[],n=(null==t?void 0:t.startKey)||null;for(let i of e.tags){let s=JSON.parse(JSON.stringify(e));s.tag=i,delete s.tags;let o=t?JSON.parse(JSON.stringify(t)):null;o&&(delete o.startKey,n&&(null==n?void 0:n[i])&&(o.startKey=n[i])),r.push(this.request("get-records",s,Object.assign({auth:!(!e.hasOwnProperty("access_group")||!("private"===e.access_group||e.access_group>0))||!!this.session},{fetchOptions:o})))}let i=[],s={},o=yield Promise.all(r);for(let t of o){for(let e in t.list)r.includes(t.list[e].rec)||(r.push(t.list[e]),i.push((0,l.normalize_record_data)(t.list[e])));t.startKey&&Array.isArray(e.tags)&&(s[e.tags.splice(0,1)[0]]=t.startKey)}let a=!0;for(let e in s)if(s[e]&&"end"!==s[e]){a=!1;break}return{list:i,endOfList:a,startKey:s}}let i=yield this.request("get-records",e,Object.assign({auth:!(!e.hasOwnProperty("access_group")||!("private"===e.access_group||e.access_group>0))||!!this.user},{fetchOptions:t}));for(let e in i.list)i.list[e]=(0,l.normalize_record_data)(i.list[e]);return i}))}getTable(e,t){return i(this,void 0,void 0,(function*(){let r=yield this.request("get-table",(0,l.checkParams)(e||{},{table:"string",condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}),Object.assign({auth:!0},{fetchOptions:t})),n={cnt_rec:"number_of_records",tbl:"table",srvc:"service"};if(Array.isArray(r.list))for(let e of r.list)for(let t in n)e.hasOwnProperty(t)&&(e[n[t]]=e[t],delete e[t]);return r}))}getIndex(e,t){return i(this,void 0,void 0,(function*(){let r=(0,l.checkParams)(e||{},{table:"string",index:e=>(0,l.checkWhiteSpaceAndSpecialChars)(e,"index name",!0,!1),order_by:{name:["average_number","total_number","number_count","average_bool","total_bool","bool_count","string_count","index_name"],value:["string","number","boolean"],condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}},["table"]);if(r.hasOwnProperty("order_by")){if("index_name"===r.order_by){if(!r.hasOwnProperty("index"))throw new a.default('"index" is required for ordered by "index_name".',{code:"INVALID_PARAMETER"});if("."!==r.index.substring(r.index.length-1))throw new a.default('"index" should be parent "index name".',{code:"INVALID_PARAMETER"})}if(r.order_by.hasOwnProperty("condition")&&!r.order_by.hasOwnProperty("value"))throw new a.default('"value" is required for "condition".',{code:"INVALID_PARAMETER"})}let n=yield this.request("get-index",r,Object.assign({auth:!0},{fetchOptions:t})),i={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(n.list)&&(n.list=n.list.map((e=>{let t=e.idx.split("/"),r={table:t[1],index:t[2],number_of_records:e.cnt_rec};for(let t in i)(null==e?void 0:e[t])&&(r[i[t]]=e[t]),(null==r?void 0:r.number_of_number_values)&&(r.average_of_number_values=e.totl_numb/e.cnt_numb),(null==r?void 0:r.number_of_boolean_values)&&(r.average_of_boolean_values=e.totl_bool/e.cnt_bool);return r}))),n}))}getTag(e,t){return i(this,void 0,void 0,(function*(){let r=yield this.request("get-tag",(0,l.checkParams)(e||{},{table:"string",tag:"string",condition:["gt","gte","lt","lte",">",">=","<","<=","=","eq","!=","ne"]}),Object.assign({auth:!0},{fetchOptions:t}));if(Array.isArray(r.list))for(let e in r.list){let t=r.list[e],n=t.tag.split("/");r.list[e]={table:n[1],tag:n[0],number_of_records:t.cnt_rec}}return r}))}deleteRecords(e){return i(this,void 0,void 0,(function*(){let t=yield this.requireAdmin();if(t&&!(null==e?void 0:e.service))throw new a.default("Service ID is required.",{code:"INVALID_PARAMETER"});if(!t&&!(null==e?void 0:e.table))throw new a.default('"table" is required.',{code:"INVALID_PARAMETER"});if(null==e?void 0:e.record_id)return yield this.request("del-records",{service:e.service,record_id:(e=>{let t=(0,l.checkWhiteSpaceAndSpecialChars)(e,"record_id",!1);return"string"==typeof t?[t]:t})(e.record_id)},{auth:!0});{if(!(null==e?void 0:e.table))throw new a.default('Either "table" or "record_id" is required.',{code:"INVALID_PARAMETER"});let r={access_group:["number","private"],table:{name:"string",subscription:e=>{if(t)return(0,l.validateUserId)(e,'User ID in "table.subscription"');throw new a.default('"table.subscription" is an invalid parameter key.',{code:"INVALID_PARAMETER"})},subscription_group:r=>{var n;if(t&&"string"!=typeof(null===(n=null==e?void 0:e.table)||void 0===n?void 0:n.subscription))throw new a.default('"table.subscription" is required.',{code:"INVALID_PARAMETER"});if("number"==typeof r&&r>0&&r<99)return r;throw new a.default("Subscription group should be between 0 ~ 99.",{code:"INVALID_PARAMETER"})}}};e=(0,l.checkParams)(e||{},r,t?["service"]:["table","access_group"])}return yield this.request("del-records",e,{auth:!0})}))}subscribeNewsletter(e,t){return i(this,void 0,void 0,(function*(){let t=(0,l.checkParams)(e||{},{email:e=>(0,l.validateEmail)(e),bypassWelcome:["boolean",()=>!0]},["email"]);return yield this.request("subscribe-newsletter",t)}))}subscriptionGroupCheck(e){return i(this,void 0,void 0,(function*(){if(yield this.__connection,e=(0,l.checkParams)(e,{user_id:e=>(0,l.validateUserId)(e,'"user_id"'),group:e=>{if("*"===e)return e;if("number"!=typeof e)throw new a.default('"group" should be type: number.',{code:"INVALID_PARAMETER"});if(e<1&&e>9)throw new a.default('"group" should be within range 1 ~ 9.',{code:"INVALID_PARAMETER"});return e}},["user_id","group"]),this.user&&e.user_id===this.user.user_id)throw new a.default('"user_id" cannot be the user\'s own ID.',{code:"INVALID_PARAMETER"});return e}))}subscribe(e){return i(this,void 0,void 0,(function*(){let{user_id:t,group:r}=yield this.subscriptionGroupCheck(e);if("*"===r)throw new a.default("Cannot subscribe to all groups at once.",{code:"INVALID_PARAMETER"});return yield this.request("subscription",{subscribe:t,group:r},{auth:!0})}))}unsubscribe(e){return i(this,void 0,void 0,(function*(){let{user_id:t,group:r}=yield this.subscriptionGroupCheck(e);return yield this.request("subscription",{unsubscribe:t,group:r},{auth:!0})}))}blockSubscriber(e){return i(this,void 0,void 0,(function*(){let{user_id:t,group:r}=yield this.subscriptionGroupCheck(e);return yield this.request("subscription",{block:t,group:r},{auth:!0})}))}unblockSubscriber(e){return i(this,void 0,void 0,(function*(){let{user_id:t,group:r}=yield this.subscriptionGroupCheck(e);return yield this.request("subscription",{unblock:t,group:r},{auth:!0})}))}getUserSubscriptions(e){var t;return i(this,void 0,void 0,(function*(){return yield this.__connection,e=(0,l.checkParams)(e,{user_id:e=>{try{return(0,l.validateUserId)(e,'"user_id"')}catch(e){}try{return(0,l.validateEmail)(e)}catch(e){}throw new a.default('"subscriber" should be either valid user ID or E-Mail.',{code:"INVALID_PARAMETER"})},group:"number"})||{},this.getSubscriptions({subscriber:e.user_id||(null===(t=this.user)||void 0===t?void 0:t.user_id),group:e.group})}))}getUserSubscribers(e){var t;return i(this,void 0,void 0,(function*(){yield this.__connection;let r={subscription:(e=(0,l.checkParams)(e,{user_id:e=>(0,l.validateUserId)(e,'"user_id"'),group:"number"})||{}).user_id||(null===(t=this.user)||void 0===t?void 0:t.user_id),group:e.group};return this.getSubscriptions(r)}))}getSubscriptions(e,t,r){return i(this,void 0,void 0,(function*(){let n=!1;if(e=(0,l.checkParams)(e,{subscriber:e=>{try{return(0,l.validateUserId)(e,'User ID in "subscriber"')}catch(e){}try{let t=(0,l.validateEmail)(e);return n=!0,t}catch(e){}throw new a.default('"subscriber" should be either valid user ID or E-Mail.',{code:"INVALID_PARAMETER"})},group:"number",subscription:e=>{try{return(0,l.validateUserId)(e,'User ID in "subscription"')}catch(e){}if("string"==typeof e&&14===e.length)return e;throw new a.default('"subscriber" should be either valid service ID or user ID.',{code:"INVALID_PARAMETER"})},blocked:"boolean"}),n&&!(null==e?void 0:e.subscription)&&(e.subscription=this.service),!e.subscriber&&!e.subscription)throw new a.default('At least either "subscriber" or "subscription" should have a value.',{code:"INVALID_PARAMETER"});let i=yield this.request("get-subscription",e,Object.assign({auth:!n},{fetchOptions:t}));return i.list=i.list.map(r||(e=>{let t={},r=e.sub.split("#");return t.subscriber=r[2],t.subscription=r[0],t.group=parseInt(r[1]),t.timestamp=e.stmp,t.blocked="N"===e.grp.substring(0,1),t})),i}))}getNewsletters(e,t){return i(this,void 0,void 0,(function*(){let r=yield this.requireAdmin(),n={message_id:"string",timestamp:"number",read:"number",complaint:"number",subject:"string"};e||(t||(t={}),t.ascending=!1);let i=e||{searchFor:"timestamp",value:0,condition:">"};e=(0,l.checkParams)(i,{searchFor:["message_id","timestamp","read","complaint","group","subject"],value:e=>{if(typeof e!==n[i.searchFor])throw new a.default(`"value" type does not match the type of "${i.searchFor}" index.`,{code:"INVALID_PARAMETER"});if("string"==typeof e&&!e)throw new a.default('"value" should not be empty string.',{code:"INVALID_PARAMETER"});return e},range:e=>{if(!i.hasOwnProperty("value")||typeof e!=typeof i.value)throw new a.default('"range" should match type of "value".',{code:"INVALID_PARAMETER"});return e},condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],group:e=>{if("newsletter"!==e&&!this.session)throw new a.default("User should be logged in.",{code:"INVALID_REQUEST"});if("string"==typeof e&&"newsletter"!==e)throw new a.default('Group should be either "newsletter" or access group number.',{code:"INVALID_PARAMETER"});if(!r&&e>parseInt(this.session.idToken.payload.access_group))throw new a.default("User has no access.",{code:"INVALID_REQUEST"});return"newsletter"===e?0:e}},["searchFor","value","group"]);let s=yield this.request(0===e.group?"get-newsletters":"get-serviceletters",e,Object.assign({method:"get",auth:0!==e.group},{fetchOptions:t})),o={message_id:"mid",timestamp:"stmp",complaint:"cmpl",read:"read",subject:"subj",bounced:"bnce",url:"url"},u={message_id:"",timestamp:0,complaint:0,read:0,subject:"",bounced:0,url:""};return s.list=s.list.map((e=>{let t={};for(let r in o)t[r]=e[o[r]]||u[o[r]];return t})),s}))}signup(e,t){return i(this,void 0,void 0,(function*(){this.logout();let r=(0,l.checkParams)(e||{},{email:e=>(0,l.validateEmail)(e),password:e=>(0,l.validatePassword)(e),name:"string",address:"string",gender:"string",birthdate:e=>(0,l.validateBirthdate)(e),phone_number:e=>(0,l.validatePhoneNumber)(e),email_public:["boolean",()=>!1],address_public:["boolean",()=>!1],gender_public:["boolean",()=>!1],birthdate_public:["boolean",()=>!1],phone_number_public:["boolean",()=>!1],email_subscription:["boolean",()=>!1]},["email","password"]);t=(0,l.checkParams)(t||{},{confirmation:e=>{if("string"==typeof e)return(0,l.validateUrl)(e);if("boolean"==typeof e)return e;throw new a.default('"option.confirmation" should be type: <string | boolean>.',{code:"INVALID_PARAMETER"})},login:e=>{if("boolean"==typeof e){if(t.confirmation&&e)throw new a.default('"login" is not allowed when "option.confirmation" is true.',{code:"INVALID_PARAMETER"});return e}throw new a.default('"option.login" should be type: boolean.',{code:"INVALID_PARAMETER"})}});let{login:n=!1,confirmation:i=!1}=t||{};if(!i&&r.email_public)throw new a.default('"option.confirmation" should be true if "email_public" is set to true.',{code:"INVALID_PARAMETER"});return yield this.request("signup",r,{meta:t}),i?"SUCCESS: The account has been created. User's email confirmation is required.":n?yield this.login({email:r.email,password:r.password}):"SUCCESS: The account has been created."}))}logout(){this.cognitoUser&&this.cognitoUser.signOut();let e={session:null,__startKey_keys:{},__cached_requests:{},user:null};for(let t in e)this[t]=e[t];return"SUCCESS: The user has been logged out."}resendSignupConfirmation(e=!1){return i(this,void 0,void 0,(function*(){if(e&&"string"==typeof e)e=(0,l.validateUrl)(e);else if("boolean"!=typeof e)throw new a.default("Argument should be type: <boolean | string>.",{code:"INVALID_REQUEST"});if(!this.__request_signup_confirmation)throw new a.default("Least one signin attempt is required.",{code:"INVALID_REQUEST"});let t=yield this.request("confirm-signup",{username:this.__request_signup_confirmation,redirect:e});return this.__request_signup_confirmation=null,t}))}recoverAccount(e=!1){return i(this,void 0,void 0,(function*(){if("string"==typeof e)(0,l.validateUrl)(e);else if("boolean"!=typeof e)throw new a.default("Argument should be type: <boolean | string>.",{code:"INVALID_REQUEST"});if(!this.__disabledAccount)throw new a.default("Least one signin attempt of disabled account is required.",{code:"INVALID_REQUEST"});let t=yield this.request("recover-account",{username:this.__disabledAccount,redirect:e});return this.__disabledAccount=null,t}))}login(e,t){this.logout();let r=(0,l.checkParams)(e,{email:e=>(0,l.validateEmail)(e),password:e=>(0,l.validatePassword)(e)},["email","password"]);return this.authentication().authenticateUser(r.email,r.password)}verifyAttribute(e,t){if(!this.cognitoUser)throw new a.default("The user has to be logged in.",{code:"INVALID_REQUEST"});return new Promise(((r,n)=>{var i,s;let o={onSuccess:i=>{t?this.authentication().updateSession({refreshToken:!0}).then((()=>{this.user&&(this.user[e+"_verified"]=!0),r(`SUCCESS: "${e}" is verified.`)})).catch((e=>{n(e)})):r("SUCCESS: Verification code has been sent.")},onFailure:e=>{n(new a.default(e.message||"Failed to request verification code.",{code:null==e?void 0:e.code}))},inputVerificationCode:null};t?null===(i=this.cognitoUser)||void 0===i||i.verifyAttribute(e,t,o):null===(s=this.cognitoUser)||void 0===s||s.getAttributeVerificationCode(e,o)}))}verifyEmail(e,t){let r=(e?(0,l.checkParams)(e,{code:["number","string"]}):{}).code||"";return this.verifyAttribute("email",r.toString())}verifyMobile(e,t){let r=(e?(0,l.checkParams)(e,{code:["number","string"]}):{}).code||null;return this.verifyAttribute("phone_number",r.toString())}forgotPassword(e,t){return i(this,void 0,void 0,(function*(){yield this.__connection;let t=(0,l.checkParams)(e,{email:e=>(0,l.validateEmail)(e)},["email"]);return new Promise(((e,r)=>i(this,void 0,void 0,(function*(){(yield this.authentication().createCognitoUser(t.email)).cognitoUser.forgotPassword({onSuccess:t=>{e("SUCCESS: Verification code has been sent.")},onFailure:e=>{r(new a.default((null==e?void 0:e.message)||"Failed to send verification code.",{code:(null==e?void 0:e.code)||"ERROR"}))}})}))))}))}resetPassword(e,t){let r=(0,l.checkParams)(e,{email:e=>(0,l.validateEmail)(e),code:["number","string"],new_password:e=>(0,l.validatePassword)(e)},["email","code","new_password"]),n=r.code,s=r.new_password;return"number"==typeof n&&(n=n.toString()),new Promise(((e,t)=>i(this,void 0,void 0,(function*(){(yield this.authentication().createCognitoUser(r.email)).cognitoUser.confirmPassword(n,s,{onSuccess:t=>{e("SUCCESS: New password has been set.")},onFailure:e=>{t(new a.default((null==e?void 0:e.message)||"Failed to reset password.",{code:null==e?void 0:e.code}))}})}))))}disableAccount(){return i(this,void 0,void 0,(function*(){if(yield this.__connection,this.user&&Array.isArray(this.user.services))for(let e of this.user.services)if(e.active)throw new a.default("All services needs to be disabled.",{code:"INVALID_REQUEST"});let e=yield this.request("remove-account",{disable:!0},{auth:!0});return this.logout(),e}))}updateUserSettings(e,t){var r;return i(this,void 0,void 0,(function*(){yield this.__connection;let t=null===(r=this.session)||void 0===r?void 0:r.attributes;if(!t||!this.cognitoUser)throw new a.default("User has to be logged in.",{code:"INVALID_REQUEST"});let n=(0,l.checkParams)(e||{},{email:e=>(0,l.validateEmail)(e),name:"string",address:"string",gender:"string",birthdate:e=>(0,l.validateBirthdate)(e),phone_number:e=>(0,l.validatePhoneNumber)(e),email_public:"boolean",phone_number_public:"boolean",address_public:"boolean",gender_public:"boolean",birthdate_public:"boolean",email_subscription:"boolean",current_password:e=>(0,l.validatePassword)(e),new_password:e=>(0,l.validatePassword)(e)});if(n&&"object"==typeof n&&!Object.keys(n).length)return this.user;if(n.new_password||n.current_password){if(!n.current_password)throw new a.default('"current_password" is needed to change the password.',{code:"INVALID_PARAMETER"});if(!n.new_password)throw new a.default('"new_password" is needed to change password.',{code:"INVALID_PARAMETER"});n.new_password!==n.current_password&&(yield new Promise(((e,t)=>{this.cognitoUser.changePassword(n.current_password,n.new_password,((r,n)=>{r&&t(new a.default((null==r?void 0:r.message)||"Failed to change users password.",{code:(null==r?void 0:r.code)||(null==r?void 0:r.name)})),e(n)}))}))),delete n.current_password,delete n.new_password}if(n.email){let e=yield this.updateConnection({request_hash:n.email});n.preferred_username=e.hash}let i=[["email_subscription","email_verified","User's E-Mail should be verified to set"],["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 e of i)if(n[e[0]]&&!this.user[e[1]])throw new a.default(`${e[2]} "${e[0]}" to true.`,{code:"INVALID_PARAMETER"});let s=["email_public","phone_number_public","address_public","gender_public","birthdate_public","email_subscription"];for(let e in n)if(n[e]===t[e])delete n[e];else if(s.includes(e)){let t=n[e];"boolean"==typeof t&&(t=t?"1":"0"),n["custom:"+e]=t,delete n[e]}if(n&&"object"==typeof n&&Object.keys(n).length){let e=[];for(let t in n)e.push(new o.CognitoUserAttribute({Name:t,Value:n[t]}));yield new Promise(((t,r)=>{var n;null===(n=this.cognitoUser)||void 0===n||n.updateAttributes(e,((e,n)=>{e&&r([(null==e?void 0:e.code)||(null==e?void 0:e.name),(null==e?void 0:e.message)||"Failed to update user settings."]),t(n)}))})),yield this.authentication().updateSession({refreshToken:!0})}return this.user}))}uploadUserData(e,t){return i(this,void 0,void 0,(function*(){let r={auth:!0};return(null==(t=(0,l.checkParams)(t||{},{private:"array"}))?void 0:t.private)&&Object.assign(r,{meta:{__private__:t.private}}),yield this.request("post-userdata",e,r),yield this.authentication().updateSession(),this.user}))}getUsers(e,t){return i(this,void 0,void 0,(function*(){let r=yield this.requireAdmin({ignoreVerification:!0});e||(t||(t={}),t.ascending=!1),e=e||{searchFor:"timestamp",condition:">",value:0};const n={user_id:e=>(0,l.validateUserId)(e),name:"string",email:e=>(0,l.validateEmail)(e),phone_number:e=>(0,l.validatePhoneNumber)(e),address:"string",gender:"string",birthdate:e=>(0,l.validateBirthdate)(e),locale:e=>{if("string"!=typeof e||"string"==typeof e&&e.length>5)throw new a.default('Value of "locale" should be a country code.');return e},subscribers:"number",timestamp:"number",group:"number",email_subscription:e=>{if(!r)throw new a.default('Only admin is allowed to search "email_subscription".',{code:"INVALID_REQUEST"});return e},blocked:e=>e?"by_admin:suspended":"by_admin:approved"};if((null==(e=(0,l.checkParams)(e,{searchFor:["user_id","name","email","phone_number","address","gender","birthdate","locale","subscribers","timestamp","group","email_subscription","blocked"],condition:[">",">=","=","<","<=","gt","gte","eq","lt","lte",()=>"="],value:t=>{let r=n[e.searchFor];if("function"==typeof r)return r(t);if(typeof t!==r)throw new a.default(`Value does not match the type of "${e.searchFor}" index.`,{code:"INVALID_PARAMETER"});return t},range:t=>{let r=n[e.searchFor];if("function"==typeof r)return r(t);if(typeof t!==r)throw new a.default(`Range does not match the type of "${e.searchFor}" index.`,{code:"INVALID_PARAMETER"});return t}},["searchFor","value"]))?void 0:e.condition)&&"="!==(null==e?void 0:e.condition)&&e.hasOwnProperty("range"))throw new a.default("Conditions does not apply on range search.",{code:"INVALID_PARAMETER"});if(["user_id","blocked"].includes(e.searchFor)&&"="!==e.condition)throw new a.default(`Condition is not allowed on "${e.searchFor}"`,{code:"INVALID_PARAMETER"});if("blocked"===e.searchFor&&(e.searchFor="suspended"),"string"==typeof(null==e?void 0:e.value)&&!(null==e?void 0:e.value))throw new a.default("Value should not be an empty string.",{code:"INVALID_PARAMETER"});if("string"==typeof(null==e?void 0:e.searchFor)&&!(null==e?void 0:e.searchFor))throw new a.default('"searchFor" should not be an empty string.',{code:"INVALID_PARAMETER"});let i="user_id"===e.searchFor&&e.value===this.session.idToken.payload.sub;if(r&&!i&&!e.service)throw new a.default("Service ID is required.",{code:"INVALID_PARAMETER"});let s=yield this.request("get-users",e,{auth:!0,fetchOptions:t});if(!s.list[0]||!i||s.list.length>1)return s;let o=s.list[0];Object.assign(o,this.user),o._what_public_see=JSON.parse(JSON.stringify(o));let u=["service","user_id","name","locale","address","birthdate","phone_number","email","gender","subscribers","timestamp","group","log","user_data"];for(let e in o._what_public_see)u.includes(e)||delete o._what_public_see[e];return o}))}updateConnection(e){return i(this,void 0,void 0,(function*(){let t=null,r={};(null==e?void 0:e.request_hash)&&(this.__serviceHash[e.request_hash]?Object.assign(r,{hash:this.__serviceHash[e.request_hash]}):t={request_hash:(0,l.validateEmail)(e.request_hash)}),this.connection&&this.connection.service===this.service&&!t||(null===t&&(t={}),Object.assign(t,{service:this.service,service_owner:this.service_owner})),Object.assign(r,t?yield this.request("service",t,{bypassAwaitConnection:!0}):this.connection),(null==e?void 0:e.request_hash)&&(this.__serviceHash[e.request_hash]=r.hash);let n=JSON.parse(JSON.stringify(r));return delete n.hash,this.connection=n,r}))}}n([(0,u.formResponse)()],c.prototype,"postRecord",null),n([(0,u.formResponse)()],c.prototype,"subscribeNewsletter",null),n([(0,u.formResponse)()],c.prototype,"subscribe",null),n([(0,u.formResponse)()],c.prototype,"unsubscribe",null),n([(0,u.formResponse)()],c.prototype,"blockSubscriber",null),n([(0,u.formResponse)()],c.prototype,"unblockSubscriber",null),n([(0,u.formResponse)()],c.prototype,"signup",null),n([(0,u.formResponse)()],c.prototype,"login",null),n([(0,u.formResponse)()],c.prototype,"verifyEmail",null),n([(0,u.formResponse)()],c.prototype,"verifyMobile",null),n([(0,u.formResponse)()],c.prototype,"forgotPassword",null),n([(0,u.formResponse)()],c.prototype,"resetPassword",null),n([(0,u.formResponse)()],c.prototype,"updateUserSettings",null),n([(0,u.formResponse)()],c.prototype,"uploadUserData",null),t.default=c},246:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});class r extends Error{constructor(e,t){e instanceof Error?(super(e.message||"Something went wrong."),this.cause=e,this.name=e.name,e.hasOwnProperty("code")&&(this.code=e.code)):"string"==typeof e&&(super(e||"Something went wrong."),this.name="SkapiError",this.code="ERROR",t&&(t.code&&(this.code=t.code),t.cause&&(this.cause=t.cause)))}}t.default=r},170:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.sha256=t.validateUrl=t.validatePhoneNumber=t.validatePassword=t.validateEmail=t.validateBirthdate=t.validateUserId=t.extractFormMetaData=t.checkParams=t.normalize_record_data=t.checkWhiteSpaceAndSpecialChars=void 0;const i=n(r(246)),s=function(e){function t(e,t){return e>>>t|e<<32-t}for(var r,n,i=Math.pow,o=i(2,32),a="",u=[],l=8*e.length,c=s.h=s.h||[],h=s.k=s.k||[],d=h.length,f={},p=2;d<64;p++)if(!f[p]){for(r=0;r<313;r+=p)f[r]=p;c[d]=i(p,.5)*o|0,h[d++]=i(p,1/3)*o|0}for(e+="";e.length%64-56;)e+="\0";for(r=0;r<e.length;r++){if((n=e.charCodeAt(r))>>8)return;u[r>>2]|=n<<(3-r)%4*8}for(u[u.length]=l/o|0,u[u.length]=l,n=0;n<u.length;){var g=u.slice(n,n+=16),v=c;for(c=c.slice(0,8),r=0;r<64;r++){var y=g[r-15],m=g[r-2],w=c[0],_=c[4],A=c[7]+(t(_,6)^t(_,11)^t(_,25))+(_&c[5]^~_&c[6])+h[r]+(g[r]=r<16?g[r]:g[r-16]+(t(y,7)^t(y,18)^y>>>3)+g[r-7]+(t(m,17)^t(m,19)^m>>>10)|0);(c=[A+((t(w,2)^t(w,13)^t(w,22))+(w&c[1]^w&c[2]^c[1]&c[2]))|0].concat(c))[4]=c[4]+A|0}for(r=0;r<8;r++)c[r]=c[r]+v[r]|0}for(r=0;r<8;r++)for(n=3;n+1;n--){var b=c[r]>>8*n&255;a+=(b<16?0:"")+b.toString(16)}return a};function o(e){function t(e,t,r,n=!0){e[t]&&n?Array.isArray(e)?e[t].push(r):e[t]=[e[t],r]:e[t]=r}if(e instanceof FormData){let r={},n=0,s=[];for(let i of e.entries()){let e=i[0],o=i[1];if(o instanceof File)s.includes(e)||s.push(e),n+=Math.round(o.size/1024);else if(o instanceof FileList){if(s.includes(e)||s.push(e),o&&o.length>0)for(let e=0;e<=o.length-1;e++)n+=Math.round(o.item(e).size/1024)}else t(r,e,o)}if(n>5120)throw new i.default("Files cannot exceed 5MB. Use skapi.uploadFiles(...) instead.",{code:"INVALID_REQUEST"});return{meta:r,files:s}}if(e instanceof HTMLFormElement){let r={},n=[],s=0,o=e.querySelectorAll("input"),a=e.querySelectorAll("textarea");for(let e of a)e.name&&t(r,e.name,e.value);for(let e of o)if(e.name)if("number"===e.type&&e.value)t(r,e.name,Number(e.value));else if("checkbox"===e.type||"radio"===e.type)"on"===e.value||"true"===e.value?t(r,e.name,e.checked,!1):"false"===e.value?t(r,e.name,!e.checked,!1):e.checked&&t(r,e.name,e.value,!1);else if("file"===e.type){if(n.includes(e.name)||n.push(e.name),e.files&&e.files.length>0)for(let t=0;t<=e.files.length-1;t++)s+=Math.round(e.files.item(t).size/1024)}else t(r,e.name,e.value);if(s>5120)throw new i.default("Files cannot exceed 5MB. Use skapi.uploadFiles(...) instead.",{code:"INVALID_REQUEST"});return{meta:r,files:n}}return null}t.sha256=s,t.checkParams=function e(t,r,n=null,s=[],a=null){var u;function l(e){if(e instanceof Promise)throw new i.default("Parameter should not be a promise",{code:"INVALID_PARAMETER"});return e&&"object"==typeof e&&!Array.isArray(e)&&Object.keys(e).length}Array.isArray(s)&&(s=s.concat(["service","service_owner"]));let c,h=t,d=null,f=a?` in "${a}" is invalid.`:". Parameter should be type <object>.";if(null===a){if(l(h)){h=h instanceof HTMLFormElement||h instanceof FormData?null===(u=o(t))||void 0===u?void 0:u.meta:JSON.parse(JSON.stringify(t));for(let e in h)if(!r.hasOwnProperty(e)&&Array.isArray(s)&&!s.includes(e))throw new i.default(`Key name "${e}" is invalid in parameter.`,{code:"INVALID_PARAMETER"});if(Array.isArray(n)&&n.length)for(let e of n)if(!Object.keys(h).includes(e))throw new i.default(`Key "${e}" is required in parameter.`,{code:"INVALID_PARAMETER"})}else if((p=h)&&"object"==typeof p&&!Array.isArray(p)&&!Object.keys(p).length||void 0===h){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:h}if(null===h)return null}var p;if(l(r)&&l(h)){for(let t in r){let n=r[t];if(h.hasOwnProperty(t)&&void 0!==h[t])h[t]=e(h[t],n,null,null,t);else{let e=Array.isArray(n)&&"function"==typeof n[n.length-1]?n[n.length-1]:null;if(e){let r=e();void 0!==r&&(h[t]=r)}}}c=h}else if(Array.isArray(r))for(let t of r)try{void 0!==typeof h&&"function"!=typeof t&&(c=e(h,t,null,null,a));break}catch(e){if("string"==typeof e&&"BREAK:"===e.substring(0,6)){let t=(e=e.substring(5)).split(":");d=new i.default(t[1],{code:t[0]});break}d=e}else{if("function"==typeof r)return r(h);if("string"==typeof r)if(Array.isArray(h)){if("array"!==r)throw new i.default(`Invalid type "${typeof h}"${f}`,{code:"INVALID_PARAMETER"});for(let e of h)if(!["number","string","boolean"].includes(typeof e)&&null!==e)throw new i.default(`Invalid type "${typeof e}" in "${a}" array value.`,{code:"INVALID_PARAMETER"});c=h}else if(["number","string","boolean","array","function"].includes(r)){if(typeof h===r){if("number"===r&&Math.abs(h)>4503599627370496)throw`BREAK:INVALID_PARAMETER:"${a}" integer value should be within -4503599627370496 ~ +4503599627370546.`;c=h}}else{if(h!==r)throw new i.default(`Value: ${h}${f}`,{code:"INVALID_PARAMETER"});c=h}else null===r&&(c=h)}if(void 0===c&&d)throw d;return c},t.extractFormMetaData=o,t.validateUserId=function(e,t="User ID"){if(!e)throw new i.default(`${t} is empty.`,{code:"INVALID_PARAMETER"});if("string"!=typeof e)throw new i.default(`${t} should be type: string.`,{code:"INVALID_PARAMETER"});if(!e.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 i.default(`${t} is invalid.`,{code:"INVALID_PARAMETER"});return e},t.validatePhoneNumber=function(e){if("string"!=typeof e||"+"!==e.charAt(0)||isNaN(Number(e.substring(1))))throw new i.default('"phone_number" is invalid. The format should be "+00123456789". Type: string.',{code:"INVALID_PARAMETER"});return e},t.validateBirthdate=function(e){if("string"!=typeof e)throw new i.default('"birthdate" is invalid. The format should be "yyyy-mm-dd". Type: string.',{code:"INVALID_PARAMETER"});{let t=new RegExp(/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/);if(10!==e.length||3!==e.split("-").length||!t.test(e))throw new i.default('"birthdate" is invalid. The format should be "yyyy-mm-dd". Type: string.',{code:"INVALID_PARAMETER"})}return e},t.validatePassword=function(e){if(!e)throw new i.default('"password" is empty.',{code:"PASSWORD_REQUIRED"});if("string"!=typeof e)throw new i.default('"password" should be type: string.',{code:"INVALID_PASSWORD"});if(e.length<6)throw new i.default('"password" should be at least 6 characters.',{code:"INVALID_PASSWORD"});if(e.length>60)throw new i.default('"password" can be up to 60 characters max.',{code:"INVALID_PASSWORD"});return e},t.validateEmail=function(e,t="email"){if(!e)throw new i.default(`"${t}" is empty.`,{code:"EMAIL_REQUIRED"});if("string"!=typeof e)throw new i.default(`"${t}"should be type: string.`,{code:"INVALID_EMAIL"});if(e.length<5||e.length>64)throw new i.default(`"${t}" should be at least 5 characters and max 64 characters.`,{code:"INVALID_EMAIL"});if(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(e)&&(e=e.trim()).split("@")[1].split(".").length>=2)return e.toLowerCase();throw new i.default(`"${e}" is an invalid email.`,{code:"INVALID_EMAIL"})},t.validateUrl=function(e){const t=(()=>{var e;let t=(null===(e=null===window||void 0===window?void 0:window.location)||void 0===e?void 0:e.origin)||null;if("file://"===t){t+=window.location.pathname;let e=t.split("/");e.pop(),t=e.join("/")}return t})();let r=e=>{if("string"==typeof e){if("*"===e)return"*";{let r=e.trim();if(!r.includes(" ")&&!r.includes(",")){"/"===r.substring(0,1)&&t&&(r=t+r);let n=null;try{n=new URL(r)}catch(t){throw new i.default(`"${e}" is an invalid url.`,{code:"INVALID_PARAMETER"})}if(n.protocol){let e=n.href;return"/"===e.charAt(e.length-1)&&(e=e.substring(0,e.length-1)),e}}}}throw new i.default(`"${e}" is an invalid url.`,{code:"INVALID_PARAMETER"})};return Array.isArray(e)?e.map((e=>r(e))):r(e)},t.normalize_record_data=function(e){const t={},r={rec:e=>{if(!e)return;t.record_id=e;let r=e.substring(0,8);t.uploaded=parseInt(r,36)},usr:e=>{e&&(t.user_id=e)},tbl:e=>{if(!e)return;let r=e.split("/");t.table=r[0],t.access_group="@@"==r[2]?"private":parseInt(r[2]),(null==r?void 0:r[3])&&(t.subscription={user_id:r[3],group:parseInt(r[4])})},idx:e=>{if(!e)return;let r=e.split("!"),n=r.splice(0,1)[0],s=function(e){let t=e.substring(2);switch(e.substring(0,2)){case"S%":return t;case"N%":return Number(t)-4503599627370496;case"B%":return"1"===t;case"L%":try{return JSON.parse(t)}catch(e){throw new i.default("Value parse error.",{code:"PARSE_ERROR"})}default:return e}}(r.join("!"));t.index={name:n,value:s}},ref:e=>{e&&(t.reference=e.split("/")[0])},tags:e=>{e&&(t.tags=e)},upd:e=>{e&&(t.updated=e)},acpt_mrf:e=>{e&&((null==t?void 0:t.config)||(t.config={}),t.config.allow_multiple_reference=e)},ref_limt:e=>{e&&((null==t?void 0:t.config)||(t.config={}),t.config.reference_limit=e)},rfd:e=>{t.referenced_count=e},prv_acs:e=>{e&&((null==t?void 0:t.config)||(t.config={}),t.config.private_access=e)},data:e=>{let r=e;"!D%{}"===e?r={}:"!L%[]"===e&&(r=[]),t.data=r}};if(e.record_id)return e;for(let t in r)r[t](e[t]);return t},t.checkWhiteSpaceAndSpecialChars=function(e,t="parameter",r=!1,n=!1){let s=(s,o=!1)=>{if("string"!=typeof s)throw new i.default(`${t} should be type: <string | string[]>.`,{code:"INVALID_PARAMETER"});if(!n&&e.includes(" "))throw new i.default(`${t} should not have whitespace.`,{code:"INVALID_PARAMETER"});if(!r&&e.includes("."))throw new i.default(`${t} should not have periods.`,{code:"INVALID_PARAMETER"});if(/[`!@#$%^&*()_+\-=\[\]{};':"\\|,<>\/?~]/.test(s))throw new i.default(`${t} should not have special characters.`,{code:"INVALID_PARAMETER"})};if(Array.isArray(e))for(let t of e)s(t,!0);else s(e,!1);return e}},243:(e,t,r)=>{"use strict";r.r(t),r.d(t,{AuthenticationDetails:()=>i,AuthenticationHelper:()=>T,CognitoAccessToken:()=>k,CognitoIdToken:()=>O,CognitoRefreshToken:()=>M,CognitoUser:()=>$,CognitoUserAttribute:()=>K,CognitoUserPool:()=>ue,CognitoUserSession:()=>V,CookieStorage:()=>ce,DateHelper:()=>q,WordArray:()=>f,appendToCognitoUserAgent:()=>Q});var n,i=function(){function e(e){var t=e||{},r=t.ValidationData,n=t.Username,i=t.Password,s=t.AuthParameters,o=t.ClientMetadata;this.validationData=r||{},this.authParameters=s||{},this.clientMetadata=o||{},this.username=n,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}(),s=r(764),o=r(249),a=r.n(o),u=(r(433),r(153)),l=r.n(u),c=r(10),h=r.n(c);if("undefined"!=typeof window&&window.crypto&&(n=window.crypto),!n&&"undefined"!=typeof window&&window.msCrypto&&(n=window.msCrypto),!n&&void 0!==r.g&&r.g.crypto&&(n=r.g.crypto),!n)try{n=r(296)}catch(e){}function d(){if(n){if("function"==typeof n.getRandomValues)try{return n.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof n.randomBytes)try{return n.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")}var f=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 r=[],n=0;n<t;n+=4)r.push(d());return new e(r,t)},t.toString=function(){return function(e){for(var t=e.words,r=e.sigBytes,n=[],i=0;i<r;i++){var s=t[i>>>2]>>>24-i%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")}(this)},e}();const p=g;function g(e,t){null!=e&&this.fromString(e,t)}function v(){return new g(null)}var y,m="undefined"!=typeof navigator;m&&"Microsoft Internet Explorer"==navigator.appName?(g.prototype.am=function(e,t,r,n,i,s){for(var o=32767&t,a=t>>15;--s>=0;){var u=32767&this[e],l=this[e++]>>15,c=a*u+l*o;i=((u=o*u+((32767&c)<<15)+r[n]+(1073741823&i))>>>30)+(c>>>15)+a*l+(i>>>30),r[n++]=1073741823&u}return i},y=30):m&&"Netscape"!=navigator.appName?(g.prototype.am=function(e,t,r,n,i,s){for(;--s>=0;){var o=t*this[e++]+r[n]+i;i=Math.floor(o/67108864),r[n++]=67108863&o}return i},y=26):(g.prototype.am=function(e,t,r,n,i,s){for(var o=16383&t,a=t>>14;--s>=0;){var u=16383&this[e],l=this[e++]>>14,c=a*u+l*o;i=((u=o*u+((16383&c)<<14)+r[n]+i)>>28)+(c>>14)+a*l,r[n++]=268435455&u}return i},y=28),g.prototype.DB=y,g.prototype.DM=(1<<y)-1,g.prototype.DV=1<<y,g.prototype.FV=Math.pow(2,52),g.prototype.F1=52-y,g.prototype.F2=2*y-52;var w,_,A=new Array;for(w="0".charCodeAt(0),_=0;_<=9;++_)A[w++]=_;for(w="a".charCodeAt(0),_=10;_<36;++_)A[w++]=_;for(w="A".charCodeAt(0),_=10;_<36;++_)A[w++]=_;function b(e){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(e)}function S(e,t){var r=A[e.charCodeAt(t)];return null==r?-1:r}function E(e){var t=v();return t.fromInt(e),t}function I(e){var t,r=1;return 0!=(t=e>>>16)&&(e=t,r+=16),0!=(t=e>>8)&&(e=t,r+=8),0!=(t=e>>4)&&(e=t,r+=4),0!=(t=e>>2)&&(e=t,r+=2),0!=(t=e>>1)&&(e=t,r+=1),r}function U(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 R(e){return s.lW.from((new f).random(e).toString(),"hex")}U.prototype.convert=function(e){var t=v();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(g.ZERO)>0&&this.m.subTo(t,t),t},U.prototype.revert=function(e){var t=v();return e.copyTo(t),this.reduce(t),t},U.prototype.reduce=function(e){for(;e.t<=this.mt2;)e[e.t++]=0;for(var t=0;t<this.m.t;++t){var r=32767&e[t],n=r*this.mpl+((r*this.mph+(e[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(e[r=t+this.m.t]+=this.m.am(0,n,e,t,0,this.m.t);e[r]>=e.DV;)e[r]-=e.DV,e[++r]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)},U.prototype.mulTo=function(e,t,r){e.multiplyTo(t,r),this.reduce(r)},U.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},g.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},g.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},g.prototype.fromString=function(e,t){var r;if(16==t)r=4;else if(8==t)r=3;else if(2==t)r=1;else if(32==t)r=5;else{if(4!=t)throw new Error("Only radix 2, 4, 8, 16, 32 are supported");r=2}this.t=0,this.s=0;for(var n=e.length,i=!1,s=0;--n>=0;){var o=S(e,n);o<0?"-"==e.charAt(n)&&(i=!0):(i=!1,0==s?this[this.t++]=o:s+r>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+=r)>=this.DB&&(s-=this.DB))}this.clamp(),i&&g.ZERO.subTo(this,this)},g.prototype.clamp=function(){for(var e=this.s&this.DM;this.t>0&&this[this.t-1]==e;)--this.t},g.prototype.dlShiftTo=function(e,t){var r;for(r=this.t-1;r>=0;--r)t[r+e]=this[r];for(r=e-1;r>=0;--r)t[r]=0;t.t=this.t+e,t.s=this.s},g.prototype.drShiftTo=function(e,t){for(var r=e;r<this.t;++r)t[r-e]=this[r];t.t=Math.max(this.t-e,0),t.s=this.s},g.prototype.lShiftTo=function(e,t){var r,n=e%this.DB,i=this.DB-n,s=(1<<i)-1,o=Math.floor(e/this.DB),a=this.s<<n&this.DM;for(r=this.t-1;r>=0;--r)t[r+o+1]=this[r]>>i|a,a=(this[r]&s)<<n;for(r=o-1;r>=0;--r)t[r]=0;t[o]=a,t.t=this.t+o+1,t.s=this.s,t.clamp()},g.prototype.rShiftTo=function(e,t){t.s=this.s;var r=Math.floor(e/this.DB);if(r>=this.t)t.t=0;else{var n=e%this.DB,i=this.DB-n,s=(1<<n)-1;t[0]=this[r]>>n;for(var o=r+1;o<this.t;++o)t[o-r-1]|=(this[o]&s)<<i,t[o-r]=this[o]>>n;n>0&&(t[this.t-r-1]|=(this.s&s)<<i),t.t=this.t-r,t.clamp()}},g.prototype.subTo=function(e,t){for(var r=0,n=0,i=Math.min(e.t,this.t);r<i;)n+=this[r]-e[r],t[r++]=n&this.DM,n>>=this.DB;if(e.t<this.t){for(n-=e.s;r<this.t;)n+=this[r],t[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<e.t;)n-=e[r],t[r++]=n&this.DM,n>>=this.DB;n-=e.s}t.s=n<0?-1:0,n<-1?t[r++]=this.DV+n:n>0&&(t[r++]=n),t.t=r,t.clamp()},g.prototype.multiplyTo=function(e,t){var r=this.abs(),n=e.abs(),i=r.t;for(t.t=i+n.t;--i>=0;)t[i]=0;for(i=0;i<n.t;++i)t[i+r.t]=r.am(0,n[i],t,i,0,r.t);t.s=0,t.clamp(),this.s!=e.s&&g.ZERO.subTo(t,t)},g.prototype.squareTo=function(e){for(var t=this.abs(),r=e.t=2*t.t;--r>=0;)e[r]=0;for(r=0;r<t.t-1;++r){var n=t.am(r,t[r],e,2*r,0,1);(e[r+t.t]+=t.am(r+1,2*t[r],e,2*r+1,n,t.t-r-1))>=t.DV&&(e[r+t.t]-=t.DV,e[r+t.t+1]=1)}e.t>0&&(e[e.t-1]+=t.am(r,t[r],e,2*r,0,1)),e.s=0,e.clamp()},g.prototype.divRemTo=function(e,t,r){var n=e.abs();if(!(n.t<=0)){var i=this.abs();if(i.t<n.t)return null!=t&&t.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=v());var s=v(),o=this.s,a=e.s,u=this.DB-I(n[n.t-1]);u>0?(n.lShiftTo(u,s),i.lShiftTo(u,r)):(n.copyTo(s),i.copyTo(r));var l=s.t,c=s[l-1];if(0!=c){var h=c*(1<<this.F1)+(l>1?s[l-2]>>this.F2:0),d=this.FV/h,f=(1<<this.F1)/h,p=1<<this.F2,y=r.t,m=y-l,w=null==t?v():t;for(s.dlShiftTo(m,w),r.compareTo(w)>=0&&(r[r.t++]=1,r.subTo(w,r)),g.ONE.dlShiftTo(l,w),w.subTo(s,s);s.t<l;)s[s.t++]=0;for(;--m>=0;){var _=r[--y]==c?this.DM:Math.floor(r[y]*d+(r[y-1]+p)*f);if((r[y]+=s.am(0,_,r,m,0,l))<_)for(s.dlShiftTo(m,w),r.subTo(w,r);r[y]<--_;)r.subTo(w,r)}null!=t&&(r.drShiftTo(l,t),o!=a&&g.ZERO.subTo(t,t)),r.t=l,r.clamp(),u>0&&r.rShiftTo(u,r),o<0&&g.ZERO.subTo(r,r)}}},g.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},g.prototype.addTo=function(e,t){for(var r=0,n=0,i=Math.min(e.t,this.t);r<i;)n+=this[r]+e[r],t[r++]=n&this.DM,n>>=this.DB;if(e.t<this.t){for(n+=e.s;r<this.t;)n+=this[r],t[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<e.t;)n+=e[r],t[r++]=n&this.DM,n>>=this.DB;n+=e.s}t.s=n<0?-1:0,n>0?t[r++]=n:n<-1&&(t[r++]=this.DV+n),t.t=r,t.clamp()},g.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 r,n=(1<<t)-1,i=!1,s="",o=this.t,a=this.DB-o*this.DB%t;if(o-- >0)for(a<this.DB&&(r=this[o]>>a)>0&&(i=!0,s=b(r));o>=0;)a<t?(r=(this[o]&(1<<a)-1)<<t-a,r|=this[--o]>>(a+=this.DB-t)):(r=this[o]>>(a-=t)&n,a<=0&&(a+=this.DB,--o)),r>0&&(i=!0),i&&(s+=b(r));return i?s:"0"},g.prototype.negate=function(){var e=v();return g.ZERO.subTo(this,e),e},g.prototype.abs=function(){return this.s<0?this.negate():this},g.prototype.compareTo=function(e){var t=this.s-e.s;if(0!=t)return t;var r=this.t;if(0!=(t=r-e.t))return this.s<0?-t:t;for(;--r>=0;)if(0!=(t=this[r]-e[r]))return t;return 0},g.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+I(this[this.t-1]^this.s&this.DM)},g.prototype.mod=function(e){var t=v();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(g.ZERO)>0&&e.subTo(t,t),t},g.prototype.equals=function(e){return 0==this.compareTo(e)},g.prototype.add=function(e){var t=v();return this.addTo(e,t),t},g.prototype.subtract=function(e){var t=v();return this.subTo(e,t),t},g.prototype.multiply=function(e){var t=v();return this.multiplyTo(e,t),t},g.prototype.divide=function(e){var t=v();return this.divRemTo(e,t,null),t},g.prototype.modPow=function(e,t,r){var n,i=e.bitLength(),s=E(1),o=new U(t);if(i<=0)return s;n=i<18?1:i<48?3:i<144?4:i<768?5:6;var a=new Array,u=3,l=n-1,c=(1<<n)-1;if(a[1]=o.convert(this),n>1){var h=v();for(o.sqrTo(a[1],h);u<=c;)a[u]=v(),o.mulTo(h,a[u-2],a[u]),u+=2}var d,f,p=e.t-1,g=!0,y=v();for(i=I(e[p])-1;p>=0;){for(i>=l?d=e[p]>>i-l&c:(d=(e[p]&(1<<i+1)-1)<<l-i,p>0&&(d|=e[p-1]>>this.DB+i-l)),u=n;0==(1&d);)d>>=1,--u;if((i-=u)<0&&(i+=this.DB,--p),g)a[d].copyTo(s),g=!1;else{for(;u>1;)o.sqrTo(s,y),o.sqrTo(y,s),u-=2;u>0?o.sqrTo(s,y):(f=s,s=y,y=f),o.mulTo(y,a[d],s)}for(;p>=0&&0==(e[p]&1<<i);)o.sqrTo(s,y),f=s,s=y,y=f,--i<0&&(i=this.DB-1,--p)}var m=o.revert(s);return r(null,m),m},g.ZERO=E(0),g.ONE=E(1);var D=/^[89a-f]/i,T=function(){function e(e){this.N=new p("FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF",16),this.g=new p("2",16),this.k=new p(this.hexHash(""+this.padHex(this.N)+this.padHex(this.g)),16),this.smallAValue=this.generateRandomSmallA(),this.getLargeAValue((function(){})),this.infoBits=s.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(r,n){r&&e(r,null),t.largeAValue=n,e(null,t.largeAValue)}))},t.generateRandomSmallA=function(){var e=R(128).toString("hex");return new p(e,16)},t.generateRandomString=function(){return R(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,r){var n=this;this.randomPassword=this.generateRandomString();var i=""+e+t+":"+this.randomPassword,s=this.hash(i),o=R(16).toString("hex");this.SaltToHashDevices=this.padHex(new p(o,16)),this.g.modPow(new p(this.hexHash(this.SaltToHashDevices+s),16),this.N,(function(e,t){e&&r(e,null),n.verifierDevices=n.padHex(t),r(null,null)}))},t.calculateA=function(e,t){var r=this;this.g.modPow(e,this.N,(function(e,n){e&&t(e,null),n.mod(r.N).equals(p.ZERO)&&t(new Error("Illegal paramater. A mod N cannot be 0."),null),t(null,n)}))},t.calculateU=function(e,t){return this.UHexHash=this.hexHash(this.padHex(e)+this.padHex(t)),new p(this.UHexHash,16)},t.hash=function(e){var t=e instanceof s.lW?a().lib.WordArray.create(e):e,r=l()(t).toString();return new Array(64-r.length).join("0")+r},t.hexHash=function(e){return this.hash(s.lW.from(e,"hex"))},t.computehkdf=function(e,t){var r=a().lib.WordArray.create(s.lW.concat([this.infoBits,s.lW.from(String.fromCharCode(1),"utf8")])),n=e instanceof s.lW?a().lib.WordArray.create(e):e,i=t instanceof s.lW?a().lib.WordArray.create(t):t,o=h()(n,i),u=h()(r,o);return s.lW.from(u.toString(),"hex").slice(0,16)},t.getPasswordAuthenticationKey=function(e,t,r,n,i){var o=this;if(r.mod(this.N).equals(p.ZERO))throw new Error("B cannot be zero.");if(this.UValue=this.calculateU(this.largeAValue,r),this.UValue.equals(p.ZERO))throw new Error("U cannot be zero.");var a=""+this.poolName+e+":"+t,u=this.hash(a),l=new p(this.hexHash(this.padHex(n)+u),16);this.calculateS(l,r,(function(e,t){e&&i(e,null);var r=o.computehkdf(s.lW.from(o.padHex(t),"hex"),s.lW.from(o.padHex(o.UValue),"hex"));i(null,r)}))},t.calculateS=function(e,t,r){var n=this;this.g.modPow(e,this.N,(function(i,s){i&&r(i,null),t.subtract(n.k.multiply(s)).modPow(n.smallAValue.add(n.UValue.multiply(e)),n.N,(function(e,t){e&&r(e,null),r(null,t.mod(n.N))}))}))},t.getNewPasswordRequiredChallengeUserAttributePrefix=function(){return"userAttributes."},t.padHex=function(e){if(!(e instanceof p))throw new Error("Not a BigInteger");var t=e.compareTo(p.ZERO)<0,r=e.abs().toString(16);if(r=r.length%2!=0?"0"+r:r,r=D.test(r)?"00"+r:r,t){var n=r.split("").map((function(e){var t=15&~parseInt(e,16);return"0123456789ABCDEF".charAt(t)})).join("");(r=new p(n,16).add(p.ONE).toString(16)).toUpperCase().startsWith("FF8")&&(r=r.substring(2))}return r},e}(),C=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(s.lW.from(e,"base64").toString("utf8"))}catch(e){return{}}},e}();function P(e,t){return P=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},P(e,t)}var k=function(e){var t,r;function n(t){var r=(void 0===t?{}:t).AccessToken;return e.call(this,r||"")||this}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,P(t,r),n}(C);function N(e,t){return N=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},N(e,t)}var O=function(e){var t,r;function n(t){var r=(void 0===t?{}:t).IdToken;return e.call(this,r||"")||this}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,N(t,r),n}(C),M=function(){function e(e){var t=(void 0===e?{}:e).RefreshToken;this.token=t||""}return e.prototype.getToken=function(){return this.token},e}(),F=r(269),x=r.n(F),V=function(){function e(e){var t=void 0===e?{}:e,r=t.IdToken,n=t.RefreshToken,i=t.AccessToken,s=t.ClockDrift;if(null==i||null==r)throw new Error("Id token and Access Token must be present.");this.idToken=r,this.refreshToken=n,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}(),L=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],B=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],q=function(){function e(){}return e.prototype.getNowString=function(){var e=new Date,t=B[e.getUTCDay()],r=L[e.getUTCMonth()],n=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+" "+r+" "+n+" "+i+":"+s+":"+o+" UTC "+e.getUTCFullYear()},e}(),K=function(){function e(e){var t=void 0===e?{}:e,r=t.Name,n=t.Value;this.Name=r||"",this.Value=n||""}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}(),j={},W=function(){function e(){}return e.setItem=function(e,t){return j[e]=t,j[e]},e.getItem=function(e){return Object.prototype.hasOwnProperty.call(j,e)?j[e]:void 0},e.removeItem=function(e){return delete j[e]},e.clear=function(){return j={}},e}(),H=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=W}}return e.prototype.getStorage=function(){return this.storageWindow},e}(),J="undefined"!=typeof navigator?navigator.userAgent:"nodejs",$=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 H).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 r=this,n=e.getAuthParameters();n.USERNAME=this.username;var i=0!==Object.keys(e.getValidationData()).length?e.getValidationData():e.getClientMetadata(),s={AuthFlow:"CUSTOM_AUTH",ClientId:this.pool.getClientId(),AuthParameters:n,ClientMetadata:i};this.getUserContextData()&&(s.UserContextData=this.getUserContextData()),this.client.request("InitiateAuth",s,(function(e,n){if(e)return t.onFailure(e);var i=n.ChallengeName,s=n.ChallengeParameters;return"CUSTOM_CHALLENGE"===i?(r.Session=n.Session,t.customChallenge(s)):(r.signInUserSession=r.getCognitoUserSession(n.AuthenticationResult),r.cacheTokens(),t.onSuccess(r.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 r,n,i=this,o=new T(this.pool.getUserPoolName()),u=new q,l={};null!=this.deviceKey&&(l.DEVICE_KEY=this.deviceKey),l.USERNAME=this.username,o.getLargeAValue((function(c,d){c&&t.onFailure(c),l.SRP_A=d.toString(16),"CUSTOM_AUTH"===i.authenticationFlowType&&(l.CHALLENGE_NAME="SRP_A");var f=0!==Object.keys(e.getValidationData()).length?e.getValidationData():e.getClientMetadata(),g={AuthFlow:i.authenticationFlowType,ClientId:i.pool.getClientId(),AuthParameters:l,ClientMetadata:f};i.getUserContextData(i.username)&&(g.UserContextData=i.getUserContextData(i.username)),i.client.request("InitiateAuth",g,(function(l,c){if(l)return t.onFailure(l);var d=c.ChallengeParameters;i.username=d.USER_ID_FOR_SRP,i.userDataKey=i.keyPrefix+"."+i.username+".userData",r=new p(d.SRP_B,16),n=new p(d.SALT,16),i.getCachedDeviceKeyAndPassword(),o.getPasswordAuthenticationKey(i.username,e.getPassword(),r,n,(function(e,r){e&&t.onFailure(e);var n=u.getNowString(),l=a().lib.WordArray.create(s.lW.concat([s.lW.from(i.pool.getUserPoolName(),"utf8"),s.lW.from(i.username,"utf8"),s.lW.from(d.SECRET_BLOCK,"base64"),s.lW.from(n,"utf8")])),p=a().lib.WordArray.create(r),g=x().stringify(h()(l,p)),v={};v.USERNAME=i.username,v.PASSWORD_CLAIM_SECRET_BLOCK=d.SECRET_BLOCK,v.TIMESTAMP=n,v.PASSWORD_CLAIM_SIGNATURE=g,null!=i.deviceKey&&(v.DEVICE_KEY=i.deviceKey);var y={ChallengeName:"PASSWORD_VERIFIER",ClientId:i.pool.getClientId(),ChallengeResponses:v,Session:c.Session,ClientMetadata:f};i.getUserContextData()&&(y.UserContextData=i.getUserContextData()),function e(t,r){return i.client.request("RespondToAuthChallenge",t,(function(n,s){return n&&"ResourceNotFoundException"===n.code&&-1!==n.message.toLowerCase().indexOf("device")?(v.DEVICE_KEY=null,i.deviceKey=null,i.randomPassword=null,i.deviceGroupKey=null,i.clearCachedDeviceKeyAndPassword(),e(t,r)):r(n,s)}))}(y,(function(e,r){return e?t.onFailure(e):i.authenticateUserInternal(r,o,t)}))}))}))}))},t.authenticateUserPlainUsernamePassword=function(e,t){var r=this,n={};if(n.USERNAME=this.username,n.PASSWORD=e.getPassword(),n.PASSWORD){var i=new T(this.pool.getUserPoolName());this.getCachedDeviceKeyAndPassword(),null!=this.deviceKey&&(n.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:n,ClientMetadata:s};this.getUserContextData(this.username)&&(o.UserContextData=this.getUserContextData(this.username)),this.client.request("InitiateAuth",o,(function(e,n){return e?t.onFailure(e):r.authenticateUserInternal(n,i,t)}))}else t.onFailure(new Error("PASSWORD parameter is required"))},t.authenticateUserInternal=function(e,t,r){var n=this,i=e.ChallengeName,o=e.ChallengeParameters;if("SMS_MFA"===i)return this.Session=e.Session,r.mfaRequired(i,o);if("SELECT_MFA_TYPE"===i)return this.Session=e.Session,r.selectMFAType(i,o);if("MFA_SETUP"===i)return this.Session=e.Session,r.mfaSetup(i,o);if("SOFTWARE_TOKEN_MFA"===i)return this.Session=e.Session,r.totpRequired(i,o);if("CUSTOM_CHALLENGE"===i)return this.Session=e.Session,r.customChallenge(o);if("NEW_PASSWORD_REQUIRED"===i){this.Session=e.Session;var a=null,u=null,l=[],c=t.getNewPasswordRequiredChallengeUserAttributePrefix();if(o&&(a=JSON.parse(e.ChallengeParameters.userAttributes),u=JSON.parse(e.ChallengeParameters.requiredAttributes)),u)for(var h=0;h<u.length;h++)l[h]=u[h].substr(c.length);return r.newPasswordRequired(a,l)}if("DEVICE_SRP_AUTH"===i)return this.Session=e.Session,void this.getDeviceResponse(r);this.signInUserSession=this.getCognitoUserSession(e.AuthenticationResult),this.challengeName=i,this.cacheTokens();var d=e.AuthenticationResult.NewDeviceMetadata;if(null==d)return r.onSuccess(this.signInUserSession);t.generateHashDevice(e.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,e.AuthenticationResult.NewDeviceMetadata.DeviceKey,(function(i){if(i)return r.onFailure(i);var o={Salt:s.lW.from(t.getSaltDevices(),"hex").toString("base64"),PasswordVerifier:s.lW.from(t.getVerifierDevices(),"hex").toString("base64")};n.verifierDevices=o.PasswordVerifier,n.deviceGroupKey=d.DeviceGroupKey,n.randomPassword=t.getRandomPassword(),n.client.request("ConfirmDevice",{DeviceKey:d.DeviceKey,AccessToken:n.signInUserSession.getAccessToken().getJwtToken(),DeviceSecretVerifierConfig:o,DeviceName:J},(function(t,i){return t?r.onFailure(t):(n.deviceKey=e.AuthenticationResult.NewDeviceMetadata.DeviceKey,n.cacheDeviceKeyAndPassword(),!0===i.UserConfirmationNecessary?r.onSuccess(n.signInUserSession,i.UserConfirmationNecessary):r.onSuccess(n.signInUserSession))}))}))},t.completeNewPasswordChallenge=function(e,t,r,n){var i=this;if(!e)return r.onFailure(new Error("New password is required."));var s=new T(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:n};this.getUserContextData()&&(u.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",u,(function(e,t){return e?r.onFailure(e):i.authenticateUserInternal(t,s,r)}))},t.getDeviceResponse=function(e,t){var r=this,n=new T(this.deviceGroupKey),i=new q,o={};o.USERNAME=this.username,o.DEVICE_KEY=this.deviceKey,n.getLargeAValue((function(u,l){u&&e.onFailure(u),o.SRP_A=l.toString(16);var c={ChallengeName:"DEVICE_SRP_AUTH",ClientId:r.pool.getClientId(),ChallengeResponses:o,ClientMetadata:t,Session:r.Session};r.getUserContextData()&&(c.UserContextData=r.getUserContextData()),r.client.request("RespondToAuthChallenge",c,(function(t,o){if(t)return e.onFailure(t);var u=o.ChallengeParameters,l=new p(u.SRP_B,16),c=new p(u.SALT,16);n.getPasswordAuthenticationKey(r.deviceKey,r.randomPassword,l,c,(function(t,n){if(t)return e.onFailure(t);var l=i.getNowString(),c=a().lib.WordArray.create(s.lW.concat([s.lW.from(r.deviceGroupKey,"utf8"),s.lW.from(r.deviceKey,"utf8"),s.lW.from(u.SECRET_BLOCK,"base64"),s.lW.from(l,"utf8")])),d=a().lib.WordArray.create(n),f=x().stringify(h()(c,d)),p={};p.USERNAME=r.username,p.PASSWORD_CLAIM_SECRET_BLOCK=u.SECRET_BLOCK,p.TIMESTAMP=l,p.PASSWORD_CLAIM_SIGNATURE=f,p.DEVICE_KEY=r.deviceKey;var g={ChallengeName:"DEVICE_PASSWORD_VERIFIER",ClientId:r.pool.getClientId(),ChallengeResponses:p,Session:o.Session};r.getUserContextData()&&(g.UserContextData=r.getUserContextData()),r.client.request("RespondToAuthChallenge",g,(function(t,n){return t?e.onFailure(t):(r.signInUserSession=r.getCognitoUserSession(n.AuthenticationResult),r.cacheTokens(),e.onSuccess(r.signInUserSession))}))}))}))}))},t.confirmRegistration=function(e,t,r,n){var i={ClientId:this.pool.getClientId(),ConfirmationCode:e,Username:this.username,ForceAliasCreation:t,ClientMetadata:n};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("ConfirmSignUp",i,(function(e){return e?r(e,null):r(null,"SUCCESS")}))},t.sendCustomChallengeAnswer=function(e,t,r){var n=this,i={};i.USERNAME=this.username,i.ANSWER=e;var s=new T(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:r};this.getUserContextData()&&(o.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",o,(function(e,r){return e?t.onFailure(e):n.authenticateUserInternal(r,s,t)}))},t.sendMFACode=function(e,t,r,n){var i=this,o={};o.USERNAME=this.username,o.SMS_MFA_CODE=e;var a=r||"SMS_MFA";"SOFTWARE_TOKEN_MFA"===a&&(o.SOFTWARE_TOKEN_MFA_CODE=e),null!=this.deviceKey&&(o.DEVICE_KEY=this.deviceKey);var u={ChallengeName:a,ChallengeResponses:o,ClientId:this.pool.getClientId(),Session:this.Session,ClientMetadata:n};this.getUserContextData()&&(u.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",u,(function(e,r){if(e)return t.onFailure(e);if("DEVICE_SRP_AUTH"!==r.ChallengeName){if(i.signInUserSession=i.getCognitoUserSession(r.AuthenticationResult),i.cacheTokens(),null==r.AuthenticationResult.NewDeviceMetadata)return t.onSuccess(i.signInUserSession);var n=new T(i.pool.getUserPoolName());n.generateHashDevice(r.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,r.AuthenticationResult.NewDeviceMetadata.DeviceKey,(function(e){if(e)return t.onFailure(e);var o={Salt:s.lW.from(n.getSaltDevices(),"hex").toString("base64"),PasswordVerifier:s.lW.from(n.getVerifierDevices(),"hex").toString("base64")};i.verifierDevices=o.PasswordVerifier,i.deviceGroupKey=r.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey,i.randomPassword=n.getRandomPassword(),i.client.request("ConfirmDevice",{DeviceKey:r.AuthenticationResult.NewDeviceMetadata.DeviceKey,AccessToken:i.signInUserSession.getAccessToken().getJwtToken(),DeviceSecretVerifierConfig:o,DeviceName:J},(function(e,n){return e?t.onFailure(e):(i.deviceKey=r.AuthenticationResult.NewDeviceMetadata.DeviceKey,i.cacheDeviceKeyAndPassword(),!0===n.UserConfirmationNecessary?t.onSuccess(i.signInUserSession,n.UserConfirmationNecessary):t.onSuccess(i.signInUserSession))}))}))}else i.getDeviceResponse(t)}))},t.changePassword=function(e,t,r,n){if(null==this.signInUserSession||!this.signInUserSession.isValid())return r(new Error("User is not authenticated"),null);this.client.request("ChangePassword",{PreviousPassword:e,ProposedPassword:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),ClientMetadata:n},(function(e){return e?r(e,null):r(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,r){if(null==this.signInUserSession||!this.signInUserSession.isValid())return r(new Error("User is not authenticated"),null);this.client.request("SetUserMFAPreference",{SMSMfaSettings:e,SoftwareTokenMfaSettings:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(e){return e?r(e,null):r(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 r=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):(r.clearCachedUser(),e(null,"SUCCESS"))}))},t.updateAttributes=function(e,t,r){var n=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:r},(function(e){return e?t(e,null):n.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,r){if(t)return e(t,null);for(var n=[],i=0;i<r.UserAttributes.length;i++){var s={Name:r.UserAttributes[i].Name,Value:r.UserAttributes[i].Value},o=new K(s);n.push(o)}return e(null,n)}))},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,r){return t?e(t,null):e(null,r.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(r){var n=t.signInUserSession.getRefreshToken();n&&n.getToken()?t.refreshSession(n,r,e.clientMetadata):r()}))},t.getUserData=function(e,t){var r=this;if(null==this.signInUserSession||!this.signInUserSession.isValid())return this.clearCachedUserData(),e(new Error("User is not authenticated"),null);var n=this.getUserDataFromCache();if(n)if(this.isFetchUserDataAndTokenRequired(t))this.fetchUserData().then((function(e){return r.refreshSessionIfPossible(t).then((function(){return e}))})).then((function(t){return e(null,t)})).catch(e);else try{return void e(null,JSON.parse(n))}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 r=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):r.getUserData((function(){return t(null,"SUCCESS")}),{bypassCache:!0})}))},t.resendConfirmationCode=function(e,t){var r={ClientId:this.pool.getClientId(),Username:this.username,ClientMetadata:t};this.client.request("ResendConfirmationCode",r,(function(t,r){return t?e(t,null):e(null,r)}))},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 r="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,n=r+".idToken",i=r+".accessToken",s=r+".refreshToken",o=r+".clockDrift";if(this.storage.getItem(n)){var a=new O({IdToken:this.storage.getItem(n)}),u=new k({AccessToken:this.storage.getItem(i)}),l=new M({RefreshToken:this.storage.getItem(s)}),c=parseInt(this.storage.getItem(o),0)||0,h=new V({IdToken:a,AccessToken:u,RefreshToken:l,ClockDrift:c});if(h.isValid())return this.signInUserSession=h,e(null,this.signInUserSession);if(!l.getToken())return e(new Error("Cannot retrieve a new session. Please authenticate."),null);this.refreshSession(l,e,t.clientMetadata)}else e(new Error("Local storage is missing an ID Token, Please authenticate"),null)},t.refreshSession=function(e,t,r){var n=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 l={ClientId:this.pool.getClientId(),AuthFlow:"REFRESH_TOKEN_AUTH",AuthParameters:s,ClientMetadata:r};this.getUserContextData()&&(l.UserContextData=this.getUserContextData()),this.client.request("InitiateAuth",l,(function(t,r){if(t)return"NotAuthorizedException"===t.code&&n.clearCachedUser(),i(t,null);if(r){var s=r.AuthenticationResult;return Object.prototype.hasOwnProperty.call(s,"RefreshToken")||(s.RefreshToken=e.getToken()),n.signInUserSession=n.getCognitoUserSession(s),n.cacheTokens(),i(null,n.signInUserSession)}}))},t.cacheTokens=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId(),t=e+"."+this.username+".idToken",r=e+"."+this.username+".accessToken",n=e+"."+this.username+".refreshToken",i=e+"."+this.username+".clockDrift",s=e+".LastAuthUser";this.storage.setItem(t,this.signInUserSession.getIdToken().getJwtToken()),this.storage.setItem(r,this.signInUserSession.getAccessToken().getJwtToken()),this.storage.setItem(n,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",r=e+".randomPasswordKey",n=e+".deviceGroupKey";this.storage.setItem(t,this.deviceKey),this.storage.setItem(r,this.randomPassword),this.storage.setItem(n,this.deviceGroupKey)},t.getCachedDeviceKeyAndPassword=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,t=e+".deviceKey",r=e+".randomPasswordKey",n=e+".deviceGroupKey";this.storage.getItem(t)&&(this.deviceKey=this.storage.getItem(t),this.randomPassword=this.storage.getItem(r),this.deviceGroupKey=this.storage.getItem(n))},t.clearCachedDeviceKeyAndPassword=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId()+"."+this.username,t=e+".deviceKey",r=e+".randomPasswordKey",n=e+".deviceGroupKey";this.storage.removeItem(t),this.storage.removeItem(r),this.storage.removeItem(n)},t.clearCachedTokens=function(){var e="CognitoIdentityServiceProvider."+this.pool.getClientId(),t=e+"."+this.username+".idToken",r=e+"."+this.username+".accessToken",n=e+"."+this.username+".refreshToken",i=e+".LastAuthUser",s=e+"."+this.username+".clockDrift";this.storage.removeItem(t),this.storage.removeItem(r),this.storage.removeItem(n),this.storage.removeItem(i),this.storage.removeItem(s)},t.getCognitoUserSession=function(e){var t=new O(e),r=new k(e),n=new M(e);return new V({IdToken:t,AccessToken:r,RefreshToken:n})},t.forgotPassword=function(e,t){var r={ClientId:this.pool.getClientId(),Username:this.username,ClientMetadata:t};this.getUserContextData()&&(r.UserContextData=this.getUserContextData()),this.client.request("ForgotPassword",r,(function(t,r){return t?e.onFailure(t):"function"==typeof e.inputVerificationCode?e.inputVerificationCode(r):e.onSuccess(r)}))},t.confirmPassword=function(e,t,r,n){var i={ClientId:this.pool.getClientId(),Username:this.username,ConfirmationCode:e,Password:t,ClientMetadata:n};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("ConfirmForgotPassword",i,(function(e){return e?r.onFailure(e):r.onSuccess("SUCCESS")}))},t.getAttributeVerificationCode=function(e,t,r){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:r},(function(e,r){return e?t.onFailure(e):"function"==typeof t.inputVerificationCode?t.inputVerificationCode(r):t.onSuccess("SUCCESS")}))},t.verifyAttribute=function(e,t,r){if(null==this.signInUserSession||!this.signInUserSession.isValid())return r.onFailure(new Error("User is not authenticated"));this.client.request("VerifyUserAttribute",{AttributeName:e,Code:t,AccessToken:this.signInUserSession.getAccessToken().getJwtToken()},(function(e){return e?r.onFailure(e):r.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,r){return t?e.onFailure(t):e.onSuccess(r)}))},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(r){return t.deviceKey=null,t.deviceGroupKey=null,t.randomPassword=null,t.clearCachedDeviceKeyAndPassword(),e.onSuccess(r)}})},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,r){if(null==this.signInUserSession||!this.signInUserSession.isValid())return r.onFailure(new Error("User is not authenticated"));var n={AccessToken:this.signInUserSession.getAccessToken().getJwtToken(),Limit:e};t&&(n.PaginationToken=t),this.client.request("ListDevices",n,(function(e,t){return e?r.onFailure(e):r.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(r){return r?e.onFailure(r):(t.clearCachedUser(),e.onSuccess("SUCCESS"))}))},t.signOut=function(e){var t=this;e&&"function"==typeof e?this.getSession((function(r,n){if(r)return e(r);t.revokeTokens((function(r){t.cleanClientData(),e(r)}))})):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(),r=this.signInUserSession.getAccessToken();if(this.isSessionRevocable(r)&&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,r=e.callback;this.client.requestWithRetry("RevokeToken",{Token:t,ClientId:this.pool.getClientId()},(function(e){if(e)return r(e);r()}))},t.sendMFASelectionAnswer=function(e,t){var r=this,n={};n.USERNAME=this.username,n.ANSWER=e;var i={ChallengeName:"SELECT_MFA_TYPE",ChallengeResponses:n,ClientId:this.pool.getClientId(),Session:this.Session};this.getUserContextData()&&(i.UserContextData=this.getUserContextData()),this.client.request("RespondToAuthChallenge",i,(function(n,i){return n?t.onFailure(n):(r.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,r){return t?e.onFailure(t):e.associateSecretCode(r.SecretCode)})):this.client.request("AssociateSoftwareToken",{Session:this.Session},(function(r,n){return r?e.onFailure(r):(t.Session=n.Session,e.associateSecretCode(n.SecretCode))}))},t.verifySoftwareToken=function(e,t,r){var n=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?r.onFailure(e):r.onSuccess(t)})):this.client.request("VerifySoftwareToken",{Session:this.Session,UserCode:e,FriendlyDeviceName:t},(function(e,t){if(e)return r.onFailure(e);n.Session=t.Session;var i={};i.USERNAME=n.username;var s={ChallengeName:"MFA_SETUP",ClientId:n.pool.getClientId(),ChallengeResponses:i,Session:n.Session};n.getUserContextData()&&(s.UserContextData=n.getUserContextData()),n.client.request("RespondToAuthChallenge",s,(function(e,t){return e?r.onFailure(e):(n.signInUserSession=n.getCognitoUserSession(t.AuthenticationResult),n.cacheTokens(),r.onSuccess(n.signInUserSession))}))}))},e}(),Y=(r(204),"aws-amplify/5.0.4"),z={userAgent:Y+" js",product:"",navigator:null,isReactNative:!1};function G(){}"undefined"!=typeof navigator&&navigator.product&&(z.product=navigator.product||"",z.navigator=navigator||null,"ReactNative"===navigator.product?(z.userAgent=Y+" react-native",z.isReactNative=!0):(z.userAgent=Y+" js",z.isReactNative=!1)),G.prototype.userAgent=z.userAgent;var Q=function(e){e&&(G.prototype.userAgent&&!G.prototype.userAgent.includes(e)&&(G.prototype.userAgent=G.prototype.userAgent.concat(" ",e)),G.prototype.userAgent&&""!==G.prototype.userAgent||(G.prototype.userAgent=e))};const Z=G;function X(e){var t="function"==typeof Map?new Map:void 0;return X=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;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,n)}function n(){return ee(e,arguments,ne(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),re(n,e)},X(e)}function ee(e,t,r){return ee=te()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&re(i,r.prototype),i},ee.apply(null,arguments)}function te(){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}}function re(e,t){return re=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},re(e,t)}function ne(e){return ne=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ne(e)}var ie=function(e){function t(t,r,n,i){var s;return(s=e.call(this,t)||this).code=r,s.name=n,s.statusCode=i,s}return n=e,(r=t).prototype=Object.create(n.prototype),r.prototype.constructor=r,re(r,n),t;var r,n}(X(Error)),se=function(){function e(e,t,r){this.endpoint=t||"https://cognito-idp."+e+".amazonaws.com/";var n=(r||{}).credentials;this.fetchOptions=n?{credentials:n}:{}}var t=e.prototype;return t.promisifyRequest=function(e,t){var r=this;return new Promise((function(n,i){r.request(e,t,(function(e,t){e?i(new ie(e.message,e.code,e.name,e.statusCode)):n(t)}))}))},t.requestWithRetry=function(e,t,r){var n,i,s=this;(n=[t],i=5e3,void 0===i&&(i=ae),oe((function(t){return new Promise((function(r,n){s.request(e,t,(function(e,t){e?n(e):r(t)}))}))}),n,function(e){return function(t){var r=100*Math.pow(2,t)+100*Math.random();return!(r>e)&&r}}(i))).then((function(e){return r(null,e)})).catch((function(e){return r(e)}))},t.request=function(e,t,r){var n,i={"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityProviderService."+e,"X-Amz-User-Agent":Z.prototype.userAgent},s=Object.assign({},this.fetchOptions,{headers:i,method:"POST",mode:"cors",cache:"no-cache",body:JSON.stringify(t)});fetch(this.endpoint,s).then((function(e){return n=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(n.ok)return r(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,r(i)})).catch((function(e){if(n&&n.headers&&n.headers.get("x-amzn-errortype"))try{var t=n.headers.get("x-amzn-errortype").split(":")[0],i=new Error(n.status?n.status.toString():null);return i.code=t,i.name=t,i.statusCode=n.status,r(i)}catch(t){return r(e)}else e instanceof Error&&"Network error"===e.message&&(e.code="NetworkError");return r(e)}))},e}();function oe(e,t,r,n){if(void 0===n&&(n=1),"function"!=typeof e)throw Error("functionToRetry must be a function");return e.name,JSON.stringify(t),e.apply(void 0,t).catch((function(i){if(e.name,(s=i)&&s.nonRetryable)throw e.name,i;var s,o=r(n,t,i);if(e.name,!1!==o)return new Promise((function(e){return setTimeout(e,o)})).then((function(){return oe(e,t,r,n+1)}));throw i}))}Error;var ae=3e5,ue=function(){function e(e,t){var r=e||{},n=r.UserPoolId,i=r.ClientId,s=r.endpoint,o=r.fetchOptions,a=r.AdvancedSecurityDataCollectionFlag;if(!n||!i)throw new Error("Both UserPoolId and ClientId are required.");if(n.length>55||!/^[\w-]+_[0-9a-zA-Z]+$/.test(n))throw new Error("Invalid UserPoolId format.");var u=n.split("_")[0];this.userPoolId=n,this.clientId=i,this.client=new se(u,s,o),this.advancedSecurityDataCollectionFlag=!1!==a,this.storage=e.Storage||(new H).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,r,n,i,s){var o=this,a={ClientId:this.clientId,Username:e,Password:t,UserAttributes:r,ValidationData:n,ClientMetadata:s};this.getUserContextData(e)&&(a.UserContextData=this.getUserContextData(e)),this.client.request("SignUp",a,(function(t,r){if(t)return i(t,null);var n={Username:e,Pool:o,Storage:o.storage},s={user:new $(n),userConfirmed:r.UserConfirmed,userSub:r.UserSub,codeDeliveryDetails:r.CodeDeliveryDetails};return i(null,s)}))},t.getCurrentUser=function(){var e="CognitoIdentityServiceProvider."+this.clientId+".LastAuthUser",t=this.storage.getItem(e);if(t){var r={Username:t,Pool:this,Storage:this.storage};return new $(r)}return null},t.getUserContextData=function(e){if("undefined"!=typeof AmazonCognitoAdvancedSecurityData){var t=AmazonCognitoAdvancedSecurityData;if(this.advancedSecurityDataCollectionFlag){var r=t.getData(e,this.userPoolId,this.clientId);if(r)return{EncodedData:r}}return{}}},e}(),le=r(808),ce=function(){function e(e){if(!e.domain)throw new Error("The domain of cookieStorage can not be undefined.");if(this.domain=e.domain,e.path?this.path=e.path:this.path="/",Object.prototype.hasOwnProperty.call(e,"expires")?this.expires=e.expires:this.expires=365,Object.prototype.hasOwnProperty.call(e,"secure")?this.secure=e.secure:this.secure=!0,Object.prototype.hasOwnProperty.call(e,"sameSite")){if(!["strict","lax","none"].includes(e.sameSite))throw new Error('The sameSite value of cookieStorage must be "lax", "strict" or "none".');if("none"===e.sameSite&&!this.secure)throw new Error("sameSite = None requires the Secure attribute in latest browser versions.");this.sameSite=e.sameSite}else this.sameSite=null}var t=e.prototype;return t.setItem=function(e,t){var r={path:this.path,expires:this.expires,domain:this.domain,secure:this.secure};return this.sameSite&&(r.sameSite=this.sameSite),le.set(e,t,r),le.get(e)},t.getItem=function(e){return le.get(e)},t.removeItem=function(e){var t={path:this.path,expires:this.expires,domain:this.domain,secure:this.secure};return this.sameSite&&(t.sameSite=this.sameSite),le.remove(e,t)},t.clear=function(){for(var e=le.get(),t=Object.keys(e).length,r=0;r<t;++r)this.removeItem(Object.keys(e)[r]);return{}},e}()},742:(e,t)=>{"use strict";t.byteLength=function(e){var t=u(e),r=t[0],n=t[1];return 3*(r+n)/4-n},t.toByteArray=function(e){var t,r,s=u(e),o=s[0],a=s[1],l=new i(function(e,t,r){return 3*(t+r)/4-r}(0,o,a)),c=0,h=a>0?o-4:o;for(r=0;r<h;r+=4)t=n[e.charCodeAt(r)]<<18|n[e.charCodeAt(r+1)]<<12|n[e.charCodeAt(r+2)]<<6|n[e.charCodeAt(r+3)],l[c++]=t>>16&255,l[c++]=t>>8&255,l[c++]=255&t;return 2===a&&(t=n[e.charCodeAt(r)]<<2|n[e.charCodeAt(r+1)]>>4,l[c++]=255&t),1===a&&(t=n[e.charCodeAt(r)]<<10|n[e.charCodeAt(r+1)]<<4|n[e.charCodeAt(r+2)]>>2,l[c++]=t>>8&255,l[c++]=255&t),l},t.fromByteArray=function(e){for(var t,n=e.length,i=n%3,s=[],o=16383,a=0,u=n-i;a<u;a+=o)s.push(l(e,a,a+o>u?u:a+o));return 1===i?(t=e[n-1],s.push(r[t>>2]+r[t<<4&63]+"==")):2===i&&(t=(e[n-2]<<8)+e[n-1],s.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"=")),s.join("")};for(var r=[],n=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,a=s.length;o<a;++o)r[o]=s[o],n[s.charCodeAt(o)]=o;function u(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function l(e,t,n){for(var i,s,o=[],a=t;a<n;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(r[(s=i)>>18&63]+r[s>>12&63]+r[s>>6&63]+r[63&s]);return o.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},764:(e,t,r)=>{"use strict";var n=r(742),i=r(645),s=r(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,r){if(!(u.TYPED_ARRAY_SUPPORT||this instanceof u))return new u(e,t,r);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 l(this,e,t,r)}function l(e,t,r,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return t=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n),u.TYPED_ARRAY_SUPPORT?(e=t).__proto__=u.prototype:e=d(e,t),e}(e,t,r,n):"string"==typeof t?function(e,t,r){if("string"==typeof r&&""!==r||(r="utf8"),!u.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|p(t,r),i=(e=a(e,n)).write(t,r);return i!==n&&(e=e.slice(0,i)),e}(e,t,r):function(e,t){if(u.isBuffer(t)){var r=0|f(t.length);return 0===(e=a(e,r)).length||t.copy(e,0,0,r),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||(n=t.length)!=n?a(e,0):d(e,t);if("Buffer"===t.type&&s(t.data))return d(e,t.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function c(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(c(t),e=a(e,t<0?0:0|f(t)),!u.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function d(e,t){var r=t.length<0?0:0|f(t.length);e=a(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function f(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 r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return B(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return q(e).length;default:if(n)return B(e).length;t=(""+t).toLowerCase(),n=!0}}function g(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return C(this,t,r);case"utf8":case"utf-8":return U(this,t,r);case"ascii":return D(this,t,r);case"latin1":case"binary":return T(this,t,r);case"base64":return I(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function v(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function y(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=u.from(t,n)),u.isBuffer(t))return 0===t.length?-1:m(e,t,r,n,i);if("number"==typeof t)return t&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):m(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(e,t,r,n,i){var s,o=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;o=2,a/=2,u/=2,r/=2}function l(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){var c=-1;for(s=r;s<a;s++)if(l(e,s)===l(t,-1===c?0:s-c)){if(-1===c&&(c=s),s-c+1===u)return c*o}else-1!==c&&(s-=s-c),c=-1}else for(r+u>a&&(r=a-u),s=r;s>=0;s--){for(var h=!0,d=0;d<u;d++)if(l(e,s+d)!==l(t,d)){h=!1;break}if(h)return s}return-1}function w(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;var s=t.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var o=0;o<n;++o){var a=parseInt(t.substr(2*o,2),16);if(isNaN(a))return o;e[r+o]=a}return o}function _(e,t,r,n){return K(B(t,e.length-r),e,r,n)}function A(e,t,r,n){return K(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function b(e,t,r,n){return A(e,t,r,n)}function S(e,t,r,n){return K(q(t),e,r,n)}function E(e,t,r,n){return K(function(e,t){for(var r,n,i,s=[],o=0;o<e.length&&!((t-=2)<0);++o)n=(r=e.charCodeAt(o))>>8,i=r%256,s.push(i),s.push(n);return s}(t,e.length-r),e,r,n)}function I(e,t,r){return 0===t&&r===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,r))}function U(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var s,o,a,u,l=e[i],c=null,h=l>239?4:l>223?3:l>191?2:1;if(i+h<=r)switch(h){case 1:l<128&&(c=l);break;case 2:128==(192&(s=e[i+1]))&&(u=(31&l)<<6|63&s)>127&&(c=u);break;case 3:s=e[i+1],o=e[i+2],128==(192&s)&&128==(192&o)&&(u=(15&l)<<12|(63&s)<<6|63&o)>2047&&(u<55296||u>57343)&&(c=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&l)<<18|(63&s)<<12|(63&o)<<6|63&a)>65535&&u<1114112&&(c=u)}null===c?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),i+=h}return function(e){var t=e.length;if(t<=R)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=R));return r}(n)}t.lW=u,t.h2=50,u.TYPED_ARRAY_SUPPORT=void 0!==r.g.TYPED_ARRAY_SUPPORT?r.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,r){return l(null,e,t,r)},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,r){return function(e,t,r,n){return c(t),t<=0?a(e,t):void 0!==r?"string"==typeof n?a(e,t).fill(r,n):a(e,t).fill(r):a(e,t)}(null,e,t,r)},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 r=e.length,n=t.length,i=0,s=Math.min(r,n);i<s;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?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 r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=u.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var o=e[r];if(!u.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},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)v(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)v(this,t,t+3),v(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)v(this,t,t+7),v(this,t+1,t+6),v(this,t+2,t+5),v(this,t+3,t+4);return this},u.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?U(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="",r=t.h2;return this.length>0&&(e=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(e+=" ... ")),"<Buffer "+e+">"},u.prototype.compare=function(e,t,r,n,i){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;for(var s=(i>>>=0)-(n>>>=0),o=(r>>>=0)-(t>>>=0),a=Math.min(s,o),l=this.slice(n,i),c=e.slice(t,r),h=0;h<a;++h)if(l[h]!==c[h]){s=l[h],o=c[h];break}return s<o?-1:o<s?1:0},u.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},u.prototype.indexOf=function(e,t,r){return y(this,e,t,r,!0)},u.prototype.lastIndexOf=function(e,t,r){return y(this,e,t,r,!1)},u.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return w(this,e,t,r);case"utf8":case"utf-8":return _(this,e,t,r);case"ascii":return A(this,e,t,r);case"latin1":case"binary":return b(this,e,t,r);case"base64":return S(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return E(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var R=4096;function D(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function T(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function C(e,t,r){var n,i=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>i)&&(r=i);for(var s="",o=t;o<r;++o)s+=(n=e[o])<16?"0"+n.toString(16):n.toString(16);return s}function P(e,t,r){for(var n=e.slice(t,r),i="",s=0;s<n.length;s+=2)i+=String.fromCharCode(n[s]+256*n[s+1]);return i}function k(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function N(e,t,r,n,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(r+n>e.length)throw new RangeError("Index out of range")}function O(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,s=Math.min(e.length-r,2);i<s;++i)e[r+i]=(t&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function M(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,s=Math.min(e.length-r,4);i<s;++i)e[r+i]=t>>>8*(n?i:3-i)&255}function F(e,t,r,n,i,s){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function x(e,t,r,n,s){return s||F(e,0,r,4),i.write(e,t,r,n,23,4),r+4}function V(e,t,r,n,s){return s||F(e,0,r,8),i.write(e,t,r,n,52,8),r+8}u.prototype.slice=function(e,t){var r,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),u.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=u.prototype;else{var i=t-e;r=new u(i,void 0);for(var s=0;s<i;++s)r[s]=this[s+e]}return r},u.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=this[e],i=1,s=0;++s<t&&(i*=256);)n+=this[e+s]*i;return n},u.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},u.prototype.readUInt8=function(e,t){return t||k(e,1,this.length),this[e]},u.prototype.readUInt16LE=function(e,t){return t||k(e,2,this.length),this[e]|this[e+1]<<8},u.prototype.readUInt16BE=function(e,t){return t||k(e,2,this.length),this[e]<<8|this[e+1]},u.prototype.readUInt32LE=function(e,t){return t||k(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||k(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},u.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=this[e],i=1,s=0;++s<t&&(i*=256);)n+=this[e+s]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*t)),n},u.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=t,i=1,s=this[e+--n];n>0&&(i*=256);)s+=this[e+--n]*i;return s>=(i*=128)&&(s-=Math.pow(2,8*t)),s},u.prototype.readInt8=function(e,t){return t||k(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},u.prototype.readInt16LE=function(e,t){t||k(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(e,t){t||k(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(e,t){return t||k(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||k(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||k(e,4,this.length),i.read(this,e,!0,23,4)},u.prototype.readFloatBE=function(e,t){return t||k(e,4,this.length),i.read(this,e,!1,23,4)},u.prototype.readDoubleLE=function(e,t){return t||k(e,8,this.length),i.read(this,e,!0,52,8)},u.prototype.readDoubleBE=function(e,t){return t||k(e,8,this.length),i.read(this,e,!1,52,8)},u.prototype.writeUIntLE=function(e,t,r,n){e=+e,t|=0,r|=0,n||N(this,e,t,r,Math.pow(2,8*r)-1,0);var i=1,s=0;for(this[t]=255&e;++s<r&&(i*=256);)this[t+s]=e/i&255;return t+r},u.prototype.writeUIntBE=function(e,t,r,n){e=+e,t|=0,r|=0,n||N(this,e,t,r,Math.pow(2,8*r)-1,0);var i=r-1,s=1;for(this[t+i]=255&e;--i>=0&&(s*=256);)this[t+i]=e/s&255;return t+r},u.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||N(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,r){return e=+e,t|=0,r||N(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):O(this,e,t,!0),t+2},u.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||N(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):O(this,e,t,!1),t+2},u.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||N(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):M(this,e,t,!0),t+4},u.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||N(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):M(this,e,t,!1),t+4},u.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);N(this,e,t,r,i-1,-i)}var s=0,o=1,a=0;for(this[t]=255&e;++s<r&&(o*=256);)e<0&&0===a&&0!==this[t+s-1]&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+r},u.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);N(this,e,t,r,i-1,-i)}var s=r-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+r},u.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||N(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,r){return e=+e,t|=0,r||N(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):O(this,e,t,!0),t+2},u.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||N(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):O(this,e,t,!1),t+2},u.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||N(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):M(this,e,t,!0),t+4},u.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||N(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):M(this,e,t,!1),t+4},u.prototype.writeFloatLE=function(e,t,r){return x(this,e,t,!0,r)},u.prototype.writeFloatBE=function(e,t,r){return x(this,e,t,!1,r)},u.prototype.writeDoubleLE=function(e,t,r){return V(this,e,t,!0,r)},u.prototype.writeDoubleBE=function(e,t,r){return V(this,e,t,!1,r)},u.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var i,s=n-r;if(this===e&&r<t&&t<n)for(i=s-1;i>=0;--i)e[i+t]=this[i+r];else if(s<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i<s;++i)e[i+t]=this[i+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+s),t);return s},u.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===e.length){var i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!u.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var s;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(s=t;s<r;++s)this[s]=e;else{var o=u.isBuffer(e)?e:B(new u(e,n).toString()),a=o.length;for(s=0;s<r-t;++s)this[s+t]=o[s%a]}return this};var L=/[^+\/0-9A-Za-z-_]/g;function B(e,t){var r;t=t||1/0;for(var n=e.length,i=null,s=[],o=0;o<n;++o){if((r=e.charCodeAt(o))>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(t-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;s.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function q(e){return n.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(L,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function K(e,t,r,n){for(var i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}},249:function(e,t,r){var n;e.exports=(n=n||function(e,t){var n;if("undefined"!=typeof window&&window.crypto&&(n=window.crypto),"undefined"!=typeof self&&self.crypto&&(n=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(n=globalThis.crypto),!n&&"undefined"!=typeof window&&window.msCrypto&&(n=window.msCrypto),!n&&void 0!==r.g&&r.g.crypto&&(n=r.g.crypto),!n)try{n=r(480)}catch(e){}var i=function(){if(n){if("function"==typeof n.getRandomValues)try{return n.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof n.randomBytes)try{return n.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 r;return e.prototype=t,r=new e,e.prototype=null,r}}(),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)}},l=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,r=e.words,n=this.sigBytes,i=e.sigBytes;if(this.clamp(),n%4)for(var s=0;s<i;s++){var o=r[s>>>2]>>>24-s%4*8&255;t[n+s>>>2]|=o<<24-(n+s)%4*8}else for(var a=0;a<i;a+=4)t[n+a>>>2]=r[a>>>2];return this.sigBytes+=i,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=u.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],r=0;r<e;r+=4)t.push(i());return new l.init(t,e)}}),c=o.enc={},h=c.Hex={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],i=0;i<r;i++){var s=t[i>>>2]>>>24-i%4*8&255;n.push((s>>>4).toString(16)),n.push((15&s).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new l.init(r,t/2)}},d=c.Latin1={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],i=0;i<r;i++){var s=t[i>>>2]>>>24-i%4*8&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new l.init(r,t)}},f=c.Utf8={stringify:function(e){try{return decodeURIComponent(escape(d.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return d.parse(unescape(encodeURIComponent(e)))}},p=a.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new l.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=f.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r,n=this._data,i=n.words,s=n.sigBytes,o=this.blockSize,a=s/(4*o),u=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,c=e.min(4*u,s);if(u){for(var h=0;h<u;h+=o)this._doProcessBlock(i,h);r=i.splice(0,u),n.sigBytes-=c}return new l.init(r,c)},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,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new g.HMAC.init(e,r).finalize(t)}}}),o.algo={});return o}(Math),n)},269:function(e,t,r){var n,i,s;e.exports=(n=r(249),s=(i=n).lib.WordArray,i.enc.Base64={stringify:function(e){var t=e.words,r=e.sigBytes,n=this._map;e.clamp();for(var i=[],s=0;s<r;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<r;a++)i.push(n.charAt(o>>>6*(3-a)&63));var u=n.charAt(64);if(u)for(;i.length%4;)i.push(u);return i.join("")},parse:function(e){var t=e.length,r=this._map,n=this._reverseMap;if(!n){n=this._reverseMap=[];for(var i=0;i<r.length;i++)n[r.charCodeAt(i)]=i}var o=r.charAt(64);if(o){var a=e.indexOf(o);-1!==a&&(t=a)}return function(e,t,r){for(var n=[],i=0,o=0;o<t;o++)if(o%4){var a=r[e.charCodeAt(o-1)]<<o%4*2|r[e.charCodeAt(o)]>>>6-o%4*2;n[i>>>2]|=a<<24-i%4*8,i++}return s.create(n,i)}(e,t,n)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},n.enc.Base64)},10:function(e,t,r){var n;e.exports=(n=r(249),r(153),r(824),n.HmacSHA256)},824:function(e,t,r){var n,i,s;e.exports=(i=(n=r(249)).lib.Base,s=n.enc.Utf8,void(n.algo.HMAC=i.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var r=e.blockSize,n=4*r;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var i=this._oKey=t.clone(),o=this._iKey=t.clone(),a=i.words,u=o.words,l=0;l<r;l++)a[l]^=1549556828,u[l]^=909522486;i.sigBytes=o.sigBytes=n,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,r=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(r))}})))},433:function(e,t,r){var n;e.exports=(n=r(249),function(){if("function"==typeof ArrayBuffer){var e=n.lib.WordArray,t=e.init,r=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 r=e.byteLength,n=[],i=0;i<r;i++)n[i>>>2]|=e[i]<<24-i%4*8;t.call(this,n,r)}else t.apply(this,arguments)};r.prototype=e}}(),n.lib.WordArray)},153:function(e,t,r){var n;e.exports=(n=r(249),function(e){var t=n,r=t.lib,i=r.WordArray,s=r.Hasher,o=t.algo,a=[],u=[];!function(){function t(t){for(var r=e.sqrt(t),n=2;n<=r;n++)if(!(t%n))return!1;return!0}function r(e){return 4294967296*(e-(0|e))|0}for(var n=2,i=0;i<64;)t(n)&&(i<8&&(a[i]=r(e.pow(n,.5))),u[i]=r(e.pow(n,1/3)),i++),n++}();var l=[],c=o.SHA256=s.extend({_doReset:function(){this._hash=new i.init(a.slice(0))},_doProcessBlock:function(e,t){for(var r=this._hash.words,n=r[0],i=r[1],s=r[2],o=r[3],a=r[4],c=r[5],h=r[6],d=r[7],f=0;f<64;f++){if(f<16)l[f]=0|e[t+f];else{var p=l[f-15],g=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,v=l[f-2],y=(v<<15|v>>>17)^(v<<13|v>>>19)^v>>>10;l[f]=g+l[f-7]+y+l[f-16]}var m=n&i^n&s^i&s,w=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22),_=d+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&c^~a&h)+u[f]+l[f];d=h,h=c,c=a,a=o+_|0,o=s,s=i,i=n,n=_+(w+m)|0}r[0]=r[0]+n|0,r[1]=r[1]+i|0,r[2]=r[2]+s|0,r[3]=r[3]+o|0,r[4]=r[4]+a|0,r[5]=r[5]+c|0,r[6]=r[6]+h|0,r[7]=r[7]+d|0},_doFinalize:function(){var t=this._data,r=t.words,n=8*this._nDataBytes,i=8*t.sigBytes;return r[i>>>5]|=128<<24-i%32,r[14+(i+64>>>9<<4)]=e.floor(n/4294967296),r[15+(i+64>>>9<<4)]=n,t.sigBytes=4*r.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(c),t.HmacSHA256=s._createHmacHelper(c)}(Math),n.SHA256)},645:(e,t)=>{t.read=function(e,t,r,n,i){var s,o,a=8*i-n-1,u=(1<<a)-1,l=u>>1,c=-7,h=r?i-1:0,d=r?-1:1,f=e[t+h];for(h+=d,s=f&(1<<-c)-1,f>>=-c,c+=a;c>0;s=256*s+e[t+h],h+=d,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+e[t+h],h+=d,c-=8);if(0===s)s=1-l;else{if(s===u)return o?NaN:1/0*(f?-1:1);o+=Math.pow(2,n),s-=l}return(f?-1:1)*o*Math.pow(2,s-n)},t.write=function(e,t,r,n,i,s){var o,a,u,l=8*s-i-1,c=(1<<l)-1,h=c>>1,d=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:s-1,p=n?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=c):(o=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-o))<1&&(o--,u*=2),(t+=o+h>=1?d/u:d*Math.pow(2,1-h))*u>=2&&(o++,u/=2),o+h>=c?(a=0,o=c):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[r+f]=255&a,f+=p,a/=256,i-=8);for(o=o<<i|a,l+=i;l>0;e[r+f]=255&o,f+=p,o/=256,l-=8);e[r+f-p]|=128*g}},826:e=>{var t={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==t.call(e)}},204:(e,t,r)=>{e.exports=self.fetch||(self.fetch=r(869).default||r(869))},808:(e,t,r)=>{var n,i,s;s=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var r=arguments[e];for(var n in r)t[n]=r[n]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function r(n){function i(){}function s(t,r,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(r);/^[\{\[]/.test(o)&&(r=o)}catch(e){}r=n.write?n.write(r,t):encodeURIComponent(String(r)).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+"="+r+a}}function o(e,r){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("=");r||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var l=t(a[0]);if(u=(n.read||n)(u,l)||t(u),r)try{u=JSON.parse(u)}catch(e){}if(i[l]=u,e===l)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,r){s(t,"",e(r,{expires:-1}))},i.defaults={},i.withConverter=r,i}((function(){}))},void 0===(i="function"==typeof(n=s)?n.call(t,r,t,e):n)||(e.exports=i),e.exports=s()},869:(e,t,r)=>{"use strict";function n(e,t){return t=t||{},new Promise((function(r,n){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 l in i.open(t.method||"get",e,!0),i.onload=function(){i.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,r){s.push(t=t.toLowerCase()),o.push([t,r]),a[t]=a[t]?a[t]+","+r:r})),r(u())},i.onerror=n,i.withCredentials="include"==t.credentials,t.headers)i.setRequestHeader(l,t.headers[l]);i.send(t.body||null)}))}r.r(t),r.d(t,{default:()=>n})},296:()=>{},480:()=>{}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}return r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(864)})()));
|
|
3
3
|
//# sourceMappingURL=skapi.js.map
|