@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
55 lines • 4.67 kB
JavaScript
import{REQUEST_LOGIN,SUCCESS_LOGIN,ERROR_LOGIN,ERROR_LEGACY_CONNECT_REGISTER,REQUEST_LOGOUT,SUCCESS_LOGOUT,ERROR_LOGOUT,REQUEST_USER,RECEIVE_USER,ERROR_USER,TOGGLE_LOGGED_IN,DISABLE_LOGIN}from"../../constants/ActionTypes";import{DEFAULT_LOGIN_STRATEGY}from"../../constants/user";/**
* Creates the dispatched REQUEST_LOGIN action object.
* It also passes login credentials to the action,
* in order to may access it within a stream subscription.
* @param {string} user The user name.
* @param {string} password The user password.
* @param {string} strategy login strategy
* @returns {Object} The dispatched action object.
*/export var requestLogin=function requestLogin(user,password){var strategy=arguments.length>2&&arguments[2]!==undefined?arguments[2]:DEFAULT_LOGIN_STRATEGY;return{type:REQUEST_LOGIN,user:user,password:password,strategy:strategy};};/**
* Creates the dispatched RECEIVE_LOGIN action object.
* @param {string} redirect The location to redirect to.
* @param {string} strategy The login strategy.
* @param {number} [sessionLifetimeInSeconds] The session lifetime in seconds
* @returns {Object} The dispatched action object.
*/export var successLogin=function successLogin(redirect){var strategy=arguments.length>1&&arguments[1]!==undefined?arguments[1]:DEFAULT_LOGIN_STRATEGY;var sessionLifetimeInSeconds=arguments.length>2?arguments[2]:undefined;return{type:SUCCESS_LOGIN,redirect:redirect,strategy:strategy,sessionLifetimeInSeconds:sessionLifetimeInSeconds};};/**
* Creates the dispatched ERROR_LOGIN action object.
* @param {Array} [messages=[]] Array of error messages.
* @param {string} code The specific error code.
* @returns {Object} The dispatched action object.
*/export var errorLogin=function errorLogin(){var messages=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var code=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'';return{type:ERROR_LOGIN,messages:messages,code:code};};/**
* Creates the dispatched ERROR_LEGACY_CONNECT_REGISTER action object.
* @returns {Object} The dispatched action object.
*/export var errorLegacyConnectRegister=function errorLegacyConnectRegister(){return{type:ERROR_LEGACY_CONNECT_REGISTER};};/**
* Creates the dispatched REQUEST_LOGOUT action object.
* @returns {Object} The dispatched action object.
*/export var requestLogout=function requestLogout(){return{type:REQUEST_LOGOUT};};/**
* Creates the dispatched RECEIVE_LOGOUT action object.
* @param {boolean} [notify=true] If set to TRUE users are notified when the logout was successful.
* @param {boolean} [autoLogout=false] Whether the logout happened because e.g. session expired
* @returns {Object} The dispatched action object.
*/export var successLogout=function successLogout(){var notify=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;var autoLogout=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return{type:SUCCESS_LOGOUT,notify:notify,autoLogout:autoLogout};};/**
* Creates the dispatched ERROR_LOGOUT action object.
* @param {Array} [messages=[]] Array of error messages
* @param {boolean} [autoLogout=false] Whether the logout happened because e.g. session expired
* @returns {Object} The dispatched action object.
*/export var errorLogout=function errorLogout(){var messages=arguments.length>0&&arguments[0]!==undefined?arguments[0]:[];var autoLogout=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return{type:ERROR_LOGOUT,messages:messages,autoLogout:autoLogout};};/**
* Creates the dispatched REQUEST_USER action object.
* @returns {Object} The dispatched action object.
*/export var requestUser=function requestUser(){return{type:REQUEST_USER};};/**
* Creates the dispatched RECEIVE_USER action object.
* @param {Object} user The user data
* @returns {Object} The dispatched action object.
*/export var receiveUser=function receiveUser(user){return{type:RECEIVE_USER,user:user};};/**
* Creates the dispatched ERROR_USER action object.
* @param {Object} error error
@returns {Object} The dispatched action object.
*/export var errorUser=function errorUser(error){return{type:ERROR_USER,error:error};};/**
* Creates the dispatched TOGGLE_LOGGED_IN action object.
* @param {boolean} value The updated logged in state.
* @returns {Object} The dispatched action object.
*/export var toggleLoggedIn=function toggleLoggedIn(value){return{type:TOGGLE_LOGGED_IN,value:value};};/**
* Creates the dispatched DISABLE_LOGIN action object.
* @param {boolean} value Whether it is enabled or disabled.
* @returns {Object}
*/export var disableLogin=function disableLogin(value){return{type:DISABLE_LOGIN,value:value};};