@akinon/next 1.45.0-rc.0 → 1.45.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +4 -240
  2. package/api/client.ts +9 -33
  3. package/assets/styles/index.scss +26 -50
  4. package/components/input.tsx +7 -21
  5. package/components/link.tsx +13 -17
  6. package/components/pagination.tsx +2 -1
  7. package/components/price.tsx +4 -11
  8. package/components/selected-payment-option-view.tsx +38 -26
  9. package/data/client/account.ts +9 -10
  10. package/data/client/address.ts +8 -32
  11. package/data/client/api.ts +1 -1
  12. package/data/client/checkout.ts +4 -47
  13. package/data/server/category.ts +2 -2
  14. package/data/server/list.ts +2 -2
  15. package/data/server/product.ts +13 -15
  16. package/data/server/special-page.ts +2 -2
  17. package/data/urls.ts +1 -5
  18. package/hooks/index.ts +1 -2
  19. package/hooks/use-payment-options.ts +1 -2
  20. package/lib/cache.ts +6 -18
  21. package/middlewares/default.ts +2 -50
  22. package/middlewares/locale.ts +30 -32
  23. package/middlewares/pretty-url.ts +0 -4
  24. package/middlewares/url-redirection.ts +0 -4
  25. package/package.json +4 -5
  26. package/plugins.d.ts +0 -1
  27. package/redux/middlewares/checkout.ts +11 -70
  28. package/redux/reducers/checkout.ts +5 -24
  29. package/redux/reducers/config.ts +0 -2
  30. package/types/commerce/account.ts +0 -1
  31. package/types/commerce/address.ts +1 -1
  32. package/types/commerce/checkout.ts +0 -30
  33. package/types/commerce/misc.ts +0 -2
  34. package/types/commerce/order.ts +0 -12
  35. package/types/index.ts +2 -28
  36. package/utils/app-fetch.ts +1 -1
  37. package/utils/generate-commerce-search-params.ts +2 -6
  38. package/utils/index.ts +6 -27
  39. package/utils/menu-generator.ts +2 -2
  40. package/utils/server-translation.ts +1 -5
  41. package/with-pz-config.js +1 -11
  42. package/assets/styles/index.css +0 -49
  43. package/assets/styles/index.css.map +0 -1
  44. package/hooks/use-message-listener.ts +0 -24
  45. package/lib/cache-handler.mjs +0 -33
  46. package/routes/pretty-url.tsx +0 -194
  47. package/utils/redirection-iframe.ts +0 -85
@@ -1,194 +0,0 @@
1
- import { URLS } from '@akinon/next/data/urls';
2
- import { Metadata, PageProps } from '@akinon/next/types';
3
- import logger from '@akinon/next/utils/log';
4
- import { notFound } from 'next/navigation';
5
-
6
- type PrettyUrlResult = {
7
- matched: boolean;
8
- path?: string;
9
- pk?: number;
10
- };
11
-
12
- const resolvePrettyUrlHandler =
13
- (pathname: string, ip: string | null) => async () => {
14
- let results = [] as { old_path: string }[];
15
- let prettyUrlResult: PrettyUrlResult = {
16
- matched: false
17
- };
18
-
19
- try {
20
- const requestUrl = URLS.misc.prettyUrls(`/${pathname}/`);
21
-
22
- logger.debug(`Resolving pretty url`, { pathname, requestUrl, ip });
23
-
24
- const start = Date.now();
25
- const apiResponse = await fetch(requestUrl, {
26
- next: {
27
- revalidate: 0
28
- }
29
- });
30
- const data = await apiResponse.json();
31
- ({ results } = data);
32
- const end = Date.now();
33
- console.warn('Pretty url response time', end - start, requestUrl);
34
-
35
- const matched = results.length > 0;
36
- const [{ old_path: path } = { old_path: '' }] = results;
37
- let pk;
38
-
39
- if (matched) {
40
- const pkRegex = /\/(\d+)\/$/;
41
- const match = path.match(pkRegex);
42
- pk = match ? parseInt(match[1]) : undefined;
43
- }
44
-
45
- prettyUrlResult = {
46
- matched,
47
- path,
48
- pk
49
- };
50
-
51
- logger.trace('Pretty url result', { prettyUrlResult, ip });
52
- } catch (error) {
53
- logger.error('Error resolving pretty url', { error, pathname, ip });
54
- }
55
-
56
- return prettyUrlResult;
57
- };
58
-
59
- export async function generateMetadata({ params }: PageProps) {
60
- let result: Metadata = {};
61
- const { prettyurl } = params;
62
- const pageSlug = prettyurl
63
- .filter((x) => !x.startsWith('searchparams'))
64
- .join('/');
65
-
66
- const searchParams = Object.fromEntries(
67
- new URLSearchParams(
68
- decodeURIComponent(
69
- prettyurl
70
- .find((x) => x.startsWith('searchparams'))
71
- ?.replace('searchparams%7C', '')
72
- ) ?? {}
73
- ).entries()
74
- );
75
-
76
- const prettyUrlResult = await resolvePrettyUrlHandler(pageSlug, null)();
77
-
78
- if (!prettyUrlResult.matched) {
79
- return notFound();
80
- }
81
-
82
- const commonProps = {
83
- params: {
84
- ...params,
85
- pk: prettyUrlResult.pk
86
- },
87
- searchParams
88
- };
89
-
90
- try {
91
- if (prettyUrlResult.path.startsWith('/product/')) {
92
- await import('@product/[pk]/page').then(async (module) => {
93
- result = await module['generateMetadata']?.(commonProps);
94
- });
95
- }
96
-
97
- if (prettyUrlResult.path.startsWith('/group-product/')) {
98
- await import('@group-product/[pk]/page').then(async (module) => {
99
- result = await module['generateMetadata']?.(commonProps);
100
- });
101
- }
102
-
103
- if (prettyUrlResult.path.startsWith('/category/')) {
104
- await import('@category/[pk]/page').then(async (module) => {
105
- result = await module['generateMetadata']?.(commonProps);
106
- });
107
- }
108
-
109
- if (prettyUrlResult.path.startsWith('/special-page/')) {
110
- await import('@special-page/[pk]/page').then(async (module) => {
111
- result = await module['generateMetadata']?.(commonProps);
112
- });
113
- }
114
-
115
- if (prettyUrlResult.path.startsWith('/flat-page/')) {
116
- await import('@flat-page/[pk]/page').then(async (module) => {
117
- result = await module['generateMetadata']?.(commonProps);
118
- });
119
- }
120
- // eslint-disable-next-line no-empty
121
- } catch (error) {}
122
-
123
- return result;
124
- }
125
-
126
- export const dynamic = 'force-static';
127
- export const revalidate = 300;
128
-
129
- export default async function Page({ params }) {
130
- const { prettyurl } = params;
131
- const pageSlug = prettyurl
132
- .filter((x) => !x.startsWith('searchparams'))
133
- .join('/');
134
-
135
- const urlSearchParams = new URLSearchParams(
136
- decodeURIComponent(
137
- prettyurl
138
- .find((x) => x.startsWith('searchparams'))
139
- ?.replace('searchparams%7C', '')
140
- ) ?? {}
141
- );
142
-
143
- const searchParams = {};
144
-
145
- for (const [key, value] of urlSearchParams.entries() as unknown as Array<
146
- [string, string]
147
- >) {
148
- if (!searchParams[key]) {
149
- searchParams[key] = [];
150
- }
151
- searchParams[key].push(value);
152
- }
153
-
154
- const result = await resolvePrettyUrlHandler(pageSlug, null)();
155
-
156
- if (!result.matched) {
157
- return notFound();
158
- }
159
-
160
- const commonProps = {
161
- params: {
162
- ...params,
163
- pk: result.pk
164
- },
165
- searchParams
166
- };
167
-
168
- if (result.path.startsWith('/category/')) {
169
- const CategoryPage = (await import('@category/[pk]/page')).default;
170
- return <CategoryPage {...commonProps} />;
171
- }
172
-
173
- if (result.path.startsWith('/product/')) {
174
- const ProductPage = (await import('@product/[pk]/page')).default;
175
- return <ProductPage {...commonProps} />;
176
- }
177
-
178
- if (result.path.startsWith('/group-product/')) {
179
- const GroupProduct = (await import('@group-product/[pk]/page')).default;
180
- return <GroupProduct {...commonProps} />;
181
- }
182
-
183
- if (result.path.startsWith('/special-page/')) {
184
- const SpecialPage = (await import('@special-page/[pk]/page')).default;
185
- return <SpecialPage {...commonProps} />;
186
- }
187
-
188
- if (result.path.startsWith('/flat-page/')) {
189
- const FlatPage = (await import('@flat-page/[pk]/page')).default;
190
- return <FlatPage {...commonProps} />;
191
- }
192
-
193
- return null;
194
- }
@@ -1,85 +0,0 @@
1
- const iframeURLChange = (iframe, callback) => {
2
- iframe.addEventListener('load', () => {
3
- setTimeout(() => {
4
- if (iframe?.contentWindow?.location) {
5
- callback(iframe.contentWindow.location);
6
- }
7
- }, 0);
8
- });
9
- };
10
-
11
- const removeIframe = async () => {
12
- const iframeSelector = document.querySelector(
13
- '.checkout-payment-redirection-iframe-wrapper'
14
- );
15
-
16
- const redirectionPaymentWrapper = document.querySelector(
17
- '.checkout-redirection-payment-wrapper'
18
- );
19
-
20
- const form = redirectionPaymentWrapper.querySelector('form') as HTMLElement;
21
-
22
- if (!iframeSelector) {
23
- return;
24
- }
25
-
26
- iframeSelector.remove();
27
-
28
- if (form) {
29
- form.style.display = 'block';
30
- }
31
-
32
- location.reload();
33
- };
34
-
35
- export const showRedirectionIframe = (redirectUrl: string) => {
36
- const iframeWrapper = document.createElement('div');
37
- const iframe = document.createElement('iframe');
38
- const closeButton = document.createElement('div');
39
- const redirectionPaymentWrapper = document.querySelector(
40
- '.checkout-redirection-payment-wrapper'
41
- );
42
- const form = redirectionPaymentWrapper.querySelector('form') as HTMLElement;
43
-
44
- iframeWrapper.className = 'checkout-payment-redirection-iframe-wrapper';
45
- closeButton.className = 'close-button';
46
-
47
- iframe.setAttribute('src', redirectUrl);
48
- closeButton.innerHTML = '&#x2715';
49
- closeButton.addEventListener('click', removeIframe);
50
-
51
- iframeWrapper.append(iframe, closeButton);
52
-
53
- if (form) {
54
- form.style.display = 'none';
55
- }
56
-
57
- redirectionPaymentWrapper.appendChild(iframeWrapper);
58
-
59
- iframeURLChange(iframe, (location) => {
60
- if (location.origin !== window.location.origin) {
61
- return false;
62
- }
63
-
64
- const searchParams = new URLSearchParams(location.search);
65
- const isOrderCompleted = location.href.includes('/orders/completed');
66
-
67
- if (isOrderCompleted) {
68
- (window.parent as any)?.postMessage?.(
69
- JSON.stringify({
70
- url: location.pathname
71
- })
72
- );
73
- }
74
-
75
- if (
76
- searchParams.has('success') ||
77
- isOrderCompleted ||
78
- location.href.includes('/orders/checkout')
79
- ) {
80
- setTimeout(() => {
81
- removeIframe();
82
- }, 0);
83
- }
84
- });
85
- };