@shopgate/pwa-common 7.30.0-alpha.7 → 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.
Files changed (306) hide show
  1. package/App.js +48 -6
  2. package/action-creators/app/index.js +75 -12
  3. package/action-creators/app/spec.js +96 -1
  4. package/action-creators/client/index.js +27 -5
  5. package/action-creators/client/spec.js +44 -1
  6. package/action-creators/error/index.js +15 -3
  7. package/action-creators/index.js +9 -1
  8. package/action-creators/menu/index.js +23 -4
  9. package/action-creators/menu/spec.js +37 -1
  10. package/action-creators/modal/index.js +15 -3
  11. package/action-creators/modal/spec.js +26 -1
  12. package/action-creators/page/index.js +24 -4
  13. package/action-creators/page/spec.js +38 -1
  14. package/action-creators/router/index.js +48 -7
  15. package/action-creators/url/index.js +24 -4
  16. package/action-creators/url/spec.js +45 -1
  17. package/action-creators/user/index.js +90 -13
  18. package/action-creators/user/spec.js +186 -2
  19. package/actions/app/handleDeepLink.js +11 -2
  20. package/actions/app/handleLink.js +62 -6
  21. package/actions/app/handlePushNotification.js +32 -4
  22. package/actions/app/handleUniversalLink.js +11 -2
  23. package/actions/app/registerLinkEvents.js +24 -3
  24. package/actions/client/fetchClientInformation.js +26 -2
  25. package/actions/menu/fetchMenu.js +23 -2
  26. package/actions/modal/closeModal.js +18 -2
  27. package/actions/modal/promiseMap.js +3 -1
  28. package/actions/modal/showModal.js +54 -8
  29. package/actions/page/fetchPageConfig.js +69 -2
  30. package/actions/page/getPageConfig.js +6 -2
  31. package/actions/page/index.js +1 -1
  32. package/actions/router/historyPop.js +12 -2
  33. package/actions/router/historyPopToRoute.js +27 -2
  34. package/actions/router/historyPush.js +12 -2
  35. package/actions/router/historyRedirect.js +21 -2
  36. package/actions/router/historyReplace.js +20 -3
  37. package/actions/router/historyReset.js +11 -2
  38. package/actions/router/historyResetTo.js +12 -2
  39. package/actions/router/index.js +17 -1
  40. package/actions/router/routeDidPop.js +11 -2
  41. package/actions/router/routeDidPush.js +13 -2
  42. package/actions/router/routeDidReplace.js +11 -2
  43. package/actions/router/routeDidReset.js +11 -2
  44. package/actions/router/routeDidUpdate.js +10 -2
  45. package/actions/router/routeWillPop.js +11 -2
  46. package/actions/router/routeWillPush.js +13 -2
  47. package/actions/router/routeWillReplace.js +11 -2
  48. package/actions/router/routeWillReset.js +11 -2
  49. package/actions/router/windowOpenOverride.js +10 -2
  50. package/actions/user/fetchRegisterUrl.js +36 -2
  51. package/actions/user/fetchUser.js +29 -3
  52. package/actions/user/getUser.js +6 -2
  53. package/actions/user/index.js +1 -1
  54. package/actions/user/login.js +76 -9
  55. package/actions/user/logout.js +30 -2
  56. package/collections/AuthRoutes.js +73 -14
  57. package/collections/Configuration.js +54 -7
  58. package/collections/EmbeddedMedia.js +84 -11
  59. package/collections/PersistedReducers.js +41 -6
  60. package/collections/Redirects.js +103 -17
  61. package/collections/index.js +5 -1
  62. package/collections/media-providers/MediaProvider.js +151 -26
  63. package/collections/media-providers/Vimeo.js +113 -19
  64. package/collections/media-providers/YouTube.js +74 -14
  65. package/collections/media-providers/index.js +3 -1
  66. package/collections/media-providers/style.js +52 -2
  67. package/components/Backdrop/index.js +95 -6
  68. package/components/Backdrop/spec.js +23 -1
  69. package/components/Backdrop/style.js +11 -2
  70. package/components/Button/index.js +47 -5
  71. package/components/Button/spec.js +36 -1
  72. package/components/Button/style.js +6 -1
  73. package/components/Checkbox/index.js +126 -32
  74. package/components/Checkbox/spec.js +94 -3
  75. package/components/Consume/helpers/buildParams.js +13 -2
  76. package/components/Consume/index.js +14 -2
  77. package/components/CountdownTimer/index.js +115 -17
  78. package/components/CountdownTimer/spec.js +126 -12
  79. package/components/Drawer/index.js +131 -16
  80. package/components/Drawer/spec.js +76 -1
  81. package/components/Drawer/style.js +37 -1
  82. package/components/Dropdown/index.js +65 -6
  83. package/components/Dropdown/style.js +4 -1
  84. package/components/Dropdown/transitions.js +34 -1
  85. package/components/Ellipsis/index.js +16 -2
  86. package/components/Ellipsis/spec.js +13 -1
  87. package/components/EmbeddedMedia/index.js +56 -6
  88. package/components/EmbeddedMedia/spec.js +52 -3
  89. package/components/ErrorBoundary/connector.js +9 -2
  90. package/components/ErrorBoundary/index.js +43 -7
  91. package/components/Grid/components/Item/index.js +40 -4
  92. package/components/Grid/components/Item/spec.js +23 -1
  93. package/components/Grid/components/Item/style.js +17 -3
  94. package/components/Grid/index.js +36 -4
  95. package/components/Grid/spec.js +23 -1
  96. package/components/Grid/style.js +11 -2
  97. package/components/HtmlSanitizer/connector.js +24 -3
  98. package/components/HtmlSanitizer/index.js +104 -12
  99. package/components/HtmlSanitizer/spec.js +207 -6
  100. package/components/I18n/components/FormatDate/index.js +26 -2
  101. package/components/I18n/components/FormatDate/spec.js +46 -1
  102. package/components/I18n/components/FormatNumber/index.js +34 -2
  103. package/components/I18n/components/FormatNumber/spec.js +41 -2
  104. package/components/I18n/components/FormatPrice/index.js +32 -2
  105. package/components/I18n/components/FormatPrice/spec.js +46 -1
  106. package/components/I18n/components/FormatTime/index.js +26 -2
  107. package/components/I18n/components/FormatTime/spec.js +43 -2
  108. package/components/I18n/components/I18nProvider/index.js +52 -9
  109. package/components/I18n/components/I18nProvider/spec.js +39 -1
  110. package/components/I18n/components/Placeholder/index.js +8 -2
  111. package/components/I18n/components/Placeholder/spec.js +30 -1
  112. package/components/I18n/components/Translate/index.js +68 -7
  113. package/components/I18n/components/Translate/spec.js +30 -1
  114. package/components/I18n/index.js +16 -1
  115. package/components/Icon/index.js +25 -2
  116. package/components/Icon/style.js +6 -1
  117. package/components/Image/Image.js +176 -19
  118. package/components/Image/ImageInner.js +48 -2
  119. package/components/Image/index.js +1 -1
  120. package/components/Image/style.js +29 -2
  121. package/components/InfiniteContainer/index.js +381 -49
  122. package/components/InfiniteContainer/spec.js +199 -10
  123. package/components/Input/components/DateInput.js +262 -6
  124. package/components/Input/components/MultiLineInput.js +98 -12
  125. package/components/Input/components/SimpleInput.js +207 -31
  126. package/components/Input/index.js +32 -3
  127. package/components/Input/spec.js +122 -1
  128. package/components/KeyboardConsumer/index.js +48 -7
  129. package/components/Link/connector.js +7 -1
  130. package/components/Link/index.js +96 -11
  131. package/components/Link/spec.js +56 -1
  132. package/components/Link/style.js +10 -1
  133. package/components/List/components/Item/index.js +35 -3
  134. package/components/List/components/Item/style.js +16 -1
  135. package/components/List/index.js +20 -2
  136. package/components/List/spec.js +31 -1
  137. package/components/Loading/index.js +6 -2
  138. package/components/Modal/index.js +38 -3
  139. package/components/Modal/style.js +36 -1
  140. package/components/ModalContainer/connector.js +17 -3
  141. package/components/ModalContainer/index.js +36 -3
  142. package/components/ModalContainer/spec.js +105 -5
  143. package/components/Picker/components/Button/index.js +34 -2
  144. package/components/Picker/components/Button/style.js +19 -1
  145. package/components/Picker/components/List/index.js +33 -2
  146. package/components/Picker/components/List/style.js +17 -1
  147. package/components/Picker/components/Modal/index.js +60 -7
  148. package/components/Picker/components/Modal/style.js +78 -1
  149. package/components/Picker/index.js +167 -21
  150. package/components/Picker/spec.js +83 -2
  151. package/components/Portal/index.js +130 -19
  152. package/components/ProductCharacteristics/connector.js +33 -4
  153. package/components/ProductCharacteristics/context.js +2 -1
  154. package/components/ProductCharacteristics/helpers/index.js +135 -21
  155. package/components/ProductCharacteristics/index.js +266 -31
  156. package/components/RangeSlider/components/Handle/index.js +25 -2
  157. package/components/RangeSlider/components/Handle/style.js +14 -1
  158. package/components/RangeSlider/helper.js +43 -8
  159. package/components/RangeSlider/index.js +228 -38
  160. package/components/RangeSlider/style.js +14 -1
  161. package/components/Route/RouteNotFound.js +46 -3
  162. package/components/Route/index.js +78 -10
  163. package/components/Router/connector.js +9 -2
  164. package/components/Router/index.js +237 -31
  165. package/components/ScannerContainer/connector.js +9 -2
  166. package/components/ScannerContainer/index.js +42 -6
  167. package/components/Select/components/Item/index.js +20 -4
  168. package/components/Select/components/Item/style.js +4 -1
  169. package/components/Select/index.js +149 -28
  170. package/components/Select/spec.js +86 -2
  171. package/components/Select/style.js +17 -1
  172. package/components/SelectBox/components/Item/index.js +47 -5
  173. package/components/SelectBox/components/Item/style.js +7 -1
  174. package/components/SelectBox/index.js +173 -17
  175. package/components/SelectBox/spec.js +59 -3
  176. package/components/SelectBox/style.js +18 -1
  177. package/components/Slider/index.js +6 -2
  178. package/components/SurroundPortals/index.js +26 -2
  179. package/components/Swiper/components/SwiperItem/index.js +28 -4
  180. package/components/Swiper/components/SwiperItem/spec.js +17 -1
  181. package/components/Swiper/components/SwiperItem/styles.js +5 -1
  182. package/components/Swiper/index.js +210 -18
  183. package/components/Swiper/styles.js +75 -7
  184. package/components/Toaster/index.js +10 -2
  185. package/components/Transition/index.js +89 -13
  186. package/components/Widgets/components/Widget/index.js +52 -4
  187. package/components/Widgets/components/Widget/spec.js +68 -3
  188. package/components/Widgets/components/Widget/style.js +21 -3
  189. package/components/Widgets/components/WidgetGrid/index.js +52 -7
  190. package/components/Widgets/components/WidgetGrid/spec.js +46 -2
  191. package/components/Widgets/components/WidgetGrid/style.js +8 -1
  192. package/components/Widgets/helpers/shouldShowWidget.js +44 -7
  193. package/components/Widgets/index.js +127 -15
  194. package/components/Widgets/spec.js +213 -6
  195. package/components/index.js +9 -1
  196. package/constants/ActionTypes.js +97 -19
  197. package/constants/Configuration.js +12 -2
  198. package/constants/Device.js +29 -2
  199. package/constants/DisplayOptions.js +8 -1
  200. package/constants/MenuIDs.js +2 -1
  201. package/constants/ModalTypes.js +1 -1
  202. package/constants/PageIDs.js +1 -1
  203. package/constants/Pipelines.js +7 -1
  204. package/constants/Portals.js +136 -3
  205. package/constants/Registration.js +3 -1
  206. package/constants/RoutePaths.js +13 -2
  207. package/constants/Tracking.js +3 -1
  208. package/constants/client.js +6 -1
  209. package/constants/ui.js +2 -1
  210. package/constants/user.js +6 -2
  211. package/context/index.js +33 -3
  212. package/helpers/config/index.js +139 -21
  213. package/helpers/config/mock.js +200 -8
  214. package/helpers/config/theme.js +50 -4
  215. package/helpers/data/index.js +204 -29
  216. package/helpers/data/spec.js +187 -7
  217. package/helpers/date/index.js +58 -6
  218. package/helpers/date/spec.js +92 -1
  219. package/helpers/dom/index.js +48 -11
  220. package/helpers/environment/index.js +14 -2
  221. package/helpers/html/decodeHTML.js +7 -1
  222. package/helpers/html/handleDOM.js +172 -21
  223. package/helpers/html/parseHTML.js +67 -12
  224. package/helpers/i18n/getDateFormatter.js +23 -4
  225. package/helpers/i18n/getNumberFormatter.js +32 -4
  226. package/helpers/i18n/getPriceFormatter.js +38 -4
  227. package/helpers/i18n/getTimeFormatter.js +23 -4
  228. package/helpers/i18n/getTranslator.js +62 -8
  229. package/helpers/i18n/index.js +5 -1
  230. package/helpers/i18n/mergeTranslations.js +36 -9
  231. package/helpers/i18n/messageCache.js +3 -1
  232. package/helpers/legacy/index.js +47 -9
  233. package/helpers/modal/withShowModal.js +13 -2
  234. package/helpers/portals/portalCollection.js +28 -6
  235. package/helpers/portals/routePortals.js +12 -1
  236. package/helpers/redux/compareObjects.js +7 -2
  237. package/helpers/redux/generateResultHash.js +36 -3
  238. package/helpers/redux/generateSortedHash.js +7 -2
  239. package/helpers/redux/hasExpired.js +10 -2
  240. package/helpers/redux/index.js +7 -1
  241. package/helpers/redux/mutable.js +143 -24
  242. package/helpers/redux/shouldFetchData.js +46 -10
  243. package/helpers/redux/shouldFetchFilters.js +17 -4
  244. package/helpers/router/index.js +49 -5
  245. package/helpers/style/index.js +43 -4
  246. package/helpers/style/spec.js +108 -2
  247. package/helpers/tracking/index.js +52 -9
  248. package/helpers/validation/index.js +39 -12
  249. package/helpers/validation/spec.js +10 -1
  250. package/package.json +3 -3
  251. package/providers/index.js +4 -1
  252. package/providers/loading/context.js +2 -1
  253. package/providers/loading/index.js +137 -22
  254. package/providers/toast/context.js +2 -1
  255. package/providers/toast/index.js +105 -11
  256. package/reducers/client/connectivity.js +22 -2
  257. package/reducers/client/index.js +7 -1
  258. package/reducers/client/info.js +27 -2
  259. package/reducers/index.js +23 -4
  260. package/reducers/menu/index.js +5 -1
  261. package/reducers/menu/menusById.js +41 -2
  262. package/reducers/modal/index.js +14 -2
  263. package/reducers/page/index.js +68 -5
  264. package/reducers/router/index.js +48 -2
  265. package/reducers/url/index.js +42 -3
  266. package/reducers/user/data.js +27 -2
  267. package/reducers/user/index.js +7 -1
  268. package/reducers/user/login.js +65 -2
  269. package/selectors/client.js +138 -21
  270. package/selectors/history.js +49 -11
  271. package/selectors/menu.js +34 -6
  272. package/selectors/modal.js +15 -4
  273. package/selectors/page.js +25 -4
  274. package/selectors/router.js +154 -30
  275. package/selectors/url.js +25 -4
  276. package/selectors/user.js +90 -13
  277. package/store/index.js +60 -6
  278. package/store/middelwares/logger.js +7 -1
  279. package/store/middelwares/streams.js +19 -2
  280. package/streams/app.js +60 -8
  281. package/streams/client.js +8 -2
  282. package/streams/error.js +14 -3
  283. package/streams/index.js +6 -1
  284. package/streams/interval.js +6 -2
  285. package/streams/main.js +27 -2
  286. package/streams/router.js +45 -8
  287. package/streams/user.js +89 -15
  288. package/streams/view.js +97 -25
  289. package/styles/reset/form.js +57 -5
  290. package/styles/reset/index.js +6 -1
  291. package/styles/reset/media.js +22 -1
  292. package/styles/reset/root.js +33 -1
  293. package/styles/reset/table.js +10 -1
  294. package/styles/reset/typography.js +26 -1
  295. package/subscriptions/app.js +148 -17
  296. package/subscriptions/error.js +292 -13
  297. package/subscriptions/helpers/buildRegisterUrl.js +25 -6
  298. package/subscriptions/helpers/clearUpInAppBrowser.js +14 -3
  299. package/subscriptions/helpers/handleLinks.js +267 -25
  300. package/subscriptions/helpers/pipeline.js +12 -1
  301. package/subscriptions/history.js +34 -6
  302. package/subscriptions/index.js +25 -4
  303. package/subscriptions/menu.js +22 -5
  304. package/subscriptions/mock.js +39 -7
  305. package/subscriptions/router.js +336 -23
  306. package/subscriptions/user.js +93 -3
@@ -1,58 +1,177 @@
1
- import noop from'lodash/noop';import{isObject}from"../validation";/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import "core-js/modules/es.string.replace.js";
3
+ import noop from 'lodash/noop';
4
+ import { isObject } from "../validation";
5
+
6
+ /**
2
7
  * @typedef {Object} MutableFunction
3
8
  * @property {Function} replace Replaces the original functionality with a custom function.
4
9
  * @property {Function} restore Restores the original function.
5
10
  * @property {Function} reset Restores the original function and removes all pre-processes steps.
6
11
  * @property {Function} useBefore Adds a pre-processing step func.
7
12
  * @property {Function} original Original function
8
- */var BEFORE_ACTION_NEXT='next';var BEFORE_ACTION_SKIP_REST='skipRest';var BEFORE_ACTION_STOP='stop';/**
13
+ */
14
+
15
+ const BEFORE_ACTION_NEXT = 'next';
16
+ const BEFORE_ACTION_SKIP_REST = 'skipRest';
17
+ const BEFORE_ACTION_STOP = 'stop';
18
+
19
+ /**
9
20
  * Defines parameters to be used by the next step or mutable function.
10
21
  * @param {*} args Transforms an argument list to be consumed by the next step or
11
22
  * @returns {Object}
12
- */export function next(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}return{action:BEFORE_ACTION_NEXT,args:args};}/**
23
+ */
24
+ export function next(...args) {
25
+ return {
26
+ action: BEFORE_ACTION_NEXT,
27
+ args
28
+ };
29
+ }
30
+
31
+ /**
13
32
  * Causes the stack to skip forward to processing the mutable using the given arguments.
14
33
  * @param {*} [args] A number of arguments to be passed to the mutable. This is optional.
15
34
  * @returns {Object}
16
- */export function skipRest(){for(var _len2=arguments.length,args=new Array(_len2),_key2=0;_key2<_len2;_key2++){args[_key2]=arguments[_key2];}return{action:BEFORE_ACTION_SKIP_REST,args:args};}/**
35
+ */
36
+ export function skipRest(...args) {
37
+ return {
38
+ action: BEFORE_ACTION_SKIP_REST,
39
+ args
40
+ };
41
+ }
42
+
43
+ /**
17
44
  * Causes the stack to stop processing any further actions. On stop only one return value possible.
18
45
  * @param {*} [arg] Optional final result value.
19
46
  * @returns {Object}
20
- */export function stop(arg){return{action:BEFORE_ACTION_STOP,args:arg};}/**
47
+ */
48
+ export function stop(arg) {
49
+ return {
50
+ action: BEFORE_ACTION_STOP,
51
+ args: arg
52
+ };
53
+ }
54
+
55
+ /**
21
56
  * Public api export
22
57
  * @type {{next: Function, stop: Function, skipRest: Function}}
23
- */export var mutableActions={next:next,skipRest:skipRest,stop:stop};/**
58
+ */
59
+ export const mutableActions = {
60
+ next,
61
+ skipRest,
62
+ stop
63
+ };
64
+
65
+ /**
24
66
  * Takes a function and makes it mutable.
25
67
  * @template {Function} T
26
68
  * @param {T} func Original function to convert to a mutable
27
69
  * @returns {T}
28
- */export var mutable=function mutable(func){var original=func;var current=func;var steps=[];/**
70
+ */
71
+ export const mutable = func => {
72
+ const original = func;
73
+ let current = func;
74
+ const steps = [];
75
+
76
+ /**
29
77
  * Takes the pre-processing steps and calls all step functions, as well as the mutable function
30
78
  * afterwards. Each step can transform the arguments, that are passed in to the next step in the
31
79
  * stack and ultimately to the mutable function.
32
80
  * @param {*} args Arguments passed down to the mutable and its pre-processor actions.
33
81
  * @returns {Function} A function to be consumed by redux
34
- */function mutableFunc(){for(var _len3=arguments.length,args=new Array(_len3),_key3=0;_key3<_len3;_key3++){args[_key3]=arguments[_key3];}var mutatedArgs=args;var runAction=true;// Execute pre-processing steps, if any available.
35
- if(steps.length>0){mutatedArgs=steps.reduce(function(acc,step,i,arr){// Call next step func in the pipeline with mutated args
36
- var res=step.apply(void 0,acc);// Keep params unchanged if the step did not perform any change action at all
37
- if(!isObject(res)){return acc;}// Unpack arguments from the "useBefore" pre-processor with "next" action.
38
- if(res.action===BEFORE_ACTION_NEXT){if(res.args&&res.args.length>0){res=res.args;}else{res=args;}}// Unpack arguments from the "useBefore" pre-processor with "skipRest" action.
39
- if(res.action===BEFORE_ACTION_SKIP_REST){arr.splice(-(arr.length-i));if(res.args&&res.args.length>0){res=res.args;}else{res=args;}}// Check if the step requested to stop any further processing including the action itself
40
- if(res.action===BEFORE_ACTION_STOP){// Cut off all following step functions including the mutable func
41
- arr.splice(-(arr.length-i));runAction=false;res=res.args;}// Replace arguments for the next step to get.
42
- return res;},args);}if(!runAction){// the return value here gets passed to the dispatch() so it must be a function or action obj
43
- return noop;}// Call the actual mutable
44
- return current.apply(void 0,mutatedArgs);}/**
82
+ */
83
+ function mutableFunc(...args) {
84
+ let mutatedArgs = args;
85
+ let runAction = true;
86
+
87
+ // Execute pre-processing steps, if any available.
88
+ if (steps.length > 0) {
89
+ mutatedArgs = steps.reduce((acc, step, i, arr) => {
90
+ // Call next step func in the pipeline with mutated args
91
+ let res = step(...acc);
92
+
93
+ // Keep params unchanged if the step did not perform any change action at all
94
+ if (!isObject(res)) {
95
+ return acc;
96
+ }
97
+
98
+ // Unpack arguments from the "useBefore" pre-processor with "next" action.
99
+ if (res.action === BEFORE_ACTION_NEXT) {
100
+ if (res.args && res.args.length > 0) {
101
+ res = res.args;
102
+ } else {
103
+ res = args;
104
+ }
105
+ }
106
+
107
+ // Unpack arguments from the "useBefore" pre-processor with "skipRest" action.
108
+ if (res.action === BEFORE_ACTION_SKIP_REST) {
109
+ arr.splice(-(arr.length - i));
110
+ if (res.args && res.args.length > 0) {
111
+ res = res.args;
112
+ } else {
113
+ res = args;
114
+ }
115
+ }
116
+
117
+ // Check if the step requested to stop any further processing including the action itself
118
+ if (res.action === BEFORE_ACTION_STOP) {
119
+ // Cut off all following step functions including the mutable func
120
+ arr.splice(-(arr.length - i));
121
+ runAction = false;
122
+ res = res.args;
123
+ }
124
+
125
+ // Replace arguments for the next step to get.
126
+ return res;
127
+ }, args);
128
+ }
129
+ if (!runAction) {
130
+ // the return value here gets passed to the dispatch() so it must be a function or action obj
131
+ return noop;
132
+ }
133
+
134
+ // Call the actual mutable
135
+ return current(...mutatedArgs);
136
+ }
137
+
138
+ /**
45
139
  * Replaces the original functionality with a custom function.
46
140
  * @param {Function} customFunc The function to execute instead of the original one.
47
- */mutableFunc.replace=function(customFunc){current=customFunc;// Allow access to the current mutation.
48
- mutableFunc.current=current;};/**
141
+ */
142
+ mutableFunc.replace = customFunc => {
143
+ current = customFunc;
144
+
145
+ // Allow access to the current mutation.
146
+ mutableFunc.current = current;
147
+ };
148
+
149
+ /**
49
150
  * Restores the original func, while keeping additional functions to be called beforehand.
50
- */mutableFunc.restore=function(){current=original;};/**
151
+ */
152
+ mutableFunc.restore = () => {
153
+ current = original;
154
+ };
155
+
156
+ /**
51
157
  * Resets the whole mutable to its initial state, restoring the original functionality and
52
158
  * dropping all injected functions.
53
- */mutableFunc.reset=function(){current=original;steps.length=0;};/**
159
+ */
160
+ mutableFunc.reset = () => {
161
+ current = original;
162
+ steps.length = 0;
163
+ };
164
+
165
+ /**
54
166
  * Adds a pre-processing step func to a list to be called before the actual functionality
55
167
  * executes. Each step can modify the arguments, passed down to the next step or the mutable.
56
168
  * @param {Function} stepFunc The function to be executed before
57
- */mutableFunc.useBefore=function(stepFunc){steps.push(stepFunc);};// Allow access to the original function.
58
- mutableFunc.original=original;return mutableFunc;};
169
+ */
170
+ mutableFunc.useBefore = stepFunc => {
171
+ steps.push(stepFunc);
172
+ };
173
+
174
+ // Allow access to the original function.
175
+ mutableFunc.original = original;
176
+ return mutableFunc;
177
+ };
@@ -1,16 +1,52 @@
1
- import{isObject}from"../validation";/**
1
+ import { isObject } from "../validation";
2
+
3
+ /**
2
4
  * Checks if an item can be fetched or (only when the itemKey parameter is set) if there is a
3
5
  * certain key inside the item that is filled with data.
4
6
  * @param {Object} item The item to check.
5
7
  * @param {string} [itemKey=null] A key of a property to check additionally.
6
8
  * @param {string} [requiredCount=null] The number of required products that should be in the store.
7
9
  * @return {boolean} Whether it can be fetched.
8
- */export function shouldFetchData(item){var itemKey=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var requiredCount=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;// Get data if we have none.
9
- if(!item){return true;}// Fetch data if we have an empty object in the store.
10
- if(isObject(item)&&Object.keys(item).length===0){return true;}// Check that the item is not fetching currently.
11
- if(!item.isFetching){// Fetch data if the expiry date has expired or is set to 0 (initially set).
12
- if(item.expires===0||item.expires&&item.expires>0&&item.expires<Date.now()){return true;}// Check for a specific key inside items and fetch it if it's not found.
13
- if(itemKey&&Array.isArray(item[itemKey])){var _item$totalResultCoun2=item.totalResultCount,totalResultCount=_item$totalResultCoun2===void 0?item[itemKey].length:_item$totalResultCoun2;// 1. Fetch by requiredCount.
14
- if(requiredCount){var assertCount=Math.min(requiredCount,totalResultCount);// Fetch is needed to assert N of items in store.
15
- if(item[itemKey].length!==assertCount){return true;}}// 2. Sync items when totalResultCount is less
16
- if(!requiredCount&&item[itemKey].length>totalResultCount){return true;}}}return false;}
10
+ */
11
+ export function shouldFetchData(item, itemKey = null, requiredCount = null) {
12
+ // Get data if we have none.
13
+ if (!item) {
14
+ return true;
15
+ }
16
+
17
+ // Fetch data if we have an empty object in the store.
18
+ if (isObject(item) && Object.keys(item).length === 0) {
19
+ return true;
20
+ }
21
+
22
+ // Check that the item is not fetching currently.
23
+ if (!item.isFetching) {
24
+ // Fetch data if the expiry date has expired or is set to 0 (initially set).
25
+ if (item.expires === 0 || item.expires && item.expires > 0 && item.expires < Date.now()) {
26
+ return true;
27
+ }
28
+
29
+ // Check for a specific key inside items and fetch it if it's not found.
30
+ if (itemKey && Array.isArray(item[itemKey])) {
31
+ const {
32
+ totalResultCount = item[itemKey].length // fallback to original items length
33
+ } = item;
34
+
35
+ // 1. Fetch by requiredCount.
36
+ if (requiredCount) {
37
+ const assertCount = Math.min(requiredCount, totalResultCount);
38
+
39
+ // Fetch is needed to assert N of items in store.
40
+ if (item[itemKey].length !== assertCount) {
41
+ return true;
42
+ }
43
+ }
44
+
45
+ // 2. Sync items when totalResultCount is less
46
+ if (!requiredCount && item[itemKey].length > totalResultCount) {
47
+ return true;
48
+ }
49
+ }
50
+ }
51
+ return false;
52
+ }
@@ -1,7 +1,20 @@
1
- import{isObject}from"../validation";import{hasExpired}from"./hasExpired";/**
1
+ import { isObject } from "../validation";
2
+ import { hasExpired } from "./hasExpired";
3
+
4
+ /**
2
5
  * Determine if there should be a request to fetch the filter data.
3
6
  * @param {Object} item The filter object.
4
7
  * @returns {boolean}
5
- */export function shouldFetchFilters(item){// Get data if we no item.
6
- if(!item){return true;}// Fetch data if we have an empty object in the store.
7
- if(isObject(item)&&Object.keys(item).length===0){return true;}return hasExpired(item);}
8
+ */
9
+ export function shouldFetchFilters(item) {
10
+ // Get data if we no item.
11
+ if (!item) {
12
+ return true;
13
+ }
14
+
15
+ // Fetch data if we have an empty object in the store.
16
+ if (isObject(item) && Object.keys(item).length === 0) {
17
+ return true;
18
+ }
19
+ return hasExpired(item);
20
+ }
@@ -1,15 +1,59 @@
1
- function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}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{createBrowserHistory}from'history';import URLSearchParams from'url-search-params';import{router}from'@virtuous/conductor';var match=/^(.*)index.html/.exec(window.location.pathname);var getCurrentRoute=router.getCurrentRoute;/**
1
+ import "core-js/modules/es.array.reduce.js";
2
+ import { createBrowserHistory } from 'history';
3
+ import URLSearchParams from 'url-search-params';
4
+ import { router } from '@virtuous/conductor';
5
+ const match = /^(.*)index.html/.exec(window.location.pathname);
6
+ const {
7
+ getCurrentRoute
8
+ } = router;
9
+ /**
2
10
  * @deprecated
3
- */export{getCurrentRoute,router};/**
11
+ */
12
+ export { getCurrentRoute, router };
13
+
14
+ /**
4
15
  * Creates the router history.
5
16
  * @returns {Object}
6
- */export var history=function history(){return createBrowserHistory({basename:match?match[0]:''});};/**
17
+ */
18
+ export const history = () => createBrowserHistory({
19
+ basename: match ? match[0] : ''
20
+ });
21
+
22
+ /**
7
23
  * Transforms a given URL query string to an object.
8
24
  * @param {string} queryString An URL query string.
9
25
  * @returns {Object}
10
- */export var parseQueryStringToObject=function parseQueryStringToObject(){var queryString=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(!queryString){return{};}var urlParams=new URLSearchParams(queryString);var keys=Array.from(urlParams.keys());return keys.reduce(function(obj,key){return _extends({},obj,_defineProperty({},key,urlParams.get(key)));},{});};/**
26
+ */
27
+ export const parseQueryStringToObject = (queryString = null) => {
28
+ if (!queryString) {
29
+ return {};
30
+ }
31
+ const urlParams = new URLSearchParams(queryString);
32
+ const keys = Array.from(urlParams.keys());
33
+ return keys.reduce((obj, key) => ({
34
+ ...obj,
35
+ [key]: urlParams.get(key)
36
+ }), {});
37
+ };
38
+
39
+ /**
11
40
  * Transforms a given object to an URL query string.
12
41
  * @param {Object} obj An object with keys/values.
13
42
  * @param {boolean} [includePrefix=true] If true a `?` is prefixed.
14
43
  * @returns {string}
15
- */export var parseObjectToQueryString=function parseObjectToQueryString(obj){var includePrefix=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;if(!obj){return'';}var urlParams=new URLSearchParams();var keys=Object.keys(obj);if(keys.length===0){return'';}keys.forEach(function(key){return urlParams.set(key,obj[key]);});if(includePrefix){return"?".concat(urlParams.toString());}return urlParams.toString();};
44
+ */
45
+ export const parseObjectToQueryString = (obj, includePrefix = true) => {
46
+ if (!obj) {
47
+ return '';
48
+ }
49
+ const urlParams = new URLSearchParams();
50
+ const keys = Object.keys(obj);
51
+ if (keys.length === 0) {
52
+ return '';
53
+ }
54
+ keys.forEach(key => urlParams.set(key, obj[key]));
55
+ if (includePrefix) {
56
+ return `?${urlParams.toString()}`;
57
+ }
58
+ return urlParams.toString();
59
+ };
@@ -1,9 +1,24 @@
1
- function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import{logger}from'@shopgate/pwa-core/helpers';import{isNumber}from"../validation";/**
1
+ import { logger } from '@shopgate/pwa-core/helpers';
2
+ import { isNumber } from "../validation";
3
+
4
+ /**
2
5
  * Calculates a rem value for a passed pixel value. The calculation is based on the root
3
6
  * font size that is defined inside the template's font styles.
4
7
  * @param {number} pixels The source value
5
8
  * @returns {string} The result value
6
- */export var rem=function rem(pixels){var result='';if(isNumber(pixels)&&pixels>=0){result="".concat(1/16*pixels,"rem");}else{result='1rem';logger.error("rem(): Invalid value (".concat(pixels,")"));}return result;};/**
9
+ */
10
+ export const rem = pixels => {
11
+ let result = '';
12
+ if (isNumber(pixels) && pixels >= 0) {
13
+ result = `${1 / 16 * pixels}rem`;
14
+ } else {
15
+ result = '1rem';
16
+ logger.error(`rem(): Invalid value (${pixels})`);
17
+ }
18
+ return result;
19
+ };
20
+
21
+ /**
7
22
  * Returns an object ready to use with glamor with one pixel size property.
8
23
  * For example physicalPixelSize('height', 1) would result in:
9
24
  * - height: 1px for screen density 1,
@@ -12,5 +27,29 @@ function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj
12
27
  * @param {string} property Css property name.
13
28
  * @param {number} [size=1] Requested physical pixel size.
14
29
  * @returns {Object}
15
- */export var physicalPixelSize=function physicalPixelSize(property){var size=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;// Android doesn't accept decimals.
16
- if(navigator&&navigator.userAgent&&navigator.userAgent.includes('Android')){return _defineProperty({},property,size);}var _double=Math.round(size/2*100)/100;var triple=Math.round(size/3*100)/100;return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},property,size),'@media (min-device-pixel-ratio: 2)',_defineProperty({},property,_double)),'@media (-webkit-min-device-pixel-ratio: 2)',_defineProperty({},property,_double)),'@media (min-device-pixel-ratio: 3)',_defineProperty({},property,triple)),'@media (-webkit-min-device-pixel-ratio: 3)',_defineProperty({},property,triple));};
30
+ */
31
+ export const physicalPixelSize = (property, size = 1) => {
32
+ // Android doesn't accept decimals.
33
+ if (navigator && navigator.userAgent && navigator.userAgent.includes('Android')) {
34
+ return {
35
+ [property]: size
36
+ };
37
+ }
38
+ const double = Math.round(size / 2 * 100) / 100;
39
+ const triple = Math.round(size / 3 * 100) / 100;
40
+ return {
41
+ [property]: size,
42
+ '@media (min-device-pixel-ratio: 2)': {
43
+ [property]: double
44
+ },
45
+ '@media (-webkit-min-device-pixel-ratio: 2)': {
46
+ [property]: double
47
+ },
48
+ '@media (min-device-pixel-ratio: 3)': {
49
+ [property]: triple
50
+ },
51
+ '@media (-webkit-min-device-pixel-ratio: 3)': {
52
+ [property]: triple
53
+ }
54
+ };
55
+ };
@@ -1,2 +1,108 @@
1
- import{rem,physicalPixelSize}from"./index";describe('style helper',function(){describe('rem helper with 16px rootSize',function(){it('should output 0.875rem for 16px input',function(){expect(rem(16)).toBe('1rem');});it('should output 0.875rem for 14px input',function(){expect(rem(14)).toBe('0.875rem');});it('should output 0.75rem for 12px input',function(){expect(rem(12)).toBe('0.75rem');});it('should output 0rem for 0px input',function(){expect(rem(0)).toBe('0rem');});});describe('rem helper error handling',function(){var consoleSpy;beforeAll(function(){// Deactivate the console for the next tests to avoid logs within the test report.
2
- consoleSpy=jest.spyOn(console,'error').mockImplementation();});afterAll(function(){consoleSpy.mockRestore();});afterEach(function(){consoleSpy.mockReset();});it('should output 1rem as fallback for wrong parameters',function(){expect(rem('rem')).toBe('1rem');expect(consoleSpy).toHaveBeenCalledTimes(1);});});describe('physicalPixelSize',function(){describe('non-Android devices',function(){beforeAll(function(){Object.defineProperty(window.navigator,'userAgent',{value:'Not And... user agent',configurable:true});});it('should output declarations for 1px size',function(){expect(physicalPixelSize('foo',1)).toEqual({foo:1,'@media (min-device-pixel-ratio: 2)':{foo:0.5},'@media (-webkit-min-device-pixel-ratio: 2)':{foo:0.5},'@media (min-device-pixel-ratio: 3)':{foo:0.33},'@media (-webkit-min-device-pixel-ratio: 3)':{foo:0.33}});});it('should output declarations for 2px size',function(){expect(physicalPixelSize('foo',2)).toEqual({foo:2,'@media (min-device-pixel-ratio: 2)':{foo:1},'@media (-webkit-min-device-pixel-ratio: 2)':{foo:1},'@media (min-device-pixel-ratio: 3)':{foo:0.67},'@media (-webkit-min-device-pixel-ratio: 3)':{foo:0.67}});});it('should output declarations for 3px size',function(){expect(physicalPixelSize('foo',3)).toEqual({foo:3,'@media (min-device-pixel-ratio: 2)':{foo:1.5},'@media (-webkit-min-device-pixel-ratio: 2)':{foo:1.5},'@media (min-device-pixel-ratio: 3)':{foo:1},'@media (-webkit-min-device-pixel-ratio: 3)':{foo:1}});});});describe('android devices',function(){beforeAll(function(){Object.defineProperty(window.navigator,'userAgent',{value:'Foo Android',configurable:true});});it('should return natural number rules only',function(){expect(physicalPixelSize('foo',3)).toEqual({foo:3});});});});});
1
+ import { rem, physicalPixelSize } from "./index";
2
+ describe('style helper', () => {
3
+ describe('rem helper with 16px rootSize', () => {
4
+ it('should output 0.875rem for 16px input', () => {
5
+ expect(rem(16)).toBe('1rem');
6
+ });
7
+ it('should output 0.875rem for 14px input', () => {
8
+ expect(rem(14)).toBe('0.875rem');
9
+ });
10
+ it('should output 0.75rem for 12px input', () => {
11
+ expect(rem(12)).toBe('0.75rem');
12
+ });
13
+ it('should output 0rem for 0px input', () => {
14
+ expect(rem(0)).toBe('0rem');
15
+ });
16
+ });
17
+ describe('rem helper error handling', () => {
18
+ let consoleSpy;
19
+ beforeAll(() => {
20
+ // Deactivate the console for the next tests to avoid logs within the test report.
21
+ consoleSpy = jest.spyOn(console, 'error').mockImplementation();
22
+ });
23
+ afterAll(() => {
24
+ consoleSpy.mockRestore();
25
+ });
26
+ afterEach(() => {
27
+ consoleSpy.mockReset();
28
+ });
29
+ it('should output 1rem as fallback for wrong parameters', () => {
30
+ expect(rem('rem')).toBe('1rem');
31
+ expect(consoleSpy).toHaveBeenCalledTimes(1);
32
+ });
33
+ });
34
+ describe('physicalPixelSize', () => {
35
+ describe('non-Android devices', () => {
36
+ beforeAll(() => {
37
+ Object.defineProperty(window.navigator, 'userAgent', {
38
+ value: 'Not And... user agent',
39
+ configurable: true
40
+ });
41
+ });
42
+ it('should output declarations for 1px size', () => {
43
+ expect(physicalPixelSize('foo', 1)).toEqual({
44
+ foo: 1,
45
+ '@media (min-device-pixel-ratio: 2)': {
46
+ foo: 0.5
47
+ },
48
+ '@media (-webkit-min-device-pixel-ratio: 2)': {
49
+ foo: 0.5
50
+ },
51
+ '@media (min-device-pixel-ratio: 3)': {
52
+ foo: 0.33
53
+ },
54
+ '@media (-webkit-min-device-pixel-ratio: 3)': {
55
+ foo: 0.33
56
+ }
57
+ });
58
+ });
59
+ it('should output declarations for 2px size', () => {
60
+ expect(physicalPixelSize('foo', 2)).toEqual({
61
+ foo: 2,
62
+ '@media (min-device-pixel-ratio: 2)': {
63
+ foo: 1
64
+ },
65
+ '@media (-webkit-min-device-pixel-ratio: 2)': {
66
+ foo: 1
67
+ },
68
+ '@media (min-device-pixel-ratio: 3)': {
69
+ foo: 0.67
70
+ },
71
+ '@media (-webkit-min-device-pixel-ratio: 3)': {
72
+ foo: 0.67
73
+ }
74
+ });
75
+ });
76
+ it('should output declarations for 3px size', () => {
77
+ expect(physicalPixelSize('foo', 3)).toEqual({
78
+ foo: 3,
79
+ '@media (min-device-pixel-ratio: 2)': {
80
+ foo: 1.5
81
+ },
82
+ '@media (-webkit-min-device-pixel-ratio: 2)': {
83
+ foo: 1.5
84
+ },
85
+ '@media (min-device-pixel-ratio: 3)': {
86
+ foo: 1
87
+ },
88
+ '@media (-webkit-min-device-pixel-ratio: 3)': {
89
+ foo: 1
90
+ }
91
+ });
92
+ });
93
+ });
94
+ describe('android devices', () => {
95
+ beforeAll(() => {
96
+ Object.defineProperty(window.navigator, 'userAgent', {
97
+ value: 'Foo Android',
98
+ configurable: true
99
+ });
100
+ });
101
+ it('should return natural number rules only', () => {
102
+ expect(physicalPixelSize('foo', 3)).toEqual({
103
+ foo: 3
104
+ });
105
+ });
106
+ });
107
+ });
108
+ });
@@ -1,25 +1,68 @@
1
- import get from'lodash/get';import{OS_ALL,TYPE_PHONE}from"../../constants/Device";import{TRACKING_TARGET_ALL,TRACKING_TARGET_APPS,TRACKING_TARGET_APPS_SMARTPHONE}from"../../constants/Tracking";/**
1
+ import get from 'lodash/get';
2
+ import { OS_ALL, TYPE_PHONE } from "../../constants/Device";
3
+ import { TRACKING_TARGET_ALL, TRACKING_TARGET_APPS, TRACKING_TARGET_APPS_SMARTPHONE } from "../../constants/Tracking";
4
+
5
+ /**
2
6
  * Extracts the action from the pathname.
3
7
  * @param {string} pathName The ULR pathname.
4
8
  * @returns {string} The action.
5
- */export var getPathAction=function getPathAction(pathName){return pathName.split('/')[1];};/**
9
+ */
10
+ export const getPathAction = pathName => pathName.split('/')[1];
11
+
12
+ /**
6
13
  * Selector that extracts the pathname from the current path.
7
14
  * @param {Object} state The current state.
8
15
  * @returns {string} The action.
9
- */export var pathActionSelector=function pathActionSelector(state){return getPathAction(state.history.pathname);};/**
16
+ */
17
+ export const pathActionSelector = state => getPathAction(state.history.pathname);
18
+
19
+ /**
10
20
  * Checks if a given target is supported by the type
11
21
  * @param {string} target Tracking target
12
22
  * @param {Object} clientInformation Information about the current client
13
23
  * @returns {boolean}
14
- */export function isTargetSupported(target,clientInformation){var type=clientInformation.type;// Always use 'all' and 'apps'
15
- var validTargets=[TRACKING_TARGET_ALL,TRACKING_TARGET_APPS];// Add more valid targets depending on the platform/device
16
- if(type===TYPE_PHONE){validTargets.push(TRACKING_TARGET_APPS_SMARTPHONE);}// Check if the given target matches any valid target
17
- return validTargets.indexOf(target)!==-1;}/**
24
+ */
25
+ export function isTargetSupported(target, clientInformation) {
26
+ const {
27
+ type
28
+ } = clientInformation;
29
+
30
+ // Always use 'all' and 'apps'
31
+ const validTargets = [TRACKING_TARGET_ALL, TRACKING_TARGET_APPS];
32
+
33
+ // Add more valid targets depending on the platform/device
34
+ if (type === TYPE_PHONE) {
35
+ validTargets.push(TRACKING_TARGET_APPS_SMARTPHONE);
36
+ }
37
+
38
+ // Check if the given target matches any valid target
39
+ return validTargets.indexOf(target) !== -1;
40
+ }
41
+
42
+ /**
18
43
  * Collects tracking configurations from the sgxs configuration, which match to the current client.
19
44
  * @param {Object} sgxsConfig The SGXS configuration
20
45
  * @param {Object} clientInformation Information about the current client
21
46
  * @return {Array}
22
- */export var getRelevantConfigs=function getRelevantConfigs(){var sgxsConfig=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var clientInformation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var _sgxsConfig$stage=sgxsConfig.stage,sgxsStage=_sgxsConfig$stage===void 0?'':_sgxsConfig$stage,_sgxsConfig$trackers=sgxsConfig.trackers,trackers=_sgxsConfig$trackers===void 0?[]:_sgxsConfig$trackers;return trackers.filter(function(_ref){var stage=_ref.stage,shopgateAccount=_ref.shopgateAccount,os=_ref.os,target=_ref.target;/**
47
+ */
48
+ export const getRelevantConfigs = (sgxsConfig = {}, clientInformation = {}) => {
49
+ const {
50
+ stage: sgxsStage = '',
51
+ trackers = []
52
+ } = sgxsConfig;
53
+ return trackers.filter(({
54
+ stage,
55
+ shopgateAccount,
56
+ os,
57
+ target
58
+ }) => {
59
+ /**
23
60
  * Only Shopgate tracking configurations contain a stage property. In case of the merchant
24
61
  * configurations we only get entries which match the stage, on which the client is running.
25
- */var validStage=!shopgateAccount||stage===sgxsStage;var validOs=!os||os===get(clientInformation,'os')||os===OS_ALL;var validTarget=isTargetSupported(target,clientInformation);return validStage&&validOs&&validTarget;});};
62
+ */
63
+ const validStage = !shopgateAccount || stage === sgxsStage;
64
+ const validOs = !os || os === get(clientInformation, 'os') || os === OS_ALL;
65
+ const validTarget = isTargetSupported(target, clientInformation);
66
+ return validStage && validOs && validTarget;
67
+ });
68
+ };