@akinon/next 1.56.0-rc.7 → 1.57.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 (57) hide show
  1. package/CHANGELOG.md +4 -554
  2. package/api/client.ts +2 -23
  3. package/assets/styles/index.scss +26 -50
  4. package/bin/pz-prebuild.js +0 -1
  5. package/bin/pz-predev.js +0 -1
  6. package/components/index.ts +0 -1
  7. package/components/input.tsx +7 -21
  8. package/components/link.tsx +13 -17
  9. package/components/price.tsx +4 -11
  10. package/components/pz-root.tsx +3 -15
  11. package/components/selected-payment-option-view.tsx +2 -1
  12. package/data/client/api.ts +1 -1
  13. package/data/client/b2b.ts +2 -35
  14. package/data/client/basket.ts +5 -6
  15. package/data/client/checkout.ts +0 -37
  16. package/data/client/user.ts +2 -3
  17. package/data/server/category.ts +19 -43
  18. package/data/server/flatpage.ts +7 -29
  19. package/data/server/form.ts +11 -29
  20. package/data/server/landingpage.ts +7 -26
  21. package/data/server/list.ts +6 -16
  22. package/data/server/menu.ts +2 -15
  23. package/data/server/product.ts +13 -33
  24. package/data/server/seo.ts +24 -17
  25. package/data/server/special-page.ts +5 -15
  26. package/data/server/widget.ts +7 -14
  27. package/data/urls.ts +1 -8
  28. package/hocs/server/with-segment-defaults.tsx +1 -4
  29. package/hooks/index.ts +1 -2
  30. package/hooks/use-pagination.ts +2 -2
  31. package/lib/cache.ts +6 -8
  32. package/middlewares/default.ts +2 -46
  33. package/middlewares/pretty-url.ts +1 -11
  34. package/middlewares/url-redirection.ts +0 -4
  35. package/package.json +3 -4
  36. package/plugins.d.ts +0 -1
  37. package/plugins.js +1 -2
  38. package/redux/middlewares/checkout.ts +11 -71
  39. package/redux/reducers/checkout.ts +3 -23
  40. package/types/commerce/address.ts +1 -1
  41. package/types/commerce/b2b.ts +2 -12
  42. package/types/commerce/checkout.ts +0 -30
  43. package/types/commerce/order.ts +0 -1
  44. package/types/index.ts +2 -17
  45. package/utils/app-fetch.ts +8 -16
  46. package/utils/generate-commerce-search-params.ts +1 -3
  47. package/utils/index.ts +6 -27
  48. package/utils/server-translation.ts +1 -11
  49. package/with-pz-config.js +2 -13
  50. package/assets/styles/index.css +0 -49
  51. package/assets/styles/index.css.map +0 -1
  52. package/bin/pz-generate-translations.js +0 -41
  53. package/components/file-input.tsx +0 -8
  54. package/hooks/use-message-listener.ts +0 -24
  55. package/lib/cache-handler.mjs +0 -33
  56. package/routes/pretty-url.tsx +0 -192
  57. package/utils/redirection-iframe.ts +0 -85
@@ -1,49 +0,0 @@
1
- .checkout-payment-iframe-wrapper {
2
- position: fixed;
3
- top: 0;
4
- left: 0;
5
- width: 100%;
6
- height: 100%;
7
- border: none;
8
- z-index: 1000;
9
- background-color: white;
10
- }
11
- .checkout-payment-iframe-wrapper iframe {
12
- width: 100%;
13
- height: 100%;
14
- border: none;
15
- background-color: white;
16
- }
17
- .checkout-payment-iframe-wrapper .close-button {
18
- position: fixed;
19
- top: 16px;
20
- right: 16px;
21
- width: 32px;
22
- height: 32px;
23
- display: flex;
24
- align-items: center;
25
- justify-content: center;
26
- z-index: 1001;
27
- }
28
-
29
- .checkout-payment-redirection-iframe-wrapper {
30
- width: 100%;
31
- position: relative;
32
- }
33
- .checkout-payment-redirection-iframe-wrapper iframe {
34
- width: 100%;
35
- height: 100%;
36
- border: none;
37
- background-color: white;
38
- }
39
- .checkout-payment-redirection-iframe-wrapper .close-button {
40
- position: absolute;
41
- top: 16px;
42
- right: 16px;
43
- width: 32px;
44
- height: 32px;
45
- display: flex;
46
- align-items: center;
47
- justify-content: center;
48
- z-index: 1001;
49
- }/*# sourceMappingURL=index.css.map */
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.scss","index.css"],"names":[],"mappings":"AAAA;EACE,eAAA;EACA,MAAA;EACA,OAAA;EACA,WAAA;EACA,YAAA;EACA,YAAA;EACA,aAAA;EACA,uBAAA;ACCF;ADCE;EACE,WAAA;EACA,YAAA;EACA,YAAA;EACA,uBAAA;ACCJ;ADEE;EACE,eAAA;EACA,SAAA;EACA,WAAA;EACA,WAAA;EACA,YAAA;EACA,aAAA;EACA,mBAAA;EACA,uBAAA;EACA,aAAA;ACAJ;;ADIA;EACE,WAAA;EACA,kBAAA;ACDF;ADGE;EACE,WAAA;EACA,YAAA;EACA,YAAA;EACA,uBAAA;ACDJ;ADIE;EACE,kBAAA;EACA,SAAA;EACA,WAAA;EACA,WAAA;EACA,YAAA;EACA,aAAA;EACA,mBAAA;EACA,uBAAA;EACA,aAAA;ACFJ","file":"index.css"}
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const localesPath = path.resolve(`public/locales/`);
6
-
7
- async function generateTranslationIndex(locale_) {
8
- let translations = {};
9
-
10
- try {
11
- const localeDirPath = path.resolve(`public/locales/${locale_}`);
12
- const fileNames = fs.readdirSync(localeDirPath);
13
-
14
- for await (const fileName of fileNames) {
15
- if (fileName === 'index.json') {
16
- continue;
17
- }
18
-
19
- const data = fs.readFileSync(
20
- path.join(localeDirPath, `/${fileName}`),
21
- 'utf-8'
22
- );
23
-
24
- translations[fileName.substring(0, fileName.lastIndexOf('.'))] =
25
- JSON.parse(data);
26
- }
27
-
28
- fs.writeFileSync(
29
- path.resolve(`public/locales/${locale_}/index.json`),
30
- JSON.stringify(translations)
31
- );
32
- } catch (error) {
33
- console.error(error);
34
- }
35
- }
36
-
37
- const localePaths = fs.readdirSync(localesPath);
38
-
39
- localePaths.forEach((localePath) => {
40
- generateTranslationIndex(localePath);
41
- });
@@ -1,8 +0,0 @@
1
- import { forwardRef } from 'react';
2
- import { FileInputProps } from '../types/index';
3
-
4
- export const FileInput = forwardRef<HTMLInputElement, FileInputProps>(
5
- function fileInput(props, ref) {
6
- return <input type="file" {...props} ref={ref} />;
7
- }
8
- );
@@ -1,24 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- export const useMessageListener = () => {
4
- useEffect(() => {
5
- const handleMessage = (event: MessageEvent) => {
6
- if (event.origin !== window.location.origin) {
7
- return;
8
- }
9
-
10
- if (event.data && typeof event.data === 'string') {
11
- const messageData = JSON.parse(event.data);
12
- if (messageData?.url) {
13
- window.location.href = messageData.url;
14
- }
15
- }
16
- };
17
-
18
- window.addEventListener('message', handleMessage);
19
-
20
- return () => {
21
- window.removeEventListener('message', handleMessage);
22
- };
23
- }, []);
24
- };
@@ -1,33 +0,0 @@
1
- import { CacheHandler } from '@neshca/cache-handler';
2
- import createLruHandler from '@neshca/cache-handler/local-lru';
3
- import createRedisHandler from '@neshca/cache-handler/redis-stack';
4
- import { createClient } from 'redis';
5
-
6
- CacheHandler.onCreation(async () => {
7
- const redisUrl = `redis://${process.env.CACHE_HOST}:${
8
- process.env.CACHE_PORT
9
- }/${process.env.CACHE_BUCKET ?? '0'}`;
10
-
11
- const client = createClient({
12
- url: redisUrl
13
- });
14
-
15
- client.on('error', (error) => {
16
- console.error('Redis client error', { redisUrl, error });
17
- });
18
-
19
- await client.connect();
20
-
21
- const redisHandler = await createRedisHandler({
22
- client,
23
- timeoutMs: 5000
24
- });
25
-
26
- const localHandler = createLruHandler();
27
-
28
- return {
29
- handlers: [redisHandler, localHandler]
30
- };
31
- });
32
-
33
- export default CacheHandler;
@@ -1,192 +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 = new URLSearchParams(
67
- decodeURIComponent(
68
- prettyurl
69
- .find((x) => x.startsWith('searchparams'))
70
- ?.replace('searchparams%7C', '')
71
- ) ?? {}
72
- );
73
-
74
- const prettyUrlResult = await resolvePrettyUrlHandler(pageSlug, null)();
75
-
76
- if (!prettyUrlResult.matched) {
77
- return notFound();
78
- }
79
-
80
- const commonProps = {
81
- params: {
82
- ...params,
83
- pk: prettyUrlResult.pk
84
- },
85
- searchParams
86
- };
87
-
88
- try {
89
- if (prettyUrlResult.path.startsWith('/product/')) {
90
- await import('@product/[pk]/page').then(async (module) => {
91
- result = await module['generateMetadata']?.(commonProps);
92
- });
93
- }
94
-
95
- if (prettyUrlResult.path.startsWith('/group-product/')) {
96
- await import('@group-product/[pk]/page').then(async (module) => {
97
- result = await module['generateMetadata']?.(commonProps);
98
- });
99
- }
100
-
101
- if (prettyUrlResult.path.startsWith('/category/')) {
102
- await import('@category/[pk]/page').then(async (module) => {
103
- result = await module['generateMetadata']?.(commonProps);
104
- });
105
- }
106
-
107
- if (prettyUrlResult.path.startsWith('/special-page/')) {
108
- await import('@special-page/[pk]/page').then(async (module) => {
109
- result = await module['generateMetadata']?.(commonProps);
110
- });
111
- }
112
-
113
- if (prettyUrlResult.path.startsWith('/flat-page/')) {
114
- await import('@flat-page/[pk]/page').then(async (module) => {
115
- result = await module['generateMetadata']?.(commonProps);
116
- });
117
- }
118
- // eslint-disable-next-line no-empty
119
- } catch (error) {}
120
-
121
- return result;
122
- }
123
-
124
- export const dynamic = 'force-static';
125
- export const revalidate = 300;
126
-
127
- export default async function Page({ params }) {
128
- const { prettyurl } = params;
129
- const pageSlug = prettyurl
130
- .filter((x) => !x.startsWith('searchparams'))
131
- .join('/');
132
-
133
- const urlSearchParams = new URLSearchParams(
134
- decodeURIComponent(
135
- prettyurl
136
- .find((x) => x.startsWith('searchparams'))
137
- ?.replace('searchparams%7C', '')
138
- ) ?? {}
139
- );
140
-
141
- const searchParams = {};
142
-
143
- for (const [key, value] of urlSearchParams.entries() as unknown as Array<
144
- [string, string]
145
- >) {
146
- if (!searchParams[key]) {
147
- searchParams[key] = [];
148
- }
149
- searchParams[key].push(value);
150
- }
151
-
152
- const result = await resolvePrettyUrlHandler(pageSlug, null)();
153
-
154
- if (!result.matched) {
155
- return notFound();
156
- }
157
-
158
- const commonProps = {
159
- params: {
160
- ...params,
161
- pk: result.pk
162
- },
163
- searchParams: new URLSearchParams(searchParams)
164
- };
165
-
166
- if (result.path.startsWith('/category/')) {
167
- const CategoryPage = (await import('@category/[pk]/page')).default;
168
- return <CategoryPage {...commonProps} />;
169
- }
170
-
171
- if (result.path.startsWith('/product/')) {
172
- const ProductPage = (await import('@product/[pk]/page')).default;
173
- return <ProductPage {...commonProps} />;
174
- }
175
-
176
- if (result.path.startsWith('/group-product/')) {
177
- const GroupProduct = (await import('@group-product/[pk]/page')).default;
178
- return <GroupProduct {...commonProps} />;
179
- }
180
-
181
- if (result.path.startsWith('/special-page/')) {
182
- const SpecialPage = (await import('@special-page/[pk]/page')).default;
183
- return <SpecialPage {...commonProps} />;
184
- }
185
-
186
- if (result.path.startsWith('/flat-page/')) {
187
- const FlatPage = (await import('@flat-page/[pk]/page')).default;
188
- return <FlatPage {...commonProps} />;
189
- }
190
-
191
- return null;
192
- }
@@ -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
- };