@akinon/next 1.76.0-rc.0 → 1.76.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.
- package/CHANGELOG.md +5 -740
- package/components/input.tsx +0 -2
- package/components/link.tsx +12 -16
- package/data/server/flatpage.ts +4 -8
- package/data/server/form.ts +4 -12
- package/data/server/landingpage.ts +4 -8
- package/data/server/menu.ts +2 -7
- package/data/server/product.ts +4 -15
- package/data/server/seo.ts +4 -11
- package/data/server/widget.ts +4 -19
- package/hocs/server/with-segment-defaults.tsx +2 -5
- package/instrumentation/index.ts +0 -7
- package/lib/cache-handler.mjs +2 -2
- package/lib/cache.ts +0 -2
- package/middlewares/complete-gpay.ts +1 -2
- package/middlewares/complete-masterpass.ts +1 -2
- package/middlewares/default.ts +1 -3
- package/middlewares/redirection-payment.ts +1 -2
- package/middlewares/saved-card-redirection.ts +1 -2
- package/middlewares/three-d-redirection.ts +1 -2
- package/package.json +3 -3
- package/redux/middlewares/index.ts +4 -2
- package/redux/middlewares/pre-order/address.ts +45 -0
- package/redux/middlewares/pre-order/attribute-based-shipping-option.ts +40 -0
- package/redux/middlewares/pre-order/data-source-shipping-option.ts +37 -0
- package/redux/middlewares/pre-order/delivery-option.ts +34 -0
- package/redux/middlewares/pre-order/index.ts +25 -0
- package/redux/middlewares/pre-order/installment-option.ts +36 -0
- package/redux/middlewares/pre-order/payment-option.ts +28 -0
- package/redux/middlewares/pre-order/pre-order-validation.ts +20 -0
- package/redux/middlewares/pre-order/redirection.ts +34 -0
- package/redux/middlewares/pre-order/set-pre-order.ts +18 -0
- package/redux/middlewares/pre-order/shipping-option.ts +38 -0
- package/redux/middlewares/pre-order/shipping-step.ts +34 -0
- package/types/commerce/checkout.ts +14 -0
- package/types/commerce/order.ts +0 -1
- package/utils/app-fetch.ts +2 -2
- package/utils/override-middleware.ts +31 -0
- package/with-pz-config.js +1 -1
- package/data/server/basket.ts +0 -72
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
import { CheckoutResult, MiddlewareParams } from '../../../types';
|
|
3
|
+
import { checkoutApi } from '../../../data/client/checkout';
|
|
4
|
+
|
|
5
|
+
export const deliveryOptionMiddleware: Middleware = ({
|
|
6
|
+
getState,
|
|
7
|
+
dispatch
|
|
8
|
+
}: MiddlewareParams) => {
|
|
9
|
+
return (next) => (action) => {
|
|
10
|
+
const result: CheckoutResult = next(action);
|
|
11
|
+
const preOrder = result?.payload?.pre_order;
|
|
12
|
+
|
|
13
|
+
if (!preOrder) {
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { deliveryOptions } = getState().checkout;
|
|
18
|
+
const { endpoints: apiEndpoints } = checkoutApi;
|
|
19
|
+
|
|
20
|
+
if (!preOrder?.delivery_option && deliveryOptions?.length > 0) {
|
|
21
|
+
const customerDeliveryOption = deliveryOptions.find(
|
|
22
|
+
(opt) => opt.delivery_option_type === 'customer'
|
|
23
|
+
)?.pk;
|
|
24
|
+
|
|
25
|
+
if (customerDeliveryOption) {
|
|
26
|
+
dispatch(
|
|
27
|
+
apiEndpoints.setDeliveryOption.initiate(customerDeliveryOption)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { preOrderValidationMiddleware } from './pre-order-validation';
|
|
2
|
+
import { redirectionMiddleware } from './redirection';
|
|
3
|
+
import { setPreOrderMiddleware } from './set-pre-order';
|
|
4
|
+
import { deliveryOptionMiddleware } from './delivery-option';
|
|
5
|
+
import { setAddressMiddleware } from './address';
|
|
6
|
+
import { shippingOptionMiddleware } from './shipping-option';
|
|
7
|
+
import { dataSourceShippingOptionMiddleware } from './data-source-shipping-option';
|
|
8
|
+
import { attributeBasedShippingOptionMiddleware } from './attribute-based-shipping-option';
|
|
9
|
+
import { paymentOptionMiddleware } from './payment-option';
|
|
10
|
+
import { installmentOptionMiddleware } from './installment-option';
|
|
11
|
+
import { shippingStepMiddleware } from './shipping-step';
|
|
12
|
+
|
|
13
|
+
export const preOrderMiddlewares = [
|
|
14
|
+
preOrderValidationMiddleware,
|
|
15
|
+
redirectionMiddleware,
|
|
16
|
+
setPreOrderMiddleware,
|
|
17
|
+
deliveryOptionMiddleware,
|
|
18
|
+
setAddressMiddleware,
|
|
19
|
+
shippingOptionMiddleware,
|
|
20
|
+
dataSourceShippingOptionMiddleware,
|
|
21
|
+
attributeBasedShippingOptionMiddleware,
|
|
22
|
+
paymentOptionMiddleware,
|
|
23
|
+
installmentOptionMiddleware,
|
|
24
|
+
shippingStepMiddleware
|
|
25
|
+
];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
import { CheckoutResult, MiddlewareParams } from '../../../types';
|
|
3
|
+
import { checkoutApi } from '../../../data/client/checkout';
|
|
4
|
+
|
|
5
|
+
export const installmentOptionMiddleware: Middleware = ({
|
|
6
|
+
getState,
|
|
7
|
+
dispatch
|
|
8
|
+
}: MiddlewareParams) => {
|
|
9
|
+
return (next) => (action) => {
|
|
10
|
+
const result: CheckoutResult = next(action);
|
|
11
|
+
const preOrder = result?.payload?.pre_order;
|
|
12
|
+
|
|
13
|
+
if (!preOrder) {
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { installmentOptions } = getState().checkout;
|
|
18
|
+
const { endpoints: apiEndpoints } = checkoutApi;
|
|
19
|
+
|
|
20
|
+
if (
|
|
21
|
+
!preOrder?.installment &&
|
|
22
|
+
preOrder?.payment_option?.payment_type !== 'saved_card' &&
|
|
23
|
+
installmentOptions.length > 0
|
|
24
|
+
) {
|
|
25
|
+
const firstInstallmentOptionPk = installmentOptions[0]?.pk;
|
|
26
|
+
|
|
27
|
+
if (firstInstallmentOptionPk) {
|
|
28
|
+
dispatch(
|
|
29
|
+
apiEndpoints.setInstallmentOption.initiate(firstInstallmentOptionPk)
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
import { CheckoutResult, MiddlewareParams } from '../../../types';
|
|
3
|
+
import { checkoutApi } from '../../../data/client/checkout';
|
|
4
|
+
|
|
5
|
+
export const paymentOptionMiddleware: Middleware = ({
|
|
6
|
+
getState,
|
|
7
|
+
dispatch
|
|
8
|
+
}: MiddlewareParams) => {
|
|
9
|
+
return (next) => (action) => {
|
|
10
|
+
const result: CheckoutResult = next(action);
|
|
11
|
+
const preOrder = result?.payload?.pre_order;
|
|
12
|
+
|
|
13
|
+
if (!preOrder) {
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { paymentOptions } = getState().checkout;
|
|
18
|
+
const { endpoints: apiEndpoints } = checkoutApi;
|
|
19
|
+
|
|
20
|
+
if (!preOrder?.payment_option && paymentOptions.length > 0) {
|
|
21
|
+
const firstPaymentOptionPk = paymentOptions[0]?.pk;
|
|
22
|
+
|
|
23
|
+
dispatch(apiEndpoints.setPaymentOption.initiate(firstPaymentOptionPk));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
import { CheckoutResult } from '../../../types';
|
|
3
|
+
|
|
4
|
+
export const preOrderValidationMiddleware: Middleware = () => {
|
|
5
|
+
return (next) => (action) => {
|
|
6
|
+
const result: CheckoutResult = next(action);
|
|
7
|
+
const preOrder = result?.payload?.pre_order;
|
|
8
|
+
|
|
9
|
+
if (
|
|
10
|
+
!preOrder ||
|
|
11
|
+
['guestLogin', 'getCheckoutLoyaltyBalance'].includes(
|
|
12
|
+
action?.meta?.arg?.endpointName
|
|
13
|
+
)
|
|
14
|
+
) {
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
import { MiddlewareParams } from '../../../types';
|
|
3
|
+
import { checkoutApi } from '../../../data/client/checkout';
|
|
4
|
+
|
|
5
|
+
export const redirectionMiddleware: Middleware = ({
|
|
6
|
+
dispatch
|
|
7
|
+
}: MiddlewareParams) => {
|
|
8
|
+
return (next) => (action) => {
|
|
9
|
+
const result = next(action);
|
|
10
|
+
const preOrder = result?.payload?.pre_order;
|
|
11
|
+
|
|
12
|
+
if (!preOrder) {
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (preOrder?.is_redirected) {
|
|
17
|
+
const contextList = result?.payload?.context_list;
|
|
18
|
+
|
|
19
|
+
if (
|
|
20
|
+
contextList?.find(
|
|
21
|
+
(ctx) => ctx.page_name === 'RedirectionPaymentSelectedPage'
|
|
22
|
+
)
|
|
23
|
+
) {
|
|
24
|
+
dispatch(
|
|
25
|
+
checkoutApi.endpoints.setPaymentOption.initiate(
|
|
26
|
+
preOrder.payment_option?.pk
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
import { MiddlewareParams } from '../../../types';
|
|
3
|
+
import { setPreOrder } from '../../../redux/reducers/checkout';
|
|
4
|
+
|
|
5
|
+
export const setPreOrderMiddleware: Middleware = ({
|
|
6
|
+
dispatch
|
|
7
|
+
}: MiddlewareParams) => {
|
|
8
|
+
return (next) => (action) => {
|
|
9
|
+
const result = next(action);
|
|
10
|
+
const preOrder = result?.payload?.pre_order;
|
|
11
|
+
|
|
12
|
+
if (preOrder) {
|
|
13
|
+
dispatch(setPreOrder(preOrder));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
import { CheckoutResult, MiddlewareParams } from '../../../types';
|
|
3
|
+
import { checkoutApi } from '../../../data/client/checkout';
|
|
4
|
+
|
|
5
|
+
export const shippingOptionMiddleware: Middleware = ({
|
|
6
|
+
getState,
|
|
7
|
+
dispatch
|
|
8
|
+
}: MiddlewareParams) => {
|
|
9
|
+
return (next) => (action) => {
|
|
10
|
+
const result: CheckoutResult = next(action);
|
|
11
|
+
const preOrder = result?.payload?.pre_order;
|
|
12
|
+
|
|
13
|
+
if (!preOrder) {
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { shippingOptions } = getState().checkout;
|
|
18
|
+
const { endpoints: apiEndpoints } = checkoutApi;
|
|
19
|
+
|
|
20
|
+
const hasShippingOptions = shippingOptions?.length > 0;
|
|
21
|
+
|
|
22
|
+
const isShippingOptionValid = preOrder?.shipping_option
|
|
23
|
+
? shippingOptions.some((opt) => opt.pk === preOrder.shipping_option.pk)
|
|
24
|
+
: false;
|
|
25
|
+
|
|
26
|
+
if (hasShippingOptions && !isShippingOptionValid) {
|
|
27
|
+
const defaultShippingOption = shippingOptions[0]?.pk;
|
|
28
|
+
|
|
29
|
+
if (defaultShippingOption) {
|
|
30
|
+
dispatch(
|
|
31
|
+
apiEndpoints.setShippingOption.initiate(defaultShippingOption)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
import { CheckoutResult, MiddlewareParams } from '../../../types';
|
|
3
|
+
import { setShippingStepCompleted } from '../../reducers/checkout';
|
|
4
|
+
|
|
5
|
+
export const shippingStepMiddleware: Middleware = ({
|
|
6
|
+
getState,
|
|
7
|
+
dispatch
|
|
8
|
+
}: MiddlewareParams) => {
|
|
9
|
+
return (next) => (action) => {
|
|
10
|
+
const result: CheckoutResult = next(action);
|
|
11
|
+
const preOrder = result?.payload?.pre_order;
|
|
12
|
+
|
|
13
|
+
if (!preOrder) {
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { addressList: addresses } = getState().checkout;
|
|
18
|
+
|
|
19
|
+
if (preOrder) {
|
|
20
|
+
const stepCompleted = [
|
|
21
|
+
preOrder.delivery_option?.delivery_option_type === 'retail_store'
|
|
22
|
+
? true
|
|
23
|
+
: preOrder.shipping_address?.pk,
|
|
24
|
+
preOrder.billing_address?.pk,
|
|
25
|
+
preOrder.shipping_option?.pk,
|
|
26
|
+
addresses.length > 0
|
|
27
|
+
].every(Boolean);
|
|
28
|
+
|
|
29
|
+
dispatch(setShippingStepCompleted(stepCompleted));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -3,6 +3,7 @@ import { Basket } from './basket';
|
|
|
3
3
|
import { RetailStore } from './misc';
|
|
4
4
|
import { PaymentOption } from './order';
|
|
5
5
|
import { Product } from './product';
|
|
6
|
+
import { RootState, TypedDispatch } from 'redux/store';
|
|
6
7
|
|
|
7
8
|
export enum CheckoutStep {
|
|
8
9
|
Shipping = 'shipping',
|
|
@@ -185,3 +186,16 @@ export interface AttributeBasedShippingOption {
|
|
|
185
186
|
attribute_key: string;
|
|
186
187
|
[key: string]: any;
|
|
187
188
|
}
|
|
189
|
+
|
|
190
|
+
export interface CheckoutResult {
|
|
191
|
+
payload: {
|
|
192
|
+
errors?: Record<string, string[]>;
|
|
193
|
+
pre_order?: PreOrder;
|
|
194
|
+
context_list?: CheckoutContext[];
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface MiddlewareParams {
|
|
199
|
+
getState: () => RootState;
|
|
200
|
+
dispatch: TypedDispatch;
|
|
201
|
+
}
|
package/types/commerce/order.ts
CHANGED
package/utils/app-fetch.ts
CHANGED
|
@@ -43,12 +43,12 @@ const appFetch = async <T>({
|
|
|
43
43
|
const requestURL = `${decodeURIComponent(commerceUrl)}${url}`;
|
|
44
44
|
|
|
45
45
|
init.headers = {
|
|
46
|
-
cookie: nextCookies.toString(),
|
|
47
46
|
...(init.headers ?? {}),
|
|
48
47
|
...(ServerVariables.globalHeaders ?? {}),
|
|
49
48
|
'Accept-Language': currentLocale.apiValue,
|
|
50
49
|
'x-currency': currency,
|
|
51
|
-
'x-forwarded-for': ip
|
|
50
|
+
'x-forwarded-for': ip,
|
|
51
|
+
cookie: nextCookies.toString()
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
init.next = {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
|
|
3
|
+
export enum MiddlewareNames {
|
|
4
|
+
PreOrderValidationMiddleware = 'preOrderValidationMiddleware',
|
|
5
|
+
RedirectionMiddleware = 'redirectionMiddleware',
|
|
6
|
+
SetPreOrderMiddleware = 'setPreOrderMiddleware',
|
|
7
|
+
DeliveryOptionMiddleware = 'deliveryOptionMiddleware',
|
|
8
|
+
SetAddressMiddleware = 'setAddressMiddleware',
|
|
9
|
+
ShippingOptionMiddleware = 'shippingOptionMiddleware',
|
|
10
|
+
DataSourceShippingOptionMiddleware = 'dataSourceShippingOptionMiddleware',
|
|
11
|
+
AttributeBasedShippingOptionMiddleware = 'attributeBasedShippingOptionMiddleware',
|
|
12
|
+
PaymentOptionMiddleware = 'paymentOptionMiddleware',
|
|
13
|
+
InstallmentOptionMiddleware = 'installmentOptionMiddleware',
|
|
14
|
+
ShippingStepMiddleware = 'shippingStepMiddleware'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const overrideMiddleware = (
|
|
18
|
+
middlewares: Middleware[],
|
|
19
|
+
updates: { name: MiddlewareNames; middleware: Middleware }[]
|
|
20
|
+
): void => {
|
|
21
|
+
const updatesMap = new Map(
|
|
22
|
+
updates.map(({ name, middleware }) => [name, middleware])
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
middlewares.forEach((mw, index) => {
|
|
26
|
+
const updatedMiddleware = updatesMap.get(mw.name as MiddlewareNames);
|
|
27
|
+
if (updatedMiddleware) {
|
|
28
|
+
middlewares[index] = updatedMiddleware;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
package/with-pz-config.js
CHANGED
package/data/server/basket.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Cache, CacheKey } from '../../lib/cache';
|
|
2
|
-
import { basket } from '../../data/urls';
|
|
3
|
-
import { Basket } from '../../types';
|
|
4
|
-
import appFetch from '../../utils/app-fetch';
|
|
5
|
-
import { ServerVariables } from '../../utils/server-variables';
|
|
6
|
-
import logger from '../../utils/log';
|
|
7
|
-
|
|
8
|
-
type GetBasketParams = {
|
|
9
|
-
locale?: string;
|
|
10
|
-
currency?: string;
|
|
11
|
-
namespace?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const getBasketDataHandler = ({
|
|
15
|
-
locale,
|
|
16
|
-
currency,
|
|
17
|
-
namespace
|
|
18
|
-
}: GetBasketParams) => {
|
|
19
|
-
return async function () {
|
|
20
|
-
try {
|
|
21
|
-
const url = namespace
|
|
22
|
-
? basket.getBasketDetail(namespace)
|
|
23
|
-
: basket.getBasket;
|
|
24
|
-
|
|
25
|
-
const basketData = await appFetch<{ basket: Basket }>({
|
|
26
|
-
url,
|
|
27
|
-
locale,
|
|
28
|
-
currency,
|
|
29
|
-
init: {
|
|
30
|
-
headers: {
|
|
31
|
-
Accept: 'application/json',
|
|
32
|
-
'Content-Type': 'application/json'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (!basketData?.basket) {
|
|
38
|
-
logger.warn('Basket data is undefined', {
|
|
39
|
-
handler: 'getBasketDataHandler',
|
|
40
|
-
namespace
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return basketData;
|
|
45
|
-
} catch (error) {
|
|
46
|
-
logger.error('Error fetching basket data', {
|
|
47
|
-
handler: 'getBasketDataHandler',
|
|
48
|
-
error,
|
|
49
|
-
namespace
|
|
50
|
-
});
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const getBasketData = async ({
|
|
57
|
-
locale = ServerVariables.locale,
|
|
58
|
-
currency = ServerVariables.currency,
|
|
59
|
-
namespace
|
|
60
|
-
}: GetBasketParams = {}) => {
|
|
61
|
-
return Cache.wrap(
|
|
62
|
-
CacheKey.Basket(namespace),
|
|
63
|
-
locale,
|
|
64
|
-
getBasketDataHandler({ locale, currency, namespace }),
|
|
65
|
-
{
|
|
66
|
-
expire: 0,
|
|
67
|
-
cache: false
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
|