@akinon/next 1.102.0 → 1.103.0-rc.80
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 +1314 -35
- package/__tests__/next-config.test.ts +1 -10
- package/__tests__/redirect.test.ts +319 -0
- package/api/form.ts +84 -0
- package/api/image-proxy.ts +75 -0
- package/api/similar-product-list.ts +84 -0
- package/api/similar-products.ts +120 -0
- package/bin/pz-prebuild.js +1 -0
- package/components/accordion.tsx +20 -5
- package/components/file-input.tsx +65 -3
- package/components/input.tsx +2 -0
- package/components/link.tsx +16 -12
- package/components/modal.tsx +32 -16
- package/components/plugin-module.tsx +32 -4
- package/data/client/checkout.ts +5 -3
- package/data/server/basket.ts +72 -0
- package/data/server/category.ts +44 -24
- package/data/server/flatpage.ts +16 -12
- package/data/server/landingpage.ts +16 -12
- package/data/server/list.ts +23 -13
- package/data/server/special-page.ts +16 -12
- package/data/urls.ts +6 -2
- package/hocs/server/with-segment-defaults.tsx +5 -2
- package/hooks/use-localization.ts +2 -3
- package/middlewares/complete-gpay.ts +2 -1
- package/middlewares/complete-masterpass.ts +2 -1
- package/middlewares/default.ts +50 -0
- package/middlewares/locale.ts +9 -1
- package/middlewares/redirection-payment.ts +2 -1
- package/middlewares/saved-card-redirection.ts +2 -1
- package/middlewares/three-d-redirection.ts +2 -2
- package/middlewares/url-redirection.ts +8 -14
- package/package.json +2 -2
- package/plugins.d.ts +8 -5
- package/plugins.js +3 -1
- package/redux/middlewares/checkout.ts +6 -2
- package/types/commerce/order.ts +1 -0
- package/types/index.ts +34 -1
- package/utils/app-fetch.ts +7 -2
- package/utils/redirect-ignore.ts +35 -0
- package/utils/redirect.ts +22 -3
- package/with-pz-config.js +1 -5
package/data/urls.ts
CHANGED
|
@@ -183,7 +183,11 @@ 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}
|
|
186
|
+
`/bundle-product/${productPk}/?${queryString}`,
|
|
187
|
+
similarProducts: (params?: string) =>
|
|
188
|
+
`/similar-products${params ? `?${params}` : ''}`,
|
|
189
|
+
similarProductsList: (params?: string) =>
|
|
190
|
+
`/similar-product-list${params ? `?${params}` : ''}`
|
|
187
191
|
};
|
|
188
192
|
|
|
189
193
|
export const wishlist = {
|
|
@@ -247,7 +251,7 @@ export const widgets = {
|
|
|
247
251
|
};
|
|
248
252
|
|
|
249
253
|
export const form = {
|
|
250
|
-
getForm: (pk: number) => `/forms/${pk}/generate
|
|
254
|
+
getForm: (pk: number) => `/forms/${pk}/generate`
|
|
251
255
|
};
|
|
252
256
|
|
|
253
257
|
const URLS = {
|
|
@@ -72,10 +72,13 @@ const addRootLayoutProps = async (componentProps: RootLayoutProps) => {
|
|
|
72
72
|
const checkRedisVariables = () => {
|
|
73
73
|
const requiredVariableValues = [
|
|
74
74
|
process.env.CACHE_HOST,
|
|
75
|
-
process.env.CACHE_PORT
|
|
76
|
-
process.env.CACHE_SECRET
|
|
75
|
+
process.env.CACHE_PORT
|
|
77
76
|
];
|
|
78
77
|
|
|
78
|
+
if (!settings.usePrettyUrlRoute) {
|
|
79
|
+
requiredVariableValues.push(process.env.CACHE_SECRET);
|
|
80
|
+
}
|
|
81
|
+
|
|
79
82
|
if (
|
|
80
83
|
!requiredVariableValues.every((v) => v) &&
|
|
81
84
|
process.env.NODE_ENV === 'production'
|
|
@@ -4,7 +4,6 @@ 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';
|
|
8
7
|
|
|
9
8
|
export const useLocalization = () => {
|
|
10
9
|
const {
|
|
@@ -18,8 +17,6 @@ export const useLocalization = () => {
|
|
|
18
17
|
localeUrlStrategy
|
|
19
18
|
} = useContext(LocalizationContext);
|
|
20
19
|
|
|
21
|
-
const router = useRouter();
|
|
22
|
-
|
|
23
20
|
/**
|
|
24
21
|
* Sets the locale in the URL.
|
|
25
22
|
* @param locale Locale value defined in the settings.
|
|
@@ -30,6 +27,8 @@ export const useLocalization = () => {
|
|
|
30
27
|
|
|
31
28
|
let targetUrl;
|
|
32
29
|
|
|
30
|
+
setCookie('pz-locale', locale);
|
|
31
|
+
|
|
33
32
|
if (localeUrlStrategy === LocaleUrlStrategy.Subdomain) {
|
|
34
33
|
const hostParts = hostname.split('.');
|
|
35
34
|
const subDomain = hostParts[0];
|
|
@@ -148,7 +148,8 @@ const withCompleteGpay =
|
|
|
148
148
|
logger.info('Redirecting to order success page', {
|
|
149
149
|
middleware: 'complete-gpay',
|
|
150
150
|
redirectUrlWithLocale,
|
|
151
|
-
ip
|
|
151
|
+
ip,
|
|
152
|
+
setCookie: request.headers.get('set-cookie')
|
|
152
153
|
});
|
|
153
154
|
|
|
154
155
|
// Using POST method while redirecting causes an error,
|
|
@@ -149,7 +149,8 @@ const withCompleteMasterpass =
|
|
|
149
149
|
logger.info('Redirecting to order success page', {
|
|
150
150
|
middleware: 'complete-masterpass',
|
|
151
151
|
redirectUrlWithLocale,
|
|
152
|
-
ip
|
|
152
|
+
ip,
|
|
153
|
+
setCookie: request.headers.get('set-cookie')
|
|
153
154
|
});
|
|
154
155
|
|
|
155
156
|
// Using POST method while redirecting causes an error,
|
package/middlewares/default.ts
CHANGED
|
@@ -338,6 +338,24 @@ const withPzDefault =
|
|
|
338
338
|
middlewareResult = NextResponse.rewrite(url);
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
+
if (
|
|
342
|
+
!req.middlewareParams.found &&
|
|
343
|
+
Settings.customNotFoundEnabled
|
|
344
|
+
) {
|
|
345
|
+
const pathSegments = url.pathname
|
|
346
|
+
.replace(/\/+$/, '')
|
|
347
|
+
.split('/');
|
|
348
|
+
if (pathSegments.length >= 3) {
|
|
349
|
+
url.pathname = `/${pathSegments[1]}/${pathSegments[2]}/pz-not-found`;
|
|
350
|
+
} else {
|
|
351
|
+
url.pathname = '/pz-not-found';
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
middlewareResult = NextResponse.rewrite(url, {
|
|
355
|
+
status: 404
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
341
359
|
const { localeUrlStrategy } =
|
|
342
360
|
Settings.localization;
|
|
343
361
|
|
|
@@ -387,6 +405,38 @@ const withPzDefault =
|
|
|
387
405
|
}
|
|
388
406
|
);
|
|
389
407
|
|
|
408
|
+
if (
|
|
409
|
+
!url.pathname.startsWith(
|
|
410
|
+
`/${currency}/orders`
|
|
411
|
+
)
|
|
412
|
+
) {
|
|
413
|
+
const currentCookieLocale =
|
|
414
|
+
req.cookies.get('pz-locale')?.value;
|
|
415
|
+
|
|
416
|
+
const urlHasExplicitLocale =
|
|
417
|
+
url.pathname.match(urlLocaleMatcherRegex);
|
|
418
|
+
const shouldUpdateCookie =
|
|
419
|
+
!currentCookieLocale ||
|
|
420
|
+
urlHasExplicitLocale;
|
|
421
|
+
|
|
422
|
+
if (shouldUpdateCookie) {
|
|
423
|
+
middlewareResult.cookies.set(
|
|
424
|
+
'pz-locale',
|
|
425
|
+
locale?.length > 0
|
|
426
|
+
? locale
|
|
427
|
+
: defaultLocaleValue,
|
|
428
|
+
{
|
|
429
|
+
domain: rootHostname,
|
|
430
|
+
sameSite: 'none',
|
|
431
|
+
secure: true,
|
|
432
|
+
expires: new Date(
|
|
433
|
+
Date.now() + 1000 * 60 * 60 * 24 * 7
|
|
434
|
+
) // 7 days
|
|
435
|
+
}
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
390
440
|
if (
|
|
391
441
|
req.cookies.get('pz-locale') &&
|
|
392
442
|
req.cookies.get('pz-locale').value !== locale
|
package/middlewares/locale.ts
CHANGED
|
@@ -23,7 +23,15 @@ const getMatchedLocale = (pathname: string, req: PzNextRequest) => {
|
|
|
23
23
|
);
|
|
24
24
|
|
|
25
25
|
if (subDomainLocaleMatched && subDomainLocaleMatched[0]) {
|
|
26
|
-
|
|
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
|
+
}
|
|
27
35
|
}
|
|
28
36
|
}
|
|
29
37
|
}
|
|
@@ -149,7 +149,8 @@ const withRedirectionPayment =
|
|
|
149
149
|
logger.info('Redirecting to order success page', {
|
|
150
150
|
middleware: 'redirection-payment',
|
|
151
151
|
redirectUrlWithLocale,
|
|
152
|
-
ip
|
|
152
|
+
ip,
|
|
153
|
+
setCookie: request.headers.get('set-cookie')
|
|
153
154
|
});
|
|
154
155
|
|
|
155
156
|
// Using POST method while redirecting causes an error,
|
|
@@ -149,7 +149,8 @@ const withSavedCardRedirection =
|
|
|
149
149
|
logger.info('Redirecting to order success page', {
|
|
150
150
|
middleware: 'saved-card-redirection',
|
|
151
151
|
redirectUrlWithLocale,
|
|
152
|
-
ip
|
|
152
|
+
ip,
|
|
153
|
+
setCookie: request.headers.get('set-cookie')
|
|
153
154
|
});
|
|
154
155
|
|
|
155
156
|
// Using POST method while redirecting causes an error,
|
|
@@ -4,7 +4,6 @@ import { Buffer } from 'buffer';
|
|
|
4
4
|
import logger from '../utils/log';
|
|
5
5
|
import { getUrlPathWithLocale } from '../utils/localization';
|
|
6
6
|
import { PzNextRequest } from '.';
|
|
7
|
-
import { ServerVariables } from '../utils/server-variables';
|
|
8
7
|
|
|
9
8
|
const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
|
|
10
9
|
if (stream) {
|
|
@@ -149,7 +148,8 @@ const withThreeDRedirection =
|
|
|
149
148
|
logger.info('Redirecting to order success page', {
|
|
150
149
|
middleware: 'three-d-redirection',
|
|
151
150
|
redirectUrlWithLocale,
|
|
152
|
-
ip
|
|
151
|
+
ip,
|
|
152
|
+
setCookie: request.headers.get('set-cookie')
|
|
153
153
|
});
|
|
154
154
|
|
|
155
155
|
// Using POST method while redirecting causes an error,
|
|
@@ -4,6 +4,7 @@ import { PzNextRequest } from '.';
|
|
|
4
4
|
import logger from '../utils/log';
|
|
5
5
|
import { urlLocaleMatcherRegex } from '../utils';
|
|
6
6
|
import { getUrlPathWithLocale } from '../utils/localization';
|
|
7
|
+
import { shouldIgnoreRedirect } from '../utils/redirect-ignore';
|
|
7
8
|
import { ROUTES } from 'routes';
|
|
8
9
|
|
|
9
10
|
// This middleware is used to handle url redirections set in Omnitron
|
|
@@ -60,20 +61,13 @@ const withUrlRedirection =
|
|
|
60
61
|
|
|
61
62
|
const setCookies = request.headers.getSetCookie();
|
|
62
63
|
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
if (shouldIgnoreRedirect) {
|
|
75
|
-
return middleware(req, event);
|
|
76
|
-
}
|
|
64
|
+
if (
|
|
65
|
+
shouldIgnoreRedirect(
|
|
66
|
+
url.pathname,
|
|
67
|
+
req.middlewareParams.rewrites.locale
|
|
68
|
+
)
|
|
69
|
+
) {
|
|
70
|
+
return middleware(req, event);
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
const response = NextResponse.redirect(redirectUrl.toString(), {
|
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.
|
|
4
|
+
"version": "1.103.0-rc.80",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"set-cookie-parser": "2.6.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@akinon/eslint-plugin-projectzero": "1.
|
|
38
|
+
"@akinon/eslint-plugin-projectzero": "1.103.0-rc.80",
|
|
39
39
|
"@babel/core": "7.26.10",
|
|
40
40
|
"@babel/preset-env": "7.26.9",
|
|
41
41
|
"@babel/preset-typescript": "7.27.0",
|
package/plugins.d.ts
CHANGED
|
@@ -31,11 +31,14 @@ declare module '@akinon/pz-saved-card' {
|
|
|
31
31
|
export const SavedCardOption: any;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
declare module '@akinon/pz-iyzico-saved-card' {
|
|
35
|
-
export const iyzicoSavedCardReducer: any;
|
|
36
|
-
export const iyzicoSavedCardMiddleware: any;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
34
|
declare module '@akinon/pz-apple-pay' {}
|
|
40
35
|
|
|
41
36
|
declare module '@akinon/pz-flow-payment' {}
|
|
37
|
+
|
|
38
|
+
declare module '@akinon/pz-similar-products' {
|
|
39
|
+
export const SimilarProductsModal: any;
|
|
40
|
+
export const SimilarProductsFilterSidebar: any;
|
|
41
|
+
export const SimilarProductsResultsGrid: any;
|
|
42
|
+
export const SimilarProductsPlugin: any;
|
|
43
|
+
export const SimilarProductsButtonPlugin: any;
|
|
44
|
+
}
|
package/plugins.js
CHANGED
|
@@ -51,7 +51,11 @@ export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
|
|
|
51
51
|
const result: CheckoutResult = next(action);
|
|
52
52
|
const errors = result?.payload?.errors;
|
|
53
53
|
|
|
54
|
-
if (
|
|
54
|
+
if (
|
|
55
|
+
!!errors &&
|
|
56
|
+
((typeof errors === 'object' && Object.keys(errors).length > 0) ||
|
|
57
|
+
(Array.isArray(errors) && errors.length > 0))
|
|
58
|
+
) {
|
|
55
59
|
dispatch(setErrors(errors));
|
|
56
60
|
}
|
|
57
61
|
|
|
@@ -98,7 +102,7 @@ export const contextListMiddleware: Middleware = ({
|
|
|
98
102
|
if (result?.payload?.context_list) {
|
|
99
103
|
result.payload.context_list.forEach((context) => {
|
|
100
104
|
const redirectUrl = context.page_context.redirect_url;
|
|
101
|
-
const isIframe = context.page_context.
|
|
105
|
+
const isIframe = context.page_context.is_iframe ?? false;
|
|
102
106
|
|
|
103
107
|
if (redirectUrl) {
|
|
104
108
|
const currentLocale = getCookie('pz-locale');
|
package/types/commerce/order.ts
CHANGED
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
|
|
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 {
|
|
@@ -346,3 +362,20 @@ export interface PaginationProps {
|
|
|
346
362
|
direction?: 'next' | 'prev';
|
|
347
363
|
isLoading?: boolean;
|
|
348
364
|
}
|
|
365
|
+
|
|
366
|
+
export interface ModalProps {
|
|
367
|
+
portalId: string;
|
|
368
|
+
children?: React.ReactNode;
|
|
369
|
+
open?: boolean;
|
|
370
|
+
setOpen?: (open: boolean) => void;
|
|
371
|
+
title?: React.ReactNode;
|
|
372
|
+
showCloseButton?: React.ReactNode;
|
|
373
|
+
className?: string;
|
|
374
|
+
overlayClassName?: string;
|
|
375
|
+
headerWrapperClassName?: string;
|
|
376
|
+
titleClassName?: string;
|
|
377
|
+
closeButtonClassName?: string;
|
|
378
|
+
iconName?: string;
|
|
379
|
+
iconSize?: number;
|
|
380
|
+
iconClassName?: string;
|
|
381
|
+
}
|
package/utils/app-fetch.ts
CHANGED
|
@@ -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 {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import settings from 'settings';
|
|
2
|
+
import { getUrlPathWithLocale } from './localization';
|
|
3
|
+
|
|
4
|
+
type IgnorePath = string | RegExp;
|
|
5
|
+
|
|
6
|
+
const defaultIgnoreList: string[] = [];
|
|
7
|
+
|
|
8
|
+
const extraIgnores: IgnorePath[] = Array.isArray(
|
|
9
|
+
settings.commerceRedirectionIgnoreList
|
|
10
|
+
)
|
|
11
|
+
? settings.commerceRedirectionIgnoreList.map((path) => {
|
|
12
|
+
if (path === '/users/reset') {
|
|
13
|
+
return /^\/users\/reset\/[^/]+\/[^/]+\/$/;
|
|
14
|
+
}
|
|
15
|
+
return path;
|
|
16
|
+
})
|
|
17
|
+
: [];
|
|
18
|
+
|
|
19
|
+
export function shouldIgnoreRedirect(
|
|
20
|
+
pathname: string,
|
|
21
|
+
locale: string
|
|
22
|
+
): boolean {
|
|
23
|
+
if (!pathname) return false;
|
|
24
|
+
|
|
25
|
+
const rawIgnoreList: IgnorePath[] = [...defaultIgnoreList, ...extraIgnores];
|
|
26
|
+
|
|
27
|
+
return rawIgnoreList.some((ignorePath) => {
|
|
28
|
+
if (ignorePath instanceof RegExp) {
|
|
29
|
+
return ignorePath.test(pathname);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const localized = getUrlPathWithLocale(ignorePath, locale);
|
|
33
|
+
return localized === pathname;
|
|
34
|
+
});
|
|
35
|
+
}
|
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 ===
|
|
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 =
|
package/with-pz-config.js
CHANGED