@shopgate/pwa-common 7.29.0-alpha.8 → 7.29.0

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{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";/**
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{ERROR_HANDLE_SUPPRESS,ERROR_HANDLE_DEFAULT}from'@shopgate/engage/core/constants';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 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);
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).setHandleErrors(cmsV2Enabled?ERROR_HANDLE_SUPPRESS:ERROR_HANDLE_DEFAULT).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);
@@ -23,4 +23,4 @@ export var APP_PLATFORM='APP_PLATFORM';export var RESET_APP_REDUCERS='RESET_APP_
23
23
  * return `${baseUrl}?width=${width}`;
24
24
  * }
25
25
  * );
26
- */export var CONFIGURATION_COLLECTION_CREATE_EXTERNAL_IMAGE_URL='CONFIGURATION_COLLECTION_CREATE_EXTERNAL_IMAGE_URL';
26
+ */export var CONFIGURATION_COLLECTION_CREATE_EXTERNAL_IMAGE_URL='CONFIGURATION_COLLECTION_CREATE_EXTERNAL_IMAGE_URL';export var CONFIGURATION_COLLECTION_KEY_THEME_TYPOGRAPHY='CONFIGURATION_COLLECTION_KEY_THEME_TYPOGRAPHY';
@@ -25,9 +25,9 @@ function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="s
25
25
  * @param {Object} dimension Dimension of the requested image.
26
26
  * @param {number} dimension.width Width in pixels.
27
27
  * @param {number} dimension.height Height in pixels.
28
- * @deprecated use @engage/core/helpers/getFullImageSource instead
28
+ * @deprecated use getFullImageSource from @shopgate/engage/core/helpers instead
29
29
  * @returns {string}
30
- */export var getActualImageSource=function getActualImageSource(src,_ref3){var width=_ref3.width,height=_ref3.height;if(src&&src.includes('images.shopgate.services/v2/images')){var fillColor='FFFFFF,1';var format=isAndroidOs?'webp':'jpeg';return"".concat(src,"&format=").concat(format,"&width=").concat(width,"&height=").concat(height,"&quality=75&fill=").concat(fillColor.replace('#',''));}if(src&&src.startsWith('https://img-cdn.shopgate.com')&&!src.includes('?')){return"".concat(src,"?w=").concat(width,"&h=").concat(height,"&q=70&zc=resize&fillc=FFFFFF");}return src;};/**
30
+ */export var getActualImageSource=function getActualImageSource(src,_ref3){var width=_ref3.width,height=_ref3.height;if(src&&src.includes('images.shopgate.services')){var fillColor='FFFFFF,1';var format=isAndroidOs?'webp':'jpeg';return"".concat(src,"&format=").concat(format,"&width=").concat(width,"&height=").concat(height,"&quality=75&fill=").concat(fillColor.replace('#',''));}if(src&&src.startsWith('https://img-cdn.shopgate.com')&&!src.includes('?')){return"".concat(src,"?w=").concat(width,"&h=").concat(height,"&q=70&zc=resize&fillc=FFFFFF");}return src;};/**
31
31
  * Finds the index of a property inside an array.
32
32
  * @param {Array} arr The array to check.
33
33
  * @param {Function} fn The callback function to filter inside the array.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-common",
3
- "version": "7.29.0-alpha.8",
3
+ "version": "7.29.0",
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.8",
20
+ "@shopgate/pwa-benchmark": "7.29.0",
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.8",
46
+ "@shopgate/pwa-core": "7.29.0",
47
47
  "@types/react-portal": "^3.0.9",
48
48
  "lodash": "^4.17.4",
49
49
  "prop-types": "~15.8.1",
@@ -1,7 +1,7 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";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);}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import queryString from'query-string';import{router,ACTION_POP,ACTION_PUSH,ACTION_REPLACE,ACTION_RESET}from'@virtuous/conductor';import Route from'@virtuous/conductor/Route';import{HISTORY_RESET_TO}from'@shopgate/pwa-common/constants/ActionTypes';import{logger}from'@shopgate/pwa-core';import{IS_PAGE_PREVIEW_ACTIVE}from'@shopgate/engage/page/constants';import{getCurrentRoute,getRouterStackIndex}from"../selectors/router";import{LoadingProvider}from"../providers";import{redirects}from"../collections";import{navigate}from"../action-creators";import{historyRedirect,historyPush,windowOpenOverride}from"../actions/router";import*as handler from"./helpers/handleLinks";import{navigate$,userDidLogin$,appWillStart$,windowOpenOverride$}from"../streams";import{isUserLoggedIn}from"../selectors/user";import{getIsConnected}from"../selectors/client";import{INDEX_PATH}from"../constants/RoutePaths";import appConfig from"../helpers/config";import authRoutes from"../collections/AuthRoutes";import ToastProvider from"../providers/toast";/**
1
+ import _regeneratorRuntime from"@babel/runtime/regenerator";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);}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import queryString from'query-string';import{router,ACTION_POP,ACTION_PUSH,ACTION_REPLACE,ACTION_RESET}from'@virtuous/conductor';import Route from'@virtuous/conductor/Route';import{HISTORY_RESET_TO}from'@shopgate/pwa-common/constants/ActionTypes';import{logger}from'@shopgate/pwa-core';import{IS_PAGE_PREVIEW_ACTIVE}from'@shopgate/engage/page/constants';import addCouponsToCart from'@shopgate/pwa-common-commerce/cart/actions/addCouponsToCart';import{getCurrentRoute,getRouterStackIndex}from"../selectors/router";import{LoadingProvider}from"../providers";import{redirects}from"../collections";import{navigate}from"../action-creators";import{historyRedirect,historyPush,windowOpenOverride}from"../actions/router";import*as handler from"./helpers/handleLinks";import{navigate$,userDidLogin$,appWillStart$,windowOpenOverride$}from"../streams";import{isUserLoggedIn}from"../selectors/user";import{getIsConnected}from"../selectors/client";import{INDEX_PATH}from"../constants/RoutePaths";import appConfig from"../helpers/config";import authRoutes from"../collections/AuthRoutes";import ToastProvider from"../providers/toast";/**
2
2
  * Router subscriptions.
3
3
  * @param {Function} subscribe The subscribe function.
4
- */export default function routerSubscriptions(subscribe){subscribe(navigate$,/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(params){var action,dispatch,getState,events,showConnectivityError,_action$params,silent,steps,resetToPathname,historyAction,routeState,location,state,historyLength,historyEmpty,_ref2,currentPathname,protector,_ref3,redirect,matcher,pathParams,queryParams,_getCurrentRoute2,pathname,pattern,_ref5,transform,route,parsedLocation,parsedRedirect,stringifiedQuery,finalRedirect,parsed,_ref7,_pathname,search;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:if(!IS_PAGE_PREVIEW_ACTIVE){_context.next=2;break;}return _context.abrupt("return");case 2:action=params.action,dispatch=params.dispatch,getState=params.getState,events=params.events;/**
4
+ */export default function routerSubscriptions(subscribe){subscribe(navigate$,/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(params){var _parsed$query;var action,dispatch,getState,events,showConnectivityError,_action$params,silent,steps,resetToPathname,historyAction,routeState,location,state,historyLength,historyEmpty,_ref2,currentPathname,protector,_ref3,redirect,matcher,pathParams,queryParams,_getCurrentRoute2,pathname,pattern,_ref5,transform,route,parsedLocation,parsedRedirect,stringifiedQuery,finalRedirect,parsed,hasBase,u,_ref7,_pathname,search;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:if(!IS_PAGE_PREVIEW_ACTIVE){_context.next=2;break;}return _context.abrupt("return");case 2:action=params.action,dispatch=params.dispatch,getState=params.getState,events=params.events;/**
5
5
  * Triggers a connectivity error toast message
6
6
  */showConnectivityError=function showConnectivityError(){events.emit(ToastProvider.ADD,{id:'navigate.error',message:'error.general'});};_action$params=action.params,silent=_action$params.silent,steps=_action$params.steps,resetToPathname=_action$params.pathname,historyAction=_action$params.action,routeState=_action$params.state;location=action.params.pathname;state=getState();historyLength=getRouterStackIndex(state)+1;historyEmpty=historyLength===1;_ref2=getCurrentRoute(state)||{},currentPathname=_ref2.pathname;if(!(historyEmpty&&[ACTION_POP,ACTION_RESET,HISTORY_RESET_TO].includes(historyAction))){_context.next=15;break;}if(!(currentPathname&&currentPathname===INDEX_PATH)){_context.next=13;break;}return _context.abrupt("return");case 13:/**
7
7
  * Replace the current route with the index, when a history action is supposed to be
@@ -21,9 +21,10 @@ if(!protector){_context.next=41;break;}dispatch(navigate({action:historyAction,p
21
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
- showConnectivityError();return _context.abrupt("return");case 71:// Override the location if is Shop link is found.
24
+ showConnectivityError();return _context.abrupt("return");case 71:if(parsed===null||parsed===void 0?void 0:(_parsed$query=parsed.query)===null||_parsed$query===void 0?void 0:_parsed$query.coupon){hasBase=location.startsWith('http://')||location.startsWith('https://');// Remove the coupon query parameter from internal URLs and redeem the coupon.
25
+ if(!hasBase){dispatch(addCouponsToCart([parsed.query.coupon],false));u=new URL(location,hasBase?undefined:'http://example.com');u.searchParams["delete"]('coupon');location=hasBase?u.toString():u.pathname+u.search+u.hash;}}// Override the location if is Shop link is found.
25
26
  if(handler.isShopLink(location)){_ref7=new URL(location),_pathname=_ref7.pathname,search=_ref7.search;location="".concat(_pathname).concat(search);}// If there is one of the known protocols in the url.
26
- if(!(location&&handler.hasKnownProtocols(location))){_context.next=75;break;}if(handler.isExternalLink(location)){handler.openExternalLink(location,historyAction,state,routeState);}else if(handler.isNativeLink(location)){handler.openNativeLink(location);}return _context.abrupt("return");case 75:if(!(location&&handler.isLegacyPage(location))){_context.next=78;break;}handler.openLegacy(location,historyAction,state);return _context.abrupt("return");case 78:if(!(location&&handler.isLegacyLink(location))){_context.next=81;break;}handler.openLegacyLink(location,historyAction,state);return _context.abrupt("return");case 81:_context.t2=historyAction;_context.next=_context.t2===ACTION_PUSH?84:_context.t2===ACTION_REPLACE?86:88;break;case 84:router.push({pathname:location,state:routeState,emitBefore:silent,emitAfter:silent});return _context.abrupt("break",89);case 86:router.replace({pathname:location,state:routeState,emitBefore:silent,emitAfter:silent});return _context.abrupt("break",89);case 88:return _context.abrupt("break",89);case 89:case"end":return _context.stop();}},_callee,null,[[49,55]]);}));return function(_x){return _ref.apply(this,arguments);};}());/**
27
+ if(!(location&&handler.hasKnownProtocols(location))){_context.next=76;break;}if(handler.isExternalLink(location)){handler.openExternalLink(location,historyAction,state,routeState);}else if(handler.isNativeLink(location)){handler.openNativeLink(location);}return _context.abrupt("return");case 76:if(!(location&&handler.isLegacyPage(location))){_context.next=79;break;}handler.openLegacy(location,historyAction,state);return _context.abrupt("return");case 79:if(!(location&&handler.isLegacyLink(location))){_context.next=82;break;}handler.openLegacyLink(location,historyAction,state);return _context.abrupt("return");case 82:_context.t2=historyAction;_context.next=_context.t2===ACTION_PUSH?85:_context.t2===ACTION_REPLACE?87:89;break;case 85:router.push({pathname:location,state:routeState,emitBefore:silent,emitAfter:silent});return _context.abrupt("break",90);case 87:router.replace({pathname:location,state:routeState,emitBefore:silent,emitAfter:silent});return _context.abrupt("break",90);case 89:return _context.abrupt("break",90);case 90:case"end":return _context.stop();}},_callee,null,[[49,55]]);}));return function(_x){return _ref.apply(this,arguments);};}());/**
27
28
  * Added a 100ms delay here to allow the Redux action to complete.
28
29
  * Without it the store would show that the user is still not
29
30
  * logged in during the upcoming navigate() action.