@akinon/next 1.59.0 → 1.60.0-rc.7
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 +659 -0
- package/api/client.ts +23 -2
- package/assets/styles/index.css +49 -0
- package/assets/styles/index.css.map +1 -0
- package/assets/styles/index.scss +50 -26
- package/bin/pz-generate-translations.js +41 -0
- package/bin/pz-prebuild.js +1 -0
- package/bin/pz-predev.js +1 -0
- package/components/file-input.tsx +8 -0
- package/components/index.ts +1 -0
- package/components/input.tsx +21 -7
- package/components/link.tsx +17 -13
- package/components/plugin-module.tsx +8 -3
- package/components/price.tsx +11 -4
- package/components/pz-root.tsx +15 -3
- package/components/selected-payment-option-view.tsx +2 -1
- package/data/client/api.ts +1 -1
- package/data/client/b2b.ts +35 -2
- package/data/client/basket.ts +6 -5
- package/data/client/checkout.ts +55 -10
- package/data/client/user.ts +3 -2
- package/data/server/category.ts +43 -19
- package/data/server/flatpage.ts +29 -7
- package/data/server/form.ts +29 -11
- package/data/server/landingpage.ts +26 -7
- package/data/server/list.ts +16 -6
- package/data/server/menu.ts +15 -2
- package/data/server/product.ts +33 -13
- package/data/server/seo.ts +17 -24
- package/data/server/special-page.ts +15 -5
- package/data/server/widget.ts +14 -7
- package/data/urls.ts +8 -1
- package/hocs/server/with-segment-defaults.tsx +4 -1
- package/hooks/index.ts +2 -1
- package/hooks/use-message-listener.ts +24 -0
- package/hooks/use-pagination.ts +2 -2
- package/hooks/use-payment-options.ts +2 -1
- package/lib/cache-handler.mjs +33 -0
- package/lib/cache.ts +8 -6
- package/middlewares/currency.ts +2 -1
- package/middlewares/default.ts +226 -152
- package/middlewares/index.ts +3 -1
- package/middlewares/oauth-login.ts +3 -1
- package/middlewares/pretty-url.ts +11 -1
- package/middlewares/saved-card-redirection.ts +179 -0
- package/middlewares/url-redirection.ts +4 -0
- package/package.json +4 -3
- package/plugins.d.ts +6 -0
- package/plugins.js +2 -1
- package/redux/middlewares/checkout.ts +78 -14
- package/redux/reducers/checkout.ts +23 -3
- package/redux/reducers/index.ts +3 -1
- package/routes/pretty-url.tsx +192 -0
- package/types/commerce/address.ts +1 -1
- package/types/commerce/b2b.ts +12 -2
- package/types/commerce/checkout.ts +30 -0
- package/types/commerce/order.ts +1 -0
- package/types/index.ts +17 -2
- package/utils/app-fetch.ts +16 -8
- package/utils/generate-commerce-search-params.ts +3 -1
- package/utils/index.ts +27 -6
- package/utils/redirection-iframe.ts +85 -0
- package/utils/server-translation.ts +11 -1
- package/with-pz-config.js +13 -2
|
@@ -4,25 +4,30 @@ import { GetCategoryResponse } from '../../types';
|
|
|
4
4
|
import { generateCommerceSearchParams } from '../../utils';
|
|
5
5
|
import appFetch from '../../utils/app-fetch';
|
|
6
6
|
import header from '../../redux/reducers/header';
|
|
7
|
+
import { ServerVariables } from '../../utils/server-variables';
|
|
7
8
|
|
|
8
9
|
const getSpecialPageDataHandler = (
|
|
9
10
|
pk: number,
|
|
11
|
+
locale: string,
|
|
12
|
+
currency: string,
|
|
10
13
|
searchParams: URLSearchParams,
|
|
11
14
|
headers?: Record<string, string>
|
|
12
15
|
) => {
|
|
13
16
|
return async function () {
|
|
14
17
|
const params = generateCommerceSearchParams(searchParams);
|
|
15
18
|
|
|
16
|
-
const data: GetCategoryResponse = await appFetch(
|
|
17
|
-
`${category.getSpecialPageByPk(pk)}${params}`,
|
|
18
|
-
|
|
19
|
+
const data: GetCategoryResponse = await appFetch({
|
|
20
|
+
url: `${category.getSpecialPageByPk(pk)}${params}`,
|
|
21
|
+
locale,
|
|
22
|
+
currency,
|
|
23
|
+
init: {
|
|
19
24
|
headers: {
|
|
20
25
|
Accept: 'application/json',
|
|
21
26
|
'Content-Type': 'application/json',
|
|
22
27
|
...(headers ?? {})
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
|
-
);
|
|
30
|
+
});
|
|
26
31
|
|
|
27
32
|
return data;
|
|
28
33
|
};
|
|
@@ -30,16 +35,21 @@ const getSpecialPageDataHandler = (
|
|
|
30
35
|
|
|
31
36
|
export const getSpecialPageData = async ({
|
|
32
37
|
pk,
|
|
38
|
+
locale = ServerVariables.locale,
|
|
39
|
+
currency = ServerVariables.currency,
|
|
33
40
|
searchParams,
|
|
34
41
|
headers
|
|
35
42
|
}: {
|
|
36
43
|
pk: number;
|
|
44
|
+
locale?: string;
|
|
45
|
+
currency?: string;
|
|
37
46
|
searchParams: URLSearchParams;
|
|
38
47
|
headers?: Record<string, string>;
|
|
39
48
|
}) => {
|
|
40
49
|
return Cache.wrap(
|
|
41
50
|
CacheKey.SpecialPage(pk, searchParams, headers),
|
|
42
|
-
|
|
51
|
+
locale,
|
|
52
|
+
getSpecialPageDataHandler(pk, locale, currency, searchParams, headers),
|
|
43
53
|
{
|
|
44
54
|
expire: 300
|
|
45
55
|
}
|
package/data/server/widget.ts
CHANGED
|
@@ -3,25 +3,32 @@ import 'server-only';
|
|
|
3
3
|
import { CacheOptions, WidgetResultType } from '../../types';
|
|
4
4
|
import appFetch from '../../utils/app-fetch';
|
|
5
5
|
import { widgets } from '../urls';
|
|
6
|
+
import { ServerVariables } from '../../utils/server-variables';
|
|
6
7
|
|
|
7
|
-
const getWidgetDataHandler =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const getWidgetDataHandler =
|
|
9
|
+
(slug: string, locale: string, currency: string) => async () => {
|
|
10
|
+
if (!slug) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
+
return await appFetch({ url: widgets.getWidget(slug), locale, currency });
|
|
15
|
+
};
|
|
14
16
|
|
|
15
17
|
export const getWidgetData = async <T>({
|
|
16
18
|
slug,
|
|
19
|
+
locale = ServerVariables.locale,
|
|
20
|
+
currency = ServerVariables.currency,
|
|
17
21
|
cacheOptions
|
|
18
22
|
}: {
|
|
19
23
|
slug: string;
|
|
24
|
+
locale?: string;
|
|
25
|
+
currency?: string;
|
|
20
26
|
cacheOptions?: CacheOptions;
|
|
21
27
|
}): Promise<WidgetResultType<T>> => {
|
|
22
28
|
return Cache.wrap(
|
|
23
29
|
CacheKey.Widget(slug),
|
|
24
|
-
|
|
30
|
+
locale,
|
|
31
|
+
getWidgetDataHandler(slug, locale, currency),
|
|
25
32
|
cacheOptions
|
|
26
33
|
);
|
|
27
34
|
};
|
package/data/urls.ts
CHANGED
|
@@ -83,6 +83,8 @@ 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',
|
|
86
88
|
setPaymentOption: '/orders/checkout/?page=PaymentOptionSelectionPage',
|
|
87
89
|
setBinNumber: '/orders/checkout/?page=BinNumberPage',
|
|
88
90
|
setMasterpassBinNumber: '/orders/checkout/?page=MasterpassBinNumberPage',
|
|
@@ -109,6 +111,8 @@ export const checkout = {
|
|
|
109
111
|
loyaltyMoneyUsage: '/orders/checkout/?page=LoyaltyMoneyUsagePage',
|
|
110
112
|
setOrderNote: '/orders/checkout/?page=OrderNotePage',
|
|
111
113
|
couponSelectionPage: '/orders/checkout/?page=CouponSelectionPage',
|
|
114
|
+
setAttributeBasedShippingOption:
|
|
115
|
+
'/orders/checkout/?page=AttributeBasedShippingOptionSelectionPage',
|
|
112
116
|
deliveryBagsPage: '/orders/checkout/?page=DeliveryBagsPage',
|
|
113
117
|
setOrderSelectionPage: '/orders/checkout/?page=OrderSelectionPage'
|
|
114
118
|
};
|
|
@@ -199,7 +203,10 @@ export const b2b = {
|
|
|
199
203
|
draftBaskets: '/b2b/basket/drafts/',
|
|
200
204
|
divisions: '/b2b/my-divisions/',
|
|
201
205
|
myQuotations: '/b2b/my-quotations/',
|
|
202
|
-
loadBasket: (id) => `/b2b/basket/${id}/load
|
|
206
|
+
loadBasket: (id) => `/b2b/basket/${id}/load/`,
|
|
207
|
+
statusBasket: (cacheKey) => `/b2b/basket/?status_cache_key=${cacheKey}`,
|
|
208
|
+
basketExport: (queryString) => `/b2b/basket/?upload=true&${queryString}`,
|
|
209
|
+
basketImport: '/b2b/basket/bulk-import/'
|
|
203
210
|
};
|
|
204
211
|
|
|
205
212
|
export const widgets = {
|
|
@@ -2,7 +2,6 @@ import settings from 'settings';
|
|
|
2
2
|
import { LayoutProps, PageProps, RootLayoutProps } from '../../types';
|
|
3
3
|
import { redirect } from 'next/navigation';
|
|
4
4
|
import { ServerVariables } from '../../utils/server-variables';
|
|
5
|
-
import { getTranslations } from '../../utils/server-translation';
|
|
6
5
|
import { ROUTES } from 'routes';
|
|
7
6
|
import logger from '../../utils/log';
|
|
8
7
|
|
|
@@ -50,7 +49,11 @@ const addRootLayoutProps = async (componentProps: RootLayoutProps) => {
|
|
|
50
49
|
return redirect(ROUTES.HOME);
|
|
51
50
|
}
|
|
52
51
|
|
|
52
|
+
const { getTranslations } = settings.useOptimizedTranslations
|
|
53
|
+
? require('translations')
|
|
54
|
+
: require('../../utils/server-translation');
|
|
53
55
|
const translations = await getTranslations(params.locale);
|
|
56
|
+
|
|
54
57
|
componentProps.translations = translations;
|
|
55
58
|
|
|
56
59
|
const locale = settings.localization.locales.find(
|
package/hooks/index.ts
CHANGED
|
@@ -8,4 +8,5 @@ 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';
|
|
11
|
+
export * from './use-pagination';
|
|
12
|
+
export * from './use-message-listener';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useMessageListener = () => {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
const handleMessage = (event: MessageEvent) => {
|
|
6
|
+
if (event.origin !== window.location.origin) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (event.data && typeof event.data === 'string') {
|
|
11
|
+
const messageData = JSON.parse(event.data);
|
|
12
|
+
if (messageData?.url) {
|
|
13
|
+
window.location.href = messageData.url;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
window.addEventListener('message', handleMessage);
|
|
19
|
+
|
|
20
|
+
return () => {
|
|
21
|
+
window.removeEventListener('message', handleMessage);
|
|
22
|
+
};
|
|
23
|
+
}, []);
|
|
24
|
+
};
|
package/hooks/use-pagination.ts
CHANGED
|
@@ -116,7 +116,7 @@ export default function usePagination(
|
|
|
116
116
|
urlSearchParams.set('page', (Number(state.page) - 1).toString());
|
|
117
117
|
return `${pathname}?${urlSearchParams.toString()}`;
|
|
118
118
|
}
|
|
119
|
-
return
|
|
119
|
+
return null;
|
|
120
120
|
}, [state.page, pathname, urlSearchParams]);
|
|
121
121
|
|
|
122
122
|
const next = useMemo(() => {
|
|
@@ -124,7 +124,7 @@ export default function usePagination(
|
|
|
124
124
|
urlSearchParams.set('page', (Number(state.page) + 1).toString());
|
|
125
125
|
return `${pathname}?${urlSearchParams.toString()}`;
|
|
126
126
|
}
|
|
127
|
-
return
|
|
127
|
+
return null;
|
|
128
128
|
}, [state.page, state.last, pathname, urlSearchParams]);
|
|
129
129
|
|
|
130
130
|
return {
|
|
@@ -19,7 +19,8 @@ export const usePaymentOptions = () => {
|
|
|
19
19
|
bkm_express: 'pz-bkm',
|
|
20
20
|
credit_payment: 'pz-credit-payment',
|
|
21
21
|
masterpass: 'pz-masterpass',
|
|
22
|
-
gpay: 'pz-gpay'
|
|
22
|
+
gpay: 'pz-gpay',
|
|
23
|
+
saved_card: 'pz-saved-card'
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
const isInitialTypeIncluded = (type: string) => initialTypes.has(type);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CacheHandler } from '@neshca/cache-handler';
|
|
2
|
+
import createLruHandler from '@neshca/cache-handler/local-lru';
|
|
3
|
+
import createRedisHandler from '@neshca/cache-handler/redis-stack';
|
|
4
|
+
import { createClient } from 'redis';
|
|
5
|
+
|
|
6
|
+
CacheHandler.onCreation(async () => {
|
|
7
|
+
const redisUrl = `redis://${process.env.CACHE_HOST}:${
|
|
8
|
+
process.env.CACHE_PORT
|
|
9
|
+
}/${process.env.CACHE_BUCKET ?? '0'}`;
|
|
10
|
+
|
|
11
|
+
const client = createClient({
|
|
12
|
+
url: redisUrl
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
client.on('error', (error) => {
|
|
16
|
+
console.error('Redis client error', { redisUrl, error });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
await client.connect();
|
|
20
|
+
|
|
21
|
+
const redisHandler = await createRedisHandler({
|
|
22
|
+
client,
|
|
23
|
+
timeoutMs: 5000
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const localHandler = createLruHandler();
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
handlers: [redisHandler, localHandler]
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export default CacheHandler;
|
package/lib/cache.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { RedisClientType } from 'redis';
|
|
|
3
3
|
import Settings from 'settings';
|
|
4
4
|
import { CacheOptions } from '../types';
|
|
5
5
|
import logger from '../utils/log';
|
|
6
|
-
import { ServerVariables } from '../utils/server-variables';
|
|
7
6
|
|
|
8
7
|
const hashCacheKey = (object?: Record<string, string>) => {
|
|
9
8
|
if (!object) {
|
|
@@ -59,10 +58,8 @@ export const CacheKey = {
|
|
|
59
58
|
export class Cache {
|
|
60
59
|
static PROXY_URL = `${process.env.NEXT_PUBLIC_URL}/api/cache`;
|
|
61
60
|
|
|
62
|
-
static formatKey(key: string) {
|
|
63
|
-
return encodeURIComponent(
|
|
64
|
-
`${Settings.commerceUrl}_${ServerVariables.locale}_${key}`
|
|
65
|
-
);
|
|
61
|
+
static formatKey(key: string, locale: string) {
|
|
62
|
+
return encodeURIComponent(`${Settings.commerceUrl}_${locale}_${key}`);
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
static clientPool: Pool<RedisClientType> = createPool(
|
|
@@ -155,9 +152,14 @@ export class Cache {
|
|
|
155
152
|
|
|
156
153
|
static async wrap<T = any>(
|
|
157
154
|
key: string,
|
|
155
|
+
locale: string,
|
|
158
156
|
handler: () => Promise<T>,
|
|
159
157
|
options?: CacheOptions
|
|
160
158
|
): Promise<T> {
|
|
159
|
+
if (Settings.usePrettyUrlRoute) {
|
|
160
|
+
return await handler();
|
|
161
|
+
}
|
|
162
|
+
|
|
161
163
|
const requiredVariables = [
|
|
162
164
|
process.env.CACHE_HOST,
|
|
163
165
|
process.env.CACHE_PORT,
|
|
@@ -174,7 +176,7 @@ export class Cache {
|
|
|
174
176
|
};
|
|
175
177
|
|
|
176
178
|
const _options = Object.assign(defaultOptions, options);
|
|
177
|
-
const formattedKey = Cache.formatKey(key);
|
|
179
|
+
const formattedKey = Cache.formatKey(key, locale);
|
|
178
180
|
|
|
179
181
|
logger.debug('Cache wrap', { key, formattedKey, _options });
|
|
180
182
|
|
package/middlewares/currency.ts
CHANGED
|
@@ -74,7 +74,8 @@ const withCurrency =
|
|
|
74
74
|
req.cookies.get('pz-currency')?.value !== activeCurrency &&
|
|
75
75
|
url.pathname.match(urlLocaleMatcherRegex) &&
|
|
76
76
|
!url.search.includes('mobile_app=true') &&
|
|
77
|
-
!url.search.includes('page=CreditCardThreeDSecurePage')
|
|
77
|
+
!url.search.includes('page=CreditCardThreeDSecurePage') &&
|
|
78
|
+
!url.search.includes('page=RedirectionPageCompletePage')
|
|
78
79
|
) {
|
|
79
80
|
logger.info('Currency changed. Resetting basket...', {
|
|
80
81
|
sessionid: req.cookies.get('osessionid')?.value ?? '',
|