@akinon/next 1.43.0-rc.1 → 1.43.0-rc.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/CHANGELOG.md CHANGED
@@ -1,5 +1,99 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.43.0-rc.11
4
+
5
+ ### Minor Changes
6
+
7
+ - 6c25f66: ZERO-2551: Check CACHE_HOST variable
8
+
9
+ ## 1.43.0-rc.10
10
+
11
+ ### Minor Changes
12
+
13
+ - d6edb1d: ZERO-2551: Fix searchparams handling for list and other routes
14
+
15
+ ## 1.43.0-rc.9
16
+
17
+ ### Minor Changes
18
+
19
+ - bc2b411: ZERO-2825: Add attribute-based shipping options to checkout page
20
+
21
+ ## 1.43.0-rc.8
22
+
23
+ ### Minor Changes
24
+
25
+ - 70279e7: ZERO-2817: Add metrics endpoint in default middleware
26
+ - 9d94f7e: ZERO-2820: update parent pk usage for menu generator
27
+
28
+ ## 1.43.0-rc.7
29
+
30
+ ### Minor Changes
31
+
32
+ - 7bd3d99: ZERO-2801: Refactor locale middleware to handle single locale configuration
33
+
34
+ ## 1.43.0-rc.6
35
+
36
+ ### Minor Changes
37
+
38
+ - 90282b5: ZERO-2729: Audit packages for yarn and npm and also update app-template
39
+ - 572d2e8: ZERO-2667: Add iframe support for redirection payment methods
40
+ - a4c8d6a: ZERO-2663: Fix the image url for gif and svgs and return them without options
41
+ - fda5b92: ZERO-2725: fix invalid import
42
+ - 2d9b2b2: ZERO-2816: Add segment to headers
43
+ - c53ea3e: ZERO-2609: Reset additional form fields when selectedFormType is not company
44
+ - 8d9ac9a: ZERO-2794: Add field to order type
45
+ - e9541a1: ZERO-2816: Add headers to url
46
+ - c53ef7b: ZERO-2668: The Link component has been updated to improve the logic for handling href values. Previously, if the href was not a string or started with 'http', it would return the href as is. Now, if the href is not provided, it will default to '#' to prevent any potential errors. Additionally, if the href is a string and does not start with 'http', it will be formatted with the locale and pathname, based on the localeUrlStrategy and defaultLocaleValue. This ensures that the correct href is generated based on the localization settings.
47
+ - 64699d3: ZERO-2761: Fix invalid import for plugin module
48
+ - 0d3a913: ZERO-2725: Update decimal scale in Price component
49
+ - 1448a96: ZERO-2612: add errors type in CheckoutState
50
+ - d3474c6: ZERO-2655: Add data source shipping option
51
+ - 75080fd: ZERO-2630: Add max limit to postcode area
52
+ - 17f8752: ZERO-2816: Make the incoming currency lowercase
53
+ - 91265bb: ZERO-2551: Improve pretty url and caching performance
54
+ - bbe18b9: ZERO-2575: Fix build error
55
+ - d409996: ZERO-2781: Refactor buildClientRequestUrl function to support caching and options
56
+ - 94b6928: ZERO-2551: Add cache handler check in url-redirection middleware
57
+ - 98bb8dc: ZERO-2706: Cache getTranlations method
58
+ - 46b7aad: ZERO-2775: Add condition and logger for menuitemmodel data
59
+ - dcc8a15: ZERO-2694: added build step to RC branch pipeline
60
+ - fad2768: ZERO-2739: add gpay to payment plugin map
61
+ - dff0d59: ZERO-2659: add formData support to proxy api requests
62
+ - eecb282: ZERO-2607: Update address-related functions to include invalidateTag option
63
+ - 4a163f2: ZERO-2761: Add condition for basket summary
64
+ - beb499e: ZERO-2551: Add new tsconfig paths
65
+ - 146ea39: ZERO-2774: Update imports
66
+ - f2c92d5: ZERO-2816: Update cookie name
67
+ - c47be30: ZERO-2744: Update Order and OrderItem types
68
+ - e9a46ac: ZERO-2738: add CVC input to registered cards in Masterpass
69
+ - f046f8e: ZERO-2575: update version for react-number-format
70
+ - 86d2531: ZERO-2693: resolve dependency collision warning for eslint-config-next
71
+ - 3f9b8d7: ZERO-2761: Update plugins.js for akinon-next
72
+
73
+ ## 1.43.0-rc.5
74
+
75
+ ### Minor Changes
76
+
77
+ - 17f8752: ZERO-2816: Make the incoming currency lowercase
78
+
79
+ ## 1.43.0-rc.4
80
+
81
+ ### Minor Changes
82
+
83
+ - 3f9b8d7: ZERO-2761: Update plugins.js for akinon-next
84
+
85
+ ## 1.43.0-rc.3
86
+
87
+ ### Minor Changes
88
+
89
+ - 64699d3: ZERO-2761: Fix invalid import for plugin module
90
+
91
+ ## 1.43.0-rc.2
92
+
93
+ ### Minor Changes
94
+
95
+ - f2c92d5: ZERO-2816: Update cookie name
96
+
3
97
  ## 1.43.0-rc.1
4
98
 
5
99
  ### Minor Changes
@@ -137,7 +137,7 @@ export default function PluginModule({
137
137
  } else if (plugin === Plugin.Akifast) {
138
138
  promise = import(`${'@akinon/pz-akifast'}`);
139
139
  } else if (plugin === Plugin.MultiBasket) {
140
- promise = import('@akinon/pz-multi-basket');
140
+ promise = import(`${'@akinon/pz-multi-basket'}`);
141
141
  }
142
142
  } catch (error) {
143
143
  logger.error(error);
@@ -676,6 +676,25 @@ export const checkoutApi = api.injectEndpoints({
676
676
  notes
677
677
  }
678
678
  })
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
+ }
679
698
  })
680
699
  }),
681
700
  overrideExisting: false
@@ -711,5 +730,6 @@ export const {
711
730
  useCompleteLoyaltyPaymentMutation,
712
731
  useGetCheckoutLoyaltyBalanceQuery,
713
732
  usePayWithLoyaltyBalanceMutation,
714
- useSetOrderNoteMutation
733
+ useSetOrderNoteMutation,
734
+ useSetAttributeBasedShippingOptionsMutation
715
735
  } = checkoutApi;
package/data/urls.ts CHANGED
@@ -110,7 +110,9 @@ export const checkout = {
110
110
  completeLoyaltyPayment: '/orders/checkout/?page=LoyaltyPaymentSelectedPage',
111
111
  loyaltyMoneyUsage: '/orders/checkout/?page=LoyaltyMoneyUsagePage',
112
112
  setOrderNote: '/orders/checkout/?page=OrderNotePage',
113
- couponSelectionPage: '/orders/checkout/?page=CouponSelectionPage'
113
+ couponSelectionPage: '/orders/checkout/?page=CouponSelectionPage',
114
+ setAttributeBasedShippingOption:
115
+ '/orders/checkout/?page=AttributeBasedShippingOptionSelectionPage'
114
116
  };
115
117
 
116
118
  export const flatpage = {
@@ -69,6 +69,10 @@ 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
+
72
76
  if (req.nextUrl.pathname.startsWith('/.well-known')) {
73
77
  const url = new URL(`${Settings.commerceUrl}${req.nextUrl.pathname}`);
74
78
  const req_ = await fetch(url.toString());
@@ -85,7 +89,7 @@ const withPzDefault =
85
89
  req.nextUrl.pathname.includes('/orders/checkout-with-token/')
86
90
  ) {
87
91
  const segment = url.searchParams.get('segment');
88
- const currency = url.searchParams.get('currency');
92
+ const currency = url.searchParams.get('currency')?.toLowerCase();
89
93
 
90
94
  const headers = {};
91
95
 
@@ -114,7 +118,11 @@ const withPzDefault =
114
118
  }
115
119
 
116
120
  if (currency) {
117
- response.cookies.set('pz-external-currency', 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
+ });
118
126
  }
119
127
 
120
128
  return response;
@@ -231,7 +239,12 @@ const withPzDefault =
231
239
 
232
240
  if (
233
241
  Settings.usePrettyUrlRoute &&
234
- url.searchParams.toString().length > 0
242
+ url.searchParams.toString().length > 0 &&
243
+ !Object.entries(ROUTES).find(([, value]) =>
244
+ new RegExp(`^${value}$`).test(
245
+ pathnameWithoutLocale
246
+ )
247
+ )
235
248
  ) {
236
249
  url.pathname =
237
250
  url.pathname +
@@ -5,22 +5,6 @@ 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
-
24
8
  const withLocale =
25
9
  (middleware: NextMiddleware) =>
26
10
  async (req: PzNextRequest, event: NextFetchEvent) => {
@@ -28,12 +12,12 @@ const withLocale =
28
12
 
29
13
  try {
30
14
  const url = req.nextUrl.clone();
31
- const matchedLocale = getMatchedLocale(url.pathname);
32
- let { localeUrlStrategy, defaultLocaleValue, redirectToDefaultLocale } =
33
- settings.localization;
34
-
35
- localeUrlStrategy =
36
- localeUrlStrategy ?? LocaleUrlStrategy.HideDefaultLocale;
15
+ const {
16
+ locales,
17
+ localeUrlStrategy,
18
+ defaultLocaleValue,
19
+ redirectToDefaultLocale
20
+ } = settings.localization;
37
21
 
38
22
  if (!defaultLocaleValue) {
39
23
  logger.error('Default locale value is not defined in settings.', {
@@ -45,16 +29,34 @@ const withLocale =
45
29
  }
46
30
 
47
31
  if (
48
- !matchedLocale?.length &&
49
- localeUrlStrategy === LocaleUrlStrategy.ShowAllLocales &&
50
- redirectToDefaultLocale &&
51
- req.method === 'GET'
32
+ locales.length === 1 &&
33
+ localeUrlStrategy === LocaleUrlStrategy.ShowAllLocales
52
34
  ) {
53
- url.pathname = `/${defaultLocaleValue}${url.pathname}`;
54
- return NextResponse.redirect(url);
55
- }
35
+ const singleLocale = locales[0].value;
36
+ const pathParts = url.pathname.split('/').filter(Boolean);
56
37
 
57
- req.middlewareParams.rewrites.locale = matchedLocale;
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;
59
+ }
58
60
  } catch (error) {
59
61
  logger.error('withLocale error', {
60
62
  error,
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.43.0-rc.1",
4
+ "version": "1.43.0-rc.11",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -30,7 +30,7 @@
30
30
  "set-cookie-parser": "2.6.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@akinon/eslint-plugin-projectzero": "1.43.0-rc.1",
33
+ "@akinon/eslint-plugin-projectzero": "1.43.0-rc.11",
34
34
  "@types/react-redux": "7.1.30",
35
35
  "@types/set-cookie-parser": "2.4.7",
36
36
  "@typescript-eslint/eslint-plugin": "6.7.4",
package/plugins.js CHANGED
@@ -10,5 +10,6 @@ module.exports = [
10
10
  'pz-credit-payment',
11
11
  'pz-masterpass',
12
12
  'pz-b2b',
13
- 'pz-akifast'
13
+ 'pz-akifast',
14
+ 'pz-multi-basket'
14
15
  ];
@@ -18,7 +18,8 @@ import {
18
18
  setShippingOptions,
19
19
  setDataSourceShippingOptions,
20
20
  setShippingStepCompleted,
21
- setCreditPaymentOptions
21
+ setCreditPaymentOptions,
22
+ setAttributeBasedShippingOptions
22
23
  } from '../../redux/reducers/checkout';
23
24
  import { RootState, TypedDispatch } from 'redux/store';
24
25
  import { checkoutApi } from '../../data/client/checkout';
@@ -77,7 +78,8 @@ export const preOrderMiddleware: Middleware = ({
77
78
  shippingOptions,
78
79
  dataSourceShippingOptions,
79
80
  paymentOptions,
80
- installmentOptions
81
+ installmentOptions,
82
+ attributeBasedShippingOptions
81
83
  } = getState().checkout;
82
84
  const { endpoints: apiEndpoints } = checkoutApi;
83
85
 
@@ -144,6 +146,24 @@ export const preOrderMiddleware: Middleware = ({
144
146
  );
145
147
  }
146
148
 
149
+ if (
150
+ Object.keys(attributeBasedShippingOptions).length > 0 &&
151
+ !preOrder.attribute_based_shipping_options
152
+ ) {
153
+ const initialSelectedOptions: Record<string, number> = Object.fromEntries(
154
+ Object.entries(attributeBasedShippingOptions).map(([key, options]) => [
155
+ key,
156
+ options[0].pk
157
+ ])
158
+ );
159
+
160
+ dispatch(
161
+ apiEndpoints.setAttributeBasedShippingOptions.initiate(
162
+ initialSelectedOptions
163
+ )
164
+ );
165
+ }
166
+
147
167
  if (!preOrder.payment_option && paymentOptions.length > 0) {
148
168
  dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
149
169
  }
@@ -249,6 +269,14 @@ export const contextListMiddleware: Middleware = ({
249
269
  );
250
270
  }
251
271
 
272
+ if (context.page_context.attribute_based_shipping_options) {
273
+ dispatch(
274
+ setAttributeBasedShippingOptions(
275
+ context.page_context.attribute_based_shipping_options
276
+ )
277
+ );
278
+ }
279
+
252
280
  if (context.page_context.payment_options) {
253
281
  dispatch(setPaymentOptions(context.page_context.payment_options));
254
282
  }
@@ -15,7 +15,8 @@ import {
15
15
  PreOrder,
16
16
  RetailStore,
17
17
  ShippingOption,
18
- DataSource
18
+ DataSource,
19
+ AttributeBasedShippingOption
19
20
  } from '../../types';
20
21
 
21
22
  export interface CheckoutState {
@@ -48,6 +49,8 @@ export interface CheckoutState {
48
49
  selectedBankAccountPk: number;
49
50
  loyaltyBalance?: string;
50
51
  retailStores: RetailStore[];
52
+ attributeBasedShippingOptions: AttributeBasedShippingOption[];
53
+ selectedShippingOptions: Record<string, number>;
51
54
  }
52
55
 
53
56
  const initialState: CheckoutState = {
@@ -78,7 +81,9 @@ const initialState: CheckoutState = {
78
81
  installmentOptions: [],
79
82
  bankAccounts: [],
80
83
  selectedBankAccountPk: null,
81
- retailStores: []
84
+ retailStores: [],
85
+ attributeBasedShippingOptions: [],
86
+ selectedShippingOptions: {}
82
87
  };
83
88
 
84
89
  const checkoutSlice = createSlice({
@@ -156,6 +161,12 @@ const checkoutSlice = createSlice({
156
161
  },
157
162
  setRetailStores(state, { payload }) {
158
163
  state.retailStores = payload;
164
+ },
165
+ setAttributeBasedShippingOptions(state, { payload }) {
166
+ state.attributeBasedShippingOptions = payload;
167
+ },
168
+ setSelectedShippingOptions: (state, { payload }) => {
169
+ state.selectedShippingOptions = payload;
159
170
  }
160
171
  }
161
172
  });
@@ -184,7 +195,9 @@ export const {
184
195
  setBankAccounts,
185
196
  setSelectedBankAccountPk,
186
197
  setLoyaltyBalance,
187
- setRetailStores
198
+ setRetailStores,
199
+ setAttributeBasedShippingOptions,
200
+ setSelectedShippingOptions
188
201
  } = checkoutSlice.actions;
189
202
 
190
203
  export default checkoutSlice.reducer;
@@ -96,6 +96,7 @@ export interface PreOrder {
96
96
  gift_box?: GiftBox;
97
97
  credit_payment_option?: CheckoutCreditPaymentOption;
98
98
  data_source_shipping_options: any;
99
+ attribute_based_shipping_options?: AttributeBasedShippingOption[];
99
100
  }
100
101
 
101
102
  export interface GuestLoginFormParams {
@@ -135,6 +136,7 @@ export interface CheckoutContext {
135
136
  redirect_url?: string;
136
137
  context_data?: any;
137
138
  balance?: string;
139
+ attribute_based_shipping_options?: AttributeBasedShippingOption[];
138
140
  [key: string]: any;
139
141
  };
140
142
  }
@@ -160,3 +162,13 @@ export interface BankAccount {
160
162
  pk: number;
161
163
  sort_order: number;
162
164
  }
165
+
166
+ export interface AttributeBasedShippingOption {
167
+ pk: number;
168
+ shipping_amount: string | null;
169
+ shipping_option_name: string | null;
170
+ shipping_option_logo: string | null;
171
+ attribute_value: string | null;
172
+ attribute_key: string;
173
+ [key: string]: any;
174
+ }
@@ -13,8 +13,8 @@ export const menuGenerator = (arr: MenuItemType[]) => {
13
13
  });
14
14
 
15
15
  Object.values(data).forEach((item) => {
16
- if (item.parent) {
17
- data[item.parent.pk].children.push(item);
16
+ if (item.parent_pk) {
17
+ data[item.parent_pk].children.push(item);
18
18
  } else {
19
19
  tree.push(item);
20
20
  }
package/with-pz-config.js CHANGED
@@ -97,7 +97,7 @@ const withPzConfig = (
97
97
  return [...pzRewrites, ...myRewrites];
98
98
  };
99
99
 
100
- if (options.useCacheHandler) {
100
+ if (options.useCacheHandler && process.env.CACHE_HOST) {
101
101
  extendedConfig.cacheHandler = require.resolve('./lib/cache-handler.mjs');
102
102
  }
103
103