wjec-one 4.0.0-alpha.21 → 4.0.0-alpha.22
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 +19 -6
- package/auth/index.js +1 -1
- package/package.json +1 -1
- package/umd/auth/index.js +1 -1
- package/umd/utils/index.js +1 -1
- package/utils/index.d.ts +2 -1
- package/utils/index.js +1 -1
package/auth/index.d.ts
CHANGED
|
@@ -15,9 +15,11 @@ declare enum AuthAction {
|
|
|
15
15
|
COMPLETE_PASSWORD_RESET = "completePasswordReset",
|
|
16
16
|
FORCE_PASSWORD_CHANGE = "forcePasswordChange",
|
|
17
17
|
GET_AUTHORIZATION_TOKEN = "getAuthorizationToken",
|
|
18
|
+
GET_USER_PREFERENCES = "getUserPreferences",
|
|
18
19
|
GET_USER_SESSION = "getUserSession",
|
|
19
20
|
INIT = "init",
|
|
20
21
|
REQUEST_PASSWORD_RESET = "requestPasswordReset",
|
|
22
|
+
REQUEST_TOTP_TOKEN = "requestSoftwareToken",
|
|
21
23
|
SET_MFA_TYPE = "setMfaType",
|
|
22
24
|
SIGN_IN = "signIn",
|
|
23
25
|
SIGN_OUT = "signOut",
|
|
@@ -34,7 +36,8 @@ declare enum ChallengeType {
|
|
|
34
36
|
NEW_PASSWORD_REQUIRED = "NEW_PASSWORD_REQUIRED",
|
|
35
37
|
SMS_MFA = "SMS",
|
|
36
38
|
TOTP_MFA = "TOTP",
|
|
37
|
-
VERIFY_TELEPHONE_NUMBER = "VERIFY_TELEPHONE_NUMBER"
|
|
39
|
+
VERIFY_TELEPHONE_NUMBER = "VERIFY_TELEPHONE_NUMBER",
|
|
40
|
+
VERIFY_TOTP_TOKEN = "VERIFY_TOTP_TOKEN"
|
|
38
41
|
}
|
|
39
42
|
declare enum MFAType {
|
|
40
43
|
EMAIL = "EMAIL",
|
|
@@ -90,7 +93,12 @@ declare type VerifyTelephoneNumberChallenge = {
|
|
|
90
93
|
challengeType: ChallengeType.VERIFY_TELEPHONE_NUMBER;
|
|
91
94
|
completeChallenge: (code: string) => Promise<boolean>;
|
|
92
95
|
};
|
|
93
|
-
declare type
|
|
96
|
+
declare type VerifyTotpTokenChallenge = {
|
|
97
|
+
challengeType: ChallengeType.VERIFY_TOTP_TOKEN;
|
|
98
|
+
completeChallenge: (code: string) => Promise<boolean>;
|
|
99
|
+
secretKey: string;
|
|
100
|
+
};
|
|
101
|
+
declare type Challenge = EmailMfaChallenge | NewPasswordChallenge | SmsMfaChallenge | TotpMfaChallenge | VerifyTelephoneNumberChallenge | VerifyTotpTokenChallenge;
|
|
94
102
|
declare enum Role {
|
|
95
103
|
EXAMS_OFFICER = "examsOfficer",
|
|
96
104
|
HEAD_TEACHER = "headTeacher",
|
|
@@ -102,7 +110,7 @@ declare enum Subject {
|
|
|
102
110
|
SCIENCE = "science"
|
|
103
111
|
}
|
|
104
112
|
declare type UserPreferences = {
|
|
105
|
-
emailMfaAccepted?:
|
|
113
|
+
emailMfaAccepted?: Date;
|
|
106
114
|
favouriteLinks?: string[];
|
|
107
115
|
role?: Role;
|
|
108
116
|
subjects?: Subject[];
|
|
@@ -129,7 +137,11 @@ declare const getAuthorizationToken: () => Promise<string>;
|
|
|
129
137
|
declare const getUserSession: () => Promise<CognitoUserSession>;
|
|
130
138
|
declare const init: (amplifyConfig: Record<string, any>, oAuthConfig: Record<string, any>, usersEndpoint: string) => Promise<CognitoUserSession>;
|
|
131
139
|
declare const requestPasswordReset: (emailAddress: string) => Promise<boolean>;
|
|
132
|
-
declare const setMfaType: (mfaType: MFAType.EMAIL | MFAType.SMS | MFAType.TOTP) => Promise<
|
|
140
|
+
declare const setMfaType: (mfaType: MFAType.EMAIL | MFAType.SMS | MFAType.TOTP) => Promise<boolean>;
|
|
141
|
+
declare const setupTotp: () => Promise<{
|
|
142
|
+
challenge?: Challenge;
|
|
143
|
+
secretKey: string;
|
|
144
|
+
}>;
|
|
133
145
|
declare const signIn: (emailAddress: string, password: string) => Promise<{
|
|
134
146
|
challenge?: Challenge;
|
|
135
147
|
user: CognitoUser;
|
|
@@ -139,7 +151,8 @@ declare const updateUserAttributes: (attributes: Partial<EditableCognitoUserAttr
|
|
|
139
151
|
challenge: Challenge;
|
|
140
152
|
success: boolean;
|
|
141
153
|
}>;
|
|
142
|
-
declare const updateUserPreferences: (preferences: Partial<UserPreferences>) => Promise<
|
|
154
|
+
declare const updateUserPreferences: (preferences: Partial<UserPreferences>) => Promise<boolean>;
|
|
155
|
+
declare const verifyTotp: (code: string) => Promise<boolean>;
|
|
143
156
|
declare const state: Readonly<{
|
|
144
157
|
readonly centrePermissions: Record<string, string>;
|
|
145
158
|
readonly emailAddress: string;
|
|
@@ -161,4 +174,4 @@ declare const state: Readonly<{
|
|
|
161
174
|
readonly totpVerified: boolean;
|
|
162
175
|
}>;
|
|
163
176
|
|
|
164
|
-
export { AuthAction, Cache, Challenge, ChallengeType, CognitoUserAttributes, EditableCognitoUserAttributes, EmailMfaChallenge, MFAType, NewPasswordChallenge, ReadonlyCognitoUserAttributes, Role, SmsMfaChallenge, Subject, TotpMfaChallenge, UserPreferences, VerifyTelephoneNumberChallenge, completePasswordReset, getAuthorizationToken, getUserSession, init, requestPasswordReset, setMfaType, signIn, signOut, state, updateUserAttributes, updateUserPreferences, useAuthorization };
|
|
177
|
+
export { AuthAction, Cache, Challenge, ChallengeType, CognitoUserAttributes, EditableCognitoUserAttributes, EmailMfaChallenge, MFAType, NewPasswordChallenge, ReadonlyCognitoUserAttributes, Role, SmsMfaChallenge, Subject, TotpMfaChallenge, UserPreferences, VerifyTelephoneNumberChallenge, VerifyTotpTokenChallenge, completePasswordReset, getAuthorizationToken, getUserSession, init, requestPasswordReset, setMfaType, setupTotp, signIn, signOut, state, updateUserAttributes, updateUserPreferences, useAuthorization, verifyTotp };
|
package/auth/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Hub as e,Auth as t,Amplify as r}from"aws-amplify";import{assertNever as n,isCallableFunction as o,developerWarning as a}from"../utils";import{useState as i,useRef as u,useEffect as c}from"react";function s(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 f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?s(Object(r),!0).forEach((function(t){m(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function l(){l=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function s(e,t,r,o){var a=t&&t.prototype instanceof d?t:d,i=Object.create(a.prototype),u=new O(o||[]);return n(i,"_invoke",{value:_(e,r,u)}),i}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var p={};function d(){}function h(){}function m(){}var g={};c(g,a,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(A([])));y&&y!==t&&r.call(y,a)&&(g=y);var E=m.prototype=d.prototype=Object.create(g);function S(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function b(e,t){function o(n,a,i,u){var c=f(e[n],e,a);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&r.call(l,"__await")?t.resolve(l.__await).then((function(e){o("next",e,i,u)}),(function(e){o("throw",e,i,u)})):t.resolve(l).then((function(e){s.value=e,i(s)}),(function(e){return o("throw",e,i,u)}))}u(c.arg)}var a;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){o(e,r,t,n)}))}return a=a?a.then(n,n):n()}})}function _(e,t,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return P()}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var u=w(i,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function w(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,w(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 n=f(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,p;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function T(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 N(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function A(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return h.prototype=m,n(E,"constructor",{value:m,configurable:!0}),n(m,"constructor",{value:h,configurable:!0}),h.displayName=c(m,u,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,c(e,u,"GeneratorFunction")),e.prototype=Object.create(E),e},e.awrap=function(e){return{__await:e}},S(b.prototype),c(b.prototype,i,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new b(s(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},S(E),c(E,u,"Generator"),c(E,a,(function(){return this})),c(E,"toString",(function(){return"[object Generator]"})),e.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}},e.values=A,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(N),!e)for(var t in this)"t"===t.charAt(0)&&r.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 n(r,n){return i.type="throw",i.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.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 r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),N(r),p}},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 o=n.arg;N(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:A(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},e}function p(e){return p="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},p(e)}function d(e,t,r,n,o,a,i){try{var u=e[a](i),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,o)}function h(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function i(e){d(a,n,o,i,u,"next",e)}function u(e){d(a,n,o,i,u,"throw",e)}i(void 0)}))}}function m(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function g(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)return;var n,o,a=[],i=!0,u=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(a.push(n.value),!t||a.length!==t);i=!0);}catch(e){u=!0,o=e}finally{try{i||null==r.return||r.return()}finally{if(u)throw o}}return a}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return v(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return v(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 v(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var y,E,S,b,_,w=function(){var e=h(l().mark((function e(){var t,r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,J();case 2:return t=e.sent,e.next=5,fetch("".concat(A("usersEndpoint")).concat(A("id"),"/preferences"),{headers:{Authorization:t}}).then((function(e){return e.json()})).catch((function(){}));case 5:return r=e.sent,e.abrupt("return",r||{});case 7:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),T=function(){var e=h(l().mark((function e(t){var r,n;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,J();case 2:return r=e.sent,e.next=5,fetch("".concat(A("usersEndpoint")).concat(A("id"),"/mfa"),{body:JSON.stringify({mfaType:t}),headers:{Authorization:r},method:"POST"}).then((function(){return!0})).catch((function(){return!1}));case 5:return n=e.sent,e.abrupt("return",n);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),N=function(){var e=h(l().mark((function e(t){var r,n;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,J();case 2:return r=e.sent,e.next=5,fetch("".concat(A("usersEndpoint")).concat(A("id"),"/preferences"),{body:JSON.stringify(t),headers:{Authorization:r},method:"POST"}).then((function(e){return e.json()})).then((function(e){return e.success})).catch((function(){return!1}));case 5:return n=e.sent,e.abrupt("return",n);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),O={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},A=function(e){return O[e]},P=function(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];Object.entries(t).forEach((function(e){var t=g(e,2),r=t[0],n=t[1];O[r]=n})),r&&e.dispatch("custom",{data:{updatedTimestamp:Date.now()},event:"cacheUpdated"})},I=function(){var e=h(l().mark((function e(t){var r,n,o;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.getIdToken().payload,P({centrePermissions:JSON.parse(n["custom:centre_permissions"]||"{}"),emailAddress:n.email,emailAddressVerified:n.email_verified,familyName:n.family_name||n.familyName,fullName:n.name,givenName:n.given_name||n.givenName,groups:n["cognito:groups"]||[],id:n.sub,isSignedIn:!0,languagePreference:n["custom:language_preference"],mfaType:n["custom:mfa_type"],middleName:n.middle_name||n.middleName,telephoneNumber:n.phone_number,telephoneNumberVerified:n.phone_number_verified,totpVerified:"true"===(null===(r=n["custom:totp_verified"])||void 0===r?void 0:r.toLowerCase())}),e.next=4,w();case 4:o=e.sent,P({preferences:o});case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),x=function(t){e.dispatch("custom",{data:{challenge:t},event:"challenge"})},R=function(t,r){e.dispatch("custom",{data:{errorDetails:r,errorType:t},event:"error"})},M=function(t){e.dispatch("custom",{data:{session:t},event:"init"})},L=function(){e.listen("auth",(function(e){var t=e.payload,r=t.data;switch(t.event){case"completeNewPassword_failure":case"forgotPassword_failure":case"forgotPasswordSubmit_failure":case"signIn_failure":case"signOut_failure":P({requestStatus:"failed"});break;case"signIn":I(r.signInUserSession);break;case"signOut":P({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})}})),e.listen("custom",(function(e){if("error"===e.payload.event)"loading"===A("requestStatus")&&P({requestStatus:"failed"})}))};!function(e){e.COMPLETE_PASSWORD_RESET="completePasswordReset",e.FORCE_PASSWORD_CHANGE="forcePasswordChange",e.GET_AUTHORIZATION_TOKEN="getAuthorizationToken",e.GET_USER_SESSION="getUserSession",e.INIT="init",e.REQUEST_PASSWORD_RESET="requestPasswordReset",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"}(y||(y={})),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||(E={})),function(e){e.EMAIL="EMAIL",e.NONE="NONE",e.SMS="SMS",e.TOTP="TOTP"}(S||(S={})),function(e){e.EXAMS_OFFICER="examsOfficer",e.HEAD_TEACHER="headTeacher",e.TEACHER="teacher"}(b||(b={})),function(e){e.ENGLISH="english",e.MATHS="maths",e.SCIENCE="science"}(_||(_={}));var U=function(e,r){return function(){var n;if(A("isInitialized")){for(var o=arguments.length,a=new Array(o),i=0;i<o;i++)a[i]=arguments[i];(n=e.call.apply(e,[t].concat(a)))instanceof Promise&&n.catch((function(e){R(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}},k=function(e,t){return e.then((function(){return P({requestStatus:"done"}),!0})).catch((function(e){return(e instanceof Error||"string"==typeof e)&&R(t,e),!1}))},C=function(e){return"object"===p(e)&&Object.hasOwn(e,"name")&&"NotAuthorizedException"===e.name},j=function(e){return"object"===p(e)&&Object.hasOwn(e,"name")&&"InvalidPasswordException"===e.name},D=function(e){return Object.entries(e).reduce((function(e,t){var r=g(t,2),o=r[0],a=r[1];return f(f({},e),{},m({},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(e)}}(o),a))}),{})},F=function(){var e=h(l().mark((function e(r){var n,o;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=A("mfaType"),e.next=3,W(E.VERIFY_TELEPHONE_NUMBER,r,{currentMfaType:n});case 3:return o=e.sent,t.verifyCurrentUserAttribute("phone_number"),n===S.SMS&&T(S.EMAIL).then((function(){P({mfaType:S.EMAIL})})),x(o),e.abrupt("return",o);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),G=function(e){return function(){var r=h(l().mark((function r(n){var o,a,i;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return P({requestStatus:"loading"}),r.next=3,t.completeNewPassword(e,n).catch((function(e){C(e)||j(e)||R(y.FORCE_PASSWORD_CHANGE,e),o=!1}));case 3:if(!(a=r.sent)){r.next=12;break}if(!a.challengeName){r.next=10;break}return r.next=8,W(a.challengeName,a,a.challengeParam);case 8:i=r.sent,x(i);case 10:P({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)}}()},q=function(e){return function(r){return P({requestStatus:"loading"}),k(t.sendCustomChallengeAnswer(e,r),y.SUBMIT_MFA_CODE)}},V=function(e){return function(){var r=h(l().mark((function r(n){var o;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return P({requestStatus:"loading"}),r.next=3,k(t.verifyCurrentUserAttributeSubmit("phone_number",n),y.VERIFY_TELEPHONE_NUMBER);case 3:return(o=r.sent)&&(P({telephoneNumberVerified:!0}),A("mfaType")!==S.SMS&&e===S.SMS&&T(S.SMS).then((function(){P({mfaType:S.SMS})}))),r.abrupt("return",o);case 6:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},W=function(e,t){var r,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=z(e,null==n?void 0:n.selectedMfaType);switch(o){case E.EMAIL_MFA:r={challengeType:E.EMAIL_MFA,completeChallenge:q(t),emailAddress:n.emailAddress};break;case E.NEW_PASSWORD_REQUIRED:r={challengeType:E.NEW_PASSWORD_REQUIRED,completeChallenge:G(t)};break;case E.SMS_MFA:r={challengeType:o,completeChallenge:q(t),telephoneNumber:e===E.CUSTOM_CHALLENGE?n.redactedPhoneNumber:n.CODE_DELIVERY_DESTINATION};break;case E.TOTP_MFA:r={challengeType:o,completeChallenge:q(t)};break;case E.VERIFY_TELEPHONE_NUMBER:r={challengeType:o,completeChallenge:V(n.currentMfaType)}}return r},z=function(e,t){if(e===E.CUSTOM_CHALLENGE)switch(t){case S.EMAIL:return E.EMAIL_MFA;case S.SMS:return E.SMS_MFA;case S.TOTP:return E.TOTP_MFA}return e},H=!1,Y=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.amplifyConfig,n=t.oAuthConfig,s=t.onChallenge,f=t.onCompletePasswordReset,l=t.onError,p=t.onInit,d=t.onRequestPasswordReset,h=t.onSignIn,m=t.onSignOut,v=t.usersEndpoint,E=i(Date.now()),S=g(E,2);S[0];var b=S[1],_=u(!1);return c((function(){var t=!1,r=e.listen("auth",(function(e){var r=e.payload,n=r.data,a=r.event;if(!t)switch(a){case"completeNewPassword_failure":o(l)&&l(y.FORCE_PASSWORD_CHANGE,n);break;case"forgotPassword":o(d)&&d(n.username);break;case"forgotPassword_failure":o(l)&&l(y.REQUEST_PASSWORD_RESET,n);break;case"forgotPasswordSubmit":o(f)&&f();break;case"forgotPasswordSubmit_failure":o(l)&&l(y.COMPLETE_PASSWORD_RESET,n);break;case"signIn":o(h)&&h(n.signInUserSession);break;case"signIn_failure":o(l)&&l(y.SIGN_IN,n);break;case"signOut":o(m)&&m()}})),n=e.listen("custom",(function(e){var r=e.payload,n=r.data,a=r.event;if(!t)switch(a){case"cacheUpdated":b(n.updatedTimestamp);break;case"challenge":o(s)&&s(n.challenge);break;case"error":o(l)&&l(n.errorType,n.errorDetails);break;case"init":o(p)&&p(n.session)}}));return function(){t=!0,r(),n()}}),[s,f,l,p,d,h,m]),c((function(){if(r||n||v){try{K(r,n,v),_.current=!0,H=!0}catch(e){o(l)&&l(y.INIT)}H&&!_.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,v]),ne},B=U((function(e,r,n){return P({requestStatus:"loading"}),k(t.forgotPasswordSubmit(e,r,n),y.COMPLETE_PASSWORD_RESET)}),y.COMPLETE_PASSWORD_RESET),J=U(h(l().mark((function e(){var t,r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Q();case 2:return t=e.sent,r=t.getIdToken().getJwtToken(),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e)}))),y.GET_AUTHORIZATION_TOKEN),Q=U(h(l().mark((function e(){var r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.currentSession();case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)}))),y.GET_USER_SESSION),K=function(){var e=h(l().mark((function e(n,o,i){var u;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!A("isInitialized")){e.next=4;break}a("WJEC One Authorization: Config cannot be changed after initialization - the config that was originally provided will continue to be used"),e.next=22;break;case 4:if(n&&o&&i){e.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 e.prev=8,r.configure(n),t.configure({oauth:o}),P({isInitialized:!0,usersEndpoint:i}),L(),e.next=15,t.currentAuthenticatedUser({bypassCache:!0}).then((function(e){var t=e.getSignInUserSession();return I(t),t})).catch((function(){}));case 15:u=e.sent,M(u),e.next=22;break;case 19:e.prev=19,e.t0=e.catch(8),R(y.INIT,e.t0);case 22:return e.abrupt("return",u);case 23:case"end":return e.stop()}}),e,null,[[8,19]])})));return function(t,r,n){return e.apply(this,arguments)}}(),Z=U((function(e){return P({requestStatus:"loading"}),k(t.forgotPassword(e),y.REQUEST_PASSWORD_RESET)}),y.REQUEST_PASSWORD_RESET),X=U(function(){var e=h(l().mark((function e(t){var r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return P({requestStatus:"loading"}),e.next=3,T(t);case 3:r=e.sent,P(r?{mfaType:t,requestStatus:"done"}:{requestStatus:"failed"});case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),y.SET_MFA_TYPE),$=U(function(){var e=h(l().mark((function e(r,n){var o,a;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return P({requestStatus:"loading"}),e.next=3,t.signIn(r,n).catch((function(e){C(e)||R(y.SIGN_IN,e)}));case 3:if(!(a=e.sent)){e.next=11;break}if(!a.challengeName){e.next=10;break}return e.next=8,W(a.challengeName,a,a.challengeParam);case 8:o=e.sent,x(o);case 10:P({requestStatus:"done"});case 11:return e.abrupt("return",{challenge:o,user:a});case 12:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}(),y.SIGN_IN),ee=U((function(){return P({requestStatus:"loading"}),k(t.signOut(),y.SIGN_OUT)}),y.SIGN_OUT),te=U(function(){var e=h(l().mark((function e(r){var n,o,a,i,u,c;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=A("telephoneNumber"),a=A("telephoneNumberVerified"),P({requestStatus:"loading"}),e.next=5,t.currentAuthenticatedUser();case 5:return i=e.sent,e.next=8,k(t.updateUserAttributes(i,D(r)),y.UPDATE_USER_ATTRIBUTES);case 8:if(!(u=e.sent)){e.next=17;break}if(P(r),!Object.hasOwn(r,"telephoneNumber")){e.next=17;break}if(c=r.telephoneNumber,o===c&&a){e.next=17;break}return e.next=16,F(i);case 16:n=e.sent;case 17:return e.abrupt("return",{challenge:n,success:u});case 18:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),y.UPDATE_USER_ATTRIBUTES),re=U(function(){var e=h(l().mark((function e(t){var r,n;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return P({requestStatus:"loading"}),r=f(f({},A("preferences")),t),e.next=4,N(r);case 4:n=e.sent,P(n?{preferences:r,requestStatus:"done"}:{requestStatus:"failed"});case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),y.UPDATE_USER_PREFERENCES),ne=Object.freeze({get centrePermissions(){return A("centrePermissions")},get emailAddress(){return A("emailAddress")},get emailAddressVerified(){return A("emailAddressVerified")},get familyName(){return A("familyName")},get fullName(){return A("fullName")},get givenName(){return A("givenName")},get groups(){return A("groups")},get id(){return A("id")},get isInitialized(){return A("isInitialized")},get isSignedIn(){return A("isSignedIn")},get languagePreference(){return A("languagePreference")},get mfaType(){return A("mfaType")},get middleName(){return A("middleName")},get preferences(){return A("preferences")},get requestStatus(){return A("requestStatus")},get telephoneNumber(){return A("telephoneNumber")},get telephoneNumberVerified(){return A("telephoneNumberVerified")},get totpVerified(){return A("totpVerified")}});export{y as AuthAction,E as ChallengeType,S as MFAType,b as Role,_ as Subject,B as completePasswordReset,J as getAuthorizationToken,Q as getUserSession,K as init,Z as requestPasswordReset,X as setMfaType,$ as signIn,ee as signOut,ne as state,te as updateUserAttributes,re as updateUserPreferences,Y as useAuthorization};
|
|
1
|
+
import{Hub as e,Auth as t,Amplify as r}from"aws-amplify";import{assertNever as n,isCallableFunction as a,developerWarning as o}from"../utils";import{useState as i,useRef as u,useEffect as c}from"react";function s(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 f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?s(Object(r),!0).forEach((function(t){m(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function l(){l=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},a="function"==typeof Symbol?Symbol:{},o=a.iterator||"@@iterator",i=a.asyncIterator||"@@asyncIterator",u=a.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function s(e,t,r,a){var o=t&&t.prototype instanceof d?t:d,i=Object.create(o.prototype),u=new N(a||[]);return n(i,"_invoke",{value:_(e,r,u)}),i}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var p={};function d(){}function h(){}function m(){}var E={};c(E,o,(function(){return this}));var g=Object.getPrototypeOf,v=g&&g(g(A([])));v&&v!==t&&r.call(v,o)&&(E=v);var y=m.prototype=d.prototype=Object.create(E);function S(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function T(e,t){function a(n,o,i,u){var c=f(e[n],e,o);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&r.call(l,"__await")?t.resolve(l.__await).then((function(e){a("next",e,i,u)}),(function(e){a("throw",e,i,u)})):t.resolve(l).then((function(e){s.value=e,i(s)}),(function(e){return a("throw",e,i,u)}))}u(c.arg)}var o;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){a(e,r,t,n)}))}return o=o?o.then(n,n):n()}})}function _(e,t,r){var n="suspendedStart";return function(a,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw o;return P()}for(r.method=a,r.arg=o;;){var i=r.delegate;if(i){var u=b(i,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function b(e,t){var r=e.iterator[t.method];if(void 0===r){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 n=f(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,p;var a=n.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 w(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 O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function N(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function A(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 n=-1,a=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],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 h.prototype=m,n(y,"constructor",{value:m,configurable:!0}),n(m,"constructor",{value:h,configurable:!0}),h.displayName=c(m,u,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,c(e,u,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},S(T.prototype),c(T.prototype,i,(function(){return this})),e.AsyncIterator=T,e.async=function(t,r,n,a,o){void 0===o&&(o=Promise);var i=new T(s(t,r,n,a),o);return e.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},S(y),c(y,u,"Generator"),c(y,o,(function(){return this})),c(y,"toString",(function(){return"[object Generator]"})),e.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}},e.values=A,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(O),!e)for(var t in this)"t"===t.charAt(0)&&r.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 n(r,n){return i.type="throw",i.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],i=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var u=r.call(o,"catchLoc"),c=r.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n];if(a.tryLoc<=this.prev&&r.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 r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),O(r),p}},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;O(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:A(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},e}function p(e){return p="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},p(e)}function d(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 h(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var o=e.apply(t,r);function i(e){d(o,n,a,i,u,"next",e)}function u(e){d(o,n,a,i,u,"throw",e)}i(void 0)}))}}function m(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function E(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)return;var n,a,o=[],i=!0,u=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);i=!0);}catch(e){u=!0,a=e}finally{try{i||null==r.return||r.return()}finally{if(u)throw a}}return o}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return g(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return g(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 g(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var v,y,S,T,_,b=function(t){e.dispatch("custom",{data:{challenge:t},event:"challenge"})},w=function(t,r){e.dispatch("custom",{data:{errorDetails:r,errorType:t},event:"error"})},O=function(t){e.dispatch("custom",{data:{session:t},event:"init"})},N=function(){var e=h(l().mark((function e(){var r,n,a;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.currentSession();case 2:return r=e.sent,n=r.getIdToken(),e.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=e.sent,e.abrupt("return",a);case 8:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),A=function(){var e=h(l().mark((function e(){var r,n,a;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.currentSession();case 2:return r=e.sent,n=r.getIdToken(),e.next=6,fetch("".concat(z("usersEndpoint")).concat(n.payload.sub,"/preferences"),{headers:{Authorization:n.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)}}(),P=function(){var e=h(l().mark((function e(r){var n,a,o;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.currentSession();case 2:return n=e.sent,a=n.getIdToken(),e.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=e.sent,e.abrupt("return",o);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),I=function(){var e=h(l().mark((function e(r){var n,a,o;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.currentSession();case 2:return n=e.sent,a=n.getIdToken(),e.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=e.sent,e.abrupt("return",o);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),R=function(){var e=h(l().mark((function e(r){var n,a,o;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.currentSession();case 2:return n=e.sent,a=n.getIdToken(),e.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=e.sent,e.abrupt("return",o);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();!function(e){e.COMPLETE_PASSWORD_RESET="completePasswordReset",e.FORCE_PASSWORD_CHANGE="forcePasswordChange",e.GET_AUTHORIZATION_TOKEN="getAuthorizationToken",e.GET_USER_PREFERENCES="getUserPreferences",e.GET_USER_SESSION="getUserSession",e.INIT="init",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"}(v||(v={})),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"}(y||(y={})),function(e){e.EMAIL="EMAIL",e.NONE="NONE",e.SMS="SMS",e.TOTP="TOTP"}(S||(S={})),function(e){e.EXAMS_OFFICER="examsOfficer",e.HEAD_TEACHER="headTeacher",e.TEACHER="teacher"}(T||(T={})),function(e){e.ENGLISH="english",e.MATHS="maths",e.SCIENCE="science"}(_||(_={}));var x=function(e){return function(){var r=h(l().mark((function r(n){var a,o,i;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return H({requestStatus:"loading"}),r.next=3,t.completeNewPassword(e,n).catch((function(e){D(e)||q(e)||w(v.FORCE_PASSWORD_CHANGE,e),a=!1}));case 3:if(!(o=r.sent)){r.next=12;break}if(!o.challengeName){r.next=10;break}return r.next=8,L(o.challengeName,o,o.challengeParam);case 8:i=r.sent,b(i);case 10:H({requestStatus:"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)}}()},k=function(e){return function(r){return H({requestStatus:"loading"}),j(t.sendCustomChallengeAnswer(e,r),v.SUBMIT_MFA_CODE)}},M=function(e){return function(){var r=h(l().mark((function r(n){var a;return l().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return H({requestStatus:"loading"}),r.next=3,j(t.verifyCurrentUserAttributeSubmit("phone_number",n),v.VERIFY_TELEPHONE_NUMBER);case 3:return(a=r.sent)&&(H({telephoneNumberVerified:!0}),z("mfaType")!==S.SMS&&e===S.SMS&&P(S.SMS).then((function(){H({mfaType:S.SMS})}))),r.abrupt("return",a);case 6:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},U=function(){return function(){var e=h(l().mark((function e(t){var r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ue(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)}}()},L=function(e,t){var r,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=C(e,null==n?void 0:n.selectedMfaType);switch(a){case y.EMAIL_MFA:r={challengeType:y.EMAIL_MFA,completeChallenge:k(t),emailAddress:n.emailAddress};break;case y.NEW_PASSWORD_REQUIRED:r={challengeType:y.NEW_PASSWORD_REQUIRED,completeChallenge:x(t)};break;case y.SMS_MFA:r={challengeType:a,completeChallenge:k(t),telephoneNumber:e===y.CUSTOM_CHALLENGE?n.redactedPhoneNumber:n.CODE_DELIVERY_DESTINATION};break;case y.TOTP_MFA:r={challengeType:a,completeChallenge:k(t)};break;case y.VERIFY_TELEPHONE_NUMBER:r={challengeType:a,completeChallenge:M(n.currentMfaType)};break;case y.VERIFY_TOTP_TOKEN:r={challengeType:a,completeChallenge:U(),secretKey:n.secretKey}}return r},C=function(e,t){if(e===y.CUSTOM_CHALLENGE)switch(t){case S.EMAIL:return y.EMAIL_MFA;case S.SMS:return y.SMS_MFA;case S.TOTP:return y.TOTP_MFA}return e},F=function(e,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=e.call.apply(e,[t].concat(o)))instanceof Promise&&n.catch((function(e){w(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}},j=function(e,t){return e.then((function(){return H({requestStatus:"done"}),!0})).catch((function(e){return(e instanceof Error||"string"==typeof e)&&w(t,e),!1}))},D=function(e){return"object"===p(e)&&Object.hasOwn(e,"name")&&"NotAuthorizedException"===e.name},q=function(e){return"object"===p(e)&&Object.hasOwn(e,"name")&&"InvalidPasswordException"===e.name},V=function(e){return Object.entries(e).reduce((function(e,t){var r=E(t,2),a=r[0],o=r[1];return f(f({},e),{},m({},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(e)}}(a),o))}),{})},G=function(){var e=h(l().mark((function e(r){var n,a;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=z("mfaType"),e.next=3,L(y.VERIFY_TELEPHONE_NUMBER,r,{currentMfaType:n});case 3:return a=e.sent,t.verifyCurrentUserAttribute("phone_number"),n===S.SMS&&P(S.EMAIL).then((function(){H({mfaType:S.EMAIL})})),b(a),e.abrupt("return",a);case 8:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),W={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},z=function(e){return W[e]},H=function(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];Object.entries(t).forEach((function(e){var t=E(e,2),r=t[0],n=t[1];W[r]=n})),r&&e.dispatch("custom",{data:{updatedTimestamp:Date.now()},event:"cacheUpdated"})},Y=function(){var e=h(l().mark((function e(t){var r,n,a;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.getIdToken().payload,H({requestStatus:"loading"}),e.next=4,A().then((function(e){return H({requestStatus:"done"}),e})).catch((function(e){return w(v.GET_USER_PREFERENCES,e),H({requestStatus:"failed"}),{}}));case 4:a=e.sent,H({centrePermissions:JSON.parse(n["custom:centre_permissions"]||"{}"),emailAddress:n.email,emailAddressVerified:n.email_verified,familyName:n.family_name||n.familyName,fullName:n.name,givenName:n.given_name||n.givenName,groups:n["cognito:groups"]||[],id:n.sub,isSignedIn:!0,languagePreference:n["custom:language_preference"],mfaType:n["custom:mfa_type"],middleName:n.middle_name||n.middleName,preferences:(o=a,f(f({},o),{},{emailMfaAccepted:o.emailMfaAccepted?new Date(o.emailMfaAccepted):void 0})),telephoneNumber:n.phone_number,telephoneNumberVerified:n.phone_number_verified,totpVerified:"true"===(null===(r=n["custom:totp_verified"])||void 0===r?void 0:r.toLowerCase())});case 6:case"end":return e.stop()}var o}),e)})));return function(t){return e.apply(this,arguments)}}(),K=function(){H({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})},J=!1,B=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.amplifyConfig,n=t.oAuthConfig,s=t.onChallenge,f=t.onCompletePasswordReset,l=t.onError,p=t.onInit,d=t.onRequestPasswordReset,h=t.onSignIn,m=t.onSignOut,g=t.usersEndpoint,y=i(Date.now()),S=E(y,2);S[0];var T=S[1],_=u(!1);return c((function(){var t=!1,r=e.listen("auth",(function(e){var r=e.payload,n=r.data,o=r.event;if(!t)switch(o){case"completeNewPassword_failure":a(l)&&l(v.FORCE_PASSWORD_CHANGE,n);break;case"forgotPassword":a(d)&&d(n.username);break;case"forgotPassword_failure":a(l)&&l(v.REQUEST_PASSWORD_RESET,n);break;case"forgotPasswordSubmit":a(f)&&f();break;case"forgotPasswordSubmit_failure":a(l)&&l(v.COMPLETE_PASSWORD_RESET,n);break;case"signIn":a(h)&&h(n.signInUserSession);break;case"signIn_failure":a(l)&&l(v.SIGN_IN,n);break;case"signOut":a(m)&&m()}})),n=e.listen("custom",(function(e){var r=e.payload,n=r.data,o=r.event;if(!t)switch(o){case"cacheUpdated":T(n.updatedTimestamp);break;case"challenge":a(s)&&s(n.challenge);break;case"error":a(l)&&l(n.errorType,n.errorDetails);break;case"init":a(p)&&p(n.session)}}));return function(){t=!0,r(),n()}}),[s,f,l,p,d,h,m]),c((function(){if(r||n||g){try{$(r,n,g),_.current=!0,J=!0}catch(e){a(l)&&l(v.INIT)}J&&!_.current&&o("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,g]),ce},Q=F((function(e,r,n){return H({requestStatus:"loading"}),j(t.forgotPasswordSubmit(e,r,n),v.COMPLETE_PASSWORD_RESET)}),v.COMPLETE_PASSWORD_RESET),Z=F(h(l().mark((function e(){var t,r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,X();case 2:return t=e.sent,r=t.getIdToken().getJwtToken(),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e)}))),v.GET_AUTHORIZATION_TOKEN),X=F(h(l().mark((function e(){var r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.currentSession();case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)}))),v.GET_USER_SESSION),$=function(){var n=h(l().mark((function n(a,i,u){var c;return l().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!z("isInitialized")){n.next=4;break}o("WJEC One Authorization: Config cannot be changed after initialization - the config that was originally provided will continue to be used"),n.next=22;break;case 4:if(a&&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(a),t.configure({oauth:i}),H({isInitialized:!0,usersEndpoint:u}),e.listen("auth",(function(e){var t=e.payload,r=t.data;switch(t.event){case"completeNewPassword_failure":case"forgotPassword_failure":case"forgotPasswordSubmit_failure":case"signIn_failure":case"signOut_failure":H({requestStatus:"failed"});break;case"signIn":Y(r.signInUserSession);break;case"signOut":K()}})),e.listen("custom",(function(e){"error"===e.payload.event&&"loading"===z("requestStatus")&&H({requestStatus:"failed"})})),n.next=15,t.currentAuthenticatedUser({bypassCache:!0}).then((function(e){var t=e.getSignInUserSession();return Y(t),t})).catch((function(){}));case 15:c=n.sent,O(c),n.next=22;break;case 19:n.prev=19,n.t0=n.catch(8),w(v.INIT,n.t0);case 22:return n.abrupt("return",c);case 23:case"end":return n.stop()}}),n,null,[[8,19]])})));return function(e,t,r){return n.apply(this,arguments)}}(),ee=F((function(e){return H({requestStatus:"loading"}),j(t.forgotPassword(e),v.REQUEST_PASSWORD_RESET)}),v.REQUEST_PASSWORD_RESET),te=F(function(){var e=h(l().mark((function e(t){var r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return H({requestStatus:"loading"}),e.next=3,P(t).catch((function(e){return w(v.SET_MFA_TYPE,e),H({requestStatus:"failed"}),!1}));case 3:return(r=e.sent)&&(H({mfaType:t,requestStatus:"done"}),t!==S.EMAIL&&I({emailMfaAccepted:void 0})),e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),v.SET_MFA_TYPE),re=F(h(l().mark((function e(){var r,n,a;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.currentAuthenticatedUser();case 2:return n=e.sent,H({requestStatus:"loading"}),e.next=6,N().catch((function(e){w(v.REQUEST_TOTP_TOKEN,e),H({requestStatus:"failed"})}));case 6:if(!(a=e.sent)){e.next=13;break}return e.next=10,L(y.VERIFY_TOTP_TOKEN,n,{secretKey:a});case 10:r=e.sent,b(r),H({requestStatus:"done"});case 13:return e.abrupt("return",{challenge:r,secretKey:a});case 14:case"end":return e.stop()}}),e)}))),v.REQUEST_TOTP_TOKEN),ne=F(function(){var e=h(l().mark((function e(r,n){var a,o;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return H({requestStatus:"loading"}),e.next=3,t.signIn(r,n).catch((function(e){D(e)||w(v.SIGN_IN,e)}));case 3:if(!(o=e.sent)){e.next=11;break}if(!o.challengeName){e.next=10;break}return e.next=8,L(o.challengeName,o,o.challengeParam);case 8:a=e.sent,b(a);case 10:H({requestStatus:"done"});case 11:return e.abrupt("return",{challenge:a,user:o});case 12:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}(),v.SIGN_IN),ae=F((function(){return H({requestStatus:"loading"}),j(t.signOut(),v.SIGN_OUT)}),v.SIGN_OUT),oe=F(function(){var e=h(l().mark((function e(r){var n,a,o,i,u,c;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=z("telephoneNumber"),o=z("telephoneNumberVerified"),H({requestStatus:"loading"}),e.next=5,t.currentAuthenticatedUser();case 5:return i=e.sent,e.next=8,j(t.updateUserAttributes(i,V(r)),v.UPDATE_USER_ATTRIBUTES);case 8:if(!(u=e.sent)){e.next=17;break}if(H(r),!Object.hasOwn(r,"telephoneNumber")){e.next=17;break}if(c=r.telephoneNumber,a===c&&o){e.next=17;break}return e.next=16,G(i);case 16:n=e.sent;case 17:return e.abrupt("return",{challenge:n,success:u});case 18:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),v.UPDATE_USER_ATTRIBUTES),ie=F(function(){var e=h(l().mark((function e(t){var r,n;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return H({requestStatus:"loading"}),r=f(f({},z("preferences")),t),e.next=4,I(r).catch((function(e){return w(v.UPDATE_USER_PREFERENCES,e),H({requestStatus:"failed"}),!1}));case 4:return(n=e.sent)&&H({preferences:r,requestStatus:"done"}),e.abrupt("return",n);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),v.UPDATE_USER_PREFERENCES),ue=F(function(){var e=h(l().mark((function e(t){var r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return H({requestStatus:"loading"}),e.next=3,R(t).catch((function(e){return w(v.VERIFY_TOTP_TOKEN,e),H({requestStatus:"failed"}),!1}));case 3:return(r=e.sent)&&H({requestStatus:"done"}),e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),v.VERIFY_TOTP_TOKEN),ce=Object.freeze({get centrePermissions(){return z("centrePermissions")},get emailAddress(){return z("emailAddress")},get emailAddressVerified(){return z("emailAddressVerified")},get familyName(){return z("familyName")},get fullName(){return z("fullName")},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 requestStatus(){return z("requestStatus")},get telephoneNumber(){return z("telephoneNumber")},get telephoneNumberVerified(){return z("telephoneNumberVerified")},get totpVerified(){return z("totpVerified")}});export{v as AuthAction,y as ChallengeType,S as MFAType,T as Role,_ as Subject,Q as completePasswordReset,Z as getAuthorizationToken,X as getUserSession,$ as init,ee as requestPasswordReset,te as setMfaType,re as setupTotp,ne as signIn,ae as signOut,ce as state,oe as updateUserAttributes,ie as updateUserPreferences,B as useAuthorization,ue as verifyTotp};
|
package/package.json
CHANGED
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})})),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(e){var t=e.getSignInUserSession();return V(t),t})).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=13;break}return n.next=10,I(e.ChallengeType.VERIFY_TOTP_TOKEN,a,{secretKey:o});case 10:r=n.sent,E(r),D({requestStatus:"done"});case 13:return n.abrupt("return",{challenge:r,secretKey:o});case 14: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}));
|
package/umd/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom/server"),require("immutable")):"function"==typeof define&&define.amd?define(["exports","react","react-dom/server","immutable"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WJECOneUtils={},e.React,e.ReactDOMServer,e.Immutable)}(this,(function(e,t,n,r){"use strict";function o(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 i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){u(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function a(e){return a="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},a(e)}function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}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,o,i=[],a=!0,u=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(u)throw o}}return i}(e,t)||f(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 d(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||f(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 f(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}function d(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 m=["a[href]","button","details","input",'[tabIndex]:not([tabIndex="-1"])',"textArea","select","summary"].map((function(e){return"".concat(e,":not([disabled])")})),p={expiration:2592e6,path:"/"},y=["date","format"],v=["January","February","March","April","May","June","July","August","September","October","November","December"],g="dd/MM/yyyy",b="HH:mm",h=function(e){var t=e.date,n=e.format,r=void 0===n?g:n,o=t.getDate(),i=t.getMonth()+1,a=t.getFullYear().toString();return r.replace(/dd/,o.toString().padStart(2,"0")).replace(/d/,o.toString()).replace(/MMM/,v[i-1].substr(0,3)).replace(/MM/,i.toString().padStart(2,"0")).replace(/M/,i.toString()).replace(/yyyy/,a).replace(/yy/,a.substr(2))},S=function(e){var t=e.date,n=e.format,r=void 0===n?b:n,o=e.meridianStrings,i=void 0===o?{am:"am",pm:"pm"}:o,a=/h{1,2}/.test(r),u=a?t.getHours()%12||12:t.getHours();return r.replace(/HH/i,u.toString().padStart(2,"0")).replace(/H/i,u.toString()).replace(/mm/,t.getMinutes().toString().padStart(2,"0")).replace(/SS/,t.getSeconds().toString().padStart(2,"0")).replace(/AM/,a?t.getHours()<12?i.am:i.pm:"")},O=function(e){return new Date(new Date(e).setHours(0,0,0,0))},w=function(e){return"[object Date]"===Object.prototype.toString.call(e)},j=function(e){return"function"==typeof e},D=function(e){return"object"===a(e)&&2===Object.keys(e).length&&Object.hasOwn(e,"key")&&Object.hasOwn(e,"label")},A=function(e){return["boolean","number","string"].includes(a(e))},E=function(e){var t=n.renderToStaticMarkup(e);return/^<svg(.*)<\/svg>$/i.test(t)},M=function(e){var t=e.container,n=void 0===t?document.body:t,r=e.modifyContainer,o=void 0===r?function(){return null}:r,i=e.modifyNode,a=void 0===i?function(){return null}:i,u=e.node,c=document.createElement("div"),l=u.cloneNode(!0);o(c),a(l),c.style.display="inline-block",c.style.position="absolute",c.style.visibility="hidden",c.style.zIndex="-1",c.appendChild(l),n.appendChild(c);var s=c.clientHeight,f=c.clientWidth;return c.parentNode.removeChild(c),{height:s,width:f}},T=function(e){console.error(e)},I=function(e){console.warn(e)},x=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=process.env.NODE_ENV;"development"===n&&t&&T(e)},k=new Uint32Array(2),C=function(e){return"[object Object]"===Object.prototype.toString.call(e)},P=function(e){var t=[];return{addListener:function(n){if(!function(e){return t.find((function(t){return t.listener===e}))}(n)){var r=function(e){return n(e.data)};t.push({listener:n,remove:function(){return e.removeEventListener("message",r)}}),e.addEventListener("message",r)}},removeListener:function(e){var n=t.findIndex((function(t){return t.listener===e})),r=t.splice(n,1)[0];r&&r.remove()}}};e.DAYS=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],e.MONTHS=v,e.assertNever=function(e){throw new Error("Unexpected object: ".concat(e))},e.containsDuplicates=function(e){return new Set(e).size!==e.length},e.createWebWorker=function(e){return e(i(i({},P(self)),{},{postMessage:function(e){return self.postMessage(e,void 0)}})),{path:""}},e.debounce=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:250;return function(){for(var r=arguments.length,o=new Array(r),i=0;i<r;i++)o[i]=arguments[i];self.clearTimeout(t),t=self.setTimeout((function(){e.apply(void 0,o)}),n)}},e.decrementDate=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.amount,r=void 0===n?1:n,o=t.unit,i=void 0===o?"day":o,a=new Date(e);return"year"===i?a.setFullYear(e.getFullYear()-r):"month"===i?a.setMonth(e.getMonth()-r):a.setDate(e.getDate()-r),a},e.developerError=x,e.developerWarning=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=process.env.NODE_ENV;"development"===n&&t&&I(e)},e.extractContent=function(e,t,n){var r=e;return t&&("function"==typeof t?r=t(e,n):"string"==typeof t&&"object"===a(e)&&Object.hasOwn(e,t)&&(r=e[t])),r},e.extractKey=function(e,t,n){var r=e&&e.toString();if(t)if("function"==typeof t)r=t(e,n);else if("string"==typeof t&&"object"===a(e)&&Object.hasOwn(e,t)){var o=e[t];r="number"==typeof o?o:o.toString()}return r},e.filterValidEntries=function(e){return e.filter((function(e){return e&&null!=e}))},e.findScrollableParent=function(e,t){var n,r=getComputedStyle(e),o=t?/(auto|scroll|hidden)/:/(auto|scroll)/,i="absolute"===r.position;return n="fixed"===r.position||e.parentElement===document.documentElement?document.documentElement:function e(t){var n=getComputedStyle(t);return(!(i=i&&"static"===n.position)||"static"!==n.position)&&o.test(n.overflow+n.overflowY+n.overflowX)||"fixed"===n.position?t:t.parentElement===document.documentElement?document.documentElement:e(t.parentElement)}(e.parentElement),n},e.formatDate=h,e.formatDateTime=function(e){var t=e.date,n=e.format,r=void 0===n?"".concat(g," ").concat(b):n,o=c(e,y),a=S(i(i({},o),{},{date:t,format:r}));return h(i(i({},o),{},{date:t,format:a}))},e.formatTime=S,e.formattedStringToPlainText=function(e){var n=[];return function e(r){var o;o=r,t.isValidElement(o)?t.Children.forEach(r.props.children,e):n.push(null==r?void 0:r.toString())}(e),n.join("")},e.generateId=function(){return crypto.getRandomValues(k).join("-")},e.getCookie=function(e){var t=decodeURIComponent(document.cookie).split(";").map((function(e){return e.trim()})).find((function(t){return 0===t.indexOf(e)}));return t&&t.substring(e.length+1)},e.getDateAtStartOfDay=O,e.getDateAtStartOfMonth=function(e){return O(new Date(new Date(e).setDate(1)))},e.getEnumKeyByValue=function(e,t){return Object.keys(e).find((function(n){return e[n]===t}))},e.getKeyboardFocusableElements=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.documentElement;return Array.from(e.querySelectorAll(m.join(","))).filter((function(e){return!e.hasAttribute("disabled")&&!e.getAttribute("aria-hidden")}))},e.getNumberOfDaysForMonth=function(e){return new Date(e.getFullYear(),e.getMonth()+1,0).getDate()},e.getSelected=function(e,t){return e&&t.includes(e)?e:t.length?t[0]:void 0},e.incrementDate=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.amount,r=void 0===n?1:n,o=t.unit,i=void 0===o?"day":o,a=new Date(e);return"year"===i?a.setFullYear(e.getFullYear()+r):"month"===i?a.setMonth(e.getMonth()+r):a.setDate(e.getDate()+r),a},e.initialiseWebWorker=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new Worker(e),r=P(n);return t.onError&&"function"==typeof t.onError&&(n.onerror=t.onError),i(i({},r),{},{postMessage:function(e){return n.postMessage(e,void 0)},terminate:n.terminate})},e.isArrayEqual=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return e.length===t.length&&e.every((function(e,r){return n?t[r]===e:t.includes(e)}))},e.isCallableFunction=j,e.isDate=w,e.isKeyLabelPair=D,e.isKeyLabelPairArray=function(e){return Array.isArray(e)&&e.every(D)},e.isPlainObject=C,e.isPrimitive=A,e.isPrimitiveArray=function(e){return Array.isArray(e)&&e.every(A)},e.isRefObject=function(e){return Object.hasOwn(e,"current")},e.isSvgComponent=E,e.measureDomNode=M,e.measureScrollbarWidth=function(){var e=document.createElement("div"),t=M({node:e}).width;return M({node:e,modifyNode:function(e){return e.style.overflowY="scroll"}}).width-t},e.noop=function(){},e.objectToString=function e(t){var n=t&&Object.keys(t).map((function(n){var r=t[n],o=null!==r&&"object"===a(r)?w(r)?'"'.concat(r.toISOString(),'"'):e(r):null!=r?"string"==typeof r?'"'.concat(r,'"'):r.toString():null===r?"null":"undefined";return Array.isArray(t)?o:"".concat(n,":").concat(o)})).join(",");return n?Array.isArray(t)?"[".concat(n,"]"):"{".concat(n,"}"):""},e.parseDateString=function(e){var t,n,r,o,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=i.format,u=i.shorthand,c=void 0===u||u,s=e&&e.trim(),f="UK"===a||!a&&(c?/^(0|1|2|3)?[0-9]\/(0|1)?[0-9]\/\d{2,4}$/.test(s):/^(0|1|2|3)[0-9]\/(0|1)[0-9]\/\d{4}$/.test(s)),d="US"===a||!a&&(c?/^(0|1)?[0-9]\/(0|1|2|3)?[0-9]\/\d{2,4}$/.test(s):/^(0|1)[0-9]\/(0|1|2|3)[0-9]\/\d{4}$/.test(s)),m=f?"dd/MM/yyyy":"MM/dd/yyyy";if(f){var p=s.split("/").map((function(e){return parseInt(e)})),y=l(p,3);n=y[0],r=y[1],o=y[2]}else if(d){var v=s.split("/").map((function(e){return parseInt(e)})),g=l(v,3);r=g[0],n=g[1],o=g[2]}if(n&&r&&o&&[2,4].includes(o.toString().length)){if(2===o.toString().length){var b=(new Date).getFullYear(),S=100*Math.floor(b/100),O=b-S;o=O<25&&o>49?S-100+o:O>75&&o<50?S+100+o:S+o}t=new Date(o,r-1,n)}var w=m.replace("dd",n&&n.toString().padStart(2,"0")).replace("MM",r&&r.toString().padStart(2,"0")).replace("yyyy",o&&o.toString());return t&&h({date:t,format:m})===w?t:void 0},e.parseTimeString=function(e){var t=l(e&&e.trim().match(/(\d+):(\d+)\s{0,}(am|pm)?/i),4);t[0];var n=t[1],r=t[2],o=t[3],i=void 0!==o;return{hour:parseInt(n)%(i?12:24),meridian:o?o.toLowerCase():void 0,minute:parseInt(r)}},e.preventDefaultBehavior=function(e){return e.preventDefault(),e.stopPropagation(),!1},e.saveBlobAsFile=function(e,t){if(self.navigator&&self.navigator.msSaveBlob)self.navigator.msSaveBlob(e,t);else{var n=document.createElement("a"),r=URL.createObjectURL(e);n.href=r,n.download=t,document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(r)}},e.setCookie=function(e,t,n){var r=i(i({},p),n),o=r.expiration,a=r.path,u=new Date;u.setTime(u.getTime()+o),document.cookie="".concat(e,"=").concat(t||"",";expires=").concat(u.toUTCString(),";path=").concat(a)},e.setInSafely=function(e,t,n){return t.slice(0,t.length).reduce((function(e,o,i){var a=l(e,2),u=a[0],c=a[1],f=[].concat(s(c),[o]);return i===t.length-1?[u.setIn(f,n),f]:u.getIn(f)?[u,f]:[u.setIn(f,r.Map([])),f]}),[e,[]])[0]},e.smoothScroll=function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.duration,o=void 0===r?500:r,i=n.element,a=void 0===i?document.documentElement:i,u=n.left,c=void 0===u?0:u,l=n.top,s=void 0===l?0:l,f=a===document.documentElement?window:a,d=c-a.scrollLeft,m=s-a.scrollTop,p=function n(r){var i=r-t,a=d*(i/o),u=m*(i/o);e||(e=r),r-e>=o?f.scrollTo(c,s):(f.scrollBy(a,u),t=r,requestAnimationFrame(n))};0===d&&0===m||requestAnimationFrame(p)},e.stripKeys=function e(t,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o=t;return C(t)&&(n.forEach((function(e){delete o[e]})),r&&(o=Object.keys(o).reduce((function(t,r){return i(i({},t),{},u({},r,e(o[r],n)))}),{}))),Array.isArray(t)&&(o=t.map((function(t){return e(t,n,r)}))),o},e.svgComponentToDataURL=function(e){if(!E(e))throw new Error("Only a component that returns SVG markup can be converted to a dataURL");return"url('data:image/svg+xml,".concat(encodeURIComponent(n.renderToStaticMarkup(e)),"')")},e.throttle=function(e){var t,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:500},o=r.beforeDelay,i=r.limit,a=void 0===i?500:i;return function(){for(var r=arguments.length,i=new Array(r),u=0;u<r;u++)i[u]=arguments[u];n?(self.clearTimeout(t),j(o)&&o.apply(void 0,i),t=self.setTimeout((function(){Date.now()-n>=a&&(e.apply(void 0,i),n=Date.now())}),a-(Date.now()-n))):(e.apply(void 0,i),n=Date.now())}},e.transparentize=function(e,t){var n="#"===e.charAt(0),r="rgb"===e.substr(0,3);if(!n&&!r||!("number"==typeof t&&t>=0&&t<=1))return x("\n StyleUtils.transparentize only supports colors in hexadecimal or rgb(a) format.\n The desired transparency must be a value between 0 and 1\n "),e;var o,i=t;n?o=(e.length>6?e.substr(1).match(/.{1,2}/g):e.substr(1).match(/./g)).map((function(e){return parseInt("".concat(e).concat(1===e.length?e:""),16)})):o=e.match(/\d+(\.?\d+)?/g).map(parseFloat);if(void 0!==o[3]){var a=r?o[3]:o[3]/255;i=a-a*t}return"rgba(".concat(o.slice(0,3).join(","),",").concat(Math.round(100*i)/100,")")}}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom/server"),require("immutable")):"function"==typeof define&&define.amd?define(["exports","react","react-dom/server","immutable"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WJECOneUtils={},e.React,e.ReactDOMServer,e.Immutable)}(this,(function(e,t,n,r){"use strict";function o(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 i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){u(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function a(e){return a="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},a(e)}function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}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,o,i=[],a=!0,u=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(u)throw o}}return i}(e,t)||f(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 d(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||f(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 f(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}function d(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 m=["a[href]","button","details","input",'[tabIndex]:not([tabIndex="-1"])',"textArea","select","summary"].map((function(e){return"".concat(e,":not([disabled])")})),p={expiration:2592e6,path:"/"},y=function(e,t,n){var r=i(i({},p),n),o=r.expiration,a=r.path,u=new Date;u.setTime(u.getTime()+o),document.cookie="".concat(e,"=").concat(t||"",";expires=").concat(u.toUTCString(),";path=").concat(a)},v=["date","format"],g=["January","February","March","April","May","June","July","August","September","October","November","December"],b="dd/MM/yyyy",h="HH:mm",S=function(e){var t=e.date,n=e.format,r=void 0===n?b:n,o=t.getDate(),i=t.getMonth()+1,a=t.getFullYear().toString();return r.replace(/dd/,o.toString().padStart(2,"0")).replace(/d/,o.toString()).replace(/MMM/,g[i-1].substr(0,3)).replace(/MM/,i.toString().padStart(2,"0")).replace(/M/,i.toString()).replace(/yyyy/,a).replace(/yy/,a.substr(2))},O=function(e){var t=e.date,n=e.format,r=void 0===n?h:n,o=e.meridianStrings,i=void 0===o?{am:"am",pm:"pm"}:o,a=/h{1,2}/.test(r),u=a?t.getHours()%12||12:t.getHours();return r.replace(/HH/i,u.toString().padStart(2,"0")).replace(/H/i,u.toString()).replace(/mm/,t.getMinutes().toString().padStart(2,"0")).replace(/SS/,t.getSeconds().toString().padStart(2,"0")).replace(/AM/,a?t.getHours()<12?i.am:i.pm:"")},w=function(e){return new Date(new Date(e).setHours(0,0,0,0))},j=function(e){return"[object Date]"===Object.prototype.toString.call(e)},D=function(e){return"function"==typeof e},A=function(e){return"object"===a(e)&&2===Object.keys(e).length&&Object.hasOwn(e,"key")&&Object.hasOwn(e,"label")},E=function(e){return["boolean","number","string"].includes(a(e))},M=function(e){var t=n.renderToStaticMarkup(e);return/^<svg(.*)<\/svg>$/i.test(t)},T=function(e){var t=e.container,n=void 0===t?document.body:t,r=e.modifyContainer,o=void 0===r?function(){return null}:r,i=e.modifyNode,a=void 0===i?function(){return null}:i,u=e.node,c=document.createElement("div"),l=u.cloneNode(!0);o(c),a(l),c.style.display="inline-block",c.style.position="absolute",c.style.visibility="hidden",c.style.zIndex="-1",c.appendChild(l),n.appendChild(c);var s=c.clientHeight,f=c.clientWidth;return c.parentNode.removeChild(c),{height:s,width:f}},x=function(e){console.error(e)},I=function(e){console.warn(e)},k=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=process.env.NODE_ENV;"development"===n&&t&&x(e)},C=new Uint32Array(2),P=function(e){return"[object Object]"===Object.prototype.toString.call(e)},F=function(e){var t=[];return{addListener:function(n){if(!function(e){return t.find((function(t){return t.listener===e}))}(n)){var r=function(e){return n(e.data)};t.push({listener:n,remove:function(){return e.removeEventListener("message",r)}}),e.addEventListener("message",r)}},removeListener:function(e){var n=t.findIndex((function(t){return t.listener===e})),r=t.splice(n,1)[0];r&&r.remove()}}};e.DAYS=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],e.MONTHS=g,e.assertNever=function(e){throw new Error("Unexpected object: ".concat(e))},e.containsDuplicates=function(e){return new Set(e).size!==e.length},e.createWebWorker=function(e){return e(i(i({},F(self)),{},{postMessage:function(e){return self.postMessage(e,void 0)}})),{path:""}},e.debounce=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:250;return function(){for(var r=arguments.length,o=new Array(r),i=0;i<r;i++)o[i]=arguments[i];self.clearTimeout(t),t=self.setTimeout((function(){e.apply(void 0,o)}),n)}},e.decrementDate=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.amount,r=void 0===n?1:n,o=t.unit,i=void 0===o?"day":o,a=new Date(e);return"year"===i?a.setFullYear(e.getFullYear()-r):"month"===i?a.setMonth(e.getMonth()-r):a.setDate(e.getDate()-r),a},e.developerError=k,e.developerWarning=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=process.env.NODE_ENV;"development"===n&&t&&I(e)},e.extractContent=function(e,t,n){var r=e;return t&&("function"==typeof t?r=t(e,n):"string"==typeof t&&"object"===a(e)&&Object.hasOwn(e,t)&&(r=e[t])),r},e.extractKey=function(e,t,n){var r=e&&e.toString();if(t)if("function"==typeof t)r=t(e,n);else if("string"==typeof t&&"object"===a(e)&&Object.hasOwn(e,t)){var o=e[t];r="number"==typeof o?o:o.toString()}return r},e.filterValidEntries=function(e){return e.filter((function(e){return e&&null!=e}))},e.findScrollableParent=function(e,t){var n,r=getComputedStyle(e),o=t?/(auto|scroll|hidden)/:/(auto|scroll)/,i="absolute"===r.position;return n="fixed"===r.position||e.parentElement===document.documentElement?document.documentElement:function e(t){var n=getComputedStyle(t);return(!(i=i&&"static"===n.position)||"static"!==n.position)&&o.test(n.overflow+n.overflowY+n.overflowX)||"fixed"===n.position?t:t.parentElement===document.documentElement?document.documentElement:e(t.parentElement)}(e.parentElement),n},e.formatDate=S,e.formatDateTime=function(e){var t=e.date,n=e.format,r=void 0===n?"".concat(b," ").concat(h):n,o=c(e,v),a=O(i(i({},o),{},{date:t,format:r}));return S(i(i({},o),{},{date:t,format:a}))},e.formatTime=O,e.formattedStringToPlainText=function(e){var n=[];return function e(r){var o;o=r,t.isValidElement(o)?t.Children.forEach(r.props.children,e):n.push(null==r?void 0:r.toString())}(e),n.join("")},e.generateId=function(){return crypto.getRandomValues(C).join("-")},e.getCookie=function(e){var t=decodeURIComponent(document.cookie).split(";").map((function(e){return e.trim()})).find((function(t){return 0===t.indexOf(e)}));return t&&t.substring(e.length+1)},e.getDateAtStartOfDay=w,e.getDateAtStartOfMonth=function(e){return w(new Date(new Date(e).setDate(1)))},e.getEnumKeyByValue=function(e,t){return Object.keys(e).find((function(n){return e[n]===t}))},e.getKeyboardFocusableElements=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.documentElement;return Array.from(e.querySelectorAll(m.join(","))).filter((function(e){return!e.hasAttribute("disabled")&&!e.getAttribute("aria-hidden")}))},e.getNumberOfDaysForMonth=function(e){return new Date(e.getFullYear(),e.getMonth()+1,0).getDate()},e.getSelected=function(e,t){return e&&t.includes(e)?e:t.length?t[0]:void 0},e.incrementDate=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.amount,r=void 0===n?1:n,o=t.unit,i=void 0===o?"day":o,a=new Date(e);return"year"===i?a.setFullYear(e.getFullYear()+r):"month"===i?a.setMonth(e.getMonth()+r):a.setDate(e.getDate()+r),a},e.initialiseWebWorker=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new Worker(e),r=F(n);return t.onError&&"function"==typeof t.onError&&(n.onerror=t.onError),i(i({},r),{},{postMessage:function(e){return n.postMessage(e,void 0)},terminate:n.terminate})},e.isArrayEqual=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return e.length===t.length&&e.every((function(e,r){return n?t[r]===e:t.includes(e)}))},e.isCallableFunction=D,e.isDate=j,e.isKeyLabelPair=A,e.isKeyLabelPairArray=function(e){return Array.isArray(e)&&e.every(A)},e.isPlainObject=P,e.isPrimitive=E,e.isPrimitiveArray=function(e){return Array.isArray(e)&&e.every(E)},e.isRefObject=function(e){return Object.hasOwn(e,"current")},e.isSvgComponent=M,e.measureDomNode=T,e.measureScrollbarWidth=function(){var e=document.createElement("div"),t=T({node:e}).width;return T({node:e,modifyNode:function(e){return e.style.overflowY="scroll"}}).width-t},e.noop=function(){},e.objectToString=function e(t){var n=t&&Object.keys(t).map((function(n){var r=t[n],o=null!==r&&"object"===a(r)?j(r)?'"'.concat(r.toISOString(),'"'):e(r):null!=r?"string"==typeof r?'"'.concat(r,'"'):r.toString():null===r?"null":"undefined";return Array.isArray(t)?o:"".concat(n,":").concat(o)})).join(",");return n?Array.isArray(t)?"[".concat(n,"]"):"{".concat(n,"}"):""},e.parseDateString=function(e){var t,n,r,o,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=i.format,u=i.shorthand,c=void 0===u||u,s=e&&e.trim(),f="UK"===a||!a&&(c?/^(0|1|2|3)?[0-9]\/(0|1)?[0-9]\/\d{2,4}$/.test(s):/^(0|1|2|3)[0-9]\/(0|1)[0-9]\/\d{4}$/.test(s)),d="US"===a||!a&&(c?/^(0|1)?[0-9]\/(0|1|2|3)?[0-9]\/\d{2,4}$/.test(s):/^(0|1)[0-9]\/(0|1|2|3)[0-9]\/\d{4}$/.test(s)),m=f?"dd/MM/yyyy":"MM/dd/yyyy";if(f){var p=s.split("/").map((function(e){return parseInt(e)})),y=l(p,3);n=y[0],r=y[1],o=y[2]}else if(d){var v=s.split("/").map((function(e){return parseInt(e)})),g=l(v,3);r=g[0],n=g[1],o=g[2]}if(n&&r&&o&&[2,4].includes(o.toString().length)){if(2===o.toString().length){var b=(new Date).getFullYear(),h=100*Math.floor(b/100),O=b-h;o=O<25&&o>49?h-100+o:O>75&&o<50?h+100+o:h+o}t=new Date(o,r-1,n)}var w=m.replace("dd",n&&n.toString().padStart(2,"0")).replace("MM",r&&r.toString().padStart(2,"0")).replace("yyyy",o&&o.toString());return t&&S({date:t,format:m})===w?t:void 0},e.parseTimeString=function(e){var t=l(e&&e.trim().match(/(\d+):(\d+)\s{0,}(am|pm)?/i),4);t[0];var n=t[1],r=t[2],o=t[3],i=void 0!==o;return{hour:parseInt(n)%(i?12:24),meridian:o?o.toLowerCase():void 0,minute:parseInt(r)}},e.preventDefaultBehavior=function(e){return e.preventDefault(),e.stopPropagation(),!1},e.removeCookie=function(e){y(e,void 0,{expiration:-1})},e.saveBlobAsFile=function(e,t){if(self.navigator&&self.navigator.msSaveBlob)self.navigator.msSaveBlob(e,t);else{var n=document.createElement("a"),r=URL.createObjectURL(e);n.href=r,n.download=t,document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(r)}},e.setCookie=y,e.setInSafely=function(e,t,n){return t.slice(0,t.length).reduce((function(e,o,i){var a=l(e,2),u=a[0],c=a[1],f=[].concat(s(c),[o]);return i===t.length-1?[u.setIn(f,n),f]:u.getIn(f)?[u,f]:[u.setIn(f,r.Map([])),f]}),[e,[]])[0]},e.smoothScroll=function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.duration,o=void 0===r?500:r,i=n.element,a=void 0===i?document.documentElement:i,u=n.left,c=void 0===u?0:u,l=n.top,s=void 0===l?0:l,f=a===document.documentElement?window:a,d=c-a.scrollLeft,m=s-a.scrollTop,p=function n(r){var i=r-t,a=d*(i/o),u=m*(i/o);e||(e=r),r-e>=o?f.scrollTo(c,s):(f.scrollBy(a,u),t=r,requestAnimationFrame(n))};0===d&&0===m||requestAnimationFrame(p)},e.stripKeys=function e(t,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o=t;return P(t)&&(n.forEach((function(e){delete o[e]})),r&&(o=Object.keys(o).reduce((function(t,r){return i(i({},t),{},u({},r,e(o[r],n)))}),{}))),Array.isArray(t)&&(o=t.map((function(t){return e(t,n,r)}))),o},e.svgComponentToDataURL=function(e){if(!M(e))throw new Error("Only a component that returns SVG markup can be converted to a dataURL");return"url('data:image/svg+xml,".concat(encodeURIComponent(n.renderToStaticMarkup(e)),"')")},e.throttle=function(e){var t,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:500},o=r.beforeDelay,i=r.limit,a=void 0===i?500:i;return function(){for(var r=arguments.length,i=new Array(r),u=0;u<r;u++)i[u]=arguments[u];n?(self.clearTimeout(t),D(o)&&o.apply(void 0,i),t=self.setTimeout((function(){Date.now()-n>=a&&(e.apply(void 0,i),n=Date.now())}),a-(Date.now()-n))):(e.apply(void 0,i),n=Date.now())}},e.transparentize=function(e,t){var n="#"===e.charAt(0),r="rgb"===e.substr(0,3);if(!n&&!r||!("number"==typeof t&&t>=0&&t<=1))return k("\n StyleUtils.transparentize only supports colors in hexadecimal or rgb(a) format.\n The desired transparency must be a value between 0 and 1\n "),e;var o,i=t;n?o=(e.length>6?e.substr(1).match(/.{1,2}/g):e.substr(1).match(/./g)).map((function(e){return parseInt("".concat(e).concat(1===e.length?e:""),16)})):o=e.match(/\d+(\.?\d+)?/g).map(parseFloat);if(void 0!==o[3]){var a=r?o[3]:o[3]/255;i=a-a*t}return"rgba(".concat(o.slice(0,3).join(","),",").concat(Math.round(100*i)/100,")")}}));
|
package/utils/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare type CookieOptions = {
|
|
|
8
8
|
expiration?: number;
|
|
9
9
|
path?: string;
|
|
10
10
|
};
|
|
11
|
+
declare const removeCookie: (name: string) => void;
|
|
11
12
|
declare const setCookie: (name: string, value: string, options?: CookieOptions) => void;
|
|
12
13
|
declare type SmoothScrollOptions = {
|
|
13
14
|
duration?: number;
|
|
@@ -170,4 +171,4 @@ declare const initialiseWebWorker: <T extends WebWorkerFile<any, any>>(workerFil
|
|
|
170
171
|
onError?: Worker['onerror'];
|
|
171
172
|
}) => WebWorker<ExtractWebWorkerProps<T>, ExtractWebWorkerResponse<T>>;
|
|
172
173
|
|
|
173
|
-
export { ContentExtractor, DAYS, ImportExists, KeyExtractor, KeyLabelPair, MONTHS, SVGComponent, Time, WebWorker, WebWorkerFile, assertNever, containsDuplicates, createWebWorker, debounce, decrementDate, developerError, developerWarning, extractContent, extractKey, filterValidEntries, findScrollableParent, formatDate, formatDateTime, formatTime, formattedStringToPlainText, generateId, getCookie, getDateAtStartOfDay, getDateAtStartOfMonth, getEnumKeyByValue, getKeyboardFocusableElements, getNumberOfDaysForMonth, getSelected, incrementDate, initialiseWebWorker, isArrayEqual, isCallableFunction, isDate, isKeyLabelPair, isKeyLabelPairArray, isPlainObject, isPrimitive, isPrimitiveArray, isRefObject, isSvgComponent, measureDomNode, measureScrollbarWidth, noop, objectToString, parseDateString, parseTimeString, preventDefaultBehavior, saveBlobAsFile, setCookie, setInSafely, smoothScroll, stripKeys, svgComponentToDataURL, throttle, transparentize };
|
|
174
|
+
export { ContentExtractor, DAYS, ImportExists, KeyExtractor, KeyLabelPair, MONTHS, SVGComponent, Time, WebWorker, WebWorkerFile, assertNever, containsDuplicates, createWebWorker, debounce, decrementDate, developerError, developerWarning, extractContent, extractKey, filterValidEntries, findScrollableParent, formatDate, formatDateTime, formatTime, formattedStringToPlainText, generateId, getCookie, getDateAtStartOfDay, getDateAtStartOfMonth, getEnumKeyByValue, getKeyboardFocusableElements, getNumberOfDaysForMonth, getSelected, incrementDate, initialiseWebWorker, isArrayEqual, isCallableFunction, isDate, isKeyLabelPair, isKeyLabelPairArray, isPlainObject, isPrimitive, isPrimitiveArray, isRefObject, isSvgComponent, measureDomNode, measureScrollbarWidth, noop, objectToString, parseDateString, parseTimeString, preventDefaultBehavior, removeCookie, saveBlobAsFile, setCookie, setInSafely, smoothScroll, stripKeys, svgComponentToDataURL, throttle, transparentize };
|
package/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"react";import{renderToStaticMarkup as e}from"react-dom/server";import{Map as n}from"immutable";function r(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function o(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?r(Object(n),!0).forEach((function(e){a(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function a(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},i=Object.keys(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}function c(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==n)return;var r,o,i=[],a=!0,u=!1;try{for(n=n.call(t);!(a=(r=n.next()).done)&&(i.push(r.value),!e||i.length!==e);a=!0);}catch(t){u=!0,o=t}finally{try{a||null==n.return||n.return()}finally{if(u)throw o}}return i}(t,e)||f(t,e)||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 l(t){return function(t){if(Array.isArray(t))return d(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||f(t)||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 f(t,e){if(t){if("string"==typeof t)return d(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(t,e):void 0}}function d(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var s=function(t){var e=decodeURIComponent(document.cookie).split(";").map((function(t){return t.trim()})).find((function(e){return 0===e.indexOf(t)}));return e&&e.substring(t.length+1)},m=["a[href]","button","details","input",'[tabIndex]:not([tabIndex="-1"])',"textArea","select","summary"].map((function(t){return"".concat(t,":not([disabled])")})),p=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.documentElement;return Array.from(t.querySelectorAll(m.join(","))).filter((function(t){return!t.hasAttribute("disabled")&&!t.getAttribute("aria-hidden")}))},y={expiration:2592e6,path:"/"},v=function(t,e,n){var r=o(o({},y),n),i=r.expiration,a=r.path,u=new Date;u.setTime(u.getTime()+i),document.cookie="".concat(t,"=").concat(e||"",";expires=").concat(u.toUTCString(),";path=").concat(a)},g=function(){var t,e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.duration,o=void 0===r?500:r,i=n.element,a=void 0===i?document.documentElement:i,u=n.left,c=void 0===u?0:u,l=n.top,f=void 0===l?0:l,d=a===document.documentElement?window:a,s=c-a.scrollLeft,m=f-a.scrollTop,p=function n(r){var i=r-e,a=s*(i/o),u=m*(i/o);t||(t=r),r-t>=o?d.scrollTo(c,f):(d.scrollBy(a,u),e=r,requestAnimationFrame(n))};0===s&&0===m||requestAnimationFrame(p)},b=["date","format"],h=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],S=["January","February","March","April","May","June","July","August","September","October","November","December"],w=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.amount,r=void 0===n?1:n,o=e.unit,i=void 0===o?"day":o,a=new Date(t);return"year"===i?a.setFullYear(t.getFullYear()-r):"month"===i?a.setMonth(t.getMonth()-r):a.setDate(t.getDate()-r),a},O=function(t){var e=t.date,n=t.format,r=void 0===n?"dd/MM/yyyy":n,o=e.getDate(),i=e.getMonth()+1,a=e.getFullYear().toString();return r.replace(/dd/,o.toString().padStart(2,"0")).replace(/d/,o.toString()).replace(/MMM/,S[i-1].substr(0,3)).replace(/MM/,i.toString().padStart(2,"0")).replace(/M/,i.toString()).replace(/yyyy/,a).replace(/yy/,a.substr(2))},j=function(t){var e=t.date,n=t.format,r=void 0===n?"HH:mm":n,o=t.meridianStrings,i=void 0===o?{am:"am",pm:"pm"}:o,a=/h{1,2}/.test(r),u=a?e.getHours()%12||12:e.getHours();return r.replace(/HH/i,u.toString().padStart(2,"0")).replace(/H/i,u.toString()).replace(/mm/,e.getMinutes().toString().padStart(2,"0")).replace(/SS/,e.getSeconds().toString().padStart(2,"0")).replace(/AM/,a?e.getHours()<12?i.am:i.pm:"")},M=function(t){var e=t.date,n=t.format,r=void 0===n?"".concat("dd/MM/yyyy"," ").concat("HH:mm"):n,i=u(t,b),a=j(o(o({},i),{},{date:e,format:r}));return O(o(o({},i),{},{date:e,format:a}))},A=function(t){return new Date(new Date(t).setHours(0,0,0,0))},E=function(t){return A(new Date(new Date(t).setDate(1)))},D=function(t){return new Date(t.getFullYear(),t.getMonth()+1,0).getDate()},I=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.amount,r=void 0===n?1:n,o=e.unit,i=void 0===o?"day":o,a=new Date(t);return"year"===i?a.setFullYear(t.getFullYear()+r):"month"===i?a.setMonth(t.getMonth()+r):a.setDate(t.getDate()+r),a},x=function(t){return"[object Date]"===Object.prototype.toString.call(t)},k=function(t){var e,n,r,o,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=i.format,u=i.shorthand,l=void 0===u||u,f=t&&t.trim(),d="UK"===a||!a&&(l?/^(0|1|2|3)?[0-9]\/(0|1)?[0-9]\/\d{2,4}$/.test(f):/^(0|1|2|3)[0-9]\/(0|1)[0-9]\/\d{4}$/.test(f)),s="US"===a||!a&&(l?/^(0|1)?[0-9]\/(0|1|2|3)?[0-9]\/\d{2,4}$/.test(f):/^(0|1)[0-9]\/(0|1|2|3)[0-9]\/\d{4}$/.test(f)),m=d?"dd/MM/yyyy":"MM/dd/yyyy";if(d){var p=f.split("/").map((function(t){return parseInt(t)})),y=c(p,3);n=y[0],r=y[1],o=y[2]}else if(s){var v=f.split("/").map((function(t){return parseInt(t)})),g=c(v,3);r=g[0],n=g[1],o=g[2]}if(n&&r&&o&&[2,4].includes(o.toString().length)){if(2===o.toString().length){var b=(new Date).getFullYear(),h=100*Math.floor(b/100),S=b-h;o=S<25&&o>49?h-100+o:S>75&&o<50?h+100+o:h+o}e=new Date(o,r-1,n)}var w=m.replace("dd",n&&n.toString().padStart(2,"0")).replace("MM",r&&r.toString().padStart(2,"0")).replace("yyyy",o&&o.toString());return e&&O({date:e,format:m})===w?e:void 0},T=function(t){var e=c(t&&t.trim().match(/(\d+):(\d+)\s{0,}(am|pm)?/i),4);e[0];var n=e[1],r=e[2],o=e[3],i=void 0!==o;return{hour:parseInt(n)%(i?12:24),meridian:o?o.toLowerCase():void 0,minute:parseInt(r)}},U=function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:250;return function(){for(var r=arguments.length,o=new Array(r),i=0;i<r;i++)o[i]=arguments[i];self.clearTimeout(e),e=self.setTimeout((function(){t.apply(void 0,o)}),n)}},C=function(t,e,n){var r=t&&t.toString();if(e)if("function"==typeof e)r=e(t,n);else if("string"==typeof e&&"object"===i(t)&&Object.hasOwn(t,e)){var o=t[e];r="number"==typeof o?o:o.toString()}return r},F=function(t,e,n){var r=t;return e&&("function"==typeof e?r=e(t,n):"string"==typeof e&&"object"===i(t)&&Object.hasOwn(t,e)&&(r=t[e])),r},H=function(t,e){var n,r=getComputedStyle(t),o=e?/(auto|scroll|hidden)/:/(auto|scroll)/,i="absolute"===r.position;return n="fixed"===r.position||t.parentElement===document.documentElement?document.documentElement:function t(e){var n=getComputedStyle(e);return(!(i=i&&"static"===n.position)||"static"!==n.position)&&o.test(n.overflow+n.overflowY+n.overflowX)||"fixed"===n.position?e:e.parentElement===document.documentElement?document.documentElement:t(e.parentElement)}(t.parentElement),n},P=function(e){var n=[];return function e(r){var o;o=r,t.isValidElement(o)?t.Children.forEach(r.props.children,e):n.push(null==r?void 0:r.toString())}(e),n.join("")},L=function(t,e){return t&&e.includes(t)?t:e.length?e[0]:void 0},N=function(t){return"function"==typeof t},Y=function(t){return"object"===i(t)&&2===Object.keys(t).length&&Object.hasOwn(t,"key")&&Object.hasOwn(t,"label")},R=function(t){return Array.isArray(t)&&t.every(Y)},$=function(t){return["boolean","number","string"].includes(i(t))},V=function(t){return Array.isArray(t)&&t.every($)},q=function(t){var n=e(t);return/^<svg(.*)<\/svg>$/i.test(n)},z=function(t){var e=t.container,n=void 0===e?document.body:e,r=t.modifyContainer,o=void 0===r?function(){return null}:r,i=t.modifyNode,a=void 0===i?function(){return null}:i,u=t.node,c=document.createElement("div"),l=u.cloneNode(!0);o(c),a(l),c.style.display="inline-block",c.style.position="absolute",c.style.visibility="hidden",c.style.zIndex="-1",c.appendChild(l),n.appendChild(c);var f=c.clientHeight,d=c.clientWidth;return c.parentNode.removeChild(c),{height:f,width:d}},B=function(){var t=document.createElement("div"),e=z({node:t}).width;return z({node:t,modifyNode:function(t){return t.style.overflowY="scroll"}}).width-e},J=function t(e){var n=e&&Object.keys(e).map((function(n){var r=e[n],o=null!==r&&"object"===i(r)?x(r)?'"'.concat(r.toISOString(),'"'):t(r):null!=r?"string"==typeof r?'"'.concat(r,'"'):r.toString():null===r?"null":"undefined";return Array.isArray(e)?o:"".concat(n,":").concat(o)})).join(",");return n?Array.isArray(e)?"[".concat(n,"]"):"{".concat(n,"}"):""},W=function(t){return t.preventDefault(),t.stopPropagation(),!1},_=function(t){if(!q(t))throw new Error("Only a component that returns SVG markup can be converted to a dataURL");return"url('data:image/svg+xml,".concat(encodeURIComponent(e(t)),"')")},G=function(t){var e,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:500},o=r.beforeDelay,i=r.limit,a=void 0===i?500:i;return function(){for(var r=arguments.length,i=new Array(r),u=0;u<r;u++)i[u]=arguments[u];n?(self.clearTimeout(e),N(o)&&o.apply(void 0,i),e=self.setTimeout((function(){Date.now()-n>=a&&(t.apply(void 0,i),n=Date.now())}),a-(Date.now()-n))):(t.apply(void 0,i),n=Date.now())}},K=function(t){console.error(t)},X=function(t){console.warn(t)},Q=function(t){throw new Error("Unexpected object: ".concat(t))},Z=function(t){return new Set(t).size!==t.length},tt=function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=process.env.NODE_ENV;"development"===n&&e&&K(t)},et=function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=process.env.NODE_ENV;"development"===n&&e&&X(t)},nt=function(t){return t.filter((function(t){return t&&null!=t}))},rt=new Uint32Array(2),ot=function(){return crypto.getRandomValues(rt).join("-")},it=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return t.length===e.length&&t.every((function(t,r){return n?e[r]===t:e.includes(t)}))},at=function(){},ut=function(t,e){return Object.keys(t).find((function(n){return t[n]===e}))},ct=function(t){return"[object Object]"===Object.prototype.toString.call(t)},lt=function(t){return Object.hasOwn(t,"current")},ft=function(t,e){if(self.navigator&&self.navigator.msSaveBlob)self.navigator.msSaveBlob(t,e);else{var n=document.createElement("a"),r=URL.createObjectURL(t);n.href=r,n.download=e,document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(r)}},dt=function t(e,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=e;return ct(e)&&(n.forEach((function(t){delete i[t]})),r&&(i=Object.keys(i).reduce((function(e,r){return o(o({},e),{},a({},r,t(i[r],n)))}),{}))),Array.isArray(e)&&(i=e.map((function(e){return t(e,n,r)}))),i},st=function(t,e,r){return e.slice(0,e.length).reduce((function(t,o,i){var a=c(t,2),u=a[0],f=a[1],d=[].concat(l(f),[o]);return i===e.length-1?[u.setIn(d,r),d]:u.getIn(d)?[u,d]:[u.setIn(d,n([])),d]}),[t,[]])[0]},mt=function(t,e){var n="#"===t.charAt(0),r="rgb"===t.substr(0,3);if(!n&&!r||!("number"==typeof e&&e>=0&&e<=1))return tt("\n StyleUtils.transparentize only supports colors in hexadecimal or rgb(a) format.\n The desired transparency must be a value between 0 and 1\n "),t;var o,i=e;n?o=(t.length>6?t.substr(1).match(/.{1,2}/g):t.substr(1).match(/./g)).map((function(t){return parseInt("".concat(t).concat(1===t.length?t:""),16)})):o=t.match(/\d+(\.?\d+)?/g).map(parseFloat);if(void 0!==o[3]){var a=r?o[3]:o[3]/255;i=a-a*e}return"rgba(".concat(o.slice(0,3).join(","),",").concat(Math.round(100*i)/100,")")},pt=function(t){var e=[];return{addListener:function(n){if(!function(t){return e.find((function(e){return e.listener===t}))}(n)){var r=function(t){return n(t.data)};e.push({listener:n,remove:function(){return t.removeEventListener("message",r)}}),t.addEventListener("message",r)}},removeListener:function(t){var n=e.findIndex((function(e){return e.listener===t})),r=e.splice(n,1)[0];r&&r.remove()}}},yt=function(t){return t(o(o({},pt(self)),{},{postMessage:function(t){return self.postMessage(t,void 0)}})),{path:""}},vt=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new Worker(t),r=pt(n);return e.onError&&"function"==typeof e.onError&&(n.onerror=e.onError),o(o({},r),{},{postMessage:function(t){return n.postMessage(t,void 0)},terminate:n.terminate})};export{h as DAYS,S as MONTHS,Q as assertNever,Z as containsDuplicates,yt as createWebWorker,U as debounce,w as decrementDate,tt as developerError,et as developerWarning,F as extractContent,C as extractKey,nt as filterValidEntries,H as findScrollableParent,O as formatDate,M as formatDateTime,j as formatTime,P as formattedStringToPlainText,ot as generateId,s as getCookie,A as getDateAtStartOfDay,E as getDateAtStartOfMonth,ut as getEnumKeyByValue,p as getKeyboardFocusableElements,D as getNumberOfDaysForMonth,L as getSelected,I as incrementDate,vt as initialiseWebWorker,it as isArrayEqual,N as isCallableFunction,x as isDate,Y as isKeyLabelPair,R as isKeyLabelPairArray,ct as isPlainObject,$ as isPrimitive,V as isPrimitiveArray,lt as isRefObject,q as isSvgComponent,z as measureDomNode,B as measureScrollbarWidth,at as noop,J as objectToString,k as parseDateString,T as parseTimeString,W as preventDefaultBehavior,ft as saveBlobAsFile,v as setCookie,st as setInSafely,g as smoothScroll,dt as stripKeys,_ as svgComponentToDataURL,G as throttle,mt as transparentize};
|
|
1
|
+
import t from"react";import{renderToStaticMarkup as e}from"react-dom/server";import{Map as n}from"immutable";function r(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function o(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?r(Object(n),!0).forEach((function(e){a(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function a(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},i=Object.keys(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}function c(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==n)return;var r,o,i=[],a=!0,u=!1;try{for(n=n.call(t);!(a=(r=n.next()).done)&&(i.push(r.value),!e||i.length!==e);a=!0);}catch(t){u=!0,o=t}finally{try{a||null==n.return||n.return()}finally{if(u)throw o}}return i}(t,e)||f(t,e)||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 l(t){return function(t){if(Array.isArray(t))return d(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||f(t)||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 f(t,e){if(t){if("string"==typeof t)return d(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(t,e):void 0}}function d(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var s=function(t){var e=decodeURIComponent(document.cookie).split(";").map((function(t){return t.trim()})).find((function(e){return 0===e.indexOf(t)}));return e&&e.substring(t.length+1)},m=["a[href]","button","details","input",'[tabIndex]:not([tabIndex="-1"])',"textArea","select","summary"].map((function(t){return"".concat(t,":not([disabled])")})),p=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.documentElement;return Array.from(t.querySelectorAll(m.join(","))).filter((function(t){return!t.hasAttribute("disabled")&&!t.getAttribute("aria-hidden")}))},y={expiration:2592e6,path:"/"},v=function(t){g(t,void 0,{expiration:-1})},g=function(t,e,n){var r=o(o({},y),n),i=r.expiration,a=r.path,u=new Date;u.setTime(u.getTime()+i),document.cookie="".concat(t,"=").concat(e||"",";expires=").concat(u.toUTCString(),";path=").concat(a)},b=function(){var t,e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=n.duration,o=void 0===r?500:r,i=n.element,a=void 0===i?document.documentElement:i,u=n.left,c=void 0===u?0:u,l=n.top,f=void 0===l?0:l,d=a===document.documentElement?window:a,s=c-a.scrollLeft,m=f-a.scrollTop,p=function n(r){var i=r-e,a=s*(i/o),u=m*(i/o);t||(t=r),r-t>=o?d.scrollTo(c,f):(d.scrollBy(a,u),e=r,requestAnimationFrame(n))};0===s&&0===m||requestAnimationFrame(p)},h=["date","format"],S=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],w=["January","February","March","April","May","June","July","August","September","October","November","December"],O=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.amount,r=void 0===n?1:n,o=e.unit,i=void 0===o?"day":o,a=new Date(t);return"year"===i?a.setFullYear(t.getFullYear()-r):"month"===i?a.setMonth(t.getMonth()-r):a.setDate(t.getDate()-r),a},j=function(t){var e=t.date,n=t.format,r=void 0===n?"dd/MM/yyyy":n,o=e.getDate(),i=e.getMonth()+1,a=e.getFullYear().toString();return r.replace(/dd/,o.toString().padStart(2,"0")).replace(/d/,o.toString()).replace(/MMM/,w[i-1].substr(0,3)).replace(/MM/,i.toString().padStart(2,"0")).replace(/M/,i.toString()).replace(/yyyy/,a).replace(/yy/,a.substr(2))},M=function(t){var e=t.date,n=t.format,r=void 0===n?"HH:mm":n,o=t.meridianStrings,i=void 0===o?{am:"am",pm:"pm"}:o,a=/h{1,2}/.test(r),u=a?e.getHours()%12||12:e.getHours();return r.replace(/HH/i,u.toString().padStart(2,"0")).replace(/H/i,u.toString()).replace(/mm/,e.getMinutes().toString().padStart(2,"0")).replace(/SS/,e.getSeconds().toString().padStart(2,"0")).replace(/AM/,a?e.getHours()<12?i.am:i.pm:"")},A=function(t){var e=t.date,n=t.format,r=void 0===n?"".concat("dd/MM/yyyy"," ").concat("HH:mm"):n,i=u(t,h),a=M(o(o({},i),{},{date:e,format:r}));return j(o(o({},i),{},{date:e,format:a}))},E=function(t){return new Date(new Date(t).setHours(0,0,0,0))},D=function(t){return E(new Date(new Date(t).setDate(1)))},I=function(t){return new Date(t.getFullYear(),t.getMonth()+1,0).getDate()},x=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.amount,r=void 0===n?1:n,o=e.unit,i=void 0===o?"day":o,a=new Date(t);return"year"===i?a.setFullYear(t.getFullYear()+r):"month"===i?a.setMonth(t.getMonth()+r):a.setDate(t.getDate()+r),a},k=function(t){return"[object Date]"===Object.prototype.toString.call(t)},T=function(t){var e,n,r,o,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=i.format,u=i.shorthand,l=void 0===u||u,f=t&&t.trim(),d="UK"===a||!a&&(l?/^(0|1|2|3)?[0-9]\/(0|1)?[0-9]\/\d{2,4}$/.test(f):/^(0|1|2|3)[0-9]\/(0|1)[0-9]\/\d{4}$/.test(f)),s="US"===a||!a&&(l?/^(0|1)?[0-9]\/(0|1|2|3)?[0-9]\/\d{2,4}$/.test(f):/^(0|1)[0-9]\/(0|1|2|3)[0-9]\/\d{4}$/.test(f)),m=d?"dd/MM/yyyy":"MM/dd/yyyy";if(d){var p=f.split("/").map((function(t){return parseInt(t)})),y=c(p,3);n=y[0],r=y[1],o=y[2]}else if(s){var v=f.split("/").map((function(t){return parseInt(t)})),g=c(v,3);r=g[0],n=g[1],o=g[2]}if(n&&r&&o&&[2,4].includes(o.toString().length)){if(2===o.toString().length){var b=(new Date).getFullYear(),h=100*Math.floor(b/100),S=b-h;o=S<25&&o>49?h-100+o:S>75&&o<50?h+100+o:h+o}e=new Date(o,r-1,n)}var w=m.replace("dd",n&&n.toString().padStart(2,"0")).replace("MM",r&&r.toString().padStart(2,"0")).replace("yyyy",o&&o.toString());return e&&j({date:e,format:m})===w?e:void 0},U=function(t){var e=c(t&&t.trim().match(/(\d+):(\d+)\s{0,}(am|pm)?/i),4);e[0];var n=e[1],r=e[2],o=e[3],i=void 0!==o;return{hour:parseInt(n)%(i?12:24),meridian:o?o.toLowerCase():void 0,minute:parseInt(r)}},C=function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:250;return function(){for(var r=arguments.length,o=new Array(r),i=0;i<r;i++)o[i]=arguments[i];self.clearTimeout(e),e=self.setTimeout((function(){t.apply(void 0,o)}),n)}},F=function(t,e,n){var r=t&&t.toString();if(e)if("function"==typeof e)r=e(t,n);else if("string"==typeof e&&"object"===i(t)&&Object.hasOwn(t,e)){var o=t[e];r="number"==typeof o?o:o.toString()}return r},H=function(t,e,n){var r=t;return e&&("function"==typeof e?r=e(t,n):"string"==typeof e&&"object"===i(t)&&Object.hasOwn(t,e)&&(r=t[e])),r},P=function(t,e){var n,r=getComputedStyle(t),o=e?/(auto|scroll|hidden)/:/(auto|scroll)/,i="absolute"===r.position;return n="fixed"===r.position||t.parentElement===document.documentElement?document.documentElement:function t(e){var n=getComputedStyle(e);return(!(i=i&&"static"===n.position)||"static"!==n.position)&&o.test(n.overflow+n.overflowY+n.overflowX)||"fixed"===n.position?e:e.parentElement===document.documentElement?document.documentElement:t(e.parentElement)}(t.parentElement),n},L=function(e){var n=[];return function e(r){var o;o=r,t.isValidElement(o)?t.Children.forEach(r.props.children,e):n.push(null==r?void 0:r.toString())}(e),n.join("")},N=function(t,e){return t&&e.includes(t)?t:e.length?e[0]:void 0},Y=function(t){return"function"==typeof t},R=function(t){return"object"===i(t)&&2===Object.keys(t).length&&Object.hasOwn(t,"key")&&Object.hasOwn(t,"label")},$=function(t){return Array.isArray(t)&&t.every(R)},V=function(t){return["boolean","number","string"].includes(i(t))},q=function(t){return Array.isArray(t)&&t.every(V)},z=function(t){var n=e(t);return/^<svg(.*)<\/svg>$/i.test(n)},B=function(t){var e=t.container,n=void 0===e?document.body:e,r=t.modifyContainer,o=void 0===r?function(){return null}:r,i=t.modifyNode,a=void 0===i?function(){return null}:i,u=t.node,c=document.createElement("div"),l=u.cloneNode(!0);o(c),a(l),c.style.display="inline-block",c.style.position="absolute",c.style.visibility="hidden",c.style.zIndex="-1",c.appendChild(l),n.appendChild(c);var f=c.clientHeight,d=c.clientWidth;return c.parentNode.removeChild(c),{height:f,width:d}},J=function(){var t=document.createElement("div"),e=B({node:t}).width;return B({node:t,modifyNode:function(t){return t.style.overflowY="scroll"}}).width-e},W=function t(e){var n=e&&Object.keys(e).map((function(n){var r=e[n],o=null!==r&&"object"===i(r)?k(r)?'"'.concat(r.toISOString(),'"'):t(r):null!=r?"string"==typeof r?'"'.concat(r,'"'):r.toString():null===r?"null":"undefined";return Array.isArray(e)?o:"".concat(n,":").concat(o)})).join(",");return n?Array.isArray(e)?"[".concat(n,"]"):"{".concat(n,"}"):""},_=function(t){return t.preventDefault(),t.stopPropagation(),!1},G=function(t){if(!z(t))throw new Error("Only a component that returns SVG markup can be converted to a dataURL");return"url('data:image/svg+xml,".concat(encodeURIComponent(e(t)),"')")},K=function(t){var e,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{limit:500},o=r.beforeDelay,i=r.limit,a=void 0===i?500:i;return function(){for(var r=arguments.length,i=new Array(r),u=0;u<r;u++)i[u]=arguments[u];n?(self.clearTimeout(e),Y(o)&&o.apply(void 0,i),e=self.setTimeout((function(){Date.now()-n>=a&&(t.apply(void 0,i),n=Date.now())}),a-(Date.now()-n))):(t.apply(void 0,i),n=Date.now())}},X=function(t){console.error(t)},Q=function(t){console.warn(t)},Z=function(t){throw new Error("Unexpected object: ".concat(t))},tt=function(t){return new Set(t).size!==t.length},et=function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=process.env.NODE_ENV;"development"===n&&e&&X(t)},nt=function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=process.env.NODE_ENV;"development"===n&&e&&Q(t)},rt=function(t){return t.filter((function(t){return t&&null!=t}))},ot=new Uint32Array(2),it=function(){return crypto.getRandomValues(ot).join("-")},at=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return t.length===e.length&&t.every((function(t,r){return n?e[r]===t:e.includes(t)}))},ut=function(){},ct=function(t,e){return Object.keys(t).find((function(n){return t[n]===e}))},lt=function(t){return"[object Object]"===Object.prototype.toString.call(t)},ft=function(t){return Object.hasOwn(t,"current")},dt=function(t,e){if(self.navigator&&self.navigator.msSaveBlob)self.navigator.msSaveBlob(t,e);else{var n=document.createElement("a"),r=URL.createObjectURL(t);n.href=r,n.download=e,document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(r)}},st=function t(e,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=e;return lt(e)&&(n.forEach((function(t){delete i[t]})),r&&(i=Object.keys(i).reduce((function(e,r){return o(o({},e),{},a({},r,t(i[r],n)))}),{}))),Array.isArray(e)&&(i=e.map((function(e){return t(e,n,r)}))),i},mt=function(t,e,r){return e.slice(0,e.length).reduce((function(t,o,i){var a=c(t,2),u=a[0],f=a[1],d=[].concat(l(f),[o]);return i===e.length-1?[u.setIn(d,r),d]:u.getIn(d)?[u,d]:[u.setIn(d,n([])),d]}),[t,[]])[0]},pt=function(t,e){var n="#"===t.charAt(0),r="rgb"===t.substr(0,3);if(!n&&!r||!("number"==typeof e&&e>=0&&e<=1))return et("\n StyleUtils.transparentize only supports colors in hexadecimal or rgb(a) format.\n The desired transparency must be a value between 0 and 1\n "),t;var o,i=e;n?o=(t.length>6?t.substr(1).match(/.{1,2}/g):t.substr(1).match(/./g)).map((function(t){return parseInt("".concat(t).concat(1===t.length?t:""),16)})):o=t.match(/\d+(\.?\d+)?/g).map(parseFloat);if(void 0!==o[3]){var a=r?o[3]:o[3]/255;i=a-a*e}return"rgba(".concat(o.slice(0,3).join(","),",").concat(Math.round(100*i)/100,")")},yt=function(t){var e=[];return{addListener:function(n){if(!function(t){return e.find((function(e){return e.listener===t}))}(n)){var r=function(t){return n(t.data)};e.push({listener:n,remove:function(){return t.removeEventListener("message",r)}}),t.addEventListener("message",r)}},removeListener:function(t){var n=e.findIndex((function(e){return e.listener===t})),r=e.splice(n,1)[0];r&&r.remove()}}},vt=function(t){return t(o(o({},yt(self)),{},{postMessage:function(t){return self.postMessage(t,void 0)}})),{path:""}},gt=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new Worker(t),r=yt(n);return e.onError&&"function"==typeof e.onError&&(n.onerror=e.onError),o(o({},r),{},{postMessage:function(t){return n.postMessage(t,void 0)},terminate:n.terminate})};export{S as DAYS,w as MONTHS,Z as assertNever,tt as containsDuplicates,vt as createWebWorker,C as debounce,O as decrementDate,et as developerError,nt as developerWarning,H as extractContent,F as extractKey,rt as filterValidEntries,P as findScrollableParent,j as formatDate,A as formatDateTime,M as formatTime,L as formattedStringToPlainText,it as generateId,s as getCookie,E as getDateAtStartOfDay,D as getDateAtStartOfMonth,ct as getEnumKeyByValue,p as getKeyboardFocusableElements,I as getNumberOfDaysForMonth,N as getSelected,x as incrementDate,gt as initialiseWebWorker,at as isArrayEqual,Y as isCallableFunction,k as isDate,R as isKeyLabelPair,$ as isKeyLabelPairArray,lt as isPlainObject,V as isPrimitive,q as isPrimitiveArray,ft as isRefObject,z as isSvgComponent,B as measureDomNode,J as measureScrollbarWidth,ut as noop,W as objectToString,T as parseDateString,U as parseTimeString,_ as preventDefaultBehavior,v as removeCookie,dt as saveBlobAsFile,g as setCookie,mt as setInSafely,b as smoothScroll,st as stripKeys,G as svgComponentToDataURL,K as throttle,pt as transparentize};
|