@akinon/next 1.99.0 → 1.100.0-rc.71
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 +1321 -41
- 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/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 +4 -2
- 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/product.ts +66 -39
- 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/jest.config.js +7 -1
- package/middlewares/complete-gpay.ts +2 -1
- package/middlewares/complete-masterpass.ts +2 -1
- package/middlewares/default.ts +50 -13
- 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 +5 -1
- 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 +31 -6
- package/with-pz-config.js +1 -5
package/utils/redirect.ts
CHANGED
|
@@ -1,23 +1,48 @@
|
|
|
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';
|
|
5
|
+
import { urlLocaleMatcherRegex } from '@akinon/next/utils';
|
|
6
6
|
|
|
7
7
|
export const redirect = (path: string, type?: RedirectType) => {
|
|
8
8
|
const nextHeaders = headers();
|
|
9
|
+
const nextCookies = cookies();
|
|
9
10
|
const pageUrl = new URL(
|
|
10
|
-
nextHeaders.get('pz-url') ?? process.env.NEXT_PUBLIC_URL
|
|
11
|
+
nextHeaders.get('pz-url') ?? process.env.NEXT_PUBLIC_URL ?? ''
|
|
11
12
|
);
|
|
12
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
|
+
|
|
13
29
|
const currentLocale = Settings.localization.locales.find(
|
|
14
|
-
(locale) => locale.value ===
|
|
30
|
+
(locale) => locale.value === currentLocaleValue
|
|
15
31
|
);
|
|
16
32
|
|
|
17
|
-
|
|
33
|
+
if (!currentLocale) {
|
|
34
|
+
currentLocaleValue = Settings.localization.defaultLocaleValue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const searchParams = new URLSearchParams(pageUrl.search);
|
|
38
|
+
|
|
39
|
+
const callbackUrl =
|
|
40
|
+
pageUrl.pathname.replace(urlLocaleMatcherRegex, '') +
|
|
41
|
+
(searchParams.toString() ? `?${searchParams.toString()}` : '');
|
|
42
|
+
|
|
18
43
|
const redirectUrlWithLocale = getUrlPathWithLocale(
|
|
19
44
|
path,
|
|
20
|
-
currentLocale
|
|
45
|
+
currentLocale?.value
|
|
21
46
|
);
|
|
22
47
|
|
|
23
48
|
const redirectUrl = `${redirectUrlWithLocale}?callbackUrl=${callbackUrl}`;
|
package/with-pz-config.js
CHANGED