@akinon/next 1.87.0-rc.2 → 1.87.0

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.
@@ -1,8 +1,6 @@
1
1
  import clsx from 'clsx';
2
2
  import { forwardRef, FocusEvent, useState, Ref } from 'react';
3
3
  import { Controller } from 'react-hook-form';
4
-
5
- // @ts-ignore
6
4
  import { PatternFormat, PatternFormatProps } from 'react-number-format';
7
5
  import { InputProps } from '../types';
8
6
  import { twMerge } from 'tailwind-merge';
@@ -10,9 +10,7 @@ type LinkProps = Omit<
10
10
  React.AnchorHTMLAttributes<HTMLAnchorElement>,
11
11
  keyof NextLinkProps
12
12
  > &
13
- NextLinkProps & {
14
- href: string;
15
- };
13
+ NextLinkProps;
16
14
 
17
15
  export const Link = ({ children, href, ...rest }: LinkProps) => {
18
16
  const { locale, defaultLocaleValue, localeUrlStrategy } = useLocalization();
@@ -28,21 +26,19 @@ export const Link = ({ children, href, ...rest }: LinkProps) => {
28
26
  return href;
29
27
  }
30
28
 
31
- if (typeof href === 'string' && !href.startsWith('http')) {
32
- const pathnameWithoutLocale = href.replace(urlLocaleMatcherRegex, '');
33
- const hrefWithLocale = `/${locale}${pathnameWithoutLocale}`;
34
-
35
- if (localeUrlStrategy === LocaleUrlStrategy.ShowAllLocales) {
36
- return hrefWithLocale;
37
- } else if (
38
- localeUrlStrategy === LocaleUrlStrategy.HideDefaultLocale &&
39
- locale !== defaultLocaleValue
40
- ) {
41
- return hrefWithLocale;
42
- }
29
+ const pathnameWithoutLocale = href.replace(urlLocaleMatcherRegex, '');
30
+ const hrefWithLocale = `/${locale}${pathnameWithoutLocale}`;
31
+
32
+ if (localeUrlStrategy === LocaleUrlStrategy.ShowAllLocales) {
33
+ return hrefWithLocale;
34
+ } else if (
35
+ localeUrlStrategy === LocaleUrlStrategy.HideDefaultLocale &&
36
+ locale !== defaultLocaleValue
37
+ ) {
38
+ return hrefWithLocale;
43
39
  }
44
40
 
45
- return href;
41
+ return href || '#';
46
42
  }, [href, defaultLocaleValue, locale, localeUrlStrategy]);
47
43
 
48
44
  return (
@@ -72,13 +72,10 @@ const addRootLayoutProps = async (componentProps: RootLayoutProps) => {
72
72
  const checkRedisVariables = () => {
73
73
  const requiredVariableValues = [
74
74
  process.env.CACHE_HOST,
75
- process.env.CACHE_PORT
75
+ process.env.CACHE_PORT,
76
+ process.env.CACHE_SECRET
76
77
  ];
77
78
 
78
- if (!settings.usePrettyUrlRoute) {
79
- requiredVariableValues.push(process.env.CACHE_SECRET);
80
- }
81
-
82
79
  if (
83
80
  !requiredVariableValues.every((v) => v) &&
84
81
  process.env.NODE_ENV === 'production'
@@ -4,19 +4,17 @@ import { Resource } from '@opentelemetry/resources';
4
4
  import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
5
5
  import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';
6
6
 
7
- if (process.env.NODE_ENV === 'development') {
8
- const sdk = new NodeSDK({
9
- resource: new Resource({
10
- [SemanticResourceAttributes.SERVICE_NAME]: 'pz-next-app'
11
- }),
12
- spanProcessor: new SimpleSpanProcessor(
13
- new OTLPTraceExporter({
14
- url: `${
15
- process.env.PZ_DASHBOARD_URL ?? 'http://localhost:3005'
16
- }/api/traces`
17
- })
18
- )
19
- });
7
+ const sdk = new NodeSDK({
8
+ resource: new Resource({
9
+ [SemanticResourceAttributes.SERVICE_NAME]: 'pz-next-app'
10
+ }),
11
+ spanProcessor: new SimpleSpanProcessor(
12
+ new OTLPTraceExporter({
13
+ url: `${
14
+ process.env.PZ_DASHBOARD_URL ?? 'http://localhost:3005'
15
+ }/api/traces`
16
+ })
17
+ )
18
+ });
20
19
 
21
- sdk.start();
22
- }
20
+ sdk.start();
package/lib/cache.ts CHANGED
@@ -31,8 +31,6 @@ export const CacheKey = {
31
31
  `category_${pk}_${encodeURIComponent(
32
32
  JSON.stringify(searchParams)
33
33
  )}${hashCacheKey(headers)}`,
34
- Basket: (namespace?: string) => `basket${namespace ? `_${namespace}` : ''}`,
35
- AllBaskets: () => 'all_baskets',
36
34
  CategorySlug: (slug: string) => `category_${slug}`,
37
35
  SpecialPage: (
38
36
  pk: number,
@@ -145,8 +145,7 @@ const withCompleteGpay =
145
145
  logger.info('Redirecting to order success page', {
146
146
  middleware: 'complete-gpay',
147
147
  redirectUrlWithLocale,
148
- ip,
149
- setCookie: request.headers.get('set-cookie')
148
+ ip
150
149
  });
151
150
 
152
151
  // Using POST method while redirecting causes an error,
@@ -145,8 +145,7 @@ const withCompleteMasterpass =
145
145
  logger.info('Redirecting to order success page', {
146
146
  middleware: 'complete-masterpass',
147
147
  redirectUrlWithLocale,
148
- ip,
149
- setCookie: request.headers.get('set-cookie')
148
+ ip
150
149
  });
151
150
 
152
151
  // Using POST method while redirecting causes an error,
@@ -146,8 +146,7 @@ const withRedirectionPayment =
146
146
  logger.info('Redirecting to order success page', {
147
147
  middleware: 'redirection-payment',
148
148
  redirectUrlWithLocale,
149
- ip,
150
- setCookie: request.headers.get('set-cookie')
149
+ ip
151
150
  });
152
151
 
153
152
  // Using POST method while redirecting causes an error,
@@ -145,8 +145,7 @@ const withSavedCardRedirection =
145
145
  logger.info('Redirecting to order success page', {
146
146
  middleware: 'saved-card-redirection',
147
147
  redirectUrlWithLocale,
148
- ip,
149
- setCookie: request.headers.get('set-cookie')
148
+ ip
150
149
  });
151
150
 
152
151
  // Using POST method while redirecting causes an error,
@@ -145,8 +145,7 @@ const withThreeDRedirection =
145
145
  logger.info('Redirecting to order success page', {
146
146
  middleware: 'three-d-redirection',
147
147
  redirectUrlWithLocale,
148
- ip,
149
- setCookie: request.headers.get('set-cookie')
148
+ ip
150
149
  });
151
150
 
152
151
  // Using POST method while redirecting causes an 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.87.0-rc.2",
4
+ "version": "1.87.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -20,7 +20,7 @@
20
20
  "@opentelemetry/sdk-trace-node": "1.19.0",
21
21
  "@opentelemetry/semantic-conventions": "1.19.0",
22
22
  "@reduxjs/toolkit": "1.9.7",
23
- "@neshca/cache-handler": "1.9.0",
23
+ "@neshca/cache-handler": "1.5.1",
24
24
  "@sentry/nextjs": "9.5.0",
25
25
  "cross-spawn": "7.0.3",
26
26
  "generic-pool": "3.9.0",
@@ -31,7 +31,7 @@
31
31
  "set-cookie-parser": "2.6.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@akinon/eslint-plugin-projectzero": "1.87.0-rc.2",
34
+ "@akinon/eslint-plugin-projectzero": "1.87.0",
35
35
  "@types/react-redux": "7.1.30",
36
36
  "@types/set-cookie-parser": "2.4.7",
37
37
  "@typescript-eslint/eslint-plugin": "6.7.4",
@@ -114,7 +114,6 @@ export interface Order {
114
114
  pk: number;
115
115
  name: string;
116
116
  slug: string;
117
- logo: string;
118
117
  [key: string]: any;
119
118
  };
120
119
  }
@@ -43,12 +43,12 @@ const appFetch = async <T>({
43
43
  const requestURL = `${decodeURIComponent(commerceUrl)}${url}`;
44
44
 
45
45
  init.headers = {
46
- cookie: nextCookies.toString(),
47
46
  ...(init.headers ?? {}),
48
47
  ...(ServerVariables.globalHeaders ?? {}),
49
48
  'Accept-Language': currentLocale.apiValue,
50
49
  'x-currency': currency,
51
- 'x-forwarded-for': ip
50
+ 'x-forwarded-for': ip,
51
+ cookie: nextCookies.toString()
52
52
  };
53
53
 
54
54
  init.next = {
package/utils/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import settings from 'settings';
2
2
  import { LocaleUrlStrategy } from '../localization';
3
- import { CDNOptions, ClientRequestOptions } from '../types';
3
+ import { CDNOptions, ClientRequestOptions, Locale } from '../types';
4
4
 
5
5
  export * from './get-currency';
6
6
  export * from './menu-generator';
@@ -155,15 +155,14 @@ export function buildCDNUrl(url: string, config?: CDNOptions) {
155
155
  const { locales, localeUrlStrategy, defaultLocaleValue } =
156
156
  settings.localization;
157
157
 
158
+ const isLocaleExcluded = (locale: Locale) =>
159
+ ![LocaleUrlStrategy.ShowAllLocales, LocaleUrlStrategy.Subdomain].includes(
160
+ localeUrlStrategy
161
+ ) && locale.value !== defaultLocaleValue;
162
+
158
163
  export const urlLocaleMatcherRegex = new RegExp(
159
- `^/(${settings.localization.locales
160
- .filter((l) =>
161
- ![LocaleUrlStrategy.ShowAllLocales, LocaleUrlStrategy.Subdomain].includes(
162
- settings.localization.localeUrlStrategy
163
- )
164
- ? l.value !== settings.localization.defaultLocaleValue
165
- : l
166
- )
164
+ `^/(${locales
165
+ .filter((l) => !isLocaleExcluded(l))
167
166
  .map((l) => l.value)
168
167
  .join('|')})(?=/|$)`
169
168
  );
@@ -1,72 +0,0 @@
1
- import { Cache, CacheKey } from '../../lib/cache';
2
- import { basket } from '../../data/urls';
3
- import { Basket } from '../../types';
4
- import appFetch from '../../utils/app-fetch';
5
- import { ServerVariables } from '../../utils/server-variables';
6
- import logger from '../../utils/log';
7
-
8
- type GetBasketParams = {
9
- locale?: string;
10
- currency?: string;
11
- namespace?: string;
12
- };
13
-
14
- const getBasketDataHandler = ({
15
- locale,
16
- currency,
17
- namespace
18
- }: GetBasketParams) => {
19
- return async function () {
20
- try {
21
- const url = namespace
22
- ? basket.getBasketDetail(namespace)
23
- : basket.getBasket;
24
-
25
- const basketData = await appFetch<{ basket: Basket }>({
26
- url,
27
- locale,
28
- currency,
29
- init: {
30
- headers: {
31
- Accept: 'application/json',
32
- 'Content-Type': 'application/json'
33
- }
34
- }
35
- });
36
-
37
- if (!basketData?.basket) {
38
- logger.warn('Basket data is undefined', {
39
- handler: 'getBasketDataHandler',
40
- namespace
41
- });
42
- }
43
-
44
- return basketData;
45
- } catch (error) {
46
- logger.error('Error fetching basket data', {
47
- handler: 'getBasketDataHandler',
48
- error,
49
- namespace
50
- });
51
- throw error;
52
- }
53
- };
54
- };
55
-
56
- export const getBasketData = async ({
57
- locale = ServerVariables.locale,
58
- currency = ServerVariables.currency,
59
- namespace
60
- }: GetBasketParams = {}) => {
61
- return Cache.wrap(
62
- CacheKey.Basket(namespace),
63
- locale,
64
- getBasketDataHandler({ locale, currency, namespace }),
65
- {
66
- expire: 0,
67
- cache: false
68
- }
69
- );
70
- };
71
-
72
-