@akinon/next 1.60.0 → 1.61.0-rc.22

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 (73) hide show
  1. package/CHANGELOG.md +662 -0
  2. package/api/client.ts +23 -2
  3. package/assets/styles/index.css +49 -0
  4. package/assets/styles/index.css.map +1 -0
  5. package/assets/styles/index.scss +50 -26
  6. package/bin/pz-generate-translations.js +41 -0
  7. package/bin/pz-install-plugins.js +0 -0
  8. package/bin/pz-install-theme.js +0 -0
  9. package/bin/pz-postbuild.js +0 -0
  10. package/bin/pz-postdev.js +0 -0
  11. package/bin/pz-postinstall.js +0 -0
  12. package/bin/pz-poststart.js +0 -0
  13. package/bin/pz-prebuild.js +1 -0
  14. package/bin/pz-predev.js +1 -0
  15. package/bin/pz-prestart.js +0 -0
  16. package/components/file-input.tsx +8 -0
  17. package/components/index.ts +1 -0
  18. package/components/input.tsx +21 -7
  19. package/components/link.tsx +17 -13
  20. package/components/plugin-module.tsx +8 -3
  21. package/components/price.tsx +11 -4
  22. package/components/pz-root.tsx +15 -3
  23. package/components/selected-payment-option-view.tsx +2 -1
  24. package/data/client/account.ts +3 -2
  25. package/data/client/api.ts +1 -1
  26. package/data/client/b2b.ts +35 -2
  27. package/data/client/basket.ts +6 -5
  28. package/data/client/checkout.ts +55 -10
  29. package/data/client/user.ts +3 -2
  30. package/data/server/category.ts +39 -19
  31. package/data/server/flatpage.ts +29 -7
  32. package/data/server/form.ts +29 -11
  33. package/data/server/landingpage.ts +26 -7
  34. package/data/server/list.ts +12 -6
  35. package/data/server/menu.ts +15 -2
  36. package/data/server/product.ts +29 -12
  37. package/data/server/seo.ts +17 -24
  38. package/data/server/special-page.ts +10 -5
  39. package/data/server/widget.ts +14 -7
  40. package/data/urls.ts +17 -4
  41. package/hocs/server/with-segment-defaults.tsx +4 -1
  42. package/hooks/index.ts +2 -1
  43. package/hooks/use-message-listener.ts +24 -0
  44. package/hooks/use-pagination.ts +2 -2
  45. package/hooks/use-payment-options.ts +2 -1
  46. package/lib/cache.ts +4 -6
  47. package/middlewares/complete-gpay.ts +1 -1
  48. package/middlewares/complete-masterpass.ts +1 -1
  49. package/middlewares/currency.ts +1 -0
  50. package/middlewares/default.ts +226 -167
  51. package/middlewares/index.ts +3 -1
  52. package/middlewares/oauth-login.ts +6 -1
  53. package/middlewares/pretty-url.ts +7 -1
  54. package/middlewares/saved-card-redirection.ts +179 -0
  55. package/middlewares/three-d-redirection.ts +1 -1
  56. package/middlewares/url-redirection.ts +14 -2
  57. package/package.json +2 -2
  58. package/plugins.d.ts +6 -0
  59. package/plugins.js +2 -1
  60. package/redux/middlewares/checkout.ts +77 -13
  61. package/redux/reducers/checkout.ts +23 -3
  62. package/redux/reducers/index.ts +3 -1
  63. package/routes/pretty-url.tsx +7 -9
  64. package/types/commerce/address.ts +1 -1
  65. package/types/commerce/b2b.ts +12 -2
  66. package/types/commerce/checkout.ts +31 -0
  67. package/types/commerce/order.ts +1 -0
  68. package/types/index.ts +15 -1
  69. package/utils/app-fetch.ts +15 -7
  70. package/utils/index.ts +27 -6
  71. package/utils/redirection-iframe.ts +85 -0
  72. package/utils/server-translation.ts +11 -1
  73. package/with-pz-config.js +2 -1
@@ -12,16 +12,18 @@ const getSpecialPageDataHandler = (
12
12
  return async function () {
13
13
  const params = generateCommerceSearchParams(searchParams);
14
14
 
15
- const data: GetCategoryResponse = await appFetch(
16
- `${category.getSpecialPageByPk(pk)}${params}`,
17
- {
15
+ const data: GetCategoryResponse = await appFetch({
16
+ url: `${category.getSpecialPageByPk(pk)}${params}`,
17
+ locale,
18
+ currency,
19
+ init: {
18
20
  headers: {
19
21
  Accept: 'application/json',
20
22
  'Content-Type': 'application/json',
21
23
  ...(headers ?? {})
22
24
  }
23
25
  }
24
- );
26
+ });
25
27
 
26
28
  return data;
27
29
  };
@@ -29,6 +31,8 @@ const getSpecialPageDataHandler = (
29
31
 
30
32
  export const getSpecialPageData = async ({
31
33
  pk,
34
+ locale = ServerVariables.locale,
35
+ currency = ServerVariables.currency,
32
36
  searchParams,
33
37
  headers
34
38
  }: {
@@ -38,7 +42,8 @@ export const getSpecialPageData = async ({
38
42
  }) => {
39
43
  return Cache.wrap(
40
44
  CacheKey.SpecialPage(pk, searchParams, headers),
41
- getSpecialPageDataHandler(pk, searchParams, headers),
45
+ locale,
46
+ getSpecialPageDataHandler(pk, locale, currency, searchParams, headers),
42
47
  {
43
48
  expire: 300
44
49
  }
@@ -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 = (slug: string) => async () => {
8
- if (!slug) {
9
- return null;
10
- }
8
+ const getWidgetDataHandler =
9
+ (slug: string, locale: string, currency: string) => async () => {
10
+ if (!slug) {
11
+ return null;
12
+ }
11
13
 
12
- return await appFetch(widgets.getWidget(slug));
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
- getWidgetDataHandler(slug),
30
+ locale,
31
+ getWidgetDataHandler(slug, locale, currency),
25
32
  cacheOptions
26
33
  );
27
34
  };
package/data/urls.ts CHANGED
@@ -17,16 +17,22 @@ export const account = {
17
17
  page,
18
18
  limit,
19
19
  createdDate,
20
- endDate
20
+ endDate,
21
+ shipping_option_slug
21
22
  }: {
22
23
  page?: number;
23
24
  limit?: number;
24
25
  createdDate?: string;
25
26
  endDate?: string;
27
+ shipping_option_slug?: string;
26
28
  }) =>
27
- `/users/orders/?page=${page || 1}&limit=${limit || 12} ${
29
+ `/users/orders/?page=${page || 1}&limit=${limit || 12}${
28
30
  createdDate ? `&created_date__gte=${createdDate}` : ''
29
- } ${endDate ? `&created_date__lte=${endDate}` : ''}`,
31
+ }${endDate ? `&created_date__lte=${endDate}` : ''}${
32
+ shipping_option_slug
33
+ ? `&shipping_option_slug=${shipping_option_slug}`
34
+ : ''
35
+ }`,
30
36
  getQuotations: (page?: number, status?: string, limit?: number) =>
31
37
  `/b2b/my-quotations/?page=${page || 1}` +
32
38
  (status ? `&status=${status}` : '') +
@@ -83,6 +89,8 @@ export const checkout = {
83
89
  setDeliveryOption: '/orders/checkout/?page=DeliveryOptionSelectionPage',
84
90
  setAddresses: '/orders/checkout/?page=AddressSelectionPage',
85
91
  setShippingOption: '/orders/checkout/?page=ShippingOptionSelectionPage',
92
+ setDataSourceShippingOption:
93
+ '/orders/checkout/?page=DataSourceShippingOptionSelectionPage',
86
94
  setPaymentOption: '/orders/checkout/?page=PaymentOptionSelectionPage',
87
95
  setBinNumber: '/orders/checkout/?page=BinNumberPage',
88
96
  setMasterpassBinNumber: '/orders/checkout/?page=MasterpassBinNumberPage',
@@ -109,6 +117,8 @@ export const checkout = {
109
117
  loyaltyMoneyUsage: '/orders/checkout/?page=LoyaltyMoneyUsagePage',
110
118
  setOrderNote: '/orders/checkout/?page=OrderNotePage',
111
119
  couponSelectionPage: '/orders/checkout/?page=CouponSelectionPage',
120
+ setAttributeBasedShippingOption:
121
+ '/orders/checkout/?page=AttributeBasedShippingOptionSelectionPage',
112
122
  deliveryBagsPage: '/orders/checkout/?page=DeliveryBagsPage',
113
123
  setOrderSelectionPage: '/orders/checkout/?page=OrderSelectionPage'
114
124
  };
@@ -199,7 +209,10 @@ export const b2b = {
199
209
  draftBaskets: '/b2b/basket/drafts/',
200
210
  divisions: '/b2b/my-divisions/',
201
211
  myQuotations: '/b2b/my-quotations/',
202
- loadBasket: (id) => `/b2b/basket/${id}/load/`
212
+ loadBasket: (id) => `/b2b/basket/${id}/load/`,
213
+ statusBasket: (cacheKey) => `/b2b/basket/?status_cache_key=${cacheKey}`,
214
+ basketExport: (queryString) => `/b2b/basket/?upload=true&${queryString}`,
215
+ basketImport: '/b2b/basket/bulk-import/'
203
216
  };
204
217
 
205
218
  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
+ };
@@ -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);
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,6 +152,7 @@ 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> {
@@ -178,7 +176,7 @@ export class Cache {
178
176
  };
179
177
 
180
178
  const _options = Object.assign(defaultOptions, options);
181
- const formattedKey = Cache.formatKey(key);
179
+ const formattedKey = Cache.formatKey(key, locale);
182
180
 
183
181
  logger.debug('Cache wrap', { key, formattedKey, _options });
184
182
 
@@ -43,7 +43,7 @@ const withCompleteGpay =
43
43
  const requestHeaders = {
44
44
  'X-Requested-With': 'XMLHttpRequest',
45
45
  'Content-Type': 'application/x-www-form-urlencoded',
46
- Cookie: `osessionid=${req.cookies.get('osessionid')?.value ?? ''}`,
46
+ Cookie: req.headers.get('cookie') ?? '',
47
47
  'x-currency': req.cookies.get('pz-currency')?.value ?? '',
48
48
  'x-forwarded-for': ip
49
49
  };
@@ -43,7 +43,7 @@ const withCompleteMasterpass =
43
43
  const requestHeaders = {
44
44
  'X-Requested-With': 'XMLHttpRequest',
45
45
  'Content-Type': 'application/x-www-form-urlencoded',
46
- Cookie: `osessionid=${req.cookies.get('osessionid')?.value ?? ''}`,
46
+ Cookie: req.headers.get('cookie') ?? '',
47
47
  'x-currency': req.cookies.get('pz-currency')?.value ?? '',
48
48
  'x-forwarded-for': ip
49
49
  };
@@ -75,6 +75,7 @@ const withCurrency =
75
75
  url.pathname.match(urlLocaleMatcherRegex) &&
76
76
  !url.search.includes('mobile_app=true') &&
77
77
  !url.search.includes('page=CreditCardThreeDSecurePage') &&
78
+ !url.search.includes('page=RedirectionPageCompletePage') &&
78
79
  settings.resetBasketOnCurrencyChange !== false
79
80
  ) {
80
81
  logger.info('Currency changed. Resetting basket...', {