wjec-one 3.8.2 → 3.9.2

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.js CHANGED
@@ -1 +1 @@
1
- import e,{Auth as t,Hub as r}from"aws-amplify";import{useState as n,useEffect as o}from"react";import"react-dom/server";var a=function(e){return e.getIdToken().getJwtToken()},i=function(e){return new Date(1e3*e.getIdToken().getExpiration())},s=function(){var e;return regeneratorRuntime.async((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,regeneratorRuntime.awrap(t.currentAuthenticatedUser());case 2:return e=r.sent,r.abrupt("return",e);case 4:case"end":return r.stop()}}))},u=function(){var e;return regeneratorRuntime.async((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,regeneratorRuntime.awrap(t.currentSession());case 2:return e=r.sent,r.abrupt("return",e);case 4:case"end":return r.stop()}}))},c=function(){var e;return regeneratorRuntime.async((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,regeneratorRuntime.awrap(u());case 2:return e=t.sent,t.next=5,regeneratorRuntime.awrap(s());case 5:t.sent.refreshSession(e.getRefreshToken(),(function(){return null}));case 7:case"end":return t.stop()}}))};function d(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 l(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function f(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 g(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(r,!0).forEach((function(t){l(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(r).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e))&&"[object Arguments]"!==Object.prototype.toString.call(e))return;var r=[],n=!0,o=!1,a=void 0;try{for(var i,s=e[Symbol.iterator]();!(n=(i=s.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(o)throw a}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var p=function(e){console.error(e)},v=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];"production"!==process.env.NODE_ENV&&t&&p(e)},h=function(e){return"function"==typeof e},y=["amplify-signin-with-hostedUI","aws-amplify-federatedInfo","CognitoIdentityServiceProvider"],w=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,r,n;return t=e,n=[{key:"clear",value:function(){(document.cookie||"").split("; ").filter((function(e){return y.some((function(t){return e.trim().startsWith(t)}))})).map((function(t){return e.getCookieName(t)})).filter((function(t){var r=e.parseCookieName(t).userPoolId;return!r||r===e.userPoolId})).forEach((function(t){var r=e.parseCookieName(t);e.removeCookie(r)}))}},{key:"getItem",value:function(t){return e.getCookie(e.parseKey(t))}},{key:"removeItem",value:function(t){var r=e.parseKey(t),n=e.getCookie(r);return e.removeCookie(r),n}},{key:"setCookieStorage",value:function(t){e.cookieSettings=t}},{key:"setItem",value:function(t,r){var n=e.cookieSettings.expires;return e.setCookie(e.parseKey(t),r,n),r}},{key:"setUserPoolId",value:function(t){e.userPoolId=t}},{key:"sync",value:function(){return e.syncPromise}},{key:"generateCookieName",value:function(t){var r,n=t.scope,o=t.type,a=t.userId;return(r=[n,"CognitoIdentityServiceProvider"===n&&e.userPoolId,a,o],r.filter((function(e){return e&&null!=e}))).join(".")}},{key:"getCookie",value:function(t){var r=(document.cookie||"").split("; ").find((function(r){var n=e.getCookieName(r),o=r.trim().startsWith("".concat(e.generateCookieName(t),"=")),a=e.parseCookieName(n).userPoolId;return o&&(!a||a===e.userPoolId)}));return r?e.getCookieValue(r):void 0}},{key:"getCookieName",value:function(e){return e.split("=")[0]}},{key:"getCookieValue",value:function(e){return e.split("=")[1]}},{key:"parseCookieName",value:function(e){var t=m(e.split("."),4),r=t[0],n=t[1],o=t[2];return{scope:r,type:t[3],userId:o,userPoolId:n}}},{key:"parseKey",value:function(e){var t=m(e.split("."),4),r=t[0],n=t[1],o=t[2],a=t[3];return"LastAuthUser"===o?{clientId:n,scope:r,type:"LastAuthUser"}:{clientId:n,scope:r,type:a,userId:o}}},{key:"removeCookie",value:function(t){e.getCookie(t)&&e.setCookie(t,"",-1)}},{key:"setCookie",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:365,a=new Date;a.setDate(a.getDate()+o);var i=(l(n={},e.generateCookieName(t),r),l(n,"path",e.cookieSettings.path||"/"),l(n,"domain",e.cookieSettings.domain),l(n,"max-age",86400*o),l(n,"expires",a.toISOString()),l(n,"samesite",e.cookieSettings.sameSite),n);e.cookieSettings.secure&&(i.secure=!0),document.cookie=Object.entries(i).map((function(e){var t=m(e,2),r=t[0],n=t[1];return"".concat(r,"=").concat(n)})).join("; ")}}],(r=null)&&d(t.prototype,r),n&&d(t,n),e}();w.syncPromise=Promise.resolve();var P=function(e){var t=e.getIdToken().payload;return Object.keys(t).filter((function(e){return e.startsWith("custom:")})).reduce((function(e,r){return g({},e,l({},r.substr("custom:".length),t[r]))}),{})},k=function(e,t){r.dispatch("custom",{data:{errorDetails:t,errorType:e},event:"error"})},I=function(e){Object.entries(e).forEach((function(e){var t=m(e,2),r=t[0],n=t[1];S[r]=n})),C=Date.now(),r.dispatch("custom",{event:"cacheUpdated"})},b=function(e){var t=e.getIdToken().payload;I({customProperties:P(e),emailAddress:t.email,familyName:t.familyName,fullName:t.name,givenName:t.givenName,groups:t["cognito:groups"]||[],id:t.sub,isSignedIn:!0})},S={currentMode:void 0,customProperties:{},defaultMode:void 0,emailAddress:void 0,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isInitialized:!1,isSignedIn:!1},C=Date.now(),R=!1,N={get customProperties(){return g({},S.customProperties)},get emailAddress(){return S.emailAddress},get familyName(){return S.familyName},get fullName(){return S.fullName},get givenName(){return S.givenName},get groups(){return S.groups},get id(){return S.id},get isInitialized(){return S.isInitialized},get isSignedIn(){return S.isSignedIn},get mode(){return S.currentMode},get type(){return S.defaultMode}},O=function(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=a.amplifyConfig,d=a.oAuthConfig,l=a.onCompleteForcedPasswordChange,f=a.onCompletePasswordChange,p=a.onCompletePasswordReset,y=a.onError,O=a.onInit,A=a.onRequestPasswordReset,M=a.onSessionRefresh,x=a.onSignIn,j=a.onSignOut,z=a.type,D=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],U=n(C),E=m(U,2),T=E[0],q=E[1],_=n(),W=m(_,2),F=W[0],K=W[1],Y=!0;o((function(){return function(){return Y=!1}}),[]),o((function(){var e=r.listen("auth",(function(e){var r=e.payload,n=r.data,o=r.event;if(Y)switch(o){case"forgotPassword":I({currentMode:"confirmResetPassword"}),h(A)&&A();break;case"forgotPassword_failure":h(y)&&y("requestPasswordReset",n);break;case"forgotPasswordSubmit":I({currentMode:S.defaultMode}),h(p)&&p();break;case"forgotPasswordSubmit_failure":h(y)&&y("completePasswordReset",n);break;case"signIn":b(n.signInUserSession),h(x)&&x(n.signInUserSession);break;case"signIn_failure":h(y)&&y("signIn",n);break;case"signOut":I({customProperties:{},emailAddress:void 0,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isSignedIn:!1}),h(j)&&j();break;case"signOut_failure":h(y)&&y("signOut",n);break;case"tokenRefresh":h(M)&&t.currentSession().then((function(e){M(e)}));break;case"tokenRefresh_failure":h(y)&&y("sessionRefresh",n)}})),n=r.listen("custom",(function(e){var t=e.payload,r=t.data,n=t.event;if(Y)switch(n){case"cacheUpdated":q(C);break;case"error":h(y)&&y(r.errorType,r.errorDetails)}}));return function(){e(),n()}}),D),o((function(){C>T&&q(C)}),[C]),o((function(){void 0===S.defaultMode?I({currentMode:z||"internal",defaultMode:z||"internal"}):void 0!==z&&z!==S.defaultMode&&v('You tried to change the authorization type to "'.concat(z,'", but it has already been initialized to "').concat(S.defaultMode,'". The type cannot be changed after initialization as this could cause unexpected behavior\n\n(If authorization was initialized with anything other than the default "internal", you will need to specify the type each time you call useAuthorization() in order to avoid this warning)'))}),[z]),o((function(){if(!S.isInitialized&&i&&d){var r=i.Auth;r.hasOwnProperty("cookieStorage")?(w.setCookieStorage(r.cookieStorage),w.setUserPoolId(r.userPoolId),e.configure(g({},i,{Auth:g({},r,{storage:w})}))):e.configure(i),t.configure({oauth:d}),I({isInitialized:!0})}}),[i,d]),o((function(){!R&&S.isInitialized&&(t.currentSession().then((function(e){b(e),h(O)&&O(e)})).catch((function(){h(O)&&O()})),R=!0)}),[S.isInitialized]);var V=function(e,r){return function(){var n;if(S.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){k(r,e)}))}else v("You tried to call ".concat(r,"() before AWS Amplify was initialized. Please provide values for amplifyConfig & oAuthConfig to get set up"));return n}},L=function(){I({currentMode:S.defaultMode})},J=function(e){t.completeNewPassword(F,e).then((function(){K(void 0),I({currentMode:S.defaultMode}),h(l)&&l()})).catch((function(e){k("completeForcedPasswordChange",e)}))},Q=function(e,r){var n;return regeneratorRuntime.async((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,regeneratorRuntime.awrap(t.currentAuthenticatedUser());case 2:n=o.sent,t.changePassword(n,e,r).then((function(){I({currentMode:S.defaultMode}),h(f)&&f()})).catch((function(e){k("completePasswordChange",e)}));case 4:case"end":return o.stop()}}))},B=function(e,r,n){"confirmResetPassword"===S.currentMode?(n&&n!==S.emailAddress&&I({emailAddress:n}),t.forgotPasswordSubmit(S.emailAddress,r,e).catch((function(e){k("completePasswordReset",e)}))):(v("You tried to call completePasswordReset() without first requesting a reset code. Please call requestPasswordReset() first"),k("completePasswordReset"))},G=function(e,r){var n;return regeneratorRuntime.async((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,regeneratorRuntime.awrap(t.signIn(e,r));case 2:return(n=o.sent)&&"NEW_PASSWORD_REQUIRED"===n.challengeName&&(K(n),I({currentMode:"forceChangePassword"})),o.abrupt("return",n);case 5:case"end":return o.stop()}}))},H=function(e){"requestResetPassword"===S.currentMode?(I({emailAddress:e}),t.forgotPassword(e).catch((function(e){k("requestPasswordReset",e)}))):(v("You tried to call requestPasswordReset() outside of the reset password flow. Please call startPasswordReset() first"),k("requestPasswordReset"))},X=function(){I({currentMode:"changePassword"})},Z=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];I({currentMode:e?"confirmResetPassword":"requestResetPassword"})},$=function(){var e,r,n,o,a=arguments;return regeneratorRuntime.async((function(i){for(;;)switch(i.prev=i.next){case 0:return e=a.length>0&&void 0!==a[0]&&a[0],i.next=3,regeneratorRuntime.awrap(t.currentSession());case 3:return r=i.sent,n=r.getIdToken().payload,!(o=n.sub===S.id)&&e&&I({currentMode:S.defaultMode,customProperties:P(r),emailAddress:n.email,familyName:n.familyName,fullName:n.name,givenName:n.givenName,groups:n["cognito:groups"]||[],id:n.sub}),i.abrupt("return",o);case 8:case"end":return i.stop()}}))},ee={getSession:V(u,"getSession"),getUser:V(s,"getUser"),refreshSession:V(c,"refreshSession"),signOut:V(t.signOut,"signOut"),verifySession:V($,"verifySession")},te=g({},ee,{signIn:V(t.federatedSignIn,"signIn")}),re=g({},ee,{cancelPasswordChange:V(L,"cancelPasswordChange"),cancelPasswordReset:V(L,"cancelPasswordReset"),completeForcedPasswordChange:V(J,"completeForcedPasswordChange"),completePasswordChange:V(Q,"completePasswordChange"),completePasswordReset:V(B,"completePasswordReset"),requestPasswordReset:V(H,"requestPasswordReset"),signIn:V(G,"signIn"),startPasswordChange:V(X,"startPasswordChange"),startPasswordReset:V(Z,"startPasswordReset")});return[g({},N),"external"===S.defaultMode?te:re]};export{a as getAuthorizationToken,i as getIdTokenExpiry,s as getUser,u as getUserSession,c as refreshUserSession,O as useAuthorization};
1
+ import e,{Auth as t,Hub as r}from"aws-amplify";import{useState as n,useEffect as o}from"react";import"react-dom/server";var s=function(e){return e.getIdToken().getJwtToken()},a=function(e){return new Date(1e3*e.getIdToken().getExpiration())},i=function(){var e;return regeneratorRuntime.async((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,regeneratorRuntime.awrap(t.currentAuthenticatedUser());case 2:return e=r.sent,r.abrupt("return",e);case 4:case"end":return r.stop()}}))},u=function(){var e;return regeneratorRuntime.async((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,regeneratorRuntime.awrap(t.currentSession());case 2:return e=r.sent,r.abrupt("return",e);case 4:case"end":return r.stop()}}))},c=function(){var e;return regeneratorRuntime.async((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,regeneratorRuntime.awrap(u());case 2:return e=t.sent,t.next=5,regeneratorRuntime.awrap(i());case 5:t.sent.refreshSession(e.getRefreshToken(),(function(){return null}));case 7:case"end":return t.stop()}}))};function d(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function f(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 l(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(r,!0).forEach((function(t){d(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(r).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e))&&"[object Arguments]"!==Object.prototype.toString.call(e))return;var r=[],n=!0,o=!1,s=void 0;try{for(var a,i=e[Symbol.iterator]();!(n=(a=i.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,s=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw s}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var m=function(e){console.error(e)},p=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];"production"!==process.env.NODE_ENV&&t&&m(e)},h=function(e){return"function"==typeof e},w=function(e){var t=e.getIdToken().payload;return Object.keys(t).filter((function(e){return e.startsWith("custom:")})).reduce((function(e,r){return l({},e,d({},r.substr("custom:".length),t[r]))}),{})},v=function(e,t){r.dispatch("custom",{data:{errorDetails:t,errorType:e},event:"error"})},P=function(e){Object.entries(e).forEach((function(e){var t=g(e,2),r=t[0],n=t[1];b[r]=n})),R=Date.now(),r.dispatch("custom",{event:"cacheUpdated"})},y=function(e){var t=e.getIdToken().payload;P({customProperties:w(e),emailAddress:t.email,familyName:t.familyName,fullName:t.name,givenName:t.givenName,groups:t["cognito:groups"]||[],id:t.sub,isSignedIn:!0})},b={currentMode:void 0,customProperties:{},defaultMode:void 0,emailAddress:void 0,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isInitialized:!1,isSignedIn:!1},R=Date.now(),I=!1,S={get customProperties(){return l({},b.customProperties)},get emailAddress(){return b.emailAddress},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 mode(){return b.currentMode},get type(){return b.defaultMode}},O=function(){var s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=s.amplifyConfig,d=s.oAuthConfig,f=s.onCompleteForcedPasswordChange,m=s.onCompletePasswordChange,O=s.onCompletePasswordReset,N=s.onError,M=s.onInit,A=s.onRequestPasswordReset,k=s.onSessionRefresh,C=s.onSignIn,x=s.onSignOut,j=s.type,z=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],D=n(R),q=g(D,2),E=q[0],T=q[1],U=n(),_=g(U,2),F=_[0],W=_[1],Y=!0;o((function(){return function(){return Y=!1}}),[]),o((function(){var e=r.listen("auth",(function(e){var r=e.payload,n=r.data,o=r.event;if(Y)switch(o){case"forgotPassword":P({currentMode:"confirmResetPassword"}),h(A)&&A();break;case"forgotPassword_failure":h(N)&&N("requestPasswordReset",n);break;case"forgotPasswordSubmit":P({currentMode:b.defaultMode}),h(O)&&O();break;case"forgotPasswordSubmit_failure":h(N)&&N("completePasswordReset",n);break;case"signIn":y(n.signInUserSession),h(C)&&C(n.signInUserSession);break;case"signIn_failure":h(N)&&N("signIn",n);break;case"signOut":P({customProperties:{},emailAddress:void 0,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isSignedIn:!1}),h(x)&&x();break;case"signOut_failure":h(N)&&N("signOut",n);break;case"tokenRefresh":h(k)&&t.currentSession().then((function(e){k(e)}));break;case"tokenRefresh_failure":h(N)&&N("sessionRefresh",n)}})),n=r.listen("custom",(function(e){var t=e.payload,r=t.data,n=t.event;if(Y)switch(n){case"cacheUpdated":T(R);break;case"error":h(N)&&N(r.errorType,r.errorDetails)}}));return function(){e(),n()}}),z),o((function(){R>E&&T(R)}),[R]),o((function(){void 0===b.defaultMode?P({currentMode:j||"internal",defaultMode:j||"internal"}):void 0!==j&&j!==b.defaultMode&&p('You tried to change the authorization type to "'.concat(j,'", but it has already been initialized to "').concat(b.defaultMode,'". The type cannot be changed after initialization as this could cause unexpected behavior\n\n(If authorization was initialized with anything other than the default "internal", you will need to specify the type each time you call useAuthorization() in order to avoid this warning)'))}),[j]),o((function(){!b.isInitialized&&a&&d&&(e.configure(a),t.configure({oauth:d}),P({isInitialized:!0}))}),[a,d]),o((function(){!I&&b.isInitialized&&(t.currentSession().then((function(e){y(e),h(M)&&M(e)})).catch((function(){h(M)&&M()})),I=!0)}),[b.isInitialized]);var J=function(e,r){return function(){var n;if(b.isInitialized){for(var o=arguments.length,s=new Array(o),a=0;a<o;a++)s[a]=arguments[a];(n=e.call.apply(e,[t].concat(s)))instanceof Promise&&n.catch((function(e){v(r,e)}))}else p("You tried to call ".concat(r,"() before AWS Amplify was initialized. Please provide values for amplifyConfig & oAuthConfig to get set up"));return n}},Q=function(){P({currentMode:b.defaultMode})},V=function(e){t.completeNewPassword(F,e).then((function(){W(void 0),P({currentMode:b.defaultMode}),h(f)&&f()})).catch((function(e){v("completeForcedPasswordChange",e)}))},B=function(e,r){var n;return regeneratorRuntime.async((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,regeneratorRuntime.awrap(t.currentAuthenticatedUser());case 2:n=o.sent,t.changePassword(n,e,r).then((function(){P({currentMode:b.defaultMode}),h(m)&&m()})).catch((function(e){v("completePasswordChange",e)}));case 4:case"end":return o.stop()}}))},G=function(e,r,n){"confirmResetPassword"===b.currentMode?(n&&n!==b.emailAddress&&P({emailAddress:n}),t.forgotPasswordSubmit(b.emailAddress,r,e).catch((function(e){v("completePasswordReset",e)}))):(p("You tried to call completePasswordReset() without first requesting a reset code. Please call requestPasswordReset() first"),v("completePasswordReset"))},H=function(e,r){var n;return regeneratorRuntime.async((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,regeneratorRuntime.awrap(t.signIn(e,r));case 2:return(n=o.sent)&&"NEW_PASSWORD_REQUIRED"===n.challengeName&&(W(n),P({currentMode:"forceChangePassword"})),o.abrupt("return",n);case 5:case"end":return o.stop()}}))},K=function(e){"requestResetPassword"===b.currentMode?(P({emailAddress:e}),t.forgotPassword(e).catch((function(e){v("requestPasswordReset",e)}))):(p("You tried to call requestPasswordReset() outside of the reset password flow. Please call startPasswordReset() first"),v("requestPasswordReset"))},L=function(){P({currentMode:"changePassword"})},X=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];P({currentMode:e?"confirmResetPassword":"requestResetPassword"})},Z=function(){var e,r,n,o,s=arguments;return regeneratorRuntime.async((function(a){for(;;)switch(a.prev=a.next){case 0:return e=s.length>0&&void 0!==s[0]&&s[0],a.next=3,regeneratorRuntime.awrap(t.currentSession());case 3:return r=a.sent,n=r.getIdToken().payload,!(o=n.sub===b.id)&&e&&P({currentMode:b.defaultMode,customProperties:w(r),emailAddress:n.email,familyName:n.familyName,fullName:n.name,givenName:n.givenName,groups:n["cognito:groups"]||[],id:n.sub}),a.abrupt("return",o);case 8:case"end":return a.stop()}}))},$={getSession:J(u,"getSession"),getUser:J(i,"getUser"),refreshSession:J(c,"refreshSession"),signOut:J(t.signOut,"signOut"),verifySession:J(Z,"verifySession")},ee=l({},$,{signIn:J(t.federatedSignIn,"signIn")}),te=l({},$,{cancelPasswordChange:J(Q,"cancelPasswordChange"),cancelPasswordReset:J(Q,"cancelPasswordReset"),completeForcedPasswordChange:J(V,"completeForcedPasswordChange"),completePasswordChange:J(B,"completePasswordChange"),completePasswordReset:J(G,"completePasswordReset"),requestPasswordReset:J(K,"requestPasswordReset"),signIn:J(H,"signIn"),startPasswordChange:J(L,"startPasswordChange"),startPasswordReset:J(X,"startPasswordReset")});return[l({},S),"external"===b.defaultMode?ee:te]};export{s as getAuthorizationToken,a as getIdTokenExpiry,i as getUser,u as getUserSession,c as refreshUserSession,O as useAuthorization};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("aws-amplify"),require("react"),require("react-dom/server")):"function"==typeof define&&define.amd?define(["exports","aws-amplify","react","react-dom/server"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WJECOne={},e.Amplify,e.React)}(this,(function(e,t,r){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(t),i=function(){var e;return regeneratorRuntime.async((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,regeneratorRuntime.awrap(t.Auth.currentAuthenticatedUser());case 2:return e=r.sent,r.abrupt("return",e);case 4:case"end":return r.stop()}}))},a=function(){var e;return regeneratorRuntime.async((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,regeneratorRuntime.awrap(t.Auth.currentSession());case 2:return e=r.sent,r.abrupt("return",e);case 4:case"end":return r.stop()}}))},s=function(){var e;return regeneratorRuntime.async((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,regeneratorRuntime.awrap(a());case 2:return e=t.sent,t.next=5,regeneratorRuntime.awrap(i());case 5:t.sent.refreshSession(e.getRefreshToken(),(function(){return null}));case 7:case"end":return t.stop()}}))};function u(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 c(e,t,r){return 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 f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(r,!0).forEach((function(t){c(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(r).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e))&&"[object Arguments]"!==Object.prototype.toString.call(e))return;var r=[],n=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==s.return||s.return()}finally{if(o)throw i}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var g=function(e){console.error(e)},p=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];"production"!==process.env.NODE_ENV&&t&&g(e)},m=function(e){return"function"==typeof e},h=["amplify-signin-with-hostedUI","aws-amplify-federatedInfo","CognitoIdentityServiceProvider"],v=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,r,n;return t=e,n=[{key:"clear",value:function(){(document.cookie||"").split("; ").filter((function(e){return h.some((function(t){return e.trim().startsWith(t)}))})).map((function(t){return e.getCookieName(t)})).filter((function(t){var r=e.parseCookieName(t).userPoolId;return!r||r===e.userPoolId})).forEach((function(t){var r=e.parseCookieName(t);e.removeCookie(r)}))}},{key:"getItem",value:function(t){return e.getCookie(e.parseKey(t))}},{key:"removeItem",value:function(t){var r=e.parseKey(t),n=e.getCookie(r);return e.removeCookie(r),n}},{key:"setCookieStorage",value:function(t){e.cookieSettings=t}},{key:"setItem",value:function(t,r){var n=e.cookieSettings.expires;return e.setCookie(e.parseKey(t),r,n),r}},{key:"setUserPoolId",value:function(t){e.userPoolId=t}},{key:"sync",value:function(){return e.syncPromise}},{key:"generateCookieName",value:function(t){var r,n=t.scope,o=t.type,i=t.userId;return(r=[n,"CognitoIdentityServiceProvider"===n&&e.userPoolId,i,o],r.filter((function(e){return e&&null!=e}))).join(".")}},{key:"getCookie",value:function(t){var r=(document.cookie||"").split("; ").find((function(r){var n=e.getCookieName(r),o=r.trim().startsWith("".concat(e.generateCookieName(t),"=")),i=e.parseCookieName(n).userPoolId;return o&&(!i||i===e.userPoolId)}));return r?e.getCookieValue(r):void 0}},{key:"getCookieName",value:function(e){return e.split("=")[0]}},{key:"getCookieValue",value:function(e){return e.split("=")[1]}},{key:"parseCookieName",value:function(e){var t=l(e.split("."),4),r=t[0],n=t[1],o=t[2];return{scope:r,type:t[3],userId:o,userPoolId:n}}},{key:"parseKey",value:function(e){var t=l(e.split("."),4),r=t[0],n=t[1],o=t[2],i=t[3];return"LastAuthUser"===o?{clientId:n,scope:r,type:"LastAuthUser"}:{clientId:n,scope:r,type:i,userId:o}}},{key:"removeCookie",value:function(t){e.getCookie(t)&&e.setCookie(t,"",-1)}},{key:"setCookie",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:365,i=new Date;i.setDate(i.getDate()+o);var a=(c(n={},e.generateCookieName(t),r),c(n,"path",e.cookieSettings.path||"/"),c(n,"domain",e.cookieSettings.domain),c(n,"max-age",86400*o),c(n,"expires",i.toISOString()),c(n,"samesite",e.cookieSettings.sameSite),n);e.cookieSettings.secure&&(a.secure=!0),document.cookie=Object.entries(a).map((function(e){var t=l(e,2),r=t[0],n=t[1];return"".concat(r,"=").concat(n)})).join("; ")}}],(r=null)&&u(t.prototype,r),n&&u(t,n),e}();v.syncPromise=Promise.resolve();var y="custom:",w=function(e){var t=e.getIdToken().payload;return Object.keys(t).filter((function(e){return e.startsWith(y)})).reduce((function(e,r){return f({},e,c({},r.substr(y.length),t[r]))}),{})},P=function(e,r){t.Hub.dispatch("custom",{data:{errorDetails:r,errorType:e},event:"error"})},k=function(e){Object.entries(e).forEach((function(e){var t=l(e,2),r=t[0],n=t[1];I[r]=n})),S=Date.now(),t.Hub.dispatch("custom",{event:"cacheUpdated"})},b=function(e){var t=e.getIdToken().payload;k({customProperties:w(e),emailAddress:t.email,familyName:t.familyName,fullName:t.name,givenName:t.givenName,groups:t["cognito:groups"]||[],id:t.sub,isSignedIn:!0})},I={currentMode:void 0,customProperties:{},defaultMode:void 0,emailAddress:void 0,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isInitialized:!1,isSignedIn:!1},S=Date.now(),C=!1,R={get customProperties(){return f({},I.customProperties)},get emailAddress(){return I.emailAddress},get familyName(){return I.familyName},get fullName(){return I.fullName},get givenName(){return I.givenName},get groups(){return I.groups},get id(){return I.id},get isInitialized(){return I.isInitialized},get isSignedIn(){return I.isSignedIn},get mode(){return I.currentMode},get type(){return I.defaultMode}};e.getAuthorizationToken=function(e){return e.getIdToken().getJwtToken()},e.getIdTokenExpiry=function(e){return new Date(1e3*e.getIdToken().getExpiration())},e.getUser=i,e.getUserSession=a,e.refreshUserSession=s,e.useAuthorization=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.amplifyConfig,u=e.oAuthConfig,c=e.onCompleteForcedPasswordChange,d=e.onCompletePasswordChange,g=e.onCompletePasswordReset,h=e.onError,y=e.onInit,A=e.onRequestPasswordReset,N=e.onSessionRefresh,O=e.onSignIn,M=e.onSignOut,x=e.type,j=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],E=r.useState(S),z=l(E,2),U=z[0],T=z[1],D=r.useState(),q=l(D,2),_=q[0],W=q[1],F=!0;r.useEffect((function(){return function(){return F=!1}}),[]),r.useEffect((function(){var e=t.Hub.listen("auth",(function(e){var r=e.payload,n=r.data,o=r.event;if(F)switch(o){case"forgotPassword":k({currentMode:"confirmResetPassword"}),m(A)&&A();break;case"forgotPassword_failure":m(h)&&h("requestPasswordReset",n);break;case"forgotPasswordSubmit":k({currentMode:I.defaultMode}),m(g)&&g();break;case"forgotPasswordSubmit_failure":m(h)&&h("completePasswordReset",n);break;case"signIn":b(n.signInUserSession),m(O)&&O(n.signInUserSession);break;case"signIn_failure":m(h)&&h("signIn",n);break;case"signOut":k({customProperties:{},emailAddress:void 0,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isSignedIn:!1}),m(M)&&M();break;case"signOut_failure":m(h)&&h("signOut",n);break;case"tokenRefresh":m(N)&&t.Auth.currentSession().then((function(e){N(e)}));break;case"tokenRefresh_failure":m(h)&&h("sessionRefresh",n)}})),r=t.Hub.listen("custom",(function(e){var t=e.payload,r=t.data,n=t.event;if(F)switch(n){case"cacheUpdated":T(S);break;case"error":m(h)&&h(r.errorType,r.errorDetails)}}));return function(){e(),r()}}),j),r.useEffect((function(){S>U&&T(S)}),[S]),r.useEffect((function(){void 0===I.defaultMode?k({currentMode:x||"internal",defaultMode:x||"internal"}):void 0!==x&&x!==I.defaultMode&&p('You tried to change the authorization type to "'.concat(x,'", but it has already been initialized to "').concat(I.defaultMode,'". The type cannot be changed after initialization as this could cause unexpected behavior\n\n(If authorization was initialized with anything other than the default "internal", you will need to specify the type each time you call useAuthorization() in order to avoid this warning)'))}),[x]),r.useEffect((function(){if(!I.isInitialized&&n&&u){var e=n.Auth;e.hasOwnProperty("cookieStorage")?(v.setCookieStorage(e.cookieStorage),v.setUserPoolId(e.userPoolId),o.default.configure(f({},n,{Auth:f({},e,{storage:v})}))):o.default.configure(n),t.Auth.configure({oauth:u}),k({isInitialized:!0})}}),[n,u]),r.useEffect((function(){!C&&I.isInitialized&&(t.Auth.currentSession().then((function(e){b(e),m(y)&&y(e)})).catch((function(){m(y)&&y()})),C=!0)}),[I.isInitialized]);var H=function(e,r){return function(){var n;if(I.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.Auth].concat(i)))instanceof Promise&&n.catch((function(e){P(r,e)}))}else p("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(){k({currentMode:I.defaultMode})},Y=function(e){t.Auth.completeNewPassword(_,e).then((function(){W(void 0),k({currentMode:I.defaultMode}),m(c)&&c()})).catch((function(e){P("completeForcedPasswordChange",e)}))},V=function(e,r){var n;return regeneratorRuntime.async((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,regeneratorRuntime.awrap(t.Auth.currentAuthenticatedUser());case 2:n=o.sent,t.Auth.changePassword(n,e,r).then((function(){k({currentMode:I.defaultMode}),m(d)&&d()})).catch((function(e){P("completePasswordChange",e)}));case 4:case"end":return o.stop()}}))},J=function(e,r,n){"confirmResetPassword"===I.currentMode?(n&&n!==I.emailAddress&&k({emailAddress:n}),t.Auth.forgotPasswordSubmit(I.emailAddress,r,e).catch((function(e){P("completePasswordReset",e)}))):(p("You tried to call completePasswordReset() without first requesting a reset code. Please call requestPasswordReset() first"),P("completePasswordReset"))},L=function(e,r){var n;return regeneratorRuntime.async((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,regeneratorRuntime.awrap(t.Auth.signIn(e,r));case 2:return(n=o.sent)&&"NEW_PASSWORD_REQUIRED"===n.challengeName&&(W(n),k({currentMode:"forceChangePassword"})),o.abrupt("return",n);case 5:case"end":return o.stop()}}))},Q=function(e){"requestResetPassword"===I.currentMode?(k({emailAddress:e}),t.Auth.forgotPassword(e).catch((function(e){P("requestPasswordReset",e)}))):(p("You tried to call requestPasswordReset() outside of the reset password flow. Please call startPasswordReset() first"),P("requestPasswordReset"))},B=function(){k({currentMode:"changePassword"})},G=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];k({currentMode:e?"confirmResetPassword":"requestResetPassword"})},X=function(){var e,r,n,o,i=arguments;return regeneratorRuntime.async((function(a){for(;;)switch(a.prev=a.next){case 0:return e=i.length>0&&void 0!==i[0]&&i[0],a.next=3,regeneratorRuntime.awrap(t.Auth.currentSession());case 3:return r=a.sent,n=r.getIdToken().payload,!(o=n.sub===I.id)&&e&&k({currentMode:I.defaultMode,customProperties:w(r),emailAddress:n.email,familyName:n.familyName,fullName:n.name,givenName:n.givenName,groups:n["cognito:groups"]||[],id:n.sub}),a.abrupt("return",o);case 8:case"end":return a.stop()}}))},Z={getSession:H(a,"getSession"),getUser:H(i,"getUser"),refreshSession:H(s,"refreshSession"),signOut:H(t.Auth.signOut,"signOut"),verifySession:H(X,"verifySession")},$=f({},Z,{signIn:H(t.Auth.federatedSignIn,"signIn")}),ee=f({},Z,{cancelPasswordChange:H(K,"cancelPasswordChange"),cancelPasswordReset:H(K,"cancelPasswordReset"),completeForcedPasswordChange:H(Y,"completeForcedPasswordChange"),completePasswordChange:H(V,"completePasswordChange"),completePasswordReset:H(J,"completePasswordReset"),requestPasswordReset:H(Q,"requestPasswordReset"),signIn:H(L,"signIn"),startPasswordChange:H(B,"startPasswordChange"),startPasswordReset:H(G,"startPasswordReset")});return[f({},R),"external"===I.defaultMode?$:ee]},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("aws-amplify"),require("react"),require("react-dom/server")):"function"==typeof define&&define.amd?define(["exports","aws-amplify","react","react-dom/server"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WJECOne={},e.Amplify,e.React)}(this,(function(e,t,r){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(t),s=function(){var e;return regeneratorRuntime.async((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,regeneratorRuntime.awrap(t.Auth.currentAuthenticatedUser());case 2:return e=r.sent,r.abrupt("return",e);case 4:case"end":return r.stop()}}))},a=function(){var e;return regeneratorRuntime.async((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,regeneratorRuntime.awrap(t.Auth.currentSession());case 2:return e=r.sent,r.abrupt("return",e);case 4:case"end":return r.stop()}}))},i=function(){var e;return regeneratorRuntime.async((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,regeneratorRuntime.awrap(a());case 2:return e=t.sent,t.next=5,regeneratorRuntime.awrap(s());case 5:t.sent.refreshSession(e.getRefreshToken(),(function(){return null}));case 7:case"end":return t.stop()}}))};function u(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function c(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 d(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?c(r,!0).forEach((function(t){u(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):c(r).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e))&&"[object Arguments]"!==Object.prototype.toString.call(e))return;var r=[],n=!0,o=!1,s=void 0;try{for(var a,i=e[Symbol.iterator]();!(n=(a=i.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,s=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw s}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l=function(e){console.error(e)},g=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];"production"!==process.env.NODE_ENV&&t&&l(e)},p=function(e){return"function"==typeof e},h="custom:",m=function(e){var t=e.getIdToken().payload;return Object.keys(t).filter((function(e){return e.startsWith(h)})).reduce((function(e,r){return d({},e,u({},r.substr(h.length),t[r]))}),{})},w=function(e,r){t.Hub.dispatch("custom",{data:{errorDetails:r,errorType:e},event:"error"})},v=function(e){Object.entries(e).forEach((function(e){var t=f(e,2),r=t[0],n=t[1];P[r]=n})),b=Date.now(),t.Hub.dispatch("custom",{event:"cacheUpdated"})},y=function(e){var t=e.getIdToken().payload;v({customProperties:m(e),emailAddress:t.email,familyName:t.familyName,fullName:t.name,givenName:t.givenName,groups:t["cognito:groups"]||[],id:t.sub,isSignedIn:!0})},P={currentMode:void 0,customProperties:{},defaultMode:void 0,emailAddress:void 0,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isInitialized:!1,isSignedIn:!1},b=Date.now(),R=!1,A={get customProperties(){return d({},P.customProperties)},get emailAddress(){return P.emailAddress},get familyName(){return P.familyName},get fullName(){return P.fullName},get givenName(){return P.givenName},get groups(){return P.groups},get id(){return P.id},get isInitialized(){return P.isInitialized},get isSignedIn(){return P.isSignedIn},get mode(){return P.currentMode},get type(){return P.defaultMode}};e.getAuthorizationToken=function(e){return e.getIdToken().getJwtToken()},e.getIdTokenExpiry=function(e){return new Date(1e3*e.getIdToken().getExpiration())},e.getUser=s,e.getUserSession=a,e.refreshUserSession=i,e.useAuthorization=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.amplifyConfig,u=e.oAuthConfig,c=e.onCompleteForcedPasswordChange,l=e.onCompletePasswordChange,h=e.onCompletePasswordReset,S=e.onError,I=e.onInit,O=e.onRequestPasswordReset,M=e.onSessionRefresh,N=e.onSignIn,k=e.onSignOut,x=e.type,C=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],E=r.useState(b),j=f(E,2),z=j[0],T=j[1],q=r.useState(),D=f(q,2),U=D[0],_=D[1],W=!0;r.useEffect((function(){return function(){return W=!1}}),[]),r.useEffect((function(){var e=t.Hub.listen("auth",(function(e){var r=e.payload,n=r.data,o=r.event;if(W)switch(o){case"forgotPassword":v({currentMode:"confirmResetPassword"}),p(O)&&O();break;case"forgotPassword_failure":p(S)&&S("requestPasswordReset",n);break;case"forgotPasswordSubmit":v({currentMode:P.defaultMode}),p(h)&&h();break;case"forgotPasswordSubmit_failure":p(S)&&S("completePasswordReset",n);break;case"signIn":y(n.signInUserSession),p(N)&&N(n.signInUserSession);break;case"signIn_failure":p(S)&&S("signIn",n);break;case"signOut":v({customProperties:{},emailAddress:void 0,familyName:void 0,fullName:void 0,givenName:void 0,groups:[],id:void 0,isSignedIn:!1}),p(k)&&k();break;case"signOut_failure":p(S)&&S("signOut",n);break;case"tokenRefresh":p(M)&&t.Auth.currentSession().then((function(e){M(e)}));break;case"tokenRefresh_failure":p(S)&&S("sessionRefresh",n)}})),r=t.Hub.listen("custom",(function(e){var t=e.payload,r=t.data,n=t.event;if(W)switch(n){case"cacheUpdated":T(b);break;case"error":p(S)&&S(r.errorType,r.errorDetails)}}));return function(){e(),r()}}),C),r.useEffect((function(){b>z&&T(b)}),[b]),r.useEffect((function(){void 0===P.defaultMode?v({currentMode:x||"internal",defaultMode:x||"internal"}):void 0!==x&&x!==P.defaultMode&&g('You tried to change the authorization type to "'.concat(x,'", but it has already been initialized to "').concat(P.defaultMode,'". The type cannot be changed after initialization as this could cause unexpected behavior\n\n(If authorization was initialized with anything other than the default "internal", you will need to specify the type each time you call useAuthorization() in order to avoid this warning)'))}),[x]),r.useEffect((function(){!P.isInitialized&&n&&u&&(o.default.configure(n),t.Auth.configure({oauth:u}),v({isInitialized:!0}))}),[n,u]),r.useEffect((function(){!R&&P.isInitialized&&(t.Auth.currentSession().then((function(e){y(e),p(I)&&I(e)})).catch((function(){p(I)&&I()})),R=!0)}),[P.isInitialized]);var F=function(e,r){return function(){var n;if(P.isInitialized){for(var o=arguments.length,s=new Array(o),a=0;a<o;a++)s[a]=arguments[a];(n=e.call.apply(e,[t.Auth].concat(s)))instanceof Promise&&n.catch((function(e){w(r,e)}))}else g("You tried to call ".concat(r,"() before AWS Amplify was initialized. Please provide values for amplifyConfig & oAuthConfig to get set up"));return n}},H=function(){v({currentMode:P.defaultMode})},Y=function(e){t.Auth.completeNewPassword(U,e).then((function(){_(void 0),v({currentMode:P.defaultMode}),p(c)&&c()})).catch((function(e){w("completeForcedPasswordChange",e)}))},J=function(e,r){var n;return regeneratorRuntime.async((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,regeneratorRuntime.awrap(t.Auth.currentAuthenticatedUser());case 2:n=o.sent,t.Auth.changePassword(n,e,r).then((function(){v({currentMode:P.defaultMode}),p(l)&&l()})).catch((function(e){w("completePasswordChange",e)}));case 4:case"end":return o.stop()}}))},Q=function(e,r,n){"confirmResetPassword"===P.currentMode?(n&&n!==P.emailAddress&&v({emailAddress:n}),t.Auth.forgotPasswordSubmit(P.emailAddress,r,e).catch((function(e){w("completePasswordReset",e)}))):(g("You tried to call completePasswordReset() without first requesting a reset code. Please call requestPasswordReset() first"),w("completePasswordReset"))},V=function(e,r){var n;return regeneratorRuntime.async((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,regeneratorRuntime.awrap(t.Auth.signIn(e,r));case 2:return(n=o.sent)&&"NEW_PASSWORD_REQUIRED"===n.challengeName&&(_(n),v({currentMode:"forceChangePassword"})),o.abrupt("return",n);case 5:case"end":return o.stop()}}))},B=function(e){"requestResetPassword"===P.currentMode?(v({emailAddress:e}),t.Auth.forgotPassword(e).catch((function(e){w("requestPasswordReset",e)}))):(g("You tried to call requestPasswordReset() outside of the reset password flow. Please call startPasswordReset() first"),w("requestPasswordReset"))},G=function(){v({currentMode:"changePassword"})},K=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];v({currentMode:e?"confirmResetPassword":"requestResetPassword"})},L=function(){var e,r,n,o,s=arguments;return regeneratorRuntime.async((function(a){for(;;)switch(a.prev=a.next){case 0:return e=s.length>0&&void 0!==s[0]&&s[0],a.next=3,regeneratorRuntime.awrap(t.Auth.currentSession());case 3:return r=a.sent,n=r.getIdToken().payload,!(o=n.sub===P.id)&&e&&v({currentMode:P.defaultMode,customProperties:m(r),emailAddress:n.email,familyName:n.familyName,fullName:n.name,givenName:n.givenName,groups:n["cognito:groups"]||[],id:n.sub}),a.abrupt("return",o);case 8:case"end":return a.stop()}}))},X={getSession:F(a,"getSession"),getUser:F(s,"getUser"),refreshSession:F(i,"refreshSession"),signOut:F(t.Auth.signOut,"signOut"),verifySession:F(L,"verifySession")},Z=d({},X,{signIn:F(t.Auth.federatedSignIn,"signIn")}),$=d({},X,{cancelPasswordChange:F(H,"cancelPasswordChange"),cancelPasswordReset:F(H,"cancelPasswordReset"),completeForcedPasswordChange:F(Y,"completeForcedPasswordChange"),completePasswordChange:F(J,"completePasswordChange"),completePasswordReset:F(Q,"completePasswordReset"),requestPasswordReset:F(B,"requestPasswordReset"),signIn:F(V,"signIn"),startPasswordChange:F(G,"startPasswordChange"),startPasswordReset:F(K,"startPasswordReset")});return[d({},A),"external"===P.defaultMode?Z:$]},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("immutable")):"function"==typeof define&&define.amd?define(["exports","immutable"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WJECOne={},e.Immutable)}(this,(function(e,t){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=o(t);e.arrayToTypedList=function(e,t){return n.default.fromJS(e,t)},e.objectToTypedMap=function(e,t){return n.default.fromJS(e,t)},Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wjec-one",
3
- "version": "3.8.2",
3
+ "version": "3.9.2",
4
4
  "description": "",
5
5
  "main": "legacy/index.js",
6
6
  "module": "index.js",
@@ -69,13 +69,13 @@
69
69
  "fork-ts-checker-webpack-plugin": "^1.3.7",
70
70
  "glob": "^7.1.4",
71
71
  "html-webpack-plugin": "^3.2.0",
72
- "immutable": "^4.0.0-rc.12",
72
+ "immutable": "^4.0.0",
73
73
  "jest": "^24.8.0",
74
74
  "jest-emotion": "^10.0.32",
75
75
  "jest-fetch-mock": "^2.1.2",
76
76
  "jest-junit": "^7.0.0",
77
77
  "mockdate": "^2.0.5",
78
- "npm-cli-login": "^1.0.0",
78
+ "npm-cli-login": "^0.1.1",
79
79
  "react": "^16.8.6",
80
80
  "react-app-polyfill": "^2.0.0",
81
81
  "react-dom": "^16.8.6",
@@ -100,7 +100,7 @@
100
100
  "react-swipeable": "^5.5.1"
101
101
  },
102
102
  "optionalDependencies": {
103
- "immutable": ">=4.0.0-rc.12"
103
+ "immutable": ">=4.0.0"
104
104
  },
105
105
  "peerDependencies": {
106
106
  "@emotion/core": ">=10.0.14",
package/store/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { Dispatch, Reducer } from 'react';
2
- import { Collection, List, Record } from 'immutable';
2
+ import { List, Map, Record } from 'immutable';
3
3
  export declare type Action = AsyncAction | SimpleAction;
4
4
  export declare type AsyncAction = (dispatch: Dispatch<Action>, state: DestructurableRecord<any>) => void | Promise<void>;
5
5
  export declare type DestructurableRecord<T extends {}> = Record<T> & {
@@ -17,12 +17,16 @@ export interface TypedList<T> extends List<TypeOrListOrTypedMap<T>> {
17
17
  toJS(): T[];
18
18
  }
19
19
  export declare type TypeOrListOrTypedMap<T> = T extends any[] ? TypedList<T[number]> : (T extends Date ? Date : T extends object ? TypedMap<T> : T);
20
- export interface TypedMap<T> extends Collection.Keyed<keyof T, any> {
20
+ export interface TypedMap<T> extends Map<keyof T, any> {
21
21
  get<K extends keyof T>(key: K, notSetValue?: TypeOrListOrTypedMap<T[K]>): TypeOrListOrTypedMap<T[K]>;
22
- getIn<K1 extends keyof T, K2 extends (keyof T[K1]) | undefined = undefined, K3 extends (keyof T[K1][K2]) | undefined = undefined, K4 extends (keyof T[K1][K2][K3]) | undefined = undefined, K5 extends (keyof T[K1][K2][K3][K4]) | undefined = undefined, K6 extends (keyof T[K1][K2][K3][K4][K5]) | undefined = undefined, R = (K6 extends undefined ? never : TypeOrListOrTypedMap<T[K1][K2][K3][K4][K5][K6]>) | (K5 extends undefined ? never : K6 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3][K4][K5]> : never) | (K4 extends undefined ? never : K5 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3][K4]> : never) | (K3 extends undefined ? never : K4 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3]> : never) | (K2 extends undefined ? never : K3 extends undefined ? TypeOrListOrTypedMap<T[K1][K2]> : never) | (K2 extends undefined ? TypeOrListOrTypedMap<T[K1]> : never)>(searchKeyPath: [K1] | [K1, K2] | [K1, K2, K3] | [K1, K2, K3, K4] | [K1, K2, K3, K4, K5] | [K1, K2, K3, K4, K5, K6], notSetValue?: R): R;
22
+ getIn<K1 extends keyof T, K2 extends (keyof T[K1]) | undefined = undefined, K3 extends (keyof T[K1][K2]) | undefined = undefined, K4 extends (keyof T[K1][K2][K3]) | undefined = undefined, K5 extends (keyof T[K1][K2][K3][K4]) | undefined = undefined, K6 extends (keyof T[K1][K2][K3][K4][K5]) | undefined = undefined, R extends unknown = (K6 extends undefined ? unknown : TypeOrListOrTypedMap<T[K1][K2][K3][K4][K5][K6]>) | (K5 extends undefined ? unknown : K6 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3][K4][K5]> : unknown) | (K4 extends undefined ? unknown : K5 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3][K4]> : unknown) | (K3 extends undefined ? unknown : K4 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3]> : unknown) | (K2 extends undefined ? unknown : K3 extends undefined ? TypeOrListOrTypedMap<T[K1][K2]> : unknown) | (K2 extends undefined ? TypeOrListOrTypedMap<T[K1]> : unknown)>(searchKeyPath: [K1] | [K1, K2] | [K1, K2, K3] | [K1, K2, K3, K4] | [K1, K2, K3, K4, K5] | [K1, K2, K3, K4, K5, K6], notSetValue?: R): R;
23
23
  set<K extends keyof T>(key: K, value: TypeOrListOrTypedMap<T[K]>): this;
24
- setIn<K1 extends keyof T, K2 extends (keyof T[K1]) | undefined = undefined, K3 extends (keyof T[K1][K2]) | undefined = undefined, K4 extends (keyof T[K1][K2][K3]) | undefined = undefined, K5 extends (keyof T[K1][K2][K3][K4]) | undefined = undefined, K6 extends (keyof T[K1][K2][K3][K4][K5]) | undefined = undefined, V = (K6 extends undefined ? never : TypeOrListOrTypedMap<T[K1][K2][K3][K4][K5][K6]>) | (K5 extends undefined ? never : K6 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3][K4][K5]> : never) | (K4 extends undefined ? never : K5 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3][K4]> : never) | (K3 extends undefined ? never : K4 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3]> : never) | (K2 extends undefined ? never : K3 extends undefined ? TypeOrListOrTypedMap<T[K1][K2]> : never) | (K2 extends undefined ? TypeOrListOrTypedMap<T[K1]> : never)>(searchKeyPath: [K1] | [K1, K2] | [K1, K2, K3] | [K1, K2, K3, K4] | [K1, K2, K3, K4, K5] | [K1, K2, K3, K4, K5, K6], value: V): this;
25
- toJS(): T;
24
+ setIn<K1 extends keyof T, K2 extends (keyof T[K1]) | undefined = undefined, K3 extends (keyof T[K1][K2]) | undefined = undefined, K4 extends (keyof T[K1][K2][K3]) | undefined = undefined, K5 extends (keyof T[K1][K2][K3][K4]) | undefined = undefined, K6 extends (keyof T[K1][K2][K3][K4][K5]) | undefined = undefined, V = (K6 extends undefined ? unknown : TypeOrListOrTypedMap<T[K1][K2][K3][K4][K5][K6]>) | (K5 extends undefined ? unknown : K6 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3][K4][K5]> : unknown) | (K4 extends undefined ? unknown : K5 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3][K4]> : unknown) | (K3 extends undefined ? unknown : K4 extends undefined ? TypeOrListOrTypedMap<T[K1][K2][K3]> : unknown) | (K2 extends undefined ? unknown : K3 extends undefined ? TypeOrListOrTypedMap<T[K1][K2]> : unknown) | (K2 extends undefined ? TypeOrListOrTypedMap<T[K1]> : unknown)>(searchKeyPath: [K1] | [K1, K2] | [K1, K2, K3] | [K1, K2, K3, K4] | [K1, K2, K3, K4, K5] | [K1, K2, K3, K4, K5, K6], value: V): this;
25
+ toJS(): T extends {
26
+ [key: string]: unknown;
27
+ } ? T : {
28
+ [key: string]: unknown;
29
+ };
26
30
  }
27
31
  declare type Reducers<T> = {
28
32
  [K in keyof T]: Reducer<T[K], SimpleAction>;
@@ -0,0 +1,4 @@
1
+ import Immutable from 'immutable';
2
+ import { TypedList, TypedMap } from '../index';
3
+ export declare const arrayToTypedList: <T extends any[]>(jsValue: T, reviver?: (key: string | number, sequence: Immutable.Collection.Keyed<string, unknown> | Immutable.Collection.Indexed<unknown>, path?: (string | number)[]) => unknown) => TypedList<T>;
4
+ export declare const objectToTypedMap: <T extends object>(jsValue: T, reviver?: (key: string | number, sequence: Immutable.Collection.Keyed<string, unknown> | Immutable.Collection.Indexed<unknown>, path?: (string | number)[]) => unknown) => TypedMap<T>;
@@ -0,0 +1 @@
1
+ import r from"immutable";var o=function(o,t){return r.fromJS(o,t)},t=function(o,t){return r.fromJS(o,t)};export{o as arrayToTypedList,t as objectToTypedMap};
@@ -1,28 +0,0 @@
1
- declare type CookieSettings = {
2
- domain: string;
3
- expires?: number;
4
- path?: string;
5
- sameSite?: 'lax' | 'strict';
6
- secure?: boolean;
7
- };
8
- declare class TokenStorage {
9
- static cookieSettings: CookieSettings;
10
- static syncPromise: Promise<void>;
11
- static userPoolId: string;
12
- static clear(): void;
13
- static getItem(key: string): string;
14
- static removeItem(key: string): string;
15
- static setCookieStorage(cookieSettings: CookieSettings): void;
16
- static setItem(key: string, value: any): any;
17
- static setUserPoolId(userPoolId: string): void;
18
- static sync(): Promise<void>;
19
- private static generateCookieName;
20
- private static getCookie;
21
- private static getCookieName;
22
- private static getCookieValue;
23
- private static parseCookieName;
24
- private static parseKey;
25
- private static removeCookie;
26
- private static setCookie;
27
- }
28
- export default TokenStorage;