@shopgate/pwa-tracking 7.30.0-alpha.6 → 7.30.0-alpha.8

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.
package/selectors/page.js CHANGED
@@ -1,27 +1,65 @@
1
- import{createSelector}from'reselect';import{getCurrentPathname,makeGetRouteParam}from'@shopgate/engage/core/selectors';import{isDev}from'@shopgate/engage/core/helpers';import{makeGetUnifiedCMSPageData}from'@shopgate/engage/page/selectors';import{shopNumber}from'@shopgate/pwa-common/helpers/config';/**
1
+ import { createSelector } from 'reselect';
2
+ import { getCurrentPathname, makeGetRouteParam } from '@shopgate/engage/core/selectors';
3
+ import { isDev } from '@shopgate/engage/core/helpers';
4
+ import { makeGetUnifiedCMSPageData } from '@shopgate/engage/page/selectors';
5
+ import { shopNumber } from '@shopgate/pwa-common/helpers/config';
6
+
7
+ /**
2
8
  * The tracking base URL.
3
9
  * @type {string}
4
- */var baseUrl="https://rapid.shopgate.com".concat(isDev?'/php/shopgate':'',"/sg_app_resources");/**
10
+ */
11
+ const baseUrl = `https://rapid.shopgate.com${isDev ? '/php/shopgate' : ''}/sg_app_resources`;
12
+
13
+ /**
5
14
  * The mapping of page names to tracking page names.
6
15
  * @type {Object}
7
- */var pageNameMap={'':'startpage',product:'productDetails',item:'productDetails',category:'productList'};/**
16
+ */
17
+ const pageNameMap = {
18
+ '': 'startpage',
19
+ product: 'productDetails',
20
+ item: 'productDetails',
21
+ category: 'productList'
22
+ };
23
+
24
+ /**
8
25
  * Selects the current tracking URL.
9
26
  * @param {Object} state The current state.
10
27
  * @returns {string} The URL.
11
- */var getTrackingUrl=createSelector(getCurrentPathname,function(pathname){return"".concat(baseUrl,"/").concat(shopNumber).concat(pathname);});/**
28
+ */
29
+ const getTrackingUrl = createSelector(getCurrentPathname, pathname => `${baseUrl}/${shopNumber}${pathname}`);
30
+
31
+ /**
12
32
  * Extracts the name of the current path.
13
33
  * @param {Object} state The current state.
14
34
  * @returns {string} The name.
15
- */var getPageName=createSelector(getCurrentPathname,function(pathname){return pathname.split('?')[0].split('/')[1];});/**
35
+ */
36
+ const getPageName = createSelector(getCurrentPathname, pathname => pathname.split('?')[0].split('/')[1]);
37
+
38
+ /**
16
39
  * Selects the tracking page name based on the current page name.
17
40
  * @param {Object} state The current state.
18
41
  * @returns {string} The page name.
19
- */var getPageTrackingName=createSelector(getPageName,function(pageName){return pageNameMap[pageName]||pageName;});/**
42
+ */
43
+ const getPageTrackingName = createSelector(getPageName, pageName => pageNameMap[pageName] || pageName);
44
+
45
+ /**
20
46
  * Creates a selector that retrieves a page config for the current route from the store.
21
47
  * @param {string} name The name of the desired parameter.
22
48
  * @returns {Function}
23
- */export var makeGetRoutePageConfig=function makeGetRoutePageConfig(){var getPageIdRouteParam=makeGetRouteParam('pageId');return createSelector(function(state){return state;},getPageIdRouteParam,function(state,pageId){return pageId?makeGetUnifiedCMSPageData({slug:pageId})(state):null;});};/**
49
+ */
50
+ export const makeGetRoutePageConfig = () => {
51
+ const getPageIdRouteParam = makeGetRouteParam('pageId');
52
+ return createSelector(state => state, getPageIdRouteParam, (state, pageId) => pageId ? makeGetUnifiedCMSPageData({
53
+ slug: pageId
54
+ })(state) : null);
55
+ };
56
+
57
+ /**
24
58
  * Selects the page information.
25
59
  * @param {Object} state The current state.
26
60
  * @returns {Object} The page information.
27
- */export default createSelector(getTrackingUrl,getPageTrackingName,function(link,name){return{link:link,name:name};});
61
+ */
62
+ export default createSelector(getTrackingUrl, getPageTrackingName, (link, name) => ({
63
+ link,
64
+ name
65
+ }));
@@ -1,12 +1,38 @@
1
- import{createSelector}from'reselect';import{makeGetRouteParam,makeGetRoutePattern}from'@shopgate/engage/core/selectors';import{hex2bin}from'@shopgate/engage/core/helpers';import{ITEM_PATTERN}from'@shopgate/engage/product/constants';import{getBaseProduct,getProduct}from'@shopgate/pwa-common-commerce/product/selectors/product';import{formatProductData}from"../helpers";/**
1
+ import { createSelector } from 'reselect';
2
+ import { makeGetRouteParam, makeGetRoutePattern } from '@shopgate/engage/core/selectors';
3
+ import { hex2bin } from '@shopgate/engage/core/helpers';
4
+ import { ITEM_PATTERN } from '@shopgate/engage/product/constants';
5
+ import { getBaseProduct, getProduct } from '@shopgate/pwa-common-commerce/product/selectors/product';
6
+ import { formatProductData } from "../helpers";
7
+
8
+ /**
2
9
  * Gets the current base product in a formatted way.
3
10
  * @param {Object} state The current state.
4
11
  * @returns {Object} The formatted selected variant.
5
- */export var getBaseProductFormatted=createSelector(getBaseProduct,formatProductData);/**
12
+ */
13
+ export const getBaseProductFormatted = createSelector(getBaseProduct, formatProductData);
14
+
15
+ /**
6
16
  * Gets the current product in a formatted way.
7
17
  * @param {Object} state The current state.
8
18
  * @returns {Object} The formatted selected variant.
9
- */export var getProductFormatted=createSelector(getProduct,formatProductData);/**
19
+ */
20
+ export const getProductFormatted = createSelector(getProduct, formatProductData);
21
+
22
+ /**
10
23
  * Creates a selector that retrieves a formatted product for the current route.
11
24
  * @returns {Function}
12
- */export var makeGetRouteProduct=function makeGetRouteProduct(){var getRoutePattern=makeGetRoutePattern();var getProductIdRouteParam=makeGetRouteParam('productId');return createSelector(function(state){return state;},getRoutePattern,getProductIdRouteParam,function(state,pattern,productId){var decodedProductId=productId?hex2bin(productId):null;if(pattern===ITEM_PATTERN&&decodedProductId){return getProductFormatted(state,{productId:decodedProductId});}return null;});};
25
+ */
26
+ export const makeGetRouteProduct = () => {
27
+ const getRoutePattern = makeGetRoutePattern();
28
+ const getProductIdRouteParam = makeGetRouteParam('productId');
29
+ return createSelector(state => state, getRoutePattern, getProductIdRouteParam, (state, pattern, productId) => {
30
+ const decodedProductId = productId ? hex2bin(productId) : null;
31
+ if (pattern === ITEM_PATTERN && decodedProductId) {
32
+ return getProductFormatted(state, {
33
+ productId: decodedProductId
34
+ });
35
+ }
36
+ return null;
37
+ });
38
+ };
@@ -1,13 +1,43 @@
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{createSelector}from'reselect';import{getSortOrder,getSearchPhrase}from'@shopgate/engage/core/selectors';import{generateResultHash}from'@shopgate/engage/core/helpers';import{getFulfillmentParams}from'@shopgate/pwa-common-commerce/product';/**
1
+ import { createSelector } from 'reselect';
2
+ import { getSortOrder, getSearchPhrase } from '@shopgate/engage/core/selectors';
3
+ import { generateResultHash } from '@shopgate/engage/core/helpers';
4
+ import { getFulfillmentParams } from '@shopgate/pwa-common-commerce/product';
5
+
6
+ /**
2
7
  * Selects the container for search results.
3
8
  * @param {Object} state The current state.
4
9
  * @returns {Object} The search results.
5
- */var resultsSelector=function resultsSelector(state){return state.product.resultsByHash;};/**
10
+ */
11
+ const resultsSelector = state => state.product.resultsByHash;
12
+
13
+ /**
6
14
  * Selects the product count for a search result.
7
15
  * @param {Object} state The current state.
8
16
  * @returns {number} The total product count.
9
- */var resultCountSelector=createSelector(getSearchPhrase,getSortOrder,resultsSelector,getFulfillmentParams,function(searchPhrase,sort,results,fulfillmentParams){var hash=searchPhrase&&generateResultHash(_extends({sort:sort,searchPhrase:searchPhrase},fulfillmentParams));if(!hash||!results[hash]){return null;}return results[hash].totalResultCount;});/**
17
+ */
18
+ const resultCountSelector = createSelector(getSearchPhrase, getSortOrder, resultsSelector, getFulfillmentParams, (searchPhrase, sort, results, fulfillmentParams) => {
19
+ const hash = searchPhrase && generateResultHash({
20
+ sort,
21
+ searchPhrase,
22
+ ...fulfillmentParams
23
+ });
24
+ if (!hash || !results[hash]) {
25
+ return null;
26
+ }
27
+ return results[hash].totalResultCount;
28
+ });
29
+
30
+ /**
10
31
  * Selects the search information.
11
32
  * @param {Object} state The current state.
12
33
  * @returns {Object} The search information.
13
- */export default createSelector(getSearchPhrase,resultCountSelector,function(query,resultCount){if(!query&&!resultCount){return null;}return{query:query,resultCount:resultCount};});
34
+ */
35
+ export default createSelector(getSearchPhrase, resultCountSelector, (query, resultCount) => {
36
+ if (!query && !resultCount) {
37
+ return null;
38
+ }
39
+ return {
40
+ query,
41
+ resultCount
42
+ };
43
+ });
package/selectors/user.js CHANGED
@@ -1,5 +1,34 @@
1
- var _excluded=["isFetching","loginType"];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 _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import{createSelector}from'reselect';import{DEFAULT_LOGIN_STRATEGY,isUserLoggedIn,getUserData,makeGetLoginStrategy}from'@shopgate/engage/user';/**
1
+ import { createSelector } from 'reselect';
2
+ import { DEFAULT_LOGIN_STRATEGY, isUserLoggedIn, getUserData, makeGetLoginStrategy } from '@shopgate/engage/user';
3
+
4
+ /**
2
5
  * Creates a selector that retrieves user tracking data from the store.
3
6
  * @param {string} name The name of the desired parameter.
4
7
  * @returns {Function}
5
- */export function makeGetUser(){var getLoginStrategy=makeGetLoginStrategy();return createSelector(isUserLoggedIn,getUserData,getLoginStrategy,function(isLoggedIn,userData,loginStrategy){if(!isLoggedIn||!userData){return null;}var _ref=userData||{},isFetching=_ref.isFetching,loginType=_ref.loginType,trackedData=_objectWithoutProperties(_ref,_excluded);if(Object.keys(trackedData).length===0){return null;}var type=null;if(loginStrategy!==DEFAULT_LOGIN_STRATEGY){type=loginStrategy;}else if(['userGuest','userAccount'].includes(loginType)){type=loginType==='userGuest'?'guest':'standard';}return _extends({},trackedData,{type:type});});}
8
+ */
9
+ export function makeGetUser() {
10
+ const getLoginStrategy = makeGetLoginStrategy();
11
+ return createSelector(isUserLoggedIn, getUserData, getLoginStrategy, (isLoggedIn, userData, loginStrategy) => {
12
+ if (!isLoggedIn || !userData) {
13
+ return null;
14
+ }
15
+ const {
16
+ isFetching,
17
+ loginType,
18
+ ...trackedData
19
+ } = userData || {};
20
+ if (Object.keys(trackedData).length === 0) {
21
+ return null;
22
+ }
23
+ let type = null;
24
+ if (loginStrategy !== DEFAULT_LOGIN_STRATEGY) {
25
+ type = loginStrategy;
26
+ } else if (['userGuest', 'userAccount'].includes(loginType)) {
27
+ type = loginType === 'userGuest' ? 'guest' : 'standard';
28
+ }
29
+ return {
30
+ ...trackedData,
31
+ type
32
+ };
33
+ });
34
+ }
package/spec.js CHANGED
@@ -1 +1,6 @@
1
- describe('Blank Test',function(){it('Ignore',function(){var x=5;expect(x).toEqual(5);});});
1
+ describe('Blank Test', () => {
2
+ it('Ignore', () => {
3
+ const x = 5;
4
+ expect(x).toEqual(5);
5
+ });
6
+ });
package/streams/app.js CHANGED
@@ -1,6 +1,12 @@
1
- import{pwaDidAppear$,pwaDidDisappear$}from'@shopgate/pwa-common/streams/app';/**
1
+ import { pwaDidAppear$, pwaDidDisappear$ } from '@shopgate/pwa-common/streams/app';
2
+
3
+ /**
2
4
  * Emits when the PWA visibility changes
3
- */export var pwaVisibility$=pwaDidAppear$.merge(pwaDidDisappear$);/**
5
+ */
6
+ export const pwaVisibility$ = pwaDidAppear$.merge(pwaDidDisappear$);
7
+
8
+ /**
4
9
  * Export the streams again from here, since e.g. checkout extensions import them.
5
10
  * @deprecated
6
- */export{pwaDidAppear$,pwaDidDisappear$};
11
+ */
12
+ export { pwaDidAppear$, pwaDidDisappear$ };
package/streams/cart.js CHANGED
@@ -1,13 +1,56 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";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'rxjs/add/operator/switchMap';import'rxjs/add/observable/of';import'rxjs/add/observable/defer';import{Observable}from'rxjs/Observable';import{productsAdded$ as originalProductsAdded$}from'@shopgate/engage/cart/streams';import{getProductById,fetchProductsById}from'@shopgate/engage/product';/**
1
+ import 'rxjs/add/operator/switchMap';
2
+ import 'rxjs/add/observable/of';
3
+ import 'rxjs/add/observable/defer';
4
+ import { Observable } from 'rxjs/Observable';
5
+ import { productsAdded$ as originalProductsAdded$ } from '@shopgate/engage/cart/streams';
6
+ import { getProductById, fetchProductsById } from '@shopgate/engage/product';
7
+
8
+ /**
2
9
  * Emits when a product was added to the cart and product data is available
3
- */export var productsAdded$=originalProductsAdded$.switchMap(function(input){var getState=input.getState,action=input.action,dispatch=input.dispatch;var _action$products=action.products,products=_action$products===void 0?[]:_action$products;// Collect product ids from the add-to-cart action
4
- var productIds=products.map(function(_ref){var productId=_ref.productId;return productId;}).filter(Boolean);// Check if we have product data for all productIds
5
- var productDataAvailable=productIds.every(function(productId){return getProductById(getState(),{productId:productId});});if(productDataAvailable){// All product data for the tracking event is available - handover action data to subscribers
6
- return Observable.of(input);}/**
7
- * Incomplete product data can be caused by an add-to-cart push message. In that case the
8
- * product was never fetched before due to visiting PDP. So we need to fetch missing product
9
- * data first.
10
- * Subscribers will receive the original action when product data comes available.
11
- */return Observable.defer(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var result;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:result={products:[]};_context.prev=1;_context.next=4;return dispatch(fetchProductsById(productIds));case 4:result=_context.sent;_context.next=9;break;case 7:_context.prev=7;_context.t0=_context["catch"](1);case 9:return _context.abrupt("return",result);case 10:case"end":return _context.stop();}},_callee,null,[[1,7]]);}))).first()// do not proceed when request didn't return any products (no suitable tracking data)
12
- .filter(function(data){return Array.isArray(data.products)&&data.products.length>0;})// handover original action to subscribers
13
- .switchMap(function(){return Observable.of(input);});});
10
+ */
11
+ export const productsAdded$ = originalProductsAdded$.switchMap(input => {
12
+ const {
13
+ getState,
14
+ action,
15
+ dispatch
16
+ } = input;
17
+ const {
18
+ products = []
19
+ } = action;
20
+
21
+ // Collect product ids from the add-to-cart action
22
+ const productIds = products.map(({
23
+ productId
24
+ }) => productId).filter(Boolean);
25
+
26
+ // Check if we have product data for all productIds
27
+ const productDataAvailable = productIds.every(productId => getProductById(getState(), {
28
+ productId
29
+ }));
30
+ if (productDataAvailable) {
31
+ // All product data for the tracking event is available - handover action data to subscribers
32
+ return Observable.of(input);
33
+ }
34
+
35
+ /**
36
+ * Incomplete product data can be caused by an add-to-cart push message. In that case the
37
+ * product was never fetched before due to visiting PDP. So we need to fetch missing product
38
+ * data first.
39
+ * Subscribers will receive the original action when product data comes available.
40
+ */
41
+ return Observable.defer(async () => {
42
+ let result = {
43
+ products: []
44
+ };
45
+ try {
46
+ result = await dispatch(fetchProductsById(productIds));
47
+ } catch (e) {
48
+ // nothing to do here - default result will be returned
49
+ }
50
+ return result;
51
+ }).first()
52
+ // do not proceed when request didn't return any products (no suitable tracking data)
53
+ .filter(data => Array.isArray(data.products) && data.products.length > 0)
54
+ // handover original action to subscribers
55
+ .switchMap(() => Observable.of(input));
56
+ });
@@ -1,19 +1,80 @@
1
- import'rxjs/add/operator/switchMap';import'rxjs/add/observable/of';import{Observable}from'rxjs/Observable';import{routeDidEnter$,pwaDidAppear$}from'@shopgate/engage/core/streams';import{hex2bin}from'@shopgate/engage/core/helpers';import{ROOT_CATEGORY_PATTERN,CATEGORY_PATTERN}from'@shopgate/engage/category/constants';import{getProductsResult}from'@shopgate/pwa-common-commerce/product/selectors/product';import{receivedRootCategories$}from'@shopgate/engage/category/streams';import{getRootCategories}from'@shopgate/engage/category/selectors';import{getIsAppWebViewVisible}from'@shopgate/engage/core/selectors';import{productsReceived$}from"./product";/**
1
+ import 'rxjs/add/operator/switchMap';
2
+ import 'rxjs/add/observable/of';
3
+ import { Observable } from 'rxjs/Observable';
4
+ import { routeDidEnter$, pwaDidAppear$ } from '@shopgate/engage/core/streams';
5
+ import { hex2bin } from '@shopgate/engage/core/helpers';
6
+ import { ROOT_CATEGORY_PATTERN, CATEGORY_PATTERN } from '@shopgate/engage/category/constants';
7
+ import { getProductsResult } from '@shopgate/pwa-common-commerce/product/selectors/product';
8
+ import { receivedRootCategories$ } from '@shopgate/engage/category/streams';
9
+ import { getRootCategories } from '@shopgate/engage/category/selectors';
10
+ import { getIsAppWebViewVisible } from '@shopgate/engage/core/selectors';
11
+ import { productsReceived$ } from "./product";
12
+
13
+ /**
2
14
  * Emits when the root category was entered.
3
- */var rootCategoryDidEnter$=routeDidEnter$.filter(function(_ref){var action=_ref.action;return action.route.pattern===ROOT_CATEGORY_PATTERN;});/**
15
+ */
16
+ const rootCategoryDidEnter$ = routeDidEnter$.filter(({
17
+ action
18
+ }) => action.route.pattern === ROOT_CATEGORY_PATTERN);
19
+
20
+ /**
4
21
  * Emits when a regular category was entered.
5
- */var categoryDidEnter$=routeDidEnter$.filter(function(_ref2){var action=_ref2.action;return action.route.pattern===CATEGORY_PATTERN;});/**
22
+ */
23
+ const categoryDidEnter$ = routeDidEnter$.filter(({
24
+ action
25
+ }) => action.route.pattern === CATEGORY_PATTERN);
26
+
27
+ /**
6
28
  * Emits when the root category data has been received.
7
- */var rootCategoryLoaded$=rootCategoryDidEnter$.switchMap(function(){return receivedRootCategories$;});/**
29
+ */
30
+ const rootCategoryLoaded$ = rootCategoryDidEnter$.switchMap(() => receivedRootCategories$);
31
+
32
+ /**
8
33
  * Emits when a root category's data is already available.
9
- */var rootCategoryPreloaded$=rootCategoryDidEnter$.filter(function(_ref3){var getState=_ref3.getState;var rootCategories=getRootCategories(getState());return rootCategories?!!rootCategories.length:false;});/**
34
+ */
35
+ const rootCategoryPreloaded$ = rootCategoryDidEnter$.filter(({
36
+ getState
37
+ }) => {
38
+ const rootCategories = getRootCategories(getState());
39
+ return rootCategories ? !!rootCategories.length : false;
40
+ });
41
+
42
+ /**
10
43
  * Emits when a category's data is available.
11
- */var categoryDataLoaded$=categoryDidEnter$// Do not track while PWA webview is in the background
12
- .filter(function(_ref4){var getState=_ref4.getState;return getIsAppWebViewVisible(getState());}).switchMap(function(data){var action=data.action,getState=data.getState;var categoryId=action.route.params.categoryId;// Check if products for the current route are already available within Redux.
13
- var productsLoaded=getProductsResult(getState(),{categoryId:hex2bin(categoryId)}).totalProductCount!==null;if(!productsLoaded){// Wait for incoming products if they are not available yet.
14
- return productsReceived$.first();}return Observable.of(data);});/**
44
+ */
45
+ const categoryDataLoaded$ = categoryDidEnter$
46
+ // Do not track while PWA webview is in the background
47
+ .filter(({
48
+ getState
49
+ }) => getIsAppWebViewVisible(getState())).switchMap(data => {
50
+ const {
51
+ action,
52
+ getState
53
+ } = data;
54
+ const {
55
+ categoryId
56
+ } = action.route.params;
57
+
58
+ // Check if products for the current route are already available within Redux.
59
+ const productsLoaded = getProductsResult(getState(), {
60
+ categoryId: hex2bin(categoryId)
61
+ }).totalProductCount !== null;
62
+ if (!productsLoaded) {
63
+ // Wait for incoming products if they are not available yet.
64
+ return productsReceived$.first();
65
+ }
66
+ return Observable.of(data);
67
+ });
68
+
69
+ /**
15
70
  * Emits when the category route comes active again after a legacy page was active.
16
- */var categoryRouteReappeared$=pwaDidAppear$.filter(function(_ref5){var action=_ref5.action;return[CATEGORY_PATTERN,ROOT_CATEGORY_PATTERN].includes(action.route.pattern);});/**
71
+ */
72
+ const categoryRouteReappeared$ = pwaDidAppear$.filter(({
73
+ action
74
+ }) => [CATEGORY_PATTERN, ROOT_CATEGORY_PATTERN].includes(action.route.pattern));
75
+
76
+ /**
17
77
  * Emits when a category or root category is ready to be tracked,
18
78
  * considering loaded or preloaded data.
19
- */export var categoryIsReady$=categoryDataLoaded$.merge(rootCategoryLoaded$,rootCategoryPreloaded$,categoryRouteReappeared$);
79
+ */
80
+ export const categoryIsReady$ = categoryDataLoaded$.merge(rootCategoryLoaded$, rootCategoryPreloaded$, categoryRouteReappeared$);
@@ -1,5 +1,26 @@
1
- import{ACTION_REPLACE,ACTION_PUSH}from'@virtuous/conductor';import{navigate$}from'@shopgate/pwa-common/streams/router';import{isUserLoggedIn}from'@shopgate/pwa-common/selectors/user';import{CHECKOUT_PATH}from'@shopgate/pwa-common/constants/RoutePaths';var actionsWl=[ACTION_PUSH,ACTION_REPLACE];export var checkoutDidEnter$=navigate$.filter(function(_ref){var action=_ref.action,getState=_ref.getState;if(action.params.pathname!==CHECKOUT_PATH){return false;}var userLoggedIn=isUserLoggedIn(getState());var navigateAction=action.params.action;// When not logged in users try to navigate to the checkout, they are redirected to the login.
2
- if(!userLoggedIn&&navigateAction===ACTION_PUSH){return false;}/**
3
- * A checkout route can be pushed when a logged in user opens the checkout. It can also replace
4
- * the current route when a user is redirected from the login form after a successful login.
5
- */return actionsWl.includes(navigateAction);});
1
+ import { ACTION_REPLACE, ACTION_PUSH } from '@virtuous/conductor';
2
+ import { navigate$ } from '@shopgate/pwa-common/streams/router';
3
+ import { isUserLoggedIn } from '@shopgate/pwa-common/selectors/user';
4
+ import { CHECKOUT_PATH } from '@shopgate/pwa-common/constants/RoutePaths';
5
+ const actionsWl = [ACTION_PUSH, ACTION_REPLACE];
6
+ export const checkoutDidEnter$ = navigate$.filter(({
7
+ action,
8
+ getState
9
+ }) => {
10
+ if (action.params.pathname !== CHECKOUT_PATH) {
11
+ return false;
12
+ }
13
+ const userLoggedIn = isUserLoggedIn(getState());
14
+ const navigateAction = action.params.action;
15
+
16
+ // When not logged in users try to navigate to the checkout, they are redirected to the login.
17
+ if (!userLoggedIn && navigateAction === ACTION_PUSH) {
18
+ return false;
19
+ }
20
+
21
+ /**
22
+ * A checkout route can be pushed when a logged in user opens the checkout. It can also replace
23
+ * the current route when a user is redirected from the login form after a successful login.
24
+ */
25
+ return actionsWl.includes(navigateAction);
26
+ });
package/streams/page.js CHANGED
@@ -1,10 +1,52 @@
1
- import'rxjs/add/operator/switchMap';import'rxjs/add/observable/of';import{Observable}from'rxjs/Observable';import{RECEIVE_PAGE_CONFIG}from'@shopgate/engage/core/constants';import{main$,routeDidEnter$,pwaDidAppear$}from'@shopgate/engage/core/streams';import{getIsAppWebViewVisible}from'@shopgate/engage/core/selectors';import{PAGE_PATTERN,RECEIVE_PAGE_CONFIG_V2}from'@shopgate/engage/page/constants';import{makeGetUnifiedCMSPageData}from'@shopgate/engage/page/selectors';/**
1
+ import 'rxjs/add/operator/switchMap';
2
+ import 'rxjs/add/observable/of';
3
+ import { Observable } from 'rxjs/Observable';
4
+ import { RECEIVE_PAGE_CONFIG } from '@shopgate/engage/core/constants';
5
+ import { main$, routeDidEnter$, pwaDidAppear$ } from '@shopgate/engage/core/streams';
6
+ import { getIsAppWebViewVisible } from '@shopgate/engage/core/selectors';
7
+ import { PAGE_PATTERN, RECEIVE_PAGE_CONFIG_V2 } from '@shopgate/engage/page/constants';
8
+ import { makeGetUnifiedCMSPageData } from '@shopgate/engage/page/selectors';
9
+
10
+ /**
2
11
  * Emits when a "page" was entered.
3
- */var pageDidEnter$=routeDidEnter$.filter(function(_ref){var action=_ref.action;return action.route.pattern===PAGE_PATTERN;});/**
12
+ */
13
+ const pageDidEnter$ = routeDidEnter$.filter(({
14
+ action
15
+ }) => action.route.pattern === PAGE_PATTERN);
16
+
17
+ /**
4
18
  * Emits when the page route comes active again after a legacy page was active.
5
- */var pageRouteReappeared$=pwaDidAppear$.filter(function(_ref2){var action=_ref2.action;return action.route.pattern===PAGE_PATTERN;});var pageConfigReceived$=main$.filter(function(_ref3){var action=_ref3.action;return[RECEIVE_PAGE_CONFIG,RECEIVE_PAGE_CONFIG_V2].includes(action.type);});/**
19
+ */
20
+ const pageRouteReappeared$ = pwaDidAppear$.filter(({
21
+ action
22
+ }) => action.route.pattern === PAGE_PATTERN);
23
+ const pageConfigReceived$ = main$.filter(({
24
+ action
25
+ }) => [RECEIVE_PAGE_CONFIG, RECEIVE_PAGE_CONFIG_V2].includes(action.type));
26
+
27
+ /**
6
28
  * Emits when a "page" was opened, and its config is available.
7
- */export var pageIsReady$=pageDidEnter$// Do not track while PWA webview is in the background
8
- .filter(function(_ref4){var getState=_ref4.getState;return getIsAppWebViewVisible(getState());}).switchMap(function(data){var action=data.action,getState=data.getState;var pageId=action.route.params.pageId;// Check if the page config for the current route is already available within Redux.
9
- var pageConfig=makeGetUnifiedCMSPageData({slug:pageId})(getState());if(!pageConfig||pageConfig.isFetching){// Wait for incoming page data if it's not available yet.
10
- return pageConfigReceived$.first().switchMap(function(){return Observable.of(data);});}return Observable.of(data);}).merge(pageRouteReappeared$);
29
+ */
30
+ export const pageIsReady$ = pageDidEnter$
31
+ // Do not track while PWA webview is in the background
32
+ .filter(({
33
+ getState
34
+ }) => getIsAppWebViewVisible(getState())).switchMap(data => {
35
+ const {
36
+ action,
37
+ getState
38
+ } = data;
39
+ const {
40
+ pageId
41
+ } = action.route.params;
42
+
43
+ // Check if the page config for the current route is already available within Redux.
44
+ const pageConfig = makeGetUnifiedCMSPageData({
45
+ slug: pageId
46
+ })(getState());
47
+ if (!pageConfig || pageConfig.isFetching) {
48
+ // Wait for incoming page data if it's not available yet.
49
+ return pageConfigReceived$.first().switchMap(() => Observable.of(data));
50
+ }
51
+ return Observable.of(data);
52
+ }).merge(pageRouteReappeared$);
package/streams/pages.js CHANGED
@@ -1,13 +1,40 @@
1
- function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import{appWillStart$,pwaDidAppear$,pwaDidDisappear$,routeDidEnter$}from'@shopgate/engage/core/streams';import{APP_WILL_START,PWA_DID_APPEAR}from'@shopgate/engage/core/constants';import{SEARCH_PATH,SEARCH_FILTER_PATTERN}from'@shopgate/engage/search/constants';import{ROOT_CATEGORY_PATTERN,CATEGORY_PATTERN,CATEGORY_FILTER_PATTERN}from'@shopgate/engage/category/constants';import{ITEM_PATTERN,ITEM_GALLERY_PATTERN,ITEM_REVIEWS_PATTERN,ITEM_WRITE_REVIEW_PATTERN}from'@shopgate/engage/product/constants';import{PAGE_PATTERN}from'@shopgate/engage/page/constants';import{pwaVisibility$}from"./app";import{checkoutDidEnter$}from"./checkout";/**
1
+ import { appWillStart$, pwaDidAppear$, pwaDidDisappear$, routeDidEnter$ } from '@shopgate/engage/core/streams';
2
+ import { APP_WILL_START, PWA_DID_APPEAR } from '@shopgate/engage/core/constants';
3
+ import { SEARCH_PATH, SEARCH_FILTER_PATTERN } from '@shopgate/engage/search/constants';
4
+ import { ROOT_CATEGORY_PATTERN, CATEGORY_PATTERN, CATEGORY_FILTER_PATTERN } from '@shopgate/engage/category/constants';
5
+ import { ITEM_PATTERN, ITEM_GALLERY_PATTERN, ITEM_REVIEWS_PATTERN, ITEM_WRITE_REVIEW_PATTERN } from '@shopgate/engage/product/constants';
6
+ import { PAGE_PATTERN } from '@shopgate/engage/page/constants';
7
+ import { pwaVisibility$ } from "./app";
8
+ import { checkoutDidEnter$ } from "./checkout";
9
+
10
+ /**
2
11
  * A blacklist of paths that should be tracked within their individual subscriptions.
3
12
  * @type {Array}
4
- */export var blacklistedPatterns=[ROOT_CATEGORY_PATTERN,CATEGORY_PATTERN,ITEM_PATTERN,SEARCH_PATH,// Patterns for routes which are not supported for tracking at the moment.
5
- CATEGORY_FILTER_PATTERN,SEARCH_FILTER_PATTERN,ITEM_GALLERY_PATTERN,ITEM_REVIEWS_PATTERN,ITEM_WRITE_REVIEW_PATTERN,PAGE_PATTERN];var latestAppActions$=appWillStart$.merge(pwaVisibility$,checkoutDidEnter$);/**
13
+ */
14
+ export const blacklistedPatterns = [ROOT_CATEGORY_PATTERN, CATEGORY_PATTERN, ITEM_PATTERN, SEARCH_PATH,
15
+ // Patterns for routes which are not supported for tracking at the moment.
16
+ CATEGORY_FILTER_PATTERN, SEARCH_FILTER_PATTERN, ITEM_GALLERY_PATTERN, ITEM_REVIEWS_PATTERN, ITEM_WRITE_REVIEW_PATTERN, PAGE_PATTERN];
17
+ const latestAppActions$ = appWillStart$.merge(pwaVisibility$, checkoutDidEnter$);
18
+
19
+ /**
6
20
  * Route did enter and PWA is visible and route is not blacklisted
7
21
  * @type {Rx.Observable<*[]>}
8
- */var routeDidEnterForVisiblePwa$=routeDidEnter$.withLatestFrom(latestAppActions$).filter(function(_ref){var _ref2=_slicedToArray(_ref,2),type=_ref2[1].action.type;return type===APP_WILL_START||type===PWA_DID_APPEAR;}).map(function(_ref3){var _ref4=_slicedToArray(_ref3,1),routeDidEnter=_ref4[0];return routeDidEnter;});/**
22
+ */
23
+ const routeDidEnterForVisiblePwa$ = routeDidEnter$.withLatestFrom(latestAppActions$).filter(([, {
24
+ action: {
25
+ type
26
+ }
27
+ }]) => type === APP_WILL_START || type === PWA_DID_APPEAR).map(([routeDidEnter]) => routeDidEnter);
28
+
29
+ /**
9
30
  * PWA reappear after disappear
10
31
  * @type {Rx.Observable<any>}
11
- */var pwaDidAppearAfterDisappear=pwaDidDisappear$.switchMap(function(){return pwaDidAppear$.first();});/**
32
+ */
33
+ const pwaDidAppearAfterDisappear = pwaDidDisappear$.switchMap(() => pwaDidAppear$.first());
34
+
35
+ /**
12
36
  * Emits when one of the tracked paths is entered or pwa reappear
13
- */export var pagesAreReady$=routeDidEnterForVisiblePwa$.merge(pwaDidAppearAfterDisappear).filter(function(_ref5){var action=_ref5.action;return!blacklistedPatterns.find(function(pattern){return action.route.pattern===pattern;});});
37
+ */
38
+ export const pagesAreReady$ = routeDidEnterForVisiblePwa$.merge(pwaDidAppearAfterDisappear).filter(({
39
+ action
40
+ }) => !blacklistedPatterns.find(pattern => action.route.pattern === pattern));
@@ -1,11 +1,37 @@
1
- import'rxjs/add/operator/switchMap';import{main$,routeWillEnter$,pwaDidAppear$}from'@shopgate/engage/core/streams';import{getIsAppWebViewVisible}from'@shopgate/engage/core/selectors';import{receivedVisibleProduct$}from'@shopgate/pwa-common-commerce/product/streams';import{RECEIVE_PRODUCTS,ITEM_PATTERN}from'@shopgate/pwa-common-commerce/product/constants';/**
1
+ import 'rxjs/add/operator/switchMap';
2
+ import { main$, routeWillEnter$, pwaDidAppear$ } from '@shopgate/engage/core/streams';
3
+ import { getIsAppWebViewVisible } from '@shopgate/engage/core/selectors';
4
+ import { receivedVisibleProduct$ } from '@shopgate/pwa-common-commerce/product/streams';
5
+ import { RECEIVE_PRODUCTS, ITEM_PATTERN } from '@shopgate/pwa-common-commerce/product/constants';
6
+
7
+ /**
2
8
  * Emits when product results has been received.
3
- */export var productsReceived$=main$.filter(function(_ref){var action=_ref.action;return action.type===RECEIVE_PRODUCTS;});/**
9
+ */
10
+ export const productsReceived$ = main$.filter(({
11
+ action
12
+ }) => action.type === RECEIVE_PRODUCTS);
13
+
14
+ /**
4
15
  * Emits when the category route comes active again after a legacy page was active.
5
- */export var productRouteReappeared$=pwaDidAppear$.filter(function(_ref2){var action=_ref2.action;return action.route.pattern===ITEM_PATTERN;});/**
16
+ */
17
+ export const productRouteReappeared$ = pwaDidAppear$.filter(({
18
+ action
19
+ }) => action.route.pattern === ITEM_PATTERN);
20
+
21
+ /**
6
22
  * Emits when a product page was initially opened.
7
- */export var productWillEnter$=routeWillEnter$.filter(function(_ref3){var action=_ref3.action;return action.route.pattern===ITEM_PATTERN;});/**
23
+ */
24
+ export const productWillEnter$ = routeWillEnter$.filter(({
25
+ action
26
+ }) => action.route.pattern === ITEM_PATTERN);
27
+
28
+ /**
8
29
  * Emits when a product page was initially opened and its data is present.
9
- */export var productIsReady$=productWillEnter$// Do not track while PWA webview is in the background
10
- .filter(function(_ref4){var getState=_ref4.getState;return getIsAppWebViewVisible(getState());})// Take care that the stream only emits when underlying streams emit within the correct order.
11
- .switchMap(function(){return receivedVisibleProduct$.first();}).merge(productRouteReappeared$);
30
+ */
31
+ export const productIsReady$ = productWillEnter$
32
+ // Do not track while PWA webview is in the background
33
+ .filter(({
34
+ getState
35
+ }) => getIsAppWebViewVisible(getState()))
36
+ // Take care that the stream only emits when underlying streams emit within the correct order.
37
+ .switchMap(() => receivedVisibleProduct$.first()).merge(productRouteReappeared$);
@@ -1,2 +1,43 @@
1
- import{main$}from'@shopgate/engage/core/streams';import{scannerDidEnter$}from'@shopgate/engage/scanner/streams';import{SUCCESS_HANDLE_SCANNER,ERROR_HANDLE_SCANNER}from'@shopgate/engage/scanner/constants';import{SCANNER_SCOPE_DEFAULT,SCANNER_TYPE_BARCODE}from'@shopgate/engage/core/constants';/** @type {Observable} */export var scanActivated$=scannerDidEnter$.filter(function(_ref){var action=_ref.action;var _action$route$query=action.route.query,_action$route$query2=_action$route$query===void 0?{}:_action$route$query,_action$route$query2$=_action$route$query2.type,type=_action$route$query2$===void 0?SCANNER_TYPE_BARCODE:_action$route$query2$,_action$route$query2$2=_action$route$query2.scope,scope=_action$route$query2$2===void 0?SCANNER_SCOPE_DEFAULT:_action$route$query2$2;// The stream in supposed to emit only for the Shopgate default scanner.
2
- return type===SCANNER_TYPE_BARCODE&&scope===SCANNER_SCOPE_DEFAULT;});/** @type {Observable} */export var scanSuccess$=main$.filter(function(_ref2){var action=_ref2.action;var type=action.type,scope=action.scope;return type===SUCCESS_HANDLE_SCANNER&&scope===SCANNER_SCOPE_DEFAULT;});/** @type {Observable} */export var scanFail$=main$.filter(function(_ref3){var action=_ref3.action;var type=action.type,scope=action.scope;return type===ERROR_HANDLE_SCANNER&&scope===SCANNER_SCOPE_DEFAULT;});
1
+ import { main$ } from '@shopgate/engage/core/streams';
2
+ import { scannerDidEnter$ } from '@shopgate/engage/scanner/streams';
3
+ import { SUCCESS_HANDLE_SCANNER, ERROR_HANDLE_SCANNER } from '@shopgate/engage/scanner/constants';
4
+ import { SCANNER_SCOPE_DEFAULT, SCANNER_TYPE_BARCODE } from '@shopgate/engage/core/constants';
5
+
6
+ /** @type {Observable} */
7
+ export const scanActivated$ = scannerDidEnter$.filter(({
8
+ action
9
+ }) => {
10
+ const {
11
+ route: {
12
+ query: {
13
+ type = SCANNER_TYPE_BARCODE,
14
+ scope = SCANNER_SCOPE_DEFAULT
15
+ } = {}
16
+ }
17
+ } = action;
18
+
19
+ // The stream in supposed to emit only for the Shopgate default scanner.
20
+ return type === SCANNER_TYPE_BARCODE && scope === SCANNER_SCOPE_DEFAULT;
21
+ });
22
+
23
+ /** @type {Observable} */
24
+ export const scanSuccess$ = main$.filter(({
25
+ action
26
+ }) => {
27
+ const {
28
+ type,
29
+ scope
30
+ } = action;
31
+ return type === SUCCESS_HANDLE_SCANNER && scope === SCANNER_SCOPE_DEFAULT;
32
+ });
33
+
34
+ /** @type {Observable} */
35
+ export const scanFail$ = main$.filter(({
36
+ action
37
+ }) => {
38
+ const {
39
+ type,
40
+ scope
41
+ } = action;
42
+ return type === ERROR_HANDLE_SCANNER && scope === SCANNER_SCOPE_DEFAULT;
43
+ });