@akinon/next 1.13.1 → 1.14.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 (133) hide show
  1. package/.editorconfig +7 -0
  2. package/.eslintrc.js +40 -40
  3. package/.prettierrc +13 -13
  4. package/CHANGELOG.md +13 -0
  5. package/api/auth.ts +231 -231
  6. package/api/cache.ts +44 -44
  7. package/api/client.ts +174 -174
  8. package/api/logout.ts +42 -42
  9. package/assets/styles/index.scss +28 -28
  10. package/bin/pz-check-dependencies.js +98 -98
  11. package/bin/pz-install-plugins.js +33 -33
  12. package/bin/pz-install-theme.js +58 -58
  13. package/bin/pz-postbuild.js +1 -1
  14. package/bin/pz-postdev.js +1 -1
  15. package/bin/pz-postinstall.js +6 -6
  16. package/bin/pz-poststart.js +1 -1
  17. package/bin/pz-prebuild.js +4 -4
  18. package/bin/pz-predev.js +4 -4
  19. package/bin/pz-prestart.js +1 -1
  20. package/bin/run-script.js +44 -44
  21. package/components/accordion.tsx +52 -0
  22. package/components/button.tsx +46 -0
  23. package/components/client-root.tsx +19 -19
  24. package/components/icon.tsx +18 -18
  25. package/components/image.tsx +133 -133
  26. package/components/index.ts +17 -1
  27. package/components/input.tsx +110 -0
  28. package/components/lazy-component.tsx +33 -33
  29. package/components/loader-spinner.tsx +23 -23
  30. package/components/mobile-app-toggler.tsx +26 -26
  31. package/components/oauth-login.tsx +24 -24
  32. package/components/plugin-module.tsx +11 -8
  33. package/components/price.tsx +55 -0
  34. package/components/pz-providers.tsx +24 -24
  35. package/components/pz-root.tsx +21 -21
  36. package/components/radio.tsx +18 -18
  37. package/components/react-portal.tsx +45 -45
  38. package/components/redirect-three-d/content/index.tsx +74 -74
  39. package/components/redirect-three-d/index.tsx +17 -17
  40. package/components/selected-payment-option-view.tsx +7 -0
  41. package/components/trans.tsx +39 -39
  42. package/data/client/account.ts +208 -208
  43. package/data/client/address.ts +107 -107
  44. package/data/client/api.ts +85 -84
  45. package/data/client/b2b.ts +106 -106
  46. package/data/client/basket.ts +82 -82
  47. package/data/client/checkout.ts +516 -479
  48. package/data/client/misc.ts +101 -101
  49. package/data/client/product.ts +89 -89
  50. package/data/client/user.ts +99 -99
  51. package/data/client/wishlist.ts +118 -88
  52. package/data/server/category.ts +132 -128
  53. package/data/server/flatpage.ts +21 -21
  54. package/data/server/form.ts +22 -22
  55. package/data/server/index.ts +10 -10
  56. package/data/server/landingpage.ts +24 -24
  57. package/data/server/list.ts +67 -62
  58. package/data/server/menu.ts +35 -35
  59. package/data/server/product.ts +86 -86
  60. package/data/server/seo.ts +48 -48
  61. package/data/server/special-page.ts +47 -47
  62. package/data/server/widget.ts +27 -27
  63. package/data/urls.ts +221 -210
  64. package/hocs/client/index.ts +1 -1
  65. package/hocs/client/with-segment-defaults.tsx +25 -25
  66. package/hocs/server/index.ts +1 -1
  67. package/hocs/server/with-segment-defaults.tsx +85 -85
  68. package/hooks/index.ts +10 -10
  69. package/hooks/use-captcha.tsx +76 -76
  70. package/hooks/use-common-product-attributes.ts +36 -36
  71. package/hooks/use-debounce.ts +20 -20
  72. package/hooks/use-localization.ts +78 -78
  73. package/hooks/use-media-query.ts +36 -36
  74. package/hooks/use-mobile-iframe-handler.ts +23 -23
  75. package/hooks/use-on-click-outside.tsx +28 -28
  76. package/hooks/use-payment-options.ts +2 -1
  77. package/hooks/use-router.ts +45 -45
  78. package/hooks/use-translation.ts +14 -14
  79. package/lib/cache.ts +215 -215
  80. package/localization/index.ts +5 -5
  81. package/localization/provider.tsx +58 -58
  82. package/middlewares/currency.ts +100 -100
  83. package/middlewares/default.ts +256 -256
  84. package/middlewares/index.ts +29 -29
  85. package/middlewares/locale.ts +68 -68
  86. package/middlewares/oauth-login.ts +79 -79
  87. package/middlewares/pretty-url.ts +104 -104
  88. package/middlewares/redirection-payment.ts +160 -160
  89. package/middlewares/three-d-redirection.ts +159 -159
  90. package/middlewares/url-redirection.ts +65 -65
  91. package/package.json +2 -2
  92. package/plugins.js +2 -1
  93. package/redux/hooks.ts +7 -7
  94. package/redux/middlewares/checkout.ts +265 -260
  95. package/redux/middlewares/index.ts +50 -50
  96. package/redux/reducers/checkout.ts +184 -171
  97. package/redux/reducers/config.ts +28 -28
  98. package/redux/reducers/header.ts +59 -59
  99. package/redux/reducers/index.ts +14 -14
  100. package/redux/reducers/root.ts +61 -61
  101. package/sentry/index.ts +27 -27
  102. package/tailwind/rtl.js +137 -137
  103. package/types/commerce/account.ts +64 -64
  104. package/types/commerce/address.ts +94 -94
  105. package/types/commerce/b2b.ts +117 -117
  106. package/types/commerce/basket.ts +43 -43
  107. package/types/commerce/category.ts +114 -114
  108. package/types/commerce/checkout.ts +143 -136
  109. package/types/commerce/flatpage.ts +7 -7
  110. package/types/commerce/form.ts +66 -66
  111. package/types/commerce/index.ts +12 -12
  112. package/types/commerce/landingpage.ts +7 -7
  113. package/types/commerce/misc.ts +127 -127
  114. package/types/commerce/order.ts +119 -119
  115. package/types/commerce/product.ts +109 -109
  116. package/types/commerce/widget.ts +28 -28
  117. package/types/gtm.ts +16 -16
  118. package/types/index.ts +274 -237
  119. package/types/metadata.ts +7 -7
  120. package/types/next-auth.d.ts +24 -24
  121. package/utils/app-fetch.ts +69 -69
  122. package/utils/deep-merge.js +24 -24
  123. package/utils/generate-commerce-search-params.ts +22 -22
  124. package/utils/get-currency.ts +29 -29
  125. package/utils/image-loader.ts +31 -31
  126. package/utils/index.ts +150 -150
  127. package/utils/localization.ts +29 -29
  128. package/utils/log.ts +138 -138
  129. package/utils/menu-generator.ts +27 -27
  130. package/utils/mobile-3d-iframe.ts +77 -77
  131. package/utils/server-translation.ts +57 -57
  132. package/utils/server-variables.ts +9 -9
  133. package/with-pz-config.js +94 -94
@@ -1,260 +1,265 @@
1
- 'use client';
2
-
3
- import { Middleware } from '@reduxjs/toolkit';
4
- import {
5
- setAddressList,
6
- setBankAccounts,
7
- setCanGuestPurchase,
8
- setCardType,
9
- setDeliveryOptions,
10
- setErrors,
11
- setHasGiftBox,
12
- setInstallmentOptions,
13
- setLoyaltyBalance,
14
- setPaymentChoices,
15
- setPaymentOptions,
16
- setPreOrder,
17
- setRetailStores,
18
- setShippingOptions,
19
- setShippingStepCompleted
20
- } from '../../redux/reducers/checkout';
21
- import { RootState, TypedDispatch } from 'redux/store';
22
- import { checkoutApi } from '../../data/client/checkout';
23
- import { CheckoutContext, PreOrder } from '../../types';
24
- import { getCookie, setCookie } from '../../utils';
25
- import settings from 'settings';
26
- import { LocaleUrlStrategy } from '../../localization';
27
- import { showMobile3dIframe } from '../../utils/mobile-3d-iframe';
28
-
29
- interface CheckoutResult {
30
- payload: {
31
- errors?: any;
32
- pre_order?: PreOrder;
33
- context_list?: CheckoutContext[];
34
- };
35
- }
36
-
37
- interface MiddlewareParams {
38
- getState: () => RootState;
39
- dispatch: TypedDispatch;
40
- }
41
-
42
- export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
43
- return (next) => (action) => {
44
- const result: CheckoutResult = next(action);
45
- const errors = result?.payload?.errors;
46
-
47
- if (errors) {
48
- dispatch(setErrors(errors));
49
- }
50
-
51
- return result;
52
- };
53
- };
54
-
55
- export const preOrderMiddleware: Middleware = ({
56
- getState,
57
- dispatch
58
- }: MiddlewareParams) => {
59
- return (next) => (action) => {
60
- const result: CheckoutResult = next(action);
61
- const preOrder = result?.payload?.pre_order;
62
-
63
- if (
64
- !preOrder ||
65
- action?.meta?.arg?.endpointName === 'guestLogin' ||
66
- action?.meta?.arg?.endpointName === 'getCheckoutLoyaltyBalance'
67
- ) {
68
- return result;
69
- }
70
-
71
- const {
72
- deliveryOptions,
73
- addressList: addresses,
74
- shippingOptions,
75
- paymentOptions,
76
- installmentOptions
77
- } = getState().checkout;
78
- const { endpoints: apiEndpoints } = checkoutApi;
79
-
80
- if (preOrder.is_redirected) {
81
- const contextList = result?.payload?.context_list;
82
-
83
- if (
84
- contextList.find(
85
- (ctx) => ctx.page_name === 'RedirectionPaymentSelectedPage'
86
- )
87
- ) {
88
- dispatch(
89
- apiEndpoints.setPaymentOption.initiate(preOrder.payment_option?.pk)
90
- );
91
- return;
92
- }
93
- }
94
-
95
- dispatch(setPreOrder(preOrder));
96
-
97
- if (!preOrder.delivery_option && deliveryOptions.length > 0) {
98
- dispatch(
99
- apiEndpoints.setDeliveryOption.initiate(
100
- deliveryOptions.find((opt) => opt.delivery_option_type === 'customer')
101
- ?.pk
102
- )
103
- );
104
- }
105
-
106
- if (
107
- (!preOrder.shipping_address || !preOrder.billing_address) &&
108
- addresses.length > 0 &&
109
- preOrder.delivery_option?.delivery_option_type === 'customer'
110
- ) {
111
- dispatch(
112
- apiEndpoints.setAddresses.initiate({
113
- shippingAddressPk: addresses[0].pk,
114
- billingAddressPk: addresses[0].pk
115
- })
116
- );
117
- }
118
-
119
- if (
120
- shippingOptions.length > 0 &&
121
- (!preOrder.shipping_option ||
122
- !shippingOptions.find((opt) => opt.pk === preOrder.shipping_option?.pk))
123
- ) {
124
- dispatch(apiEndpoints.setShippingOption.initiate(shippingOptions[0].pk));
125
- }
126
-
127
- if (!preOrder.payment_option && paymentOptions.length > 0) {
128
- dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
129
- }
130
-
131
- if (!preOrder.installment && installmentOptions.length > 0) {
132
- dispatch(
133
- apiEndpoints.setInstallmentOption.initiate(installmentOptions[0].pk)
134
- );
135
- }
136
-
137
- dispatch(
138
- setShippingStepCompleted(
139
- [
140
- preOrder.delivery_option?.delivery_option_type === 'retail_store'
141
- ? true
142
- : preOrder.shipping_address?.pk,
143
- preOrder.billing_address?.pk,
144
- preOrder.shipping_option?.pk,
145
- addresses.length > 0
146
- ].every(Boolean)
147
- )
148
- );
149
-
150
- return result;
151
- };
152
- };
153
-
154
- export const contextListMiddleware: Middleware = ({
155
- dispatch,
156
- getState
157
- }: MiddlewareParams) => {
158
- return (next) => (action) => {
159
- const { isMobileApp } = getState().root;
160
- const result: CheckoutResult = next(action);
161
-
162
- if (result?.payload?.context_list) {
163
- result.payload.context_list.forEach((context) => {
164
- const redirectUrl = context.page_context.redirect_url;
165
-
166
- if (redirectUrl) {
167
- const currentLocale = getCookie('pz-locale');
168
-
169
- let url = redirectUrl;
170
-
171
- if (currentLocale && !redirectUrl.includes('/orders/redirection')) {
172
- const { defaultLocaleValue, localeUrlStrategy } =
173
- settings.localization;
174
-
175
- url =
176
- currentLocale === defaultLocaleValue &&
177
- localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales
178
- ? redirectUrl
179
- : `/${currentLocale}${redirectUrl}`;
180
- }
181
-
182
- const urlObj = new URL(url, window.location.origin);
183
- urlObj.searchParams.set('t', new Date().getTime().toString());
184
-
185
- if (
186
- (isMobileApp ||
187
- /iPad|iPhone|iPod|Android/i.test(navigator.userAgent)) &&
188
- !settings.checkout?.iframeExcludedPaymentOptions?.includes(
189
- result.payload?.pre_order?.payment_option?.slug
190
- )
191
- ) {
192
- showMobile3dIframe(urlObj.toString());
193
- } else {
194
- window.location.href = urlObj.toString();
195
- }
196
-
197
- return;
198
- }
199
-
200
- if (context.page_context.has_gift_box) {
201
- dispatch(setHasGiftBox(context.page_context.has_gift_box));
202
- }
203
-
204
- if (typeof context.page_context.can_guest_purchase === 'boolean') {
205
- dispatch(
206
- setCanGuestPurchase(context.page_context.can_guest_purchase)
207
- );
208
- }
209
-
210
- if (context.page_context.delivery_options) {
211
- dispatch(setDeliveryOptions(context.page_context.delivery_options));
212
- }
213
-
214
- if (context.page_context.addresses) {
215
- dispatch(setAddressList(context.page_context.addresses));
216
- }
217
-
218
- if (context.page_context.shipping_options) {
219
- dispatch(setShippingOptions(context.page_context.shipping_options));
220
- }
221
-
222
- if (context.page_context.payment_options) {
223
- dispatch(setPaymentOptions(context.page_context.payment_options));
224
- }
225
-
226
- if (context.page_context.payment_choices) {
227
- dispatch(setPaymentChoices(context.page_context.payment_choices));
228
- }
229
-
230
- if (context.page_context.bank_accounts) {
231
- dispatch(setBankAccounts(context.page_context.bank_accounts));
232
- }
233
-
234
- if (
235
- !result.payload.context_list.find(
236
- (ctx) => ctx.page_name === 'DeliveryOptionSelectionPage'
237
- )
238
- ) {
239
- if (context.page_context.card_type) {
240
- dispatch(setCardType(context.page_context.card_type));
241
- }
242
-
243
- if (context.page_context.installments) {
244
- dispatch(setInstallmentOptions(context.page_context.installments));
245
- }
246
- }
247
-
248
- if (context.page_context.balance) {
249
- dispatch(setLoyaltyBalance(context.page_context.balance));
250
- }
251
-
252
- if (context.page_context.retail_stores) {
253
- dispatch(setRetailStores(context.page_context.retail_stores));
254
- }
255
- });
256
- }
257
-
258
- return result;
259
- };
260
- };
1
+ 'use client';
2
+
3
+ import { Middleware } from '@reduxjs/toolkit';
4
+ import {
5
+ setAddressList,
6
+ setBankAccounts,
7
+ setCanGuestPurchase,
8
+ setCardType,
9
+ setDeliveryOptions,
10
+ setErrors,
11
+ setHasGiftBox,
12
+ setInstallmentOptions,
13
+ setLoyaltyBalance,
14
+ setPaymentChoices,
15
+ setPaymentOptions,
16
+ setPreOrder,
17
+ setRetailStores,
18
+ setShippingOptions,
19
+ setShippingStepCompleted,
20
+ setCreditPaymentOptions
21
+ } from '../../redux/reducers/checkout';
22
+ import { RootState, TypedDispatch } from 'redux/store';
23
+ import { checkoutApi } from '../../data/client/checkout';
24
+ import { CheckoutContext, PreOrder } from '../../types';
25
+ import { getCookie, setCookie } from '../../utils';
26
+ import settings from 'settings';
27
+ import { LocaleUrlStrategy } from '../../localization';
28
+ import { showMobile3dIframe } from '../../utils/mobile-3d-iframe';
29
+
30
+ interface CheckoutResult {
31
+ payload: {
32
+ errors?: any;
33
+ pre_order?: PreOrder;
34
+ context_list?: CheckoutContext[];
35
+ };
36
+ }
37
+
38
+ interface MiddlewareParams {
39
+ getState: () => RootState;
40
+ dispatch: TypedDispatch;
41
+ }
42
+
43
+ export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
44
+ return (next) => (action) => {
45
+ const result: CheckoutResult = next(action);
46
+ const errors = result?.payload?.errors;
47
+
48
+ if (errors) {
49
+ dispatch(setErrors(errors));
50
+ }
51
+
52
+ return result;
53
+ };
54
+ };
55
+
56
+ export const preOrderMiddleware: Middleware = ({
57
+ getState,
58
+ dispatch
59
+ }: MiddlewareParams) => {
60
+ return (next) => (action) => {
61
+ const result: CheckoutResult = next(action);
62
+ const preOrder = result?.payload?.pre_order;
63
+
64
+ if (
65
+ !preOrder ||
66
+ action?.meta?.arg?.endpointName === 'guestLogin' ||
67
+ action?.meta?.arg?.endpointName === 'getCheckoutLoyaltyBalance'
68
+ ) {
69
+ return result;
70
+ }
71
+
72
+ const {
73
+ deliveryOptions,
74
+ addressList: addresses,
75
+ shippingOptions,
76
+ paymentOptions,
77
+ installmentOptions
78
+ } = getState().checkout;
79
+ const { endpoints: apiEndpoints } = checkoutApi;
80
+
81
+ if (preOrder.is_redirected) {
82
+ const contextList = result?.payload?.context_list;
83
+
84
+ if (
85
+ contextList.find(
86
+ (ctx) => ctx.page_name === 'RedirectionPaymentSelectedPage'
87
+ )
88
+ ) {
89
+ dispatch(
90
+ apiEndpoints.setPaymentOption.initiate(preOrder.payment_option?.pk)
91
+ );
92
+ return;
93
+ }
94
+ }
95
+
96
+ dispatch(setPreOrder(preOrder));
97
+
98
+ if (!preOrder.delivery_option && deliveryOptions.length > 0) {
99
+ dispatch(
100
+ apiEndpoints.setDeliveryOption.initiate(
101
+ deliveryOptions.find((opt) => opt.delivery_option_type === 'customer')
102
+ ?.pk
103
+ )
104
+ );
105
+ }
106
+
107
+ if (
108
+ (!preOrder.shipping_address || !preOrder.billing_address) &&
109
+ addresses.length > 0 &&
110
+ preOrder.delivery_option?.delivery_option_type === 'customer'
111
+ ) {
112
+ dispatch(
113
+ apiEndpoints.setAddresses.initiate({
114
+ shippingAddressPk: addresses[0].pk,
115
+ billingAddressPk: addresses[0].pk
116
+ })
117
+ );
118
+ }
119
+
120
+ if (
121
+ shippingOptions.length > 0 &&
122
+ (!preOrder.shipping_option ||
123
+ !shippingOptions.find((opt) => opt.pk === preOrder.shipping_option?.pk))
124
+ ) {
125
+ dispatch(apiEndpoints.setShippingOption.initiate(shippingOptions[0].pk));
126
+ }
127
+
128
+ if (!preOrder.payment_option && paymentOptions.length > 0) {
129
+ dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
130
+ }
131
+
132
+ if (!preOrder.installment && installmentOptions.length > 0) {
133
+ dispatch(
134
+ apiEndpoints.setInstallmentOption.initiate(installmentOptions[0].pk)
135
+ );
136
+ }
137
+
138
+ dispatch(
139
+ setShippingStepCompleted(
140
+ [
141
+ preOrder.delivery_option?.delivery_option_type === 'retail_store'
142
+ ? true
143
+ : preOrder.shipping_address?.pk,
144
+ preOrder.billing_address?.pk,
145
+ preOrder.shipping_option?.pk,
146
+ addresses.length > 0
147
+ ].every(Boolean)
148
+ )
149
+ );
150
+
151
+ return result;
152
+ };
153
+ };
154
+
155
+ export const contextListMiddleware: Middleware = ({
156
+ dispatch,
157
+ getState
158
+ }: MiddlewareParams) => {
159
+ return (next) => (action) => {
160
+ const { isMobileApp } = getState().root;
161
+ const result: CheckoutResult = next(action);
162
+
163
+ if (result?.payload?.context_list) {
164
+ result.payload.context_list.forEach((context) => {
165
+ const redirectUrl = context.page_context.redirect_url;
166
+
167
+ if (redirectUrl) {
168
+ const currentLocale = getCookie('pz-locale');
169
+
170
+ let url = redirectUrl;
171
+
172
+ if (currentLocale && !redirectUrl.includes('/orders/redirection')) {
173
+ const { defaultLocaleValue, localeUrlStrategy } =
174
+ settings.localization;
175
+
176
+ url =
177
+ currentLocale === defaultLocaleValue &&
178
+ localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales
179
+ ? redirectUrl
180
+ : `/${currentLocale}${redirectUrl}`;
181
+ }
182
+
183
+ const urlObj = new URL(url, window.location.origin);
184
+ urlObj.searchParams.set('t', new Date().getTime().toString());
185
+
186
+ if (
187
+ (isMobileApp ||
188
+ /iPad|iPhone|iPod|Android/i.test(navigator.userAgent)) &&
189
+ !settings.checkout?.iframeExcludedPaymentOptions?.includes(
190
+ result.payload?.pre_order?.payment_option?.slug
191
+ )
192
+ ) {
193
+ showMobile3dIframe(urlObj.toString());
194
+ } else {
195
+ window.location.href = urlObj.toString();
196
+ }
197
+
198
+ return;
199
+ }
200
+
201
+ if (context.page_context.has_gift_box) {
202
+ dispatch(setHasGiftBox(context.page_context.has_gift_box));
203
+ }
204
+
205
+ if (typeof context.page_context.can_guest_purchase === 'boolean') {
206
+ dispatch(
207
+ setCanGuestPurchase(context.page_context.can_guest_purchase)
208
+ );
209
+ }
210
+
211
+ if (context.page_context.delivery_options) {
212
+ dispatch(setDeliveryOptions(context.page_context.delivery_options));
213
+ }
214
+
215
+ if (context.page_context.addresses) {
216
+ dispatch(setAddressList(context.page_context.addresses));
217
+ }
218
+
219
+ if (context.page_context.shipping_options) {
220
+ dispatch(setShippingOptions(context.page_context.shipping_options));
221
+ }
222
+
223
+ if (context.page_context.payment_options) {
224
+ dispatch(setPaymentOptions(context.page_context.payment_options));
225
+ }
226
+
227
+ if (context.page_context.credit_payment_options) {
228
+ dispatch(setCreditPaymentOptions(context.page_context.credit_payment_options));
229
+ }
230
+
231
+ if (context.page_context.payment_choices) {
232
+ dispatch(setPaymentChoices(context.page_context.payment_choices));
233
+ }
234
+
235
+ if (context.page_context.bank_accounts) {
236
+ dispatch(setBankAccounts(context.page_context.bank_accounts));
237
+ }
238
+
239
+ if (
240
+ !result.payload.context_list.find(
241
+ (ctx) => ctx.page_name === 'DeliveryOptionSelectionPage'
242
+ )
243
+ ) {
244
+ if (context.page_context.card_type) {
245
+ dispatch(setCardType(context.page_context.card_type));
246
+ }
247
+
248
+ if (context.page_context.installments) {
249
+ dispatch(setInstallmentOptions(context.page_context.installments));
250
+ }
251
+ }
252
+
253
+ if (context.page_context.balance) {
254
+ dispatch(setLoyaltyBalance(context.page_context.balance));
255
+ }
256
+
257
+ if (context.page_context.retail_stores) {
258
+ dispatch(setRetailStores(context.page_context.retail_stores));
259
+ }
260
+ });
261
+ }
262
+
263
+ return result;
264
+ };
265
+ };
@@ -1,50 +1,50 @@
1
- 'use client';
2
-
3
- import { signOut } from 'next-auth/react';
4
- import { ROUTES } from 'routes';
5
- import type { Middleware } from '@reduxjs/toolkit';
6
- import {
7
- errorMiddleware,
8
- contextListMiddleware,
9
- preOrderMiddleware
10
- } from './checkout';
11
- import { api } from '../../data/client/api';
12
- import logger from '@akinon/next/utils/log';
13
-
14
- export const rtkQueryResponseHandler: Middleware =
15
- ({ dispatch }) =>
16
- (next) =>
17
- (action) => {
18
- return next(action);
19
- };
20
-
21
- export const rtkQueryErrorHandler: Middleware =
22
- () => (next) => async (action) => {
23
- if (action?.payload?.status === 401) {
24
- await signOut({
25
- callbackUrl: `${ROUTES.AUTH}?callbackUrl=${window.location.pathname}`
26
- });
27
- logger.debug('Session expired: 401');
28
-
29
- return;
30
- }
31
-
32
- if (action?.payload?.status === 404) {
33
- logger.warn(
34
- `404 - Not Found. Endpoint: ${action.meta.arg.endpointName}, url: ${action.meta.baseQueryMeta.request.url}`
35
- );
36
- }
37
-
38
- return next(action);
39
- };
40
-
41
- const middlewares = [
42
- api.middleware,
43
- rtkQueryResponseHandler,
44
- rtkQueryErrorHandler,
45
- errorMiddleware,
46
- preOrderMiddleware,
47
- contextListMiddleware
48
- ];
49
-
50
- export default middlewares;
1
+ 'use client';
2
+
3
+ import { signOut } from 'next-auth/react';
4
+ import { ROUTES } from 'routes';
5
+ import type { Middleware } from '@reduxjs/toolkit';
6
+ import {
7
+ errorMiddleware,
8
+ contextListMiddleware,
9
+ preOrderMiddleware
10
+ } from './checkout';
11
+ import { api } from '../../data/client/api';
12
+ import logger from '@akinon/next/utils/log';
13
+
14
+ export const rtkQueryResponseHandler: Middleware =
15
+ ({ dispatch }) =>
16
+ (next) =>
17
+ (action) => {
18
+ return next(action);
19
+ };
20
+
21
+ export const rtkQueryErrorHandler: Middleware =
22
+ () => (next) => async (action) => {
23
+ if (action?.payload?.status === 401) {
24
+ await signOut({
25
+ callbackUrl: `${ROUTES.AUTH}?callbackUrl=${window.location.pathname}`
26
+ });
27
+ logger.debug('Session expired: 401');
28
+
29
+ return;
30
+ }
31
+
32
+ if (action?.payload?.status === 404) {
33
+ logger.warn(
34
+ `404 - Not Found. Endpoint: ${action.meta.arg.endpointName}, url: ${action.meta.baseQueryMeta.request.url}`
35
+ );
36
+ }
37
+
38
+ return next(action);
39
+ };
40
+
41
+ const middlewares = [
42
+ api.middleware,
43
+ rtkQueryResponseHandler,
44
+ rtkQueryErrorHandler,
45
+ errorMiddleware,
46
+ preOrderMiddleware,
47
+ contextListMiddleware
48
+ ];
49
+
50
+ export default middlewares;