@akinon/next 2.0.0-beta.1 → 2.0.0-beta.11
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/.eslintrc.js +12 -0
- package/CHANGELOG.md +56 -0
- package/__tests__/next-config.test.ts +83 -0
- package/__tests__/tsconfig.json +23 -0
- package/api/auth.ts +72 -5
- package/api/client.ts +18 -1
- package/babel.config.js +6 -0
- package/bin/pz-prebuild.js +1 -0
- package/bin/pz-run-tests.js +99 -0
- package/bin/run-prebuild-tests.js +46 -0
- package/components/accordion.tsx +1 -1
- package/components/button.tsx +51 -36
- package/components/client-root.tsx +20 -0
- package/components/input.tsx +1 -1
- package/components/modal.tsx +1 -1
- package/components/price.tsx +2 -2
- package/components/select.tsx +1 -1
- package/components/selected-payment-option-view.tsx +1 -1
- package/data/client/api.ts +2 -0
- package/data/client/basket.ts +27 -5
- package/data/client/checkout.ts +62 -7
- package/data/client/misc.ts +25 -1
- package/data/client/product.ts +19 -2
- package/data/client/user.ts +16 -8
- package/data/server/flatpage.ts +8 -4
- package/data/server/form.ts +12 -4
- package/data/server/landingpage.ts +8 -4
- package/data/server/menu.ts +7 -2
- package/data/server/product.ts +16 -5
- package/data/server/seo.ts +11 -4
- package/data/server/widget.ts +19 -4
- package/data/urls.ts +11 -3
- package/hooks/index.ts +1 -0
- package/hooks/use-localization.ts +24 -10
- package/hooks/use-router.ts +5 -2
- package/hooks/use-sentry-uncaught-errors.ts +24 -0
- package/instrumentation/index.ts +10 -0
- package/jest.config.js +19 -0
- package/lib/cache-handler.mjs +2 -2
- package/lib/cache.ts +4 -4
- package/localization/index.ts +2 -1
- package/middlewares/default.ts +31 -4
- package/middlewares/locale.ts +35 -11
- package/middlewares/url-redirection.ts +16 -0
- package/package.json +8 -4
- package/plugins.js +2 -1
- package/redux/middlewares/checkout.ts +30 -130
- package/redux/middlewares/index.ts +6 -2
- package/redux/middlewares/pre-order/address.ts +50 -0
- package/redux/middlewares/pre-order/attribute-based-shipping-option.ts +46 -0
- package/redux/middlewares/pre-order/data-source-shipping-option.ts +43 -0
- package/redux/middlewares/pre-order/delivery-option.ts +40 -0
- package/redux/middlewares/pre-order/index.ts +29 -0
- package/redux/middlewares/pre-order/installment-option.ts +42 -0
- package/redux/middlewares/pre-order/payment-option.ts +34 -0
- package/redux/middlewares/pre-order/pre-order-validation.ts +24 -0
- package/redux/middlewares/pre-order/redirection.ts +40 -0
- package/redux/middlewares/pre-order/set-pre-order.ts +22 -0
- package/redux/middlewares/pre-order/shipping-option.ts +44 -0
- package/redux/middlewares/pre-order/shipping-step.ts +38 -0
- package/redux/reducers/checkout.ts +8 -2
- package/redux/reducers/index.ts +5 -3
- package/redux/reducers/root.ts +7 -2
- package/sentry/index.ts +36 -17
- package/tailwind/content.js +16 -0
- package/types/commerce/account.ts +5 -1
- package/types/commerce/checkout.ts +23 -0
- package/types/index.ts +7 -2
- package/utils/get-root-hostname.ts +28 -0
- package/utils/index.ts +6 -2
- package/utils/localization.ts +4 -0
- package/utils/override-middleware.ts +25 -0
- package/views/error-page.tsx +93 -0
- package/with-pz-config.js +4 -3
package/components/select.tsx
CHANGED
|
@@ -41,7 +41,7 @@ const Select = forwardRef<HTMLSelectElement, SelectProps>((props, ref) => {
|
|
|
41
41
|
ref={ref}
|
|
42
42
|
className={twMerge(
|
|
43
43
|
clsx(
|
|
44
|
-
'cursor-pointer truncate h-10 w-40 px-2.5 shrink-0 outline-
|
|
44
|
+
'cursor-pointer truncate h-10 w-40 px-2.5 shrink-0 outline-hidden',
|
|
45
45
|
!borderless &&
|
|
46
46
|
'border border-gray-200 transition-all duration-150 hover:border-primary'
|
|
47
47
|
),
|
|
@@ -4,7 +4,7 @@ import { RootState } from 'redux/store';
|
|
|
4
4
|
import { useAppSelector } from '../redux/hooks';
|
|
5
5
|
import dynamic, { DynamicOptionsLoadingProps } from 'next/dynamic';
|
|
6
6
|
import { PaymentOptionViews } from 'views/checkout/steps/payment';
|
|
7
|
-
import { useMemo } from 'react';
|
|
7
|
+
import { JSX, useMemo } from 'react';
|
|
8
8
|
|
|
9
9
|
const fallbackView = () => <></>;
|
|
10
10
|
|
package/data/client/api.ts
CHANGED
package/data/client/basket.ts
CHANGED
|
@@ -24,6 +24,26 @@ export const basketApi = api.injectEndpoints({
|
|
|
24
24
|
transformResponse: (response: { basket: Basket }) => response.basket,
|
|
25
25
|
providesTags: ['Basket']
|
|
26
26
|
}),
|
|
27
|
+
getMiniBasket: build.query<
|
|
28
|
+
{ pk: number | null; total_quantity: number },
|
|
29
|
+
void
|
|
30
|
+
>({
|
|
31
|
+
query: () =>
|
|
32
|
+
buildClientRequestUrl(basket.getMiniBasket, {
|
|
33
|
+
contentType: 'application/json'
|
|
34
|
+
}),
|
|
35
|
+
providesTags: ['MiniBasket']
|
|
36
|
+
}),
|
|
37
|
+
getMiniBasketDetail: build.query<
|
|
38
|
+
{ pk: number | null; total_quantity: number },
|
|
39
|
+
{ namespace: string }
|
|
40
|
+
>({
|
|
41
|
+
query: ({ namespace }) =>
|
|
42
|
+
buildClientRequestUrl(basket.getMiniBasketDetail(namespace), {
|
|
43
|
+
contentType: 'application/json'
|
|
44
|
+
}),
|
|
45
|
+
providesTags: ['MiniBasket']
|
|
46
|
+
}),
|
|
27
47
|
getBasketDetail: build.query<Basket, { namespace: string }>({
|
|
28
48
|
query: ({ namespace }) =>
|
|
29
49
|
buildClientRequestUrl(basket.getBasketDetail(namespace)),
|
|
@@ -46,7 +66,7 @@ export const basketApi = api.injectEndpoints({
|
|
|
46
66
|
method: 'DELETE',
|
|
47
67
|
body: { pk }
|
|
48
68
|
}),
|
|
49
|
-
invalidatesTags: ['MultiBasket', 'Basket']
|
|
69
|
+
invalidatesTags: ['MultiBasket', 'Basket', 'MiniBasket']
|
|
50
70
|
}),
|
|
51
71
|
selectMainBasket: build.mutation<Basket, { pk: number }>({
|
|
52
72
|
query: ({ pk }) => ({
|
|
@@ -57,7 +77,7 @@ export const basketApi = api.injectEndpoints({
|
|
|
57
77
|
body: { pk }
|
|
58
78
|
}),
|
|
59
79
|
transformResponse: (response: { baskets: Basket }) => response.baskets,
|
|
60
|
-
invalidatesTags: ['MultiBasket', 'Basket']
|
|
80
|
+
invalidatesTags: ['MultiBasket', 'Basket', 'MiniBasket']
|
|
61
81
|
}),
|
|
62
82
|
selectNameSpaceMainBasket: build.mutation<Basket, { namespace: string }>({
|
|
63
83
|
query: ({ namespace }) => ({
|
|
@@ -71,7 +91,7 @@ export const basketApi = api.injectEndpoints({
|
|
|
71
91
|
body: { namespace }
|
|
72
92
|
}),
|
|
73
93
|
transformResponse: (response: { baskets: Basket }) => response.baskets,
|
|
74
|
-
invalidatesTags: ['MultiBasket', 'Basket']
|
|
94
|
+
invalidatesTags: ['MultiBasket', 'Basket', 'MiniBasket']
|
|
75
95
|
}),
|
|
76
96
|
updateQuantity: build.mutation<
|
|
77
97
|
UpdateQuantityResponse,
|
|
@@ -84,7 +104,7 @@ export const basketApi = api.injectEndpoints({
|
|
|
84
104
|
method: 'PUT',
|
|
85
105
|
body
|
|
86
106
|
}),
|
|
87
|
-
invalidatesTags: ['MultiBasket', 'Basket']
|
|
107
|
+
invalidatesTags: ['MultiBasket', 'Basket', 'MiniBasket']
|
|
88
108
|
}),
|
|
89
109
|
clearBasket: build.mutation<Basket, void>({
|
|
90
110
|
query: (body) => ({
|
|
@@ -95,7 +115,7 @@ export const basketApi = api.injectEndpoints({
|
|
|
95
115
|
body
|
|
96
116
|
}),
|
|
97
117
|
transformResponse: (response: { basket: Basket }) => response.basket,
|
|
98
|
-
invalidatesTags: ['Basket']
|
|
118
|
+
invalidatesTags: ['Basket', 'MiniBasket', 'MiniBasket']
|
|
99
119
|
}),
|
|
100
120
|
applyVoucherCode: build.mutation<Basket, { voucher_code: string }>({
|
|
101
121
|
query: (body) => ({
|
|
@@ -125,6 +145,8 @@ export const basketApi = api.injectEndpoints({
|
|
|
125
145
|
|
|
126
146
|
export const {
|
|
127
147
|
useGetBasketQuery,
|
|
148
|
+
useGetMiniBasketQuery,
|
|
149
|
+
useGetMiniBasketDetailQuery,
|
|
128
150
|
useLazyGetBasketDetailQuery,
|
|
129
151
|
useGetAllBasketsQuery,
|
|
130
152
|
useRemoveBasketMutation,
|
package/data/client/checkout.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
setBankAccounts,
|
|
3
3
|
setCardType,
|
|
4
4
|
setInstallmentOptions,
|
|
5
|
+
setPaymentOptions,
|
|
5
6
|
setPaymentStepBusy,
|
|
6
7
|
setSelectedBankAccountPk,
|
|
7
8
|
setSelectedCreditPaymentPk,
|
|
@@ -12,7 +13,9 @@ import {
|
|
|
12
13
|
ExtraField,
|
|
13
14
|
GuestLoginFormParams,
|
|
14
15
|
Order,
|
|
15
|
-
PreOrder
|
|
16
|
+
PreOrder,
|
|
17
|
+
SendSmsType,
|
|
18
|
+
VerifySmsType
|
|
16
19
|
} from '../../types';
|
|
17
20
|
import { buildClientRequestUrl } from '../../utils';
|
|
18
21
|
import { api } from './api';
|
|
@@ -182,6 +185,11 @@ export const checkoutApi = api.injectEndpoints({
|
|
|
182
185
|
}),
|
|
183
186
|
providesTags: ['Checkout']
|
|
184
187
|
}),
|
|
188
|
+
resetCheckoutState: build.query<CheckoutResponse, void>({
|
|
189
|
+
query: () => ({
|
|
190
|
+
url: buildClientRequestUrl(checkout.guestLogin, {})
|
|
191
|
+
})
|
|
192
|
+
}),
|
|
185
193
|
fetchCheckoutResult: build.query<{ order: Order }, string>({
|
|
186
194
|
query: (token: string) =>
|
|
187
195
|
buildClientRequestUrl(checkout.fetchCheckoutResult(token))
|
|
@@ -419,6 +427,12 @@ export const checkoutApi = api.injectEndpoints({
|
|
|
419
427
|
}
|
|
420
428
|
})
|
|
421
429
|
}),
|
|
430
|
+
fetchPaymentOptions: build.query<CheckoutResponse, void>({
|
|
431
|
+
query: () => ({
|
|
432
|
+
url: buildClientRequestUrl(checkout.setPaymentOption)
|
|
433
|
+
}),
|
|
434
|
+
providesTags: ['PaymentOptions']
|
|
435
|
+
}),
|
|
422
436
|
setPaymentOption: build.mutation<CheckoutResponse, number>({
|
|
423
437
|
query: (pk: number) => ({
|
|
424
438
|
url: buildClientRequestUrl(checkout.setPaymentOption, {
|
|
@@ -467,16 +481,15 @@ export const checkoutApi = api.injectEndpoints({
|
|
|
467
481
|
CheckoutResponse,
|
|
468
482
|
{
|
|
469
483
|
payment_token?: string;
|
|
484
|
+
[key: string]: any;
|
|
470
485
|
}
|
|
471
486
|
>({
|
|
472
|
-
query: (
|
|
487
|
+
query: (requestBody) => ({
|
|
473
488
|
url: buildClientRequestUrl(checkout.setWalletPaymentPage, {
|
|
474
489
|
useFormData: true
|
|
475
490
|
}),
|
|
476
491
|
method: 'POST',
|
|
477
|
-
body:
|
|
478
|
-
payment_token
|
|
479
|
-
}
|
|
492
|
+
body: requestBody
|
|
480
493
|
}),
|
|
481
494
|
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
482
495
|
dispatch(setPaymentStepBusy(true));
|
|
@@ -732,7 +745,27 @@ export const checkoutApi = api.injectEndpoints({
|
|
|
732
745
|
body: {
|
|
733
746
|
loyalty_amount_to_use: amount
|
|
734
747
|
}
|
|
735
|
-
})
|
|
748
|
+
}),
|
|
749
|
+
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
750
|
+
dispatch(setPaymentStepBusy(true));
|
|
751
|
+
dispatch(setPaymentOptions([]));
|
|
752
|
+
await queryFulfilled;
|
|
753
|
+
|
|
754
|
+
const paymentOptionsData = await dispatch(
|
|
755
|
+
checkoutApi.endpoints.fetchPaymentOptions.initiate()
|
|
756
|
+
).unwrap();
|
|
757
|
+
|
|
758
|
+
const paymentOptions = paymentOptionsData?.context_list?.find(
|
|
759
|
+
(context) => context?.page_name === 'PaymentOptionSelectionPage'
|
|
760
|
+
)?.page_context?.payment_options;
|
|
761
|
+
|
|
762
|
+
if (paymentOptions) {
|
|
763
|
+
dispatch(setPaymentOptions(paymentOptions));
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
dispatch(setPaymentStepBusy(false));
|
|
767
|
+
},
|
|
768
|
+
invalidatesTags: ['PaymentOptions']
|
|
736
769
|
}),
|
|
737
770
|
setOrderNote: build.mutation<CheckoutResponse, string>({
|
|
738
771
|
query: (notes) => ({
|
|
@@ -816,6 +849,24 @@ export const checkoutApi = api.injectEndpoints({
|
|
|
816
849
|
selected_loyalty_amount: amount
|
|
817
850
|
}
|
|
818
851
|
})
|
|
852
|
+
}),
|
|
853
|
+
sendSms: build.mutation<CheckoutResponse, SendSmsType>({
|
|
854
|
+
query: (body) => ({
|
|
855
|
+
url: buildClientRequestUrl(checkout.sendSmsPage, {
|
|
856
|
+
useFormData: true
|
|
857
|
+
}),
|
|
858
|
+
method: 'POST',
|
|
859
|
+
body
|
|
860
|
+
})
|
|
861
|
+
}),
|
|
862
|
+
verifySms: build.mutation<CheckoutResponse, VerifySmsType>({
|
|
863
|
+
query: (body) => ({
|
|
864
|
+
url: buildClientRequestUrl(checkout.verifySmsPage, {
|
|
865
|
+
useFormData: true
|
|
866
|
+
}),
|
|
867
|
+
method: 'POST',
|
|
868
|
+
body
|
|
869
|
+
})
|
|
819
870
|
})
|
|
820
871
|
}),
|
|
821
872
|
overrideExisting: false
|
|
@@ -835,6 +886,7 @@ export const {
|
|
|
835
886
|
useSetAddressesMutation,
|
|
836
887
|
useSetShippingOptionMutation,
|
|
837
888
|
useSetDataSourceShippingOptionsMutation,
|
|
889
|
+
useFetchPaymentOptionsQuery,
|
|
838
890
|
useSetPaymentOptionMutation,
|
|
839
891
|
useSetBinNumberMutation,
|
|
840
892
|
useSetInstallmentOptionMutation,
|
|
@@ -859,5 +911,8 @@ export const {
|
|
|
859
911
|
useSetLoyaltyDataMutation,
|
|
860
912
|
useSetWalletSelectionPageMutation,
|
|
861
913
|
useSetWalletPaymentPageMutation,
|
|
862
|
-
useSetWalletCompletePageMutation
|
|
914
|
+
useSetWalletCompletePageMutation,
|
|
915
|
+
useSendSmsMutation,
|
|
916
|
+
useVerifySmsMutation,
|
|
917
|
+
useResetCheckoutStateQuery
|
|
863
918
|
} = checkoutApi;
|
package/data/client/misc.ts
CHANGED
|
@@ -92,6 +92,29 @@ export const miscApi = api.injectEndpoints({
|
|
|
92
92
|
transformResponse: (response: { menu: MenuItemType[] }) => {
|
|
93
93
|
return response.menu;
|
|
94
94
|
}
|
|
95
|
+
}),
|
|
96
|
+
getBukalemunImageUrl: builder.query<
|
|
97
|
+
any,
|
|
98
|
+
{ current_chapter: string; sku: string; selected_attributes: any }
|
|
99
|
+
>({
|
|
100
|
+
query: ({ current_chapter, sku, selected_attributes }) => {
|
|
101
|
+
const data = {
|
|
102
|
+
...selected_attributes,
|
|
103
|
+
current_chapter,
|
|
104
|
+
sku
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const params = new URLSearchParams(data);
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
url: buildClientRequestUrl(
|
|
111
|
+
misc.bukalemunImageUrl(params.toString()),
|
|
112
|
+
{
|
|
113
|
+
responseType: 'json'
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
95
118
|
})
|
|
96
119
|
}),
|
|
97
120
|
overrideExisting: true
|
|
@@ -102,5 +125,6 @@ export const {
|
|
|
102
125
|
useEmailSubscriptionMutation,
|
|
103
126
|
useSetLanguageMutation,
|
|
104
127
|
useGetWidgetQuery,
|
|
105
|
-
useGetMenuQuery
|
|
128
|
+
useGetMenuQuery,
|
|
129
|
+
useGetBukalemunImageUrlQuery
|
|
106
130
|
} = miscApi;
|
package/data/client/product.ts
CHANGED
|
@@ -69,12 +69,28 @@ export const productApi = api.injectEndpoints({
|
|
|
69
69
|
}),
|
|
70
70
|
method: 'POST',
|
|
71
71
|
body
|
|
72
|
-
})
|
|
72
|
+
}),
|
|
73
|
+
invalidatesTags: ['MiniBasket']
|
|
73
74
|
}),
|
|
74
75
|
getInstallments: build.query<any, any>({
|
|
75
76
|
query: (productPk) => ({
|
|
76
77
|
url: buildClientRequestUrl(product.installments(productPk))
|
|
77
78
|
})
|
|
79
|
+
}),
|
|
80
|
+
getBundleProductData: build.query<
|
|
81
|
+
any,
|
|
82
|
+
{ productPk: string; queryString: string }
|
|
83
|
+
>({
|
|
84
|
+
query: ({ productPk, queryString }) => {
|
|
85
|
+
return {
|
|
86
|
+
url: buildClientRequestUrl(
|
|
87
|
+
product.bundleProduct(productPk, queryString),
|
|
88
|
+
{
|
|
89
|
+
responseType: 'json'
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
78
94
|
})
|
|
79
95
|
}),
|
|
80
96
|
overrideExisting: true
|
|
@@ -85,5 +101,6 @@ export const {
|
|
|
85
101
|
useGetProductByPkQuery,
|
|
86
102
|
useGetRetailStoreStockMutation,
|
|
87
103
|
useGetInstallmentsQuery,
|
|
88
|
-
useGetProductByParamsQuery
|
|
104
|
+
useGetProductByParamsQuery,
|
|
105
|
+
useGetBundleProductDataQuery
|
|
89
106
|
} = productApi;
|
package/data/client/user.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { api } from './api';
|
|
2
2
|
import { user } from '../urls';
|
|
3
3
|
import { ForgotPasswordFormType, Order } from '../../types';
|
|
4
|
-
import { buildClientRequestUrl } from '../../utils';
|
|
4
|
+
import { buildClientRequestUrl, getCookie } from '../../utils';
|
|
5
5
|
|
|
6
6
|
interface GetCaptchaResponse {
|
|
7
7
|
siteKey: string;
|
|
@@ -64,13 +64,21 @@ const userApi = api.injectEndpoints({
|
|
|
64
64
|
})
|
|
65
65
|
}),
|
|
66
66
|
forgotPassword: build.mutation<void, ForgotPasswordFormType>({
|
|
67
|
-
query: (body) =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
query: (body) => {
|
|
68
|
+
const frontendId = getCookie('pz-frontend-id');
|
|
69
|
+
const headers = frontendId
|
|
70
|
+
? { 'x-frontend-id': frontendId }
|
|
71
|
+
: undefined;
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
url: buildClientRequestUrl(user.forgotPassword, {
|
|
75
|
+
contentType: 'application/json'
|
|
76
|
+
}),
|
|
77
|
+
method: 'POST',
|
|
78
|
+
body,
|
|
79
|
+
headers
|
|
80
|
+
};
|
|
81
|
+
}
|
|
74
82
|
}),
|
|
75
83
|
otpLogin: build.mutation<void, { phone: string }>({
|
|
76
84
|
query: ({ phone }) => ({
|
package/data/server/flatpage.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { ServerVariables } from '../../utils/server-variables';
|
|
|
7
7
|
const getFlatPageDataHandler = (
|
|
8
8
|
pk: number,
|
|
9
9
|
locale: string,
|
|
10
|
-
currency: string
|
|
10
|
+
currency: string,
|
|
11
|
+
headers?: Record<string, string>
|
|
11
12
|
) => {
|
|
12
13
|
return async function () {
|
|
13
14
|
const data = await appFetch<FlatPage>({
|
|
@@ -17,7 +18,8 @@ const getFlatPageDataHandler = (
|
|
|
17
18
|
init: {
|
|
18
19
|
headers: {
|
|
19
20
|
Accept: 'application/json',
|
|
20
|
-
'Content-Type': 'application/json'
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
...(headers ?? {})
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
});
|
|
@@ -29,15 +31,17 @@ const getFlatPageDataHandler = (
|
|
|
29
31
|
export const getFlatPageData = ({
|
|
30
32
|
pk,
|
|
31
33
|
locale = ServerVariables.locale,
|
|
32
|
-
currency = ServerVariables.currency
|
|
34
|
+
currency = ServerVariables.currency,
|
|
35
|
+
headers
|
|
33
36
|
}: {
|
|
34
37
|
pk: number;
|
|
35
38
|
locale?: string;
|
|
36
39
|
currency?: string;
|
|
40
|
+
headers?: Record<string, string>;
|
|
37
41
|
}) => {
|
|
38
42
|
return Cache.wrap(
|
|
39
43
|
CacheKey.FlatPage(pk),
|
|
40
44
|
locale,
|
|
41
|
-
getFlatPageDataHandler(pk, locale, currency)
|
|
45
|
+
getFlatPageDataHandler(pk, locale, currency, headers)
|
|
42
46
|
);
|
|
43
47
|
};
|
package/data/server/form.ts
CHANGED
|
@@ -5,7 +5,12 @@ import appFetch from '../../utils/app-fetch';
|
|
|
5
5
|
import { ServerVariables } from '../../utils/server-variables';
|
|
6
6
|
import { form } from '../urls';
|
|
7
7
|
|
|
8
|
-
const getFormDataHandler = (
|
|
8
|
+
const getFormDataHandler = (
|
|
9
|
+
pk: number,
|
|
10
|
+
locale: string,
|
|
11
|
+
currency: string,
|
|
12
|
+
headers?: Record<string, string>
|
|
13
|
+
) => {
|
|
9
14
|
return async function () {
|
|
10
15
|
const data = await appFetch<FormType>({
|
|
11
16
|
url: form.getForm(pk),
|
|
@@ -14,7 +19,8 @@ const getFormDataHandler = (pk: number, locale: string, currency: string) => {
|
|
|
14
19
|
init: {
|
|
15
20
|
headers: {
|
|
16
21
|
Accept: 'application/json',
|
|
17
|
-
'Content-Type': 'application/json'
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
...(headers ?? {})
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
26
|
});
|
|
@@ -26,15 +32,17 @@ const getFormDataHandler = (pk: number, locale: string, currency: string) => {
|
|
|
26
32
|
export const getFormData = ({
|
|
27
33
|
pk,
|
|
28
34
|
locale = ServerVariables.locale,
|
|
29
|
-
currency = ServerVariables.currency
|
|
35
|
+
currency = ServerVariables.currency,
|
|
36
|
+
headers
|
|
30
37
|
}: {
|
|
31
38
|
pk: number;
|
|
32
39
|
locale?: string;
|
|
33
40
|
currency?: string;
|
|
41
|
+
headers?: Record<string, string>;
|
|
34
42
|
}) => {
|
|
35
43
|
return Cache.wrap(
|
|
36
44
|
CacheKey.Form(pk),
|
|
37
45
|
locale,
|
|
38
|
-
getFormDataHandler(pk, locale, currency)
|
|
46
|
+
getFormDataHandler(pk, locale, currency, headers)
|
|
39
47
|
);
|
|
40
48
|
};
|
|
@@ -7,7 +7,8 @@ import { ServerVariables } from '../../utils/server-variables';
|
|
|
7
7
|
const getLandingPageHandler = (
|
|
8
8
|
pk: number,
|
|
9
9
|
locale: string,
|
|
10
|
-
currency: string
|
|
10
|
+
currency: string,
|
|
11
|
+
headers?: Record<string, string>
|
|
11
12
|
) => {
|
|
12
13
|
return async function () {
|
|
13
14
|
const data = await appFetch<LandingPage>({
|
|
@@ -17,7 +18,8 @@ const getLandingPageHandler = (
|
|
|
17
18
|
init: {
|
|
18
19
|
headers: {
|
|
19
20
|
Accept: 'application/json',
|
|
20
|
-
'Content-Type': 'application/json'
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
...(headers ?? {})
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
});
|
|
@@ -29,15 +31,17 @@ const getLandingPageHandler = (
|
|
|
29
31
|
export const getLandingPageData = ({
|
|
30
32
|
pk,
|
|
31
33
|
locale = ServerVariables.locale,
|
|
32
|
-
currency = ServerVariables.currency
|
|
34
|
+
currency = ServerVariables.currency,
|
|
35
|
+
headers
|
|
33
36
|
}: {
|
|
34
37
|
pk: number;
|
|
35
38
|
locale?: string;
|
|
36
39
|
currency?: string;
|
|
40
|
+
headers?: Record<string, string>;
|
|
37
41
|
}) => {
|
|
38
42
|
return Cache.wrap(
|
|
39
43
|
CacheKey.LandingPage(pk),
|
|
40
44
|
locale,
|
|
41
|
-
getLandingPageHandler(pk, locale, currency)
|
|
45
|
+
getLandingPageHandler(pk, locale, currency, headers)
|
|
42
46
|
);
|
|
43
47
|
};
|
package/data/server/menu.ts
CHANGED
|
@@ -13,6 +13,7 @@ interface MenuHandlerParams {
|
|
|
13
13
|
currency?: string;
|
|
14
14
|
depth?: number;
|
|
15
15
|
parent?: string;
|
|
16
|
+
headers?: Record<string, string>;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
const DEFAULT_DEPTH = 3;
|
|
@@ -22,13 +23,17 @@ const getMenuHandler =
|
|
|
22
23
|
locale = ServerVariables.locale,
|
|
23
24
|
currency = ServerVariables.currency,
|
|
24
25
|
depth,
|
|
25
|
-
parent
|
|
26
|
+
parent,
|
|
27
|
+
headers
|
|
26
28
|
}: MenuHandlerParams = {}) =>
|
|
27
29
|
async () => {
|
|
28
30
|
const response = await appFetch<MenuResponse>({
|
|
29
31
|
url: misc.menus(depth ?? DEFAULT_DEPTH, parent),
|
|
30
32
|
locale,
|
|
31
|
-
currency
|
|
33
|
+
currency,
|
|
34
|
+
init: {
|
|
35
|
+
headers
|
|
36
|
+
}
|
|
32
37
|
});
|
|
33
38
|
|
|
34
39
|
return response?.menu;
|
package/data/server/product.ts
CHANGED
|
@@ -11,6 +11,7 @@ type GetProduct = {
|
|
|
11
11
|
currency?: string;
|
|
12
12
|
searchParams?: URLSearchParams;
|
|
13
13
|
groupProduct?: boolean;
|
|
14
|
+
headers?: Record<string, string>;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
const getProductDataHandler = ({
|
|
@@ -18,7 +19,8 @@ const getProductDataHandler = ({
|
|
|
18
19
|
locale,
|
|
19
20
|
currency,
|
|
20
21
|
searchParams,
|
|
21
|
-
groupProduct
|
|
22
|
+
groupProduct,
|
|
23
|
+
headers
|
|
22
24
|
}: GetProduct) => {
|
|
23
25
|
return async function () {
|
|
24
26
|
let url = groupProduct
|
|
@@ -29,7 +31,7 @@ const getProductDataHandler = ({
|
|
|
29
31
|
url +=
|
|
30
32
|
'?' +
|
|
31
33
|
Object.keys(searchParams)
|
|
32
|
-
.map((key) => `${key}=${searchParams[key]}`)
|
|
34
|
+
.map((key) => `${key}=${encodeURIComponent(searchParams[key])}`)
|
|
33
35
|
.join('&');
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -40,7 +42,8 @@ const getProductDataHandler = ({
|
|
|
40
42
|
init: {
|
|
41
43
|
headers: {
|
|
42
44
|
Accept: 'application/json',
|
|
43
|
-
'Content-Type': 'application/json'
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
...(headers ?? {})
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
});
|
|
@@ -95,7 +98,8 @@ export const getProductData = async ({
|
|
|
95
98
|
locale = ServerVariables.locale,
|
|
96
99
|
currency = ServerVariables.currency,
|
|
97
100
|
searchParams,
|
|
98
|
-
groupProduct
|
|
101
|
+
groupProduct,
|
|
102
|
+
headers
|
|
99
103
|
}: GetProduct) => {
|
|
100
104
|
return Cache.wrap(
|
|
101
105
|
CacheKey[groupProduct ? 'GroupProduct' : 'Product'](
|
|
@@ -103,7 +107,14 @@ export const getProductData = async ({
|
|
|
103
107
|
searchParams ?? new URLSearchParams()
|
|
104
108
|
),
|
|
105
109
|
locale,
|
|
106
|
-
getProductDataHandler({
|
|
110
|
+
getProductDataHandler({
|
|
111
|
+
pk,
|
|
112
|
+
locale,
|
|
113
|
+
currency,
|
|
114
|
+
searchParams,
|
|
115
|
+
groupProduct,
|
|
116
|
+
headers
|
|
117
|
+
}),
|
|
107
118
|
{
|
|
108
119
|
expire: 300
|
|
109
120
|
}
|
package/data/server/seo.ts
CHANGED
|
@@ -7,9 +7,10 @@ interface SeoDataParams {
|
|
|
7
7
|
url: string;
|
|
8
8
|
locale?: string;
|
|
9
9
|
currency?: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
function getSeoDataHandler({ url, locale, currency }: SeoDataParams) {
|
|
13
|
+
function getSeoDataHandler({ url, locale, currency, headers }: SeoDataParams) {
|
|
13
14
|
return async function () {
|
|
14
15
|
let data = {} as {
|
|
15
16
|
title: string;
|
|
@@ -19,7 +20,12 @@ function getSeoDataHandler({ url, locale, currency }: SeoDataParams) {
|
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
try {
|
|
22
|
-
data = await appFetch({
|
|
23
|
+
data = await appFetch({
|
|
24
|
+
url: misc.cmsSeo(url),
|
|
25
|
+
locale,
|
|
26
|
+
currency,
|
|
27
|
+
init: { headers }
|
|
28
|
+
});
|
|
23
29
|
} catch (error) {
|
|
24
30
|
// logger.error('Error while fetching seo data', { url, error });
|
|
25
31
|
}
|
|
@@ -31,11 +37,12 @@ function getSeoDataHandler({ url, locale, currency }: SeoDataParams) {
|
|
|
31
37
|
export const getSeoData = async (
|
|
32
38
|
url,
|
|
33
39
|
locale = ServerVariables.locale,
|
|
34
|
-
currency = ServerVariables.currency
|
|
40
|
+
currency = ServerVariables.currency,
|
|
41
|
+
headers?: Record<string, string>
|
|
35
42
|
) => {
|
|
36
43
|
return Cache.wrap(
|
|
37
44
|
CacheKey.Seo(url),
|
|
38
45
|
locale,
|
|
39
|
-
getSeoDataHandler({ url, locale, currency })
|
|
46
|
+
getSeoDataHandler({ url, locale, currency, headers })
|
|
40
47
|
);
|
|
41
48
|
};
|
package/data/server/widget.ts
CHANGED
|
@@ -6,29 +6,44 @@ import { widgets } from '../urls';
|
|
|
6
6
|
import { ServerVariables } from '../../utils/server-variables';
|
|
7
7
|
|
|
8
8
|
const getWidgetDataHandler =
|
|
9
|
-
(
|
|
9
|
+
(
|
|
10
|
+
slug: string,
|
|
11
|
+
locale: string,
|
|
12
|
+
currency: string,
|
|
13
|
+
headers?: Record<string, string>
|
|
14
|
+
) =>
|
|
15
|
+
async () => {
|
|
10
16
|
if (!slug) {
|
|
11
17
|
return null;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
return await appFetch({
|
|
20
|
+
return await appFetch({
|
|
21
|
+
url: widgets.getWidget(slug),
|
|
22
|
+
locale,
|
|
23
|
+
currency,
|
|
24
|
+
init: {
|
|
25
|
+
headers
|
|
26
|
+
}
|
|
27
|
+
});
|
|
15
28
|
};
|
|
16
29
|
|
|
17
30
|
export const getWidgetData = async <T>({
|
|
18
31
|
slug,
|
|
19
32
|
locale = ServerVariables.locale,
|
|
20
33
|
currency = ServerVariables.currency,
|
|
21
|
-
cacheOptions
|
|
34
|
+
cacheOptions,
|
|
35
|
+
headers
|
|
22
36
|
}: {
|
|
23
37
|
slug: string;
|
|
24
38
|
locale?: string;
|
|
25
39
|
currency?: string;
|
|
26
40
|
cacheOptions?: CacheOptions;
|
|
41
|
+
headers?: Record<string, string>;
|
|
27
42
|
}): Promise<WidgetResultType<T>> => {
|
|
28
43
|
return Cache.wrap(
|
|
29
44
|
CacheKey.Widget(slug),
|
|
30
45
|
locale,
|
|
31
|
-
getWidgetDataHandler(slug, locale, currency),
|
|
46
|
+
getWidgetDataHandler(slug, locale, currency, headers),
|
|
32
47
|
cacheOptions
|
|
33
48
|
);
|
|
34
49
|
};
|