@akinon/next 1.105.0 → 1.106.0-rc.85

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/types/index.ts CHANGED
@@ -83,6 +83,12 @@ export interface Settings {
83
83
  };
84
84
  usePrettyUrlRoute?: boolean;
85
85
  commerceUrl: string;
86
+ /**
87
+ * This option allows you to track Sentry events on the client side, in addition to server and edge environments.
88
+ *
89
+ * It overrides process.env.NEXT_PUBLIC_SENTRY_DSN and process.env.SENTRY_DSN.
90
+ */
91
+ sentryDsn?: string;
86
92
  redis: {
87
93
  defaultExpirationTime: number;
88
94
  };
@@ -292,7 +298,13 @@ export interface ButtonProps
292
298
  target?: '_blank' | '_self' | '_parent' | '_top';
293
299
  }
294
300
 
295
- export type FileInputProps = React.HTMLProps<HTMLInputElement>;
301
+ export interface FileInputProps extends React.HTMLProps<HTMLInputElement> {
302
+ fileClassName?: string;
303
+ fileNameWrapperClassName?: string;
304
+ fileInputClassName?: string;
305
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
306
+ buttonClassName?: string;
307
+ }
296
308
 
297
309
  export interface PriceProps {
298
310
  currencyCode?: string;
@@ -313,15 +325,19 @@ export interface InputProps extends React.HTMLProps<HTMLInputElement> {
313
325
 
314
326
  export interface AccordionProps {
315
327
  isCollapse?: boolean;
328
+ collapseClassName?: string;
316
329
  title?: string;
317
330
  subTitle?: string;
318
331
  icons?: string[];
319
332
  iconSize?: number;
320
333
  iconColor?: string;
321
334
  children?: ReactNode;
335
+ headerClassName?: string;
322
336
  className?: string;
323
337
  titleClassName?: string;
338
+ subTitleClassName?: string;
324
339
  dataTestId?: string;
340
+ contentClassName?: string;
325
341
  }
326
342
 
327
343
  export interface PluginModuleComponentProps {
@@ -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(),
46
47
  ...(init.headers ?? {}),
47
48
  ...(ServerVariables.globalHeaders ?? {}),
48
49
  'Accept-Language': currentLocale.apiValue,
49
50
  'x-currency': currency,
50
- 'x-forwarded-for': ip,
51
- cookie: nextCookies.toString()
51
+ 'x-forwarded-for': ip
52
52
  };
53
53
 
54
54
  init.next = {
@@ -60,6 +60,11 @@ const appFetch = async <T>({
60
60
  status = req.status;
61
61
  logger.debug(`FETCH END ${url}`, { status: req.status, ip });
62
62
 
63
+ if (!req.ok) {
64
+ const errorMessage = `HTTP ${req.status}: ${req.statusText}`;
65
+ throw new Error(errorMessage);
66
+ }
67
+
63
68
  if (responseType === FetchResponseType.JSON) {
64
69
  response = (await req.json()) as T;
65
70
  } else {
package/utils/redirect.ts CHANGED
@@ -1,20 +1,39 @@
1
1
  import { redirect as nextRedirect, RedirectType } from 'next/navigation';
2
2
  import Settings from 'settings';
3
- import { headers } from 'next/headers';
4
- import { ServerVariables } from '@akinon/next/utils/server-variables';
3
+ import { headers, cookies } from 'next/headers';
5
4
  import { getUrlPathWithLocale } from '@akinon/next/utils/localization';
6
5
  import { urlLocaleMatcherRegex } from '@akinon/next/utils';
7
6
 
8
7
  export const redirect = (path: string, type?: RedirectType) => {
9
8
  const nextHeaders = headers();
9
+ const nextCookies = cookies();
10
10
  const pageUrl = new URL(
11
11
  nextHeaders.get('pz-url') ?? process.env.NEXT_PUBLIC_URL ?? ''
12
12
  );
13
13
 
14
+ let currentLocaleValue = Settings.localization.defaultLocaleValue;
15
+ const urlLocaleMatch = pageUrl.pathname.match(urlLocaleMatcherRegex);
16
+
17
+ if (urlLocaleMatch && urlLocaleMatch[0]) {
18
+ currentLocaleValue = urlLocaleMatch[0].replace('/', '');
19
+ } else {
20
+ const cookieLocale = nextCookies.get('pz-locale')?.value;
21
+ if (
22
+ cookieLocale &&
23
+ Settings.localization.locales.find((l) => l.value === cookieLocale)
24
+ ) {
25
+ currentLocaleValue = cookieLocale;
26
+ }
27
+ }
28
+
14
29
  const currentLocale = Settings.localization.locales.find(
15
- (locale) => locale.value === ServerVariables.locale
30
+ (locale) => locale.value === currentLocaleValue
16
31
  );
17
32
 
33
+ if (!currentLocale) {
34
+ currentLocaleValue = Settings.localization.defaultLocaleValue;
35
+ }
36
+
18
37
  const searchParams = new URLSearchParams(pageUrl.search);
19
38
 
20
39
  const callbackUrl =