@aws-amplify/auth 4.6.15 → 4.6.17

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.
@@ -39,5 +39,5 @@ function O(e){return h.Buffer.from((new w).random(e).toString(),"hex")}R.prototy
39
39
  /*!
40
40
  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
41
41
  * SPDX-License-Identifier: Apache-2.0
42
- */)((function(t){return new Promise((function(n,i){r.request(e,t,(function(e,t){e?i(e):n(t)}))}))}),[t],5e3).then((function(e){return n(null,e)})).catch((function(e){return n(e)}))},t.request=function(e,t,n){var r,i={"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityProviderService."+e,"X-Amz-User-Agent":ne.prototype.userAgent},o=Object.assign({},this.fetchOptions,{headers:i,method:"POST",mode:"cors",cache:"no-cache",body:JSON.stringify(t)});fetch(this.endpoint,o).then((function(e){return r=e,e}),(function(e){if(e instanceof TypeError)throw new Error("Network error");throw e})).then((function(e){return e.json().catch((function(){return{}}))})).then((function(e){if(r.ok)return n(null,e);e;var t=(e.__type||e.code).split("#").pop(),i=new Error(e.message||e.Message||null);return i.name=t,i.code=t,n(i)})).catch((function(e){if(r&&r.headers&&r.headers.get("x-amzn-errortype"))try{var t=r.headers.get("x-amzn-errortype").split(":")[0],i=new Error(r.status?r.status.toString():null);return i.code=t,i.name=t,i.statusCode=r.status,n(i)}catch(t){return n(e)}else e instanceof Error&&"Network error"===e.message&&(e.code="NetworkError");return n(e)}))},e}(),fe=function(){};Error;var le,de=function(){function e(e,t){var n=e||{},r=n.UserPoolId,i=n.ClientId,o=n.endpoint,s=n.fetchOptions,a=n.AdvancedSecurityDataCollectionFlag;if(!r||!i)throw new Error("Both UserPoolId and ClientId are required.");if(r.length>55||!/^[\w-]+_[0-9a-zA-Z]+$/.test(r))throw new Error("Invalid UserPoolId format.");var u=r.split("_")[0];this.userPoolId=r,this.clientId=i,this.client=new he(u,o,s),this.advancedSecurityDataCollectionFlag=!1!==a,this.storage=e.Storage||(new Z).getStorage(),t&&(this.wrapRefreshSessionCallback=t)}var t=e.prototype;return t.getUserPoolId=function(){return this.userPoolId},t.getUserPoolName=function(){return this.getUserPoolId().split("_")[1]},t.getClientId=function(){return this.clientId},t.signUp=function(e,t,n,r,i,o){var s=this,a={ClientId:this.clientId,Username:e,Password:t,UserAttributes:n,ValidationData:r,ClientMetadata:o};this.getUserContextData(e)&&(a.UserContextData=this.getUserContextData(e)),this.client.request("SignUp",a,(function(t,n){if(t)return i(t,null);var r={Username:e,Pool:s,Storage:s.storage},o={user:new $(r),userConfirmed:n.UserConfirmed,userSub:n.UserSub,codeDeliveryDetails:n.CodeDeliveryDetails};return i(null,o)}))},t.getCurrentUser=function(){var e="CognitoIdentityServiceProvider."+this.clientId+".LastAuthUser",t=this.storage.getItem(e);if(t){var n={Username:t,Pool:this,Storage:this.storage};return new $(n)}return null},t.getUserContextData=function(e){if("undefined"!=typeof AmazonCognitoAdvancedSecurityData){var t=AmazonCognitoAdvancedSecurityData;if(this.advancedSecurityDataCollectionFlag){var n=t.getData(e,this.userPoolId,this.clientId);if(n)return{EncodedData:n}}return{}}},e}(),pe=n(5),ge=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 n={path:this.path,expires:this.expires,domain:this.domain,secure:this.secure};return this.sameSite&&(n.sameSite=this.sameSite),pe.set(e,t,n),pe.get(e)},t.getItem=function(e){return pe.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),pe.remove(e,t)},t.clear=function(){for(var e=pe.get(),t=Object.keys(e).length,n=0;n<t;++n)this.removeItem(Object.keys(e)[n]);return{}},e}(),me=n(3),ye=function(e){var t=window.open(e,"_self");return t?Promise.resolve(t):Promise.reject()},ve=n(13),we=n.n(ve),Se=n(14),Ae=n.n(Se),be=function(){return(be=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},Ce=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},Ue=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},Ie=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s},Ee="undefined"!=typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("amplify_default"):"@@amplify_default",_e=function(e,t,n){u.Hub.dispatch("auth",{event:e,data:t,message:n},"Auth",Ee)},Te=new u.ConsoleLogger("OAuth"),Pe=function(){function e(e){var t=e.config,n=e.cognitoClientId,r=e.scopes,i=void 0===r?[]:r;if(this._urlOpener=t.urlOpener||ye,this._config=t,this._cognitoClientId=n,!this.isValidScopes(i))throw Error("scopes must be a String Array");this._scopes=i}return e.prototype.isValidScopes=function(e){return Array.isArray(e)&&e.every((function(e){return"string"==typeof e}))},e.prototype.oauthSignIn=function(e,t,n,i,o,s){void 0===e&&(e="code"),void 0===o&&(o=r.Cognito);var a=this._generateState(32),c=s?a+"-"+Object(u.urlSafeEncode)(s):a;!function(e){window.sessionStorage.setItem("oauth_state",e)}(c);var h,f=this._generateRandom(128);h=f,window.sessionStorage.setItem("ouath_pkce_key",h);var l=this._generateChallenge(f),d=this._scopes.join(" "),p="https://"+t+"/oauth2/authorize?"+Object.entries(be(be({redirect_uri:n,response_type:e,client_id:i,identity_provider:o,scope:d,state:c},"code"===e?{code_challenge:l}:{}),"code"===e?{code_challenge_method:"S256"}:{})).map((function(e){var t=Ie(e,2),n=t[0],r=t[1];return encodeURIComponent(n)+"="+encodeURIComponent(r)})).join("&");Te.debug("Redirecting to "+p),this._urlOpener(p,n)},e.prototype._handleCodeFlow=function(e){return Ce(this,void 0,void 0,(function(){var t,n,r,i,o,s,u,c,h,f,l,d,p,g;return Ue(this,(function(m){switch(m.label){case 0:return t=(Object(me.parse)(e).query||"").split("&").map((function(e){return e.split("=")})).reduce((function(e,t){var n,r=Ie(t,2),i=r[0],o=r[1];return be(be({},e),((n={})[i]=o,n))}),{code:void 0}).code,n=Object(me.parse)(e).pathname||"/",r=Object(me.parse)(this._config.redirectSignIn).pathname||"/",t&&n===r?(i="https://"+this._config.domain+"/oauth2/token",_e("codeFlow",{},"Retrieving tokens from "+i),o=a(this._config)?this._cognitoClientId:this._config.clientID,s=a(this._config)?this._config.redirectSignIn:this._config.redirectUri,y=window.sessionStorage.getItem("ouath_pkce_key"),window.sessionStorage.removeItem("ouath_pkce_key"),c=be({grant_type:"authorization_code",code:t,client_id:o,redirect_uri:s},(u=y)?{code_verifier:u}:{}),Te.debug("Calling token endpoint: "+i+" with",c),h=Object.entries(c).map((function(e){var t=Ie(e,2),n=t[0],r=t[1];return encodeURIComponent(n)+"="+encodeURIComponent(r)})).join("&"),[4,fetch(i,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:h})]):[2];case 1:return[4,m.sent().json()];case 2:if(f=m.sent(),l=f.access_token,d=f.refresh_token,p=f.id_token,g=f.error)throw new Error(g);return[2,{accessToken:l,refreshToken:d,idToken:p}]}var y}))}))},e.prototype._handleImplicitFlow=function(e){return Ce(this,void 0,void 0,(function(){var t,n,r;return Ue(this,(function(i){return t=(Object(me.parse)(e).hash||"#").substr(1).split("&").map((function(e){return e.split("=")})).reduce((function(e,t){var n,r=Ie(t,2),i=r[0],o=r[1];return be(be({},e),((n={})[i]=o,n))}),{id_token:void 0,access_token:void 0}),n=t.id_token,r=t.access_token,_e("implicitFlow",{},"Got tokens from "+e),Te.debug("Retrieving implicit tokens from "+e+" with"),[2,{accessToken:r,idToken:n,refreshToken:null}]}))}))},e.prototype.handleAuthResponse=function(e){return Ce(this,void 0,void 0,(function(){var t,n,r,i,o,s,a;return Ue(this,(function(u){switch(u.label){case 0:if(u.trys.push([0,5,,6]),t=e?be(be({},(Object(me.parse)(e).hash||"#").substr(1).split("&").map((function(e){return e.split("=")})).reduce((function(e,t){var n=Ie(t,2),r=n[0],i=n[1];return e[r]=i,e}),{})),(Object(me.parse)(e).query||"").split("&").map((function(e){return e.split("=")})).reduce((function(e,t){var n=Ie(t,2),r=n[0],i=n[1];return e[r]=i,e}),{})):{},n=t.error,r=t.error_description,n)throw new Error(r);return i=this._validateState(t),Te.debug("Starting "+this._config.responseType+" flow with "+e),"code"!==this._config.responseType?[3,2]:(o=[{}],[4,this._handleCodeFlow(e)]);case 1:return[2,be.apply(void 0,[be.apply(void 0,o.concat([u.sent()])),{state:i}])];case 2:return s=[{}],[4,this._handleImplicitFlow(e)];case 3:return[2,be.apply(void 0,[be.apply(void 0,s.concat([u.sent()])),{state:i}])];case 4:return[3,6];case 5:throw a=u.sent(),Te.error("Error handling auth response.",a),a;case 6:return[2]}}))}))},e.prototype._validateState=function(e){if(e){var t,n=(t=window.sessionStorage.getItem("oauth_state"),window.sessionStorage.removeItem("oauth_state"),t),r=e.state;if(n&&n!==r)throw new Error("Invalid state in OAuth flow");return r}},e.prototype.signOut=function(){return Ce(this,void 0,void 0,(function(){var e,t,n;return Ue(this,(function(r){return e="https://"+this._config.domain+"/logout?",t=a(this._config)?this._cognitoClientId:this._config.oauth.clientID,n=a(this._config)?this._config.redirectSignOut:this._config.returnTo,e+=Object.entries({client_id:t,logout_uri:encodeURIComponent(n)}).map((function(e){var t=Ie(e,2);return t[0]+"="+t[1]})).join("&"),_e("oAuthSignOut",{oAuth:"signOut"},"Signing out from "+e),Te.debug("Signing out from "+e),[2,this._urlOpener(e,n)]}))}))},e.prototype._generateState=function(e){for(var t="",n=e,r="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";n>0;--n)t+=r[Math.round(Math.random()*(r.length-1))];return t},e.prototype._generateChallenge=function(e){return this._base64URL(we()(e))},e.prototype._base64URL=function(e){return e.toString(Ae.a).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},e.prototype._generateRandom=function(e){var t=new Uint8Array(e);if("undefined"!=typeof window&&window.crypto)window.crypto.getRandomValues(t);else for(var n=0;n<e;n+=1)t[n]=Math.random()*"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~".length|0;return this._bufferToString(t)},e.prototype._bufferToString=function(e){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=[],r=0;r<e.byteLength;r+=1){var i=e[r]%t.length;n.push(t[i])}return n.join("")},e}();!function(e){e.DEFAULT_MSG="Authentication Error",e.EMPTY_EMAIL="Email cannot be empty",e.EMPTY_PHONE="Phone number cannot be empty",e.EMPTY_USERNAME="Username cannot be empty",e.INVALID_USERNAME="The username should either be a string or one of the sign in types",e.EMPTY_PASSWORD="Password cannot be empty",e.EMPTY_CODE="Confirmation code cannot be empty",e.SIGN_UP_ERROR="Error creating account",e.NO_MFA="No valid MFA method provided",e.INVALID_MFA="Invalid MFA type",e.EMPTY_CHALLENGE="Challenge response cannot be empty",e.NO_USER_SESSION="Failed to get the session because the user is empty",e.NETWORK_ERROR="Network Error",e.DEVICE_CONFIG="Device tracking has not been configured in this User Pool",e.AUTOSIGNIN_ERROR="Please use your credentials to sign in"}(le||(le={}));var De,Re=(De=function(e,t){return(De=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}De(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),Oe=new u.ConsoleLogger("AuthError"),ke=function(e){function t(n){var r=this,i=Fe[n],o=i.message,s=i.log;return(r=e.call(this,o)||this).constructor=t,Object.setPrototypeOf(r,t.prototype),r.name="AuthError",r.log=s||o,Oe.error(r.log),r}return Re(t,e),t}(Error),Me=function(e){function t(n){var r=e.call(this,n)||this;return r.constructor=t,Object.setPrototypeOf(r,t.prototype),r.name="NoUserPoolError",r}return Re(t,e),t}(ke),Fe={noConfig:{message:le.DEFAULT_MSG,log:"\n Error: Amplify has not been configured correctly.\n This error is typically caused by one of the following scenarios:\n\n 1. Make sure you're passing the awsconfig object to Amplify.configure() in your app's entry point\n See https://aws-amplify.github.io/docs/js/authentication#configure-your-app for more information\n \n 2. There might be multiple conflicting versions of amplify packages in your node_modules.\n\t\t\t\tRefer to our docs site for help upgrading Amplify packages (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js)\n "},missingAuthConfig:{message:le.DEFAULT_MSG,log:"\n Error: Amplify has not been configured correctly. \n The configuration object is missing required auth properties.\n This error is typically caused by one of the following scenarios:\n\n 1. Did you run `amplify push` after adding auth via `amplify add auth`?\n See https://aws-amplify.github.io/docs/js/authentication#amplify-project-setup for more information\n\n 2. This could also be caused by multiple conflicting versions of amplify packages, see (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js) for help upgrading Amplify packages.\n "},emptyUsername:{message:le.EMPTY_USERNAME},invalidUsername:{message:le.INVALID_USERNAME},emptyPassword:{message:le.EMPTY_PASSWORD},emptyCode:{message:le.EMPTY_CODE},signUpError:{message:le.SIGN_UP_ERROR,log:"The first parameter should either be non-null string or object"},noMFA:{message:le.NO_MFA},invalidMFA:{message:le.INVALID_MFA},emptyChallengeResponse:{message:le.EMPTY_CHALLENGE},noUserSession:{message:le.NO_USER_SESSION},deviceConfig:{message:le.DEVICE_CONFIG},networkError:{message:le.NETWORK_ERROR},autoSignInError:{message:le.AUTOSIGNIN_ERROR},default:{message:le.DEFAULT_MSG}};function Ne(e){return(Ne="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var xe=function(){return(xe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},Be=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},je=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},Ve=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s},qe=new u.ConsoleLogger("AuthClass"),Ke="undefined"!=typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("amplify_default"):"@@amplify_default",He=function(e,t,n){u.Hub.dispatch("auth",{event:e,data:t,message:n},"Auth",Ke)},Le=new(function(){function e(e){var t=this;this.userPool=null,this.user=null,this.oAuthFlowInProgress=!1,this.autoSignInInitiated=!1,this.Credentials=u.Credentials,this.wrapRefreshSessionCallback=function(e){return function(t,n){return n?He("tokenRefresh",void 0,"New token retrieved"):He("tokenRefresh_failure",t,"Failed to retrieve new token"),e(t,n)}},this.configure(e),this.currentCredentials=this.currentCredentials.bind(this),this.currentUserCredentials=this.currentUserCredentials.bind(this),u.Hub.listen("auth",(function(e){switch(e.payload.event){case"signIn":t._storage.setItem("amplify-signin-with-hostedUI","false");break;case"signOut":t._storage.removeItem("amplify-signin-with-hostedUI");break;case"cognitoHostedUI":t._storage.setItem("amplify-signin-with-hostedUI","true")}}))}return e.prototype.getModuleName=function(){return"Auth"},e.prototype.configure=function(e){var t=this;if(!e)return this._config||{};qe.debug("configure Auth");var n=Object.assign({},this._config,u.Parser.parseMobilehubConfig(e).Auth,e);this._config=n;var r=this._config,o=r.userPoolId,s=r.userPoolWebClientId,c=r.cookieStorage,h=r.oauth,f=r.region,l=r.identityPoolId,d=r.mandatorySignIn,p=r.refreshHandlers,g=r.identityPoolRegion,m=r.clientMetadata,y=r.endpoint;if(this._config.storage){if(!this._isValidAuthStorage(this._config.storage))throw qe.error("The storage in the Auth config is not valid!"),new Error("Empty storage object");this._storage=this._config.storage}else this._storage=c?new ge(c):e.ssr?new u.UniversalStorage:(new u.StorageHelper).getStorage();if(this._storageSync=Promise.resolve(),"function"==typeof this._storage.sync&&(this._storageSync=this._storage.sync()),o){var v={UserPoolId:o,ClientId:s,endpoint:y};v.Storage=this._storage,this.userPool=new de(v,this.wrapRefreshSessionCallback)}this.Credentials.configure({mandatorySignIn:d,region:g||f,userPoolId:o,identityPoolId:l,refreshHandlers:p,storage:this._storage});var w=h?a(this._config.oauth)?h:h.awsCognito:void 0;if(w){var S=Object.assign({cognitoClientId:s,UserPoolId:o,domain:w.domain,scopes:w.scope,redirectSignIn:w.redirectSignIn,redirectSignOut:w.redirectSignOut,responseType:w.responseType,Storage:this._storage,urlOpener:w.urlOpener,clientMetadata:m},w.options);this._oAuthHandler=new Pe({scopes:S.scopes,config:S,cognitoClientId:S.cognitoClientId});var A={};!function(e){if(Object(u.browserOrNode)().isBrowser&&window.location)e({url:window.location.href});else if(!Object(u.browserOrNode)().isNode)throw new Error("Not supported")}((function(e){var n=e.url;A[n]||(A[n]=!0,t._handleAuthResponse(n))}))}(He("configured",null,"The Auth category has been configured successfully"),this.autoSignInInitiated||"function"!=typeof this._storage.getItem)||(this.isTrueStorageValue("amplify-polling-started")&&(He("autoSignIn_failure",null,i.AutoSignInError),this._storage.removeItem("amplify-auto-sign-in")),this._storage.removeItem("amplify-polling-started"));return this._config},e.prototype.signUp=function(e){for(var t,n,r,o=this,s=[],a=1;a<arguments.length;a++)s[a-1]=arguments[a];if(!this.userPool)return this.rejectNoUserPool();var u,c=null,h=null,f=[],l=null,d={enabled:!1},p={},g={};if(e&&"string"==typeof e){c=e,h=s?s[0]:null;var m=s?s[1]:null,y=s?s[2]:null;m&&f.push(new G({Name:"email",Value:m})),y&&f.push(new G({Name:"phone_number",Value:y}))}else{if(!e||"object"!==Ne(e))return this.rejectAuthError(i.SignUpError);c=e.username,h=e.password,e&&e.clientMetadata?u=e.clientMetadata:this._config.clientMetadata&&(u=this._config.clientMetadata);var v=e.attributes;v&&Object.keys(v).map((function(e){f.push(new G({Name:e,Value:v[e]}))}));var w=e.validationData;w&&(l=[],Object.keys(w).map((function(e){l.push(new G({Name:e,Value:w[e]}))}))),(d=null!==(t=e.autoSignIn)&&void 0!==t?t:{enabled:!1}).enabled&&(this._storage.setItem("amplify-auto-sign-in","true"),p=null!==(n=d.validationData)&&void 0!==n?n:{},g=null!==(r=d.clientMetaData)&&void 0!==r?r:{})}return c?h?(qe.debug("signUp attrs:",f),qe.debug("signUp validation data:",l),new Promise((function(e,t){o.userPool.signUp(c,h,f,l,(function(n,r){n?(He("signUp_failure",n,c+" failed to signup"),t(n)):(He("signUp",r,c+" has signed up successfully"),d.enabled&&o.handleAutoSignIn(c,h,p,g,r),e(r))}),u)}))):this.rejectAuthError(i.EmptyPassword):this.rejectAuthError(i.EmptyUsername)},e.prototype.handleAutoSignIn=function(e,t,n,r,i){this.autoSignInInitiated=!0;var o=new c({Username:e,Password:t,ValidationData:n,ClientMetadata:r});i.userConfirmed?this.signInAfterUserConfirmed(o):"link"===this._config.signUpVerificationMethod?this.handleLinkAutoSignIn(o):this.handleCodeAutoSignIn(o)},e.prototype.handleCodeAutoSignIn=function(e){var t=this;u.Hub.listen("auth",(function n(r){"confirmSignUp"===r.payload.event&&t.signInAfterUserConfirmed(e,n)}))},e.prototype.handleLinkAutoSignIn=function(e){var t=this;this._storage.setItem("amplify-polling-started","true");var n=Date.now(),r=setInterval((function(){Date.now()-n>18e4?(clearInterval(r),He("autoSignIn_failure",null,"Please confirm your account and use your credentials to sign in."),t._storage.removeItem("amplify-auto-sign-in")):t.signInAfterUserConfirmed(e,null,r)}),5e3)},e.prototype.signInAfterUserConfirmed=function(e,t,n){return Be(this,void 0,void 0,(function(){var r,i,o=this;return je(this,(function(s){switch(s.label){case 0:r=this.createCognitoUser(e.getUsername()),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,r.authenticateUser(e,this.authCallbacks(r,(function(r){He("autoSignIn",r,e.getUsername()+" has signed in successfully"),t&&u.Hub.remove("auth",t),n&&(clearInterval(n),o._storage.removeItem("amplify-polling-started")),o._storage.removeItem("amplify-auto-sign-in")}),(function(e){qe.error(e),o._storage.removeItem("amplify-auto-sign-in")})))];case 2:return s.sent(),[3,4];case 3:return i=s.sent(),qe.error(i),[3,4];case 4:return[2]}}))}))},e.prototype.confirmSignUp=function(e,t,n){var r=this;if(!this.userPool)return this.rejectNoUserPool();if(!e)return this.rejectAuthError(i.EmptyUsername);if(!t)return this.rejectAuthError(i.EmptyCode);var o,s=this.createCognitoUser(e),a=!n||"boolean"!=typeof n.forceAliasCreation||n.forceAliasCreation;return n&&n.clientMetadata?o=n.clientMetadata:this._config.clientMetadata&&(o=this._config.clientMetadata),new Promise((function(n,u){s.confirmRegistration(t,a,(function(t,o){t?u(t):(He("confirmSignUp",o,e+" has been confirmed successfully"),r.isTrueStorageValue("amplify-auto-sign-in")&&!r.autoSignInInitiated&&(He("autoSignIn_failure",null,i.AutoSignInError),r._storage.removeItem("amplify-auto-sign-in")),n(o))}),o)}))},e.prototype.isTrueStorageValue=function(e){var t=this._storage.getItem(e);return!!t&&"true"===t},e.prototype.resendSignUp=function(e,t){if(void 0===t&&(t=this._config.clientMetadata),!this.userPool)return this.rejectNoUserPool();if(!e)return this.rejectAuthError(i.EmptyUsername);var n=this.createCognitoUser(e);return new Promise((function(e,r){n.resendConfirmationCode((function(t,n){t?r(t):e(n)}),t)}))},e.prototype.signIn=function(e,t,n){if(void 0===n&&(n=this._config.clientMetadata),!this.userPool)return this.rejectNoUserPool();var r=null,o=null,s={};if("string"==typeof e)r=e,o=t;else{if(!e.username)return this.rejectAuthError(i.InvalidUsername);void 0!==t&&qe.warn("The password should be defined under the first parameter object!"),r=e.username,o=e.password,s=e.validationData}if(!r)return this.rejectAuthError(i.EmptyUsername);var a=new c({Username:r,Password:o,ValidationData:s,ClientMetadata:n});return o?this.signInWithPassword(a):this.signInWithoutPassword(a)},e.prototype.authCallbacks=function(e,t,n){var r=this,i=this;return{onSuccess:function(o){return Be(r,void 0,void 0,(function(){var r,s,a,u;return je(this,(function(c){switch(c.label){case 0:qe.debug(o),delete e.challengeName,delete e.challengeParam,c.label=1;case 1:return c.trys.push([1,4,5,9]),[4,this.Credentials.clear()];case 2:return c.sent(),[4,this.Credentials.set(o,"session")];case 3:return r=c.sent(),qe.debug("succeed to get cognito credentials",r),[3,9];case 4:return s=c.sent(),qe.debug("cannot get cognito credentials",s),[3,9];case 5:return c.trys.push([5,7,,8]),[4,this.currentUserPoolUser()];case 6:return a=c.sent(),i.user=a,He("signIn",a,"A user "+e.getUsername()+" has been signed in"),t(a),[3,8];case 7:return u=c.sent(),qe.error("Failed to get the signed in user",u),n(u),[3,8];case 8:return[7];case 9:return[2]}}))}))},onFailure:function(t){qe.debug("signIn failure",t),He("signIn_failure",t,e.getUsername()+" failed to signin"),n(t)},customChallenge:function(n){qe.debug("signIn custom challenge answer required"),e.challengeName="CUSTOM_CHALLENGE",e.challengeParam=n,t(e)},mfaRequired:function(n,r){qe.debug("signIn MFA required"),e.challengeName=n,e.challengeParam=r,t(e)},mfaSetup:function(n,r){qe.debug("signIn mfa setup",n),e.challengeName=n,e.challengeParam=r,t(e)},newPasswordRequired:function(n,r){qe.debug("signIn new password"),e.challengeName="NEW_PASSWORD_REQUIRED",e.challengeParam={userAttributes:n,requiredAttributes:r},t(e)},totpRequired:function(n,r){qe.debug("signIn totpRequired"),e.challengeName=n,e.challengeParam=r,t(e)},selectMFAType:function(n,r){qe.debug("signIn selectMFAType",n),e.challengeName=n,e.challengeParam=r,t(e)}}},e.prototype.signInWithPassword=function(e){var t=this;if(this.pendingSignIn)throw new Error("Pending sign-in attempt already in progress");var n=this.createCognitoUser(e.getUsername());return this.pendingSignIn=new Promise((function(r,i){n.authenticateUser(e,t.authCallbacks(n,(function(e){t.pendingSignIn=null,r(e)}),(function(e){t.pendingSignIn=null,i(e)})))})),this.pendingSignIn},e.prototype.signInWithoutPassword=function(e){var t=this,n=this.createCognitoUser(e.getUsername());return n.setAuthenticationFlowType("CUSTOM_AUTH"),new Promise((function(r,i){n.initiateAuth(e,t.authCallbacks(n,r,i))}))},e.prototype.getMFAOptions=function(e){return new Promise((function(t,n){e.getMFAOptions((function(e,r){if(e)return qe.debug("get MFA Options failed",e),void n(e);qe.debug("get MFA options success",r),t(r)}))}))},e.prototype.getPreferredMFA=function(e,t){var n=this,r=this;return new Promise((function(i,o){var s=n._config.clientMetadata,a=!!t&&t.bypassCache;e.getUserData((function(t,s){return Be(n,void 0,void 0,(function(){var n,a;return je(this,(function(u){switch(u.label){case 0:if(!t)return[3,5];if(qe.debug("getting preferred mfa failed",t),!this.isSessionInvalid(t))return[3,4];u.label=1;case 1:return u.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(e)];case 2:return u.sent(),[3,4];case 3:return n=u.sent(),o(new Error("Session is invalid due to: "+t.message+" and failed to clean up invalid session: "+n.message)),[2];case 4:return o(t),[2];case 5:return(a=r._getMfaTypeFromUserData(s))?(i(a),[2]):(o("invalid MFA Type"),[2])}}))}))}),{bypassCache:a,clientMetadata:s})}))},e.prototype._getMfaTypeFromUserData=function(e){var t=null,n=e.PreferredMfaSetting;if(n)t=n;else{var r=e.UserMFASettingList;if(r)0===r.length?t="NOMFA":qe.debug("invalid case for getPreferredMFA",e);else t=e.MFAOptions?"SMS_MFA":"NOMFA"}return t},e.prototype._getUserData=function(e,t){var n=this;return new Promise((function(r,i){e.getUserData((function(t,o){return Be(n,void 0,void 0,(function(){var n;return je(this,(function(s){switch(s.label){case 0:if(!t)return[3,5];if(qe.debug("getting user data failed",t),!this.isSessionInvalid(t))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(e)];case 2:return s.sent(),[3,4];case 3:return n=s.sent(),i(new Error("Session is invalid due to: "+t.message+" and failed to clean up invalid session: "+n.message)),[2];case 4:return i(t),[2];case 5:r(o),s.label=6;case 6:return[2]}}))}))}),t)}))},e.prototype.setPreferredMFA=function(e,t){return Be(this,void 0,void 0,(function(){var n,r,o,s,a,u,c=this;return je(this,(function(h){switch(h.label){case 0:return n=this._config.clientMetadata,[4,this._getUserData(e,{bypassCache:!0,clientMetadata:n})];case 1:switch(r=h.sent(),o=null,s=null,t){case"TOTP":case"SOFTWARE_TOKEN_MFA":return[3,2];case"SMS":case"SMS_MFA":return[3,3];case"NOMFA":return[3,4]}return[3,6];case 2:return s={PreferredMfa:!0,Enabled:!0},[3,7];case 3:return o={PreferredMfa:!0,Enabled:!0},[3,7];case 4:return a=r.UserMFASettingList,[4,this._getMfaTypeFromUserData(r)];case 5:if("NOMFA"===(u=h.sent()))return[2,Promise.resolve("No change for mfa type")];if("SMS_MFA"===u)o={PreferredMfa:!1,Enabled:!1};else{if("SOFTWARE_TOKEN_MFA"!==u)return[2,this.rejectAuthError(i.InvalidMFA)];s={PreferredMfa:!1,Enabled:!1}}return a&&0!==a.length&&a.forEach((function(e){"SMS_MFA"===e?o={PreferredMfa:!1,Enabled:!1}:"SOFTWARE_TOKEN_MFA"===e&&(s={PreferredMfa:!1,Enabled:!1})})),[3,7];case 6:return qe.debug("no validmfa method provided"),[2,this.rejectAuthError(i.NoMFA)];case 7:return this,[2,new Promise((function(t,r){e.setUserMfaPreference(o,s,(function(i,o){if(i)return qe.debug("Set user mfa preference error",i),r(i);qe.debug("Set user mfa success",o),qe.debug("Caching the latest user data into local"),e.getUserData((function(n,i){return Be(c,void 0,void 0,(function(){var i;return je(this,(function(s){switch(s.label){case 0:if(!n)return[3,5];if(qe.debug("getting user data failed",n),!this.isSessionInvalid(n))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(e)];case 2:return s.sent(),[3,4];case 3:return i=s.sent(),r(new Error("Session is invalid due to: "+n.message+" and failed to clean up invalid session: "+i.message)),[2];case 4:return[2,r(n)];case 5:return[2,t(o)]}}))}))}),{bypassCache:!0,clientMetadata:n})}))}))]}}))}))},e.prototype.disableSMS=function(e){return new Promise((function(t,n){e.disableMFA((function(e,r){if(e)return qe.debug("disable mfa failed",e),void n(e);qe.debug("disable mfa succeed",r),t(r)}))}))},e.prototype.enableSMS=function(e){return new Promise((function(t,n){e.enableMFA((function(e,r){if(e)return qe.debug("enable mfa failed",e),void n(e);qe.debug("enable mfa succeed",r),t(r)}))}))},e.prototype.setupTOTP=function(e){return new Promise((function(t,n){e.associateSoftwareToken({onFailure:function(e){qe.debug("associateSoftwareToken failed",e),n(e)},associateSecretCode:function(e){qe.debug("associateSoftwareToken sucess",e),t(e)}})}))},e.prototype.verifyTotpToken=function(e,t){return qe.debug("verification totp token",e,t),new Promise((function(n,r){e.verifySoftwareToken(t,"My TOTP device",{onFailure:function(e){qe.debug("verifyTotpToken failed",e),r(e)},onSuccess:function(t){He("signIn",e,"A user "+e.getUsername()+" has been signed in"),qe.debug("verifyTotpToken success",t),n(t)}})}))},e.prototype.confirmSignIn=function(e,t,n,r){var o=this;if(void 0===r&&(r=this._config.clientMetadata),!t)return this.rejectAuthError(i.EmptyCode);var s=this;return new Promise((function(i,a){e.sendMFACode(t,{onSuccess:function(t){return Be(o,void 0,void 0,(function(){var n,r;return je(this,(function(o){switch(o.label){case 0:qe.debug(t),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,this.Credentials.clear()];case 2:return o.sent(),[4,this.Credentials.set(t,"session")];case 3:return n=o.sent(),qe.debug("succeed to get cognito credentials",n),[3,6];case 4:return r=o.sent(),qe.debug("cannot get cognito credentials",r),[3,6];case 5:return s.user=e,He("signIn",e,"A user "+e.getUsername()+" has been signed in"),i(e),[7];case 6:return[2]}}))}))},onFailure:function(e){qe.debug("confirm signIn failure",e),a(e)}},n,r)}))},e.prototype.completeNewPassword=function(e,t,n,r){var o=this;if(void 0===n&&(n={}),void 0===r&&(r=this._config.clientMetadata),!t)return this.rejectAuthError(i.EmptyPassword);var s=this;return new Promise((function(i,a){e.completeNewPasswordChallenge(t,n,{onSuccess:function(t){return Be(o,void 0,void 0,(function(){var n,r;return je(this,(function(o){switch(o.label){case 0:qe.debug(t),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,this.Credentials.clear()];case 2:return o.sent(),[4,this.Credentials.set(t,"session")];case 3:return n=o.sent(),qe.debug("succeed to get cognito credentials",n),[3,6];case 4:return r=o.sent(),qe.debug("cannot get cognito credentials",r),[3,6];case 5:return s.user=e,He("signIn",e,"A user "+e.getUsername()+" has been signed in"),i(e),[7];case 6:return[2]}}))}))},onFailure:function(e){qe.debug("completeNewPassword failure",e),He("completeNewPassword_failure",e,o.user+" failed to complete the new password flow"),a(e)},mfaRequired:function(t,n){qe.debug("signIn MFA required"),e.challengeName=t,e.challengeParam=n,i(e)},mfaSetup:function(t,n){qe.debug("signIn mfa setup",t),e.challengeName=t,e.challengeParam=n,i(e)},totpRequired:function(t,n){qe.debug("signIn mfa setup",t),e.challengeName=t,e.challengeParam=n,i(e)}},r)}))},e.prototype.sendCustomChallengeAnswer=function(e,t,n){var r=this;if(void 0===n&&(n=this._config.clientMetadata),!this.userPool)return this.rejectNoUserPool();if(!t)return this.rejectAuthError(i.EmptyChallengeResponse);return new Promise((function(i,o){e.sendCustomChallengeAnswer(t,r.authCallbacks(e,i,o),n)}))},e.prototype.deleteUserAttributes=function(e,t){var n=this;return new Promise((function(r,i){n.userSession(e).then((function(n){e.deleteAttributes(t,(function(e,t){return e?i(e):r(t)}))}))}))},e.prototype.deleteUser=function(){return Be(this,void 0,void 0,(function(){var e,t,n=this;return je(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._storageSync];case 1:return r.sent(),[3,3];case 2:throw e=r.sent(),qe.debug("Failed to sync cache info into memory",e),new Error(e);case 3:return t=this._oAuthHandler&&"true"===this._storage.getItem("amplify-signin-with-hostedUI"),[2,new Promise((function(e,r){return Be(n,void 0,void 0,(function(){var n,i=this;return je(this,(function(o){if(this.userPool){if(!(n=this.userPool.getCurrentUser()))return qe.debug("Failed to get user from user pool"),[2,r(new Error("No current user."))];n.getSession((function(o,s){return Be(i,void 0,void 0,(function(){var i,s=this;return je(this,(function(a){switch(a.label){case 0:if(!o)return[3,5];if(qe.debug("Failed to get the user session",o),!this.isSessionInvalid(o))return[3,4];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(n)];case 2:return a.sent(),[3,4];case 3:return i=a.sent(),r(new Error("Session is invalid due to: "+o.message+" and failed to clean up invalid session: "+i.message)),[2];case 4:return[2,r(o)];case 5:n.deleteUser((function(i,o){if(i)r(i);else{He("userDeleted",o,"The authenticated user has been deleted."),n.signOut(),s.user=null;try{s.cleanCachedItems()}catch(e){qe.debug("failed to clear cached items")}t?s.oAuthSignOutRedirect(e,r):(He("signOut",s.user,"A user has been signed out"),e(o))}})),a.label=6;case 6:return[2]}}))}))}))}else qe.debug("no Congito User pool"),r(new Error("Cognito User pool does not exist"));return[2]}))}))}))]}}))}))},e.prototype.updateUserAttributes=function(e,t,n){void 0===n&&(n=this._config.clientMetadata);var r=[],i=this;return new Promise((function(o,s){i.userSession(e).then((function(i){for(var a in t)if("sub"!==a&&a.indexOf("_verified")<0){var u={Name:a,Value:t[a]};r.push(u)}e.updateAttributes(r,(function(e,t){return e?s(e):o(t)}),n)}))}))},e.prototype.userAttributes=function(e){var t=this;return new Promise((function(n,r){t.userSession(e).then((function(t){e.getUserAttributes((function(e,t){e?r(e):n(t)}))}))}))},e.prototype.verifiedContact=function(e){var t=this;return this.userAttributes(e).then((function(e){var n=t.attributesToObject(e),r={},i={};return n.email&&(n.email_verified?i.email=n.email:r.email=n.email),n.phone_number&&(n.phone_number_verified?i.phone_number=n.phone_number:r.phone_number=n.phone_number),{verified:i,unverified:r}}))},e.prototype.isErrorWithMessage=function(e){return"object"===Ne(e)&&Object.prototype.hasOwnProperty.call(e,"message")},e.prototype.isTokenRevokedError=function(e){return this.isErrorWithMessage(e)&&"Access Token has been revoked"===e.message},e.prototype.isRefreshTokenRevokedError=function(e){return this.isErrorWithMessage(e)&&"Refresh Token has been revoked"===e.message},e.prototype.isUserDisabledError=function(e){return this.isErrorWithMessage(e)&&"User is disabled."===e.message},e.prototype.isUserDoesNotExistError=function(e){return this.isErrorWithMessage(e)&&"User does not exist."===e.message},e.prototype.isRefreshTokenExpiredError=function(e){return this.isErrorWithMessage(e)&&"Refresh Token has expired"===e.message},e.prototype.isSignedInHostedUI=function(){return this._oAuthHandler&&"true"===this._storage.getItem("amplify-signin-with-hostedUI")},e.prototype.isSessionInvalid=function(e){return this.isUserDisabledError(e)||this.isUserDoesNotExistError(e)||this.isTokenRevokedError(e)||this.isRefreshTokenRevokedError(e)||this.isRefreshTokenExpiredError(e)},e.prototype.cleanUpInvalidSession=function(e){return Be(this,void 0,void 0,(function(){var t=this;return je(this,(function(n){switch(n.label){case 0:e.signOut(),this.user=null,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.cleanCachedItems()];case 2:return n.sent(),[3,4];case 3:return n.sent(),qe.debug("failed to clear cached items"),[3,4];case 4:return this.isSignedInHostedUI()?[2,new Promise((function(e,n){t.oAuthSignOutRedirect(e,n)}))]:(He("signOut",this.user,"A user has been signed out"),[2])}}))}))},e.prototype.currentUserPoolUser=function(e){var t=this;return this.userPool?new Promise((function(n,r){t._storageSync.then((function(){return Be(t,void 0,void 0,(function(){var t,i,o=this;return je(this,(function(s){switch(s.label){case 0:return this.isOAuthInProgress()?(qe.debug("OAuth signIn in progress, waiting for resolution..."),[4,new Promise((function(e){var t=setTimeout((function(){qe.debug("OAuth signIn in progress timeout"),u.Hub.remove("auth",n),e()}),1e4);function n(r){var i=r.payload.event;"cognitoHostedUI"!==i&&"cognitoHostedUI_failure"!==i||(qe.debug("OAuth signIn resolved: "+i),clearTimeout(t),u.Hub.remove("auth",n),e())}u.Hub.listen("auth",n)}))]):[3,2];case 1:s.sent(),s.label=2;case 2:return(t=this.userPool.getCurrentUser())?(i=this._config.clientMetadata,t.getSession((function(i,s){return Be(o,void 0,void 0,(function(){var o,a,u,c,h=this;return je(this,(function(f){switch(f.label){case 0:if(!i)return[3,5];if(qe.debug("Failed to get the user session",i),!this.isSessionInvalid(i))return[3,4];f.label=1;case 1:return f.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(t)];case 2:return f.sent(),[3,4];case 3:return o=f.sent(),r(new Error("Session is invalid due to: "+i.message+" and failed to clean up invalid session: "+o.message)),[2];case 4:return r(i),[2];case 5:return(a=!!e&&e.bypassCache)?[4,this.Credentials.clear()]:[3,7];case 6:f.sent(),f.label=7;case 7:return u=this._config.clientMetadata,c=s.getAccessToken().decodePayload().scope,(void 0===c?"":c).split(" ").includes("aws.cognito.signin.user.admin")?(t.getUserData((function(e,i){return Be(h,void 0,void 0,(function(){var o,s,a,u,c,h,f;return je(this,(function(l){switch(l.label){case 0:if(!e)return[3,7];if(qe.debug("getting user data failed",e),!this.isSessionInvalid(e))return[3,5];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(t)];case 2:return l.sent(),[3,4];case 3:return o=l.sent(),r(new Error("Session is invalid due to: "+e.message+" and failed to clean up invalid session: "+o.message)),[2];case 4:return r(e),[3,6];case 5:n(t),l.label=6;case 6:return[2];case 7:for(s=i.PreferredMfaSetting||"NOMFA",a=[],u=0;u<i.UserAttributes.length;u++)c={Name:i.UserAttributes[u].Name,Value:i.UserAttributes[u].Value},h=new G(c),a.push(h);return f=this.attributesToObject(a),Object.assign(t,{attributes:f,preferredMFA:s}),[2,n(t)]}}))}))}),{bypassCache:a,clientMetadata:u}),[2]):(qe.debug("Unable to get the user data because the aws.cognito.signin.user.admin is not in the scopes of the access token"),[2,n(t)])}}))}))}),{clientMetadata:i}),[2]):(qe.debug("Failed to get user from user pool"),r("No current user"),[2])}}))}))})).catch((function(e){return qe.debug("Failed to sync cache info into memory",e),r(e)}))})):this.rejectNoUserPool()},e.prototype.isOAuthInProgress=function(){return this.oAuthFlowInProgress},e.prototype.currentAuthenticatedUser=function(e){return Be(this,void 0,void 0,(function(){var t,n,r,i,o;return je(this,(function(s){switch(s.label){case 0:qe.debug("getting current authenticated user"),t=null,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this._storageSync];case 2:return s.sent(),[3,4];case 3:throw n=s.sent(),qe.debug("Failed to sync cache info into memory",n),n;case 4:try{(r=JSON.parse(this._storage.getItem("aws-amplify-federatedInfo")))&&(t=xe(xe({},r.user),{token:r.token}))}catch(e){qe.debug("cannot load federated user from auth storage")}return t?(this.user=t,qe.debug("get current authenticated federated user",this.user),[2,this.user]):[3,5];case 5:qe.debug("get current authenticated userpool user"),i=null,s.label=6;case 6:return s.trys.push([6,8,,9]),[4,this.currentUserPoolUser(e)];case 7:return i=s.sent(),[3,9];case 8:return"No userPool"===(o=s.sent())&&qe.error("Cannot get the current user because the user pool is missing. Please make sure the Auth module is configured with a valid Cognito User Pool ID"),qe.debug("The user is not authenticated by the error",o),[2,Promise.reject("The user is not authenticated")];case 9:return this.user=i,[2,this.user]}}))}))},e.prototype.currentSession=function(){var e=this;return qe.debug("Getting current session"),this.userPool?new Promise((function(t,n){e.currentUserPoolUser().then((function(r){e.userSession(r).then((function(e){t(e)})).catch((function(e){qe.debug("Failed to get the current session",e),n(e)}))})).catch((function(e){qe.debug("Failed to get the current user",e),n(e)}))})):Promise.reject(new Error("No User Pool in the configuration."))},e.prototype.userSession=function(e){var t=this;if(!e)return qe.debug("the user is null"),this.rejectAuthError(i.NoUserSession);var n=this._config.clientMetadata;return new Promise((function(r,i){qe.debug("Getting the session from this user:",e),e.getSession((function(n,o){return Be(t,void 0,void 0,(function(){var t;return je(this,(function(s){switch(s.label){case 0:if(!n)return[3,5];if(qe.debug("Failed to get the session from user",e),!this.isSessionInvalid(n))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(e)];case 2:return s.sent(),[3,4];case 3:return t=s.sent(),i(new Error("Session is invalid due to: "+n.message+" and failed to clean up invalid session: "+t.message)),[2];case 4:return i(n),[2];case 5:return qe.debug("Succeed to get the user session",o),r(o),[2]}}))}))}),{clientMetadata:n})}))},e.prototype.currentUserCredentials=function(){return Be(this,void 0,void 0,(function(){var e,t,n=this;return je(this,(function(r){switch(r.label){case 0:qe.debug("Getting current user credentials"),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this._storageSync];case 2:return r.sent(),[3,4];case 3:throw e=r.sent(),qe.debug("Failed to sync cache info into memory",e),e;case 4:t=null;try{t=JSON.parse(this._storage.getItem("aws-amplify-federatedInfo"))}catch(e){qe.debug("failed to get or parse item aws-amplify-federatedInfo",e)}return t?[2,this.Credentials.refreshFederatedToken(t)]:[2,this.currentSession().then((function(e){return qe.debug("getting session success",e),n.Credentials.set(e,"session")})).catch((function(){return qe.debug("getting guest credentials"),n.Credentials.set(null,"guest")}))]}}))}))},e.prototype.currentCredentials=function(){return qe.debug("getting current credentials"),this.Credentials.get()},e.prototype.verifyUserAttribute=function(e,t,n){return void 0===n&&(n=this._config.clientMetadata),new Promise((function(r,i){e.getAttributeVerificationCode(t,{onSuccess:function(e){return r(e)},onFailure:function(e){return i(e)}},n)}))},e.prototype.verifyUserAttributeSubmit=function(e,t,n){return n?new Promise((function(r,i){e.verifyAttribute(t,n,{onSuccess:function(e){r(e)},onFailure:function(e){i(e)}})})):this.rejectAuthError(i.EmptyCode)},e.prototype.verifyCurrentUserAttribute=function(e){var t=this;return t.currentUserPoolUser().then((function(n){return t.verifyUserAttribute(n,e)}))},e.prototype.verifyCurrentUserAttributeSubmit=function(e,t){var n=this;return n.currentUserPoolUser().then((function(r){return n.verifyUserAttributeSubmit(r,e,t)}))},e.prototype.cognitoIdentitySignOut=function(e,t){return Be(this,void 0,void 0,(function(){var n,r,i=this;return je(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this._storageSync];case 1:return o.sent(),[3,3];case 2:throw n=o.sent(),qe.debug("Failed to sync cache info into memory",n),n;case 3:return r=this._oAuthHandler&&"true"===this._storage.getItem("amplify-signin-with-hostedUI"),[2,new Promise((function(n,o){if(e&&e.global){qe.debug("user global sign out",t);var s=i._config.clientMetadata;t.getSession((function(e,s){return Be(i,void 0,void 0,(function(){var i,s=this;return je(this,(function(a){switch(a.label){case 0:if(!e)return[3,5];if(qe.debug("failed to get the user session",e),!this.isSessionInvalid(e))return[3,4];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(t)];case 2:return a.sent(),[3,4];case 3:return i=a.sent(),o(new Error("Session is invalid due to: "+e.message+" and failed to clean up invalid session: "+i.message)),[2];case 4:return[2,o(e)];case 5:return t.globalSignOut({onSuccess:function(e){if(qe.debug("global sign out success"),!r)return n();s.oAuthSignOutRedirect(n,o)},onFailure:function(e){return qe.debug("global sign out failed",e),o(e)}}),[2]}}))}))}),{clientMetadata:s})}else qe.debug("user sign out",t),t.signOut((function(){if(!r)return n();i.oAuthSignOutRedirect(n,o)}))}))]}}))}))},e.prototype.oAuthSignOutRedirect=function(e,t){Object(u.browserOrNode)().isBrowser?this.oAuthSignOutRedirectOrReject(t):this.oAuthSignOutAndResolve(e)},e.prototype.oAuthSignOutAndResolve=function(e){this._oAuthHandler.signOut(),e()},e.prototype.oAuthSignOutRedirectOrReject=function(e){this._oAuthHandler.signOut(),setTimeout((function(){return e(Error("Signout timeout fail"))}),3e3)},e.prototype.signOut=function(e){return Be(this,void 0,void 0,(function(){var t;return je(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.cleanCachedItems()];case 1:return n.sent(),[3,3];case 2:return n.sent(),qe.debug("failed to clear cached items"),[3,3];case 3:return this.userPool?(t=this.userPool.getCurrentUser())?[4,this.cognitoIdentitySignOut(e,t)]:[3,5]:[3,7];case 4:return n.sent(),[3,6];case 5:qe.debug("no current Cognito user"),n.label=6;case 6:return[3,8];case 7:qe.debug("no Cognito User pool"),n.label=8;case 8:return He("signOut",this.user,"A user has been signed out"),this.user=null,[2]}}))}))},e.prototype.cleanCachedItems=function(){return Be(this,void 0,void 0,(function(){return je(this,(function(e){switch(e.label){case 0:return[4,this.Credentials.clear()];case 1:return e.sent(),[2]}}))}))},e.prototype.changePassword=function(e,t,n,r){var i=this;return void 0===r&&(r=this._config.clientMetadata),new Promise((function(o,s){i.userSession(e).then((function(i){e.changePassword(t,n,(function(e,t){return e?(qe.debug("change password failure",e),s(e)):o(t)}),r)}))}))},e.prototype.forgotPassword=function(e,t){if(void 0===t&&(t=this._config.clientMetadata),!this.userPool)return this.rejectNoUserPool();if(!e)return this.rejectAuthError(i.EmptyUsername);var n=this.createCognitoUser(e);return new Promise((function(r,i){n.forgotPassword({onSuccess:function(){r()},onFailure:function(t){qe.debug("forgot password failure",t),He("forgotPassword_failure",t,e+" forgotPassword failed"),i(t)},inputVerificationCode:function(t){He("forgotPassword",n,e+" has initiated forgot password flow"),r(t)}},t)}))},e.prototype.forgotPasswordSubmit=function(e,t,n,r){if(void 0===r&&(r=this._config.clientMetadata),!this.userPool)return this.rejectNoUserPool();if(!e)return this.rejectAuthError(i.EmptyUsername);if(!t)return this.rejectAuthError(i.EmptyCode);if(!n)return this.rejectAuthError(i.EmptyPassword);var o=this.createCognitoUser(e);return new Promise((function(i,s){o.confirmPassword(t,n,{onSuccess:function(t){He("forgotPasswordSubmit",o,e+" forgotPasswordSubmit successful"),i(t)},onFailure:function(t){He("forgotPasswordSubmit_failure",t,e+" forgotPasswordSubmit failed"),s(t)}},r)}))},e.prototype.currentUserInfo=function(){return Be(this,void 0,void 0,(function(){var e,t,n,r,i,o,s;return je(this,(function(a){switch(a.label){case 0:return(e=this.Credentials.getCredSource())&&"aws"!==e&&"userPool"!==e?[3,9]:[4,this.currentUserPoolUser().catch((function(e){return qe.error(e)}))];case 1:if(!(s=a.sent()))return[2,null];a.label=2;case 2:return a.trys.push([2,8,,9]),[4,this.userAttributes(s)];case 3:t=a.sent(),n=this.attributesToObject(t),r=null,a.label=4;case 4:return a.trys.push([4,6,,7]),[4,this.currentCredentials()];case 5:return r=a.sent(),[3,7];case 6:return i=a.sent(),qe.debug("Failed to retrieve credentials while getting current user info",i),[3,7];case 7:return[2,{id:r?r.identityId:void 0,username:s.getUsername(),attributes:n}];case 8:return o=a.sent(),qe.error("currentUserInfo error",o),[2,{}];case 9:return"federated"===e?[2,(s=this.user)||{}]:[2]}}))}))},e.prototype.federatedSignIn=function(e,t,n){return Be(this,void 0,void 0,(function(){var i,o,u,c,h,f,l,d,p,g,m;return je(this,(function(y){switch(y.label){case 0:if(!this._config.identityPoolId&&!this._config.userPoolId)throw new Error("Federation requires either a User Pool or Identity Pool in config");if(void 0===e&&this._config.identityPoolId&&!this._config.userPoolId)throw new Error("Federation with Identity Pools requires tokens passed as arguments");return s(e)||(v=e)&&["customProvider"].find((function(e){return v.hasOwnProperty(e)}))||function(e){return e&&!!["customState"].find((function(t){return e.hasOwnProperty(t)}))}(e)||void 0===e?(i=e||{provider:r.Cognito},h=s(i)?i.provider:i.customProvider,s(i),o=i.customState,this._config.userPoolId&&(u=a(this._config.oauth)?this._config.userPoolWebClientId:this._config.oauth.clientID,c=a(this._config.oauth)?this._config.oauth.redirectSignIn:this._config.oauth.redirectUri,this._oAuthHandler.oauthSignIn(this._config.oauth.responseType,this._config.oauth.domain,c,u,h,o)),[3,4]):[3,1];case 1:h=e;try{(f=JSON.stringify(JSON.parse(this._storage.getItem("aws-amplify-federatedInfo")).user))&&qe.warn("There is already a signed in user: "+f+" in your app.\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tYou should not call Auth.federatedSignIn method again as it may cause unexpected behavior.")}catch(e){}return l=t.token,d=t.identity_id,p=t.expires_at,[4,this.Credentials.set({provider:h,token:l,identity_id:d,user:n,expires_at:p},"federation")];case 2:return g=y.sent(),[4,this.currentAuthenticatedUser()];case 3:return m=y.sent(),He("signIn",m,"A user "+m.username+" has been signed in"),qe.debug("federated sign in credentials",g),[2,g];case 4:return[2]}var v}))}))},e.prototype._handleAuthResponse=function(e){return Be(this,void 0,void 0,(function(){var t,n,r,i,o,s,a,c,h,f,l,d,p,g;return je(this,(function(m){switch(m.label){case 0:if(this.oAuthFlowInProgress)return qe.debug("Skipping URL "+e+" current flow in progress"),[2];m.label=1;case 1:if(m.trys.push([1,,8,9]),this.oAuthFlowInProgress=!0,!this._config.userPoolId)throw new Error("OAuth responses require a User Pool defined in config");if(He("parsingCallbackUrl",{url:e},"The callback url is being parsed"),t=e||(Object(u.browserOrNode)().isBrowser?window.location.href:""),n=!!(Object(me.parse)(t).query||"").split("&").map((function(e){return e.split("=")})).find((function(e){var t=Ve(e,1)[0];return"code"===t||"error"===t})),r=!!(Object(me.parse)(t).hash||"#").substr(1).split("&").map((function(e){return e.split("=")})).find((function(e){var t=Ve(e,1)[0];return"access_token"===t||"error"===t})),!n&&!r)return[3,7];this._storage.setItem("amplify-redirected-from-hosted-ui","true"),m.label=2;case 2:return m.trys.push([2,6,,7]),[4,this._oAuthHandler.handleAuthResponse(t)];case 3:return i=m.sent(),o=i.accessToken,s=i.idToken,a=i.refreshToken,c=i.state,h=new H({IdToken:new j({IdToken:s}),RefreshToken:new V({RefreshToken:a}),AccessToken:new x({AccessToken:o})}),f=void 0,this._config.identityPoolId?[4,this.Credentials.set(h,"session")]:[3,5];case 4:f=m.sent(),qe.debug("AWS credentials",f),m.label=5;case 5:return l=/-/.test(c),(d=this.createCognitoUser(h.getIdToken().decodePayload()["cognito:username"])).setSignInUserSession(h),window&&void 0!==window.history&&window.history.replaceState({},null,this._config.oauth.redirectSignIn),He("signIn",d,"A user "+d.getUsername()+" has been signed in"),He("cognitoHostedUI",d,"A user "+d.getUsername()+" has been signed in via Cognito Hosted UI"),l&&(p=c.split("-").splice(1).join("-"),He("customOAuthState",Object(u.urlSafeDecode)(p),"State for user "+d.getUsername())),[2,f];case 6:return g=m.sent(),qe.debug("Error in cognito hosted auth response",g),window&&void 0!==window.history&&window.history.replaceState({},null,this._config.oauth.redirectSignIn),He("signIn_failure",g,"The OAuth response flow failed"),He("cognitoHostedUI_failure",g,"A failure occurred when returning to the Cognito Hosted UI"),He("customState_failure",g,"A failure occurred when returning state"),[3,7];case 7:return[3,9];case 8:return this.oAuthFlowInProgress=!1,[7];case 9:return[2]}}))}))},e.prototype.essentialCredentials=function(e){return{accessKeyId:e.accessKeyId,sessionToken:e.sessionToken,secretAccessKey:e.secretAccessKey,identityId:e.identityId,authenticated:e.authenticated}},e.prototype.attributesToObject=function(e){var t=this,n={};return e&&e.map((function(e){"email_verified"===e.Name||"phone_number_verified"===e.Name?n[e.Name]=t.isTruthyString(e.Value)||!0===e.Value:n[e.Name]=e.Value})),n},e.prototype.isTruthyString=function(e){return"function"==typeof e.toLowerCase&&"true"===e.toLowerCase()},e.prototype.createCognitoUser=function(e){var t={Username:e,Pool:this.userPool};t.Storage=this._storage;var n=this._config.authenticationFlowType,r=new $(t);return n&&r.setAuthenticationFlowType(n),r},e.prototype._isValidAuthStorage=function(e){return!!e&&"function"==typeof e.getItem&&"function"==typeof e.setItem&&"function"==typeof e.removeItem&&"function"==typeof e.clear},e.prototype.noUserPoolErrorHandler=function(e){return!e||e.userPoolId&&e.identityPoolId?i.NoConfig:i.MissingAuthConfig},e.prototype.rejectAuthError=function(e){return Promise.reject(new ke(e))},e.prototype.rejectNoUserPool=function(){var e=this.noUserPoolErrorHandler(this._config);return Promise.reject(new Me(e))},e.prototype.rememberDevice=function(){return Be(this,void 0,void 0,(function(){var e,t;return je(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.currentUserPoolUser()];case 1:return e=n.sent(),[3,3];case 2:return t=n.sent(),qe.debug("The user is not authenticated by the error",t),[2,Promise.reject("The user is not authenticated")];case 3:return e.getCachedDeviceKeyAndPassword(),[2,new Promise((function(t,n){e.setDeviceStatusRemembered({onSuccess:function(e){t(e)},onFailure:function(e){"InvalidParameterException"===e.code?n(new ke(i.DeviceConfig)):"NetworkError"===e.code?n(new ke(i.NetworkError)):n(e)}})}))]}}))}))},e.prototype.forgetDevice=function(){return Be(this,void 0,void 0,(function(){var e,t;return je(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.currentUserPoolUser()];case 1:return e=n.sent(),[3,3];case 2:return t=n.sent(),qe.debug("The user is not authenticated by the error",t),[2,Promise.reject("The user is not authenticated")];case 3:return e.getCachedDeviceKeyAndPassword(),[2,new Promise((function(t,n){e.forgetDevice({onSuccess:function(e){t(e)},onFailure:function(e){"InvalidParameterException"===e.code?n(new ke(i.DeviceConfig)):"NetworkError"===e.code?n(new ke(i.NetworkError)):n(e)}})}))]}}))}))},e.prototype.fetchDevices=function(){return Be(this,void 0,void 0,(function(){var e,t;return je(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.currentUserPoolUser()];case 1:return e=n.sent(),[3,3];case 2:throw t=n.sent(),qe.debug("The user is not authenticated by the error",t),new Error("The user is not authenticated");case 3:return e.getCachedDeviceKeyAndPassword(),[2,new Promise((function(t,n){var r={onSuccess:function(e){var n=e.Devices.map((function(e){var t=e.DeviceAttributes.find((function(e){return"device_name"===e.Name}))||{};return{id:e.DeviceKey,name:t.Value}}));t(n)},onFailure:function(e){"InvalidParameterException"===e.code?n(new ke(i.DeviceConfig)):"NetworkError"===e.code?n(new ke(i.NetworkError)):n(e)}};e.listDevices(60,null,r)}))]}}))}))},e}())(null);u.Amplify.register(Le);t.default=Le}])}));
42
+ */)((function(t){return new Promise((function(n,i){r.request(e,t,(function(e,t){e?i(e):n(t)}))}))}),[t],5e3).then((function(e){return n(null,e)})).catch((function(e){return n(e)}))},t.request=function(e,t,n){var r,i={"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"AWSCognitoIdentityProviderService."+e,"X-Amz-User-Agent":ne.prototype.userAgent,"Cache-Control":"no-store"},o=Object.assign({},this.fetchOptions,{headers:i,method:"POST",mode:"cors",body:JSON.stringify(t)});fetch(this.endpoint,o).then((function(e){return r=e,e}),(function(e){if(e instanceof TypeError)throw new Error("Network error");throw e})).then((function(e){return e.json().catch((function(){return{}}))})).then((function(e){if(r.ok)return n(null,e);e;var t=(e.__type||e.code).split("#").pop(),i=new Error(e.message||e.Message||null);return i.name=t,i.code=t,n(i)})).catch((function(e){if(r&&r.headers&&r.headers.get("x-amzn-errortype"))try{var t=r.headers.get("x-amzn-errortype").split(":")[0],i=new Error(r.status?r.status.toString():null);return i.code=t,i.name=t,i.statusCode=r.status,n(i)}catch(t){return n(e)}else e instanceof Error&&"Network error"===e.message&&(e.code="NetworkError");return n(e)}))},e}(),fe=function(){};Error;var le,de=function(){function e(e,t){var n=e||{},r=n.UserPoolId,i=n.ClientId,o=n.endpoint,s=n.fetchOptions,a=n.AdvancedSecurityDataCollectionFlag;if(!r||!i)throw new Error("Both UserPoolId and ClientId are required.");if(r.length>55||!/^[\w-]+_[0-9a-zA-Z]+$/.test(r))throw new Error("Invalid UserPoolId format.");var u=r.split("_")[0];this.userPoolId=r,this.clientId=i,this.client=new he(u,o,s),this.advancedSecurityDataCollectionFlag=!1!==a,this.storage=e.Storage||(new Z).getStorage(),t&&(this.wrapRefreshSessionCallback=t)}var t=e.prototype;return t.getUserPoolId=function(){return this.userPoolId},t.getUserPoolName=function(){return this.getUserPoolId().split("_")[1]},t.getClientId=function(){return this.clientId},t.signUp=function(e,t,n,r,i,o){var s=this,a={ClientId:this.clientId,Username:e,Password:t,UserAttributes:n,ValidationData:r,ClientMetadata:o};this.getUserContextData(e)&&(a.UserContextData=this.getUserContextData(e)),this.client.request("SignUp",a,(function(t,n){if(t)return i(t,null);var r={Username:e,Pool:s,Storage:s.storage},o={user:new $(r),userConfirmed:n.UserConfirmed,userSub:n.UserSub,codeDeliveryDetails:n.CodeDeliveryDetails};return i(null,o)}))},t.getCurrentUser=function(){var e="CognitoIdentityServiceProvider."+this.clientId+".LastAuthUser",t=this.storage.getItem(e);if(t){var n={Username:t,Pool:this,Storage:this.storage};return new $(n)}return null},t.getUserContextData=function(e){if("undefined"!=typeof AmazonCognitoAdvancedSecurityData){var t=AmazonCognitoAdvancedSecurityData;if(this.advancedSecurityDataCollectionFlag){var n=t.getData(e,this.userPoolId,this.clientId);if(n)return{EncodedData:n}}return{}}},e}(),pe=n(5),ge=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 n={path:this.path,expires:this.expires,domain:this.domain,secure:this.secure};return this.sameSite&&(n.sameSite=this.sameSite),pe.set(e,t,n),pe.get(e)},t.getItem=function(e){return pe.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),pe.remove(e,t)},t.clear=function(){for(var e=pe.get(),t=Object.keys(e).length,n=0;n<t;++n)this.removeItem(Object.keys(e)[n]);return{}},e}(),me=n(3),ye=function(e){var t=window.open(e,"_self");return t?Promise.resolve(t):Promise.reject()},ve=n(13),we=n.n(ve),Se=n(14),Ae=n.n(Se),be=function(){return(be=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},Ce=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},Ue=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},Ie=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s},Ee="undefined"!=typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("amplify_default"):"@@amplify_default",_e=function(e,t,n){u.Hub.dispatch("auth",{event:e,data:t,message:n},"Auth",Ee)},Te=new u.ConsoleLogger("OAuth"),Pe=function(){function e(e){var t=e.config,n=e.cognitoClientId,r=e.scopes,i=void 0===r?[]:r;if(this._urlOpener=t.urlOpener||ye,this._config=t,this._cognitoClientId=n,!this.isValidScopes(i))throw Error("scopes must be a String Array");this._scopes=i}return e.prototype.isValidScopes=function(e){return Array.isArray(e)&&e.every((function(e){return"string"==typeof e}))},e.prototype.oauthSignIn=function(e,t,n,i,o,s){void 0===e&&(e="code"),void 0===o&&(o=r.Cognito);var a=this._generateState(32),c=s?a+"-"+Object(u.urlSafeEncode)(s):a;!function(e){window.sessionStorage.setItem("oauth_state",e)}(c);var h,f=this._generateRandom(128);h=f,window.sessionStorage.setItem("ouath_pkce_key",h);var l=this._generateChallenge(f),d=this._scopes.join(" "),p="https://"+t+"/oauth2/authorize?"+Object.entries(be(be({redirect_uri:n,response_type:e,client_id:i,identity_provider:o,scope:d,state:c},"code"===e?{code_challenge:l}:{}),"code"===e?{code_challenge_method:"S256"}:{})).map((function(e){var t=Ie(e,2),n=t[0],r=t[1];return encodeURIComponent(n)+"="+encodeURIComponent(r)})).join("&");Te.debug("Redirecting to "+p),this._urlOpener(p,n)},e.prototype._handleCodeFlow=function(e){return Ce(this,void 0,void 0,(function(){var t,n,r,i,o,s,u,c,h,f,l,d,p,g;return Ue(this,(function(m){switch(m.label){case 0:return t=(Object(me.parse)(e).query||"").split("&").map((function(e){return e.split("=")})).reduce((function(e,t){var n,r=Ie(t,2),i=r[0],o=r[1];return be(be({},e),((n={})[i]=o,n))}),{code:void 0}).code,n=Object(me.parse)(e).pathname||"/",r=Object(me.parse)(this._config.redirectSignIn).pathname||"/",t&&n===r?(i="https://"+this._config.domain+"/oauth2/token",_e("codeFlow",{},"Retrieving tokens from "+i),o=a(this._config)?this._cognitoClientId:this._config.clientID,s=a(this._config)?this._config.redirectSignIn:this._config.redirectUri,y=window.sessionStorage.getItem("ouath_pkce_key"),window.sessionStorage.removeItem("ouath_pkce_key"),c=be({grant_type:"authorization_code",code:t,client_id:o,redirect_uri:s},(u=y)?{code_verifier:u}:{}),Te.debug("Calling token endpoint: "+i+" with",c),h=Object.entries(c).map((function(e){var t=Ie(e,2),n=t[0],r=t[1];return encodeURIComponent(n)+"="+encodeURIComponent(r)})).join("&"),[4,fetch(i,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:h})]):[2];case 1:return[4,m.sent().json()];case 2:if(f=m.sent(),l=f.access_token,d=f.refresh_token,p=f.id_token,g=f.error)throw new Error(g);return[2,{accessToken:l,refreshToken:d,idToken:p}]}var y}))}))},e.prototype._handleImplicitFlow=function(e){return Ce(this,void 0,void 0,(function(){var t,n,r;return Ue(this,(function(i){return t=(Object(me.parse)(e).hash||"#").substr(1).split("&").map((function(e){return e.split("=")})).reduce((function(e,t){var n,r=Ie(t,2),i=r[0],o=r[1];return be(be({},e),((n={})[i]=o,n))}),{id_token:void 0,access_token:void 0}),n=t.id_token,r=t.access_token,_e("implicitFlow",{},"Got tokens from "+e),Te.debug("Retrieving implicit tokens from "+e+" with"),[2,{accessToken:r,idToken:n,refreshToken:null}]}))}))},e.prototype.handleAuthResponse=function(e){return Ce(this,void 0,void 0,(function(){var t,n,r,i,o,s,a;return Ue(this,(function(u){switch(u.label){case 0:if(u.trys.push([0,5,,6]),t=e?be(be({},(Object(me.parse)(e).hash||"#").substr(1).split("&").map((function(e){return e.split("=")})).reduce((function(e,t){var n=Ie(t,2),r=n[0],i=n[1];return e[r]=i,e}),{})),(Object(me.parse)(e).query||"").split("&").map((function(e){return e.split("=")})).reduce((function(e,t){var n=Ie(t,2),r=n[0],i=n[1];return e[r]=i,e}),{})):{},n=t.error,r=t.error_description,n)throw new Error(r);return i=this._validateState(t),Te.debug("Starting "+this._config.responseType+" flow with "+e),"code"!==this._config.responseType?[3,2]:(o=[{}],[4,this._handleCodeFlow(e)]);case 1:return[2,be.apply(void 0,[be.apply(void 0,o.concat([u.sent()])),{state:i}])];case 2:return s=[{}],[4,this._handleImplicitFlow(e)];case 3:return[2,be.apply(void 0,[be.apply(void 0,s.concat([u.sent()])),{state:i}])];case 4:return[3,6];case 5:throw a=u.sent(),Te.error("Error handling auth response.",a),a;case 6:return[2]}}))}))},e.prototype._validateState=function(e){if(e){var t,n=(t=window.sessionStorage.getItem("oauth_state"),window.sessionStorage.removeItem("oauth_state"),t),r=e.state;if(n&&n!==r)throw new Error("Invalid state in OAuth flow");return r}},e.prototype.signOut=function(){return Ce(this,void 0,void 0,(function(){var e,t,n;return Ue(this,(function(r){return e="https://"+this._config.domain+"/logout?",t=a(this._config)?this._cognitoClientId:this._config.oauth.clientID,n=a(this._config)?this._config.redirectSignOut:this._config.returnTo,e+=Object.entries({client_id:t,logout_uri:encodeURIComponent(n)}).map((function(e){var t=Ie(e,2);return t[0]+"="+t[1]})).join("&"),_e("oAuthSignOut",{oAuth:"signOut"},"Signing out from "+e),Te.debug("Signing out from "+e),[2,this._urlOpener(e,n)]}))}))},e.prototype._generateState=function(e){for(var t="",n=e,r="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";n>0;--n)t+=r[Math.round(Math.random()*(r.length-1))];return t},e.prototype._generateChallenge=function(e){return this._base64URL(we()(e))},e.prototype._base64URL=function(e){return e.toString(Ae.a).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},e.prototype._generateRandom=function(e){var t=new Uint8Array(e);if("undefined"!=typeof window&&window.crypto)window.crypto.getRandomValues(t);else for(var n=0;n<e;n+=1)t[n]=Math.random()*"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~".length|0;return this._bufferToString(t)},e.prototype._bufferToString=function(e){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=[],r=0;r<e.byteLength;r+=1){var i=e[r]%t.length;n.push(t[i])}return n.join("")},e}();!function(e){e.DEFAULT_MSG="Authentication Error",e.EMPTY_EMAIL="Email cannot be empty",e.EMPTY_PHONE="Phone number cannot be empty",e.EMPTY_USERNAME="Username cannot be empty",e.INVALID_USERNAME="The username should either be a string or one of the sign in types",e.EMPTY_PASSWORD="Password cannot be empty",e.EMPTY_CODE="Confirmation code cannot be empty",e.SIGN_UP_ERROR="Error creating account",e.NO_MFA="No valid MFA method provided",e.INVALID_MFA="Invalid MFA type",e.EMPTY_CHALLENGE="Challenge response cannot be empty",e.NO_USER_SESSION="Failed to get the session because the user is empty",e.NETWORK_ERROR="Network Error",e.DEVICE_CONFIG="Device tracking has not been configured in this User Pool",e.AUTOSIGNIN_ERROR="Please use your credentials to sign in"}(le||(le={}));var De,Re=(De=function(e,t){return(De=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}De(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),Oe=new u.ConsoleLogger("AuthError"),ke=function(e){function t(n){var r=this,i=Fe[n],o=i.message,s=i.log;return(r=e.call(this,o)||this).constructor=t,Object.setPrototypeOf(r,t.prototype),r.name="AuthError",r.log=s||o,Oe.error(r.log),r}return Re(t,e),t}(Error),Me=function(e){function t(n){var r=e.call(this,n)||this;return r.constructor=t,Object.setPrototypeOf(r,t.prototype),r.name="NoUserPoolError",r}return Re(t,e),t}(ke),Fe={noConfig:{message:le.DEFAULT_MSG,log:"\n Error: Amplify has not been configured correctly.\n This error is typically caused by one of the following scenarios:\n\n 1. Make sure you're passing the awsconfig object to Amplify.configure() in your app's entry point\n See https://aws-amplify.github.io/docs/js/authentication#configure-your-app for more information\n \n 2. There might be multiple conflicting versions of amplify packages in your node_modules.\n\t\t\t\tRefer to our docs site for help upgrading Amplify packages (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js)\n "},missingAuthConfig:{message:le.DEFAULT_MSG,log:"\n Error: Amplify has not been configured correctly. \n The configuration object is missing required auth properties.\n This error is typically caused by one of the following scenarios:\n\n 1. Did you run `amplify push` after adding auth via `amplify add auth`?\n See https://aws-amplify.github.io/docs/js/authentication#amplify-project-setup for more information\n\n 2. This could also be caused by multiple conflicting versions of amplify packages, see (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js) for help upgrading Amplify packages.\n "},emptyUsername:{message:le.EMPTY_USERNAME},invalidUsername:{message:le.INVALID_USERNAME},emptyPassword:{message:le.EMPTY_PASSWORD},emptyCode:{message:le.EMPTY_CODE},signUpError:{message:le.SIGN_UP_ERROR,log:"The first parameter should either be non-null string or object"},noMFA:{message:le.NO_MFA},invalidMFA:{message:le.INVALID_MFA},emptyChallengeResponse:{message:le.EMPTY_CHALLENGE},noUserSession:{message:le.NO_USER_SESSION},deviceConfig:{message:le.DEVICE_CONFIG},networkError:{message:le.NETWORK_ERROR},autoSignInError:{message:le.AUTOSIGNIN_ERROR},default:{message:le.DEFAULT_MSG}};function Ne(e){return(Ne="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var xe=function(){return(xe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},Be=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{u(r.next(e))}catch(e){o(e)}}function a(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},je=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},Ve=function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s},qe=new u.ConsoleLogger("AuthClass"),Ke="undefined"!=typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("amplify_default"):"@@amplify_default",He=function(e,t,n){u.Hub.dispatch("auth",{event:e,data:t,message:n},"Auth",Ke)},Le=new(function(){function e(e){var t=this;this.userPool=null,this.user=null,this.oAuthFlowInProgress=!1,this.autoSignInInitiated=!1,this.Credentials=u.Credentials,this.wrapRefreshSessionCallback=function(e){return function(t,n){return n?He("tokenRefresh",void 0,"New token retrieved"):He("tokenRefresh_failure",t,"Failed to retrieve new token"),e(t,n)}},this.configure(e),this.currentCredentials=this.currentCredentials.bind(this),this.currentUserCredentials=this.currentUserCredentials.bind(this),u.Hub.listen("auth",(function(e){switch(e.payload.event){case"signIn":t._storage.setItem("amplify-signin-with-hostedUI","false");break;case"signOut":t._storage.removeItem("amplify-signin-with-hostedUI");break;case"cognitoHostedUI":t._storage.setItem("amplify-signin-with-hostedUI","true")}}))}return e.prototype.getModuleName=function(){return"Auth"},e.prototype.configure=function(e){var t=this;if(!e)return this._config||{};qe.debug("configure Auth");var n=Object.assign({},this._config,u.Parser.parseMobilehubConfig(e).Auth,e);this._config=n;var r=this._config,o=r.userPoolId,s=r.userPoolWebClientId,c=r.cookieStorage,h=r.oauth,f=r.region,l=r.identityPoolId,d=r.mandatorySignIn,p=r.refreshHandlers,g=r.identityPoolRegion,m=r.clientMetadata,y=r.endpoint;if(this._config.storage){if(!this._isValidAuthStorage(this._config.storage))throw qe.error("The storage in the Auth config is not valid!"),new Error("Empty storage object");this._storage=this._config.storage}else this._storage=c?new ge(c):e.ssr?new u.UniversalStorage:(new u.StorageHelper).getStorage();if(this._storageSync=Promise.resolve(),"function"==typeof this._storage.sync&&(this._storageSync=this._storage.sync()),o){var v={UserPoolId:o,ClientId:s,endpoint:y};v.Storage=this._storage,this.userPool=new de(v,this.wrapRefreshSessionCallback)}this.Credentials.configure({mandatorySignIn:d,region:g||f,userPoolId:o,identityPoolId:l,refreshHandlers:p,storage:this._storage});var w=h?a(this._config.oauth)?h:h.awsCognito:void 0;if(w){var S=Object.assign({cognitoClientId:s,UserPoolId:o,domain:w.domain,scopes:w.scope,redirectSignIn:w.redirectSignIn,redirectSignOut:w.redirectSignOut,responseType:w.responseType,Storage:this._storage,urlOpener:w.urlOpener,clientMetadata:m},w.options);this._oAuthHandler=new Pe({scopes:S.scopes,config:S,cognitoClientId:S.cognitoClientId});var A={};!function(e){if(Object(u.browserOrNode)().isBrowser&&window.location)e({url:window.location.href});else if(!Object(u.browserOrNode)().isNode)throw new Error("Not supported")}((function(e){var n=e.url;A[n]||(A[n]=!0,t._handleAuthResponse(n))}))}(He("configured",null,"The Auth category has been configured successfully"),this.autoSignInInitiated||"function"!=typeof this._storage.getItem)||(this.isTrueStorageValue("amplify-polling-started")&&(He("autoSignIn_failure",null,i.AutoSignInError),this._storage.removeItem("amplify-auto-sign-in")),this._storage.removeItem("amplify-polling-started"));return this._config},e.prototype.signUp=function(e){for(var t,n,r,o=this,s=[],a=1;a<arguments.length;a++)s[a-1]=arguments[a];if(!this.userPool)return this.rejectNoUserPool();var u,c=null,h=null,f=[],l=null,d={enabled:!1},p={},g={};if(e&&"string"==typeof e){c=e,h=s?s[0]:null;var m=s?s[1]:null,y=s?s[2]:null;m&&f.push(new G({Name:"email",Value:m})),y&&f.push(new G({Name:"phone_number",Value:y}))}else{if(!e||"object"!==Ne(e))return this.rejectAuthError(i.SignUpError);c=e.username,h=e.password,e&&e.clientMetadata?u=e.clientMetadata:this._config.clientMetadata&&(u=this._config.clientMetadata);var v=e.attributes;v&&Object.keys(v).map((function(e){f.push(new G({Name:e,Value:v[e]}))}));var w=e.validationData;w&&(l=[],Object.keys(w).map((function(e){l.push(new G({Name:e,Value:w[e]}))}))),(d=null!==(t=e.autoSignIn)&&void 0!==t?t:{enabled:!1}).enabled&&(this._storage.setItem("amplify-auto-sign-in","true"),p=null!==(n=d.validationData)&&void 0!==n?n:{},g=null!==(r=d.clientMetaData)&&void 0!==r?r:{})}return c?h?(qe.debug("signUp attrs:",f),qe.debug("signUp validation data:",l),new Promise((function(e,t){o.userPool.signUp(c,h,f,l,(function(n,r){n?(He("signUp_failure",n,c+" failed to signup"),t(n)):(He("signUp",r,c+" has signed up successfully"),d.enabled&&o.handleAutoSignIn(c,h,p,g,r),e(r))}),u)}))):this.rejectAuthError(i.EmptyPassword):this.rejectAuthError(i.EmptyUsername)},e.prototype.handleAutoSignIn=function(e,t,n,r,i){this.autoSignInInitiated=!0;var o=new c({Username:e,Password:t,ValidationData:n,ClientMetadata:r});i.userConfirmed?this.signInAfterUserConfirmed(o):"link"===this._config.signUpVerificationMethod?this.handleLinkAutoSignIn(o):this.handleCodeAutoSignIn(o)},e.prototype.handleCodeAutoSignIn=function(e){var t=this;u.Hub.listen("auth",(function n(r){"confirmSignUp"===r.payload.event&&t.signInAfterUserConfirmed(e,n)}))},e.prototype.handleLinkAutoSignIn=function(e){var t=this;this._storage.setItem("amplify-polling-started","true");var n=Date.now(),r=setInterval((function(){Date.now()-n>18e4?(clearInterval(r),He("autoSignIn_failure",null,"Please confirm your account and use your credentials to sign in."),t._storage.removeItem("amplify-auto-sign-in")):t.signInAfterUserConfirmed(e,null,r)}),5e3)},e.prototype.signInAfterUserConfirmed=function(e,t,n){return Be(this,void 0,void 0,(function(){var r,i,o=this;return je(this,(function(s){switch(s.label){case 0:r=this.createCognitoUser(e.getUsername()),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,r.authenticateUser(e,this.authCallbacks(r,(function(r){He("autoSignIn",r,e.getUsername()+" has signed in successfully"),t&&u.Hub.remove("auth",t),n&&(clearInterval(n),o._storage.removeItem("amplify-polling-started")),o._storage.removeItem("amplify-auto-sign-in")}),(function(e){qe.error(e),o._storage.removeItem("amplify-auto-sign-in")})))];case 2:return s.sent(),[3,4];case 3:return i=s.sent(),qe.error(i),[3,4];case 4:return[2]}}))}))},e.prototype.confirmSignUp=function(e,t,n){var r=this;if(!this.userPool)return this.rejectNoUserPool();if(!e)return this.rejectAuthError(i.EmptyUsername);if(!t)return this.rejectAuthError(i.EmptyCode);var o,s=this.createCognitoUser(e),a=!n||"boolean"!=typeof n.forceAliasCreation||n.forceAliasCreation;return n&&n.clientMetadata?o=n.clientMetadata:this._config.clientMetadata&&(o=this._config.clientMetadata),new Promise((function(n,u){s.confirmRegistration(t,a,(function(t,o){t?u(t):(He("confirmSignUp",o,e+" has been confirmed successfully"),r.isTrueStorageValue("amplify-auto-sign-in")&&!r.autoSignInInitiated&&(He("autoSignIn_failure",null,i.AutoSignInError),r._storage.removeItem("amplify-auto-sign-in")),n(o))}),o)}))},e.prototype.isTrueStorageValue=function(e){var t=this._storage.getItem(e);return!!t&&"true"===t},e.prototype.resendSignUp=function(e,t){if(void 0===t&&(t=this._config.clientMetadata),!this.userPool)return this.rejectNoUserPool();if(!e)return this.rejectAuthError(i.EmptyUsername);var n=this.createCognitoUser(e);return new Promise((function(e,r){n.resendConfirmationCode((function(t,n){t?r(t):e(n)}),t)}))},e.prototype.signIn=function(e,t,n){if(void 0===n&&(n=this._config.clientMetadata),!this.userPool)return this.rejectNoUserPool();var r=null,o=null,s={};if("string"==typeof e)r=e,o=t;else{if(!e.username)return this.rejectAuthError(i.InvalidUsername);void 0!==t&&qe.warn("The password should be defined under the first parameter object!"),r=e.username,o=e.password,s=e.validationData}if(!r)return this.rejectAuthError(i.EmptyUsername);var a=new c({Username:r,Password:o,ValidationData:s,ClientMetadata:n});return o?this.signInWithPassword(a):this.signInWithoutPassword(a)},e.prototype.authCallbacks=function(e,t,n){var r=this,i=this;return{onSuccess:function(o){return Be(r,void 0,void 0,(function(){var r,s,a,u;return je(this,(function(c){switch(c.label){case 0:qe.debug(o),delete e.challengeName,delete e.challengeParam,c.label=1;case 1:return c.trys.push([1,4,5,9]),[4,this.Credentials.clear()];case 2:return c.sent(),[4,this.Credentials.set(o,"session")];case 3:return r=c.sent(),qe.debug("succeed to get cognito credentials",r),[3,9];case 4:return s=c.sent(),qe.debug("cannot get cognito credentials",s),[3,9];case 5:return c.trys.push([5,7,,8]),[4,this.currentUserPoolUser()];case 6:return a=c.sent(),i.user=a,He("signIn",a,"A user "+e.getUsername()+" has been signed in"),t(a),[3,8];case 7:return u=c.sent(),qe.error("Failed to get the signed in user",u),n(u),[3,8];case 8:return[7];case 9:return[2]}}))}))},onFailure:function(t){qe.debug("signIn failure",t),He("signIn_failure",t,e.getUsername()+" failed to signin"),n(t)},customChallenge:function(n){qe.debug("signIn custom challenge answer required"),e.challengeName="CUSTOM_CHALLENGE",e.challengeParam=n,t(e)},mfaRequired:function(n,r){qe.debug("signIn MFA required"),e.challengeName=n,e.challengeParam=r,t(e)},mfaSetup:function(n,r){qe.debug("signIn mfa setup",n),e.challengeName=n,e.challengeParam=r,t(e)},newPasswordRequired:function(n,r){qe.debug("signIn new password"),e.challengeName="NEW_PASSWORD_REQUIRED",e.challengeParam={userAttributes:n,requiredAttributes:r},t(e)},totpRequired:function(n,r){qe.debug("signIn totpRequired"),e.challengeName=n,e.challengeParam=r,t(e)},selectMFAType:function(n,r){qe.debug("signIn selectMFAType",n),e.challengeName=n,e.challengeParam=r,t(e)}}},e.prototype.signInWithPassword=function(e){var t=this;if(this.pendingSignIn)throw new Error("Pending sign-in attempt already in progress");var n=this.createCognitoUser(e.getUsername());return this.pendingSignIn=new Promise((function(r,i){n.authenticateUser(e,t.authCallbacks(n,(function(e){t.pendingSignIn=null,r(e)}),(function(e){t.pendingSignIn=null,i(e)})))})),this.pendingSignIn},e.prototype.signInWithoutPassword=function(e){var t=this,n=this.createCognitoUser(e.getUsername());return n.setAuthenticationFlowType("CUSTOM_AUTH"),new Promise((function(r,i){n.initiateAuth(e,t.authCallbacks(n,r,i))}))},e.prototype.getMFAOptions=function(e){return new Promise((function(t,n){e.getMFAOptions((function(e,r){if(e)return qe.debug("get MFA Options failed",e),void n(e);qe.debug("get MFA options success",r),t(r)}))}))},e.prototype.getPreferredMFA=function(e,t){var n=this,r=this;return new Promise((function(i,o){var s=n._config.clientMetadata,a=!!t&&t.bypassCache;e.getUserData((function(t,s){return Be(n,void 0,void 0,(function(){var n,a;return je(this,(function(u){switch(u.label){case 0:if(!t)return[3,5];if(qe.debug("getting preferred mfa failed",t),!this.isSessionInvalid(t))return[3,4];u.label=1;case 1:return u.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(e)];case 2:return u.sent(),[3,4];case 3:return n=u.sent(),o(new Error("Session is invalid due to: "+t.message+" and failed to clean up invalid session: "+n.message)),[2];case 4:return o(t),[2];case 5:return(a=r._getMfaTypeFromUserData(s))?(i(a),[2]):(o("invalid MFA Type"),[2])}}))}))}),{bypassCache:a,clientMetadata:s})}))},e.prototype._getMfaTypeFromUserData=function(e){var t=null,n=e.PreferredMfaSetting;if(n)t=n;else{var r=e.UserMFASettingList;if(r)0===r.length?t="NOMFA":qe.debug("invalid case for getPreferredMFA",e);else t=e.MFAOptions?"SMS_MFA":"NOMFA"}return t},e.prototype._getUserData=function(e,t){var n=this;return new Promise((function(r,i){e.getUserData((function(t,o){return Be(n,void 0,void 0,(function(){var n;return je(this,(function(s){switch(s.label){case 0:if(!t)return[3,5];if(qe.debug("getting user data failed",t),!this.isSessionInvalid(t))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(e)];case 2:return s.sent(),[3,4];case 3:return n=s.sent(),i(new Error("Session is invalid due to: "+t.message+" and failed to clean up invalid session: "+n.message)),[2];case 4:return i(t),[2];case 5:r(o),s.label=6;case 6:return[2]}}))}))}),t)}))},e.prototype.setPreferredMFA=function(e,t){return Be(this,void 0,void 0,(function(){var n,r,o,s,a,u,c=this;return je(this,(function(h){switch(h.label){case 0:return n=this._config.clientMetadata,[4,this._getUserData(e,{bypassCache:!0,clientMetadata:n})];case 1:switch(r=h.sent(),o=null,s=null,t){case"TOTP":case"SOFTWARE_TOKEN_MFA":return[3,2];case"SMS":case"SMS_MFA":return[3,3];case"NOMFA":return[3,4]}return[3,6];case 2:return s={PreferredMfa:!0,Enabled:!0},[3,7];case 3:return o={PreferredMfa:!0,Enabled:!0},[3,7];case 4:return a=r.UserMFASettingList,[4,this._getMfaTypeFromUserData(r)];case 5:if("NOMFA"===(u=h.sent()))return[2,Promise.resolve("No change for mfa type")];if("SMS_MFA"===u)o={PreferredMfa:!1,Enabled:!1};else{if("SOFTWARE_TOKEN_MFA"!==u)return[2,this.rejectAuthError(i.InvalidMFA)];s={PreferredMfa:!1,Enabled:!1}}return a&&0!==a.length&&a.forEach((function(e){"SMS_MFA"===e?o={PreferredMfa:!1,Enabled:!1}:"SOFTWARE_TOKEN_MFA"===e&&(s={PreferredMfa:!1,Enabled:!1})})),[3,7];case 6:return qe.debug("no validmfa method provided"),[2,this.rejectAuthError(i.NoMFA)];case 7:return this,[2,new Promise((function(t,r){e.setUserMfaPreference(o,s,(function(i,o){if(i)return qe.debug("Set user mfa preference error",i),r(i);qe.debug("Set user mfa success",o),qe.debug("Caching the latest user data into local"),e.getUserData((function(n,i){return Be(c,void 0,void 0,(function(){var i;return je(this,(function(s){switch(s.label){case 0:if(!n)return[3,5];if(qe.debug("getting user data failed",n),!this.isSessionInvalid(n))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(e)];case 2:return s.sent(),[3,4];case 3:return i=s.sent(),r(new Error("Session is invalid due to: "+n.message+" and failed to clean up invalid session: "+i.message)),[2];case 4:return[2,r(n)];case 5:return[2,t(o)]}}))}))}),{bypassCache:!0,clientMetadata:n})}))}))]}}))}))},e.prototype.disableSMS=function(e){return new Promise((function(t,n){e.disableMFA((function(e,r){if(e)return qe.debug("disable mfa failed",e),void n(e);qe.debug("disable mfa succeed",r),t(r)}))}))},e.prototype.enableSMS=function(e){return new Promise((function(t,n){e.enableMFA((function(e,r){if(e)return qe.debug("enable mfa failed",e),void n(e);qe.debug("enable mfa succeed",r),t(r)}))}))},e.prototype.setupTOTP=function(e){return new Promise((function(t,n){e.associateSoftwareToken({onFailure:function(e){qe.debug("associateSoftwareToken failed",e),n(e)},associateSecretCode:function(e){qe.debug("associateSoftwareToken sucess",e),t(e)}})}))},e.prototype.verifyTotpToken=function(e,t){return qe.debug("verification totp token",e,t),new Promise((function(n,r){e.verifySoftwareToken(t,"My TOTP device",{onFailure:function(e){qe.debug("verifyTotpToken failed",e),r(e)},onSuccess:function(t){He("signIn",e,"A user "+e.getUsername()+" has been signed in"),qe.debug("verifyTotpToken success",t),n(t)}})}))},e.prototype.confirmSignIn=function(e,t,n,r){var o=this;if(void 0===r&&(r=this._config.clientMetadata),!t)return this.rejectAuthError(i.EmptyCode);var s=this;return new Promise((function(i,a){e.sendMFACode(t,{onSuccess:function(t){return Be(o,void 0,void 0,(function(){var n,r;return je(this,(function(o){switch(o.label){case 0:qe.debug(t),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,this.Credentials.clear()];case 2:return o.sent(),[4,this.Credentials.set(t,"session")];case 3:return n=o.sent(),qe.debug("succeed to get cognito credentials",n),[3,6];case 4:return r=o.sent(),qe.debug("cannot get cognito credentials",r),[3,6];case 5:return s.user=e,He("signIn",e,"A user "+e.getUsername()+" has been signed in"),i(e),[7];case 6:return[2]}}))}))},onFailure:function(e){qe.debug("confirm signIn failure",e),a(e)}},n,r)}))},e.prototype.completeNewPassword=function(e,t,n,r){var o=this;if(void 0===n&&(n={}),void 0===r&&(r=this._config.clientMetadata),!t)return this.rejectAuthError(i.EmptyPassword);var s=this;return new Promise((function(i,a){e.completeNewPasswordChallenge(t,n,{onSuccess:function(t){return Be(o,void 0,void 0,(function(){var n,r;return je(this,(function(o){switch(o.label){case 0:qe.debug(t),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,this.Credentials.clear()];case 2:return o.sent(),[4,this.Credentials.set(t,"session")];case 3:return n=o.sent(),qe.debug("succeed to get cognito credentials",n),[3,6];case 4:return r=o.sent(),qe.debug("cannot get cognito credentials",r),[3,6];case 5:return s.user=e,He("signIn",e,"A user "+e.getUsername()+" has been signed in"),i(e),[7];case 6:return[2]}}))}))},onFailure:function(e){qe.debug("completeNewPassword failure",e),He("completeNewPassword_failure",e,o.user+" failed to complete the new password flow"),a(e)},mfaRequired:function(t,n){qe.debug("signIn MFA required"),e.challengeName=t,e.challengeParam=n,i(e)},mfaSetup:function(t,n){qe.debug("signIn mfa setup",t),e.challengeName=t,e.challengeParam=n,i(e)},totpRequired:function(t,n){qe.debug("signIn mfa setup",t),e.challengeName=t,e.challengeParam=n,i(e)}},r)}))},e.prototype.sendCustomChallengeAnswer=function(e,t,n){var r=this;if(void 0===n&&(n=this._config.clientMetadata),!this.userPool)return this.rejectNoUserPool();if(!t)return this.rejectAuthError(i.EmptyChallengeResponse);return new Promise((function(i,o){e.sendCustomChallengeAnswer(t,r.authCallbacks(e,i,o),n)}))},e.prototype.deleteUserAttributes=function(e,t){var n=this;return new Promise((function(r,i){n.userSession(e).then((function(n){e.deleteAttributes(t,(function(e,t){return e?i(e):r(t)}))}))}))},e.prototype.deleteUser=function(){return Be(this,void 0,void 0,(function(){var e,t,n=this;return je(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._storageSync];case 1:return r.sent(),[3,3];case 2:throw e=r.sent(),qe.debug("Failed to sync cache info into memory",e),new Error(e);case 3:return t=this._oAuthHandler&&"true"===this._storage.getItem("amplify-signin-with-hostedUI"),[2,new Promise((function(e,r){return Be(n,void 0,void 0,(function(){var n,i=this;return je(this,(function(o){if(this.userPool){if(!(n=this.userPool.getCurrentUser()))return qe.debug("Failed to get user from user pool"),[2,r(new Error("No current user."))];n.getSession((function(o,s){return Be(i,void 0,void 0,(function(){var i,s=this;return je(this,(function(a){switch(a.label){case 0:if(!o)return[3,5];if(qe.debug("Failed to get the user session",o),!this.isSessionInvalid(o))return[3,4];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(n)];case 2:return a.sent(),[3,4];case 3:return i=a.sent(),r(new Error("Session is invalid due to: "+o.message+" and failed to clean up invalid session: "+i.message)),[2];case 4:return[2,r(o)];case 5:n.deleteUser((function(i,o){if(i)r(i);else{He("userDeleted",o,"The authenticated user has been deleted."),n.signOut(),s.user=null;try{s.cleanCachedItems()}catch(e){qe.debug("failed to clear cached items")}t?s.oAuthSignOutRedirect(e,r):(He("signOut",s.user,"A user has been signed out"),e(o))}})),a.label=6;case 6:return[2]}}))}))}))}else qe.debug("no Congito User pool"),r(new Error("Cognito User pool does not exist"));return[2]}))}))}))]}}))}))},e.prototype.updateUserAttributes=function(e,t,n){void 0===n&&(n=this._config.clientMetadata);var r=[],i=this;return new Promise((function(o,s){i.userSession(e).then((function(i){for(var a in t)if("sub"!==a&&a.indexOf("_verified")<0){var u={Name:a,Value:t[a]};r.push(u)}e.updateAttributes(r,(function(e,t){return e?s(e):o(t)}),n)}))}))},e.prototype.userAttributes=function(e){var t=this;return new Promise((function(n,r){t.userSession(e).then((function(t){e.getUserAttributes((function(e,t){e?r(e):n(t)}))}))}))},e.prototype.verifiedContact=function(e){var t=this;return this.userAttributes(e).then((function(e){var n=t.attributesToObject(e),r={},i={};return n.email&&(n.email_verified?i.email=n.email:r.email=n.email),n.phone_number&&(n.phone_number_verified?i.phone_number=n.phone_number:r.phone_number=n.phone_number),{verified:i,unverified:r}}))},e.prototype.isErrorWithMessage=function(e){return"object"===Ne(e)&&Object.prototype.hasOwnProperty.call(e,"message")},e.prototype.isTokenRevokedError=function(e){return this.isErrorWithMessage(e)&&"Access Token has been revoked"===e.message},e.prototype.isRefreshTokenRevokedError=function(e){return this.isErrorWithMessage(e)&&"Refresh Token has been revoked"===e.message},e.prototype.isUserDisabledError=function(e){return this.isErrorWithMessage(e)&&"User is disabled."===e.message},e.prototype.isUserDoesNotExistError=function(e){return this.isErrorWithMessage(e)&&"User does not exist."===e.message},e.prototype.isRefreshTokenExpiredError=function(e){return this.isErrorWithMessage(e)&&"Refresh Token has expired"===e.message},e.prototype.isSignedInHostedUI=function(){return this._oAuthHandler&&"true"===this._storage.getItem("amplify-signin-with-hostedUI")},e.prototype.isSessionInvalid=function(e){return this.isUserDisabledError(e)||this.isUserDoesNotExistError(e)||this.isTokenRevokedError(e)||this.isRefreshTokenRevokedError(e)||this.isRefreshTokenExpiredError(e)},e.prototype.cleanUpInvalidSession=function(e){return Be(this,void 0,void 0,(function(){var t=this;return je(this,(function(n){switch(n.label){case 0:e.signOut(),this.user=null,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.cleanCachedItems()];case 2:return n.sent(),[3,4];case 3:return n.sent(),qe.debug("failed to clear cached items"),[3,4];case 4:return this.isSignedInHostedUI()?[2,new Promise((function(e,n){t.oAuthSignOutRedirect(e,n)}))]:(He("signOut",this.user,"A user has been signed out"),[2])}}))}))},e.prototype.currentUserPoolUser=function(e){var t=this;return this.userPool?new Promise((function(n,r){t._storageSync.then((function(){return Be(t,void 0,void 0,(function(){var t,i,o=this;return je(this,(function(s){switch(s.label){case 0:return this.isOAuthInProgress()?(qe.debug("OAuth signIn in progress, waiting for resolution..."),[4,new Promise((function(e){var t=setTimeout((function(){qe.debug("OAuth signIn in progress timeout"),u.Hub.remove("auth",n),e()}),1e4);function n(r){var i=r.payload.event;"cognitoHostedUI"!==i&&"cognitoHostedUI_failure"!==i||(qe.debug("OAuth signIn resolved: "+i),clearTimeout(t),u.Hub.remove("auth",n),e())}u.Hub.listen("auth",n)}))]):[3,2];case 1:s.sent(),s.label=2;case 2:return(t=this.userPool.getCurrentUser())?(i=this._config.clientMetadata,t.getSession((function(i,s){return Be(o,void 0,void 0,(function(){var o,a,u,c,h=this;return je(this,(function(f){switch(f.label){case 0:if(!i)return[3,5];if(qe.debug("Failed to get the user session",i),!this.isSessionInvalid(i))return[3,4];f.label=1;case 1:return f.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(t)];case 2:return f.sent(),[3,4];case 3:return o=f.sent(),r(new Error("Session is invalid due to: "+i.message+" and failed to clean up invalid session: "+o.message)),[2];case 4:return r(i),[2];case 5:return(a=!!e&&e.bypassCache)?[4,this.Credentials.clear()]:[3,7];case 6:f.sent(),f.label=7;case 7:return u=this._config.clientMetadata,c=s.getAccessToken().decodePayload().scope,(void 0===c?"":c).split(" ").includes("aws.cognito.signin.user.admin")?(t.getUserData((function(e,i){return Be(h,void 0,void 0,(function(){var o,s,a,u,c,h,f;return je(this,(function(l){switch(l.label){case 0:if(!e)return[3,7];if(qe.debug("getting user data failed",e),!this.isSessionInvalid(e))return[3,5];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(t)];case 2:return l.sent(),[3,4];case 3:return o=l.sent(),r(new Error("Session is invalid due to: "+e.message+" and failed to clean up invalid session: "+o.message)),[2];case 4:return r(e),[3,6];case 5:n(t),l.label=6;case 6:return[2];case 7:for(s=i.PreferredMfaSetting||"NOMFA",a=[],u=0;u<i.UserAttributes.length;u++)c={Name:i.UserAttributes[u].Name,Value:i.UserAttributes[u].Value},h=new G(c),a.push(h);return f=this.attributesToObject(a),Object.assign(t,{attributes:f,preferredMFA:s}),[2,n(t)]}}))}))}),{bypassCache:a,clientMetadata:u}),[2]):(qe.debug("Unable to get the user data because the aws.cognito.signin.user.admin is not in the scopes of the access token"),[2,n(t)])}}))}))}),{clientMetadata:i}),[2]):(qe.debug("Failed to get user from user pool"),r("No current user"),[2])}}))}))})).catch((function(e){return qe.debug("Failed to sync cache info into memory",e),r(e)}))})):this.rejectNoUserPool()},e.prototype.isOAuthInProgress=function(){return this.oAuthFlowInProgress},e.prototype.currentAuthenticatedUser=function(e){return Be(this,void 0,void 0,(function(){var t,n,r,i,o;return je(this,(function(s){switch(s.label){case 0:qe.debug("getting current authenticated user"),t=null,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this._storageSync];case 2:return s.sent(),[3,4];case 3:throw n=s.sent(),qe.debug("Failed to sync cache info into memory",n),n;case 4:try{(r=JSON.parse(this._storage.getItem("aws-amplify-federatedInfo")))&&(t=xe(xe({},r.user),{token:r.token}))}catch(e){qe.debug("cannot load federated user from auth storage")}return t?(this.user=t,qe.debug("get current authenticated federated user",this.user),[2,this.user]):[3,5];case 5:qe.debug("get current authenticated userpool user"),i=null,s.label=6;case 6:return s.trys.push([6,8,,9]),[4,this.currentUserPoolUser(e)];case 7:return i=s.sent(),[3,9];case 8:return"No userPool"===(o=s.sent())&&qe.error("Cannot get the current user because the user pool is missing. Please make sure the Auth module is configured with a valid Cognito User Pool ID"),qe.debug("The user is not authenticated by the error",o),[2,Promise.reject("The user is not authenticated")];case 9:return this.user=i,[2,this.user]}}))}))},e.prototype.currentSession=function(){var e=this;return qe.debug("Getting current session"),this.userPool?new Promise((function(t,n){e.currentUserPoolUser().then((function(r){e.userSession(r).then((function(e){t(e)})).catch((function(e){qe.debug("Failed to get the current session",e),n(e)}))})).catch((function(e){qe.debug("Failed to get the current user",e),n(e)}))})):Promise.reject(new Error("No User Pool in the configuration."))},e.prototype.userSession=function(e){var t=this;if(!e)return qe.debug("the user is null"),this.rejectAuthError(i.NoUserSession);var n=this._config.clientMetadata;return new Promise((function(r,i){qe.debug("Getting the session from this user:",e),e.getSession((function(n,o){return Be(t,void 0,void 0,(function(){var t;return je(this,(function(s){switch(s.label){case 0:if(!n)return[3,5];if(qe.debug("Failed to get the session from user",e),!this.isSessionInvalid(n))return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(e)];case 2:return s.sent(),[3,4];case 3:return t=s.sent(),i(new Error("Session is invalid due to: "+n.message+" and failed to clean up invalid session: "+t.message)),[2];case 4:return i(n),[2];case 5:return qe.debug("Succeed to get the user session",o),r(o),[2]}}))}))}),{clientMetadata:n})}))},e.prototype.currentUserCredentials=function(){return Be(this,void 0,void 0,(function(){var e,t,n=this;return je(this,(function(r){switch(r.label){case 0:qe.debug("Getting current user credentials"),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this._storageSync];case 2:return r.sent(),[3,4];case 3:throw e=r.sent(),qe.debug("Failed to sync cache info into memory",e),e;case 4:t=null;try{t=JSON.parse(this._storage.getItem("aws-amplify-federatedInfo"))}catch(e){qe.debug("failed to get or parse item aws-amplify-federatedInfo",e)}return t?[2,this.Credentials.refreshFederatedToken(t)]:[2,this.currentSession().then((function(e){return qe.debug("getting session success",e),n.Credentials.set(e,"session")})).catch((function(){return qe.debug("getting guest credentials"),n.Credentials.set(null,"guest")}))]}}))}))},e.prototype.currentCredentials=function(){return qe.debug("getting current credentials"),this.Credentials.get()},e.prototype.verifyUserAttribute=function(e,t,n){return void 0===n&&(n=this._config.clientMetadata),new Promise((function(r,i){e.getAttributeVerificationCode(t,{onSuccess:function(e){return r(e)},onFailure:function(e){return i(e)}},n)}))},e.prototype.verifyUserAttributeSubmit=function(e,t,n){return n?new Promise((function(r,i){e.verifyAttribute(t,n,{onSuccess:function(e){r(e)},onFailure:function(e){i(e)}})})):this.rejectAuthError(i.EmptyCode)},e.prototype.verifyCurrentUserAttribute=function(e){var t=this;return t.currentUserPoolUser().then((function(n){return t.verifyUserAttribute(n,e)}))},e.prototype.verifyCurrentUserAttributeSubmit=function(e,t){var n=this;return n.currentUserPoolUser().then((function(r){return n.verifyUserAttributeSubmit(r,e,t)}))},e.prototype.cognitoIdentitySignOut=function(e,t){return Be(this,void 0,void 0,(function(){var n,r,i=this;return je(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this._storageSync];case 1:return o.sent(),[3,3];case 2:throw n=o.sent(),qe.debug("Failed to sync cache info into memory",n),n;case 3:return r=this._oAuthHandler&&"true"===this._storage.getItem("amplify-signin-with-hostedUI"),[2,new Promise((function(n,o){if(e&&e.global){qe.debug("user global sign out",t);var s=i._config.clientMetadata;t.getSession((function(e,s){return Be(i,void 0,void 0,(function(){var i,s=this;return je(this,(function(a){switch(a.label){case 0:if(!e)return[3,5];if(qe.debug("failed to get the user session",e),!this.isSessionInvalid(e))return[3,4];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.cleanUpInvalidSession(t)];case 2:return a.sent(),[3,4];case 3:return i=a.sent(),o(new Error("Session is invalid due to: "+e.message+" and failed to clean up invalid session: "+i.message)),[2];case 4:return[2,o(e)];case 5:return t.globalSignOut({onSuccess:function(e){if(qe.debug("global sign out success"),!r)return n();s.oAuthSignOutRedirect(n,o)},onFailure:function(e){return qe.debug("global sign out failed",e),o(e)}}),[2]}}))}))}),{clientMetadata:s})}else qe.debug("user sign out",t),t.signOut((function(){if(!r)return n();i.oAuthSignOutRedirect(n,o)}))}))]}}))}))},e.prototype.oAuthSignOutRedirect=function(e,t){Object(u.browserOrNode)().isBrowser?this.oAuthSignOutRedirectOrReject(t):this.oAuthSignOutAndResolve(e)},e.prototype.oAuthSignOutAndResolve=function(e){this._oAuthHandler.signOut(),e()},e.prototype.oAuthSignOutRedirectOrReject=function(e){this._oAuthHandler.signOut(),setTimeout((function(){return e(Error("Signout timeout fail"))}),3e3)},e.prototype.signOut=function(e){return Be(this,void 0,void 0,(function(){var t;return je(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.cleanCachedItems()];case 1:return n.sent(),[3,3];case 2:return n.sent(),qe.debug("failed to clear cached items"),[3,3];case 3:return this.userPool?(t=this.userPool.getCurrentUser())?[4,this.cognitoIdentitySignOut(e,t)]:[3,5]:[3,7];case 4:return n.sent(),[3,6];case 5:qe.debug("no current Cognito user"),n.label=6;case 6:return[3,8];case 7:qe.debug("no Cognito User pool"),n.label=8;case 8:return He("signOut",this.user,"A user has been signed out"),this.user=null,[2]}}))}))},e.prototype.cleanCachedItems=function(){return Be(this,void 0,void 0,(function(){return je(this,(function(e){switch(e.label){case 0:return[4,this.Credentials.clear()];case 1:return e.sent(),[2]}}))}))},e.prototype.changePassword=function(e,t,n,r){var i=this;return void 0===r&&(r=this._config.clientMetadata),new Promise((function(o,s){i.userSession(e).then((function(i){e.changePassword(t,n,(function(e,t){return e?(qe.debug("change password failure",e),s(e)):o(t)}),r)}))}))},e.prototype.forgotPassword=function(e,t){if(void 0===t&&(t=this._config.clientMetadata),!this.userPool)return this.rejectNoUserPool();if(!e)return this.rejectAuthError(i.EmptyUsername);var n=this.createCognitoUser(e);return new Promise((function(r,i){n.forgotPassword({onSuccess:function(){r()},onFailure:function(t){qe.debug("forgot password failure",t),He("forgotPassword_failure",t,e+" forgotPassword failed"),i(t)},inputVerificationCode:function(t){He("forgotPassword",n,e+" has initiated forgot password flow"),r(t)}},t)}))},e.prototype.forgotPasswordSubmit=function(e,t,n,r){if(void 0===r&&(r=this._config.clientMetadata),!this.userPool)return this.rejectNoUserPool();if(!e)return this.rejectAuthError(i.EmptyUsername);if(!t)return this.rejectAuthError(i.EmptyCode);if(!n)return this.rejectAuthError(i.EmptyPassword);var o=this.createCognitoUser(e);return new Promise((function(i,s){o.confirmPassword(t,n,{onSuccess:function(t){He("forgotPasswordSubmit",o,e+" forgotPasswordSubmit successful"),i(t)},onFailure:function(t){He("forgotPasswordSubmit_failure",t,e+" forgotPasswordSubmit failed"),s(t)}},r)}))},e.prototype.currentUserInfo=function(){return Be(this,void 0,void 0,(function(){var e,t,n,r,i,o,s;return je(this,(function(a){switch(a.label){case 0:return(e=this.Credentials.getCredSource())&&"aws"!==e&&"userPool"!==e?[3,9]:[4,this.currentUserPoolUser().catch((function(e){return qe.error(e)}))];case 1:if(!(s=a.sent()))return[2,null];a.label=2;case 2:return a.trys.push([2,8,,9]),[4,this.userAttributes(s)];case 3:t=a.sent(),n=this.attributesToObject(t),r=null,a.label=4;case 4:return a.trys.push([4,6,,7]),[4,this.currentCredentials()];case 5:return r=a.sent(),[3,7];case 6:return i=a.sent(),qe.debug("Failed to retrieve credentials while getting current user info",i),[3,7];case 7:return[2,{id:r?r.identityId:void 0,username:s.getUsername(),attributes:n}];case 8:return o=a.sent(),qe.error("currentUserInfo error",o),[2,{}];case 9:return"federated"===e?[2,(s=this.user)||{}]:[2]}}))}))},e.prototype.federatedSignIn=function(e,t,n){return Be(this,void 0,void 0,(function(){var i,o,u,c,h,f,l,d,p,g,m;return je(this,(function(y){switch(y.label){case 0:if(!this._config.identityPoolId&&!this._config.userPoolId)throw new Error("Federation requires either a User Pool or Identity Pool in config");if(void 0===e&&this._config.identityPoolId&&!this._config.userPoolId)throw new Error("Federation with Identity Pools requires tokens passed as arguments");return s(e)||(v=e)&&["customProvider"].find((function(e){return v.hasOwnProperty(e)}))||function(e){return e&&!!["customState"].find((function(t){return e.hasOwnProperty(t)}))}(e)||void 0===e?(i=e||{provider:r.Cognito},h=s(i)?i.provider:i.customProvider,s(i),o=i.customState,this._config.userPoolId&&(u=a(this._config.oauth)?this._config.userPoolWebClientId:this._config.oauth.clientID,c=a(this._config.oauth)?this._config.oauth.redirectSignIn:this._config.oauth.redirectUri,this._oAuthHandler.oauthSignIn(this._config.oauth.responseType,this._config.oauth.domain,c,u,h,o)),[3,4]):[3,1];case 1:h=e;try{(f=JSON.stringify(JSON.parse(this._storage.getItem("aws-amplify-federatedInfo")).user))&&qe.warn("There is already a signed in user: "+f+" in your app.\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tYou should not call Auth.federatedSignIn method again as it may cause unexpected behavior.")}catch(e){}return l=t.token,d=t.identity_id,p=t.expires_at,[4,this.Credentials.set({provider:h,token:l,identity_id:d,user:n,expires_at:p},"federation")];case 2:return g=y.sent(),[4,this.currentAuthenticatedUser()];case 3:return m=y.sent(),He("signIn",m,"A user "+m.username+" has been signed in"),qe.debug("federated sign in credentials",g),[2,g];case 4:return[2]}var v}))}))},e.prototype._handleAuthResponse=function(e){return Be(this,void 0,void 0,(function(){var t,n,r,i,o,s,a,c,h,f,l,d,p,g;return je(this,(function(m){switch(m.label){case 0:if(this.oAuthFlowInProgress)return qe.debug("Skipping URL "+e+" current flow in progress"),[2];m.label=1;case 1:if(m.trys.push([1,,8,9]),this.oAuthFlowInProgress=!0,!this._config.userPoolId)throw new Error("OAuth responses require a User Pool defined in config");if(He("parsingCallbackUrl",{url:e},"The callback url is being parsed"),t=e||(Object(u.browserOrNode)().isBrowser?window.location.href:""),n=!!(Object(me.parse)(t).query||"").split("&").map((function(e){return e.split("=")})).find((function(e){var t=Ve(e,1)[0];return"code"===t||"error"===t})),r=!!(Object(me.parse)(t).hash||"#").substr(1).split("&").map((function(e){return e.split("=")})).find((function(e){var t=Ve(e,1)[0];return"access_token"===t||"error"===t})),!n&&!r)return[3,7];this._storage.setItem("amplify-redirected-from-hosted-ui","true"),m.label=2;case 2:return m.trys.push([2,6,,7]),[4,this._oAuthHandler.handleAuthResponse(t)];case 3:return i=m.sent(),o=i.accessToken,s=i.idToken,a=i.refreshToken,c=i.state,h=new H({IdToken:new j({IdToken:s}),RefreshToken:new V({RefreshToken:a}),AccessToken:new x({AccessToken:o})}),f=void 0,this._config.identityPoolId?[4,this.Credentials.set(h,"session")]:[3,5];case 4:f=m.sent(),qe.debug("AWS credentials",f),m.label=5;case 5:return l=/-/.test(c),(d=this.createCognitoUser(h.getIdToken().decodePayload()["cognito:username"])).setSignInUserSession(h),window&&void 0!==window.history&&window.history.replaceState({},null,this._config.oauth.redirectSignIn),He("signIn",d,"A user "+d.getUsername()+" has been signed in"),He("cognitoHostedUI",d,"A user "+d.getUsername()+" has been signed in via Cognito Hosted UI"),l&&(p=c.split("-").splice(1).join("-"),He("customOAuthState",Object(u.urlSafeDecode)(p),"State for user "+d.getUsername())),[2,f];case 6:return g=m.sent(),qe.debug("Error in cognito hosted auth response",g),window&&void 0!==window.history&&window.history.replaceState({},null,this._config.oauth.redirectSignIn),He("signIn_failure",g,"The OAuth response flow failed"),He("cognitoHostedUI_failure",g,"A failure occurred when returning to the Cognito Hosted UI"),He("customState_failure",g,"A failure occurred when returning state"),[3,7];case 7:return[3,9];case 8:return this.oAuthFlowInProgress=!1,[7];case 9:return[2]}}))}))},e.prototype.essentialCredentials=function(e){return{accessKeyId:e.accessKeyId,sessionToken:e.sessionToken,secretAccessKey:e.secretAccessKey,identityId:e.identityId,authenticated:e.authenticated}},e.prototype.attributesToObject=function(e){var t=this,n={};return e&&e.map((function(e){"email_verified"===e.Name||"phone_number_verified"===e.Name?n[e.Name]=t.isTruthyString(e.Value)||!0===e.Value:n[e.Name]=e.Value})),n},e.prototype.isTruthyString=function(e){return"function"==typeof e.toLowerCase&&"true"===e.toLowerCase()},e.prototype.createCognitoUser=function(e){var t={Username:e,Pool:this.userPool};t.Storage=this._storage;var n=this._config.authenticationFlowType,r=new $(t);return n&&r.setAuthenticationFlowType(n),r},e.prototype._isValidAuthStorage=function(e){return!!e&&"function"==typeof e.getItem&&"function"==typeof e.setItem&&"function"==typeof e.removeItem&&"function"==typeof e.clear},e.prototype.noUserPoolErrorHandler=function(e){return!e||e.userPoolId&&e.identityPoolId?i.NoConfig:i.MissingAuthConfig},e.prototype.rejectAuthError=function(e){return Promise.reject(new ke(e))},e.prototype.rejectNoUserPool=function(){var e=this.noUserPoolErrorHandler(this._config);return Promise.reject(new Me(e))},e.prototype.rememberDevice=function(){return Be(this,void 0,void 0,(function(){var e,t;return je(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.currentUserPoolUser()];case 1:return e=n.sent(),[3,3];case 2:return t=n.sent(),qe.debug("The user is not authenticated by the error",t),[2,Promise.reject("The user is not authenticated")];case 3:return e.getCachedDeviceKeyAndPassword(),[2,new Promise((function(t,n){e.setDeviceStatusRemembered({onSuccess:function(e){t(e)},onFailure:function(e){"InvalidParameterException"===e.code?n(new ke(i.DeviceConfig)):"NetworkError"===e.code?n(new ke(i.NetworkError)):n(e)}})}))]}}))}))},e.prototype.forgetDevice=function(){return Be(this,void 0,void 0,(function(){var e,t;return je(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.currentUserPoolUser()];case 1:return e=n.sent(),[3,3];case 2:return t=n.sent(),qe.debug("The user is not authenticated by the error",t),[2,Promise.reject("The user is not authenticated")];case 3:return e.getCachedDeviceKeyAndPassword(),[2,new Promise((function(t,n){e.forgetDevice({onSuccess:function(e){t(e)},onFailure:function(e){"InvalidParameterException"===e.code?n(new ke(i.DeviceConfig)):"NetworkError"===e.code?n(new ke(i.NetworkError)):n(e)}})}))]}}))}))},e.prototype.fetchDevices=function(){return Be(this,void 0,void 0,(function(){var e,t;return je(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.currentUserPoolUser()];case 1:return e=n.sent(),[3,3];case 2:throw t=n.sent(),qe.debug("The user is not authenticated by the error",t),new Error("The user is not authenticated");case 3:return e.getCachedDeviceKeyAndPassword(),[2,new Promise((function(t,n){var r={onSuccess:function(e){var n=e.Devices.map((function(e){var t=e.DeviceAttributes.find((function(e){return"device_name"===e.Name}))||{};return{id:e.DeviceKey,name:t.Value}}));t(n)},onFailure:function(e){"InvalidParameterException"===e.code?n(new ke(i.DeviceConfig)):"NetworkError"===e.code?n(new ke(i.NetworkError)):n(e)}};e.listDevices(60,null,r)}))]}}))}))},e}())(null);u.Amplify.register(Le);t.default=Le}])}));
43
43
  //# sourceMappingURL=aws-amplify-auth.min.js.map