wjec-one 4.0.4 → 4.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/auth/index.d.ts +2 -1
- package/auth/index.js +1 -1
- package/config/jest.config.js +2 -2
- package/config/utils.js +1 -2
- package/config/webpack.config.js +4 -4
- package/index.js +1 -1
- package/package.json +1 -1
- package/portal/index.d.ts +1 -0
- package/portal/index.js +1 -1
- package/scripts/check-tests.js +1 -2
- package/scripts/test.js +9 -2
- package/umd/auth/index.js +1 -1
- package/umd/index.js +1 -1
- package/umd/portal/index.js +1 -1
package/auth/index.d.ts
CHANGED
|
@@ -145,6 +145,7 @@ declare const useAuthorization: UseAuthorizationHook;
|
|
|
145
145
|
|
|
146
146
|
declare const changePassword: (currentPassword: string, newPassword: string) => Promise<boolean>;
|
|
147
147
|
declare const completePasswordReset: (username: string, code: string, newPassword: string) => Promise<boolean>;
|
|
148
|
+
declare const externalSignIn: (provider: string) => void;
|
|
148
149
|
declare const getAuthorizationToken: () => Promise<string>;
|
|
149
150
|
declare const getUserSession: () => Promise<CognitoUserSession>;
|
|
150
151
|
declare const init: (amplifyConfig: Record<string, any>, oAuthConfig: Record<string, any>, usersEndpoint: string) => Promise<CognitoUserSession>;
|
|
@@ -186,4 +187,4 @@ declare const state: Readonly<{
|
|
|
186
187
|
readonly totpVerified: boolean;
|
|
187
188
|
}>;
|
|
188
189
|
|
|
189
|
-
export { AuthAction, Cache, Challenge, ChallengeType, CognitoUserAttributes, EditableCognitoUserAttributes, EditablePrivateUserAttributes, EmailMfaChallenge, MFAType, NewPasswordChallenge, ReadonlyCognitoUserAttributes, Role, SmsMfaChallenge, Subject, TotpMfaChallenge, UserPreferences, VerifyTelephoneNumberChallenge, VerifyTotpTokenChallenge, changePassword, completePasswordReset, getAuthorizationToken, getUserSession, init, refreshUserSession, requestPasswordReset, setMfaType, setupTotp, signIn, signOut, state, updateUserAttributes, updateUserPreferences, useAuthorization, verifyTelephoneNumber, verifyTotp };
|
|
190
|
+
export { AuthAction, Cache, Challenge, ChallengeType, CognitoUserAttributes, EditableCognitoUserAttributes, EditablePrivateUserAttributes, EmailMfaChallenge, MFAType, NewPasswordChallenge, ReadonlyCognitoUserAttributes, Role, SmsMfaChallenge, Subject, TotpMfaChallenge, UserPreferences, VerifyTelephoneNumberChallenge, VerifyTotpTokenChallenge, changePassword, completePasswordReset, externalSignIn, getAuthorizationToken, getUserSession, init, refreshUserSession, requestPasswordReset, setMfaType, setupTotp, signIn, signOut, state, updateUserAttributes, updateUserPreferences, useAuthorization, verifyTelephoneNumber, verifyTotp };
|
package/auth/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Auth as e,Hub as t,Amplify as r}from"aws-amplify";import{assertNever as n,developerWarning as a,isCallableFunction as o}from"wjec-one/utils";import{useState as i,useRef as u,useEffect as c}from"react";function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function f(e,t,r,n,a,o,i){try{var u=e[o](i),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,a)}function l(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var o=e.apply(t,r);function i(e){f(o,n,a,i,u,"next",e)}function u(e){f(o,n,a,i,u,"throw",e)}i(void 0)}))}}function p(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function h(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){p(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function E(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.includes(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],t.includes(r)||{}.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}function m(){m=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var o=t&&t.prototype instanceof S?t:S,i=Object.create(o.prototype),u=new x(n||[]);return a(i,"_invoke",{value:w(e,r,u)}),i}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var p="suspendedStart",d="suspendedYield",h="executing",E="completed",v={};function S(){}function g(){}function y(){}var T={};s(T,i,(function(){return this}));var _=Object.getPrototypeOf,b=_&&_(_(U([])));b&&b!==r&&n.call(b,i)&&(T=b);var O=y.prototype=S.prototype=Object.create(T);function N(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function R(e,t){function r(a,o,i,u){var c=l(e[a],e,o);if("throw"!==c.type){var s=c.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,i,u)}),(function(e){r("throw",e,i,u)})):t.resolve(f).then((function(e){s.value=e,i(s)}),(function(e){return r("throw",e,i,u)}))}u(c.arg)}var o;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return o=o?o.then(a,a):a()}})}function w(t,r,n){var a=p;return function(o,i){if(a===h)throw Error("Generator is already running");if(a===E){if("throw"===o)throw i;return{value:e,done:!0}}for(n.method=o,n.arg=i;;){var u=n.delegate;if(u){var c=A(u,n);if(c){if(c===v)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===p)throw a=E,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=h;var s=l(t,r,n);if("normal"===s.type){if(a=n.done?E:d,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(a=E,n.method="throw",n.arg=s.arg)}}}function A(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var o=l(a,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,v;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function P(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(P,this),this.reset(!0)}function U(t){if(t||""===t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,o=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return o.next=o}}throw new TypeError(typeof t+" is not iterable")}return g.prototype=y,a(O,"constructor",{value:y,configurable:!0}),a(y,"constructor",{value:g,configurable:!0}),g.displayName=s(y,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===g||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,s(e,c,"GeneratorFunction")),e.prototype=Object.create(O),e},t.awrap=function(e){return{__await:e}},N(R.prototype),s(R.prototype,u,(function(){return this})),t.AsyncIterator=R,t.async=function(e,r,n,a,o){void 0===o&&(o=Promise);var i=new R(f(e,r,n,a),o);return t.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},N(O),s(O,c,"Generator"),s(O,i,(function(){return this})),s(O,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=U,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(I),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return u.type="throw",u.arg=t,r.next=n,a&&(r.method="next",r.arg=e),!!a}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return a("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(c&&s){if(this.prev<i.catchLoc)return a(i.catchLoc,!0);if(this.prev<i.finallyLoc)return a(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return a(i.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return a(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var o=a;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;I(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:U(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}function v(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o,i,u=[],c=!0,s=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=o.call(r)).done)&&(u.push(n.value),u.length!==t);c=!0);}catch(e){s=!0,a=e}finally{try{if(!c&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(s)throw a}}return u}}(e,t)||y(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||y(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e){return g="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},g(e)}function y(e,t){if(e){if("string"==typeof e)return s(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}var T,_,b,O,N;!function(e){e.CHANGE_PASSWORD="changePassword",e.COMPLETE_PASSWORD_RESET="completePasswordReset",e.FORCE_CHANGE_PASSWORD="forceChangePassword",e.GET_AUTHORIZATION_TOKEN="getAuthorizationToken",e.GET_USER_PREFERENCES="getUserPreferences",e.GET_USER_SESSION="getUserSession",e.INIT="init",e.REFRESH_USER_SESSION="refreshUserSession",e.REQUEST_PASSWORD_RESET="requestPasswordReset",e.REQUEST_TOTP_TOKEN="requestSoftwareToken",e.SET_MFA_TYPE="setMfaType",e.SIGN_IN="signIn",e.SIGN_OUT="signOut",e.SUBMIT_MFA_CODE="confirmSignIn",e.UPDATE_USER_ATTRIBUTES="updateUserAttributes",e.UPDATE_USER_PREFERENCES="updateUserPreferences",e.VERIFY_TELEPHONE_NUMBER="verifyTelephoneNumber",e.VERIFY_TOTP_TOKEN="verifySoftwareToken"}(T||(T={})),function(e){e.CUSTOM_CHALLENGE="CUSTOM_CHALLENGE",e.EMAIL_MFA="EMAIL",e.MFA_SETUP="MFA_SETUP",e.NEW_PASSWORD_REQUIRED="NEW_PASSWORD_REQUIRED",e.SMS_MFA="SMS",e.TOTP_MFA="TOTP",e.VERIFY_TELEPHONE_NUMBER="VERIFY_TELEPHONE_NUMBER",e.VERIFY_TOTP_TOKEN="VERIFY_TOTP_TOKEN"}(_||(_={})),function(e){e.EMAIL="EMAIL",e.NONE="NONE",e.SMS="SMS",e.TOTP="TOTP"}(b||(b={})),function(e){e.ADMINISTRATIVE_SUPPORT="administrativeSupport",e.EXAMS_OFFICER="examsOfficer",e.HEAD_OF_DEPARTMENT="headOfDepartment",e.HEAD_OF_YEAR="headOfYear",e.HEAD_TEACHER="headTeacher",e.LOCAL_AUTHORITY_ADVISOR="localAuthorityAdvisor",e.OTHER="other",e.STAKEHOLDER="stakeholder",e.TEACHER="teacher",e.TUTOR="tutor"}(O||(O={})),function(e){e.ENGLISH="english",e.MATHS="maths",e.SCIENCE="science"}(N||(N={}));var R=function(t,r){return function(){var n;if(z("isInitialized")){for(var a=arguments.length,o=new Array(a),i=0;i<a;i++)o[i]=arguments[i];(n=t.call.apply(t,[e].concat(o)))instanceof Promise&&n.catch((function(e){C(r,e)}))}else console.error("WJEC One Authorization: You tried to call ".concat(r,"() before AWS Amplify was initialized. Please provide values for amplifyConfig & oAuthConfig to get set up"));return n}},w=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e.then((function(){return!1!==r.updateStatus&&k(t,"done"),!0})).catch((function(e){return("function"==typeof r.isUnhandledError?r.isUnhandledError(e):e instanceof Error||"string"==typeof e)&&C(t,e),!1}))},A=function(e){return"object"===g(e)&&Object.hasOwn(e,"name")&&"NotAuthorizedException"===e.name},P=function(e){return"object"===g(e)&&Object.hasOwn(e,"name")&&"InvalidPasswordException"===e.name},I=function(e){return"object"===g(e)&&Object.hasOwn(e,"name")&&"CodeMismatchException"===e.name},x=function(e){return Object.entries(e).reduce((function(e,t){var r=v(t,2),a=r[0],o=r[1];return h(h({},e),{},p({},function(e){return"telephoneNumber"===e?"phone_number":n(e)}(a),o))}),{})},U=function(e){return h(h({},e),{},{emailMfaAccepted:e.emailMfaAccepted?new Date(e.emailMfaAccepted):void 0})},k=function(e,t){var r=z("requestStatuses");B({requestStatuses:h(h({},r),{},p({},e,t))})},M=function(e){t.dispatch("custom",{data:{challenge:e},event:"challenge"})},C=function(e,r){t.dispatch("custom",{data:{errorDetails:r,errorType:e},event:"error"})},F=function(e,r){t.dispatch("custom",{data:r,event:e})},L=function(e){F(T.INIT,{session:e})},D=function(){var t=l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,n=r.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(n.payload.sub,"/mfa/secret"),{headers:{Authorization:n.getJwtToken()}}).then((function(e){return e.json()})).then((function(e){return e.secret}));case 6:return a=t.sent,t.abrupt("return",a);case 8:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),j=function(){var t=l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,n=r.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(n.payload.sub,"/preferences"),{headers:{Authorization:n.getJwtToken()}}).then((function(e){return null==e?void 0:e.json()}));case 6:return a=t.sent,t.abrupt("return",a||{});case 8:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),G=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(a.payload.sub,"/mfa"),{body:JSON.stringify({mfaType:r}),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){if(2!==Math.floor(e.status/100))throw new Error("Request failed");return!0}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),V=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(a.payload.sub),{body:JSON.stringify(r),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){if(2!==Math.floor(e.status/100))throw new Error("Request failed");return!0}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),H=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(a.payload.sub,"/preferences"),{body:JSON.stringify(r),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){return e.json()})).then((function(e){return e.success}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),W=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(a.payload.sub,"/mfa/secret"),{body:JSON.stringify({totpCode:r}),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){if(2!==Math.floor(e.status/100))throw new Error("Request failed");return!0}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Y={centrePermissions:{},emailAddress:void 0,emailAddressVerified:!1,familyName:void 0,name:void 0,givenName:void 0,groups:[],id:void 0,isInitialized:!1,isSignedIn:!1,languagePreference:"en-gb",mfaType:void 0,middleName:void 0,preferences:{},provider:void 0,requestStatuses:Object.values(T).reduce((function(e,t){return h(h({},e),{},p({},t,"idle"))}),{}),telephoneNumber:void 0,telephoneNumberVerified:!1,totpVerified:!1,usersEndpoint:void 0},z=function(e){return Y[e]},B=function(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];Object.entries(e).forEach((function(e){var t=v(e,2),r=t[0],n=t[1];Y[r]=n})),r&&t.dispatch("custom",{data:{updatedTimestamp:Date.now()},event:"cacheUpdated"})},K=function(){var e=l(m().mark((function e(t){var r,n,a,o,i,u;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=t.getIdToken().payload,k(T.GET_USER_PREFERENCES,"loading"),e.next=4,j().then((function(e){return k(T.GET_USER_PREFERENCES,"done"),e})).catch((function(e){return C(T.GET_USER_PREFERENCES,e),{}}));case 4:i=e.sent,u=U(i),B({centrePermissions:JSON.parse(o["custom:centre_permissions"]||"{}"),emailAddress:o.email,emailAddressVerified:o.email_verified,familyName:o.family_name||o.familyName,name:o.name,givenName:o.given_name||o.givenName,groups:o["cognito:groups"]||[],id:o.sub,isInitialized:!0,isSignedIn:!0,languagePreference:o["custom:language_preference"],mfaType:o["custom:mfa_type"],middleName:o.middle_name||o.middleName,preferences:u,provider:(null===(r=o.identities)||void 0===r||null===(n=r[0])||void 0===n?void 0:n.providerName)||"Cognito",telephoneNumber:o.phone_number,telephoneNumberVerified:o.phone_number_verified,totpVerified:"true"===(null===(a=o["custom:totp_verified"])||void 0===a?void 0:a.toLowerCase())});case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),J=function(){B({centrePermissions:{},emailAddress:void 0,emailAddressVerified:!1,familyName:void 0,name:void 0,givenName:void 0,groups:[],id:void 0,isSignedIn:!1,languagePreference:void 0,mfaType:void 0,middleName:void 0,preferences:{},provider:void 0,telephoneNumber:void 0,telephoneNumberVerified:!1,totpVerified:!1})},Q=function(t){return function(){var r=l(m().mark((function r(n){var a,o,i;return m().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return k(T.FORCE_CHANGE_PASSWORD,"loading"),r.next=3,e.completeNewPassword(t,n).catch((function(e){A(e)||P(e)||C(T.FORCE_CHANGE_PASSWORD,e),a=!1}));case 3:if(!(o=r.sent)){r.next=12;break}if(!o.challengeName){r.next=10;break}return r.next=8,Z(o.challengeName,o,o.challengeParam);case 8:i=r.sent,M(i);case 10:k(T.FORCE_CHANGE_PASSWORD,"done"),a=!0;case 12:return r.abrupt("return",a);case 13:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},q=function(t){return function(){var r=l(m().mark((function r(n){var a;return m().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return k(T.SUBMIT_MFA_CODE,"loading"),r.next=3,e.sendCustomChallengeAnswer(t,n).then(function(){var e=l(m().mark((function e(r){return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==r||!r.challengeName){e.next=5;break}return e.next=3,Z(r.challengeName,t,r.challengeParam);case 3:a=e.sent,M(a);case 5:k(T.SUBMIT_MFA_CODE,"done");case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){I(e)||C(T.SUBMIT_MFA_CODE,e)}));case 3:return r.abrupt("return",a);case 4:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},Z=function(t,r){var n,a,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=X(t,null==o?void 0:o.selectedMfaType);switch(i){case _.EMAIL_MFA:n={attemptNumber:o.attemptNumber?parseInt(o.attemptNumber):void 0,challengeType:_.EMAIL_MFA,completeChallenge:q(r),emailAddress:o.emailAddress};break;case _.NEW_PASSWORD_REQUIRED:n={challengeType:_.NEW_PASSWORD_REQUIRED,completeChallenge:Q(r)};break;case _.SMS_MFA:n={attemptNumber:o.attemptNumber?parseInt(o.attemptNumber):void 0,challengeType:i,completeChallenge:q(r),telephoneNumber:t===_.CUSTOM_CHALLENGE?o.redactedPhoneNumber:o.CODE_DELIVERY_DESTINATION};break;case _.TOTP_MFA:n={attemptNumber:o.attemptNumber?parseInt(o.attemptNumber):void 0,challengeType:i,completeChallenge:q(r)};break;case _.VERIFY_TELEPHONE_NUMBER:n={challengeType:i,completeChallenge:(a=o.currentMfaType,function(){var t=l(m().mark((function t(r){var n;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.VERIFY_TELEPHONE_NUMBER,"loading"),t.next=3,w(e.verifyCurrentUserAttributeSubmit("phone_number",r),T.VERIFY_TELEPHONE_NUMBER);case 3:if(!(n=t.sent)){t.next=9;break}if(B({telephoneNumberVerified:!0}),z("mfaType")===b.SMS||a!==b.SMS){t.next=9;break}return t.next=9,fe(b.SMS,!0);case 9:return t.abrupt("return",n);case 10:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())};break;case _.VERIFY_TOTP_TOKEN:n={challengeType:i,completeChallenge:function(){var e=l(m().mark((function e(t){var r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ve(t);case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),secretKey:o.secretKey}}return n},X=function(e,t){if(e===_.CUSTOM_CHALLENGE)switch(t){case b.EMAIL:return _.EMAIL_MFA;case b.SMS:return _.SMS_MFA;case b.TOTP:return _.TOTP_MFA}return e},$=["amplifyConfig","oAuthConfig","usersEndpoint"],ee=!1,te=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.amplifyConfig,n=e.oAuthConfig,s=e.usersEndpoint,f=E(e,$),l=v(i(Date.now()),2);l[0];var p=l[1],d=u(!1),m=u(h({},f));c((function(){m.current=h({},f)}),S(Object.values(f)));var g=function(e){if(o(m.current[e])){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),a=1;a<r;a++)n[a-1]=arguments[a];(t=m.current[e]).call.apply(t,[void 0].concat(n))}};return c((function(){if(r||n||s){try{ue(r,n,s),d.current=!0,ee=!0}catch(e){g("onError",T.INIT)}ee&&!d.current&&a("WJEC One useAuthorization: Config should only be provided to the first instance of the useAuthorization hook in your component tree (recommendation is to include this in your entry point component, even if you don't need authorization tools at that point)")}}),[r,n,s]),c((function(){var e=!1,r=t.listen("auth",(function(t){var r=t.payload,n=r.data,a=r.event;if(!e)switch(a){case"completeNewPassword_failure":g("onError",T.FORCE_CHANGE_PASSWORD,n);break;case"forgotPassword":g("onRequestPasswordReset",n.username);break;case"forgotPassword_failure":g("onError",T.REQUEST_PASSWORD_RESET,n);break;case"forgotPasswordSubmit":g("onCompletePasswordReset");break;case"forgotPasswordSubmit_failure":g("onError",T.COMPLETE_PASSWORD_RESET,n);break;case"signIn_failure":g("onError",T.SIGN_IN,n);break;case"signOut":g("onSignOut");break;case"tokenRefresh":o(m.current.onRefreshSession)&&ie().then(m.current.onRefreshSession);break;case"tokenRefresh_failure":g("onError",T.REFRESH_USER_SESSION,n)}})),n=t.listen("custom",(function(t){var r=t.payload,n=r.data,a=r.event;if(!e)switch(a){case"cacheUpdated":p(n.updatedTimestamp);break;case"challenge":g("onChallenge",n.challenge);break;case"error":g("onError",n.errorType,n.errorDetails);break;case"init":g("onInit",n.session);break;case"setMfaType":g("onSetMfaType",n.mfaType);break;case T.SIGN_IN:g("onSignIn",n.session)}}));return function(){e=!0,r(),n()}}),[]),Se},re=["telephoneNumber"],ne=R(function(){var t=l(m().mark((function t(r,n){var a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.CHANGE_PASSWORD,"loading"),t.next=3,e.currentAuthenticatedUser();case 3:return a=t.sent,t.abrupt("return",w(e.changePassword(a,r,n),T.CHANGE_PASSWORD));case 5:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),T.CHANGE_PASSWORD),ae=R((function(t,r,n){return k(T.COMPLETE_PASSWORD_RESET,"loading"),w(e.forgotPasswordSubmit(t,r,n),T.COMPLETE_PASSWORD_RESET,{isUnhandledError:function(e){return!I(e)}})}),T.COMPLETE_PASSWORD_RESET),oe=R(l(m().mark((function e(){var t,r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ie();case 2:return t=e.sent,r=t.getIdToken().getJwtToken(),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e)}))),T.GET_AUTHORIZATION_TOKEN),ie=R(l(m().mark((function t(){var r;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,t.abrupt("return",r);case 4:case"end":return t.stop()}}),t)}))),T.GET_USER_SESSION),ue=function(){var n=l(m().mark((function n(o,i,u){var c;return m().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!z("isInitialized")){n.next=4;break}a("WJEC One Authorization: Config cannot be changed after initialization - the config that was originally provided will continue to be used"),n.next=23;break;case 4:if(o&&i&&u){n.next=8;break}throw new Error("WJEC One Authorization: Both amplifyConfig and oAuthConfig objects must be provided, in addition to the endpoint URL for the users service");case 8:return n.prev=8,r.configure(o),e.configure({oauth:i}),B({usersEndpoint:u},!1),t.listen("auth",function(){var e=l(m().mark((function e(t){var r,n,a;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=t.payload,n=r.data,a=r.event,e.t0=a,e.next="completeNewPassword_failure"===e.t0?4:"forgotPassword_failure"===e.t0?6:"forgotPasswordSubmit_failure"===e.t0?8:"signIn"===e.t0?10:"signIn_failure"===e.t0?14:"signOut"===e.t0?16:"signOut_failure"===e.t0?18:"tokenRefresh_failure"===e.t0?20:22;break;case 4:return k(T.FORCE_CHANGE_PASSWORD,"failed"),e.abrupt("break",22);case 6:return k(T.REQUEST_PASSWORD_RESET,"failed"),e.abrupt("break",22);case 8:return k(T.COMPLETE_PASSWORD_RESET,"failed"),e.abrupt("break",22);case 10:return e.next=12,K(n.signInUserSession);case 12:return F(T.SIGN_IN,{session:n.signInUserSession}),e.abrupt("break",22);case 14:return k(T.SIGN_IN,"failed"),e.abrupt("break",22);case 16:return J(),e.abrupt("break",22);case 18:return k(T.SIGN_OUT,"failed"),e.abrupt("break",22);case 20:return k(T.REFRESH_USER_SESSION,"failed"),e.abrupt("break",22);case 22:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),t.listen("custom",(function(e){var t=e.payload,r=t.data;if("error"===t.event){var n=r.errorType;"loading"===z("requestStatuses")[n]&&k(n,"failed")}})),n.next=15,e.currentAuthenticatedUser({bypassCache:!0}).then(function(){var e=l(m().mark((function e(t){var r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.getSignInUserSession(),e.next=3,K(r);case 3:return e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(){}));case 15:(c=n.sent)||B({isInitialized:!0}),L(c),n.next=23;break;case 20:n.prev=20,n.t0=n.catch(8),C(T.INIT,n.t0);case 23:return n.abrupt("return",c);case 24:case"end":return n.stop()}}),n,null,[[8,20]])})));return function(e,t,r){return n.apply(this,arguments)}}(),ce=R(l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,t.next=5,e.currentAuthenticatedUser();case 5:return n=t.sent,t.next=8,new Promise((function(e,t){try{n.refreshSession(r.getRefreshToken(),(function(t,r){if(t)throw t;e(r)}))}catch(e){C(T.REFRESH_USER_SESSION,e),t(e)}}));case 8:return a=t.sent,t.abrupt("return",a);case 10:case"end":return t.stop()}}),t)}))),T.REFRESH_USER_SESSION),se=R((function(t){return k(T.REQUEST_PASSWORD_RESET,"loading"),w(e.forgotPassword(t),T.REQUEST_PASSWORD_RESET)}),T.REQUEST_PASSWORD_RESET),fe=R(function(){var e=l(m().mark((function e(t){var r,n,a=arguments;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=a.length>1&&void 0!==a[1]&&a[1],k(T.SET_MFA_TYPE,"loading"),e.next=4,G(t).catch((function(e){return C(T.SET_MFA_TYPE,e),!1}));case 4:return(n=e.sent)&&(B({mfaType:t},r),F(T.SET_MFA_TYPE,{mfaType:t}),k(T.SET_MFA_TYPE,"done"),t!==b.EMAIL&&Ee({emailMfaAccepted:void 0})),e.abrupt("return",n);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),T.SET_MFA_TYPE),le=R(l(m().mark((function t(){var r,n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.REQUEST_TOTP_TOKEN,"loading"),n=z("mfaType"),t.next=4,e.currentAuthenticatedUser();case 4:if(a=t.sent,n!==b.TOTP){t.next=8;break}return t.next=8,fe(b.EMAIL);case 8:return t.next=10,D().catch((function(e){C(T.REQUEST_TOTP_TOKEN,e)}));case 10:if(!(o=t.sent)){t.next=18;break}return t.next=14,Z(_.VERIFY_TOTP_TOKEN,a,{secretKey:o});case 14:r=t.sent,M(r),B({totpVerified:!1},!1),k(T.REQUEST_TOTP_TOKEN,"done");case 18:return t.abrupt("return",{challenge:r,secretKey:o});case 19:case"end":return t.stop()}}),t)}))),T.REQUEST_TOTP_TOKEN),pe=R(function(){var t=l(m().mark((function t(r,n){var a,o,i;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.SIGN_IN,"loading"),t.next=3,e.signIn(r,n).catch((function(e){A(e)||C(T.SIGN_IN,e)}));case 3:if(!(o=t.sent)){t.next=16;break}if(!o.challengeName){t.next=15;break}if((null===(i=o.challengeParam)||void 0===i?void 0:i.selectedMfaType)!==b.NONE){t.next=11;break}return t.next=9,e.sendCustomChallengeAnswer(o,"N/A").catch((function(e){C(T.SIGN_IN,e)}));case 9:t.next=15;break;case 11:return t.next=13,Z(o.challengeName,o,o.challengeParam);case 13:a=t.sent,M(a);case 15:k(T.SIGN_IN,"done");case 16:return t.abrupt("return",{challenge:a,user:o});case 17:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),T.SIGN_IN),de=R((function(){return k(T.SIGN_OUT,"loading"),w(e.signOut(),T.SIGN_OUT)}),T.SIGN_OUT),he=R(function(){var t=l(m().mark((function t(r){var n,a,o,i,u,c,s;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.telephoneNumber,a=E(r,re),o=!0,k(T.UPDATE_USER_ATTRIBUTES,"loading"),!Object.hasOwn(r,"telephoneNumber")){t.next=13;break}return i=z("telephoneNumber"),u=z("telephoneNumberVerified"),t.next=8,e.currentAuthenticatedUser();case 8:return c=t.sent,t.next=11,w(e.updateUserAttributes(c,x({telephoneNumber:n})),T.UPDATE_USER_ATTRIBUTES,{updateStatus:!1});case 11:(o=t.sent)&&B({telephoneNumber:n,telephoneNumberVerified:n===i&&u},!1);case 13:return t.next=15,V(a);case 15:return(s=t.sent)&&B(a,!1),k(T.UPDATE_USER_ATTRIBUTES,o&&s?"done":"failed"),t.abrupt("return",o&&s);case 19:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),T.UPDATE_USER_ATTRIBUTES),Ee=R(function(){var e=l(m().mark((function e(t){var r,n;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return k(T.UPDATE_USER_PREFERENCES,"loading"),r=h(h({},z("preferences")),t),e.next=4,H(r).catch((function(e){return C(T.UPDATE_USER_PREFERENCES,e),!1}));case 4:return(n=e.sent)&&(B({preferences:r},!1),k(T.UPDATE_USER_PREFERENCES,"done")),e.abrupt("return",n);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),T.UPDATE_USER_PREFERENCES),me=R(l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.VERIFY_TELEPHONE_NUMBER,"loading"),t.next=3,e.currentAuthenticatedUser();case 3:return n=t.sent,a=z("mfaType"),t.next=7,w(e.verifyCurrentUserAttribute("phone_number"),T.VERIFY_TELEPHONE_NUMBER);case 7:if(!t.sent){t.next=17;break}return t.next=11,Z(_.VERIFY_TELEPHONE_NUMBER,n,{currentMfaType:a});case 11:if(r=t.sent,a!==b.SMS){t.next=15;break}return t.next=15,fe(b.EMAIL,!0);case 15:M(r),k(T.VERIFY_TELEPHONE_NUMBER,"done");case 17:return t.abrupt("return",r);case 18:case"end":return t.stop()}}),t)}))),T.VERIFY_TELEPHONE_NUMBER),ve=R(function(){var e=l(m().mark((function e(t){var r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return k(T.VERIFY_TOTP_TOKEN,"loading"),e.next=3,W(t).catch((function(e){return C(T.VERIFY_TOTP_TOKEN,e),!1}));case 3:return(r=e.sent)&&(B({totpVerified:!0},!1),k(T.VERIFY_TOTP_TOKEN,"done")),e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),T.VERIFY_TOTP_TOKEN),Se=Object.freeze({get centrePermissions(){return z("centrePermissions")},get emailAddress(){return z("emailAddress")},get emailAddressVerified(){return z("emailAddressVerified")},get familyName(){return z("familyName")},get name(){return z("name")},get givenName(){return z("givenName")},get groups(){return z("groups")},get id(){return z("id")},get isInitialized(){return z("isInitialized")},get isSignedIn(){return z("isSignedIn")},get languagePreference(){return z("languagePreference")},get mfaType(){return z("mfaType")},get middleName(){return z("middleName")},get preferences(){return z("preferences")},get provider(){return z("provider")},get requestStatuses(){return z("requestStatuses")},get telephoneNumber(){return z("telephoneNumber")},get telephoneNumberVerified(){return z("telephoneNumberVerified")},get totpVerified(){return z("totpVerified")}});export{T as AuthAction,_ as ChallengeType,b as MFAType,O as Role,N as Subject,ne as changePassword,ae as completePasswordReset,oe as getAuthorizationToken,ie as getUserSession,ue as init,ce as refreshUserSession,se as requestPasswordReset,fe as setMfaType,le as setupTotp,pe as signIn,de as signOut,Se as state,he as updateUserAttributes,Ee as updateUserPreferences,te as useAuthorization,me as verifyTelephoneNumber,ve as verifyTotp};
|
|
1
|
+
import{Auth as e,Hub as t,Amplify as r}from"aws-amplify";import{assertNever as n,developerWarning as a,isCallableFunction as o}from"wjec-one/utils";import{useState as i,useRef as u,useEffect as c}from"react";function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function f(e,t,r,n,a,o,i){try{var u=e[o](i),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,a)}function l(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var o=e.apply(t,r);function i(e){f(o,n,a,i,u,"next",e)}function u(e){f(o,n,a,i,u,"throw",e)}i(void 0)}))}}function p(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function h(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){p(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function E(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.includes(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],t.includes(r)||{}.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}function m(){m=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var o=t&&t.prototype instanceof S?t:S,i=Object.create(o.prototype),u=new x(n||[]);return a(i,"_invoke",{value:w(e,r,u)}),i}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var p="suspendedStart",d="suspendedYield",h="executing",E="completed",v={};function S(){}function g(){}function y(){}var T={};s(T,i,(function(){return this}));var _=Object.getPrototypeOf,b=_&&_(_(U([])));b&&b!==r&&n.call(b,i)&&(T=b);var O=y.prototype=S.prototype=Object.create(T);function N(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function R(e,t){function r(a,o,i,u){var c=l(e[a],e,o);if("throw"!==c.type){var s=c.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,i,u)}),(function(e){r("throw",e,i,u)})):t.resolve(f).then((function(e){s.value=e,i(s)}),(function(e){return r("throw",e,i,u)}))}u(c.arg)}var o;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return o=o?o.then(a,a):a()}})}function w(t,r,n){var a=p;return function(o,i){if(a===h)throw Error("Generator is already running");if(a===E){if("throw"===o)throw i;return{value:e,done:!0}}for(n.method=o,n.arg=i;;){var u=n.delegate;if(u){var c=A(u,n);if(c){if(c===v)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===p)throw a=E,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=h;var s=l(t,r,n);if("normal"===s.type){if(a=n.done?E:d,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(a=E,n.method="throw",n.arg=s.arg)}}}function A(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var o=l(a,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,v;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function P(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(P,this),this.reset(!0)}function U(t){if(t||""===t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,o=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return o.next=o}}throw new TypeError(typeof t+" is not iterable")}return g.prototype=y,a(O,"constructor",{value:y,configurable:!0}),a(y,"constructor",{value:g,configurable:!0}),g.displayName=s(y,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===g||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,s(e,c,"GeneratorFunction")),e.prototype=Object.create(O),e},t.awrap=function(e){return{__await:e}},N(R.prototype),s(R.prototype,u,(function(){return this})),t.AsyncIterator=R,t.async=function(e,r,n,a,o){void 0===o&&(o=Promise);var i=new R(f(e,r,n,a),o);return t.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},N(O),s(O,c,"Generator"),s(O,i,(function(){return this})),s(O,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=U,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(I),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return u.type="throw",u.arg=t,r.next=n,a&&(r.method="next",r.arg=e),!!a}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return a("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(c&&s){if(this.prev<i.catchLoc)return a(i.catchLoc,!0);if(this.prev<i.finallyLoc)return a(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return a(i.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return a(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var o=a;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;I(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:U(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}function v(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o,i,u=[],c=!0,s=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=o.call(r)).done)&&(u.push(n.value),u.length!==t);c=!0);}catch(e){s=!0,a=e}finally{try{if(!c&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(s)throw a}}return u}}(e,t)||y(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||y(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e){return g="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},g(e)}function y(e,t){if(e){if("string"==typeof e)return s(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}var T,_,b,O,N;!function(e){e.CHANGE_PASSWORD="changePassword",e.COMPLETE_PASSWORD_RESET="completePasswordReset",e.FORCE_CHANGE_PASSWORD="forceChangePassword",e.GET_AUTHORIZATION_TOKEN="getAuthorizationToken",e.GET_USER_PREFERENCES="getUserPreferences",e.GET_USER_SESSION="getUserSession",e.INIT="init",e.REFRESH_USER_SESSION="refreshUserSession",e.REQUEST_PASSWORD_RESET="requestPasswordReset",e.REQUEST_TOTP_TOKEN="requestSoftwareToken",e.SET_MFA_TYPE="setMfaType",e.SIGN_IN="signIn",e.SIGN_OUT="signOut",e.SUBMIT_MFA_CODE="confirmSignIn",e.UPDATE_USER_ATTRIBUTES="updateUserAttributes",e.UPDATE_USER_PREFERENCES="updateUserPreferences",e.VERIFY_TELEPHONE_NUMBER="verifyTelephoneNumber",e.VERIFY_TOTP_TOKEN="verifySoftwareToken"}(T||(T={})),function(e){e.CUSTOM_CHALLENGE="CUSTOM_CHALLENGE",e.EMAIL_MFA="EMAIL",e.MFA_SETUP="MFA_SETUP",e.NEW_PASSWORD_REQUIRED="NEW_PASSWORD_REQUIRED",e.SMS_MFA="SMS",e.TOTP_MFA="TOTP",e.VERIFY_TELEPHONE_NUMBER="VERIFY_TELEPHONE_NUMBER",e.VERIFY_TOTP_TOKEN="VERIFY_TOTP_TOKEN"}(_||(_={})),function(e){e.EMAIL="EMAIL",e.NONE="NONE",e.SMS="SMS",e.TOTP="TOTP"}(b||(b={})),function(e){e.ADMINISTRATIVE_SUPPORT="administrativeSupport",e.EXAMS_OFFICER="examsOfficer",e.HEAD_OF_DEPARTMENT="headOfDepartment",e.HEAD_OF_YEAR="headOfYear",e.HEAD_TEACHER="headTeacher",e.LOCAL_AUTHORITY_ADVISOR="localAuthorityAdvisor",e.OTHER="other",e.STAKEHOLDER="stakeholder",e.TEACHER="teacher",e.TUTOR="tutor"}(O||(O={})),function(e){e.ENGLISH="english",e.MATHS="maths",e.SCIENCE="science"}(N||(N={}));var R=function(t,r){return function(){var n;if(z("isInitialized")){for(var a=arguments.length,o=new Array(a),i=0;i<a;i++)o[i]=arguments[i];(n=t.call.apply(t,[e].concat(o)))instanceof Promise&&n.catch((function(e){C(r,e)}))}else console.error("WJEC One Authorization: You tried to call ".concat(r,"() before AWS Amplify was initialized. Please provide values for amplifyConfig & oAuthConfig to get set up"));return n}},w=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e.then((function(){return!1!==r.updateStatus&&k(t,"done"),!0})).catch((function(e){return("function"==typeof r.isUnhandledError?r.isUnhandledError(e):e instanceof Error||"string"==typeof e)&&C(t,e),!1}))},A=function(e){return"object"===g(e)&&Object.hasOwn(e,"name")&&"NotAuthorizedException"===e.name},P=function(e){return"object"===g(e)&&Object.hasOwn(e,"name")&&"InvalidPasswordException"===e.name},I=function(e){return"object"===g(e)&&Object.hasOwn(e,"name")&&"CodeMismatchException"===e.name},x=function(e){return Object.entries(e).reduce((function(e,t){var r=v(t,2),a=r[0],o=r[1];return h(h({},e),{},p({},function(e){return"telephoneNumber"===e?"phone_number":n(e)}(a),o))}),{})},U=function(e){return h(h({},e),{},{emailMfaAccepted:e.emailMfaAccepted?new Date(e.emailMfaAccepted):void 0})},k=function(e,t){var r=z("requestStatuses");B({requestStatuses:h(h({},r),{},p({},e,t))})},M=function(e){t.dispatch("custom",{data:{challenge:e},event:"challenge"})},C=function(e,r){t.dispatch("custom",{data:{errorDetails:r,errorType:e},event:"error"})},F=function(e,r){t.dispatch("custom",{data:r,event:e})},L=function(e){F(T.INIT,{session:e})},D=function(){var t=l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,n=r.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(n.payload.sub,"/mfa/secret"),{headers:{Authorization:n.getJwtToken()}}).then((function(e){return e.json()})).then((function(e){return e.secret}));case 6:return a=t.sent,t.abrupt("return",a);case 8:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),j=function(){var t=l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,n=r.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(n.payload.sub,"/preferences"),{headers:{Authorization:n.getJwtToken()}}).then((function(e){return null==e?void 0:e.json()}));case 6:return a=t.sent,t.abrupt("return",a||{});case 8:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),G=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(a.payload.sub,"/mfa"),{body:JSON.stringify({mfaType:r}),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){if(2!==Math.floor(e.status/100))throw new Error("Request failed");return!0}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),V=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(a.payload.sub),{body:JSON.stringify(r),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){if(2!==Math.floor(e.status/100))throw new Error("Request failed");return!0}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),H=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(a.payload.sub,"/preferences"),{body:JSON.stringify(r),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){return e.json()})).then((function(e){return e.success}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),W=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(z("usersEndpoint")).concat(a.payload.sub,"/mfa/secret"),{body:JSON.stringify({totpCode:r}),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){if(2!==Math.floor(e.status/100))throw new Error("Request failed");return!0}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Y={centrePermissions:{},emailAddress:void 0,emailAddressVerified:!1,familyName:void 0,name:void 0,givenName:void 0,groups:[],id:void 0,isInitialized:!1,isSignedIn:!1,languagePreference:"en-gb",mfaType:void 0,middleName:void 0,preferences:{},provider:void 0,requestStatuses:Object.values(T).reduce((function(e,t){return h(h({},e),{},p({},t,"idle"))}),{}),telephoneNumber:void 0,telephoneNumberVerified:!1,totpVerified:!1,usersEndpoint:void 0},z=function(e){return Y[e]},B=function(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];Object.entries(e).forEach((function(e){var t=v(e,2),r=t[0],n=t[1];Y[r]=n})),r&&t.dispatch("custom",{data:{updatedTimestamp:Date.now()},event:"cacheUpdated"})},K=function(){var e=l(m().mark((function e(t){var r,n,a,o,i,u;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=t.getIdToken().payload,k(T.GET_USER_PREFERENCES,"loading"),e.next=4,j().then((function(e){return k(T.GET_USER_PREFERENCES,"done"),e})).catch((function(e){return C(T.GET_USER_PREFERENCES,e),{}}));case 4:i=e.sent,u=U(i),B({centrePermissions:JSON.parse(o["custom:centre_permissions"]||"{}"),emailAddress:o.email,emailAddressVerified:o.email_verified,familyName:o.family_name||o.familyName,name:o.name,givenName:o.given_name||o.givenName,groups:o["cognito:groups"]||[],id:o.sub,isInitialized:!0,isSignedIn:!0,languagePreference:o["custom:language_preference"],mfaType:o["custom:mfa_type"],middleName:o.middle_name||o.middleName,preferences:u,provider:(null===(r=o.identities)||void 0===r||null===(n=r[0])||void 0===n?void 0:n.providerName)||"Cognito",telephoneNumber:o.phone_number,telephoneNumberVerified:o.phone_number_verified,totpVerified:"true"===(null===(a=o["custom:totp_verified"])||void 0===a?void 0:a.toLowerCase())});case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),J=function(){B({centrePermissions:{},emailAddress:void 0,emailAddressVerified:!1,familyName:void 0,name:void 0,givenName:void 0,groups:[],id:void 0,isSignedIn:!1,languagePreference:void 0,mfaType:void 0,middleName:void 0,preferences:{},provider:void 0,telephoneNumber:void 0,telephoneNumberVerified:!1,totpVerified:!1})},Q=function(t){return function(){var r=l(m().mark((function r(n){var a,o,i;return m().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return k(T.FORCE_CHANGE_PASSWORD,"loading"),r.next=3,e.completeNewPassword(t,n).catch((function(e){A(e)||P(e)||C(T.FORCE_CHANGE_PASSWORD,e),a=!1}));case 3:if(!(o=r.sent)){r.next=12;break}if(!o.challengeName){r.next=10;break}return r.next=8,Z(o.challengeName,o,o.challengeParam);case 8:i=r.sent,M(i);case 10:k(T.FORCE_CHANGE_PASSWORD,"done"),a=!0;case 12:return r.abrupt("return",a);case 13:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},q=function(t){return function(){var r=l(m().mark((function r(n){var a;return m().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return k(T.SUBMIT_MFA_CODE,"loading"),r.next=3,e.sendCustomChallengeAnswer(t,n).then(function(){var e=l(m().mark((function e(r){return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==r||!r.challengeName){e.next=5;break}return e.next=3,Z(r.challengeName,t,r.challengeParam);case 3:a=e.sent,M(a);case 5:k(T.SUBMIT_MFA_CODE,"done");case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){I(e)||C(T.SUBMIT_MFA_CODE,e)}));case 3:return r.abrupt("return",a);case 4:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},Z=function(t,r){var n,a,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=X(t,null==o?void 0:o.selectedMfaType);switch(i){case _.EMAIL_MFA:n={attemptNumber:o.attemptNumber?parseInt(o.attemptNumber):void 0,challengeType:_.EMAIL_MFA,completeChallenge:q(r),emailAddress:o.emailAddress};break;case _.NEW_PASSWORD_REQUIRED:n={challengeType:_.NEW_PASSWORD_REQUIRED,completeChallenge:Q(r)};break;case _.SMS_MFA:n={attemptNumber:o.attemptNumber?parseInt(o.attemptNumber):void 0,challengeType:i,completeChallenge:q(r),telephoneNumber:t===_.CUSTOM_CHALLENGE?o.redactedPhoneNumber:o.CODE_DELIVERY_DESTINATION};break;case _.TOTP_MFA:n={attemptNumber:o.attemptNumber?parseInt(o.attemptNumber):void 0,challengeType:i,completeChallenge:q(r)};break;case _.VERIFY_TELEPHONE_NUMBER:n={challengeType:i,completeChallenge:(a=o.currentMfaType,function(){var t=l(m().mark((function t(r){var n;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.VERIFY_TELEPHONE_NUMBER,"loading"),t.next=3,w(e.verifyCurrentUserAttributeSubmit("phone_number",r),T.VERIFY_TELEPHONE_NUMBER);case 3:if(!(n=t.sent)){t.next=9;break}if(B({telephoneNumberVerified:!0}),z("mfaType")===b.SMS||a!==b.SMS){t.next=9;break}return t.next=9,le(b.SMS,!0);case 9:return t.abrupt("return",n);case 10:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())};break;case _.VERIFY_TOTP_TOKEN:n={challengeType:i,completeChallenge:function(){var e=l(m().mark((function e(t){var r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Se(t);case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),secretKey:o.secretKey}}return n},X=function(e,t){if(e===_.CUSTOM_CHALLENGE)switch(t){case b.EMAIL:return _.EMAIL_MFA;case b.SMS:return _.SMS_MFA;case b.TOTP:return _.TOTP_MFA}return e},$=["amplifyConfig","oAuthConfig","usersEndpoint"],ee=!1,te=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.amplifyConfig,n=e.oAuthConfig,s=e.usersEndpoint,f=E(e,$),l=v(i(Date.now()),2);l[0];var p=l[1],d=u(!1),m=u(h({},f));c((function(){m.current=h({},f)}),S(Object.values(f)));var g=function(e){if(o(m.current[e])){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),a=1;a<r;a++)n[a-1]=arguments[a];(t=m.current[e]).call.apply(t,[void 0].concat(n))}};return c((function(){if(r||n||s){try{ce(r,n,s),d.current=!0,ee=!0}catch(e){g("onError",T.INIT)}ee&&!d.current&&a("WJEC One useAuthorization: Config should only be provided to the first instance of the useAuthorization hook in your component tree (recommendation is to include this in your entry point component, even if you don't need authorization tools at that point)")}}),[r,n,s]),c((function(){var e=!1,r=t.listen("auth",(function(t){var r=t.payload,n=r.data,a=r.event;if(!e)switch(a){case"completeNewPassword_failure":g("onError",T.FORCE_CHANGE_PASSWORD,n);break;case"forgotPassword":g("onRequestPasswordReset",n.username);break;case"forgotPassword_failure":g("onError",T.REQUEST_PASSWORD_RESET,n);break;case"forgotPasswordSubmit":g("onCompletePasswordReset");break;case"forgotPasswordSubmit_failure":g("onError",T.COMPLETE_PASSWORD_RESET,n);break;case"signIn_failure":g("onError",T.SIGN_IN,n);break;case"signOut":g("onSignOut");break;case"tokenRefresh":o(m.current.onRefreshSession)&&ue().then(m.current.onRefreshSession);break;case"tokenRefresh_failure":g("onError",T.REFRESH_USER_SESSION,n)}})),n=t.listen("custom",(function(t){var r=t.payload,n=r.data,a=r.event;if(!e)switch(a){case"cacheUpdated":p(n.updatedTimestamp);break;case"challenge":g("onChallenge",n.challenge);break;case"error":g("onError",n.errorType,n.errorDetails);break;case"init":g("onInit",n.session);break;case"setMfaType":g("onSetMfaType",n.mfaType);break;case T.SIGN_IN:g("onSignIn",n.session)}}));return function(){e=!0,r(),n()}}),[]),ge},re=["telephoneNumber"],ne=R(function(){var t=l(m().mark((function t(r,n){var a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.CHANGE_PASSWORD,"loading"),t.next=3,e.currentAuthenticatedUser();case 3:return a=t.sent,t.abrupt("return",w(e.changePassword(a,r,n),T.CHANGE_PASSWORD));case 5:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),T.CHANGE_PASSWORD),ae=R((function(t,r,n){return k(T.COMPLETE_PASSWORD_RESET,"loading"),w(e.forgotPasswordSubmit(t,r,n),T.COMPLETE_PASSWORD_RESET,{isUnhandledError:function(e){return!I(e)}})}),T.COMPLETE_PASSWORD_RESET),oe=R((function(t){e.federatedSignIn({customProvider:t})}),T.SIGN_IN),ie=R(l(m().mark((function e(){var t,r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ue();case 2:return t=e.sent,r=t.getIdToken().getJwtToken(),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e)}))),T.GET_AUTHORIZATION_TOKEN),ue=R(l(m().mark((function t(){var r;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,t.abrupt("return",r);case 4:case"end":return t.stop()}}),t)}))),T.GET_USER_SESSION),ce=function(){var n=l(m().mark((function n(o,i,u){var c;return m().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!z("isInitialized")){n.next=4;break}a("WJEC One Authorization: Config cannot be changed after initialization - the config that was originally provided will continue to be used"),n.next=23;break;case 4:if(o&&i&&u){n.next=8;break}throw new Error("WJEC One Authorization: Both amplifyConfig and oAuthConfig objects must be provided, in addition to the endpoint URL for the users service");case 8:return n.prev=8,r.configure(o),e.configure({oauth:i}),B({usersEndpoint:u},!1),t.listen("auth",function(){var e=l(m().mark((function e(t){var r,n,a;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=t.payload,n=r.data,a=r.event,e.t0=a,e.next="completeNewPassword_failure"===e.t0?4:"forgotPassword_failure"===e.t0?6:"forgotPasswordSubmit_failure"===e.t0?8:"signIn"===e.t0?10:"signIn_failure"===e.t0?14:"signOut"===e.t0?16:"signOut_failure"===e.t0?18:"tokenRefresh_failure"===e.t0?20:22;break;case 4:return k(T.FORCE_CHANGE_PASSWORD,"failed"),e.abrupt("break",22);case 6:return k(T.REQUEST_PASSWORD_RESET,"failed"),e.abrupt("break",22);case 8:return k(T.COMPLETE_PASSWORD_RESET,"failed"),e.abrupt("break",22);case 10:return e.next=12,K(n.signInUserSession);case 12:return F(T.SIGN_IN,{session:n.signInUserSession}),e.abrupt("break",22);case 14:return k(T.SIGN_IN,"failed"),e.abrupt("break",22);case 16:return J(),e.abrupt("break",22);case 18:return k(T.SIGN_OUT,"failed"),e.abrupt("break",22);case 20:return k(T.REFRESH_USER_SESSION,"failed"),e.abrupt("break",22);case 22:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),t.listen("custom",(function(e){var t=e.payload,r=t.data;if("error"===t.event){var n=r.errorType;"loading"===z("requestStatuses")[n]&&k(n,"failed")}})),n.next=15,e.currentAuthenticatedUser({bypassCache:!0}).then(function(){var e=l(m().mark((function e(t){var r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.getSignInUserSession(),e.next=3,K(r);case 3:return e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(){}));case 15:(c=n.sent)||B({isInitialized:!0}),L(c),n.next=23;break;case 20:n.prev=20,n.t0=n.catch(8),C(T.INIT,n.t0);case 23:return n.abrupt("return",c);case 24:case"end":return n.stop()}}),n,null,[[8,20]])})));return function(e,t,r){return n.apply(this,arguments)}}(),se=R(l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,t.next=5,e.currentAuthenticatedUser();case 5:return n=t.sent,t.next=8,new Promise((function(e,t){try{n.refreshSession(r.getRefreshToken(),(function(t,r){if(t)throw t;e(r)}))}catch(e){C(T.REFRESH_USER_SESSION,e),t(e)}}));case 8:return a=t.sent,t.abrupt("return",a);case 10:case"end":return t.stop()}}),t)}))),T.REFRESH_USER_SESSION),fe=R((function(t){return k(T.REQUEST_PASSWORD_RESET,"loading"),w(e.forgotPassword(t),T.REQUEST_PASSWORD_RESET)}),T.REQUEST_PASSWORD_RESET),le=R(function(){var e=l(m().mark((function e(t){var r,n,a=arguments;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=a.length>1&&void 0!==a[1]&&a[1],k(T.SET_MFA_TYPE,"loading"),e.next=4,G(t).catch((function(e){return C(T.SET_MFA_TYPE,e),!1}));case 4:return(n=e.sent)&&(B({mfaType:t},r),F(T.SET_MFA_TYPE,{mfaType:t}),k(T.SET_MFA_TYPE,"done"),t!==b.EMAIL&&me({emailMfaAccepted:void 0})),e.abrupt("return",n);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),T.SET_MFA_TYPE),pe=R(l(m().mark((function t(){var r,n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.REQUEST_TOTP_TOKEN,"loading"),n=z("mfaType"),t.next=4,e.currentAuthenticatedUser();case 4:if(a=t.sent,n!==b.TOTP){t.next=8;break}return t.next=8,le(b.EMAIL);case 8:return t.next=10,D().catch((function(e){C(T.REQUEST_TOTP_TOKEN,e)}));case 10:if(!(o=t.sent)){t.next=18;break}return t.next=14,Z(_.VERIFY_TOTP_TOKEN,a,{secretKey:o});case 14:r=t.sent,M(r),B({totpVerified:!1},!1),k(T.REQUEST_TOTP_TOKEN,"done");case 18:return t.abrupt("return",{challenge:r,secretKey:o});case 19:case"end":return t.stop()}}),t)}))),T.REQUEST_TOTP_TOKEN),de=R(function(){var t=l(m().mark((function t(r,n){var a,o,i;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.SIGN_IN,"loading"),t.next=3,e.signIn(r,n).catch((function(e){A(e)||C(T.SIGN_IN,e)}));case 3:if(!(o=t.sent)){t.next=16;break}if(!o.challengeName){t.next=15;break}if((null===(i=o.challengeParam)||void 0===i?void 0:i.selectedMfaType)!==b.NONE){t.next=11;break}return t.next=9,e.sendCustomChallengeAnswer(o,"N/A").catch((function(e){C(T.SIGN_IN,e)}));case 9:t.next=15;break;case 11:return t.next=13,Z(o.challengeName,o,o.challengeParam);case 13:a=t.sent,M(a);case 15:k(T.SIGN_IN,"done");case 16:return t.abrupt("return",{challenge:a,user:o});case 17:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),T.SIGN_IN),he=R((function(){return k(T.SIGN_OUT,"loading"),w(e.signOut(),T.SIGN_OUT)}),T.SIGN_OUT),Ee=R(function(){var t=l(m().mark((function t(r){var n,a,o,i,u,c,s;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.telephoneNumber,a=E(r,re),o=!0,k(T.UPDATE_USER_ATTRIBUTES,"loading"),!Object.hasOwn(r,"telephoneNumber")){t.next=13;break}return i=z("telephoneNumber"),u=z("telephoneNumberVerified"),t.next=8,e.currentAuthenticatedUser();case 8:return c=t.sent,t.next=11,w(e.updateUserAttributes(c,x({telephoneNumber:n})),T.UPDATE_USER_ATTRIBUTES,{updateStatus:!1});case 11:(o=t.sent)&&B({telephoneNumber:n,telephoneNumberVerified:n===i&&u},!1);case 13:return t.next=15,V(a);case 15:return(s=t.sent)&&B(a,!1),k(T.UPDATE_USER_ATTRIBUTES,o&&s?"done":"failed"),t.abrupt("return",o&&s);case 19:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),T.UPDATE_USER_ATTRIBUTES),me=R(function(){var e=l(m().mark((function e(t){var r,n;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return k(T.UPDATE_USER_PREFERENCES,"loading"),r=h(h({},z("preferences")),t),e.next=4,H(r).catch((function(e){return C(T.UPDATE_USER_PREFERENCES,e),!1}));case 4:return(n=e.sent)&&(B({preferences:r},!1),k(T.UPDATE_USER_PREFERENCES,"done")),e.abrupt("return",n);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),T.UPDATE_USER_PREFERENCES),ve=R(l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.VERIFY_TELEPHONE_NUMBER,"loading"),t.next=3,e.currentAuthenticatedUser();case 3:return n=t.sent,a=z("mfaType"),t.next=7,w(e.verifyCurrentUserAttribute("phone_number"),T.VERIFY_TELEPHONE_NUMBER);case 7:if(!t.sent){t.next=17;break}return t.next=11,Z(_.VERIFY_TELEPHONE_NUMBER,n,{currentMfaType:a});case 11:if(r=t.sent,a!==b.SMS){t.next=15;break}return t.next=15,le(b.EMAIL,!0);case 15:M(r),k(T.VERIFY_TELEPHONE_NUMBER,"done");case 17:return t.abrupt("return",r);case 18:case"end":return t.stop()}}),t)}))),T.VERIFY_TELEPHONE_NUMBER),Se=R(function(){var e=l(m().mark((function e(t){var r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return k(T.VERIFY_TOTP_TOKEN,"loading"),e.next=3,W(t).catch((function(e){return C(T.VERIFY_TOTP_TOKEN,e),!1}));case 3:return(r=e.sent)&&(B({totpVerified:!0},!1),k(T.VERIFY_TOTP_TOKEN,"done")),e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),T.VERIFY_TOTP_TOKEN),ge=Object.freeze({get centrePermissions(){return z("centrePermissions")},get emailAddress(){return z("emailAddress")},get emailAddressVerified(){return z("emailAddressVerified")},get familyName(){return z("familyName")},get name(){return z("name")},get givenName(){return z("givenName")},get groups(){return z("groups")},get id(){return z("id")},get isInitialized(){return z("isInitialized")},get isSignedIn(){return z("isSignedIn")},get languagePreference(){return z("languagePreference")},get mfaType(){return z("mfaType")},get middleName(){return z("middleName")},get preferences(){return z("preferences")},get provider(){return z("provider")},get requestStatuses(){return z("requestStatuses")},get telephoneNumber(){return z("telephoneNumber")},get telephoneNumberVerified(){return z("telephoneNumberVerified")},get totpVerified(){return z("totpVerified")}});export{T as AuthAction,_ as ChallengeType,b as MFAType,O as Role,N as Subject,ne as changePassword,ae as completePasswordReset,oe as externalSignIn,ie as getAuthorizationToken,ue as getUserSession,ce as init,se as refreshUserSession,fe as requestPasswordReset,le as setMfaType,pe as setupTotp,de as signIn,he as signOut,ge as state,Ee as updateUserAttributes,me as updateUserPreferences,te as useAuthorization,ve as verifyTelephoneNumber,Se as verifyTotp};
|
package/config/jest.config.js
CHANGED
|
@@ -28,16 +28,16 @@ module.exports = {
|
|
|
28
28
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
|
|
29
29
|
moduleNameMapper: {
|
|
30
30
|
// eslint-disable-next-line max-len
|
|
31
|
-
'\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': path.
|
|
31
|
+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': path.join(testPath, 'assetsTransformer.ts'),
|
|
32
32
|
'\\.svg': path.join(testPath, 'svgTransformer.tsx'),
|
|
33
33
|
'^src/(.&)$': '<rootDir>/src/$1'
|
|
34
34
|
},
|
|
35
35
|
modulePaths: ['./'],
|
|
36
36
|
modulePathIgnorePatterns: ['./lib', 'dist'],
|
|
37
|
+
rootDir: appPath,
|
|
37
38
|
roots: [
|
|
38
39
|
'<rootDir>'
|
|
39
40
|
],
|
|
40
|
-
rootDir: appPath,
|
|
41
41
|
setupFiles: [
|
|
42
42
|
path.join(testPath, 'setupTests.ts')
|
|
43
43
|
],
|
package/config/utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
1
|
const path = require('path');
|
|
3
2
|
|
|
4
|
-
const appPath =
|
|
3
|
+
const appPath = path.resolve(__dirname, '../../../');
|
|
5
4
|
const configFilePath = path.resolve(appPath, './config/config.json');
|
|
6
5
|
const packageFilePath = path.resolve(appPath, './package.json');
|
|
7
6
|
|
package/config/webpack.config.js
CHANGED
|
@@ -7,8 +7,8 @@ const webpack = require('webpack');
|
|
|
7
7
|
|
|
8
8
|
const { generateFilename } = require('./utils');
|
|
9
9
|
|
|
10
|
-
const appPath =
|
|
11
|
-
const
|
|
10
|
+
const appPath = path.resolve(__dirname, '../../../');
|
|
11
|
+
const configPath = path.resolve(__dirname, './');
|
|
12
12
|
|
|
13
13
|
const { overrides = {} } = require(path.join(appPath, 'package.json'));
|
|
14
14
|
const devServerHost = overrides.devServerHost || 'localhost';
|
|
@@ -50,13 +50,13 @@ module.exports = () => ({
|
|
|
50
50
|
}),
|
|
51
51
|
new ForkTsCheckerWebpackPlugin({
|
|
52
52
|
typescript: {
|
|
53
|
-
configFile: path.join(
|
|
53
|
+
configFile: path.join(configPath, './tsconfig.json')
|
|
54
54
|
}
|
|
55
55
|
}),
|
|
56
56
|
new HtmlWebpackPlugin({
|
|
57
57
|
template: path.join(appPath, 'index.html'),
|
|
58
58
|
filename: './index.html',
|
|
59
|
-
tsconfig: path.join(
|
|
59
|
+
tsconfig: path.join(configPath, './tsconfig.json')
|
|
60
60
|
})
|
|
61
61
|
],
|
|
62
62
|
resolve: {
|