@yva/session
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.2.0](https://github.com/yva/yva-packages/compare/@yva/session@1.1.1...@yva/session@1.2.0) (2019-02-28) | ||
### Features | ||
* **locale:** change user locale ([efa3489](https://github.com/yva/yva-packages/commit/efa3489)) | ||
## [1.1.1](https://github.com/yva/yva-packages/compare/@yva/session@1.1.0...@yva/session@1.1.1) (2019-02-26) | ||
@@ -8,0 +19,0 @@ |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var request=require("@yva/request"),config=require("@yva/config"),reduxActions=require("redux-actions"),qs=require("qs"),reduxAsyncEpic=require("redux-async-epic"),reactRouterRedux=require("react-router-redux"),credits=require("@yva/credits"),operators=require("rxjs/operators"),immutable=require("immutable"),Record=_interopDefault(require("immutable-nestable-record")),reduxImmutable=require("redux-immutable"),uiState=require("@yva/ui-state"),reduxObservable=require("redux-observable"),rxjs=require("rxjs"),locale=require("@yva/locale"),getToken=function(e){var r=config.getConfig();return request.request({url:r.SSO+"/oauth2/token/",method:"POST",responseType:"json",body:{clientId:r.CLIENT_ID,redirectUri:r.REDIRECT_URI,grantType:"authorizationCode",code:e}})},getProfile=function(){var e=config.getConfig();return request.request({url:e.API+"/users/users/me/"})},api=Object.freeze({getToken:getToken,getProfile:getProfile}),name="@yva/session",types={signIn:name+"/sign-in",signOut:name+"/sign-out",fetchProfile:name+"/fetch-profile",fetchToken:name+"/fetch-token"};function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _objectSpread(e){for(var r=1;arguments.length>r;r++){var t=null!=arguments[r]?arguments[r]:{},o=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),o.forEach(function(r){_defineProperty(e,r,t[r])})}return e}var _handleActions,signIn=reduxActions.createAction(types.signIn,function(e){return e&&e.state?_objectSpread({},qs.parse(e.state.search,{ignoreQueryPrefix:!0}),{state:JSON.stringify(e.state)}):{}}),signOut=reduxActions.createAction(types.signOut),fetchProfile=reduxActions.createAction(types.fetchProfile,null,function(e){var r;return(r={})[reduxAsyncEpic.async]=!0,r.method=getProfile,r.onSuccess=function(){var r="/";try{r=JSON.parse(e)}catch(e){}return reactRouterRedux.replace(r)},r}),fetchToken=reduxActions.createAction(types.fetchToken,null,function(e){var r;return(r={})[reduxAsyncEpic.async]=!0,r.method=function(){return getToken(e.code).pipe(operators.pluck("response"),operators.tap(credits.saveCreds),operators.pluck("accessToken"))},r.onSuccess=function(){return fetchProfile(e.storedLocation)},r}),index=Object.freeze({name:name,types:types,signIn:signIn,signOut:signOut,fetchProfile:fetchProfile,fetchToken:fetchToken}),Email=Record({value:"",isPrimary:!1,isConfirmed:!1,isHeuristic:!1},{},"SessionEmail"),Roles=Record({isAdministrator:!1,isManager:!1,sendSurveys:!1,includeIn360Survey:!1},{},"SessionRoles"),Profile=Record({id:null,firstName:null,lastName:null,displayName:null,primaryEmail:null,jobTitle:null,department:null,status:null,emails:immutable.List(),userId:null,teamId:null,avatar:null,rolesAndSettings:new Roles,createdAt:null,locale:"en"},{emails:[immutable.List,Email],rolesAndSettings:Roles},"SessionProfile"),profileReducer=reduxActions.handleActions(((_handleActions={})[reduxAsyncEpic.getSuccessType(types.fetchProfile)]=function(e,r){return r.payload&&r.payload.response?new Profile(r.payload.response):e},_handleActions),null),uiReducer=function(e,r){return r.type.startsWith(name)?uiState.uiReducer(e,r):e},getAuthLink=function(e){var r=config.getConfig(),t=r.SSO,o=_objectSpread({clientId:r.CLIENT_ID,redirectUri:r.REDIRECT_URI,responseType:"Code"},e);return t+"/oauth2/authorize?"+qs.stringify(o)},hasAccessToken=function(){return!!credits.getCreds().accessToken},storeProfile=function(e){try{return sessionStorage.setItem("profile",JSON.stringify(e)),!0}catch(e){}return!1},restoreProfile=function(){try{var e=sessionStorage.getItem("profile");return JSON.parse(e)}catch(e){}return null},clearStoredProfile=function(){try{sessionStorage.removeItem("profile")}catch(e){}},loadProfile=function(){var e=restoreProfile();return e?new Profile(e):null},InitialState=Record({profile:loadProfile(),ui:new uiState.UI},{profile:Profile,ui:uiState.UI},"SessionState"),sessionReducer=reduxImmutable.combineReducers({profile:profileReducer,ui:uiReducer},InitialState),getUI=function(e){return e.get("ui")},isUserAuthenticated=function(e){return null!==e.get("profile")},getProfile$1=function(e){return e.get("profile")},hasUserATeam=function(e){return!!e.getIn(["profile","teamId"],!1)},getRoles=function(e){return e.getIn(["profile","rolesAndSettings"],null)},signIn$1=function(e){return e.pipe(reduxObservable.ofType(types.signIn),operators.switchMap(function(e){var r=e.payload;return hasAccessToken()?rxjs.of(fetchProfile(r.state)):rxjs.of(r).pipe(operators.tap(function(e){window.location.assign(getAuthLink(e))}),operators.ignoreElements())}))},signOut$1=function(e){return e.pipe(reduxObservable.ofType(types.signOut),operators.tap(function(){credits.clearCreds(),locale.clearLocale(),clearStoredProfile()}),operators.tap(function(){window.location.assign(getAuthLink({logout:!0}))}),operators.ignoreElements())},storeProfile$1=function(e){return e.pipe(reduxObservable.ofType(reduxAsyncEpic.getSuccessType(types.fetchProfile)),operators.tap(function(e){var r=e.payload;r&&r.response&&(storeProfile(r.response),locale.saveLocale(r.response.locale))}),operators.ignoreElements())},is401=function(e){var r=e.payload;return r&&401===r.status},handle401=function(e){return e.pipe(operators.filter(function(e){return reduxAsyncEpic.isErrorAction(e)&&is401(e)}),operators.map(function(){return reactRouterRedux.replace({pathname:"/auth/refresh",state:{pathname:window.location.pathname.replace(config.getConfig().BASE_NAME,"")}})}))},is403=function(e){var r=e.payload;return r&&403===r.status},handle403=function(e){return e.pipe(operators.filter(function(e){return reduxAsyncEpic.isErrorAction(e)&&is403(e)}),operators.map(function(){return reactRouterRedux.replace({pathname:"/error",state:{errorCode:"403"}})}))},index$1=reduxObservable.combineEpics(signIn$1,signOut$1,storeProfile$1,handle401,handle403);exports.sessionApi=api,exports.sessionActions=index,exports.sessionEpic=index$1,exports.profileReducer=profileReducer,exports.sessionReducer=sessionReducer,exports.Email=Email,exports.InitialState=InitialState,exports.Profile=Profile,exports.Roles=Roles,exports.getAuthLink=getAuthLink,exports.hasAccessToken=hasAccessToken,exports.storeProfile=storeProfile,exports.restoreProfile=restoreProfile,exports.clearStoredProfile=clearStoredProfile,exports.getUI=getUI,exports.isUserAuthenticated=isUserAuthenticated,exports.getProfile=getProfile$1,exports.hasUserATeam=hasUserATeam,exports.getRoles=getRoles; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var request=require("@yva/request"),config=require("@yva/config"),reduxActions=require("redux-actions"),qs=require("qs"),reduxAsyncEpic=require("redux-async-epic"),reactRouterRedux=require("react-router-redux"),credits=require("@yva/credits"),operators=require("rxjs/operators"),immutable=require("immutable"),Record=_interopDefault(require("immutable-nestable-record")),reduxImmutable=require("redux-immutable"),uiState=require("@yva/ui-state"),reduxObservable=require("redux-observable"),rxjs=require("rxjs"),locale=require("@yva/locale"),getToken=function(e){var r=config.getConfig();return request.request({url:r.SSO+"/oauth2/token/",method:"POST",responseType:"json",body:{clientId:r.CLIENT_ID,redirectUri:r.REDIRECT_URI,grantType:"authorizationCode",code:e}})},getProfile=function(){var e=config.getConfig();return request.request({url:e.API+"/users/users/me/"})},changeLocale=function(e){var r=config.getConfig();return request.request({url:r.API+"/users/users/me/locale",method:"put",body:{value:e}})},api=Object.freeze({getToken:getToken,getProfile:getProfile,changeLocale:changeLocale}),name="@yva/session",types={signIn:name+"/sign-in",signOut:name+"/sign-out",fetchProfile:name+"/fetch-profile",fetchToken:name+"/fetch-token",changeLocale:name+"/change-locale"};function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _objectSpread(e){for(var r=1;arguments.length>r;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(r){_defineProperty(e,r,t[r])})}return e}var _handleActions,signIn=reduxActions.createAction(types.signIn,function(e){return e&&e.state?_objectSpread({},qs.parse(e.state.search,{ignoreQueryPrefix:!0}),{state:JSON.stringify(e.state)}):{}}),signOut=reduxActions.createAction(types.signOut),fetchProfile=reduxActions.createAction(types.fetchProfile,null,function(e){var r;return(r={})[reduxAsyncEpic.async]=!0,r.method=getProfile,r.onSuccess=function(){var r="/";try{r=JSON.parse(e)}catch(e){}return reactRouterRedux.replace(r)},r}),changeLocale$1=reduxActions.createAction(types.changeLocale,null,function(e){var r;return(r={})[reduxAsyncEpic.async]=!0,r.method=function(){return changeLocale(e.locale)},r}),fetchToken=reduxActions.createAction(types.fetchToken,null,function(e){var r;return(r={})[reduxAsyncEpic.async]=!0,r.method=function(){return getToken(e.code).pipe(operators.pluck("response"),operators.tap(credits.saveCreds),operators.pluck("accessToken"))},r.onSuccess=function(){return fetchProfile(e.storedLocation)},r}),index=Object.freeze({name:name,types:types,signIn:signIn,signOut:signOut,fetchProfile:fetchProfile,changeLocale:changeLocale$1,fetchToken:fetchToken}),Email=Record({value:"",isPrimary:!1,isConfirmed:!1,isHeuristic:!1},{},"SessionEmail"),Roles=Record({isAdministrator:!1,isManager:!1,sendSurveys:!1,includeIn360Survey:!1},{},"SessionRoles"),Profile=Record({id:null,firstName:null,lastName:null,displayName:null,primaryEmail:null,jobTitle:null,department:null,status:null,emails:immutable.List(),userId:null,teamId:null,avatar:null,rolesAndSettings:new Roles,createdAt:null,locale:"en"},{emails:[immutable.List,Email],rolesAndSettings:Roles},"SessionProfile"),profileReducer=reduxActions.handleActions(((_handleActions={})[reduxAsyncEpic.getSuccessType(types.fetchProfile)]=function(e,r){return r.payload&&r.payload.response?new Profile(r.payload.response):e},_handleActions),null),uiReducer=function(e,r){return r.type.startsWith(name)?uiState.uiReducer(e,r):e},getAuthLink=function(e){var r=config.getConfig(),t=r.SSO,n=_objectSpread({clientId:r.CLIENT_ID,redirectUri:r.REDIRECT_URI,responseType:"Code"},e);return t+"/oauth2/authorize?"+qs.stringify(n)},hasAccessToken=function(){return!!credits.getCreds().accessToken},storeProfile=function(e){try{return sessionStorage.setItem("profile",JSON.stringify(e)),!0}catch(e){}return!1},restoreProfile=function(){try{var e=sessionStorage.getItem("profile");return JSON.parse(e)}catch(e){}return null},clearStoredProfile=function(){try{sessionStorage.removeItem("profile")}catch(e){}},loadProfile=function(){var e=restoreProfile();return e?new Profile(e):null},InitialState=Record({profile:loadProfile(),ui:new uiState.UI},{profile:Profile,ui:uiState.UI},"SessionState"),sessionReducer=reduxImmutable.combineReducers({profile:profileReducer,ui:uiReducer},InitialState),getUI=function(e){return e.get("ui")},isUserAuthenticated=function(e){return null!==e.get("profile")},getProfile$1=function(e){return e.get("profile")},hasUserATeam=function(e){return!!e.getIn(["profile","teamId"],!1)},getRoles=function(e){return e.getIn(["profile","rolesAndSettings"],null)},signIn$1=function(e){return e.pipe(reduxObservable.ofType(types.signIn),operators.switchMap(function(e){var r=e.payload;return hasAccessToken()?rxjs.of(fetchProfile(r.state)):rxjs.of(r).pipe(operators.tap(function(e){window.location.assign(getAuthLink(e))}),operators.ignoreElements())}))},signOut$1=function(e){return e.pipe(reduxObservable.ofType(types.signOut),operators.tap(function(){credits.clearCreds(),locale.clearLocale(),clearStoredProfile()}),operators.tap(function(){window.location.assign(getAuthLink({logout:!0}))}),operators.ignoreElements())},storeProfile$1=function(e){return e.pipe(reduxObservable.ofType(reduxAsyncEpic.getSuccessType(types.fetchProfile)),operators.tap(function(e){var r=e.payload;r&&r.response&&(storeProfile(r.response),locale.saveLocale(r.response.locale))}),operators.ignoreElements())},changeLocale$2=function(e){return e.pipe(reduxObservable.ofType(reduxAsyncEpic.getSuccessType(types.changeLocale)),operators.tap(function(){clearStoredProfile(),window.location.href.includes("/auth")||window.location.reload()}),operators.ignoreElements())},is401=function(e){var r=e.payload;return r&&401===r.status},handle401=function(e){return e.pipe(operators.filter(function(e){return reduxAsyncEpic.isErrorAction(e)&&is401(e)}),operators.map(function(){return reactRouterRedux.replace({pathname:"/auth/refresh",state:{pathname:window.location.pathname.replace(config.getConfig().BASE_NAME,"")}})}))},is403=function(e){var r=e.payload;return r&&403===r.status},handle403=function(e){return e.pipe(operators.filter(function(e){return reduxAsyncEpic.isErrorAction(e)&&is403(e)}),operators.map(function(){return reactRouterRedux.replace({pathname:"/error",state:{errorCode:"403"}})}))},index$1=reduxObservable.combineEpics(signIn$1,signOut$1,storeProfile$1,changeLocale$2,handle401,handle403);exports.sessionApi=api,exports.sessionActions=index,exports.sessionEpic=index$1,exports.profileReducer=profileReducer,exports.sessionReducer=sessionReducer,exports.Email=Email,exports.InitialState=InitialState,exports.Profile=Profile,exports.Roles=Roles,exports.getAuthLink=getAuthLink,exports.hasAccessToken=hasAccessToken,exports.storeProfile=storeProfile,exports.restoreProfile=restoreProfile,exports.clearStoredProfile=clearStoredProfile,exports.getUI=getUI,exports.isUserAuthenticated=isUserAuthenticated,exports.getProfile=getProfile$1,exports.hasUserATeam=hasUserATeam,exports.getRoles=getRoles; |
@@ -1,1 +0,1 @@ | ||
import{request as e}from"@yva/request";import{getConfig as r}from"@yva/config";import{createAction as t,handleActions as n}from"redux-actions";import{parse as o,stringify as i}from"qs";import{async as u,getSuccessType as s,isErrorAction as a}from"redux-async-epic";import{replace as l}from"react-router-redux";import{saveCreds as c,getCreds as f,clearCreds as p}from"@yva/credits";import{pluck as m,tap as d,switchMap as y,ignoreElements as g,filter as h,map as v}from"rxjs/operators";import{List as S}from"immutable";import I from"immutable-nestable-record";import{combineReducers as b}from"redux-immutable";import{uiReducer as O,UI as P}from"@yva/ui-state";import{ofType as T,combineEpics as w}from"redux-observable";import{of as E}from"rxjs";import{clearLocale as j,saveLocale as A}from"@yva/locale";var N=function(t){var n=r();return e({url:n.SSO+"/oauth2/token/",method:"POST",responseType:"json",body:{clientId:n.CLIENT_ID,redirectUri:n.REDIRECT_URI,grantType:"authorizationCode",code:t}})},k=function(){var t=r();return e({url:t.API+"/users/users/me/"})},x=Object.freeze({getToken:N,getProfile:k}),C="@yva/session",R={signIn:C+"/sign-in",signOut:C+"/sign-out",fetchProfile:C+"/fetch-profile",fetchToken:C+"/fetch-token"};function D(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function _(e){for(var r=1;arguments.length>r;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(r){D(e,r,t[r])})}return e}var z,J,U=t(R.signIn,function(e){return e&&e.state?_({},o(e.state.search,{ignoreQueryPrefix:!0}),{state:JSON.stringify(e.state)}):{}}),L=t(R.signOut),q=t(R.fetchProfile,null,function(e){var r;return(r={})[u]=!0,r.method=k,r.onSuccess=function(){var r="/";try{r=JSON.parse(e)}catch(e){}return l(r)},r}),M=t(R.fetchToken,null,function(e){var r;return(r={})[u]=!0,r.method=function(){return N(e.code).pipe(m("response"),d(c),m("accessToken"))},r.onSuccess=function(){return q(e.storedLocation)},r}),B=Object.freeze({name:C,types:R,signIn:U,signOut:L,fetchProfile:q,fetchToken:M}),H=I({value:"",isPrimary:!1,isConfirmed:!1,isHeuristic:!1},{},"SessionEmail"),Q=I({isAdministrator:!1,isManager:!1,sendSurveys:!1,includeIn360Survey:!1},{},"SessionRoles"),W=I({id:null,firstName:null,lastName:null,displayName:null,primaryEmail:null,jobTitle:null,department:null,status:null,emails:S(),userId:null,teamId:null,avatar:null,rolesAndSettings:new Q,createdAt:null,locale:"en"},{emails:[S,H],rolesAndSettings:Q},"SessionProfile"),F=n(((z={})[s(R.fetchProfile)]=function(e,r){return r.payload&&r.payload.response?new W(r.payload.response):e},z),null),G=function(e){var t=r(),n=t.SSO,o=_({clientId:t.CLIENT_ID,redirectUri:t.REDIRECT_URI,responseType:"Code"},e);return n+"/oauth2/authorize?"+i(o)},K=function(){return!!f().accessToken},V=function(e){try{return sessionStorage.setItem("profile",JSON.stringify(e)),!0}catch(e){}return!1},X=function(){try{var e=sessionStorage.getItem("profile");return JSON.parse(e)}catch(e){}return null},Y=function(){try{sessionStorage.removeItem("profile")}catch(e){}},Z=I({profile:(J=X(),J?new W(J):null),ui:new P},{profile:W,ui:P},"SessionState"),$=b({profile:F,ui:function(e,r){return r.type.startsWith(C)?O(e,r):e}},Z),ee=function(e){return e.get("ui")},re=function(e){return null!==e.get("profile")},te=function(e){return e.get("profile")},ne=function(e){return!!e.getIn(["profile","teamId"],!1)},oe=function(e){return e.getIn(["profile","rolesAndSettings"],null)},ie=w(function(e){return e.pipe(T(R.signIn),y(function(e){var r=e.payload;return K()?E(q(r.state)):E(r).pipe(d(function(e){window.location.assign(G(e))}),g())}))},function(e){return e.pipe(T(R.signOut),d(function(){p(),j(),Y()}),d(function(){window.location.assign(G({logout:!0}))}),g())},function(e){return e.pipe(T(s(R.fetchProfile)),d(function(e){var r=e.payload;r&&r.response&&(V(r.response),A(r.response.locale))}),g())},function(e){return e.pipe(h(function(e){return a(e)&&(r=e.payload)&&401===r.status;var r}),v(function(){return l({pathname:"/auth/refresh",state:{pathname:window.location.pathname.replace(r().BASE_NAME,"")}})}))},function(e){return e.pipe(h(function(e){return a(e)&&(r=e.payload)&&403===r.status;var r}),v(function(){return l({pathname:"/error",state:{errorCode:"403"}})}))});export{x as sessionApi,B as sessionActions,ie as sessionEpic,F as profileReducer,$ as sessionReducer,H as Email,Z as InitialState,W as Profile,Q as Roles,G as getAuthLink,K as hasAccessToken,V as storeProfile,X as restoreProfile,Y as clearStoredProfile,ee as getUI,re as isUserAuthenticated,te as getProfile,ne as hasUserATeam,oe as getRoles}; | ||
import{request as e}from"@yva/request";import{getConfig as n}from"@yva/config";import{createAction as r,handleActions as t}from"redux-actions";import{parse as o,stringify as i}from"qs";import{async as u,getSuccessType as a,isErrorAction as s}from"redux-async-epic";import{replace as l}from"react-router-redux";import{saveCreds as c,getCreds as f,clearCreds as p}from"@yva/credits";import{pluck as m,tap as d,switchMap as g,ignoreElements as h,filter as y,map as v}from"rxjs/operators";import{List as S}from"immutable";import I from"immutable-nestable-record";import{combineReducers as b}from"redux-immutable";import{uiReducer as O,UI as w}from"@yva/ui-state";import{ofType as P,combineEpics as T}from"redux-observable";import{of as E}from"rxjs";import{clearLocale as j,saveLocale as A}from"@yva/locale";var N=function(r){var t=n();return e({url:t.SSO+"/oauth2/token/",method:"POST",responseType:"json",body:{clientId:t.CLIENT_ID,redirectUri:t.REDIRECT_URI,grantType:"authorizationCode",code:r}})},k=function(){var r=n();return e({url:r.API+"/users/users/me/"})},x=function(r){var t=n();return e({url:t.API+"/users/users/me/locale",method:"put",body:{value:r}})},C=Object.freeze({getToken:N,getProfile:k,changeLocale:x}),L="@yva/session",R={signIn:L+"/sign-in",signOut:L+"/sign-out",fetchProfile:L+"/fetch-profile",fetchToken:L+"/fetch-token",changeLocale:L+"/change-locale"};function D(e,n,r){return n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function _(e){for(var n=1;arguments.length>n;n++){var r=null!=arguments[n]?arguments[n]:{},t=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),t.forEach(function(n){D(e,n,r[n])})}return e}var z,J,U=r(R.signIn,function(e){return e&&e.state?_({},o(e.state.search,{ignoreQueryPrefix:!0}),{state:JSON.stringify(e.state)}):{}}),q=r(R.signOut),M=r(R.fetchProfile,null,function(e){var n;return(n={})[u]=!0,n.method=k,n.onSuccess=function(){var n="/";try{n=JSON.parse(e)}catch(e){}return l(n)},n}),B=r(R.changeLocale,null,function(e){var n;return(n={})[u]=!0,n.method=function(){return x(e.locale)},n}),H=r(R.fetchToken,null,function(e){var n;return(n={})[u]=!0,n.method=function(){return N(e.code).pipe(m("response"),d(c),m("accessToken"))},n.onSuccess=function(){return M(e.storedLocation)},n}),Q=Object.freeze({name:L,types:R,signIn:U,signOut:q,fetchProfile:M,changeLocale:B,fetchToken:H}),W=I({value:"",isPrimary:!1,isConfirmed:!1,isHeuristic:!1},{},"SessionEmail"),F=I({isAdministrator:!1,isManager:!1,sendSurveys:!1,includeIn360Survey:!1},{},"SessionRoles"),G=I({id:null,firstName:null,lastName:null,displayName:null,primaryEmail:null,jobTitle:null,department:null,status:null,emails:S(),userId:null,teamId:null,avatar:null,rolesAndSettings:new F,createdAt:null,locale:"en"},{emails:[S,W],rolesAndSettings:F},"SessionProfile"),K=t(((z={})[a(R.fetchProfile)]=function(e,n){return n.payload&&n.payload.response?new G(n.payload.response):e},z),null),V=function(e){var r=n(),t=r.SSO,o=_({clientId:r.CLIENT_ID,redirectUri:r.REDIRECT_URI,responseType:"Code"},e);return t+"/oauth2/authorize?"+i(o)},X=function(){return!!f().accessToken},Y=function(e){try{return sessionStorage.setItem("profile",JSON.stringify(e)),!0}catch(e){}return!1},Z=function(){try{var e=sessionStorage.getItem("profile");return JSON.parse(e)}catch(e){}return null},$=function(){try{sessionStorage.removeItem("profile")}catch(e){}},ee=I({profile:(J=Z(),J?new G(J):null),ui:new w},{profile:G,ui:w},"SessionState"),ne=b({profile:K,ui:function(e,n){return n.type.startsWith(L)?O(e,n):e}},ee),re=function(e){return e.get("ui")},te=function(e){return null!==e.get("profile")},oe=function(e){return e.get("profile")},ie=function(e){return!!e.getIn(["profile","teamId"],!1)},ue=function(e){return e.getIn(["profile","rolesAndSettings"],null)},ae=T(function(e){return e.pipe(P(R.signIn),g(function(e){var n=e.payload;return X()?E(M(n.state)):E(n).pipe(d(function(e){window.location.assign(V(e))}),h())}))},function(e){return e.pipe(P(R.signOut),d(function(){p(),j(),$()}),d(function(){window.location.assign(V({logout:!0}))}),h())},function(e){return e.pipe(P(a(R.fetchProfile)),d(function(e){var n=e.payload;n&&n.response&&(Y(n.response),A(n.response.locale))}),h())},function(e){return e.pipe(P(a(R.changeLocale)),d(function(){$(),window.location.href.includes("/auth")||window.location.reload()}),h())},function(e){return e.pipe(y(function(e){return s(e)&&(n=e.payload)&&401===n.status;var n}),v(function(){return l({pathname:"/auth/refresh",state:{pathname:window.location.pathname.replace(n().BASE_NAME,"")}})}))},function(e){return e.pipe(y(function(e){return s(e)&&(n=e.payload)&&403===n.status;var n}),v(function(){return l({pathname:"/error",state:{errorCode:"403"}})}))});export{C as sessionApi,Q as sessionActions,ae as sessionEpic,K as profileReducer,ne as sessionReducer,W as Email,ee as InitialState,G as Profile,F as Roles,V as getAuthLink,X as hasAccessToken,Y as storeProfile,Z as restoreProfile,$ as clearStoredProfile,re as getUI,te as isUserAuthenticated,oe as getProfile,ie as hasUserATeam,ue as getRoles}; |
{ | ||
"name": "@yva/session", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -42,3 +42,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "bb7a3f346dbf99e7226dac904432ce4bcfecd902" | ||
"gitHead": "ec71c496a4f3eea34293bd588379858abef52198" | ||
} |
16985
49