@akinon/next 1.105.0-rc.84 → 1.105.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,6 +1,15 @@
1
1
  import { resolve } from 'path';
2
2
  import type { NextConfig } from 'next';
3
- const findBaseDir = require('../utils/find-base-dir');
3
+
4
+ function findBaseDir() {
5
+ const insideNodeModules = __dirname.includes('node_modules');
6
+
7
+ if (insideNodeModules) {
8
+ return resolve(__dirname, '../../../../');
9
+ } else {
10
+ return resolve(__dirname, '../../../apps/projectzeronext');
11
+ }
12
+ }
4
13
 
5
14
  const baseDir = findBaseDir();
6
15
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  const runScript = require('./run-script');
4
4
 
5
- runScript('pz-run-tests.js');
6
5
  runScript('pz-install-theme.js');
7
6
  runScript('pz-pre-check-dist.js');
8
7
  runScript('pz-generate-translations.js');
@@ -7,19 +7,15 @@ import { AccordionProps } from '../types';
7
7
 
8
8
  export const Accordion = ({
9
9
  isCollapse = false,
10
- collapseClassName,
11
10
  title,
12
11
  subTitle,
13
12
  icons = ['chevron-up', 'chevron-down'],
14
13
  iconSize = 16,
15
14
  iconColor = 'fill-[#000000]',
16
15
  children,
17
- headerClassName,
18
16
  className,
19
17
  titleClassName,
20
- subTitleClassName,
21
- dataTestId,
22
- contentClassName
18
+ dataTestId
23
19
  }: AccordionProps) => {
24
20
  const [collapse, setCollapse] = useState(isCollapse);
25
21
 
@@ -31,22 +27,15 @@ export const Accordion = ({
31
27
  )}
32
28
  >
33
29
  <div
34
- className={twMerge(
35
- 'flex items-center justify-between cursor-pointer',
36
- headerClassName
37
- )}
30
+ className="flex items-center justify-between cursor-pointer"
38
31
  onClick={() => setCollapse(!collapse)}
39
32
  data-testid={dataTestId}
40
33
  >
41
- <div className={twMerge('flex flex-col', contentClassName)}>
34
+ <div className="flex flex-col">
42
35
  {title && (
43
36
  <h3 className={twMerge('text-sm', titleClassName)}>{title}</h3>
44
37
  )}
45
- {subTitle && (
46
- <h4 className={twMerge('text-xs text-gray-700', subTitleClassName)}>
47
- {subTitle}
48
- </h4>
49
- )}
38
+ {subTitle && <h4 className="text-xs text-gray-700">{subTitle}</h4>}
50
39
  </div>
51
40
 
52
41
  {icons && (
@@ -57,11 +46,7 @@ export const Accordion = ({
57
46
  />
58
47
  )}
59
48
  </div>
60
- {collapse && (
61
- <div className={twMerge('mt-3 text-sm', collapseClassName)}>
62
- {children}
63
- </div>
64
- )}
49
+ {collapse && <div className="mt-3 text-sm">{children}</div>}
65
50
  </div>
66
51
  );
67
52
  };
@@ -1,70 +1,8 @@
1
- import { useState } from 'react';
2
1
  import { forwardRef } from 'react';
3
- import { useLocalization } from '@akinon/next/hooks';
4
- import { twMerge } from 'tailwind-merge';
5
- import { FileInputProps } from '../types';
2
+ import { FileInputProps } from '../types/index';
6
3
 
7
4
  export const FileInput = forwardRef<HTMLInputElement, FileInputProps>(
8
- function FileInput(
9
- {
10
- buttonClassName,
11
- onChange,
12
- fileClassName,
13
- fileNameWrapperClassName,
14
- fileInputClassName,
15
- ...props
16
- },
17
- ref
18
- ) {
19
- const { t } = useLocalization();
20
- const [fileNames, setFileNames] = useState<string[]>([]);
21
-
22
- const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
23
- const files = Array.from(event.target.files || []);
24
- setFileNames(files.map((file) => file.name));
25
-
26
- if (onChange) {
27
- onChange(event);
28
- }
29
- };
30
-
31
- return (
32
- <div className="relative">
33
- <input
34
- type="file"
35
- {...props}
36
- ref={ref}
37
- className={twMerge(
38
- 'absolute inset-0 w-full h-full opacity-0 cursor-pointer',
39
- fileInputClassName
40
- )}
41
- onChange={handleFileChange}
42
- />
43
- <button
44
- type="button"
45
- className={twMerge(
46
- 'bg-primary text-white py-2 px-4 text-sm',
47
- buttonClassName
48
- )}
49
- >
50
- {t('common.file_input.select_file')}
51
- </button>
52
- <div
53
- className={twMerge('mt-1 text-gray-500', fileNameWrapperClassName)}
54
- >
55
- {fileNames.length > 0 ? (
56
- <ul className={twMerge('list-disc pl-4 text-xs', fileClassName)}>
57
- {fileNames.map((name, index) => (
58
- <li key={index}>{name}</li>
59
- ))}
60
- </ul>
61
- ) : (
62
- <span className={twMerge('text-xs', fileClassName)}>
63
- {t('common.file_input.no_file')}
64
- </span>
65
- )}
66
- </div>
67
- </div>
68
- );
5
+ function fileInput(props, ref) {
6
+ return <input type="file" {...props} ref={ref} />;
69
7
  }
70
8
  );
@@ -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 (
@@ -22,8 +22,7 @@ enum Plugin {
22
22
  MultiBasket = 'pz-multi-basket',
23
23
  SavedCard = 'pz-saved-card',
24
24
  Hepsipay = 'pz-hepsipay',
25
- FlowPayment = 'pz-flow-payment',
26
- SimilarProducts = 'pz-similar-products'
25
+ FlowPayment = 'pz-flow-payment'
27
26
  }
28
27
 
29
28
  export enum Component {
@@ -50,15 +49,7 @@ export enum Component {
50
49
  MultiBasket = 'MultiBasket',
51
50
  SavedCard = 'SavedCardOption',
52
51
  Hepsipay = 'Hepsipay',
53
- FlowPayment = 'FlowPayment',
54
- SimilarProductsModal = 'SimilarProductsModal',
55
- SimilarProductsFilterSidebar = 'SimilarProductsFilterSidebar',
56
- SimilarProductsResultsGrid = 'SimilarProductsResultsGrid',
57
- SimilarProductsPlugin = 'SimilarProductsPlugin',
58
- ProductImageSearchFeature = 'ProductImageSearchFeature',
59
- ImageSearchButton = 'ImageSearchButton',
60
- HeaderImageSearchFeature = 'HeaderImageSearchFeature',
61
- IyzicoSavedCard = 'IyzicoSavedCardOption'
52
+ FlowPayment = 'FlowPayment'
62
53
  }
63
54
 
64
55
  const PluginComponents = new Map([
@@ -91,21 +82,9 @@ const PluginComponents = new Map([
91
82
  [Component.AkifastQuickLoginButton, Component.AkifastCheckoutButton]
92
83
  ],
93
84
  [Plugin.MultiBasket, [Component.MultiBasket]],
94
- [Plugin.SavedCard, [Component.SavedCard, Component.IyzicoSavedCard]],
85
+ [Plugin.SavedCard, [Component.SavedCard]],
95
86
  [Plugin.Hepsipay, [Component.Hepsipay]],
96
- [Plugin.FlowPayment, [Component.FlowPayment]],
97
- [
98
- Plugin.SimilarProducts,
99
- [
100
- Component.SimilarProductsModal,
101
- Component.SimilarProductsFilterSidebar,
102
- Component.SimilarProductsResultsGrid,
103
- Component.SimilarProductsPlugin,
104
- Component.ProductImageSearchFeature,
105
- Component.ImageSearchButton,
106
- Component.HeaderImageSearchFeature
107
- ]
108
- ]
87
+ [Plugin.FlowPayment, [Component.FlowPayment]]
109
88
  ]);
110
89
 
111
90
  const getPlugin = (component: Component) => {
@@ -174,8 +153,6 @@ export default function PluginModule({
174
153
  promise = import(`${'@akinon/pz-hepsipay'}`);
175
154
  } else if (plugin === Plugin.FlowPayment) {
176
155
  promise = import(`${'@akinon/pz-flow-payment'}`);
177
- } else if (plugin === Plugin.SimilarProducts) {
178
- promise = import(`${'@akinon/pz-similar-products'}`);
179
156
  }
180
157
  } catch (error) {
181
158
  logger.error(error);
@@ -35,10 +35,8 @@ import {
35
35
 
36
36
  interface CheckoutResponse {
37
37
  pre_order?: PreOrder;
38
- errors?: {
39
- non_field_errors?: string;
40
- sample_products?: string[];
41
- [key: string]: string | string[] | undefined;
38
+ errors: {
39
+ non_field_errors: string;
42
40
  };
43
41
  context_list?: CheckoutContext[];
44
42
  template_name?: string;
@@ -5,6 +5,7 @@ import { category, product } from '../urls';
5
5
  import { Cache, CacheKey } from '../../lib/cache';
6
6
  import { parse } from 'lossless-json';
7
7
  import logger from '../../utils/log';
8
+ import { headers as nHeaders } from 'next/headers';
8
9
  import { ServerVariables } from '../../utils/server-variables';
9
10
 
10
11
  function getCategoryDataHandler(
@@ -17,30 +18,19 @@ function getCategoryDataHandler(
17
18
  return async function () {
18
19
  const params = generateCommerceSearchParams(searchParams);
19
20
 
20
- let rawData: string;
21
-
22
- try {
23
- rawData = await appFetch<string>({
24
- url: `${category.getCategoryByPk(pk)}${params ? params : ''}`,
25
- locale,
26
- currency,
27
- init: {
28
- headers: {
29
- Accept: 'application/json',
30
- 'Content-Type': 'application/json',
31
- ...(headers ?? {})
32
- }
33
- },
34
- responseType: FetchResponseType.TEXT
35
- });
36
- } catch (error) {
37
- logger.error('Failed to fetch category data', {
38
- handler: 'getCategoryDataHandler',
39
- pk,
40
- error: error.message
41
- });
42
- return null;
43
- }
21
+ const rawData = await appFetch<string>({
22
+ url: `${category.getCategoryByPk(pk)}${params ? params : ''}`,
23
+ locale,
24
+ currency,
25
+ init: {
26
+ headers: {
27
+ Accept: 'application/json',
28
+ 'Content-Type': 'application/json',
29
+ ...(headers ?? {})
30
+ }
31
+ },
32
+ responseType: FetchResponseType.TEXT
33
+ });
44
34
 
45
35
  let data: GetCategoryResponse;
46
36
 
@@ -74,27 +64,17 @@ function getCategoryDataHandler(
74
64
  return { data, breadcrumbData: undefined };
75
65
  }
76
66
 
77
- let breadcrumbData: { menu?: unknown } = {};
78
-
79
- try {
80
- breadcrumbData = await appFetch<{ menu?: unknown }>({
81
- url: product.breadcrumbUrl(menuItemModel),
82
- locale,
83
- currency,
84
- init: {
85
- headers: {
86
- Accept: 'application/json',
87
- 'Content-Type': 'application/json'
88
- }
67
+ const breadcrumbData = await appFetch<any>({
68
+ url: product.breadcrumbUrl(menuItemModel),
69
+ locale,
70
+ currency,
71
+ init: {
72
+ headers: {
73
+ Accept: 'application/json',
74
+ 'Content-Type': 'application/json'
89
75
  }
90
- });
91
- } catch (error) {
92
- logger.warn('Failed to fetch breadcrumb data', {
93
- handler: 'getCategoryDataHandler',
94
- pk,
95
- error: error.message
96
- });
97
- }
76
+ }
77
+ });
98
78
 
99
79
  return { data, breadcrumbData: breadcrumbData?.menu };
100
80
  };
@@ -11,24 +11,20 @@ const getFlatPageDataHandler = (
11
11
  headers?: Record<string, string>
12
12
  ) => {
13
13
  return async function () {
14
- try {
15
- const data = await appFetch<FlatPage>({
16
- url: flatpage.getFlatPageByPk(pk),
17
- locale,
18
- currency,
19
- init: {
20
- headers: {
21
- Accept: 'application/json',
22
- 'Content-Type': 'application/json',
23
- ...(headers ?? {})
24
- }
14
+ const data = await appFetch<FlatPage>({
15
+ url: flatpage.getFlatPageByPk(pk),
16
+ locale,
17
+ currency,
18
+ init: {
19
+ headers: {
20
+ Accept: 'application/json',
21
+ 'Content-Type': 'application/json',
22
+ ...(headers ?? {})
25
23
  }
26
- });
24
+ }
25
+ });
27
26
 
28
- return data;
29
- } catch (error) {
30
- return null;
31
- }
27
+ return data;
32
28
  };
33
29
  };
34
30
 
@@ -11,24 +11,20 @@ const getLandingPageHandler = (
11
11
  headers?: Record<string, string>
12
12
  ) => {
13
13
  return async function () {
14
- try {
15
- const data = await appFetch<LandingPage>({
16
- url: landingpage.getLandingPageByPk(pk),
17
- locale,
18
- currency,
19
- init: {
20
- headers: {
21
- Accept: 'application/json',
22
- 'Content-Type': 'application/json',
23
- ...(headers ?? {})
24
- }
14
+ const data = await appFetch<LandingPage>({
15
+ url: landingpage.getLandingPageByPk(pk),
16
+ locale,
17
+ currency,
18
+ init: {
19
+ headers: {
20
+ Accept: 'application/json',
21
+ 'Content-Type': 'application/json',
22
+ ...(headers ?? {})
25
23
  }
26
- });
24
+ }
25
+ });
27
26
 
28
- return data;
29
- } catch (error) {
30
- return null;
31
- }
27
+ return data;
32
28
  };
33
29
  };
34
30
 
@@ -16,29 +16,19 @@ const getListDataHandler = (
16
16
  return async function () {
17
17
  const params = generateCommerceSearchParams(searchParams);
18
18
 
19
- let rawData: string;
20
-
21
- try {
22
- rawData = await appFetch<string>({
23
- url: `${category.list}${params}`,
24
- locale,
25
- currency,
26
- init: {
27
- headers: {
28
- Accept: 'application/json',
29
- 'Content-Type': 'application/json',
30
- ...(headers ?? {})
31
- }
32
- },
33
- responseType: FetchResponseType.TEXT
34
- });
35
- } catch (error) {
36
- logger.error('Failed to fetch list data', {
37
- handler: 'getListDataHandler',
38
- error: error.message
39
- });
40
- return null;
41
- }
19
+ const rawData = await appFetch<string>({
20
+ url: `${category.list}${params}`,
21
+ locale,
22
+ currency,
23
+ init: {
24
+ headers: {
25
+ Accept: 'application/json',
26
+ 'Content-Type': 'application/json',
27
+ ...(headers ?? {})
28
+ }
29
+ },
30
+ responseType: FetchResponseType.TEXT
31
+ });
42
32
 
43
33
  let data: GetCategoryResponse;
44
34
 
@@ -15,24 +15,20 @@ const getSpecialPageDataHandler = (
15
15
  return async function () {
16
16
  const params = generateCommerceSearchParams(searchParams);
17
17
 
18
- try {
19
- const data: GetCategoryResponse = await appFetch({
20
- url: `${category.getSpecialPageByPk(pk)}${params}`,
21
- locale,
22
- currency,
23
- init: {
24
- headers: {
25
- Accept: 'application/json',
26
- 'Content-Type': 'application/json',
27
- ...(headers ?? {})
28
- }
18
+ const data: GetCategoryResponse = await appFetch({
19
+ url: `${category.getSpecialPageByPk(pk)}${params}`,
20
+ locale,
21
+ currency,
22
+ init: {
23
+ headers: {
24
+ Accept: 'application/json',
25
+ 'Content-Type': 'application/json',
26
+ ...(headers ?? {})
29
27
  }
30
- });
28
+ }
29
+ });
31
30
 
32
- return data;
33
- } catch (error) {
34
- return null;
35
- }
31
+ return data;
36
32
  };
37
33
  };
38
34
 
package/data/urls.ts CHANGED
@@ -183,11 +183,7 @@ export const product = {
183
183
  breadcrumbUrl: (menuitemmodel: string) =>
184
184
  `/menus/generate_breadcrumb/?item=${menuitemmodel}&generator_name=menu_item`,
185
185
  bundleProduct: (productPk: string, queryString: string) =>
186
- `/bundle-product/${productPk}/?${queryString}`,
187
- similarProducts: (params?: string) =>
188
- `/similar-products${params ? `?${params}` : ''}`,
189
- similarProductsList: (params?: string) =>
190
- `/similar-product-list${params ? `?${params}` : ''}`
186
+ `/bundle-product/${productPk}/?${queryString}`
191
187
  };
192
188
 
193
189
  export const wishlist = {
@@ -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,6 +4,7 @@ import { LocalizationContext } from '../localization/provider';
4
4
  import { useContext } from 'react';
5
5
  import { setCookie, urlLocaleMatcherRegex } from '../utils';
6
6
  import { LocaleUrlStrategy } from '../localization';
7
+ import { useRouter } from 'next/navigation';
7
8
 
8
9
  export const useLocalization = () => {
9
10
  const {
@@ -17,6 +18,8 @@ export const useLocalization = () => {
17
18
  localeUrlStrategy
18
19
  } = useContext(LocalizationContext);
19
20
 
21
+ const router = useRouter();
22
+
20
23
  /**
21
24
  * Sets the locale in the URL.
22
25
  * @param locale Locale value defined in the settings.
@@ -27,8 +30,6 @@ export const useLocalization = () => {
27
30
 
28
31
  let targetUrl;
29
32
 
30
- setCookie('pz-locale', locale);
31
-
32
33
  if (localeUrlStrategy === LocaleUrlStrategy.Subdomain) {
33
34
  const hostParts = hostname.split('.');
34
35
  const subDomain = hostParts[0];
@@ -148,8 +148,7 @@ const withCompleteGpay =
148
148
  logger.info('Redirecting to order success page', {
149
149
  middleware: 'complete-gpay',
150
150
  redirectUrlWithLocale,
151
- ip,
152
- setCookie: request.headers.get('set-cookie')
151
+ ip
153
152
  });
154
153
 
155
154
  // Using POST method while redirecting causes an error,
@@ -149,8 +149,7 @@ const withCompleteMasterpass =
149
149
  logger.info('Redirecting to order success page', {
150
150
  middleware: 'complete-masterpass',
151
151
  redirectUrlWithLocale,
152
- ip,
153
- setCookie: request.headers.get('set-cookie')
152
+ ip
154
153
  });
155
154
 
156
155
  // Using POST method while redirecting causes an error,
@@ -23,15 +23,7 @@ const getMatchedLocale = (pathname: string, req: PzNextRequest) => {
23
23
  );
24
24
 
25
25
  if (subDomainLocaleMatched && subDomainLocaleMatched[0]) {
26
- const subdomainLocale = subDomainLocaleMatched[0].slice(1);
27
-
28
- const isValidSubdomainLocale = settings.localization.locales.find(
29
- (l) => l.value === subdomainLocale
30
- );
31
-
32
- if (isValidSubdomainLocale) {
33
- matchedLocale = subdomainLocale;
34
- }
26
+ matchedLocale = subDomainLocaleMatched[0].slice(1);
35
27
  }
36
28
  }
37
29
  }
@@ -149,8 +149,7 @@ const withRedirectionPayment =
149
149
  logger.info('Redirecting to order success page', {
150
150
  middleware: 'redirection-payment',
151
151
  redirectUrlWithLocale,
152
- ip,
153
- setCookie: request.headers.get('set-cookie')
152
+ ip
154
153
  });
155
154
 
156
155
  // Using POST method while redirecting causes an error,
@@ -149,8 +149,7 @@ const withSavedCardRedirection =
149
149
  logger.info('Redirecting to order success page', {
150
150
  middleware: 'saved-card-redirection',
151
151
  redirectUrlWithLocale,
152
- ip,
153
- setCookie: request.headers.get('set-cookie')
152
+ ip
154
153
  });
155
154
 
156
155
  // Using POST method while redirecting causes an error,
@@ -148,8 +148,7 @@ const withThreeDRedirection =
148
148
  logger.info('Redirecting to order success page', {
149
149
  middleware: 'three-d-redirection',
150
150
  redirectUrlWithLocale,
151
- ip,
152
- setCookie: request.headers.get('set-cookie')
151
+ ip
153
152
  });
154
153
 
155
154
  // Using POST method while redirecting causes an error,