@akinon/next 1.43.0-rc.6 → 1.43.0-rc.8

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,18 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.43.0-rc.8
4
+
5
+ ### Minor Changes
6
+
7
+ - 70279e7: ZERO-2817: Add metrics endpoint in default middleware
8
+ - 9d94f7e: ZERO-2820: update parent pk usage for menu generator
9
+
10
+ ## 1.43.0-rc.7
11
+
12
+ ### Minor Changes
13
+
14
+ - 7bd3d99: ZERO-2801: Refactor locale middleware to handle single locale configuration
15
+
3
16
  ## 1.43.0-rc.6
4
17
 
5
18
  ### Minor Changes
@@ -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());
@@ -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.6",
4
+ "version": "1.43.0-rc.8",
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.6",
33
+ "@akinon/eslint-plugin-projectzero": "1.43.0-rc.8",
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",
@@ -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
  }