wjec-one 4.0.0-alpha.21 → 4.0.0-alpha.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wjec-one",
3
- "version": "4.0.0-alpha.21",
3
+ "version": "4.0.0-alpha.23",
4
4
  "description": "",
5
5
  "main": "umd/index.js",
6
6
  "module": "index.js",
package/umd/auth/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("aws-amplify"),require("../utils"),require("react")):"function"==typeof define&&define.amd?define(["exports","aws-amplify","../utils","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WJECOneAuth={},e.aws_amplify,e["C:\\Users\\wiseth\\git\\wjec-one\\temp\\utils"],e.React)}(this,(function(e,t,n,r){"use strict";function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){l(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function a(){a=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,n){return e[t]=n}}function l(e,t,n,i){var o=t&&t.prototype instanceof h?t:h,a=Object.create(o.prototype),u=new N(i||[]);return r(a,"_invoke",{value:b(e,n,u)}),a}function f(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var p={};function h(){}function d(){}function m(){}var g={};s(g,o,(function(){return this}));var y=Object.getPrototypeOf,v=y&&y(y(O([])));v&&v!==t&&n.call(v,o)&&(g=v);var E=m.prototype=h.prototype=Object.create(g);function A(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function S(e,t){function i(r,o,a,u){var c=f(e[r],e,o);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?t.resolve(l.__await).then((function(e){i("next",e,a,u)}),(function(e){i("throw",e,a,u)})):t.resolve(l).then((function(e){s.value=e,a(s)}),(function(e){return i("throw",e,a,u)}))}u(c.arg)}var o;r(this,"_invoke",{value:function(e,n){function r(){return new t((function(t,r){i(e,n,t,r)}))}return o=o?o.then(r,r):r()}})}function b(e,t,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return P()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var u=T(a,n);if(u){if(u===p)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=f(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function T(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,T(e,t),"throw"===t.method))return p;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var r=f(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,p;var i=r.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function _(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 w(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function N(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(_,this),this.reset(!0)}function O(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:P}}function P(){return{value:void 0,done:!0}}return d.prototype=m,r(E,"constructor",{value:m,configurable:!0}),r(m,"constructor",{value:d,configurable:!0}),d.displayName=s(m,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,s(e,c,"GeneratorFunction")),e.prototype=Object.create(E),e},e.awrap=function(e){return{__await:e}},A(S.prototype),s(S.prototype,u,(function(){return this})),e.AsyncIterator=S,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var a=new S(l(t,n,r,i),o);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},A(E),s(E,c,"Generator"),s(E,o,(function(){return this})),s(E,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},e.values=O,N.prototype={constructor:N,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(a)},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),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),w(n),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;w(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:O(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),p}},e}function u(e){return u="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},u(e)}function c(e,t,n,r,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void n(e)}u.done?t(c):Promise.resolve(c).then(r,i)}function s(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var o=e.apply(t,n);function a(e){c(o,r,i,a,u,"next",e)}function u(e){c(o,r,i,a,u,"throw",e)}a(void 0)}))}}function l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,i,o=[],a=!0,u=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);a=!0);}catch(e){u=!0,i=e}finally{try{a||null==n.return||n.return()}finally{if(u)throw i}}return o}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return p(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return p(e,t)}(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 p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var h,d,m,g,y,v=function(){var e=s(a().mark((function e(){var t,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,G();case 2:return t=e.sent,e.next=5,fetch("".concat(b("usersEndpoint")).concat(b("id"),"/preferences"),{headers:{Authorization:t}}).then((function(e){return e.json()})).catch((function(){}));case 5:return n=e.sent,e.abrupt("return",n||{});case 7:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),E=function(){var e=s(a().mark((function e(t){var n,r;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,G();case 2:return n=e.sent,e.next=5,fetch("".concat(b("usersEndpoint")).concat(b("id"),"/mfa"),{body:JSON.stringify({mfaType:t}),headers:{Authorization:n},method:"POST"}).then((function(){return!0})).catch((function(){return!1}));case 5:return r=e.sent,e.abrupt("return",r);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),A=function(){var e=s(a().mark((function e(t){var n,r;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,G();case 2:return n=e.sent,e.next=5,fetch("".concat(b("usersEndpoint")).concat(b("id"),"/preferences"),{body:JSON.stringify(t),headers:{Authorization:n},method:"POST"}).then((function(e){return e.json()})).then((function(e){return e.success})).catch((function(){return!1}));case 5:return r=e.sent,e.abrupt("return",r);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),S={centrePermissions:{},emailAddress:void 0,emailAddressVerified:!1,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isInitialized:!1,isSignedIn:!1,languagePreference:"en-gb",mfaType:void 0,middleName:void 0,preferences:{},requestStatus:"idle",telephoneNumber:void 0,telephoneNumberVerified:!1,totpVerified:!1,usersEndpoint:void 0},b=function(e){return S[e]},T=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];Object.entries(e).forEach((function(e){var t=f(e,2),n=t[0],r=t[1];S[n]=r})),n&&t.Hub.dispatch("custom",{data:{updatedTimestamp:Date.now()},event:"cacheUpdated"})},_=function(){var e=s(a().mark((function e(t){var n,r,i;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.getIdToken().payload,T({centrePermissions:JSON.parse(r["custom:centre_permissions"]||"{}"),emailAddress:r.email,emailAddressVerified:r.email_verified,familyName:r.family_name||r.familyName,fullName:r.name,givenName:r.given_name||r.givenName,groups:r["cognito:groups"]||[],id:r.sub,isSignedIn:!0,languagePreference:r["custom:language_preference"],mfaType:r["custom:mfa_type"],middleName:r.middle_name||r.middleName,telephoneNumber:r.phone_number,telephoneNumberVerified:r.phone_number_verified,totpVerified:"true"===(null===(n=r["custom:totp_verified"])||void 0===n?void 0:n.toLowerCase())}),e.next=4,v();case 4:i=e.sent,T({preferences:i});case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),w=function(e){t.Hub.dispatch("custom",{data:{challenge:e},event:"challenge"})},N=function(e,n){t.Hub.dispatch("custom",{data:{errorDetails:n,errorType:e},event:"error"})},O=function(e){t.Hub.dispatch("custom",{data:{session:e},event:"init"})},P=function(){t.Hub.listen("auth",(function(e){var t=e.payload,n=t.data;switch(t.event){case"completeNewPassword_failure":case"forgotPassword_failure":case"forgotPasswordSubmit_failure":case"signIn_failure":case"signOut_failure":T({requestStatus:"failed"});break;case"signIn":_(n.signInUserSession);break;case"signOut":T({centrePermissions:{},emailAddress:void 0,emailAddressVerified:!1,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isSignedIn:!1,languagePreference:void 0,mfaType:void 0,middleName:void 0,preferences:{},telephoneNumber:void 0,telephoneNumberVerified:!1,totpVerified:!1})}})),t.Hub.listen("custom",(function(e){if("error"===e.payload.event)"loading"===b("requestStatus")&&T({requestStatus:"failed"})}))};e.AuthAction=void 0,(h=e.AuthAction||(e.AuthAction={})).COMPLETE_PASSWORD_RESET="completePasswordReset",h.FORCE_PASSWORD_CHANGE="forcePasswordChange",h.GET_AUTHORIZATION_TOKEN="getAuthorizationToken",h.GET_USER_SESSION="getUserSession",h.INIT="init",h.REQUEST_PASSWORD_RESET="requestPasswordReset",h.SET_MFA_TYPE="setMfaType",h.SIGN_IN="signIn",h.SIGN_OUT="signOut",h.SUBMIT_MFA_CODE="confirmSignIn",h.UPDATE_USER_ATTRIBUTES="updateUserAttributes",h.UPDATE_USER_PREFERENCES="updateUserPreferences",h.VERIFY_TELEPHONE_NUMBER="verifyTelephoneNumber",h.VERIFY_TOTP_TOKEN="verifySoftwareToken",e.ChallengeType=void 0,(d=e.ChallengeType||(e.ChallengeType={})).CUSTOM_CHALLENGE="CUSTOM_CHALLENGE",d.EMAIL_MFA="EMAIL",d.MFA_SETUP="MFA_SETUP",d.NEW_PASSWORD_REQUIRED="NEW_PASSWORD_REQUIRED",d.SMS_MFA="SMS",d.TOTP_MFA="TOTP",d.VERIFY_TELEPHONE_NUMBER="VERIFY_TELEPHONE_NUMBER",e.MFAType=void 0,(m=e.MFAType||(e.MFAType={})).EMAIL="EMAIL",m.NONE="NONE",m.SMS="SMS",m.TOTP="TOTP",e.Role=void 0,(g=e.Role||(e.Role={})).EXAMS_OFFICER="examsOfficer",g.HEAD_TEACHER="headTeacher",g.TEACHER="teacher",e.Subject=void 0,(y=e.Subject||(e.Subject={})).ENGLISH="english",y.MATHS="maths",y.SCIENCE="science";var I=function(e,n){return function(){var r;if(b("isInitialized")){for(var i=arguments.length,o=new Array(i),a=0;a<i;a++)o[a]=arguments[a];(r=e.call.apply(e,[t.Auth].concat(o)))instanceof Promise&&r.catch((function(e){N(n,e)}))}else console.error("WJEC One Authorization: You tried to call ".concat(n,"() before AWS Amplify was initialized. Please provide values for amplifyConfig & oAuthConfig to get set up"));return r}},C=function(e,t){return e.then((function(){return T({requestStatus:"done"}),!0})).catch((function(e){return(e instanceof Error||"string"==typeof e)&&N(t,e),!1}))},R=function(e){return"object"===u(e)&&Object.hasOwn(e,"name")&&"NotAuthorizedException"===e.name},x=function(e){return"object"===u(e)&&Object.hasOwn(e,"name")&&"InvalidPasswordException"===e.name},M=function(e){return Object.entries(e).reduce((function(e,t){var r=f(t,2),i=r[0],a=r[1];return o(o({},e),{},l({},function(e){switch(e){case"familyName":return"family_name";case"fullName":return"name";case"givenName":return"given_name";case"languagePreference":return"custom:language_preference";case"middleName":return"middle_name";case"telephoneNumber":return"phone_number";default:return n.assertNever(e)}}(i),a))}),{})},U=function(){var n=s(a().mark((function n(r){var i,o;return a().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return i=b("mfaType"),n.next=3,j(e.ChallengeType.VERIFY_TELEPHONE_NUMBER,r,{currentMfaType:i});case 3:return o=n.sent,t.Auth.verifyCurrentUserAttribute("phone_number"),i===e.MFAType.SMS&&E(e.MFAType.EMAIL).then((function(){T({mfaType:e.MFAType.EMAIL})})),w(o),n.abrupt("return",o);case 8:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),F=function(n){return function(){var r=s(a().mark((function r(i){var o,u,c;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return T({requestStatus:"loading"}),r.next=3,t.Auth.completeNewPassword(n,i).catch((function(t){R(t)||x(t)||N(e.AuthAction.FORCE_PASSWORD_CHANGE,t),o=!1}));case 3:if(!(u=r.sent)){r.next=12;break}if(!u.challengeName){r.next=10;break}return r.next=8,j(u.challengeName,u,u.challengeParam);case 8:c=r.sent,w(c);case 10:T({requestStatus:"done"}),o=!0;case 12:return r.abrupt("return",o);case 13:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},L=function(n){return function(r){return T({requestStatus:"loading"}),C(t.Auth.sendCustomChallengeAnswer(n,r),e.AuthAction.SUBMIT_MFA_CODE)}},k=function(n){return function(){var r=s(a().mark((function r(i){var o;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return T({requestStatus:"loading"}),r.next=3,C(t.Auth.verifyCurrentUserAttributeSubmit("phone_number",i),e.AuthAction.VERIFY_TELEPHONE_NUMBER);case 3:return(o=r.sent)&&(T({telephoneNumberVerified:!0}),b("mfaType")!==e.MFAType.SMS&&n===e.MFAType.SMS&&E(e.MFAType.SMS).then((function(){T({mfaType:e.MFAType.SMS})}))),r.abrupt("return",o);case 6:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},j=function(t,n){var r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=D(t,null==i?void 0:i.selectedMfaType);switch(o){case e.ChallengeType.EMAIL_MFA:r={challengeType:e.ChallengeType.EMAIL_MFA,completeChallenge:L(n),emailAddress:i.emailAddress};break;case e.ChallengeType.NEW_PASSWORD_REQUIRED:r={challengeType:e.ChallengeType.NEW_PASSWORD_REQUIRED,completeChallenge:F(n)};break;case e.ChallengeType.SMS_MFA:r={challengeType:o,completeChallenge:L(n),telephoneNumber:t===e.ChallengeType.CUSTOM_CHALLENGE?i.redactedPhoneNumber:i.CODE_DELIVERY_DESTINATION};break;case e.ChallengeType.TOTP_MFA:r={challengeType:o,completeChallenge:L(n)};break;case e.ChallengeType.VERIFY_TELEPHONE_NUMBER:r={challengeType:o,completeChallenge:k(i.currentMfaType)}}return r},D=function(t,n){if(t===e.ChallengeType.CUSTOM_CHALLENGE)switch(n){case e.MFAType.EMAIL:return e.ChallengeType.EMAIL_MFA;case e.MFAType.SMS:return e.ChallengeType.SMS_MFA;case e.MFAType.TOTP:return e.ChallengeType.TOTP_MFA}return t},q=!1,H=I((function(n,r,i){return T({requestStatus:"loading"}),C(t.Auth.forgotPasswordSubmit(n,r,i),e.AuthAction.COMPLETE_PASSWORD_RESET)}),e.AuthAction.COMPLETE_PASSWORD_RESET),G=I(s(a().mark((function e(){var t,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,W();case 2:return t=e.sent,n=t.getIdToken().getJwtToken(),e.abrupt("return",n);case 5:case"end":return e.stop()}}),e)}))),e.AuthAction.GET_AUTHORIZATION_TOKEN),W=I(s(a().mark((function e(){var n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.Auth.currentSession();case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)}))),e.AuthAction.GET_USER_SESSION),V=function(){var r=s(a().mark((function r(i,o,u){var c;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(!b("isInitialized")){r.next=4;break}n.developerWarning("WJEC One Authorization: Config cannot be changed after initialization - the config that was originally provided will continue to be used"),r.next=22;break;case 4:if(i&&o&&u){r.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 r.prev=8,t.Amplify.configure(i),t.Auth.configure({oauth:o}),T({isInitialized:!0,usersEndpoint:u}),P(),r.next=15,t.Auth.currentAuthenticatedUser({bypassCache:!0}).then((function(e){var t=e.getSignInUserSession();return _(t),t})).catch((function(){}));case 15:c=r.sent,O(c),r.next=22;break;case 19:r.prev=19,r.t0=r.catch(8),N(e.AuthAction.INIT,r.t0);case 22:return r.abrupt("return",c);case 23:case"end":return r.stop()}}),r,null,[[8,19]])})));return function(e,t,n){return r.apply(this,arguments)}}(),z=I((function(n){return T({requestStatus:"loading"}),C(t.Auth.forgotPassword(n),e.AuthAction.REQUEST_PASSWORD_RESET)}),e.AuthAction.REQUEST_PASSWORD_RESET),Y=I(function(){var e=s(a().mark((function e(t){var n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T({requestStatus:"loading"}),e.next=3,E(t);case 3:n=e.sent,T(n?{mfaType:t,requestStatus:"done"}:{requestStatus:"failed"});case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.AuthAction.SET_MFA_TYPE),B=I(function(){var n=s(a().mark((function n(r,i){var o,u;return a().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return T({requestStatus:"loading"}),n.next=3,t.Auth.signIn(r,i).catch((function(t){R(t)||N(e.AuthAction.SIGN_IN,t)}));case 3:if(!(u=n.sent)){n.next=11;break}if(!u.challengeName){n.next=10;break}return n.next=8,j(u.challengeName,u,u.challengeParam);case 8:o=n.sent,w(o);case 10:T({requestStatus:"done"});case 11:return n.abrupt("return",{challenge:o,user:u});case 12:case"end":return n.stop()}}),n)})));return function(e,t){return n.apply(this,arguments)}}(),e.AuthAction.SIGN_IN),J=I((function(){return T({requestStatus:"loading"}),C(t.Auth.signOut(),e.AuthAction.SIGN_OUT)}),e.AuthAction.SIGN_OUT),Q=I(function(){var n=s(a().mark((function n(r){var i,o,u,c,s,l;return a().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=b("telephoneNumber"),u=b("telephoneNumberVerified"),T({requestStatus:"loading"}),n.next=5,t.Auth.currentAuthenticatedUser();case 5:return c=n.sent,n.next=8,C(t.Auth.updateUserAttributes(c,M(r)),e.AuthAction.UPDATE_USER_ATTRIBUTES);case 8:if(!(s=n.sent)){n.next=17;break}if(T(r),!Object.hasOwn(r,"telephoneNumber")){n.next=17;break}if(l=r.telephoneNumber,o===l&&u){n.next=17;break}return n.next=16,U(c);case 16:i=n.sent;case 17:return n.abrupt("return",{challenge:i,success:s});case 18:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),e.AuthAction.UPDATE_USER_ATTRIBUTES),K=I(function(){var e=s(a().mark((function e(t){var n,r;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return T({requestStatus:"loading"}),n=o(o({},b("preferences")),t),e.next=4,A(n);case 4:r=e.sent,T(r?{preferences:n,requestStatus:"done"}:{requestStatus:"failed"});case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.AuthAction.UPDATE_USER_PREFERENCES),Z=Object.freeze({get centrePermissions(){return b("centrePermissions")},get emailAddress(){return b("emailAddress")},get emailAddressVerified(){return b("emailAddressVerified")},get familyName(){return b("familyName")},get fullName(){return b("fullName")},get givenName(){return b("givenName")},get groups(){return b("groups")},get id(){return b("id")},get isInitialized(){return b("isInitialized")},get isSignedIn(){return b("isSignedIn")},get languagePreference(){return b("languagePreference")},get mfaType(){return b("mfaType")},get middleName(){return b("middleName")},get preferences(){return b("preferences")},get requestStatus(){return b("requestStatus")},get telephoneNumber(){return b("telephoneNumber")},get telephoneNumberVerified(){return b("telephoneNumberVerified")},get totpVerified(){return b("totpVerified")}});e.completePasswordReset=H,e.getAuthorizationToken=G,e.getUserSession=W,e.init=V,e.requestPasswordReset=z,e.setMfaType=Y,e.signIn=B,e.signOut=J,e.state=Z,e.updateUserAttributes=Q,e.updateUserPreferences=K,e.useAuthorization=function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=i.amplifyConfig,a=i.oAuthConfig,u=i.onChallenge,c=i.onCompletePasswordReset,s=i.onError,l=i.onInit,p=i.onRequestPasswordReset,h=i.onSignIn,d=i.onSignOut,m=i.usersEndpoint,g=r.useState(Date.now()),y=f(g,2);y[0];var v=y[1],E=r.useRef(!1);return r.useEffect((function(){var r=!1,i=t.Hub.listen("auth",(function(t){var i=t.payload,o=i.data,a=i.event;if(!r)switch(a){case"completeNewPassword_failure":n.isCallableFunction(s)&&s(e.AuthAction.FORCE_PASSWORD_CHANGE,o);break;case"forgotPassword":n.isCallableFunction(p)&&p(o.username);break;case"forgotPassword_failure":n.isCallableFunction(s)&&s(e.AuthAction.REQUEST_PASSWORD_RESET,o);break;case"forgotPasswordSubmit":n.isCallableFunction(c)&&c();break;case"forgotPasswordSubmit_failure":n.isCallableFunction(s)&&s(e.AuthAction.COMPLETE_PASSWORD_RESET,o);break;case"signIn":n.isCallableFunction(h)&&h(o.signInUserSession);break;case"signIn_failure":n.isCallableFunction(s)&&s(e.AuthAction.SIGN_IN,o);break;case"signOut":n.isCallableFunction(d)&&d()}})),o=t.Hub.listen("custom",(function(e){var t=e.payload,i=t.data,o=t.event;if(!r)switch(o){case"cacheUpdated":v(i.updatedTimestamp);break;case"challenge":n.isCallableFunction(u)&&u(i.challenge);break;case"error":n.isCallableFunction(s)&&s(i.errorType,i.errorDetails);break;case"init":n.isCallableFunction(l)&&l(i.session)}}));return function(){r=!0,i(),o()}}),[u,c,s,l,p,h,d]),r.useEffect((function(){if(o||a||m){try{V(o,a,m),E.current=!0,q=!0}catch(t){n.isCallableFunction(s)&&s(e.AuthAction.INIT)}q&&!E.current&&n.developerWarning("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)")}}),[o,a,m]),Z}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("aws-amplify"),require("../utils"),require("react")):"function"==typeof define&&define.amd?define(["exports","aws-amplify","../utils","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WJECOneAuth={},e.aws_amplify,e["C:\\Users\\wiseth\\git\\wjec-one\\temp\\utils"],e.React)}(this,(function(e,t,n,r){"use strict";function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){f(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(){i=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},a="function"==typeof Symbol?Symbol:{},o=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",c=a.toStringTag||"@@toStringTag";function s(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,n){return e[t]=n}}function f(e,t,n,a){var o=t&&t.prototype instanceof h?t:h,i=Object.create(o.prototype),u=new O(a||[]);return r(i,"_invoke",{value:S(e,n,u)}),i}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=f;var p={};function h(){}function d(){}function m(){}var g={};s(g,o,(function(){return this}));var y=Object.getPrototypeOf,E=y&&y(y(N([])));E&&E!==t&&n.call(E,o)&&(g=E);var v=m.prototype=h.prototype=Object.create(g);function A(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function T(e,t){function a(r,o,i,u){var c=l(e[r],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){a("next",e,i,u)}),(function(e){a("throw",e,i,u)})):t.resolve(f).then((function(e){s.value=e,i(s)}),(function(e){return a("throw",e,i,u)}))}u(c.arg)}var o;r(this,"_invoke",{value:function(e,n){function r(){return new t((function(t,r){a(e,n,t,r)}))}return o=o?o.then(r,r):r()}})}function S(e,t,n){var r="suspendedStart";return function(a,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===a)throw o;return P()}for(n.method=a,n.arg=o;;){var i=n.delegate;if(i){var u=b(i,n);if(u){if(u===p)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=l(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function b(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method))return p;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var r=l(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,p;var a=r.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function _(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 w(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(_,this),this.reset(!0)}function N(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:P}}function P(){return{value:void 0,done:!0}}return d.prototype=m,r(v,"constructor",{value:m,configurable:!0}),r(m,"constructor",{value:d,configurable:!0}),d.displayName=s(m,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,s(e,c,"GeneratorFunction")),e.prototype=Object.create(v),e},e.awrap=function(e){return{__await:e}},A(T.prototype),s(T.prototype,u,(function(){return this})),e.AsyncIterator=T,e.async=function(t,n,r,a,o){void 0===o&&(o=Promise);var i=new T(f(t,n,r,a),o);return e.isGeneratorFunction(n)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},A(v),s(v,c,"Generator"),s(v,o,(function(){return this})),s(v,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},e.values=N,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return i.type="throw",i.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],i=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.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,p):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),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),w(n),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var a=r.arg;w(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:N(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),p}},e}function u(e){return u="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},u(e)}function c(e,t,n,r,a,o,i){try{var u=e[o](i),c=u.value}catch(e){return void n(e)}u.done?t(c):Promise.resolve(c).then(r,a)}function s(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var o=e.apply(t,n);function i(e){c(o,r,a,i,u,"next",e)}function u(e){c(o,r,a,i,u,"throw",e)}i(void 0)}))}}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,a,o=[],i=!0,u=!1;try{for(n=n.call(e);!(i=(r=n.next()).done)&&(o.push(r.value),!t||o.length!==t);i=!0);}catch(e){u=!0,a=e}finally{try{i||null==n.return||n.return()}finally{if(u)throw a}}return o}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return p(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return p(e,t)}(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 p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var h,d,m,g,y,E=function(e){t.Hub.dispatch("custom",{data:{challenge:e},event:"challenge"})},v=function(e,n){t.Hub.dispatch("custom",{data:{errorDetails:n,errorType:e},event:"error"})},A=function(e){t.Hub.dispatch("custom",{data:{session:e},event:"init"})},T=function(){var e=s(i().mark((function e(){var n,r,a;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.Auth.currentSession();case 2:return n=e.sent,r=n.getIdToken(),e.next=6,fetch("".concat(q("usersEndpoint")).concat(r.payload.sub,"/mfa/secret"),{headers:{Authorization:r.getJwtToken()}}).then((function(e){return e.json()})).then((function(e){return e.secret}));case 6:return a=e.sent,e.abrupt("return",a);case 8:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),S=function(){var e=s(i().mark((function e(){var n,r,a;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.Auth.currentSession();case 2:return n=e.sent,r=n.getIdToken(),e.next=6,fetch("".concat(q("usersEndpoint")).concat(r.payload.sub,"/preferences"),{headers:{Authorization:r.getJwtToken()}}).then((function(e){return e.json()}));case 6:return a=e.sent,e.abrupt("return",a||{});case 8:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),b=function(){var e=s(i().mark((function e(n){var r,a,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.Auth.currentSession();case 2:return r=e.sent,a=r.getIdToken(),e.next=6,fetch("".concat(q("usersEndpoint")).concat(a.payload.sub,"/mfa"),{body:JSON.stringify({mfaType:n}),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=e.sent,e.abrupt("return",o);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),_=function(){var e=s(i().mark((function e(n){var r,a,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.Auth.currentSession();case 2:return r=e.sent,a=r.getIdToken(),e.next=6,fetch("".concat(q("usersEndpoint")).concat(a.payload.sub,"/preferences"),{body:JSON.stringify(n),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){return e.json()})).then((function(e){return e.success}));case 6:return o=e.sent,e.abrupt("return",o);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),w=function(){var e=s(i().mark((function e(n){var r,a,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.Auth.currentSession();case 2:return r=e.sent,a=r.getIdToken(),e.next=6,fetch("".concat(q("usersEndpoint")).concat(a.payload.sub,"/mfa/secret"),{body:JSON.stringify({totpCode:n}),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=e.sent,e.abrupt("return",o);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();e.AuthAction=void 0,(h=e.AuthAction||(e.AuthAction={})).COMPLETE_PASSWORD_RESET="completePasswordReset",h.FORCE_PASSWORD_CHANGE="forcePasswordChange",h.GET_AUTHORIZATION_TOKEN="getAuthorizationToken",h.GET_USER_PREFERENCES="getUserPreferences",h.GET_USER_SESSION="getUserSession",h.INIT="init",h.REQUEST_PASSWORD_RESET="requestPasswordReset",h.REQUEST_TOTP_TOKEN="requestSoftwareToken",h.SET_MFA_TYPE="setMfaType",h.SIGN_IN="signIn",h.SIGN_OUT="signOut",h.SUBMIT_MFA_CODE="confirmSignIn",h.UPDATE_USER_ATTRIBUTES="updateUserAttributes",h.UPDATE_USER_PREFERENCES="updateUserPreferences",h.VERIFY_TELEPHONE_NUMBER="verifyTelephoneNumber",h.VERIFY_TOTP_TOKEN="verifySoftwareToken",e.ChallengeType=void 0,(d=e.ChallengeType||(e.ChallengeType={})).CUSTOM_CHALLENGE="CUSTOM_CHALLENGE",d.EMAIL_MFA="EMAIL",d.MFA_SETUP="MFA_SETUP",d.NEW_PASSWORD_REQUIRED="NEW_PASSWORD_REQUIRED",d.SMS_MFA="SMS",d.TOTP_MFA="TOTP",d.VERIFY_TELEPHONE_NUMBER="VERIFY_TELEPHONE_NUMBER",d.VERIFY_TOTP_TOKEN="VERIFY_TOTP_TOKEN",e.MFAType=void 0,(m=e.MFAType||(e.MFAType={})).EMAIL="EMAIL",m.NONE="NONE",m.SMS="SMS",m.TOTP="TOTP",e.Role=void 0,(g=e.Role||(e.Role={})).EXAMS_OFFICER="examsOfficer",g.HEAD_TEACHER="headTeacher",g.TEACHER="teacher",e.Subject=void 0,(y=e.Subject||(e.Subject={})).ENGLISH="english",y.MATHS="maths",y.SCIENCE="science";var O=function(n){return function(){var r=s(i().mark((function r(a){var o,u,c;return i().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return D({requestStatus:"loading"}),r.next=3,t.Auth.completeNewPassword(n,a).catch((function(t){k(t)||F(t)||v(e.AuthAction.FORCE_PASSWORD_CHANGE,t),o=!1}));case 3:if(!(u=r.sent)){r.next=12;break}if(!u.challengeName){r.next=10;break}return r.next=8,I(u.challengeName,u,u.challengeParam);case 8:c=r.sent,E(c);case 10:D({requestStatus:"done"}),o=!0;case 12:return r.abrupt("return",o);case 13:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},N=function(n){return function(r){return D({requestStatus:"loading"}),M(t.Auth.sendCustomChallengeAnswer(n,r),e.AuthAction.SUBMIT_MFA_CODE)}},P=function(n){return function(){var r=s(i().mark((function r(a){var o;return i().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return D({requestStatus:"loading"}),r.next=3,M(t.Auth.verifyCurrentUserAttributeSubmit("phone_number",a),e.AuthAction.VERIFY_TELEPHONE_NUMBER);case 3:return(o=r.sent)&&(D({telephoneNumberVerified:!0}),q("mfaType")!==e.MFAType.SMS&&n===e.MFAType.SMS&&b(e.MFAType.SMS).then((function(){D({mfaType:e.MFAType.SMS})}))),r.abrupt("return",o);case 6:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},R=function(){return function(){var e=s(i().mark((function e(t){var n;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,te(t);case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()},I=function(t,n){var r,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=x(t,null==a?void 0:a.selectedMfaType);switch(o){case e.ChallengeType.EMAIL_MFA:r={challengeType:e.ChallengeType.EMAIL_MFA,completeChallenge:N(n),emailAddress:a.emailAddress};break;case e.ChallengeType.NEW_PASSWORD_REQUIRED:r={challengeType:e.ChallengeType.NEW_PASSWORD_REQUIRED,completeChallenge:O(n)};break;case e.ChallengeType.SMS_MFA:r={challengeType:o,completeChallenge:N(n),telephoneNumber:t===e.ChallengeType.CUSTOM_CHALLENGE?a.redactedPhoneNumber:a.CODE_DELIVERY_DESTINATION};break;case e.ChallengeType.TOTP_MFA:r={challengeType:o,completeChallenge:N(n)};break;case e.ChallengeType.VERIFY_TELEPHONE_NUMBER:r={challengeType:o,completeChallenge:P(a.currentMfaType)};break;case e.ChallengeType.VERIFY_TOTP_TOKEN:r={challengeType:o,completeChallenge:R(),secretKey:a.secretKey}}return r},x=function(t,n){if(t===e.ChallengeType.CUSTOM_CHALLENGE)switch(n){case e.MFAType.EMAIL:return e.ChallengeType.EMAIL_MFA;case e.MFAType.SMS:return e.ChallengeType.SMS_MFA;case e.MFAType.TOTP:return e.ChallengeType.TOTP_MFA}return t},C=function(e,n){return function(){var r;if(q("isInitialized")){for(var a=arguments.length,o=new Array(a),i=0;i<a;i++)o[i]=arguments[i];(r=e.call.apply(e,[t.Auth].concat(o)))instanceof Promise&&r.catch((function(e){v(n,e)}))}else console.error("WJEC One Authorization: You tried to call ".concat(n,"() before AWS Amplify was initialized. Please provide values for amplifyConfig & oAuthConfig to get set up"));return r}},M=function(e,t){return e.then((function(){return D({requestStatus:"done"}),!0})).catch((function(e){return(e instanceof Error||"string"==typeof e)&&v(t,e),!1}))},k=function(e){return"object"===u(e)&&Object.hasOwn(e,"name")&&"NotAuthorizedException"===e.name},F=function(e){return"object"===u(e)&&Object.hasOwn(e,"name")&&"InvalidPasswordException"===e.name},U=function(e){return Object.entries(e).reduce((function(e,t){var r=l(t,2),a=r[0],i=r[1];return o(o({},e),{},f({},function(e){switch(e){case"familyName":return"family_name";case"fullName":return"name";case"givenName":return"given_name";case"languagePreference":return"custom:language_preference";case"middleName":return"middle_name";case"telephoneNumber":return"phone_number";default:return n.assertNever(e)}}(a),i))}),{})},L=function(){var n=s(i().mark((function n(r){var a,o;return i().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=q("mfaType"),n.next=3,I(e.ChallengeType.VERIFY_TELEPHONE_NUMBER,r,{currentMfaType:a});case 3:return o=n.sent,t.Auth.verifyCurrentUserAttribute("phone_number"),a===e.MFAType.SMS&&b(e.MFAType.EMAIL).then((function(){D({mfaType:e.MFAType.EMAIL})})).catch((function(t){v(e.AuthAction.SET_MFA_TYPE,t)})),E(o),n.abrupt("return",o);case 8:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),j={centrePermissions:{},emailAddress:void 0,emailAddressVerified:!1,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isInitialized:!1,isSignedIn:!1,languagePreference:"en-gb",mfaType:void 0,middleName:void 0,preferences:{},requestStatus:"idle",telephoneNumber:void 0,telephoneNumberVerified:!1,totpVerified:!1,usersEndpoint:void 0},q=function(e){return j[e]},D=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];Object.entries(e).forEach((function(e){var t=l(e,2),n=t[0],r=t[1];j[n]=r})),n&&t.Hub.dispatch("custom",{data:{updatedTimestamp:Date.now()},event:"cacheUpdated"})},V=function(){var t=s(i().mark((function t(n){var r,a,u;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=n.getIdToken().payload,D({requestStatus:"loading"}),t.next=4,S().then((function(e){return D({requestStatus:"done"}),e})).catch((function(t){return v(e.AuthAction.GET_USER_PREFERENCES,t),D({requestStatus:"failed"}),{}}));case 4:u=t.sent,D({centrePermissions:JSON.parse(a["custom:centre_permissions"]||"{}"),emailAddress:a.email,emailAddressVerified:a.email_verified,familyName:a.family_name||a.familyName,fullName:a.name,givenName:a.given_name||a.givenName,groups:a["cognito:groups"]||[],id:a.sub,isSignedIn:!0,languagePreference:a["custom:language_preference"],mfaType:a["custom:mfa_type"],middleName:a.middle_name||a.middleName,preferences:(i=u,o(o({},i),{},{emailMfaAccepted:i.emailMfaAccepted?new Date(i.emailMfaAccepted):void 0})),telephoneNumber:a.phone_number,telephoneNumberVerified:a.phone_number_verified,totpVerified:"true"===(null===(r=a["custom:totp_verified"])||void 0===r?void 0:r.toLowerCase())});case 6:case"end":return t.stop()}var i}),t)})));return function(e){return t.apply(this,arguments)}}(),G=function(){D({centrePermissions:{},emailAddress:void 0,emailAddressVerified:!1,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isSignedIn:!1,languagePreference:void 0,mfaType:void 0,middleName:void 0,preferences:{},telephoneNumber:void 0,telephoneNumberVerified:!1,totpVerified:!1})},H=!1,W=C((function(n,r,a){return D({requestStatus:"loading"}),M(t.Auth.forgotPasswordSubmit(n,r,a),e.AuthAction.COMPLETE_PASSWORD_RESET)}),e.AuthAction.COMPLETE_PASSWORD_RESET),z=C(s(i().mark((function e(){var t,n;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Y();case 2:return t=e.sent,n=t.getIdToken().getJwtToken(),e.abrupt("return",n);case 5:case"end":return e.stop()}}),e)}))),e.AuthAction.GET_AUTHORIZATION_TOKEN),Y=C(s(i().mark((function e(){var n;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.Auth.currentSession();case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)}))),e.AuthAction.GET_USER_SESSION),K=function(){var r=s(i().mark((function r(a,o,u){var c;return i().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(!q("isInitialized")){r.next=4;break}n.developerWarning("WJEC One Authorization: Config cannot be changed after initialization - the config that was originally provided will continue to be used"),r.next=22;break;case 4:if(a&&o&&u){r.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 r.prev=8,t.Amplify.configure(a),t.Auth.configure({oauth:o}),D({isInitialized:!0,usersEndpoint:u}),t.Hub.listen("auth",(function(e){var t=e.payload,n=t.data;switch(t.event){case"completeNewPassword_failure":case"forgotPassword_failure":case"forgotPasswordSubmit_failure":case"signIn_failure":case"signOut_failure":D({requestStatus:"failed"});break;case"signIn":V(n.signInUserSession);break;case"signOut":G()}})),t.Hub.listen("custom",(function(e){"error"===e.payload.event&&"loading"===q("requestStatus")&&D({requestStatus:"failed"})})),r.next=15,t.Auth.currentAuthenticatedUser({bypassCache:!0}).then(function(){var e=s(i().mark((function e(t){var n;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.getSignInUserSession(),e.next=3,V(n);case 3:return e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(){}));case 15:c=r.sent,A(c),r.next=22;break;case 19:r.prev=19,r.t0=r.catch(8),v(e.AuthAction.INIT,r.t0);case 22:return r.abrupt("return",c);case 23:case"end":return r.stop()}}),r,null,[[8,19]])})));return function(e,t,n){return r.apply(this,arguments)}}(),J=C((function(n){return D({requestStatus:"loading"}),M(t.Auth.forgotPassword(n),e.AuthAction.REQUEST_PASSWORD_RESET)}),e.AuthAction.REQUEST_PASSWORD_RESET),B=C(function(){var t=s(i().mark((function t(n){var r;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return D({requestStatus:"loading"}),t.next=3,b(n).catch((function(t){return v(e.AuthAction.SET_MFA_TYPE,t),D({requestStatus:"failed"}),!1}));case 3:return(r=t.sent)&&(D({mfaType:n,requestStatus:"done"}),n!==e.MFAType.EMAIL&&_({emailMfaAccepted:void 0})),t.abrupt("return",r);case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),e.AuthAction.SET_MFA_TYPE),Q=C(s(i().mark((function n(){var r,a,o;return i().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,t.Auth.currentAuthenticatedUser();case 2:return a=n.sent,D({requestStatus:"loading"}),n.next=6,T().catch((function(t){v(e.AuthAction.REQUEST_TOTP_TOKEN,t),D({requestStatus:"failed"})}));case 6:if(!(o=n.sent)){n.next=15;break}return q("mfaType")===e.MFAType.SMS&&b(e.MFAType.EMAIL).then((function(){D({mfaType:e.MFAType.EMAIL})})).catch((function(t){v(e.AuthAction.SET_MFA_TYPE,t)})),n.next=12,I(e.ChallengeType.VERIFY_TOTP_TOKEN,a,{secretKey:o});case 12:r=n.sent,E(r),D({requestStatus:"done"});case 15:return n.abrupt("return",{challenge:r,secretKey:o});case 16:case"end":return n.stop()}}),n)}))),e.AuthAction.REQUEST_TOTP_TOKEN),Z=C(function(){var n=s(i().mark((function n(r,a){var o,u;return i().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return D({requestStatus:"loading"}),n.next=3,t.Auth.signIn(r,a).catch((function(t){k(t)||v(e.AuthAction.SIGN_IN,t)}));case 3:if(!(u=n.sent)){n.next=11;break}if(!u.challengeName){n.next=10;break}return n.next=8,I(u.challengeName,u,u.challengeParam);case 8:o=n.sent,E(o);case 10:D({requestStatus:"done"});case 11:return n.abrupt("return",{challenge:o,user:u});case 12:case"end":return n.stop()}}),n)})));return function(e,t){return n.apply(this,arguments)}}(),e.AuthAction.SIGN_IN),X=C((function(){return D({requestStatus:"loading"}),M(t.Auth.signOut(),e.AuthAction.SIGN_OUT)}),e.AuthAction.SIGN_OUT),$=C(function(){var n=s(i().mark((function n(r){var a,o,u,c,s,f;return i().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=q("telephoneNumber"),u=q("telephoneNumberVerified"),D({requestStatus:"loading"}),n.next=5,t.Auth.currentAuthenticatedUser();case 5:return c=n.sent,n.next=8,M(t.Auth.updateUserAttributes(c,U(r)),e.AuthAction.UPDATE_USER_ATTRIBUTES);case 8:if(!(s=n.sent)){n.next=17;break}if(D(r),!Object.hasOwn(r,"telephoneNumber")){n.next=17;break}if(f=r.telephoneNumber,o===f&&u){n.next=17;break}return n.next=16,L(c);case 16:a=n.sent;case 17:return n.abrupt("return",{challenge:a,success:s});case 18:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),e.AuthAction.UPDATE_USER_ATTRIBUTES),ee=C(function(){var t=s(i().mark((function t(n){var r,a;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return D({requestStatus:"loading"}),r=o(o({},q("preferences")),n),t.next=4,_(r).catch((function(t){return v(e.AuthAction.UPDATE_USER_PREFERENCES,t),D({requestStatus:"failed"}),!1}));case 4:return(a=t.sent)&&D({preferences:r,requestStatus:"done"}),t.abrupt("return",a);case 7:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),e.AuthAction.UPDATE_USER_PREFERENCES),te=C(function(){var t=s(i().mark((function t(n){var r;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return D({requestStatus:"loading"}),t.next=3,w(n).catch((function(t){return v(e.AuthAction.VERIFY_TOTP_TOKEN,t),D({requestStatus:"failed"}),!1}));case 3:return(r=t.sent)&&D({requestStatus:"done"}),t.abrupt("return",r);case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),e.AuthAction.VERIFY_TOTP_TOKEN),ne=Object.freeze({get centrePermissions(){return q("centrePermissions")},get emailAddress(){return q("emailAddress")},get emailAddressVerified(){return q("emailAddressVerified")},get familyName(){return q("familyName")},get fullName(){return q("fullName")},get givenName(){return q("givenName")},get groups(){return q("groups")},get id(){return q("id")},get isInitialized(){return q("isInitialized")},get isSignedIn(){return q("isSignedIn")},get languagePreference(){return q("languagePreference")},get mfaType(){return q("mfaType")},get middleName(){return q("middleName")},get preferences(){return q("preferences")},get requestStatus(){return q("requestStatus")},get telephoneNumber(){return q("telephoneNumber")},get telephoneNumberVerified(){return q("telephoneNumberVerified")},get totpVerified(){return q("totpVerified")}});e.completePasswordReset=W,e.getAuthorizationToken=z,e.getUserSession=Y,e.init=K,e.requestPasswordReset=J,e.setMfaType=B,e.setupTotp=Q,e.signIn=Z,e.signOut=X,e.state=ne,e.updateUserAttributes=$,e.updateUserPreferences=ee,e.useAuthorization=function(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=a.amplifyConfig,i=a.oAuthConfig,u=a.onChallenge,c=a.onCompletePasswordReset,s=a.onError,f=a.onInit,p=a.onRequestPasswordReset,h=a.onSignIn,d=a.onSignOut,m=a.usersEndpoint,g=r.useState(Date.now()),y=l(g,2);y[0];var E=y[1],v=r.useRef(!1);return r.useEffect((function(){var r=!1,a=t.Hub.listen("auth",(function(t){var a=t.payload,o=a.data,i=a.event;if(!r)switch(i){case"completeNewPassword_failure":n.isCallableFunction(s)&&s(e.AuthAction.FORCE_PASSWORD_CHANGE,o);break;case"forgotPassword":n.isCallableFunction(p)&&p(o.username);break;case"forgotPassword_failure":n.isCallableFunction(s)&&s(e.AuthAction.REQUEST_PASSWORD_RESET,o);break;case"forgotPasswordSubmit":n.isCallableFunction(c)&&c();break;case"forgotPasswordSubmit_failure":n.isCallableFunction(s)&&s(e.AuthAction.COMPLETE_PASSWORD_RESET,o);break;case"signIn":n.isCallableFunction(h)&&h(o.signInUserSession);break;case"signIn_failure":n.isCallableFunction(s)&&s(e.AuthAction.SIGN_IN,o);break;case"signOut":n.isCallableFunction(d)&&d()}})),o=t.Hub.listen("custom",(function(e){var t=e.payload,a=t.data,o=t.event;if(!r)switch(o){case"cacheUpdated":E(a.updatedTimestamp);break;case"challenge":n.isCallableFunction(u)&&u(a.challenge);break;case"error":n.isCallableFunction(s)&&s(a.errorType,a.errorDetails);break;case"init":n.isCallableFunction(f)&&f(a.session)}}));return function(){r=!0,a(),o()}}),[u,c,s,f,p,h,d]),r.useEffect((function(){if(o||i||m){try{K(o,i,m),v.current=!0,H=!0}catch(t){n.isCallableFunction(s)&&s(e.AuthAction.INIT)}H&&!v.current&&n.developerWarning("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)")}}),[o,i,m]),ne},e.verifyTotp=te}));