@shopgate/pwa-common 7.29.0-alpha.2 → 7.29.0-alpha.4
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{PipelineRequest}from'@shopgate/pwa-core';import{getDeviceTypeForCms}from'@shopgate/engage/core';import{hasNewServices}from'@shopgate/engage/core/helpers';import{SHOPGATE_CMS_GET_PAGE_CONFIG}from"../../constants/Pipelines";import{requestPageConfig,receivePageConfig,errorPageConfig}from"../../action-creators/page";import{shouldFetchData,mutable}from"../../helpers/redux";import{getPageConfigById}from"../../selectors/page";/**
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{PipelineRequest}from'@shopgate/pwa-core';import{getDeviceTypeForCms}from'@shopgate/engage/core';import{makeGetPage,getIsCms2Enabled}from'@shopgate/engage/page/selectors';import{requestPageConfigV2,receivePageConfigV2,errorPageConfigV2}from'@shopgate/engage/page/action-creators';import{hasNewServices}from'@shopgate/engage/core/helpers';import{SHOPGATE_CMS_GET_PAGE_CONFIG}from"../../constants/Pipelines";import{requestPageConfig,receivePageConfig,errorPageConfig}from"../../action-creators/page";import{shouldFetchData,mutable}from"../../helpers/redux";import{getPageConfigById}from"../../selectors/page";/**
|
|
2
2
|
* Retrieves the config for a page.
|
|
3
3
|
* @param {string} pageId The ID of the page to request.
|
|
4
4
|
* @return {Function} The dispatched action.
|
|
5
|
-
*/function fetchPageConfig(pageId){return function(dispatch,getState){var state=getState();var pageConfig=getPageConfigById(state,{pageId:pageId});if(!shouldFetchData(pageConfig)){return Promise.resolve(null);}var deviceTypeOfCmsPage=getDeviceTypeForCms();dispatch(requestPageConfig(pageId));var request=new PipelineRequest(SHOPGATE_CMS_GET_PAGE_CONFIG).setInput(_extends({pageId:pageId},hasNewServices()?{deviceType:deviceTypeOfCmsPage}:null)).dispatch();request.then(function(result){dispatch(receivePageConfig(pageId,result));})["catch"](function(error){dispatch(errorPageConfig(pageId,error.code));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchPageConfig);
|
|
5
|
+
*/function fetchPageConfig(pageId){return function(dispatch,getState){var state=getState();var cmsV2Enabled=getIsCms2Enabled(state);var pageConfig;if(cmsV2Enabled){pageConfig=makeGetPage({slug:pageId})(state);}else{pageConfig=getPageConfigById(state,{pageId:pageId});}if(!shouldFetchData(pageConfig)){return Promise.resolve(null);}var deviceTypeOfCmsPage=getDeviceTypeForCms();if(cmsV2Enabled){dispatch(requestPageConfigV2({slug:pageId}));}else{dispatch(requestPageConfig(pageId));}var request=new PipelineRequest(SHOPGATE_CMS_GET_PAGE_CONFIG).setVersion(cmsV2Enabled?2:1).setInput(_extends({pageId:pageId},hasNewServices()&&!cmsV2Enabled?{deviceType:deviceTypeOfCmsPage}:null)).dispatch();request.then(function(result){if(cmsV2Enabled){dispatch(receivePageConfigV2({slug:pageId,data:result.page}));}else{dispatch(receivePageConfig(pageId,result));}})["catch"](function(error){if(cmsV2Enabled){dispatch(errorPageConfigV2({slug:pageId,code:error.code}));}else{dispatch(errorPageConfig(pageId,error.code));}});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchPageConfig);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-common",
|
|
3
|
-
"version": "7.29.0-alpha.
|
|
3
|
+
"version": "7.29.0-alpha.4",
|
|
4
4
|
"description": "Common library for the Shopgate Connect PWA.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@redux-devtools/extension": "^3.3.0",
|
|
19
19
|
"@sentry/browser": "6.0.1",
|
|
20
|
-
"@shopgate/pwa-benchmark": "7.29.0-alpha.
|
|
20
|
+
"@shopgate/pwa-benchmark": "7.29.0-alpha.4",
|
|
21
21
|
"@virtuous/conductor": "~2.5.0",
|
|
22
22
|
"@virtuous/react-conductor": "~2.5.0",
|
|
23
23
|
"@virtuous/redux-persister": "1.1.0-beta.7",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"url-search-params": "^0.10.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@shopgate/pwa-core": "7.29.0-alpha.
|
|
46
|
+
"@shopgate/pwa-core": "7.29.0-alpha.4",
|
|
47
47
|
"@types/react-portal": "^3.0.9",
|
|
48
48
|
"lodash": "^4.17.4",
|
|
49
49
|
"prop-types": "~15.8.1",
|
package/selectors/page.js
CHANGED
|
@@ -5,4 +5,9 @@ import{createSelector}from'reselect';/**
|
|
|
5
5
|
* @param {Object} state The current application state.
|
|
6
6
|
* @param {Object} props The current component props.
|
|
7
7
|
* @return {Array|null}
|
|
8
|
-
*/export var getPageConfigById=createSelector(getPageState,function(state,props){return props.pageId;},function(pageState,pageId){if(!pageState||!pageState[pageId]){return null;}return pageState[pageId];})
|
|
8
|
+
*/export var getPageConfigById=createSelector(getPageState,function(state,props){return props.pageId;},function(pageState,pageId){if(!pageState||!pageState[pageId]){return null;}return pageState[pageId];});/**
|
|
9
|
+
* Creates a selector that retrieves a page configuration by its ID.
|
|
10
|
+
* @param {Object} params The selector parameters.
|
|
11
|
+
* @param {string} params.pageId The ID of the page.
|
|
12
|
+
* @returns {Function} A selector function that retrieves the page configuration.
|
|
13
|
+
*/export var makeGetPageConfigById=function makeGetPageConfigById(_ref){var pageId=_ref.pageId;return createSelector(getPageState,function(pageState){if(!pageState||!pageState[pageId]){return null;}return pageState[pageId];});};
|
package/subscriptions/router.js
CHANGED
|
@@ -18,7 +18,7 @@ if(location&&!handler.isExternalLink(location)){location=handler.sanitizeLink(lo
|
|
|
18
18
|
if(location){_context.next=31;break;}return _context.abrupt("return");case 31:if(!(historyAction===ACTION_PUSH&&location===currentPathname)){_context.next=33;break;}return _context.abrupt("return");case 33:if(getIsConnected(state)){_context.next=36;break;}showConnectivityError();return _context.abrupt("return");case 36:if(isUserLoggedIn(state)){_context.next=41;break;}// Determine whether or not this location is protected.
|
|
19
19
|
protector=authRoutes.getProtector(location);// If protected then navigate to the protector instead.
|
|
20
20
|
if(!protector){_context.next=41;break;}dispatch(navigate({action:historyAction,pathname:protector,state:{redirect:{location:location,state:routeState}}}));return _context.abrupt("return");case 41:/* eslint-disable prefer-const */ // Check for a redirect and change location if one is found.
|
|
21
|
-
_ref3=redirects.getRedirectExtended(location)||{},redirect=_ref3.handler,matcher=_ref3.matcher,pathParams=_ref3.pathParams,queryParams=_ref3.queryParams;/* eslint-enable prefer-const */if(!redirect){_context.next=67;break;}if(!(typeof redirect==='function'||redirect instanceof Promise)){_context.next=62;break;}_getCurrentRoute2=getCurrentRoute(state),pathname=_getCurrentRoute2.pathname;LoadingProvider.setLoading(pathname);pattern=router.findPattern(location.split('?')[0]);_ref5=router.patterns[pattern]||{},transform=_ref5.transform;route=new Route({pathname:location,pattern:pattern,
|
|
21
|
+
_ref3=redirects.getRedirectExtended(location)||{},redirect=_ref3.handler,matcher=_ref3.matcher,pathParams=_ref3.pathParams,queryParams=_ref3.queryParams;/* eslint-enable prefer-const */if(!redirect){_context.next=67;break;}if(!(typeof redirect==='function'||redirect instanceof Promise)){_context.next=62;break;}_getCurrentRoute2=getCurrentRoute(state),pathname=_getCurrentRoute2.pathname;LoadingProvider.setLoading(pathname);pattern=router.findPattern(location.split('?')[0]);_ref5=router.patterns[pattern]||{},transform=_ref5.transform;route=new Route({pathname:location,pattern:pattern,state:routeState,transform:transform});_context.prev=49;_context.next=52;return redirect(_extends({},params,{action:_extends({},params.action,{params:_extends({},params.action.params,{// Merge the sanitized location into the redirect handler payload.
|
|
22
22
|
pathname:location}),route:route,redirectMeta:{location:location,matcher:matcher,pathParams:pathParams,queryParams:queryParams}})}));case 52:redirect=_context.sent;_context.next=59;break;case 55:_context.prev=55;_context.t1=_context["catch"](49);redirect=null;logger.error(_context.t1);case 59:LoadingProvider.unsetLoading(pathname);if(redirect){_context.next=62;break;}return _context.abrupt("return");case 62:// Add query parameters from the original location to the redirect
|
|
23
23
|
parsedLocation=queryString.parseUrl(location);parsedRedirect=queryString.parseUrl(redirect);stringifiedQuery=queryString.stringify(_extends({},parsedLocation.query,{},parsedRedirect.query));finalRedirect=stringifiedQuery?"".concat(parsedRedirect.url,"?").concat(stringifiedQuery):parsedRedirect.url;location=finalRedirect;case 67:parsed=queryString.parseUrl(location);if(parsed.url){_context.next=71;break;}// The URL is not valid - show a toast message
|
|
24
24
|
showConnectivityError();return _context.abrupt("return");case 71:// Override the location if is Shop link is found.
|