@akinon/next 1.60.0-rc.9 → 1.60.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.
- package/CHANGELOG.md +9 -666
- package/api/client.ts +2 -23
- package/assets/styles/index.scss +26 -50
- package/bin/pz-prebuild.js +0 -1
- package/bin/pz-predev.js +0 -1
- package/components/index.ts +0 -1
- package/components/input.tsx +7 -21
- package/components/link.tsx +13 -17
- package/components/plugin-module.tsx +3 -8
- package/components/price.tsx +4 -11
- package/components/pz-root.tsx +3 -15
- package/components/selected-payment-option-view.tsx +1 -2
- package/data/client/api.ts +1 -1
- package/data/client/b2b.ts +2 -35
- package/data/client/basket.ts +5 -6
- package/data/client/checkout.ts +10 -55
- package/data/client/user.ts +2 -3
- package/data/server/category.ts +19 -43
- package/data/server/flatpage.ts +7 -29
- package/data/server/form.ts +11 -29
- package/data/server/landingpage.ts +7 -26
- package/data/server/list.ts +6 -16
- package/data/server/menu.ts +2 -15
- package/data/server/product.ts +13 -33
- package/data/server/seo.ts +24 -17
- package/data/server/special-page.ts +5 -16
- package/data/server/widget.ts +7 -14
- package/data/urls.ts +1 -8
- package/hocs/server/with-segment-defaults.tsx +1 -4
- package/hooks/index.ts +1 -2
- package/hooks/use-pagination.ts +2 -2
- package/hooks/use-payment-options.ts +1 -2
- package/lib/cache.ts +6 -4
- package/middlewares/currency.ts +1 -1
- package/middlewares/default.ts +167 -226
- package/middlewares/index.ts +1 -3
- package/middlewares/oauth-login.ts +1 -6
- package/middlewares/pretty-url.ts +1 -7
- package/package.json +2 -2
- package/plugins.d.ts +0 -6
- package/plugins.js +1 -2
- package/redux/middlewares/checkout.ts +14 -78
- package/redux/reducers/checkout.ts +3 -23
- package/redux/reducers/index.ts +1 -3
- package/routes/pretty-url.tsx +9 -7
- package/types/commerce/address.ts +1 -1
- package/types/commerce/b2b.ts +2 -12
- package/types/commerce/checkout.ts +0 -30
- package/types/commerce/order.ts +0 -1
- package/types/index.ts +7 -16
- package/utils/app-fetch.ts +7 -15
- package/utils/index.ts +6 -27
- package/utils/server-translation.ts +1 -11
- package/with-pz-config.js +1 -2
- package/assets/styles/index.css +0 -49
- package/assets/styles/index.css.map +0 -1
- package/bin/pz-generate-translations.js +0 -41
- package/components/file-input.tsx +0 -8
- package/hooks/use-message-listener.ts +0 -24
- package/middlewares/saved-card-redirection.ts +0 -179
- package/utils/redirection-iframe.ts +0 -85
|
@@ -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,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,179 +0,0 @@
|
|
|
1
|
-
import { NextFetchEvent, NextMiddleware, NextResponse } from 'next/server';
|
|
2
|
-
import Settings from 'settings';
|
|
3
|
-
import { Buffer } from 'buffer';
|
|
4
|
-
import logger from '../utils/log';
|
|
5
|
-
import { getUrlPathWithLocale } from '../utils/localization';
|
|
6
|
-
import { PzNextRequest } from '.';
|
|
7
|
-
|
|
8
|
-
const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
|
|
9
|
-
if (stream) {
|
|
10
|
-
const chunks = [];
|
|
11
|
-
let result = '';
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
for await (const chunk of stream as any) {
|
|
15
|
-
chunks.push(Buffer.from(chunk));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
result = Buffer.concat(chunks).toString('utf-8');
|
|
19
|
-
} catch (error) {
|
|
20
|
-
logger.error('Error while reading body stream', {
|
|
21
|
-
middleware: 'saved-card-redirection',
|
|
22
|
-
error
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const withSavedCardRedirection =
|
|
32
|
-
(middleware: NextMiddleware) =>
|
|
33
|
-
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
34
|
-
const url = req.nextUrl.clone();
|
|
35
|
-
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
36
|
-
const sessionId = req.cookies.get('osessionid');
|
|
37
|
-
|
|
38
|
-
if (url.search.indexOf('SavedCardThreeDSecurePage') === -1) {
|
|
39
|
-
return middleware(req, event);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const requestUrl = `${Settings.commerceUrl}/orders/checkout/${url.search}`;
|
|
43
|
-
const requestHeaders = {
|
|
44
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
45
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
46
|
-
Cookie: `osessionid=${req.cookies.get('osessionid')?.value ?? ''}`,
|
|
47
|
-
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
48
|
-
'x-forwarded-for': ip
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const body = await streamToString(req.body);
|
|
53
|
-
|
|
54
|
-
if (!sessionId) {
|
|
55
|
-
logger.warn(
|
|
56
|
-
'Make sure that the SESSION_COOKIE_SAMESITE environment variable is set to None in Commerce.',
|
|
57
|
-
{
|
|
58
|
-
middleware: 'saved-card-redirection',
|
|
59
|
-
ip
|
|
60
|
-
}
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
return NextResponse.redirect(
|
|
64
|
-
`${url.origin}${getUrlPathWithLocale(
|
|
65
|
-
'/orders/checkout/',
|
|
66
|
-
req.cookies.get('pz-locale')?.value
|
|
67
|
-
)}`,
|
|
68
|
-
303
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const request = await fetch(requestUrl, {
|
|
73
|
-
method: 'POST',
|
|
74
|
-
headers: requestHeaders,
|
|
75
|
-
body
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
logger.info('Complete 3D payment request', {
|
|
79
|
-
requestUrl,
|
|
80
|
-
status: request.status,
|
|
81
|
-
requestHeaders,
|
|
82
|
-
ip
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const response = await request.json();
|
|
86
|
-
|
|
87
|
-
const { context_list: contextList, errors } = response;
|
|
88
|
-
const redirectionContext = contextList?.find(
|
|
89
|
-
(context) => context.page_context?.redirect_url
|
|
90
|
-
);
|
|
91
|
-
const redirectUrl = redirectionContext?.page_context?.redirect_url;
|
|
92
|
-
|
|
93
|
-
if (errors && Object.keys(errors).length) {
|
|
94
|
-
logger.error('Error while completing 3D payment', {
|
|
95
|
-
middleware: 'saved-card-redirection',
|
|
96
|
-
errors,
|
|
97
|
-
requestHeaders,
|
|
98
|
-
ip
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return NextResponse.redirect(
|
|
102
|
-
`${url.origin}${getUrlPathWithLocale(
|
|
103
|
-
'/orders/checkout/',
|
|
104
|
-
req.cookies.get('pz-locale')?.value
|
|
105
|
-
)}`,
|
|
106
|
-
{
|
|
107
|
-
status: 303,
|
|
108
|
-
headers: {
|
|
109
|
-
'Set-Cookie': `pz-pos-error=${JSON.stringify(errors)}; path=/;`
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
logger.info('Order success page context list', {
|
|
116
|
-
middleware: 'saved-card-redirection',
|
|
117
|
-
contextList,
|
|
118
|
-
ip
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
if (!redirectUrl) {
|
|
122
|
-
logger.warn(
|
|
123
|
-
'No redirection url for order success page found in page_context. Redirecting to checkout page.',
|
|
124
|
-
{
|
|
125
|
-
middleware: 'saved-card-redirection',
|
|
126
|
-
requestHeaders,
|
|
127
|
-
response: JSON.stringify(response),
|
|
128
|
-
ip
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
133
|
-
'/orders/checkout/',
|
|
134
|
-
req.cookies.get('pz-locale')?.value
|
|
135
|
-
)}`;
|
|
136
|
-
|
|
137
|
-
return NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
141
|
-
redirectUrl,
|
|
142
|
-
req.cookies.get('pz-locale')?.value
|
|
143
|
-
)}`;
|
|
144
|
-
|
|
145
|
-
logger.info('Redirecting to order success page', {
|
|
146
|
-
middleware: 'saved-card-redirection',
|
|
147
|
-
redirectUrlWithLocale,
|
|
148
|
-
ip
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
// Using POST method while redirecting causes an error,
|
|
152
|
-
// So we use 303 status code to change the method to GET
|
|
153
|
-
const nextResponse = NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
154
|
-
|
|
155
|
-
nextResponse.headers.set(
|
|
156
|
-
'Set-Cookie',
|
|
157
|
-
request.headers.get('set-cookie') ?? ''
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
return nextResponse;
|
|
161
|
-
} catch (error) {
|
|
162
|
-
logger.error('Error while completing 3D payment', {
|
|
163
|
-
middleware: 'saved-card-redirection',
|
|
164
|
-
error,
|
|
165
|
-
requestHeaders,
|
|
166
|
-
ip
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
return NextResponse.redirect(
|
|
170
|
-
`${url.origin}${getUrlPathWithLocale(
|
|
171
|
-
'/orders/checkout/',
|
|
172
|
-
req.cookies.get('pz-locale')?.value
|
|
173
|
-
)}`,
|
|
174
|
-
303
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
export default withSavedCardRedirection;
|
|
@@ -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 = '✕';
|
|
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
|
-
};
|