@akinon/next 1.48.0-rc.3 → 1.48.0-rc.5

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,17 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.48.0-rc.5
4
+
5
+ ### Minor Changes
6
+
7
+ - 20da358: ZERO-2898: Add setDeliveryBags mutation to checkout api
8
+
9
+ ## 1.48.0-rc.4
10
+
11
+ ### Minor Changes
12
+
13
+ - 5dfeea0: ZERO-2801: Revert ZERO-2801
14
+
3
15
  ## 1.48.0-rc.3
4
16
 
5
17
  ### Minor Changes
@@ -677,6 +677,25 @@ export const checkoutApi = api.injectEndpoints({
677
677
  }
678
678
  })
679
679
  }),
680
+ setDeliveryBags: build.mutation<
681
+ CheckoutResponse,
682
+ { sku: string; quantity?: number }
683
+ >({
684
+ query: ({ sku, quantity }) => {
685
+ const body = {
686
+ product: sku,
687
+ ...(quantity !== undefined && { quantity })
688
+ };
689
+
690
+ return {
691
+ url: buildClientRequestUrl(checkout.deliveryBagsPage, {
692
+ useFormData: true
693
+ }),
694
+ method: 'POST',
695
+ body
696
+ };
697
+ }
698
+ }),
680
699
  setAttributeBasedShippingOptions: build.mutation<
681
700
  CheckoutResponse,
682
701
  Record<string, number>
@@ -731,5 +750,6 @@ export const {
731
750
  useGetCheckoutLoyaltyBalanceQuery,
732
751
  usePayWithLoyaltyBalanceMutation,
733
752
  useSetOrderNoteMutation,
753
+ useSetDeliveryBagsMutation,
734
754
  useSetAttributeBasedShippingOptionsMutation
735
755
  } = checkoutApi;
package/data/urls.ts CHANGED
@@ -112,7 +112,8 @@ export const checkout = {
112
112
  setOrderNote: '/orders/checkout/?page=OrderNotePage',
113
113
  couponSelectionPage: '/orders/checkout/?page=CouponSelectionPage',
114
114
  setAttributeBasedShippingOption:
115
- '/orders/checkout/?page=AttributeBasedShippingOptionSelectionPage'
115
+ '/orders/checkout/?page=AttributeBasedShippingOptionSelectionPage',
116
+ deliveryBagsPage: '/orders/checkout/?page=DeliveryBagsPage'
116
117
  };
117
118
 
118
119
  export const flatpage = {
@@ -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
- locales,
17
- localeUrlStrategy,
18
- defaultLocaleValue,
19
- redirectToDefaultLocale
20
- } = settings.localization;
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
- locales.length === 1 &&
33
- localeUrlStrategy === LocaleUrlStrategy.ShowAllLocales
48
+ !matchedLocale?.length &&
49
+ localeUrlStrategy === LocaleUrlStrategy.ShowAllLocales &&
50
+ redirectToDefaultLocale &&
51
+ req.method === 'GET'
34
52
  ) {
35
- const singleLocale = locales[0].value;
36
- const pathParts = url.pathname.split('/').filter(Boolean);
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,
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.48.0-rc.3",
4
+ "version": "1.48.0-rc.5",
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.48.0-rc.3",
33
+ "@akinon/eslint-plugin-projectzero": "1.48.0-rc.5",
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",