@akinon/next 1.93.0-snapshot-ZERO-3574-20250813140510 → 1.93.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 +26 -1244
- package/__tests__/next-config.test.ts +10 -1
- package/bin/pz-prebuild.js +1 -0
- package/components/accordion.tsx +5 -20
- package/components/file-input.tsx +3 -65
- package/components/input.tsx +0 -2
- package/components/link.tsx +12 -16
- package/components/modal.tsx +16 -32
- package/components/plugin-module.tsx +3 -35
- package/components/selected-payment-option-view.tsx +0 -11
- package/data/client/checkout.ts +4 -25
- package/data/server/category.ts +28 -48
- package/data/server/flatpage.ts +12 -16
- package/data/server/landingpage.ts +12 -16
- package/data/server/list.ts +13 -23
- package/data/server/product.ts +39 -66
- package/data/server/special-page.ts +12 -16
- package/data/urls.ts +2 -7
- package/hocs/server/with-segment-defaults.tsx +2 -5
- package/hooks/use-localization.ts +3 -2
- package/instrumentation/node.ts +13 -15
- package/jest.config.js +1 -7
- package/lib/cache-handler.mjs +52 -35
- package/lib/cache.ts +0 -2
- package/middlewares/checkout-provider.ts +1 -1
- package/middlewares/complete-gpay.ts +2 -6
- package/middlewares/complete-masterpass.ts +2 -7
- package/middlewares/default.ts +183 -232
- package/middlewares/index.ts +1 -3
- package/middlewares/locale.ts +1 -9
- package/middlewares/redirection-payment.ts +2 -6
- package/middlewares/saved-card-redirection.ts +2 -7
- package/middlewares/three-d-redirection.ts +2 -7
- package/middlewares/url-redirection.ts +15 -9
- package/package.json +3 -3
- package/plugins.d.ts +0 -10
- package/plugins.js +1 -4
- package/redux/middlewares/checkout.ts +2 -15
- package/redux/reducers/checkout.ts +1 -9
- package/sentry/index.ts +17 -54
- package/types/commerce/order.ts +0 -1
- package/types/index.ts +1 -42
- package/utils/app-fetch.ts +2 -7
- package/utils/index.ts +10 -34
- package/utils/redirect.ts +6 -31
- package/with-pz-config.js +5 -1
- package/__tests__/redirect.test.ts +0 -319
- package/api/image-proxy.ts +0 -75
- package/api/similar-product-list.ts +0 -84
- package/api/similar-products.ts +0 -120
- package/data/server/basket.ts +0 -72
- package/hooks/use-loyalty-availability.ts +0 -21
- package/middlewares/wallet-complete-redirection.ts +0 -203
- package/utils/redirect-ignore.ts +0 -35
|
@@ -1,203 +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: 'wallet-complete-redirection',
|
|
22
|
-
error
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const withWalletCompleteRedirection =
|
|
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('WalletCompletePage') === -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: req.headers.get('cookie') ?? '',
|
|
47
|
-
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
48
|
-
'x-forwarded-for': ip
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const existingBody = await streamToString(req.body);
|
|
53
|
-
const queryParams = new URLSearchParams(url.search);
|
|
54
|
-
const bodyParams = new URLSearchParams();
|
|
55
|
-
|
|
56
|
-
if (existingBody) {
|
|
57
|
-
try {
|
|
58
|
-
const existingParams = new URLSearchParams(existingBody);
|
|
59
|
-
|
|
60
|
-
existingParams.forEach((value, key) => {
|
|
61
|
-
bodyParams.append(key, value);
|
|
62
|
-
});
|
|
63
|
-
} catch {
|
|
64
|
-
logger.error('Error parsing existing body as URL-encoded data', {
|
|
65
|
-
middleware: 'wallet-complete-redirection',
|
|
66
|
-
existingBody,
|
|
67
|
-
ip
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
queryParams.forEach((value, key) => {
|
|
73
|
-
bodyParams.append(key, value);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const body = bodyParams.toString();
|
|
77
|
-
|
|
78
|
-
if (!sessionId) {
|
|
79
|
-
logger.warn(
|
|
80
|
-
'Make sure that the SESSION_COOKIE_SAMESITE environment variable is set to None in Commerce.',
|
|
81
|
-
{
|
|
82
|
-
middleware: 'wallet-complete-redirection',
|
|
83
|
-
ip
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
return NextResponse.redirect(
|
|
88
|
-
`${url.origin}${getUrlPathWithLocale(
|
|
89
|
-
'/orders/checkout/',
|
|
90
|
-
req.cookies.get('pz-locale')?.value
|
|
91
|
-
)}`,
|
|
92
|
-
303
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const request = await fetch(requestUrl, {
|
|
97
|
-
method: 'POST',
|
|
98
|
-
headers: requestHeaders,
|
|
99
|
-
body
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
logger.info('Complete wallet payment request', {
|
|
103
|
-
requestUrl,
|
|
104
|
-
status: request.status,
|
|
105
|
-
requestHeaders,
|
|
106
|
-
ip
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
const response = await request.json();
|
|
110
|
-
|
|
111
|
-
const { context_list: contextList, errors } = response;
|
|
112
|
-
const redirectionContext = contextList?.find(
|
|
113
|
-
(context) => context.page_context?.redirect_url
|
|
114
|
-
);
|
|
115
|
-
const redirectUrl = redirectionContext?.page_context?.redirect_url;
|
|
116
|
-
|
|
117
|
-
if (errors && Object.keys(errors).length) {
|
|
118
|
-
logger.error('Error while completing wallet payment', {
|
|
119
|
-
middleware: 'wallet-complete-redirection',
|
|
120
|
-
errors,
|
|
121
|
-
requestHeaders,
|
|
122
|
-
ip
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
return NextResponse.redirect(
|
|
126
|
-
`${url.origin}${getUrlPathWithLocale(
|
|
127
|
-
'/orders/checkout/',
|
|
128
|
-
req.cookies.get('pz-locale')?.value
|
|
129
|
-
)}`,
|
|
130
|
-
{
|
|
131
|
-
status: 303,
|
|
132
|
-
headers: {
|
|
133
|
-
'Set-Cookie': `pz-pos-error=${JSON.stringify(errors)}; path=/;`
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
logger.info('Order success page context list', {
|
|
140
|
-
middleware: 'wallet-complete-redirection',
|
|
141
|
-
contextList,
|
|
142
|
-
ip
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
if (!redirectUrl) {
|
|
146
|
-
logger.warn(
|
|
147
|
-
'No redirection url for order success page found in page_context. Redirecting to checkout page.',
|
|
148
|
-
{
|
|
149
|
-
middleware: 'wallet-complete-redirection',
|
|
150
|
-
requestHeaders,
|
|
151
|
-
response: JSON.stringify(response),
|
|
152
|
-
ip
|
|
153
|
-
}
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
157
|
-
'/orders/checkout/',
|
|
158
|
-
req.cookies.get('pz-locale')?.value
|
|
159
|
-
)}`;
|
|
160
|
-
|
|
161
|
-
return NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
165
|
-
redirectUrl,
|
|
166
|
-
req.cookies.get('pz-locale')?.value
|
|
167
|
-
)}`;
|
|
168
|
-
|
|
169
|
-
logger.info('Redirecting to order success page', {
|
|
170
|
-
middleware: 'wallet-complete-redirection',
|
|
171
|
-
redirectUrlWithLocale,
|
|
172
|
-
ip
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// Using POST method while redirecting causes an error,
|
|
176
|
-
// So we use 303 status code to change the method to GET
|
|
177
|
-
const nextResponse = NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
178
|
-
|
|
179
|
-
nextResponse.headers.set(
|
|
180
|
-
'Set-Cookie',
|
|
181
|
-
request.headers.get('set-cookie') ?? ''
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
return nextResponse;
|
|
185
|
-
} catch (error) {
|
|
186
|
-
logger.error('Error while completing wallet payment', {
|
|
187
|
-
middleware: 'wallet-complete-redirection',
|
|
188
|
-
error,
|
|
189
|
-
requestHeaders,
|
|
190
|
-
ip
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
return NextResponse.redirect(
|
|
194
|
-
`${url.origin}${getUrlPathWithLocale(
|
|
195
|
-
'/orders/checkout/',
|
|
196
|
-
req.cookies.get('pz-locale')?.value
|
|
197
|
-
)}`,
|
|
198
|
-
303
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
export default withWalletCompleteRedirection;
|
package/utils/redirect-ignore.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import settings from 'settings';
|
|
2
|
-
import { getUrlPathWithLocale } from './localization';
|
|
3
|
-
|
|
4
|
-
type IgnorePath = string | RegExp;
|
|
5
|
-
|
|
6
|
-
const defaultIgnoreList: string[] = [];
|
|
7
|
-
|
|
8
|
-
const extraIgnores: IgnorePath[] = Array.isArray(
|
|
9
|
-
settings.commerceRedirectionIgnoreList
|
|
10
|
-
)
|
|
11
|
-
? settings.commerceRedirectionIgnoreList.map((path) => {
|
|
12
|
-
if (path === '/users/reset') {
|
|
13
|
-
return /^\/users\/reset\/[^/]+\/[^/]+\/$/;
|
|
14
|
-
}
|
|
15
|
-
return path;
|
|
16
|
-
})
|
|
17
|
-
: [];
|
|
18
|
-
|
|
19
|
-
export function shouldIgnoreRedirect(
|
|
20
|
-
pathname: string,
|
|
21
|
-
locale: string
|
|
22
|
-
): boolean {
|
|
23
|
-
if (!pathname) return false;
|
|
24
|
-
|
|
25
|
-
const rawIgnoreList: IgnorePath[] = [...defaultIgnoreList, ...extraIgnores];
|
|
26
|
-
|
|
27
|
-
return rawIgnoreList.some((ignorePath) => {
|
|
28
|
-
if (ignorePath instanceof RegExp) {
|
|
29
|
-
return ignorePath.test(pathname);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const localized = getUrlPathWithLocale(ignorePath, locale);
|
|
33
|
-
return localized === pathname;
|
|
34
|
-
});
|
|
35
|
-
}
|