@sentecacommerce-theme/lib 0.12.33 → 0.12.37

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 (52) hide show
  1. package/dist/cjs/brands/api/ssr/prefetchBrands.js +2 -1
  2. package/dist/cjs/brands/api/ssr/prefetchBrands.js.map +1 -1
  3. package/dist/cjs/checkout/contexts/BoricaResponseContext.js.map +1 -1
  4. package/dist/cjs/checkout/contexts/PaypalResponseContext.js +29 -0
  5. package/dist/cjs/checkout/contexts/PaypalResponseContext.js.map +1 -0
  6. package/dist/cjs/checkout/contexts/index.js +8 -0
  7. package/dist/cjs/checkout/contexts/index.js.map +1 -1
  8. package/dist/cjs/checkout/hooks/index.js.map +1 -1
  9. package/dist/cjs/checkout/hooks/useVerifyBoricaResponse.js.map +1 -1
  10. package/dist/cjs/checkout/ssr/capturePaypalOrder.js +36 -0
  11. package/dist/cjs/checkout/ssr/capturePaypalOrder.js.map +1 -0
  12. package/dist/cjs/checkout/ssr/index.js +8 -0
  13. package/dist/cjs/checkout/ssr/index.js.map +1 -1
  14. package/dist/cjs/contexts/CheckoutForm/index.js +9 -0
  15. package/dist/cjs/contexts/CheckoutForm/index.js.map +1 -1
  16. package/dist/cjs/hooks/useCheckoutSubmit/index.js +26 -7
  17. package/dist/cjs/hooks/useCheckoutSubmit/index.js.map +1 -1
  18. package/dist/cjs/seo/api/ssr/getCanonicalUrl.js +1 -3
  19. package/dist/cjs/seo/api/ssr/getCanonicalUrl.js.map +1 -1
  20. package/dist/cjs/user/api/utils/processLoginPayload.js +11 -0
  21. package/dist/cjs/user/api/utils/processLoginPayload.js.map +1 -1
  22. package/dist/cjs/utils/prefetchSDKConfig.js.map +1 -1
  23. package/dist/esm/brands/api/ssr/prefetchBrands.js +1 -0
  24. package/dist/esm/brands/api/ssr/prefetchBrands.js.map +1 -1
  25. package/dist/esm/checkout/contexts/BoricaResponseContext.js.map +1 -1
  26. package/dist/esm/checkout/contexts/PaypalResponseContext.js +17 -0
  27. package/dist/esm/checkout/contexts/PaypalResponseContext.js.map +1 -0
  28. package/dist/esm/checkout/contexts/index.js +1 -0
  29. package/dist/esm/checkout/contexts/index.js.map +1 -1
  30. package/dist/esm/checkout/hooks/index.js.map +1 -1
  31. package/dist/esm/checkout/hooks/useVerifyBoricaResponse.js.map +1 -1
  32. package/dist/esm/checkout/ssr/capturePaypalOrder.js +12 -0
  33. package/dist/esm/checkout/ssr/capturePaypalOrder.js.map +1 -0
  34. package/dist/esm/checkout/ssr/index.js +1 -0
  35. package/dist/esm/checkout/ssr/index.js.map +1 -1
  36. package/dist/esm/contexts/CheckoutForm/index.js +10 -1
  37. package/dist/esm/contexts/CheckoutForm/index.js.map +1 -1
  38. package/dist/esm/hooks/useCheckoutSubmit/index.js +6 -1
  39. package/dist/esm/hooks/useCheckoutSubmit/index.js.map +1 -1
  40. package/dist/esm/seo/api/ssr/getCanonicalUrl.js +1 -3
  41. package/dist/esm/seo/api/ssr/getCanonicalUrl.js.map +1 -1
  42. package/dist/esm/user/api/utils/processLoginPayload.js +12 -1
  43. package/dist/esm/user/api/utils/processLoginPayload.js.map +1 -1
  44. package/dist/esm/utils/prefetchSDKConfig.js.map +1 -1
  45. package/dist/types/brands/api/ssr/prefetchBrands.d.ts +1 -1
  46. package/dist/types/checkout/contexts/BoricaResponseContext.d.ts +2 -2
  47. package/dist/types/checkout/contexts/PaypalResponseContext.d.ts +6 -0
  48. package/dist/types/checkout/contexts/index.d.ts +1 -0
  49. package/dist/types/checkout/ssr/capturePaypalOrder.d.ts +2 -0
  50. package/dist/types/checkout/ssr/index.d.ts +1 -0
  51. package/dist/types/hooks/useCheckoutSubmit/index.d.ts +2 -1
  52. package/package.json +4 -4
@@ -40,8 +40,9 @@ function _prefetchBrands() {
40
40
  refetchOnReconnect: false,
41
41
  refetchOnWindowFocus: false
42
42
  });
43
+ return _context.abrupt("return", data);
43
44
 
44
- case 4:
45
+ case 5:
45
46
  case "end":
46
47
  return _context.stop();
47
48
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/brands/api/ssr/prefetchBrands.ts"],"names":["prefetchBrands","queryCache","terms","stats","ranges","data","setQueryData","BrandsQueryEnum","useAllBrandsQuery","staleTime","retry","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus"],"mappings":";;;;;;;;;;;AACA;;AAEA;;SAEsBA,c;;;;;kGAAf,iBACLC,UADK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAGc,2BAAiB;AAClCC,cAAAA,KAAK,EAAE,QAD2B;AAElCC,cAAAA,KAAK,EAAE,EAF2B;AAGlCC,cAAAA,MAAM,EAAE;AAH0B,aAAjB,CAHd;;AAAA;AAGCC,YAAAA,IAHD;AASLJ,YAAAA,UAAU,CAACK,YAAX,CAAwBC,sBAAgBC,iBAAxC,EAA2DH,IAA3D,EAAiE;AAC/DI,cAAAA,SAAS,EAAE,KADoD;AAE/DC,cAAAA,KAAK,EAAE,KAFwD;AAG/DC,cAAAA,cAAc,EAAE,KAH+C;AAI/DC,cAAAA,kBAAkB,EAAE,KAJ2C;AAK/DC,cAAAA,oBAAoB,EAAE;AALyC,aAAjE;;AATK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G","sourcesContent":["import type { QueryCache } from 'react-query'\nimport { CatalogAggregate } from '@sentecacommerce/sdk'\n\nimport { BrandsQueryEnum } from '../queries/keys'\n\nexport async function prefetchBrands(\n queryCache: QueryCache,\n) {\n const data = await CatalogAggregate({\n terms: 'brands',\n stats: '',\n ranges: '',\n })\n\n queryCache.setQueryData(BrandsQueryEnum.useAllBrandsQuery, data, {\n staleTime: 30000,\n retry: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n })\n}\n"],"file":"prefetchBrands.js"}
1
+ {"version":3,"sources":["../../../../../src/brands/api/ssr/prefetchBrands.ts"],"names":["prefetchBrands","queryCache","terms","stats","ranges","data","setQueryData","BrandsQueryEnum","useAllBrandsQuery","staleTime","retry","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus"],"mappings":";;;;;;;;;;;AACA;;AAEA;;SAEsBA,c;;;;;kGAAf,iBAA8BC,UAA9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBACc,2BAAiB;AAClCC,cAAAA,KAAK,EAAE,QAD2B;AAElCC,cAAAA,KAAK,EAAE,EAF2B;AAGlCC,cAAAA,MAAM,EAAE;AAH0B,aAAjB,CADd;;AAAA;AACCC,YAAAA,IADD;AAOLJ,YAAAA,UAAU,CAACK,YAAX,CAAwBC,sBAAgBC,iBAAxC,EAA2DH,IAA3D,EAAiE;AAC/DI,cAAAA,SAAS,EAAE,KADoD;AAE/DC,cAAAA,KAAK,EAAE,KAFwD;AAG/DC,cAAAA,cAAc,EAAE,KAH+C;AAI/DC,cAAAA,kBAAkB,EAAE,KAJ2C;AAK/DC,cAAAA,oBAAoB,EAAE;AALyC,aAAjE;AAPK,6CAeER,IAfF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G","sourcesContent":["import type { QueryCache } from 'react-query'\nimport { CatalogAggregate } from '@sentecacommerce/sdk'\n\nimport { BrandsQueryEnum } from '../queries/keys'\n\nexport async function prefetchBrands(queryCache: QueryCache) {\n const data = await CatalogAggregate({\n terms: 'brands',\n stats: '',\n ranges: '',\n })\n\n queryCache.setQueryData(BrandsQueryEnum.useAllBrandsQuery, data, {\n staleTime: 30000,\n retry: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n })\n\n return data\n}\n"],"file":"prefetchBrands.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/checkout/contexts/BoricaResponseContext.tsx"],"names":["BoricaResponseContext","BoricaResponseProvider","children","response","useBoricaResponse","context","Error"],"mappings":";;;;;;;AAAA;;AAGA,IAAMA,qBAAqB,gBAAG,0BAC5B,EAD4B,CAA9B;;AAIO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB,OAMhC;AAAA,MALJC,QAKI,QALJA,QAKI;AAAA,MAJJC,QAII,QAJJA,QAII;AACJ,sBACE,gCAAC,qBAAD,CAAuB,QAAvB;AAAgC,IAAA,KAAK,EAAEA;AAAvC,KACGD,QADH,CADF;AAKD,CAZM;;;;AAcA,IAAME,iBAAiB,GAAG,SAApBA,iBAAoB,GAAM;AACrC,MAAMC,OAAO,GAAG,uBAAWL,qBAAX,CAAhB;AAEA,MAAI,CAACK,OAAL,EACE,MAAM,IAAIC,KAAJ,CACJ,8DADI,CAAN;AAIF,SAAOD,OAAP;AACD,CATM","sourcesContent":["import React, { createContext, useContext } from 'react'\nimport type { BoricaVerifyPaymentDataRequest as Reponse } from '@sentecacommerce/sdk'\n\nconst BoricaResponseContext = createContext<Reponse>(\n {} as any\n)\n\nexport const BoricaResponseProvider = ({\n children,\n response,\n}: {\n children: any\n response: Reponse\n}) => {\n return (\n <BoricaResponseContext.Provider value={response}>\n {children}\n </BoricaResponseContext.Provider>\n )\n}\n\nexport const useBoricaResponse = () => {\n const context = useContext(BoricaResponseContext)\n\n if (!context)\n throw new Error(\n 'useBoricaResponse hook must be within BoricaResponseProvider'\n )\n\n return context\n}\n"],"file":"BoricaResponseContext.js"}
1
+ {"version":3,"sources":["../../../../src/checkout/contexts/BoricaResponseContext.tsx"],"names":["BoricaResponseContext","BoricaResponseProvider","children","response","useBoricaResponse","context","Error"],"mappings":";;;;;;;AAAA;;AAGA,IAAMA,qBAAqB,gBAAG,0BAA4B,EAA5B,CAA9B;;AAEO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB,OAMhC;AAAA,MALJC,QAKI,QALJA,QAKI;AAAA,MAJJC,QAII,QAJJA,QAII;AACJ,sBACE,gCAAC,qBAAD,CAAuB,QAAvB;AAAgC,IAAA,KAAK,EAAEA;AAAvC,KACGD,QADH,CADF;AAKD,CAZM;;;;AAcA,IAAME,iBAAiB,GAAG,SAApBA,iBAAoB,GAAM;AACrC,MAAMC,OAAO,GAAG,uBAAWL,qBAAX,CAAhB;AAEA,MAAI,CAACK,OAAL,EACE,MAAM,IAAIC,KAAJ,CACJ,8DADI,CAAN;AAIF,SAAOD,OAAP;AACD,CATM","sourcesContent":["import React, { createContext, useContext } from 'react'\nimport type { BoricaVerifyPaymentDataRequest as Reponse } from '@sentecacommerce/sdk'\n\nconst BoricaResponseContext = createContext<Reponse | {}>({})\n\nexport const BoricaResponseProvider = ({\n children,\n response,\n}: {\n children: any\n response: Reponse | {}\n}) => {\n return (\n <BoricaResponseContext.Provider value={response}>\n {children}\n </BoricaResponseContext.Provider>\n )\n}\n\nexport const useBoricaResponse = () => {\n const context = useContext(BoricaResponseContext)\n\n if (!context)\n throw new Error(\n 'useBoricaResponse hook must be within BoricaResponseProvider'\n )\n\n return context\n}\n"],"file":"BoricaResponseContext.js"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
+
5
+ exports.__esModule = true;
6
+ exports.usePaypalResponse = exports.PaypalResponseProvider = void 0;
7
+
8
+ var _react = _interopRequireWildcard(require("react"));
9
+
10
+ var PaypalResponseContext = /*#__PURE__*/(0, _react.createContext)({});
11
+
12
+ var PaypalResponseProvider = function PaypalResponseProvider(_ref) {
13
+ var children = _ref.children,
14
+ response = _ref.response;
15
+ return /*#__PURE__*/_react["default"].createElement(PaypalResponseContext.Provider, {
16
+ value: response
17
+ }, children);
18
+ };
19
+
20
+ exports.PaypalResponseProvider = PaypalResponseProvider;
21
+
22
+ var usePaypalResponse = function usePaypalResponse() {
23
+ var context = (0, _react.useContext)(PaypalResponseContext);
24
+ if (!context) throw new Error('usePaypalResponse hook must be within PaypalResponseProvider');
25
+ return context;
26
+ };
27
+
28
+ exports.usePaypalResponse = usePaypalResponse;
29
+ //# sourceMappingURL=PaypalResponseContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/checkout/contexts/PaypalResponseContext.tsx"],"names":["PaypalResponseContext","PaypalResponseProvider","children","response","usePaypalResponse","context","Error"],"mappings":";;;;;;;AAAA;;AAGA,IAAMA,qBAAqB,gBAAG,0BAA6B,EAA7B,CAA9B;;AAEO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB,OAMhC;AAAA,MALJC,QAKI,QALJA,QAKI;AAAA,MAJJC,QAII,QAJJA,QAII;AACJ,sBACE,gCAAC,qBAAD,CAAuB,QAAvB;AAAgC,IAAA,KAAK,EAAEA;AAAvC,KACGD,QADH,CADF;AAKD,CAZM;;;;AAcA,IAAME,iBAAiB,GAAG,SAApBA,iBAAoB,GAAM;AACrC,MAAMC,OAAO,GAAG,uBAAWL,qBAAX,CAAhB;AAEA,MAAI,CAACK,OAAL,EACE,MAAM,IAAIC,KAAJ,CACJ,8DADI,CAAN;AAIF,SAAOD,OAAP;AACD,CATM","sourcesContent":["import React, { createContext, useContext } from 'react'\nimport type { PaypalVerifyPaymentDataResponseDTO as Response } from '@sentecacommerce/sdk'\n\nconst PaypalResponseContext = createContext<Response | {}>({})\n\nexport const PaypalResponseProvider = ({\n children,\n response,\n}: {\n children: any\n response: Response | {}\n}) => {\n return (\n <PaypalResponseContext.Provider value={response}>\n {children}\n </PaypalResponseContext.Provider>\n )\n}\n\nexport const usePaypalResponse = () => {\n const context = useContext(PaypalResponseContext)\n\n if (!context)\n throw new Error(\n 'usePaypalResponse hook must be within PaypalResponseProvider'\n )\n\n return context\n}\n"],"file":"PaypalResponseContext.js"}
@@ -9,4 +9,12 @@ Object.keys(_BoricaResponseContext).forEach(function (key) {
9
9
  if (key in exports && exports[key] === _BoricaResponseContext[key]) return;
10
10
  exports[key] = _BoricaResponseContext[key];
11
11
  });
12
+
13
+ var _PaypalResponseContext = require("./PaypalResponseContext");
14
+
15
+ Object.keys(_PaypalResponseContext).forEach(function (key) {
16
+ if (key === "default" || key === "__esModule") return;
17
+ if (key in exports && exports[key] === _PaypalResponseContext[key]) return;
18
+ exports[key] = _PaypalResponseContext[key];
19
+ });
12
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/checkout/contexts/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './BoricaResponseContext'"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/checkout/contexts/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './BoricaResponseContext'\nexport * from './PaypalResponseContext'\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/checkout/hooks/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './useVerifyBoricaResponse'"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/checkout/hooks/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './useVerifyBoricaResponse'\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/checkout/hooks/useVerifyBoricaResponse.ts"],"names":["useVerifyBoricaResponse","res"],"mappings":";;;;;AAAA;;AAEO,IAAMA,uBAAuB,GAAG,SAA1BA,uBAA0B,GAAM;AAC3C,MAAMC,GAAG,GAAG,0BAAZ;AAEA,SAAO,oCAA6BA,GAA7B,CAAP;AACD,CAJM","sourcesContent":["import { useBoricaResponse, useVerifyBoricaResponseQuery } from '..'\n\nexport const useVerifyBoricaResponse = () => {\n const res = useBoricaResponse();\n\n return useVerifyBoricaResponseQuery(res)\n}\n"],"file":"useVerifyBoricaResponse.js"}
1
+ {"version":3,"sources":["../../../../src/checkout/hooks/useVerifyBoricaResponse.ts"],"names":["useVerifyBoricaResponse","res"],"mappings":";;;;;AACA;;AAEO,IAAMA,uBAAuB,GAAG,SAA1BA,uBAA0B,GAAM;AAC3C,MAAMC,GAAG,GAAG,0BAAZ;AACA,SAAO,oCAA6BA,GAA7B,CAAP;AACD,CAHM","sourcesContent":["import { BoricaVerifyPaymentDataRequest } from '@sentecacommerce/sdk'\nimport { useBoricaResponse, useVerifyBoricaResponseQuery } from '..'\n\nexport const useVerifyBoricaResponse = () => {\n const res = useBoricaResponse()\n return useVerifyBoricaResponseQuery(res as BoricaVerifyPaymentDataRequest)\n}\n"],"file":"useVerifyBoricaResponse.js"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.capturePaypalOrder = 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 capturePaypalOrder = /*#__PURE__*/function () {
15
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(res) {
16
+ return _regenerator["default"].wrap(function _callee$(_context) {
17
+ while (1) {
18
+ switch (_context.prev = _context.next) {
19
+ case 0:
20
+ return _context.abrupt("return", (0, _sdk.MyPaymentsPaypalCaptureOrder)(res));
21
+
22
+ case 1:
23
+ case "end":
24
+ return _context.stop();
25
+ }
26
+ }
27
+ }, _callee);
28
+ }));
29
+
30
+ return function capturePaypalOrder(_x) {
31
+ return _ref.apply(this, arguments);
32
+ };
33
+ }();
34
+
35
+ exports.capturePaypalOrder = capturePaypalOrder;
36
+ //# sourceMappingURL=capturePaypalOrder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/checkout/ssr/capturePaypalOrder.ts"],"names":["capturePaypalOrder","res"],"mappings":";;;;;;;;;;;AAAA;;AAGO,IAAMA,kBAAkB;AAAA,2FAAG,iBAAOC,GAAP;AAAA;AAAA;AAAA;AAAA;AAAA,6CACzB,uCAAaA,GAAb,CADyB;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAAH;;AAAA,kBAAlBD,kBAAkB;AAAA;AAAA;AAAA,GAAxB","sourcesContent":["import { MyPaymentsPaypalCaptureOrder as captureOrder } from '@sentecacommerce/sdk'\nimport { PaypalCaptureRequestDTO } from '@sentecacommerce/sdk'\n\nexport const capturePaypalOrder = async (res: PaypalCaptureRequestDTO) => {\n return captureOrder(res)\n}\n"],"file":"capturePaypalOrder.js"}
@@ -9,4 +9,12 @@ Object.keys(_verifyBoricaResponse).forEach(function (key) {
9
9
  if (key in exports && exports[key] === _verifyBoricaResponse[key]) return;
10
10
  exports[key] = _verifyBoricaResponse[key];
11
11
  });
12
+
13
+ var _capturePaypalOrder = require("./capturePaypalOrder");
14
+
15
+ Object.keys(_capturePaypalOrder).forEach(function (key) {
16
+ if (key === "default" || key === "__esModule") return;
17
+ if (key in exports && exports[key] === _capturePaypalOrder[key]) return;
18
+ exports[key] = _capturePaypalOrder[key];
19
+ });
12
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/checkout/ssr/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './verifyBoricaResponse'"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/checkout/ssr/index.ts"],"names":[],"mappings":";;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './verifyBoricaResponse'\nexport * from './capturePaypalOrder'\n"],"file":"index.js"}
@@ -188,8 +188,17 @@ function CheckoutFormContextProvider(_ref) {
188
188
  }, redirectTimeout);
189
189
  };
190
190
 
191
+ var onBeforePaypalRedirect = function onBeforePaypalRedirect(data) {
192
+ onBeforeRedirect == null ? void 0 : onBeforeRedirect();
193
+ setIsRedirecting(true);
194
+ setTimeout(function () {
195
+ window.location.replace(data.redirectUrl);
196
+ }, redirectTimeout);
197
+ };
198
+
191
199
  var _useCheckoutSubmit = (0, _useCheckoutSubmit2.useCheckoutSubmit)({
192
200
  onBeforeBoricaRedirect: onBeforeBoricaRedirect,
201
+ onBeforePaypalRedirect: onBeforePaypalRedirect,
193
202
  onSuccess: onSuccess,
194
203
  onError: function onError(errors) {
195
204
  updateServerErrors(errors);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/contexts/CheckoutForm/index.tsx"],"names":["CheckoutFormContext","CheckoutFormContextProvider","children","defaultStep","errorLabels","enableSavedAddressList","withPersistBeforePageLeave","shippingValidations","defaultShippingValidations","validateBillingAddress","genericBillingAddressValidation","enableSaveBillingAddress","enableSavedBillingAddressList","countryCode","enableSaveAddress","autofillShippingPersonalData","onSubmit","paymentEnabledOnStep","getPaymentMethodsWhenShippingMethodIsSelected","shippingEnabledOnStep","billingEnabledOnStep","customState","initialCustomState","redirectTimeout","onBeforeRedirect","onSuccess","onError","isBoricaInDevMode","withPixelMeta","requiredFieldsOnShippingStep","requiredFieldsOnBillingAddressStep","enableNoShippingMethodMode","orderQuery","myCartApi","useGet","boricaData","setBoricaData","step","setStep","isRedirecting","setIsRedirecting","fieldsWithError","serverErrors","setServerErrors","collectFieldsWithError","error","push","handleStepChange","newStep","window","scrollTo","updateServerErrors","errors","formattedErrors","reduce","data","code","response","internalError","isAuthenticated","isShippingEnabled","userQuery","usersApi","enabled","shippingState","Boolean","validations","requiredFields","mod","getIsPaymentMethodsEnabled","moduleKey","moduleData","methodKey","paymentState","billingState","withSavedBillingAddressList","requiredFieldsOnShipping","onBeforeBoricaRedirect","setTimeout","withMeta","handleCheckoutSubmit","scrollToFirstError","interval","setInterval","errorElement","top","clearInterval","handleSubmit","e","preventDefault","Promise","all","persistShippingAddress","persistBillingAddress","isShippingValid","isValid","setIsShippingSubmitting","updateIsSubmitting","isBillingValid","setIsBillingSubmitting","isPaymentValid","setIsPaymentSubmitting","updateStep","saveOrder","shippingAddress","state","errorRef","errorFields","CheckoutFormStepsEnum","useCheckoutFormStep","context","Error","currentStep","useCheckoutFormOrder","useCheckoutFormErrorLabels","useCheckoutFormServerErrors","useCheckoutFormBillingState","useCheckoutFormShippingState","useCheckoutErrorFields","useCheckoutFormPaymentState"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AAaA;;AACA;;AAQA;;AACA;;AAEA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AAEO,IAAMA,mBAAmB,gBAAG,0BACjC,EADiC,CAA5B;;;AAMA,SAASC,2BAAT,OAmCG;AAAA,MAlCRC,QAkCQ,QAlCRA,QAkCQ;AAAA,MAjCRC,WAiCQ,QAjCRA,WAiCQ;AAAA,MAhCRC,WAgCQ,QAhCRA,WAgCQ;AAAA,MA/BRC,sBA+BQ,QA/BRA,sBA+BQ;AAAA,MA9BRC,0BA8BQ,QA9BRA,0BA8BQ;AAAA,mCA7BRC,mBA6BQ;AAAA,MA7BRA,mBA6BQ,sCA7BcC,iCA6Bd;AAAA,mCA5BRC,sBA4BQ;AAAA,MA5BRA,sBA4BQ,sCA5BiBC,sCA4BjB;AAAA,MA3BRC,wBA2BQ,QA3BRA,wBA2BQ;AAAA,MA1BRC,6BA0BQ,QA1BRA,6BA0BQ;AAAA,MAzBRC,WAyBQ,QAzBRA,WAyBQ;AAAA,MAxBRC,iBAwBQ,QAxBRA,iBAwBQ;AAAA,MAvBRC,4BAuBQ,QAvBRA,4BAuBQ;AAAA,MAtBRC,QAsBQ,QAtBRA,QAsBQ;AAAA,MApBRC,oBAoBQ,QApBRA,oBAoBQ;AAAA,MAnBRC,6CAmBQ,QAnBRA,6CAmBQ;AAAA,MAlBRC,qBAkBQ,QAlBRA,qBAkBQ;AAAA,MAjBRC,oBAiBQ,QAjBRA,oBAiBQ;AAAA,8BAfRC,WAeQ;AAAA,MAfKC,kBAeL,iCAf0B,EAe1B;AAAA,kCAdRC,eAcQ;AAAA,MAdRA,eAcQ,qCAdU,GAcV;AAAA,MAbRC,gBAaQ,QAbRA,gBAaQ;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J,0EADI,CAAN;AAGD;;AAED,SAAO;AACLJ,IAAAA,WAAW,EAAEG,OAAO,CAACH,WADhB;AAELD,IAAAA,QAAQ,EAAEI,OAAO,CAACJ;AAFb,GAAP;AAID,CAbM;;;;AAeA,IAAMa,2BAA2B,GAAG,SAA9BA,2BAA8B,GAAM;AAC/C,MAAMT,OAAO,GAAG,uBAAW9G,mBAAX,CAAhB;;AAEA,MAAI,CAAC8G,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,+EADI,CAAN;AAGD;;AAED,SAAOD,OAAO,CAACrC,YAAf;AACD,CAVM","sourcesContent":["import React, {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n} from 'react'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n AddressDTO,\n} from '@sentecacommerce/sdk'\nimport { MutateFunction, QueryResult } from 'react-query'\nimport { myCartApi } from '../../api/myCartApi'\nimport {\n useBilling,\n UseBillingResultType,\n usePayment,\n UsePaymentResultType,\n useShipping,\n UseShippingResultType,\n} from './hooks'\nimport { useIsAuthenticated } from '../../user/hooks'\nimport { useCheckoutSubmit } from '../../hooks/useCheckoutSubmit'\n\nimport {\n ShippingValidationsType,\n defaultShippingValidations,\n genericBillingAddressValidation,\n BillingAddressValidationType,\n} from './utils'\nimport { usersApi } from '../../api/usersApi'\nimport { useCheckoutShippingModule } from '../../hooks/useCheckoutShippingModule'\nimport { BoricaRedirect, CheckoutFormCustomStateProvider } from './Components'\nimport { useScrollTo } from '../../hooks/ui-hooks'\nimport { getElementOffset } from '../../utils/getElementOffset'\n\nexport const CheckoutFormContext = createContext<CheckoutFormContextType>(\n {} as any\n)\n\nexport type CheckoutCustomState = {}\n\nexport function CheckoutFormContextProvider({\n children,\n defaultStep,\n errorLabels,\n enableSavedAddressList,\n withPersistBeforePageLeave,\n shippingValidations = defaultShippingValidations,\n validateBillingAddress = genericBillingAddressValidation,\n enableSaveBillingAddress,\n enableSavedBillingAddressList,\n countryCode,\n enableSaveAddress,\n autofillShippingPersonalData,\n onSubmit,\n\n paymentEnabledOnStep,\n getPaymentMethodsWhenShippingMethodIsSelected,\n shippingEnabledOnStep,\n billingEnabledOnStep,\n\n customState: initialCustomState = {},\n redirectTimeout = 420,\n onBeforeRedirect,\n onSuccess,\n onError,\n isBoricaInDevMode,\n withPixelMeta = false,\n requiredFieldsOnShippingStep = [\n 'firstName',\n 'lastName',\n 'email',\n 'phoneNumber',\n ],\n requiredFieldsOnBillingAddressStep = ['city', 'postalCode', 'streetName'],\n enableNoShippingMethodMode = false,\n}: Props) {\n const orderQuery = myCartApi.useGet()\n const [\n boricaData,\n setBoricaData,\n ] = useState<BoricaGeneratePaymentDataResponse | null>(null)\n\n const [step, setStep] = useState<CheckoutFormStepsEnum>(defaultStep)\n const [isRedirecting, setIsRedirecting] = useState(false)\n\n const fieldsWithError: HTMLElement[] = []\n\n const [serverErrors, setServerErrors] = useState<ServerErrors>(null)\n\n const collectFieldsWithError = (error: HTMLElement) => {\n fieldsWithError.push(error)\n }\n\n const handleStepChange = useCallback((newStep: CheckoutFormStepsEnum) => {\n window.scrollTo(0, 0)\n\n setStep(newStep)\n }, [])\n\n const updateServerErrors = useCallback((errors: any[]) => {\n // Example Error\n // [{\n // code: \"OutOfStock\"\n // message: \"Some of the ordered line items are out of stock at the time of placing the order.\"\n // responses: {\n // availableQuantity: 1\n // sku: \"200000095849\"\n // status: \"unavailable\"\n // }\n // }]\n const formattedErrors = errors?.reduce?.(\n (data: ServerErrors, error: any) => {\n return {\n ...data,\n [error?.code || 'internal']: error?.response,\n }\n },\n {}\n )\n setServerErrors(formattedErrors || { internalError: errors })\n }, [])\n\n const { isAuthenticated } = useIsAuthenticated()\n\n const isShippingEnabled = shippingEnabledOnStep === step\n\n const userQuery = usersApi.useGet(\n {},\n { enabled: isShippingEnabled && autofillShippingPersonalData }\n )\n\n const shippingState = useShipping({\n errorLabels,\n orderQuery,\n enableSavedAddressList: Boolean(isAuthenticated && enableSavedAddressList),\n enableSaveAddress: Boolean(isAuthenticated && enableSaveAddress),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n validations: shippingValidations,\n autofillShippingPersonalData: Boolean(\n isAuthenticated && autofillShippingPersonalData\n ),\n userQuery,\n enabled: isShippingEnabled,\n countryCode,\n requiredFields: requiredFieldsOnShippingStep,\n enableNoShippingMethodMode,\n })\n const mod = useCheckoutShippingModule(orderQuery, !enableNoShippingMethodMode)\n\n const getIsPaymentMethodsEnabled = () => {\n if (paymentEnabledOnStep) {\n return paymentEnabledOnStep === step\n }\n\n if (\n !enableNoShippingMethodMode &&\n getPaymentMethodsWhenShippingMethodIsSelected\n ) {\n return Boolean(mod?.moduleKey && mod?.moduleData.methodKey)\n }\n\n return false\n }\n\n const paymentState = usePayment({\n errorLabels,\n orderQuery,\n enabled: getIsPaymentMethodsEnabled(),\n })\n\n const billingState = useBilling({\n errorLabels,\n orderQuery,\n validateBillingAddress,\n enableSaveBillingAddress: Boolean(\n isAuthenticated && enableSaveBillingAddress\n ),\n withSavedBillingAddressList: Boolean(\n isAuthenticated && enableSavedBillingAddressList\n ),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n countryCode,\n enabled: billingEnabledOnStep === step,\n requiredFields: requiredFieldsOnBillingAddressStep,\n requiredFieldsOnShipping: requiredFieldsOnShippingStep,\n })\n\n const onBeforeBoricaRedirect = (data: BoricaGeneratePaymentDataResponse) => {\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setBoricaData(data)\n }, redirectTimeout)\n }\n\n const { handleCheckoutSubmit } = useCheckoutSubmit({\n onBeforeBoricaRedirect,\n onSuccess,\n onError: (errors: any) => {\n updateServerErrors(errors)\n onError(errors)\n },\n withMeta: withPixelMeta,\n })\n\n const { scrollTo } = useScrollTo(fieldsWithError[0], 0)\n\n const scrollToFirstError = () => {\n const interval = setInterval(() => {\n const errorElement = fieldsWithError[0]\n if (!errorElement) return\n\n scrollTo(getElementOffset(errorElement).top - 100)\n clearInterval(interval)\n }, 50)\n\n setTimeout(() => {\n clearInterval(interval)\n }, 1000)\n }\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n\n await Promise.all([\n shippingState.persistShippingAddress(),\n billingState.persistBillingAddress(),\n ]).catch(() => {})\n\n onSubmit({\n isShippingValid: shippingState.isValid,\n setIsShippingSubmitting: shippingState.updateIsSubmitting,\n isBillingValid: billingState.isValid,\n setIsBillingSubmitting: billingState.updateIsSubmitting,\n isPaymentValid: paymentState.isValid,\n setIsPaymentSubmitting: paymentState.updateIsSubmitting,\n step,\n updateStep: setStep,\n saveOrder: handleCheckoutSubmit,\n updateServerErrors,\n scrollToFirstError,\n shippingState,\n shippingAddress: shippingState.data,\n })\n }\n\n const state = {\n setStep: handleStepChange,\n step,\n orderQuery,\n serverErrors,\n updateServerErrors,\n errorLabels,\n shippingState,\n paymentState,\n billingState,\n errorRef: collectFieldsWithError,\n errorFields: fieldsWithError,\n }\n\n return (\n <CheckoutFormContext.Provider value={state}>\n <CheckoutFormCustomStateProvider initialCustomState={initialCustomState}>\n <>\n <form noValidate onSubmit={handleSubmit}>\n {children}\n </form>\n {!!boricaData && (\n <BoricaRedirect\n isInDevMode={isBoricaInDevMode}\n formData={boricaData}\n />\n )}\n </>\n </CheckoutFormCustomStateProvider>\n </CheckoutFormContext.Provider>\n )\n}\n\nexport type CheckoutFormOnSubmitData = {\n isShippingValid: boolean\n setIsShippingSubmitting: (value: boolean) => void\n isBillingValid: boolean\n setIsBillingSubmitting: (value: boolean) => void\n isPaymentValid: boolean\n setIsPaymentSubmitting: (value: boolean) => void\n step: CheckoutFormStepsEnum\n updateStep: (step: CheckoutFormStepsEnum) => void\n saveOrder: MutateFunction<OrderDTO, unknown, any, unknown>\n\n updateServerErrors: (errors: any) => void\n scrollToFirstError: () => void\n shippingState: UseShippingResultType\n shippingAddress?: AddressDTO\n}\n\ntype Props = {\n children: any\n defaultStep: CheckoutFormStepsEnum\n errorLabels: CheckoutFormErrorLabelsType\n withPersistBeforePageLeave: boolean\n countryCode: string\n onSubmit: (data: CheckoutFormOnSubmitData) => void\n onError: (error: any) => void\n onSuccess: (order: OrderDTO) => void\n\n redirectTimeout?: number\n onBeforeRedirect?: () => void\n\n customState?: CheckoutCustomState\n\n enableSavedAddressList: boolean\n shippingValidations?: ShippingValidationsType\n enableSaveAddress: boolean\n autofillShippingPersonalData: boolean\n autoSelectDefaultShippingAddress: boolean\n\n enableSaveBillingAddress: boolean\n validateBillingAddress?: BillingAddressValidationType\n enableSavedBillingAddressList: boolean\n autoSelectDefaultBillingAddress: boolean\n\n paymentEnabledOnStep?: CheckoutFormStepsEnum\n getPaymentMethodsWhenShippingMethodIsSelected?: boolean\n\n shippingEnabledOnStep: CheckoutFormStepsEnum\n\n billingEnabledOnStep: CheckoutFormStepsEnum\n\n isBoricaInDevMode?: boolean\n\n withPixelMeta?: boolean\n requiredFieldsOnShippingStep?: string[]\n requiredFieldsOnBillingAddressStep?: string[]\n enableNoShippingMethodMode?: boolean\n}\n\ntype ServerErrors = { [key: string]: any } | null\n\nexport enum CheckoutFormStepsEnum {\n Basket = 'Basket',\n Shipping = 'Shipping',\n BillingAddress = 'BillingAddress',\n Payment = 'Payment',\n Preview = 'Preview',\n All = 'All',\n}\n\nexport type CheckoutFormErrorsResultType =\n | {\n [key: string]: string\n }\n | null\n | undefined\n\nexport type ShippingFormErrorLabels = {\n fieldIsRequired: string\n\n fillStreetNumberBuildingEntranceOrApartment: string\n streetIsRequired: string\n invalidPhoneNumber?: string\n quarterIsRequired: string\n cantFindStreetOrQuarterMessage: string\n cityIsRequired: string\n emailIsRequired: string\n officeIsRequired: string\n selectCourier: string\n\n noStoreSelected: string\n}\n\nexport type CheckoutFormErrorLabelsType = ShippingFormErrorLabels & {\n selectPaymentMethod: string\n}\n\nexport type CheckoutFormContextType = {\n setStep: (step: CheckoutFormStepsEnum) => void\n step: CheckoutFormStepsEnum\n serverErrors: ServerErrors\n updateServerErrors: (errors: any) => void\n errorRef: (error: HTMLElement) => void\n errorFields: HTMLElement[]\n errorLabels: CheckoutFormErrorLabelsType\n orderQuery: QueryResult<OrderDTO, unknown>\n shippingState: UseShippingResultType\n paymentState: UsePaymentResultType\n billingState: UseBillingResultType\n}\n\nexport const useCheckoutFormStep = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormStep must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n currentStep: context.step,\n updateStep: context.setStep,\n }\n }, [context])\n}\n\nexport const useCheckoutFormOrder = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormOrder must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.orderQuery\n}\n\nexport const useCheckoutFormErrorLabels = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormErrorLabels must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.errorLabels\n}\n\nexport const useCheckoutFormServerErrors = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormServerErrors must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n serverErrors: context.serverErrors,\n updateServerErrors: context.updateServerErrors,\n }\n }, [context])\n}\n\nexport const useCheckoutFormBillingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormBillingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.billingState\n}\n\nexport const useCheckoutFormShippingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormShippingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.shippingState\n}\n\nexport const useCheckoutErrorFields = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutErrorFields must be used within a CheckoutFormContextProvider'\n )\n }\n\n return {\n errorFields: context.errorFields,\n errorRef: context.errorRef,\n }\n}\n\nexport const useCheckoutFormPaymentState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormPaymentState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.paymentState\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/contexts/CheckoutForm/index.tsx"],"names":["CheckoutFormContext","CheckoutFormContextProvider","children","defaultStep","errorLabels","enableSavedAddressList","withPersistBeforePageLeave","shippingValidations","defaultShippingValidations","validateBillingAddress","genericBillingAddressValidation","enableSaveBillingAddress","enableSavedBillingAddressList","countryCode","enableSaveAddress","autofillShippingPersonalData","onSubmit","paymentEnabledOnStep","getPaymentMethodsWhenShippingMethodIsSelected","shippingEnabledOnStep","billingEnabledOnStep","customState","initialCustomState","redirectTimeout","onBeforeRedirect","onSuccess","onError","isBoricaInDevMode","withPixelMeta","requiredFieldsOnShippingStep","requiredFieldsOnBillingAddressStep","enableNoShippingMethodMode","orderQuery","myCartApi","useGet","boricaData","setBoricaData","step","setStep","isRedirecting","setIsRedirecting","fieldsWithError","serverErrors","setServerErrors","collectFieldsWithError","error","push","handleStepChange","newStep","window","scrollTo","updateServerErrors","errors","formattedErrors","reduce","data","code","response","internalError","isAuthenticated","isShippingEnabled","userQuery","usersApi","enabled","shippingState","Boolean","validations","requiredFields","mod","getIsPaymentMethodsEnabled","moduleKey","moduleData","methodKey","paymentState","billingState","withSavedBillingAddressList","requiredFieldsOnShipping","onBeforeBoricaRedirect","setTimeout","onBeforePaypalRedirect","location","replace","redirectUrl","withMeta","handleCheckoutSubmit","scrollToFirstError","interval","setInterval","errorElement","top","clearInterval","handleSubmit","e","preventDefault","Promise","all","persistShippingAddress","persistBillingAddress","isShippingValid","isValid","setIsShippingSubmitting","updateIsSubmitting","isBillingValid","setIsBillingSubmitting","isPaymentValid","setIsPaymentSubmitting","updateStep","saveOrder","shippingAddress","state","errorRef","errorFields","CheckoutFormStepsEnum","useCheckoutFormStep","context","Error","currentStep","useCheckoutFormOrder","useCheckoutFormErrorLabels","useCheckoutFormServerErrors","useCheckoutFormBillingState","useCheckoutFormShippingState","useCheckoutErrorFields","useCheckoutFormPaymentState"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AAcA;;AACA;;AAQA;;AACA;;AAEA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AAEO,IAAMA,mBAAmB,gBAAG,0BACjC,EADiC,CAA5B;;;AAMA,SAASC,2BAAT,OAmCG;AAAA,MAlCRC,QAkCQ,QAlCRA,QAkCQ;AAAA,MAjCRC,WAiCQ,QAjCRA,WAiCQ;AAAA,MAhCRC,WAgCQ,QAhCRA,WAgCQ;AAAA,MA/BRC,sBA+BQ,QA/BRA,sBA+BQ;AAAA,MA9BRC,0BA8BQ,QA9BRA,0BA8BQ;AAAA,mCA7BRC,mBA6BQ;AAAA,MA7BRA,mBA6BQ,sCA7BcC,iCA6Bd;AAAA,mCA5BRC,sBA4BQ;AAAA,MA5BRA,sBA4BQ,sCA5BiBC,sCA4BjB;AAAA,MA3BRC,wBA2BQ,QA3BRA,wBA2BQ;AAAA,MA1BRC,6BA0BQ,QA1BRA,6BA0BQ;AAAA,MAzBRC,WAyBQ,QAzBRA,WAyBQ;AAAA,MAxBRC,iBAwBQ,QAxBRA,iBAwBQ;AAAA,MAvBRC,4BAuBQ,QAvBRA,4BAuBQ;AAAA,MAtBRC,QAsBQ,QAtBRA,QAsBQ;AAAA,MApBRC,oBAoBQ,QApBRA,oBAoBQ;AAAA,MAnBRC,6CAmBQ,QAnBRA,6CAmBQ;AAAA,MAlBRC,qBAkBQ,QAlBRA,qBAkBQ;AAAA,MAjBRC,oBAiBQ,QAjBRA,oBAiBQ;AAAA,8BAfRC,WAeQ;AAAA,MAfKC,kBAeL,iCAf0B,EAe1B;AAAA,kCAdRC,eAcQ;AAAA,MAdRA,eAcQ,qCAdU,GAcV;AAAA,MAbRC,gBAaQ,QAbRA,gBAaQ;AAAA,MAZRC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MAAMP,OAAO,GAAG,uBAAWlH,mBAAX,CAAhB;;AAEA,MAAI,CAACkH,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,gFADI,CAAN;AAGD;;AAED,SAAOD,OAAO,CAAClD,aAAf;AACD,CAVM;;;;AAYA,IAAM0D,sBAAsB,GAAG,SAAzBA,sBAAyB,GAAM;AAC1C,MAAMR,OAAO,GAAG,uBAAWlH,mBAAX,CAAhB;;AAEA,MAAI,CAACkH,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,0EADI,CAAN;AAGD;;AAED,SAAO;AACLJ,IAAAA,WAAW,EAAEG,OAAO,CAACH,WADhB;AAELD,IAAAA,QAAQ,EAAEI,OAAO,CAACJ;AAFb,GAAP;AAID,CAbM;;;;AAeA,IAAMa,2BAA2B,GAAG,SAA9BA,2BAA8B,GAAM;AAC/C,MAAMT,OAAO,GAAG,uBAAWlH,mBAAX,CAAhB;;AAEA,MAAI,CAACkH,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,+EADI,CAAN;AAGD;;AAED,SAAOD,OAAO,CAACzC,YAAf;AACD,CAVM","sourcesContent":["import React, {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n} from 'react'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n AddressDTO,\n PaypalGeneratePaymentUrlResponseDTO,\n} from '@sentecacommerce/sdk'\nimport { MutateFunction, QueryResult } from 'react-query'\nimport { myCartApi } from '../../api/myCartApi'\nimport {\n useBilling,\n UseBillingResultType,\n usePayment,\n UsePaymentResultType,\n useShipping,\n UseShippingResultType,\n} from './hooks'\nimport { useIsAuthenticated } from '../../user/hooks'\nimport { useCheckoutSubmit } from '../../hooks/useCheckoutSubmit'\n\nimport {\n ShippingValidationsType,\n defaultShippingValidations,\n genericBillingAddressValidation,\n BillingAddressValidationType,\n} from './utils'\nimport { usersApi } from '../../api/usersApi'\nimport { useCheckoutShippingModule } from '../../hooks/useCheckoutShippingModule'\nimport { CheckoutFormCustomStateProvider, BoricaRedirect } from './Components'\nimport { useScrollTo } from '../../hooks/ui-hooks'\nimport { getElementOffset } from '../../utils/getElementOffset'\n\nexport const CheckoutFormContext = createContext<CheckoutFormContextType>(\n {} as any\n)\n\nexport type CheckoutCustomState = {}\n\nexport function CheckoutFormContextProvider({\n children,\n defaultStep,\n errorLabels,\n enableSavedAddressList,\n withPersistBeforePageLeave,\n shippingValidations = defaultShippingValidations,\n validateBillingAddress = genericBillingAddressValidation,\n enableSaveBillingAddress,\n enableSavedBillingAddressList,\n countryCode,\n enableSaveAddress,\n autofillShippingPersonalData,\n onSubmit,\n\n paymentEnabledOnStep,\n getPaymentMethodsWhenShippingMethodIsSelected,\n shippingEnabledOnStep,\n billingEnabledOnStep,\n\n customState: initialCustomState = {},\n redirectTimeout = 420,\n onBeforeRedirect,\n onSuccess,\n onError,\n isBoricaInDevMode,\n withPixelMeta = false,\n requiredFieldsOnShippingStep = [\n 'firstName',\n 'lastName',\n 'email',\n 'phoneNumber',\n ],\n requiredFieldsOnBillingAddressStep = ['city', 'postalCode', 'streetName'],\n enableNoShippingMethodMode = false,\n}: Props) {\n const orderQuery = myCartApi.useGet()\n const [\n boricaData,\n setBoricaData,\n ] = useState<BoricaGeneratePaymentDataResponse | null>(null)\n const [step, setStep] = useState<CheckoutFormStepsEnum>(defaultStep)\n const [isRedirecting, setIsRedirecting] = useState(false)\n\n const fieldsWithError: HTMLElement[] = []\n\n const [serverErrors, setServerErrors] = useState<ServerErrors>(null)\n\n const collectFieldsWithError = (error: HTMLElement) => {\n fieldsWithError.push(error)\n }\n\n const handleStepChange = useCallback((newStep: CheckoutFormStepsEnum) => {\n window.scrollTo(0, 0)\n\n setStep(newStep)\n }, [])\n\n const updateServerErrors = useCallback((errors: any[]) => {\n // Example Error\n // [{\n // code: \"OutOfStock\"\n // message: \"Some of the ordered line items are out of stock at the time of placing the order.\"\n // responses: {\n // availableQuantity: 1\n // sku: \"200000095849\"\n // status: \"unavailable\"\n // }\n // }]\n const formattedErrors = errors?.reduce?.(\n (data: ServerErrors, error: any) => {\n return {\n ...data,\n [error?.code || 'internal']: error?.response,\n }\n },\n {}\n )\n setServerErrors(formattedErrors || { internalError: errors })\n }, [])\n\n const { isAuthenticated } = useIsAuthenticated()\n\n const isShippingEnabled = shippingEnabledOnStep === step\n\n const userQuery = usersApi.useGet(\n {},\n { enabled: isShippingEnabled && autofillShippingPersonalData }\n )\n\n const shippingState = useShipping({\n errorLabels,\n orderQuery,\n enableSavedAddressList: Boolean(isAuthenticated && enableSavedAddressList),\n enableSaveAddress: Boolean(isAuthenticated && enableSaveAddress),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n validations: shippingValidations,\n autofillShippingPersonalData: Boolean(\n isAuthenticated && autofillShippingPersonalData\n ),\n userQuery,\n enabled: isShippingEnabled,\n countryCode,\n requiredFields: requiredFieldsOnShippingStep,\n enableNoShippingMethodMode,\n })\n const mod = useCheckoutShippingModule(orderQuery, !enableNoShippingMethodMode)\n\n const getIsPaymentMethodsEnabled = () => {\n if (paymentEnabledOnStep) {\n return paymentEnabledOnStep === step\n }\n\n if (\n !enableNoShippingMethodMode &&\n getPaymentMethodsWhenShippingMethodIsSelected\n ) {\n return Boolean(mod?.moduleKey && mod?.moduleData.methodKey)\n }\n\n return false\n }\n\n const paymentState = usePayment({\n errorLabels,\n orderQuery,\n enabled: getIsPaymentMethodsEnabled(),\n })\n\n const billingState = useBilling({\n errorLabels,\n orderQuery,\n validateBillingAddress,\n enableSaveBillingAddress: Boolean(\n isAuthenticated && enableSaveBillingAddress\n ),\n withSavedBillingAddressList: Boolean(\n isAuthenticated && enableSavedBillingAddressList\n ),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n countryCode,\n enabled: billingEnabledOnStep === step,\n requiredFields: requiredFieldsOnBillingAddressStep,\n requiredFieldsOnShipping: requiredFieldsOnShippingStep,\n })\n\n const onBeforeBoricaRedirect = (data: BoricaGeneratePaymentDataResponse) => {\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setBoricaData(data)\n }, redirectTimeout)\n }\n\n const onBeforePaypalRedirect = (\n data: PaypalGeneratePaymentUrlResponseDTO\n ) => {\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n window.location.replace(data.redirectUrl)\n }, redirectTimeout)\n }\n const { handleCheckoutSubmit } = useCheckoutSubmit({\n onBeforeBoricaRedirect,\n onBeforePaypalRedirect,\n onSuccess,\n onError: (errors: any) => {\n updateServerErrors(errors)\n onError(errors)\n },\n withMeta: withPixelMeta,\n })\n\n const { scrollTo } = useScrollTo(fieldsWithError[0], 0)\n\n const scrollToFirstError = () => {\n const interval = setInterval(() => {\n const errorElement = fieldsWithError[0]\n if (!errorElement) return\n\n scrollTo(getElementOffset(errorElement).top - 100)\n clearInterval(interval)\n }, 50)\n\n setTimeout(() => {\n clearInterval(interval)\n }, 1000)\n }\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n\n await Promise.all([\n shippingState.persistShippingAddress(),\n billingState.persistBillingAddress(),\n ]).catch(() => {})\n\n onSubmit({\n isShippingValid: shippingState.isValid,\n setIsShippingSubmitting: shippingState.updateIsSubmitting,\n isBillingValid: billingState.isValid,\n setIsBillingSubmitting: billingState.updateIsSubmitting,\n isPaymentValid: paymentState.isValid,\n setIsPaymentSubmitting: paymentState.updateIsSubmitting,\n step,\n updateStep: setStep,\n saveOrder: handleCheckoutSubmit,\n updateServerErrors,\n scrollToFirstError,\n shippingState,\n shippingAddress: shippingState.data,\n })\n }\n\n const state = {\n setStep: handleStepChange,\n step,\n orderQuery,\n serverErrors,\n updateServerErrors,\n errorLabels,\n shippingState,\n paymentState,\n billingState,\n errorRef: collectFieldsWithError,\n errorFields: fieldsWithError,\n }\n\n return (\n <CheckoutFormContext.Provider value={state}>\n <CheckoutFormCustomStateProvider initialCustomState={initialCustomState}>\n <>\n <form noValidate onSubmit={handleSubmit}>\n {children}\n </form>\n {!!boricaData && (\n <BoricaRedirect\n isInDevMode={isBoricaInDevMode}\n formData={boricaData}\n />\n )}\n </>\n </CheckoutFormCustomStateProvider>\n </CheckoutFormContext.Provider>\n )\n}\n\nexport type CheckoutFormOnSubmitData = {\n isShippingValid: boolean\n setIsShippingSubmitting: (value: boolean) => void\n isBillingValid: boolean\n setIsBillingSubmitting: (value: boolean) => void\n isPaymentValid: boolean\n setIsPaymentSubmitting: (value: boolean) => void\n step: CheckoutFormStepsEnum\n updateStep: (step: CheckoutFormStepsEnum) => void\n saveOrder: MutateFunction<OrderDTO, unknown, any, unknown>\n\n updateServerErrors: (errors: any) => void\n scrollToFirstError: () => void\n shippingState: UseShippingResultType\n shippingAddress?: AddressDTO\n}\n\ntype Props = {\n children: any\n defaultStep: CheckoutFormStepsEnum\n errorLabels: CheckoutFormErrorLabelsType\n withPersistBeforePageLeave: boolean\n countryCode: string\n onSubmit: (data: CheckoutFormOnSubmitData) => void\n onError: (error: any) => void\n onSuccess: (order: OrderDTO) => void\n\n redirectTimeout?: number\n onBeforeRedirect?: () => void\n\n customState?: CheckoutCustomState\n\n enableSavedAddressList: boolean\n shippingValidations?: ShippingValidationsType\n enableSaveAddress: boolean\n autofillShippingPersonalData: boolean\n autoSelectDefaultShippingAddress: boolean\n\n enableSaveBillingAddress: boolean\n validateBillingAddress?: BillingAddressValidationType\n enableSavedBillingAddressList: boolean\n autoSelectDefaultBillingAddress: boolean\n\n paymentEnabledOnStep?: CheckoutFormStepsEnum\n getPaymentMethodsWhenShippingMethodIsSelected?: boolean\n\n shippingEnabledOnStep: CheckoutFormStepsEnum\n\n billingEnabledOnStep: CheckoutFormStepsEnum\n\n isBoricaInDevMode?: boolean\n\n withPixelMeta?: boolean\n requiredFieldsOnShippingStep?: string[]\n requiredFieldsOnBillingAddressStep?: string[]\n enableNoShippingMethodMode?: boolean\n}\n\ntype ServerErrors = { [key: string]: any } | null\n\nexport enum CheckoutFormStepsEnum {\n Basket = 'Basket',\n Shipping = 'Shipping',\n BillingAddress = 'BillingAddress',\n Payment = 'Payment',\n Preview = 'Preview',\n All = 'All',\n}\n\nexport type CheckoutFormErrorsResultType =\n | {\n [key: string]: string\n }\n | null\n | undefined\n\nexport type ShippingFormErrorLabels = {\n fieldIsRequired: string\n\n fillStreetNumberBuildingEntranceOrApartment: string\n streetIsRequired: string\n invalidPhoneNumber?: string\n quarterIsRequired: string\n cantFindStreetOrQuarterMessage: string\n cityIsRequired: string\n emailIsRequired: string\n officeIsRequired: string\n selectCourier: string\n\n noStoreSelected: string\n}\n\nexport type CheckoutFormErrorLabelsType = ShippingFormErrorLabels & {\n selectPaymentMethod: string\n}\n\nexport type CheckoutFormContextType = {\n setStep: (step: CheckoutFormStepsEnum) => void\n step: CheckoutFormStepsEnum\n serverErrors: ServerErrors\n updateServerErrors: (errors: any) => void\n errorRef: (error: HTMLElement) => void\n errorFields: HTMLElement[]\n errorLabels: CheckoutFormErrorLabelsType\n orderQuery: QueryResult<OrderDTO, unknown>\n shippingState: UseShippingResultType\n paymentState: UsePaymentResultType\n billingState: UseBillingResultType\n}\n\nexport const useCheckoutFormStep = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormStep must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n currentStep: context.step,\n updateStep: context.setStep,\n }\n }, [context])\n}\n\nexport const useCheckoutFormOrder = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormOrder must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.orderQuery\n}\n\nexport const useCheckoutFormErrorLabels = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormErrorLabels must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.errorLabels\n}\n\nexport const useCheckoutFormServerErrors = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormServerErrors must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n serverErrors: context.serverErrors,\n updateServerErrors: context.updateServerErrors,\n }\n }, [context])\n}\n\nexport const useCheckoutFormBillingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormBillingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.billingState\n}\n\nexport const useCheckoutFormShippingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormShippingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.shippingState\n}\n\nexport const useCheckoutErrorFields = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutErrorFields must be used within a CheckoutFormContextProvider'\n )\n }\n\n return {\n errorFields: context.errorFields,\n errorRef: context.errorRef,\n }\n}\n\nexport const useCheckoutFormPaymentState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormPaymentState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.paymentState\n}\n"],"file":"index.js"}
@@ -20,6 +20,7 @@ var _purchase = require("../../analytics/purchase");
20
20
  var useCheckoutSubmit = function useCheckoutSubmit(_ref) {
21
21
  var onSuccess = _ref.onSuccess,
22
22
  onBeforeBoricaRedirect = _ref.onBeforeBoricaRedirect,
23
+ onBeforePaypalRedirect = _ref.onBeforePaypalRedirect,
23
24
  onError = _ref.onError,
24
25
  withMeta = _ref.withMeta;
25
26
  var Config = (0, _useConfig.useConfigState)();
@@ -27,38 +28,56 @@ var useCheckoutSubmit = function useCheckoutSubmit(_ref) {
27
28
 
28
29
  var _myOrdersApi$useCreat = _.myOrdersApi.useCreate(withMeta ? districtMeta : {}, /*#__PURE__*/function () {
29
30
  var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(result) {
30
- var boricaPayment, boricaResult;
31
+ var paypalPayment, boricaPayment, boricaResult, paypalResponse;
31
32
  return _regenerator["default"].wrap(function _callee$(_context) {
32
33
  while (1) {
33
34
  switch (_context.prev = _context.next) {
34
35
  case 0:
35
36
  // Analytics
36
37
  (0, _purchase.purchase)(result, Config);
38
+ paypalPayment = result.payments.find(function (payment) {
39
+ return payment.type === _sdk.PaymentMethodDTOTypeEnum.PaymentServiceProvider && payment.moduleKey === 'Paypal';
40
+ });
37
41
  boricaPayment = result.payments.find(function (payment) {
38
42
  return payment.type === _sdk.PaymentMethodDTOTypeEnum.PaymentServiceProvider && payment.moduleKey === 'Borica';
39
43
  });
40
44
 
41
45
  if (!boricaPayment) {
42
- _context.next = 9;
46
+ _context.next = 10;
43
47
  break;
44
48
  }
45
49
 
46
- _context.next = 5;
50
+ _context.next = 6;
47
51
  return _.myPaymentsBoricaApi.pay({
48
52
  orderId: result._id,
49
53
  paymentId: boricaPayment._id
50
54
  });
51
55
 
52
- case 5:
56
+ case 6:
53
57
  boricaResult = _context.sent;
54
58
  onBeforeBoricaRedirect == null ? void 0 : onBeforeBoricaRedirect(boricaResult);
55
- _context.next = 10;
59
+ _context.next = 18;
56
60
  break;
57
61
 
58
- case 9:
62
+ case 10:
63
+ if (!paypalPayment) {
64
+ _context.next = 17;
65
+ break;
66
+ }
67
+
68
+ _context.next = 13;
69
+ return (0, _sdk.MyPaymentsPaypalPayMyOrder)(result._id, paypalPayment._id);
70
+
71
+ case 13:
72
+ paypalResponse = _context.sent;
73
+ onBeforePaypalRedirect == null ? void 0 : onBeforePaypalRedirect(paypalResponse);
74
+ _context.next = 18;
75
+ break;
76
+
77
+ case 17:
59
78
  onSuccess == null ? void 0 : onSuccess(result);
60
79
 
61
- case 10:
80
+ case 18:
62
81
  case "end":
63
82
  return _context.stop();
64
83
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/hooks/useCheckoutSubmit/index.ts"],"names":["useCheckoutSubmit","onSuccess","onBeforeBoricaRedirect","onError","withMeta","Config","districtMeta","myOrdersApi","useCreate","result","boricaPayment","payments","find","payment","type","PaymentMethodDTOTypeEnum","PaymentServiceProvider","moduleKey","myPaymentsBoricaApi","pay","orderId","_id","paymentId","boricaResult","handleCheckoutSubmit"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAKA;;AACA;;AAEO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,OAU3B;AAAA,MATJC,SASI,QATJA,SASI;AAAA,MARJC,sBAQI,QARJA,sBAQI;AAAA,MAPJC,OAOI,QAPJA,OAOI;AAAA,MANJC,QAMI,QANJA,QAMI;AACJ,MAAMC,MAAM,GAAG,gCAAf;AAEA,MAAMC,YAAY,GAAG,wBAArB;;AAHI,8BAK2BC,cAAYC,SAAZ,CAC7BJ,QAAQ,GAAGE,YAAH,GAAkB,EADG;AAAA,8FAE7B,iBAAOG,MAAP;AAAA;AAAA;AAAA;AAAA;AAAA;AACE;AACA,sCAASA,MAAT,EAAiBJ,MAAjB;AAEMK,cAAAA,aAJR,GAIwBD,MAAM,CAACE,QAAP,CAAgBC,IAAhB,CACpB,UAACC,OAAD;AAAA,uBACEA,OAAO,CAACC,IAAR,KAAiBC,8BAAyBC,sBAA1C,IACAH,OAAO,CAACI,SAAR,KAAsB,QAFxB;AAAA,eADoB,CAJxB;;AAAA,mBAUMP,aAVN;AAAA;AAAA;AAAA;;AAAA;AAAA,qBAW+BQ,sBAAoBC,GAApB,CAAwB;AACjDC,gBAAAA,OAAO,EAAEX,MAAM,CAACY,GADiC;AAEjDC,gBAAAA,SAAS,EAAEZ,aAAa,CAACW;AAFwB,eAAxB,CAX/B;;AAAA;AAWUE,cAAAA,YAXV;AAeIrB,cAAAA,sBAAsB,QAAtB,YAAAA,sBAAsB,CAAGqB,YAAH,CAAtB;AAfJ;AAAA;;AAAA;AAiBItB,cAAAA,SAAS,QAAT,YAAAA,SAAS,CAAGQ,MAAH,CAAT;;AAjBJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAF6B;;AAAA;AAAA;AAAA;AAAA,OAsB7BN,OAtB6B,CAL3B;AAAA,MAKGqB,oBALH;;AA8BJ,SAAO;AACLA,IAAAA,oBAAoB,EAApBA;AADK,GAAP;AAGD,CA3CM","sourcesContent":["import { myOrdersApi, myPaymentsBoricaApi, useDistrictMeta } from '../../'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n PaymentMethodDTOTypeEnum,\n} from '@sentecacommerce/sdk'\nimport { useConfigState } from '../useConfig'\nimport { purchase } from '../../analytics/purchase'\n\nexport const useCheckoutSubmit = ({\n onSuccess,\n onBeforeBoricaRedirect,\n onError,\n withMeta,\n}: {\n onSuccess?: (result: OrderDTO) => void\n onBeforeBoricaRedirect?: (formData: BoricaGeneratePaymentDataResponse) => void\n onError?: (error: any) => void\n withMeta?: boolean\n}) => {\n const Config = useConfigState()\n\n const districtMeta = useDistrictMeta()\n\n const [handleCheckoutSubmit] = myOrdersApi.useCreate(\n withMeta ? districtMeta : {},\n async (result: OrderDTO) => {\n // Analytics\n purchase(result, Config)\n\n const boricaPayment = result.payments.find(\n (payment) =>\n payment.type === PaymentMethodDTOTypeEnum.PaymentServiceProvider &&\n payment.moduleKey === 'Borica'\n )\n\n if (boricaPayment) {\n const boricaResult = await myPaymentsBoricaApi.pay({\n orderId: result._id,\n paymentId: boricaPayment._id,\n })\n onBeforeBoricaRedirect?.(boricaResult)\n } else {\n onSuccess?.(result)\n }\n },\n onError\n )\n\n return {\n handleCheckoutSubmit,\n }\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/hooks/useCheckoutSubmit/index.ts"],"names":["useCheckoutSubmit","onSuccess","onBeforeBoricaRedirect","onBeforePaypalRedirect","onError","withMeta","Config","districtMeta","myOrdersApi","useCreate","result","paypalPayment","payments","find","payment","type","PaymentMethodDTOTypeEnum","PaymentServiceProvider","moduleKey","boricaPayment","myPaymentsBoricaApi","pay","orderId","_id","paymentId","boricaResult","paypalResponse","handleCheckoutSubmit"],"mappings":";;;;;;;;;;;A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A;AAAA,qBAuBiC,qCAC3BD,MAAM,CAACa,GADoB,EAE3BZ,aAAa,CAACY,GAFa,CAvBjC;;AAAA;AAuBUG,cAAAA,cAvBV;AA4BIvB,cAAAA,sBAAsB,QAAtB,YAAAA,sBAAsB,CAAGuB,cAAH,CAAtB;AA5BJ;AAAA;;AAAA;AA8BIzB,cAAAA,SAAS,QAAT,YAAAA,SAAS,CAAGS,MAAH,CAAT;;AA9BJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAF6B;;AAAA;AAAA;AAAA;AAAA,OAmC7BN,OAnC6B,CAL3B;AAAA,MAKGuB,oBALH;;AA2CJ,SAAO;AACLA,IAAAA,oBAAoB,EAApBA;AADK,GAAP;AAGD,CA1DM","sourcesContent":["import { myOrdersApi, myPaymentsBoricaApi, useDistrictMeta } from '../../'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n PaymentMethodDTOTypeEnum,\n MyPaymentsPaypalPayMyOrder,\n} from '@sentecacommerce/sdk'\nimport { useConfigState } from '../useConfig'\nimport { purchase } from '../../analytics/purchase'\n\nexport const useCheckoutSubmit = ({\n onSuccess,\n onBeforeBoricaRedirect,\n onBeforePaypalRedirect,\n onError,\n withMeta,\n}: {\n onSuccess?: (result: OrderDTO) => void\n onBeforeBoricaRedirect?: (formData: BoricaGeneratePaymentDataResponse) => void\n onError?: (error: any) => void\n withMeta?: boolean\n onBeforePaypalRedirect: any\n}) => {\n const Config = useConfigState()\n\n const districtMeta = useDistrictMeta()\n\n const [handleCheckoutSubmit] = myOrdersApi.useCreate(\n withMeta ? districtMeta : {},\n async (result: OrderDTO) => {\n // Analytics\n purchase(result, Config)\n\n const paypalPayment = result.payments.find(\n (payment) =>\n payment.type === PaymentMethodDTOTypeEnum.PaymentServiceProvider &&\n payment.moduleKey === 'Paypal'\n )\n\n const boricaPayment = result.payments.find(\n (payment) =>\n payment.type === PaymentMethodDTOTypeEnum.PaymentServiceProvider &&\n payment.moduleKey === 'Borica'\n )\n\n if (boricaPayment) {\n const boricaResult = await myPaymentsBoricaApi.pay({\n orderId: result._id,\n paymentId: boricaPayment._id,\n })\n onBeforeBoricaRedirect?.(boricaResult)\n } else if (paypalPayment) {\n const paypalResponse = await MyPaymentsPaypalPayMyOrder(\n result._id,\n paypalPayment._id\n )\n\n onBeforePaypalRedirect?.(paypalResponse)\n } else {\n onSuccess?.(result)\n }\n },\n onError\n )\n\n return {\n handleCheckoutSubmit,\n }\n}\n"],"file":"index.js"}
@@ -13,16 +13,14 @@ var getCanonicalUrl = function getCanonicalUrl(context, localeData, redirectTo)
13
13
  var domain = (localeData == null ? void 0 : localeData.domain) || '';
14
14
  domain = domain[domain.length - 1] === '/' ? domain.slice(0, domain.length - 1) : domain;
15
15
  if (!reqHost || !reqSSL || !domain) return;
16
- var areWeSecured = reqSSL === 'https';
16
+ var areWeSecured = reqSSL === 'true';
17
17
 
18
18
  var _ref = ((_req$url = req.url) == null ? void 0 : _req$url.split('?')) || ['/'],
19
19
  currentPath = _ref[0],
20
20
  queryString = _ref[1];
21
21
 
22
- console.log('req.headers', req.headers, reqHost, reqSSL, 'redirectTo: ' + redirectTo, 'areWeSecured: ', areWeSecured, 'domain: ' + domain, 'is req host === domain', domain === reqHost, 'is req host / locale === domain', domain === reqHost + "/" + localeData.locale);
23
22
  if (!redirectTo && areWeSecured && (domain === reqHost || domain === reqHost + "/" + localeData.locale)) return;
24
23
  var address = "https://" + domain + (redirectTo || currentPath) + (queryString ? "?" + queryString : '');
25
- console.log('redirect url', address);
26
24
  return address;
27
25
  };
28
26
 
@@ -1 +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","console","log","locale","address"],"mappings":";;;;;AAGO,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,CAC7BC,OAD6B,EAE7BC,UAF6B,EAG7BC,UAH6B,EAI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AC,EAAAA,OAAO,CAACC,GAAR,CAAY,cAAZ,EAA4BE,OAA5B;AAEA,SAAOA,OAAP;AACD,CAnDM","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 const [currentPath, queryString] = req.url?.split('?') || ['/']\n\n console.log(\n 'req.headers',\n req.headers,\n reqHost,\n reqSSL,\n 'redirectTo: ' + redirectTo,\n 'areWeSecured: ',\n areWeSecured,\n 'domain: ' + domain,\n 'is req host === domain',\n domain === reqHost,\n 'is req host / locale === domain',\n domain === `${reqHost}/${localeData.locale}`\n )\n if (\n !redirectTo &&\n areWeSecured &&\n (domain === reqHost || domain === `${reqHost}/${localeData.locale}`)\n )\n return\n\n const address = `https://${domain}${redirectTo || currentPath}${\n queryString ? `?${queryString}` : ''\n }`\n\n console.log('redirect url', address)\n\n return address\n}\n"],"file":"getCanonicalUrl.js"}
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","address"],"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,MAAhC;;AAhBuB,aAiBY,aAAAH,GAAG,CAACQ,GAAJ,8BAASC,KAAT,CAAe,GAAf,MAAuB,CAAC,GAAD,CAjBnC;AAAA,MAiBhBC,WAjBgB;AAAA,MAiBHC,WAjBG;;AAmBvB,MACE,CAACZ,UAAD,IACAQ,YADA,KAECH,MAAM,KAAKH,OAAX,IAAsBG,MAAM,KAAQH,OAAR,SAAmBH,UAAU,CAACc,MAF3D,CADF,EAKE;AAEF,MAAMC,OAAO,gBAAcT,MAAd,IAAuBL,UAAU,IAAIW,WAArC,KACXC,WAAW,SAAOA,WAAP,GAAuB,EADvB,CAAb;AAIA,SAAOE,OAAP;AACD,CAnCM","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 === 'true'\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 const address = `https://${domain}${redirectTo || currentPath}${\n queryString ? `?${queryString}` : ''\n }`\n\n return address\n}\n"],"file":"getCanonicalUrl.js"}
@@ -14,8 +14,19 @@ var processLoginPayload = function processLoginPayload(data, anonymous) {
14
14
  anonymous = false;
15
15
  }
16
16
 
17
+ var accessTokenExpires = data.expires;
18
+ var refreshTokenExpires = data.refreshTokenExpires;
17
19
  (0, _utils.writeToLocalStorage)(_wishlistApi.WISHLIST_STORAGE_KEY, data.wishList);
18
20
  (0, _utils.writeToLocalStorage)(_myCartApi.BASKET_STORAGE_KEY, data.basket);
21
+ (0, _utils.setAccessToken)(data.accessToken, anonymous, {
22
+ expires: (0, _utils.convertDateIntoRemainingDays)(new Date(), new Date(accessTokenExpires))
23
+ });
24
+ (0, _utils.setExpiryToken)(data.expires, {
25
+ expires: (0, _utils.convertDateIntoRemainingDays)(new Date(), new Date(refreshTokenExpires))
26
+ });
27
+ (0, _utils.setRefreshToken)(data.refreshToken, {
28
+ expires: (0, _utils.convertDateIntoRemainingDays)(new Date(), new Date(refreshTokenExpires))
29
+ });
19
30
  !anonymous && (0, _utils.removeAnonToken)();
20
31
  };
21
32
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/user/api/utils/processLoginPayload.ts"],"names":["processLoginPayload","data","anonymous","WISHLIST_STORAGE_KEY","wishList","BASKET_STORAGE_KEY","basket"],"mappings":";;;;;AAEA;;AACA;;AAEA;;AAEO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAsB,CACjCC,IADiC,EAEjCC,SAFiC,EAG9B;AAAA,MADHA,SACG;AADHA,IAAAA,SACG,GADS,KACT;AAAA;;AACH,kCAAoBC,iCAApB,EAA0CF,IAAI,CAACG,QAA/C;AACA,kCAAoBC,6BAApB,EAAwCJ,IAAI,CAACK,MAA7C;AAEA,GAACJ,SAAD,IAAc,6BAAd;AACD,CARM","sourcesContent":["import { TokenResponseDTO } from '@sentecacommerce/sdk'\n\nimport { WISHLIST_STORAGE_KEY } from '../../../api/wishlistApi'\nimport { BASKET_STORAGE_KEY } from '../../../api/myCartApi'\n\nimport { writeToLocalStorage, removeAnonToken } from '../../../utils'\n\nexport const processLoginPayload = (\n data: TokenResponseDTO,\n anonymous = false\n) => {\n writeToLocalStorage(WISHLIST_STORAGE_KEY, data.wishList)\n writeToLocalStorage(BASKET_STORAGE_KEY, data.basket)\n\n !anonymous && removeAnonToken()\n}\n"],"file":"processLoginPayload.js"}
1
+ {"version":3,"sources":["../../../../../src/user/api/utils/processLoginPayload.ts"],"names":["processLoginPayload","data","anonymous","accessTokenExpires","expires","refreshTokenExpires","WISHLIST_STORAGE_KEY","wishList","BASKET_STORAGE_KEY","basket","accessToken","Date","refreshToken"],"mappings":";;;;;AAEA;;AACA;;AAEA;;AASO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAsB,CACjCC,IADiC,EAEjCC,SAFiC,EAG9B;AAAA,MADHA,SACG;AADHA,IAAAA,SACG,GADS,KACT;AAAA;;AACH,MAAMC,kBAAkB,GAAGF,IAAI,CAACG,OAAhC;AACA,MAAMC,mBAAmB,GAAGJ,IAAI,CAACI,mBAAjC;AAEA,kCAAoBC,iCAApB,EAA0CL,IAAI,CAACM,QAA/C;AACA,kCAAoBC,6BAApB,EAAwCP,IAAI,CAACQ,MAA7C;AAEA,6BAAeR,IAAI,CAACS,WAApB,EAA2CR,SAA3C,EAAsD;AACpDE,IAAAA,OAAO,EAAE,yCACP,IAAIO,IAAJ,EADO,EAEP,IAAIA,IAAJ,CAASR,kBAAT,CAFO;AAD2C,GAAtD;AAMA,6BAAeF,IAAI,CAACG,OAApB,EAAuC;AACrCA,IAAAA,OAAO,EAAE,yCACP,IAAIO,IAAJ,EADO,EAEP,IAAIA,IAAJ,CAASN,mBAAT,CAFO;AAD4B,GAAvC;AAMA,8BAAgBJ,IAAI,CAACW,YAArB,EAA6C;AAC3CR,IAAAA,OAAO,EAAE,yCACP,IAAIO,IAAJ,EADO,EAEP,IAAIA,IAAJ,CAASN,mBAAT,CAFO;AADkC,GAA7C;AAMA,GAACH,SAAD,IAAc,6BAAd;AACD,CA7BM","sourcesContent":["import { TokenResponseDTO } from '@sentecacommerce/sdk'\n\nimport { WISHLIST_STORAGE_KEY } from '../../../api/wishlistApi'\nimport { BASKET_STORAGE_KEY } from '../../../api/myCartApi'\n\nimport {\n writeToLocalStorage,\n setAccessToken,\n setExpiryToken,\n setRefreshToken,\n removeAnonToken,\n convertDateIntoRemainingDays,\n} from '../../../utils'\n\nexport const processLoginPayload = (\n data: TokenResponseDTO,\n anonymous = false\n) => {\n const accessTokenExpires = data.expires as number\n const refreshTokenExpires = data.refreshTokenExpires as number\n\n writeToLocalStorage(WISHLIST_STORAGE_KEY, data.wishList)\n writeToLocalStorage(BASKET_STORAGE_KEY, data.basket)\n\n setAccessToken(data.accessToken as string, anonymous, {\n expires: convertDateIntoRemainingDays(\n new Date(),\n new Date(accessTokenExpires as number)\n ),\n })\n setExpiryToken(data.expires as number, {\n expires: convertDateIntoRemainingDays(\n new Date(),\n new Date(refreshTokenExpires as number)\n ),\n })\n setRefreshToken(data.refreshToken as string, {\n expires: convertDateIntoRemainingDays(\n new Date(),\n new Date(refreshTokenExpires as number)\n ),\n })\n !anonymous && removeAnonToken()\n}\n"],"file":"processLoginPayload.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/prefetchSDKConfig.ts"],"names":["prefetchSDKConfig","interfaceKey","storeKey","cookies","token","config","Configuration","process","env","API_KEY","basePath","API_HOST","fetchApi","require","headers","InterfaceKey","StoreKey","HttpClient","defaultConfig","transientConfig"],"mappings":";;;;;AAAA;;AAKO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,OAU3B;AAAA,MATJC,YASI,QATJA,YASI;AAAA,MARJC,QAQI,QARJA,QAQI;AAAA,MAPJC,OAOI,QAPJA,OAOI;AAAA,MANJC,KAMI,QANJA,KAMI;AACJ,MAAMC,MAAM,GAAG,IAAIC,kBAAJ,CAAkB;AAC/BF,IAAAA,KAAK,EAAEA,KAAK,IAAIG,OAAO,CAACC,GAAR,CAAYC,OADG;AAE/BC,IAAAA,QAAQ,EAAEH,OAAO,CAACC,GAAR,CAAYG,QAFS;AAG/BC,IAAAA,QAAQ,EAAEC,OAAO,CAAC,YAAD,CAHc;AAI/BC,IAAAA,OAAO,EAAE;AACPC,MAAAA,YAAY,EAAEd,YADP;AAEPe,MAAAA,QAAQ,EAAEd;AAFH;AAJsB,GAAlB,CAAf;AAUAe,kBAAWC,aAAX,GAA2Bb,MAA3B;AACAY,kBAAWE,eAAX,GAA6Bd,MAA7B;AAEA,SAAOA,MAAP;AACD,CAzBM","sourcesContent":["import {\n HttpClient,\n Configuration,\n} from '@sentecacommerce/sdk'\n\nexport const prefetchSDKConfig = ({\n interfaceKey,\n storeKey,\n cookies,\n token,\n}: {\n interfaceKey: string\n storeKey: string\n cookies?: { [key: string]: string }\n token?: string\n}) => {\n const config = new Configuration({\n token: token || process.env.API_KEY,\n basePath: process.env.API_HOST,\n fetchApi: require('node-fetch'),\n headers: {\n InterfaceKey: interfaceKey,\n StoreKey: storeKey,\n },\n })\n\n HttpClient.defaultConfig = config\n HttpClient.transientConfig = config\n\n return config\n}\n"],"file":"prefetchSDKConfig.js"}
1
+ {"version":3,"sources":["../../../src/utils/prefetchSDKConfig.ts"],"names":["prefetchSDKConfig","interfaceKey","storeKey","cookies","token","config","Configuration","process","env","API_KEY","basePath","API_HOST","fetchApi","require","headers","InterfaceKey","StoreKey","HttpClient","defaultConfig","transientConfig"],"mappings":";;;;;AAAA;;AAEO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,OAU3B;AAAA,MATJC,YASI,QATJA,YASI;AAAA,MARJC,QAQI,QARJA,QAQI;AAAA,MAPJC,OAOI,QAPJA,OAOI;AAAA,MANJC,KAMI,QANJA,KAMI;AACJ,MAAMC,MAAM,GAAG,IAAIC,kBAAJ,CAAkB;AAC/BF,IAAAA,KAAK,EAAEA,KAAK,IAAIG,OAAO,CAACC,GAAR,CAAYC,OADG;AAE/BC,IAAAA,QAAQ,EAAEH,OAAO,CAACC,GAAR,CAAYG,QAFS;AAG/BC,IAAAA,QAAQ,EAAEC,OAAO,CAAC,YAAD,CAHc;AAI/BC,IAAAA,OAAO,EAAE;AACPC,MAAAA,YAAY,EAAEd,YADP;AAEPe,MAAAA,QAAQ,EAAEd;AAFH;AAJsB,GAAlB,CAAf;AAUAe,kBAAWC,aAAX,GAA2Bb,MAA3B;AACAY,kBAAWE,eAAX,GAA6Bd,MAA7B;AAEA,SAAOA,MAAP;AACD,CAzBM","sourcesContent":["import { HttpClient, Configuration } from '@sentecacommerce/sdk'\n\nexport const prefetchSDKConfig = ({\n interfaceKey,\n storeKey,\n cookies,\n token,\n}: {\n interfaceKey: string\n storeKey: string\n cookies?: { [key: string]: string }\n token?: string\n}) => {\n const config = new Configuration({\n token: token || process.env.API_KEY,\n basePath: process.env.API_HOST,\n fetchApi: require('node-fetch'),\n headers: {\n InterfaceKey: interfaceKey,\n StoreKey: storeKey,\n },\n })\n\n HttpClient.defaultConfig = config\n HttpClient.transientConfig = config\n\n return config\n}\n"],"file":"prefetchSDKConfig.js"}
@@ -19,6 +19,7 @@ function _prefetchBrands() {
19
19
  refetchOnReconnect: false,
20
20
  refetchOnWindowFocus: false
21
21
  });
22
+ return data;
22
23
  });
23
24
  return _prefetchBrands.apply(this, arguments);
24
25
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/brands/api/ssr/prefetchBrands.ts"],"names":["CatalogAggregate","BrandsQueryEnum","prefetchBrands","queryCache","data","terms","stats","ranges","setQueryData","useAllBrandsQuery","staleTime","retry","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus"],"mappings":";AACA,SAASA,gBAAT,QAAiC,sBAAjC;AAEA,SAASC,eAAT,QAAgC,iBAAhC;AAEA,gBAAsBC,cAAtB;AAAA;AAAA;;;sCAAO,WACLC,UADK,EAEL;AACA,QAAMC,IAAI,SAASJ,gBAAgB,CAAC;AAClCK,MAAAA,KAAK,EAAE,QAD2B;AAElCC,MAAAA,KAAK,EAAE,EAF2B;AAGlCC,MAAAA,MAAM,EAAE;AAH0B,KAAD,CAAnC;AAMAJ,IAAAA,UAAU,CAACK,YAAX,CAAwBP,eAAe,CAACQ,iBAAxC,EAA2DL,IAA3D,EAAiE;AAC/DM,MAAAA,SAAS,EAAE,KADoD;AAE/DC,MAAAA,KAAK,EAAE,KAFwD;AAG/DC,MAAAA,cAAc,EAAE,KAH+C;AAI/DC,MAAAA,kBAAkB,EAAE,KAJ2C;AAK/DC,MAAAA,oBAAoB,EAAE;AALyC,KAAjE;AAOD,G","sourcesContent":["import type { QueryCache } from 'react-query'\nimport { CatalogAggregate } from '@sentecacommerce/sdk'\n\nimport { BrandsQueryEnum } from '../queries/keys'\n\nexport async function prefetchBrands(\n queryCache: QueryCache,\n) {\n const data = await CatalogAggregate({\n terms: 'brands',\n stats: '',\n ranges: '',\n })\n\n queryCache.setQueryData(BrandsQueryEnum.useAllBrandsQuery, data, {\n staleTime: 30000,\n retry: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n })\n}\n"],"file":"prefetchBrands.js"}
1
+ {"version":3,"sources":["../../../../../src/brands/api/ssr/prefetchBrands.ts"],"names":["CatalogAggregate","BrandsQueryEnum","prefetchBrands","queryCache","data","terms","stats","ranges","setQueryData","useAllBrandsQuery","staleTime","retry","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus"],"mappings":";AACA,SAASA,gBAAT,QAAiC,sBAAjC;AAEA,SAASC,eAAT,QAAgC,iBAAhC;AAEA,gBAAsBC,cAAtB;AAAA;AAAA;;;sCAAO,WAA8BC,UAA9B,EAAsD;AAC3D,QAAMC,IAAI,SAASJ,gBAAgB,CAAC;AAClCK,MAAAA,KAAK,EAAE,QAD2B;AAElCC,MAAAA,KAAK,EAAE,EAF2B;AAGlCC,MAAAA,MAAM,EAAE;AAH0B,KAAD,CAAnC;AAMAJ,IAAAA,UAAU,CAACK,YAAX,CAAwBP,eAAe,CAACQ,iBAAxC,EAA2DL,IAA3D,EAAiE;AAC/DM,MAAAA,SAAS,EAAE,KADoD;AAE/DC,MAAAA,KAAK,EAAE,KAFwD;AAG/DC,MAAAA,cAAc,EAAE,KAH+C;AAI/DC,MAAAA,kBAAkB,EAAE,KAJ2C;AAK/DC,MAAAA,oBAAoB,EAAE;AALyC,KAAjE;AAQA,WAAOV,IAAP;AACD,G","sourcesContent":["import type { QueryCache } from 'react-query'\nimport { CatalogAggregate } from '@sentecacommerce/sdk'\n\nimport { BrandsQueryEnum } from '../queries/keys'\n\nexport async function prefetchBrands(queryCache: QueryCache) {\n const data = await CatalogAggregate({\n terms: 'brands',\n stats: '',\n ranges: '',\n })\n\n queryCache.setQueryData(BrandsQueryEnum.useAllBrandsQuery, data, {\n staleTime: 30000,\n retry: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n })\n\n return data\n}\n"],"file":"prefetchBrands.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/checkout/contexts/BoricaResponseContext.tsx"],"names":["React","createContext","useContext","BoricaResponseContext","BoricaResponseProvider","children","response","useBoricaResponse","context","Error"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,aAAhB,EAA+BC,UAA/B,QAAiD,OAAjD;AAGA,IAAMC,qBAAqB,gBAAGF,aAAa,CACzC,EADyC,CAA3C;AAIA,OAAO,IAAMG,sBAAsB,GAAG,UAMhC;AAAA,MANiC;AACrCC,IAAAA,QADqC;AAErCC,IAAAA;AAFqC,GAMjC;AACJ,sBACE,oBAAC,qBAAD,CAAuB,QAAvB;AAAgC,IAAA,KAAK,EAAEA;AAAvC,KACGD,QADH,CADF;AAKD,CAZM;AAcP,OAAO,IAAME,iBAAiB,GAAG,MAAM;AACrC,MAAMC,OAAO,GAAGN,UAAU,CAACC,qBAAD,CAA1B;AAEA,MAAI,CAACK,OAAL,EACE,MAAM,IAAIC,KAAJ,CACJ,8DADI,CAAN;AAIF,SAAOD,OAAP;AACD,CATM","sourcesContent":["import React, { createContext, useContext } from 'react'\nimport type { BoricaVerifyPaymentDataRequest as Reponse } from '@sentecacommerce/sdk'\n\nconst BoricaResponseContext = createContext<Reponse>(\n {} as any\n)\n\nexport const BoricaResponseProvider = ({\n children,\n response,\n}: {\n children: any\n response: Reponse\n}) => {\n return (\n <BoricaResponseContext.Provider value={response}>\n {children}\n </BoricaResponseContext.Provider>\n )\n}\n\nexport const useBoricaResponse = () => {\n const context = useContext(BoricaResponseContext)\n\n if (!context)\n throw new Error(\n 'useBoricaResponse hook must be within BoricaResponseProvider'\n )\n\n return context\n}\n"],"file":"BoricaResponseContext.js"}
1
+ {"version":3,"sources":["../../../../src/checkout/contexts/BoricaResponseContext.tsx"],"names":["React","createContext","useContext","BoricaResponseContext","BoricaResponseProvider","children","response","useBoricaResponse","context","Error"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,aAAhB,EAA+BC,UAA/B,QAAiD,OAAjD;AAGA,IAAMC,qBAAqB,gBAAGF,aAAa,CAAe,EAAf,CAA3C;AAEA,OAAO,IAAMG,sBAAsB,GAAG,UAMhC;AAAA,MANiC;AACrCC,IAAAA,QADqC;AAErCC,IAAAA;AAFqC,GAMjC;AACJ,sBACE,oBAAC,qBAAD,CAAuB,QAAvB;AAAgC,IAAA,KAAK,EAAEA;AAAvC,KACGD,QADH,CADF;AAKD,CAZM;AAcP,OAAO,IAAME,iBAAiB,GAAG,MAAM;AACrC,MAAMC,OAAO,GAAGN,UAAU,CAACC,qBAAD,CAA1B;AAEA,MAAI,CAACK,OAAL,EACE,MAAM,IAAIC,KAAJ,CACJ,8DADI,CAAN;AAIF,SAAOD,OAAP;AACD,CATM","sourcesContent":["import React, { createContext, useContext } from 'react'\nimport type { BoricaVerifyPaymentDataRequest as Reponse } from '@sentecacommerce/sdk'\n\nconst BoricaResponseContext = createContext<Reponse | {}>({})\n\nexport const BoricaResponseProvider = ({\n children,\n response,\n}: {\n children: any\n response: Reponse | {}\n}) => {\n return (\n <BoricaResponseContext.Provider value={response}>\n {children}\n </BoricaResponseContext.Provider>\n )\n}\n\nexport const useBoricaResponse = () => {\n const context = useContext(BoricaResponseContext)\n\n if (!context)\n throw new Error(\n 'useBoricaResponse hook must be within BoricaResponseProvider'\n )\n\n return context\n}\n"],"file":"BoricaResponseContext.js"}
@@ -0,0 +1,17 @@
1
+ import React, { createContext, useContext } from 'react';
2
+ var PaypalResponseContext = /*#__PURE__*/createContext({});
3
+ export var PaypalResponseProvider = (_ref) => {
4
+ var {
5
+ children,
6
+ response
7
+ } = _ref;
8
+ return /*#__PURE__*/React.createElement(PaypalResponseContext.Provider, {
9
+ value: response
10
+ }, children);
11
+ };
12
+ export var usePaypalResponse = () => {
13
+ var context = useContext(PaypalResponseContext);
14
+ if (!context) throw new Error('usePaypalResponse hook must be within PaypalResponseProvider');
15
+ return context;
16
+ };
17
+ //# sourceMappingURL=PaypalResponseContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/checkout/contexts/PaypalResponseContext.tsx"],"names":["React","createContext","useContext","PaypalResponseContext","PaypalResponseProvider","children","response","usePaypalResponse","context","Error"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,aAAhB,EAA+BC,UAA/B,QAAiD,OAAjD;AAGA,IAAMC,qBAAqB,gBAAGF,aAAa,CAAgB,EAAhB,CAA3C;AAEA,OAAO,IAAMG,sBAAsB,GAAG,UAMhC;AAAA,MANiC;AACrCC,IAAAA,QADqC;AAErCC,IAAAA;AAFqC,GAMjC;AACJ,sBACE,oBAAC,qBAAD,CAAuB,QAAvB;AAAgC,IAAA,KAAK,EAAEA;AAAvC,KACGD,QADH,CADF;AAKD,CAZM;AAcP,OAAO,IAAME,iBAAiB,GAAG,MAAM;AACrC,MAAMC,OAAO,GAAGN,UAAU,CAACC,qBAAD,CAA1B;AAEA,MAAI,CAACK,OAAL,EACE,MAAM,IAAIC,KAAJ,CACJ,8DADI,CAAN;AAIF,SAAOD,OAAP;AACD,CATM","sourcesContent":["import React, { createContext, useContext } from 'react'\nimport type { PaypalVerifyPaymentDataResponseDTO as Response } from '@sentecacommerce/sdk'\n\nconst PaypalResponseContext = createContext<Response | {}>({})\n\nexport const PaypalResponseProvider = ({\n children,\n response,\n}: {\n children: any\n response: Response | {}\n}) => {\n return (\n <PaypalResponseContext.Provider value={response}>\n {children}\n </PaypalResponseContext.Provider>\n )\n}\n\nexport const usePaypalResponse = () => {\n const context = useContext(PaypalResponseContext)\n\n if (!context)\n throw new Error(\n 'usePaypalResponse hook must be within PaypalResponseProvider'\n )\n\n return context\n}\n"],"file":"PaypalResponseContext.js"}
@@ -1,2 +1,3 @@
1
1
  export * from './BoricaResponseContext';
2
+ export * from './PaypalResponseContext';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/checkout/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAd","sourcesContent":["export * from './BoricaResponseContext'"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/checkout/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAd;AACA,cAAc,yBAAd","sourcesContent":["export * from './BoricaResponseContext'\nexport * from './PaypalResponseContext'\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/checkout/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAAd","sourcesContent":["export * from './useVerifyBoricaResponse'"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/checkout/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAAd","sourcesContent":["export * from './useVerifyBoricaResponse'\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/checkout/hooks/useVerifyBoricaResponse.ts"],"names":["useBoricaResponse","useVerifyBoricaResponseQuery","useVerifyBoricaResponse","res"],"mappings":"AAAA,SAASA,iBAAT,EAA4BC,4BAA5B,QAAgE,IAAhE;AAEA,OAAO,IAAMC,uBAAuB,GAAG,MAAM;AAC3C,MAAMC,GAAG,GAAGH,iBAAiB,EAA7B;AAEA,SAAOC,4BAA4B,CAACE,GAAD,CAAnC;AACD,CAJM","sourcesContent":["import { useBoricaResponse, useVerifyBoricaResponseQuery } from '..'\n\nexport const useVerifyBoricaResponse = () => {\n const res = useBoricaResponse();\n\n return useVerifyBoricaResponseQuery(res)\n}\n"],"file":"useVerifyBoricaResponse.js"}
1
+ {"version":3,"sources":["../../../../src/checkout/hooks/useVerifyBoricaResponse.ts"],"names":["useBoricaResponse","useVerifyBoricaResponseQuery","useVerifyBoricaResponse","res"],"mappings":"AACA,SAASA,iBAAT,EAA4BC,4BAA5B,QAAgE,IAAhE;AAEA,OAAO,IAAMC,uBAAuB,GAAG,MAAM;AAC3C,MAAMC,GAAG,GAAGH,iBAAiB,EAA7B;AACA,SAAOC,4BAA4B,CAACE,GAAD,CAAnC;AACD,CAHM","sourcesContent":["import { BoricaVerifyPaymentDataRequest } from '@sentecacommerce/sdk'\nimport { useBoricaResponse, useVerifyBoricaResponseQuery } from '..'\n\nexport const useVerifyBoricaResponse = () => {\n const res = useBoricaResponse()\n return useVerifyBoricaResponseQuery(res as BoricaVerifyPaymentDataRequest)\n}\n"],"file":"useVerifyBoricaResponse.js"}
@@ -0,0 +1,12 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import { MyPaymentsPaypalCaptureOrder as captureOrder } from '@sentecacommerce/sdk';
3
+ export var capturePaypalOrder = /*#__PURE__*/function () {
4
+ var _ref = _asyncToGenerator(function* (res) {
5
+ return captureOrder(res);
6
+ });
7
+
8
+ return function capturePaypalOrder(_x) {
9
+ return _ref.apply(this, arguments);
10
+ };
11
+ }();
12
+ //# sourceMappingURL=capturePaypalOrder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/checkout/ssr/capturePaypalOrder.ts"],"names":["MyPaymentsPaypalCaptureOrder","captureOrder","capturePaypalOrder","res"],"mappings":";AAAA,SAASA,4BAA4B,IAAIC,YAAzC,QAA6D,sBAA7D;AAGA,OAAO,IAAMC,kBAAkB;AAAA,+BAAG,WAAOC,GAAP,EAAwC;AACxE,WAAOF,YAAY,CAACE,GAAD,CAAnB;AACD,GAF8B;;AAAA,kBAAlBD,kBAAkB;AAAA;AAAA;AAAA,GAAxB","sourcesContent":["import { MyPaymentsPaypalCaptureOrder as captureOrder } from '@sentecacommerce/sdk'\nimport { PaypalCaptureRequestDTO } from '@sentecacommerce/sdk'\n\nexport const capturePaypalOrder = async (res: PaypalCaptureRequestDTO) => {\n return captureOrder(res)\n}\n"],"file":"capturePaypalOrder.js"}
@@ -1,2 +1,3 @@
1
1
  export * from './verifyBoricaResponse';
2
+ export * from './capturePaypalOrder';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/checkout/ssr/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAd","sourcesContent":["export * from './verifyBoricaResponse'"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/checkout/ssr/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAd;AACA,cAAc,sBAAd","sourcesContent":["export * from './verifyBoricaResponse'\nexport * from './capturePaypalOrder'\n"],"file":"index.js"}
@@ -8,7 +8,7 @@ import { useCheckoutSubmit } from '../../hooks/useCheckoutSubmit';
8
8
  import { defaultShippingValidations, genericBillingAddressValidation } from './utils';
9
9
  import { usersApi } from '../../api/usersApi';
10
10
  import { useCheckoutShippingModule } from '../../hooks/useCheckoutShippingModule';
11
- import { BoricaRedirect, CheckoutFormCustomStateProvider } from './Components';
11
+ import { CheckoutFormCustomStateProvider, BoricaRedirect } from './Components';
12
12
  import { useScrollTo } from '../../hooks/ui-hooks';
13
13
  import { getElementOffset } from '../../utils/getElementOffset';
14
14
  export var CheckoutFormContext = /*#__PURE__*/createContext({});
@@ -138,10 +138,19 @@ export function CheckoutFormContextProvider(_ref) {
138
138
  }, redirectTimeout);
139
139
  };
140
140
 
141
+ var onBeforePaypalRedirect = data => {
142
+ onBeforeRedirect == null ? void 0 : onBeforeRedirect();
143
+ setIsRedirecting(true);
144
+ setTimeout(() => {
145
+ window.location.replace(data.redirectUrl);
146
+ }, redirectTimeout);
147
+ };
148
+
141
149
  var {
142
150
  handleCheckoutSubmit
143
151
  } = useCheckoutSubmit({
144
152
  onBeforeBoricaRedirect,
153
+ onBeforePaypalRedirect,
145
154
  onSuccess,
146
155
  onError: errors => {
147
156
  updateServerErrors(errors);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/contexts/CheckoutForm/index.tsx"],"names":["React","createContext","useCallback","useContext","useMemo","useState","myCartApi","useBilling","usePayment","useShipping","useIsAuthenticated","useCheckoutSubmit","defaultShippingValidations","genericBillingAddressValidation","usersApi","useCheckoutShippingModule","BoricaRedirect","CheckoutFormCustomStateProvider","useScrollTo","getElementOffset","CheckoutFormContext","CheckoutFormContextProvider","children","defaultStep","errorLabels","enableSavedAddressList","withPersistBeforePageLeave","shippingValidations","validateBillingAddress","enableSaveBillingAddress","enableSavedBillingAddressList","countryCode","enableSaveAddress","autofillShippingPersonalData","onSubmit","paymentEnabledOnStep","getPaymentMethodsWhenShippingMethodIsSelected","shippingEnabledOnStep","billingEnabledOnStep","customState","initialCustomState","redirectTimeout","onBeforeRedirect","onSuccess","onError","isBoricaInDevMode","withPixelMeta","requiredFieldsOnShippingStep","requiredFieldsOnBillingAddressStep","enableNoShippingMethodMode","orderQuery","useGet","boricaData","setBoricaData","step","setStep","isRedirecting","setIsRedirecting","fieldsWithError","serverErrors","setServerErrors","collectFieldsWithError","error","push","handleStepChange","newStep","window","scrollTo","updateServerErrors","errors","formattedErrors","reduce","data","code","response","internalError","isAuthenticated","isShippingEnabled","userQuery","enabled","shippingState","Boolean","validations","requiredFields","mod","getIsPaymentMethodsEnabled","moduleKey","moduleData","methodKey","paymentState","billingState","withSavedBillingAddressList","requiredFieldsOnShipping","onBeforeBoricaRedirect","setTimeout","handleCheckoutSubmit","withMeta","scrollToFirstError","interval","setInterval","errorElement","top","clearInterval","handleSubmit","e","preventDefault","Promise","all","persistShippingAddress","persistBillingAddress","catch","isShippingValid","isValid","setIsShippingSubmitting","updateIsSubmitting","isBillingValid","setIsBillingSubmitting","isPaymentValid","setIsPaymentSubmitting","updateStep","saveOrder","shippingAddress","state","errorRef","errorFields","CheckoutFormStepsEnum","useCheckoutFormStep","context","Error","currentStep","useCheckoutFormOrder","useCheckoutFormErrorLabels","useCheckoutFormServerErrors","useCheckoutFormBillingState","useCheckoutFormShippingState","useCheckoutErrorFields","useCheckoutFormPaymentState"],"mappings":";;AAAA,OAAOA,KAAP,IACEC,aADF,EAEEC,WAFF,EAGEC,UAHF,EAIEC,OAJF,EAKEC,QALF,QAMO,OANP;AAaA,SAASC,SAAT,QAA0B,qBAA1B;AACA,SACEC,UADF,EAGEC,UAHF,EAKEC,WALF,QAOO,SAPP;AAQA,SAASC,kBAAT,QAAmC,kBAAnC;AACA,SAASC,iBAAT,QAAkC,+BAAlC;AAEA,SAEEC,0BAFF,EAGEC,+BAHF,QAKO,SALP;AAMA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,yBAAT,QAA0C,uCAA1C;AACA,SAASC,cAAT,EAAyBC,+BAAzB,QAAgE,cAAhE;AACA,SAASC,WAAT,QAA4B,sBAA5B;AACA,SAASC,gBAAT,QAAiC,8BAAjC;AAEA,OAAO,IAAMC,mBAAmB,gBAAGnB,aAAa,CAC9C,EAD8C,CAAzC;AAMP,OAAO,SAASoB,2BAAT,OAmCG;AAAA,MAnCkC;AAC1CC,IAAAA,QAD0C;AAE1CC,IAAAA,WAF0C;AAG1CC,IAAAA,WAH0C;AAI1CC,IAAAA,sBAJ0C;AAK1CC,IAAAA,0BAL0C;AAM1CC,IAAAA,mBAAmB,GAAGf,0BANoB;AAO1CgB,IAA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H,UAAU,CAACiB,mBAAD,CAA1B;;AAEA,MAAI,CAAC2G,OAAL,EAAc;AACZ,UAAM,IAAIC,KAAJ,CACJ,+EADI,CAAN;AAGD;;AAED,SAAOD,OAAO,CAACtC,YAAf;AACD,CAVM","sourcesContent":["import React, {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n} from 'react'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n AddressDTO,\n} from '@sentecacommerce/sdk'\nimport { MutateFunction, QueryResult } from 'react-query'\nimport { myCartApi } from '../../api/myCartApi'\nimport {\n useBilling,\n UseBillingResultType,\n usePayment,\n UsePaymentResultType,\n useShipping,\n UseShippingResultType,\n} from './hooks'\nimport { useIsAuthenticated } from '../../user/hooks'\nimport { useCheckoutSubmit } from '../../hooks/useCheckoutSubmit'\n\nimport {\n ShippingValidationsType,\n defaultShippingValidations,\n genericBillingAddressValidation,\n BillingAddressValidationType,\n} from './utils'\nimport { usersApi } from '../../api/usersApi'\nimport { useCheckoutShippingModule } from '../../hooks/useCheckoutShippingModule'\nimport { BoricaRedirect, CheckoutFormCustomStateProvider } from './Components'\nimport { useScrollTo } from '../../hooks/ui-hooks'\nimport { getElementOffset } from '../../utils/getElementOffset'\n\nexport const CheckoutFormContext = createContext<CheckoutFormContextType>(\n {} as any\n)\n\nexport type CheckoutCustomState = {}\n\nexport function CheckoutFormContextProvider({\n children,\n defaultStep,\n errorLabels,\n enableSavedAddressList,\n withPersistBeforePageLeave,\n shippingValidations = defaultShippingValidations,\n validateBillingAddress = genericBillingAddressValidation,\n enableSaveBillingAddress,\n enableSavedBillingAddressList,\n countryCode,\n enableSaveAddress,\n autofillShippingPersonalData,\n onSubmit,\n\n paymentEnabledOnStep,\n getPaymentMethodsWhenShippingMethodIsSelected,\n shippingEnabledOnStep,\n billingEnabledOnStep,\n\n customState: initialCustomState = {},\n redirectTimeout = 420,\n onBeforeRedirect,\n onSuccess,\n onError,\n isBoricaInDevMode,\n withPixelMeta = false,\n requiredFieldsOnShippingStep = [\n 'firstName',\n 'lastName',\n 'email',\n 'phoneNumber',\n ],\n requiredFieldsOnBillingAddressStep = ['city', 'postalCode', 'streetName'],\n enableNoShippingMethodMode = false,\n}: Props) {\n const orderQuery = myCartApi.useGet()\n const [\n boricaData,\n setBoricaData,\n ] = useState<BoricaGeneratePaymentDataResponse | null>(null)\n\n const [step, setStep] = useState<CheckoutFormStepsEnum>(defaultStep)\n const [isRedirecting, setIsRedirecting] = useState(false)\n\n const fieldsWithError: HTMLElement[] = []\n\n const [serverErrors, setServerErrors] = useState<ServerErrors>(null)\n\n const collectFieldsWithError = (error: HTMLElement) => {\n fieldsWithError.push(error)\n }\n\n const handleStepChange = useCallback((newStep: CheckoutFormStepsEnum) => {\n window.scrollTo(0, 0)\n\n setStep(newStep)\n }, [])\n\n const updateServerErrors = useCallback((errors: any[]) => {\n // Example Error\n // [{\n // code: \"OutOfStock\"\n // message: \"Some of the ordered line items are out of stock at the time of placing the order.\"\n // responses: {\n // availableQuantity: 1\n // sku: \"200000095849\"\n // status: \"unavailable\"\n // }\n // }]\n const formattedErrors = errors?.reduce?.(\n (data: ServerErrors, error: any) => {\n return {\n ...data,\n [error?.code || 'internal']: error?.response,\n }\n },\n {}\n )\n setServerErrors(formattedErrors || { internalError: errors })\n }, [])\n\n const { isAuthenticated } = useIsAuthenticated()\n\n const isShippingEnabled = shippingEnabledOnStep === step\n\n const userQuery = usersApi.useGet(\n {},\n { enabled: isShippingEnabled && autofillShippingPersonalData }\n )\n\n const shippingState = useShipping({\n errorLabels,\n orderQuery,\n enableSavedAddressList: Boolean(isAuthenticated && enableSavedAddressList),\n enableSaveAddress: Boolean(isAuthenticated && enableSaveAddress),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n validations: shippingValidations,\n autofillShippingPersonalData: Boolean(\n isAuthenticated && autofillShippingPersonalData\n ),\n userQuery,\n enabled: isShippingEnabled,\n countryCode,\n requiredFields: requiredFieldsOnShippingStep,\n enableNoShippingMethodMode,\n })\n const mod = useCheckoutShippingModule(orderQuery, !enableNoShippingMethodMode)\n\n const getIsPaymentMethodsEnabled = () => {\n if (paymentEnabledOnStep) {\n return paymentEnabledOnStep === step\n }\n\n if (\n !enableNoShippingMethodMode &&\n getPaymentMethodsWhenShippingMethodIsSelected\n ) {\n return Boolean(mod?.moduleKey && mod?.moduleData.methodKey)\n }\n\n return false\n }\n\n const paymentState = usePayment({\n errorLabels,\n orderQuery,\n enabled: getIsPaymentMethodsEnabled(),\n })\n\n const billingState = useBilling({\n errorLabels,\n orderQuery,\n validateBillingAddress,\n enableSaveBillingAddress: Boolean(\n isAuthenticated && enableSaveBillingAddress\n ),\n withSavedBillingAddressList: Boolean(\n isAuthenticated && enableSavedBillingAddressList\n ),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n countryCode,\n enabled: billingEnabledOnStep === step,\n requiredFields: requiredFieldsOnBillingAddressStep,\n requiredFieldsOnShipping: requiredFieldsOnShippingStep,\n })\n\n const onBeforeBoricaRedirect = (data: BoricaGeneratePaymentDataResponse) => {\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setBoricaData(data)\n }, redirectTimeout)\n }\n\n const { handleCheckoutSubmit } = useCheckoutSubmit({\n onBeforeBoricaRedirect,\n onSuccess,\n onError: (errors: any) => {\n updateServerErrors(errors)\n onError(errors)\n },\n withMeta: withPixelMeta,\n })\n\n const { scrollTo } = useScrollTo(fieldsWithError[0], 0)\n\n const scrollToFirstError = () => {\n const interval = setInterval(() => {\n const errorElement = fieldsWithError[0]\n if (!errorElement) return\n\n scrollTo(getElementOffset(errorElement).top - 100)\n clearInterval(interval)\n }, 50)\n\n setTimeout(() => {\n clearInterval(interval)\n }, 1000)\n }\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n\n await Promise.all([\n shippingState.persistShippingAddress(),\n billingState.persistBillingAddress(),\n ]).catch(() => {})\n\n onSubmit({\n isShippingValid: shippingState.isValid,\n setIsShippingSubmitting: shippingState.updateIsSubmitting,\n isBillingValid: billingState.isValid,\n setIsBillingSubmitting: billingState.updateIsSubmitting,\n isPaymentValid: paymentState.isValid,\n setIsPaymentSubmitting: paymentState.updateIsSubmitting,\n step,\n updateStep: setStep,\n saveOrder: handleCheckoutSubmit,\n updateServerErrors,\n scrollToFirstError,\n shippingState,\n shippingAddress: shippingState.data,\n })\n }\n\n const state = {\n setStep: handleStepChange,\n step,\n orderQuery,\n serverErrors,\n updateServerErrors,\n errorLabels,\n shippingState,\n paymentState,\n billingState,\n errorRef: collectFieldsWithError,\n errorFields: fieldsWithError,\n }\n\n return (\n <CheckoutFormContext.Provider value={state}>\n <CheckoutFormCustomStateProvider initialCustomState={initialCustomState}>\n <>\n <form noValidate onSubmit={handleSubmit}>\n {children}\n </form>\n {!!boricaData && (\n <BoricaRedirect\n isInDevMode={isBoricaInDevMode}\n formData={boricaData}\n />\n )}\n </>\n </CheckoutFormCustomStateProvider>\n </CheckoutFormContext.Provider>\n )\n}\n\nexport type CheckoutFormOnSubmitData = {\n isShippingValid: boolean\n setIsShippingSubmitting: (value: boolean) => void\n isBillingValid: boolean\n setIsBillingSubmitting: (value: boolean) => void\n isPaymentValid: boolean\n setIsPaymentSubmitting: (value: boolean) => void\n step: CheckoutFormStepsEnum\n updateStep: (step: CheckoutFormStepsEnum) => void\n saveOrder: MutateFunction<OrderDTO, unknown, any, unknown>\n\n updateServerErrors: (errors: any) => void\n scrollToFirstError: () => void\n shippingState: UseShippingResultType\n shippingAddress?: AddressDTO\n}\n\ntype Props = {\n children: any\n defaultStep: CheckoutFormStepsEnum\n errorLabels: CheckoutFormErrorLabelsType\n withPersistBeforePageLeave: boolean\n countryCode: string\n onSubmit: (data: CheckoutFormOnSubmitData) => void\n onError: (error: any) => void\n onSuccess: (order: OrderDTO) => void\n\n redirectTimeout?: number\n onBeforeRedirect?: () => void\n\n customState?: CheckoutCustomState\n\n enableSavedAddressList: boolean\n shippingValidations?: ShippingValidationsType\n enableSaveAddress: boolean\n autofillShippingPersonalData: boolean\n autoSelectDefaultShippingAddress: boolean\n\n enableSaveBillingAddress: boolean\n validateBillingAddress?: BillingAddressValidationType\n enableSavedBillingAddressList: boolean\n autoSelectDefaultBillingAddress: boolean\n\n paymentEnabledOnStep?: CheckoutFormStepsEnum\n getPaymentMethodsWhenShippingMethodIsSelected?: boolean\n\n shippingEnabledOnStep: CheckoutFormStepsEnum\n\n billingEnabledOnStep: CheckoutFormStepsEnum\n\n isBoricaInDevMode?: boolean\n\n withPixelMeta?: boolean\n requiredFieldsOnShippingStep?: string[]\n requiredFieldsOnBillingAddressStep?: string[]\n enableNoShippingMethodMode?: boolean\n}\n\ntype ServerErrors = { [key: string]: any } | null\n\nexport enum CheckoutFormStepsEnum {\n Basket = 'Basket',\n Shipping = 'Shipping',\n BillingAddress = 'BillingAddress',\n Payment = 'Payment',\n Preview = 'Preview',\n All = 'All',\n}\n\nexport type CheckoutFormErrorsResultType =\n | {\n [key: string]: string\n }\n | null\n | undefined\n\nexport type ShippingFormErrorLabels = {\n fieldIsRequired: string\n\n fillStreetNumberBuildingEntranceOrApartment: string\n streetIsRequired: string\n invalidPhoneNumber?: string\n quarterIsRequired: string\n cantFindStreetOrQuarterMessage: string\n cityIsRequired: string\n emailIsRequired: string\n officeIsRequired: string\n selectCourier: string\n\n noStoreSelected: string\n}\n\nexport type CheckoutFormErrorLabelsType = ShippingFormErrorLabels & {\n selectPaymentMethod: string\n}\n\nexport type CheckoutFormContextType = {\n setStep: (step: CheckoutFormStepsEnum) => void\n step: CheckoutFormStepsEnum\n serverErrors: ServerErrors\n updateServerErrors: (errors: any) => void\n errorRef: (error: HTMLElement) => void\n errorFields: HTMLElement[]\n errorLabels: CheckoutFormErrorLabelsType\n orderQuery: QueryResult<OrderDTO, unknown>\n shippingState: UseShippingResultType\n paymentState: UsePaymentResultType\n billingState: UseBillingResultType\n}\n\nexport const useCheckoutFormStep = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormStep must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n currentStep: context.step,\n updateStep: context.setStep,\n }\n }, [context])\n}\n\nexport const useCheckoutFormOrder = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormOrder must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.orderQuery\n}\n\nexport const useCheckoutFormErrorLabels = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormErrorLabels must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.errorLabels\n}\n\nexport const useCheckoutFormServerErrors = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormServerErrors must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n serverErrors: context.serverErrors,\n updateServerErrors: context.updateServerErrors,\n }\n }, [context])\n}\n\nexport const useCheckoutFormBillingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormBillingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.billingState\n}\n\nexport const useCheckoutFormShippingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormShippingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.shippingState\n}\n\nexport const useCheckoutErrorFields = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutErrorFields must be used within a CheckoutFormContextProvider'\n )\n }\n\n return {\n errorFields: context.errorFields,\n errorRef: context.errorRef,\n }\n}\n\nexport const useCheckoutFormPaymentState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormPaymentState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.paymentState\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/contexts/CheckoutForm/index.tsx"],"names":["React","createContext","useCallback","useContext","useMemo","useState","myCartApi","useBilling","usePayment","useShipping","useIsAuthenticated","useCheckoutSubmit","defaultShippingValidations","genericBillingAddressValidation","usersApi","useCheckoutShippingModule","CheckoutFormCustomStateProvider","BoricaRedirect","useScrollTo","getElementOffset","CheckoutFormContext","CheckoutFormContextProvider","children","defaultStep","errorLabels","enableSavedAddressList","withPersistBeforePageLeave","shippingValidations","validateBillingAddress","enableSaveBillingAddress","enableSavedBillingAddressList","countryCode","enableSaveAddress","autofillShippingPersonalData","onSubmit","paymentEnabledOnStep","getPaymentMethodsWhenShippingMethodIsSelected","shippingEnabledOnStep","billingEnabledOnStep","customState","initialCustomState","redirectTimeout","onBeforeRedirect","onSuccess","onError","isBoricaInDevMode","withPixelMeta","requiredFieldsOnShippingStep","requiredFieldsOnBillingAddressStep","enableNoShippingMethodMode","orderQuery","useGet","boricaData","setBoricaData","step","setStep","isRedirecting","setIsRedirecting","fieldsWithError","serverErrors","setServerErrors","collectFieldsWithError","error","push","handleStepChange","newStep","window","scrollTo","updateServerErrors","errors","formattedErrors","reduce","data","code","response","internalError","isAuthenticated","isShippingEnabled","userQuery","enabled","shippingState","Boolean","validations","requiredFields","mod","getIsPaymentMethodsEnabled","moduleKey","moduleData","methodKey","paymentState","billingState","withSavedBillingAddressList","requiredFieldsOnShipping","onBeforeBoricaRedirect","setTimeout","onBeforePaypalRedirect","location","replace","redirectUrl","handleCheckoutSubmit","withMeta","scrollToFirstError","interval","setInterval","errorElement","top","clearInterval","handleSubmit","e","preventDefault","Promise","all","persistShippingAddress","persistBillingAddress","catch","isShippingValid","isValid","setIsShippingSubmitting","updateIsSubmitting","isBillingValid","setIsBillingSubmitting","isPaymentValid","setIsPaymentSubmitting","updateStep","saveOrder","shippingAddress","state","errorRef","errorFields","CheckoutFormStepsEnum","useCheckoutFormStep","context","Error","currentStep","useCheckoutFormOrder","useCheckoutFormErrorLabels","useCheckoutFormServerErrors","useCheckout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ACJ,+EADI,CAAN;AAGD;;AAED,SAAOD,OAAO,CAAC1C,YAAf;AACD,CAVM","sourcesContent":["import React, {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n} from 'react'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n AddressDTO,\n PaypalGeneratePaymentUrlResponseDTO,\n} from '@sentecacommerce/sdk'\nimport { MutateFunction, QueryResult } from 'react-query'\nimport { myCartApi } from '../../api/myCartApi'\nimport {\n useBilling,\n UseBillingResultType,\n usePayment,\n UsePaymentResultType,\n useShipping,\n UseShippingResultType,\n} from './hooks'\nimport { useIsAuthenticated } from '../../user/hooks'\nimport { useCheckoutSubmit } from '../../hooks/useCheckoutSubmit'\n\nimport {\n ShippingValidationsType,\n defaultShippingValidations,\n genericBillingAddressValidation,\n BillingAddressValidationType,\n} from './utils'\nimport { usersApi } from '../../api/usersApi'\nimport { useCheckoutShippingModule } from '../../hooks/useCheckoutShippingModule'\nimport { CheckoutFormCustomStateProvider, BoricaRedirect } from './Components'\nimport { useScrollTo } from '../../hooks/ui-hooks'\nimport { getElementOffset } from '../../utils/getElementOffset'\n\nexport const CheckoutFormContext = createContext<CheckoutFormContextType>(\n {} as any\n)\n\nexport type CheckoutCustomState = {}\n\nexport function CheckoutFormContextProvider({\n children,\n defaultStep,\n errorLabels,\n enableSavedAddressList,\n withPersistBeforePageLeave,\n shippingValidations = defaultShippingValidations,\n validateBillingAddress = genericBillingAddressValidation,\n enableSaveBillingAddress,\n enableSavedBillingAddressList,\n countryCode,\n enableSaveAddress,\n autofillShippingPersonalData,\n onSubmit,\n\n paymentEnabledOnStep,\n getPaymentMethodsWhenShippingMethodIsSelected,\n shippingEnabledOnStep,\n billingEnabledOnStep,\n\n customState: initialCustomState = {},\n redirectTimeout = 420,\n onBeforeRedirect,\n onSuccess,\n onError,\n isBoricaInDevMode,\n withPixelMeta = false,\n requiredFieldsOnShippingStep = [\n 'firstName',\n 'lastName',\n 'email',\n 'phoneNumber',\n ],\n requiredFieldsOnBillingAddressStep = ['city', 'postalCode', 'streetName'],\n enableNoShippingMethodMode = false,\n}: Props) {\n const orderQuery = myCartApi.useGet()\n const [\n boricaData,\n setBoricaData,\n ] = useState<BoricaGeneratePaymentDataResponse | null>(null)\n const [step, setStep] = useState<CheckoutFormStepsEnum>(defaultStep)\n const [isRedirecting, setIsRedirecting] = useState(false)\n\n const fieldsWithError: HTMLElement[] = []\n\n const [serverErrors, setServerErrors] = useState<ServerErrors>(null)\n\n const collectFieldsWithError = (error: HTMLElement) => {\n fieldsWithError.push(error)\n }\n\n const handleStepChange = useCallback((newStep: CheckoutFormStepsEnum) => {\n window.scrollTo(0, 0)\n\n setStep(newStep)\n }, [])\n\n const updateServerErrors = useCallback((errors: any[]) => {\n // Example Error\n // [{\n // code: \"OutOfStock\"\n // message: \"Some of the ordered line items are out of stock at the time of placing the order.\"\n // responses: {\n // availableQuantity: 1\n // sku: \"200000095849\"\n // status: \"unavailable\"\n // }\n // }]\n const formattedErrors = errors?.reduce?.(\n (data: ServerErrors, error: any) => {\n return {\n ...data,\n [error?.code || 'internal']: error?.response,\n }\n },\n {}\n )\n setServerErrors(formattedErrors || { internalError: errors })\n }, [])\n\n const { isAuthenticated } = useIsAuthenticated()\n\n const isShippingEnabled = shippingEnabledOnStep === step\n\n const userQuery = usersApi.useGet(\n {},\n { enabled: isShippingEnabled && autofillShippingPersonalData }\n )\n\n const shippingState = useShipping({\n errorLabels,\n orderQuery,\n enableSavedAddressList: Boolean(isAuthenticated && enableSavedAddressList),\n enableSaveAddress: Boolean(isAuthenticated && enableSaveAddress),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n validations: shippingValidations,\n autofillShippingPersonalData: Boolean(\n isAuthenticated && autofillShippingPersonalData\n ),\n userQuery,\n enabled: isShippingEnabled,\n countryCode,\n requiredFields: requiredFieldsOnShippingStep,\n enableNoShippingMethodMode,\n })\n const mod = useCheckoutShippingModule(orderQuery, !enableNoShippingMethodMode)\n\n const getIsPaymentMethodsEnabled = () => {\n if (paymentEnabledOnStep) {\n return paymentEnabledOnStep === step\n }\n\n if (\n !enableNoShippingMethodMode &&\n getPaymentMethodsWhenShippingMethodIsSelected\n ) {\n return Boolean(mod?.moduleKey && mod?.moduleData.methodKey)\n }\n\n return false\n }\n\n const paymentState = usePayment({\n errorLabels,\n orderQuery,\n enabled: getIsPaymentMethodsEnabled(),\n })\n\n const billingState = useBilling({\n errorLabels,\n orderQuery,\n validateBillingAddress,\n enableSaveBillingAddress: Boolean(\n isAuthenticated && enableSaveBillingAddress\n ),\n withSavedBillingAddressList: Boolean(\n isAuthenticated && enableSavedBillingAddressList\n ),\n withPersistBeforePageLeave: !isRedirecting && withPersistBeforePageLeave,\n countryCode,\n enabled: billingEnabledOnStep === step,\n requiredFields: requiredFieldsOnBillingAddressStep,\n requiredFieldsOnShipping: requiredFieldsOnShippingStep,\n })\n\n const onBeforeBoricaRedirect = (data: BoricaGeneratePaymentDataResponse) => {\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n setBoricaData(data)\n }, redirectTimeout)\n }\n\n const onBeforePaypalRedirect = (\n data: PaypalGeneratePaymentUrlResponseDTO\n ) => {\n onBeforeRedirect?.()\n setIsRedirecting(true)\n setTimeout(() => {\n window.location.replace(data.redirectUrl)\n }, redirectTimeout)\n }\n const { handleCheckoutSubmit } = useCheckoutSubmit({\n onBeforeBoricaRedirect,\n onBeforePaypalRedirect,\n onSuccess,\n onError: (errors: any) => {\n updateServerErrors(errors)\n onError(errors)\n },\n withMeta: withPixelMeta,\n })\n\n const { scrollTo } = useScrollTo(fieldsWithError[0], 0)\n\n const scrollToFirstError = () => {\n const interval = setInterval(() => {\n const errorElement = fieldsWithError[0]\n if (!errorElement) return\n\n scrollTo(getElementOffset(errorElement).top - 100)\n clearInterval(interval)\n }, 50)\n\n setTimeout(() => {\n clearInterval(interval)\n }, 1000)\n }\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault()\n\n await Promise.all([\n shippingState.persistShippingAddress(),\n billingState.persistBillingAddress(),\n ]).catch(() => {})\n\n onSubmit({\n isShippingValid: shippingState.isValid,\n setIsShippingSubmitting: shippingState.updateIsSubmitting,\n isBillingValid: billingState.isValid,\n setIsBillingSubmitting: billingState.updateIsSubmitting,\n isPaymentValid: paymentState.isValid,\n setIsPaymentSubmitting: paymentState.updateIsSubmitting,\n step,\n updateStep: setStep,\n saveOrder: handleCheckoutSubmit,\n updateServerErrors,\n scrollToFirstError,\n shippingState,\n shippingAddress: shippingState.data,\n })\n }\n\n const state = {\n setStep: handleStepChange,\n step,\n orderQuery,\n serverErrors,\n updateServerErrors,\n errorLabels,\n shippingState,\n paymentState,\n billingState,\n errorRef: collectFieldsWithError,\n errorFields: fieldsWithError,\n }\n\n return (\n <CheckoutFormContext.Provider value={state}>\n <CheckoutFormCustomStateProvider initialCustomState={initialCustomState}>\n <>\n <form noValidate onSubmit={handleSubmit}>\n {children}\n </form>\n {!!boricaData && (\n <BoricaRedirect\n isInDevMode={isBoricaInDevMode}\n formData={boricaData}\n />\n )}\n </>\n </CheckoutFormCustomStateProvider>\n </CheckoutFormContext.Provider>\n )\n}\n\nexport type CheckoutFormOnSubmitData = {\n isShippingValid: boolean\n setIsShippingSubmitting: (value: boolean) => void\n isBillingValid: boolean\n setIsBillingSubmitting: (value: boolean) => void\n isPaymentValid: boolean\n setIsPaymentSubmitting: (value: boolean) => void\n step: CheckoutFormStepsEnum\n updateStep: (step: CheckoutFormStepsEnum) => void\n saveOrder: MutateFunction<OrderDTO, unknown, any, unknown>\n\n updateServerErrors: (errors: any) => void\n scrollToFirstError: () => void\n shippingState: UseShippingResultType\n shippingAddress?: AddressDTO\n}\n\ntype Props = {\n children: any\n defaultStep: CheckoutFormStepsEnum\n errorLabels: CheckoutFormErrorLabelsType\n withPersistBeforePageLeave: boolean\n countryCode: string\n onSubmit: (data: CheckoutFormOnSubmitData) => void\n onError: (error: any) => void\n onSuccess: (order: OrderDTO) => void\n\n redirectTimeout?: number\n onBeforeRedirect?: () => void\n\n customState?: CheckoutCustomState\n\n enableSavedAddressList: boolean\n shippingValidations?: ShippingValidationsType\n enableSaveAddress: boolean\n autofillShippingPersonalData: boolean\n autoSelectDefaultShippingAddress: boolean\n\n enableSaveBillingAddress: boolean\n validateBillingAddress?: BillingAddressValidationType\n enableSavedBillingAddressList: boolean\n autoSelectDefaultBillingAddress: boolean\n\n paymentEnabledOnStep?: CheckoutFormStepsEnum\n getPaymentMethodsWhenShippingMethodIsSelected?: boolean\n\n shippingEnabledOnStep: CheckoutFormStepsEnum\n\n billingEnabledOnStep: CheckoutFormStepsEnum\n\n isBoricaInDevMode?: boolean\n\n withPixelMeta?: boolean\n requiredFieldsOnShippingStep?: string[]\n requiredFieldsOnBillingAddressStep?: string[]\n enableNoShippingMethodMode?: boolean\n}\n\ntype ServerErrors = { [key: string]: any } | null\n\nexport enum CheckoutFormStepsEnum {\n Basket = 'Basket',\n Shipping = 'Shipping',\n BillingAddress = 'BillingAddress',\n Payment = 'Payment',\n Preview = 'Preview',\n All = 'All',\n}\n\nexport type CheckoutFormErrorsResultType =\n | {\n [key: string]: string\n }\n | null\n | undefined\n\nexport type ShippingFormErrorLabels = {\n fieldIsRequired: string\n\n fillStreetNumberBuildingEntranceOrApartment: string\n streetIsRequired: string\n invalidPhoneNumber?: string\n quarterIsRequired: string\n cantFindStreetOrQuarterMessage: string\n cityIsRequired: string\n emailIsRequired: string\n officeIsRequired: string\n selectCourier: string\n\n noStoreSelected: string\n}\n\nexport type CheckoutFormErrorLabelsType = ShippingFormErrorLabels & {\n selectPaymentMethod: string\n}\n\nexport type CheckoutFormContextType = {\n setStep: (step: CheckoutFormStepsEnum) => void\n step: CheckoutFormStepsEnum\n serverErrors: ServerErrors\n updateServerErrors: (errors: any) => void\n errorRef: (error: HTMLElement) => void\n errorFields: HTMLElement[]\n errorLabels: CheckoutFormErrorLabelsType\n orderQuery: QueryResult<OrderDTO, unknown>\n shippingState: UseShippingResultType\n paymentState: UsePaymentResultType\n billingState: UseBillingResultType\n}\n\nexport const useCheckoutFormStep = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormStep must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n currentStep: context.step,\n updateStep: context.setStep,\n }\n }, [context])\n}\n\nexport const useCheckoutFormOrder = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormOrder must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.orderQuery\n}\n\nexport const useCheckoutFormErrorLabels = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormErrorLabels must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.errorLabels\n}\n\nexport const useCheckoutFormServerErrors = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormServerErrors must be used within a CheckoutFormContextProvider'\n )\n }\n\n return useMemo(() => {\n return {\n serverErrors: context.serverErrors,\n updateServerErrors: context.updateServerErrors,\n }\n }, [context])\n}\n\nexport const useCheckoutFormBillingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormBillingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.billingState\n}\n\nexport const useCheckoutFormShippingState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormShippingState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.shippingState\n}\n\nexport const useCheckoutErrorFields = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutErrorFields must be used within a CheckoutFormContextProvider'\n )\n }\n\n return {\n errorFields: context.errorFields,\n errorRef: context.errorRef,\n }\n}\n\nexport const useCheckoutFormPaymentState = () => {\n const context = useContext(CheckoutFormContext)\n\n if (!context) {\n throw new Error(\n 'useCheckoutFormPaymentState must be used within a CheckoutFormContextProvider'\n )\n }\n\n return context.paymentState\n}\n"],"file":"index.js"}
@@ -1,12 +1,13 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import { myOrdersApi, myPaymentsBoricaApi, useDistrictMeta } from '../../';
3
- import { PaymentMethodDTOTypeEnum } from '@sentecacommerce/sdk';
3
+ import { PaymentMethodDTOTypeEnum, MyPaymentsPaypalPayMyOrder } from '@sentecacommerce/sdk';
4
4
  import { useConfigState } from '../useConfig';
5
5
  import { purchase } from '../../analytics/purchase';
6
6
  export var useCheckoutSubmit = (_ref) => {
7
7
  var {
8
8
  onSuccess,
9
9
  onBeforeBoricaRedirect,
10
+ onBeforePaypalRedirect,
10
11
  onError,
11
12
  withMeta
12
13
  } = _ref;
@@ -16,6 +17,7 @@ export var useCheckoutSubmit = (_ref) => {
16
17
  var _ref2 = _asyncToGenerator(function* (result) {
17
18
  // Analytics
18
19
  purchase(result, Config);
20
+ var paypalPayment = result.payments.find(payment => payment.type === PaymentMethodDTOTypeEnum.PaymentServiceProvider && payment.moduleKey === 'Paypal');
19
21
  var boricaPayment = result.payments.find(payment => payment.type === PaymentMethodDTOTypeEnum.PaymentServiceProvider && payment.moduleKey === 'Borica');
20
22
 
21
23
  if (boricaPayment) {
@@ -24,6 +26,9 @@ export var useCheckoutSubmit = (_ref) => {
24
26
  paymentId: boricaPayment._id
25
27
  });
26
28
  onBeforeBoricaRedirect == null ? void 0 : onBeforeBoricaRedirect(boricaResult);
29
+ } else if (paypalPayment) {
30
+ var paypalResponse = yield MyPaymentsPaypalPayMyOrder(result._id, paypalPayment._id);
31
+ onBeforePaypalRedirect == null ? void 0 : onBeforePaypalRedirect(paypalResponse);
27
32
  } else {
28
33
  onSuccess == null ? void 0 : onSuccess(result);
29
34
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/hooks/useCheckoutSubmit/index.ts"],"names":["myOrdersApi","myPaymentsBoricaApi","useDistrictMeta","PaymentMethodDTOTypeEnum","useConfigState","purchase","useCheckoutSubmit","onSuccess","onBeforeBoricaRedirect","onError","withMeta","Config","districtMeta","handleCheckoutSubmit","useCreate","result","boricaPayment","payments","find","payment","type","PaymentServiceProvider","moduleKey","boricaResult","pay","orderId","_id","paymentId"],"mappings":";AAAA,SAASA,WAAT,EAAsBC,mBAAtB,EAA2CC,eAA3C,QAAkE,QAAlE;AACA,SAGEC,wBAHF,QAIO,sBAJP;AAKA,SAASC,cAAT,QAA+B,cAA/B;AACA,SAASC,QAAT,QAAyB,0BAAzB;AAEA,OAAO,IAAMC,iBAAiB,GAAG,UAU3B;AAAA,MAV4B;AAChCC,IAAAA,SADgC;AAEhCC,IAAAA,sBAFgC;AAGhCC,IAAAA,OAHgC;AAIhCC,IAAAA;AAJgC,GAU5B;AACJ,MAAMC,MAAM,GAAGP,cAAc,EAA7B;AAEA,MAAMQ,YAAY,GAAGV,eAAe,EAApC;AAEA,MAAM,CAACW,oBAAD,IAAyBb,WAAW,CAACc,SAAZ,CAC7BJ,QAAQ,GAAGE,YAAH,GAAkB,EADG;AAAA,kCAE7B,WAAOG,MAAP,EAA4B;AAC1B;AACAV,MAAAA,QAAQ,CAACU,MAAD,EAASJ,MAAT,CAAR;AAEA,UAAMK,aAAa,GAAGD,MAAM,CAACE,QAAP,CAAgBC,IAAhB,CACnBC,OAAD,IACEA,OAAO,CAACC,IAAR,KAAiBjB,wBAAwB,CAACkB,sBAA1C,IACAF,OAAO,CAACG,SAAR,KAAsB,QAHJ,CAAtB;;AAMA,UAAIN,aAAJ,EAAmB;AACjB,YAAMO,YAAY,SAAStB,mBAAmB,CAACuB,GAApB,CAAwB;AACjDC,UAAAA,OAAO,EAAEV,MAAM,CAACW,GADiC;AAEjDC,UAAAA,SAAS,EAAEX,aAAa,CAACU;AAFwB,SAAxB,CAA3B;AAIAlB,QAAAA,sBAAsB,QAAtB,YAAAA,sBAAsB,CAAGe,YAAH,CAAtB;AACD,OAND,MAMO;AACLhB,QAAAA,SAAS,QAAT,YAAAA,SAAS,CAAGQ,MAAH,CAAT;AACD;AACF,KArB4B;;AAAA;AAAA;AAAA;AAAA,OAsB7BN,OAtB6B,CAA/B;AAyBA,SAAO;AACLI,IAAAA;AADK,GAAP;AAGD,CA3CM","sourcesContent":["import { myOrdersApi, myPaymentsBoricaApi, useDistrictMeta } from '../../'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n PaymentMethodDTOTypeEnum,\n} from '@sentecacommerce/sdk'\nimport { useConfigState } from '../useConfig'\nimport { purchase } from '../../analytics/purchase'\n\nexport const useCheckoutSubmit = ({\n onSuccess,\n onBeforeBoricaRedirect,\n onError,\n withMeta,\n}: {\n onSuccess?: (result: OrderDTO) => void\n onBeforeBoricaRedirect?: (formData: BoricaGeneratePaymentDataResponse) => void\n onError?: (error: any) => void\n withMeta?: boolean\n}) => {\n const Config = useConfigState()\n\n const districtMeta = useDistrictMeta()\n\n const [handleCheckoutSubmit] = myOrdersApi.useCreate(\n withMeta ? districtMeta : {},\n async (result: OrderDTO) => {\n // Analytics\n purchase(result, Config)\n\n const boricaPayment = result.payments.find(\n (payment) =>\n payment.type === PaymentMethodDTOTypeEnum.PaymentServiceProvider &&\n payment.moduleKey === 'Borica'\n )\n\n if (boricaPayment) {\n const boricaResult = await myPaymentsBoricaApi.pay({\n orderId: result._id,\n paymentId: boricaPayment._id,\n })\n onBeforeBoricaRedirect?.(boricaResult)\n } else {\n onSuccess?.(result)\n }\n },\n onError\n )\n\n return {\n handleCheckoutSubmit,\n }\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../../src/hooks/useCheckoutSubmit/index.ts"],"names":["myOrdersApi","myPaymentsBoricaApi","useDistrictMeta","PaymentMethodDTOTypeEnum","MyPaymentsPaypalPayMyOrder","useConfigState","purchase","useCheckoutSubmit","onSuccess","onBeforeBoricaRedirect","onBeforePaypalRedirect","onError","withMeta","Config","districtMeta","handleCheckoutSubmit","useCreate","result","paypalPayment","payments","find","payment","type","PaymentServiceProvider","moduleKey","boricaPayment","boricaResult","pay","orderId","_id","paymentId","paypalResponse"],"mappings":";AAAA,SAASA,WAAT,EAAsBC,mBAAtB,EAA2CC,eAA3C,QAAkE,QAAlE;AACA,SAGEC,wBAHF,EAIEC,0BAJF,QAKO,sBALP;AAMA,SAASC,cAAT,QAA+B,cAA/B;AACA,SAASC,QAAT,QAAyB,0BAAzB;AAEA,OAAO,IAAMC,iBAAiB,GAAG,UAY3B;AAAA,MAZ4B;AAChCC,IAAAA,SADgC;AAEhCC,IAAAA,sBAFgC;AAGhCC,IAAAA,sBAHgC;AAIhCC,IAAAA,OAJgC;AAKhCC,IAAAA;AALgC,GAY5B;AACJ,MAAMC,MAAM,GAAGR,cAAc,EAA7B;AAEA,MAAMS,YAAY,GAAGZ,eAAe,EAApC;AAEA,MAAM,CAACa,oBAAD,IAAyBf,WAAW,CAACgB,SAAZ,CAC7BJ,QAAQ,GAAGE,YAAH,GAAkB,EADG;AAAA,kCAE7B,WAAOG,MAAP,EAA4B;AAC1B;AACAX,MAAAA,QAAQ,CAACW,MAAD,EAASJ,MAAT,CAAR;AAEA,UAAMK,aAAa,GAAGD,MAAM,CAACE,QAAP,CAAgBC,IAAhB,CACnBC,OAAD,IACEA,OAAO,CAACC,IAAR,KAAiBnB,wBAAwB,CAACoB,sBAA1C,IACAF,OAAO,CAACG,SAAR,KAAsB,QAHJ,CAAtB;AAMA,UAAMC,aAAa,GAAGR,MAAM,CAACE,QAAP,CAAgBC,IAAhB,CACnBC,OAAD,IACEA,OAAO,CAACC,IAAR,KAAiBnB,wBAAwB,CAACoB,sBAA1C,IACAF,OAAO,CAACG,SAAR,KAAsB,QAHJ,CAAtB;;AAMA,UAAIC,aAAJ,EAAmB;AACjB,YAAMC,YAAY,SAASzB,mBAAmB,CAAC0B,GAApB,CAAwB;AACjDC,UAAAA,OAAO,EAAEX,MAAM,CAACY,GADiC;AAEjDC,UAAAA,SAAS,EAAEL,aAAa,CAACI;AAFwB,SAAxB,CAA3B;AAIApB,QAAAA,sBAAsB,QAAtB,YAAAA,sBAAsB,CAAGiB,YAAH,CAAtB;AACD,OAND,MAMO,IAAIR,aAAJ,EAAmB;AACxB,YAAMa,cAAc,SAAS3B,0BAA0B,CACrDa,MAAM,CAACY,GAD8C,EAErDX,aAAa,CAACW,GAFuC,CAAvD;AAKAnB,QAAAA,sBAAsB,QAAtB,YAAAA,sBAAsB,CAAGqB,cAAH,CAAtB;AACD,OAPM,MAOA;AACLvB,QAAAA,SAAS,QAAT,YAAAA,SAAS,CAAGS,MAAH,CAAT;AACD;AACF,KAlC4B;;AAAA;AAAA;AAAA;AAAA,OAmC7BN,OAnC6B,CAA/B;AAsCA,SAAO;AACLI,IAAAA;AADK,GAAP;AAGD,CA1DM","sourcesContent":["import { myOrdersApi, myPaymentsBoricaApi, useDistrictMeta } from '../../'\nimport {\n BoricaGeneratePaymentDataResponse,\n OrderDTO,\n PaymentMethodDTOTypeEnum,\n MyPaymentsPaypalPayMyOrder,\n} from '@sentecacommerce/sdk'\nimport { useConfigState } from '../useConfig'\nimport { purchase } from '../../analytics/purchase'\n\nexport const useCheckoutSubmit = ({\n onSuccess,\n onBeforeBoricaRedirect,\n onBeforePaypalRedirect,\n onError,\n withMeta,\n}: {\n onSuccess?: (result: OrderDTO) => void\n onBeforeBoricaRedirect?: (formData: BoricaGeneratePaymentDataResponse) => void\n onError?: (error: any) => void\n withMeta?: boolean\n onBeforePaypalRedirect: any\n}) => {\n const Config = useConfigState()\n\n const districtMeta = useDistrictMeta()\n\n const [handleCheckoutSubmit] = myOrdersApi.useCreate(\n withMeta ? districtMeta : {},\n async (result: OrderDTO) => {\n // Analytics\n purchase(result, Config)\n\n const paypalPayment = result.payments.find(\n (payment) =>\n payment.type === PaymentMethodDTOTypeEnum.PaymentServiceProvider &&\n payment.moduleKey === 'Paypal'\n )\n\n const boricaPayment = result.payments.find(\n (payment) =>\n payment.type === PaymentMethodDTOTypeEnum.PaymentServiceProvider &&\n payment.moduleKey === 'Borica'\n )\n\n if (boricaPayment) {\n const boricaResult = await myPaymentsBoricaApi.pay({\n orderId: result._id,\n paymentId: boricaPayment._id,\n })\n onBeforeBoricaRedirect?.(boricaResult)\n } else if (paypalPayment) {\n const paypalResponse = await MyPaymentsPaypalPayMyOrder(\n result._id,\n paypalPayment._id\n )\n\n onBeforePaypalRedirect?.(paypalResponse)\n } else {\n onSuccess?.(result)\n }\n },\n onError\n )\n\n return {\n handleCheckoutSubmit,\n }\n}\n"],"file":"index.js"}
@@ -10,12 +10,10 @@ export var getCanonicalUrl = (context, localeData, redirectTo) => {
10
10
  var domain = (localeData == null ? void 0 : localeData.domain) || '';
11
11
  domain = domain[domain.length - 1] === '/' ? domain.slice(0, domain.length - 1) : domain;
12
12
  if (!reqHost || !reqSSL || !domain) return;
13
- var areWeSecured = reqSSL === 'https';
13
+ var areWeSecured = reqSSL === 'true';
14
14
  var [currentPath, queryString] = ((_req$url = req.url) == null ? void 0 : _req$url.split('?')) || ['/'];
15
- console.log('req.headers', req.headers, reqHost, reqSSL, 'redirectTo: ' + redirectTo, 'areWeSecured: ', areWeSecured, 'domain: ' + domain, 'is req host === domain', domain === reqHost, 'is req host / locale === domain', domain === reqHost + "/" + localeData.locale);
16
15
  if (!redirectTo && areWeSecured && (domain === reqHost || domain === reqHost + "/" + localeData.locale)) return;
17
16
  var address = "https://" + domain + (redirectTo || currentPath) + (queryString ? "?" + queryString : '');
18
- console.log('redirect url', address);
19
17
  return address;
20
18
  };
21
19
  //# sourceMappingURL=getCanonicalUrl.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/seo/api/ssr/getCanonicalUrl.ts"],"names":["getCanonicalUrl","context","localeData","redirectTo","req","reqHost","headers","reqSSL","domain","length","slice","areWeSecured","currentPath","queryString","url","split","console","log","locale","address"],"mappings":"AAGA,OAAO,IAAMA,eAAe,GAAG,CAC7BC,OAD6B,EAE7BC,UAF6B,EAG7BC,UAH6B,KAIN;AAAA;;AACvB,MAA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AZ,EAA4BE,OAA5B;AAEA,SAAOA,OAAP;AACD,CAnDM","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 const [currentPath, queryString] = req.url?.split('?') || ['/']\n\n console.log(\n 'req.headers',\n req.headers,\n reqHost,\n reqSSL,\n 'redirectTo: ' + redirectTo,\n 'areWeSecured: ',\n areWeSecured,\n 'domain: ' + domain,\n 'is req host === domain',\n domain === reqHost,\n 'is req host / locale === domain',\n domain === `${reqHost}/${localeData.locale}`\n )\n if (\n !redirectTo &&\n areWeSecured &&\n (domain === reqHost || domain === `${reqHost}/${localeData.locale}`)\n )\n return\n\n const address = `https://${domain}${redirectTo || currentPath}${\n queryString ? `?${queryString}` : ''\n }`\n\n console.log('redirect url', address)\n\n return address\n}\n"],"file":"getCanonicalUrl.js"}
1
+ {"version":3,"sources":["../../../../../src/seo/api/ssr/getCanonicalUrl.ts"],"names":["getCanonicalUrl","context","localeData","redirectTo","req","reqHost","headers","reqSSL","domain","length","slice","areWeSecured","currentPath","queryString","url","split","locale","address"],"mappings":"AAGA,OAAO,IAAMA,eAAe,GAAG,CAC7BC,OAD6B,EAE7BC,UAF6B,EAG7BC,UAH6B,KAIN;AAAA;;AACvB,MAAM;AAAEC,IAAAA;AAAF,MAAUH,OAAhB;AAEA,MAAMI,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,MAAhC;AACA,MAAM,CAACK,WAAD,EAAcC,WAAd,IAA6B,aAAAT,GAAG,CAACU,GAAJ,8BAASC,KAAT,CAAe,GAAf,MAAuB,CAAC,GAAD,CAA1D;AAEA,MACE,CAACZ,UAAD,IACAQ,YADA,KAECH,MAAM,KAAKH,OAAX,IAAsBG,MAAM,KAAQH,OAAR,SAAmBH,UAAU,CAACc,MAF3D,CADF,EAKE;AAEF,MAAMC,OAAO,gBAAcT,MAAd,IAAuBL,UAAU,IAAIS,WAArC,KACXC,WAAW,SAAOA,WAAP,GAAuB,EADvB,CAAb;AAIA,SAAOI,OAAP;AACD,CAnCM","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 === 'true'\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 const address = `https://${domain}${redirectTo || currentPath}${\n queryString ? `?${queryString}` : ''\n }`\n\n return address\n}\n"],"file":"getCanonicalUrl.js"}
@@ -1,13 +1,24 @@
1
1
  import { WISHLIST_STORAGE_KEY } from '../../../api/wishlistApi';
2
2
  import { BASKET_STORAGE_KEY } from '../../../api/myCartApi';
3
- import { writeToLocalStorage, removeAnonToken } from '../../../utils';
3
+ import { writeToLocalStorage, setAccessToken, setExpiryToken, setRefreshToken, removeAnonToken, convertDateIntoRemainingDays } from '../../../utils';
4
4
  export var processLoginPayload = function processLoginPayload(data, anonymous) {
5
5
  if (anonymous === void 0) {
6
6
  anonymous = false;
7
7
  }
8
8
 
9
+ var accessTokenExpires = data.expires;
10
+ var refreshTokenExpires = data.refreshTokenExpires;
9
11
  writeToLocalStorage(WISHLIST_STORAGE_KEY, data.wishList);
10
12
  writeToLocalStorage(BASKET_STORAGE_KEY, data.basket);
13
+ setAccessToken(data.accessToken, anonymous, {
14
+ expires: convertDateIntoRemainingDays(new Date(), new Date(accessTokenExpires))
15
+ });
16
+ setExpiryToken(data.expires, {
17
+ expires: convertDateIntoRemainingDays(new Date(), new Date(refreshTokenExpires))
18
+ });
19
+ setRefreshToken(data.refreshToken, {
20
+ expires: convertDateIntoRemainingDays(new Date(), new Date(refreshTokenExpires))
21
+ });
11
22
  !anonymous && removeAnonToken();
12
23
  };
13
24
  //# sourceMappingURL=processLoginPayload.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/user/api/utils/processLoginPayload.ts"],"names":["WISHLIST_STORAGE_KEY","BASKET_STORAGE_KEY","writeToLocalStorage","removeAnonToken","processLoginPayload","data","anonymous","wishList","basket"],"mappings":"AAEA,SAASA,oBAAT,QAAqC,0BAArC;AACA,SAASC,kBAAT,QAAmC,wBAAnC;AAEA,SAASC,mBAAT,EAA8BC,eAA9B,QAAqD,gBAArD;AAEA,OAAO,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CACjCC,IADiC,EAEjCC,SAFiC,EAG9B;AAAA,MADHA,SACG;AADHA,IAAAA,SACG,GADS,KACT;AAAA;;AACHJ,EAAAA,mBAAmB,CAACF,oBAAD,EAAuBK,IAAI,CAACE,QAA5B,CAAnB;AACAL,EAAAA,mBAAmB,CAACD,kBAAD,EAAqBI,IAAI,CAACG,MAA1B,CAAnB;AAEA,GAACF,SAAD,IAAcH,eAAe,EAA7B;AACD,CARM","sourcesContent":["import { TokenResponseDTO } from '@sentecacommerce/sdk'\n\nimport { WISHLIST_STORAGE_KEY } from '../../../api/wishlistApi'\nimport { BASKET_STORAGE_KEY } from '../../../api/myCartApi'\n\nimport { writeToLocalStorage, removeAnonToken } from '../../../utils'\n\nexport const processLoginPayload = (\n data: TokenResponseDTO,\n anonymous = false\n) => {\n writeToLocalStorage(WISHLIST_STORAGE_KEY, data.wishList)\n writeToLocalStorage(BASKET_STORAGE_KEY, data.basket)\n\n !anonymous && removeAnonToken()\n}\n"],"file":"processLoginPayload.js"}
1
+ {"version":3,"sources":["../../../../../src/user/api/utils/processLoginPayload.ts"],"names":["WISHLIST_STORAGE_KEY","BASKET_STORAGE_KEY","writeToLocalStorage","setAccessToken","setExpiryToken","setRefreshToken","removeAnonToken","convertDateIntoRemainingDays","processLoginPayload","data","anonymous","accessTokenExpires","expires","refreshTokenExpires","wishList","basket","accessToken","Date","refreshToken"],"mappings":"AAEA,SAASA,oBAAT,QAAqC,0BAArC;AACA,SAASC,kBAAT,QAAmC,wBAAnC;AAEA,SACEC,mBADF,EAEEC,cAFF,EAGEC,cAHF,EAIEC,eAJF,EAKEC,eALF,EAMEC,4BANF,QAOO,gBAPP;AASA,OAAO,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CACjCC,IADiC,EAEjCC,SAFiC,EAG9B;AAAA,MADHA,SACG;AADHA,IAAAA,SACG,GADS,KACT;AAAA;;AACH,MAAMC,kBAAkB,GAAGF,IAAI,CAACG,OAAhC;AACA,MAAMC,mBAAmB,GAAGJ,IAAI,CAACI,mBAAjC;AAEAX,EAAAA,mBAAmB,CAACF,oBAAD,EAAuBS,IAAI,CAACK,QAA5B,CAAnB;AACAZ,EAAAA,mBAAmB,CAACD,kBAAD,EAAqBQ,IAAI,CAACM,MAA1B,CAAnB;AAEAZ,EAAAA,cAAc,CAACM,IAAI,CAACO,WAAN,EAA6BN,SAA7B,EAAwC;AACpDE,IAAAA,OAAO,EAAEL,4BAA4B,CACnC,IAAIU,IAAJ,EADmC,EAEnC,IAAIA,IAAJ,CAASN,kBAAT,CAFmC;AADe,GAAxC,CAAd;AAMAP,EAAAA,cAAc,CAACK,IAAI,CAACG,OAAN,EAAyB;AACrCA,IAAAA,OAAO,EAAEL,4BAA4B,CACnC,IAAIU,IAAJ,EADmC,EAEnC,IAAIA,IAAJ,CAASJ,mBAAT,CAFmC;AADA,GAAzB,CAAd;AAMAR,EAAAA,eAAe,CAACI,IAAI,CAACS,YAAN,EAA8B;AAC3CN,IAAAA,OAAO,EAAEL,4BAA4B,CACnC,IAAIU,IAAJ,EADmC,EAEnC,IAAIA,IAAJ,CAASJ,mBAAT,CAFmC;AADM,GAA9B,CAAf;AAMA,GAACH,SAAD,IAAcJ,eAAe,EAA7B;AACD,CA7BM","sourcesContent":["import { TokenResponseDTO } from '@sentecacommerce/sdk'\n\nimport { WISHLIST_STORAGE_KEY } from '../../../api/wishlistApi'\nimport { BASKET_STORAGE_KEY } from '../../../api/myCartApi'\n\nimport {\n writeToLocalStorage,\n setAccessToken,\n setExpiryToken,\n setRefreshToken,\n removeAnonToken,\n convertDateIntoRemainingDays,\n} from '../../../utils'\n\nexport const processLoginPayload = (\n data: TokenResponseDTO,\n anonymous = false\n) => {\n const accessTokenExpires = data.expires as number\n const refreshTokenExpires = data.refreshTokenExpires as number\n\n writeToLocalStorage(WISHLIST_STORAGE_KEY, data.wishList)\n writeToLocalStorage(BASKET_STORAGE_KEY, data.basket)\n\n setAccessToken(data.accessToken as string, anonymous, {\n expires: convertDateIntoRemainingDays(\n new Date(),\n new Date(accessTokenExpires as number)\n ),\n })\n setExpiryToken(data.expires as number, {\n expires: convertDateIntoRemainingDays(\n new Date(),\n new Date(refreshTokenExpires as number)\n ),\n })\n setRefreshToken(data.refreshToken as string, {\n expires: convertDateIntoRemainingDays(\n new Date(),\n new Date(refreshTokenExpires as number)\n ),\n })\n !anonymous && removeAnonToken()\n}\n"],"file":"processLoginPayload.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/prefetchSDKConfig.ts"],"names":["HttpClient","Configuration","prefetchSDKConfig","interfaceKey","storeKey","cookies","token","config","process","env","API_KEY","basePath","API_HOST","fetchApi","require","headers","InterfaceKey","StoreKey","defaultConfig","transientConfig"],"mappings":"AAAA,SACEA,UADF,EAEEC,aAFF,QAGO,sBAHP;AAKA,OAAO,IAAMC,iBAAiB,GAAG,UAU3B;AAAA,MAV4B;AAChCC,IAAAA,YADgC;AAEhCC,IAAAA,QAFgC;AAGhCC,IAAAA,OAHgC;AAIhCC,IAAAA;AAJgC,GAU5B;AACJ,MAAMC,MAAM,GAAG,IAAIN,aAAJ,CAAkB;AAC/BK,IAAAA,KAAK,EAAEA,KAAK,IAAIE,OAAO,CAACC,GAAR,CAAYC,OADG;AAE/BC,IAAAA,QAAQ,EAAEH,OAAO,CAACC,GAAR,CAAYG,QAFS;AAG/BC,IAAAA,QAAQ,EAAEC,OAAO,CAAC,YAAD,CAHc;AAI/BC,IAAAA,OAAO,EAAE;AACPC,MAAAA,YAAY,EAAEb,YADP;AAEPc,MAAAA,QAAQ,EAAEb;AAFH;AAJsB,GAAlB,CAAf;AAUAJ,EAAAA,UAAU,CAACkB,aAAX,GAA2BX,MAA3B;AACAP,EAAAA,UAAU,CAACmB,eAAX,GAA6BZ,MAA7B;AAEA,SAAOA,MAAP;AACD,CAzBM","sourcesContent":["import {\n HttpClient,\n Configuration,\n} from '@sentecacommerce/sdk'\n\nexport const prefetchSDKConfig = ({\n interfaceKey,\n storeKey,\n cookies,\n token,\n}: {\n interfaceKey: string\n storeKey: string\n cookies?: { [key: string]: string }\n token?: string\n}) => {\n const config = new Configuration({\n token: token || process.env.API_KEY,\n basePath: process.env.API_HOST,\n fetchApi: require('node-fetch'),\n headers: {\n InterfaceKey: interfaceKey,\n StoreKey: storeKey,\n },\n })\n\n HttpClient.defaultConfig = config\n HttpClient.transientConfig = config\n\n return config\n}\n"],"file":"prefetchSDKConfig.js"}
1
+ {"version":3,"sources":["../../../src/utils/prefetchSDKConfig.ts"],"names":["HttpClient","Configuration","prefetchSDKConfig","interfaceKey","storeKey","cookies","token","config","process","env","API_KEY","basePath","API_HOST","fetchApi","require","headers","InterfaceKey","StoreKey","defaultConfig","transientConfig"],"mappings":"AAAA,SAASA,UAAT,EAAqBC,aAArB,QAA0C,sBAA1C;AAEA,OAAO,IAAMC,iBAAiB,GAAG,UAU3B;AAAA,MAV4B;AAChCC,IAAAA,YADgC;AAEhCC,IAAAA,QAFgC;AAGhCC,IAAAA,OAHgC;AAIhCC,IAAAA;AAJgC,GAU5B;AACJ,MAAMC,MAAM,GAAG,IAAIN,aAAJ,CAAkB;AAC/BK,IAAAA,KAAK,EAAEA,KAAK,IAAIE,OAAO,CAACC,GAAR,CAAYC,OADG;AAE/BC,IAAAA,QAAQ,EAAEH,OAAO,CAACC,GAAR,CAAYG,QAFS;AAG/BC,IAAAA,QAAQ,EAAEC,OAAO,CAAC,YAAD,CAHc;AAI/BC,IAAAA,OAAO,EAAE;AACPC,MAAAA,YAAY,EAAEb,YADP;AAEPc,MAAAA,QAAQ,EAAEb;AAFH;AAJsB,GAAlB,CAAf;AAUAJ,EAAAA,UAAU,CAACkB,aAAX,GAA2BX,MAA3B;AACAP,EAAAA,UAAU,CAACmB,eAAX,GAA6BZ,MAA7B;AAEA,SAAOA,MAAP;AACD,CAzBM","sourcesContent":["import { HttpClient, Configuration } from '@sentecacommerce/sdk'\n\nexport const prefetchSDKConfig = ({\n interfaceKey,\n storeKey,\n cookies,\n token,\n}: {\n interfaceKey: string\n storeKey: string\n cookies?: { [key: string]: string }\n token?: string\n}) => {\n const config = new Configuration({\n token: token || process.env.API_KEY,\n basePath: process.env.API_HOST,\n fetchApi: require('node-fetch'),\n headers: {\n InterfaceKey: interfaceKey,\n StoreKey: storeKey,\n },\n })\n\n HttpClient.defaultConfig = config\n HttpClient.transientConfig = config\n\n return config\n}\n"],"file":"prefetchSDKConfig.js"}
@@ -1,2 +1,2 @@
1
1
  import type { QueryCache } from 'react-query';
2
- export declare function prefetchBrands(queryCache: QueryCache): Promise<void>;
2
+ export declare function prefetchBrands(queryCache: QueryCache): Promise<import("@sentecacommerce/sdk").CatalogAggregateResponseDTO>;
@@ -1,6 +1,6 @@
1
1
  import type { BoricaVerifyPaymentDataRequest as Reponse } from '@sentecacommerce/sdk';
2
2
  export declare const BoricaResponseProvider: ({ children, response, }: {
3
3
  children: any;
4
- response: Reponse;
4
+ response: Reponse | {};
5
5
  }) => JSX.Element;
6
- export declare const useBoricaResponse: () => Reponse;
6
+ export declare const useBoricaResponse: () => {} | Reponse;
@@ -0,0 +1,6 @@
1
+ import type { PaypalVerifyPaymentDataResponseDTO as Response } from '@sentecacommerce/sdk';
2
+ export declare const PaypalResponseProvider: ({ children, response, }: {
3
+ children: any;
4
+ response: Response | {};
5
+ }) => JSX.Element;
6
+ export declare const usePaypalResponse: () => {} | Response;
@@ -1 +1,2 @@
1
1
  export * from './BoricaResponseContext';
2
+ export * from './PaypalResponseContext';
@@ -0,0 +1,2 @@
1
+ import { PaypalCaptureRequestDTO } from '@sentecacommerce/sdk';
2
+ export declare const capturePaypalOrder: (res: PaypalCaptureRequestDTO) => Promise<import("@sentecacommerce/sdk").PaypalVerifyPaymentDataResponseDTO>;
@@ -1 +1,2 @@
1
1
  export * from './verifyBoricaResponse';
2
+ export * from './capturePaypalOrder';
@@ -1,9 +1,10 @@
1
1
  import { BoricaGeneratePaymentDataResponse, OrderDTO } from '@sentecacommerce/sdk';
2
- export declare const useCheckoutSubmit: ({ onSuccess, onBeforeBoricaRedirect, onError, withMeta, }: {
2
+ export declare const useCheckoutSubmit: ({ onSuccess, onBeforeBoricaRedirect, onBeforePaypalRedirect, onError, withMeta, }: {
3
3
  onSuccess?: ((result: OrderDTO) => void) | undefined;
4
4
  onBeforeBoricaRedirect?: ((formData: BoricaGeneratePaymentDataResponse) => void) | undefined;
5
5
  onError?: ((error: any) => void) | undefined;
6
6
  withMeta?: boolean | undefined;
7
+ onBeforePaypalRedirect: any;
7
8
  }) => {
8
9
  handleCheckoutSubmit: import("react-query").MutateFunction<OrderDTO, unknown, any, unknown>;
9
10
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentecacommerce-theme/lib",
3
3
  "sideEffects": false,
4
- "version": "0.12.33",
4
+ "version": "0.12.37",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -28,10 +28,10 @@
28
28
  "build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
29
29
  "dev": "yarn build:esm --watch"
30
30
  },
31
- "gitHead": "c782cd2e11336dc4323a0e1bac5ef73d3de35f32",
31
+ "gitHead": "e60206c3f10d400852f7a0412a2e506b5d0f0d34",
32
32
  "dependencies": {
33
- "@sentecacommerce-theme/base": "^0.12.33",
34
- "@sentecacommerce/sdk": "^2.0.104",
33
+ "@sentecacommerce-theme/base": "^0.12.37",
34
+ "@sentecacommerce/sdk": "^2.0.112",
35
35
  "body-scroll-lock": "^3.1.5",
36
36
  "copy-to-clipboard": "^3.3.1",
37
37
  "embla-carousel": "^4.5.1",