@akinon/next 1.98.0 → 1.99.0-rc.66

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +1319 -41
  2. package/__tests__/next-config.test.ts +1 -10
  3. package/__tests__/redirect.test.ts +319 -0
  4. package/api/image-proxy.ts +75 -0
  5. package/api/similar-product-list.ts +84 -0
  6. package/api/similar-products.ts +120 -0
  7. package/components/accordion.tsx +20 -5
  8. package/components/file-input.tsx +65 -3
  9. package/components/input.tsx +2 -0
  10. package/components/link.tsx +16 -12
  11. package/components/modal.tsx +32 -16
  12. package/components/plugin-module.tsx +32 -4
  13. package/data/client/checkout.ts +4 -2
  14. package/data/server/basket.ts +72 -0
  15. package/data/server/category.ts +44 -24
  16. package/data/server/flatpage.ts +16 -12
  17. package/data/server/landingpage.ts +16 -12
  18. package/data/server/list.ts +23 -13
  19. package/data/server/product.ts +66 -39
  20. package/data/server/special-page.ts +16 -12
  21. package/data/urls.ts +5 -1
  22. package/hocs/server/with-segment-defaults.tsx +5 -2
  23. package/hooks/use-localization.ts +2 -3
  24. package/jest.config.js +7 -1
  25. package/lib/cache.ts +2 -0
  26. package/middlewares/complete-gpay.ts +2 -1
  27. package/middlewares/complete-masterpass.ts +2 -1
  28. package/middlewares/default.ts +50 -13
  29. package/middlewares/locale.ts +9 -1
  30. package/middlewares/redirection-payment.ts +2 -1
  31. package/middlewares/saved-card-redirection.ts +2 -1
  32. package/middlewares/three-d-redirection.ts +2 -1
  33. package/middlewares/url-redirection.ts +8 -14
  34. package/package.json +3 -3
  35. package/plugins.d.ts +8 -5
  36. package/plugins.js +3 -1
  37. package/redux/middlewares/checkout.ts +5 -1
  38. package/types/commerce/order.ts +1 -0
  39. package/types/index.ts +34 -1
  40. package/utils/app-fetch.ts +7 -2
  41. package/utils/redirect-ignore.ts +35 -0
  42. package/utils/redirect.ts +31 -6
  43. 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 === ServerVariables.locale
30
+ (locale) => locale.value === currentLocaleValue
15
31
  );
16
32
 
17
- const callbackUrl = pageUrl.pathname;
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.localePath ?? currentLocale.value
45
+ currentLocale?.value
21
46
  );
22
47
 
23
48
  const redirectUrl = `${redirectUrlWithLocale}?callbackUrl=${callbackUrl}`;
package/with-pz-config.js CHANGED
@@ -16,12 +16,8 @@ const defaultConfig = {
16
16
  remotePatterns: [
17
17
  {
18
18
  protocol: 'https',
19
- hostname: '**.akinoncloud.com'
19
+ hostname: '**'
20
20
  },
21
- {
22
- protocol: 'https',
23
- hostname: '**.akinoncdn.com'
24
- }
25
21
  ]
26
22
  },
27
23
  modularizeImports: {