@akinon/next 2.0.0-beta.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/CHANGELOG.md +438 -21
  2. package/__tests__/next-config.test.ts +83 -0
  3. package/__tests__/tsconfig.json +23 -0
  4. package/api/auth.ts +367 -63
  5. package/api/barcode-search.ts +59 -0
  6. package/api/cache.ts +41 -5
  7. package/api/client.ts +21 -4
  8. package/api/form.ts +85 -0
  9. package/api/image-proxy.ts +75 -0
  10. package/api/product-categories.ts +53 -0
  11. package/api/similar-product-list.ts +63 -0
  12. package/api/similar-products.ts +111 -0
  13. package/api/virtual-try-on.ts +382 -0
  14. package/assets/styles/index.scss +84 -0
  15. package/babel.config.js +6 -0
  16. package/bin/pz-generate-routes.js +115 -0
  17. package/bin/pz-install-plugins.js +1 -1
  18. package/bin/pz-prebuild.js +1 -0
  19. package/bin/pz-predev.js +1 -0
  20. package/bin/pz-run-tests.js +99 -0
  21. package/components/accordion.tsx +21 -6
  22. package/components/client-root.tsx +119 -3
  23. package/components/file-input.tsx +65 -3
  24. package/components/index.ts +1 -0
  25. package/components/input.tsx +2 -2
  26. package/components/link.tsx +46 -16
  27. package/components/logger-popup.tsx +213 -0
  28. package/components/modal.tsx +32 -16
  29. package/components/plugin-module.tsx +62 -3
  30. package/components/price.tsx +2 -2
  31. package/components/select.tsx +3 -3
  32. package/components/selected-payment-option-view.tsx +21 -0
  33. package/data/client/account.ts +17 -2
  34. package/data/client/basket.ts +39 -0
  35. package/data/client/checkout.ts +336 -99
  36. package/data/client/misc.ts +13 -1
  37. package/data/server/category.ts +11 -9
  38. package/data/server/flatpage.ts +4 -1
  39. package/data/server/form.ts +4 -1
  40. package/data/server/landingpage.ts +4 -1
  41. package/data/server/list.ts +5 -4
  42. package/data/server/menu.ts +4 -1
  43. package/data/server/product.ts +97 -52
  44. package/data/server/seo.ts +4 -1
  45. package/data/server/special-page.ts +5 -4
  46. package/data/server/widget.ts +71 -1
  47. package/data/urls.ts +6 -3
  48. package/hocs/client/with-segment-defaults.tsx +2 -2
  49. package/hocs/server/with-segment-defaults.tsx +81 -20
  50. package/hooks/index.ts +3 -0
  51. package/hooks/use-localization.ts +24 -10
  52. package/hooks/use-logger-context.tsx +114 -0
  53. package/hooks/use-logger.ts +92 -0
  54. package/hooks/use-loyalty-availability.ts +21 -0
  55. package/hooks/use-payment-options.ts +2 -1
  56. package/hooks/use-pz-params.ts +37 -0
  57. package/hooks/use-router.ts +53 -19
  58. package/instrumentation/index.ts +0 -1
  59. package/instrumentation/node.ts +2 -20
  60. package/jest.config.js +25 -0
  61. package/lib/cache-handler.mjs +534 -16
  62. package/lib/cache.ts +269 -34
  63. package/localization/provider.tsx +2 -5
  64. package/middlewares/bfcache-headers.ts +18 -0
  65. package/middlewares/checkout-provider.ts +1 -1
  66. package/middlewares/complete-gpay.ts +32 -26
  67. package/middlewares/complete-masterpass.ts +33 -26
  68. package/middlewares/complete-wallet.ts +182 -0
  69. package/middlewares/default.ts +357 -203
  70. package/middlewares/index.ts +10 -2
  71. package/middlewares/locale.ts +5 -3
  72. package/middlewares/masterpass-rest-callback.ts +230 -0
  73. package/middlewares/oauth-login.ts +200 -57
  74. package/middlewares/pretty-url.ts +21 -8
  75. package/middlewares/redirection-payment.ts +32 -26
  76. package/middlewares/saved-card-redirection.ts +33 -26
  77. package/middlewares/three-d-redirection.ts +32 -26
  78. package/middlewares/url-redirection.ts +9 -15
  79. package/middlewares/wallet-complete-redirection.ts +206 -0
  80. package/package.json +24 -10
  81. package/plugins.d.ts +19 -4
  82. package/plugins.js +9 -1
  83. package/redux/actions.ts +47 -0
  84. package/redux/middlewares/checkout.ts +61 -8
  85. package/redux/middlewares/index.ts +14 -10
  86. package/redux/middlewares/pre-order/address.ts +1 -1
  87. package/redux/middlewares/pre-order/attribute-based-shipping-option.ts +1 -1
  88. package/redux/middlewares/pre-order/data-source-shipping-option.ts +1 -1
  89. package/redux/middlewares/pre-order/delivery-option.ts +1 -1
  90. package/redux/middlewares/pre-order/index.ts +3 -1
  91. package/redux/middlewares/pre-order/installment-option.ts +2 -1
  92. package/redux/middlewares/pre-order/payment-option-reset.ts +37 -0
  93. package/redux/middlewares/pre-order/payment-option.ts +1 -1
  94. package/redux/middlewares/pre-order/pre-order-validation.ts +4 -3
  95. package/redux/middlewares/pre-order/redirection.ts +2 -2
  96. package/redux/middlewares/pre-order/set-pre-order.ts +2 -2
  97. package/redux/middlewares/pre-order/shipping-option.ts +1 -1
  98. package/redux/middlewares/pre-order/shipping-step.ts +1 -1
  99. package/redux/reducers/checkout.ts +15 -1
  100. package/redux/reducers/index.ts +7 -1
  101. package/redux/reducers/widget.ts +80 -0
  102. package/sentry/index.ts +54 -17
  103. package/tailwind/content.js +16 -0
  104. package/types/commerce/checkout.ts +26 -1
  105. package/types/commerce/widget.ts +33 -0
  106. package/types/index.ts +114 -5
  107. package/types/next-auth.d.ts +2 -2
  108. package/types/widget.ts +80 -0
  109. package/utils/app-fetch.ts +7 -2
  110. package/utils/generate-commerce-search-params.ts +3 -2
  111. package/utils/get-checkout-path.ts +3 -0
  112. package/utils/get-root-hostname.ts +28 -0
  113. package/utils/index.ts +69 -18
  114. package/utils/mobile-3d-iframe.ts +8 -2
  115. package/utils/override-middleware.ts +1 -0
  116. package/utils/pz-segments.ts +92 -0
  117. package/utils/redirect-ignore.ts +35 -0
  118. package/utils/redirect.ts +9 -3
  119. package/utils/redirection-iframe.ts +8 -2
  120. package/utils/widget-styles.ts +107 -0
  121. package/with-pz-config.js +20 -7
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "2.0.0-beta.8",
4
+ "version": "2.0.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -13,31 +13,45 @@
13
13
  "pz-predev": "bin/pz-predev.js",
14
14
  "pz-postdev": "bin/pz-postdev.js"
15
15
  },
16
+ "scripts": {
17
+ "test": "jest"
18
+ },
16
19
  "dependencies": {
20
+ "@mongodb-js/zstd": "^2.0.1",
21
+ "@neshca/cache-handler": "1.9.0",
17
22
  "@opentelemetry/exporter-trace-otlp-http": "0.46.0",
18
23
  "@opentelemetry/resources": "1.19.0",
19
24
  "@opentelemetry/sdk-node": "0.46.0",
20
25
  "@opentelemetry/sdk-trace-node": "1.19.0",
21
26
  "@opentelemetry/semantic-conventions": "1.19.0",
22
27
  "@reduxjs/toolkit": "1.9.7",
23
- "@neshca/cache-handler": "1.5.1",
24
- "@sentry/nextjs": "9.5.0",
28
+ "@sentry/nextjs": "10.39.0",
25
29
  "cross-spawn": "7.0.3",
26
30
  "generic-pool": "3.9.0",
27
- "react-redux": "8.1.3",
31
+ "lottie-web": "^5.13.0",
32
+ "react-multi-carousel": "2.8.4",
33
+ "react-redux": "9.2.0",
28
34
  "react-string-replace": "1.1.1",
29
35
  "redis": "4.6.13",
30
36
  "semver": "7.6.2",
31
37
  "set-cookie-parser": "2.6.0"
32
38
  },
33
39
  "devDependencies": {
34
- "@akinon/eslint-plugin-projectzero": "2.0.0-beta.8",
40
+ "@akinon/eslint-plugin-projectzero": "2.0.0",
41
+ "@babel/core": "7.26.10",
42
+ "@babel/preset-env": "7.26.9",
43
+ "@babel/preset-typescript": "7.27.0",
44
+ "@types/jest": "29.5.14",
35
45
  "@types/react-redux": "7.1.30",
36
46
  "@types/set-cookie-parser": "2.4.7",
37
- "@typescript-eslint/eslint-plugin": "8.18.2",
38
- "@typescript-eslint/parser": "8.18.2",
39
- "eslint": "9.17.0",
40
- "eslint-config-next": "15.1.2",
41
- "eslint-config-prettier": "9.1.0"
47
+ "@typescript-eslint/eslint-plugin": "6.7.4",
48
+ "@typescript-eslint/parser": "6.7.4",
49
+ "babel-jest": "29.7.0",
50
+ "eslint": "8.56.0",
51
+ "eslint-config-next": "16.1.6",
52
+ "eslint-config-prettier": "8.5.0",
53
+ "jest": "29.7.0",
54
+ "ts-jest": "29.3.2",
55
+ "typescript": "5.9.3"
42
56
  }
43
57
  }
package/plugins.d.ts CHANGED
@@ -13,6 +13,7 @@ declare module '@akinon/pz-masterpass/src/redux/reducer' {
13
13
  export const setError: any;
14
14
  export const setOtpModalVisible: any;
15
15
  export const setCvcRequired: any;
16
+ export const resetMasterpassState: any;
16
17
  }
17
18
 
18
19
  declare module '@akinon/pz-otp' {
@@ -30,9 +31,23 @@ declare module '@akinon/pz-saved-card' {
30
31
  export const SavedCardOption: any;
31
32
  }
32
33
 
33
- declare module '@akinon/pz-iyzico-saved-card' {
34
- export const iyzicoSavedCardReducer: any;
35
- export const iyzicoSavedCardMiddleware: any;
34
+ declare module '@akinon/pz-apple-pay' {}
35
+
36
+ declare module '@akinon/pz-cybersource-uc/src/redux/middleware' {
37
+ export default middleware as any;
36
38
  }
37
39
 
38
- declare module '@akinon/pz-apple-pay' {}
40
+ declare module '@akinon/pz-cybersource-uc/src/redux/reducer' {
41
+ export default reducer as any;
42
+ }
43
+
44
+ declare module '@akinon/pz-cybersource-uc' {
45
+ export const CyberSourceUcPaymentOption: any;
46
+ }
47
+
48
+ declare module '@akinon/pz-flow-payment' {}
49
+
50
+ declare module '@akinon/pz-masterpass-rest' {
51
+ export const MasterpassRestOption: React.FC;
52
+ export const masterpassRestReducer: any;
53
+ }
package/plugins.js CHANGED
@@ -15,5 +15,13 @@ module.exports = [
15
15
  'pz-saved-card',
16
16
  'pz-tabby-extension',
17
17
  'pz-apple-pay',
18
- 'pz-tamara-extension'
18
+ 'pz-tamara-extension',
19
+ 'pz-cybersource-uc',
20
+ 'pz-hepsipay',
21
+ 'pz-flow-payment',
22
+ 'pz-virtual-try-on',
23
+ 'pz-masterpass-rest',
24
+ 'pz-similar-products',
25
+ 'pz-haso',
26
+ 'pz-google-pay'
19
27
  ];
@@ -0,0 +1,47 @@
1
+ // Re-export all action creators from slice modules
2
+ export * from './reducers/root';
3
+ export * from './reducers/header';
4
+ export * from './reducers/checkout';
5
+ export * from './reducers/config';
6
+
7
+ // Import RTK Query APIs
8
+ import { basketApi } from '../data/client/basket';
9
+ import { productApi } from '../data/client/product';
10
+ import { miscApi } from '../data/client/misc';
11
+ import { checkoutApi } from '../data/client/checkout';
12
+ import { wishlistApi } from '../data/client/wishlist';
13
+
14
+ // Create RTK Query action creators
15
+ export const rtkApiActionCreators = {
16
+ // RTK Query API endpoints
17
+ ...Object.fromEntries(
18
+ Object.entries(basketApi.endpoints).map(([key, endpoint]) => [
19
+ `api_basket_${key}`,
20
+ endpoint.initiate
21
+ ])
22
+ ),
23
+ ...Object.fromEntries(
24
+ Object.entries(productApi.endpoints).map(([key, endpoint]) => [
25
+ `api_product_${key}`,
26
+ endpoint.initiate
27
+ ])
28
+ ),
29
+ ...Object.fromEntries(
30
+ Object.entries(miscApi.endpoints).map(([key, endpoint]) => [
31
+ `api_misc_${key}`,
32
+ endpoint.initiate
33
+ ])
34
+ ),
35
+ ...Object.fromEntries(
36
+ Object.entries(checkoutApi.endpoints).map(([key, endpoint]) => [
37
+ `api_checkout_${key}`,
38
+ endpoint.initiate
39
+ ])
40
+ ),
41
+ ...Object.fromEntries(
42
+ Object.entries(wishlistApi.endpoints).map(([key, endpoint]) => [
43
+ `api_wishlist_${key}`,
44
+ endpoint.initiate
45
+ ])
46
+ )
47
+ } as any;
@@ -14,13 +14,15 @@ import {
14
14
  setHasGiftBox,
15
15
  setInstallmentOptions,
16
16
  setLoyaltyBalance,
17
+ setLoyaltyBalances,
17
18
  setPaymentChoices,
18
19
  setPaymentOptions,
19
20
  setRetailStores,
20
21
  setShippingOptions,
21
22
  setHepsipayAvailability,
22
23
  setWalletPaymentData,
23
- setPayOnDeliveryOtpModalActive
24
+ setPayOnDeliveryOtpModalActive,
25
+ setUnavailablePaymentOptions
24
26
  } from '../../redux/reducers/checkout';
25
27
  import { RootState, TypedDispatch } from 'redux/store';
26
28
  import { checkoutApi } from '../../data/client/checkout';
@@ -36,6 +38,7 @@ interface CheckoutResult {
36
38
  errors?: Record<string, string[]>;
37
39
  pre_order?: PreOrder;
38
40
  context_list?: CheckoutContext[];
41
+ redirect_url?: string;
39
42
  };
40
43
  }
41
44
 
@@ -46,10 +49,14 @@ interface MiddlewareParams {
46
49
 
47
50
  export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
48
51
  return (next) => (action) => {
49
- const result: CheckoutResult = next(action);
52
+ const result = next(action) as CheckoutResult;
50
53
  const errors = result?.payload?.errors;
51
54
 
52
- if (errors) {
55
+ if (
56
+ !!errors &&
57
+ ((typeof errors === 'object' && Object.keys(errors).length > 0) ||
58
+ (Array.isArray(errors) && errors.length > 0))
59
+ ) {
53
60
  dispatch(setErrors(errors));
54
61
  }
55
62
 
@@ -57,19 +64,46 @@ export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
57
64
  };
58
65
  };
59
66
 
67
+ export const redirectUrlMiddleware: Middleware = () => {
68
+ return (next) => (action) => {
69
+ const result = next(action) as CheckoutResult;
70
+ const redirectUrl = result?.payload?.redirect_url;
71
+
72
+ if (redirectUrl) {
73
+ const currentLocale = getCookie('pz-locale');
74
+
75
+ let url = redirectUrl;
76
+
77
+ if (currentLocale && !redirectUrl.includes('/orders/redirection')) {
78
+ const { defaultLocaleValue, localeUrlStrategy } = settings.localization;
79
+
80
+ url =
81
+ currentLocale === defaultLocaleValue &&
82
+ localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales
83
+ ? redirectUrl
84
+ : `/${currentLocale}${redirectUrl}`;
85
+ }
86
+
87
+ window.location.href = url;
88
+ }
89
+
90
+ return result;
91
+ };
92
+ };
93
+
60
94
  export const contextListMiddleware: Middleware = ({
61
95
  dispatch,
62
96
  getState
63
97
  }: MiddlewareParams) => {
64
98
  return (next) => (action) => {
65
99
  const { isMobileApp, userPhoneNumber } = getState().root;
66
- const result: CheckoutResult = next(action);
100
+ const result = next(action) as CheckoutResult;
67
101
  const preOrder = result?.payload?.pre_order;
68
102
 
69
103
  if (result?.payload?.context_list) {
70
104
  result.payload.context_list.forEach((context) => {
71
105
  const redirectUrl = context.page_context.redirect_url;
72
- const isIframe = context.page_context.is_frame ?? false;
106
+ const isIframe = context.page_context.is_iframe ?? false;
73
107
 
74
108
  if (redirectUrl) {
75
109
  const currentLocale = getCookie('pz-locale');
@@ -148,6 +182,14 @@ export const contextListMiddleware: Middleware = ({
148
182
  dispatch(setPaymentOptions(context.page_context.payment_options));
149
183
  }
150
184
 
185
+ if (context.page_context.unavailable_options) {
186
+ dispatch(
187
+ setUnavailablePaymentOptions(
188
+ context.page_context.unavailable_options
189
+ )
190
+ );
191
+ }
192
+
151
193
  if (context.page_context.credit_payment_options) {
152
194
  dispatch(
153
195
  setCreditPaymentOptions(context.page_context.credit_payment_options)
@@ -171,7 +213,10 @@ export const contextListMiddleware: Middleware = ({
171
213
  dispatch(setCardType(context.page_context.card_type));
172
214
  }
173
215
 
174
- if (context.page_context.installments) {
216
+ if (
217
+ context.page_context.installments &&
218
+ preOrder?.payment_option?.payment_type !== 'masterpass_rest'
219
+ ) {
175
220
  dispatch(setInstallmentOptions(context.page_context.installments));
176
221
  }
177
222
  }
@@ -180,6 +225,14 @@ export const contextListMiddleware: Middleware = ({
180
225
  dispatch(setLoyaltyBalance(context.page_context.balance));
181
226
  }
182
227
 
228
+ if (context.page_context.balances) {
229
+ dispatch(setLoyaltyBalances(context.page_context.balances));
230
+ }
231
+
232
+ if (context.page_context.accounts) {
233
+ dispatch(setLoyaltyBalances(context.page_context.accounts));
234
+ }
235
+
183
236
  if (context.page_context.retail_stores) {
184
237
  dispatch(setRetailStores(context.page_context.retail_stores));
185
238
  }
@@ -207,7 +260,7 @@ export const hepsiPayMiddleware: Middleware = ({
207
260
  dispatch
208
261
  }: MiddlewareParams) => {
209
262
  return (next) => (action) => {
210
- const result: CheckoutResult = next(action);
263
+ const result = next(action) as CheckoutResult;
211
264
  const { payload } = result;
212
265
  const preOrder = payload?.pre_order;
213
266
  const contextList = payload?.context_list;
@@ -261,7 +314,7 @@ export const walletPaymentMiddleware: Middleware = ({
261
314
  dispatch
262
315
  }: MiddlewareParams) => {
263
316
  return (next) => (action) => {
264
- const result: CheckoutResult = next(action);
317
+ const result = next(action) as CheckoutResult;
265
318
  const { payload } = result;
266
319
  const preOrder = payload?.pre_order;
267
320
  const contextList = payload?.context_list;
@@ -3,8 +3,10 @@
3
3
  import { signOut } from 'next-auth/react';
4
4
  import { ROUTES } from 'routes';
5
5
  import type { Middleware } from '@reduxjs/toolkit';
6
+ import type { MiddlewareAction } from '../../types';
6
7
  import {
7
8
  errorMiddleware,
9
+ redirectUrlMiddleware,
8
10
  contextListMiddleware,
9
11
  hepsiPayMiddleware,
10
12
  walletPaymentMiddleware
@@ -17,17 +19,17 @@ import logger from '@akinon/next/utils/log';
17
19
 
18
20
  // Plugin middlewares
19
21
  import { savedCardMiddleware } from '@akinon/pz-saved-card';
22
+ import cyberSourceUcMiddleware from '@akinon/pz-cybersource-uc/src/redux/middleware';
20
23
 
21
- export const rtkQueryResponseHandler: Middleware =
22
- ({ dispatch }) =>
23
- (next) =>
24
- (action) => {
25
- return next(action);
26
- };
24
+ export const rtkQueryResponseHandler: Middleware = () => (next) => (action) => {
25
+ return next(action);
26
+ };
27
27
 
28
28
  export const rtkQueryErrorHandler: Middleware =
29
29
  () => (next) => async (action) => {
30
- if (action?.payload?.status === 401) {
30
+ const act = action as MiddlewareAction;
31
+
32
+ if (act?.payload?.status === 401) {
31
33
  await signOut({
32
34
  callbackUrl: `${ROUTES.AUTH}?callbackUrl=${window.location.pathname}`
33
35
  });
@@ -36,9 +38,9 @@ export const rtkQueryErrorHandler: Middleware =
36
38
  return;
37
39
  }
38
40
 
39
- if (action?.payload?.status === 404) {
41
+ if (act?.payload?.status === 404) {
40
42
  logger.warn(
41
- `404 - Not Found. Endpoint: ${action.meta.arg.endpointName}, url: ${action.meta.baseQueryMeta.request.url}`
43
+ `404 - Not Found. Endpoint: ${act.meta.arg.endpointName}, url: ${act.meta.baseQueryMeta.request.url}`
42
44
  );
43
45
  }
44
46
 
@@ -50,11 +52,13 @@ const middlewares = [
50
52
  rtkQueryResponseHandler,
51
53
  rtkQueryErrorHandler,
52
54
  errorMiddleware,
55
+ redirectUrlMiddleware,
53
56
  ...preOrderMiddlewares,
54
57
  contextListMiddleware,
55
58
  hepsiPayMiddleware,
56
59
  walletPaymentMiddleware,
57
- savedCardMiddleware
60
+ savedCardMiddleware,
61
+ cyberSourceUcMiddleware
58
62
  ];
59
63
 
60
64
  // Filter out any non-function middleware to ensure all middlewares are valid and executable
@@ -7,7 +7,7 @@ export const setAddressMiddleware: Middleware = ({
7
7
  dispatch
8
8
  }: MiddlewareParams) => {
9
9
  return (next) => (action) => {
10
- const result: CheckoutResult = next(action);
10
+ const result = next(action) as CheckoutResult;
11
11
  const preOrder = result?.payload?.pre_order;
12
12
 
13
13
  if (!preOrder) {
@@ -7,7 +7,7 @@ export const attributeBasedShippingOptionMiddleware: Middleware = ({
7
7
  dispatch
8
8
  }: MiddlewareParams) => {
9
9
  return (next) => (action) => {
10
- const result: CheckoutResult = next(action);
10
+ const result = next(action) as CheckoutResult;
11
11
  const preOrder = result?.payload?.pre_order;
12
12
 
13
13
  if (!preOrder) {
@@ -7,7 +7,7 @@ export const dataSourceShippingOptionMiddleware: Middleware = ({
7
7
  dispatch
8
8
  }: MiddlewareParams) => {
9
9
  return (next) => (action) => {
10
- const result: CheckoutResult = next(action);
10
+ const result = next(action) as CheckoutResult;
11
11
  const preOrder = result?.payload?.pre_order;
12
12
 
13
13
  if (!preOrder) {
@@ -7,7 +7,7 @@ export const deliveryOptionMiddleware: Middleware = ({
7
7
  dispatch
8
8
  }: MiddlewareParams) => {
9
9
  return (next) => (action) => {
10
- const result: CheckoutResult = next(action);
10
+ const result = next(action) as CheckoutResult;
11
11
  const preOrder = result?.payload?.pre_order;
12
12
 
13
13
  if (!preOrder) {
@@ -8,15 +8,17 @@ import { dataSourceShippingOptionMiddleware } from './data-source-shipping-optio
8
8
  import { attributeBasedShippingOptionMiddleware } from './attribute-based-shipping-option';
9
9
  import { paymentOptionMiddleware } from './payment-option';
10
10
  import { installmentOptionMiddleware } from './installment-option';
11
+ import { paymentOptionResetMiddleware } from './payment-option-reset';
11
12
  import { shippingStepMiddleware } from './shipping-step';
12
13
 
13
14
  // ⚠️ WARNING: Redux Toolkit applies middlewares in reverse order (from last to first).
14
- // This list is written **in reverse execution order** to ensure they run in the correct sequence.
15
+ // This list is written **in reverse execution order** to ensure they run in the correct sequence.
15
16
  // If you add a new middleware, make sure to insert it **in reverse order** based on execution priority.
16
17
 
17
18
  export const preOrderMiddlewares = [
18
19
  shippingStepMiddleware,
19
20
  installmentOptionMiddleware,
21
+ paymentOptionResetMiddleware,
20
22
  paymentOptionMiddleware,
21
23
  attributeBasedShippingOptionMiddleware,
22
24
  dataSourceShippingOptionMiddleware,
@@ -7,7 +7,7 @@ export const installmentOptionMiddleware: Middleware = ({
7
7
  dispatch
8
8
  }: MiddlewareParams) => {
9
9
  return (next) => (action) => {
10
- const result: CheckoutResult = next(action);
10
+ const result = next(action) as CheckoutResult;
11
11
  const preOrder = result?.payload?.pre_order;
12
12
 
13
13
  if (!preOrder) {
@@ -20,6 +20,7 @@ export const installmentOptionMiddleware: Middleware = ({
20
20
  if (
21
21
  !preOrder?.installment &&
22
22
  preOrder?.payment_option?.payment_type !== 'saved_card' &&
23
+ preOrder?.payment_option?.payment_type !== 'masterpass_rest' &&
23
24
  installmentOptions.length > 0
24
25
  ) {
25
26
  const firstInstallmentOptionPk = installmentOptions[0]?.pk;
@@ -0,0 +1,37 @@
1
+ import { Middleware } from '@reduxjs/toolkit';
2
+ import { CheckoutResult, MiddlewareAction, MiddlewareParams } from '../../../types';
3
+ import {
4
+ setBankAccounts,
5
+ setCardType,
6
+ setInstallmentOptions,
7
+ setSelectedBankAccountPk
8
+ } from '../../reducers/checkout';
9
+ import { resetMasterpassState } from '@akinon/pz-masterpass/src/redux/reducer';
10
+
11
+ export const paymentOptionResetMiddleware: Middleware = ({
12
+ dispatch
13
+ }: MiddlewareParams) => {
14
+ return (next) => (action) => {
15
+ const result = next(action) as CheckoutResult;
16
+ const act = action as MiddlewareAction;
17
+
18
+ if (
19
+ act.type === 'api/executeMutation/fulfilled' &&
20
+ act.meta?.arg?.endpointName === 'setPaymentOption'
21
+ ) {
22
+ dispatch(setInstallmentOptions([]));
23
+ dispatch(setBankAccounts([]));
24
+ dispatch(setSelectedBankAccountPk(null));
25
+ dispatch(setCardType(null));
26
+ if(resetMasterpassState){
27
+ dispatch(resetMasterpassState());
28
+ }
29
+ }
30
+
31
+ return result;
32
+ };
33
+ };
34
+
35
+ Object.defineProperty(paymentOptionResetMiddleware, 'name', {
36
+ value: 'paymentOptionResetMiddleware'
37
+ });
@@ -7,7 +7,7 @@ export const paymentOptionMiddleware: Middleware = ({
7
7
  dispatch
8
8
  }: MiddlewareParams) => {
9
9
  return (next) => (action) => {
10
- const result: CheckoutResult = next(action);
10
+ const result = next(action) as CheckoutResult;
11
11
  const preOrder = result?.payload?.pre_order;
12
12
 
13
13
  if (!preOrder) {
@@ -1,15 +1,16 @@
1
1
  import { Middleware } from '@reduxjs/toolkit';
2
- import { CheckoutResult } from '../../../types';
2
+ import { CheckoutResult, MiddlewareAction } from '../../../types';
3
3
 
4
4
  export const preOrderValidationMiddleware: Middleware = () => {
5
5
  return (next) => (action) => {
6
- const result: CheckoutResult = next(action);
6
+ const result = next(action) as CheckoutResult;
7
7
  const preOrder = result?.payload?.pre_order;
8
+ const act = action as MiddlewareAction;
8
9
 
9
10
  if (
10
11
  !preOrder ||
11
12
  ['guestLogin', 'getCheckoutLoyaltyBalance'].includes(
12
- action?.meta?.arg?.endpointName
13
+ act?.meta?.arg?.endpointName
13
14
  )
14
15
  ) {
15
16
  return result;
@@ -1,12 +1,12 @@
1
1
  import { Middleware } from '@reduxjs/toolkit';
2
- import { MiddlewareParams } from '../../../types';
2
+ import { CheckoutResult, MiddlewareParams } from '../../../types';
3
3
  import { checkoutApi } from '../../../data/client/checkout';
4
4
 
5
5
  export const redirectionMiddleware: Middleware = ({
6
6
  dispatch
7
7
  }: MiddlewareParams) => {
8
8
  return (next) => (action) => {
9
- const result = next(action);
9
+ const result = next(action) as CheckoutResult;
10
10
  const preOrder = result?.payload?.pre_order;
11
11
 
12
12
  if (!preOrder) {
@@ -1,12 +1,12 @@
1
1
  import { Middleware } from '@reduxjs/toolkit';
2
- import { MiddlewareParams } from '../../../types';
2
+ import { CheckoutResult, MiddlewareParams } from '../../../types';
3
3
  import { setPreOrder } from '../../../redux/reducers/checkout';
4
4
 
5
5
  export const setPreOrderMiddleware: Middleware = ({
6
6
  dispatch
7
7
  }: MiddlewareParams) => {
8
8
  return (next) => (action) => {
9
- const result = next(action);
9
+ const result = next(action) as CheckoutResult;
10
10
  const preOrder = result?.payload?.pre_order;
11
11
 
12
12
  if (preOrder) {
@@ -7,7 +7,7 @@ export const shippingOptionMiddleware: Middleware = ({
7
7
  dispatch
8
8
  }: MiddlewareParams) => {
9
9
  return (next) => (action) => {
10
- const result: CheckoutResult = next(action);
10
+ const result = next(action) as CheckoutResult;
11
11
  const preOrder = result?.payload?.pre_order;
12
12
 
13
13
  if (!preOrder) {
@@ -7,7 +7,7 @@ export const shippingStepMiddleware: Middleware = ({
7
7
  dispatch
8
8
  }: MiddlewareParams) => {
9
9
  return (next) => (action) => {
10
- const result: CheckoutResult = next(action);
10
+ const result = next(action) as CheckoutResult;
11
11
  const preOrder = result?.payload?.pre_order;
12
12
 
13
13
  if (!preOrder) {
@@ -9,6 +9,7 @@ import {
9
9
  CreditCardType,
10
10
  DeliveryOption,
11
11
  InstallmentOption,
12
+ LoyaltyBalanceItem,
12
13
  PaymentChoice,
13
14
  PaymentOption,
14
15
  CheckoutCreditPaymentOption,
@@ -40,6 +41,7 @@ export interface CheckoutState {
40
41
  shippingOptions: ShippingOption[];
41
42
  dataSourceShippingOptions: DataSource[];
42
43
  paymentOptions: PaymentOption[];
44
+ unavailablePaymentOptions: PaymentOption[];
43
45
  creditPaymentOptions: CheckoutCreditPaymentOption[];
44
46
  selectedCreditPaymentPk: number;
45
47
  paymentChoices: PaymentChoice[];
@@ -48,6 +50,7 @@ export interface CheckoutState {
48
50
  bankAccounts: BankAccount[];
49
51
  selectedBankAccountPk: number;
50
52
  loyaltyBalance?: string;
53
+ loyaltyBalances?: LoyaltyBalanceItem[];
51
54
  retailStores: RetailStore[];
52
55
  attributeBasedShippingOptions: AttributeBasedShippingOption[];
53
56
  selectedShippingOptions: Record<string, number>;
@@ -60,6 +63,8 @@ export interface CheckoutState {
60
63
  countryCode: string;
61
64
  currencyCode: string;
62
65
  version: string;
66
+ public_key: string;
67
+ [key: string]: any;
63
68
  };
64
69
  detail: {
65
70
  label: string;
@@ -94,6 +99,7 @@ const initialState: CheckoutState = {
94
99
  shippingOptions: [],
95
100
  dataSourceShippingOptions: [],
96
101
  paymentOptions: [],
102
+ unavailablePaymentOptions: [],
97
103
  creditPaymentOptions: [],
98
104
  selectedCreditPaymentPk: null,
99
105
  paymentChoices: [],
@@ -157,6 +163,9 @@ const checkoutSlice = createSlice({
157
163
  setPaymentOptions(state, { payload }) {
158
164
  state.paymentOptions = payload;
159
165
  },
166
+ setUnavailablePaymentOptions(state, { payload }) {
167
+ state.unavailablePaymentOptions = payload;
168
+ },
160
169
  setPaymentChoices(state, { payload }) {
161
170
  state.paymentChoices = payload;
162
171
  },
@@ -181,6 +190,9 @@ const checkoutSlice = createSlice({
181
190
  setLoyaltyBalance(state, { payload }) {
182
191
  state.loyaltyBalance = payload;
183
192
  },
193
+ setLoyaltyBalances(state, { payload }) {
194
+ state.loyaltyBalances = payload;
195
+ },
184
196
  setRetailStores(state, { payload }) {
185
197
  state.retailStores = payload;
186
198
  },
@@ -218,14 +230,16 @@ export const {
218
230
  setShippingOptions,
219
231
  setDataSourceShippingOptions,
220
232
  setPaymentOptions,
233
+ setUnavailablePaymentOptions,
234
+ setPaymentChoices,
221
235
  setCreditPaymentOptions,
222
236
  setSelectedCreditPaymentPk,
223
- setPaymentChoices,
224
237
  setCardType,
225
238
  setInstallmentOptions,
226
239
  setBankAccounts,
227
240
  setSelectedBankAccountPk,
228
241
  setLoyaltyBalance,
242
+ setLoyaltyBalances,
229
243
  setRetailStores,
230
244
  setAttributeBasedShippingOptions,
231
245
  setSelectedShippingOptions,