@akinon/next 1.92.0-rc.9 → 1.92.0-snapshot-ZERO-3449-20250618101111
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 +33 -1180
- package/api/similar-product-list.ts +63 -0
- package/api/similar-products.ts +109 -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 -13
- package/components/selected-payment-option-view.tsx +0 -11
- package/data/client/similar-products.ts +122 -0
- package/data/urls.ts +5 -1
- package/hocs/server/with-segment-defaults.tsx +2 -5
- package/hooks/index.ts +2 -0
- package/hooks/use-image-cropper.ts +160 -0
- package/hooks/use-similar-products.ts +720 -0
- package/instrumentation/node.ts +13 -15
- package/lib/cache.ts +0 -2
- package/middlewares/complete-gpay.ts +1 -2
- package/middlewares/complete-masterpass.ts +1 -2
- package/middlewares/default.ts +184 -196
- package/middlewares/index.ts +1 -3
- package/middlewares/redirection-payment.ts +1 -2
- package/middlewares/saved-card-redirection.ts +1 -2
- package/middlewares/three-d-redirection.ts +1 -2
- package/middlewares/url-redirection.ts +14 -8
- package/package.json +3 -3
- package/plugins.d.ts +0 -2
- package/plugins.js +1 -3
- 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 +73 -26
- package/utils/app-fetch.ts +2 -2
- package/utils/image-validation.ts +303 -0
- package/utils/redirect.ts +3 -5
- package/with-pz-config.js +5 -1
- package/data/server/basket.ts +0 -72
- package/hooks/use-loyalty-availability.ts +0 -21
- package/middlewares/wallet-complete-redirection.ts +0 -179
- package/utils/redirect-ignore.ts +0 -35
package/data/server/basket.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Cache, CacheKey } from '../../lib/cache';
|
|
2
|
-
import { basket } from '../../data/urls';
|
|
3
|
-
import { Basket } from '../../types';
|
|
4
|
-
import appFetch from '../../utils/app-fetch';
|
|
5
|
-
import { ServerVariables } from '../../utils/server-variables';
|
|
6
|
-
import logger from '../../utils/log';
|
|
7
|
-
|
|
8
|
-
type GetBasketParams = {
|
|
9
|
-
locale?: string;
|
|
10
|
-
currency?: string;
|
|
11
|
-
namespace?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const getBasketDataHandler = ({
|
|
15
|
-
locale,
|
|
16
|
-
currency,
|
|
17
|
-
namespace
|
|
18
|
-
}: GetBasketParams) => {
|
|
19
|
-
return async function () {
|
|
20
|
-
try {
|
|
21
|
-
const url = namespace
|
|
22
|
-
? basket.getBasketDetail(namespace)
|
|
23
|
-
: basket.getBasket;
|
|
24
|
-
|
|
25
|
-
const basketData = await appFetch<{ basket: Basket }>({
|
|
26
|
-
url,
|
|
27
|
-
locale,
|
|
28
|
-
currency,
|
|
29
|
-
init: {
|
|
30
|
-
headers: {
|
|
31
|
-
Accept: 'application/json',
|
|
32
|
-
'Content-Type': 'application/json'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (!basketData?.basket) {
|
|
38
|
-
logger.warn('Basket data is undefined', {
|
|
39
|
-
handler: 'getBasketDataHandler',
|
|
40
|
-
namespace
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return basketData;
|
|
45
|
-
} catch (error) {
|
|
46
|
-
logger.error('Error fetching basket data', {
|
|
47
|
-
handler: 'getBasketDataHandler',
|
|
48
|
-
error,
|
|
49
|
-
namespace
|
|
50
|
-
});
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const getBasketData = async ({
|
|
57
|
-
locale = ServerVariables.locale,
|
|
58
|
-
currency = ServerVariables.currency,
|
|
59
|
-
namespace
|
|
60
|
-
}: GetBasketParams = {}) => {
|
|
61
|
-
return Cache.wrap(
|
|
62
|
-
CacheKey.Basket(namespace),
|
|
63
|
-
locale,
|
|
64
|
-
getBasketDataHandler({ locale, currency, namespace }),
|
|
65
|
-
{
|
|
66
|
-
expire: 0,
|
|
67
|
-
cache: false
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { useAppSelector } from '../redux/hooks';
|
|
2
|
-
|
|
3
|
-
export const useLoyaltyAvailability = () => {
|
|
4
|
-
const { paymentOptions, unavailablePaymentOptions } = useAppSelector(
|
|
5
|
-
(state) => state.checkout
|
|
6
|
-
);
|
|
7
|
-
|
|
8
|
-
const hasLoyaltyInAvailable = paymentOptions.some(
|
|
9
|
-
(option) =>
|
|
10
|
-
option.payment_type === 'loyalty_money' ||
|
|
11
|
-
option.payment_type === 'loyalty'
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
const hasLoyaltyInUnavailable = unavailablePaymentOptions.some(
|
|
15
|
-
(option) =>
|
|
16
|
-
option.payment_type === 'loyalty_money' ||
|
|
17
|
-
option.payment_type === 'loyalty'
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return hasLoyaltyInAvailable || hasLoyaltyInUnavailable;
|
|
21
|
-
};
|
|
@@ -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: '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 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: 'wallet-complete-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 wallet 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 wallet payment', {
|
|
95
|
-
middleware: 'wallet-complete-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: 'wallet-complete-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: 'wallet-complete-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: 'wallet-complete-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 wallet payment', {
|
|
163
|
-
middleware: 'wallet-complete-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 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
|
-
}
|