@akinon/next 1.45.0-rc.0 → 1.45.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 +4 -240
- package/api/client.ts +9 -33
- package/assets/styles/index.scss +26 -50
- package/components/input.tsx +7 -21
- package/components/link.tsx +13 -17
- package/components/pagination.tsx +2 -1
- package/components/price.tsx +4 -11
- package/components/selected-payment-option-view.tsx +38 -26
- package/data/client/account.ts +9 -10
- package/data/client/address.ts +8 -32
- package/data/client/api.ts +1 -1
- package/data/client/checkout.ts +4 -47
- package/data/server/category.ts +2 -2
- package/data/server/list.ts +2 -2
- package/data/server/product.ts +13 -15
- package/data/server/special-page.ts +2 -2
- package/data/urls.ts +1 -5
- package/hooks/index.ts +1 -2
- package/hooks/use-payment-options.ts +1 -2
- package/lib/cache.ts +6 -18
- package/middlewares/default.ts +2 -50
- package/middlewares/locale.ts +30 -32
- package/middlewares/pretty-url.ts +0 -4
- package/middlewares/url-redirection.ts +0 -4
- package/package.json +4 -5
- package/plugins.d.ts +0 -1
- package/redux/middlewares/checkout.ts +11 -70
- package/redux/reducers/checkout.ts +5 -24
- package/redux/reducers/config.ts +0 -2
- package/types/commerce/account.ts +0 -1
- package/types/commerce/address.ts +1 -1
- package/types/commerce/checkout.ts +0 -30
- package/types/commerce/misc.ts +0 -2
- package/types/commerce/order.ts +0 -12
- package/types/index.ts +2 -28
- package/utils/app-fetch.ts +1 -1
- package/utils/generate-commerce-search-params.ts +2 -6
- package/utils/index.ts +6 -27
- package/utils/menu-generator.ts +2 -2
- package/utils/server-translation.ts +1 -5
- package/with-pz-config.js +1 -11
- package/assets/styles/index.css +0 -49
- package/assets/styles/index.css.map +0 -1
- package/hooks/use-message-listener.ts +0 -24
- package/lib/cache-handler.mjs +0 -33
- package/routes/pretty-url.tsx +0 -194
- package/utils/redirection-iframe.ts +0 -85
package/data/client/account.ts
CHANGED
|
@@ -123,16 +123,15 @@ const accountApi = api.injectEndpoints({
|
|
|
123
123
|
query: ({ page, status, limit }) =>
|
|
124
124
|
buildClientRequestUrl(account.getQuotations(page, status, limit))
|
|
125
125
|
}),
|
|
126
|
-
sendContact: builder.mutation<void,
|
|
127
|
-
query: (body) => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
126
|
+
sendContact: builder.mutation<void, ContactFormType>({
|
|
127
|
+
query: (body) => ({
|
|
128
|
+
url: buildClientRequestUrl(account.sendContact, {
|
|
129
|
+
contentType: 'application/json',
|
|
130
|
+
responseType: 'text'
|
|
131
|
+
}),
|
|
132
|
+
method: 'POST',
|
|
133
|
+
body
|
|
134
|
+
})
|
|
136
135
|
}),
|
|
137
136
|
cancelOrder: builder.mutation<void, AccountOrderCancellation>({
|
|
138
137
|
query: ({ id, ...body }) => ({
|
package/data/client/address.ts
CHANGED
|
@@ -39,10 +39,7 @@ const addressApi = api.injectEndpoints({
|
|
|
39
39
|
query: (city) =>
|
|
40
40
|
buildClientRequestUrl(address.getRetailStoreTownships(city))
|
|
41
41
|
}),
|
|
42
|
-
addAddress: builder.mutation<
|
|
43
|
-
Address,
|
|
44
|
-
Partial<Address> & { invalidateTag?: 'Addresses' | 'Checkout' }
|
|
45
|
-
>({
|
|
42
|
+
addAddress: builder.mutation<Address, Partial<Address>>({
|
|
46
43
|
query: (body) => ({
|
|
47
44
|
url: buildClientRequestUrl(address.base, {
|
|
48
45
|
contentType: 'application/json'
|
|
@@ -53,16 +50,9 @@ const addressApi = api.injectEndpoints({
|
|
|
53
50
|
type: body.is_corporate === 'true' ? 'corporate' : 'personal'
|
|
54
51
|
}
|
|
55
52
|
}),
|
|
56
|
-
invalidatesTags: (_, error
|
|
57
|
-
if (error) return [];
|
|
58
|
-
if (arg.invalidateTag) return [arg.invalidateTag];
|
|
59
|
-
return ['Addresses', 'Checkout'];
|
|
60
|
-
}
|
|
53
|
+
invalidatesTags: (_, error) => (error ? [] : ['Addresses', 'Checkout'])
|
|
61
54
|
}),
|
|
62
|
-
editAddress: builder.mutation<
|
|
63
|
-
Address,
|
|
64
|
-
Partial<Address> & { invalidateTag?: 'Addresses' | 'Checkout' }
|
|
65
|
-
>({
|
|
55
|
+
editAddress: builder.mutation<Address, Partial<Address>>({
|
|
66
56
|
query: ({ pk, ...body }) => ({
|
|
67
57
|
url: buildClientRequestUrl(address.editAddress(pk), {
|
|
68
58
|
contentType: 'application/json'
|
|
@@ -74,28 +64,14 @@ const addressApi = api.injectEndpoints({
|
|
|
74
64
|
type: body.is_corporate === 'true' ? 'corporate' : 'personal'
|
|
75
65
|
}
|
|
76
66
|
}),
|
|
77
|
-
invalidatesTags: (_, error,
|
|
78
|
-
if (error) return [];
|
|
79
|
-
if (arg.invalidateTag) return [arg.invalidateTag];
|
|
80
|
-
return ['Addresses', 'Checkout'];
|
|
81
|
-
}
|
|
67
|
+
invalidatesTags: (_, error) => (error ? [] : ['Addresses', 'Checkout']) // TODO: Invalidate one of these tags when necessary (e.g. Address page invalidates Addresses tag, Checkout page invalidates Checkout tag)
|
|
82
68
|
}),
|
|
83
|
-
removeAddress: builder.mutation<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
>({
|
|
87
|
-
query: (arg) => ({
|
|
88
|
-
url: buildClientRequestUrl(
|
|
89
|
-
address.removeAddress(typeof arg === 'number' ? arg : arg.id)
|
|
90
|
-
),
|
|
69
|
+
removeAddress: builder.mutation<void, number>({
|
|
70
|
+
query: (id) => ({
|
|
71
|
+
url: buildClientRequestUrl(address.removeAddress(id)),
|
|
91
72
|
method: 'DELETE'
|
|
92
73
|
}),
|
|
93
|
-
invalidatesTags: (_, error,
|
|
94
|
-
if (error) return [];
|
|
95
|
-
if (typeof arg === 'object' && arg.invalidateTag)
|
|
96
|
-
return [arg.invalidateTag];
|
|
97
|
-
return ['Addresses', 'Checkout'];
|
|
98
|
-
}
|
|
74
|
+
invalidatesTags: (_, error) => (error ? [] : ['Addresses', 'Checkout']) // TODO: Invalidate one of these tags when necessary (e.g. Address page invalidates Addresses tag, Checkout page invalidates Checkout tag)
|
|
99
75
|
}),
|
|
100
76
|
setDefaultAddress: builder.mutation<Address, Partial<Address>>({
|
|
101
77
|
query: ({ pk, primary }) => ({
|
package/data/client/api.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from '@reduxjs/toolkit/query/react';
|
|
10
10
|
import settings from 'settings';
|
|
11
11
|
import { getCookie } from '../../utils';
|
|
12
|
-
import { RootState } from 'redux/store';
|
|
12
|
+
import { RootState } from '@theme/redux/store';
|
|
13
13
|
|
|
14
14
|
interface CustomBaseQueryApi extends BaseQueryApi {
|
|
15
15
|
getState: () => RootState;
|
package/data/client/checkout.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
setBankAccounts,
|
|
3
|
-
setCardType,
|
|
4
3
|
setInstallmentOptions,
|
|
5
4
|
setPaymentStepBusy,
|
|
6
5
|
setSelectedBankAccountPk,
|
|
7
6
|
setSelectedCreditPaymentPk,
|
|
8
|
-
setShippingStepBusy
|
|
7
|
+
setShippingStepBusy,
|
|
8
|
+
setCardType
|
|
9
9
|
} from '../../redux/reducers/checkout';
|
|
10
10
|
import {
|
|
11
11
|
CheckoutContext,
|
|
@@ -20,7 +20,6 @@ import { AppDispatch, AppStore, store } from 'redux/store';
|
|
|
20
20
|
import settings from 'settings';
|
|
21
21
|
import { showMobile3dIframe } from '../../utils/mobile-3d-iframe';
|
|
22
22
|
import {
|
|
23
|
-
setCvcRequired,
|
|
24
23
|
setError,
|
|
25
24
|
setOtpModalVisible
|
|
26
25
|
} from '@akinon/pz-masterpass/src/redux/reducer';
|
|
@@ -114,8 +113,7 @@ const completeMasterpassPayment = async (
|
|
|
114
113
|
? await buildDirectPurchaseForm(commonFormValues, params)
|
|
115
114
|
: await buildPurchaseForm({
|
|
116
115
|
...commonFormValues,
|
|
117
|
-
selectedCard
|
|
118
|
-
cardCvc: params?.card_cvv
|
|
116
|
+
selectedCard
|
|
119
117
|
});
|
|
120
118
|
|
|
121
119
|
window.MFS?.[
|
|
@@ -153,10 +151,6 @@ const completeMasterpassPayment = async (
|
|
|
153
151
|
return;
|
|
154
152
|
}
|
|
155
153
|
|
|
156
|
-
if (['5013', '5182'].includes(response.responseCode)) {
|
|
157
|
-
dispatch(setCvcRequired(true));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
154
|
if (
|
|
161
155
|
response.token &&
|
|
162
156
|
(response.responseCode == '0000' || response.responseCode == '')
|
|
@@ -379,22 +373,6 @@ export const checkoutApi = api.injectEndpoints({
|
|
|
379
373
|
dispatch(setShippingStepBusy(false));
|
|
380
374
|
}
|
|
381
375
|
}),
|
|
382
|
-
setDataSourceShippingOptions: build.mutation<CheckoutResponse, number[]>({
|
|
383
|
-
query: (pks) => ({
|
|
384
|
-
url: buildClientRequestUrl(checkout.setDataSourceShippingOption, {
|
|
385
|
-
useFormData: true
|
|
386
|
-
}),
|
|
387
|
-
method: 'POST',
|
|
388
|
-
body: {
|
|
389
|
-
data_source_shipping_options: JSON.stringify(pks)
|
|
390
|
-
}
|
|
391
|
-
}),
|
|
392
|
-
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
393
|
-
dispatch(setShippingStepBusy(true));
|
|
394
|
-
await queryFulfilled;
|
|
395
|
-
dispatch(setShippingStepBusy(false));
|
|
396
|
-
}
|
|
397
|
-
}),
|
|
398
376
|
setRetailStore: build.mutation<CheckoutResponse, SetRetailStoreParams>({
|
|
399
377
|
query: ({ retailStorePk, billingAddressPk }) => ({
|
|
400
378
|
url: buildClientRequestUrl(
|
|
@@ -676,25 +654,6 @@ export const checkoutApi = api.injectEndpoints({
|
|
|
676
654
|
notes
|
|
677
655
|
}
|
|
678
656
|
})
|
|
679
|
-
}),
|
|
680
|
-
setAttributeBasedShippingOptions: build.mutation<
|
|
681
|
-
CheckoutResponse,
|
|
682
|
-
Record<string, number>
|
|
683
|
-
>({
|
|
684
|
-
query: (options) => ({
|
|
685
|
-
url: buildClientRequestUrl(checkout.setAttributeBasedShippingOption, {
|
|
686
|
-
useFormData: true
|
|
687
|
-
}),
|
|
688
|
-
method: 'POST',
|
|
689
|
-
body: {
|
|
690
|
-
attribute_based_shipping_options: JSON.stringify(options)
|
|
691
|
-
}
|
|
692
|
-
}),
|
|
693
|
-
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
694
|
-
dispatch(setShippingStepBusy(true));
|
|
695
|
-
await queryFulfilled;
|
|
696
|
-
dispatch(setShippingStepBusy(false));
|
|
697
|
-
}
|
|
698
657
|
})
|
|
699
658
|
}),
|
|
700
659
|
overrideExisting: false
|
|
@@ -713,7 +672,6 @@ export const {
|
|
|
713
672
|
useSetDeliveryOptionMutation,
|
|
714
673
|
useSetAddressesMutation,
|
|
715
674
|
useSetShippingOptionMutation,
|
|
716
|
-
useSetDataSourceShippingOptionsMutation,
|
|
717
675
|
useSetPaymentOptionMutation,
|
|
718
676
|
useSetBinNumberMutation,
|
|
719
677
|
useSetInstallmentOptionMutation,
|
|
@@ -730,6 +688,5 @@ export const {
|
|
|
730
688
|
useCompleteLoyaltyPaymentMutation,
|
|
731
689
|
useGetCheckoutLoyaltyBalanceQuery,
|
|
732
690
|
usePayWithLoyaltyBalanceMutation,
|
|
733
|
-
useSetOrderNoteMutation
|
|
734
|
-
useSetAttributeBasedShippingOptionsMutation
|
|
691
|
+
useSetOrderNoteMutation
|
|
735
692
|
} = checkoutApi;
|
package/data/server/category.ts
CHANGED
|
@@ -8,7 +8,7 @@ import logger from '../../utils/log';
|
|
|
8
8
|
|
|
9
9
|
function getCategoryDataHandler(
|
|
10
10
|
pk: number,
|
|
11
|
-
searchParams?:
|
|
11
|
+
searchParams?: URLSearchParams,
|
|
12
12
|
headers?: Record<string, string>
|
|
13
13
|
) {
|
|
14
14
|
return async function () {
|
|
@@ -78,7 +78,7 @@ export const getCategoryData = ({
|
|
|
78
78
|
headers
|
|
79
79
|
}: {
|
|
80
80
|
pk: number;
|
|
81
|
-
searchParams?:
|
|
81
|
+
searchParams?: URLSearchParams;
|
|
82
82
|
headers?: Record<string, string>;
|
|
83
83
|
}) => {
|
|
84
84
|
return Cache.wrap(
|
package/data/server/list.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { parse } from 'lossless-json';
|
|
|
7
7
|
import logger from '../../utils/log';
|
|
8
8
|
|
|
9
9
|
const getListDataHandler = (
|
|
10
|
-
searchParams:
|
|
10
|
+
searchParams: URLSearchParams,
|
|
11
11
|
headers?: Record<string, string>
|
|
12
12
|
) => {
|
|
13
13
|
return async function () {
|
|
@@ -54,7 +54,7 @@ export const getListData = async ({
|
|
|
54
54
|
searchParams,
|
|
55
55
|
headers
|
|
56
56
|
}: {
|
|
57
|
-
searchParams:
|
|
57
|
+
searchParams: URLSearchParams;
|
|
58
58
|
headers?: Record<string, string>;
|
|
59
59
|
}) => {
|
|
60
60
|
return Cache.wrap(
|
package/data/server/product.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Cache, CacheKey } from '../../lib/cache';
|
|
2
2
|
import { product } from '../urls';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
BreadcrumbResultType,
|
|
5
|
+
ProductCategoryResult,
|
|
6
|
+
ProductResult
|
|
7
|
+
} from '../../types';
|
|
4
8
|
import appFetch from '../../utils/app-fetch';
|
|
5
|
-
import logger from '../../utils/log';
|
|
6
9
|
|
|
7
10
|
type GetProduct = {
|
|
8
11
|
pk: number;
|
|
9
|
-
searchParams?:
|
|
12
|
+
searchParams?: URLSearchParams;
|
|
10
13
|
groupProduct?: boolean;
|
|
11
14
|
};
|
|
12
15
|
|
|
@@ -47,17 +50,9 @@ const getProductDataHandler = ({
|
|
|
47
50
|
}
|
|
48
51
|
);
|
|
49
52
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
logger.warn('menuItemModel is undefined, skipping breadcrumbData fetch', {
|
|
54
|
-
handler: 'getProductDataHandler',
|
|
55
|
-
pk
|
|
56
|
-
});
|
|
57
|
-
return { data, breadcrumbData: undefined };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const breadcrumbUrl = product.breadcrumbUrl(menuItemModel);
|
|
53
|
+
const breadcrumbUrl = product.breadcrumbUrl(
|
|
54
|
+
productCategoryData.results[0].menuitemmodel
|
|
55
|
+
);
|
|
61
56
|
|
|
62
57
|
const breadcrumbData = await appFetch<any>(breadcrumbUrl, {
|
|
63
58
|
headers: {
|
|
@@ -79,7 +74,10 @@ export const getProductData = async ({
|
|
|
79
74
|
groupProduct
|
|
80
75
|
}: GetProduct) => {
|
|
81
76
|
return Cache.wrap(
|
|
82
|
-
CacheKey[groupProduct ? 'GroupProduct' : 'Product'](
|
|
77
|
+
CacheKey[groupProduct ? 'GroupProduct' : 'Product'](
|
|
78
|
+
pk,
|
|
79
|
+
searchParams ?? new URLSearchParams()
|
|
80
|
+
),
|
|
83
81
|
getProductDataHandler({ pk, searchParams, groupProduct }),
|
|
84
82
|
{
|
|
85
83
|
expire: 300
|
|
@@ -7,7 +7,7 @@ import header from '../../redux/reducers/header';
|
|
|
7
7
|
|
|
8
8
|
const getSpecialPageDataHandler = (
|
|
9
9
|
pk: number,
|
|
10
|
-
searchParams:
|
|
10
|
+
searchParams: URLSearchParams,
|
|
11
11
|
headers?: Record<string, string>
|
|
12
12
|
) => {
|
|
13
13
|
return async function () {
|
|
@@ -34,7 +34,7 @@ export const getSpecialPageData = async ({
|
|
|
34
34
|
headers
|
|
35
35
|
}: {
|
|
36
36
|
pk: number;
|
|
37
|
-
searchParams:
|
|
37
|
+
searchParams: URLSearchParams;
|
|
38
38
|
headers?: Record<string, string>;
|
|
39
39
|
}) => {
|
|
40
40
|
return Cache.wrap(
|
package/data/urls.ts
CHANGED
|
@@ -83,8 +83,6 @@ export const checkout = {
|
|
|
83
83
|
setDeliveryOption: '/orders/checkout/?page=DeliveryOptionSelectionPage',
|
|
84
84
|
setAddresses: '/orders/checkout/?page=AddressSelectionPage',
|
|
85
85
|
setShippingOption: '/orders/checkout/?page=ShippingOptionSelectionPage',
|
|
86
|
-
setDataSourceShippingOption:
|
|
87
|
-
'/orders/checkout/?page=DataSourceShippingOptionSelectionPage',
|
|
88
86
|
setPaymentOption: '/orders/checkout/?page=PaymentOptionSelectionPage',
|
|
89
87
|
setBinNumber: '/orders/checkout/?page=BinNumberPage',
|
|
90
88
|
setMasterpassBinNumber: '/orders/checkout/?page=MasterpassBinNumberPage',
|
|
@@ -110,9 +108,7 @@ export const checkout = {
|
|
|
110
108
|
completeLoyaltyPayment: '/orders/checkout/?page=LoyaltyPaymentSelectedPage',
|
|
111
109
|
loyaltyMoneyUsage: '/orders/checkout/?page=LoyaltyMoneyUsagePage',
|
|
112
110
|
setOrderNote: '/orders/checkout/?page=OrderNotePage',
|
|
113
|
-
couponSelectionPage: '/orders/checkout/?page=CouponSelectionPage'
|
|
114
|
-
setAttributeBasedShippingOption:
|
|
115
|
-
'/orders/checkout/?page=AttributeBasedShippingOptionSelectionPage'
|
|
111
|
+
couponSelectionPage: '/orders/checkout/?page=CouponSelectionPage'
|
|
116
112
|
};
|
|
117
113
|
|
|
118
114
|
export const flatpage = {
|
package/hooks/index.ts
CHANGED
|
@@ -8,5 +8,4 @@ export * from './use-media-query';
|
|
|
8
8
|
export * from './use-on-click-outside';
|
|
9
9
|
export * from './use-mobile-iframe-handler';
|
|
10
10
|
export * from './use-payment-options';
|
|
11
|
-
export * from './use-pagination';
|
|
12
|
-
export * from './use-message-listener';
|
|
11
|
+
export * from './use-pagination';
|
|
@@ -18,8 +18,7 @@ export const usePaymentOptions = () => {
|
|
|
18
18
|
pay_on_delivery: 'pz-pay-on-delivery',
|
|
19
19
|
bkm_express: 'pz-bkm',
|
|
20
20
|
credit_payment: 'pz-credit-payment',
|
|
21
|
-
masterpass: 'pz-masterpass'
|
|
22
|
-
gpay: 'pz-gpay'
|
|
21
|
+
masterpass: 'pz-masterpass'
|
|
23
22
|
};
|
|
24
23
|
|
|
25
24
|
const isInitialTypeIncluded = (type: string) => initialTypes.has(type);
|
package/lib/cache.ts
CHANGED
|
@@ -20,16 +20,13 @@ const hashCacheKey = (object?: Record<string, string>) => {
|
|
|
20
20
|
return `_${encodeURIComponent(cacheKey)}`;
|
|
21
21
|
};
|
|
22
22
|
export const CacheKey = {
|
|
23
|
-
List: (
|
|
24
|
-
searchParams: { [key: string]: string | string[] | undefined },
|
|
25
|
-
headers?: Record<string, string>
|
|
26
|
-
) =>
|
|
23
|
+
List: (searchParams: URLSearchParams, headers?: Record<string, string>) =>
|
|
27
24
|
`list_${encodeURIComponent(JSON.stringify(searchParams))}${hashCacheKey(
|
|
28
25
|
headers
|
|
29
26
|
)}`,
|
|
30
27
|
Category: (
|
|
31
28
|
pk: number,
|
|
32
|
-
searchParams?:
|
|
29
|
+
searchParams?: URLSearchParams,
|
|
33
30
|
headers?: Record<string, string>
|
|
34
31
|
) =>
|
|
35
32
|
`category_${pk}_${encodeURIComponent(
|
|
@@ -38,20 +35,15 @@ export const CacheKey = {
|
|
|
38
35
|
CategorySlug: (slug: string) => `category_${slug}`,
|
|
39
36
|
SpecialPage: (
|
|
40
37
|
pk: number,
|
|
41
|
-
searchParams:
|
|
38
|
+
searchParams: URLSearchParams,
|
|
42
39
|
headers?: Record<string, string>
|
|
43
40
|
) =>
|
|
44
41
|
`special_page_${pk}_${encodeURIComponent(
|
|
45
42
|
JSON.stringify(searchParams)
|
|
46
43
|
)}${hashCacheKey(headers)}`,
|
|
47
|
-
Product: (
|
|
48
|
-
pk
|
|
49
|
-
|
|
50
|
-
) => `product_${pk}_${encodeURIComponent(JSON.stringify(searchParams))}`,
|
|
51
|
-
GroupProduct: (
|
|
52
|
-
pk: number,
|
|
53
|
-
searchParams: { [key: string]: string | string[] | undefined }
|
|
54
|
-
) =>
|
|
44
|
+
Product: (pk: number, searchParams: URLSearchParams) =>
|
|
45
|
+
`product_${pk}_${encodeURIComponent(JSON.stringify(searchParams))}`,
|
|
46
|
+
GroupProduct: (pk: number, searchParams: URLSearchParams) =>
|
|
55
47
|
`group_product_${pk}_${encodeURIComponent(JSON.stringify(searchParams))}`,
|
|
56
48
|
FlatPage: (pk: number) => `flat_page_${pk}`,
|
|
57
49
|
LandingPage: (pk: number) => `landing_page_${pk}`,
|
|
@@ -166,10 +158,6 @@ export class Cache {
|
|
|
166
158
|
handler: () => Promise<T>,
|
|
167
159
|
options?: CacheOptions
|
|
168
160
|
): Promise<T> {
|
|
169
|
-
if (Settings.usePrettyUrlRoute) {
|
|
170
|
-
return await handler();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
161
|
const requiredVariables = [
|
|
174
162
|
process.env.CACHE_HOST,
|
|
175
163
|
process.env.CACHE_PORT,
|
package/middlewares/default.ts
CHANGED
|
@@ -69,10 +69,6 @@ const withPzDefault =
|
|
|
69
69
|
return NextResponse.json({ status: 'ok' });
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
if (url.pathname.startsWith('/metrics')) {
|
|
73
|
-
return new NextResponse(null, { status: 200 });
|
|
74
|
-
}
|
|
75
|
-
|
|
76
72
|
if (req.nextUrl.pathname.startsWith('/.well-known')) {
|
|
77
73
|
const url = new URL(`${Settings.commerceUrl}${req.nextUrl.pathname}`);
|
|
78
74
|
const req_ = await fetch(url.toString());
|
|
@@ -88,44 +84,14 @@ const withPzDefault =
|
|
|
88
84
|
req.nextUrl.pathname.includes('/orders/hooks/') ||
|
|
89
85
|
req.nextUrl.pathname.includes('/orders/checkout-with-token/')
|
|
90
86
|
) {
|
|
91
|
-
|
|
92
|
-
const currency = url.searchParams.get('currency')?.toLowerCase();
|
|
93
|
-
|
|
94
|
-
const headers = {};
|
|
95
|
-
|
|
96
|
-
if (segment) {
|
|
97
|
-
headers['X-Segment-Id'] = segment;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (currency) {
|
|
101
|
-
headers['x-currency'] = currency;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const response = NextResponse.rewrite(
|
|
87
|
+
return NextResponse.rewrite(
|
|
105
88
|
new URL(
|
|
106
89
|
`${Settings.commerceUrl}${req.nextUrl.pathname.replace(
|
|
107
90
|
urlLocaleMatcherRegex,
|
|
108
91
|
''
|
|
109
92
|
)}`
|
|
110
|
-
)
|
|
111
|
-
{
|
|
112
|
-
headers
|
|
113
|
-
}
|
|
93
|
+
)
|
|
114
94
|
);
|
|
115
|
-
|
|
116
|
-
if (segment) {
|
|
117
|
-
response.cookies.set('pz-segment', segment);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (currency) {
|
|
121
|
-
response.cookies.set('pz-currency', currency, {
|
|
122
|
-
sameSite: 'none',
|
|
123
|
-
secure: true,
|
|
124
|
-
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7) // 7 days
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return response;
|
|
129
95
|
}
|
|
130
96
|
|
|
131
97
|
if (req.nextUrl.pathname.startsWith('/orders/redirection/')) {
|
|
@@ -237,20 +203,6 @@ const withPzDefault =
|
|
|
237
203
|
);
|
|
238
204
|
}
|
|
239
205
|
|
|
240
|
-
if (
|
|
241
|
-
Settings.usePrettyUrlRoute &&
|
|
242
|
-
url.searchParams.toString().length > 0 &&
|
|
243
|
-
!Object.entries(ROUTES).find(([, value]) =>
|
|
244
|
-
new RegExp(`^${value}/?$`).test(
|
|
245
|
-
pathnameWithoutLocale
|
|
246
|
-
)
|
|
247
|
-
)
|
|
248
|
-
) {
|
|
249
|
-
url.pathname =
|
|
250
|
-
url.pathname +
|
|
251
|
-
`searchparams|${url.searchParams.toString()}`;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
206
|
Settings.rewrites.forEach((rewrite) => {
|
|
255
207
|
url.pathname = url.pathname.replace(
|
|
256
208
|
rewrite.source,
|
package/middlewares/locale.ts
CHANGED
|
@@ -5,6 +5,22 @@ import { LocaleUrlStrategy } from '../localization';
|
|
|
5
5
|
import { urlLocaleMatcherRegex } from '../utils';
|
|
6
6
|
import logger from '../utils/log';
|
|
7
7
|
|
|
8
|
+
const getMatchedLocale = (pathname: string) => {
|
|
9
|
+
let matchedLocale = pathname.match(urlLocaleMatcherRegex)?.[0] ?? '';
|
|
10
|
+
matchedLocale = matchedLocale.replace('/', '');
|
|
11
|
+
|
|
12
|
+
if (!matchedLocale.length) {
|
|
13
|
+
if (
|
|
14
|
+
settings.localization.localeUrlStrategy !==
|
|
15
|
+
LocaleUrlStrategy.ShowAllLocales
|
|
16
|
+
) {
|
|
17
|
+
matchedLocale = settings.localization.defaultLocaleValue;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return matchedLocale;
|
|
22
|
+
};
|
|
23
|
+
|
|
8
24
|
const withLocale =
|
|
9
25
|
(middleware: NextMiddleware) =>
|
|
10
26
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
@@ -12,12 +28,12 @@ const withLocale =
|
|
|
12
28
|
|
|
13
29
|
try {
|
|
14
30
|
const url = req.nextUrl.clone();
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
const matchedLocale = getMatchedLocale(url.pathname);
|
|
32
|
+
let { localeUrlStrategy, defaultLocaleValue, redirectToDefaultLocale } =
|
|
33
|
+
settings.localization;
|
|
34
|
+
|
|
35
|
+
localeUrlStrategy =
|
|
36
|
+
localeUrlStrategy ?? LocaleUrlStrategy.HideDefaultLocale;
|
|
21
37
|
|
|
22
38
|
if (!defaultLocaleValue) {
|
|
23
39
|
logger.error('Default locale value is not defined in settings.', {
|
|
@@ -29,34 +45,16 @@ const withLocale =
|
|
|
29
45
|
}
|
|
30
46
|
|
|
31
47
|
if (
|
|
32
|
-
|
|
33
|
-
localeUrlStrategy === LocaleUrlStrategy.ShowAllLocales
|
|
48
|
+
!matchedLocale?.length &&
|
|
49
|
+
localeUrlStrategy === LocaleUrlStrategy.ShowAllLocales &&
|
|
50
|
+
redirectToDefaultLocale &&
|
|
51
|
+
req.method === 'GET'
|
|
34
52
|
) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (pathParts[0] === singleLocale) {
|
|
39
|
-
url.pathname = '/' + pathParts.slice(1).join('/');
|
|
40
|
-
return NextResponse.redirect(url);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
req.middlewareParams.rewrites.locale = singleLocale;
|
|
44
|
-
} else {
|
|
45
|
-
const matchedLocale =
|
|
46
|
-
url.pathname.match(urlLocaleMatcherRegex)?.[0]?.replace('/', '') ||
|
|
47
|
-
'';
|
|
48
|
-
if (
|
|
49
|
-
!matchedLocale &&
|
|
50
|
-
localeUrlStrategy === LocaleUrlStrategy.ShowAllLocales &&
|
|
51
|
-
redirectToDefaultLocale &&
|
|
52
|
-
req.method === 'GET'
|
|
53
|
-
) {
|
|
54
|
-
url.pathname = `/${defaultLocaleValue}${url.pathname}`;
|
|
55
|
-
return NextResponse.redirect(url);
|
|
56
|
-
}
|
|
57
|
-
req.middlewareParams.rewrites.locale =
|
|
58
|
-
matchedLocale || defaultLocaleValue;
|
|
53
|
+
url.pathname = `/${defaultLocaleValue}${url.pathname}`;
|
|
54
|
+
return NextResponse.redirect(url);
|
|
59
55
|
}
|
|
56
|
+
|
|
57
|
+
req.middlewareParams.rewrites.locale = matchedLocale;
|
|
60
58
|
} catch (error) {
|
|
61
59
|
logger.error('withLocale error', {
|
|
62
60
|
error,
|
|
@@ -56,10 +56,6 @@ const resolvePrettyUrl = async (pathname: string, ip: string | null) => {
|
|
|
56
56
|
const withPrettyUrl =
|
|
57
57
|
(middleware: NextMiddleware) =>
|
|
58
58
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
59
|
-
if (Settings.usePrettyUrlRoute) {
|
|
60
|
-
return middleware(req, event);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
59
|
const url = req.nextUrl.clone();
|
|
64
60
|
const matchedLanguagePrefix = url.pathname.match(
|
|
65
61
|
urlLocaleMatcherRegex
|
|
@@ -11,10 +11,6 @@ import { ROUTES } from 'routes';
|
|
|
11
11
|
const withUrlRedirection =
|
|
12
12
|
(middleware: NextMiddleware) =>
|
|
13
13
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
14
|
-
if (settings.usePrettyUrlRoute) {
|
|
15
|
-
return middleware(req, event);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
14
|
const url = req.nextUrl.clone();
|
|
19
15
|
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
20
16
|
const pathnameWithoutLocale = url.pathname.replace(
|
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": "1.45.0
|
|
4
|
+
"version": "1.45.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -20,22 +20,21 @@
|
|
|
20
20
|
"@opentelemetry/sdk-trace-node": "1.19.0",
|
|
21
21
|
"@opentelemetry/semantic-conventions": "1.19.0",
|
|
22
22
|
"@reduxjs/toolkit": "1.9.7",
|
|
23
|
-
"@neshca/cache-handler": "1.5.1",
|
|
24
23
|
"cross-spawn": "7.0.3",
|
|
25
24
|
"generic-pool": "3.9.0",
|
|
26
25
|
"react-redux": "8.1.3",
|
|
27
26
|
"react-string-replace": "1.1.1",
|
|
28
|
-
"redis": "4.
|
|
29
|
-
"semver": "7.
|
|
27
|
+
"redis": "4.5.1",
|
|
28
|
+
"semver": "7.5.4",
|
|
30
29
|
"set-cookie-parser": "2.6.0"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@akinon/eslint-plugin-projectzero": "1.45.0-rc.0",
|
|
34
32
|
"@types/react-redux": "7.1.30",
|
|
35
33
|
"@types/set-cookie-parser": "2.4.7",
|
|
36
34
|
"@typescript-eslint/eslint-plugin": "6.7.4",
|
|
37
35
|
"@typescript-eslint/parser": "6.7.4",
|
|
38
36
|
"eslint": "^8.14.0",
|
|
37
|
+
"@akinon/eslint-plugin-projectzero": "1.45.0",
|
|
39
38
|
"eslint-config-prettier": "8.5.0"
|
|
40
39
|
}
|
|
41
40
|
}
|
package/plugins.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ declare module '@akinon/pz-masterpass/src/utils' {
|
|
|
12
12
|
declare module '@akinon/pz-masterpass/src/redux/reducer' {
|
|
13
13
|
export const setError: any;
|
|
14
14
|
export const setOtpModalVisible: any;
|
|
15
|
-
export const setCvcRequired: any;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
declare module '@akinon/pz-otp' {
|