@sentecacommerce-theme/lib 0.12.26 → 0.12.30

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 (182) hide show
  1. package/dist/cjs/analytics/Releva/api/query/useRelevaQuery.js +4 -2
  2. package/dist/cjs/analytics/Releva/api/query/useRelevaQuery.js.map +1 -1
  3. package/dist/cjs/analytics/Releva/hooks/useRelevaData.js +2 -2
  4. package/dist/cjs/analytics/Releva/hooks/useRelevaData.js.map +1 -1
  5. package/dist/cjs/analytics/Releva/useReleva.js +8 -1
  6. package/dist/cjs/analytics/Releva/useReleva.js.map +1 -1
  7. package/dist/cjs/cms/api/queries/index.js +16 -0
  8. package/dist/cjs/cms/api/queries/index.js.map +1 -1
  9. package/dist/cjs/cms/api/queries/keys.js +15 -1
  10. package/dist/cjs/cms/api/queries/keys.js.map +1 -1
  11. package/dist/cjs/cms/api/queries/useCMSContentListQuery.js +64 -0
  12. package/dist/cjs/cms/api/queries/useCMSContentListQuery.js.map +1 -0
  13. package/dist/cjs/cms/api/queries/useCMSContentQuery.js +54 -0
  14. package/dist/cjs/cms/api/queries/useCMSContentQuery.js.map +1 -0
  15. package/dist/cjs/cms/hooks/index.js +24 -0
  16. package/dist/cjs/cms/hooks/index.js.map +1 -1
  17. package/dist/cjs/{hooks/cms-content-hooks/useCmsContent/index.js → cms/hooks/useCmsContent.js} +6 -8
  18. package/dist/cjs/cms/hooks/useCmsContent.js.map +1 -0
  19. package/dist/cjs/{hooks/cms-content-hooks/useCmsContentList/index.js → cms/hooks/useCmsContentList.js} +5 -5
  20. package/dist/cjs/cms/hooks/useCmsContentList.js.map +1 -0
  21. package/dist/cjs/{hooks/cms-content-hooks/useContentCategoriesMap/index.js → cms/hooks/useContentCategoriesMap.js} +1 -1
  22. package/dist/cjs/cms/hooks/useContentCategoriesMap.js.map +1 -0
  23. package/dist/cjs/cms/ssr/fetchPagePaths.js.map +1 -1
  24. package/dist/cjs/cms/ssr/index.js +16 -0
  25. package/dist/cjs/cms/ssr/index.js.map +1 -1
  26. package/dist/cjs/cms/ssr/prefetchCmsContent.js +78 -0
  27. package/dist/cjs/cms/ssr/prefetchCmsContent.js.map +1 -0
  28. package/dist/cjs/cms/ssr/prefetchCmsContentList.js +85 -0
  29. package/dist/cjs/cms/ssr/prefetchCmsContentList.js.map +1 -0
  30. package/dist/cjs/cms/utils/getCMSContentListFilter.js +16 -0
  31. package/dist/cjs/cms/utils/getCMSContentListFilter.js.map +1 -0
  32. package/dist/cjs/cms/utils/index.js +8 -0
  33. package/dist/cjs/cms/utils/index.js.map +1 -1
  34. package/dist/cjs/config/SentecaProvider.js.map +1 -1
  35. package/dist/cjs/contexts/CheckoutForm/hooks/useBilling/index.js +4 -2
  36. package/dist/cjs/contexts/CheckoutForm/hooks/useBilling/index.js.map +1 -1
  37. package/dist/cjs/contexts/CheckoutForm/hooks/useShipping/index.js +8 -6
  38. package/dist/cjs/contexts/CheckoutForm/hooks/useShipping/index.js.map +1 -1
  39. package/dist/cjs/contexts/CheckoutForm/index.js +16 -9
  40. package/dist/cjs/contexts/CheckoutForm/index.js.map +1 -1
  41. package/dist/cjs/contexts/CheckoutForm/utils/validateBillingAddress.js +1 -2
  42. package/dist/cjs/contexts/CheckoutForm/utils/validateBillingAddress.js.map +1 -1
  43. package/dist/cjs/contexts/CheckoutForm/utils/validateShipping.js +28 -21
  44. package/dist/cjs/contexts/CheckoutForm/utils/validateShipping.js.map +1 -1
  45. package/dist/cjs/hooks/addresses-hooks/useAddressForm/index.js +4 -2
  46. package/dist/cjs/hooks/addresses-hooks/useAddressForm/index.js.map +1 -1
  47. package/dist/cjs/hooks/order-hooks/useOrder/index.js +12 -1
  48. package/dist/cjs/hooks/order-hooks/useOrder/index.js.map +1 -1
  49. package/dist/cjs/hooks/useAggregateResult/index.js +0 -4
  50. package/dist/cjs/hooks/useAggregateResult/index.js.map +1 -1
  51. package/dist/cjs/hooks/useCheckoutShippingModule/index.js +6 -1
  52. package/dist/cjs/hooks/useCheckoutShippingModule/index.js.map +1 -1
  53. package/dist/cjs/index.js +0 -16
  54. package/dist/cjs/index.js.map +1 -1
  55. package/dist/cjs/seo/api/ssr/getCanonicalUrl.js +27 -0
  56. package/dist/cjs/seo/api/ssr/getCanonicalUrl.js.map +1 -0
  57. package/dist/cjs/seo/api/ssr/index.js +8 -0
  58. package/dist/cjs/seo/api/ssr/index.js.map +1 -1
  59. package/dist/cjs/user/api/index.js +8 -0
  60. package/dist/cjs/user/api/index.js.map +1 -1
  61. package/dist/cjs/user/api/utils/generateAnonymousToken.js +48 -0
  62. package/dist/cjs/user/api/utils/generateAnonymousToken.js.map +1 -0
  63. package/dist/cjs/user/api/utils/index.js +8 -0
  64. package/dist/cjs/user/api/utils/index.js.map +1 -1
  65. package/dist/cjs/user/index.js +8 -0
  66. package/dist/cjs/user/index.js.map +1 -1
  67. package/dist/esm/analytics/Releva/api/query/useRelevaQuery.js +4 -2
  68. package/dist/esm/analytics/Releva/api/query/useRelevaQuery.js.map +1 -1
  69. package/dist/esm/analytics/Releva/hooks/useRelevaData.js +2 -2
  70. package/dist/esm/analytics/Releva/hooks/useRelevaData.js.map +1 -1
  71. package/dist/esm/analytics/Releva/useReleva.js +8 -2
  72. package/dist/esm/analytics/Releva/useReleva.js.map +1 -1
  73. package/dist/esm/cms/api/queries/index.js +2 -0
  74. package/dist/esm/cms/api/queries/index.js.map +1 -1
  75. package/dist/esm/cms/api/queries/keys.js +5 -0
  76. package/dist/esm/cms/api/queries/keys.js.map +1 -1
  77. package/dist/esm/cms/api/queries/useCMSContentListQuery.js +31 -0
  78. package/dist/esm/cms/api/queries/useCMSContentListQuery.js.map +1 -0
  79. package/dist/esm/cms/api/queries/useCMSContentQuery.js +17 -0
  80. package/dist/esm/cms/api/queries/useCMSContentQuery.js.map +1 -0
  81. package/dist/esm/cms/hooks/index.js +3 -0
  82. package/dist/esm/cms/hooks/index.js.map +1 -1
  83. package/dist/esm/{hooks/cms-content-hooks/useCmsContent/index.js → cms/hooks/useCmsContent.js} +6 -8
  84. package/dist/esm/cms/hooks/useCmsContent.js.map +1 -0
  85. package/dist/esm/{hooks/cms-content-hooks/useCmsContentList/index.js → cms/hooks/useCmsContentList.js} +5 -5
  86. package/dist/esm/cms/hooks/useCmsContentList.js.map +1 -0
  87. package/dist/esm/{hooks/cms-content-hooks/useContentCategoriesMap/index.js → cms/hooks/useContentCategoriesMap.js} +1 -1
  88. package/dist/esm/cms/hooks/useContentCategoriesMap.js.map +1 -0
  89. package/dist/esm/cms/ssr/fetchPagePaths.js.map +1 -1
  90. package/dist/esm/cms/ssr/index.js +2 -0
  91. package/dist/esm/cms/ssr/index.js.map +1 -1
  92. package/dist/esm/cms/ssr/prefetchCmsContent.js +30 -0
  93. package/dist/esm/cms/ssr/prefetchCmsContent.js.map +1 -0
  94. package/dist/esm/cms/ssr/prefetchCmsContentList.js +32 -0
  95. package/dist/esm/cms/ssr/prefetchCmsContentList.js.map +1 -0
  96. package/dist/esm/cms/utils/getCMSContentListFilter.js +9 -0
  97. package/dist/esm/cms/utils/getCMSContentListFilter.js.map +1 -0
  98. package/dist/esm/cms/utils/index.js +1 -0
  99. package/dist/esm/cms/utils/index.js.map +1 -1
  100. package/dist/esm/config/SentecaProvider.js.map +1 -1
  101. package/dist/esm/contexts/CheckoutForm/hooks/useBilling/index.js +4 -2
  102. package/dist/esm/contexts/CheckoutForm/hooks/useBilling/index.js.map +1 -1
  103. package/dist/esm/contexts/CheckoutForm/hooks/useShipping/index.js +8 -6
  104. package/dist/esm/contexts/CheckoutForm/hooks/useShipping/index.js.map +1 -1
  105. package/dist/esm/contexts/CheckoutForm/index.js +13 -9
  106. package/dist/esm/contexts/CheckoutForm/index.js.map +1 -1
  107. package/dist/esm/contexts/CheckoutForm/utils/validateBillingAddress.js +1 -2
  108. package/dist/esm/contexts/CheckoutForm/utils/validateBillingAddress.js.map +1 -1
  109. package/dist/esm/contexts/CheckoutForm/utils/validateShipping.js +25 -18
  110. package/dist/esm/contexts/CheckoutForm/utils/validateShipping.js.map +1 -1
  111. package/dist/esm/hooks/addresses-hooks/useAddressForm/index.js +3 -2
  112. package/dist/esm/hooks/addresses-hooks/useAddressForm/index.js.map +1 -1
  113. package/dist/esm/hooks/order-hooks/useOrder/index.js +10 -1
  114. package/dist/esm/hooks/order-hooks/useOrder/index.js.map +1 -1
  115. package/dist/esm/hooks/useAggregateResult/index.js +0 -2
  116. package/dist/esm/hooks/useAggregateResult/index.js.map +1 -1
  117. package/dist/esm/hooks/useCheckoutShippingModule/index.js +6 -1
  118. package/dist/esm/hooks/useCheckoutShippingModule/index.js.map +1 -1
  119. package/dist/esm/index.js +0 -2
  120. package/dist/esm/index.js.map +1 -1
  121. package/dist/esm/seo/api/ssr/getCanonicalUrl.js +18 -0
  122. package/dist/esm/seo/api/ssr/getCanonicalUrl.js.map +1 -0
  123. package/dist/esm/seo/api/ssr/index.js +1 -0
  124. package/dist/esm/seo/api/ssr/index.js.map +1 -1
  125. package/dist/esm/user/api/index.js +1 -0
  126. package/dist/esm/user/api/index.js.map +1 -1
  127. package/dist/esm/user/api/utils/generateAnonymousToken.js +23 -0
  128. package/dist/esm/user/api/utils/generateAnonymousToken.js.map +1 -0
  129. package/dist/esm/user/api/utils/index.js +1 -0
  130. package/dist/esm/user/api/utils/index.js.map +1 -1
  131. package/dist/esm/user/index.js +1 -0
  132. package/dist/esm/user/index.js.map +1 -1
  133. package/dist/types/analytics/Releva/api/query/useRelevaQuery.d.ts +1 -1
  134. package/dist/types/analytics/Releva/hooks/useRelevaData.d.ts +1 -1
  135. package/dist/types/cms/api/queries/index.d.ts +2 -0
  136. package/dist/types/cms/api/queries/keys.d.ts +5 -1
  137. package/dist/types/cms/api/queries/useCMSContentListQuery.d.ts +15 -0
  138. package/dist/types/cms/api/queries/useCMSContentQuery.d.ts +1 -0
  139. package/dist/types/cms/hooks/index.d.ts +3 -0
  140. package/dist/types/{hooks/cms-content-hooks/useCmsContent/index.d.ts → cms/hooks/useCmsContent.d.ts} +0 -0
  141. package/dist/types/{hooks/cms-content-hooks/useCmsContentList/index.d.ts → cms/hooks/useCmsContentList.d.ts} +1 -1
  142. package/dist/types/{hooks/cms-content-hooks/useContentCategoriesMap/index.d.ts → cms/hooks/useContentCategoriesMap.d.ts} +0 -0
  143. package/dist/types/cms/ssr/fetchPagePaths.d.ts +1 -1
  144. package/dist/types/cms/ssr/index.d.ts +2 -0
  145. package/dist/types/cms/ssr/prefetchCmsContent.d.ts +5 -0
  146. package/dist/types/cms/ssr/prefetchCmsContentList.d.ts +3 -0
  147. package/dist/types/cms/utils/getCMSContentListFilter.d.ts +1 -0
  148. package/dist/types/cms/utils/index.d.ts +1 -0
  149. package/dist/types/config/SentecaProvider.d.ts +1 -0
  150. package/dist/types/contexts/CheckoutForm/hooks/useBilling/index.d.ts +4 -2
  151. package/dist/types/contexts/CheckoutForm/hooks/useShipping/index.d.ts +3 -1
  152. package/dist/types/contexts/CheckoutForm/index.d.ts +4 -1
  153. package/dist/types/contexts/CheckoutForm/utils/validateBillingAddress.d.ts +2 -2
  154. package/dist/types/contexts/CheckoutForm/utils/validateShipping.d.ts +1 -1
  155. package/dist/types/hooks/addresses-hooks/useAddressForm/index.d.ts +2 -1
  156. package/dist/types/hooks/order-hooks/useOrder/index.d.ts +7 -1
  157. package/dist/types/hooks/useAggregateResult/index.d.ts +2 -2
  158. package/dist/types/hooks/useCheckoutShippingModule/index.d.ts +2 -2
  159. package/dist/types/index.d.ts +0 -2
  160. package/dist/types/seo/api/ssr/getCanonicalUrl.d.ts +3 -0
  161. package/dist/types/seo/api/ssr/index.d.ts +1 -0
  162. package/dist/types/user/api/index.d.ts +1 -0
  163. package/dist/types/user/api/utils/generateAnonymousToken.d.ts +1 -0
  164. package/dist/types/user/api/utils/index.d.ts +1 -0
  165. package/dist/types/user/index.d.ts +1 -0
  166. package/package.json +3 -3
  167. package/dist/cjs/api/cmsContentApi/index.js +0 -325
  168. package/dist/cjs/api/cmsContentApi/index.js.map +0 -1
  169. package/dist/cjs/hooks/cms-content-hooks/index.js +0 -28
  170. package/dist/cjs/hooks/cms-content-hooks/index.js.map +0 -1
  171. package/dist/cjs/hooks/cms-content-hooks/useCmsContent/index.js.map +0 -1
  172. package/dist/cjs/hooks/cms-content-hooks/useCmsContentList/index.js.map +0 -1
  173. package/dist/cjs/hooks/cms-content-hooks/useContentCategoriesMap/index.js.map +0 -1
  174. package/dist/esm/api/cmsContentApi/index.js +0 -161
  175. package/dist/esm/api/cmsContentApi/index.js.map +0 -1
  176. package/dist/esm/hooks/cms-content-hooks/index.js +0 -4
  177. package/dist/esm/hooks/cms-content-hooks/index.js.map +0 -1
  178. package/dist/esm/hooks/cms-content-hooks/useCmsContent/index.js.map +0 -1
  179. package/dist/esm/hooks/cms-content-hooks/useCmsContentList/index.js.map +0 -1
  180. package/dist/esm/hooks/cms-content-hooks/useContentCategoriesMap/index.js.map +0 -1
  181. package/dist/types/api/cmsContentApi/index.d.ts +0 -37
  182. package/dist/types/hooks/cms-content-hooks/index.d.ts +0 -3
@@ -12,14 +12,12 @@ exports.defaultShippingValidations = void 0;
12
12
 
13
13
  var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
14
14
 
15
- var _validations = require("../../../utils/validations");
15
+ var _validations2 = require("../../../utils/validations");
16
16
 
17
17
  var _api = require("../../../api.v2");
18
18
 
19
19
  var _defaultShippingValid;
20
20
 
21
- var alwaysRequiredField = ['firstName', 'lastName', 'email', 'phoneNumber'];
22
-
23
21
  function genericAddressValidation(_ref) {
24
22
  var _mod$moduleData, _data$quarter, _data$streetName, _data$additionalAddre;
25
23
 
@@ -133,11 +131,15 @@ var defaultShippingValidations = (_defaultShippingValid = {}, _defaultShippingVa
133
131
  Default: pickupFromStoreValidation
134
132
  }, _defaultShippingValid);
135
133
  exports.defaultShippingValidations = defaultShippingValidations;
134
+ var defaultRequiredFields = ['firstName', 'lastName', 'email', 'phoneNumber'];
136
135
 
137
- function validateShipping(data, mod, errorLabels, validations) {
138
- var _mod$moduleData5, _validations$mod$modu;
136
+ function validateShipping(data, mod, errorLabels, validations, requiredFields, enableNoShippingMethodMode) {
137
+ if (requiredFields === void 0) {
138
+ requiredFields = defaultRequiredFields;
139
+ }
139
140
 
140
- var globalErrors = alwaysRequiredField.reduce(function (errors, field) {
141
+ var validateErrors = {};
142
+ var globalErrors = requiredFields.reduce(function (errors, field) {
141
143
  var _data$field;
142
144
 
143
145
  if (!(data != null && (_data$field = data[field]) != null && _data$field.trim != null && _data$field.trim())) {
@@ -149,31 +151,36 @@ function validateShipping(data, mod, errorLabels, validations) {
149
151
  return errors;
150
152
  }, {});
151
153
 
152
- if (data != null && data.email && !_validations.emailRegex.test(data.email)) {
154
+ if (data != null && data.email && !_validations2.emailRegex.test(data.email)) {
153
155
  globalErrors.email = errorLabels.emailIsRequired;
154
156
  }
155
157
 
156
- if (data != null && data.phoneNumber && !_validations.phoneNumberRegex.test(data == null ? void 0 : data.phoneNumber)) {
158
+ if (data != null && data.phoneNumber && !_validations2.phoneNumberRegex.test(data == null ? void 0 : data.phoneNumber)) {
157
159
  globalErrors.phoneNumber = (errorLabels == null ? void 0 : errorLabels.invalidPhoneNumber) || '';
158
160
  }
159
161
 
160
- if (!(mod != null && mod.moduleKey) || !(mod != null && (_mod$moduleData5 = mod.moduleData) != null && _mod$moduleData5.methodKey)) {
161
- return (0, _extends3["default"])({}, globalErrors, {
162
- courier: errorLabels.selectCourier
163
- });
164
- }
162
+ if (!enableNoShippingMethodMode) {
163
+ var _mod$moduleData5, _validations;
165
164
 
166
- var validate = (_validations$mod$modu = validations[mod.moduleKey]) == null ? void 0 : _validations$mod$modu[mod.moduleData.methodKey];
165
+ if (!(mod != null && mod.moduleKey) || !(mod != null && (_mod$moduleData5 = mod.moduleData) != null && _mod$moduleData5.methodKey)) {
166
+ return (0, _extends3["default"])({}, globalErrors, {
167
+ courier: errorLabels.selectCourier
168
+ });
169
+ }
170
+
171
+ var validate = (_validations = validations[mod == null ? void 0 : mod.moduleKey]) == null ? void 0 : _validations[mod == null ? void 0 : mod.moduleData.methodKey];
172
+
173
+ if (!validate) {
174
+ throw new Error("Validation for shipping with provider: " + (mod == null ? void 0 : mod.moduleKey) + " and method key: " + (mod == null ? void 0 : mod.moduleData.methodKey) + " not found");
175
+ }
167
176
 
168
- if (!validate) {
169
- throw new Error("Validation for shipping with provider: " + mod.moduleKey + " and method key: " + mod.moduleData.methodKey + " not found");
177
+ validateErrors = validate({
178
+ data: data,
179
+ mod: mod,
180
+ errorLabels: errorLabels
181
+ }) || {};
170
182
  }
171
183
 
172
- var validateErrors = validate({
173
- data: data,
174
- mod: mod,
175
- errorLabels: errorLabels
176
- }) || {};
177
184
  var errors = (0, _extends3["default"])({}, globalErrors, validateErrors);
178
185
  return Object.keys(errors).length ? errors : null;
179
186
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/contexts/CheckoutForm/utils/validateShipping.ts"],"names":["alwaysRequiredField","genericAddressValidation","data","mod","errorLabels","address","moduleData","city","cityIsRequired","quarter","trim","streetNumber","entrance","building","apartment","any","fillStreetNumberBuildingEntranceOrApartment","street","streetName","additionalAddressInfo","cantFindStreetOrQuarterMessage","streetIsRequired","quarterIsRequired","fanAddressValidation","errors","fieldIsRequired","Object","keys","length","genericOfficeValidation","office","officeIsRequired","pickupFromStoreValidation","stockLocation","pickupFromStore","noStoreSelected","undefined","defaultShippingValidations","ShippingModulesTypeEnum","Speedy","Address","Office","Econt","Evropat","Fan","PickUpFromStore","Default","validateShipping","validations","globalErrors","reduce","field","email","emailRegex","test","emailIsRequired","phoneNumber","phoneNumberRegex","invalidPhoneNumber","moduleKey","methodKey","courier","selectCourier","validate","Error","validateErrors"],"mappings":";;;;;;;;;;;;;;AAQA;;AACA;;;;AAEA,IAAMA,mBAAmB,GAAG,CAAC,WAAD,EAAc,UAAd,EAA0B,OAA1B,EAAmC,aAAnC,CAA5B;;AAQO,SAASC,wBAAT,OAI2C;AAAA;;AAAA,MAHhDC,IAGgD,QAHhDA,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AA5C,CAAjB;;AAEA,MAAI,CAACG,QAAL,EAAe;AACb,UAAM,IAAIC,KAAJ,6CACsC7D,GAAG,CAACwD,SAD1C,yBACuExD,GAAG,CAACG,UAAJ,CAAesD,SADtF,gBAAN;AAGD;;AAED,MAAMK,cAAc,GAAGF,QAAQ,CAAC;AAAE7D,IAAAA,IAAI,EAAJA,IAAF;AAAQC,IAAAA,GAAG,EAAHA,GAAR;AAAaC,IAAAA,WAAW,EAAXA;AAAb,GAAD,CAAR,IAAwC,EAA/D;AAEA,MAAMoB,MAAoC,iCACrCyB,YADqC,EAErCgB,cAFqC,CAA1C;AAKA,SAAOvC,MAAM,CAACC,IAAP,CAAYH,MAAZ,EAAoBI,MAApB,GAA6BJ,MAA7B,GAAsC,IAA7C;AACD","sourcesContent":["/* eslint-disable prefer-const */\nimport { AddressDTO } from '@sentecacommerce/sdk'\nimport { ShippingModule } from '../../../hooks/useCheckoutShippingModule'\n\nimport {\n CheckoutFormErrorLabelsType,\n CheckoutFormErrorsResultType,\n} from '../index'\nimport { emailRegex, phoneNumberRegex } from '../../../utils/validations'\nimport { ShippingModulesTypeEnum } from '../../../api.v2'\n\nconst alwaysRequiredField = ['firstName', 'lastName', 'email', 'phoneNumber']\n\ntype ValidationProps = {\n data?: AddressDTO | null\n mod?: ShippingModule | null\n errorLabels: CheckoutFormErrorLabelsType\n}\n\nexport function genericAddressValidation({\n data,\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n const address = mod?.moduleData?.address\n\n if (!data) return\n\n if (!address?.city) {\n // City is always required\n return {\n city: errorLabels.cityIsRequired,\n }\n }\n\n // case 1: city + quarter + anything else\n if (address?.quarter || data.quarter?.trim()) {\n if (\n !data.streetNumber?.trim() &&\n !data.entrance?.trim() &&\n !data.building?.trim() &&\n !data.apartment?.trim()\n ) {\n return {\n any: errorLabels.fillStreetNumberBuildingEntranceOrApartment,\n }\n }\n }\n // case 2: city + street + anything else\n else if (address?.street || data.streetName?.trim()) {\n if (\n !data.streetNumber?.trim() &&\n !data.entrance?.trim() &&\n !data.building?.trim() &&\n !data.apartment?.trim()\n ) {\n return {\n any: errorLabels.fillStreetNumberBuildingEntranceOrApartment,\n }\n }\n }\n // case 3: city + additional info\n else if (!data.additionalAddressInfo?.trim()) {\n return {\n additionalAddressInfo: errorLabels.cantFindStreetOrQuarterMessage,\n street: errorLabels.streetIsRequired,\n quarter: errorLabels.quarterIsRequired,\n }\n }\n}\n\nexport function fanAddressValidation({\n data,\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n const address = mod?.moduleData?.address\n const errors: CheckoutFormErrorsResultType = {}\n\n if (!data) return\n\n // City, Street and StreetNumber are always required\n if (!address?.city) {\n errors.city = errorLabels.cityIsRequired\n }\n\n if (!address?.street) {\n errors.street = errorLabels.streetIsRequired\n }\n\n if (!data.streetNumber) {\n errors.streetNumber = errorLabels.fieldIsRequired\n }\n\n return Object.keys(errors).length ? errors : null\n}\n\nexport function genericOfficeValidation({\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n let errors: CheckoutFormErrorsResultType = {}\n\n const address = mod?.moduleData?.address\n\n if (!address?.city) {\n errors.city = errorLabels.cityIsRequired\n }\n\n if (!address?.office) {\n errors.office = errorLabels.officeIsRequired\n }\n\n return Object.keys(errors).length ? errors : null\n}\n\nexport function pickupFromStoreValidation({\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n return !mod?.moduleData?.stockLocation\n ? { pickupFromStore: errorLabels.noStoreSelected }\n : undefined\n}\n\nexport const defaultShippingValidations: ShippingValidationsType = {\n [ShippingModulesTypeEnum.Speedy]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Econt]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Evropat]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Fan]: {\n Address: fanAddressValidation,\n },\n [ShippingModulesTypeEnum.PickUpFromStore]: {\n Default: pickupFromStoreValidation,\n },\n}\n\nexport interface ShippingValidationsType {\n [key: string]: {\n [key: string]: (\n data: ValidationProps\n ) => { [key: string]: string } | null | undefined\n }\n}\n\nexport function validateShipping(\n data: AddressDTO | null | undefined,\n mod: ShippingModule | undefined,\n errorLabels: CheckoutFormErrorLabelsType,\n validations: ShippingValidationsType\n): CheckoutFormErrorsResultType {\n const globalErrors: CheckoutFormErrorsResultType = alwaysRequiredField.reduce(\n (errors, field) => {\n if (!data?.[field]?.trim?.()) {\n return {\n ...errors,\n [field]: errorLabels.fieldIsRequired,\n }\n }\n\n return errors\n },\n {}\n )\n\n if (data?.email && !emailRegex.test(data.email)) {\n globalErrors.email = errorLabels.emailIsRequired\n }\n\n if (data?.phoneNumber && !phoneNumberRegex.test(data?.phoneNumber)) {\n globalErrors.phoneNumber = errorLabels?.invalidPhoneNumber || ''\n }\n\n if (!mod?.moduleKey || !mod?.moduleData?.methodKey) {\n return {\n ...globalErrors,\n courier: errorLabels.selectCourier,\n }\n }\n\n const validate = validations[mod.moduleKey]?.[mod.moduleData.methodKey]\n\n if (!validate) {\n throw new Error(\n `Validation for shipping with provider: ${mod.moduleKey} and method key: ${mod.moduleData.methodKey} not found`\n )\n }\n\n const validateErrors = validate({ data, mod, errorLabels }) || {}\n\n const errors: CheckoutFormErrorsResultType = {\n ...globalErrors,\n ...validateErrors,\n }\n\n return Object.keys(errors).length ? errors : null\n}\n"],"file":"validateShipping.js"}
1
+ {"version":3,"sources":["../../../../../src/contexts/CheckoutForm/utils/validateShipping.ts"],"names":["genericAddressValidation","data","mod","errorLabels","address","moduleData","city","cityIsRequired","quarter","trim","streetNumber","entrance","building","apartment","any","fillStreetNumberBuildingEntranceOrApartment","street","streetName","additionalAddressInfo","cantFindStreetOrQuarterMessage","streetIsRequired","quarterIsRequired","fanAddressValidation","errors","fieldIsRequired","Object","keys","length","genericOfficeValidation","office","officeIsRequired","pickupFromStoreValidation","stockLocation","pickupFromStore","noStoreSelected","undefined","defaultShippingValidations","ShippingModulesTypeEnum","Speedy","Address","Office","Econt","Evropat","Fan","PickUpFromStore","Default","defaultRequiredFields","validateShipping","validations","requiredFields","enableNoShippingMethodMode","validateErrors","globalErrors","reduce","field","email","emailRegex","test","emailIsRequired","phoneNumber","phoneNumberRegex","invalidPhoneNumber","moduleKey","methodKey","courier","selectCourier","validate","Error"],"mappings":";;;;;;;;;;;;;;AAQA;;AACA;;;;AAQO,SAASA,wBAAT,OAI2C;AAAA;;AAAA,MAHhDC,IAGgD,QAHhDA,IAGgD;AAAA,MAFhDC,GAEgD,QAFhDA,GAEgD;AAAA,MADhDC,WACgD,QADhDA,WACgD;AAChD,MAAMC,OAAO,GAAGF,GAAH,uCAAGA,GAAG,CAAEG,UAAR,qBAAG,gBAAiBD,OAAjC;AAEA,MAAI,CAACH,IAAL,EAAW;;AAEX,MAAI,EAACG,OAAD,YAACA,OAAO,CAAEE,IAAV,CAAJ,EAAoB;AAClB;AACA,WAAO;AACLA,MAAAA,IAAI,EAAEH,WAAW,CAACI;AADb,KAAP;AAGD,GAV+C,CAYhD;;;AACA,MAAIH,OAAO,QAAP,IAAAA,OAAO,CAAEI,OAAT,qBAAoBP,IAAI,CAACO,OAAzB,aAAoB,cAAcC,IAAd,EAAxB,EAA8C;AAAA;;AAC5C,QACE,wBAACR,IAAI,CAACS,YAAN,aAAC,mBAAmBD,IAAnB,EAAD,KACA,oBAACR,IAAI,CAACU,QAAN,aAAC,eAAeF,IAAf,EAAD,CADA,IAEA,oBAACR,IAAI,CAACW,QAAN,aAAC,eAAeH,IAAf,EAAD,CAFA,IAGA,qBAACR,IAAI,CAACY,SAAN,aAAC,gBAAgBJ,IAAhB,EAAD,CAJF,EAKE;AACA,aAAO;AACLK,QAAAA,GAAG,EAAEX,WAAW,CAACY;AADZ,OAAP;AAGD;AACF,GAXD,CAYA;AAZA,OAaK,IAAIX,OAAO,QAAP,IAAAA,OA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\nimport { ShippingModule } from '../../../hooks/useCheckoutShippingModule'\n\nimport {\n CheckoutFormErrorLabelsType,\n CheckoutFormErrorsResultType,\n} from '../index'\nimport { emailRegex, phoneNumberRegex } from '../../../utils/validations'\nimport { ShippingModulesTypeEnum } from '../../../api.v2'\n\ntype ValidationProps = {\n data?: AddressDTO | null\n mod?: ShippingModule | null\n errorLabels: CheckoutFormErrorLabelsType\n}\n\nexport function genericAddressValidation({\n data,\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n const address = mod?.moduleData?.address\n\n if (!data) return\n\n if (!address?.city) {\n // City is always required\n return {\n city: errorLabels.cityIsRequired,\n }\n }\n\n // case 1: city + quarter + anything else\n if (address?.quarter || data.quarter?.trim()) {\n if (\n !data.streetNumber?.trim() &&\n !data.entrance?.trim() &&\n !data.building?.trim() &&\n !data.apartment?.trim()\n ) {\n return {\n any: errorLabels.fillStreetNumberBuildingEntranceOrApartment,\n }\n }\n }\n // case 2: city + street + anything else\n else if (address?.street || data.streetName?.trim()) {\n if (\n !data.streetNumber?.trim() &&\n !data.entrance?.trim() &&\n !data.building?.trim() &&\n !data.apartment?.trim()\n ) {\n return {\n any: errorLabels.fillStreetNumberBuildingEntranceOrApartment,\n }\n }\n }\n // case 3: city + additional info\n else if (!data.additionalAddressInfo?.trim()) {\n return {\n additionalAddressInfo: errorLabels.cantFindStreetOrQuarterMessage,\n street: errorLabels.streetIsRequired,\n quarter: errorLabels.quarterIsRequired,\n }\n }\n}\n\nexport function fanAddressValidation({\n data,\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n const address = mod?.moduleData?.address\n const errors: CheckoutFormErrorsResultType = {}\n\n if (!data) return\n\n // City, Street and StreetNumber are always required\n if (!address?.city) {\n errors.city = errorLabels.cityIsRequired\n }\n\n if (!address?.street) {\n errors.street = errorLabels.streetIsRequired\n }\n\n if (!data.streetNumber) {\n errors.streetNumber = errorLabels.fieldIsRequired\n }\n\n return Object.keys(errors).length ? errors : null\n}\n\nexport function genericOfficeValidation({\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n let errors: CheckoutFormErrorsResultType = {}\n\n const address = mod?.moduleData?.address\n\n if (!address?.city) {\n errors.city = errorLabels.cityIsRequired\n }\n\n if (!address?.office) {\n errors.office = errorLabels.officeIsRequired\n }\n\n return Object.keys(errors).length ? errors : null\n}\n\nexport function pickupFromStoreValidation({\n mod,\n errorLabels,\n}: ValidationProps): CheckoutFormErrorsResultType {\n return !mod?.moduleData?.stockLocation\n ? { pickupFromStore: errorLabels.noStoreSelected }\n : undefined\n}\n\nexport const defaultShippingValidations: ShippingValidationsType = {\n [ShippingModulesTypeEnum.Speedy]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Econt]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Evropat]: {\n Address: genericAddressValidation,\n Office: genericOfficeValidation,\n },\n [ShippingModulesTypeEnum.Fan]: {\n Address: fanAddressValidation,\n },\n [ShippingModulesTypeEnum.PickUpFromStore]: {\n Default: pickupFromStoreValidation,\n },\n}\n\nexport interface ShippingValidationsType {\n [key: string]: {\n [key: string]: (\n data: ValidationProps\n ) => { [key: string]: string } | null | undefined\n }\n}\n\nconst defaultRequiredFields = ['firstName', 'lastName', 'email', 'phoneNumber']\n\nexport function validateShipping(\n data: AddressDTO | null | undefined,\n mod: ShippingModule | undefined,\n errorLabels: CheckoutFormErrorLabelsType,\n validations: ShippingValidationsType,\n requiredFields: string[] = defaultRequiredFields,\n enableNoShippingMethodMode?: boolean\n): CheckoutFormErrorsResultType {\n let validateErrors: { [key: string]: string } = {}\n\n const globalErrors: CheckoutFormErrorsResultType = requiredFields.reduce(\n (errors, field) => {\n if (!data?.[field]?.trim?.()) {\n return {\n ...errors,\n [field]: errorLabels.fieldIsRequired,\n }\n }\n\n return errors\n },\n {}\n )\n\n if (data?.email && !emailRegex.test(data.email)) {\n globalErrors.email = errorLabels.emailIsRequired\n }\n\n if (data?.phoneNumber && !phoneNumberRegex.test(data?.phoneNumber)) {\n globalErrors.phoneNumber = errorLabels?.invalidPhoneNumber || ''\n }\n\n if (!enableNoShippingMethodMode) {\n if (!mod?.moduleKey || !mod?.moduleData?.methodKey) {\n return {\n ...globalErrors,\n courier: errorLabels.selectCourier,\n }\n }\n\n const validate =\n validations[mod?.moduleKey as string]?.[mod?.moduleData.methodKey]\n\n if (!validate) {\n throw new Error(\n `Validation for shipping with provider: ${mod?.moduleKey} and method key: ${mod?.moduleData.methodKey} not found`\n )\n }\n\n validateErrors = validate({ data, mod, errorLabels }) || {}\n }\n\n const errors: CheckoutFormErrorsResultType = {\n ...globalErrors,\n ...validateErrors,\n }\n\n return Object.keys(errors).length ? errors : null\n}\n"],"file":"validateShipping.js"}
@@ -38,7 +38,9 @@ var AddressFormContextProvider = function AddressFormContextProvider(_ref) {
38
38
  onSuccess = _ref.onSuccess,
39
39
  _ref$validations = _ref.validations,
40
40
  validations = _ref$validations === void 0 ? _utils.defaultShippingValidations : _ref$validations,
41
- errorLabels = _ref.errorLabels;
41
+ errorLabels = _ref.errorLabels,
42
+ _ref$requiredFields = _ref.requiredFields,
43
+ requiredFields = _ref$requiredFields === void 0 ? ['firstName', 'lastName', 'email', 'phoneNumber'] : _ref$requiredFields;
42
44
  var emptyAddress = {
43
45
  _id: (currentAddress == null ? void 0 : currentAddress._id) || '',
44
46
  createdAt: Date.now(),
@@ -110,7 +112,7 @@ var AddressFormContextProvider = function AddressFormContextProvider(_ref) {
110
112
  };
111
113
  }, []);
112
114
  var addressErrors = (0, _react.useMemo)(function () {
113
- return (0, _utils.validateShipping)(address, moduleData, errorLabels, validations);
115
+ return (0, _utils.validateShipping)(address, moduleData, errorLabels, validations, requiredFields);
114
116
  }, [address, moduleData, errorLabels, validations]);
115
117
  /**
116
118
  * Format all platform and merchant modules
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/hooks/addresses-hooks/useAddressForm/index.tsx"],"names":["Couriers","AddressFormContext","React","createContext","AddressFormContextProvider","children","currentAddress","address","onSuccess","validations","defaultShippingValidations","errorLabels","emptyAddress","_id","createdAt","Date","now","updatedAt","setAddress","isSubmitting","setIsSubmitting","moduleData","setModuleData","addressesApi","useAdd","addNewAddress","addNewError","error","useUpdate","updateAddress","updateError","myCartApi","useGetAllShippingMethods","moduleTypesRaw","data","isModuleTypesLoading","isLoading","selectModule","moduleKey","methodKey","setModuleAddressData","key","value","formatMethod","method","select","addressErrors","modules","platformMethods","platformShippingMethods","map","merchantMethods","merchantsShippingMethods","methods","flat","result","reduce","current","onChange","name","addNewErrors","updateErrors","errors","hasErrors","Boolean","Object","keys","length","handleSubmit","e","preventDefault","id","dto","undefined","state","formKey","addressState","setAddressState","onInputChange","isValid","useAddressForm","context","useContext","Error"],"mappings":";;;;;;;;;;;AAAA;;AAMA;;AACA;;AACA;;AAMA;;IAEYA,Q;;;WAAAA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;GAAAA,Q,wBAAAA,Q;;AAiCZ,IAAMC,kBAAkB,gBAAGC,kBAAMC,aAAN,CACzB,EADyB,CAA3B;;AAMO,IAAMC,0BAA0B,GAAG,SAA7BA,0BAA6B,OAYpC;AAAA;;AAAA,MAXJC,QAWI,QAXJA,QAWI;AAAA,MAVKC,cAUL,QAVJC,OAUI;AAAA,MATJC,SASI,QATJA,SASI;AAAA,8BARJC,WAQI;AAAA,MARJA,WAQI,iCARUC,iCAQV;AAAA,MAPJC,WAOI,QAPJA,WAOI;AACJ,MAAMC,YAAwB,GAAG;AAC/BC,IAAAA,GAAG,EAAE,CAAAP,cAAc,QAAd,YAAAA,cAAc,CAAEO,GAAhB,KAAuB,EADG;AAE/BC,IAAAA,SAAS,EAAEC,IAAI,CAACC,GAAL,EAFoB;AAG/BC,IAAAA,SAAS,EAAEF,IAAI,CAACC,GAAL;AAHoB,GAAjC;;AADI,kBAO0B,qBAASV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L4D,MAAAA,OAAO,EAAE,CAAChB;AAXL,KAAP;AAaD,GAda,EAcX,CACD1C,UADC,EAEDd,OAFC,EAGD6B,SAHC,EAIDW,OAJC,EAKDP,oBALC,EAMDkB,QANC,EAODvC,YAPC,EAQD2C,MARC,EASDC,SATC,CAdW,CAAd;AA0BA,sBACE,gCAAC,kBAAD,CAAoB,QAApB;AAA6B,IAAA,KAAK,EAAEW;AAApC,kBACE;AAAM,IAAA,QAAQ,EAAEN,YAAhB;AAA8B,IAAA,UAAU;AAAxC,KACG/D,QADH,CADF,CADF;AAOD,CAnNM;;;;AAqNA,IAAM2E,cAAc,GAAG,SAAjBA,cAAiB,GAAM;AAClC,MAAMC,OAAO,GAAG/E,kBAAMgF,UAAN,CAAiBjF,kBAAjB,CAAhB;;AAEA,MAAI,CAACgF,OAAL,EAAc;AACZ,UAAM,IAAIE,KAAJ,CACJ,iEADI,CAAN;AAGD;;AAED,SAAOF,OAAP;AACD,CAVM","sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n AddressModuleDataDTO,\n ShippingMethodDTO,\n AddressDTO,\n} from '@sentecacommerce/sdk'\nimport { addressesApi } from '../../../api/addressesApi'\nimport { myCartApi } from '../../../api/myCartApi'\nimport {\n validateShipping,\n defaultShippingValidations,\n ShippingValidationsType,\n} from '../../../contexts/CheckoutForm/utils'\nimport { ShippingFormErrorLabels } from '../../../contexts/CheckoutForm'\nimport { useErrors, DefaultFormErrors } from '../../error-handling'\n\nexport enum Couriers {\n 'Speedy' = 'Speedy',\n 'Econt' = 'Econt',\n 'Evropat' = 'Evropat',\n}\n\nexport type AddressFormModule = {\n methods: {\n key?: string\n select: () => void\n }[]\n}\n\ntype Modules = {\n [key in Couriers]: AddressFormModule\n}\n\ntype AddressFormContextValue = {\n formKey: string\n modules: Modules\n isLoading: boolean\n addressState?: AddressDTO\n setAddressState: React.Dispatch<AddressDTO>\n onInputChange: (name: string, value: any) => void\n moduleData?: AddressModuleDataDTO\n setModuleAddressData: (key: string, value: any) => void\n isSubmitting: boolean\n isValid: boolean\n errors: {\n [key: string]: string | undefined\n }\n}\n\nconst AddressFormContext = React.createContext<AddressFormContextValue>(\n {} as any\n)\n\nexport type AddressFormLabelsType = ShippingFormErrorLabels & DefaultFormErrors\n\nexport const AddressFormContextProvider = ({\n children,\n address: currentAddress,\n onSuccess,\n validations = defaultShippingValidations,\n errorLabels,\n}: {\n children: JSX.Element | JSX.Element[]\n address?: AddressDTO\n onSuccess: () => void\n validations?: ShippingValidationsType\n errorLabels: AddressFormLabelsType\n}) => {\n const emptyAddress: AddressDTO = {\n _id: currentAddress?._id || '',\n createdAt: Date.now(),\n updatedAt: Date.now(),\n }\n \n const [address, setAddress] = useState(currentAddress || emptyAddress)\n\n const [isSubmitting, setIsSubmitting] = useState(false)\n\n const [moduleData, setModuleData] = useState(currentAddress?.moduleData?.[0])\n\n const [addNewAddress, { error: addNewError }] = addressesApi.useAdd({\n onSuccess,\n })\n const [updateAddress, { error: updateError }] = addressesApi.useUpdate(\n onSuccess\n )\n\n const {\n data: moduleTypesRaw,\n isLoading: isModuleTypesLoading,\n } = myCartApi.useGetAllShippingMethods()\n\n const isLoading = isModuleTypesLoading\n\n // set initial data\n useEffect(() => {\n if (!address && currentAddress) {\n setAddress(currentAddress)\n setModuleData(currentAddress.moduleData?.[0])\n }\n }, [address, currentAddress])\n\n const selectModule = (moduleKey: string, methodKey: string) => {\n setModuleData({ moduleKey, moduleData: { methodKey } })\n }\n\n const setModuleAddressData = useCallback(\n (key: string, value: any) => {\n if (!moduleData) return\n\n const data = { ...moduleData }\n\n if (!data.moduleData) data.moduleData = {}\n\n data.moduleData.address = {\n ...(data.moduleData.address || {}),\n [key]: value,\n }\n\n setModuleData(data)\n },\n [moduleData]\n )\n\n const formatMethod = useCallback((method: ShippingMethodDTO) => {\n return {\n moduleKey: method.moduleKey,\n select: () =>\n selectModule(method.moduleKey as string, method.methodKey as string),\n methodKey: method.methodKey,\n }\n }, [])\n\n const addressErrors = useMemo(() => {\n return validateShipping(\n address,\n moduleData,\n errorLabels as any,\n validations\n )\n }, [address, moduleData, errorLabels, validations])\n\n /**\n * Format all platform and merchant modules\n */\n const modules = useMemo((): Modules => {\n const platformMethods =\n moduleTypesRaw?.platformShippingMethods?.map?.(formatMethod) || []\n\n const merchantMethods =\n moduleTypesRaw?.merchantsShippingMethods?.map?.((data) => {\n return data?.methods?.map?.(formatMethod)\n }) || []\n\n const data = [...platformMethods, ...merchantMethods.flat()]\n\n const result = data.reduce((current, method) => {\n return {\n ...current,\n [method.moduleKey as Couriers]: {\n methods: [\n ...(current[method.moduleKey as Couriers]?.methods || []),\n {\n key: method.methodKey,\n select: method.select,\n },\n ],\n },\n }\n }, {})\n\n return (result as unknown) as Modules\n }, [moduleTypesRaw, formatMethod])\n\n /**\n * On input change\n */\n const onChange = useCallback(\n (name: string, value: any) => {\n if (!address) return\n\n setAddress({\n ...address,\n [name]: value,\n })\n },\n [address]\n )\n\n const addNewErrors = useErrors<AddressFormLabelsType>(\n addNewError,\n errorLabels\n )\n const updateErrors = useErrors<AddressFormLabelsType>(\n updateError,\n errorLabels\n )\n\n const errors = useMemo(() => {\n return {\n ...(addressErrors || {}),\n ...(updateErrors || {}),\n ...(addNewErrors || {}),\n }\n }, [addressErrors, updateErrors, addNewErrors])\n\n const hasErrors = Boolean(Object.keys(errors).length)\n\n const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n setIsSubmitting(true)\n\n if (hasErrors) return\n\n if (currentAddress?._id) {\n updateAddress({\n id: currentAddress._id,\n dto: {\n ...address,\n moduleData: moduleData && [moduleData],\n },\n })\n\n return\n }\n\n addNewAddress({\n ...address,\n _id: undefined,\n moduleData: moduleData && [moduleData],\n })\n }\n\n const state = useMemo((): AddressFormContextValue => {\n return {\n formKey: `${moduleData?.moduleKey}-${moduleData?.moduleData?.methodKey}`,\n modules,\n isLoading,\n addressState: address,\n setAddressState: setAddress,\n onInputChange: onChange,\n moduleData,\n setModuleAddressData,\n errors: isSubmitting ? errors : {},\n isSubmitting,\n isValid: !hasErrors,\n }\n }, [\n moduleData,\n address,\n isLoading,\n modules,\n setModuleAddressData,\n onChange,\n isSubmitting,\n errors,\n hasErrors,\n ])\n\n return (\n <AddressFormContext.Provider value={state}>\n <form onSubmit={handleSubmit} noValidate>\n {children}\n </form>\n </AddressFormContext.Provider>\n )\n}\n\nexport const useAddressForm = () => {\n const context = React.useContext(AddressFormContext)\n\n if (!context) {\n throw new Error(\n 'useAddressForm must be used within a AddressFormContextProvider'\n )\n }\n\n return context\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../../src/hooks/addresses-hooks/useAddressForm/index.tsx"],"names":["Couriers","AddressFormContext","React","createContext","AddressFormContextProvider","children","currentAddress","address","onSuccess","validations","defaultShippingValidations","errorLabels","requiredFields","emptyAddress","_id","createdAt","Date","now","updatedAt","setAddress","isSubmitting","setIsSubmitting","moduleData","setModuleData","addressesApi","useAdd","addNewAddress","addNewError","error","useUpdate","updateAddress","updateError","myCartApi","useGetAllShippingMethods","moduleTypesRaw","data","isModuleTypesLoading","isLoading","selectModule","moduleKey","methodKey","setModuleAddressData","key","value","formatMethod","method","select","addressErrors","modules","platformMethods","platformShippingMethods","map","merchantMethods","merchantsShippingMethods","methods","flat","result","reduce","current","onChange","name","addNewErrors","updateErrors","errors","hasErrors","Boolean","Object","keys","length","handleSubmit","e","preventDefault","id","dto","undefined","state","formKey","addressState","setAddressState","onInputChange","isValid","useAddressForm","context","useContext","Error"],"mappings":";;;;;;;;;;;AAAA;;AAMA;;AACA;;AACA;;AAMA;;IAEYA,Q;;;WAAAA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;AAAAA,EAAAA,Q;GAAAA,Q,wBAAAA,Q;;AAiCZ,IAAMC,kBAAkB,gBAAGC,kBAAMC,aAAN,CACzB,EADyB,CAA3B;;AAMO,IAAMC,0BAA0B,GAAG,SAA7BA,0BAA6B,OAcpC;AAAA;;AAAA,M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,MAAMqD,KAAK,GAAG,oBAAQ,YAA+B;AAAA;;AACnD,WAAO;AACLC,MAAAA,OAAO,GAAKtD,UAAL,oBAAKA,UAAU,CAAEiB,SAAjB,WAA8BjB,UAA9B,6CAA8BA,UAAU,CAAEA,UAA1C,qBAA8B,sBAAwBkB,SAAtD,CADF;AAELQ,MAAAA,OAAO,EAAPA,OAFK;AAGLX,MAAAA,SAAS,EAATA,SAHK;AAILwC,MAAAA,YAAY,EAAEtE,OAJT;AAKLuE,MAAAA,eAAe,EAAE3D,UALZ;AAML4D,MAAAA,aAAa,EAAEpB,QANV;AAOLrC,MAAAA,UAAU,EAAVA,UAPK;AAQLmB,MAAAA,oBAAoB,EAApBA,oBARK;AASLsB,MAAAA,MAAM,EAAE3C,YAAY,GAAG2C,MAAH,GAAY,EAT3B;AAUL3C,MAAAA,YAAY,EAAZA,YAVK;AAWL4D,MAAAA,OAAO,EAAE,CAAChB;AAXL,KAAP;AAaD,GAda,EAcX,CACD1C,UADC,EAEDf,OAFC,EAGD8B,SAHC,EAIDW,OAJC,EAKDP,oBALC,EAMDkB,QANC,EAODvC,YAPC,EAQD2C,MARC,EASDC,SATC,CAdW,CAAd;AA0BA,sBACE,gCAAC,kBAAD,CAAoB,QAApB;AAA6B,IAAA,KAAK,EAAEW;AAApC,kBACE;AAAM,IAAA,QAAQ,EAAEN,YAAhB;AAA8B,IAAA,UAAU;AAAxC,KACGhE,QADH,CADF,CADF;AAOD,CAtNM;;;;AAwNA,IAAM4E,cAAc,GAAG,SAAjBA,cAAiB,GAAM;AAClC,MAAMC,OAAO,GAAGhF,kBAAMiF,UAAN,CAAiBlF,kBAAjB,CAAhB;;AAEA,MAAI,CAACiF,OAAL,EAAc;AACZ,UAAM,IAAIE,KAAJ,CACJ,iEADI,CAAN;AAGD;;AAED,SAAOF,OAAP;AACD,CAVM","sourcesContent":["import React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n AddressModuleDataDTO,\n ShippingMethodDTO,\n AddressDTO,\n} from '@sentecacommerce/sdk'\nimport { addressesApi } from '../../../api/addressesApi'\nimport { myCartApi } from '../../../api/myCartApi'\nimport {\n validateShipping,\n defaultShippingValidations,\n ShippingValidationsType,\n} from '../../../contexts/CheckoutForm/utils'\nimport { ShippingFormErrorLabels } from '../../../contexts/CheckoutForm'\nimport { useErrors, DefaultFormErrors } from '../../error-handling'\n\nexport enum Couriers {\n 'Speedy' = 'Speedy',\n 'Econt' = 'Econt',\n 'Evropat' = 'Evropat',\n}\n\nexport type AddressFormModule = {\n methods: {\n key?: string\n select: () => void\n }[]\n}\n\ntype Modules = {\n [key in Couriers]: AddressFormModule\n}\n\ntype AddressFormContextValue = {\n formKey: string\n modules: Modules\n isLoading: boolean\n addressState?: AddressDTO\n setAddressState: React.Dispatch<AddressDTO>\n onInputChange: (name: string, value: any) => void\n moduleData?: AddressModuleDataDTO\n setModuleAddressData: (key: string, value: any) => void\n isSubmitting: boolean\n isValid: boolean\n errors: {\n [key: string]: string | undefined\n }\n}\n\nconst AddressFormContext = React.createContext<AddressFormContextValue>(\n {} as any\n)\n\nexport type AddressFormLabelsType = ShippingFormErrorLabels & DefaultFormErrors\n\nexport const AddressFormContextProvider = ({\n children,\n address: currentAddress,\n onSuccess,\n validations = defaultShippingValidations,\n errorLabels,\n requiredFields = ['firstName', 'lastName', 'email', 'phoneNumber'],\n}: {\n children: JSX.Element | JSX.Element[]\n address?: AddressDTO\n onSuccess: () => void\n validations?: ShippingValidationsType\n errorLabels: AddressFormLabelsType\n requiredFields?: string[]\n}) => {\n const emptyAddress: AddressDTO = {\n _id: currentAddress?._id || '',\n createdAt: Date.now(),\n updatedAt: Date.now(),\n }\n\n const [address, setAddress] = useState(currentAddress || emptyAddress)\n\n const [isSubmitting, setIsSubmitting] = useState(false)\n\n const [moduleData, setModuleData] = useState(currentAddress?.moduleData?.[0])\n\n const [addNewAddress, { error: addNewError }] = addressesApi.useAdd({\n onSuccess,\n })\n const [updateAddress, { error: updateError }] = addressesApi.useUpdate(\n onSuccess\n )\n\n const {\n data: moduleTypesRaw,\n isLoading: isModuleTypesLoading,\n } = myCartApi.useGetAllShippingMethods()\n\n const isLoading = isModuleTypesLoading\n\n // set initial data\n useEffect(() => {\n if (!address && currentAddress) {\n setAddress(currentAddress)\n setModuleData(currentAddress.moduleData?.[0])\n }\n }, [address, currentAddress])\n\n const selectModule = (moduleKey: string, methodKey: string) => {\n setModuleData({ moduleKey, moduleData: { methodKey } })\n }\n\n const setModuleAddressData = useCallback(\n (key: string, value: any) => {\n if (!moduleData) return\n\n const data = { ...moduleData }\n\n if (!data.moduleData) data.moduleData = {}\n\n data.moduleData.address = {\n ...(data.moduleData.address || {}),\n [key]: value,\n }\n\n setModuleData(data)\n },\n [moduleData]\n )\n\n const formatMethod = useCallback((method: ShippingMethodDTO) => {\n return {\n moduleKey: method.moduleKey,\n select: () =>\n selectModule(method.moduleKey as string, method.methodKey as string),\n methodKey: method.methodKey,\n }\n }, [])\n\n const addressErrors = useMemo(() => {\n return validateShipping(\n address,\n moduleData,\n errorLabels as any,\n validations,\n requiredFields\n )\n }, [address, moduleData, errorLabels, validations])\n\n /**\n * Format all platform and merchant modules\n */\n const modules = useMemo((): Modules => {\n const platformMethods =\n moduleTypesRaw?.platformShippingMethods?.map?.(formatMethod) || []\n\n const merchantMethods =\n moduleTypesRaw?.merchantsShippingMethods?.map?.((data) => {\n return data?.methods?.map?.(formatMethod)\n }) || []\n\n const data = [...platformMethods, ...merchantMethods.flat()]\n\n const result = data.reduce((current, method) => {\n return {\n ...current,\n [method.moduleKey as Couriers]: {\n methods: [\n ...(current[method.moduleKey as Couriers]?.methods || []),\n {\n key: method.methodKey,\n select: method.select,\n },\n ],\n },\n }\n }, {})\n\n return (result as unknown) as Modules\n }, [moduleTypesRaw, formatMethod])\n\n /**\n * On input change\n */\n const onChange = useCallback(\n (name: string, value: any) => {\n if (!address) return\n\n setAddress({\n ...address,\n [name]: value,\n })\n },\n [address]\n )\n\n const addNewErrors = useErrors<AddressFormLabelsType>(\n addNewError,\n errorLabels\n )\n const updateErrors = useErrors<AddressFormLabelsType>(\n updateError,\n errorLabels\n )\n\n const errors = useMemo(() => {\n return {\n ...(addressErrors || {}),\n ...(updateErrors || {}),\n ...(addNewErrors || {}),\n }\n }, [addressErrors, updateErrors, addNewErrors])\n\n const hasErrors = Boolean(Object.keys(errors).length)\n\n const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n setIsSubmitting(true)\n\n if (hasErrors) return\n\n if (currentAddress?._id) {\n updateAddress({\n id: currentAddress._id,\n dto: {\n ...address,\n moduleData: moduleData && [moduleData],\n },\n })\n\n return\n }\n\n addNewAddress({\n ...address,\n _id: undefined,\n moduleData: moduleData && [moduleData],\n })\n }\n\n const state = useMemo((): AddressFormContextValue => {\n return {\n formKey: `${moduleData?.moduleKey}-${moduleData?.moduleData?.methodKey}`,\n modules,\n isLoading,\n addressState: address,\n setAddressState: setAddress,\n onInputChange: onChange,\n moduleData,\n setModuleAddressData,\n errors: isSubmitting ? errors : {},\n isSubmitting,\n isValid: !hasErrors,\n }\n }, [\n moduleData,\n address,\n isLoading,\n modules,\n setModuleAddressData,\n onChange,\n isSubmitting,\n errors,\n hasErrors,\n ])\n\n return (\n <AddressFormContext.Provider value={state}>\n <form onSubmit={handleSubmit} noValidate>\n {children}\n </form>\n </AddressFormContext.Provider>\n )\n}\n\nexport const useAddressForm = () => {\n const context = React.useContext(AddressFormContext)\n\n if (!context) {\n throw new Error(\n 'useAddressForm must be used within a AddressFormContextProvider'\n )\n }\n\n return context\n}\n"],"file":"index.js"}
@@ -5,8 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  exports.__esModule = true;
6
6
  exports.useOrder = void 0;
7
7
 
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
8
10
  var _react = _interopRequireDefault(require("react"));
9
11
 
12
+ var _index = require("../../../index");
13
+
10
14
  var _myOrdersApi = require("../../../api/myOrdersApi");
11
15
 
12
16
  var useOrder = function useOrder(_ref) {
@@ -18,7 +22,7 @@ var useOrder = function useOrder(_ref) {
18
22
  var order = data || orderQuery.data;
19
23
 
20
24
  var result = _react["default"].useMemo(function () {
21
- var _order$shippings, _shipping$deliveries, _shipping$deliveries$, _order$shippingAddres, _order$shippingAddres2, _order$shippingAddres3, _order$shippingAddres4, _order$shippingAddres5, _order$shippingAddres6, _order$lineItemsCount;
25
+ var _order$shippings, _shipping$deliveries, _shipping$deliveries$, _order$shippingAddres, _order$shippingAddres2, _order$shippingAddres3, _order$shippingAddres4, _order$shippingAddres5, _order$shippingAddres6, _order$lineItemsCount, _order$customLineItem;
22
26
 
23
27
  var shipping = order == null ? void 0 : (_order$shippings = order.shippings) == null ? void 0 : _order$shippings[0];
24
28
  var parcels = shipping == null ? void 0 : (_shipping$deliveries = shipping.deliveries) == null ? void 0 : (_shipping$deliveries$ = _shipping$deliveries[0]) == null ? void 0 : _shipping$deliveries$.parcels;
@@ -30,10 +34,17 @@ var useOrder = function useOrder(_ref) {
30
34
  orderRefNumber: order == null ? void 0 : order.orderRefNumber,
31
35
  createdAt: order == null ? void 0 : order.createdAt,
32
36
  discountCodes: mapDiscountCodes(order == null ? void 0 : order.discountCodes),
37
+ customLineItems: order == null ? void 0 : (_order$customLineItem = order.customLineItems) == null ? void 0 : _order$customLineItem.map(function (customLineItem) {
38
+ return (0, _extends2["default"])({}, customLineItem, {
39
+ name: (0, _index.getTranslatableField)(customLineItem.name)
40
+ });
41
+ }),
42
+ shippingAddress: order == null ? void 0 : order.shippingAddress,
33
43
  shippingMethod: {
34
44
  isOffice: isShippingMethodOffice,
35
45
  isAddress: isShippingMethodOffice ? false : true
36
46
  },
47
+ billingAddress: order == null ? void 0 : order.billingAddress,
37
48
  trackingData: mapTrackingData(parcels)
38
49
  };
39
50
  return orderData;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/hooks/order-hooks/useOrder/index.ts"],"names":["useOrder","data","id","orderQuery","myOrdersApi","useGetById","order","result","React","useMemo","shipping","shippings","parcels","deliveries","isShippingMethodOffice","Boolean","shippingAddress","moduleData","address","office","orderData","lineItems","lineItemsCount","status","orderRefNumber","createdAt","discountCodes","mapDiscountCodes","shippingMethod","isOffice","isAddress","trackingData","mapTrackingData","map","parcel","courierName","provider","trackingId","trackingUrl","providerMeta","trackUrl","codes","codeNames","filter","code","discountCode","resource","name","value"],"mappings":";;;;;;;AAAA;;AASA;;AAsBO,IAAMA,QAAQ,GAAG,SAAXA,QAAW,OAMH;AAAA,MALnBC,IAKmB,QALnBA,IAKmB;AAAA,MAJnBC,EAImB,QAJnBA,EAImB;;AACnB,MAAMC,UAAU,GAAGC,yBAAYC,UAAZ,CAAuBH,EAAvB,CAAnB;;AAEA,MAAMI,KAAK,GAAGL,IAAI,IAAIE,UAAU,CAACF,IAAjC;;AAEA,MAAMM,MAAM,GAAGC,kBAAMC,OAAN,CAAc,YAAM;AAAA;;AACjC,QAAMC,QAAQ,GAAGJ,KAAH,wCAAGA,KAAK,CAAEK,SAAV,qBAAG,iBAAmB,CAAnB,CAAjB;AACA,QAAMC,OAAO,GAAGF,QAAH,4CAAGA,QAAQ,CAAEG,UAAb,8CAAG,qBAAuB,CAAvB,CAAH,qBAAG,sBAA2BD,OAA3C;AAEA,QAAME,sBAAsB,GAAGC,OAAO,CACpCT,KADoC,6CACpCA,KAAK,CAAEU,eAD6B,+CACpC,sBAAwBC,UADY,+CACpC,uBAAqC,CAArC,CADoC,+CACpC,uBAAyCA,UADL,+CACpC,uBAAqDC,OADjB,+CACpC,uBAA8DC,MAD1B,qBACpC,uBACID,OAFgC,CAAtC;AAKA,QAAME,SAAwB,GAAG;AAC/BC,MAAAA,SAAS,EAAEf,KAAF,oBAAEA,KAAK,CAAEe,SADa;AAE/BC,MAAAA,cAAc,2BAAEhB,KAAF,oBAAEA,KAAK,CAAEgB,cAAT,oCAA2B,CAFV;AAG/BC,MAAAA,MAAM,EAAEjB,KAAF,oBAAEA,KA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,SAAOmB,SAAP,oBAAOA,SAAS,CAAET,GAAX,CAAe,UAACW,IAAD,EAAU;AAC9B,WAAOA,IAAI,CAACC,YAAL,CAAkBC,QAAlB,CAA2BC,IAA3B,CAAgC,CAAhC,EAAmCC,KAA1C;AACD,GAFM,CAAP;AAGD","sourcesContent":["import React from 'react'\nimport {\n DiscountCodeInfoDTO,\n LineItemDTO,\n OrderDTO,\n OrderDTOStatusEnum,\n ShippingDeliveryParcelDTO,\n} from '@sentecacommerce/sdk'\n\nimport { myOrdersApi } from '../../../api/myOrdersApi'\n\ntype TrackingProp = {\n provider?: string\n trackingId?: string\n trackingUrl?: string\n}\n\ntype UseOrderProps = {\n lineItems?: LineItemDTO[]\n lineItemsCount: number\n createdAt?: number\n orderRefNumber?: string\n status?: OrderDTOStatusEnum\n discountCodes?: string[]\n shippingMethod: {\n isOffice: boolean\n isAddress: boolean\n }\n trackingData: TrackingProp[]\n}\n\nexport const useOrder = ({\n data,\n id,\n}: {\n data?: OrderDTO\n id?: string\n}): UseOrderProps => {\n const orderQuery = myOrdersApi.useGetById(id)\n\n const order = data || orderQuery.data\n\n const result = React.useMemo(() => {\n const shipping = order?.shippings?.[0]\n const parcels = shipping?.deliveries?.[0]?.parcels\n\n const isShippingMethodOffice = Boolean(\n order?.shippingAddress?.moduleData?.[0]?.moduleData?.address?.office\n ?.address\n )\n\n const orderData: UseOrderProps = {\n lineItems: order?.lineItems,\n lineItemsCount: order?.lineItemsCount ?? 0,\n status: order?.status,\n orderRefNumber: order?.orderRefNumber,\n createdAt: order?.createdAt,\n discountCodes: mapDiscountCodes(order?.discountCodes),\n\n shippingMethod: {\n isOffice: isShippingMethodOffice,\n isAddress: isShippingMethodOffice ? false : true,\n },\n\n trackingData: mapTrackingData(parcels),\n }\n return orderData\n }, [order])\n\n return result\n}\n\nfunction mapTrackingData(parcels?: ShippingDeliveryParcelDTO[]) {\n return (\n parcels?.map((parcel) => {\n return {\n courierName: parcel?.moduleData?.trackingData?.provider,\n trackingId: parcel?.moduleData?.trackingData?.trackingId,\n trackingUrl: parcel?.moduleData?.providerMeta?.trackUrl,\n }\n }) || []\n )\n}\n\nfunction mapDiscountCodes(codes?: DiscountCodeInfoDTO[]) {\n const codeNames = codes?.filter((code) => code.status !== 'NotValid')\n\n return codeNames?.map((code) => {\n return code.discountCode.resource.name[0].value\n })\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../../src/hooks/order-hooks/useOrder/index.ts"],"names":["useOrder","data","id","orderQuery","myOrdersApi","useGetById","order","result","React","useMemo","shipping","shippings","parcels","deliveries","isShippingMethodOffice","Boolean","shippingAddress","moduleData","address","office","orderData","lineItems","lineItemsCount","status","orderRefNumber","createdAt","discountCodes","mapDiscountCodes","customLineItems","map","customLineItem","name","shippingMethod","isOffice","isAddress","billingAddress","trackingData","mapTrackingData","parcel","courierName","provider","trackingId","trackingUrl","providerMeta","trackUrl","codes","codeNames","filter","code","discountCode","resource","value"],"mappings":";;;;;;;;;AAAA;;AAWA;;AACA;;AA6BO,IAAMA,QAAQ,GAAG,SAAXA,QAAW,OAMH;AAAA,MALnBC,IAKmB,QALnBA,IAKmB;AAAA,MAJnBC,EAImB,QAJnBA,EAImB;;AACnB,MAAMC,UAAU,GAAGC,yBAAYC,UAAZ,CAAuBH,EAAvB,CAAnB;;AAEA,MAAMI,KAAK,GAAGL,IAAI,IAAIE,UAAU,CAACF,IAAjC;;AAEA,MAAMM,MAAM,GAAGC,kBAAMC,OAAN,CAAc,YAAM;AAAA;;AACjC,QAAMC,QAAQ,GAAGJ,KAAH,wCAAGA,KAAK,CAAEK,SAAV,qBAAG,iBAAmB,CAAnB,CAAjB;AACA,QAAMC,OAAO,GAAGF,QAAH,4CAAGA,QAAQ,CAAEG,UAAb,8CAAG,qBAAuB,CAAvB,CAAH,qBAAG,sBAA2BD,OAA3C;AAEA,QAAME,sBAAsB,GAAGC,OAAO,CACpCT,KADoC,6CACpCA,KAAK,CAAEU,eAD6B,+CACpC,sBAAwBC,UADY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eAAT,CAAyBzB,OAAzB,EAAgE;AAC9D,SACE,CAAAA,OAAO,QAAP,YAAAA,OAAO,CAAEiB,GAAT,CAAa,UAACS,MAAD,EAAY;AAAA;;AACvB,WAAO;AACLC,MAAAA,WAAW,EAAED,MAAF,0CAAEA,MAAM,CAAErB,UAAV,8CAAE,mBAAoBmB,YAAtB,qBAAE,sBAAkCI,QAD1C;AAELC,MAAAA,UAAU,EAAEH,MAAF,2CAAEA,MAAM,CAAErB,UAAV,8CAAE,oBAAoBmB,YAAtB,qBAAE,sBAAkCK,UAFzC;AAGLC,MAAAA,WAAW,EAAEJ,MAAF,2CAAEA,MAAM,CAAErB,UAAV,8CAAE,oBAAoB0B,YAAtB,qBAAE,sBAAkCC;AAH1C,KAAP;AAKD,GAND,MAMM,EAPR;AASD;;AAED,SAASjB,gBAAT,CAA0BkB,KAA1B,EAAyD;AACvD,MAAMC,SAAS,GAAGD,KAAH,oBAAGA,KAAK,CAAEE,MAAP,CAAc,UAACC,IAAD;AAAA,WAAUA,IAAI,CAACzB,MAAL,KAAgB,UAA1B;AAAA,GAAd,CAAlB;AAEA,SAAOuB,SAAP,oBAAOA,SAAS,CAAEjB,GAAX,CAAe,UAACmB,IAAD,EAAU;AAC9B,WAAOA,IAAI,CAACC,YAAL,CAAkBC,QAAlB,CAA2BnB,IAA3B,CAAgC,CAAhC,EAAmCoB,KAA1C;AACD,GAFM,CAAP;AAGD","sourcesContent":["import React from 'react'\nimport {\n DiscountCodeInfoDTO,\n LineItemDTO,\n OrderDTO,\n OrderDTOStatusEnum,\n ShippingDeliveryParcelDTO,\n CustomLineItemDTO,\n AddressDTO,\n} from '@sentecacommerce/sdk'\n\nimport { getTranslatableField } from '../../../index'\nimport { myOrdersApi } from '../../../api/myOrdersApi'\n\ntype TrackingProp = {\n provider?: string\n trackingId?: string\n trackingUrl?: string\n}\n\nexport type MappedCustomLineItemDTO = CustomLineItemDTO & {\n name: string\n}\n\ntype UseOrderProps = {\n lineItems?: LineItemDTO[]\n lineItemsCount: number\n createdAt?: number\n orderRefNumber?: string\n status?: OrderDTOStatusEnum\n discountCodes?: string[]\n shippingMethod: {\n isOffice: boolean\n isAddress: boolean\n }\n trackingData: TrackingProp[]\n customLineItems?: MappedCustomLineItemDTO[]\n shippingAddress: AddressDTO\n billingAddress?: AddressDTO\n}\n\nexport const useOrder = ({\n data,\n id,\n}: {\n data?: OrderDTO\n id?: string\n}): UseOrderProps => {\n const orderQuery = myOrdersApi.useGetById(id)\n\n const order = data || orderQuery.data\n\n const result = React.useMemo(() => {\n const shipping = order?.shippings?.[0]\n const parcels = shipping?.deliveries?.[0]?.parcels\n\n const isShippingMethodOffice = Boolean(\n order?.shippingAddress?.moduleData?.[0]?.moduleData?.address?.office\n ?.address\n )\n\n const orderData: UseOrderProps = {\n lineItems: order?.lineItems,\n lineItemsCount: order?.lineItemsCount ?? 0,\n status: order?.status,\n orderRefNumber: order?.orderRefNumber,\n createdAt: order?.createdAt,\n discountCodes: mapDiscountCodes(order?.discountCodes),\n customLineItems: order?.customLineItems?.map((customLineItem) => {\n return {\n ...customLineItem,\n name: getTranslatableField(customLineItem.name),\n } as MappedCustomLineItemDTO\n }),\n shippingAddress: order?.shippingAddress as AddressDTO,\n\n shippingMethod: {\n isOffice: isShippingMethodOffice,\n isAddress: isShippingMethodOffice ? false : true,\n },\n billingAddress: order?.billingAddress,\n\n trackingData: mapTrackingData(parcels),\n }\n return orderData\n }, [order])\n\n return result\n}\n\nfunction mapTrackingData(parcels?: ShippingDeliveryParcelDTO[]) {\n return (\n parcels?.map((parcel) => {\n return {\n courierName: parcel?.moduleData?.trackingData?.provider,\n trackingId: parcel?.moduleData?.trackingData?.trackingId,\n trackingUrl: parcel?.moduleData?.providerMeta?.trackUrl,\n }\n }) || []\n )\n}\n\nfunction mapDiscountCodes(codes?: DiscountCodeInfoDTO[]) {\n const codeNames = codes?.filter((code) => code.status !== 'NotValid')\n\n return codeNames?.map((code) => {\n return code.discountCode.resource.name[0].value\n })\n}\n"],"file":"index.js"}
@@ -9,10 +9,6 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
 
10
10
  var _utils = require("../../utils");
11
11
 
12
- var _sdk = require("@sentecacommerce/sdk");
13
-
14
- exports.TermAggregationResult = _sdk.TermAggregationResult;
15
-
16
12
  var _router = require("next/router");
17
13
 
18
14
  var _react = require("react");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/hooks/useAggregateResult/index.ts"],"names":["byOrder","a","b","order","operatorMap","ranges","stats","terms","mapKey","r","type","key","from","to","filterByType","filters","filterName","includes","filter","useAggregateResult","aggregates","slug","predicate","query","router","transformedQuery","catalogApi","useAggregate","aggData","data","isLoading","isIdle","isFetching","result","sort","reduce","res","current","aggregationType","find","c","name","aggregationDefinition","split","selectedCount","results","acc","count","filterKey","selected","filterDefinition","concat","onClick","push","aggType","aggKey","aggOperator","label","component","items","clearAll","pathname"],"mappings":";;;;;;;;;AAAA;;AAIA;;;;AAQA;;AACA;;AAEA;;AAEA,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAACC,CAAD,EAASC,CAAT,EAAoB;AAClC,MAAID,CAAC,CAACE,KAAF,GAAUD,CAAC,CAACC,KAAhB,EAAuB,OAAO,CAAP;AAEvB,MAAIF,CAAC,CAACE,KAAF,GAAUD,CAAC,CAACC,KAAhB,EAAuB,OAAO,CAAC,CAAR;AAEvB,SAAO,CAAP;AACD,CAND;;AAoCA,IAAMC,WAAW,GAAG;AAClBC,EAAAA,MAAM,EAAE,OADU;AAElBC,EAAAA,KAAK,EAAE,OAFW;AAGlBC,EAAAA,KAAK,EAAE;AAHW,CAApB,C,CAMA;;AACA,IAAMC,MAAM,GAAG,SAATA,MAAS,CAACC,CAAD,EAASC,IAAT,EAAuB;AACpC,UAAQ,IAAR;AACE,SAAKA,IAAI,KAAK,OAAd;AACE,oBAAWD,CAAC,CAACE,GAAb;;AACF,SAAKD,IAAI,KAAK,QAAd;AACE,aAAUD,CAAC,CAACG,IAAZ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A,KAAK,EAAEd,OAHT;AAIED,QAAAA,aAAa,EAAbA,aAJF;AAKEgB,QAAAA,QAAQ,EAAE;AAAA,iBACRpC,MAAM,CAAC6B,IAAP,CAAY;AACVQ,YAAAA,QAAQ,EAAErC,MAAM,CAACqC,QADP;AAEVtC,YAAAA,KAAK,gCACAC,MAAM,CAACD,KADP;AAEHL,cAAAA,MAAM,EAAEJ,YAAY,CAACU,MAAM,CAACD,KAAP,CAAaL,MAAd,EAAsBjB,CAAC,CAACiD,gBAAxB;AAFjB;AAFK,WAAZ,CADQ;AAAA,SALZ;AAaExC,QAAAA,IAAI,EAAET,CAAC,CAACqC;AAbV,OADgB,CAAX,CAAP;AAiBD,KAhEY,EAgEV,EAhEU,CAAf;AAkEA,WAAOL,MAAP;AACD,GAtEY,EAsEV,CAACH,SAAD,EAAYF,OAAZ,EAAqBR,UAArB,EAAiCC,IAAjC,EAAuCX,IAAvC,CAtEU,CAAb;AAwEA,SAAO;AACLoB,IAAAA,SAAS,EAATA,SADK;AAELC,IAAAA,MAAM,EAANA,MAFK;AAGLF,IAAAA,IAAI,EAAJA,IAHK;AAILG,IAAAA,UAAU,EAAVA;AAJK,GAAP;AAMD,CAtGM","sourcesContent":["import {\n createAggregateQuery,\n generateQueryFromRouter,\n} from '../../utils'\nimport {\n TermAggregation,\n StatAggregation,\n RangeAggregation,\n TermAggregationResult,\n StatAggregationResult,\n RangeAggregationResult,\n} from '@sentecacommerce/sdk'\nimport { useRouter } from 'next/router'\nimport { useMemo } from 'react'\nimport { FiltersQuery } from '../../listing/types'\nimport { catalogApi } from '../../api/catalogApi'\n\nconst byOrder = (a: any, b: any) => {\n if (a.order > b.order) return 1\n\n if (a.order < b.order) return -1\n\n return 0\n}\n\ntype AggregationType = TermAggregation | StatAggregation | RangeAggregation\n\nexport type AggregationTypes = 'ranges' | 'terms' | 'stats'\n\ntype AggregationDTO =\n | TermAggregationResult\n | StatAggregationResult\n | RangeAggregationResult\n\nexport { TermAggregationResult }\n\nexport type FormattedAggregationResultType = {\n onClick: () => void\n selected: boolean\n data: AggregationDTO\n label?: string\n aggregationType?: AggregationTypes\n}\n\nexport type AggregateResultType = {\n name: string\n component: string\n items: FormattedAggregationResultType[]\n type: AggregationTypes\n selectedCount: number\n clearAll: () => void\n}\n\nconst operatorMap = {\n ranges: 'range',\n stats: 'range',\n terms: 'eq',\n}\n\n// TODO: Additional mappers later\nconst mapKey = (r: any, type: any) => {\n switch (true) {\n case type === 'terms':\n return `\"${r.key}\"`\n case type === 'ranges':\n return `${r.from},${r.to}`\n default:\n return r.key\n }\n}\n\nconst filterByType = (\n filters: string | string[] | undefined,\n filterName: string\n) => {\n if (!filters) return\n\n if (typeof filters === 'string') {\n if (filters.includes(filterName)) return\n\n return filters\n }\n\n return filters.filter((filter) => !filter.includes(filterName))\n}\n\nexport const useAggregateResult = (\n type: 'category' | 'brand' | 'search' | 'view',\n aggregates: any[],\n slug: string,\n predicate: string,\n query: FiltersQuery\n) => {\n const router = useRouter()\n\n const transformedQuery = generateQueryFromRouter(query)\n\n const {\n data: aggData,\n isLoading,\n isIdle,\n isFetching,\n } = catalogApi.useAggregate(\n type,\n aggregates,\n slug,\n predicate,\n transformedQuery\n )\n\n const data = useMemo(() => {\n if (isLoading || !aggData) return null\n\n const result = aggregates\n .sort(byOrder)\n .reduce<AggregateResultType[]>((res, a) => {\n const current = aggData[a.aggregationType].find(\n (c: AggregationType) =>\n c.name === a.aggregationDefinition.split(':')[0]\n )\n let selectedCount = 0\n const results = current.results.reduce<\n FormattedAggregationResultType[]\n >((acc: FormattedAggregationResultType[], r: AggregationDTO) => {\n if (r.count === 0) return acc\n const filterKey = mapKey(r, a.aggregationType)\n\n const selected = router.query?.filter?.includes(\n `${a.filterDefinition};${\n operatorMap[a.aggregationType]\n };${filterKey}`\n )\n ? true\n : false\n\n if (selected) selectedCount++\n\n return acc.concat([\n {\n data: r,\n selected,\n onClick: () => {\n router.push(\n createAggregateQuery(\n type,\n slug,\n {\n aggType: a.filterDefinition,\n aggKey: filterKey,\n aggOperator: operatorMap[a.aggregationType],\n },\n selected,\n router\n )\n )\n },\n },\n ])\n }, [])\n\n return res.concat([\n {\n name: a.label,\n component: a.component,\n items: results,\n selectedCount,\n clearAll: () =>\n router.push({\n pathname: router.pathname,\n query: {\n ...router.query,\n filter: filterByType(router.query.filter, a.filterDefinition),\n },\n }),\n type: a.aggregationType as AggregationTypes,\n },\n ])\n }, [])\n\n return result\n }, [isLoading, aggData, aggregates, slug, type])\n\n return {\n isLoading,\n isIdle,\n data,\n isFetching,\n }\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/hooks/useAggregateResult/index.ts"],"names":["byOrder","a","b","order","operatorMap","ranges","stats","terms","mapKey","r","type","key","from","to","filterByType","filters","filterName","includes","filter","useAggregateResult","aggregates","slug","predicate","query","router","transformedQuery","catalogApi","useAggregate","aggData","data","isLoading","isIdle","isFetching","result","sort","reduce","res","current","aggregationType","find","c","name","aggregationDefinition","split","selectedCount","results","acc","count","filterKey","selected","filterDefinition","concat","onClick","push","aggType","aggKey","aggOperator","label","component","items","clearAll","pathname"],"mappings":";;;;;;;;;AAAA;;AAYA;;AACA;;AAEA;;AAEA,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAACC,CAAD,EAASC,CAAT,EAAoB;AAClC,MAAID,CAAC,CAACE,KAAF,GAAUD,CAAC,CAACC,KAAhB,EAAuB,OAAO,CAAP;AAEvB,MAAIF,CAAC,CAACE,KAAF,GAAUD,CAAC,CAACC,KAAhB,EAAuB,OAAO,CAAC,CAAR;AAEvB,SAAO,CAAP;AACD,CAND;;AAoCA,IAAMC,WAAW,GAAG;AAClBC,EAAAA,MAAM,EAAE,OADU;AAElBC,EAAAA,KAAK,EAAE,OAFW;AAGlBC,EAAAA,KAAK,EAAE;AAHW,CAApB,C,CAMA;;AACA,IAAMC,MAAM,GAAG,SAATA,MAAS,CAACC,CAAD,EAASC,IAAT,EAAuB;AACpC,UAAQ,IAAR;AACE,SAAKA,I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ChB;AACEV,QAAAA,IAAI,EAAExC,CAAC,CAACwD,KADV;AAEEC,QAAAA,SAAS,EAAEzD,CAAC,CAACyD,SAFf;AAGEC,QAAAA,KAAK,EAAEd,OAHT;AAIED,QAAAA,aAAa,EAAbA,aAJF;AAKEgB,QAAAA,QAAQ,EAAE;AAAA,iBACRpC,MAAM,CAAC6B,IAAP,CAAY;AACVQ,YAAAA,QAAQ,EAAErC,MAAM,CAACqC,QADP;AAEVtC,YAAAA,KAAK,gCACAC,MAAM,CAACD,KADP;AAEHL,cAAAA,MAAM,EAAEJ,YAAY,CAACU,MAAM,CAACD,KAAP,CAAaL,MAAd,EAAsBjB,CAAC,CAACiD,gBAAxB;AAFjB;AAFK,WAAZ,CADQ;AAAA,SALZ;AAaExC,QAAAA,IAAI,EAAET,CAAC,CAACqC;AAbV,OADgB,CAAX,CAAP;AAiBD,KAhEY,EAgEV,EAhEU,CAAf;AAkEA,WAAOL,MAAP;AACD,GAtEY,EAsEV,CAACH,SAAD,EAAYF,OAAZ,EAAqBR,UAArB,EAAiCC,IAAjC,EAAuCX,IAAvC,CAtEU,CAAb;AAwEA,SAAO;AACLoB,IAAAA,SAAS,EAATA,SADK;AAELC,IAAAA,MAAM,EAANA,MAFK;AAGLF,IAAAA,IAAI,EAAJA,IAHK;AAILG,IAAAA,UAAU,EAAVA;AAJK,GAAP;AAMD,CAtGM","sourcesContent":["import {\n createAggregateQuery,\n generateQueryFromRouter,\n} from '../../utils'\nimport type {\n TermAggregation,\n StatAggregation,\n RangeAggregation,\n TermAggregationResult,\n StatAggregationResult,\n RangeAggregationResult,\n} from '@sentecacommerce/sdk'\nimport { useRouter } from 'next/router'\nimport { useMemo } from 'react'\nimport { FiltersQuery } from '../../listing/types'\nimport { catalogApi } from '../../api/catalogApi'\n\nconst byOrder = (a: any, b: any) => {\n if (a.order > b.order) return 1\n\n if (a.order < b.order) return -1\n\n return 0\n}\n\ntype AggregationType = TermAggregation | StatAggregation | RangeAggregation\n\nexport type AggregationTypes = 'ranges' | 'terms' | 'stats'\n\ntype AggregationDTO =\n | TermAggregationResult\n | StatAggregationResult\n | RangeAggregationResult\n\nexport type { TermAggregationResult }\n\nexport type FormattedAggregationResultType = {\n onClick: () => void\n selected: boolean\n data: AggregationDTO\n label?: string\n aggregationType?: AggregationTypes\n}\n\nexport type AggregateResultType = {\n name: string\n component: string\n items: FormattedAggregationResultType[]\n type: AggregationTypes\n selectedCount: number\n clearAll: () => void\n}\n\nconst operatorMap = {\n ranges: 'range',\n stats: 'range',\n terms: 'eq',\n}\n\n// TODO: Additional mappers later\nconst mapKey = (r: any, type: any) => {\n switch (true) {\n case type === 'terms':\n return `\"${r.key}\"`\n case type === 'ranges':\n return `${r.from},${r.to}`\n default:\n return r.key\n }\n}\n\nconst filterByType = (\n filters: string | string[] | undefined,\n filterName: string\n) => {\n if (!filters) return\n\n if (typeof filters === 'string') {\n if (filters.includes(filterName)) return\n\n return filters\n }\n\n return filters.filter((filter) => !filter.includes(filterName))\n}\n\nexport const useAggregateResult = (\n type: 'category' | 'brand' | 'search' | 'view',\n aggregates: any[],\n slug: string,\n predicate: string,\n query: FiltersQuery\n) => {\n const router = useRouter()\n\n const transformedQuery = generateQueryFromRouter(query)\n\n const {\n data: aggData,\n isLoading,\n isIdle,\n isFetching,\n } = catalogApi.useAggregate(\n type,\n aggregates,\n slug,\n predicate,\n transformedQuery\n )\n\n const data = useMemo(() => {\n if (isLoading || !aggData) return null\n\n const result = aggregates\n .sort(byOrder)\n .reduce<AggregateResultType[]>((res, a) => {\n const current = aggData[a.aggregationType].find(\n (c: AggregationType) =>\n c.name === a.aggregationDefinition.split(':')[0]\n )\n let selectedCount = 0\n const results = current.results.reduce<\n FormattedAggregationResultType[]\n >((acc: FormattedAggregationResultType[], r: AggregationDTO) => {\n if (r.count === 0) return acc\n const filterKey = mapKey(r, a.aggregationType)\n\n const selected = router.query?.filter?.includes(\n `${a.filterDefinition};${\n operatorMap[a.aggregationType]\n };${filterKey}`\n )\n ? true\n : false\n\n if (selected) selectedCount++\n\n return acc.concat([\n {\n data: r,\n selected,\n onClick: () => {\n router.push(\n createAggregateQuery(\n type,\n slug,\n {\n aggType: a.filterDefinition,\n aggKey: filterKey,\n aggOperator: operatorMap[a.aggregationType],\n },\n selected,\n router\n )\n )\n },\n },\n ])\n }, [])\n\n return res.concat([\n {\n name: a.label,\n component: a.component,\n items: results,\n selectedCount,\n clearAll: () =>\n router.push({\n pathname: router.pathname,\n query: {\n ...router.query,\n filter: filterByType(router.query.filter, a.filterDefinition),\n },\n }),\n type: a.aggregationType as AggregationTypes,\n },\n ])\n }, [])\n\n return result\n }, [isLoading, aggData, aggregates, slug, type])\n\n return {\n isLoading,\n isIdle,\n data,\n isFetching,\n }\n}\n"],"file":"index.js"}
@@ -9,11 +9,16 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
 
10
10
  var _react = require("react");
11
11
 
12
- var useCheckoutShippingModule = function useCheckoutShippingModule(orderQuery) {
12
+ var useCheckoutShippingModule = function useCheckoutShippingModule(orderQuery, isEnabled) {
13
+ if (isEnabled === void 0) {
14
+ isEnabled = true;
15
+ }
16
+
13
17
  var cartData = orderQuery.data;
14
18
  return (0, _react.useMemo)(function () {
15
19
  var _cartData$shippings;
16
20
 
21
+ if (!isEnabled) return;
17
22
  var shipping = cartData == null ? void 0 : (_cartData$shippings = cartData.shippings) == null ? void 0 : _cartData$shippings[0];
18
23
  return {
19
24
  moduleKey: shipping == null ? void 0 : shipping.moduleKey,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/hooks/useCheckoutShippingModule/index.tsx"],"names":["useCheckoutShippingModule","orderQuery","cartData","data","shipping","shippings","moduleKey","moduleData","methodKey","moduleMethodKey"],"mappings":";;;;;;;;;AACA;;AAGO,IAAMA,yBAAyB,GAAG,SAA5BA,yBAA4B,CACvCC,UADuC,EAEpB;AAAA,MACLC,QADK,GACQD,UADR,CACXE,IADW;AAGnB,SAAO,oBAAQ,YAAM;AAAA;;AACnB,QAAMC,QAAQ,GAAGF,QAAH,2CAAGA,QAAQ,CAAEG,SAAb,qBAAG,oBAAsB,CAAtB,CAAjB;AAEA,WAAO;AACLC,MAAAA,SAAS,EAAEF,QAAF,oBAAEA,QAAQ,CAAEE,SADhB;AAELC,MAAAA,UAAU,gCACLH,QADK,oBACLA,QAAQ,CAAEG,UADL;AAERC,QAAAA,SAAS,EAAEJ,QAAF,oBAAEA,QAAQ,CAAEK;AAFb;AAFL,KAAP;AAOD,GAVM,EAUJ,CAACP,QAAD,CAVI,CAAP;AAWD,CAhBM","sourcesContent":["import { OrderDTO } from '@sentecacommerce/sdk'\nimport { useMemo } from 'react'\nimport { QueryResult } from 'react-query'\n\nexport const useCheckoutShippingModule = (\n orderQuery: QueryResult<OrderDTO, unknown>\n): ShippingModule => {\n const { data: cartData } = orderQuery\n\n return useMemo(() => {\n const shipping = cartData?.shippings?.[0]\n\n return {\n moduleKey: shipping?.moduleKey,\n moduleData: {\n ...shipping?.moduleData,\n methodKey: shipping?.moduleMethodKey,\n },\n }\n }, [cartData])\n}\n\nexport type ShippingModule = {\n moduleKey?: string\n moduleData?: any\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/hooks/useCheckoutShippingModule/index.tsx"],"names":["useCheckoutShippingModule","orderQuery","isEnabled","cartData","data","shipping","shippings","moduleKey","moduleData","methodKey","moduleMethodKey"],"mappings":";;;;;;;;;AACA;;AAGO,IAAMA,yBAAyB,GAAG,SAA5BA,yBAA4B,CACvCC,UADuC,EAEvCC,SAFuC,EAGpB;AAAA,MADnBA,SACmB;AADnBA,IAAAA,SACmB,GADP,IACO;AAAA;;AAAA,MACLC,QADK,GACQF,UADR,CACXG,IADW;AAGnB,SAAO,oBAAQ,YAAM;AAAA;;AACnB,QAAI,CAACF,SAAL,EAAgB;AAEhB,QAAMG,QAAQ,GAAGF,QAAH,2CAAGA,QAAQ,CAAEG,SAAb,qBAAG,oBAAsB,CAAtB,CAAjB;AAEA,WAAO;AACLC,MAAAA,SAAS,EAAEF,QAAF,oBAAEA,QAAQ,CAAEE,SADhB;AAELC,MAAAA,UAAU,gCACLH,QADK,oBACLA,QAAQ,CAAEG,UADL;AAERC,QAAAA,SAAS,EAAEJ,QAAF,oBAAEA,QAAQ,CAAEK;AAFb;AAFL,KAAP;AAOD,GAZM,EAYJ,CAACP,QAAD,CAZI,CAAP;AAaD,CAnBM","sourcesContent":["import { OrderDTO } from '@sentecacommerce/sdk'\nimport { useMemo } from 'react'\nimport { QueryResult } from 'react-query'\n\nexport const useCheckoutShippingModule = (\n orderQuery: QueryResult<OrderDTO, unknown>,\n isEnabled = true\n): ShippingModule => {\n const { data: cartData } = orderQuery\n\n return useMemo(() => {\n if (!isEnabled) return\n\n const shipping = cartData?.shippings?.[0]\n\n return {\n moduleKey: shipping?.moduleKey,\n moduleData: {\n ...shipping?.moduleData,\n methodKey: shipping?.moduleMethodKey,\n },\n }\n }, [cartData])\n}\n\nexport type ShippingModule =\n | {\n moduleKey?: string\n moduleData?: any\n }\n | undefined\n"],"file":"index.js"}
package/dist/cjs/index.js CHANGED
@@ -162,14 +162,6 @@ Object.keys(_myShippingsEvropatApi).forEach(function (key) {
162
162
  exports[key] = _myShippingsEvropatApi[key];
163
163
  });
164
164
 
165
- var _cmsContentApi = require("./api/cmsContentApi");
166
-
167
- Object.keys(_cmsContentApi).forEach(function (key) {
168
- if (key === "default" || key === "__esModule") return;
169
- if (key in exports && exports[key] === _cmsContentApi[key]) return;
170
- exports[key] = _cmsContentApi[key];
171
- });
172
-
173
165
  var _citiesApi = require("./api/citiesApi");
174
166
 
175
167
  Object.keys(_citiesApi).forEach(function (key) {
@@ -386,14 +378,6 @@ Object.keys(_wishlistHooks).forEach(function (key) {
386
378
  exports[key] = _wishlistHooks[key];
387
379
  });
388
380
 
389
- var _cmsContentHooks = require("./hooks/cms-content-hooks");
390
-
391
- Object.keys(_cmsContentHooks).forEach(function (key) {
392
- if (key === "default" || key === "__esModule") return;
393
- if (key in exports && exports[key] === _cmsContentHooks[key]) return;
394
- exports[key] = _cmsContentHooks[key];
395
- });
396
-
397
381
  var _labels = require("./hooks/labels");
398
382
 
399
383
  Object.keys(_labels).forEach(function (key) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAIA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAIA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AA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A;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './dto'\n\n// API\n// export * from './api/myCart'\nexport * from './api/productsApi'\nexport * from './api/pagesApi'\nexport * from './api/usersApi'\nexport * from './api/profileApi'\nexport * from './api/wishlistApi'\nexport * from './api/addressesApi'\nexport * from './api/consentsApi'\nexport * from './api/catalogApi'\nexport * from './api/categoriesApi'\nexport * from './api/brandsApi'\nexport * from './api/viewsApi'\nexport * from './api/notificationsApi'\nexport * from './api/companiesApi'\nexport * from './api/vouchersApi'\nexport * from './api/myCartApi'\nexport * from './api/myShippingsSpeedyApi'\nexport * from './api/myOrdersApi'\nexport * from './api/myShippingsEcontApi'\nexport * from './api/myShippingsEvropatApi'\nexport * from './api/cmsContentApi'\nexport * from './api/citiesApi'\nexport * from './api/searchHistoryApi'\n\nexport * from './api/walletApi'\nexport * from './api/myShippingsPickupFromStoreAPI'\n\nexport * from './api/myPaymentsBoricaApi'\n// Components\n\n// Contexts\nexport * from './contexts/Strings'\nexport * from './contexts/CheckoutForm'\nexport * from './contexts/CheckoutForm/utils'\nexport * from './contexts/CustomProductProvider'\n\n// Components\nexport * from './components'\n\n// Hooks\nexport * from './hooks/useCarousel'\nexport * from './hooks/useZoom'\nexport * from './hooks/useProduct'\nexport * from './hooks/useCatalogResult'\nexport * from './hooks/useCopyToClipboard'\nexport * from './hooks/useVouchers'\nexport * from './hooks/usePromoCode'\nexport * from './hooks/useCheckoutDelivery'\nexport * from './hooks/useCheckoutPayment'\nexport * from './hooks/useCheckoutShippingAddress'\nexport * from './hooks/useCheckoutBillingAddress'\nexport * from './hooks/useCheckoutSubmit'\nexport * from './hooks/useCheckoutDiscountCode'\nexport * from './hooks/wishlist-hooks/useWishlist'\nexport * from './hooks/useCheckoutSummary'\nexport * from './hooks/usePrice'\nexport * from './hooks/wishlist-hooks'\nexport * from './hooks/cms-content-hooks'\nexport * from './hooks/labels'\nexport * from './hooks/checkout-hooks'\n\nexport * from './hooks/basket-hooks/useBasketTotalCount'\nexport * from './hooks/useIsBasketWithFixedShippingPrice'\nexport * from './hooks/useProductCarousel'\nexport * from './hooks/useSearchbar'\nexport * from './hooks/useSEOAggregateResult'\nexport * from './hooks/useCatalogPredicates'\nexport * from './hooks/useAggregateResult'\nexport * from './hooks/useSelectedFilters'\nexport * from './hooks/useAllSelectedFilters'\nexport * from './hooks/useClearAllFilters'\nexport * from './hooks/useCheckoutPickupFromStore'\nexport * from './hooks/useCheckoutShippingModule'\nexport * from './hooks/useLoyaltyProgram'\nexport * from './hooks/useCategoryTree'\nexport * from './hooks/useWallet'\nexport * from './hooks/useSizesReducer'\nexport * from './hooks/useAvailability'\n\nexport * from './hooks/cities-hooks'\n\nexport * from './hooks/useLineItem'\nexport * from './hooks/usePrefetchProduct'\nexport * from './hooks/ui-hooks'\nexport * from './hooks/order-hooks'\nexport * from './hooks/basket-hooks'\nexport * from './hooks/useAddressList'\n// export * from './hooks/third-party'\n\nexport * from './hooks/useConfig'\nexport * from './hooks/useShippingAddress'\nexport * from './hooks/useBillingAddress'\nexport * from './hooks/useContactForm'\n\nexport * from './hooks/user-hooks'\nexport * from './hooks/error-handling'\n\nexport * from './hooks/profile-hooks'\nexport * from './hooks/addresses-hooks'\nexport * from './hooks/companies-hooks'\nexport * from './hooks/subscriptions-hooks'\nexport * from './hooks/useRouterRedirect'\nexport * from './hooks/useProgressBar'\nexport * from './hooks/useCatalogDiscounts'\nexport * from './hooks/useLocalRating'\n\n// Utils\nexport * from './utils'\nexport * from './types'\n\n// SEO\nexport * from './seo'\n\n// Analytics\nexport * from './analytics/initiateCheckout'\nexport * from './analytics/viewContent'\n\nexport * from './analytics/Releva'\nexport * from './analytics/Pixel'\n\n// WebView\nexport * from './webview'\n\n// Carousel\nexport * from 'embla-carousel/react'\n\n// CMS\nexport * from './cms'\n\n// API v2\nexport * from './config'\nexport * from './api.v2/core'\n\nexport * from './api.v2/core/misc'\n\nexport * from './ssr/'\nexport * from './listing'\nexport * from './brands'\nexport * from './navigation'\nexport * from './GDPR'\n\n// User\nexport * from './user'\n\n// UI Components and hooks\nexport * from './ui'\n\nexport * from './wishlist'\n\n// Build Scripts \nexport * from './build'\n\n// Order\nexport * from './order'\n\n// Product\nexport * from './product'\n\n// Checkout\nexport * from './checkout'\n\n// PostCSS and related configuration\nexport * from './postcss'"],"file":"index.js"}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAIA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AA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AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './dto'\n\n// API\n// export * from './api/myCart'\nexport * from './api/productsApi'\nexport * from './api/pagesApi'\nexport * from './api/usersApi'\nexport * from './api/profileApi'\nexport * from './api/wishlistApi'\nexport * from './api/addressesApi'\nexport * from './api/consentsApi'\nexport * from './api/catalogApi'\nexport * from './api/categoriesApi'\nexport * from './api/brandsApi'\nexport * from './api/viewsApi'\nexport * from './api/notificationsApi'\nexport * from './api/companiesApi'\nexport * from './api/vouchersApi'\nexport * from './api/myCartApi'\nexport * from './api/myShippingsSpeedyApi'\nexport * from './api/myOrdersApi'\nexport * from './api/myShippingsEcontApi'\nexport * from './api/myShippingsEvropatApi'\nexport * from './api/citiesApi'\nexport * from './api/searchHistoryApi'\n\nexport * from './api/walletApi'\nexport * from './api/myShippingsPickupFromStoreAPI'\n\nexport * from './api/myPaymentsBoricaApi'\n// Components\n\n// Contexts\nexport * from './contexts/Strings'\nexport * from './contexts/CheckoutForm'\nexport * from './contexts/CheckoutForm/utils'\nexport * from './contexts/CustomProductProvider'\n\n// Components\nexport * from './components'\n\n// Hooks\nexport * from './hooks/useCarousel'\nexport * from './hooks/useZoom'\nexport * from './hooks/useProduct'\nexport * from './hooks/useCatalogResult'\nexport * from './hooks/useCopyToClipboard'\nexport * from './hooks/useVouchers'\nexport * from './hooks/usePromoCode'\nexport * from './hooks/useCheckoutDelivery'\nexport * from './hooks/useCheckoutPayment'\nexport * from './hooks/useCheckoutShippingAddress'\nexport * from './hooks/useCheckoutBillingAddress'\nexport * from './hooks/useCheckoutSubmit'\nexport * from './hooks/useCheckoutDiscountCode'\nexport * from './hooks/wishlist-hooks/useWishlist'\nexport * from './hooks/useCheckoutSummary'\nexport * from './hooks/usePrice'\nexport * from './hooks/wishlist-hooks'\nexport * from './hooks/labels'\nexport * from './hooks/checkout-hooks'\n\nexport * from './hooks/basket-hooks/useBasketTotalCount'\nexport * from './hooks/useIsBasketWithFixedShippingPrice'\nexport * from './hooks/useProductCarousel'\nexport * from './hooks/useSearchbar'\nexport * from './hooks/useSEOAggregateResult'\nexport * from './hooks/useCatalogPredicates'\nexport * from './hooks/useAggregateResult'\nexport * from './hooks/useSelectedFilters'\nexport * from './hooks/useAllSelectedFilters'\nexport * from './hooks/useClearAllFilters'\nexport * from './hooks/useCheckoutPickupFromStore'\nexport * from './hooks/useCheckoutShippingModule'\nexport * from './hooks/useLoyaltyProgram'\nexport * from './hooks/useCategoryTree'\nexport * from './hooks/useWallet'\nexport * from './hooks/useSizesReducer'\nexport * from './hooks/useAvailability'\n\nexport * from './hooks/cities-hooks'\n\nexport * from './hooks/useLineItem'\nexport * from './hooks/usePrefetchProduct'\nexport * from './hooks/ui-hooks'\nexport * from './hooks/order-hooks'\nexport * from './hooks/basket-hooks'\nexport * from './hooks/useAddressList'\n// export * from './hooks/third-party'\n\nexport * from './hooks/useConfig'\nexport * from './hooks/useShippingAddress'\nexport * from './hooks/useBillingAddress'\nexport * from './hooks/useContactForm'\n\nexport * from './hooks/user-hooks'\nexport * from './hooks/error-handling'\n\nexport * from './hooks/profile-hooks'\nexport * from './hooks/addresses-hooks'\nexport * from './hooks/companies-hooks'\nexport * from './hooks/subscriptions-hooks'\nexport * from './hooks/useRouterRedirect'\nexport * from './hooks/useProgressBar'\nexport * from './hooks/useCatalogDiscounts'\nexport * from './hooks/useLocalRating'\n\n// Utils\nexport * from './utils'\nexport * from './types'\n\n// SEO\nexport * from './seo'\n\n// Analytics\nexport * from './analytics/initiateCheckout'\nexport * from './analytics/viewContent'\n\nexport * from './analytics/Releva'\nexport * from './analytics/Pixel'\n\n// WebView\nexport * from './webview'\n\n// Carousel\nexport * from 'embla-carousel/react'\n\n// CMS\nexport * from './cms'\n\n// API v2\nexport * from './config'\nexport * from './api.v2/core'\n\nexport * from './api.v2/core/misc'\n\nexport * from './ssr/'\nexport * from './listing'\nexport * from './brands'\nexport * from './navigation'\nexport * from './GDPR'\n\n// User\nexport * from './user'\n\n// UI Components and hooks\nexport * from './ui'\n\nexport * from './wishlist'\n\n// Build Scripts \nexport * from './build'\n\n// Order\nexport * from './order'\n\n// Product\nexport * from './product'\n\n// Checkout\nexport * from './checkout'\n\n// PostCSS and related configuration\nexport * from './postcss'"],"file":"index.js"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.getCanonicalUrl = void 0;
5
+
6
+ var getCanonicalUrl = function getCanonicalUrl(context, localeData, redirectTo) {
7
+ var _req$url;
8
+
9
+ var req = context.req;
10
+ var reqHost = req.headers['senteca-host'];
11
+ var reqSSL = req.headers['senteca-ssl']; // Format domain (remove http and the slash at the end)
12
+
13
+ var domain = (localeData == null ? void 0 : localeData.domain) || '';
14
+ domain = domain[domain.length - 1] === '/' ? domain.slice(0, domain.length - 1) : domain;
15
+ if (!reqHost || !reqSSL || !domain) return;
16
+ var areWeSecured = reqSSL === 'https';
17
+
18
+ var _ref = ((_req$url = req.url) == null ? void 0 : _req$url.split('?')) || ['/'],
19
+ currentPath = _ref[0],
20
+ queryString = _ref[1];
21
+
22
+ if (!redirectTo && areWeSecured && (domain === reqHost || domain === reqHost + "/" + localeData.locale)) return;
23
+ return "https://" + domain + (redirectTo || currentPath) + (queryString ? "?" + queryString : '');
24
+ };
25
+
26
+ exports.getCanonicalUrl = getCanonicalUrl;
27
+ //# sourceMappingURL=getCanonicalUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/seo/api/ssr/getCanonicalUrl.ts"],"names":["getCanonicalUrl","context","localeData","redirectTo","req","reqHost","headers","reqSSL","domain","length","slice","areWeSecured","url","split","currentPath","queryString","locale"],"mappings":";;;;;AAGO,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAC7BC,OAD6B,EAE7BC,UAF6B,EAG7BC,UAH6B,EAIN;AAAA;;AAAA,MACfC,GADe,GACPH,OADO,CACfG,GADe;AAGvB,MAAMC,OAAO,GAAGD,GAAG,CAACE,OAAJ,CAAY,cAAZ,CAAhB;AACA,MAAMC,MAAM,GAAGH,GAAG,CAACE,OAAJ,CAAY,aAAZ,CAAf,CAJuB,CAMvB;;AACA,MAAIE,MAAM,GAAG,CAAAN,UAAU,QAAV,YAAAA,UAAU,CAAEM,MAAZ,KAAsB,EAAnC;AAEAA,EAAAA,MAAM,GACJA,MAAM,CAACA,MAAM,CAACC,MAAP,GAAgB,CAAjB,CAAN,KAA8B,GAA9B,GACID,MAAM,CAACE,KAAP,CAAa,CAAb,EAAgBF,MAAM,CAACC,MAAP,GAAgB,CAAhC,CADJ,GAEID,MAHN;AAKA,MAAI,CAACH,OAAD,IAAY,CAACE,MAAb,IAAuB,CAACC,MAA5B,EAAoC;AAEpC,MAAMG,YAAY,GAAGJ,MAAM,KAAK,OAAhC;;AAhBuB,aAkBY,aAAAH,GAAG,CAACQ,GAAJ,8BAASC,KAAT,CAAe,GAAf,MAAuB,CAAC,GAAD,CAlBnC;AAAA,MAkBhBC,WAlBgB;AAAA,MAkBHC,WAlBG;;AAoBvB,MACE,CAACZ,UAAD,IACAQ,YADA,KAECH,MAAM,KAAKH,OAAX,IAAsBG,MAAM,KAAQH,OAAR,SAAmBH,UAAU,CAACc,MAF3D,CADF,EAKE;AAEF,sBAAkBR,MAAlB,IAA2BL,UAAU,IAAIW,WAAzC,KACEC,WAAW,SAAOA,WAAP,GAAuB,EADpC;AAGD,CAlCM","sourcesContent":["import { GetServerSidePropsContext } from 'next'\nimport { LocaleData } from '../../..'\n\nexport const getCanonicalUrl = (\n context: GetServerSidePropsContext,\n localeData: LocaleData,\n redirectTo?: string\n): string | undefined => {\n const { req } = context\n\n const reqHost = req.headers['senteca-host']\n const reqSSL = req.headers['senteca-ssl']\n\n // Format domain (remove http and the slash at the end)\n let domain = localeData?.domain || ''\n\n domain =\n domain[domain.length - 1] === '/'\n ? domain.slice(0, domain.length - 1)\n : domain\n\n if (!reqHost || !reqSSL || !domain) return\n\n const areWeSecured = reqSSL === 'https'\n\n const [currentPath, queryString] = req.url?.split('?') || ['/']\n\n if (\n !redirectTo &&\n areWeSecured &&\n (domain === reqHost || domain === `${reqHost}/${localeData.locale}`)\n )\n return\n\n return `https://${domain}${redirectTo || currentPath}${\n queryString ? `?${queryString}` : ''\n }`\n}\n"],"file":"getCanonicalUrl.js"}
@@ -17,4 +17,12 @@ Object.keys(_fetchRedirectByFrom).forEach(function (key) {
17
17
  if (key in exports && exports[key] === _fetchRedirectByFrom[key]) return;
18
18
  exports[key] = _fetchRedirectByFrom[key];
19
19
  });
20
+
21
+ var _getCanonicalUrl = require("./getCanonicalUrl");
22
+
23
+ Object.keys(_getCanonicalUrl).forEach(function (key) {
24
+ if (key === "default" || key === "__esModule") return;
25
+ if (key in exports && exports[key] === _getCanonicalUrl[key]) return;
26
+ exports[key] = _getCanonicalUrl[key];
27
+ });
20
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/seo/api/ssr/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './fetchSitemaps'\nexport * from './fetchRedirectByFrom'"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../../src/seo/api/ssr/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './fetchSitemaps'\nexport * from './fetchRedirectByFrom'\nexport * from './getCanonicalUrl'"],"file":"index.js"}
@@ -17,4 +17,12 @@ Object.keys(_queries).forEach(function (key) {
17
17
  if (key in exports && exports[key] === _queries[key]) return;
18
18
  exports[key] = _queries[key];
19
19
  });
20
+
21
+ var _utils = require("./utils");
22
+
23
+ Object.keys(_utils).forEach(function (key) {
24
+ if (key === "default" || key === "__esModule") return;
25
+ if (key in exports && exports[key] === _utils[key]) return;
26
+ exports[key] = _utils[key];
27
+ });
20
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/user/api/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './mutations'\nexport * from './queries'\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/user/api/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './mutations'\nexport * from './queries'\nexport * from './utils'\n"],"file":"index.js"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.generateAnonymousToken = void 0;
7
+
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+
12
+ var _sdk = require("@sentecacommerce/sdk");
13
+
14
+ var _ = require("../../../");
15
+
16
+ var generateAnonymousToken = /*#__PURE__*/function () {
17
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
18
+ return _regenerator["default"].wrap(function _callee$(_context) {
19
+ while (1) {
20
+ switch (_context.prev = _context.next) {
21
+ case 0:
22
+ if (!_sdk.HttpClient.defaultConfig) {
23
+ (0, _.prefetchSDKConfig)({
24
+ interfaceKey: process.env.DEFAULT_INTERFACE_KEY,
25
+ storeKey: process.env.STORE
26
+ });
27
+ }
28
+
29
+ return _context.abrupt("return", (0, _sdk.AuthCreateAnonymousToken)({}, {
30
+ grantType: _sdk.TokenRequestDTOGrantTypeEnum.Implicit,
31
+ anonymousId: (0, _.generateGuid)()
32
+ }));
33
+
34
+ case 2:
35
+ case "end":
36
+ return _context.stop();
37
+ }
38
+ }
39
+ }, _callee);
40
+ }));
41
+
42
+ return function generateAnonymousToken() {
43
+ return _ref.apply(this, arguments);
44
+ };
45
+ }();
46
+
47
+ exports.generateAnonymousToken = generateAnonymousToken;
48
+ //# sourceMappingURL=generateAnonymousToken.js.map