New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@yva/session

Package Overview
Dependencies
Maintainers
4
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yva/session - npm Package Compare versions

Comparing version 1.2.1 to 2.0.0

16

CHANGELOG.md

@@ -6,2 +6,18 @@ # Change Log

# [2.0.0](https://github.com/yva/yva-packages/compare/@yva/session@1.2.1...@yva/session@2.0.0) (2019-03-01)
### Code Refactoring
* **.env:** move @yva/session getConfig to getEnv ([19a2941](https://github.com/yva/yva-packages/commit/19a2941))
### BREAKING CHANGES
* **.env:** new SSO URL scheme
## [1.2.1](https://github.com/yva/yva-packages/compare/@yva/session@1.2.0...@yva/session@1.2.1) (2019-03-01)

@@ -8,0 +24,0 @@

2

dist/index.js

@@ -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/"})},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;
"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"),urljoin=_interopDefault(require("url-join")),reduxObservable=require("redux-observable"),rxjs=require("rxjs"),locale=require("@yva/locale"),getToken=function(e){var r=config.getEnv("SSO"),t=config.getEnv("CLIENT_ID"),n=config.getEnv("REDIRECT_URI"),o=new URL(n,window.location.origin).href;return request.request({url:r+"/oauth2/token/",method:"POST",responseType:"json",body:{clientId:t,redirectUri:o,grantType:"authorizationCode",code:e}})},getProfile=function(){var e=config.getEnv("API");return request.request({url:e+"/users/users/me/"})},changeLocale=function(e){var r=config.getEnv("API");return request.request({url:r+"/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.getEnv("CLIENT_ID"),t=config.getEnv("SSO"),n=config.getEnv("ROOT"),o=config.getEnv("REDIRECT_URI"),i=_objectSpread({clientId:r,redirectUri:new URL(urljoin(n,o),window.location.origin).href,responseType:"Code"},e);return t+"/oauth2/authorize?"+qs.stringify(i)},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 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};
import{request as e}from"@yva/request";import{getEnv as n,getConfig as r}from"@yva/config";import{createAction as t,handleActions as o}from"redux-actions";import{parse as i,stringify as u}from"qs";import{async as a,getSuccessType as s,isErrorAction as l}from"redux-async-epic";import{replace as c}from"react-router-redux";import{saveCreds as f,getCreds as p,clearCreds as m}from"@yva/credits";import{pluck as d,tap as g,switchMap as h,ignoreElements as y,filter as v,map as S}from"rxjs/operators";import{List as I}from"immutable";import w from"immutable-nestable-record";import{combineReducers as O}from"redux-immutable";import{uiReducer as b,UI as P}from"@yva/ui-state";import T from"url-join";import{ofType as j,combineEpics as E}from"redux-observable";import{of as A}from"rxjs";import{clearLocale as L,saveLocale as N}from"@yva/locale";var R=function(r){var t=n("SSO"),o=n("CLIENT_ID"),i=n("REDIRECT_URI"),u=new URL(i,window.location.origin).href;return e({url:t+"/oauth2/token/",method:"POST",responseType:"json",body:{clientId:o,redirectUri:u,grantType:"authorizationCode",code:r}})},k=function(){var r=n("API");return e({url:r+"/users/users/me/"})},x=function(r){var t=n("API");return e({url:t+"/users/users/me/locale",method:"put",body:{value:r}})},C=Object.freeze({getToken:R,getProfile:k,changeLocale:x}),U="@yva/session",D={signIn:U+"/sign-in",signOut:U+"/sign-out",fetchProfile:U+"/fetch-profile",fetchToken:U+"/fetch-token",changeLocale:U+"/change-locale"};function _(e,n,r){return n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function z(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){_(e,n,r[n])})}return e}var J,q,M=t(D.signIn,function(e){return e&&e.state?z({},i(e.state.search,{ignoreQueryPrefix:!0}),{state:JSON.stringify(e.state)}):{}}),B=t(D.signOut),H=t(D.fetchProfile,null,function(e){var n;return(n={})[a]=!0,n.method=k,n.onSuccess=function(){var n="/";try{n=JSON.parse(e)}catch(e){}return c(n)},n}),Q=t(D.changeLocale,null,function(e){var n;return(n={})[a]=!0,n.method=function(){return x(e.locale)},n}),W=t(D.fetchToken,null,function(e){var n;return(n={})[a]=!0,n.method=function(){return R(e.code).pipe(d("response"),g(f),d("accessToken"))},n.onSuccess=function(){return H(e.storedLocation)},n}),F=Object.freeze({name:U,types:D,signIn:M,signOut:B,fetchProfile:H,changeLocale:Q,fetchToken:W}),G=w({value:"",isPrimary:!1,isConfirmed:!1,isHeuristic:!1},{},"SessionEmail"),K=w({isAdministrator:!1,isManager:!1,sendSurveys:!1,includeIn360Survey:!1},{},"SessionRoles"),V=w({id:null,firstName:null,lastName:null,displayName:null,primaryEmail:null,jobTitle:null,department:null,status:null,emails:I(),userId:null,teamId:null,avatar:null,rolesAndSettings:new K,createdAt:null,locale:"en"},{emails:[I,G],rolesAndSettings:K},"SessionProfile"),X=o(((J={})[s(D.fetchProfile)]=function(e,n){return n.payload&&n.payload.response?new V(n.payload.response):e},J),null),Y=function(e){var r=n("CLIENT_ID"),t=n("SSO"),o=n("ROOT"),i=n("REDIRECT_URI"),a=z({clientId:r,redirectUri:new URL(T(o,i),window.location.origin).href,responseType:"Code"},e);return t+"/oauth2/authorize?"+u(a)},Z=function(){return!!p().accessToken},$=function(e){try{return sessionStorage.setItem("profile",JSON.stringify(e)),!0}catch(e){}return!1},ee=function(){try{var e=sessionStorage.getItem("profile");return JSON.parse(e)}catch(e){}return null},ne=function(){try{sessionStorage.removeItem("profile")}catch(e){}},re=w({profile:(q=ee(),q?new V(q):null),ui:new P},{profile:V,ui:P},"SessionState"),te=O({profile:X,ui:function(e,n){return n.type.startsWith(U)?b(e,n):e}},re),oe=function(e){return e.get("ui")},ie=function(e){return null!==e.get("profile")},ue=function(e){return e.get("profile")},ae=function(e){return!!e.getIn(["profile","teamId"],!1)},se=function(e){return e.getIn(["profile","rolesAndSettings"],null)},le=E(function(e){return e.pipe(j(D.signIn),h(function(e){var n=e.payload;return Z()?A(H(n.state)):A(n).pipe(g(function(e){window.location.assign(Y(e))}),y())}))},function(e){return e.pipe(j(D.signOut),g(function(){m(),L(),ne()}),g(function(){window.location.assign(Y({logout:!0}))}),y())},function(e){return e.pipe(j(s(D.fetchProfile)),g(function(e){var n=e.payload;n&&n.response&&($(n.response),N(n.response.locale))}),y())},function(e){return e.pipe(j(s(D.changeLocale)),g(function(){ne(),window.location.href.includes("/auth")||window.location.reload()}),y())},function(e){return e.pipe(v(function(e){return l(e)&&(n=e.payload)&&401===n.status;var n}),S(function(){return c({pathname:"/auth/refresh",state:{pathname:window.location.pathname.replace(r().BASE_NAME,"")}})}))},function(e){return e.pipe(v(function(e){return l(e)&&(n=e.payload)&&403===n.status;var n}),S(function(){return c({pathname:"/error",state:{errorCode:"403"}})}))});export{C as sessionApi,F as sessionActions,le as sessionEpic,X as profileReducer,te as sessionReducer,G as Email,re as InitialState,V as Profile,K as Roles,Y as getAuthLink,Z as hasAccessToken,$ as storeProfile,ee as restoreProfile,ne as clearStoredProfile,oe as getUI,ie as isUserAuthenticated,ue as getProfile,ae as hasUserATeam,se as getRoles};
{
"name": "@yva/session",
"version": "1.2.1",
"version": "2.0.0",
"description": "",

@@ -25,3 +25,3 @@ "main": "dist/index.js",

"dependencies": {
"@yva/config": "^0.2.0",
"@yva/config": "^0.2.1",
"@yva/credits": "^0.2.0",

@@ -41,5 +41,6 @@ "@yva/locale": "^0.2.0",

"reselect": "^4.0.0",
"rxjs": "^6.3.3"
"rxjs": "^6.3.3",
"url-join": "^4.0.0"
},
"gitHead": "173923de80a953a93b6e4ea72623a765e62f3048"
"gitHead": "d35ea748a7b4051cac6af10386cdbd47e622b7aa"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc