wjec-one 4.0.0-alpha.8 → 4.0.0

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.
Files changed (51) hide show
  1. package/auth/index.d.ts +162 -62
  2. package/auth/index.js +1 -1
  3. package/config/babel.config.js +62 -0
  4. package/config/eslint-config.js +224 -0
  5. package/config/jest.config.js +77 -0
  6. package/config/tsconfig.json +52 -0
  7. package/config/webpack.config.js +237 -0
  8. package/index.d.ts +383 -233
  9. package/index.js +1 -1
  10. package/localization/index.d.ts +32 -30
  11. package/localization/index.js +1 -1
  12. package/package.json +67 -76
  13. package/portal/index.d.ts +270 -0
  14. package/portal/index.js +1 -0
  15. package/scripts/bin/wjec-one-scripts.js +44 -0
  16. package/scripts/build.js +54 -0
  17. package/scripts/check-config.js +46 -0
  18. package/scripts/check-tests.js +93 -0
  19. package/scripts/config/babel.config.js +29 -0
  20. package/scripts/config/webpack.standalone.config.js +119 -0
  21. package/scripts/init.js +91 -0
  22. package/scripts/standalone.js +28 -0
  23. package/scripts/start.js +25 -0
  24. package/scripts/test.js +78 -0
  25. package/services/index.d.ts +14 -14
  26. package/services/index.js +1 -1
  27. package/store/index.d.ts +9 -9
  28. package/store/index.js +1 -1
  29. package/store/utils/index.d.ts +2 -23
  30. package/test/assetsTransformer.ts +7 -0
  31. package/test/index.d.ts +106 -0
  32. package/test/index.js +1 -0
  33. package/test/index.ts +182 -0
  34. package/test/setupTests.ts +76 -0
  35. package/test/setupTestsAfterEnv.ts +47 -0
  36. package/test/svgTransformer.tsx +3 -0
  37. package/test/wjecOneMocks.ts +247 -0
  38. package/theme/index.d.ts +23 -24
  39. package/theme/index.js +1 -1
  40. package/umd/auth/index.js +1 -1
  41. package/umd/index.js +1 -1
  42. package/umd/localization/index.js +1 -1
  43. package/umd/portal/index.js +1 -0
  44. package/umd/services/index.js +1 -1
  45. package/umd/store/index.js +1 -1
  46. package/umd/test/index.js +1 -0
  47. package/umd/theme/index.js +1 -1
  48. package/umd/utils/index.js +1 -1
  49. package/utils/index.d.ts +50 -53
  50. package/utils/index.js +1 -1
  51. package/wjec-one-project.d.ts +74 -0
package/auth/index.d.ts CHANGED
@@ -1,89 +1,189 @@
1
- import * as amazon_cognito_identity_js from 'amazon-cognito-identity-js';
2
1
  import { CognitoUserSession, CognitoUser } from 'amazon-cognito-identity-js';
2
+ import { LocalizationState } from 'wjec-one/localization';
3
+ import { ServiceCallStatus as ServiceCallStatus$1 } from 'wjec-one/services';
3
4
 
4
- declare type ServiceCallStatus = 'done' | 'failed' | 'idle' | 'loading';
5
+ type ServiceCallStatus = 'done' | 'failed' | 'idle' | 'loading';
5
6
 
6
- declare type GenericStrings = {
7
- [key: string]: string;
8
- };
9
- declare type LocalizationState<L extends number | string | symbol = any, S extends GenericStrings = any> = {
10
- availableLocales: L[];
11
- locale: L;
12
- strings: S;
13
- };
14
-
15
- interface Attributes {
7
+ declare enum AuthAction {
8
+ CHANGE_PASSWORD = "changePassword",
9
+ COMPLETE_PASSWORD_RESET = "completePasswordReset",
10
+ FORCE_CHANGE_PASSWORD = "forceChangePassword",
11
+ GET_AUTHORIZATION_TOKEN = "getAuthorizationToken",
12
+ GET_USER_PREFERENCES = "getUserPreferences",
13
+ GET_USER_SESSION = "getUserSession",
14
+ INIT = "init",
15
+ REFRESH_USER_SESSION = "refreshUserSession",
16
+ REQUEST_PASSWORD_RESET = "requestPasswordReset",
17
+ REQUEST_TOTP_TOKEN = "requestSoftwareToken",
18
+ SET_MFA_TYPE = "setMfaType",
19
+ SIGN_IN = "signIn",
20
+ SIGN_OUT = "signOut",
21
+ SUBMIT_MFA_CODE = "confirmSignIn",
22
+ UPDATE_USER_ATTRIBUTES = "updateUserAttributes",
23
+ UPDATE_USER_PREFERENCES = "updateUserPreferences",
24
+ VERIFY_TELEPHONE_NUMBER = "verifyTelephoneNumber",
25
+ VERIFY_TOTP_TOKEN = "verifySoftwareToken"
26
+ }
27
+ declare enum ChallengeType {
28
+ CUSTOM_CHALLENGE = "CUSTOM_CHALLENGE",
29
+ EMAIL_MFA = "EMAIL",
30
+ MFA_SETUP = "MFA_SETUP",
31
+ NEW_PASSWORD_REQUIRED = "NEW_PASSWORD_REQUIRED",
32
+ SMS_MFA = "SMS",
33
+ TOTP_MFA = "TOTP",
34
+ VERIFY_TELEPHONE_NUMBER = "VERIFY_TELEPHONE_NUMBER",
35
+ VERIFY_TOTP_TOKEN = "VERIFY_TOTP_TOKEN"
36
+ }
37
+ declare enum MFAType {
38
+ EMAIL = "EMAIL",
39
+ NONE = "NONE",
40
+ SMS = "SMS",
41
+ TOTP = "TOTP"
42
+ }
43
+ interface Cache extends EditableCognitoUserAttributes, EditablePrivateUserAttributes, ReadonlyCognitoUserAttributes {
44
+ isInitialized: boolean;
45
+ isSignedIn: boolean;
46
+ preferences: UserPreferences;
47
+ provider: 'Cognito' | 'AzureWJEC' | string;
48
+ requestStatuses: Record<AuthAction, ServiceCallStatus$1>;
49
+ usersEndpoint: string;
50
+ }
51
+ interface EditableCognitoUserAttributes {
52
+ telephoneNumber: string;
53
+ }
54
+ interface EditablePrivateUserAttributes {
16
55
  familyName: string;
17
- fullName: string;
56
+ name: string;
18
57
  givenName: string;
19
58
  languagePreference: LocalizationState['locale'];
20
59
  middleName: string;
21
- telephoneNumber: string;
22
60
  }
23
- interface Cache extends Attributes {
61
+ interface ReadonlyCognitoUserAttributes {
62
+ centrePermissions: Record<string, string>;
24
63
  emailAddress: string;
64
+ emailAddressVerified: boolean;
25
65
  groups: string[];
26
66
  id: string;
27
- isInitialized: boolean;
28
- isSignedIn: boolean;
29
- requestStatus: ServiceCallStatus;
67
+ mfaType: MFAType;
68
+ telephoneNumberVerified: boolean;
69
+ totpVerified: boolean;
30
70
  }
31
- declare type NewPasswordChallenge = {
32
- challengeType: 'NEW_PASSWORD_REQUIRED';
71
+ type CognitoUserAttributes = EditableCognitoUserAttributes & ReadonlyCognitoUserAttributes;
72
+ type EmailMfaChallenge = {
73
+ attemptNumber: number;
74
+ challengeType: ChallengeType.EMAIL_MFA;
75
+ completeChallenge: (code: string) => Promise<Challenge>;
76
+ emailAddress: string;
77
+ };
78
+ type NewPasswordChallenge = {
79
+ challengeType: ChallengeType.NEW_PASSWORD_REQUIRED;
33
80
  completeChallenge: (newPassword: string) => Promise<boolean>;
34
81
  };
35
- declare type Challenge = NewPasswordChallenge;
36
-
37
- declare class Authorization {
38
- static state: {
39
- readonly emailAddress: string;
40
- readonly familyName: string;
41
- readonly fullName: string;
42
- readonly givenName: string;
43
- readonly groups: string[];
44
- readonly id: string;
45
- readonly isInitialized: boolean;
46
- readonly isSignedIn: boolean;
47
- readonly languagePreference: any;
48
- readonly middleName: string;
49
- readonly requestStatus: ServiceCallStatus;
50
- readonly telephoneNumber: string;
51
- };
52
- static completePasswordReset: (emailAddress: string, code: string, newPassword: string) => Promise<boolean>;
53
- static getAuthorizationToken: () => Promise<string>;
54
- static getUserSession: () => Promise<CognitoUserSession>;
55
- static requestPasswordReset: (emailAddress: string) => Promise<boolean>;
56
- static signIn: (emailAddress: string, password: string) => Promise<{
57
- challenge?: Challenge;
58
- user: CognitoUser;
59
- }>;
60
- static signOut: () => Promise<boolean>;
61
- static updateUserAttributes: (attributes: Partial<Attributes>) => Promise<boolean>;
62
- static init(amplifyConfig: Record<string, any>, oAuthConfig: Record<string, any>): Promise<CognitoUserSession>;
63
- }
64
-
65
- declare const tools: {
66
- completePasswordReset: (emailAddress: string, code: string, newPassword: string) => Promise<boolean>;
67
- requestPasswordReset: (emailAddress: string) => Promise<boolean>;
68
- signIn: (emailAddress: string, password: string) => Promise<{
69
- challenge?: NewPasswordChallenge;
70
- user: amazon_cognito_identity_js.CognitoUser;
71
- }>;
72
- signOut: () => Promise<boolean>;
73
- updateUserAttributes: (attributes: Partial<Attributes>) => Promise<boolean>;
82
+ type SmsMfaChallenge = {
83
+ attemptNumber: number;
84
+ challengeType: ChallengeType.SMS_MFA;
85
+ completeChallenge: (code: string) => Promise<Challenge>;
86
+ telephoneNumber: string;
87
+ };
88
+ type TotpMfaChallenge = {
89
+ attemptNumber: number;
90
+ challengeType: ChallengeType.TOTP_MFA;
91
+ completeChallenge: (code: string) => Promise<Challenge>;
92
+ };
93
+ type VerifyTelephoneNumberChallenge = {
94
+ challengeType: ChallengeType.VERIFY_TELEPHONE_NUMBER;
95
+ completeChallenge: (code: string) => Promise<boolean>;
74
96
  };
97
+ type VerifyTotpTokenChallenge = {
98
+ challengeType: ChallengeType.VERIFY_TOTP_TOKEN;
99
+ completeChallenge: (code: string) => Promise<boolean>;
100
+ secretKey: string;
101
+ };
102
+ type Challenge = EmailMfaChallenge | NewPasswordChallenge | SmsMfaChallenge | TotpMfaChallenge | VerifyTelephoneNumberChallenge | VerifyTotpTokenChallenge;
103
+ declare enum Role {
104
+ ADMINISTRATIVE_SUPPORT = "administrativeSupport",
105
+ EXAMS_OFFICER = "examsOfficer",
106
+ HEAD_OF_DEPARTMENT = "headOfDepartment",
107
+ HEAD_OF_YEAR = "headOfYear",
108
+ HEAD_TEACHER = "headTeacher",
109
+ LOCAL_AUTHORITY_ADVISOR = "localAuthorityAdvisor",
110
+ OTHER = "other",
111
+ STAKEHOLDER = "stakeholder",
112
+ TEACHER = "teacher",
113
+ TUTOR = "tutor"
114
+ }
115
+ declare enum Subject {
116
+ ENGLISH = "english",
117
+ MATHS = "maths",
118
+ SCIENCE = "science"
119
+ }
120
+ type UserPreferences = {
121
+ emailMfaAccepted?: Date;
122
+ favouriteLinks?: string[];
123
+ lastSeenVersion?: string;
124
+ role?: Role;
125
+ subjects?: Subject[];
126
+ title?: string;
127
+ };
128
+
75
129
  interface Props {
76
130
  amplifyConfig?: Record<string, any>;
77
131
  oAuthConfig?: Record<string, any>;
78
132
  onChallenge?: (challenge: Challenge) => void;
79
133
  onCompletePasswordReset?: () => void;
80
- onError?: (errorType: keyof typeof tools | 'initialization', errorDetails?: any) => void;
134
+ onError?: (errorType: AuthAction, errorDetails?: any) => void;
81
135
  onInit?: (session: CognitoUserSession) => void;
136
+ onRefreshSession?: (session: CognitoUserSession) => void;
82
137
  onRequestPasswordReset?: (emailAddress: string) => void;
138
+ onSetMfaType?: (mfaType: MFAType) => void;
83
139
  onSignIn?: (session: CognitoUserSession) => void;
84
140
  onSignOut?: () => void;
141
+ usersEndpoint?: string;
85
142
  }
86
- declare type UseAuthorizationHook = (props?: Props) => ([typeof Authorization.state, typeof tools]);
143
+ type UseAuthorizationHook = (props?: Props) => typeof state;
87
144
  declare const useAuthorization: UseAuthorizationHook;
88
145
 
89
- export { Attributes, Authorization, Cache, Challenge, NewPasswordChallenge, useAuthorization };
146
+ declare const changePassword: (currentPassword: string, newPassword: string) => Promise<boolean>;
147
+ declare const completePasswordReset: (username: string, code: string, newPassword: string) => Promise<boolean>;
148
+ declare const getAuthorizationToken: () => Promise<string>;
149
+ declare const getUserSession: () => Promise<CognitoUserSession>;
150
+ declare const init: (amplifyConfig: Record<string, any>, oAuthConfig: Record<string, any>, usersEndpoint: string) => Promise<CognitoUserSession>;
151
+ declare const refreshUserSession: () => Promise<CognitoUserSession>;
152
+ declare const requestPasswordReset: (emailAddress: string) => Promise<boolean>;
153
+ declare const setMfaType: (mfaType: MFAType.EMAIL | MFAType.SMS | MFAType.TOTP, syncCache?: boolean) => Promise<boolean>;
154
+ declare const setupTotp: () => Promise<{
155
+ challenge?: Challenge;
156
+ secretKey: string;
157
+ }>;
158
+ declare const signIn: (emailAddress: string, password: string) => Promise<{
159
+ challenge?: Challenge;
160
+ user: CognitoUser;
161
+ }>;
162
+ declare const signOut: () => Promise<boolean>;
163
+ declare const updateUserAttributes: (attributes: Partial<EditableCognitoUserAttributes & EditablePrivateUserAttributes>) => Promise<boolean>;
164
+ declare const updateUserPreferences: (preferences: Partial<UserPreferences>) => Promise<boolean>;
165
+ declare const verifyTelephoneNumber: () => Promise<Challenge>;
166
+ declare const verifyTotp: (code: string) => Promise<boolean>;
167
+ declare const state: Readonly<{
168
+ readonly centrePermissions: Record<string, string>;
169
+ readonly emailAddress: string;
170
+ readonly emailAddressVerified: boolean;
171
+ readonly familyName: string;
172
+ readonly name: string;
173
+ readonly givenName: string;
174
+ readonly groups: string[];
175
+ readonly id: string;
176
+ readonly isInitialized: boolean;
177
+ readonly isSignedIn: boolean;
178
+ readonly languagePreference: any;
179
+ readonly mfaType: MFAType;
180
+ readonly middleName: string;
181
+ readonly preferences: UserPreferences;
182
+ readonly provider: string;
183
+ readonly requestStatuses: Record<AuthAction, ServiceCallStatus>;
184
+ readonly telephoneNumber: string;
185
+ readonly telephoneNumberVerified: boolean;
186
+ readonly totpVerified: boolean;
187
+ }>;
188
+
189
+ export { AuthAction, Cache, Challenge, ChallengeType, CognitoUserAttributes, EditableCognitoUserAttributes, EditablePrivateUserAttributes, EmailMfaChallenge, MFAType, NewPasswordChallenge, ReadonlyCognitoUserAttributes, Role, SmsMfaChallenge, Subject, TotpMfaChallenge, UserPreferences, VerifyTelephoneNumberChallenge, VerifyTotpTokenChallenge, changePassword, completePasswordReset, getAuthorizationToken, getUserSession, init, refreshUserSession, requestPasswordReset, setMfaType, setupTotp, signIn, signOut, state, updateUserAttributes, updateUserPreferences, useAuthorization, verifyTelephoneNumber, verifyTotp };
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}from"../utils";import{useState as i,useRef as a,useEffect as u}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 c(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){p(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:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function c(e,t,r,o){var i=t&&t.prototype instanceof h?t:h,a=Object.create(i.prototype),u=new E(o||[]);return n(a,"_invoke",{value:P(e,r,u)}),a}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var d={};function h(){}function p(){}function g(){}var m={};s(m,i,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(_([])));y&&y!==t&&r.call(y,i)&&(m=y);var w=g.prototype=h.prototype=Object.create(m);function b(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function O(e,t){function o(n,i,a,u){var s=f(e[n],e,i);if("throw"!==s.type){var c=s.arg,l=c.value;return l&&"object"==typeof l&&r.call(l,"__await")?t.resolve(l.__await).then((function(e){o("next",e,a,u)}),(function(e){o("throw",e,a,u)})):t.resolve(l).then((function(e){c.value=e,a(c)}),(function(e){return o("throw",e,a,u)}))}u(s.arg)}var i;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){o(e,r,t,n)}))}return i=i?i.then(n,n):n()}})}function P(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=S(a,r);if(u){if(u===d)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 s=f(e,t,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}function S(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,S(e,t),"throw"===t.method))return d;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var n=f(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,d;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,d):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}function N(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 x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(N,this),this.reset(!0)}function _(e){if(e){var t=e[i];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:k}}function k(){return{value:void 0,done:!0}}return p.prototype=g,n(w,"constructor",{value:g,configurable:!0}),n(g,"constructor",{value:p,configurable:!0}),p.displayName=s(g,u,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,g):(e.__proto__=g,s(e,u,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},b(O.prototype),s(O.prototype,a,(function(){return this})),e.AsyncIterator=O,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new O(c(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},b(w),s(w,u,"Generator"),s(w,i,(function(){return this})),s(w,"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=_,E.prototype={constructor:E,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(x),!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 a.type="throw",a.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 i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),s=r.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.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 i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,d):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),d},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),x(r),d}},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;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:_(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},e}function f(e,t,r,n,o,i,a){try{var u=e[i](a),s=u.value}catch(e){return void r(e)}u.done?t(s):Promise.resolve(s).then(n,o)}function d(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){f(i,n,o,a,u,"next",e)}function u(e){f(i,n,o,a,u,"throw",e)}a(void 0)}))}}function h(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function p(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,i=[],a=!0,u=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(u)throw o}}return i}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return m(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 m(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 m(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={emailAddress:void 0,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isInitialized:!1,isSignedIn:!1,languagePreference:"en-gb",middleName:void 0,requestStatus:"idle",telephoneNumber:void 0},y=function(e){return v[e]},w=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];v[r]=n})),r&&e.dispatch("custom",{data:{updatedTimestamp:Date.now()},event:"cacheUpdated"})},b=function(e){var t=e.getIdToken().payload;w({emailAddress:t.email,familyName:t.family_name||t.familyName,fullName:t.name,givenName:t.given_name||t.givenName,groups:t["cognito:groups"]||[],id:t.sub,isSignedIn:!0,languagePreference:t["custom:language_preference"],middleName:t.middle_name||t.middleName,telephoneNumber:t.phone_number})},O=function(e,r){return function(){var n;if(y("isInitialized")){for(var o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];(n=e.call.apply(e,[t].concat(i)))instanceof Promise&&n.catch((function(e){N(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}},P=function(e,r){var n;if("NEW_PASSWORD_REQUIRED"===e)n={challengeType:"NEW_PASSWORD_REQUIRED",completeChallenge:function(e){return w({requestStatus:"loading"}),E(t.completeNewPassword(r,e),"newPasswordChallenge")}};return n},S=function(t){e.dispatch("custom",{data:{challenge:t},event:"challenge"})},N=function(t,r){e.dispatch("custom",{data:{errorDetails:r,errorType:t},event:"error"})},x=function(t){e.dispatch("custom",{data:{session:t},event:"init"})},E=function(e,t){return e.then((function(){return w({requestStatus:"done"}),!0})).catch((function(e){return(e instanceof Error||"string"==typeof e)&&N(t,e),!1}))},_=function(e){return Object.entries(e).reduce((function(e,t){var r=g(t,2),o=r[0],i=r[1];return c(c({},e),{},p({},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),i))}),{})},k=function(){function n(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n)}var o,i,a,u;return o=n,i=null,a=[{key:"init",value:(u=d(l().mark((function n(o,i){var a;return l().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!y("isInitialized")){n.next=4;break}console.warn("WJEC One Authorization: Config cannot be changed after initialization - the config that was originally provided will continue to be used"),n.next=16;break;case 4:if(o&&i){n.next=8;break}throw new Error("WJEC One Authorization: Both amplifyConfig and oAuthConfig objects must be provided");case 8:return r.configure(o),t.configure({oauth:i}),w({isInitialized:!0},!1),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":w({requestStatus:"failed"});break;case"signIn":b(r.signInUserSession);break;case"signOut":w({emailAddress:void 0,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isSignedIn:!1})}})),e.listen("custom",(function(e){"error"===e.payload.event&&"loading"===y("requestStatus")&&w({requestStatus:"failed"})})),n.next=14,t.currentSession().then((function(e){return b(e),e})).catch((function(){}));case 14:a=n.sent,x(a);case 16:return n.abrupt("return",a);case 17:case"end":return n.stop()}}),n)}))),function(e,t){return u.apply(this,arguments)})}],i&&h(o.prototype,i),a&&h(o,a),Object.defineProperty(o,"prototype",{writable:!1}),n}();p(k,"state",{get emailAddress(){return y("emailAddress")},get familyName(){return y("familyName")},get fullName(){return y("fullName")},get givenName(){return y("givenName")},get groups(){return y("groups")},get id(){return y("id")},get isInitialized(){return y("isInitialized")},get isSignedIn(){return y("isSignedIn")},get languagePreference(){return y("languagePreference")},get middleName(){return y("middleName")},get requestStatus(){return y("requestStatus")},get telephoneNumber(){return y("telephoneNumber")}}),p(k,"completePasswordReset",O((function(e,r,n){return w({requestStatus:"loading"}),E(t.forgotPasswordSubmit(e,r,n),"completePasswordReset")}),"completePasswordReset")),p(k,"getAuthorizationToken",O(d(l().mark((function e(){var t,r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,k.getUserSession();case 2:return t=e.sent,r=t.getIdToken().getJwtToken(),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e)}))),"getAuthorizationToken")),p(k,"getUserSession",O(d(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)}))),"getUserSession")),p(k,"requestPasswordReset",O((function(e){return w({requestStatus:"loading"}),E(t.forgotPassword(e),"requestPasswordReset")}),"requestPasswordReset")),p(k,"signIn",O(function(){var e=d(l().mark((function e(r,n){var o,i;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w({requestStatus:"loading"}),e.next=3,t.signIn(r,n).catch((function(e){(e instanceof Error||"string"==typeof e)&&N("signIn",e)}));case 3:return(i=e.sent)&&(i.challengeName&&(o=P(i.challengeName,i),S(o)),w({requestStatus:"done"})),e.abrupt("return",{challenge:o,user:i});case 6:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}(),"signIn")),p(k,"signOut",O((function(){return w({requestStatus:"loading"}),E(t.signOut(),"signOut")}),"signOut")),p(k,"updateUserAttributes",O(function(){var e=d(l().mark((function e(r){var n,o;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return w({requestStatus:"loading"}),e.next=3,t.currentAuthenticatedUser();case 3:return n=e.sent,e.next=6,E(t.updateUserAttributes(n,_(r)),"updateUserAttributes");case 6:return(o=e.sent)&&w(r),e.abrupt("return",o);case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),"updateUserAttributes"));var A=k,I={completePasswordReset:A.completePasswordReset,requestPasswordReset:A.requestPasswordReset,signIn:A.signIn,signOut:A.signOut,updateUserAttributes:A.updateUserAttributes},j=!1,L=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.amplifyConfig,n=t.oAuthConfig,s=t.onChallenge,c=t.onCompletePasswordReset,l=t.onError,f=t.onInit,d=t.onRequestPasswordReset,h=t.onSignIn,p=t.onSignOut,m=i(Date.now()),v=g(m,2);v[0];var y=v[1],w=a(!1);return u((function(){var t=!1,r=e.listen("auth",(function(e){var r=e.payload,n=r.data,i=r.event;if(!t)switch(i){case"forgotPassword":o(d)&&d(n.username);break;case"forgotPassword_failure":o(l)&&l("requestPasswordReset",n);break;case"forgotPasswordSubmit":o(c)&&c();break;case"forgotPasswordSubmit_failure":o(l)&&l("completePasswordReset",n);break;case"signIn":o(h)&&h(n.signInUserSession);break;case"signIn_failure":o(l)&&l("signIn",n);break;case"signOut":o(p)&&p()}})),n=e.listen("custom",(function(e){var r=e.payload,n=r.data,i=r.event;if(!t)switch(i){case"cacheUpdated":y(n.updatedTimestamp);break;case"challenge":o(s)&&s(n.challenge);break;case"error":o(l)&&l(n.errorType,n.errorDetails);break;case"init":o(f)&&f(n.session)}}));return function(){t=!0,r(),n()}}),[]),u((function(){if(r&&n){try{A.init(r,n),w.current=!0,j=!0}catch(e){o(l)&&l("initialization")}j&&!w.current&&console.warn("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]),[A.state,I]};export{A as Authorization,L as useAuthorization};
1
+ import{Auth as e,Hub as t,Amplify as r}from"aws-amplify";import{assertNever as n,developerWarning as a,isCallableFunction as o}from"wjec-one/utils";import{useState as i,useRef as u,useEffect as c}from"react";function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function f(e,t,r,n,a,o,i){try{var u=e[o](i),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,a)}function l(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var o=e.apply(t,r);function i(e){f(o,n,a,i,u,"next",e)}function u(e){f(o,n,a,i,u,"throw",e)}i(void 0)}))}}function p(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function h(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){p(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function E(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.includes(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],t.includes(r)||{}.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}function m(){m=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var o=t&&t.prototype instanceof S?t:S,i=Object.create(o.prototype),u=new x(n||[]);return a(i,"_invoke",{value:w(e,r,u)}),i}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var p="suspendedStart",d="suspendedYield",h="executing",E="completed",v={};function S(){}function g(){}function y(){}var T={};s(T,i,(function(){return this}));var _=Object.getPrototypeOf,b=_&&_(_(k([])));b&&b!==r&&n.call(b,i)&&(T=b);var O=y.prototype=S.prototype=Object.create(T);function N(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function R(e,t){function r(a,o,i,u){var c=l(e[a],e,o);if("throw"!==c.type){var s=c.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,i,u)}),(function(e){r("throw",e,i,u)})):t.resolve(f).then((function(e){s.value=e,i(s)}),(function(e){return r("throw",e,i,u)}))}u(c.arg)}var o;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return o=o?o.then(a,a):a()}})}function w(t,r,n){var a=p;return function(o,i){if(a===h)throw Error("Generator is already running");if(a===E){if("throw"===o)throw i;return{value:e,done:!0}}for(n.method=o,n.arg=i;;){var u=n.delegate;if(u){var c=A(u,n);if(c){if(c===v)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===p)throw a=E,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=h;var s=l(t,r,n);if("normal"===s.type){if(a=n.done?E:d,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(a=E,n.method="throw",n.arg=s.arg)}}}function A(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var o=l(a,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,v;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function P(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(P,this),this.reset(!0)}function k(t){if(t||""===t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,o=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return o.next=o}}throw new TypeError(typeof t+" is not iterable")}return g.prototype=y,a(O,"constructor",{value:y,configurable:!0}),a(y,"constructor",{value:g,configurable:!0}),g.displayName=s(y,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===g||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,s(e,c,"GeneratorFunction")),e.prototype=Object.create(O),e},t.awrap=function(e){return{__await:e}},N(R.prototype),s(R.prototype,u,(function(){return this})),t.AsyncIterator=R,t.async=function(e,r,n,a,o){void 0===o&&(o=Promise);var i=new R(f(e,r,n,a),o);return t.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},N(O),s(O,c,"Generator"),s(O,i,(function(){return this})),s(O,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=k,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(I),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return u.type="throw",u.arg=t,r.next=n,a&&(r.method="next",r.arg=e),!!a}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return a("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(c&&s){if(this.prev<i.catchLoc)return a(i.catchLoc,!0);if(this.prev<i.finallyLoc)return a(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return a(i.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return a(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var o=a;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;I(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:k(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}function v(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o,i,u=[],c=!0,s=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=o.call(r)).done)&&(u.push(n.value),u.length!==t);c=!0);}catch(e){s=!0,a=e}finally{try{if(!c&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(s)throw a}}return u}}(e,t)||y(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||y(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e){return g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g(e)}function y(e,t){if(e){if("string"==typeof e)return s(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}var T,_,b,O,N;!function(e){e.CHANGE_PASSWORD="changePassword",e.COMPLETE_PASSWORD_RESET="completePasswordReset",e.FORCE_CHANGE_PASSWORD="forceChangePassword",e.GET_AUTHORIZATION_TOKEN="getAuthorizationToken",e.GET_USER_PREFERENCES="getUserPreferences",e.GET_USER_SESSION="getUserSession",e.INIT="init",e.REFRESH_USER_SESSION="refreshUserSession",e.REQUEST_PASSWORD_RESET="requestPasswordReset",e.REQUEST_TOTP_TOKEN="requestSoftwareToken",e.SET_MFA_TYPE="setMfaType",e.SIGN_IN="signIn",e.SIGN_OUT="signOut",e.SUBMIT_MFA_CODE="confirmSignIn",e.UPDATE_USER_ATTRIBUTES="updateUserAttributes",e.UPDATE_USER_PREFERENCES="updateUserPreferences",e.VERIFY_TELEPHONE_NUMBER="verifyTelephoneNumber",e.VERIFY_TOTP_TOKEN="verifySoftwareToken"}(T||(T={})),function(e){e.CUSTOM_CHALLENGE="CUSTOM_CHALLENGE",e.EMAIL_MFA="EMAIL",e.MFA_SETUP="MFA_SETUP",e.NEW_PASSWORD_REQUIRED="NEW_PASSWORD_REQUIRED",e.SMS_MFA="SMS",e.TOTP_MFA="TOTP",e.VERIFY_TELEPHONE_NUMBER="VERIFY_TELEPHONE_NUMBER",e.VERIFY_TOTP_TOKEN="VERIFY_TOTP_TOKEN"}(_||(_={})),function(e){e.EMAIL="EMAIL",e.NONE="NONE",e.SMS="SMS",e.TOTP="TOTP"}(b||(b={})),function(e){e.ADMINISTRATIVE_SUPPORT="administrativeSupport",e.EXAMS_OFFICER="examsOfficer",e.HEAD_OF_DEPARTMENT="headOfDepartment",e.HEAD_OF_YEAR="headOfYear",e.HEAD_TEACHER="headTeacher",e.LOCAL_AUTHORITY_ADVISOR="localAuthorityAdvisor",e.OTHER="other",e.STAKEHOLDER="stakeholder",e.TEACHER="teacher",e.TUTOR="tutor"}(O||(O={})),function(e){e.ENGLISH="english",e.MATHS="maths",e.SCIENCE="science"}(N||(N={}));var R=function(t,r){return function(){var n;if(Y("isInitialized")){for(var a=arguments.length,o=new Array(a),i=0;i<a;i++)o[i]=arguments[i];(n=t.call.apply(t,[e].concat(o)))instanceof Promise&&n.catch((function(e){M(r,e)}))}else console.error("WJEC One Authorization: You tried to call ".concat(r,"() before AWS Amplify was initialized. Please provide values for amplifyConfig & oAuthConfig to get set up"));return n}},w=function(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return e.then((function(){return r&&k(t,"done"),!0})).catch((function(e){return(e instanceof Error||"string"==typeof e)&&M(t,e),!1}))},A=function(e){return"object"===g(e)&&Object.hasOwn(e,"name")&&"NotAuthorizedException"===e.name},P=function(e){return"object"===g(e)&&Object.hasOwn(e,"name")&&"InvalidPasswordException"===e.name},I=function(e){return Object.entries(e).reduce((function(e,t){var r=v(t,2),a=r[0],o=r[1];return h(h({},e),{},p({},function(e){return"telephoneNumber"===e?"phone_number":n(e)}(a),o))}),{})},x=function(e){return h(h({},e),{},{emailMfaAccepted:e.emailMfaAccepted?new Date(e.emailMfaAccepted):void 0})},k=function(e,t){var r=Y("requestStatuses");z({requestStatuses:h(h({},r),{},p({},e,t))})},U=function(e){t.dispatch("custom",{data:{challenge:e},event:"challenge"})},M=function(e,r){t.dispatch("custom",{data:{errorDetails:r,errorType:e},event:"error"})},C=function(e,r){t.dispatch("custom",{data:r,event:e})},F=function(e){C(T.INIT,{session:e})},L=function(){var t=l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,n=r.getIdToken(),t.next=6,fetch("".concat(Y("usersEndpoint")).concat(n.payload.sub,"/mfa/secret"),{headers:{Authorization:n.getJwtToken()}}).then((function(e){return e.json()})).then((function(e){return e.secret}));case 6:return a=t.sent,t.abrupt("return",a);case 8:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),D=function(){var t=l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,n=r.getIdToken(),t.next=6,fetch("".concat(Y("usersEndpoint")).concat(n.payload.sub,"/preferences"),{headers:{Authorization:n.getJwtToken()}}).then((function(e){return null==e?void 0:e.json()}));case 6:return a=t.sent,t.abrupt("return",a||{});case 8:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),j=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(Y("usersEndpoint")).concat(a.payload.sub,"/mfa"),{body:JSON.stringify({mfaType:r}),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){if(2!==Math.floor(e.status/100))throw new Error("Request failed");return!0}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),G=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(Y("usersEndpoint")).concat(a.payload.sub),{body:JSON.stringify(r),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){return e.json()})).then((function(e){return e.success}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),V=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(Y("usersEndpoint")).concat(a.payload.sub,"/preferences"),{body:JSON.stringify(r),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){return e.json()})).then((function(e){return e.success}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),H=function(){var t=l(m().mark((function t(r){var n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return n=t.sent,a=n.getIdToken(),t.next=6,fetch("".concat(Y("usersEndpoint")).concat(a.payload.sub,"/mfa/secret"),{body:JSON.stringify({totpCode:r}),headers:{Authorization:a.getJwtToken()},method:"POST"}).then((function(e){if(2!==Math.floor(e.status/100))throw new Error("Request failed");return!0}));case 6:return o=t.sent,t.abrupt("return",o);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),W={centrePermissions:{},emailAddress:void 0,emailAddressVerified:!1,familyName:void 0,name:void 0,givenName:void 0,groups:[],id:void 0,isInitialized:!1,isSignedIn:!1,languagePreference:"en-gb",mfaType:void 0,middleName:void 0,preferences:{},provider:void 0,requestStatuses:Object.values(T).reduce((function(e,t){return h(h({},e),{},p({},t,"idle"))}),{}),telephoneNumber:void 0,telephoneNumberVerified:!1,totpVerified:!1,usersEndpoint:void 0},Y=function(e){return W[e]},z=function(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];Object.entries(e).forEach((function(e){var t=v(e,2),r=t[0],n=t[1];W[r]=n})),r&&t.dispatch("custom",{data:{updatedTimestamp:Date.now()},event:"cacheUpdated"})},B=function(){var e=l(m().mark((function e(t){var r,n,a,o,i,u;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=t.getIdToken().payload,k(T.GET_USER_PREFERENCES,"loading"),e.next=4,D().then((function(e){return k(T.GET_USER_PREFERENCES,"done"),e})).catch((function(e){return M(T.GET_USER_PREFERENCES,e),{}}));case 4:i=e.sent,u=x(i),z({centrePermissions:JSON.parse(o["custom:centre_permissions"]||"{}"),emailAddress:o.email,emailAddressVerified:o.email_verified,familyName:o.family_name||o.familyName,name:o.name,givenName:o.given_name||o.givenName,groups:o["cognito:groups"]||[],id:o.sub,isInitialized:!0,isSignedIn:!0,languagePreference:o["custom:language_preference"],mfaType:o["custom:mfa_type"],middleName:o.middle_name||o.middleName,preferences:u,provider:(null===(r=o.identities)||void 0===r||null===(n=r[0])||void 0===n?void 0:n.providerName)||"Cognito",telephoneNumber:o.phone_number,telephoneNumberVerified:o.phone_number_verified,totpVerified:"true"===(null===(a=o["custom:totp_verified"])||void 0===a?void 0:a.toLowerCase())});case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),K=function(){z({centrePermissions:{},emailAddress:void 0,emailAddressVerified:!1,familyName:void 0,name:void 0,givenName:void 0,groups:[],id:void 0,isSignedIn:!1,languagePreference:void 0,mfaType:void 0,middleName:void 0,preferences:{},provider:void 0,telephoneNumber:void 0,telephoneNumberVerified:!1,totpVerified:!1})},J=function(t){return function(){var r=l(m().mark((function r(n){var a,o,i;return m().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return k(T.FORCE_CHANGE_PASSWORD,"loading"),r.next=3,e.completeNewPassword(t,n).catch((function(e){A(e)||P(e)||M(T.FORCE_CHANGE_PASSWORD,e),a=!1}));case 3:if(!(o=r.sent)){r.next=12;break}if(!o.challengeName){r.next=10;break}return r.next=8,q(o.challengeName,o,o.challengeParam);case 8:i=r.sent,U(i);case 10:k(T.FORCE_CHANGE_PASSWORD,"done"),a=!0;case 12:return r.abrupt("return",a);case 13:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},Q=function(t){return function(){var r=l(m().mark((function r(n){var a;return m().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return k(T.SUBMIT_MFA_CODE,"loading"),r.next=3,e.sendCustomChallengeAnswer(t,n).then(function(){var e=l(m().mark((function e(r){return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==r||!r.challengeName){e.next=5;break}return e.next=3,q(r.challengeName,t,r.challengeParam);case 3:a=e.sent,U(a);case 5:k(T.SUBMIT_MFA_CODE,"done");case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){M(T.SUBMIT_MFA_CODE,e)}));case 3:return r.abrupt("return",a);case 4:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}()},q=function(t,r){var n,a,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=Z(t,null==o?void 0:o.selectedMfaType);switch(i){case _.EMAIL_MFA:n={attemptNumber:o.attemptNumber?parseInt(o.attemptNumber):void 0,challengeType:_.EMAIL_MFA,completeChallenge:Q(r),emailAddress:o.emailAddress};break;case _.NEW_PASSWORD_REQUIRED:n={challengeType:_.NEW_PASSWORD_REQUIRED,completeChallenge:J(r)};break;case _.SMS_MFA:n={attemptNumber:o.attemptNumber?parseInt(o.attemptNumber):void 0,challengeType:i,completeChallenge:Q(r),telephoneNumber:t===_.CUSTOM_CHALLENGE?o.redactedPhoneNumber:o.CODE_DELIVERY_DESTINATION};break;case _.TOTP_MFA:n={attemptNumber:o.attemptNumber?parseInt(o.attemptNumber):void 0,challengeType:i,completeChallenge:Q(r)};break;case _.VERIFY_TELEPHONE_NUMBER:n={challengeType:i,completeChallenge:(a=o.currentMfaType,function(){var t=l(m().mark((function t(r){var n;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.VERIFY_TELEPHONE_NUMBER,"loading"),t.next=3,w(e.verifyCurrentUserAttributeSubmit("phone_number",r),T.VERIFY_TELEPHONE_NUMBER);case 3:if(!(n=t.sent)){t.next=9;break}if(z({telephoneNumberVerified:!0}),Y("mfaType")===b.SMS||a!==b.SMS){t.next=9;break}return t.next=9,se(b.SMS,!0);case 9:return t.abrupt("return",n);case 10:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())};break;case _.VERIFY_TOTP_TOKEN:n={challengeType:i,completeChallenge:function(){var e=l(m().mark((function e(t){var r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,me(t);case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),secretKey:o.secretKey}}return n},Z=function(e,t){if(e===_.CUSTOM_CHALLENGE)switch(t){case b.EMAIL:return _.EMAIL_MFA;case b.SMS:return _.SMS_MFA;case b.TOTP:return _.TOTP_MFA}return e},X=["amplifyConfig","oAuthConfig","usersEndpoint"],$=!1,ee=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.amplifyConfig,n=e.oAuthConfig,s=e.usersEndpoint,f=E(e,X),l=v(i(Date.now()),2);l[0];var p=l[1],d=u(!1),m=u(h({},f));c((function(){m.current=h({},f)}),S(Object.values(f)));var g=function(e){if(o(m.current[e])){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),a=1;a<r;a++)n[a-1]=arguments[a];(t=m.current[e]).call.apply(t,[void 0].concat(n))}};return c((function(){if(r||n||s){try{ie(r,n,s),d.current=!0,$=!0}catch(e){g("onError",T.INIT)}$&&!d.current&&a("WJEC One useAuthorization: Config should only be provided to the first instance of the useAuthorization hook in your component tree (recommendation is to include this in your entry point component, even if you don't need authorization tools at that point)")}}),[r,n,s]),c((function(){var e=!1,r=t.listen("auth",(function(t){var r=t.payload,n=r.data,a=r.event;if(!e)switch(a){case"completeNewPassword_failure":g("onError",T.FORCE_CHANGE_PASSWORD,n);break;case"forgotPassword":g("onRequestPasswordReset",n.username);break;case"forgotPassword_failure":g("onError",T.REQUEST_PASSWORD_RESET,n);break;case"forgotPasswordSubmit":g("onCompletePasswordReset");break;case"forgotPasswordSubmit_failure":g("onError",T.COMPLETE_PASSWORD_RESET,n);break;case"signIn_failure":g("onError",T.SIGN_IN,n);break;case"signOut":g("onSignOut");break;case"tokenRefresh":o(m.current.onRefreshSession)&&oe().then(m.current.onRefreshSession);break;case"tokenRefresh_failure":g("onError",T.REFRESH_USER_SESSION,n)}})),n=t.listen("custom",(function(t){var r=t.payload,n=r.data,a=r.event;if(!e)switch(a){case"cacheUpdated":p(n.updatedTimestamp);break;case"challenge":g("onChallenge",n.challenge);break;case"error":g("onError",n.errorType,n.errorDetails);break;case"init":g("onInit",n.session);break;case"setMfaType":g("onSetMfaType",n.mfaType);break;case T.SIGN_IN:g("onSignIn",n.session)}}));return function(){e=!0,r(),n()}}),[]),ve},te=["telephoneNumber"],re=R(function(){var t=l(m().mark((function t(r,n){var a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.CHANGE_PASSWORD,"loading"),t.next=3,e.currentAuthenticatedUser();case 3:return a=t.sent,t.abrupt("return",w(e.changePassword(a,r,n),T.CHANGE_PASSWORD));case 5:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),T.CHANGE_PASSWORD),ne=R((function(t,r,n){return k(T.COMPLETE_PASSWORD_RESET,"loading"),w(e.forgotPasswordSubmit(t,r,n),T.COMPLETE_PASSWORD_RESET)}),T.COMPLETE_PASSWORD_RESET),ae=R(l(m().mark((function e(){var t,r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,oe();case 2:return t=e.sent,r=t.getIdToken().getJwtToken(),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e)}))),T.GET_AUTHORIZATION_TOKEN),oe=R(l(m().mark((function t(){var r;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,t.abrupt("return",r);case 4:case"end":return t.stop()}}),t)}))),T.GET_USER_SESSION),ie=function(){var n=l(m().mark((function n(o,i,u){var c;return m().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!Y("isInitialized")){n.next=4;break}a("WJEC One Authorization: Config cannot be changed after initialization - the config that was originally provided will continue to be used"),n.next=23;break;case 4:if(o&&i&&u){n.next=8;break}throw new Error("WJEC One Authorization: Both amplifyConfig and oAuthConfig objects must be provided, in addition to the endpoint URL for the users service");case 8:return n.prev=8,r.configure(o),e.configure({oauth:i}),z({usersEndpoint:u},!1),t.listen("auth",function(){var e=l(m().mark((function e(t){var r,n,a;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=t.payload,n=r.data,a=r.event,e.t0=a,e.next="completeNewPassword_failure"===e.t0?4:"forgotPassword_failure"===e.t0?6:"forgotPasswordSubmit_failure"===e.t0?8:"signIn"===e.t0?10:"signIn_failure"===e.t0?14:"signOut"===e.t0?16:"signOut_failure"===e.t0?18:"tokenRefresh_failure"===e.t0?20:22;break;case 4:return k(T.FORCE_CHANGE_PASSWORD,"failed"),e.abrupt("break",22);case 6:return k(T.REQUEST_PASSWORD_RESET,"failed"),e.abrupt("break",22);case 8:return k(T.COMPLETE_PASSWORD_RESET,"failed"),e.abrupt("break",22);case 10:return e.next=12,B(n.signInUserSession);case 12:return C(T.SIGN_IN,{session:n.signInUserSession}),e.abrupt("break",22);case 14:return k(T.SIGN_IN,"failed"),e.abrupt("break",22);case 16:return K(),e.abrupt("break",22);case 18:return k(T.SIGN_OUT,"failed"),e.abrupt("break",22);case 20:return k(T.REFRESH_USER_SESSION,"failed"),e.abrupt("break",22);case 22:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),t.listen("custom",(function(e){var t=e.payload,r=t.data;if("error"===t.event){var n=r.errorType;"loading"===Y("requestStatuses")[n]&&k(n,"failed")}})),n.next=15,e.currentAuthenticatedUser({bypassCache:!0}).then(function(){var e=l(m().mark((function e(t){var r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.getSignInUserSession(),e.next=3,B(r);case 3:return e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(){}));case 15:(c=n.sent)||z({isInitialized:!0}),F(c),n.next=23;break;case 20:n.prev=20,n.t0=n.catch(8),M(T.INIT,n.t0);case 23:return n.abrupt("return",c);case 24:case"end":return n.stop()}}),n,null,[[8,20]])})));return function(e,t,r){return n.apply(this,arguments)}}(),ue=R(l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.currentSession();case 2:return r=t.sent,t.next=5,e.currentAuthenticatedUser();case 5:return n=t.sent,t.next=8,new Promise((function(e,t){try{n.refreshSession(r.getRefreshToken(),(function(t,r){if(t)throw t;e(r)}))}catch(e){M(T.REFRESH_USER_SESSION,e),t(e)}}));case 8:return a=t.sent,t.abrupt("return",a);case 10:case"end":return t.stop()}}),t)}))),T.REFRESH_USER_SESSION),ce=R((function(t){return k(T.REQUEST_PASSWORD_RESET,"loading"),w(e.forgotPassword(t),T.REQUEST_PASSWORD_RESET)}),T.REQUEST_PASSWORD_RESET),se=R(function(){var e=l(m().mark((function e(t){var r,n,a=arguments;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=a.length>1&&void 0!==a[1]&&a[1],k(T.SET_MFA_TYPE,"loading"),e.next=4,j(t).catch((function(e){return M(T.SET_MFA_TYPE,e),!1}));case 4:return(n=e.sent)&&(z({mfaType:t},r),C(T.SET_MFA_TYPE,{mfaType:t}),k(T.SET_MFA_TYPE,"done"),t!==b.EMAIL&&he({emailMfaAccepted:void 0})),e.abrupt("return",n);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),T.SET_MFA_TYPE),fe=R(l(m().mark((function t(){var r,n,a,o;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.REQUEST_TOTP_TOKEN,"loading"),n=Y("mfaType"),t.next=4,e.currentAuthenticatedUser();case 4:if(a=t.sent,n!==b.TOTP){t.next=8;break}return t.next=8,se(b.EMAIL);case 8:return t.next=10,L().catch((function(e){M(T.REQUEST_TOTP_TOKEN,e)}));case 10:if(!(o=t.sent)){t.next=18;break}return t.next=14,q(_.VERIFY_TOTP_TOKEN,a,{secretKey:o});case 14:r=t.sent,U(r),z({totpVerified:!1},!1),k(T.REQUEST_TOTP_TOKEN,"done");case 18:return t.abrupt("return",{challenge:r,secretKey:o});case 19:case"end":return t.stop()}}),t)}))),T.REQUEST_TOTP_TOKEN),le=R(function(){var t=l(m().mark((function t(r,n){var a,o,i;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.SIGN_IN,"loading"),t.next=3,e.signIn(r,n).catch((function(e){A(e)||M(T.SIGN_IN,e)}));case 3:if(!(o=t.sent)){t.next=16;break}if(!o.challengeName){t.next=15;break}if((null===(i=o.challengeParam)||void 0===i?void 0:i.selectedMfaType)!==b.NONE){t.next=11;break}return t.next=9,e.sendCustomChallengeAnswer(o,"N/A").catch((function(e){M(T.SIGN_IN,e)}));case 9:t.next=15;break;case 11:return t.next=13,q(o.challengeName,o,o.challengeParam);case 13:a=t.sent,U(a);case 15:k(T.SIGN_IN,"done");case 16:return t.abrupt("return",{challenge:a,user:o});case 17:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),T.SIGN_IN),pe=R((function(){return k(T.SIGN_OUT,"loading"),w(e.signOut(),T.SIGN_OUT)}),T.SIGN_OUT),de=R(function(){var t=l(m().mark((function t(r){var n,a,o,i,u,c,s;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.telephoneNumber,a=E(r,te),o=!0,k(T.UPDATE_USER_ATTRIBUTES,"loading"),!Object.hasOwn(r,"telephoneNumber")){t.next=13;break}return i=Y("telephoneNumber"),u=Y("telephoneNumberVerified"),t.next=8,e.currentAuthenticatedUser();case 8:return c=t.sent,t.next=11,w(e.updateUserAttributes(c,I({telephoneNumber:n})),T.UPDATE_USER_ATTRIBUTES,!1);case 11:(o=t.sent)&&z({telephoneNumber:n,telephoneNumberVerified:n===i&&u},!1);case 13:return t.next=15,G(a);case 15:return(s=t.sent)&&z(a,!1),k(T.UPDATE_USER_ATTRIBUTES,o&&s?"done":"failed"),t.abrupt("return",o&&s);case 19:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),T.UPDATE_USER_ATTRIBUTES),he=R(function(){var e=l(m().mark((function e(t){var r,n;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return k(T.UPDATE_USER_PREFERENCES,"loading"),r=h(h({},Y("preferences")),t),e.next=4,V(r).catch((function(e){return M(T.UPDATE_USER_PREFERENCES,e),!1}));case 4:return(n=e.sent)&&(z({preferences:r},!1),k(T.UPDATE_USER_PREFERENCES,"done")),e.abrupt("return",n);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),T.UPDATE_USER_PREFERENCES),Ee=R(l(m().mark((function t(){var r,n,a;return m().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return k(T.VERIFY_TELEPHONE_NUMBER,"loading"),t.next=3,e.currentAuthenticatedUser();case 3:return n=t.sent,a=Y("mfaType"),t.next=7,w(e.verifyCurrentUserAttribute("phone_number"),T.VERIFY_TELEPHONE_NUMBER);case 7:if(!t.sent){t.next=17;break}return t.next=11,q(_.VERIFY_TELEPHONE_NUMBER,n,{currentMfaType:a});case 11:if(r=t.sent,a!==b.SMS){t.next=15;break}return t.next=15,se(b.EMAIL,!0);case 15:U(r),k(T.VERIFY_TELEPHONE_NUMBER,"done");case 17:return t.abrupt("return",r);case 18:case"end":return t.stop()}}),t)}))),T.VERIFY_TELEPHONE_NUMBER),me=R(function(){var e=l(m().mark((function e(t){var r;return m().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return k(T.VERIFY_TOTP_TOKEN,"loading"),e.next=3,H(t).catch((function(e){return M(T.VERIFY_TOTP_TOKEN,e),!1}));case 3:return(r=e.sent)&&(z({totpVerified:!0},!1),k(T.VERIFY_TOTP_TOKEN,"done")),e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),T.VERIFY_TOTP_TOKEN),ve=Object.freeze({get centrePermissions(){return Y("centrePermissions")},get emailAddress(){return Y("emailAddress")},get emailAddressVerified(){return Y("emailAddressVerified")},get familyName(){return Y("familyName")},get name(){return Y("name")},get givenName(){return Y("givenName")},get groups(){return Y("groups")},get id(){return Y("id")},get isInitialized(){return Y("isInitialized")},get isSignedIn(){return Y("isSignedIn")},get languagePreference(){return Y("languagePreference")},get mfaType(){return Y("mfaType")},get middleName(){return Y("middleName")},get preferences(){return Y("preferences")},get provider(){return Y("provider")},get requestStatuses(){return Y("requestStatuses")},get telephoneNumber(){return Y("telephoneNumber")},get telephoneNumberVerified(){return Y("telephoneNumberVerified")},get totpVerified(){return Y("totpVerified")}});export{T as AuthAction,_ as ChallengeType,b as MFAType,O as Role,N as Subject,re as changePassword,ne as completePasswordReset,ae as getAuthorizationToken,oe as getUserSession,ie as init,ue as refreshUserSession,ce as requestPasswordReset,se as setMfaType,fe as setupTotp,le as signIn,pe as signOut,ve as state,de as updateUserAttributes,he as updateUserPreferences,ee as useAuthorization,Ee as verifyTelephoneNumber,me as verifyTotp};
@@ -0,0 +1,62 @@
1
+ module.exports = {
2
+ env: {
3
+ production: {
4
+ plugins: [
5
+ ['emotion', { sourceMap: false }],
6
+ '@babel/proposal-class-properties',
7
+ '@babel/proposal-optional-chaining',
8
+ ['module-resolver', {
9
+ root: ['./'],
10
+ alias: {
11
+ auth: './auth',
12
+ localization: './localization',
13
+ portal: './portal',
14
+ root: './',
15
+ src: './src',
16
+ store: './store',
17
+ test: './test',
18
+ theme: './theme',
19
+ utils: './utils'
20
+ }
21
+ }]
22
+ ]
23
+ },
24
+ development: {
25
+ plugins: [
26
+ 'emotion',
27
+ '@babel/proposal-class-properties',
28
+ '@babel/proposal-optional-chaining',
29
+ ['module-resolver', {
30
+ root: ['./'],
31
+ alias: {
32
+ auth: './auth',
33
+ localization: './localization',
34
+ portal: './portal',
35
+ root: './',
36
+ src: './src',
37
+ store: './store',
38
+ test: './test',
39
+ theme: './theme',
40
+ utils: './utils'
41
+ }
42
+ }]
43
+ ]
44
+ }
45
+ },
46
+ presets: [
47
+ '@babel/react',
48
+ '@babel/typescript',
49
+ '@emotion/babel-preset-css-prop',
50
+ ['@babel/preset-env', {
51
+ corejs: '3.6.5',
52
+ targets: {
53
+ chrome: 58,
54
+ firefox: 62,
55
+ ie: 10
56
+ },
57
+ useBuiltIns: 'entry'
58
+ }]
59
+ ].filter((e) => e),
60
+ sourceType: 'unambiguous'
61
+ };
62
+